时效性验证

tags/yfai-pcn-ext-v1.0
王杰 11 months ago
parent 434c87fde3
commit 1d6bd87867

@ -17,7 +17,7 @@ public interface IMesProductionRecordService {
/**
*
* @param serialNo
* @param productSn
* @param sourceId
* @param dataSource ,,
*
@ -27,7 +27,7 @@ public interface IMesProductionRecordService {
* DATA_SOURCE30(30, "非排序装配件");
*
*/
Map<String, Object> checkSnTimeliness(String organizeCode, String serialNo, Long sourceId, Integer dataSource, Boolean isAssembly);
Map<String, Object> checkSnTimeliness(String organizeCode, String productSn, Long sourceId, Integer dataSource);
@ApiOperation(value = "根据零件条码查询加工记录信息")
List<MesProductionRecord> findProductionRecordList(String organizeCode, String productSn);

@ -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);
//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){
//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;
}
}
resultMap.put(MesPcnExtConstWords.RESULT, true);//校验成功
try {
if (isAssembly){
Date now = new Date();
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);
//时差
int minDiff = (int) ((now.getTime() - productDateTime.getTime())/(60 * 1000));
}
//1.根据prodRuleNoSortId 获取 非排序加工规则的 时效性数据 --- 当前的条码需要完全匹配查询的规则
DdlPackBean timelinessPackBean = DdlPackBean.getDdlPackBean(organizeCode);
DdlPreparedPack.getNumEqualPack(sourceId, MesPcnExtConstWords.SOURCE_ID, timelinessPackBean);
List<MesTimeEfficientCfg> timelinessList = timeEfficientCfgRepository.findByHqlWhere(timelinessPackBean);
//2.如果timelinessList为空 且 非装配件校验 直接返回true
if (CollectionUtils.isEmpty(timelinessList)) return resultMap;
//3.根据条码获取生产加工记录结果
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) {
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()));
}
} catch (ParseException e) {
throw new RuntimeException(e);
return resultMap;
} catch (Exception e) {
return backResultMap(resultMap, String.format("零件条码[%s]时效性零件号[%s]工艺[%s]验证异常:%s!", productSn, e.toString()));
}
}
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();

