package com.chinaztt.mes.quality.service.impl;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.chinaztt.mes.quality.dto.ZxLabelBindRelationDTO;
|
import com.chinaztt.mes.quality.entity.ZxLabelBindRelation;
|
import com.chinaztt.mes.quality.mapper.ZxLabelBindRelationMapper;
|
import com.chinaztt.mes.quality.service.ZxLabelBindRelationService;
|
import com.google.gson.Gson;
|
import lombok.AllArgsConstructor;
|
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.math.BigDecimal;
|
import java.util.Arrays;
|
import java.util.List;
|
|
/**
|
* @Description : 中兴标签关系绑定
|
* @ClassName : ZxLabelBindRelationServiceImpl
|
* @Author : sll
|
* @Date: 2022-11-30 15:04
|
*/
|
@Service
|
@AllArgsConstructor
|
@Component
|
@Transactional(rollbackFor = Exception.class)
|
public class ZxLabelBindRelationServiceImpl extends ServiceImpl<ZxLabelBindRelationMapper, ZxLabelBindRelation> implements ZxLabelBindRelationService{
|
|
@Override
|
public ZxLabelBindRelation addLabelRelation(ZxLabelBindRelationDTO zxLabelBindRelationDTO){
|
if(null == zxLabelBindRelationDTO.getShopCode() || !zxLabelBindRelationDTO.getShopCode().equals("GD")){
|
throw new RuntimeException("车间代码异常");
|
}
|
|
//校验mes码、pkg码、ce码是否获取成功
|
if(null == zxLabelBindRelationDTO.getMesNode() || null == zxLabelBindRelationDTO.getPkgCode() || null == zxLabelBindRelationDTO.getCeCode()){
|
throw new RuntimeException("标签码数据为空");
|
}
|
|
//解析出所需数据
|
try{
|
List<String> stringList = Arrays.asList(zxLabelBindRelationDTO.getPkgCode().split("&"));
|
if(stringList.size() < 3){
|
//正常的按&切割后是8段,但只有前3段对我们是有用的
|
throw new RuntimeException("PKG码格式错误");
|
}else{
|
ZxLabelBindRelationDTO.PkgNode pkgNode = new ZxLabelBindRelationDTO.PkgNode();
|
pkgNode.setPkgId(stringList.get(0));//pkgid
|
pkgNode.setMaterialCode(stringList.get(1));//物料编码
|
pkgNode.setQuality(new BigDecimal(stringList.get(2)));//数量
|
zxLabelBindRelationDTO.setPkgNode(pkgNode);
|
}
|
}catch(Exception e){
|
throw new RuntimeException("解析pkg码异常 -> " + e.getMessage());
|
}
|
|
//【校验唯一性】
|
//1.mes批次号
|
ZxLabelBindRelation zxLabelBindRelation = baseMapper.selectOne(Wrappers.<ZxLabelBindRelation>lambdaQuery().eq(ZxLabelBindRelation::getLotBatchNo,zxLabelBindRelationDTO.getMesNode().getLot_batch_no()).last("limit 1"));
|
if(null != zxLabelBindRelation){
|
throw new RuntimeException("批次号 = 【" + zxLabelBindRelationDTO.getMesNode().getLot_batch_no() + "】 -> 已存在绑定关系");
|
}
|
//2.pkgid
|
zxLabelBindRelation = baseMapper.selectOne(Wrappers.<ZxLabelBindRelation>lambdaQuery().eq(ZxLabelBindRelation::getPkgId,zxLabelBindRelationDTO.getPkgNode().getPkgId()).last("limit 1"));
|
if(null != zxLabelBindRelation){
|
throw new RuntimeException("pkgid = 【" + zxLabelBindRelationDTO.getPkgNode().getPkgId() + "】 -> 已存在绑定关系");
|
}
|
|
|
//【校验物料码】
|
if(!zxLabelBindRelationDTO.getCeCode().equals(zxLabelBindRelationDTO.getMesNode().getMaterial_code()) || !zxLabelBindRelationDTO.getCeCode().equals(zxLabelBindRelationDTO.getPkgNode().getMaterialCode()) || !zxLabelBindRelationDTO.getMesNode().getMaterial_code().equals(zxLabelBindRelationDTO.getPkgNode().getMaterialCode())){
|
throw new RuntimeException("mes码 -> pkg码 -> ce码物料码不一致");
|
}
|
|
//【校验数量】(mes码中的计量单位是km,pkg码中的计量单位是m)
|
if(zxLabelBindRelationDTO.getMesNode().getQty_arrived().compareTo(zxLabelBindRelationDTO.getPkgNode().getQuality().divide(new BigDecimal("1000"))) != 0){
|
throw new RuntimeException("mes码中生产数量不等于pkg码中生产数量");
|
}
|
|
//校验都通过后新增绑定关系
|
Gson gson = new Gson();
|
zxLabelBindRelationDTO.setMesCode(gson.toJson(zxLabelBindRelationDTO.getMesNode()));//将mesnode转成mescode
|
zxLabelBindRelationDTO.setLotBatchNo(zxLabelBindRelationDTO.getMesNode().getLot_batch_no());//批次号
|
zxLabelBindRelationDTO.setPkgId(zxLabelBindRelationDTO.getPkgNode().getPkgId());//pkgid
|
zxLabelBindRelationDTO.setQuantity(zxLabelBindRelationDTO.getPkgNode().getQuality());//pkg码中的数量
|
zxLabelBindRelationDTO.setPartNo(zxLabelBindRelationDTO.getMesNode().getPart_no());//零件号
|
zxLabelBindRelationDTO.setMaterialCode(zxLabelBindRelationDTO.getMesNode().getMaterial_code());//客户物料编码
|
|
baseMapper.insert(zxLabelBindRelationDTO);//新增标签关系记录
|
|
return zxLabelBindRelationDTO;
|
}
|
}
|