时效性验证接口

tags/yfai-pcn-ext-v1.0
administrator 11 months ago
parent f8b0ae62f4
commit f64efdb8a5

@ -0,0 +1,27 @@
package cn.estsh.i3plus.ext.mes.pcn.api.busi;
import java.util.Map;
/**
* @Description :
* @Reference :
* @Author : Castle
* @CreateDate : 2024/6/20 21:05
* @Modify:
**/
public interface IMesProductionRecordService {
/**
*
* @param sn
* @param prodRuleNoSortId
* @param dataSource ,,
*
* MesExtEnumUtil.TIME_DATA_SOURCE
* DATA_SOURCE10(10, "排序加工规则"),
* DATA_SOURCE20(20, "非排序加工规则"),
* DATA_SOURCE30(30, "非排序装配件");
*
*/
Map<String,Object> checkSnTimeliness(String sn, Long prodRuleNoSortId , String organizeCode , Integer dataSource ,Boolean isAssembly);
}

@ -0,0 +1,190 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionRecordService;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import cn.estsh.i3plus.pojo.mes.bean.MesProductionAssembly;
import cn.estsh.i3plus.pojo.mes.bean.MesProductionRecord;
import cn.estsh.i3plus.pojo.mes.bean.MesTimeEfficientCfg;
import cn.estsh.i3plus.pojo.mes.repository.MesProductionAssemblyRepository;
import cn.estsh.i3plus.pojo.mes.repository.MesProductionRecordRepository;
import cn.estsh.i3plus.pojo.mes.repository.MesTimeEfficientCfgRepository;
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Description :
* @Reference :
* @Author : Castle
* @CreateDate : 2024/6/20 21:20
* @Modify:
**/
@Service
public class MesProductionRecordServiceImpl implements IMesProductionRecordService {
@Autowired
private MesTimeEfficientCfgRepository mesTimeEfficientCfgRao;
@Autowired
private MesProductionRecordRepository mesProductionRecordRao;
@Autowired
private MesProductionAssemblyRepository mesProductionAssemblyRao;
/**
* :
* 0.
* 1.
* 1.1 ; true
* 1.2 ,
* 1.2.1
* 1.2.2
* 2.
* 2.1 --
* 2.2
* 2.3 ,
*
* timeDataSource + sourceId MES_TIME_EFFICIENT_CFG
* DATA_SOURCE10(10, "排序加工规则"),
* DATA_SOURCE20(20, "非排序加工规则"),
* DATA_SOURCE30(30, "非排序装配件");
*
* @param sn
* @param sourceId
* @param organizeCode
* @param isAssembly
* @return
*/
@Override
public Map<String, Object> checkSnTimeliness(String sn, Long sourceId ,String organizeCode ,Integer timeDataSource , Boolean isAssembly) {
Map<String, Object> resultMap = new HashMap<>();
//校验成功
resultMap.put("result", true);
//1.根据prodRuleNoSortId 获取 非排序加工规则的 时效性数据 --- 当前的条码需要完全匹配查询的规则
DdlPackBean timelinessPackBean = DdlPackBean.getDdlPackBean(organizeCode);
DdlPreparedPack.getNumEqualPack(sourceId,"sourceId",timelinessPackBean);
List<MesTimeEfficientCfg> timelinessList = mesTimeEfficientCfgRao.findByHqlWhere(timelinessPackBean);
//2.如果timelinessList为空 且 非装配件校验 直接返回true
if (timelinessList.isEmpty() && !isAssembly){
return resultMap;
}
//查询主条码的逻辑
if (!isAssembly){
//3.根据条码获取生产加工记录结果
DdlPackBean recordPackBean = DdlPackBean.getDdlPackBean(organizeCode);
DdlPreparedPack.getStringEqualPack(sn,"productSn",recordPackBean);
List<MesProductionRecord> recordList = mesProductionRecordRao.findByHqlWhere(recordPackBean);
boolean checkedResult = checkProductSn(recordList, timelinessList);
if (!checkedResult){
resultMap.put("result", false);
return resultMap;
}
}
try {
if (isAssembly){
Date now = new Date();
for (MesTimeEfficientCfg timeliness : timelinessList) {
//需要查询装配件记录表 production_assembly mesProductionAssemblyRao
DdlPackBean assemblyPackBean = DdlPackBean.getDdlPackBean(organizeCode);
DdlPreparedPack.getStringEqualPack(sn,"assemblySn",assemblyPackBean);
DdlPreparedPack.getStringEqualPack(timeliness.getCraftCode(),"craftCode",assemblyPackBean);
List<MesProductionAssembly> productionAssemblyList = mesProductionAssemblyRao.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));
}
}
} catch (ParseException e) {
throw new RuntimeException(e);
}
return resultMap;
}
/**
* MATCH_RULE_10("10", "生产时间小于装配件有效期"),
* MATCH_RULE_20("20", "小于最小时差有效"),
* MATCH_RULE_30("30", "大于最小时差有效"),
* MATCH_RULE_40("40", "最大最小时差有效"),
* MATCH_RULE_50("50", "最大外或最小内有效");
*
*
*
*
* @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.isNoneBlank(timeliness.getPartNo())){
records = recordList.stream().filter(item -> item.getPartNo().equals(timeliness.getPartNo())).sorted(Comparator.comparing(MesProductionRecord::getCompleteDateTime)).collect(Collectors.toList());
}
//时效性规则 工艺不为空时
if (StringUtils.isNoneBlank(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();
Double maxValue = timeliness.getMaxValue();
if (MesExtEnumUtil.MATCH_RULE.MATCH_RULE_20.getValue().equals(matchRule)) {
//差值 大于等于最小值
if (minDiff >= minValue){
return false;
}
} else if (MesExtEnumUtil.MATCH_RULE.MATCH_RULE_30.getValue().equals(matchRule)) {
// 差值 小于等于最大值
if (minDiff <= minValue){
return false;
}
} else if (MesExtEnumUtil.MATCH_RULE.MATCH_RULE_40.getValue().equals(matchRule)) {
// 差值 在 最大值 最小值之间
if (minDiff <= minValue || minDiff >= maxValue){
return false;
}
} else if (MesExtEnumUtil.MATCH_RULE.MATCH_RULE_50.getValue().equals(matchRule)) {
// 差值 在 最小值之间
if (minDiff >= minValue && maxValue <= minDiff){
return false;
}
}
return true;
}
}

@ -53,6 +53,8 @@ public class MesProductSnPrintStepService extends BaseStepService {
* labelTemplateParamList: List<Map<String,Object>>
* }
*
* foreign
*
*/
String organizeCode = reqBean.getOrganizeCode();
StationResultBean resultBean = new StationResultBean();
@ -67,6 +69,9 @@ public class MesProductSnPrintStepService extends BaseStepService {
//2. 获取条码需要模板、模板代码、打印机 --- 循环遍历条码 封装数据
for (MesProductionPsOutContext sn : productionPsOutContextList) {
String prodLabelTemplate = sn.getProdLabelTemplate();
if (prodLabelTemplate == null) {
execExpSendMsgAndThrowEx(reqBean, resultBean, String.format("零件号[%s]的模板代码[%s]的模板信息丢失,请配置!", sn.getPartNo(), prodLabelTemplate));
}
MesLabelTemplate labelTemplate;
// 查模板代码
if (!labelTemplateMap.containsKey(prodLabelTemplate)) {
@ -120,6 +125,7 @@ public class MesProductSnPrintStepService extends BaseStepService {
data.put("valueList", dataMaps);
printData.add(data);
}
//前端接收到busiTyep是customComponent并且 dataType是file类型的消息就需要打印后续消息里的数据一个模板对应多个打印数据
resultBean.setBusiType(MesPcnEnumUtil.STATION_BUSI_TYPE.CUSTOM_COMPONENT.getValue());
resultBean.setDataType(MesPcnEnumUtil.STATION_DATA_TYPE.FILE.getValue());
@ -127,6 +133,7 @@ public class MesProductSnPrintStepService extends BaseStepService {
//3. 发送数据给到前端
this.sendMessage(reqBean, resultBean);
//todo 更新打印状态
return stepResult;
}

Loading…
Cancel
Save