screen-job/src/main/java/com/moral/api/mapper/AlarmInfoMapper.java
@@ -13,4 +13,6 @@ */ public interface AlarmInfoMapper extends BaseMapper<AlarmInfo> { void createTable(String timeUnits); } screen-job/src/main/java/com/moral/api/service/AlarmInfoService.java
@@ -12,5 +12,14 @@ * @since 2021-11-12 */ public interface AlarmInfoService extends IService<AlarmInfo> { /** *@Description: 创建污染警报表 *@Param: [timeUnits] *@return: void *@Author: lizijie *@Date: 2022/1/5 15:55 **/ void createTable(String timeUnits); } screen-job/src/main/java/com/moral/api/service/impl/AlarmInfoServiceImpl.java
@@ -4,6 +4,7 @@ import com.moral.api.mapper.AlarmInfoMapper; import com.moral.api.service.AlarmInfoService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** @@ -17,4 +18,11 @@ @Service public class AlarmInfoServiceImpl extends ServiceImpl<AlarmInfoMapper, AlarmInfo> implements AlarmInfoService { @Autowired private AlarmInfoMapper alarmInfoMapper; @Override public void createTable(String timeUnits) { alarmInfoMapper.createTable(timeUnits); } } screen-job/src/main/java/com/moral/api/task/CreateTableTask.java
@@ -1,5 +1,6 @@ package com.moral.api.task; import com.moral.api.service.AlarmInfoService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -23,6 +24,9 @@ @Autowired private HistoryHourlyService historyHourlyService; @Autowired private AlarmInfoService alarmInfoService; //分钟表创建任务 @@ -82,4 +86,17 @@ } return ReturnT.SUCCESS; } //小时表创建任务 @XxlJob("createAlarmInfoTable") public ReturnT createAlarmInfoTable() { String timeUnits = DateUtils.getDateStringOfMon(1, DateUtils.yyyyMM_EN); try { alarmInfoService.createTable(timeUnits); } catch (Exception e) { XxlJobHelper.log(e.getMessage()); return new ReturnT(ReturnT.FAIL_CODE, e.getMessage()); } return ReturnT.SUCCESS; } } screen-job/src/main/resources/mapper/AlarmInfoMapper.xml
@@ -13,4 +13,17 @@ <result column="create_time" property="createTime" /> </resultMap> <update id="createTable" parameterType="String"> CREATE TABLE IF NOT EXISTS `alarm_info_${timeUnits}` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id', `alarm_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '报警时间', `index` varchar(255) NOT NULL COMMENT '指标(因子)', `device_id` int(11) NOT NULL COMMENT '点位(设备)', `alarm_type` varchar(255) NOT NULL COMMENT '报警类型', `alarm_information` varchar(255) NOT NULL COMMENT '报警信息', `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '报警信息小时表'; </update> </mapper>