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

385 lines
17 KiB
Java

package com.glxp.api.controller.trace;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
2 years ago
import com.alibaba.fastjson.JSON;
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;
2 years ago
import com.glxp.api.config.rabbit.TopicRabbitConfig;
2 years ago
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;
2 years ago
import com.glxp.api.req.trace.TraceManuDetailRequest;
import com.glxp.api.req.trace.TraceManuOrderUploadRequest;
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.system.SystemParamConfigService;
import com.glxp.api.service.trace.*;
2 years ago
import com.glxp.api.service.trace.impl.TraceManuCodeRelService;
import com.glxp.api.util.GennerOrderUtils;
import com.glxp.api.util.udi.FilterUdiUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
2 years ago
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
2 years ago
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils;
import org.springframework.transaction.annotation.Transactional;
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
@Api(tags = "UDI追溯相关接口")
@ApiIgnore
@RestController
@Slf4j
2 years ago
@RequiredArgsConstructor
public class UdiTraceController extends BaseController {
2 years ago
@Resource
BasicUdiRelService basicUdiRelService;
@Resource
TraceTaskNoticeService traceTaskNoticeService;
2 years ago
@Resource
TraceOrderService traceOrderService;
@Resource
TraceManuOrderService traceManuOrderService;
@Resource
TraceManuCodeRelService traceManuCodeRelService;
@Resource
TraceRecordService traceRecordService;
@Resource
UdiTraceService udiTraceService;
@Resource
UserCompanyService userCompanyService;
@Resource
2 years ago
private final RabbitTemplate rabbitTemplate;
2 years ago
@ApiIgnore
@ApiOperation(value = "消息推送接口", response = BaseResponse.class)
2 years ago
@GetMapping("/udi/trace/source/sendUDI")
public BaseResponse sendUdi(@RequestBody TraceRecordRequest traceRecordRequest) {
String messageJson = JSON.toJSONString(traceRecordRequest);
System.out.println(messageJson);
2 years ago
rabbitTemplate.convertAndSend("trace.topic.exchange", TopicRabbitConfig.common, messageJson);
return ResultVOUtils.success("发送成功");
}
2 years ago
@PostMapping("/udi/trace/source/task")
public BaseResponse sendTask(@RequestBody MqTaskDelayMessage mqTaskDelayMessage) {
String messageJson = JSON.toJSONString(mqTaskDelayMessage);
System.out.println(messageJson);
rabbitTemplate.convertAndSend(TopicRabbitConfig.TRACE_DELAY_EXCHANGE, TopicRabbitConfig.delaytrace, mqTaskDelayMessage);
return ResultVOUtils.success("发送成功");
}
2 years ago
/**
*
*
* @param traceRecordRequest
* @return
*/
@ApiOperation(value = "源头追溯查询", response = TraceOrderEntity.class)
2 years ago
@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.查询源头企业
System.out.println(udiEntity.getUdi());
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, "规格型号不能为空!");
}
if (StrUtil.isEmpty(traceRecordRequest.getNameCode())) {
return ResultVOUtils.error(500, "DI标识不能为空!");
}
if (StrUtil.isEmpty(traceRecordRequest.getBatchNo())) {
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(traceRecordLogEntity.getRecordCode());
}
2 years ago
/**
*
*
* @param traceRecordRequest
* @return
*/
@ApiOperation(value = "现场检查查询", response = TraceOrderEntity.class)
2 years ago
@AuthRuleAnnotation("udi/trace/scene/search")
@GetMapping("udi/trace/scene/search")
public BaseResponse sceneTrace(TraceRecordRequest traceRecordRequest) {
TraceRecordLogEntity traceRecordLogEntity = null;
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 = 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() + "";
traceRecordLogEntity = udiTraceService.createRecordLog(userId, traceRecordRequest.getFromType(), traceRecordRequest.getTraceType());
//5.创建查询详情记录,若存在相同查询记录则直接获取
traceProductDetailEntity = udiTraceService.createTracerProductByUdiCode(traceRecordRequest.getUdiCode(), 2, 1, basicUdiRelResponse, udiEntity);
traceRecordLogEntity.setTraceProductIdFk(traceProductDetailEntity.getId());
traceRecordService.updateById(traceRecordLogEntity);
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
}
// List<TraceOrderEntity> traceOrderEntities = traceOrderService.findByProductIdFk(traceRecordLogEntity.getTraceProductIdFk());
return ResultVOUtils.success(traceRecordLogEntity.getRecordCode());
2 years ago
}
2 years ago
/**
*
*
* @param traceOrderUploadRequest
* @param bindingResult
* @return
*/
@Transactional
@ApiOperation(value = "客户端根据任务上传出入库单据", response = BaseResponse.class)
@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());
}
TraceTaskNoticeEntity taskNoticeEntity = traceTaskNoticeService.getById(traceOrderUploadRequest.getTaskId());
if (taskNoticeEntity == null) {
return ResultVOUtils.error(500, "任务已过期,或任务不存在!");
}
//清空历史数据
traceOrderService.deleteByCompanyId(taskNoticeEntity.getProdudctRecordIdFk(), taskNoticeEntity.getCompanyIdFk());
TraceOrderEntity traceOrderEntity = new TraceOrderEntity();
BeanUtils.copyProperties(traceOrderUploadRequest, traceOrderEntity);
traceOrderEntity.setId(IdUtil.getSnowflakeNextId());
traceOrderEntity.setUpdateTime(new Date());
traceOrderService.save(traceOrderEntity);
//设置任务已完成
taskNoticeEntity.setStatus(3);
traceTaskNoticeService.updateById(taskNoticeEntity);
udiTraceService.pushDelayRemoveTask(taskNoticeEntity);
return ResultVOUtils.success("上传成功");
}
/**
*
*
* @param traceManuOrderUploadRequest
* @param bindingResult
* @return
*/
@Transactional
@ApiOperation(value = "客户端根据任务上传生产关联关系信息", response = BaseResponse.class)
@AuthRuleAnnotation("udi/trace/manuOrder/upload")
@PostMapping("udi/trace/manuOrder/upload")
public BaseResponse uploadManuOrder(@RequestBody TraceManuOrderUploadRequest traceManuOrderUploadRequest, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
TraceTaskNoticeEntity taskNoticeEntity = traceTaskNoticeService.getById(traceManuOrderUploadRequest.getTaskId());
if (taskNoticeEntity == null) {
return ResultVOUtils.error(500, "任务已过期,或任务不存在!");
}
//清除历史数据
TraceManuOrderEntity originOrder = traceManuOrderService.findByBillNo(traceManuOrderUploadRequest.getBillNo(), taskNoticeEntity.getProdudctRecordIdFk(), taskNoticeEntity.getCompanyIdFk());
if (originOrder != null) {
traceManuOrderService.removeById(originOrder.getId());
traceManuCodeRelService.remove(new QueryWrapper<TraceManuCodeRelEntity>().eq("manuOrderIdFk", originOrder.getId()));
}
//新增生产订单
TraceManuOrderEntity traceManuOrderEntity = new TraceManuOrderEntity();
BeanUtils.copyProperties(traceManuOrderUploadRequest, traceManuOrderEntity);
traceManuOrderEntity.setId(IdUtil.getSnowflakeNextId());
traceManuOrderService.save(traceManuOrderEntity);
//新增订单关联明细
List<TraceManuDetailRequest> traceManuDetailRequests = traceManuOrderUploadRequest.getDetails();
if (CollUtil.isNotEmpty(traceManuDetailRequests)) {
for (TraceManuDetailRequest traceManuDetailRequest : traceManuDetailRequests) {
TraceManuCodeRelEntity traceManuCodeRelEntity = new TraceManuCodeRelEntity();
BeanUtils.copyProperties(traceManuDetailRequest, traceManuCodeRelEntity);
traceManuCodeRelEntity.setId(IdUtil.getSnowflakeNextId());
traceManuCodeRelEntity.setManuOrderIdFk(traceManuOrderEntity.getId());
traceManuOrderService.save(traceManuOrderEntity);
}
}
//设置任务已完成
taskNoticeEntity.setStatus(3);
traceTaskNoticeService.updateById(taskNoticeEntity);
udiTraceService.pushDelayRemoveTask(taskNoticeEntity);
return ResultVOUtils.success("上传成功");
}
}