|  |  |  | @ -2,6 +2,7 @@ package com.glxp.api.service.thrsys.impl; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | import cn.hutool.core.collection.CollUtil; | 
			
		
	
		
			
				
					|  |  |  |  | import cn.hutool.core.collection.CollectionUtil; | 
			
		
	
		
			
				
					|  |  |  |  | import cn.hutool.core.date.DateUtil; | 
			
		
	
		
			
				
					|  |  |  |  | import cn.hutool.core.util.IdUtil; | 
			
		
	
		
			
				
					|  |  |  |  | import cn.hutool.core.util.ObjectUtil; | 
			
		
	
		
			
				
					|  |  |  |  | import cn.hutool.core.util.StrUtil; | 
			
		
	
	
		
			
				
					|  |  |  | @ -14,6 +15,7 @@ import com.glxp.api.common.util.ResultVOUtils; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.constant.Constant; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.constant.ConstantStatus; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.constant.ConstantType; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.dao.basic.ProductInfoDao; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.dao.basic.UdiRelevanceDao; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.dao.inout.IoCodeTempDao; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.dao.thrsys.ThrInvOrderDetailMapper; | 
			
		
	
	
		
			
				
					|  |  |  | @ -113,6 +115,8 @@ public class ThrInvOrderServiceImpl implements ThrInvOrderService { | 
			
		
	
		
			
				
					|  |  |  |  |     IoAddInoutService addInoutService; | 
			
		
	
		
			
				
					|  |  |  |  |     @Resource | 
			
		
	
		
			
				
					|  |  |  |  |     UdiCalCountUtil udiCalCountUtil; | 
			
		
	
		
			
				
					|  |  |  |  |     @Resource | 
			
		
	
		
			
				
					|  |  |  |  |     ProductInfoDao productInfoDao; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // 设置要输出的日期格式
 | 
			
		
	
		
			
				
					|  |  |  |  |     SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); | 
			
		
	
	
		
			
				
					|  |  |  | @ -174,32 +178,38 @@ public class ThrInvOrderServiceImpl implements ThrInvOrderService { | 
			
		
	
		
			
				
					|  |  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |  |     public void handleExternalThrInvPhOrder(FilterInvProductRequest filterInvProductRequest) { | 
			
		
	
		
			
				
					|  |  |  |  |         BaseResponse<PageSimpleResponse<ThrInvResultResponse>> baseResponse = erpInvClient.getInvPhResult(filterInvProductRequest); | 
			
		
	
		
			
				
					|  |  |  |  |         if (baseResponse!= null && baseResponse.getCode() == 20000) { | 
			
		
	
		
			
				
					|  |  |  |  |         if (baseResponse != null && baseResponse.getCode() == 20000) { | 
			
		
	
		
			
				
					|  |  |  |  |             List<ThrInvResultResponse> list = baseResponse.getData().getList(); | 
			
		
	
		
			
				
					|  |  |  |  |             if (CollectionUtil.isNotEmpty(list)) { | 
			
		
	
		
			
				
					|  |  |  |  |                 String billNo = generateBillNo(filterInvProductRequest);//单据号
 | 
			
		
	
		
			
				
					|  |  |  |  |                 //处理 返回实体 转换成 单据 和 单据明细
 | 
			
		
	
		
			
				
					|  |  |  |  |                 ThrInvOrder thrInvOrder = new ThrInvOrder(); | 
			
		
	
		
			
				
					|  |  |  |  |                 List<ThrInvOrderDetail> thrInvOrderDetails = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |  |                 String thirdSys = filterInvProductRequest.getThirdSys(); | 
			
		
	
		
			
				
					|  |  |  |  |                 handleExternalConvertThrInvOrderDetail(list, thrInvOrderDetails, billNo, thirdSys, thrInvOrder, 0); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |                 if (CollectionUtil.isNotEmpty(thrInvOrderDetails)) { | 
			
		
	
		
			
				
					|  |  |  |  |                     handleExternalConvertThrInvOrder(billNo, filterInvProductRequest, thrInvOrder, list.get(0), Constant.THR_INV_PH_ORDER_TYPE); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |                     //是否自动生成出入库单据
 | 
			
		
	
		
			
				
					|  |  |  |  |                     if (IntUtil.value(systemParamConfigService.selectValueByParamKey("fee_out_auto_gen")) > 0) { | 
			
		
	
		
			
				
					|  |  |  |  |                         GenerateOrderRequest generateOrderRequest = new GenerateOrderRequest(); | 
			
		
	
		
			
				
					|  |  |  |  |                         generateOrderRequest.setBillNo(thrInvOrder.getBillNo()); | 
			
		
	
		
			
				
					|  |  |  |  |                         generateOrderRequest.setAction(thrInvOrder.getBillType()); | 
			
		
	
		
			
				
					|  |  |  |  |                         generateOrderRequest.setFromCorp(thrInvOrder.getFromCorp()); | 
			
		
	
		
			
				
					|  |  |  |  |                         generateOrder(generateOrderRequest); | 
			
		
	
		
			
				
					|  |  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |  |                 Map<String, List<ThrInvResultResponse>> groupedByInv = list.stream() | 
			
		
	
		
			
				
					|  |  |  |  |                         .collect(Collectors.groupingBy( | 
			
		
	
		
			
				
					|  |  |  |  |                                 item -> item.getInvCode() + "-" + item.getBillType() | 
			
		
	
		
			
				
					|  |  |  |  |                         )); | 
			
		
	
		
			
				
					|  |  |  |  |                 groupedByInv.forEach((invCode, invResultResponses) -> { | 
			
		
	
		
			
				
					|  |  |  |  |                     String billNo = generateBillNo(filterInvProductRequest);//单据号
 | 
			
		
	
		
			
				
					|  |  |  |  |                     //处理 返回实体 转换成 单据 和 单据明细
 | 
			
		
	
		
			
				
					|  |  |  |  |                     ThrInvOrder thrInvOrder = new ThrInvOrder(); | 
			
		
	
		
			
				
					|  |  |  |  |                     List<ThrInvOrderDetail> thrInvOrderDetails = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |  |                     String thirdSys = filterInvProductRequest.getThirdSys(); | 
			
		
	
		
			
				
					|  |  |  |  |                     handleExternalConvertThrInvOrderDetail(invResultResponses, thrInvOrderDetails, billNo, thirdSys, thrInvOrder, 0); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |                     //保存数据
 | 
			
		
	
		
			
				
					|  |  |  |  |                     thrInvOrderMapper.insert(thrInvOrder); | 
			
		
	
		
			
				
					|  |  |  |  |                     thrInvOrderDetailMapper.insertBatch(thrInvOrderDetails); | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |                     if (CollectionUtil.isNotEmpty(thrInvOrderDetails)) { | 
			
		
	
		
			
				
					|  |  |  |  |                         handleExternalConvertThrInvOrder(billNo, filterInvProductRequest, thrInvOrder, invResultResponses.get(0), Constant.THR_INV_PH_ORDER_TYPE); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |                         //是否自动生成出入库单据
 | 
			
		
	
		
			
				
					|  |  |  |  |                         if (IntUtil.value(systemParamConfigService.selectValueByParamKey("fee_out_auto_gen")) > 0) { | 
			
		
	
		
			
				
					|  |  |  |  |                             GenerateOrderRequest generateOrderRequest = new GenerateOrderRequest(); | 
			
		
	
		
			
				
					|  |  |  |  |                             generateOrderRequest.setBillNo(thrInvOrder.getBillNo()); | 
			
		
	
		
			
				
					|  |  |  |  |                             generateOrderRequest.setAction(thrInvOrder.getBillType()); | 
			
		
	
		
			
				
					|  |  |  |  |                             generateOrderRequest.setFromCorp(thrInvOrder.getFromCorp()); | 
			
		
	
		
			
				
					|  |  |  |  |                             generateOrder(generateOrderRequest); | 
			
		
	
		
			
				
					|  |  |  |  |                         } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |                         //保存数据
 | 
			
		
	
		
			
				
					|  |  |  |  |                         thrInvOrderMapper.insert(thrInvOrder); | 
			
		
	
		
			
				
					|  |  |  |  |                         thrInvOrderDetailMapper.insertBatch(thrInvOrderDetails); | 
			
		
	
		
			
				
					|  |  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |  |                 }); | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
	
		
			
				
					|  |  |  | @ -227,11 +237,11 @@ public class ThrInvOrderServiceImpl implements ThrInvOrderService { | 
			
		
	
		
			
				
					|  |  |  |  |                                 thrInvOrder.setSickerCode(thrInvResultResponse.getSickerCode()); | 
			
		
	
		
			
				
					|  |  |  |  |                                 thrInvOrder.setSickerName(thrInvResultResponse.getSickerName()); | 
			
		
	
		
			
				
					|  |  |  |  |                                 thrInvOrder.setCreateUser(thrInvResultResponse.getChargeUser()); | 
			
		
	
		
			
				
					|  |  |  |  |                                 try { | 
			
		
	
		
			
				
					|  |  |  |  |                                     thrInvOrder.setChargeTime(sdf2.parse(thrInvResultResponse.getChargeTime())); | 
			
		
	
		
			
				
					|  |  |  |  |                                 } catch (ParseException e) { | 
			
		
	
		
			
				
					|  |  |  |  |                                     log.error("第三方高耗收费明细下载--收费时间转化出错,原数据:【" + thrInvResultResponse.getChargeTime() + "】"); | 
			
		
	
		
			
				
					|  |  |  |  |                                 } | 
			
		
	
		
			
				
					|  |  |  |  | //                                try {
 | 
			
		
	
		
			
				
					|  |  |  |  |                                     thrInvOrder.setChargeTime(thrInvResultResponse.getChargeTime()); | 
			
		
	
		
			
				
					|  |  |  |  | //                                } catch (ParseException e) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                    log.error("第三方高耗收费明细下载--收费时间转化出错,原数据:【" + thrInvResultResponse.getChargeTime() + "】");
 | 
			
		
	
		
			
				
					|  |  |  |  | //                                }
 | 
			
		
	
		
			
				
					|  |  |  |  |                                 //保存数据
 | 
			
		
	
		
			
				
					|  |  |  |  |                                 thrInvOrderMapper.insert(thrInvOrder); | 
			
		
	
		
			
				
					|  |  |  |  |                                 thrInvOrderDetailMapper.insertBatch(thrInvOrderDetails); | 
			
		
	
	
		
			
				
					|  |  |  | @ -1513,23 +1523,36 @@ public class ThrInvOrderServiceImpl implements ThrInvOrderService { | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         Date newDate = new Date(); | 
			
		
	
		
			
				
					|  |  |  |  |         ThrSystemBusApiEntity thrSystemBusApiEntity = thrSystemBusApiService.getOne(new QueryWrapper<ThrSystemBusApiEntity>().eq("code", thrInvResultResponse.getBillType()).last("limit 1")); | 
			
		
	
		
			
				
					|  |  |  |  |         thrInvOrder.setBillNo(billNo);//单据号
 | 
			
		
	
		
			
				
					|  |  |  |  |         thrInvOrder.setBillDate(newDate);//单据时间
 | 
			
		
	
		
			
				
					|  |  |  |  |         thrInvOrder.setStartDate(filterInvProductRequest.getStartDate());//库存开始时间
 | 
			
		
	
		
			
				
					|  |  |  |  |         thrInvOrder.setEndDate(filterInvProductRequest.getEndDate());//库存结束时间
 | 
			
		
	
		
			
				
					|  |  |  |  |         thrInvOrder.setMainAction(thrInvResultResponse.getMainAction());//出入库类型
 | 
			
		
	
		
			
				
					|  |  |  |  |         thrInvOrder.setBillType(thrInvResultResponse.getBillType());//第三方单据类型
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         if ("OUT".equals(thrInvResultResponse.getBillType())){//收费出库
 | 
			
		
	
		
			
				
					|  |  |  |  |             thrInvOrder.setMainAction("WareHouseOut");//出入库类型
 | 
			
		
	
		
			
				
					|  |  |  |  |             thrInvOrder.setBillType("SC71021292871198");//第三方单据类型
 | 
			
		
	
		
			
				
					|  |  |  |  |         }else { | 
			
		
	
		
			
				
					|  |  |  |  |             thrInvOrder.setMainAction("WareHouseIn");//出入库类型
 | 
			
		
	
		
			
				
					|  |  |  |  |             thrInvOrder.setBillType("SC72854426720051");//第三方单据类型
 | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         thrInvOrder.setThirdSysFk(filterInvProductRequest.getThirdSys());//外部系统
 | 
			
		
	
		
			
				
					|  |  |  |  |         thrInvOrder.setDeptCode(thrInvResultResponse.getDeptCode());//部门编号
 | 
			
		
	
		
			
				
					|  |  |  |  |         thrInvOrder.setDeptName(thrInvResultResponse.getDeptName());//部门编号
 | 
			
		
	
		
			
				
					|  |  |  |  |         thrInvOrder.setInvCode(thrInvResultResponse.getInvCode());//仓库代码
 | 
			
		
	
		
			
				
					|  |  |  |  |         thrInvOrder.setInvName(thrInvResultResponse.getInvName());//仓库代码
 | 
			
		
	
		
			
				
					|  |  |  |  |         thrInvOrder.setSpaceCode(thrInvResultResponse.getSpaceCode());//货位编码
 | 
			
		
	
		
			
				
					|  |  |  |  |         thrInvOrder.setStatus(ConstantStatus.SFIO_DRAFT);//单据状态 草稿
 | 
			
		
	
		
			
				
					|  |  |  |  |         thrInvOrder.setSourceType(SourceType);//来源类型
 | 
			
		
	
		
			
				
					|  |  |  |  |         thrInvOrder.setCreateTime(newDate); | 
			
		
	
		
			
				
					|  |  |  |  |         thrInvOrder.setGenStatus(1); | 
			
		
	
		
			
				
					|  |  |  |  |         if (thrSystemBusApiEntity != null) | 
			
		
	
		
			
				
					|  |  |  |  |             thrInvOrder.setFromCorp(thrSystemBusApiEntity.getFromCorp()); | 
			
		
	
		
			
				
					|  |  |  |  |         thrInvOrder.setSickerCode(thrInvResultResponse.getSickerCode()); | 
			
		
	
		
			
				
					|  |  |  |  |         thrInvOrder.setSickerName(thrInvResultResponse.getSickerName()); | 
			
		
	
		
			
				
					|  |  |  |  |         thrInvOrder.setChargeTime(DateUtil.formatDate(DateUtil.parse(thrInvResultResponse.getChargeTime(), "yyyyMMdd"))); | 
			
		
	
		
			
				
					|  |  |  |  |         thrInvOrder.setChargeUser(thrInvResultResponse.getChargeUser()); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         ThrSystemBusApiEntity thrSystemBusApiEntity = thrSystemBusApiService.getOne(new QueryWrapper<ThrSystemBusApiEntity>().eq("code", thrInvOrder.getBillType()).last("limit 1")); | 
			
		
	
		
			
				
					|  |  |  |  |         if (thrSystemBusApiEntity != null)  thrInvOrder.setFromCorp(thrSystemBusApiEntity.getFromCorp()); | 
			
		
	
		
			
				
					|  |  |  |  |         thrInvOrder.setCreateUser("外部系统下载"); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
	
		
			
				
					|  |  |  | @ -1563,8 +1586,9 @@ public class ThrInvOrderServiceImpl implements ThrInvOrderService { | 
			
		
	
		
			
				
					|  |  |  |  |                 String mainAction = item.getMainAction(); | 
			
		
	
		
			
				
					|  |  |  |  |                 String thrCode = item.getThrCode(); | 
			
		
	
		
			
				
					|  |  |  |  |                 Long relId = null; | 
			
		
	
		
			
				
					|  |  |  |  |                 UdiRelevanceEntity udiRelevanceEntity = new UdiRelevanceEntity(); | 
			
		
	
		
			
				
					|  |  |  |  |                 if (mainIdRelIdMap != null){ | 
			
		
	
		
			
				
					|  |  |  |  |                     UdiRelevanceEntity udiRelevanceEntity = mainIdRelIdMap.get(thrCode); | 
			
		
	
		
			
				
					|  |  |  |  |                     udiRelevanceEntity = mainIdRelIdMap.get(thrCode); | 
			
		
	
		
			
				
					|  |  |  |  |                     if (udiRelevanceEntity != null){ | 
			
		
	
		
			
				
					|  |  |  |  |                         relId = udiRelevanceEntity.getId(); | 
			
		
	
		
			
				
					|  |  |  |  |                     } | 
			
		
	
	
		
			
				
					|  |  |  | @ -1582,6 +1606,22 @@ public class ThrInvOrderServiceImpl implements ThrInvOrderService { | 
			
		
	
		
			
				
					|  |  |  |  |                 thrInvOrderDetail.setRelId(relId); | 
			
		
	
		
			
				
					|  |  |  |  |                 thrInvOrderDetail.setThrCode(thrCode); | 
			
		
	
		
			
				
					|  |  |  |  |                 thrInvOrderDetail.setReCount(String.valueOf(count)); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |                 if (udiRelevanceEntity != null) { | 
			
		
	
		
			
				
					|  |  |  |  |                     String uuid = udiRelevanceEntity.getUuid(); | 
			
		
	
		
			
				
					|  |  |  |  |                     List<ProductInfoEntity> productInfoEntities = productInfoDao.selectByUuid(uuid); | 
			
		
	
		
			
				
					|  |  |  |  |                     if (CollUtil.isNotEmpty(productInfoEntities)){ | 
			
		
	
		
			
				
					|  |  |  |  |                         ProductInfoEntity productInfoEntity = productInfoEntities.get(0); | 
			
		
	
		
			
				
					|  |  |  |  |                         if(productInfoEntity != null && StrUtil.isEmpty(thrInvOrderDetail.getYlqxzcrbarmc())){ | 
			
		
	
		
			
				
					|  |  |  |  |                             thrInvOrderDetail.setYlqxzcrbarmc(productInfoEntity.getYlqxzcrbarmc()); | 
			
		
	
		
			
				
					|  |  |  |  |                         } | 
			
		
	
		
			
				
					|  |  |  |  |                         if(productInfoEntity != null && StrUtil.isEmpty(thrInvOrderDetail.getZczbhhzbapzbh())){ | 
			
		
	
		
			
				
					|  |  |  |  |                             thrInvOrderDetail.setZczbhhzbapzbh(productInfoEntity.getZczbhhzbapzbh()); | 
			
		
	
		
			
				
					|  |  |  |  |                         } | 
			
		
	
		
			
				
					|  |  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |                 if (ObjectUtil.isNull(relId)) { | 
			
		
	
		
			
				
					|  |  |  |  |                     exmsg.append(thrCode + ","); | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
	
		
			
				
					|  |  |  | @ -1617,7 +1657,7 @@ public class ThrInvOrderServiceImpl implements ThrInvOrderService { | 
			
		
	
		
			
				
					|  |  |  |  |                     if (relId != null){ | 
			
		
	
		
			
				
					|  |  |  |  |                         //过滤是否高值
 | 
			
		
	
		
			
				
					|  |  |  |  |                         if (IntUtil.value(highFilter) > 0) { | 
			
		
	
		
			
				
					|  |  |  |  |                             UdiRelevanceEntity udiRelevanceEntity = mainIdRelIdMap.get(thrCode); | 
			
		
	
		
			
				
					|  |  |  |  |                             UdiRelevanceEntity udiRelevanceEntity1 = mainIdRelIdMap.get(thrCode); | 
			
		
	
		
			
				
					|  |  |  |  |                             if (IntUtil.value(udiRelevanceEntity.getHcType()) != 1) { | 
			
		
	
		
			
				
					|  |  |  |  |                                 thrInvOrderDetails.add(thrInvOrderDetail); | 
			
		
	
		
			
				
					|  |  |  |  |                             } | 
			
		
	
	
		
			
				
					|  |  |  | @ -1628,7 +1668,7 @@ public class ThrInvOrderServiceImpl implements ThrInvOrderService { | 
			
		
	
		
			
				
					|  |  |  |  |                 } else { | 
			
		
	
		
			
				
					|  |  |  |  |                     //过滤是否高值
 | 
			
		
	
		
			
				
					|  |  |  |  |                     if (IntUtil.value(highFilter) > 0) { | 
			
		
	
		
			
				
					|  |  |  |  |                         UdiRelevanceEntity udiRelevanceEntity = mainIdRelIdMap.get(thrCode); | 
			
		
	
		
			
				
					|  |  |  |  |                         UdiRelevanceEntity udiRelevanceEntity1 = mainIdRelIdMap.get(thrCode); | 
			
		
	
		
			
				
					|  |  |  |  |                         if (IntUtil.value(udiRelevanceEntity.getHcType()) != 1) { | 
			
		
	
		
			
				
					|  |  |  |  |                             thrInvOrderDetails.add(thrInvOrderDetail); | 
			
		
	
		
			
				
					|  |  |  |  |                         } | 
			
		
	
	
		
			
				
					|  |  |  | 
 |