jx pcn 采集生产数据

tags/yfai-pcn-ext-v1.0
王杰 1 year ago
parent 75b02b2c0e
commit 5faef47bd6

@ -29,26 +29,26 @@ public class SxThirdPartyPlcCollectCellTaktService implements ISxThirdPartyPlcCo
String organizeCode = paramMap.get(MesPcnExtConstWords.ORGANIZE_CODE); String organizeCode = paramMap.get(MesPcnExtConstWords.ORGANIZE_CODE);
log.info("工厂{}第三方PLC数据采集 --- STRATEGY {} EXEC SERVICE START --- PARAM:{}", organizeCode, MesPcnExtConstWords.COLLECT_CELL_TAKT, paramMap.toString()); log.info("工厂{}第三方PLC数据采集 --- STRATEGY {} EXEC SERVICE START --- PARAM:{}", organizeCode, MesPcnExtConstWords.CELL_TAKT, paramMap.toString());
if (checkOrgIsStopMonitor(organizeCode, paramMap.get(MesPcnExtConstWords.STATUS))) return; if (checkOrgIsStopMonitor(organizeCode, paramMap.get(MesPcnExtConstWords.STATUS))) return;
Map<String, Object> cfgMap = getWorkCellTaktCollectPlcCfgList(organizeCode); Map<String, Object> cfgMap = getWorkCellTaktCollectPlcCfgList(organizeCode);
log.info("工厂{}第三方PLC数据采集 --- STRATEGY {} EXEC SERVICE --- CFGMAP:{}", organizeCode, MesPcnExtConstWords.COLLECT_CELL_TAKT, cfgMap.toString()); log.info("工厂{}第三方PLC数据采集 --- STRATEGY {} EXEC SERVICE --- CFGMAP:{}", organizeCode, MesPcnExtConstWords.CELL_TAKT, cfgMap.toString());
if (!SxThirdPartyPlcCollectDispatchSingleton.getIsInit()) SxThirdPartyPlcCollectDispatchSingleton.getInstance(); if (!SxThirdPartyPlcCollectDispatchSingleton.getIsInit()) SxThirdPartyPlcCollectDispatchSingleton.getInstance();
SxThirdPartyPlcCollectDispatchSingleton.execMonitor(organizeCode, MesPcnExtConstWords.COLLECT_CELL_TAKT, cfgMap, true); SxThirdPartyPlcCollectDispatchSingleton.execMonitor(organizeCode, MesPcnExtConstWords.CELL_TAKT, cfgMap, true);
log.info("工厂{}第三方PLC数据采集 --- STRATEGY {} EXEC SERVICE END ---", organizeCode, MesPcnExtConstWords.COLLECT_CELL_TAKT); log.info("工厂{}第三方PLC数据采集 --- STRATEGY {} EXEC SERVICE END ---", organizeCode, MesPcnExtConstWords.CELL_TAKT);
} }
private Boolean checkOrgIsStopMonitor(String organizeCode, String status) { private Boolean checkOrgIsStopMonitor(String organizeCode, String status) {
if (!StringUtils.isEmpty(status) && status.equals(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValueStr())) return false; if (!StringUtils.isEmpty(status) && status.equals(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValueStr())) return false;
if (SxThirdPartyPlcCollectDispatchSingleton.getIsInit()) SxThirdPartyPlcCollectDispatchSingleton.execMonitor(organizeCode, MesPcnExtConstWords.COLLECT_CELL_TAKT, null, true); if (SxThirdPartyPlcCollectDispatchSingleton.getIsInit()) SxThirdPartyPlcCollectDispatchSingleton.execMonitor(organizeCode, MesPcnExtConstWords.CELL_TAKT, null, true);
log.info("工厂{}第三方PLC数据采集 --- STRATEGY {} EXEC SERVICE END --- MONITOR CLOSED COMPLETED ---", organizeCode, MesPcnExtConstWords.COLLECT_CELL_TAKT); log.info("工厂{}第三方PLC数据采集 --- STRATEGY {} EXEC SERVICE END --- MONITOR CLOSED COMPLETED ---", organizeCode, MesPcnExtConstWords.CELL_TAKT);
return true; return true;
} }
@ -64,7 +64,7 @@ public class SxThirdPartyPlcCollectCellTaktService implements ISxThirdPartyPlcCo
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(SxWorkCellTaktCollectPlcCfg::getPlcCode))), ArrayList::new)); Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(SxWorkCellTaktCollectPlcCfg::getPlcCode))), ArrayList::new));
return CollectionUtils.isEmpty(workCellTaktCollectPlcCfgList) ? new HashMap<>() : return CollectionUtils.isEmpty(workCellTaktCollectPlcCfgList) ? new HashMap<>() :
workCellTaktCollectPlcCfgList.stream().filter(o -> null != o).collect(Collectors.toMap(o -> workCellTaktCollectPlcCfgList.stream().filter(o -> null != o).collect(Collectors.toMap(o ->
new StringJoiner(MesPcnExtConstWords.COLON).add(MesPcnExtConstWords.COLLECT_CELL_TAKT).add(organizeCode).add(o.getWorkCenterCode()).add(o.getWorkCellCode()).toString(), SxWorkCellTaktCollectPlcCfg::getPlcCode)); new StringJoiner(MesPcnExtConstWords.COLON).add(MesPcnExtConstWords.CELL_TAKT).add(organizeCode).add(o.getWorkCenterCode()).add(o.getWorkCellCode()).toString(), SxWorkCellTaktCollectPlcCfg::getPlcCode));
} }
} }

