|
|
@@ -1,28 +1,44 @@
|
|
|
package com.xunmei.core.board.service.impl;
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.date.DateField;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
import com.xunmei.common.core.domain.DateRange;
|
|
|
+import com.xunmei.common.core.domain.panel.vo.PanelListVo;
|
|
|
import com.xunmei.common.core.enums.CycleCommonEnum;
|
|
|
+import com.xunmei.common.core.exception.ServiceException;
|
|
|
import com.xunmei.common.core.utils.DateUtils;
|
|
|
import com.xunmei.common.security.utils.SecurityUtils;
|
|
|
+import com.xunmei.core.board.dto.app.AppGA38InfoDto;
|
|
|
+import com.xunmei.core.board.dto.app.AppOverviewTaskInfoDto;
|
|
|
import com.xunmei.core.board.dto.app.AppTaskRankingDto;
|
|
|
+import com.xunmei.core.board.mapper.AppCockpitMapper;
|
|
|
import com.xunmei.core.board.mapper.CockpitMapper;
|
|
|
import com.xunmei.core.board.service.AppCockpitService;
|
|
|
import com.xunmei.core.board.vo.app.AppBaseInfoVo;
|
|
|
+import com.xunmei.core.board.vo.app.AppOverviewItemVo;
|
|
|
+import com.xunmei.core.board.vo.app.AppOverviewVo;
|
|
|
import com.xunmei.core.board.vo.app.AppTaskRankingVo;
|
|
|
import com.xunmei.core.board.vo.web.TaskStatisticVo;
|
|
|
+import com.xunmei.core.thread.ThreadPoolConfig;
|
|
|
import com.xunmei.system.api.RemoteOrgService;
|
|
|
import com.xunmei.system.api.domain.SysOrg;
|
|
|
+import io.reactivex.rxjava3.core.Single;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Comparator;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
+import java.util.concurrent.ExecutionException;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.concurrent.TimeoutException;
|
|
|
|
|
|
@Service
|
|
|
public class AppCockpitServiceImpl implements AppCockpitService {
|
|
|
@@ -30,8 +46,16 @@ public class AppCockpitServiceImpl implements AppCockpitService {
|
|
|
private CockpitMapper cockpitMapper;
|
|
|
|
|
|
@Resource
|
|
|
+ private AppCockpitMapper appCockpitMapper;
|
|
|
+ @Resource
|
|
|
RemoteOrgService remoteOrgService;
|
|
|
|
|
|
+ public static final int TIMEOUT = 3;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ @Qualifier(ThreadPoolConfig.SOC_EXECUTOR)
|
|
|
+ private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
|
|
+
|
|
|
@Override
|
|
|
public List<AppTaskRankingVo> taskRanking(AppTaskRankingDto dto) {
|
|
|
DateRange range = DateUtils.getStartAndEnd(dto.getMonth(), CycleCommonEnum.MONTHLY);
|
|
|
@@ -44,6 +68,7 @@ public class AppCockpitServiceImpl implements AppCockpitService {
|
|
|
List<TaskStatisticVo> childrenStatistic = new ArrayList<>();
|
|
|
for (SysOrg child : children) {
|
|
|
TaskStatisticVo childVo = new TaskStatisticVo();
|
|
|
+ childVo.setOrgName(child.getShortName());
|
|
|
childrenStatistic.add(childVo);
|
|
|
|
|
|
for (TaskStatisticVo orgItem : list) {
|
|
|
@@ -63,6 +88,7 @@ public class AppCockpitServiceImpl implements AppCockpitService {
|
|
|
} else {
|
|
|
vo.setRate(i.getCompletedCount() / i.getTaskTotal());
|
|
|
}
|
|
|
+ r.add(vo);
|
|
|
});
|
|
|
r.sort(new Comparator<AppTaskRankingVo>() {
|
|
|
@Override
|
|
|
@@ -82,4 +108,142 @@ public class AppCockpitServiceImpl implements AppCockpitService {
|
|
|
public AppBaseInfoVo baseInfo() {
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 总览
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public AppOverviewVo overview() throws ExecutionException, InterruptedException, TimeoutException {
|
|
|
+ SysOrg org = remoteOrgService.selectOrgById(SecurityUtils.getLoginUser().getOrgId(), SecurityConstants.INNER);
|
|
|
+ AppOverviewVo vo = new AppOverviewVo();
|
|
|
+ if (ObjectUtil.isNull(org)) {
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ Date currentMonth = DateUtil.beginOfMonth(new Date());
|
|
|
+ Date prevMonth = DateUtil.beginOfMonth(new Date()).offset(DateField.MONTH, -1);
|
|
|
+
|
|
|
+ CompletableFuture<AppOverviewVo> orgOverview = CompletableFuture.supplyAsync(() ->
|
|
|
+ appCockpitMapper.selectOrgOverview(org.getPath()), threadPoolTaskExecutor
|
|
|
+ );
|
|
|
+ AppGA38InfoDto d1 = appCockpitMapper.selectOrgGa38(org.getPath(), currentMonth);
|
|
|
+ CompletableFuture<AppGA38InfoDto> orgga38 = CompletableFuture.supplyAsync(() ->
|
|
|
+ appCockpitMapper.selectOrgGa38(org.getPath(), currentMonth), threadPoolTaskExecutor
|
|
|
+ );
|
|
|
+
|
|
|
+ CompletableFuture<AppOverviewTaskInfoDto> resumption = CompletableFuture.supplyAsync(() ->
|
|
|
+ appCockpitMapper.selectOverViewResumptionTaskInfo(org.getPath(), currentMonth, prevMonth), threadPoolTaskExecutor
|
|
|
+ );
|
|
|
+
|
|
|
+ CompletableFuture<AppOverviewTaskInfoDto> safetyCheck = CompletableFuture.supplyAsync(() ->
|
|
|
+ appCockpitMapper.selectOverViewSafetyCheckTaskInfo(org.getPath(), currentMonth, prevMonth), threadPoolTaskExecutor
|
|
|
+ );
|
|
|
+
|
|
|
+ CompletableFuture<AppOverviewTaskInfoDto> edu = CompletableFuture.supplyAsync(() ->
|
|
|
+ appCockpitMapper.selectOverViewEduTaskInfo(org.getPath(), currentMonth, prevMonth), threadPoolTaskExecutor
|
|
|
+ );
|
|
|
+
|
|
|
+ CompletableFuture<AppOverviewTaskInfoDto> monitor = CompletableFuture.supplyAsync(() ->
|
|
|
+ appCockpitMapper.selectOverViewMonitorTaskInfo(org.getPath(), currentMonth, prevMonth), threadPoolTaskExecutor
|
|
|
+ );
|
|
|
+
|
|
|
+ Date currentQuarter = DateUtil.beginOfQuarter(new Date());
|
|
|
+ Date prevQuarter = DateUtil.beginOfMonth(new Date()).offset(DateField.MONTH, -3);
|
|
|
+ CompletableFuture<AppOverviewTaskInfoDto> drill = CompletableFuture.supplyAsync(() ->
|
|
|
+ appCockpitMapper.selectOverViewDrillTaskInfo(org.getPath(), currentQuarter, prevQuarter), threadPoolTaskExecutor
|
|
|
+ );
|
|
|
+
|
|
|
+ Date near90 = DateUtil.beginOfDay(new Date()).offset(DateField.DAY_OF_YEAR, -90);
|
|
|
+ CompletableFuture<AppOverviewTaskInfoDto> question = CompletableFuture.supplyAsync(() ->
|
|
|
+ appCockpitMapper.selectOverViewQuestionInfo(org.getPath(), near90), threadPoolTaskExecutor
|
|
|
+ );
|
|
|
+
|
|
|
+ CompletableFuture<Void> allQueries = CompletableFuture.allOf(
|
|
|
+ orgOverview, orgga38, resumption,
|
|
|
+ safetyCheck, edu, drill, question, monitor
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+ allQueries.get(TIMEOUT, TimeUnit.SECONDS);
|
|
|
+
|
|
|
+ BeanUtils.copyProperties(orgOverview.join(), vo);
|
|
|
+ vo.setGa38(new HashMap<>());
|
|
|
+ vo.getGa38().put("GA382021", computeGa38(orgga38.get().getTotal(), orgga38.get().getGa382021(), orgga38.get().getGa382021current(), orgga38.get().getGa382021prev()));
|
|
|
+ vo.getGa38().put("GA382015", computeGa38(orgga38.get().getTotal(), orgga38.get().getGa382015(), orgga38.get().getGa382015current(), orgga38.get().getGa382015prev()));
|
|
|
+
|
|
|
+ vo.setTaskInfo(new HashMap<>());
|
|
|
+ vo.getTaskInfo().put("日常履职", computeOverviewItem(resumption.get()));
|
|
|
+ vo.getTaskInfo().put("网点自查", computeOverviewItem(safetyCheck.get()));
|
|
|
+ vo.getTaskInfo().put("教育培训", computeOverviewItem(edu.get()));
|
|
|
+ vo.getTaskInfo().put("预案演练", computeOverviewItem(drill.get()));
|
|
|
+ vo.getTaskInfo().put("监控调阅", computeOverviewItem(monitor.get()));
|
|
|
+
|
|
|
+ AppOverviewItemVo questionVo = new AppOverviewItemVo();
|
|
|
+ questionVo.setShouldComplete(question.get().getTotal());
|
|
|
+ questionVo.setCurrentCompletedCount(question.get().getCompleted());
|
|
|
+ if (ObjectUtil.equal(questionVo.getShouldComplete(), 0)) {
|
|
|
+ questionVo.setCurrentCompletedRate(1F);
|
|
|
+ } else {
|
|
|
+ questionVo.setCurrentCompletedRate(questionVo.getCurrentCompletedCount().floatValue() / questionVo.getShouldComplete());
|
|
|
+ }
|
|
|
+ vo.getTaskInfo().put("问题整改", questionVo);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ private AppOverviewItemVo computeOverviewItem(AppOverviewTaskInfoDto dto) {
|
|
|
+
|
|
|
+ AppOverviewItemVo vo = new AppOverviewItemVo();
|
|
|
+ if(ObjectUtil.isNull(dto)){
|
|
|
+ vo.setShouldComplete(0);
|
|
|
+ vo.setCurrentCompletedCount(0);
|
|
|
+ vo.setCurrentCompletedRate(0F);
|
|
|
+ vo.setCompare(0F);
|
|
|
+
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+ vo.setCurrentCompletedCount(dto.getCompleted());
|
|
|
+ vo.setShouldComplete(dto.getTotal());
|
|
|
+ if (ObjectUtil.equal(dto.getTotal(), 0) || ObjectUtil.isNull(dto.getTotal())) {
|
|
|
+ vo.setCurrentCompletedRate(1F);
|
|
|
+ } else if (ObjectUtil.equal(dto.getCompleted(), 0) || ObjectUtil.isNull(dto.getCompleted())) {
|
|
|
+ vo.setCurrentCompletedCount(0);
|
|
|
+ } else {
|
|
|
+ vo.setCurrentCompletedRate(((float) dto.getCompleted()) / dto.getTotal());
|
|
|
+ }
|
|
|
+
|
|
|
+ float prevRate = 0;
|
|
|
+ if (ObjectUtil.equal(dto.getPrevTotal(), 0) || ObjectUtil.isNull(dto.getPrevTotal())) {
|
|
|
+ prevRate = 1F;
|
|
|
+ } else if (ObjectUtil.isNotNull(dto.getPrevCompleted())) {
|
|
|
+ prevRate = ((float) dto.getPrevCompleted()) / dto.getPrevTotal();
|
|
|
+ }
|
|
|
+
|
|
|
+ vo.setPrevCompletedRate(prevRate);
|
|
|
+ vo.setCompare(vo.getCurrentCompletedRate() - prevRate);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param total 应完成
|
|
|
+ * @param completed 已完成
|
|
|
+ * @param currentCompleted 本周期完成
|
|
|
+ * @param prevCompleted 上一周期完成
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private AppOverviewItemVo computeGa38(int total, int completed, int currentCompleted, int prevCompleted) {
|
|
|
+ AppOverviewItemVo vo = new AppOverviewItemVo();
|
|
|
+ if (ObjectUtil.equal(total, 0)) {
|
|
|
+ vo.setCurrentCompletedRate(1F);
|
|
|
+ } else {
|
|
|
+ vo.setCurrentCompletedRate(((float) completed) / total);
|
|
|
+ }
|
|
|
+
|
|
|
+ vo.setCompare(((float) currentCompleted) - prevCompleted);
|
|
|
+ vo.setCurrentCompletedCount(currentCompleted);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
}
|