|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
package com.glxp.api.controller.trace;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.glxp.api.annotation.AuthRuleAnnotation;
|
|
|
|
|
import com.glxp.api.common.enums.ResultEnum;
|
|
|
|
|
import com.glxp.api.common.res.BaseResponse;
|
|
|
|
@ -10,6 +12,7 @@ import com.glxp.api.controller.BaseController;
|
|
|
|
|
import com.glxp.api.entity.basic.UdiEntity;
|
|
|
|
|
import com.glxp.api.entity.sup.UserCompanyEntity;
|
|
|
|
|
import com.glxp.api.entity.trace.*;
|
|
|
|
|
import com.glxp.api.req.basic.FilterUdiRelRequest;
|
|
|
|
|
import com.glxp.api.req.trace.TraceOrderUploadRequest;
|
|
|
|
|
import com.glxp.api.req.trace.TraceRecordRequest;
|
|
|
|
|
import com.glxp.api.res.basic.BasicUdiRelResponse;
|
|
|
|
@ -36,8 +39,6 @@ import java.util.List;
|
|
|
|
|
public class UdiTraceController extends BaseController {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
TraceRecordService traceRecordService;
|
|
|
|
|
@Resource
|
|
|
|
|
TraceProductDetailService traceProductDetailService;
|
|
|
|
|
@Resource
|
|
|
|
@ -50,6 +51,10 @@ public class UdiTraceController extends BaseController {
|
|
|
|
|
RabbitPushService rabbitPushService;
|
|
|
|
|
@Resource
|
|
|
|
|
TraceOrderService traceOrderService;
|
|
|
|
|
@Resource
|
|
|
|
|
TraceRecordService traceRecordService;
|
|
|
|
|
@Resource
|
|
|
|
|
UdiTraceService udiTraceService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -61,116 +66,104 @@ public class UdiTraceController extends BaseController {
|
|
|
|
|
@AuthRuleAnnotation("udi/trace/source/search")
|
|
|
|
|
@GetMapping("udi/trace/source/search")
|
|
|
|
|
public BaseResponse createTrace(TraceRecordRequest traceRecordRequest) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TraceRecordLogEntity traceRecordLogEntity = null;
|
|
|
|
|
TraceProductDetailEntity traceProductDetailEntity = null;
|
|
|
|
|
BasicUdiRelResponse basicUdiRelResponse = null;
|
|
|
|
|
UdiEntity udiEntity = null;
|
|
|
|
|
UserCompanyEntity userCompanyEntity = null;
|
|
|
|
|
if (traceRecordRequest.getTraceType() == Constant.UDI_TRACE) {
|
|
|
|
|
|
|
|
|
|
//1.校验UDI码格式
|
|
|
|
|
UdiEntity udiEntity = FilterUdiUtils.getUdi(traceRecordRequest.getUdiCode());
|
|
|
|
|
udiEntity = FilterUdiUtils.getUdi(traceRecordRequest.getUdiCode());
|
|
|
|
|
if (udiEntity == null) {
|
|
|
|
|
return ResultVOUtils.error(500, "UDI码格式错误");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//2.查询源头企业
|
|
|
|
|
UserCompanyEntity userCompanyEntity = basicUdiRelService.findByNameCode(udiEntity.getUdi());
|
|
|
|
|
userCompanyEntity = basicUdiRelService.findByNameCode(udiEntity.getUdi());
|
|
|
|
|
if (userCompanyEntity == null) {
|
|
|
|
|
return ResultVOUtils.error(500, "生产企业未关联该产品信息!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//3.查询产品信息
|
|
|
|
|
BasicUdiRelResponse basicUdiRelResponse = basicUdiRelService.findByProductNameCode(traceRecordRequest.getNameCode());
|
|
|
|
|
basicUdiRelResponse = basicUdiRelService.findByProductNameCode(udiEntity.getUdi());
|
|
|
|
|
if (basicUdiRelResponse == null) {
|
|
|
|
|
return ResultVOUtils.error(500, "未查询到产品信息");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//4.生成查询记录
|
|
|
|
|
String userId = getUserId() + "";
|
|
|
|
|
TraceRecordLogEntity traceRecordLogEntity = new TraceRecordLogEntity();
|
|
|
|
|
traceRecordLogEntity.setId(IdUtil.getSnowflakeNextId());
|
|
|
|
|
traceRecordLogEntity.setRecordCode(gennerOrderUtils.getRecordNo());
|
|
|
|
|
traceRecordLogEntity.setCreateTime(new Date());
|
|
|
|
|
traceRecordLogEntity.setUpdateTime(new Date());
|
|
|
|
|
traceRecordLogEntity.setStatus(1);
|
|
|
|
|
traceRecordLogEntity.setCreateUser(userId);
|
|
|
|
|
traceRecordLogEntity.setFromType(traceRecordRequest.getFromType());
|
|
|
|
|
traceRecordLogEntity.setTraceType(traceRecordRequest.getTraceType());
|
|
|
|
|
|
|
|
|
|
//4.创建查询详情记录,若存在相同查询记录则直接获取
|
|
|
|
|
TraceProductDetailEntity traceProductDetailEntity = null;
|
|
|
|
|
if (traceRecordRequest.getTraceType() == 1) {//按UDI码查询
|
|
|
|
|
traceProductDetailEntity = traceProductDetailService.findUniqueByCode(1, traceRecordRequest.getUdiCode());
|
|
|
|
|
if (traceProductDetailEntity == null) {
|
|
|
|
|
traceProductDetailEntity.setId(IdUtil.getSnowflakeNextId());
|
|
|
|
|
traceProductDetailEntity.setTraceSource(1);
|
|
|
|
|
traceProductDetailEntity.setTraceType(traceRecordRequest.getTraceType());
|
|
|
|
|
traceProductDetailEntity.setUdiCode(traceRecordRequest.getUdiCode());
|
|
|
|
|
traceProductDetailEntity.setYlqxzcrbarmc(basicUdiRelResponse.getYlqxzcrbarmc());
|
|
|
|
|
traceProductDetailEntity.setCreditNum(basicUdiRelResponse.getTyshxydm());
|
|
|
|
|
traceProductDetailEntity.setCpmctymc(basicUdiRelResponse.getCpmctymc());
|
|
|
|
|
traceProductDetailEntity.setGgxh(basicUdiRelResponse.getGgxh());
|
|
|
|
|
traceProductDetailEntity.setNameCode(basicUdiRelResponse.getNameCode());
|
|
|
|
|
traceProductDetailEntity.setBatchNo(udiEntity.getBatchNo());
|
|
|
|
|
traceProductDetailEntity.setProduceDate(udiEntity.getProduceDate());
|
|
|
|
|
traceProductDetailEntity.setExpireDate(udiEntity.getExpireDate());
|
|
|
|
|
traceProductDetailEntity.setSerialNo(udiEntity.getSerialNo());
|
|
|
|
|
traceProductDetailEntity.setStatus(1);
|
|
|
|
|
traceProductDetailService.save(traceProductDetailEntity);
|
|
|
|
|
}
|
|
|
|
|
} else { //按批次号查询
|
|
|
|
|
traceProductDetailEntity = traceProductDetailService.findUniqueByData(1, traceRecordRequest.getYlqxzcrbarmc(),
|
|
|
|
|
traceRecordRequest.getCpmctymc(), traceRecordRequest.getGgxh(), traceRecordRequest.getNameCode(), traceRecordRequest.getBatchNo());
|
|
|
|
|
traceRecordLogEntity = traceRecordService.getById(traceRecordRequest.getRecordCode());
|
|
|
|
|
if (traceRecordLogEntity == null)
|
|
|
|
|
traceRecordLogEntity = udiTraceService.createRecordLog(userId, traceRecordRequest.getFromType(), traceRecordRequest.getTraceType());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//5.创建查询详情记录,若存在相同查询记录则直接获取
|
|
|
|
|
if (traceRecordLogEntity.getTraceProductIdFk() != null) {
|
|
|
|
|
traceProductDetailEntity = traceProductDetailService.getById(traceRecordLogEntity.getTraceProductIdFk());
|
|
|
|
|
if (traceProductDetailEntity == null) {
|
|
|
|
|
traceProductDetailEntity.setId(IdUtil.getSnowflakeNextId());
|
|
|
|
|
traceProductDetailEntity.setTraceSource(1);
|
|
|
|
|
traceProductDetailEntity.setTraceType(traceRecordRequest.getTraceType());
|
|
|
|
|
traceProductDetailEntity.setYlqxzcrbarmc(basicUdiRelResponse.getYlqxzcrbarmc());
|
|
|
|
|
traceProductDetailEntity.setCreditNum(basicUdiRelResponse.getTyshxydm());
|
|
|
|
|
traceProductDetailEntity.setCpmctymc(basicUdiRelResponse.getCpmctymc());
|
|
|
|
|
traceProductDetailEntity.setGgxh(basicUdiRelResponse.getGgxh());
|
|
|
|
|
traceProductDetailEntity.setNameCode(basicUdiRelResponse.getNameCode());
|
|
|
|
|
traceProductDetailEntity.setBatchNo(traceRecordRequest.getBatchNo());
|
|
|
|
|
traceProductDetailEntity.setStatus(1);
|
|
|
|
|
traceProductDetailService.save(traceProductDetailEntity);
|
|
|
|
|
traceProductDetailEntity = udiTraceService.createTracerProductByUdiCode(traceRecordRequest.getUdiCode(), 1, 1, basicUdiRelResponse, udiEntity);
|
|
|
|
|
traceRecordLogEntity.setTraceProductIdFk(traceProductDetailEntity.getId());
|
|
|
|
|
traceRecordService.updateById(traceRecordLogEntity);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
traceProductDetailEntity = udiTraceService.createTracerProductByUdiCode(traceRecordRequest.getUdiCode(), 1, 1, basicUdiRelResponse, udiEntity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
//1:校验参数是否正确
|
|
|
|
|
if (StrUtil.isEmpty(traceRecordRequest.getYlqxzcrbarmc())) {
|
|
|
|
|
return ResultVOUtils.error(500, "医疗器械注册人不能为空!");
|
|
|
|
|
}
|
|
|
|
|
if (StrUtil.isEmpty(traceRecordRequest.getCpmctymc())) {
|
|
|
|
|
return ResultVOUtils.error(500, "产品通用名称不能为空!");
|
|
|
|
|
}
|
|
|
|
|
if (StrUtil.isEmpty(traceRecordRequest.getGgxh())) {
|
|
|
|
|
return ResultVOUtils.error(500, "规格型号不能为空!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//5.创建查询任务表
|
|
|
|
|
TraceTaskNoticeEntity traceTaskNoticeEntity = new TraceTaskNoticeEntity();
|
|
|
|
|
traceTaskNoticeEntity.setId(IdUtil.getSnowflakeNextId());
|
|
|
|
|
traceTaskNoticeEntity.setRecordCode(traceRecordLogEntity.getId());
|
|
|
|
|
traceTaskNoticeEntity.setTaskType(1);
|
|
|
|
|
traceTaskNoticeEntity.setStatus(1);
|
|
|
|
|
traceTaskNoticeEntity.setCompanyIdFk(basicUdiRelResponse.getCompanyIdFk());
|
|
|
|
|
traceTaskNoticeEntity.setYlqxzcrbarmc(basicUdiRelResponse.getYlqxzcrbarmc());
|
|
|
|
|
traceTaskNoticeEntity.setCreditNum(basicUdiRelResponse.getTyshxydm());
|
|
|
|
|
traceTaskNoticeEntity.setCpmctymc(basicUdiRelResponse.getCpmctymc());
|
|
|
|
|
traceTaskNoticeEntity.setGgxh(basicUdiRelResponse.getGgxh());
|
|
|
|
|
traceTaskNoticeEntity.setBatchNo(udiEntity.getBatchNo());
|
|
|
|
|
traceTaskNoticeEntity.setProduceDate(udiEntity.getProduceDate());
|
|
|
|
|
traceTaskNoticeEntity.setExpireDate(udiEntity.getExpireDate());
|
|
|
|
|
traceTaskNoticeEntity.setSerialNo(udiEntity.getSerialNo());
|
|
|
|
|
traceTaskNoticeEntity.setCreateTime(new Date());
|
|
|
|
|
List<String> diList = basicUdiRelService.getBaseMapper().findDiList(basicUdiRelResponse.getUuid());
|
|
|
|
|
traceTaskNoticeEntity.setDiList(diList);
|
|
|
|
|
traceTaskNoticeEntity.setTaskType(1);
|
|
|
|
|
traceTaskNoticeService.save(traceTaskNoticeEntity);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//6.构建MQ推送消息
|
|
|
|
|
MqTraceMessage mqTraceMessage = new MqTraceMessage();
|
|
|
|
|
mqTraceMessage.setCreateTime(new Date());
|
|
|
|
|
mqTraceMessage.setTaskType(1);
|
|
|
|
|
mqTraceMessage.setCompanyId(basicUdiRelResponse.getCompanyIdFk());
|
|
|
|
|
mqTraceMessage.setCerditNo(userCompanyEntity.getCreditNum());
|
|
|
|
|
rabbitPushService.send(mqTraceMessage);
|
|
|
|
|
|
|
|
|
|
return ResultVOUtils.success("创建查询成功,请稍后刷新查看查询结果!");
|
|
|
|
|
//2.查询源头企业
|
|
|
|
|
FilterUdiRelRequest filterUdiRelRequest = new FilterUdiRelRequest();
|
|
|
|
|
filterUdiRelRequest.setYlqxzcrbarmc(traceRecordRequest.getYlqxzcrbarmc());
|
|
|
|
|
filterUdiRelRequest.setCpmctymc(traceRecordRequest.getCpmctymc());
|
|
|
|
|
filterUdiRelRequest.setGgxh(traceRecordRequest.getGgxh());
|
|
|
|
|
userCompanyEntity = basicUdiRelService.findByProduct(filterUdiRelRequest);
|
|
|
|
|
if (userCompanyEntity == null) {
|
|
|
|
|
return ResultVOUtils.error(500, "生产企业未关联该产品信息!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//3.查询产品信息
|
|
|
|
|
basicUdiRelResponse = basicUdiRelService.findByProductName(filterUdiRelRequest);
|
|
|
|
|
if (basicUdiRelResponse == null) {
|
|
|
|
|
return ResultVOUtils.error(500, "未查询到产品信息");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//4.生成查询记录
|
|
|
|
|
String userId = getUserId() + "";
|
|
|
|
|
traceRecordLogEntity = udiTraceService.createRecordLog(userId, traceRecordRequest.getFromType(), traceRecordRequest.getTraceType());
|
|
|
|
|
|
|
|
|
|
//5.创建查询详情记录,若存在相同查询记录则直接获取
|
|
|
|
|
traceProductDetailEntity = udiTraceService.createTracerProductByBatchNo(traceRecordRequest, 1, 2, basicUdiRelResponse);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultVOUtils.error(500, "查询失败");
|
|
|
|
|
}
|
|
|
|
|
//5.创建查询任务表
|
|
|
|
|
TraceTaskNoticeEntity traceTaskNoticeEntity = udiTraceService.createTraceNotice(1, traceProductDetailEntity, basicUdiRelResponse, udiEntity);
|
|
|
|
|
|
|
|
|
|
//6.构建MQ推送消息
|
|
|
|
|
MqTraceMessage mqTraceMessage = new MqTraceMessage();
|
|
|
|
|
mqTraceMessage.setCreateTime(new Date());
|
|
|
|
|
mqTraceMessage.setTaskType(1);
|
|
|
|
|
mqTraceMessage.setCompanyId(basicUdiRelResponse.getCompanyIdFk());
|
|
|
|
|
mqTraceMessage.setCerditNo(userCompanyEntity.getCreditNum());
|
|
|
|
|
mqTraceMessage.setTaskId(traceTaskNoticeEntity.getId());
|
|
|
|
|
rabbitPushService.send(mqTraceMessage);
|
|
|
|
|
|
|
|
|
|
return ResultVOUtils.success(traceRecordLogEntity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 现场检查查询
|
|
|
|
|