diff --git a/modules/i3plus-ext-mes-pcn-api/src/main/java/cn/estsh/i3plus/ext/mes/pcn/api/busi/ISxThirdPartyPlcCollectDataJobService.java b/modules/i3plus-ext-mes-pcn-api/src/main/java/cn/estsh/i3plus/ext/mes/pcn/api/busi/ISxThirdPartyPlcCollectDataJobService.java index 808f500..03f9eb1 100644 --- a/modules/i3plus-ext-mes-pcn-api/src/main/java/cn/estsh/i3plus/ext/mes/pcn/api/busi/ISxThirdPartyPlcCollectDataJobService.java +++ b/modules/i3plus-ext-mes-pcn-api/src/main/java/cn/estsh/i3plus/ext/mes/pcn/api/busi/ISxThirdPartyPlcCollectDataJobService.java @@ -1,21 +1,21 @@ -package cn.estsh.i3plus.ext.mes.pcn.api.job.gz; +package cn.estsh.i3plus.ext.mes.pcn.api.busi; import io.swagger.annotations.ApiOperation; +import java.util.Map; + /** * @Author: wangjie * @CreateDate: 2021/01/19 15:06 下午 * @Description: **/ -public interface IGzThirdPartyDbCollectDataJobService { +public interface ISxThirdPartyPlcCollectDataJobService { /** - * 第三方数据库数据采集定时任务 - * @param organizeCode 组织代码 - * @param cfgCode 配置代码 - * @param userInfo 操作人 + * 第三方PLC数据采集定时任务 + * @param paramMap 参数 */ - @ApiOperation(value = "第三方数据库数据采集定时任务", notes = "第三方数据库数据采集定时任务") - void doThirdPartyDbCollectData(String organizeCode, String cfgCode, String userInfo); + @ApiOperation(value = "第三方PLC数据采集定时任务", notes = "第三方PLC数据采集定时任务") + void doThirdPartyPlcCollectData(Map paramMap); } diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/schedulejob/SxThirdPartyPlcCollectDataJob.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/schedulejob/SxThirdPartyPlcCollectDataJob.java index 195d9d9..340dafd 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/schedulejob/SxThirdPartyPlcCollectDataJob.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/schedulejob/SxThirdPartyPlcCollectDataJob.java @@ -1,51 +1,48 @@ -package cn.estsh.i3plus.ext.mes.pcn.apiservice.schedulejob.gz; +package cn.estsh.i3plus.ext.mes.pcn.apiservice.schedulejob; -import cn.estsh.i3plus.ext.mes.pcn.api.job.gz.IGzThirdPartyDbCollectDataJobService; +import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyPlcCollectDataJobService; import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords; +import cn.estsh.impp.framework.boot.util.SpringContextsUtil; +import com.alibaba.fastjson.JSONObject; import io.swagger.annotations.ApiOperation; -import org.jboss.logging.Logger; +import lombok.extern.slf4j.Slf4j; import org.quartz.DisallowConcurrentExecution; import org.quartz.Job; import org.quartz.JobExecutionContext; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.StringUtils; +import java.util.Map; + /** * @author wangjie * @version 1.0 * @date 2021/2/2 16:44 **/ +@Slf4j @DisallowConcurrentExecution -@ApiOperation("第三方数据库数据采集定时任务") -public class GzThirdPartyDbCollectDataJob implements Job { - - private static final Logger LOGGER = Logger.getLogger(GzThirdPartyDbCollectDataJob.class); - - @Autowired - private IGzThirdPartyDbCollectDataJobService thirdPartyDbCollectDataJobService; +@ApiOperation("第三方PLC数据采集定时任务") +public class SxThirdPartyPlcCollectDataJob implements Job { @Override public void execute(JobExecutionContext jobExecutionContext) { - LOGGER.info("Pcn处理第三方数据库数据采集JOB开始执行..."); Object param = jobExecutionContext.getJobDetail().getJobDataMap().get(MesPcnExtConstWords.PARAM); - if (StringUtils.isEmpty(param)) { - LOGGER.error("Pcn处理第三方数据库数据采集JOB,未配置参数"); - return; - } - String[] paramArr = param.toString().split(MesPcnExtConstWords.COMMA); - if (paramArr.length != 2) { - LOGGER.error("Pcn处理第三方数据库数据采集JOB,配置的参数无效"); - return; - } + if (StringUtils.isEmpty(param)) return; + + log.info("第三方PLC数据采集 --- JOB START --- PARAM:{}", param.toString()); + + Map paramMap = JSONObject.parseObject(param.toString(), Map.class); + if (!paramMap.containsKey(MesPcnExtConstWords.ORGANIZE_CODE) || !paramMap.containsKey(MesPcnExtConstWords.STRATEGY_CLASS)) return; + if (!paramMap.containsKey(MesPcnExtConstWords.USER_INFO)) paramMap.put(MesPcnExtConstWords.USER_INFO, MesPcnExtConstWords.JOB); long startTime = System.currentTimeMillis(); - thirdPartyDbCollectDataJobService.doThirdPartyDbCollectData(paramArr[0], paramArr[1], MesPcnExtConstWords.JOB); + ((ISxThirdPartyPlcCollectDataJobService) SpringContextsUtil.getBean(paramMap.get(MesPcnExtConstWords.STRATEGY_CLASS))).doThirdPartyPlcCollectData(paramMap); long endTime = System.currentTimeMillis(); - LOGGER.info("Pcn处理第三方数据库数据采集JOB执行完成耗时: " + (endTime - startTime) + "ms"); + + log.info("第三方PLC数据采集 --- JOB END --- 耗时: {} ms", endTime - startTime); } } diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/job/SxThirdPartyPlcCollectCellTaktService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/job/SxThirdPartyPlcCollectCellTaktService.java index 9b15557..b35581f 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/job/SxThirdPartyPlcCollectCellTaktService.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/job/SxThirdPartyPlcCollectCellTaktService.java @@ -1,4 +1,54 @@ package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.job; -public class SxThirdPartyPlcCollectCellTaktService { +import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyPlcCollectDataJobService; +import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.SxWorkCellTaktCollectPlcCfg; +import cn.estsh.i3plus.ext.mes.pcn.pojo.repository.SxWorkCellTaktCollectPlcCfgRepository; +import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords; +import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * 采集工位节拍实现 + */ +@Service +public class SxThirdPartyPlcCollectCellTaktService implements ISxThirdPartyPlcCollectDataJobService { + + @Autowired + private SxWorkCellTaktCollectPlcCfgRepository workCellTaktCollectPlcCfgRepository; + + @Override + public void doThirdPartyPlcCollectData(Map paramMap) { + + if (!checkConfigStatus(paramMap)) return; + + List workCellTaktCollectPlcCfgList = getWorkCellTaktCollectPlcCfgList(paramMap.get(MesPcnExtConstWords.ORGANIZE_CODE)); + + + } + + private List 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()}); + workCellTaktCollectPlcCfgList = CollectionUtils.isEmpty(workCellTaktCollectPlcCfgList) ? null : + workCellTaktCollectPlcCfgList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getPlcCode()))).distinct().collect(Collectors.collectingAndThen( + Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> new StringJoiner(MesPcnExtConstWords.AND).add(o.getWorkCenterCode()).add(o.getWorkCellCode()).toString()))), ArrayList::new)); + workCellTaktCollectPlcCfgList = CollectionUtils.isEmpty(workCellTaktCollectPlcCfgList) ? null : + workCellTaktCollectPlcCfgList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getPlcCode()))).distinct().collect(Collectors.collectingAndThen( + Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(SxWorkCellTaktCollectPlcCfg::getPlcCode))), ArrayList::new)); + return workCellTaktCollectPlcCfgList; + } + + private Boolean checkConfigStatus(Map paramMap) { + if (paramMap.containsKey(MesPcnExtConstWords.STATUS) && paramMap.get(MesPcnExtConstWords.STATUS).equals(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValueStr())) return true; + + return false; + } + } diff --git a/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/bean/SxWorkCellTaktCollectPlcCfg.java b/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/bean/SxWorkCellTaktCollectPlcCfg.java index bee91e7..a643e00 100644 --- a/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/bean/SxWorkCellTaktCollectPlcCfg.java +++ b/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/bean/SxWorkCellTaktCollectPlcCfg.java @@ -27,36 +27,28 @@ import java.io.Serializable; @EqualsAndHashCode(callSuper = true) @Table(name = "MES_TIME_SEGMENT_STATISTICS", indexes = { @Index(columnList = "SYSTEM_SYNC_STATUS"), - @Index(columnList = "WORK_CENTER_CODE, SHIFT_CODE") + @Index(columnList = "WORK_CENTER_CODE") }) -@Api("MES_分时段统计方式表") -public class MesTimeSegmentStatistics extends BaseBean implements Serializable { +@Api("松下工位节拍PLC配置表") +public class SxWorkCellTaktCollectPlcCfg extends BaseBean implements Serializable { - private static final long serialVersionUID = -5490654692344095490L; + private static final long serialVersionUID = -3461472423451230096L; @Column(name = "WORK_CENTER_CODE") @ApiParam("工作中心代码") private String workCenterCode; - @Column(name = "SHIFT_CODE") - @ApiParam("班次") - private String shiftCode; - - @Column(name = "START_TIME") - @ApiParam("开始时间") - private String startTime; - - @Column(name = "END_TIME") - @ApiParam("结束时间") - private String endTime; + @Column(name = "WORK_CELL_CODE") + @ApiParam("工作中心代码") + private String workCellCode; - @Column(name = "TIME_LENGTH") - @ApiParam("实际工作时间长度(分钟)") - private String timeLength; + @Column(name = "PLC_CODE") + @ApiParam("PLC代码") + private String plcCode; - @Column(name = "TIME_SEGMENT_CODE") - @ApiParam("分时代码(方便统计)") - private String timeSegmentCode; + @Column(name = "STATUS") + @ApiParam("状态") + private Integer status; @Column(name = "SYSTEM_SYNC_STATUS") @ColumnDefault("2") diff --git a/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/repository/SxWorkCellTaktCollectPlcCfgRepository.java b/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/repository/SxWorkCellTaktCollectPlcCfgRepository.java index ab6dc23..0838cd1 100644 --- a/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/repository/SxWorkCellTaktCollectPlcCfgRepository.java +++ b/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/repository/SxWorkCellTaktCollectPlcCfgRepository.java @@ -1,6 +1,6 @@ package cn.estsh.i3plus.ext.mes.pcn.pojo.repository; -import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.SxWorkCellTaktCollectRecord; +import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.SxWorkCellTaktCollectPlcCfg; import cn.estsh.i3plus.pojo.base.jpa.dao.BaseRepository; import org.springframework.stereotype.Repository; @@ -10,5 +10,5 @@ import org.springframework.stereotype.Repository; * @date 2021/1/29 15:02 **/ @Repository -public interface SxWorkCellTaktCollectRecordRepository extends BaseRepository { +public interface SxWorkCellTaktCollectPlcCfgRepository extends BaseRepository { } diff --git a/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/util/MesPcnExtConstWords.java b/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/util/MesPcnExtConstWords.java index 1482b9c..0c9cff0 100644 --- a/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/util/MesPcnExtConstWords.java +++ b/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/util/MesPcnExtConstWords.java @@ -1011,4 +1011,7 @@ public class MesPcnExtConstWords { //PLC放行值 public static final String PLC_PASS_VALUE = "PLC_PASS_VALUE"; + //策略实现类 + public static final String STRATEGY_CLASS = "strategyClass"; + }