|
|
|
@ -15,6 +15,7 @@ import cn.estsh.i3plus.pojo.mes.repository.MesTimeEfficientCfgRepository;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
import java.text.ParseException;
|
|
|
|
@ -59,59 +60,63 @@ public class MesProductionRecordService implements IMesProductionRecordService {
|
|
|
|
|
* DATA_SOURCE20(20, "非排序加工规则"),
|
|
|
|
|
* DATA_SOURCE30(30, "非排序装配件");
|
|
|
|
|
* 排除未知的零件号生产记录
|
|
|
|
|
* @param serialNo 条码 用于查询生产加工记录
|
|
|
|
|
* @param productSn 条码 用于查询生产加工记录
|
|
|
|
|
* @param sourceId 用于获取时效性记录
|
|
|
|
|
* @param organizeCode
|
|
|
|
|
* @param isAssembly 如果是装配件需要查询装配记录
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Map<String, Object> checkSnTimeliness(String organizeCode, String serialNo, Long sourceId, Integer dataSource, Boolean isAssembly) {
|
|
|
|
|
public Map<String, Object> checkSnTimeliness(String organizeCode, String productSn, Long sourceId, Integer dataSource) {
|
|
|
|
|
|
|
|
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
|
//校验成功
|
|
|
|
|
resultMap.put(MesPcnExtConstWords.RESULT, true);
|
|
|
|
|
resultMap.put(MesPcnExtConstWords.RESULT, true);//校验成功
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
//1.根据prodRuleNoSortId 获取 非排序加工规则的 时效性数据 --- 当前的条码需要完全匹配查询的规则
|
|
|
|
|
DdlPackBean timelinessPackBean = DdlPackBean.getDdlPackBean(organizeCode);
|
|
|
|
|
DdlPreparedPack.getNumEqualPack(sourceId, MesPcnExtConstWords.SOURCE_ID, timelinessPackBean);
|
|
|
|
|
List<MesTimeEfficientCfg> timelinessList = timeEfficientCfgRepository.findByHqlWhere(timelinessPackBean);
|
|
|
|
|
|
|
|
|
|
//2.如果timelinessList为空 且 非装配件校验 直接返回true
|
|
|
|
|
if (timelinessList.isEmpty() && !isAssembly){
|
|
|
|
|
return resultMap;
|
|
|
|
|
}
|
|
|
|
|
//查询主条码的逻辑
|
|
|
|
|
if (!isAssembly){
|
|
|
|
|
if (CollectionUtils.isEmpty(timelinessList)) return resultMap;
|
|
|
|
|
|
|
|
|
|
//3.根据条码获取生产加工记录结果
|
|
|
|
|
DdlPackBean recordPackBean = DdlPackBean.getDdlPackBean(organizeCode);
|
|
|
|
|
DdlPreparedPack.getStringEqualPack(serialNo, MesPcnExtConstWords.PRODUCT_SN, recordPackBean);
|
|
|
|
|
List<MesProductionRecord> recordList = productionRecordRepository.findByHqlWhere(recordPackBean);
|
|
|
|
|
boolean checkedResult = checkProductSn(recordList, timelinessList);
|
|
|
|
|
if (!checkedResult){
|
|
|
|
|
resultMap.put(MesPcnExtConstWords.RESULT, false);
|
|
|
|
|
return resultMap;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
if (isAssembly){
|
|
|
|
|
List<MesProductionRecord> productionRecordList = findProductionRecordList(organizeCode, productSn);
|
|
|
|
|
if (CollectionUtils.isEmpty(productionRecordList)) return backResultMap(resultMap, String.format("零件条码[%s]时效性验证失败,未查询到加工记录信息!", productSn));
|
|
|
|
|
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat(MesPcnExtConstWords.DATE_FORMAT);
|
|
|
|
|
for (MesTimeEfficientCfg timeliness : timelinessList) {
|
|
|
|
|
//需要查询装配件记录表 production_assembly productionAssemblyRepository
|
|
|
|
|
DdlPackBean assemblyPackBean = DdlPackBean.getDdlPackBean(organizeCode);
|
|
|
|
|
DdlPreparedPack.getStringEqualPack(serialNo,"assemblySn",assemblyPackBean);
|
|
|
|
|
DdlPreparedPack.getStringEqualPack(timeliness.getCraftCode(),"craftCode",assemblyPackBean);
|
|
|
|
|
List<MesProductionAssembly> productionAssemblyList = productionAssemblyRepository.findByHqlWhere(assemblyPackBean);
|
|
|
|
|
|
|
|
|
|
MesProductionAssembly mesProductionAssembly = productionAssemblyList.get(0);
|
|
|
|
|
String productDateTimeStr = mesProductionAssembly.getCreateDatetime();
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
Date productDateTime = sdf.parse(productDateTimeStr);
|
|
|
|
|
|
|
|
|
|
if (null == timeliness || StringUtils.isEmpty(timeliness.getCraftCode())) continue;
|
|
|
|
|
|
|
|
|
|
List<MesProductionRecord> filterList;
|
|
|
|
|
//时效性规则 零件号不为空或者为空 过滤数据
|
|
|
|
|
if (!StringUtils.isEmpty(timeliness.getPartNo())) filterList = productionRecordList.stream().filter(o -> o.getPartNo().equals(timeliness.getPartNo()) && o.getCraftCode().equals(timeliness.getCraftCode())).sorted(Comparator.comparing(MesProductionRecord::getCreateDatetime).reversed()).collect(Collectors.toList());
|
|
|
|
|
else filterList = productionRecordList.stream().filter(item -> item.getCraftCode().equals(timeliness.getCraftCode())).sorted(Comparator.comparing(MesProductionRecord::getCreateDatetime).reversed()).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(filterList)) return backResultMap(resultMap, String.format("零件条码[%s]时效性零件号[%s]工艺[%s]验证失败,未查询到加工记录信息!", productSn, timeliness.getPartNo(), timeliness.getCraftCode()));
|
|
|
|
|
|
|
|
|
|
//不为空 则 需要校验时效性
|
|
|
|
|
String completeDateTime = filterList.get(0).getCompleteDateTime();
|
|
|
|
|
Date productDateTime = sdf.parse(completeDateTime);
|
|
|
|
|
//时差
|
|
|
|
|
int minDiff = (int) ((now.getTime() - productDateTime.getTime())/(60 * 1000));
|
|
|
|
|
if (!checkTimeliness(timeliness, minDiff)) return backResultMap(resultMap, String.format("零件条码[%s]时效性零件号[%s]工艺[%s]验证失败!", productSn, timeliness.getPartNo(), timeliness.getCraftCode()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resultMap;
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return backResultMap(resultMap, String.format("零件条码[%s]时效性零件号[%s]工艺[%s]验证异常:%s!", productSn, e.toString()));
|
|
|
|
|
}
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<String, Object> backResultMap(Map<String, Object> resultMap, String message) {
|
|
|
|
|
resultMap.put(MesPcnExtConstWords.RESULT, false);
|
|
|
|
|
resultMap.put(MesPcnExtConstWords.MESSAGE, message);
|
|
|
|
|
return resultMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -128,41 +133,6 @@ public class MesProductionRecordService implements IMesProductionRecordService {
|
|
|
|
|
* @param
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private boolean checkProductSn(List<MesProductionRecord> recordList,List<MesTimeEfficientCfg> timelinessList) {
|
|
|
|
|
try {
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
for (MesTimeEfficientCfg timeliness : timelinessList) {
|
|
|
|
|
List<MesProductionRecord> records = new ArrayList<>();
|
|
|
|
|
//时效性规则 零件号不为空
|
|
|
|
|
if (!StringUtils.isEmpty(timeliness.getPartNo())){
|
|
|
|
|
records = recordList.stream().filter(item -> item.getPartNo().equals(timeliness.getPartNo())).sorted(Comparator.comparing(MesProductionRecord::getCompleteDateTime)).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
//时效性规则 工艺不为空时
|
|
|
|
|
if (!StringUtils.isEmpty(timeliness.getCraftCode())){
|
|
|
|
|
records = recordList.stream().filter(item -> item.getCraftCode().equals(timeliness.getCraftCode())).sorted(Comparator.comparing(MesProductionRecord::getCompleteDateTime)).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (records.isEmpty()){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
//不为空 则 需要校验时效性
|
|
|
|
|
MesProductionRecord record = records.get(0);
|
|
|
|
|
String completeDateTime = record.getCompleteDateTime();
|
|
|
|
|
Date productDateTime = sdf.parse(completeDateTime);
|
|
|
|
|
//时差
|
|
|
|
|
int minDiff = (int) ((now.getTime() - productDateTime.getTime())/(60 * 1000));
|
|
|
|
|
if (!checkTimeliness(timeliness, minDiff)){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean checkTimeliness(MesTimeEfficientCfg timeliness, int minDiff) {
|
|
|
|
|
String matchRule = timeliness.getMatchRule();
|
|
|
|
|
Double minValue = timeliness.getMinValue();
|
|
|
|
|