|
|
|
@ -32,9 +32,10 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import java.util.stream.IntStream;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -153,6 +154,8 @@ public class MesReworkTaskServiceImpl implements IMesReworkTaskService {
|
|
|
|
|
public List<MesProductionAssembly> assemblyQuery(MesReworkTaskRequestModel requestModel) {
|
|
|
|
|
DdlPackBean packBean = DdlPackBean.getDdlPackBean(requestModel.getOrganizeCode());
|
|
|
|
|
DdlPreparedPack.getStringEqualPack(requestModel.getCustSn(), "custSn", packBean);
|
|
|
|
|
DdlPreparedPack.getNumEqualPack(requestModel.getIsOrigSn(), "isOrigSn", packBean);
|
|
|
|
|
|
|
|
|
|
//DdlPreparedPack.getStringEqualPack(requestModel.getPartNo(), "partNo", packBean);
|
|
|
|
|
if (!StringUtils.isEmpty(requestModel.getAssemblyPartNo())) {
|
|
|
|
|
DdlPreparedPack.getStringEqualPack(requestModel.getAssemblyPartNo(), "assemblyPartNo", packBean);
|
|
|
|
@ -161,8 +164,6 @@ public class MesReworkTaskServiceImpl implements IMesReworkTaskService {
|
|
|
|
|
DdlPreparedPack.getNumEqualPack(requestModel.getAssemblyPartStatus(), "assemblyStatus", packBean);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DdlPreparedPack.getOrderByPack(new Object[]{CommonEnumUtil.ASC_OR_DESC.ASC.getValue()}, new String[]{"assemblyStatus"}, packBean);
|
|
|
|
|
|
|
|
|
|
List<MesProductionAssembly> mesProductionAssemblies = mesProductionAssemblyRepository.findByHqlWhere(packBean);
|
|
|
|
|
if (CollectionUtils.isEmpty(mesProductionAssemblies)) {
|
|
|
|
|
MesPcnException.throwFlowException("装配件信息不存在");
|
|
|
|
@ -186,37 +187,114 @@ public class MesReworkTaskServiceImpl implements IMesReworkTaskService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean validateSn(MesReworkTaskRequestModel requestModel) {
|
|
|
|
|
//
|
|
|
|
|
List<String> snList = Arrays.asList(requestModel.getSn().split(","));
|
|
|
|
|
List<String> idList = Arrays.asList(requestModel.getAssemblyIds().split(","));
|
|
|
|
|
// 判断数量是否一致
|
|
|
|
|
if (snList.size() != idList.size()) MesPcnException.throwFlowException("选中的装配件个数和输入的个数不一致");
|
|
|
|
|
// 判断顺序是否一致
|
|
|
|
|
Map<String, String> map = IntStream.range(0, snList.size()).boxed().collect(Collectors.toMap(idList::get, snList::get, (a, b) -> b));
|
|
|
|
|
List<Long> idLonglist = idList.stream().map(str -> Long.parseLong(str)).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();
|
|
|
|
|
DdlPreparedPack.getInPackList(idLonglist, "id", ddlPackBean);
|
|
|
|
|
List<MesProductionAssembly> mesProductionAssemblies = mesProductionAssemblyRepository.findByHqlWhere(ddlPackBean);
|
|
|
|
|
if (CollectionUtils.isEmpty(mesProductionAssemblies)) {
|
|
|
|
|
MesPcnException.throwFlowException("装配件记录不存在");
|
|
|
|
|
}
|
|
|
|
|
Map<Long, String> mapProduction = mesProductionAssemblies.stream().collect(Collectors.toMap(mesProductionAssembly -> mesProductionAssembly.getId(), mesProductionAssembly -> mesProductionAssembly.getPartNo()));
|
|
|
|
|
map.forEach((k, v) -> {
|
|
|
|
|
MesProductionAssembly mesProductionAssembly = mesProductionAssemblyRepository.getById(Long.parseLong(k));
|
|
|
|
|
if (!Objects.equals(mapProduction.get(k), mesProductionAssembly.getPartNo())) {
|
|
|
|
|
MesPcnException.throwFlowException(String.format("装配件记录不匹配id=【%s】,sn=【%s】", k, v));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* map id和sn对应关系
|
|
|
|
|
* mapProductionAssemble id 和物料对应关系
|
|
|
|
|
* mapProduceSn 物料和条码对应关系
|
|
|
|
|
*
|
|
|
|
|
* 根据mapProductionAssemble id找map的sn
|
|
|
|
|
* 根据mapProductionAssemble 物料找mmapProduceSn的sn
|
|
|
|
|
* 两者必须一致才允许
|
|
|
|
|
*
|
|
|
|
|
* @param requestModel
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void assemblySnRepeat(MesReworkTaskRequestModel requestModel) {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
//
|
|
|
|
|
List<String> snList = Arrays.asList(requestModel.getSn().split(","));
|
|
|
|
|
List<String> idList = Arrays.asList(requestModel.getAssemblyIds().split(","));
|
|
|
|
|
// 判断数量是否一致
|
|
|
|
|
if (snList.size() != idList.size()) MesPcnException.throwFlowException("选中的装配件个数和输入的个数不一致");
|
|
|
|
|
// 判断顺序是否一致 key = id, value = sn
|
|
|
|
|
Map<String, String> map = IntStream.range(0, snList.size()).boxed().collect(Collectors.toMap(idList::get, snList::get, (a, b) -> b));
|
|
|
|
|
List<Long> idLonglist = idList.stream().map(str -> Long.parseLong(str)).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
// 获取装配件记录列表
|
|
|
|
|
DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();
|
|
|
|
|
DdlPreparedPack.getInPackList(idLonglist, "id", ddlPackBean);
|
|
|
|
|
List<MesProductionAssembly> mesProductionAssemblies = mesProductionAssemblyRepository.findByHqlWhere(ddlPackBean);
|
|
|
|
|
if (CollectionUtils.isEmpty(mesProductionAssemblies)) {
|
|
|
|
|
MesPcnException.throwFlowException("装配件记录不存在");
|
|
|
|
|
}
|
|
|
|
|
Map<Long, String> mapProductionAssemble = mesProductionAssemblies.stream().collect(Collectors.toMap(mesProductionAssembly -> mesProductionAssembly.getId(), mesProductionAssembly -> mesProductionAssembly.getAssemblyPartNo()));
|
|
|
|
|
|
|
|
|
|
// 获取替换条码信息列表
|
|
|
|
|
DdlPackBean snDdlPackBean = DdlPackBean.getDdlPackBean();
|
|
|
|
|
DdlPreparedPack.getInPackList(snList, "productSn", snDdlPackBean);
|
|
|
|
|
List<MesProduceSn> mesProduceSns = mesProduceSnRepository.findByHqlWhere(snDdlPackBean);
|
|
|
|
|
if (CollectionUtils.isEmpty(mesProductionAssemblies)) {
|
|
|
|
|
MesPcnException.throwFlowException("零件条码不存在");
|
|
|
|
|
}
|
|
|
|
|
Map<String, String> mapProduceSn = mesProduceSns.stream().collect(Collectors.toMap(mesProduceSn -> mesProduceSn.getPartNo(), mesProduceSn -> mesProduceSn.getProductSn()));
|
|
|
|
|
|
|
|
|
|
mapProductionAssemble.forEach((k, v) -> {
|
|
|
|
|
String sn = map.get(k + "");
|
|
|
|
|
String newSn = mapProduceSn.get(v);
|
|
|
|
|
if (!Objects.equals(sn, newSn)) {
|
|
|
|
|
MesPcnException.throwFlowException(String.format("装配件记录不匹配id=【%s】,sn=【%s】", k, sn));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
for (String sn : snList) {
|
|
|
|
|
DdlPackBean packBean = DdlPackBean.getDdlPackBean(requestModel.getOrganizeCode());
|
|
|
|
|
DdlPreparedPack.getStringEqualPack(requestModel.getSn(), "productSn", packBean);
|
|
|
|
|
DdlPreparedPack.getStringEqualPack(sn, "productSn", packBean);
|
|
|
|
|
MesProduceSn mesProduceSn = mesProduceSnRepository.getByProperty(packBean);
|
|
|
|
|
if (mesProduceSn == null) {
|
|
|
|
|
MesPcnException.throwFlowException("条码信息不存在");
|
|
|
|
|
}
|
|
|
|
|
requestModel.setAssemblyPartNo(mesProduceSn.getPartNo());
|
|
|
|
|
requestModel.setAssemblyPartStatus(MesExtEnumUtil.ASSEMBLY_STATUS.ASSEMBLY_STATUS_10.getValue());
|
|
|
|
|
List<MesProductionAssembly> mesProductionAssemblies = assemblyQuery(requestModel);
|
|
|
|
|
if (CollectionUtils.isEmpty(mesProductionAssemblies)) {
|
|
|
|
|
List<MesProductionAssembly> mesProductionAssemblieList = assemblyQuery(requestModel);
|
|
|
|
|
if (CollectionUtils.isEmpty(mesProductionAssemblieList)) {
|
|
|
|
|
MesPcnException.throwFlowException("未匹配到该条码的零件号");
|
|
|
|
|
}
|
|
|
|
|
// 需要变更之前的记录
|
|
|
|
|
MesProductionAssembly mesProductionAssembly = mesProductionAssemblies.get(0);
|
|
|
|
|
MesProductionAssembly mesProductionAssembly = mesProductionAssemblieList.get(0);
|
|
|
|
|
mesProductionAssembly.setAssemblyStatus(MesExtEnumUtil.ASSEMBLY_STATUS.ASSEMBLY_STATUS_20.getValue());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 需要新增一条替换条码的记录
|
|
|
|
|
MesProductionAssembly mesProductionRepeatAssembly = new MesProductionAssembly();
|
|
|
|
|
BeanUtils.copyProperties(mesProductionAssembly, mesProductionRepeatAssembly);
|
|
|
|
|
mesProductionRepeatAssembly.setAssemblySn(requestModel.getSn());
|
|
|
|
|
mesProductionRepeatAssembly.setAssemblySn(sn);
|
|
|
|
|
mesProductionRepeatAssembly.setAssemblyStatus(MesExtEnumUtil.ASSEMBLY_STATUS.ASSEMBLY_STATUS_10.getValue());
|
|
|
|
|
mesProductionRepeatAssembly.setId(null);
|
|
|
|
|
mesProductionAssembly.setIsOrigSn(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue());
|
|
|
|
|
|
|
|
|
|
mesProductionAssembly.setRepeatAssemblySn(requestModel.getSn());
|
|
|
|
|
mesProductionAssembly.setRepeatAssemblySn(sn);
|
|
|
|
|
mesProductionAssemblyRepository.update(mesProductionAssembly);
|
|
|
|
|
|
|
|
|
|
mesProductionAssemblyRepository.save(mesProductionRepeatAssembly);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 需要更新NC标记后进入的表明细状态为已处理
|
|
|
|
|
*/
|
|
|
|
@ -225,6 +303,7 @@ public class MesReworkTaskServiceImpl implements IMesReworkTaskService {
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("替换条码异常", e);
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|