diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/collect/SxThirdPartyPlcCollectCellTaktDispatchSingleton.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/collect/SxThirdPartyPlcCollectCellTaktDispatchSingleton.java deleted file mode 100644 index 22d0fd0..0000000 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/collect/SxThirdPartyPlcCollectCellTaktDispatchSingleton.java +++ /dev/null @@ -1,73 +0,0 @@ -package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.collect; - -import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords; -import com.alibaba.fastjson.JSONObject; -import lombok.extern.slf4j.Slf4j; -import org.springframework.util.CollectionUtils; -import org.springframework.util.StringUtils; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; - -/** - * 采集工位节拍调度单例模式 - */ -@Slf4j -public class SxThirdPartyPlcCollectCellTaktDispatchSingleton { - - protected volatile static Boolean isInit = false; - - private static class SxCellTaktDispatchHolder { private final static SxThirdPartyPlcCollectCellTaktDispatchSingleton INSTANCE = new SxThirdPartyPlcCollectCellTaktDispatchSingleton(); } - - public static SxThirdPartyPlcCollectCellTaktDispatchSingleton getInstance() { return SxCellTaktDispatchHolder.INSTANCE; } - - private SxThirdPartyPlcCollectCellTaktDispatchSingleton() { isInit = true; } - - private volatile static Map cellTaktMonitorMap = new ConcurrentHashMap<>(); - - public static Boolean getIsInit() { return isInit; } - - public static synchronized void execMonitor(String org, Map cfgMap) { - if (CollectionUtils.isEmpty(cfgMap)) execMonitorRemove(org, getCellTaktMonitorMapKeyList(org)); - else execMonitorCompareToCfg(org, cfgMap); - } - - private static void execMonitorRemove(String org, List removeKeyList) { - log.info("工厂{}第三方PLC数据采集 --- {} STRATEGY EXEC SINGLETON --- MONITOR CLOSED KEY: {} --- START ---", org, MesPcnExtConstWords.COLLECT_CELL_TAKT, CollectionUtils.isEmpty(removeKeyList) ? MesPcnExtConstWords.EMPTY : JSONObject.toJSONString(removeKeyList)); - if (!CollectionUtils.isEmpty(removeKeyList)) removeKeyList.stream().forEach(SxThirdPartyPlcCollectCellTaktDispatchSingleton::execMonitorRemove); - } - - private static void execMonitorCompareToCfg(String org, Map cfgMap) { - List cellTaktMonitorMapKeyList = getCellTaktMonitorMapKeyList(org); - List removeKeyList = CollectionUtils.isEmpty(cellTaktMonitorMapKeyList) ? null : cellTaktMonitorMapKeyList.stream().filter(o -> (!StringUtils.isEmpty(o) && !cfgMap.containsKey(o))).collect(Collectors.toList()); - execMonitorRemove(org, removeKeyList); - execMonitorCompute(org, cfgMap); - } - - private static List getCellTaktMonitorMapKeyList(String org) { - List cellTaktMonitorMapKeyList = CollectionUtils.isEmpty(cellTaktMonitorMap) ? null : new ArrayList<>(cellTaktMonitorMap.keySet()); - return CollectionUtils.isEmpty(cellTaktMonitorMapKeyList) ? null : cellTaktMonitorMapKeyList.stream().filter(o -> (!StringUtils.isEmpty(o) && o.split(MesPcnExtConstWords.COLON)[1].equals(org))).collect(Collectors.toList()); - } - - private static void execMonitorRemove(String key) { - SxThirdPartyPlcCollectCellTaktMonitorHandler handler = cellTaktMonitorMap.get(key); - handler.cancel(); - cellTaktMonitorMap.remove(key); - log.info("工厂{}第三方PLC数据采集 --- {} STRATEGY EXEC SINGLETON --- MONITOR CLOSED KEY: {} ---", key.split(MesPcnExtConstWords.COLON)[1], MesPcnExtConstWords.COLLECT_CELL_TAKT, key); - } - - private static void execMonitorCompute(String org, Map cfgMap) { - for (String key : cfgMap.keySet()) { - if (StringUtils.isEmpty(key)) continue; - String[] plcCodeArr = cfgMap.get(key).split(MesPcnExtConstWords.COMMA); - if (null == plcCodeArr || plcCodeArr.length != 2) continue; - SxThirdPartyPlcCollectCellTaktMonitorHandler handler = cellTaktMonitorMap.computeIfAbsent(key, o -> new SxThirdPartyPlcCollectCellTaktMonitorHandler(org, key)); - handler.isRetry(plcCodeArr); - log.info("工厂{}第三方PLC数据采集 --- {} STRATEGY EXEC SINGLETON --- MONITOR {} KEY: {} ---", org, MesPcnExtConstWords.COLLECT_CELL_TAKT, handler.version() ? "ADD" : "RETRY", key); - } - } - -} diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/collect/SxThirdPartyPlcCollectCellTaktMonitorHandler.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/collect/SxThirdPartyPlcCollectCellTaktMonitorHandler.java index 626a642..3fd6fcc 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/collect/SxThirdPartyPlcCollectCellTaktMonitorHandler.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/collect/SxThirdPartyPlcCollectCellTaktMonitorHandler.java @@ -2,70 +2,36 @@ package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.collect; import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords; import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil; -import cn.estsh.i3plus.pojo.mes.model.StepResult; -import cn.estsh.impp.framework.boot.util.SpringContextsUtil; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.common.util.concurrent.MoreExecutors; import org.springframework.util.StringUtils; -import java.util.HashMap; import java.util.Map; import java.util.StringJoiner; -import java.util.concurrent.ExecutorService; /** - * 采集工位节拍监控处理器 + * 第三方PLC数据采集-监控处理器-工位节拍 */ -public class SxThirdPartyPlcCollectCellTaktMonitorHandler { - - protected volatile Boolean isOpen = true; - - protected volatile Boolean isRetry = false; - - protected volatile Integer version = 0; - - private SxThirdPartyPlcCollectStepFilterChain filterChain; - - private ExecutorService executorService; - - private ListenableFuture listenFuture; +public class SxThirdPartyPlcCollectCellTaktMonitorHandler extends SxThirdPartyPlcCollectMonitorHandler { private volatile String plcCode2Flag; private volatile String plcCode2Data; - private String org; - - private String key; - - private StepResult stepResult; - public SxThirdPartyPlcCollectCellTaktMonitorHandler(String org, String key) { - this.org = org; - this.key = key; + super(org, key); initStepResult(); - executorService = SpringContextsUtil.getBean(ExecutorService.class); - ListeningExecutorService listenExecutor = MoreExecutors.listeningDecorator(executorService); - listenFuture = listenExecutor.submit(() -> { - execMonitor(); - return null; - }); } private void initStepResult() { - Map dataMap = new HashMap<>(); - dataMap.put(MesPcnExtConstWords.ORGANIZE_CODE, org); - dataMap.put(MesPcnExtConstWords.KEY, key); - dataMap.put(MesPcnExtConstWords.BUSI_CODE, MesPcnExtConstWords.COLLECT_CELL_TAKT); - dataMap.put(MesPcnExtConstWords.WORK_CENTER_CODE, key.split(MesPcnExtConstWords.COLON)[2]); - dataMap.put(MesPcnExtConstWords.WORK_CELL_CODE, key.split(MesPcnExtConstWords.COLON)[3]); - stepResult = StepResult.getSuccessComplete().data(dataMap); + ((Map) stepResult.getData()).put(MesPcnExtConstWords.BUSI_CODE, MesPcnExtConstWords.COLLECT_CELL_TAKT); + ((Map) stepResult.getData()).put(MesPcnExtConstWords.WORK_CENTER_CODE, key.split(MesPcnExtConstWords.COLON)[2]); + ((Map) stepResult.getData()).put(MesPcnExtConstWords.WORK_CELL_CODE, key.split(MesPcnExtConstWords.COLON)[3]); } - public SxThirdPartyPlcCollectCellTaktMonitorHandler isRetry(String[] plcCodeArr) { - version ++; + @Override + public SxThirdPartyPlcCollectCellTaktMonitorHandler doRetry(Object obj) { + super.doRetry(obj); if (isRetry) return this; + String[] plcCodeArr = obj.toString().split(MesPcnExtConstWords.COMMA); if (StringUtils.isEmpty(plcCode2Flag) || !plcCode2Flag.equals(plcCodeArr[0])) plcCode2Flag = null; if (StringUtils.isEmpty(plcCode2Data) || !plcCode2Data.equals(plcCodeArr[1])) plcCode2Data = null; if (!StringUtils.isEmpty(plcCode2Flag) && !StringUtils.isEmpty(plcCode2Data)) return this; @@ -75,27 +41,8 @@ public class SxThirdPartyPlcCollectCellTaktMonitorHandler { return this; } - public void cancel() { - isOpen = false; - if (null != listenFuture) listenFuture.cancel(true); - } - - public Boolean version() { return version == 1 ? true : false; } - - private void instanceFilterChain() { - - filterChain = new SxThirdPartyPlcCollectStepFilterChain(org, key, MesPcnExtConstWords.COLLECT_CELL_TAKT, plcCode2Flag, plcCode2Data); - - filterChain.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 SxThirdPartyPlcCollectWritePlcStepService(plcCode2Flag).targetValue(MesPcnExtConstWords.ZERO_STR)) - .add(new SxThirdPartyPlcCollectCellTaktStepService().targetField(plcCode2Data)); - - isRetry = false; - - } - - private void execMonitor() { + @Override + public void execMonitor() { while (isOpen) { @@ -108,5 +55,14 @@ public class SxThirdPartyPlcCollectCellTaktMonitorHandler { } } + private void instanceFilterChain() { + filterChain = new SxThirdPartyPlcCollectStepFilterChain(org, key, MesPcnExtConstWords.COLLECT_CELL_TAKT) + .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(plcCode2Data)) + .add(new SxThirdPartyPlcCollectWritePlcStepService(plcCode2Flag).targetValue(MesPcnExtConstWords.ZERO_STR)) + .add(new SxThirdPartyPlcCollectCellTaktStepService().targetField(plcCode2Data)); + isRetry = false; + } } diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/collect/SxThirdPartyPlcCollectCellTaktService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/collect/SxThirdPartyPlcCollectCellTaktService.java index eb01e4c..8354808 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/collect/SxThirdPartyPlcCollectCellTaktService.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/collect/SxThirdPartyPlcCollectCellTaktService.java @@ -15,7 +15,7 @@ import java.util.*; import java.util.stream.Collectors; /** - * 采集工位节拍实现 + * 第三方PLC数据采集定时任务-采集工位节拍实现 */ @Slf4j @Service @@ -29,30 +29,30 @@ public class SxThirdPartyPlcCollectCellTaktService implements ISxThirdPartyPlcCo String organizeCode = paramMap.get(MesPcnExtConstWords.ORGANIZE_CODE); - log.info("工厂{}第三方PLC数据采集 --- {} STRATEGY START --- PARAM:{}", organizeCode, MesPcnExtConstWords.COLLECT_CELL_TAKT, paramMap.toString()); + log.info("工厂{}第三方PLC数据采集 --- STRATEGY {} EXEC SERVICE START --- PARAM:{}", organizeCode, MesPcnExtConstWords.COLLECT_CELL_TAKT, paramMap.toString()); if (checkOrgIsStopMonitor(organizeCode, paramMap.get(MesPcnExtConstWords.STATUS))) return; - Map cfgMap = getWorkCellTaktCollectPlcCfgList(organizeCode); + Map cfgMap = getWorkCellTaktCollectPlcCfgList(organizeCode); - log.info("工厂{}第三方PLC数据采集 --- {} STRATEGY EXEC --- CFGMAP:{}", organizeCode, MesPcnExtConstWords.COLLECT_CELL_TAKT, cfgMap.toString()); + log.info("工厂{}第三方PLC数据采集 --- STRATEGY {} EXEC SERVICE --- CFGMAP:{}", organizeCode, MesPcnExtConstWords.COLLECT_CELL_TAKT, cfgMap.toString()); - if (!SxThirdPartyPlcCollectCellTaktDispatchSingleton.getIsInit()) SxThirdPartyPlcCollectCellTaktDispatchSingleton.getInstance(); + if (!SxThirdPartyPlcCollectDispatchSingleton.getIsInit()) SxThirdPartyPlcCollectDispatchSingleton.getInstance(); - SxThirdPartyPlcCollectCellTaktDispatchSingleton.execMonitor(organizeCode, cfgMap); + SxThirdPartyPlcCollectDispatchSingleton.execMonitor(organizeCode, MesPcnExtConstWords.COLLECT_CELL_TAKT, cfgMap, true); - log.info("工厂{}第三方PLC数据采集 --- {} STRATEGY END --- CFGMAP:{}", organizeCode, MesPcnExtConstWords.COLLECT_CELL_TAKT, cfgMap.toString()); + log.info("工厂{}第三方PLC数据采集 --- STRATEGY {} EXEC SERVICE END ---", organizeCode, MesPcnExtConstWords.COLLECT_CELL_TAKT); } private Boolean checkOrgIsStopMonitor(String organizeCode, String status) { if (!StringUtils.isEmpty(status) && status.equals(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValueStr())) return false; - if (SxThirdPartyPlcCollectCellTaktDispatchSingleton.getIsInit()) SxThirdPartyPlcCollectCellTaktDispatchSingleton.execMonitor(organizeCode, null); - log.info("工厂{}第三方PLC数据采集 --- {} STRATEGY END --- MONITOR CLOSED COMPLETED ---", organizeCode, MesPcnExtConstWords.COLLECT_CELL_TAKT); + if (SxThirdPartyPlcCollectDispatchSingleton.getIsInit()) SxThirdPartyPlcCollectDispatchSingleton.execMonitor(organizeCode, MesPcnExtConstWords.COLLECT_CELL_TAKT, null, true); + log.info("工厂{}第三方PLC数据采集 --- STRATEGY {} EXEC SERVICE END --- MONITOR CLOSED COMPLETED ---", organizeCode, MesPcnExtConstWords.COLLECT_CELL_TAKT); return true; } - private Map getWorkCellTaktCollectPlcCfgList(String organizeCode) { + private Map getWorkCellTaktCollectPlcCfgList(String organizeCode) { List workCellTaktCollectPlcCfgList = workCellTaktCollectPlcCfgRepository.findByProperty( new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.STATUS}, new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()}); diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/collect/SxThirdPartyPlcCollectDispatchSingleton.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/collect/SxThirdPartyPlcCollectDispatchSingleton.java new file mode 100644 index 0000000..c83b86c --- /dev/null +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/collect/SxThirdPartyPlcCollectDispatchSingleton.java @@ -0,0 +1,76 @@ +package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.collect; + +import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords; +import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.StringJoiner; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; + +/** + * 第三方PLC数据采集-调度-单例模式 + */ +@Slf4j +public class SxThirdPartyPlcCollectDispatchSingleton { + + protected volatile static Boolean isInit = false; + + private static class SxCellTaktDispatchHolder { private final static SxThirdPartyPlcCollectDispatchSingleton INSTANCE = new SxThirdPartyPlcCollectDispatchSingleton(); } + + public static SxThirdPartyPlcCollectDispatchSingleton getInstance() { return SxCellTaktDispatchHolder.INSTANCE; } + + private SxThirdPartyPlcCollectDispatchSingleton() { isInit = true; } + + private volatile static Map monitorHandlerMap = new ConcurrentHashMap<>(); + + public static Boolean getIsInit() { return isInit; } + + public static synchronized void execMonitor(String org, String busiCode, Map cfgMap, Boolean flag) { + if (flag) { + if (CollectionUtils.isEmpty(cfgMap)) execMonitorRemove(org, busiCode, getCellTaktMonitorMapKeyList(org, busiCode)); + else execMonitorCompareToCfg(org, busiCode, cfgMap); + } else execMonitorCompute(org, busiCode, cfgMap); + } + + private static void execMonitorRemove(String org, String busiCode, List removeKeyList) { + log.info("工厂{}第三方PLC数据采集 --- STRATEGY {} EXEC SINGLETON --- MONITOR CLOSED KEY: {} --- START ---", org, busiCode, CollectionUtils.isEmpty(removeKeyList) ? MesPcnExtConstWords.EMPTY : JSONObject.toJSONString(removeKeyList)); + if (!CollectionUtils.isEmpty(removeKeyList)) removeKeyList.stream().forEach(SxThirdPartyPlcCollectDispatchSingleton::execMonitorRemove); + } + + private static void execMonitorCompareToCfg(String org, String busiCode, Map cfgMap) { + List cellTaktMonitorMapKeyList = getCellTaktMonitorMapKeyList(org, busiCode); + List removeKeyList = CollectionUtils.isEmpty(cellTaktMonitorMapKeyList) ? null : cellTaktMonitorMapKeyList.stream().filter(o -> (!StringUtils.isEmpty(o) && !cfgMap.containsKey(o))).collect(Collectors.toList()); + execMonitorRemove(org, busiCode, removeKeyList); + execMonitorCompute(org, busiCode, cfgMap); + } + + private static List getCellTaktMonitorMapKeyList(String org, String busiCode) { + List cellTaktMonitorMapKeyList = CollectionUtils.isEmpty(monitorHandlerMap) ? null : new ArrayList<>(monitorHandlerMap.keySet()); + if (CollectionUtils.isEmpty(cellTaktMonitorMapKeyList)) return null; + String suffix = new StringJoiner(MesPcnExtConstWords.COLON).add(busiCode).add(org).toString(); + return CollectionUtils.isEmpty(cellTaktMonitorMapKeyList) ? null : cellTaktMonitorMapKeyList.stream().filter(o -> (!StringUtils.isEmpty(o) && o.contains(suffix))).collect(Collectors.toList()); + } + + private static void execMonitorRemove(String key) { + SxThirdPartyPlcCollectMonitorHandler handler = monitorHandlerMap.get(key); + handler.cancel(); + monitorHandlerMap.remove(key); + log.info("工厂{}第三方PLC数据采集 --- STRATEGY {} EXEC SINGLETON --- MONITOR CLOSED KEY: {} ---", key.split(MesPcnExtConstWords.COLON)[1], key.split(MesPcnExtConstWords.COLON)[0], key); + } + + private static void execMonitorCompute(String org, String busiCode, Map cfgMap) { + for (String key : cfgMap.keySet()) { + if (StringUtils.isEmpty(key)) continue; + SxThirdPartyPlcCollectMonitorHandler handler = monitorHandlerMap.computeIfAbsent(key, o -> new SxThirdPartyPlcCollectCellTaktMonitorHandler(org, key)); + handler.doRetry(cfgMap.get(key)); + log.info("工厂{}第三方PLC数据采集 --- STRATEGY {} EXEC SINGLETON --- MONITOR {} KEY: {} ---", org, busiCode, handler.version() ? "ADD" : "RETRY", key); + } + } + +} diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/collect/SxThirdPartyPlcCollectMonitorHandler.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/collect/SxThirdPartyPlcCollectMonitorHandler.java new file mode 100644 index 0000000..337851f --- /dev/null +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/collect/SxThirdPartyPlcCollectMonitorHandler.java @@ -0,0 +1,73 @@ +package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.collect; + +import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords; +import cn.estsh.i3plus.pojo.mes.model.StepResult; +import cn.estsh.impp.framework.boot.util.SpringContextsUtil; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.ListeningExecutorService; +import com.google.common.util.concurrent.MoreExecutors; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ExecutorService; + +/** + * 第三方PLC数据采集-监控处理器-父类 + */ +public class SxThirdPartyPlcCollectMonitorHandler { + + public volatile Boolean isOpen = true; + + public volatile Boolean isRetry = false; + + public String org; + + public String key; + + public StepResult stepResult; + + public volatile Integer version = 0; + + public ExecutorService executorService; + + public ListenableFuture listenFuture; + + public SxThirdPartyPlcCollectStepFilterChain filterChain; + + public SxThirdPartyPlcCollectMonitorHandler(String org, String key) { + + this.org = org; + this.key = key; + + Map dataMap = new HashMap<>(); + dataMap.put(MesPcnExtConstWords.ORGANIZE_CODE, org); + dataMap.put(MesPcnExtConstWords.KEY, key); + stepResult = StepResult.getSuccessComplete().data(dataMap); + + executorService = SpringContextsUtil.getBean(ExecutorService.class); + ListeningExecutorService listenExecutor = MoreExecutors.listeningDecorator(executorService); + listenFuture = listenExecutor.submit(() -> { + execMonitor(); + return null; + }); + + } + + public void execMonitor() { + System.out.println("3条34用她4用"); + } + + public SxThirdPartyPlcCollectMonitorHandler doRetry(Object obj) { + if (version == 0) version ++; + else version = 2; + return this; + } + + public void cancel() { + isOpen = false; + if (null != listenFuture) listenFuture.cancel(true); + } + + public Boolean version() { return version == 1 ? true : false; } + +} diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/collect/SxThirdPartyPlcCollectStepFilterChain.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/collect/SxThirdPartyPlcCollectStepFilterChain.java index 72e31fe..55aa020 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/collect/SxThirdPartyPlcCollectStepFilterChain.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/collect/SxThirdPartyPlcCollectStepFilterChain.java @@ -24,12 +24,28 @@ public class SxThirdPartyPlcCollectStepFilterChain implements ISxThirdPartyPlcCo private String key; private String busiCode; private String[] clearField; + private Long sleepTime2UnComplete; + private Long sleepTime2Completed; - public SxThirdPartyPlcCollectStepFilterChain(String org, String key, String busiCode, String... clearField) { + public SxThirdPartyPlcCollectStepFilterChain(String org, String key, String busiCode) { this.org = org; this.key = key; this.busiCode = busiCode; + } + + public SxThirdPartyPlcCollectStepFilterChain clearField(String... clearField) { this.clearField = clearField; + return this; + } + + public SxThirdPartyPlcCollectStepFilterChain sleepTime2UnComplete(Long sleepTime2UnComplete) { + this.sleepTime2UnComplete = sleepTime2UnComplete; + return this; + } + + public SxThirdPartyPlcCollectStepFilterChain sleepTime2Completed(Long sleepTime2Completed) { + this.sleepTime2Completed = sleepTime2Completed; + return this; } public SxThirdPartyPlcCollectStepFilterChain add(ISxThirdPartyPlcCollectDataStepService stepService) { @@ -40,7 +56,7 @@ public class SxThirdPartyPlcCollectStepFilterChain implements ISxThirdPartyPlcCo @Override public StepResult exec(StepResult stepResult) { - LOGGER.info(String.format("工厂%s第三方PLC数据采集 --- %s STEP EXEC --- key: %s START --- stepResult:%s ---", org, busiCode, key, JSONObject.toJSONString(stepResult))); + LOGGER.info(String.format("工厂%s第三方PLC数据采集 --- STRATEGY %s STEP EXEC --- key: %s START --- stepResult:%s ---", org, busiCode, key, JSONObject.toJSONString(stepResult))); try { for (ISxThirdPartyPlcCollectDataStepService stepService : stepServiceList) { @@ -49,13 +65,14 @@ public class SxThirdPartyPlcCollectStepFilterChain implements ISxThirdPartyPlcCo if (!stepResult.isCompleted()) break; } - TimeUnit.MILLISECONDS.sleep(!stepResult.isCompleted() ? 1000L: 2000L); + if (!stepResult.isCompleted()) TimeUnit.MILLISECONDS.sleep(!StringUtils.isEmpty(sleepTime2UnComplete) ? sleepTime2UnComplete : 1000L); + else if (!StringUtils.isEmpty(sleepTime2Completed)) TimeUnit.MILLISECONDS.sleep(sleepTime2Completed); } catch (Exception e) { - LOGGER.info(String.format("工厂%s第三方PLC数据采集 --- %s STEP ERROR --- key: %s --- %s --- stepResult:%s --- %s ---", org, busiCode, key, e.toString(), JSONObject.toJSONString(stepResult), JSONObject.toJSONString(e))); + LOGGER.info(String.format("工厂%s第三方PLC数据采集 --- STRATEGY %s STEP ERROR --- key: %s --- %s --- stepResult:%s --- %s ---", org, busiCode, key, e.toString(), JSONObject.toJSONString(stepResult), JSONObject.toJSONString(e))); } - LOGGER.info(String.format("工厂%s第三方PLC数据采集 --- %s STEP EXEC --- key: %s END --- stepResult:%s ---", org, busiCode, key, JSONObject.toJSONString(stepResult))); + LOGGER.info(String.format("工厂%s第三方PLC数据采集 --- STRATEGY %s STEP EXEC --- key: %s END --- stepResult:%s ---", org, busiCode, key, JSONObject.toJSONString(stepResult))); return rollBackStepResult(stepResult); diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/step/jx/JxSnProcessingCollectDataStepService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/step/jx/JxSnProcessingCollectDataStepService.java new file mode 100644 index 0000000..9d568dd --- /dev/null +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/step/jx/JxSnProcessingCollectDataStepService.java @@ -0,0 +1,39 @@ +package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.step.jx; + +import cn.estsh.i3plus.mes.pcn.serviceimpl.base.BaseStepService; +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 lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +/** + * @Description : 嘉兴条码加工采集数据工步 + * @Reference : + * @Author : wangjie + * @CreateDate : 2019-07-11 + * @Modify: + **/ +@Slf4j +@Service("jxSnProcessingCollectDataStepService") +public class JxSnProcessingCollectDataStepService extends BaseStepService { + + @Override + public StepResult execute(StationRequestBean reqBean) { + + log.info("工厂{}生产线{}工位{}: --- STEP EXECUTE --- JxSnProcessingCollectDataStepService --- START --- ", reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode()); + + StepResult stepResult = StepResult.getSuccessComplete(); + + StationResultBean resultBean = new StationResultBean(); + + 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()); + + return stepResult; + } + +} \ No newline at end of file