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