package com.zteits.park.job; import org.apache.commons.lang3.StringUtils; 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.park.dao.ParkinglotHeatmapDayDao; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; /** * 企业云平台-->停车热力分布图-->按照天.
* * Copyright: Copyright (c) 2017 zteits * * @ClassName: ParkingLotHeatMapHourJob.java * @Description: * @version: v1.0.0 * @author: wangfs * @date: 2017年7月10日 下午5:24:36 * Modification History: * Date Author Version Description *---------------------------------------------------------* * 2017年7月10日 wangfs v1.0.0 创建 */ @Component public class ParkingLotHeatMapDayJob{ private static final Logger logger = LoggerFactory.getLogger(ParkingLotHeatMapDayJob.class); @Autowired private ParkinglotHeatmapDayDao parkinglotHeatmapDayDao; /** * 企业云平台-->停车热力分布图-->按照天.
* 描述:1.每天 2点 执行, 0 0 2 * * ? * * * */ @XxlJob("ParkingLotHeatMapDayJob") public ReturnT execute(String... params) throws Exception { String param = XxlJobHelper.getJobParam(); if (StringUtils.isNotEmpty(param) && params == null) { params = param.split(","); } SimpleDateFormat formart = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat formartDate = new SimpleDateFormat("yyyy-MM-dd"); Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); cal.add(Calendar.DAY_OF_MONTH, -1); Integer insertCount = 0 ; this.log("--begin---企业云平台-->停车热力分布图-->按照天..."+formart.format(new Date())); try{ this.log("插入数据DayTime= "+formartDate.format(cal.getTime())); Date heatmapTime = formartDate.parse(formartDate.format(cal.getTime())); insertCount = this.executeparkinglotHeatmapDay(heatmapTime); }catch (Exception e) { if (e instanceof InterruptedException) { throw e; } logger.warn("{}", e); } this.log("--end---企业云平台-->停车热力分布图-->按照天..."+formart.format(new Date())); return insertCount >0 ? ReturnT.SUCCESS :ReturnT.FAIL; } private Integer executeparkinglotHeatmapDay(Date heatmapTime){ SimpleDateFormat formartDate = new SimpleDateFormat("yyyy-MM-dd"); this.log("begin删除数据,入参="+formartDate.format(heatmapTime)); Integer deleteCount = parkinglotHeatmapDayDao.deleteParkinglotHeatmapDayByheatmapTime(heatmapTime); this.log("end删除数据,结果,删除条数="+deleteCount+" 条。"); this.log("begin插入数据,入参="+formartDate.format(heatmapTime)); Integer insertCount = parkinglotHeatmapDayDao.insertParkinglotHeatmapDayList(heatmapTime); this.log("end插入数据,结果,插入条数="+insertCount+" 条。"); return insertCount; } private void log(String msg){ XxlJobHelper.log(msg); logger.info(msg); } }