@ -55,6 +55,9 @@ public class MesAssemblyGeneratePartNoStepService extends BaseStepService {
@Autowired
private IMesProdRuleCfgExtService prodRuleCfgExtService;
@Autowired
private IMesProductionRecordService productionRecordService;
@Override
public StepResult execute(StationRequestBean reqBean) {
@ -109,7 +112,7 @@ public class MesAssemblyGeneratePartNoStepService extends BaseStepService {
//判断是否存在未消费的装配件条码
Optional<MesEquipVariableCollectContext> optional = equipVariableCollectContextList.stream().filter(o -> (null != o && o.getIsConsume().compareTo(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()) == 0)).findFirst();
if (CollectionUtils.isEmpty(prodRuleContextList) || (null != optional && optional.isPresent()))
return execNonCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog().scanInfo(assemblySn), stepResult, String.format("上下文中的装配件条码%s匹配失败!", assemblySn));
return execNonCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog().scanInfo(assemblySn), stepResult, String.format("上下文中的装配件条码%s匹配失败!%s", assemblySn, StringUtils.isEmpty(stepResult.getMsg()) ? MesPcnExtConstWords.EMPTY : stepResult.getMsg()));
//保存上下文产品加工规则信息集合
productionDispatchContextStepService.saveProdRuleDataContext(reqBean, prodRuleContextList);
@ -190,8 +193,17 @@ public class MesAssemblyGeneratePartNoStepService extends BaseStepService {
//匹配失败
if (CollectionUtils.isEmpty(filterList)) continue;
//时效性验证
if (!StringUtils.isEmpty(filterList.get(0).getProductSnId())) {
Map<String, Object> result = productionRecordService.checkSnTimeliness(reqBean.getOrganizeCode(), equipVariableCollectContext.getEquipVariableValue(), filterList.get(0).getSourceId(), MesExtEnumUtil.TIME_DATA_SOURCE.DATA_SOURCE30.getValue());
if (!(Boolean)result.get(MesPcnExtConstWords.RESULT)) {
stepResult.msg(String.format("%s%s", StringUtils.isEmpty(stepResult.getMsg()) ? MesPcnExtConstWords.EMPTY : stepResult.getMsg(), result.get(MesPcnExtConstWords.MESSAGE)));
continue;
}
}
//装配件清单该数据标记已装配
productionAssemblyNosortContext.assemblyStatus().assemblySn(equipVariableCollectContext.getEquipVariableValue());
productionAssemblyNosortContext.assemblyStatus().assemblySn(equipVariableCollectContext.getEquipVariableValue()).productSnId(filterList.get(0).getProductSnId());
}

@ -22,6 +22,7 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -127,7 +128,8 @@ public class MesAssemblyMatchNosortStepService extends BaseStepService {
if (result) return execDynamicsCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog().scanInfo(assemblySn),
stepResult.nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_ASSEMBLY), false, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT, String.format("上下文中的装配件条码%s匹配成功!", assemblySn));
return execNonCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog().scanInfo(assemblySn), stepResult.nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_ASSEMBLY), String.format("上下文中的装配件条码%s匹配失败!", assemblySn));
return execNonCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog().scanInfo(assemblySn),
stepResult.nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_ASSEMBLY), String.format("上下文中的装配件条码%s匹配失败!%s", assemblySn, StringUtils.isEmpty(stepResult.getMsg()) ? MesPcnExtConstWords.EMPTY : stepResult.getMsg()));
}
@ -183,9 +185,14 @@ public class MesAssemblyMatchNosortStepService extends BaseStepService {
//匹配失败
if (CollectionUtils.isEmpty(filterList)) continue;
//TODO 判断类型 提示信息
if (!(Boolean) productionRecordService.checkSnTimeliness(
reqBean.getOrganizeCode(), equipVariableCollectContext.getEquipVariableValue(), filterList.get(0).getSourceId(), MesExtEnumUtil.TIME_DATA_SOURCE.DATA_SOURCE30.getValue(), true).get(MesPcnExtConstWords.RESULT)) continue;
//时效性验证
if (!StringUtils.isEmpty(filterList.get(0).getProductSnId())) {
Map<String, Object> result = productionRecordService.checkSnTimeliness(reqBean.getOrganizeCode(), equipVariableCollectContext.getEquipVariableValue(), filterList.get(0).getSourceId(), MesExtEnumUtil.TIME_DATA_SOURCE.DATA_SOURCE30.getValue());
if (!(Boolean)result.get(MesPcnExtConstWords.RESULT)) {
stepResult.msg(String.format("%s%s", StringUtils.isEmpty(stepResult.getMsg()) ? MesPcnExtConstWords.EMPTY : stepResult.getMsg(), result.get(MesPcnExtConstWords.MESSAGE)));
continue;
}
}
//匹配成功
equipVariableCollectContext.isConsume();

@ -197,11 +197,14 @@ public class MesAssemblyShowNosortStepService extends BaseStepService {
"请检查非排序产品加工规则信息,根据设备[%s]进料零件条码[%s]查询到[%s]条加工规则配置信息,无法显示出装配件清单!", cellEquipContext.getEquipmentName(), productionPsInContext.getProductSn(), CollectionUtils.isEmpty(filterList) ? MesPcnExtConstWords.ZERO : filterList.size()));
}
if (!StringUtils.isEmpty(productionPsInContext.getPartNo()) && !(Boolean) productionRecordService.checkSnTimeliness(
reqBean.getOrganizeCode(), productionPsInContext.getProductSn(), filterList.get(0).getId(), MesExtEnumUtil.TIME_DATA_SOURCE.DATA_SOURCE20.getValue(), false).get(MesPcnExtConstWords.RESULT)) {
if (productionPsInContext.getMessageSource().compareTo(MesExtEnumUtil.CELL_MESSAGE_SOURCE.SCAN.getValue()) == 0) productionPsInContext.busiCheckToDelete();
else productionPsInContextList.forEach(o -> o.busiCheckToDelete());
return execNonCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog().scanInfo(productionPsInContext.getProductSn()), stepResult, String.format("请检查进料主条码信息,进料主条码[%s]时效性验证不通过!", productionPsInContext.getProductSn()));
//时效性验证
if (!StringUtils.isEmpty(productionPsInContext.getPartNo())) {
Map<String, Object> result = productionRecordService.checkSnTimeliness(reqBean.getOrganizeCode(), productionPsInContext.getProductSn(), filterList.get(0).getId(), MesExtEnumUtil.TIME_DATA_SOURCE.DATA_SOURCE20.getValue());
if (!(Boolean)result.get(MesPcnExtConstWords.RESULT)) {
if (productionPsInContext.getMessageSource().compareTo(MesExtEnumUtil.CELL_MESSAGE_SOURCE.SCAN.getValue()) == 0) productionPsInContext.busiCheckToDelete();
else productionPsInContextList.forEach(o -> o.busiCheckToDelete());
return execNonCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog().scanInfo(productionPsInContext.getProductSn()), stepResult, (String) result.get(MesPcnExtConstWords.MESSAGE));
}
}
//【非排序线】获取产品加工规则对应的装配件信息
@ -261,11 +264,14 @@ public class MesAssemblyShowNosortStepService extends BaseStepService {
if (CollectionUtils.isEmpty(innerfilterList) || innerfilterList.size() > 1) continue;
if (!StringUtils.isEmpty(productionPsInContext.getPartNo()) && !(Boolean) productionRecordService.checkSnTimeliness(
reqBean.getOrganizeCode(), productionPsInContext.getProductSn(), innerfilterList.get(0).getId(), MesExtEnumUtil.TIME_DATA_SOURCE.DATA_SOURCE20.getValue(), false).get(MesPcnExtConstWords.RESULT)) {
if (productionPsInContext.getMessageSource().compareTo(MesExtEnumUtil.CELL_MESSAGE_SOURCE.SCAN.getValue()) == 0) productionPsInContext.busiCheckToDelete();
else productionPsInContextList.forEach(o -> o.busiCheckToDelete());
return execNonCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog().scanInfo(productionPsInContext.getProductSn()), stepResult, String.format("请检查进料主条码信息,进料主条码[%s]时效性验证不通过!", productionPsInContext.getProductSn()));
//时效性验证
if (!StringUtils.isEmpty(productionPsInContext.getPartNo())) {
Map<String, Object> result = productionRecordService.checkSnTimeliness(reqBean.getOrganizeCode(), productionPsInContext.getProductSn(), innerfilterList.get(0).getId(), MesExtEnumUtil.TIME_DATA_SOURCE.DATA_SOURCE20.getValue());
if (!(Boolean)result.get(MesPcnExtConstWords.RESULT)) {
if (productionPsInContext.getMessageSource().compareTo(MesExtEnumUtil.CELL_MESSAGE_SOURCE.SCAN.getValue()) == 0) productionPsInContext.busiCheckToDelete();
else productionPsInContextList.forEach(o -> o.busiCheckToDelete());
return execNonCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog().scanInfo(productionPsInContext.getProductSn()), stepResult, (String) result.get(MesPcnExtConstWords.MESSAGE));
}
}
productionPartContext.foreignKey(productionPsInContext.foreignKey(foreignKey += 1).getForeignKey());

@ -141,6 +141,11 @@ public class MesPcnExtConstWords {
public static final String CELL_MESSAGE_SOURCE = "cellMessageSource";
// 结果
public static final String RESULT = "result";
// 信息
public static final String MESSAGE = "message";
// 时间格式
public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
//设备数据变量读写访问配置

Loading…
Cancel
Save