|
|
|
package com.glxp.api.controller.trace;
|
|
|
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
|
import com.glxp.api.annotation.AuthRuleAnnotation;
|
|
|
|
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.TraceProductDetailEntity;
|
|
|
|
import com.glxp.api.entity.trace.TraceRecordLogEntity;
|
|
|
|
import com.glxp.api.entity.trace.TraceTaskNoticeEntity;
|
|
|
|
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.TraceProductDetailService;
|
|
|
|
import com.glxp.api.service.trace.TraceRecordService;
|
|
|
|
import com.glxp.api.util.GennerOrderUtils;
|
|
|
|
import com.glxp.api.util.udi.FilterUdiUtils;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import springfox.documentation.annotations.ApiIgnore;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
@ApiIgnore
|
|
|
|
@RestController
|
|
|
|
@Slf4j
|
|
|
|
public class UdiTraceController extends BaseController {
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
TraceRecordService traceRecordService;
|
|
|
|
@Resource
|
|
|
|
TraceProductDetailService traceProductDetailService;
|
|
|
|
@Resource
|
|
|
|
BasicUdiRelService basicUdiRelService;
|
|
|
|
@Resource
|
|
|
|
GennerOrderUtils gennerOrderUtils;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 源头追溯查询
|
|
|
|
*
|
|
|
|
* @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 { //按批次号查询
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//5.创建查询任务表
|
|
|
|
TraceTaskNoticeEntity traceTaskNoticeEntity = new TraceTaskNoticeEntity();
|
|
|
|
traceTaskNoticeEntity.setId(IdUtil.getSnowflakeNextId());
|
|
|
|
traceTaskNoticeEntity.setCreateTime(new Date());
|
|
|
|
List<String> diList = basicUdiRelService.getBaseMapper().findDiList(basicUdiRelResponse.getUuid());
|
|
|
|
traceTaskNoticeEntity.setDiList(diList);
|
|
|
|
traceTaskNoticeEntity.setTaskType(1);
|
|
|
|
traceTaskNoticeEntity.setStatus(1);
|
|
|
|
|
|
|
|
|
|
|
|
} else if (traceRecordRequest.getTraceType() == Constant.UDI_BATCHNO) {
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return ResultVOUtils.error(500, "请选择查询方式!");
|
|
|
|
}
|
|
|
|
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, "查询失败");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|