123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- package com.bosshand.virgo.api.job;
- import cn.hutool.core.date.DateUtil;
- import com.alibaba.fastjson.JSONObject;
- import com.bosshand.virgo.api.dao.ProjectCityWeatherDao;
- import com.bosshand.virgo.api.dao.ProjectDao;
- import com.bosshand.virgo.api.dao.WeeklyDao;
- import com.bosshand.virgo.api.dao.WeeklyTypeDao;
- import com.bosshand.virgo.api.model.Project;
- import com.bosshand.virgo.api.model.Weekly;
- import com.bosshand.virgo.api.model.WeeklyType;
- import org.quartz.JobDataMap;
- import org.quartz.JobExecutionContext;
- import org.quartz.JobExecutionException;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.scheduling.quartz.QuartzJobBean;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- /**
- * 定时生成项目周报数据
- */
- public class JobProjectWeeklyQuartz extends QuartzJobBean {
- @Autowired
- WeeklyDao weeklyDao;
- @Autowired
- WeeklyTypeDao weeklyTypeDao;
- @Autowired
- ProjectDao projectDao;
- @Autowired
- ProjectCityWeatherDao projectCityWeatherDao;
- static Logger log = LoggerFactory.getLogger(JobProjectWeeklyQuartz.class);
- @Override
- public void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
- log.info("=========================生成项目周报====================");
- JobDataMap mergedJobDataMap = jobExecutionContext.getMergedJobDataMap();
- String data = mergedJobDataMap.getString("data");
- JSONObject json = JSONObject.parseObject(data);
- long projectId = json.getLongValue("projectId");
- Date createDate = json.getDate("createDate");
- Project project = projectDao.getProject(projectId);
- Weekly weekly = new Weekly();
- weekly.setOrganizationId(project.getOrganizationId());
- weekly.setProjectId(projectId);
- weekly.setName(project.getName() + "项目周报");
- Weekly max = weeklyDao.getMax(projectId);
- if (max != null) {
- int number = max.getNumber();
- weekly.setNumber(number + 1);
- weekly.setStartDate(max.getEndDate());
- weekly.setEndDate(DateUtil.formatDateTime(jobExecutionContext.getFireTime()));
- } else {
- weekly.setNumber(1);
- weekly.setStartDate(DateUtil.formatDateTime(createDate));
- weekly.setEndDate(DateUtil.formatDateTime(jobExecutionContext.getFireTime()));
- }
- weeklyDao.save(weekly);
- weeklyTypeDao.batchSave(initWorkTypeList(projectId, weekly.getId(), weekly.getStartDate(), weekly.getEndDate()));
- }
- private List<WeeklyType> initWorkTypeList(long projectId, long weeklyId, String startDate, String endDate) {
- List<WeeklyType> list = new ArrayList<>();
- String[] typeNameList = WeeklyType.TYPENAMELIST;
- for (int i = 0; i < typeNameList.length; i++) {
- WeeklyType wt = new WeeklyType();
- wt.setWeeklyId(weeklyId);
- wt.setName(typeNameList[i]);
- wt.setType(i);
- switch (i) {
- //天气情况
- case 0:
- wt.setData(null);
- break;
- //客户管理
- case 1:
- wt.setData(null);
- break;
- //合同管理
- case 2:
- wt.setData(null);
- break;
- //费用管理
- case 3:
- wt.setData(null);
- break;
- //设备管理
- case 4:
- wt.setData(null);
- break;
- //房源管理
- case 5:
- wt.setData(null);
- break;
- default:
- throw new IllegalStateException("Unexpected value: " + i);
- }
- list.add(wt);
- }
- return list;
- }
- }
|