c3c500e8148b0ca8911e8d3cc02069871203391b.svn-base 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package cn.com.goldenwater.dcproj.task;
  2. import cn.com.goldenwater.dcproj.constValue.CommonLabel;
  3. import cn.com.goldenwater.dcproj.dao.BisInspAllDao;
  4. import cn.com.goldenwater.dcproj.dto.DataDto;
  5. import cn.com.goldenwater.dcproj.dto.OrgDto;
  6. import cn.com.goldenwater.dcproj.dto.UserLineDto;
  7. import cn.com.goldenwater.dcproj.service.BisInspMileageService;
  8. import cn.com.goldenwater.dcproj.service.CountTaskService;
  9. import cn.com.goldenwater.dcproj.utils.InspUtils;
  10. import net.sf.json.JSONObject;
  11. import org.slf4j.Logger;
  12. import org.slf4j.LoggerFactory;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.beans.factory.annotation.Value;
  15. import org.springframework.data.redis.core.RedisTemplate;
  16. import org.springframework.scheduling.annotation.EnableScheduling;
  17. import org.springframework.scheduling.annotation.Scheduled;
  18. import org.springframework.stereotype.Component;
  19. import java.io.File;
  20. import java.text.SimpleDateFormat;
  21. import java.util.Date;
  22. import java.util.HashMap;
  23. import java.util.List;
  24. import java.util.Map;
  25. @Component
  26. @EnableScheduling
  27. public class CountDataTask {
  28. private Logger logger = LoggerFactory.getLogger(getClass());
  29. @Autowired
  30. private CountTaskService countTaskService;
  31. @Autowired
  32. private BisInspMileageService bisInspMileageService;
  33. @Autowired
  34. private RedisTemplate redisTemplate;
  35. @Autowired
  36. private BisInspAllDao bisInspAllDao;
  37. /**
  38. * 统计当前的数据-实时
  39. */
  40. // @Scheduled(cron = "0 0/3 * * * ?")
  41. public void submitTj() {
  42. // 获取所有省
  43. List<OrgDto> orgDtoList = bisInspAllDao.findOrgMsg();
  44. long time = System.currentTimeMillis();
  45. String nowTime = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
  46. Map<String, String> userMap = new HashMap<>();
  47. DataDto dataDto = null;
  48. List<UserLineDto> userLineDtoList = bisInspAllDao.countUserLine2(null);
  49. for (OrgDto orgDto : orgDtoList) {
  50. dataDto = bisInspAllDao.countSysMsg(nowTime, orgDto.getOrgId());
  51. if (dataDto != null) {
  52. for (UserLineDto lineDto : userLineDtoList) {
  53. if (lineDto.getOrgId().equals(orgDto.getOrgId())) {
  54. userMap.put("totalPers", "" + lineDto.getPersTotal());
  55. userMap.put("icePers", "" + (lineDto.getPersTotal() - lineDto.getActiveUser()));
  56. }
  57. }
  58. userMap.put("duchaType", "" + dataDto.getDuchaType());
  59. userMap.put("duchaGroup", "" + dataDto.getDuchaGroup());
  60. userMap.put("duchaPers", "" + dataDto.getDuchaPers());
  61. userMap.put("duchaObj", "" + dataDto.getDuchaObj());
  62. userMap.put("duchaPblm", "" + dataDto.getDuchaPblm());
  63. userMap.put("platformName", orgDto.getOrgNm());
  64. JSONObject jsonObject = JSONObject.fromObject(userMap);
  65. logger.info("数据推送:" + jsonObject.toString());
  66. redisTemplate.convertAndSend(CommonLabel.SEND_TO_UPDATE, jsonObject);
  67. }
  68. }
  69. long haishi = System.currentTimeMillis() - time;
  70. logger.info("耗时:" + haishi + "毫秒!!");
  71. }
  72. @Scheduled(cron = "0 32 08 * * ?")
  73. public void initData() {
  74. countTaskService.countData("");
  75. }
  76. @Value("${export.basePath.docx}")
  77. private String docxPath;
  78. @Scheduled(cron = "0 0 19 * * ?")
  79. public void delTempDoc() {
  80. logger.info("删除rever,vill,track临时文件");
  81. File file = new File(docxPath);
  82. InspUtils.initTempDocFile(file);
  83. }
  84. @Scheduled(cron = "0 34 23 * * ?")
  85. public void delTempLog() {
  86. logger.info("删除log4j日志临时文件");
  87. File file = new File("../logs");
  88. InspUtils.initTempDocFile(file);
  89. }
  90. @Scheduled(cron = "0 20 23 * * ?")
  91. public void calMileage() {
  92. logger.info("=====开始计算人员里程=====");
  93. long stime = System.currentTimeMillis();
  94. try {
  95. bisInspMileageService.calMilage();
  96. } catch (Exception e) {
  97. logger.error("定时计算里程出错", e);
  98. }
  99. long etime = System.currentTimeMillis();
  100. logger.info(String.format("=====里程计算结束,耗时%d s=====", (etime - stime) / 1000));
  101. }
  102. }