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.
117 lines
4.9 KiB
Java
117 lines
4.9 KiB
Java
package com.glxp.api.service.collect;
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.glxp.api.dao.basic.BasicProductsDao;
|
|
import com.glxp.api.dao.collect.RelCodeDetailMapper;
|
|
import com.glxp.api.entity.basic.BasicProductsEntity;
|
|
import com.glxp.api.entity.basic.UdiEntity;
|
|
import com.glxp.api.entity.collect.RelCodeDetail;
|
|
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.List;
|
|
|
|
@Service
|
|
public class RelCodeDetailService extends ServiceImpl<RelCodeDetailMapper, RelCodeDetail> {
|
|
|
|
@Resource
|
|
private BasicProductsDao basicProductsDao;
|
|
|
|
/**
|
|
* 扫码获取关联
|
|
* @param relCodeDetailRequest
|
|
* @return
|
|
*/
|
|
public RelCodeDetailResponse scanCode(RelCodeDetailRequest relCodeDetailRequest) {
|
|
String curCode = relCodeDetailRequest.getCurCode();
|
|
String parentCode = relCodeDetailRequest.getParentCode();
|
|
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> cw = new LambdaQueryWrapper<BasicProductsEntity>()
|
|
.eq(BasicProductsEntity::getNameCode, curCodeUdi.getUdi())
|
|
.last("limit 1");
|
|
BasicProductsEntity cur = basicProductsDao.selectOne(cw);
|
|
if(cur == null){
|
|
throw new JsonException("产品信息不存在");
|
|
}
|
|
//是否已存在数据库中
|
|
List<RelCodeDetail> list = this.baseMapper.selectList(new LambdaQueryWrapper<RelCodeDetail>().eq(RelCodeDetail::getCurCode, curCode));
|
|
if (CollUtil.isNotEmpty(list)){
|
|
throw new JsonException("当前条码关联关系已被维护!");
|
|
}
|
|
if(StrUtil.isNotBlank(parentCode)){
|
|
if (parentCode.endsWith("\u001D")) {
|
|
parentCode = parentCode.replace("\u001D", "");
|
|
}
|
|
if(StrUtil.equals(curCode,parentCode)){
|
|
throw new JsonException("录入条码重复!");
|
|
}
|
|
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 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(1);
|
|
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;
|
|
}
|
|
|
|
/**
|
|
* 明细列表
|
|
* @param relCodeDetailRequest
|
|
* @return
|
|
*/
|
|
public List<RelCodeDetailResponse> filterList(RelCodeDetailRequest relCodeDetailRequest) {
|
|
if (relCodeDetailRequest == null) {
|
|
return Collections.emptyList();
|
|
}
|
|
if (relCodeDetailRequest.getPage() != null) {
|
|
int offset = (relCodeDetailRequest.getPage() - 1) * relCodeDetailRequest.getLimit();
|
|
PageHelper.offsetPage(offset, relCodeDetailRequest.getLimit());
|
|
}
|
|
return this.baseMapper.filterList(relCodeDetailRequest);
|
|
}
|
|
|
|
}
|