package cn.com.goldenwater.dcproj.task; import cn.com.goldenwater.dcproj.constValue.CommonLabel; import cn.com.goldenwater.dcproj.dao.BisInspAllDao; import cn.com.goldenwater.dcproj.dto.DataDto; import cn.com.goldenwater.dcproj.dto.OrgDto; import cn.com.goldenwater.dcproj.dto.UserLineDto; import cn.com.goldenwater.dcproj.service.BisInspMileageService; import cn.com.goldenwater.dcproj.service.CountTaskService; import cn.com.goldenwater.dcproj.utils.InspUtils; import net.sf.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @Component @EnableScheduling public class CountDataTask { private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private CountTaskService countTaskService; @Autowired private BisInspMileageService bisInspMileageService; @Autowired private RedisTemplate redisTemplate; @Autowired private BisInspAllDao bisInspAllDao; /** * 统计当前的数据-实时 */ // @Scheduled(cron = "0 0/3 * * * ?") public void submitTj() { // 获取所有省 List orgDtoList = bisInspAllDao.findOrgMsg(); long time = System.currentTimeMillis(); String nowTime = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); Map userMap = new HashMap<>(); DataDto dataDto = null; List userLineDtoList = bisInspAllDao.countUserLine2(null); for (OrgDto orgDto : orgDtoList) { dataDto = bisInspAllDao.countSysMsg(nowTime, orgDto.getOrgId()); if (dataDto != null) { for (UserLineDto lineDto : userLineDtoList) { if (lineDto.getOrgId().equals(orgDto.getOrgId())) { userMap.put("totalPers", "" + lineDto.getPersTotal()); userMap.put("icePers", "" + (lineDto.getPersTotal() - lineDto.getActiveUser())); } } userMap.put("duchaType", "" + dataDto.getDuchaType()); userMap.put("duchaGroup", "" + dataDto.getDuchaGroup()); userMap.put("duchaPers", "" + dataDto.getDuchaPers()); userMap.put("duchaObj", "" + dataDto.getDuchaObj()); userMap.put("duchaPblm", "" + dataDto.getDuchaPblm()); userMap.put("platformName", orgDto.getOrgNm()); JSONObject jsonObject = JSONObject.fromObject(userMap); logger.info("数据推送:" + jsonObject.toString()); redisTemplate.convertAndSend(CommonLabel.SEND_TO_UPDATE, jsonObject); } } long haishi = System.currentTimeMillis() - time; logger.info("耗时:" + haishi + "毫秒!!"); } @Scheduled(cron = "0 32 08 * * ?") public void initData() { countTaskService.countData(""); } @Value("${export.basePath.docx}") private String docxPath; @Scheduled(cron = "0 0 19 * * ?") public void delTempDoc() { logger.info("删除rever,vill,track临时文件"); File file = new File(docxPath); InspUtils.initTempDocFile(file); } @Scheduled(cron = "0 34 23 * * ?") public void delTempLog() { logger.info("删除log4j日志临时文件"); File file = new File("../logs"); InspUtils.initTempDocFile(file); } @Scheduled(cron = "0 20 23 * * ?") public void calMileage() { logger.info("=====开始计算人员里程====="); long stime = System.currentTimeMillis(); try { bisInspMileageService.calMilage(); } catch (Exception e) { logger.error("定时计算里程出错", e); } long etime = System.currentTimeMillis(); logger.info(String.format("=====里程计算结束,耗时%d s=====", (etime - stime) / 1000)); } }