@ -6,6 +6,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.lang.reflect.Constructor;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -67,10 +68,32 @@ public class SxThirdPartyPlcCollectDispatchSingleton {
private static void execMonitorCompute(String org, String busiCode, Map<String, Object> cfgMap) { private static void execMonitorCompute(String org, String busiCode, Map<String, Object> cfgMap) {
for (String key : cfgMap.keySet()) { for (String key : cfgMap.keySet()) {
if (StringUtils.isEmpty(key)) continue; if (StringUtils.isEmpty(key)) continue;
SxThirdPartyPlcCollectMonitorHandler handler = monitorHandlerMap.computeIfAbsent(key, o -> new SxThirdPartyPlcCollectCellTaktMonitorHandler(org, key)); SxThirdPartyPlcCollectMonitorHandler handler = monitorHandlerMap.computeIfAbsent(key, o -> instanceStrategyHandler(busiCode, org, key));
if (null == handler) continue;
handler.doRetry(cfgMap.get(key)); handler.doRetry(cfgMap.get(key));
log.info("工厂{}第三方PLC数据采集 --- STRATEGY {} EXEC SINGLETON --- MONITOR {} KEY: {} ---", org, busiCode, handler.version() ? "ADD" : "RETRY", key); log.info("工厂{}第三方PLC数据采集 --- STRATEGY {} EXEC SINGLETON --- MONITOR {} KEY: {} ---", org, busiCode, handler.version() ? "ADD" : "RETRY", key);
} }
} }
private static SxThirdPartyPlcCollectMonitorHandler instanceStrategyHandler(String busiCode, String org, String key) {
try {
Class clazz = Class.forName(new StringJoiner(MesPcnExtConstWords.DECIMAL_POINT_UNESCAPE)
.add(SxThirdPartyPlcCollectDispatchSingleton.class.getPackage().getName()).add(MesPcnExtConstWords.SX_TPPCM_SUFFIX + busiCode + MesPcnExtConstWords.HANDLER_SUFFIX).toString());
Constructor constructor = clazz.getConstructor(String.class, String.class);
return (SxThirdPartyPlcCollectMonitorHandler) constructor.newInstance(org, key);
} catch (Exception e) {
log.info("工厂{}第三方PLC数据采集 --- STRATEGY {} EXEC SINGLETON --- MONITOR ERROR KEY: {} --- INSTANCE STRATEGY HANDLER ERROR: {} ---", org, busiCode, key, e.getMessage());
return null;
}
}
} }

