Browse Source

增加首页数据统计接口

tags/24080901
WendyYang 7 months ago
parent
commit
00336e48c2
5 changed files with 176 additions and 13 deletions
  1. +5
    -1
      hz-pm-api/src/main/java/com/hz/pm/api/projectlib/handle/AbstractProcessHandle.java
  2. +11
    -3
      hz-pm-api/src/main/java/com/hz/pm/api/workbench/controller/WorkbenchController.java
  3. +115
    -9
      hz-pm-api/src/main/java/com/hz/pm/api/workbench/manage/WorkbenchManage.java
  4. +20
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/workbench/model/WorkbenchReq.java
  5. +25
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/workbench/model/vo/ProjectProcessStageStatisticsVO.java

+ 5
- 1
hz-pm-api/src/main/java/com/hz/pm/api/projectlib/handle/AbstractProcessHandle.java View File

@@ -38,7 +38,7 @@ public abstract class AbstractProcessHandle implements Ordered {

@Getter
@AllArgsConstructor
enum ProcessNode {
public enum ProcessNode {

PROJECT_DECLARED("项目申报", 1),
PROJECT_REVIEW("项目评审", 2),
@@ -57,6 +57,10 @@ public abstract class AbstractProcessHandle implements Ordered {
private final String name;
private final Integer order;

public static final List<ProcessNode> ALL = Arrays.stream(ProcessNode.values())
.sorted(Comparator.comparingInt(ProcessNode::getOrder))
.collect(Collectors.toList());

}

private static final Map<ProcessStatusEnum, Integer> PROCESS_STATUS_PRIORITY_MAP = new HashMap<>();


+ 11
- 3
hz-pm-api/src/main/java/com/hz/pm/api/workbench/controller/WorkbenchController.java View File

@@ -1,6 +1,8 @@
package com.hz.pm.api.workbench.controller;

import com.hz.pm.api.workbench.manage.WorkbenchManage;
import com.hz.pm.api.workbench.model.WorkbenchReq;
import com.hz.pm.api.workbench.model.vo.ProjectProcessStageStatisticsVO;
import com.hz.pm.api.workbench.model.vo.ProjectTotalViewVO;
import com.hz.pm.api.workbench.model.vo.WorkbenchVO;
import com.ningdatech.log.annotation.WebLog;
@@ -10,6 +12,7 @@ import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

/**
* <p>
@@ -48,9 +51,14 @@ public class WorkbenchController {

@GetMapping("/projectTotalView")
@ApiOperation("获取项目总览")
public ProjectTotalViewVO projectTotalView(@RequestParam(required = false) Long unitId,
@RequestParam(required = false) Integer projectYear) {
return workbenchManage.projectTotalView(unitId, projectYear);
public ProjectTotalViewVO projectTotalView(WorkbenchReq req) {
return workbenchManage.projectTotalView(req);
}

@GetMapping("/projectProcessStageStatistics")
@ApiOperation("各阶段项目数据统计")
public List<ProjectProcessStageStatisticsVO> projectProcessStageStatistics(WorkbenchReq req) {
return workbenchManage.projectProcessStageStatistics(req);
}

}

+ 115
- 9
hz-pm-api/src/main/java/com/hz/pm/api/workbench/manage/WorkbenchManage.java View File

@@ -9,15 +9,23 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hz.pm.api.common.helper.UserInfoHelper;
import com.hz.pm.api.common.model.constant.BizConst;
import com.hz.pm.api.common.model.entity.KeyValDTO;
import com.hz.pm.api.common.statemachine.event.*;
import com.hz.pm.api.common.util.DecimalUtil;
import com.hz.pm.api.projectdeclared.model.entity.Purchase;
import com.hz.pm.api.projectdeclared.service.IPurchaseService;
import com.hz.pm.api.projectlib.entity.ProjectGovSystemReplaceInfos;
import com.hz.pm.api.projectlib.entity.PurchaseStatusChange;
import com.hz.pm.api.projectlib.handle.AbstractProcessHandle.ProcessNode;
import com.hz.pm.api.projectlib.manage.ProjectLibManage;
import com.hz.pm.api.projectlib.model.entity.Project;
import com.hz.pm.api.projectlib.model.entity.ProjectStatusChange;
import com.hz.pm.api.projectlib.model.enumeration.GovSystemReplaceTypeEnum;
import com.hz.pm.api.projectlib.model.req.ProjectListReq;
import com.hz.pm.api.projectlib.model.vo.ProjectLibListItemVO;
import com.hz.pm.api.projectlib.service.IProjectGovSystemReplaceInfosService;
import com.hz.pm.api.projectlib.service.IProjectService;
import com.hz.pm.api.projectlib.service.IProjectStatusChangeService;
import com.hz.pm.api.projectlib.service.IPurchaseStatusChangeService;
import com.hz.pm.api.sys.manage.EarlyWarningManage;
import com.hz.pm.api.sys.model.entity.WflowEarlyWarningRecords;
import com.hz.pm.api.sys.service.IEarlyWarningRecordsService;
@@ -30,6 +38,8 @@ import com.hz.pm.api.user.helper.MhUnitCache;
import com.hz.pm.api.user.security.model.UserFullInfoDTO;
import com.hz.pm.api.user.util.LoginUserUtil;
import com.hz.pm.api.workbench.converter.WorkbenchConverter;
import com.hz.pm.api.workbench.model.WorkbenchReq;
import com.hz.pm.api.workbench.model.vo.ProjectProcessStageStatisticsVO;
import com.hz.pm.api.workbench.model.vo.ProjectTotalViewVO;
import com.hz.pm.api.workbench.model.vo.WorkbenchVO;
import com.ningdatech.basic.model.PageVo;
@@ -47,6 +57,7 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.function.ToLongFunction;
import java.util.stream.Collectors;

/**
@@ -69,8 +80,11 @@ public class WorkbenchManage {
private final ProjectLibManage projectLibManage;
private final EarlyWarningManage earlyWarningManage;
private final IProjectService projectService;
private final IProjectStatusChangeService projectStatusChangeService;
private final IPurchaseService purchaseService;
private final MhUnitCache mhUnitCache;
private final IProjectGovSystemReplaceInfosService systemReplaceInfosService;
private final IPurchaseStatusChangeService purchaseStatusChangeService;

public WorkbenchVO getWorkbenchData(Integer year) {
WorkbenchVO res = new WorkbenchVO();
@@ -145,20 +159,23 @@ public class WorkbenchManage {
return "催办成功了" + employees.length + "个人";
}

public ProjectTotalViewVO projectTotalView(Long unitId, Integer projectYear) {
ProjectTotalViewVO retDetail = new ProjectTotalViewVO();
if (unitId == null) {
unitId = LoginUserUtil.loginUserDetail().getMhUnitId();
private void initWorkbenchDefaultParam(WorkbenchReq req) {
if (req.getUnitId() == null) {
req.setUnitId(LoginUserUtil.loginUserDetail().getMhUnitId());
}
if (projectYear == null) {
projectYear = LocalDate.now().getYear();
if (req.getProjectYear() == null) {
req.setProjectYear(LocalDate.now().getYear());
}
}

public ProjectTotalViewVO projectTotalView(WorkbenchReq req) {
ProjectTotalViewVO retDetail = new ProjectTotalViewVO();
initWorkbenchDefaultParam(req);
LambdaQueryWrapper<Project> query = Wrappers.lambdaQuery(Project.class)
.select(Project::getReviewAmount, Project::getApprovalGovOwnFinanceAmount, Project::getId)
.eq(Project::getProjectYear, projectYear)
.eq(Project::getProjectYear, req.getProjectYear())
.eq(Project::getNewest, Boolean.TRUE);
List<Long> viewUnitIds = mhUnitCache.getChildIdsRecursion(unitId);
viewUnitIds.add(unitId);
List<Long> viewUnitIds = mhUnitCache.getViewChildIdsRecursion(req.getUnitId());
query.in(Project::getBuildOrgCode, CollUtils.convert(viewUnitIds, String::valueOf));
List<Project> projects = projectService.list(query);
if (projects.isEmpty()) {
@@ -192,4 +209,93 @@ public class WorkbenchManage {
return retDetail;
}

public List<ProjectProcessStageStatisticsVO> projectProcessStageStatistics(WorkbenchReq req) {
initWorkbenchDefaultParam(req);
List<ProjectProcessStageStatisticsVO> retData = new ArrayList<>();
List<Long> projectIds = new ArrayList<>();
Map<String, Long> purchaseEventMap = new HashMap<>();
ToLongFunction<AbstractStateChangeEvent> getPurchaseCount = event -> purchaseEventMap.getOrDefault(event.name(), 0L);
long firstInspectedCount = 0;
for (ProcessNode node : ProcessNode.ALL) {
long count;
switch (node) {
case PROJECT_DECLARED:
List<Long> viewUnitIds = mhUnitCache.getViewChildIdsRecursion(req.getUnitId());
Wrapper<Project> query = Wrappers.lambdaQuery(Project.class)
.select(Project::getId)
.eq(Project::getProjectYear, req.getProjectYear())
.eq(Project::getNewest, Boolean.TRUE)
.in(Project::getBuildOrgCode, CollUtils.convert(viewUnitIds, String::valueOf));
List<Project> projects = projectService.list(query);
if (projects.isEmpty()) {
return retData;
}
count = projects.size();
projectIds.addAll(CollUtils.fieldList(projects, Project::getId));
break;
case PROJECT_REVIEW:
count = 0;
break;
case APPROVAL_AMOUNT:
count = projectService.count(Wrappers.lambdaQuery(Project.class)
.in(Project::getId, projectIds)
.isNotNull(Project::getApprovalAmount));
break;
case PROJECT_APPROVAL:
count = projectStatusChangeService.count(Wrappers.lambdaQuery(ProjectStatusChange.class)
.in(ProjectStatusChange::getProjectId, projectIds)
.eq(ProjectStatusChange::getEvent, ProjectStateChangeEvent.DECLARED_RECORD_PASS));
break;
case PROJECT_PURCHASE:
count = purchaseService.count(Wrappers.lambdaQuery(Purchase.class)
.in(Purchase::getProjectId, projectIds));
if (count > 0) {
Wrapper<PurchaseStatusChange> pQuery = Wrappers.lambdaQuery(PurchaseStatusChange.class)
.select(PurchaseStatusChange::getEvent)
.in(PurchaseStatusChange::getProjectId, projectIds)
.in(PurchaseStatusChange::getEvent, AdaptStateChangeEvent.ADAPT_INFO_PASSED,
SelfTestStateChangeEvent.SELF_TEST_PASSED,
TestValidStateChangeEvent.TEST_VALID_INFO_PASSED,
TenderStateChangeEvent.SUBMIT_FIRST_INSPECTED_FILES,
XcfhxStateChangeEvent.XCFHX_APPLY_PASSED,
TenderStateChangeEvent.FINALLY_INSPECTED_PASSED);
List<PurchaseStatusChange> changes = purchaseStatusChangeService.list(pQuery);
changes.forEach(change -> purchaseEventMap.merge(change.getEvent(), 1L, Long::sum));
}
break;
case PROJECT_ADAPTION:
count = getPurchaseCount.applyAsLong(AdaptStateChangeEvent.ADAPT_INFO_PASSED);
break;
case SYSTEM_SELF_TEST:
count = getPurchaseCount.applyAsLong(SelfTestStateChangeEvent.SELF_TEST_PASSED);
break;
case SYSTEM_TEST_VALID:
count = getPurchaseCount.applyAsLong(TestValidStateChangeEvent.TEST_VALID_INFO_PASSED);
break;
case FIRST_INSPECTED:
count = getPurchaseCount.applyAsLong(TenderStateChangeEvent.SUBMIT_FIRST_INSPECTED_FILES);
firstInspectedCount = count;
break;
case PILOT_RUNNING:
count = firstInspectedCount;
break;
case XCFHX_REVIEW:
count = getPurchaseCount.applyAsLong(XcfhxStateChangeEvent.XCFHX_APPLY_PASSED);
break;
case FINAL_INSPECTED:
count = getPurchaseCount.applyAsLong(TenderStateChangeEvent.FINALLY_INSPECTED_PASSED);
break;
default:
count = 0;
break;
}
retData.add(ProjectProcessStageStatisticsVO.builder()
.stage(node)
.stageName(node.getName())
.count((int) count)
.build());
}
return retData;
}

}

+ 20
- 0
hz-pm-api/src/main/java/com/hz/pm/api/workbench/model/WorkbenchReq.java View File

@@ -0,0 +1,20 @@
package com.hz.pm.api.workbench.model;

import lombok.Data;

/**
* <p>
* WorkbenchReq
* </p>
*
* @author WendyYang
* @since 18:27 2024/4/10
*/
@Data
public class WorkbenchReq {

private Long unitId;

private Integer projectYear;

}

+ 25
- 0
hz-pm-api/src/main/java/com/hz/pm/api/workbench/model/vo/ProjectProcessStageStatisticsVO.java View File

@@ -0,0 +1,25 @@
package com.hz.pm.api.workbench.model.vo;

import com.hz.pm.api.projectlib.handle.AbstractProcessHandle.ProcessNode;
import lombok.Builder;
import lombok.Data;

/**
* <p>
* ProjectProcessStageStatisticsVO
* </p>
*
* @author WendyYang
* @since 15:28 2024/4/10
*/
@Data
@Builder
public class ProjectProcessStageStatisticsVO {

private ProcessNode stage;

private String stageName;

private Integer count;

}

Loading…
Cancel
Save