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

240 lines
11 KiB
Java

package com.glxp.api.controller.trace;
import cn.hutool.core.util.IdUtil;
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.trace.TraceOrderUploadRequest;
2 years ago
import com.glxp.api.req.trace.TraceRecordRequest;
import com.glxp.api.res.basic.BasicUdiRelResponse;
import com.glxp.api.service.basic.BasicUdiRelService;
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
2 years ago
@Resource
TraceRecordService traceRecordService;
@Resource
TraceProductDetailService traceProductDetailService;
@Resource
BasicUdiRelService basicUdiRelService;
@Resource
GennerOrderUtils gennerOrderUtils;
@Resource
TraceTaskNoticeService traceTaskNoticeService;
@Resource
RabbitPushService rabbitPushService;
@Resource
TraceOrderService traceOrderService;
2 years ago
/**
*
*
* @param traceRecordRequest
* @return
*/
@AuthRuleAnnotation("udi/trace/source/search")
@GetMapping("udi/trace/source/search")
public BaseResponse createTrace(TraceRecordRequest traceRecordRequest) {
if (traceRecordRequest.getTraceType() == Constant.UDI_TRACE) {
//1.校验UDI码格式
UdiEntity udiEntity = FilterUdiUtils.getUdi(traceRecordRequest.getUdiCode());
if (udiEntity == null) {
return ResultVOUtils.error(500, "UDI码格式错误");
}
//2.查询源头企业
UserCompanyEntity userCompanyEntity = basicUdiRelService.findByNameCode(udiEntity.getUdi());
if (userCompanyEntity == null) {
return ResultVOUtils.error(500, "生产企业未关联该产品信息!");
}
//3.查询产品信息
BasicUdiRelResponse basicUdiRelResponse = basicUdiRelService.findByProductNameCode(traceRecordRequest.getNameCode());
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());
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);
}
}
//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);
2 years ago
return ResultVOUtils.success("创建查询成功,请稍后刷新查看查询结果!");
2 years ago
}
2 years ago
return ResultVOUtils.error(500, "查询失败");
}
/**
*
*
* @param traceRecordRequest
* @return
*/
@AuthRuleAnnotation("udi/trace/scene/search")
@GetMapping("udi/trace/scene/search")
public BaseResponse sceneTrace(TraceRecordRequest traceRecordRequest) {
if (traceRecordRequest.getTraceType() == Constant.UDI_TRACE) {
} else if (traceRecordRequest.getTraceType() == Constant.UDI_BATCHNO) {
} else {
return ResultVOUtils.error(500, "请选择查询方式!");
}
return ResultVOUtils.error(500, "查询失败");
}
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("上传成功");
}
}