|
@@ -1,9 +1,19 @@
|
|
|
package com.example.opc_da.dynamicSchedule;
|
|
|
|
|
|
+import com.example.opc_common.entity.DataSource;
|
|
|
+import com.example.opc_common.entity.DataSourceType;
|
|
|
+import com.example.opc_common.entity.ItemGroup;
|
|
|
import com.example.opc_common.entity.ReportTable;
|
|
|
+import com.example.opc_common.enums.DataSourceTypeEnum;
|
|
|
+import com.example.opc_common.enums.OpcDaDriverEnum;
|
|
|
+import com.example.opc_common.enums.ResultEnum;
|
|
|
+import com.example.opc_common.exception.CustomException;
|
|
|
import com.example.opc_common.util.Blank;
|
|
|
import com.example.opc_common.util.ConstantStr;
|
|
|
+import com.example.opc_da.dao.DataSourceDao;
|
|
|
+import com.example.opc_da.dao.ItemGroupDao;
|
|
|
import com.example.opc_da.dao.ReportTableDao;
|
|
|
+import com.example.opc_da.task.OpcDaTask;
|
|
|
import com.example.opc_da.task.ReportTableTask;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
@@ -12,6 +22,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
@Slf4j
|
|
|
@Configuration
|
|
@@ -22,6 +33,12 @@ public class DynamicScheduleConfig implements SchedulingConfigurer {
|
|
|
ReportTableDao reportTableDao;
|
|
|
|
|
|
@Resource
|
|
|
+ private ItemGroupDao itemGroupDao;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private DataSourceDao dataSourceDao;
|
|
|
+
|
|
|
+ @Resource
|
|
|
CronTaskRegister cronTaskRegister;
|
|
|
|
|
|
@Override
|
|
@@ -38,5 +55,51 @@ public class DynamicScheduleConfig implements SchedulingConfigurer {
|
|
|
cronTaskRegister.addCronTask(new SchedulingRunnable(ReportTableTask.class, "getTableData", new Object[]{reportTable}), reportTable.getCronId(), reportTable.getCron());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ List<ItemGroup> itemGroupList = itemGroupDao.getAllItemGroup(null);
|
|
|
+ if (Blank.isNotEmpty(itemGroupList)) {
|
|
|
+ for (ItemGroup itemGroup : itemGroupList) {
|
|
|
+ String readWeek = itemGroup.getReadWeek();
|
|
|
+ DataSource dataSource = DataSource.convertPassword(dataSourceDao.getDataSourceById(itemGroup.getDataSourceId()));
|
|
|
+ String clsId = dataSource.getClsId().toUpperCase();
|
|
|
+ DataSourceType dataSourceType = dataSourceDao.getDataSourceTypeById(dataSource.getTypeId());
|
|
|
+ if (dataSourceType.getDataSourceTypeKey().equals(DataSourceTypeEnum.OPC_DA_REAL.getValue()) ||
|
|
|
+ dataSourceType.getDataSourceTypeKey().equals(DataSourceTypeEnum.OPC_AE_ALARMS.getValue()) ||
|
|
|
+ dataSourceType.getDataSourceTypeKey().equals(DataSourceTypeEnum.OPC_HDA_HISTORY.getValue())) {
|
|
|
+ if (itemGroup.getRunState() == ConstantStr.START_UP) {
|
|
|
+ if (Blank.isEmpty(dataSource.getIpAddress(), dataSource.getIpUserName(), dataSource.getIpPassword())) {
|
|
|
+ throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "数据组配置的数据源的ip地址,帐户,密码都不能为空");
|
|
|
+ }
|
|
|
+ Integer id = itemGroup.getId();
|
|
|
+ if (clsId.equals(OpcDaDriverEnum.KEPSERVER.getValue()) ||
|
|
|
+ clsId.equals(OpcDaDriverEnum.OPCIFIX.getValue()) ||
|
|
|
+ clsId.equals(OpcDaDriverEnum.WINCC.getValue()) ||
|
|
|
+ clsId.equals(OpcDaDriverEnum.SCADA.getValue()) ||
|
|
|
+ clsId.equals(OpcDaDriverEnum.YOKOGAWA.getValue()) ||
|
|
|
+ clsId.equals(OpcDaDriverEnum.PAS300.getValue())
|
|
|
+ ) {
|
|
|
+ //新增定时器任务
|
|
|
+ String cronId = "";
|
|
|
+ String cron = "0 0 0 ? * ";
|
|
|
+ if (Blank.isEmpty(readWeek)) {
|
|
|
+ cron = cron + "MON,TUE,WED,THU,FRI,SAT,SUN";
|
|
|
+ } else {
|
|
|
+ cron = cron + itemGroup.getReadWeek();
|
|
|
+ }
|
|
|
+ if (Blank.isEmpty(itemGroup.getCronId())) {
|
|
|
+ cronId = UUID.randomUUID().toString().replace("-", "");
|
|
|
+ } else {
|
|
|
+ cronId = itemGroup.getCronId();
|
|
|
+ }
|
|
|
+ SchedulingRunnable task = new SchedulingRunnable(OpcDaTask.class, "opcDaTask", new Object[]{itemGroup, dataSource, cronId});
|
|
|
+ cronTaskRegister.addCronTask(task, cronId, cron);
|
|
|
+ itemGroupDao.runItemGroupById(id, ConstantStr.START_UP, cronId);
|
|
|
+ } else {
|
|
|
+ throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前未适配此种驱动类型");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|