jx pcn takt collect

tags/yfai-pcn-ext-v1.0
王杰 1 year ago
parent 9d5600f548
commit 9d81c7d6ec

@ -1,10 +1,7 @@
package cn.estsh.i3plus.ext.mes.pcn.api.busi; package cn.estsh.i3plus.ext.mes.pcn.api.busi;
import cn.estsh.i3plus.pojo.mes.model.StepResult; import cn.estsh.i3plus.pojo.mes.model.StepResult;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
/** /**
* @Author: wangjie * @Author: wangjie
@ -19,7 +16,6 @@ public interface ISxThirdPartyPlcCollectDataStepService {
* @return * @return
*/ */
@ApiOperation(value = "第三方PLC数据采集定时任务---步骤执行", notes = "第三方PLC数据采集定时任务---步骤执行") @ApiOperation(value = "第三方PLC数据采集定时任务---步骤执行", notes = "第三方PLC数据采集定时任务---步骤执行")
@Transactional(propagation = Propagation.REQUIRES_NEW, noRollbackFor = {ImppBusiException.class, Exception.class})
StepResult exec(StepResult stepResult); StepResult exec(StepResult stepResult);
} }

@ -0,0 +1,24 @@
package cn.estsh.i3plus.ext.mes.pcn.api.busi.jx;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.SxWorkCellTaktCollectRecord;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
/**
* @Author: wangjie
* @CreateDate: 2021/01/18 11:22
* @Description:
**/
public interface IJxWorkCellTaktCollectRecordService {
/**
* ()
* @param workCellTaktCollectRecord
*/
@ApiOperation(value = "插入节拍信息(新事务,不回滚)", notes = "插入节拍信息(新事务,不回滚)")
@Transactional(propagation = Propagation.REQUIRES_NEW, noRollbackFor = {ImppBusiException.class, Exception.class})
void insertWorkCellTaktCollectRecordNoRollback(SxWorkCellTaktCollectRecord workCellTaktCollectRecord);
}

@ -36,7 +36,7 @@ public class SxCellTaktDispatchSingleton {
} }
private static void execMonitorRemove(String org, List<String> removeKeyList) { 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)); 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(SxCellTaktDispatchSingleton::execMonitorRemove); if (!CollectionUtils.isEmpty(removeKeyList)) removeKeyList.stream().forEach(SxCellTaktDispatchSingleton::execMonitorRemove);
} }
@ -56,7 +56,7 @@ public class SxCellTaktDispatchSingleton {
SxCellTaktMonitorHandler handler = cellTaktMonitorMap.get(key); SxCellTaktMonitorHandler handler = cellTaktMonitorMap.get(key);
handler.cancel(); handler.cancel();
cellTaktMonitorMap.remove(key); cellTaktMonitorMap.remove(key);
log.info("工厂{}第三方PLC数据采集 --- {} STRATEGY EXEC SINGLETON --- MONITOR CLOSED KEY:[{}] ---", key.split(MesPcnExtConstWords.COLON)[1], MesPcnExtConstWords.COLLECT_CELL_TAKT, 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) { private static void execMonitorCompute(String org, Map<String, String> cfgMap) {
@ -66,7 +66,7 @@ public class SxCellTaktDispatchSingleton {
if (null == plcCodeArr || plcCodeArr.length != 2) continue; if (null == plcCodeArr || plcCodeArr.length != 2) continue;
SxCellTaktMonitorHandler handler = cellTaktMonitorMap.computeIfAbsent(key, o -> new SxCellTaktMonitorHandler(org, key)); SxCellTaktMonitorHandler handler = cellTaktMonitorMap.computeIfAbsent(key, o -> new SxCellTaktMonitorHandler(org, key));
handler.isRetry(plcCodeArr); handler.isRetry(plcCodeArr);
log.info("工厂{}第三方PLC数据采集 --- {} STRATEGY EXEC SINGLETON --- MONITOR {} KEY:[{}] ---", org, MesPcnExtConstWords.COLLECT_CELL_TAKT, handler.version() ? "ADD" : "RETRY", key); log.info("工厂{}第三方PLC数据采集 --- {} STRATEGY EXEC SINGLETON --- MONITOR {} KEY: {} ---", org, MesPcnExtConstWords.COLLECT_CELL_TAKT, handler.version() ? "ADD" : "RETRY", key);
} }
} }

