关联关系优化

dev_drug
qiuyt 2 months ago
parent 52787a7080
commit a131d5a734

@ -21,6 +21,7 @@ import com.glxp.api.dao.inout.IoCodeTempDao;
import com.glxp.api.entity.auth.AuthAdmin; import com.glxp.api.entity.auth.AuthAdmin;
import com.glxp.api.entity.basic.BasicBussinessTypeEntity; import com.glxp.api.entity.basic.BasicBussinessTypeEntity;
import com.glxp.api.entity.basic.EntrustReceEntity; import com.glxp.api.entity.basic.EntrustReceEntity;
import com.glxp.api.entity.collect.RelCodeBatch;
import com.glxp.api.entity.inout.*; import com.glxp.api.entity.inout.*;
import com.glxp.api.entity.system.SystemParamConfigEntity; import com.glxp.api.entity.system.SystemParamConfigEntity;
import com.glxp.api.req.alihealth.AlihealthYljgSinglerelationReqeust; import com.glxp.api.req.alihealth.AlihealthYljgSinglerelationReqeust;
@ -47,8 +48,10 @@ import com.glxp.api.service.sync.SpsSyncDownloadService;
import com.glxp.api.service.system.SystemParamConfigService; import com.glxp.api.service.system.SystemParamConfigService;
import com.glxp.api.util.*; import com.glxp.api.util.*;
import com.glxp.api.util.alihealth.AlihealthYljgUtils; import com.glxp.api.util.alihealth.AlihealthYljgUtils;
import com.glxp.api.util.redis.RedisDelayedQueue;
import com.glxp.api.util.udi.UdiCalCountUtil; import com.glxp.api.util.udi.UdiCalCountUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@ -129,13 +132,14 @@ public class IoOrderReviewController extends BaseController {
private RelCodeDetailService relCodeDetailService; private RelCodeDetailService relCodeDetailService;
@Resource @Resource
private IoCodeDao ioCodeDao; private IoCodeDao ioCodeDao;
//前端二次审核 //前端二次审核
@AuthRuleAnnotation("") @AuthRuleAnnotation("")
@PostMapping("/spms/inout/order/web/updateStatus") @PostMapping("/spms/inout/order/web/updateStatus")
@Log(title = "单据管理", businessType = BusinessType.UPDATE) @Log(title = "单据管理", businessType = BusinessType.UPDATE)
public BaseResponse webUpdateStatus(@RequestBody ReviewFinishRequest updateExportStatusRequest, public BaseResponse webUpdateStatus(@RequestBody ReviewFinishRequest updateExportStatusRequest,
BindingResult bindingResult) { BindingResult bindingResult) {
log.error("单据审核进来了==="+updateExportStatusRequest); log.error("单据审核进来了===" + updateExportStatusRequest);
if (bindingResult.hasErrors()) { if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
} }
@ -144,13 +148,13 @@ public class IoOrderReviewController extends BaseController {
return ResultVOUtils.error(500, "未找到该业务单据"); return ResultVOUtils.error(500, "未找到该业务单据");
} }
if (orderEntity.getStatus() == ConstantStatus.ORDER_STATUS_CHECK_REW) { if (orderEntity.getStatus() == ConstantStatus.ORDER_STATUS_CHECK_REW) {
BaseResponse baseResponse = updateReview(getUser(), orderEntity); BaseResponse baseResponse = updateReview(getUser(), orderEntity);
log.error("单据审核进来了===orderEntity===="+orderEntity); log.error("单据审核进来了===orderEntity====" + orderEntity);
if(baseResponse.getCode() == 20000) { if (baseResponse.getCode() == 20000) {
//todo 审核通过上传关联关系 //todo 审核通过上传关联关系
BasicBussinessTypeEntity businessType = basicBussinessTypeService.findByAction(orderEntity.getAction()); BasicBussinessTypeEntity businessType = basicBussinessTypeService.findByAction(orderEntity.getAction());
log.error("单据审核进来了===businessType===="+businessType); log.error("单据审核进来了===businessType====" + businessType);
if (businessType.getCorpType() == ConstantStatus.CORP_SP && businessType.getMainAction().equals(ConstantType.TYPE_PUT) && businessType.getProductType() == 2) { if (businessType.getCorpType() == ConstantStatus.CORP_SP && businessType.getMainAction().equals(ConstantType.TYPE_PUT) && businessType.getProductType() == 2) {
aliBillsDispose(orderEntity); aliBillsDispose(orderEntity);
@ -165,9 +169,6 @@ public class IoOrderReviewController extends BaseController {
} }
} }
//前端第三次验收 //前端第三次验收
@ -463,8 +464,14 @@ public class IoOrderReviewController extends BaseController {
ioCheckInoutService.checkThird(orderEntity); ioCheckInoutService.checkThird(orderEntity);
return ResultVOUtils.success("更新成功"); return ResultVOUtils.success("更新成功");
} }
@Value("${REL_CODE_DELAY_SECONDS:7200}")
private Integer relCodeDelaySeconds;
@Resource
private RedisDelayedQueue redisDelayedQueue;
// 异步处理阿里单据 // 异步处理阿里单据
public BaseResponse aliBillsDispose( IoOrderEntity orderEntity) { public BaseResponse aliBillsDispose(IoOrderEntity orderEntity) {
ThreadUtil.execAsync(() -> { ThreadUtil.execAsync(() -> {
//1.上传入库单 //1.上传入库单
AlihealthYljgUploadinoutbillReqeust alihealthYljgUploadinoutbillReqeust = new AlihealthYljgUploadinoutbillReqeust(); AlihealthYljgUploadinoutbillReqeust alihealthYljgUploadinoutbillReqeust = new AlihealthYljgUploadinoutbillReqeust();
@ -475,40 +482,34 @@ public class IoOrderReviewController extends BaseController {
alihealthYljgUploadinoutbillReqeust.setPhysic_type(3); alihealthYljgUploadinoutbillReqeust.setPhysic_type(3);
alihealthYljgUploadinoutbillReqeust.setClient_type("2"); alihealthYljgUploadinoutbillReqeust.setClient_type("2");
// 查询改单据传的码 // 查询改单据传的码
List<IoCodeEntity> ioCodeEntityList = ioCodeDao.selectList(new QueryWrapper<IoCodeEntity>().eq("orderId", orderEntity.getBillNo())); List<IoCodeEntity> ioCodeEntityList = ioCodeDao.selectList(new QueryWrapper<IoCodeEntity>().eq("orderId", orderEntity.getBillNo()));
if(ioCodeEntityList!=null && ioCodeEntityList.size() >0){ if (ioCodeEntityList != null && ioCodeEntityList.size() > 0) {
List<String> codeList = new ArrayList<>(); List<String> codeList = new ArrayList<>();
for (IoCodeEntity ioCodeEntity : ioCodeEntityList) { for (IoCodeEntity ioCodeEntity : ioCodeEntityList) {
codeList.add(ioCodeEntity.getCode()); codeList.add(ioCodeEntity.getCode());
} }
Set<String> set = new HashSet<>(codeList); Set<String> set = new HashSet<>(codeList);
alihealthYljgUploadinoutbillReqeust.setTrace_codes(String.join(",", codeList));
alihealthYljgUploadinoutbillReqeust.setTrace_codes( String.join(",", codeList));
// 单据上传先注释了 // 单据上传先注释了
// BaseResponse baseResponseUploadinoutbill = alihealthYljgUtils.yljgUploadinoutbill(alihealthYljgUploadinoutbillReqeust,orderEntity.getFromCorp()); // BaseResponse baseResponseUploadinoutbill = alihealthYljgUtils.yljgUploadinoutbill(alihealthYljgUploadinoutbillReqeust,orderEntity.getFromCorp());
// if(baseResponseUploadinoutbill.getCode() == 20000){ log.error("要查询阿里关联关系的码===" + set);
// try { String erpId = orderEntity.getFromCorp();
// Thread.sleep(1000); for (String code : set) {
log.error("要查询阿里关联关系的码==="+set); relCodeBatchService.addRelCodeAli(code, orderEntity.getFromCorp());
relCodeBatchService.addRelCodeAli(set, orderEntity.getFromCorp()); RelCodeBatch relCodeBatch = relCodeBatchService.getOne(
new QueryWrapper<RelCodeBatch>().eq("curCode", code)
);
if (Objects.isNull(relCodeBatch)) {
// redisDelayedQueue.addTaskToQueue(code + "&&&" + erpId, relCodeDelaySeconds, "rel_code_queue");
// } catch (InterruptedException e) { } else {
// } log.error("有关联关系了此码===" + code);
}
// }else { }
// log.error("阿里调用上传单据失败==="+baseResponseUploadinoutbill.getMessage());
//
// }
} }
}); });
return ResultVOUtils.success("更新成功"); return ResultVOUtils.success("更新成功");
} }
@Resource @Resource
SpsSyncDownloadService spsSyncDownloadService; SpsSyncDownloadService spsSyncDownloadService;

@ -83,6 +83,7 @@ public class RelCodeBatchService extends ServiceImpl<RelCodeBatchMapper, RelCode
private CustomerInfoService customerInfoService; private CustomerInfoService customerInfoService;
@Resource @Resource
private RelCodeBatchService relCodeBatchService; private RelCodeBatchService relCodeBatchService;
/** /**
* *
* *
@ -701,92 +702,64 @@ public class RelCodeBatchService extends ServiceImpl<RelCodeBatchMapper, RelCode
} }
return; return;
} }
@Resource @Resource
private AlihealthYljgUtils alihealthYljgUtils; private AlihealthYljgUtils alihealthYljgUtils;
@Resource @Resource
private RedisDelayedQueue redisDelayedQueue; private RedisDelayedQueue redisDelayedQueue;
@Resource
@Value("${REL_CODE_DELAY_SECONDS:7200}")
private Integer relCodeDelaySeconds;
// 处理阿里新增关联关系
public void addRelCodeAli(Set<String> set, String erpId){
try {
//2.下载关联关系存到关联关系表
for (String code : set) {
AlihealthYljgSinglerelationReqeust alihealthYljgSinglerelationReqeust = new AlihealthYljgSinglerelationReqeust();
alihealthYljgSinglerelationReqeust.setCode(code);
BaseResponse<AlihealthYljgSinglerelationResponse> baseResponse = alihealthYljgUtils.relCodeInsert(alihealthYljgSinglerelationReqeust);
if (baseResponse.getCode() == 20000) {
AlihealthYljgSinglerelationResponse alihealthKytSinglerelationResponse = baseResponse.getData();
// 返回的码关联关系进行插入
List<RelCodeBatch> batchList = alihealthKytSinglerelationResponse.disposeRelCodeBatch(erpId,code);
for (RelCodeBatch relCodeBatch : batchList) {
RelCodeBatch relCodeBatchOne = relCodeBatchService.getOne(new QueryWrapper<RelCodeBatch>().eq("curCode", relCodeBatch.getCurCode())
.last("limit 1")
);
if (Objects.isNull(relCodeBatchOne)) {
relCodeBatch.setCreateUser(erpId);
relCodeBatch.setCreateTime(new Date());
relCodeBatchService.save(relCodeBatch);
} else { // 处理阿里新增关联关系
if(relCodeBatchOne.getOneLevelCount()!=null){ public void addRelCodeAli(String code, String erpId) {
relCodeBatch.setOneLevelCount(relCodeBatchOne.getOneLevelCount() +relCodeBatch.getOneLevelCount() ); //2.下载关联关系存到关联关系表
} AlihealthYljgSinglerelationReqeust alihealthYljgSinglerelationReqeust = new AlihealthYljgSinglerelationReqeust();
if(relCodeBatchOne.getTwoLevelCount()!=null){ alihealthYljgSinglerelationReqeust.setCode(code);
relCodeBatch.setTwoLevelCount(relCodeBatchOne.getTwoLevelCount() +relCodeBatch.getTwoLevelCount() ); BaseResponse<AlihealthYljgSinglerelationResponse> baseResponse = alihealthYljgUtils.relCodeInsert(alihealthYljgSinglerelationReqeust);
} if (baseResponse.getCode() == 20000) {
if(relCodeBatchOne.getThreeLevelCount()!=null){ AlihealthYljgSinglerelationResponse alihealthKytSinglerelationResponse = baseResponse.getData();
relCodeBatch.setThreeLevelCount(relCodeBatchOne.getThreeLevelCount() +relCodeBatch.getThreeLevelCount() ); // 返回的码关联关系进行插入
} List<RelCodeBatch> batchList = alihealthKytSinglerelationResponse.disposeRelCodeBatch(erpId, code);
relCodeBatchService.update(relCodeBatch, new QueryWrapper<RelCodeBatch>().eq("curCode", relCodeBatch.getCurCode())); for (RelCodeBatch relCodeBatch : batchList) {
} RelCodeBatch relCodeBatchOne = relCodeBatchService.getOne(new QueryWrapper<RelCodeBatch>().eq("curCode", relCodeBatch.getCurCode())
relCodeBatchOne = relCodeBatchService.getOne(new QueryWrapper<RelCodeBatch>().eq("curCode", relCodeBatch.getCurCode())); .last("limit 1")
);
if (Objects.isNull(relCodeBatchOne)) {
relCodeBatch.setCreateUser(erpId);
relCodeBatch.setCreateTime(new Date());
relCodeBatchService.save(relCodeBatch);
Integer id = relCodeBatchOne.getId(); } else {
if (relCodeBatchOne.getOneLevelCount() != null) {
relCodeBatch.setOneLevelCount(relCodeBatchOne.getOneLevelCount() + relCodeBatch.getOneLevelCount());
}
if (relCodeBatchOne.getTwoLevelCount() != null) {
relCodeBatch.setTwoLevelCount(relCodeBatchOne.getTwoLevelCount() + relCodeBatch.getTwoLevelCount());
}
if (relCodeBatchOne.getThreeLevelCount() != null) {
relCodeBatch.setThreeLevelCount(relCodeBatchOne.getThreeLevelCount() + relCodeBatch.getThreeLevelCount());
}
relCodeBatchService.update(relCodeBatch, new QueryWrapper<RelCodeBatch>().eq("curCode", relCodeBatch.getCurCode()));
}
relCodeBatchOne = relCodeBatchService.getOne(new QueryWrapper<RelCodeBatch>().eq("curCode", relCodeBatch.getCurCode()));
// 进行查询 Integer id = relCodeBatchOne.getId();
List<RelCodeDetail> list = alihealthKytSinglerelationResponse.disposeRelRodeDetailList(id,relCodeBatch.getCurCode());
if (list != null && list.size() > 0) {
List curCodeList = new ArrayList();
for (RelCodeDetail relCodeDetail : list) {
curCodeList.add(relCodeDetail.getCurCode());
}
relCodeDetailService.remove(new QueryWrapper<RelCodeDetail>().in("curCode", curCodeList));
relCodeDetailService.saveBatch(list); // 进行查询
} List<RelCodeDetail> list = alihealthKytSinglerelationResponse.disposeRelRodeDetailList(id, relCodeBatch.getCurCode());
if (list != null && list.size() > 0) {
List curCodeList = new ArrayList();
for (RelCodeDetail relCodeDetail : list) {
curCodeList.add(relCodeDetail.getCurCode());
} }
relCodeDetailService.remove(new QueryWrapper<RelCodeDetail>().in("curCode", curCodeList));
} else { relCodeDetailService.saveBatch(list);
log.error("阿里调用码关联关系失败==="+baseResponse.getMessage());
}
RelCodeBatch relCodeBatch = relCodeBatchService.getOne(
new QueryWrapper<RelCodeBatch>().eq("curCode",code)
);
if(Objects.isNull(relCodeBatch)){
redisDelayedQueue.addTaskToQueue(code+"&&&"+erpId,relCodeDelaySeconds,"rel_code_queue");
}else {
log.error("有关联关系了此码==="+code);
} }
} }
}catch (Exception E){
E.printStackTrace();
}
// 父级编码
// if(relCodeBatchList!=null && relCodeBatchList.size() >0){
// List<RelCodeDetail> list = relCodeDetailService.list(
// new QueryWrapper<RelCodeDetail>().in("curCode",relCodeBatchList)
// );
// if(list!=null && list.size() >0){
// RelCodeBatch relCodeBatch =new RelCodeBatch();
// relCodeBatchService.update(relCodeBatch, new QueryWrapper<RelCodeBatch>().eq("productCode", relCodeBatch.getProductCode()));
//
// }
// }
} else {
log.error("阿里调用码关联关系失败===" + baseResponse.getMessage());
}
} }

@ -80,74 +80,19 @@ public class AliRelCodeDetailTask implements SchedulingConfigurer {
Iterator<Tuple> iterator = tasksToProcess.iterator(); Iterator<Tuple> iterator = tasksToProcess.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
Tuple task = iterator.next(); Tuple task = iterator.next();
String taskId = task.getElement(); String taskId = task.getElement();
String[] codes = taskId.split("&&&"); String[] codes = taskId.split("&&&");
if (codes!=null && codes.length>0) { if (codes!=null && codes.length>0) {
// List<String> relCodeBatchList =new ArrayList<>();
String code = codes[0]; String code = codes[0];
String erpId = codes[1]; String erpId = codes[1];
log.error("关联关系下载任务ID===" + code); log.error("关联关系下载任务ID===" + code);
// 处理阿里关联关系
// 执行任务逻辑 (你可以在这里调用实际的业务逻辑) relCodeBatchService.addRelCodeAli(code,erpId);
AlihealthYljgSinglerelationReqeust alihealthYljgSinglerelationReqeust = new AlihealthYljgSinglerelationReqeust();
alihealthYljgSinglerelationReqeust.setCode(code);
BaseResponse<AlihealthYljgSinglerelationResponse> baseResponse = alihealthYljgUtils.relCodeInsert(alihealthYljgSinglerelationReqeust);
if (baseResponse.getCode() == 20000) {
AlihealthYljgSinglerelationResponse alihealthKytSinglerelationResponse = baseResponse.getData();
// 返回的码关联关系进行插入
List<RelCodeBatch> batchList = alihealthKytSinglerelationResponse.disposeRelCodeBatch(erpId,code);
for (RelCodeBatch relCodeBatch : batchList) {
RelCodeBatch relCodeBatchOne = relCodeBatchService.getOne(new QueryWrapper<RelCodeBatch>().eq("curCode", relCodeBatch.getCurCode())
.last("limit 1")
);
if (Objects.isNull(relCodeBatchOne)) {
relCodeBatch.setCreateUser(erpId);
relCodeBatch.setCreateTime(new Date());
relCodeBatchService.save(relCodeBatch);
} else {
if(relCodeBatchOne.getOneLevelCount()!=null){
relCodeBatch.setOneLevelCount(relCodeBatchOne.getOneLevelCount() +relCodeBatch.getOneLevelCount() );
}
if(relCodeBatchOne.getTwoLevelCount()!=null){
relCodeBatch.setTwoLevelCount(relCodeBatchOne.getTwoLevelCount() +relCodeBatch.getTwoLevelCount() );
}
if(relCodeBatchOne.getThreeLevelCount()!=null){
relCodeBatch.setThreeLevelCount(relCodeBatchOne.getThreeLevelCount() +relCodeBatch.getThreeLevelCount() );
}
relCodeBatchService.update(relCodeBatch, new QueryWrapper<RelCodeBatch>().eq("curCode", relCodeBatch.getCurCode()));
}
relCodeBatchOne = relCodeBatchService.getOne(new QueryWrapper<RelCodeBatch>().eq("curCode", relCodeBatch.getCurCode()));
Integer id = relCodeBatchOne.getId();
// relCodeBatchList.add(relCodeBatchOne.getCurCode());
// 进行查询
List<RelCodeDetail> list = alihealthKytSinglerelationResponse.disposeRelRodeDetailList(id,relCodeBatch.getCurCode());
if (list != null && list.size() > 0) {
List curCodeList = new ArrayList();
for (RelCodeDetail relCodeDetail : list) {
curCodeList.add(relCodeDetail.getCurCode());
}
relCodeDetailService.remove(new QueryWrapper<RelCodeDetail>().in("curCode", curCodeList));
relCodeDetailService.saveBatch(list);
}
}
} else {
log.error("阿里调用码关联关系失败==="+baseResponse.getMessage());
}
} }
// 从队列中删除已执行的任务 // 从队列中删除已执行的任务
redisDelayedQueue.getJedis().zrem("rel_code_queue", taskId); redisDelayedQueue.getJedis().zrem("rel_code_queue", taskId);
log.error("关联关系下载删除任务ID " + taskId + " removed from queue."); log.error("关联关系下载删除任务ID " + taskId + " removed from queue.");
} }
} }

Loading…
Cancel
Save