forked from I3-YF/i3plus-mes-pcn-yfai
Compare commits
11 Commits
e9a6bcbc25
...
83a5e9ae35
Author | SHA1 | Date |
---|---|---|
|
83a5e9ae35 | 2 months ago |
|
8cb969b30a | 2 months ago |
|
b42af31686 | 2 months ago |
|
88bd632347 | 2 months ago |
|
ce75150d14 | 2 months ago |
|
e2d09dcbb7 | 2 months ago |
|
0a5d7976c8 | 2 months ago |
|
a57f3e7cb5 | 2 months ago |
|
e181519b04 | 2 months ago |
|
ece6e4f88d | 2 months ago |
|
7cc05f616f | 3 months ago |
@ -0,0 +1,89 @@
|
||||
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.numberrule;
|
||||
|
||||
import cn.estsh.i3plus.ext.mes.pcn.apiservice.util.MesPcnException;
|
||||
import cn.estsh.i3plus.mes.pcn.api.iservice.busi.INumberRulePackAttributeStrategyService;
|
||||
import cn.estsh.i3plus.platform.common.tool.TimeTool;
|
||||
import cn.estsh.i3plus.pojo.mes.model.GenSerialNoModel;
|
||||
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @Description : 出风口条码
|
||||
* @Reference :
|
||||
* @Author : puxiao
|
||||
* @CreateDate : 2025/6/30 18:57
|
||||
* @Modify:
|
||||
**/
|
||||
@Component
|
||||
public class AirOutletCustSnNumberRuleStrategyService implements INumberRulePackAttributeStrategyService {
|
||||
|
||||
|
||||
@Override
|
||||
public GenSerialNoModel execute(GenSerialNoModel genSerialNoModel) {
|
||||
if (null == genSerialNoModel) {
|
||||
MesPcnException.throwMesBusiException("请检查客户零件信息,零件[%s]客户零件关系未维护", genSerialNoModel.getPartNo());
|
||||
|
||||
}
|
||||
Date date = new Date();
|
||||
genSerialNoModel.setYear(getYearShort(date));
|
||||
genSerialNoModel.setMonth(getMonthShort(date));
|
||||
genSerialNoModel.setDay(getDayShort(date));
|
||||
genSerialNoModel.setMinute(getDayOfYear(date));
|
||||
genSerialNoModel.setSecond(getBydMonthShort(date));
|
||||
return genSerialNoModel;
|
||||
}
|
||||
|
||||
|
||||
private String getYearShort(Date date) {
|
||||
return MesExtEnumUtil.YEAR_SHORT.valueOfDescription(Integer.parseInt(TimeTool.getYear(date)));
|
||||
}
|
||||
|
||||
private String getBydMonthShort(Date date) {
|
||||
return MesExtEnumUtil.MONTH_SHORT.valueOfDescription(Integer.parseInt(TimeTool.getYear(date)));
|
||||
}
|
||||
|
||||
private String getMonthShort(Date date) {
|
||||
String monthShort = "";
|
||||
int monthValue = Integer.parseInt(TimeTool.getMonth(date));
|
||||
switch (monthValue){
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
monthShort = String.valueOf(monthValue);
|
||||
break;
|
||||
case 10:
|
||||
monthShort = "0";
|
||||
break;
|
||||
case 11:
|
||||
monthShort = "A";
|
||||
break;
|
||||
case 12:
|
||||
monthShort = "B";
|
||||
break;
|
||||
default:
|
||||
}
|
||||
return monthShort;
|
||||
}
|
||||
|
||||
private String getDayShort(Date date) {
|
||||
return TimeTool.pareDateToString("dd",date);
|
||||
}
|
||||
|
||||
|
||||
private String getDayOfYear(Date date) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR);
|
||||
DecimalFormat df = new DecimalFormat("000");
|
||||
return df.format(dayOfYear);
|
||||
}
|
||||
}
|
@ -0,0 +1,182 @@
|
||||
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.step;
|
||||
|
||||
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesEquipVariableRwExtService;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionProcessContextStepService;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesCellEquipContext;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionProcessContext;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
|
||||
import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.BaseStepService;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.MesPcnEnumUtil;
|
||||
import cn.estsh.i3plus.pojo.mes.bean.MesEquipmentVariable;
|
||||
import cn.estsh.i3plus.pojo.mes.bean.MesEquipmentVariableCfg;
|
||||
import cn.estsh.i3plus.pojo.mes.bean.MesProdRouteOptParam;
|
||||
import cn.estsh.i3plus.pojo.mes.model.MesEquipVariableRwResult;
|
||||
import cn.estsh.i3plus.pojo.mes.model.StationRequestBean;
|
||||
import cn.estsh.i3plus.pojo.mes.model.StationResultBean;
|
||||
import cn.estsh.i3plus.pojo.mes.model.StepResult;
|
||||
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Description : 向PLC点位发送自定义指令工步
|
||||
* @Reference :
|
||||
* @Author : logic
|
||||
* @CreateDate : 2025/6/9 16:58
|
||||
* @Modify:
|
||||
**/
|
||||
@Slf4j
|
||||
@Service("mesSendUserDefinedCmdStepService")
|
||||
public class MesSendUserDefinedCmdStepService extends BaseStepService {
|
||||
|
||||
@Autowired
|
||||
private IMesProductionProcessContextStepService productionProcessContextStepService;
|
||||
|
||||
@Autowired
|
||||
private IMesEquipVariableRwExtService equipVariableRwExtService;
|
||||
|
||||
@Override
|
||||
public StepResult execute(StationRequestBean reqBean) {
|
||||
|
||||
StepResult stepResult = StepResult.getSuccessComplete();
|
||||
|
||||
StationResultBean resultBean = new StationResultBean();
|
||||
|
||||
//获取工步参数
|
||||
Optional<Map<String, MesProdRouteOptParam>> stepParamMap = getStepParams(reqBean);
|
||||
|
||||
//获取上下文信息
|
||||
MesProductionProcessContext productionProcessContext =
|
||||
productionProcessContextStepService.dispatchCurCellEquipment(reqBean, stepParamMap);
|
||||
|
||||
//获取生产过程上下文对象有异常信息 抛出异常
|
||||
if (!productionProcessContextStepService.getEquipmentVariableCfgList(productionProcessContext).getSuccess()) {
|
||||
stepExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), productionProcessContext.getMessage());
|
||||
}
|
||||
|
||||
//从上下文的设备数据变量接口逻辑对象集合中取出当前设备信息的逻辑类型对应的接口逻辑对象集合
|
||||
List<MesEquipmentVariableCfg> equipmentVariableCfgList = productionProcessContext.getEquipVariableCfgListByVct();
|
||||
|
||||
//根据变量类别[用户自定义指令]搜集设备数据变量接口逻辑信息
|
||||
String userDefinedEquipVariableCfgCategory = (
|
||||
null != stepParamMap &&
|
||||
stepParamMap.isPresent() &&
|
||||
stepParamMap.get().containsKey(MesPcnExtConstWords.USER_DEFINED_EQUIP_VARIABLE_CFG_CATEGORY)) ?
|
||||
stepParamMap.get().get(MesPcnExtConstWords.USER_DEFINED_EQUIP_VARIABLE_CFG_CATEGORY).getParamValue() :
|
||||
null;
|
||||
equipmentVariableCfgList = productionProcessContextStepService.collectEquipmentVariableCfgList(
|
||||
equipmentVariableCfgList, userDefinedEquipVariableCfgCategory);
|
||||
|
||||
//当前工位使用的设备
|
||||
MesCellEquipContext cellEquipContext = productionProcessContext.getCurCellEquip();
|
||||
|
||||
//配置错误 抛出异常
|
||||
if (!productionProcessContextStepService.checkNecessaryEquipmentVariableCfgAndValue(productionProcessContext,
|
||||
cellEquipContext, equipmentVariableCfgList, userDefinedEquipVariableCfgCategory).getSuccess()) {
|
||||
stepExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), productionProcessContext.getMessage());
|
||||
}
|
||||
|
||||
//搜集设备数据变量接口逻辑信息中的二级变量
|
||||
List<String> categoryLevelTwoList = productionProcessContextStepService.collectCategoryLevelTwoList(equipmentVariableCfgList);
|
||||
|
||||
//根据变量类型与二级变量获取设备数据变量信息
|
||||
List<MesEquipmentVariable> equipmentVariableList = productionProcessContextStepService.findEquipmentVariableList(
|
||||
productionProcessContext, MesExtEnumUtil.EQUIP_VARIABLE_TYPE.PRODUCTION.getValue(), categoryLevelTwoList);
|
||||
|
||||
//配置错误 抛出异常
|
||||
if (!productionProcessContextStepService.checkIsEmptyEquipmentVariableList(productionProcessContext,
|
||||
cellEquipContext, equipmentVariableList, MesExtEnumUtil.EQUIP_VARIABLE_TYPE.PRODUCTION, categoryLevelTwoList).getSuccess()) {
|
||||
stepExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), productionProcessContext.getMessage());
|
||||
}
|
||||
|
||||
//存储生产过程上下文对象
|
||||
productionProcessContextStepService.dispatchProductionProcessContext(reqBean, productionProcessContext);
|
||||
|
||||
//发送数据给设备的数据变量
|
||||
return execSendInitializationCmd(reqBean, resultBean, stepParamMap, stepResult, cellEquipContext,
|
||||
equipmentVariableCfgList, equipmentVariableList,
|
||||
cellEquipContext.getKepwareFlag(equipmentVariableList.get(0).getChannel()));
|
||||
|
||||
}
|
||||
|
||||
private StepResult execSendInitializationCmd(StationRequestBean reqBean, StationResultBean resultBean,
|
||||
Optional<Map<String, MesProdRouteOptParam>> stepParamMap,
|
||||
StepResult stepResult, MesCellEquipContext cellEquipContext,
|
||||
List<MesEquipmentVariableCfg> equipmentVariableCfgList,
|
||||
List<MesEquipmentVariable> equipmentVariableList, String kepwareFlag) {
|
||||
|
||||
//最大重试次数[工步参数]
|
||||
Integer maxRetryTimes = getMaxRetryTimes(stepParamMap);
|
||||
|
||||
MesEquipVariableRwResult equipVariableRwResult = null;
|
||||
|
||||
Map<String, List<MesEquipmentVariableCfg>> categoryLevelTwoMap = equipmentVariableCfgList.stream().filter(
|
||||
Objects::nonNull).collect(Collectors.groupingBy(MesEquipmentVariableCfg::getCategoryLevelTwo));
|
||||
|
||||
for (int i = 1; i <= maxRetryTimes; i ++) {
|
||||
|
||||
//写值
|
||||
for (MesEquipmentVariable equipmentVariable : equipmentVariableList) {
|
||||
|
||||
equipVariableRwResult = equipVariableRwExtService.writeVariable(
|
||||
categoryLevelTwoMap.get(equipmentVariable.getCategoryLevelTwo()).get(0), equipmentVariable, kepwareFlag);
|
||||
|
||||
if (equipVariableRwResult.getIsSuccessed()) {
|
||||
this.sendMessage(reqBean, new StationResultBean().writeDbLog().checkRepeat(),
|
||||
String.format("[%s]%s", cellEquipContext.getEquipmentName(), equipVariableRwResult.getMessage()),
|
||||
MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
|
||||
} else {
|
||||
this.sendMessage(reqBean, new StationResultBean().writeDbLog().checkRepeat(),
|
||||
String.format("设备[%s]:自定义指令发送失败!原因:%s", cellEquipContext.getEquipmentName(),
|
||||
JSONObject.toJSONString(equipVariableRwResult)), MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO,
|
||||
MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!equipVariableRwResult.getIsSuccessed() && equipVariableRwResult.getIsNoCfg()) {
|
||||
stepExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), String.format("设备[%s]:自定义指令发送失败!原因:%s",
|
||||
cellEquipContext.getEquipmentName(), equipVariableRwResult.getMessage()));
|
||||
}
|
||||
|
||||
if (equipVariableRwResult.getIsSuccessed()) {
|
||||
return stepSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, String.format("设备[%s]:自定义指令发送成功!", cellEquipContext.getEquipmentName()));
|
||||
}
|
||||
|
||||
stepNonCompleteAndSendMsg(reqBean, resultBean.writeDbLog().checkRepeat(), stepResult, String.format("设备[%s]:自定义指令发送失败!累计次数[%s]!原因:%s", cellEquipContext.getEquipmentName(), i, equipVariableRwResult.getMessage()));
|
||||
|
||||
//每失败一次 睡眠
|
||||
if (i != maxRetryTimes) {
|
||||
threadSleep(stepParamMap, MesPcnExtConstWords.READ_FAILURE_SLEEP, MesPcnExtConstWords.READ_FAILURE_SLEEP_DEFAULT_TIME);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
stepSendTaskCompleteAndThrowEx(reqBean, stepResult, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
|
||||
|
||||
return stepResult;
|
||||
|
||||
}
|
||||
|
||||
//最大重试次数[工步参数]
|
||||
private Integer getMaxRetryTimes(Optional<Map<String, MesProdRouteOptParam>> stepParamMap) {
|
||||
Integer maxRetryTimes = null;
|
||||
try {
|
||||
maxRetryTimes = (null != stepParamMap && stepParamMap.isPresent() &&
|
||||
stepParamMap.get().containsKey(MesPcnExtConstWords.MAX_RETRY_TIMES)) ?
|
||||
Integer.valueOf(stepParamMap.get().get(MesPcnExtConstWords.MAX_RETRY_TIMES).getParamValue()) : null;
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
return !StringUtils.isEmpty(maxRetryTimes) ? maxRetryTimes : MesPcnExtConstWords.MAX_RETRY_TIMES_DEFAULT;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue