kaiyu
2020-11-19 f2cfc6973ec1b43391654b4bd722c2c316d06fc7
增加删除天表代码
5 files modified
29 ■■■■ changed files
src/main/java/com/moral/mapper/HistoryMapper.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/HistoryService.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/HistoryServiceImpl.java 5 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/task/HistoryTableCreatAndDeleteTask.java 16 ●●●● patch | view | raw | blame | history
src/main/resources/mapper/HistoryMapper.xml 4 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/mapper/HistoryMapper.java
@@ -35,4 +35,6 @@
    void createHistoryTable(@Param("yearMonthDay") String yearMonthDay);
    void dropHistoryTable(@Param("yearMonthDay") String yearMonthDay);
}
src/main/java/com/moral/service/HistoryService.java
@@ -16,4 +16,6 @@
    void deletePartition(String p);
    void createHistoryTable(String yearMonthDay);
    void dropHistoryTable(String yearMonthDay);
}
src/main/java/com/moral/service/impl/HistoryServiceImpl.java
@@ -41,4 +41,9 @@
    public void createHistoryTable(String yearMonthDay) {
        historyMapper.createHistoryTable(yearMonthDay);
    }
    @Override
    public void dropHistoryTable(String yearMonthDay) {
        historyMapper.dropHistoryTable(yearMonthDay);
    }
}
src/main/java/com/moral/task/HistoryTableCreatAndDeleteTask.java
@@ -22,20 +22,28 @@
    @XxlJob("deleteHitoryTable")
    public ReturnT deleteHistoryTable(String param) {
       return new ReturnT(200,"删除成功");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String yearMonthDay = sdf.format(DateUtil.rollHour(new Date(), -8*24));
        try {
            historyService.dropHistoryTable(yearMonthDay);
        } catch (Exception e) {
            logger.error(e.getMessage());
            return new ReturnT(500, "history_" + yearMonthDay + "删除失败");
        }
        return new ReturnT(200, "history_" + yearMonthDay + "删除成功");
    }
    @XxlJob("createHistoryTable")
    public ReturnT createHistoryTable(String param) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            String yearMonthDay = sdf.format(DateUtil.rollHour(new Date(), 24));
        try {
            historyService.createHistoryTable(yearMonthDay);
        }catch (Exception e){
            logger.error(e.getMessage());
            return new ReturnT(500,"history天表失败");
            return new ReturnT(500, "history_" + yearMonthDay + "创建失败");
        }
        return new ReturnT(200,"history天表创建成功");
        return new ReturnT(200, "history_" + yearMonthDay + "创建成功");
    }
}
src/main/resources/mapper/HistoryMapper.xml
@@ -259,4 +259,8 @@
        KEY `_idx_time` (`time`) USING BTREE
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC
    </update>
    <delete id="dropHistoryTable" parameterType="String">
        drop table history_${yearMonthDay}
    </delete>
</mapper>