You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
udi-cpt-java/src/main/java/com/glxp/api/controller/trace/UdiTraceController.java

303 lines
14 KiB
Java

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;
2 years ago
import com.glxp.api.annotation.AuthRuleAnnotation;
import com.glxp.api.common.enums.ResultEnum;
2 years ago
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import com.glxp.api.constant.Constant;
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;
2 years ago
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;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.BindingResult;
2 years ago
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
2 years ago
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
2 years ago
@ApiIgnore
@RestController
@Slf4j
public class UdiTraceController extends BaseController {
2 years ago
@Resource
TraceProductDetailService traceProductDetailService;
@Resource
BasicUdiRelService basicUdiRelService;
@Resource
GennerOrderUtils gennerOrderUtils;
@Resource
TraceTaskNoticeService traceTaskNoticeService;
2 years ago
@Resource
TraceOrderService traceOrderService;
@Resource
TraceRecordService traceRecordService;
@Resource
UdiTraceService udiTraceService;
@Resource
UserCompanyService userCompanyService;
2 years ago
/**
*
*
* @param traceRecordRequest
* @return
*/
@AuthRuleAnnotation("udi/trace/source/search")
@GetMapping("udi/trace/source/search")
public BaseResponse createTrace(TraceRecordRequest traceRecordRequest) {
TraceRecordLogEntity traceRecordLogEntity;
TraceProductDetailEntity traceProductDetailEntity = null;
BasicUdiRelResponse basicUdiRelResponse = null;
UdiEntity udiEntity = null;
UserCompanyEntity userCompanyEntity = null;
2 years ago
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) {
return ResultVOUtils.error(500, "UDI码格式错误");
}
//2.查询源头企业
userCompanyEntity = basicUdiRelService.findByNameCode(udiEntity.getUdi());
if (userCompanyEntity == null) {
return ResultVOUtils.error(500, "生产企业未关联该产品信息!");
}
//3.查询产品信息
basicUdiRelResponse = basicUdiRelService.findByProductNameCode(udiEntity.getUdi());
if (basicUdiRelResponse == null) {
return ResultVOUtils.error(500, "未查询到产品信息");
}
//4.生成查询记录
String userId = getUserId() + "";
traceRecordLogEntity = udiTraceService.createRecordLog(userId, traceRecordRequest.getFromType(), traceRecordRequest.getTraceType());
//5.创建查询详情记录,若存在相同查询记录则直接获取
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, "医疗器械注册人不能为空!");
}
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 = 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);
traceRecordLogEntity.setTraceProductIdFk(traceProductDetailEntity.getId());
traceRecordService.updateById(traceRecordLogEntity);
udiTraceService.createSourceTraceTask(traceProductDetailEntity, userCompanyEntity.getId());
2 years ago
2 years ago
}
List<TraceOrderEntity> traceOrderEntities = traceOrderService.findByProductIdFk(traceRecordLogEntity.getTraceProductIdFk());
return ResultVOUtils.success(traceOrderEntities);
}
2 years ago
/**
*
*
* @param traceRecordRequest
* @return
*/
@AuthRuleAnnotation("udi/trace/scene/search")
@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;
2 years ago
if (traceRecordRequest.getTraceType() == Constant.UDI_TRACE) {
//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());
2 years ago
} 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, "规格型号不能为空!");
}
//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());
2 years ago
}
traceSearchReponse.setTraceRecordLogEntity(traceRecordLogEntity);
return ResultVOUtils.success(traceSearchReponse);
2 years ago
}
2 years ago
/**
*
*
* @param traceOrderUploadRequest
* @param bindingResult
* @return
*/
@AuthRuleAnnotation("udi/trace/order/upload")
@PostMapping("udi/trace/order/upload")
public BaseResponse uploadOrder(@RequestBody TraceOrderUploadRequest traceOrderUploadRequest, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
TraceOrderEntity traceOrderEntity = new TraceOrderEntity();
BeanUtils.copyProperties(traceOrderUploadRequest, traceOrderEntity);
traceOrderEntity.setId(IdUtil.getSnowflakeNextId());
traceOrderEntity.setUpdateTime(new Date());
traceOrderService.save(traceOrderEntity);
return ResultVOUtils.success("上传成功");
}
/**
*
*
* @param traceOrderUploadRequest
* @param bindingResult
* @return
*/
@AuthRuleAnnotation("udi/trace/manuOrder/upload")
@PostMapping("udi/trace/manuOrder/upload")
public BaseResponse uploadManuOrder(@RequestBody TraceOrderUploadRequest traceOrderUploadRequest, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
TraceOrderEntity traceOrderEntity = new TraceOrderEntity();
BeanUtils.copyProperties(traceOrderUploadRequest, traceOrderEntity);
traceOrderEntity.setId(IdUtil.getSnowflakeNextId());
traceOrderEntity.setUpdateTime(new Date());
traceOrderService.save(traceOrderEntity);
return ResultVOUtils.success("上传成功");
}
}