|
|
@@ -2,32 +2,42 @@ package com.xunmei.core.board.service.impl;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
import com.xunmei.common.core.domain.DateRange;
|
|
|
+import com.xunmei.common.core.domain.R;
|
|
|
import com.xunmei.common.core.enums.CycleCommonEnum;
|
|
|
import com.xunmei.common.core.enums.OrgTypeEnum;
|
|
|
import com.xunmei.common.core.exception.ServiceException;
|
|
|
import com.xunmei.common.core.utils.DateUtils;
|
|
|
+import com.xunmei.common.core.utils.IDHelper;
|
|
|
import com.xunmei.common.core.utils.NumberUtils;
|
|
|
import com.xunmei.common.core.utils.StringUtils;
|
|
|
+import com.xunmei.core.board.domain.ResumptionTaskCount;
|
|
|
import com.xunmei.core.board.dto.web.OrgMapDto;
|
|
|
import com.xunmei.core.board.dto.web.TaskStatisticDto;
|
|
|
import com.xunmei.core.board.dto.web.WebSyntheticQuestionDto;
|
|
|
import com.xunmei.core.board.enums.PeriodEnum;
|
|
|
import com.xunmei.core.board.mapper.CockpitMapper;
|
|
|
+import com.xunmei.core.board.mapper.ResumptionTaskCountMapper;
|
|
|
import com.xunmei.core.board.service.CockpitService;
|
|
|
+import com.xunmei.core.board.service.ResumptionTaskCountService;
|
|
|
import com.xunmei.core.board.vo.web.*;
|
|
|
import com.xunmei.system.api.RemoteDictDataService;
|
|
|
import com.xunmei.system.api.RemoteOrgService;
|
|
|
import com.xunmei.system.api.domain.SysDictData;
|
|
|
import com.xunmei.system.api.domain.SysOrg;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.http.annotation.Obsolete;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
-
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class CockpitServiceImpl implements CockpitService {
|
|
|
@Resource
|
|
|
@@ -39,15 +49,134 @@ public class CockpitServiceImpl implements CockpitService {
|
|
|
@Resource
|
|
|
RemoteDictDataService remoteDictDataService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ ResumptionTaskCountMapper resumptionTaskCountMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ ResumptionTaskCountService resumptionTaskCountService;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public List<TaskStatisticVo> resumption(TaskStatisticDto dto) {
|
|
|
+ List<TaskStatisticVo> list;
|
|
|
Date date = getStartDate(dto.getPeriod());
|
|
|
SysOrg org = getOrgThrowIfNull(dto.getOrgId());
|
|
|
String orgPath = org.getPath();
|
|
|
- List<TaskStatisticVo> list = cockpitMapper.resumption(date, DateUtil.endOfDay(new Date()), orgPath);
|
|
|
-// return taskStatistic(list, org, Arrays.asList(OrgTypeEnum.LIHANG_ZIZHU_YINGHANG.getCode(), OrgTypeEnum.YINGYE_WANGDIAN.getCode()));
|
|
|
+
|
|
|
+ // 判断是否为本年查询
|
|
|
+ if (PeriodEnum.ThisYear.getCode().equals(dto.getPeriod())) {
|
|
|
+ list= handleThisYearCase(org.getPath());
|
|
|
+ } else {
|
|
|
+ list = cockpitMapper.resumption(date, DateUtil.endOfDay(new Date()), orgPath);
|
|
|
+ }
|
|
|
return taskStatistic(list, org, Arrays.asList(OrgTypeEnum.YINGYE_WANGDIAN.getCode()));
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 处理“本年”特殊逻辑
|
|
|
+ */
|
|
|
+ private List<TaskStatisticVo> handleThisYearCase(String orgPath)
|
|
|
+ {
|
|
|
+ // 1. 从统计表获取历史数据(年初到昨天)
|
|
|
+ List<TaskStatisticVo> list = resumptionTaskCountService.list().stream().map(this::convertToVo).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 2. 实时查询今日数据
|
|
|
+ List<TaskStatisticVo> toDayTaskStatistic = cockpitMapper.resumption(DateUtil.beginOfDay(new Date()), DateUtil.endOfDay(new Date()), orgPath);
|
|
|
+
|
|
|
+ // 3. 统计表数据为空 直接返回 实时查询的今日数据
|
|
|
+ if(CollectionUtils.isEmpty(list))
|
|
|
+ {
|
|
|
+ return toDayTaskStatistic;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 合并:按 orgId 聚合,任务数和完成数相加
|
|
|
+ Map<Long, TaskStatisticVo> map = new HashMap<>(list.size());
|
|
|
+ for (TaskStatisticVo task : list) {
|
|
|
+ map.put(task.getOrgId(),task);
|
|
|
+ }
|
|
|
+
|
|
|
+ toDayTaskStatistic.stream().forEach(x->{
|
|
|
+ TaskStatisticVo existing = map.get(x.getOrgId());
|
|
|
+ if (existing != null) {
|
|
|
+ existing.setTaskTotal(existing.getTaskTotal() + x.getTaskTotal());
|
|
|
+ existing.setCompletedCount(existing.getCompletedCount() + x.getCompletedCount());
|
|
|
+ } else {
|
|
|
+ map.put(x.getOrgId(), x);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return new ArrayList<>(map.values());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * VO 转换:Entity -> VO
|
|
|
+ */
|
|
|
+ private TaskStatisticVo convertToVo(ResumptionTaskCount x) {
|
|
|
+ TaskStatisticVo vo = new TaskStatisticVo();
|
|
|
+ vo.setOrgId(x.getOrgId());
|
|
|
+ vo.setOrgPath(x.getOrgPath());
|
|
|
+ vo.setTaskTotal(x.getTaskTotal());
|
|
|
+ vo.setCompletedCount(x.getCompletedCount());
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * VO 转换:VO -> Entity
|
|
|
+ */
|
|
|
+ private ResumptionTaskCount convertToEntity(ResumptionTaskStatisticVo vo,SysOrg org) {
|
|
|
+ ResumptionTaskCount entity = new ResumptionTaskCount();
|
|
|
+ entity.setId(IDHelper.id());
|
|
|
+ entity.setOrgId(org.getId());
|
|
|
+ entity.setOrgPath(org.getPath());
|
|
|
+ entity.setTaskTotal(vo.getTaskTotal());
|
|
|
+ entity.setCreateTime(new Date());
|
|
|
+ entity.setCompletedCount(ObjectUtil.isNull(vo.getCompletedCount()) ? 0: vo.getCompletedCount());
|
|
|
+ return entity;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 由于履职任务数据量较大,为提高查询速度,定时提前统计机构任务数据
|
|
|
+ * 统计每个机构本年内的履职任务总数量和已完成数量
|
|
|
+ * 统计范围:年初到当前时间的前一天
|
|
|
+ */
|
|
|
+ @Async
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void statisticCurrentYearResumptionTaskCount() {
|
|
|
+ try {
|
|
|
+ log.info("开始:统计本年履职任务数量和已完成数量");
|
|
|
+ Date startDate = getStartDate(PeriodEnum.ThisYear.getCode());
|
|
|
+ Date endDate = DateUtil.offsetDay(DateUtil.endOfDay(new Date()), -1);
|
|
|
+
|
|
|
+ //开年第一天不统计
|
|
|
+ if(endDate.before(startDate))
|
|
|
+ {
|
|
|
+ //删除前一年的结果
|
|
|
+ resumptionTaskCountMapper.deleteAll();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ final R<List<SysOrg>> allOrgResult = remoteOrgService.getAllOrg(SecurityConstants.INNER);
|
|
|
+ if (allOrgResult == null || allOrgResult.getData() == null || allOrgResult.getData().isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<SysOrg> allOrg = allOrgResult.getData();
|
|
|
+ List<ResumptionTaskCount> taskCountList =new ArrayList<>();
|
|
|
+ for (SysOrg org : allOrg) {
|
|
|
+ ResumptionTaskStatisticVo taskStatisticVo = cockpitMapper.statisticOneOrgResumptionTask(startDate, endDate, org.getId());
|
|
|
+ if(taskStatisticVo!=null && taskStatisticVo.getTaskTotal()!=null && taskStatisticVo.getTaskTotal()>0)
|
|
|
+ {
|
|
|
+ taskCountList.add(convertToEntity(taskStatisticVo,org));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //先删除,再插入
|
|
|
+ resumptionTaskCountMapper.deleteAll();
|
|
|
+ resumptionTaskCountService.saveBatch(taskCountList);
|
|
|
+ log.info("结束:统计本年履职任务数量和已完成数量");
|
|
|
+ } catch (Exception ex) {
|
|
|
+ log.error("提前统计本年履职任务数量和已完成数量失败:{},{}",ex.getMessage(),ex.getStackTrace());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public List<WebSafetyCheckVo> safetyCheck(TaskStatisticDto dto) {
|
|
|
@@ -259,7 +388,7 @@ public class CockpitServiceImpl implements CockpitService {
|
|
|
/**
|
|
|
* 本月来访
|
|
|
*
|
|
|
- * @param orgPath
|
|
|
+ * @param orgId
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|