|
@@ -17,11 +17,7 @@ import com.example.opc_da.dao.ReportTableDao;
|
|
|
import com.example.opc_da.policy.ChangeReportDataPolicyTaskRegister;
|
|
|
import com.example.opc_da.policy.EventReportDataPolicyTaskRegister;
|
|
|
import com.example.opc_da.policy.FreReportDataPolicyTaskRegister;
|
|
|
-import com.example.opc_da.task.AutoTableQuartzTask;
|
|
|
-import com.example.opc_da.task.AutoTableTimerTask;
|
|
|
import com.example.opc_da.service.ReportTableService;
|
|
|
-import com.example.opc_da.timer.PeriodTimerFactory;
|
|
|
-import com.example.opc_da.timer.QuartzTimerFactory;
|
|
|
import com.example.opc_da.util.RedisUtil;
|
|
|
import com.example.opc_da.util.UserUtil;
|
|
|
import com.example.opc_da.validate.reportTable.ReportTableValidate;
|
|
@@ -502,101 +498,7 @@ public class ReportTableServiceImpl implements ReportTableService {
|
|
|
if (Blank.isEmpty(reportTable)) {
|
|
|
return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "报表不存在,请刷新后再试");
|
|
|
}
|
|
|
- Integer reportTableType = reportTable.getReportTableType();
|
|
|
- if (Blank.isEmpty(reportTableType)) {
|
|
|
- return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "未知报表类型,请刷新重试");
|
|
|
- }
|
|
|
- if (reportTableType.equals(ConstantStr.AUTOMATIC_REPORT)) {
|
|
|
- Integer oldRunState = reportTable.getRunState();
|
|
|
- String cronId = reportTable.getCronId();
|
|
|
- if (Blank.isEmpty(cronId)) {
|
|
|
- return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "请先配置定时时间");
|
|
|
- }
|
|
|
- String cron = reportTable.getCron();
|
|
|
- if (Blank.isEmpty(oldRunState)) {
|
|
|
- return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "未知报表运行状态,请刷新重试");
|
|
|
- }
|
|
|
- reportTableDao.runAutoTableById(id, runState);
|
|
|
- if (runState.equals(ConstantStr.START_UP)) {
|
|
|
- if (Blank.isEmpty(cron)) {
|
|
|
- return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "请先配置定时时间");
|
|
|
- }
|
|
|
- if (oldRunState.equals(ConstantStr.START_UP)) {
|
|
|
- return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "此自动报表已经处于启动状态");
|
|
|
- }
|
|
|
- //新增定时器任务
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
- Integer type = reportTable.getType();
|
|
|
- map.put("reportTable", reportTable);
|
|
|
- if (type.equals(0)) {
|
|
|
- PeriodTimerFactory.creteTimer().addTask(cronId, new AutoTableTimerTask(), Integer.valueOf(cron), map);
|
|
|
- } else if (type.equals(1)) {
|
|
|
- QuartzTimerFactory.creteTimer().addTask(cronId, AutoTableQuartzTask.class, cron, map);
|
|
|
- } else {
|
|
|
- throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前没有此种类型的定时器");
|
|
|
- }
|
|
|
- return Result.ok("启动成功");
|
|
|
- } else if (runState.equals(ConstantStr.STOP_IT)) {
|
|
|
- if (Blank.isEmpty(cronId)) {
|
|
|
- throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "定时器主键丢失,停止失败");
|
|
|
- }
|
|
|
- if (oldRunState.equals(ConstantStr.STOP_IT)) {
|
|
|
- return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "此自动报表已经处于停止状态");
|
|
|
- }
|
|
|
- Integer type = reportTable.getType();
|
|
|
- if (type.equals(0)) {
|
|
|
- PeriodTimerFactory.creteTimer().delTask(cronId);
|
|
|
- } else if (type.equals(1)) {
|
|
|
- QuartzTimerFactory.creteTimer().delTask(cronId);
|
|
|
- } else {
|
|
|
- throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前没有此种类型的定时器");
|
|
|
- }
|
|
|
- return Result.ok("停止成功");
|
|
|
- } else {
|
|
|
- throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "自动报表的状态只有启动或停止");
|
|
|
- }
|
|
|
- } else if (reportTableType.equals(ConstantStr.EVENT_DRIVEN_REPORT)) {
|
|
|
- Integer oldRunState = reportTable.getRunState();
|
|
|
- reportTableDao.runAutoTableById(id, runState);
|
|
|
- if (runState.equals(ConstantStr.START_UP)) {
|
|
|
- if (oldRunState.equals(ConstantStr.START_UP)) {
|
|
|
- return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "此报表已经处于启动状态");
|
|
|
- }
|
|
|
- eventReportDataPolicyTaskRegister.addReportTableTask(reportTable);
|
|
|
- redisUtil.set(ConstantStr.TABLE_ID + id, true);
|
|
|
- return Result.ok("启动成功");
|
|
|
- } else if (runState.equals(ConstantStr.STOP_IT)) {
|
|
|
- eventReportDataPolicyTaskRegister.removeReportTable(reportTable);
|
|
|
- if (oldRunState.equals(ConstantStr.STOP_IT)) {
|
|
|
- return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "此报表已经处于停止状态");
|
|
|
- }
|
|
|
- redisUtil.set(ConstantStr.TABLE_ID + id, false);
|
|
|
- return Result.ok("停止成功");
|
|
|
- } else {
|
|
|
- throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "报表的状态只有启动或停止");
|
|
|
- }
|
|
|
- } else if (reportTableType.equals(ConstantStr.DEVICE_REPORT)) {
|
|
|
- Integer oldRunState = reportTable.getRunState();
|
|
|
- reportTableDao.runAutoTableById(id, runState);
|
|
|
- if (runState.equals(ConstantStr.START_UP)) {
|
|
|
- if (oldRunState.equals(ConstantStr.START_UP)) {
|
|
|
- return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "此报表已经处于启动状态");
|
|
|
- }
|
|
|
-// eventReportDataPolicyTaskRegister.addReportTableTask(reportTable);
|
|
|
- redisUtil.set(ConstantStr.TABLE_ID + id, true);
|
|
|
- return Result.ok("启动成功");
|
|
|
- } else if (runState.equals(ConstantStr.STOP_IT)) {
|
|
|
- if (oldRunState.equals(ConstantStr.STOP_IT)) {
|
|
|
- return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "此报表已经处于停止状态");
|
|
|
- }
|
|
|
- redisUtil.set(ConstantStr.TABLE_ID + id, false);
|
|
|
- return Result.ok("停止成功");
|
|
|
- } else {
|
|
|
- throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "报表的状态只有启动或停止");
|
|
|
- }
|
|
|
- } else {
|
|
|
- return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "自动,事件驱动,设备报表才可以启动和停止");
|
|
|
- }
|
|
|
+ return ReportTableValidateFactory.getReportTableValidate(reportTable.getReportTableType()).runTable(id, runState, reportTable);
|
|
|
}
|
|
|
|
|
|
public List<Integer> gen(List<Integer> dictIdList, List<Dict> dictList, Integer dictId) {
|