src/main/java/com/moral/mapper/HistoryMapper.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/service/HistoryService.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/service/impl/HistoryServiceImpl.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/task/HistoryTableCreatAndDeleteTask.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/task/HistoryTableDeleteTask.java | ●●●●● patch | view | raw | blame | history | |
src/main/resources/mapper/HistoryMapper.xml | ●●●●● patch | view | raw | blame | history |
src/main/java/com/moral/mapper/HistoryMapper.java
@@ -33,4 +33,6 @@ void deletePartition(@Param("p") String p); void createHistoryTable(@Param("yearMonthDay") String yearMonthDay); } src/main/java/com/moral/service/HistoryService.java
@@ -14,4 +14,6 @@ int deleteHistoryData(String oldTime); void deletePartition(String p); void createHistoryTable(String yearMonthDay); } src/main/java/com/moral/service/impl/HistoryServiceImpl.java
@@ -36,4 +36,9 @@ public void deletePartition(String p) { historyMapper.deletePartition(p); } @Override public void createHistoryTable(String yearMonthDay) { historyMapper.createHistoryTable(yearMonthDay); } } src/main/java/com/moral/task/HistoryTableCreatAndDeleteTask.java
New file @@ -0,0 +1,36 @@ package com.moral.task; import javax.annotation.Resource; import com.moral.service.HistoryService; import com.moral.util.DateUtil; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.annotation.XxlJob; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import java.text.SimpleDateFormat; import java.util.Date; @Component public class HistoryTableCreatAndDeleteTask { private static transient Logger logger = LoggerFactory.getLogger(HistoryTableInsertTask.class); @Resource private HistoryService historyService; @XxlJob("deleteHitoryTable") public ReturnT deleteHistoryTable(String param) { return new ReturnT(200,"删除成功"); } @XxlJob("createHistoryTable") public ReturnT createHistoryTable(String param) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String yearMonthDay = sdf.format(DateUtil.rollHour(new Date(),24)); historyService.createHistoryTable(yearMonthDay); return new ReturnT(200,"创建成功"); } } src/main/java/com/moral/task/HistoryTableDeleteTask.java
File was deleted src/main/resources/mapper/HistoryMapper.xml
@@ -247,4 +247,16 @@ <update id="deletePartition"> ALTER table history drop PARTITION ${p}; </update> <update id="createHistoryTable" parameterType="String"> CREATE TABLE history_${yearMonthDay} ( `mac` varchar(20) DEFAULT NULL, `value` json DEFAULT NULL, `time` datetime DEFAULT NULL, `version` int(11) DEFAULT NULL, KEY `_idx_mac_time` (`mac`,`time`) USING BTREE, KEY `_idx_mac` (`mac`) USING BTREE, KEY `_idx_time` (`time`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC </update> </mapper>