浏览代码

ws-设备报表子报表修改

ws 11 月之前
父节点
当前提交
786f9bd85f

+ 41 - 0
industry-system/industry-da/src/main/java/com/example/opc_da/task/DeviceTableQuartzTask.java

@@ -0,0 +1,41 @@
+package com.example.opc_da.task;
+
+import cn.hutool.core.util.IdUtil;
+import com.example.opc_common.entity.ReportTable;
+import com.example.opc_common.util.ConstantStr;
+import com.example.opc_common.util.DateUtil;
+import com.example.opc_da.validate.reportTable.ReportTableValidateFactory;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.SerializationUtils;
+import org.quartz.JobDataMap;
+import org.quartz.JobExecutionContext;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.quartz.QuartzJobBean;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+
+@Slf4j
+@Component
+public class DeviceTableQuartzTask extends QuartzJobBean {
+
+    @Autowired
+    private AsyncTask asyncTask;
+
+    @Override
+    protected void executeInternal(JobExecutionContext context) {
+        JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
+        ReportTable reportTable = (ReportTable) jobDataMap.get("reportTable");
+        log.info("自动报表,{},执行开始,时间为{}", reportTable.getId(), DateUtil.dateChangeStrYmdhmss(new Date()));
+        //使用深拷贝或者其他方式创建一个新的报表对象,并将其设置为运行状态
+        ReportTable newReportTable = SerializationUtils.clone(reportTable);
+        newReportTable.setRunState(ConstantStr.START_UP);
+        //生成一张新的子报表,并添加相应的日志,以及用户组授权
+        String id = IdUtil.createSnowflake(1, 1).nextId() + "";
+        asyncTask.addHaveKeyChReport(reportTable.getId(), id, ConstantStr.DEVICE_GENERATE_REPORT,
+                ReportTableValidateFactory.getReportTableValidate(
+                        reportTable.getReportTableType()
+                ).getData(newReportTable).getReportTableData(), true);
+        log.info("自动报表,{},执行结束,时间为{}", reportTable.getId(), DateUtil.dateChangeStrYmdhmss(new Date()));
+    }
+}

+ 38 - 0
industry-system/industry-da/src/main/java/com/example/opc_da/task/DeviceTableTimerTask.java

@@ -0,0 +1,38 @@
+package com.example.opc_da.task;
+
+import cn.hutool.core.util.IdUtil;
+import com.example.opc_common.entity.ReportTable;
+import com.example.opc_common.util.ConstantStr;
+import com.example.opc_common.util.DateUtil;
+import com.example.opc_da.config.SpringContextUtils;
+import com.example.opc_da.timer.PeriodTimerTask;
+import com.example.opc_da.validate.reportTable.ReportTableValidateFactory;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.SerializationUtils;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.Map;
+
+@Slf4j
+@Component
+public class DeviceTableTimerTask extends PeriodTimerTask {
+
+    AsyncTask asyncTask = SpringContextUtils.getBean(AsyncTask.class);
+
+    @Override
+    protected void runInit(Map<String, Object> map) {
+        ReportTable reportTable = (ReportTable) map.get("reportTable");
+        log.info("自动报表,{},执行开始,时间为{}", reportTable.getId(), DateUtil.dateChangeStrYmdhmss(new Date()));
+        //使用深拷贝或者其他方式创建一个新的报表对象,并将其设置为运行状态
+        ReportTable newReportTable = SerializationUtils.clone(reportTable);
+        newReportTable.setRunState(ConstantStr.START_UP);
+        //生成一张新的子报表,并添加相应的日志,以及用户组授权
+        String id = IdUtil.createSnowflake(1, 1).nextId() + "";
+        asyncTask.addHaveKeyChReport(reportTable.getId(), id, ConstantStr.DEVICE_GENERATE_REPORT,
+                ReportTableValidateFactory.getReportTableValidate(
+                        reportTable.getReportTableType()
+                ).getData(newReportTable).getReportTableData(), true);
+        log.info("自动报表,{},执行结束,时间为{}", reportTable.getId(), DateUtil.dateChangeStrYmdhmss(new Date()));
+    }
+}

+ 4 - 2
industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/DeviceMaReportTableValidate.java

@@ -16,6 +16,8 @@ import com.example.opc_da.dao.DictDao;
 import com.example.opc_da.dao.ReportTableDao;
 import com.example.opc_da.task.AutoTableQuartzTask;
 import com.example.opc_da.task.AutoTableTimerTask;
+import com.example.opc_da.task.DeviceTableQuartzTask;
+import com.example.opc_da.task.DeviceTableTimerTask;
 import com.example.opc_da.timer.PeriodTimerFactory;
 import com.example.opc_da.timer.QuartzTimerFactory;
 import org.quartz.CronExpression;
@@ -75,9 +77,9 @@ public class DeviceMaReportTableValidate extends DeviceReportTableValidate {
             Integer type = reportTable.getType();
             map.put("reportTable", reportTable);
             if (type.equals(0)) {
-                PeriodTimerFactory.creteTimer().addTask(cronId, AutoTableTimerTask.class, cron, map);
+                PeriodTimerFactory.creteTimer().addTask(cronId, DeviceTableTimerTask.class, cron, map);
             } else if (type.equals(1)) {
-                QuartzTimerFactory.creteTimer().addTask(cronId, AutoTableQuartzTask.class, cron, map);
+                QuartzTimerFactory.creteTimer().addTask(cronId, DeviceTableQuartzTask.class, cron, map);
             } else {
                 throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前没有此种类型的定时器");
             }