增加for循环

This commit is contained in:
xiangerlin 2025-07-03 19:39:49 +08:00
parent da159a25ee
commit 6a062c8cd1
1 changed files with 104 additions and 102 deletions

View File

@ -94,117 +94,119 @@ public class CInvoiceImportPluginServiceImpl implements ICInvoiceImportPluginSer
importHEntity.setStart_date_end(start_date_end);
List<CInvoiceImportHEntity> cInvoiceImportHList = cInvoiceImportHService.queryInvoiceList(importHEntity);
if (CollectionUtils.isNotEmpty(cInvoiceImportHList)) {
ParamAssembler assembler = null;
CInvoiceImportHEntity cInvoiceH = cInvoiceImportHList.get(0);
cInvoiceH.setDataSourceCode(dataSourceCode);
//2 查OA明细表
//3 查迈瑞思发票表
//迈锐思发票公共信息表
logger.info("开始查迈锐思发票公共表信息:{},{}",cInvoiceH.getId(),cInvoiceH.getBill_code());
LexmisPublicinfoEntity lexmisPublicinfoEntity = new LexmisPublicinfoEntity(cInvoiceH.getId(), dataSourceCode);
//lexmisPublicinfoEntity.setPI_ID("6952494198841691018");
List<LexmisPublicinfoEntity> lexmisPublicinfoEntityList = lexmisPublicinfoService.query(lexmisPublicinfoEntity);
if (CollectionUtils.isNotEmpty(lexmisPublicinfoEntityList)) {
cInvoiceH.setPush_status("1");
cInvoiceImportHService.updateStatus(cInvoiceH);
//税务接口每次最多传50张发票
int size = lexmisPublicinfoEntityList.size();
int batchSize = 50;
for (int i = 0; i < size; i += batchSize) {
try {
int no = 1;//序号
//4 根据发票类型组装不同参数
JSONObject head = new JSONObject();
JSONArray inputInfos = new JSONArray();
head.put("inputInfos", inputInfos);//发票录入信息单次最大50张
// 获取当前批次的子列表
List<LexmisPublicinfoEntity> batchList = lexmisPublicinfoEntityList.subList(i, Math.min(i + batchSize, size));
//使用stream方式 publicinfoList PI_TABLENAME分组
Map<String, List<LexmisPublicinfoEntity>> groupedByPiTablename = batchList.stream()
.collect(Collectors.groupingBy(LexmisPublicinfoEntity::getPI_TABLENAME));
for (Map.Entry<String, List<LexmisPublicinfoEntity>> entry : groupedByPiTablename.entrySet()) {
String key = entry.getKey();//对应发票类型的表名
List<LexmisPublicinfoEntity> publicinfoList = entry.getValue();
for (LexmisPublicinfoEntity info : publicinfoList) {
for (CInvoiceImportHEntity cInvoiceH : cInvoiceImportHList) {
ParamAssembler assembler = null;
//CInvoiceImportHEntity cInvoiceH = cInvoiceImportHList.get(0);
cInvoiceH.setDataSourceCode(dataSourceCode);
//2 查OA明细表
//3 查迈瑞思发票表
//迈锐思发票公共信息表
logger.info("开始查迈锐思发票公共表信息:{},{}",cInvoiceH.getId(),cInvoiceH.getBill_code());
LexmisPublicinfoEntity lexmisPublicinfoEntity = new LexmisPublicinfoEntity(cInvoiceH.getId(), dataSourceCode);
//lexmisPublicinfoEntity.setPI_ID("6952494198841691018");
List<LexmisPublicinfoEntity> lexmisPublicinfoEntityList = lexmisPublicinfoService.query(lexmisPublicinfoEntity);
if (CollectionUtils.isNotEmpty(lexmisPublicinfoEntityList)) {
cInvoiceH.setPush_status("1");
cInvoiceImportHService.updateStatus(cInvoiceH);
//税务接口每次最多传50张发票
int size = lexmisPublicinfoEntityList.size();
int batchSize = 50;
for (int i = 0; i < size; i += batchSize) {
try {
int no = 1;//序号
//4 根据发票类型组装不同参数
JSONObject head = new JSONObject();
JSONArray inputInfos = new JSONArray();
head.put("inputInfos", inputInfos);//发票录入信息单次最大50张
// 获取当前批次的子列表
List<LexmisPublicinfoEntity> batchList = lexmisPublicinfoEntityList.subList(i, Math.min(i + batchSize, size));
//使用stream方式 publicinfoList PI_TABLENAME分组
Map<String, List<LexmisPublicinfoEntity>> groupedByPiTablename = batchList.stream()
.collect(Collectors.groupingBy(LexmisPublicinfoEntity::getPI_TABLENAME));
for (Map.Entry<String, List<LexmisPublicinfoEntity>> entry : groupedByPiTablename.entrySet()) {
String key = entry.getKey();//对应发票类型的表名
List<LexmisPublicinfoEntity> publicinfoList = entry.getValue();
for (LexmisPublicinfoEntity info : publicinfoList) {
JSONObject inputInfo = new JSONObject();
inputInfos.add(inputInfo);
inputInfo.put("no", no);//编号
inputInfo.put("systemName", "4");//来源系统 默认写4 代表OA
inputInfo.put("businessNo", cInvoiceH.getBill_code());//业务单据号
inputInfo.put("bookkeepingStatus", "1");//记账状态默认传1
inputInfo.put("customFlag", "2");//业务流转状态默认传2
JSONObject invoiceInfo = new JSONObject();//票面信息
inputInfo.put("invoiceInfo", invoiceInfo);
JSONObject baseInfo = new JSONObject();//发票基本信息
JSONObject contentInfo = new JSONObject();//发票内容
JSONArray taxturnsInfos = new JSONArray();//进项转出信息
invoiceInfo.put("taxturnsInfos", taxturnsInfos);
JSONObject inputInfo = new JSONObject();
inputInfos.add(inputInfo);
inputInfo.put("no", no);//编号
inputInfo.put("systemName", "4");//来源系统 默认写4 代表OA
inputInfo.put("businessNo", cInvoiceH.getBill_code());//业务单据号
inputInfo.put("bookkeepingStatus", "1");//记账状态默认传1
inputInfo.put("customFlag", "2");//业务流转状态默认传2
JSONObject invoiceInfo = new JSONObject();//票面信息
inputInfo.put("invoiceInfo", invoiceInfo);
JSONObject baseInfo = new JSONObject();//发票基本信息
JSONObject contentInfo = new JSONObject();//发票内容
JSONArray taxturnsInfos = new JSONArray();//进项转出信息
invoiceInfo.put("taxturnsInfos", taxturnsInfos);
switch (key) {
case "LEXMISCIV_INVOICEMAIN"://增值税发票
zzsInvoice(dataSourceCode, info, invoiceInfo, baseInfo);
break;
case "LEXMISCIV_TRAINTICKET"://火车票
trainInvoice(dataSourceCode, inputInfos, info, inputInfo, invoiceInfo, baseInfo);
break;
case "LEXMISCIV_PLANETICKET"://飞机行程单
planeInvoice(dataSourceCode, info, invoiceInfo, baseInfo);
break;
case "LEXMISCIV_BUSINVOICE"://客运汽车票
busInvoice(dataSourceCode, info, invoiceInfo, baseInfo);
break;
default:
logger.info("没有匹配到类型");
break;
switch (key) {
case "LEXMISCIV_INVOICEMAIN"://增值税发票
zzsInvoice(dataSourceCode, info, invoiceInfo, baseInfo);
break;
case "LEXMISCIV_TRAINTICKET"://火车票
trainInvoice(dataSourceCode, inputInfos, info, inputInfo, invoiceInfo, baseInfo);
break;
case "LEXMISCIV_PLANETICKET"://飞机行程单
planeInvoice(dataSourceCode, info, invoiceInfo, baseInfo);
break;
case "LEXMISCIV_BUSINVOICE"://客运汽车票
busInvoice(dataSourceCode, info, invoiceInfo, baseInfo);
break;
default:
logger.info("没有匹配到类型");
break;
}
no++;
}
no++;
head.put("taxNo", publicinfoList.get(0).getPI_TAXNO());//当前企业税号
}
head.put("taxNo", publicinfoList.get(0).getPI_TAXNO());//当前企业税号
}
logger.info("调用有度发票批量导入接口请求参数:{}", head.toString());
//调用税务接口
Map<String, String> headerMap = MapBuilder.<String, String>create(true)
.put("apiCode", "8000600005")//有度发票导入接口
.put("publicKey", "ZJYA7f8FzV219otH8zhkReiyyWpXswpbY/+StvC2em0hf59Ce7eDIk+3zDUT+v578prj")//发起方应用
.put("secretKey", "xJ9J1Ev2F0faiJ/nQnCNklskAgtQp3QSm+ihO21uY/H0UADj0tSDPxmIhFfC4v6Fj3JzOP8MtA1LSGvL+2BWG8c/o7DKi92S4mr3zcGearA=")//发起方应用
.put("appId", "800060")
.build();
String body = HttpRequest.post(url).addHeaders(headerMap).body(head.toString()).timeout(60000).execute().body();
//String body = null;
logger.info("调用有度发票批量导入接口响应参数:{}", body);
//保存操作日志
if (StrUtil.isNotEmpty(body)) {
JSONObject jsonObject = JSONObject.parseObject(body);
Boolean flag = jsonObject.getBoolean("flag");
JSONObject resObj = jsonObject.getJSONObject("attribute");
if (null != resObj && "0".equals(resObj.getString("code"))) {
String result = resObj.getString("result");
if (StrUtil.isNotEmpty(result)) {
cInvoiceH.setDataSourceCode(dataSourceCode);
cInvoiceH.setYd_result(result);
cInvoiceImportHService.updateResultId(cInvoiceH);
logger.info("调用有度发票批量导入接口请求参数:{}", head.toString());
//调用税务接口
Map<String, String> headerMap = MapBuilder.<String, String>create(true)
.put("apiCode", "8000600005")//有度发票导入接口
.put("publicKey", "ZJYA7f8FzV219otH8zhkReiyyWpXswpbY/+StvC2em0hf59Ce7eDIk+3zDUT+v578prj")//发起方应用
.put("secretKey", "xJ9J1Ev2F0faiJ/nQnCNklskAgtQp3QSm+ihO21uY/H0UADj0tSDPxmIhFfC4v6Fj3JzOP8MtA1LSGvL+2BWG8c/o7DKi92S4mr3zcGearA=")//发起方应用
.put("appId", "800060")
.build();
String body = HttpRequest.post(url).addHeaders(headerMap).body(head.toString()).timeout(60000).execute().body();
//String body = null;
logger.info("调用有度发票批量导入接口响应参数:{}", body);
//保存操作日志
if (StrUtil.isNotEmpty(body)) {
JSONObject jsonObject = JSONObject.parseObject(body);
Boolean flag = jsonObject.getBoolean("flag");
JSONObject resObj = jsonObject.getJSONObject("attribute");
if (null != resObj && "0".equals(resObj.getString("code"))) {
String result = resObj.getString("result");
if (StrUtil.isNotEmpty(result)) {
cInvoiceH.setDataSourceCode(dataSourceCode);
cInvoiceH.setYd_result(result);
cInvoiceImportHService.updateResultId(cInvoiceH);
}
}
//保存日志
IntegrationTaskLivingDetailsEntity taskLivingDetail = new IntegrationTaskLivingDetailsEntity();
taskLivingDetail.setCreate_time(new Date());
taskLivingDetail.setModify_time(new Date());
taskLivingDetail.setRootAppPk(cInvoiceH.getId());
taskLivingDetail.setRootAppBill(cInvoiceH.getBill_code());
taskLivingDetail.setPluginId("CInvoiceImportPluginInitializer");
taskLivingDetail.setRootAppNewData(head.toString());
taskLivingDetail.setNewTransmitInfo(body);
taskLivingDetail.setNewPushDate(new Date());
this.saveLog(id, flag, taskLivingDetail);
}
//保存日志
IntegrationTaskLivingDetailsEntity taskLivingDetail = new IntegrationTaskLivingDetailsEntity();
taskLivingDetail.setCreate_time(new Date());
taskLivingDetail.setModify_time(new Date());
taskLivingDetail.setRootAppPk(cInvoiceH.getId());
taskLivingDetail.setRootAppBill(cInvoiceH.getBill_code());
taskLivingDetail.setPluginId("CInvoiceImportPluginInitializer");
taskLivingDetail.setRootAppNewData(head.toString());
taskLivingDetail.setNewTransmitInfo(body);
taskLivingDetail.setNewPushDate(new Date());
this.saveLog(id, flag, taskLivingDetail);
} catch (Exception e) {
logger.error("发票批量导入有度系统循环中出错:{}", e.getMessage());
}
} catch (Exception e) {
logger.error("发票批量导入有度系统循环中出错:{}", e.getMessage());
}
}else {
cInvoiceH.setPush_status("未查询到有效数据不推送");
cInvoiceImportHService.updateStatus(cInvoiceH);
}
}else {
cInvoiceH.setPush_status("未查询到有效数据不推送");
cInvoiceImportHService.updateStatus(cInvoiceH);
}
}