forked from I3-YF/i3plus-mes-pcn-yfai
jx pcn 节拍采集 优化
parent
a270c26ed3
commit
75b02b2c0e
@ -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<String, SxThirdPartyPlcCollectCellTaktMonitorHandler> cellTaktMonitorMap = new ConcurrentHashMap<>();
|
||||
|
||||
public static Boolean getIsInit() { return isInit; }
|
||||
|
||||
public static synchronized void execMonitor(String org, Map<String, String> cfgMap) {
|
||||
if (CollectionUtils.isEmpty(cfgMap)) execMonitorRemove(org, getCellTaktMonitorMapKeyList(org));
|
||||
else execMonitorCompareToCfg(org, cfgMap);
|
||||
}
|
||||
|
||||
private static void execMonitorRemove(String org, List<String> 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<String, String> cfgMap) {
|
||||
List<String> cellTaktMonitorMapKeyList = getCellTaktMonitorMapKeyList(org);
|
||||
List<String> 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<String> getCellTaktMonitorMapKeyList(String org) {
|
||||
List<String> 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<String, String> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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<String, SxThirdPartyPlcCollectMonitorHandler> monitorHandlerMap = new ConcurrentHashMap<>();
|
||||
|
||||
public static Boolean getIsInit() { return isInit; }
|
||||
|
||||
public static synchronized void execMonitor(String org, String busiCode, Map<String, Object> 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<String> 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<String, Object> cfgMap) {
|
||||
List<String> cellTaktMonitorMapKeyList = getCellTaktMonitorMapKeyList(org, busiCode);
|
||||
List<String> 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<String> getCellTaktMonitorMapKeyList(String org, String busiCode) {
|
||||
List<String> 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<String, Object> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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<Object> listenFuture;
|
||||
|
||||
public SxThirdPartyPlcCollectStepFilterChain filterChain;
|
||||
|
||||
public SxThirdPartyPlcCollectMonitorHandler(String org, String key) {
|
||||
|
||||
this.org = org;
|
||||
this.key = key;
|
||||
|
||||
Map<String, Object> 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; }
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue