|  |  |  | @ -7,8 +7,10 @@ import cn.hutool.core.util.StrUtil; | 
			
		
	
		
			
				
					|  |  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.common.res.BaseResponse; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.common.util.ResultVOUtils; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.dao.basic.UdiRelevanceDao; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.dao.thrsys.ThrOrderDao; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.dao.thrsys.ThrOrderDetailDao; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.entity.basic.UdiRelevanceEntity; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.entity.collect.IoCollectOrder; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.entity.collect.IoCollectOrderBiz; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.entity.thrsys.ThrOrderDetailEntity; | 
			
		
	
	
		
			
				
					|  |  |  | @ -19,7 +21,7 @@ import com.glxp.api.req.thrsys.FilterThrOrderRequest; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.res.PageSimpleResponse; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.res.thrsys.ThrOrderResponse; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.service.collect.IoCollectOrderService; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.util.IntUtil; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.util.MsDateUtil; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springframework.stereotype.Service; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | import javax.annotation.Resource; | 
			
		
	
	
		
			
				
					|  |  |  | @ -45,67 +47,32 @@ public class ThrOrderDownload implements IDownload { | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |  |     public BaseResponse downloadOrder(CollectOrderRequest collectOrderRequest) { | 
			
		
	
		
			
				
					|  |  |  |  |         LambdaQueryWrapper<ThrOrderEntity> w = new LambdaQueryWrapper<>(); | 
			
		
	
		
			
				
					|  |  |  |  |         w.eq(StrUtil.isNotBlank(collectOrderRequest.getBillNo()), ThrOrderEntity::getBillNo, collectOrderRequest.getBillNo()); | 
			
		
	
		
			
				
					|  |  |  |  |         List<ThrOrderEntity> thrOrderEntities = thrOrderDao.selectList(w); | 
			
		
	
		
			
				
					|  |  |  |  |         if (CollUtil.isNotEmpty(thrOrderEntities)) { | 
			
		
	
		
			
				
					|  |  |  |  |             return this.importThrOrder(thrOrderEntities, collectOrderRequest); | 
			
		
	
		
			
				
					|  |  |  |  |         } else { | 
			
		
	
		
			
				
					|  |  |  |  |             int page = 1; | 
			
		
	
		
			
				
					|  |  |  |  |             int limit = 100; | 
			
		
	
		
			
				
					|  |  |  |  | //        LambdaQueryWrapper<ThrOrderEntity> w = new LambdaQueryWrapper<>();
 | 
			
		
	
		
			
				
					|  |  |  |  | //        w.eq(StrUtil.isNotBlank(collectOrderRequest.getBillNo()), ThrOrderEntity::getBillNo, collectOrderRequest.getBillNo());
 | 
			
		
	
		
			
				
					|  |  |  |  | //        List<ThrOrderEntity> thrOrderEntities = thrOrderDao.selectList(w);
 | 
			
		
	
		
			
				
					|  |  |  |  | //        if (CollUtil.isNotEmpty(thrOrderEntities)) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //            return this.importThrOrder(thrOrderEntities, collectOrderRequest);
 | 
			
		
	
		
			
				
					|  |  |  |  | //        } else {
 | 
			
		
	
		
			
				
					|  |  |  |  |         //三方拉取
 | 
			
		
	
		
			
				
					|  |  |  |  |         FilterThrOrderRequest filterThrOrderRequest = new FilterThrOrderRequest(); | 
			
		
	
		
			
				
					|  |  |  |  |             filterThrOrderRequest.setLimit(limit); | 
			
		
	
		
			
				
					|  |  |  |  |         filterThrOrderRequest.setPage(1); | 
			
		
	
		
			
				
					|  |  |  |  |         filterThrOrderRequest.setLimit(100); | 
			
		
	
		
			
				
					|  |  |  |  |         filterThrOrderRequest.setBillNo(collectOrderRequest.getBillNo()); | 
			
		
	
		
			
				
					|  |  |  |  |         filterThrOrderRequest.setThirdSys("thirdId"); | 
			
		
	
		
			
				
					|  |  |  |  |         filterThrOrderRequest.setBusType(collectOrderRequest.getBusType()); | 
			
		
	
		
			
				
					|  |  |  |  |         filterThrOrderRequest.setWorkPlaceCode(collectOrderRequest.getWorkPlaceCode()); | 
			
		
	
		
			
				
					|  |  |  |  |         filterThrOrderRequest.setFromType(collectOrderRequest.getFromType()); | 
			
		
	
		
			
				
					|  |  |  |  |             while (true){ | 
			
		
	
		
			
				
					|  |  |  |  |                 filterThrOrderRequest.setPage(page); | 
			
		
	
		
			
				
					|  |  |  |  |                 BaseResponse<PageSimpleResponse<ThrOrderResponse>> baseResponse = erpBasicClient.getThrOrders(filterThrOrderRequest); | 
			
		
	
		
			
				
					|  |  |  |  |         BaseResponse<PageSimpleResponse<IoCollectOrder>> baseResponse = erpBasicClient.getThrOrders(filterThrOrderRequest); | 
			
		
	
		
			
				
					|  |  |  |  |         if (baseResponse.getCode() == 20000) { | 
			
		
	
		
			
				
					|  |  |  |  |                     List<ThrOrderResponse> list = baseResponse.getData().getList(); | 
			
		
	
		
			
				
					|  |  |  |  |                     if (CollUtil.isNotEmpty(list)) { | 
			
		
	
		
			
				
					|  |  |  |  |                         list.forEach(item -> { | 
			
		
	
		
			
				
					|  |  |  |  |                             ThrOrderEntity thrOrderEntity = new ThrOrderEntity(); | 
			
		
	
		
			
				
					|  |  |  |  |                             ThrOrderEntity old = thrOrderDao.selectOne(new LambdaQueryWrapper<ThrOrderEntity>().eq(ThrOrderEntity::getBillNo, item.getBillNo()).last("limit 1")); | 
			
		
	
		
			
				
					|  |  |  |  |                             BeanUtil.copyProperties(item, thrOrderEntity); | 
			
		
	
		
			
				
					|  |  |  |  |                             if(old == null){ | 
			
		
	
		
			
				
					|  |  |  |  |                                 //新增
 | 
			
		
	
		
			
				
					|  |  |  |  |                                 thrOrderEntity.setCreateTime(new Date()); | 
			
		
	
		
			
				
					|  |  |  |  |                                 thrOrderEntity.setUpdateTime(new Date()); | 
			
		
	
		
			
				
					|  |  |  |  |                             }else{ | 
			
		
	
		
			
				
					|  |  |  |  |                                 //更新
 | 
			
		
	
		
			
				
					|  |  |  |  |                                 thrOrderEntity.setId(old.getId()); | 
			
		
	
		
			
				
					|  |  |  |  |                                 thrOrderEntity.setUpdateTime(new Date()); | 
			
		
	
		
			
				
					|  |  |  |  |                             } | 
			
		
	
		
			
				
					|  |  |  |  |                             List<ThrOrderDetailEntity> detailList = item.getDetailList(); | 
			
		
	
		
			
				
					|  |  |  |  |                             if (CollUtil.isNotEmpty(detailList)) { | 
			
		
	
		
			
				
					|  |  |  |  |                                 thrOrderDetailDao.delete(new LambdaQueryWrapper<ThrOrderDetailEntity>().eq(ThrOrderDetailEntity::getOrderIdFk, item.getBillNo())); | 
			
		
	
		
			
				
					|  |  |  |  |                                 for (ThrOrderDetailEntity detail : detailList) { | 
			
		
	
		
			
				
					|  |  |  |  |                                     detail.setCreateTime(thrOrderEntity.getCreateTime()); | 
			
		
	
		
			
				
					|  |  |  |  |                                     detail.setUpdateTime(thrOrderEntity.getUpdateTime()); | 
			
		
	
		
			
				
					|  |  |  |  |                                     thrOrderDetailDao.insert(detail); | 
			
		
	
		
			
				
					|  |  |  |  |                                 } | 
			
		
	
		
			
				
					|  |  |  |  |                             } | 
			
		
	
		
			
				
					|  |  |  |  |                             thrOrderDao.insertOrUpdate(thrOrderEntity); | 
			
		
	
		
			
				
					|  |  |  |  |                         }); | 
			
		
	
		
			
				
					|  |  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |  |                     if ((list.size() >= limit && !baseResponse.getData().getTotal().equals(-666)) || IntUtil.value(baseResponse.getData().getTotal()) == -555) { | 
			
		
	
		
			
				
					|  |  |  |  |                         page++; | 
			
		
	
		
			
				
					|  |  |  |  |                     } else { | 
			
		
	
		
			
				
					|  |  |  |  |                         break; | 
			
		
	
		
			
				
					|  |  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |  |                 }else { | 
			
		
	
		
			
				
					|  |  |  |  |                     return ResultVOUtils.error(500, "下载第三方系统产品信息异常"); | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             //再次获取
 | 
			
		
	
		
			
				
					|  |  |  |  |             thrOrderEntities = thrOrderDao.selectList(w); | 
			
		
	
		
			
				
					|  |  |  |  |             return this.importThrOrder(thrOrderEntities, collectOrderRequest); | 
			
		
	
		
			
				
					|  |  |  |  |             List<IoCollectOrder> list = baseResponse.getData().getList(); | 
			
		
	
		
			
				
					|  |  |  |  |             return this.importThrOrder(list, collectOrderRequest); | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         return ResultVOUtils.error("下载失败"); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     //    }
 | 
			
		
	
		
			
				
					|  |  |  |  |     @Resource | 
			
		
	
		
			
				
					|  |  |  |  |     UdiRelevanceDao udiRelevanceDao; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |  |      * 下载至单据 | 
			
		
	
	
		
			
				
					|  |  |  | @ -113,41 +80,31 @@ public class ThrOrderDownload implements IDownload { | 
			
		
	
		
			
				
					|  |  |  |  |      * @param thrOrderEntities | 
			
		
	
		
			
				
					|  |  |  |  |      * @param collectOrderRequest | 
			
		
	
		
			
				
					|  |  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |  |     private BaseResponse importThrOrder(List<ThrOrderEntity> thrOrderEntities, CollectOrderRequest collectOrderRequest) { | 
			
		
	
		
			
				
					|  |  |  |  |     private BaseResponse importThrOrder(List<IoCollectOrder> thrOrderEntities, CollectOrderRequest collectOrderRequest) { | 
			
		
	
		
			
				
					|  |  |  |  |         List<IoCollectOrder> ioCollectOrderList = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |  |         if (CollUtil.isNotEmpty(thrOrderEntities)) { | 
			
		
	
		
			
				
					|  |  |  |  |             for (ThrOrderEntity thrOrder : thrOrderEntities) { | 
			
		
	
		
			
				
					|  |  |  |  |             for (IoCollectOrder thrOrder : thrOrderEntities) { | 
			
		
	
		
			
				
					|  |  |  |  |                 IoCollectOrder ioCollectOrder = new IoCollectOrder(); | 
			
		
	
		
			
				
					|  |  |  |  |                 BeanUtil.copyProperties(thrOrder, ioCollectOrder); | 
			
		
	
		
			
				
					|  |  |  |  |                 StringBuilder errorMsg = new StringBuilder(); | 
			
		
	
		
			
				
					|  |  |  |  |                 ioCollectOrder.setBillNo(thrOrder.getBillNo()); | 
			
		
	
		
			
				
					|  |  |  |  |                 ioCollectOrder.setFromType("HIS系统"); | 
			
		
	
		
			
				
					|  |  |  |  |                 ioCollectOrder.setFromCorp(null); | 
			
		
	
		
			
				
					|  |  |  |  |                 ioCollectOrder.setWorkPlaceCode(collectOrderRequest.getWorkPlaceCode()); | 
			
		
	
		
			
				
					|  |  |  |  |                 ioCollectOrder.setFromCorpName(""); | 
			
		
	
		
			
				
					|  |  |  |  |                 ioCollectOrder.setBillTime(DateUtil.parseTime(thrOrder.getBilldate())); | 
			
		
	
		
			
				
					|  |  |  |  |                 ioCollectOrder.setCreateTime(new Date()); | 
			
		
	
		
			
				
					|  |  |  |  |                 ioCollectOrder.setCreateUser(collectOrderRequest.getCreateUser()); | 
			
		
	
		
			
				
					|  |  |  |  |                 ioCollectOrder.setBackupOrderRemark1(null); | 
			
		
	
		
			
				
					|  |  |  |  |                 ioCollectOrder.setUpdateTime(new Date()); | 
			
		
	
		
			
				
					|  |  |  |  |                 ioCollectOrder.setSplitStatus(0); | 
			
		
	
		
			
				
					|  |  |  |  |                 ioCollectOrder.setTagStatus(0); | 
			
		
	
		
			
				
					|  |  |  |  |                 List<ThrOrderDetailEntity> thrOrderDetailEntities = thrOrderDetailDao.selectList(new LambdaQueryWrapper<ThrOrderDetailEntity>().eq(ThrOrderDetailEntity::getOrderIdFk, thrOrder.getBillNo())); | 
			
		
	
		
			
				
					|  |  |  |  |                 List<IoCollectOrderBiz> bizList = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |  |                 for (ThrOrderDetailEntity entity : thrOrderDetailEntities) { | 
			
		
	
		
			
				
					|  |  |  |  |                 for (IoCollectOrderBiz entity : thrOrder.getBizList()) { | 
			
		
	
		
			
				
					|  |  |  |  |                     IoCollectOrderBiz collectOrderBiz = new IoCollectOrderBiz(); | 
			
		
	
		
			
				
					|  |  |  |  | //                    BasicUdirelEntity basicUdirelEntity = basicUdirelDao.selectOne(new LambdaQueryWrapper<BasicUdirelEntity>().eq(BasicUdirelEntity::getMainId, entity.getPHYSIC_CODE()));
 | 
			
		
	
		
			
				
					|  |  |  |  | //                    if (basicUdirelEntity != null) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                        collectOrderBiz.setRelId(basicUdirelEntity.getId());
 | 
			
		
	
		
			
				
					|  |  |  |  | //                    } else {
 | 
			
		
	
		
			
				
					|  |  |  |  | //                        errorMsg.append(entity.getPHYSIC_NAME()).append("字典未对照").append(";");
 | 
			
		
	
		
			
				
					|  |  |  |  | //                    }
 | 
			
		
	
		
			
				
					|  |  |  |  |                     collectOrderBiz.setThrCode(null); | 
			
		
	
		
			
				
					|  |  |  |  |                     collectOrderBiz.setCpmctymc(null); | 
			
		
	
		
			
				
					|  |  |  |  |                     collectOrderBiz.setGgxh(null); | 
			
		
	
		
			
				
					|  |  |  |  |                     collectOrderBiz.setBatchNo(entity.getBatchNo()); | 
			
		
	
		
			
				
					|  |  |  |  |                     collectOrderBiz.setOrderIdFk(ioCollectOrder.getBillNo()); | 
			
		
	
		
			
				
					|  |  |  |  |                     collectOrderBiz.setCount(entity.getCount()); | 
			
		
	
		
			
				
					|  |  |  |  |                     collectOrderBiz.setMeasureUnit(null); | 
			
		
	
		
			
				
					|  |  |  |  |                     BeanUtil.copyProperties(entity, collectOrderBiz); | 
			
		
	
		
			
				
					|  |  |  |  |                     UdiRelevanceEntity basicUdirelEntity = udiRelevanceDao.selectOne(new LambdaQueryWrapper<UdiRelevanceEntity>().eq(UdiRelevanceEntity::getMainId, entity.getThrCode())); | 
			
		
	
		
			
				
					|  |  |  |  |                     if (basicUdirelEntity != null) { | 
			
		
	
		
			
				
					|  |  |  |  |                         collectOrderBiz.setRelId(basicUdirelEntity.getId()); | 
			
		
	
		
			
				
					|  |  |  |  |                     } else { | 
			
		
	
		
			
				
					|  |  |  |  |                         errorMsg.append(entity.getCpmctymc()).append("字典未对照").append(";"); | 
			
		
	
		
			
				
					|  |  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |  |                     collectOrderBiz.setTagStatus(1); | 
			
		
	
		
			
				
					|  |  |  |  |                     collectOrderBiz.setUnTagCount(0); | 
			
		
	
		
			
				
					|  |  |  |  |                     bizList.add(collectOrderBiz); | 
			
		
	
	
		
			
				
					|  |  |  | 
 |