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 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 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); } }