EqpReportStatisticJob.java
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.zteits.park.job;
import org.apache.commons.lang3.StringUtils;
import com.clouds.common.utils.DateUtil;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.zteits.clouds.api.apibase.constants.DataStatusEnum;
import com.zteits.park.dao.TpPEqpReportStatisticDao;
import com.zteits.park.domain.TpPEqpReportStatistic;
import com.zteits.park.mapper.smapper.TpPEqpReportStatisticSMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
@Component
public class EqpReportStatisticJob{
private static final Logger logger = LoggerFactory.getLogger(EqpReportStatisticJob.class);
@Autowired
private TpPEqpReportStatisticSMapper tpPEqpReportStatisticSMapper;
@Autowired
private TpPEqpReportStatisticDao tpPEqpReportStatisticDao;
@XxlJob("eqpReportStatisticJob")
public ReturnT<String> execute(String... params) throws Exception {
String param = XxlJobHelper.getJobParam();
if (StringUtils.isNotEmpty(param) && params == null) {
params = param.split(",");
}
log("开始统计昨天设备上报次数");
LocalDate date = LocalDate.now();
LocalDate yesterday = date.minusDays(1L);
String tableName = "tp_p_eqp_log"+yesterday.format(DateTimeFormatter.ofPattern(DateUtil.YYYYMM));
log("表名:"+tableName);
final String yesterdayStr = yesterday.toString();
log("统计日期:"+yesterdayStr);
List<TpPEqpReportStatistic> tpPEqpReportStatistics = tpPEqpReportStatisticSMapper.statisticReportNum(tableName, yesterdayStr);
if(tpPEqpReportStatistics==null || CollectionUtils.isEmpty(tpPEqpReportStatistics)){
log("没有查询到数据");
return ReturnT.SUCCESS;
}
log("查询到数据条数为:"+tpPEqpReportStatistics.size());
Date now = new Date();
tpPEqpReportStatistics.forEach(item->{
item.setCreateTime(now);
item.setDataState(DataStatusEnum.DATA_STATUS_VALID.value());
item.setModifyTime(now);
item.setStatisticBeginTime(yesterdayStr);
item.setStatisticEndTime(yesterdayStr);
item.setStatisticType(1);
});
tpPEqpReportStatisticDao.saveEqpReportStatistic(tpPEqpReportStatistics, yesterdayStr);
return ReturnT.SUCCESS;
}
private void log(String msg){
XxlJobHelper.log(msg);
logger.info(msg);
}
}