JobProjectWeeklyQuartz.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package com.bosshand.virgo.api.job;
  2. import cn.hutool.core.date.DateUtil;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.bosshand.virgo.api.dao.ProjectCityWeatherDao;
  5. import com.bosshand.virgo.api.dao.ProjectDao;
  6. import com.bosshand.virgo.api.dao.WeeklyDao;
  7. import com.bosshand.virgo.api.dao.WeeklyTypeDao;
  8. import com.bosshand.virgo.api.model.Project;
  9. import com.bosshand.virgo.api.model.Weekly;
  10. import com.bosshand.virgo.api.model.WeeklyType;
  11. import org.quartz.JobDataMap;
  12. import org.quartz.JobExecutionContext;
  13. import org.quartz.JobExecutionException;
  14. import org.slf4j.Logger;
  15. import org.slf4j.LoggerFactory;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.scheduling.quartz.QuartzJobBean;
  18. import java.util.ArrayList;
  19. import java.util.Date;
  20. import java.util.List;
  21. /**
  22. * 定时生成项目周报数据
  23. */
  24. public class JobProjectWeeklyQuartz extends QuartzJobBean {
  25. @Autowired
  26. WeeklyDao weeklyDao;
  27. @Autowired
  28. WeeklyTypeDao weeklyTypeDao;
  29. @Autowired
  30. ProjectDao projectDao;
  31. @Autowired
  32. ProjectCityWeatherDao projectCityWeatherDao;
  33. static Logger log = LoggerFactory.getLogger(JobProjectWeeklyQuartz.class);
  34. @Override
  35. public void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
  36. log.info("=========================生成项目周报====================");
  37. JobDataMap mergedJobDataMap = jobExecutionContext.getMergedJobDataMap();
  38. String data = mergedJobDataMap.getString("data");
  39. JSONObject json = JSONObject.parseObject(data);
  40. long projectId = json.getLongValue("projectId");
  41. Date createDate = json.getDate("createDate");
  42. Project project = projectDao.getProject(projectId);
  43. Weekly weekly = new Weekly();
  44. weekly.setOrganizationId(project.getOrganizationId());
  45. weekly.setProjectId(projectId);
  46. weekly.setName(project.getName() + "项目周报");
  47. Weekly max = weeklyDao.getMax(projectId);
  48. if (max != null) {
  49. int number = max.getNumber();
  50. weekly.setNumber(number + 1);
  51. weekly.setStartDate(max.getEndDate());
  52. weekly.setEndDate(DateUtil.formatDateTime(jobExecutionContext.getFireTime()));
  53. } else {
  54. weekly.setNumber(1);
  55. weekly.setStartDate(DateUtil.formatDateTime(createDate));
  56. weekly.setEndDate(DateUtil.formatDateTime(jobExecutionContext.getFireTime()));
  57. }
  58. weeklyDao.save(weekly);
  59. weeklyTypeDao.batchSave(initWorkTypeList(projectId, weekly.getId(), weekly.getStartDate(), weekly.getEndDate()));
  60. }
  61. private List<WeeklyType> initWorkTypeList(long projectId, long weeklyId, String startDate, String endDate) {
  62. List<WeeklyType> list = new ArrayList<>();
  63. String[] typeNameList = WeeklyType.TYPENAMELIST;
  64. for (int i = 0; i < typeNameList.length; i++) {
  65. WeeklyType wt = new WeeklyType();
  66. wt.setWeeklyId(weeklyId);
  67. wt.setName(typeNameList[i]);
  68. wt.setType(i);
  69. switch (i) {
  70. //天气情况
  71. case 0:
  72. wt.setData(null);
  73. break;
  74. //客户管理
  75. case 1:
  76. wt.setData(null);
  77. break;
  78. //合同管理
  79. case 2:
  80. wt.setData(null);
  81. break;
  82. //费用管理
  83. case 3:
  84. wt.setData(null);
  85. break;
  86. //设备管理
  87. case 4:
  88. wt.setData(null);
  89. break;
  90. //房源管理
  91. case 5:
  92. wt.setData(null);
  93. break;
  94. default:
  95. throw new IllegalStateException("Unexpected value: " + i);
  96. }
  97. list.add(wt);
  98. }
  99. return list;
  100. }
  101. }