追溯查询代码备份

cert
anthonywj 2 years ago
parent d588b27bb2
commit 8f18729614

@ -1,5 +1,6 @@
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;
@ -7,9 +8,15 @@ 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;
@ -17,6 +24,8 @@ 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
@ -27,7 +36,11 @@ public class UdiTraceController extends BaseController {
@Resource
TraceRecordService traceRecordService;
@Resource
TraceProductDetailService traceProductDetailService;
@Resource
BasicUdiRelService basicUdiRelService;
@Resource
GennerOrderUtils gennerOrderUtils;
/**
*
@ -54,6 +67,45 @@ public class UdiTraceController extends BaseController {
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.创建查询详情记录,若存在相同查询记录则直接获取
if (traceRecordRequest.getTraceType() == 1) {//按UDI码查询
TraceProductDetailEntity traceProductDetailEntity = traceProductDetailService.findUniqueByCode(1, traceRecordRequest.getUdiCode());
if (traceProductDetailEntity == null) {
}
} 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) {

@ -18,4 +18,6 @@ public interface BasicUdiRelMapper extends BaseMapper<BasicUdiRelEntity> {
UserCompanyEntity findByNameCode(@Param("nameCode") String nameCode);
List<String> findDiList(@Param("nameCode") String uuid);
}

@ -1,9 +1,9 @@
package com.glxp.api.dao.trace;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.glxp.api.entity.trace.TraceRecordDetailEntity;
import com.glxp.api.entity.trace.TraceProductDetailEntity;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface TraceRecordDetailMapper extends BaseMapper<TraceRecordDetailEntity> {
public interface TraceRecordDetailMapper extends BaseMapper<TraceProductDetailEntity> {
}

@ -1,7 +1,7 @@
package com.glxp.api.dao.trace;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.glxp.api.entity.trace.TraceRecordEntity;
import com.glxp.api.entity.trace.TraceRecordLogEntity;
import com.glxp.api.req.trace.TraceRecordRequest;
import com.glxp.api.res.trace.TraceRecordResponse;
import org.apache.ibatis.annotations.Mapper;
@ -9,7 +9,7 @@ import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface TraceRecordMapper extends BaseMapper<TraceRecordEntity> {
public interface TraceRecordMapper extends BaseMapper<TraceRecordLogEntity> {
List<TraceRecordResponse> filterTraces(TraceRecordRequest traceRecordRequest);

@ -4,27 +4,28 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import lombok.Data;
/**
*
*/
*
*/
@Data
@TableName(value = "trace_record_detail")
public class TraceRecordDetailEntity implements Serializable {
public class TraceProductDetailEntity implements Serializable {
@TableId(value = "id", type = IdType.INPUT)
private Long id;
/**
* ID
* 1:2)
*/
@TableField(value = "recordIdFk")
private String recordIdFk;
@TableField(value = "traceSource")
private Integer traceSource;
/**
* UDI/
* 1:UDI;2:
*/
@TableField(value = "traceType")
private Integer traceType;
@ -89,5 +90,12 @@ public class TraceRecordDetailEntity implements Serializable {
@TableField(value = "serialNo")
private String serialNo;
/**
* 1:2.3.
*/
@TableField(value = "status")
private Integer status;
private static final long serialVersionUID = 1L;
}

@ -4,21 +4,24 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
/**
*
*/
*
*/
@Data
@TableName(value = "trace_record")
public class TraceRecordEntity implements Serializable {
@TableName(value = "trace_record_log")
public class TraceRecordLogEntity implements Serializable {
@TableId(value = "id", type = IdType.INPUT)
private Long id;
/**
*
*
*/
@TableField(value = "recordCode")
private String recordCode;
@ -53,5 +56,18 @@ public class TraceRecordEntity implements Serializable {
@TableField(value = "remark")
private String remark;
/**
* 1:2.3.
*/
@TableField(value = "status")
private Integer status;
/**
* 1:UDI; 2:
*/
@TableField(value = "traceType")
private Integer traceType;
private static final long serialVersionUID = 1L;
}

@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import lombok.Data;
@ -29,14 +30,13 @@ public class TraceTaskNoticeEntity implements Serializable {
* 123
*/
@TableField(value = "taskType")
private Byte taskType;
private Integer taskType;
/**
* //
*
* 1.234:
*/
@TableField(value = "`status`")
private Byte status;
private Integer status;
/**
* ID
@ -103,6 +103,9 @@ public class TraceTaskNoticeEntity implements Serializable {
@TableField(value = "updateTime")
private Date updateTime;
@TableField(value = "diList")
private List<String> diList;
private static final long serialVersionUID = 1L;
}

@ -84,7 +84,7 @@ public class TraceManuOrderResponse {
private String companyName;
/**
*
*
*/
private String recordCode;

@ -1,9 +1,5 @@
package com.glxp.api.res.trace;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.models.auth.In;
import lombok.Data;
import java.util.Date;

@ -1,5 +1,7 @@
package com.glxp.api.service.basic;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.glxp.api.entity.sup.UserCompanyEntity;
@ -35,4 +37,15 @@ public class BasicUdiRelService extends ServiceImpl<BasicUdiRelMapper, BasicUdiR
return basicUdiRelMapper.findByNameCode(nameCode);
}
public BasicUdiRelResponse findByProductNameCode(String namCode) {
if (StrUtil.isEmpty(namCode))
return null;
FilterUdiRelRequest filterUdiRelRequest = new FilterUdiRelRequest();
List<BasicUdiRelResponse> udiRelResponses = basicUdiRelMapper.filterList(filterUdiRelRequest);
if (CollUtil.isNotEmpty(udiRelResponses))
return udiRelResponses.get(0);
return null;
}
}

@ -0,0 +1,40 @@
package com.glxp.api.service.trace;
import cn.hutool.core.lang.UUID;
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.entity.trace.MqTraceMessage;
import com.glxp.api.util.DateUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@Service
@RequiredArgsConstructor
public class RabbitPushService {
@Resource
private final RabbitTemplate rabbitTemplate;
public BaseResponse send(MqTraceMessage mqTraceMessage) {
rabbitTemplate.convertAndSend("topicExchange", TopicRabbitConfig.trace, mqTraceMessage);
return ResultVOUtils.success("发送成功");
}
public BaseResponse sendCommon(String key) {
String messageId = String.valueOf(UUID.randomUUID());
Map<String, Object> messageMap = new HashMap<>();
messageMap.put("messageId", messageId);
messageMap.put("messageData", key);
messageMap.put("createTime", DateUtil.formatDate(new Date()));
rabbitTemplate.convertAndSend("topicExchange", TopicRabbitConfig.common, messageMap);
return ResultVOUtils.success("发送成功");
}
}

@ -0,0 +1,42 @@
package com.glxp.api.service.trace;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.glxp.api.dao.trace.TraceRecordDetailMapper;
import com.glxp.api.entity.trace.TraceProductDetailEntity;
import javax.annotation.Resource;
import java.util.List;
@Service
public class TraceProductDetailService extends ServiceImpl<TraceRecordDetailMapper, TraceProductDetailEntity> {
@Resource
TraceRecordDetailMapper traceRecordDetailMapper;
public TraceProductDetailEntity findUniqueByCode(Integer traceType, String udiCode) {
List<TraceProductDetailEntity> traceRecordDetailEntities = traceRecordDetailMapper.selectList(new QueryWrapper<TraceProductDetailEntity>()
.eq("traceType", traceType)
.eq("udiCode", udiCode).last("limit 1"));
if (CollUtil.isNotEmpty(traceRecordDetailEntities))
return traceRecordDetailEntities.get(0);
else return null;
}
public TraceProductDetailEntity findUniqueByData(Integer traceType, String ylqxzcrbarmc, String cpmctymc, String ggxh, String nameCode, String batchNo) {
List<TraceProductDetailEntity> traceRecordDetailEntities = traceRecordDetailMapper.selectList(new QueryWrapper<TraceProductDetailEntity>()
.eq("traceType", traceType)
.eq("ylqxzcrbarmc", ylqxzcrbarmc)
.eq("cpmctymc", cpmctymc)
.eq("ggxh", ggxh)
.eq("nameCode", nameCode)
.eq("batchNo", batchNo)
.last("limit 1"));
if (CollUtil.isNotEmpty(traceRecordDetailEntities))
return traceRecordDetailEntities.get(0);
else return null;
}
}

@ -1,8 +0,0 @@
package com.glxp.api.service.trace;
import com.glxp.api.entity.trace.TraceRecordDetailEntity;
import com.baomidou.mybatisplus.extension.service.IService;
public interface TraceRecordDetailService extends IService<TraceRecordDetailEntity>{
}

@ -1,13 +1,35 @@
package com.glxp.api.service.trace;
import com.glxp.api.entity.trace.TraceRecordEntity;
import com.baomidou.mybatisplus.extension.service.IService;
import com.github.pagehelper.PageHelper;
import com.glxp.api.req.trace.TraceRecordRequest;
import com.glxp.api.res.trace.TraceRecordResponse;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.glxp.api.dao.trace.TraceRecordMapper;
import com.glxp.api.entity.trace.TraceRecordLogEntity;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
public interface TraceRecordService extends IService<TraceRecordEntity> {
@Service
public class TraceRecordService extends ServiceImpl<TraceRecordMapper, TraceRecordLogEntity> {
@Resource
TraceRecordMapper traceRecordMapper;
public List<TraceRecordResponse> filterTraces(TraceRecordRequest traceRecordRequest) {
if (traceRecordRequest == null) {
return Collections.emptyList();
}
if (traceRecordRequest.getPage() != null) {
int offset = (traceRecordRequest.getPage() - 1) * traceRecordRequest.getLimit();
PageHelper.offsetPage(offset, traceRecordRequest.getLimit());
}
return traceRecordMapper.filterTraces(traceRecordRequest);
}
List<TraceRecordResponse> filterTraces(TraceRecordRequest traceRecordRequest);
}

@ -1,12 +0,0 @@
package com.glxp.api.service.trace.impl;
import com.glxp.api.service.trace.TraceRecordDetailService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.glxp.api.dao.trace.TraceRecordDetailMapper;
import com.glxp.api.entity.trace.TraceRecordDetailEntity;
@Service
public class TraceRecordDetailServiceImpl extends ServiceImpl<TraceRecordDetailMapper, TraceRecordDetailEntity> implements TraceRecordDetailService {
}

@ -1,34 +0,0 @@
package com.glxp.api.service.trace.impl;
import com.github.pagehelper.PageHelper;
import com.glxp.api.req.trace.TraceRecordRequest;
import com.glxp.api.res.trace.TraceRecordResponse;
import com.glxp.api.service.trace.TraceRecordService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.glxp.api.dao.trace.TraceRecordMapper;
import com.glxp.api.entity.trace.TraceRecordEntity;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
@Service
public class TraceRecordServiceImpl extends ServiceImpl<TraceRecordMapper, TraceRecordEntity> implements TraceRecordService {
@Resource
TraceRecordMapper traceRecordMapper;
@Override
public List<TraceRecordResponse> filterTraces(TraceRecordRequest traceRecordRequest) {
if (traceRecordRequest == null) {
return Collections.emptyList();
}
if (traceRecordRequest.getPage() != null) {
int offset = (traceRecordRequest.getPage() - 1) * traceRecordRequest.getLimit();
PageHelper.offsetPage(offset, traceRecordRequest.getLimit());
}
return traceRecordMapper.filterTraces(traceRecordRequest);
}
}

@ -110,6 +110,16 @@ public class GennerOrderUtils {
return sb.toString();
}
/**
*
*
* @return
*/
public String getRecordNo() {
String orderNo = createRecordOrderNo(new OrderNoTypeBean("T", "yyyyMMdd"));
return orderNo;
}
/**
* @param orderNoTypeEnum:
* @Description redis( + )
@ -118,7 +128,7 @@ public class GennerOrderUtils {
* @time: 14:15
* @return: java.lang.String
**/
public String createScOrderNo(OrderNoTypeBean orderNoTypeEnum) {
public String createRecordOrderNo(OrderNoTypeBean orderNoTypeEnum) {
//获得单号前缀
//格式 固定前缀 +时间前缀 示例
String formNoPrefix = getFormNoPrefix(orderNoTypeEnum);
@ -137,44 +147,6 @@ public class GennerOrderUtils {
return completionRandom(serialWithPrefix, orderNoTypeEnum);
}
public String createStOrderNo(OrderNoTypeBean orderNoTypeEnum) {
//获得单号前缀
//格式 固定前缀 +时间前缀 示例
String formNoPrefix = getFormNoPrefix(orderNoTypeEnum);
//获得缓存key
String cacheKey = getStCacheKey(formNoPrefix);
//获得当日自增数
Long incrementalSerial = redisUtil.incr(cacheKey, 1);
// 设置key过期时间, 保证每天的流水号从1开始
if (incrementalSerial == 1) {
//设置失效时间 凌晨过期
redisUtil.expire(cacheKey, getSecondsNextEarlyMorning());
}
//组合单号并补全流水号
String serialWithPrefix = completionSerial(formNoPrefix, incrementalSerial, orderNoTypeEnum);
//补全随机数
return completionRandom(serialWithPrefix, orderNoTypeEnum);
}
public String createPurOrderNo(OrderNoTypeBean orderNoTypeEnum) {
//获得单号前缀
//格式 固定前缀 +时间前缀 示例
String formNoPrefix = getFormNoPrefix(orderNoTypeEnum);
//获得缓存key
String cacheKey = getStCacheKey(formNoPrefix);
//获得当日自增数
Long incrementalSerial = redisUtil.incr(cacheKey, 1);
// 设置key过期时间, 保证每天的流水号从1开始
if (incrementalSerial == 1) {
//设置失效时间 凌晨过期
redisUtil.expire(cacheKey, getSecondsNextEarlyMorning());
}
//组合单号并补全流水号
String serialWithPrefix = completionSerial(formNoPrefix, incrementalSerial, orderNoTypeEnum);
//补全随机数
return completionRandom(serialWithPrefix, orderNoTypeEnum);
}
private Long getSecondsNextEarlyMorning() {
Calendar cal = Calendar.getInstance();

@ -4,55 +4,55 @@
<select id="filterList" parameterType="com.glxp.api.req.basic.FilterUdiRelRequest"
resultType="com.glxp.api.res.basic.BasicUdiRelResponse">
select bur.*,
uc.companyName,
nameCode,
packRatio,
packLevel,
bhxjsl,
bhzxxsbzsl,
zxxsbzbhsydysl,
bhxjcpbm,
sjcpbm,
bzcj,
thirdProductNo,
thirdProductName,
addType,
deviceRecordKey,
isUseDy,
cpmctymc,
cplb,
flbm,
ggxh,
qxlb,
tyshxydm,
ylqxzcrbarmc,
zczbhhzbapzbh,
ylqxzcrbarywmc,
sydycpbs,
versionNumber,
diType,
scbssfbhph,
scbssfbhxlh,
scbssfbhscrq,
scbssfbhsxrq,
ybbm,
spmc,
cphhhbh,
cpms,
cpbsbmtxmc,
cplx,
hchzsb,
sfwblztlcp,
cgzmraqxgxx,
sfbjwycxsy,
zdcfsycs,
sfwwjbz,
syqsfxyjxmj,
qtxxdwzlj,
mjfs
uc.companyName,
nameCode,
packRatio,
packLevel,
bhxjsl,
bhzxxsbzsl,
zxxsbzbhsydysl,
bhxjcpbm,
sjcpbm,
bzcj,
thirdProductNo,
thirdProductName,
addType,
deviceRecordKey,
isUseDy,
cpmctymc,
cplb,
flbm,
ggxh,
qxlb,
tyshxydm,
ylqxzcrbarmc,
zczbhhzbapzbh,
ylqxzcrbarywmc,
sydycpbs,
versionNumber,
diType,
scbssfbhph,
scbssfbhxlh,
scbssfbhscrq,
scbssfbhsxrq,
ybbm,
spmc,
cphhhbh,
cpms,
cpbsbmtxmc,
cplx,
hchzsb,
sfwblztlcp,
cgzmraqxgxx,
sfbjwycxsy,
zdcfsycs,
sfwwjbz,
syqsfxyjxmj,
qtxxdwzlj,
mjfs
FROM basic_udi_rel bur
left JOIN productinfo p on bur.uuid = p.uuid
left join user_company uc on bur.companyIdFk = uc.id
left JOIN basic_udi_product p on bur.uuid = p.uuid
left join user_company uc on bur.companyIdFk = uc.id
<where>
<if test="ylqxzcrbarmc != '' and ylqxzcrbarmc != null">
AND ylqxzcrbarmc LIKE concat('%', #{ylqxzcrbarmc}, '%')
@ -99,9 +99,16 @@
resultType="com.glxp.api.entity.sup.UserCompanyEntity">
select user_company.*
from basic_udi_rel
INNER JOIN basic_udi_product on basic_udi_rel.uuid = basic_udi_product.uuid
INNER JOIN user_company on basic_udi_rel.companyIdFk = user_company.id
INNER JOIN basic_udi_product on basic_udi_rel.uuid = basic_udi_product.uuid
INNER JOIN user_company on basic_udi_rel.companyIdFk = user_company.id
where basic_udi_product.nameCode = #{nameCode}
limit 1
</select>
<select id="findDiList" parameterType="java.lang.String"
resultType="java.lang.String">
select nameCode
from basic_udi_product
where uuid = #{uuid}
</select>
</mapper>

Loading…
Cancel
Save