|
|
|
@ -5,12 +5,15 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
|
import com.glxp.api.dao.basic.BasicProductsDao;
|
|
|
|
|
import com.glxp.api.entity.basic.BasicProductsEntity;
|
|
|
|
|
import com.glxp.api.entity.basic.UdiEntity;
|
|
|
|
|
import com.glxp.api.exception.JsonException;
|
|
|
|
|
import com.glxp.api.req.collect.RelCodeDetailRequest;
|
|
|
|
|
import com.glxp.api.res.collect.RelCodeDetailResponse;
|
|
|
|
|
import com.glxp.api.util.udi.FilterUdiUtils;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.Currency;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import com.glxp.api.dao.collect.RelCodeDetailMapper;
|
|
|
|
@ -22,37 +25,65 @@ public class RelCodeDetailService extends ServiceImpl<RelCodeDetailMapper, RelCo
|
|
|
|
|
private BasicProductsDao basicProductsDao;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 扫码获取子集
|
|
|
|
|
* 扫码获取关联
|
|
|
|
|
* @param relCodeDetailRequest
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public RelCodeDetailResponse scanCode(RelCodeDetailRequest relCodeDetailRequest) {
|
|
|
|
|
String curCode = relCodeDetailRequest.getCurCode();
|
|
|
|
|
String parentCode = relCodeDetailRequest.getParentCode();
|
|
|
|
|
if(StrUtil.isBlank(parentCode)){
|
|
|
|
|
throw new JsonException("父级码不能为空");
|
|
|
|
|
if(StrUtil.isBlank(curCode)){
|
|
|
|
|
throw new JsonException("追溯码不能为空");
|
|
|
|
|
}
|
|
|
|
|
if (curCode.endsWith("\u001D")) {
|
|
|
|
|
curCode = curCode.replace("\u001D", "");
|
|
|
|
|
}
|
|
|
|
|
UdiEntity curCodeUdi = FilterUdiUtils.getUdi(curCode);
|
|
|
|
|
if (curCodeUdi == null){
|
|
|
|
|
throw new JsonException("无效条码!");
|
|
|
|
|
}
|
|
|
|
|
RelCodeDetailResponse relCodeDetailResponse = new RelCodeDetailResponse();
|
|
|
|
|
LambdaQueryWrapper<BasicProductsEntity> qw = new LambdaQueryWrapper<BasicProductsEntity>()
|
|
|
|
|
.eq(BasicProductsEntity::getNameCode, relCodeDetailRequest.getParentCode())
|
|
|
|
|
LambdaQueryWrapper<BasicProductsEntity> cw = new LambdaQueryWrapper<BasicProductsEntity>()
|
|
|
|
|
.eq(BasicProductsEntity::getNameCode, curCodeUdi.getUdi())
|
|
|
|
|
.last("limit 1");
|
|
|
|
|
BasicProductsEntity parent = basicProductsDao.selectOne(qw);
|
|
|
|
|
if(parent == null){
|
|
|
|
|
BasicProductsEntity cur = basicProductsDao.selectOne(cw);
|
|
|
|
|
if(cur == null){
|
|
|
|
|
throw new JsonException("产品信息不存在");
|
|
|
|
|
}
|
|
|
|
|
Integer packLevel = Integer.valueOf(parent.getPackLevel());
|
|
|
|
|
if(packLevel == 1){
|
|
|
|
|
throw new JsonException("产品信息不存在子包装");
|
|
|
|
|
if(StrUtil.isNotBlank(parentCode)){
|
|
|
|
|
if (parentCode.endsWith("\u001D")) {
|
|
|
|
|
parentCode = parentCode.replace("\u001D", "");
|
|
|
|
|
}
|
|
|
|
|
//todo 可能存在多个子集 如何处理
|
|
|
|
|
LambdaQueryWrapper<BasicProductsEntity> qw2 = new LambdaQueryWrapper<BasicProductsEntity>()
|
|
|
|
|
.eq(BasicProductsEntity::getUuid, parent.getUuid())
|
|
|
|
|
.eq(BasicProductsEntity::getPackLevel,packLevel - 1)
|
|
|
|
|
UdiEntity parentCodeUdi = FilterUdiUtils.getUdi(parentCode);
|
|
|
|
|
if (parentCodeUdi == null){
|
|
|
|
|
throw new JsonException("无效父级条码!");
|
|
|
|
|
}
|
|
|
|
|
LambdaQueryWrapper<BasicProductsEntity> pw = new LambdaQueryWrapper<BasicProductsEntity>()
|
|
|
|
|
.eq(BasicProductsEntity::getNameCode, parentCodeUdi.getUdi())
|
|
|
|
|
.last("limit 1");
|
|
|
|
|
BasicProductsEntity subset = basicProductsDao.selectOne(qw2);
|
|
|
|
|
relCodeDetailResponse.setCurCode(subset.getNameCode());
|
|
|
|
|
relCodeDetailResponse.setPackLayer(Integer.valueOf(subset.getPackLevel()));
|
|
|
|
|
relCodeDetailResponse.setParentCode(parent.getNameCode());
|
|
|
|
|
relCodeDetailResponse.setFlag(Integer.valueOf(subset.getMajorStatus()));
|
|
|
|
|
BasicProductsEntity parent = basicProductsDao.selectOne(pw);
|
|
|
|
|
if(parent == null){
|
|
|
|
|
throw new JsonException("父级产品信息不存在");
|
|
|
|
|
}
|
|
|
|
|
if(!StrUtil.equals(parent.getUuid(),cur.getUuid())){
|
|
|
|
|
throw new JsonException("当前条码不是同一产品");
|
|
|
|
|
}
|
|
|
|
|
if(Integer.valueOf(parent.getPackLevel()) - Integer.valueOf(cur.getPackLevel()) != 1){
|
|
|
|
|
throw new JsonException("当前条码不属于子条码");
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
parentCode = "0";
|
|
|
|
|
}
|
|
|
|
|
relCodeDetailResponse.setCurCode(curCode);
|
|
|
|
|
relCodeDetailResponse.setParentCode(parentCode);
|
|
|
|
|
relCodeDetailResponse.setPackLayer(Integer.valueOf(cur.getPackLevel()));
|
|
|
|
|
relCodeDetailResponse.setFlag(Integer.valueOf(cur.getMajorStatus()));
|
|
|
|
|
relCodeDetailResponse.setCpmctymc(cur.getCpmctymc());
|
|
|
|
|
relCodeDetailResponse.setProductCode(cur.getNameCode());
|
|
|
|
|
relCodeDetailResponse.setBhxjsl(cur.getBhxjsl());
|
|
|
|
|
relCodeDetailResponse.setPackageSpec(cur.getBzgg());
|
|
|
|
|
relCodeDetailResponse.setCascadeRatio(cur.getPackRatio());
|
|
|
|
|
relCodeDetailResponse.setPackUnit(cur.getPackUnit());
|
|
|
|
|
return relCodeDetailResponse;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|