|
|
|
@ -16,7 +16,9 @@ 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;
|
|
|
|
|
import com.glxp.api.res.trace.TraceSearchReponse;
|
|
|
|
|
import com.glxp.api.service.basic.BasicUdiRelService;
|
|
|
|
|
import com.glxp.api.service.sup.UserCompanyService;
|
|
|
|
|
import com.glxp.api.service.trace.*;
|
|
|
|
|
import com.glxp.api.util.GennerOrderUtils;
|
|
|
|
|
import com.glxp.api.util.udi.FilterUdiUtils;
|
|
|
|
@ -54,6 +56,8 @@ public class UdiTraceController extends BaseController {
|
|
|
|
|
TraceRecordService traceRecordService;
|
|
|
|
|
@Resource
|
|
|
|
|
UdiTraceService udiTraceService;
|
|
|
|
|
@Resource
|
|
|
|
|
UserCompanyService userCompanyService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -65,13 +69,17 @@ public class UdiTraceController extends BaseController {
|
|
|
|
|
@AuthRuleAnnotation("udi/trace/source/search")
|
|
|
|
|
@GetMapping("udi/trace/source/search")
|
|
|
|
|
public BaseResponse createTrace(TraceRecordRequest traceRecordRequest) {
|
|
|
|
|
TraceRecordLogEntity traceRecordLogEntity = null;
|
|
|
|
|
|
|
|
|
|
TraceRecordLogEntity traceRecordLogEntity;
|
|
|
|
|
TraceProductDetailEntity traceProductDetailEntity = null;
|
|
|
|
|
BasicUdiRelResponse basicUdiRelResponse = null;
|
|
|
|
|
UdiEntity udiEntity = null;
|
|
|
|
|
UserCompanyEntity userCompanyEntity = null;
|
|
|
|
|
if (traceRecordRequest.getTraceType() == Constant.UDI_TRACE) {
|
|
|
|
|
|
|
|
|
|
if (StrUtil.isNotEmpty(traceRecordRequest.getUdiCode())) {
|
|
|
|
|
traceRecordRequest.setTraceType(Constant.UDI_TRACE);
|
|
|
|
|
}
|
|
|
|
|
if (traceRecordRequest.getTraceType() == Constant.UDI_TRACE) {
|
|
|
|
|
//1.校验UDI码格式
|
|
|
|
|
udiEntity = FilterUdiUtils.getUdi(traceRecordRequest.getUdiCode());
|
|
|
|
|
if (udiEntity == null) {
|
|
|
|
@ -90,28 +98,18 @@ public class UdiTraceController extends BaseController {
|
|
|
|
|
return ResultVOUtils.error(500, "未查询到产品信息");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//4.生成查询记录
|
|
|
|
|
String userId = getUserId() + "";
|
|
|
|
|
traceRecordLogEntity = traceRecordService.getById(traceRecordRequest.getRecordCode());
|
|
|
|
|
if (traceRecordLogEntity == null)
|
|
|
|
|
traceRecordLogEntity = udiTraceService.createRecordLog(userId, traceRecordRequest.getFromType(), traceRecordRequest.getTraceType());
|
|
|
|
|
traceRecordLogEntity = udiTraceService.createRecordLog(userId, traceRecordRequest.getFromType(), traceRecordRequest.getTraceType());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//5.创建查询详情记录,若存在相同查询记录则直接获取
|
|
|
|
|
if (traceRecordLogEntity.getTraceProductIdFk() != null) {
|
|
|
|
|
traceProductDetailEntity = traceProductDetailService.getById(traceRecordLogEntity.getTraceProductIdFk());
|
|
|
|
|
if (traceProductDetailEntity == null) {
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
traceProductDetailEntity = udiTraceService.createTracerProductByUdiCode(traceRecordRequest.getUdiCode(), 1, 1, basicUdiRelResponse, udiEntity);
|
|
|
|
|
traceRecordLogEntity.setTraceProductIdFk(traceProductDetailEntity.getId());
|
|
|
|
|
traceRecordService.updateById(traceRecordLogEntity);
|
|
|
|
|
udiTraceService.createSourceTraceTask(traceProductDetailEntity, userCompanyEntity.getId());
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
//1:校验参数是否正确
|
|
|
|
|
if (StrUtil.isEmpty(traceRecordRequest.getYlqxzcrbarmc())) {
|
|
|
|
|
return ResultVOUtils.error(500, "医疗器械注册人不能为空!");
|
|
|
|
@ -123,7 +121,6 @@ public class UdiTraceController extends BaseController {
|
|
|
|
|
return ResultVOUtils.error(500, "规格型号不能为空!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//2.查询源头企业
|
|
|
|
|
FilterUdiRelRequest filterUdiRelRequest = new FilterUdiRelRequest();
|
|
|
|
|
filterUdiRelRequest.setYlqxzcrbarmc(traceRecordRequest.getYlqxzcrbarmc());
|
|
|
|
@ -146,12 +143,13 @@ public class UdiTraceController extends BaseController {
|
|
|
|
|
|
|
|
|
|
//5.创建查询详情记录,若存在相同查询记录则直接获取
|
|
|
|
|
traceProductDetailEntity = udiTraceService.createTracerProductByBatchNo(traceRecordRequest, 1, 2, basicUdiRelResponse);
|
|
|
|
|
|
|
|
|
|
traceRecordLogEntity.setTraceProductIdFk(traceProductDetailEntity.getId());
|
|
|
|
|
traceRecordService.updateById(traceRecordLogEntity);
|
|
|
|
|
udiTraceService.createSourceTraceTask(traceProductDetailEntity, userCompanyEntity.getId());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ResultVOUtils.success(traceRecordLogEntity);
|
|
|
|
|
List<TraceOrderEntity> traceOrderEntities = traceOrderService.findByProductIdFk(traceRecordLogEntity.getTraceProductIdFk());
|
|
|
|
|
return ResultVOUtils.success(traceOrderEntities);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -164,14 +162,97 @@ public class UdiTraceController extends BaseController {
|
|
|
|
|
@GetMapping("udi/trace/scene/search")
|
|
|
|
|
public BaseResponse sceneTrace(TraceRecordRequest traceRecordRequest) {
|
|
|
|
|
|
|
|
|
|
TraceSearchReponse traceSearchReponse = new TraceSearchReponse();
|
|
|
|
|
TraceRecordLogEntity traceRecordLogEntity = traceRecordService.getById(traceRecordRequest.getRecordCode());
|
|
|
|
|
if (traceRecordLogEntity != null) {
|
|
|
|
|
List<TraceOrderEntity> traceOrderEntities = traceOrderService.findByProductIdFk(traceRecordLogEntity.getTraceProductIdFk());
|
|
|
|
|
traceSearchReponse.setTraceRecordLogEntity(traceRecordLogEntity);
|
|
|
|
|
traceSearchReponse.setTraceOrderEntities(traceOrderEntities);
|
|
|
|
|
return ResultVOUtils.success(traceSearchReponse);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TraceProductDetailEntity traceProductDetailEntity = null;
|
|
|
|
|
BasicUdiRelResponse basicUdiRelResponse = null;
|
|
|
|
|
UdiEntity udiEntity = null;
|
|
|
|
|
UserCompanyEntity userCompanyEntity = null;
|
|
|
|
|
if (traceRecordRequest.getTraceType() == Constant.UDI_TRACE) {
|
|
|
|
|
|
|
|
|
|
} else if (traceRecordRequest.getTraceType() == Constant.UDI_BATCHNO) {
|
|
|
|
|
//1.校验UDI码格式
|
|
|
|
|
udiEntity = FilterUdiUtils.getUdi(traceRecordRequest.getUdiCode());
|
|
|
|
|
if (udiEntity == null) {
|
|
|
|
|
return ResultVOUtils.error(500, "UDI码格式错误");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//2.查询报备企业
|
|
|
|
|
userCompanyEntity = userCompanyService.getById(traceRecordRequest.getCompanyId());
|
|
|
|
|
if (userCompanyEntity == null) {
|
|
|
|
|
return ResultVOUtils.error(500, "未查询到该报备企业信息!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//3.查询产品信息
|
|
|
|
|
basicUdiRelResponse = basicUdiRelService.findByProductNameCode(udiEntity.getUdi());
|
|
|
|
|
if (basicUdiRelResponse == null) {
|
|
|
|
|
return ResultVOUtils.error(500, "未查询到产品信息");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//4.生成查询记录
|
|
|
|
|
String userId = getUserId() + "";
|
|
|
|
|
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 = udiTraceService.createTracerProductByUdiCode(traceRecordRequest.getUdiCode(), 2, 1, basicUdiRelResponse, udiEntity);
|
|
|
|
|
traceRecordLogEntity.setTraceProductIdFk(traceProductDetailEntity.getId());
|
|
|
|
|
traceRecordService.updateById(traceRecordLogEntity);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
traceProductDetailEntity = udiTraceService.createTracerProductByUdiCode(traceRecordRequest.getUdiCode(), 2, 1, basicUdiRelResponse, udiEntity);
|
|
|
|
|
}
|
|
|
|
|
udiTraceService.createCheckTraceTask(traceProductDetailEntity, userCompanyEntity.getId());
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
return ResultVOUtils.error(500, "请选择查询方式!");
|
|
|
|
|
//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, "规格型号不能为空!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//2.查询源头企业
|
|
|
|
|
FilterUdiRelRequest filterUdiRelRequest = new FilterUdiRelRequest();
|
|
|
|
|
filterUdiRelRequest.setYlqxzcrbarmc(traceRecordRequest.getYlqxzcrbarmc());
|
|
|
|
|
filterUdiRelRequest.setCpmctymc(traceRecordRequest.getCpmctymc());
|
|
|
|
|
filterUdiRelRequest.setGgxh(traceRecordRequest.getGgxh());
|
|
|
|
|
|
|
|
|
|
userCompanyEntity = userCompanyService.getById(traceRecordRequest.getCompanyId());
|
|
|
|
|
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, 2, 2, basicUdiRelResponse);
|
|
|
|
|
udiTraceService.createCheckTraceTask(traceProductDetailEntity, userCompanyEntity.getId());
|
|
|
|
|
}
|
|
|
|
|
return ResultVOUtils.error(500, "查询失败");
|
|
|
|
|
traceSearchReponse.setTraceRecordLogEntity(traceRecordLogEntity);
|
|
|
|
|
return ResultVOUtils.success(traceSearchReponse);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|