forked from I3-YF/i3plus-mes-pcn-yfai
jx collect takt data
parent
34b60d1fc2
commit
09c1d60704
@ -0,0 +1,54 @@
|
||||
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.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.platform.common.convert.ConvertBean;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.MesPcnEnumUtil;
|
||||
import cn.estsh.i3plus.pojo.mes.model.StepResult;
|
||||
import cn.estsh.impp.framework.boot.util.SpringContextsUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 第三方PLC数据采集定时任务---步骤执行---写节拍
|
||||
*/
|
||||
@Slf4j
|
||||
public class SxThirdPartyPlcCollectCellTaktStepService implements ISxThirdPartyPlcCollectDataStepService {
|
||||
|
||||
private SxWorkCellTaktCollectRecordRepository workCellTaktCollectRecordRepository;
|
||||
|
||||
protected String targetField;
|
||||
|
||||
public SxThirdPartyPlcCollectCellTaktStepService() {
|
||||
this.workCellTaktCollectRecordRepository = (SxWorkCellTaktCollectRecordRepository) SpringContextsUtil.getBean("sxWorkCellTaktCollectRecordRepository");
|
||||
}
|
||||
|
||||
public SxThirdPartyPlcCollectCellTaktStepService targetField(String targetField) {
|
||||
this.targetField = targetField;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StepResult exec(StepResult stepResult) {
|
||||
|
||||
String organizeCode = (String) ((Map<String, Object>) stepResult.getData()).get(MesPcnExtConstWords.ORGANIZE_CODE);
|
||||
String workCenterCode = (String) ((Map<String, Object>) stepResult.getData()).get(MesPcnExtConstWords.WORK_CENTER_CODE);
|
||||
String workCellCode = (String) ((Map<String, Object>) stepResult.getData()).get(MesPcnExtConstWords.WORK_CELL_CODE);
|
||||
Object targetValue = ((Map<String, Object>) stepResult.getData()).get(targetField);
|
||||
|
||||
SxWorkCellTaktCollectRecord workCellTaktCollectRecord = new SxWorkCellTaktCollectRecord();
|
||||
workCellTaktCollectRecord.setWorkCenterCode(workCenterCode);
|
||||
workCellTaktCollectRecord.setWorkCellCode(workCellCode);
|
||||
workCellTaktCollectRecord.setWorkTakt(targetValue.toString());
|
||||
workCellTaktCollectRecord.setOrganizeCode(organizeCode);
|
||||
workCellTaktCollectRecord.setSystemSyncStatus(MesPcnEnumUtil.IF_SYNC_STATUS.NO_SYNC.getValue());
|
||||
ConvertBean.serviceModelInitialize(workCellTaktCollectRecord, MesPcnExtConstWords.JOB);
|
||||
workCellTaktCollectRecordRepository.insert(workCellTaktCollectRecord);
|
||||
|
||||
return stepResult;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
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.jx.IJxPlcExtService;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
|
||||
import cn.estsh.i3plus.pojo.mes.bean.MesPlc;
|
||||
import cn.estsh.i3plus.pojo.mes.model.StepResult;
|
||||
import cn.estsh.impp.framework.boot.util.SpringContextsUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 第三方PLC数据采集定时任务---步骤执行---写PLC
|
||||
*/
|
||||
@Slf4j
|
||||
public class SxThirdPartyPlcCollectWritePlcStepService implements ISxThirdPartyPlcCollectDataStepService {
|
||||
|
||||
protected String plcCode;
|
||||
|
||||
protected String targetValue;
|
||||
|
||||
private IJxPlcExtService plcExtService;
|
||||
|
||||
public SxThirdPartyPlcCollectWritePlcStepService(String plcCode) {
|
||||
this.plcCode = plcCode;
|
||||
this.plcExtService = (IJxPlcExtService) SpringContextsUtil.getBean("jxPlcExtService");
|
||||
}
|
||||
|
||||
public SxThirdPartyPlcCollectWritePlcStepService targetValue(String targetValue) {
|
||||
this.targetValue = targetValue;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StepResult exec(StepResult stepResult) {
|
||||
|
||||
if (StringUtils.isEmpty(targetValue)) return stepResult.isCompleted(false).msg(String.format("写入plcCode:%s 参数缺失目标值", plcCode));
|
||||
|
||||
String organizeCode = (String) ((Map<String, Object>) stepResult.getData()).get(MesPcnExtConstWords.ORGANIZE_CODE);
|
||||
|
||||
String key = (String) ((Map<String, Object>) stepResult.getData()).get(MesPcnExtConstWords.KEY);
|
||||
|
||||
MesPlc plc = plcExtService.getPlcData(organizeCode, plcCode, key);
|
||||
|
||||
if (null == plc || (StringUtils.isEmpty(plc.getChannel()) || StringUtils.isEmpty(plc.getDevice()) || StringUtils.isEmpty(plc.getTagAddress()))) return stepResult.isCompleted(false).msg(String.format("写入plcCode:%s 配置无效", plcCode));
|
||||
|
||||
Boolean value = plcExtService.doWriteOpcParamValue(plc, targetValue);
|
||||
|
||||
((Map<String, Object>) stepResult.getData()).put(plcCode, value);
|
||||
|
||||
if (StringUtils.isEmpty(value) || !value) return stepResult.isCompleted(false).msg(String.format("写入plcCode:%s 失败", plcCode));
|
||||
|
||||
return stepResult;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue