package com.moral.task; import java.time.LocalDateTime; import java.util.List; import java.util.Map; import javax.annotation.Resource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; import com.moral.service.AlarmService; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.annotation.XxlJob; @Component public class AlarmTableInsertTask { private static transient Logger logger = LoggerFactory.getLogger(AlarmTableInsertTask.class); @Resource private AlarmService alarmService; @XxlJob("alarmDaily") public ReturnT insertAlarmDailyTable() { List> list = alarmService.getAlarmData(); if (!CollectionUtils.isEmpty(list)) { alarmService.insertAlarmDaily(list); return new ReturnT(200, "插入天表成功"); } return new ReturnT(500, "插入天表失败"); } @XxlJob("createAlarmSubTable") public ReturnT createAlarmSubTable() { LocalDateTime time = LocalDateTime.now().plusMonths(1); String year = time.getYear() + ""; String month = time.getMonthValue() + ""; if (time.getMonthValue() < 10) { month = "0" + time.getMonthValue(); } alarmService.createTable(year + month); ReturnT returnT = new ReturnT(200, "创建alarm年月分表成功"); return returnT; } }