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.
392 lines
18 KiB
Java
392 lines
18 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;
|
|
import com.alibaba.fastjson.JSON;
|
|
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;
|
|
import com.glxp.api.common.util.ResultVOUtils;
|
|
import com.glxp.api.config.rabbit.TopicRabbitConfig;
|
|
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.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.sup.UserCompanyResponse;
|
|
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.*;
|
|
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;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.validation.BindingResult;
|
|
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;
|
|
|
|
import javax.annotation.Resource;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
|
|
@Api(tags = "UDI追溯相关接口")
|
|
@ApiIgnore
|
|
@RestController
|
|
@Slf4j
|
|
@RequiredArgsConstructor
|
|
public class UdiTraceController extends BaseController {
|
|
|
|
|
|
@Resource
|
|
BasicUdiRelService basicUdiRelService;
|
|
@Resource
|
|
TraceTaskNoticeService traceTaskNoticeService;
|
|
|
|
@Resource
|
|
TraceOrderService traceOrderService;
|
|
@Resource
|
|
TraceManuOrderService traceManuOrderService;
|
|
@Resource
|
|
TraceManuCodeRelService traceManuCodeRelService;
|
|
@Resource
|
|
TraceRecordService traceRecordService;
|
|
@Resource
|
|
UdiTraceService udiTraceService;
|
|
|
|
@Resource
|
|
UserCompanyService userCompanyService;
|
|
@Resource
|
|
private final RabbitTemplate rabbitTemplate;
|
|
|
|
@ApiIgnore
|
|
@ApiOperation(value = "消息推送接口", response = BaseResponse.class)
|
|
@GetMapping("/udi/trace/source/sendUDI")
|
|
public BaseResponse sendUdi(@RequestBody TraceRecordRequest traceRecordRequest) {
|
|
String messageJson = JSON.toJSONString(traceRecordRequest);
|
|
System.out.println(messageJson);
|
|
rabbitTemplate.convertAndSend("trace.topic.exchange", TopicRabbitConfig.common, messageJson);
|
|
return ResultVOUtils.success("发送成功");
|
|
}
|
|
|
|
@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("发送成功");
|
|
}
|
|
|
|
|
|
/**
|
|
* 源头追溯查询
|
|
*
|
|
* @param traceRecordRequest
|
|
* @return
|
|
*/
|
|
@ApiOperation(value = "源头追溯查询", response = TraceOrderEntity.class)
|
|
@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;
|
|
List<UserCompanyResponse> userCompanyResponses = null;
|
|
|
|
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.查询源头企业
|
|
userCompanyResponses = basicUdiRelService.findSourceByNameCode(udiEntity.getUdi());
|
|
if (CollUtil.isEmpty(userCompanyResponses)) {
|
|
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, null);
|
|
traceRecordLogEntity.setTraceProductIdFk(traceProductDetailEntity.getId());
|
|
traceRecordService.updateById(traceRecordLogEntity);
|
|
for (UserCompanyResponse userCompanyResponse : userCompanyResponses) {
|
|
udiTraceService.createSourceTraceTask(traceProductDetailEntity, userCompanyResponse.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());
|
|
userCompanyResponses = basicUdiRelService.findSourceByNameCode(traceRecordRequest.getNameCode());
|
|
if (CollUtil.isEmpty(userCompanyResponses)) {
|
|
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, null);
|
|
traceRecordLogEntity.setTraceProductIdFk(traceProductDetailEntity.getId());
|
|
traceRecordService.updateById(traceRecordLogEntity);
|
|
for (UserCompanyResponse userCompanyResponse : userCompanyResponses) {
|
|
udiTraceService.createSourceTraceTask(traceProductDetailEntity, userCompanyResponse.getId());
|
|
}
|
|
}
|
|
// List<TraceOrderEntity> traceOrderEntities = traceOrderService.findByProductIdFk(traceRecordLogEntity.getTraceProductIdFk());
|
|
return ResultVOUtils.success(traceRecordLogEntity.getRecordCode());
|
|
}
|
|
|
|
/**
|
|
* 现场检查查询
|
|
*
|
|
* @param traceRecordRequest
|
|
* @return
|
|
*/
|
|
@ApiOperation(value = "现场检查查询", response = TraceOrderEntity.class)
|
|
@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;
|
|
|
|
if (traceRecordRequest.getCompanyId() == null) {
|
|
return ResultVOUtils.error(500, "请先选择当前所在企业!");
|
|
}
|
|
|
|
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, traceRecordRequest.getCompanyId() + "");
|
|
traceRecordLogEntity.setTraceProductIdFk(traceProductDetailEntity.getId());
|
|
traceRecordService.updateById(traceRecordLogEntity);
|
|
udiTraceService.createCheckTraceTask(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 = 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, traceRecordRequest.getCompanyId() + "");
|
|
udiTraceService.createCheckTraceTask(traceProductDetailEntity, userCompanyEntity.getId());
|
|
}
|
|
// List<TraceOrderEntity> traceOrderEntities = traceOrderService.findByProductIdFk(traceRecordLogEntity.getTraceProductIdFk());
|
|
return ResultVOUtils.success(traceRecordLogEntity.getRecordCode());
|
|
}
|
|
|
|
|
|
// /**
|
|
// * 客户端根据任务上传出入库单据
|
|
// *
|
|
// * @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("上传成功");
|
|
// }
|
|
|
|
}
|