@ -11,6 +11,7 @@ import org.springframework.util.StringUtils;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.StringJoiner;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
/** /**
@ -85,7 +86,7 @@ public class SxCellTaktMonitorHandler {
filterChain = new SxThirdPartyPlcCollectStepFilterChain(org, key, MesPcnExtConstWords.COLLECT_CELL_TAKT, plcCode2Flag, plcCode2Data); filterChain = new SxThirdPartyPlcCollectStepFilterChain(org, key, MesPcnExtConstWords.COLLECT_CELL_TAKT, plcCode2Flag, plcCode2Data);
filterChain.add(new SxThirdPartyPlcCollectReadPlcStepService(plcCode2Flag).targetValue(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValueStr())) 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 SxThirdPartyPlcCollectReadPlcStepService(plcCode2Data))
.add(new SxThirdPartyPlcCollectWritePlcStepService(plcCode2Flag).targetValue(MesPcnExtConstWords.ZERO_STR)) .add(new SxThirdPartyPlcCollectWritePlcStepService(plcCode2Flag).targetValue(MesPcnExtConstWords.ZERO_STR))
.add(new SxThirdPartyPlcCollectCellTaktStepService().targetField(plcCode2Data)); .add(new SxThirdPartyPlcCollectCellTaktStepService().targetField(plcCode2Data));

@ -1,11 +1,11 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.collect; package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.collect;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyPlcCollectDataStepService; import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyPlcCollectDataStepService;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.jx.IJxWorkCellTaktCollectRecordService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.SxWorkCellTaktCollectRecord; import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.SxWorkCellTaktCollectRecord;
import cn.estsh.i3plus.ext.mes.pcn.pojo.repository.SxWorkCellTaktCollectRecordRepository;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords; import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtEnumUtil;
import cn.estsh.i3plus.platform.common.convert.ConvertBean; import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.pojo.base.enumutil.MesPcnEnumUtil;
import cn.estsh.i3plus.pojo.mes.model.StepResult; import cn.estsh.i3plus.pojo.mes.model.StepResult;
import cn.estsh.impp.framework.boot.util.SpringContextsUtil; import cn.estsh.impp.framework.boot.util.SpringContextsUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -18,12 +18,12 @@ import java.util.Map;
@Slf4j @Slf4j
public class SxThirdPartyPlcCollectCellTaktStepService implements ISxThirdPartyPlcCollectDataStepService { public class SxThirdPartyPlcCollectCellTaktStepService implements ISxThirdPartyPlcCollectDataStepService {
private SxWorkCellTaktCollectRecordRepository workCellTaktCollectRecordRepository; private IJxWorkCellTaktCollectRecordService workCellTaktCollectRecordService;
protected String targetField; protected String targetField;
public SxThirdPartyPlcCollectCellTaktStepService() { public SxThirdPartyPlcCollectCellTaktStepService() {
this.workCellTaktCollectRecordRepository = (SxWorkCellTaktCollectRecordRepository) SpringContextsUtil.getBean("sxWorkCellTaktCollectRecordRepository"); this.workCellTaktCollectRecordService = (IJxWorkCellTaktCollectRecordService) SpringContextsUtil.getBean("jxWorkCellTaktCollectRecordService");
} }
public SxThirdPartyPlcCollectCellTaktStepService targetField(String targetField) { public SxThirdPartyPlcCollectCellTaktStepService targetField(String targetField) {
@ -44,9 +44,9 @@ public class SxThirdPartyPlcCollectCellTaktStepService implements ISxThirdPartyP
workCellTaktCollectRecord.setWorkCellCode(workCellCode); workCellTaktCollectRecord.setWorkCellCode(workCellCode);
workCellTaktCollectRecord.setWorkTakt(targetValue.toString()); workCellTaktCollectRecord.setWorkTakt(targetValue.toString());
workCellTaktCollectRecord.setOrganizeCode(organizeCode); workCellTaktCollectRecord.setOrganizeCode(organizeCode);
workCellTaktCollectRecord.setSystemSyncStatus(MesPcnEnumUtil.IF_SYNC_STATUS.NO_SYNC.getValue()); workCellTaktCollectRecord.setSystemSyncStatus(MesPcnExtEnumUtil.IF_SYNC_STATUS.NO_SYNC.getValue());
ConvertBean.serviceModelInitialize(workCellTaktCollectRecord, MesPcnExtConstWords.JOB); ConvertBean.serviceModelInitialize(workCellTaktCollectRecord, MesPcnExtConstWords.JOB);
workCellTaktCollectRecordRepository.insert(workCellTaktCollectRecord); workCellTaktCollectRecordService.insertWorkCellTaktCollectRecordNoRollback(workCellTaktCollectRecord);
return stepResult; return stepResult;
} }

@ -9,6 +9,7 @@ import cn.estsh.impp.framework.boot.util.SpringContextsUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.util.Arrays;
import java.util.Map; import java.util.Map;
/** /**
@ -48,7 +49,7 @@ public class SxThirdPartyPlcCollectReadPlcStepService implements ISxThirdPartyPl
((Map<String, Object>) stepResult.getData()).put(plcCode, value); ((Map<String, Object>) stepResult.getData()).put(plcCode, value);
if (StringUtils.isEmpty(value) || (!StringUtils.isEmpty(targetValue) && !targetValue.equals(value.toString()))) return stepResult.isCompleted(false).msg(String.format("读取plcCode:%s 值无效", plcCode)); if (StringUtils.isEmpty(value) || (!StringUtils.isEmpty(targetValue) && !Arrays.asList(targetValue.split(MesPcnExtConstWords.COMMA)).contains(value.toString()))) return stepResult.isCompleted(false).msg(String.format("读取plcCode:%s 值无效", plcCode));
return stepResult; return stepResult;
} }

@ -40,7 +40,7 @@ public class SxThirdPartyPlcCollectStepFilterChain implements ISxThirdPartyPlcCo
@Override @Override
public StepResult exec(StepResult stepResult) { 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数据采集 --- %s STEP EXEC --- key: %s START --- stepResult:%s ---", org, busiCode, key, JSONObject.toJSONString(stepResult)));
try { try {
for (ISxThirdPartyPlcCollectDataStepService stepService : stepServiceList) { for (ISxThirdPartyPlcCollectDataStepService stepService : stepServiceList) {
@ -52,10 +52,10 @@ public class SxThirdPartyPlcCollectStepFilterChain implements ISxThirdPartyPlcCo
TimeUnit.MILLISECONDS.sleep(!stepResult.isCompleted() ? 1000L: 2000L); TimeUnit.MILLISECONDS.sleep(!stepResult.isCompleted() ? 1000L: 2000L);
} catch (Exception e) { } 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), "\r\n" + JSONObject.toJSONString(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数据采集 --- %s STEP EXEC --- key:[%s] END --- stepResult:%s ---", org, busiCode, key, JSONObject.toJSONString(stepResult))); LOGGER.info(String.format("工厂%s第三方PLC数据采集 --- %s STEP EXEC --- key: %s END --- stepResult:%s ---", org, busiCode, key, JSONObject.toJSONString(stepResult)));
return rollBackStepResult(stepResult); return rollBackStepResult(stepResult);
@ -67,7 +67,7 @@ public class SxThirdPartyPlcCollectStepFilterChain implements ISxThirdPartyPlcCo
if (StringUtils.isEmpty(field)) continue; if (StringUtils.isEmpty(field)) continue;
((Map<String, Object>) stepResult.getData()).remove(field); ((Map<String, Object>) stepResult.getData()).remove(field);
} }
return stepResult.isCompleted(true); return stepResult.isCompleted(true).msg(null);
} }
} }

@ -0,0 +1,27 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.jx;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.jx.IJxWorkCellTaktCollectRecordService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.SxWorkCellTaktCollectRecord;
import cn.estsh.i3plus.ext.mes.pcn.pojo.repository.SxWorkCellTaktCollectRecordRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @Author: wangjie
* @CreateDate: 2021/01/18 11:41
* @Description:
**/
@Slf4j
@Service
public class JxWorkCellTaktCollectRecordService implements IJxWorkCellTaktCollectRecordService {
@Autowired
private SxWorkCellTaktCollectRecordRepository workCellTaktCollectRecordRepository;
@Override
public void insertWorkCellTaktCollectRecordNoRollback(SxWorkCellTaktCollectRecord workCellTaktCollectRecord) {
workCellTaktCollectRecordRepository.insert(workCellTaktCollectRecord);
}
}
Loading…
Cancel
Save