@ -10,25 +10,25 @@ import java.util.StringJoiner;
/** /**
* PLC-- * PLC--
*/ */
public class SxThirdPartyPlcCollectCellTaktMonitorHandler extends SxThirdPartyPlcCollectMonitorHandler { public class SxThirdPartyPlcCollectMonitorCellTaktHandler extends SxThirdPartyPlcCollectMonitorHandler {
private volatile String plcCode2Flag; private volatile String plcCode2Flag;
private volatile String plcCode2Data; private volatile String plcCode2Data;
public SxThirdPartyPlcCollectCellTaktMonitorHandler(String org, String key) { public SxThirdPartyPlcCollectMonitorCellTaktHandler(String org, String key) {
super(org, key); super(org, key);
initStepResult(); initStepResult();
} }
private void initStepResult() { private void initStepResult() {
((Map<String, Object>) stepResult.getData()).put(MesPcnExtConstWords.BUSI_CODE, MesPcnExtConstWords.COLLECT_CELL_TAKT); ((Map<String, Object>) stepResult.getData()).put(MesPcnExtConstWords.BUSI_CODE, MesPcnExtConstWords.CELL_TAKT);
((Map<String, Object>) stepResult.getData()).put(MesPcnExtConstWords.WORK_CENTER_CODE, key.split(MesPcnExtConstWords.COLON)[2]); ((Map<String, Object>) stepResult.getData()).put(MesPcnExtConstWords.WORK_CENTER_CODE, key.split(MesPcnExtConstWords.COLON)[2]);
((Map<String, Object>) stepResult.getData()).put(MesPcnExtConstWords.WORK_CELL_CODE, key.split(MesPcnExtConstWords.COLON)[3]); ((Map<String, Object>) stepResult.getData()).put(MesPcnExtConstWords.WORK_CELL_CODE, key.split(MesPcnExtConstWords.COLON)[3]);
} }
@Override @Override
public SxThirdPartyPlcCollectCellTaktMonitorHandler doRetry(Object obj) { public SxThirdPartyPlcCollectMonitorCellTaktHandler doRetry(Object obj) {
super.doRetry(obj); super.doRetry(obj);
if (isRetry) return this; if (isRetry) return this;
String[] plcCodeArr = obj.toString().split(MesPcnExtConstWords.COMMA); String[] plcCodeArr = obj.toString().split(MesPcnExtConstWords.COMMA);
@ -56,7 +56,7 @@ public class SxThirdPartyPlcCollectCellTaktMonitorHandler extends SxThirdPartyPl
} }
private void instanceFilterChain() { private void instanceFilterChain() {
filterChain = new SxThirdPartyPlcCollectStepFilterChain(org, key, MesPcnExtConstWords.COLLECT_CELL_TAKT) filterChain = new SxThirdPartyPlcCollectStepFilterChain(org, key, MesPcnExtConstWords.CELL_TAKT)
.clearField(plcCode2Flag, plcCode2Data).sleepTime2UnComplete(1000L).sleepTime2Completed(2000L) .clearField(plcCode2Flag, plcCode2Data).sleepTime2UnComplete(1000L).sleepTime2Completed(2000L)
.add(new SxThirdPartyPlcCollectReadPlcStepService(plcCode2Flag).targetValue(new StringJoiner(MesPcnExtConstWords.COMMA).add(CommonEnumUtil.TRUE_OR_FALSE.TRUE.name().toLowerCase()).add(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValueStr()).toString())) .add(new SxThirdPartyPlcCollectReadPlcStepService(plcCode2Flag).targetValue(new StringJoiner(MesPcnExtConstWords.COMMA).add(CommonEnumUtil.TRUE_OR_FALSE.TRUE.name().toLowerCase()).add(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValueStr()).toString()))
.add(new SxThirdPartyPlcCollectReadPlcStepService(plcCode2Data)) .add(new SxThirdPartyPlcCollectReadPlcStepService(plcCode2Data))

@ -53,9 +53,7 @@ public class SxThirdPartyPlcCollectMonitorHandler {
} }
public void execMonitor() { public void execMonitor() {}
System.out.println("3条34用她4用");
}
public SxThirdPartyPlcCollectMonitorHandler doRetry(Object obj) { public SxThirdPartyPlcCollectMonitorHandler doRetry(Object obj) {
if (version == 0) version ++; if (version == 0) version ++;

@ -0,0 +1,32 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.collect;
/**
* PLC--
*/
public class SxThirdPartyPlcCollectMonitorProductDataHandler extends SxThirdPartyPlcCollectMonitorHandler {
private volatile String plcCode2Flag;
private volatile String plcCode2Data;
public SxThirdPartyPlcCollectMonitorProductDataHandler(String org, String key) {
super(org, key);
initStepResult();
}
private void initStepResult() {
}
@Override
public SxThirdPartyPlcCollectMonitorProductDataHandler doRetry(Object obj) {
return doRetry(obj);
}
@Override
public void execMonitor() {
}
}

@ -9,20 +9,20 @@ import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
* @Description : * @Description :
* @Reference : * @Reference :
* @Author : wangjie * @Author : wangjie
* @CreateDate : 2019-07-11 * @CreateDate : 2019-07-11
* @Modify: * @Modify:
**/ **/
@Slf4j @Slf4j
@Service("jxSnProcessingCollectDataStepService") @Service("jxSnProcessingCollectProductDataStepService")
public class JxSnProcessingCollectDataStepService extends BaseStepService { public class JxSnProcessingCollectProductDataStepService extends BaseStepService {
@Override @Override
public StepResult execute(StationRequestBean reqBean) { public StepResult execute(StationRequestBean reqBean) {
log.info("工厂{}生产线{}工位{}: --- STEP EXECUTE --- JxSnProcessingCollectDataStepService --- START --- ", reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode()); log.info("工厂{}生产线{}工位{}: --- STEP EXECUTE --- JxSnProcessingCollectProductDataStepService --- START --- ", reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode());
StepResult stepResult = StepResult.getSuccessComplete(); StepResult stepResult = StepResult.getSuccessComplete();
@ -31,7 +31,7 @@ public class JxSnProcessingCollectDataStepService extends BaseStepService {
if (StringUtils.isEmpty(reqBean.getSerialNumber()) && StringUtils.isEmpty(reqBean.getProductSn())) return execNonCompleteAndSendMsgReturn(reqBean, resultBean, stepResult, "入参缺少过程条码或产品条码!"); if (StringUtils.isEmpty(reqBean.getSerialNumber()) && StringUtils.isEmpty(reqBean.getProductSn())) return execNonCompleteAndSendMsgReturn(reqBean, resultBean, stepResult, "入参缺少过程条码或产品条码!");
log.info("工厂{}生产线{}工位{}: --- STEP EXECUTE --- JxSnProcessingCollectDataStepService --- SUCCESS --- ", reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode()); log.info("工厂{}生产线{}工位{}: --- STEP EXECUTE --- JxSnProcessingCollectProductDataStepService --- SUCCESS --- ", reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode());
return stepResult; return stepResult;
} }

@ -515,6 +515,8 @@ public class MesPcnExtConstWords {
//-----------------DATE-------------------------- //-----------------DATE--------------------------
//. //.
public static final String DECIMAL_POINT = "\\."; public static final String DECIMAL_POINT = "\\.";
//.
public static final String DECIMAL_POINT_UNESCAPE = ".";
//空格 //空格
public static final String ONE_SPACE = " "; public static final String ONE_SPACE = " ";
//拼接秒 //拼接秒
@ -1024,7 +1026,12 @@ public class MesPcnExtConstWords {
public static final String KEY = "key"; public static final String KEY = "key";
//工位节拍 //工位节拍
public final static String COLLECT_CELL_TAKT = "COLLECT_CELL_TAKT"; public final static String CELL_TAKT = "CellTakt";
//生产数据
public final static String PRODUCT_DATA = "ProductData";
public final static String SX_TPPCM_SUFFIX = "SxThirdPartyPlcCollectMonitor";
public final static String HANDLER_SUFFIX = "Handler";
//业务代码 //业务代码
public static final String BUSI_CODE = "BUSI_CODE"; public static final String BUSI_CODE = "BUSI_CODE";

Loading…
Cancel
Save