diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/constant/AnalysisBasicConstant.java b/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/constant/AnalysisBasicConstant.java index f579a02..e8af093 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/constant/AnalysisBasicConstant.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/constant/AnalysisBasicConstant.java @@ -11,7 +11,7 @@ public class AnalysisBasicConstant { /** * 丽水市区域编码 */ - private static final String LS_REGION_CODE = "331100"; + public static final String LS_REGION_CODE = "331100"; diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/constant/ChartTypeEnum.java b/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/constant/ChartTypeEnum.java index 4f7bb1e..cca5749 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/constant/ChartTypeEnum.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/constant/ChartTypeEnum.java @@ -20,5 +20,10 @@ public enum ChartTypeEnum { /** * 各区域专家职称级别分布 */ - REGION_EXPERT_TITLE_LEVEL_CHART; + REGION_EXPERT_TITLE_LEVEL_CHART, + + /** + * 各类型评审次数 + */ + MEETING_TYPE_CNT_CHART; } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/helper/DashboardRegionHelper.java b/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/helper/DashboardRegionHelper.java new file mode 100644 index 0000000..5bd5012 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/helper/DashboardRegionHelper.java @@ -0,0 +1,35 @@ +package com.ningdatech.pmapi.dashboard.helper; + +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.ningdatech.pmapi.dashboard.constant.AnalysisBasicConstant; +import com.ningdatech.pmapi.sys.model.entity.Region; +import com.ningdatech.pmapi.sys.service.IRegionService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * @author liuxinxin + * @date 2023/8/3 下午3:13 + */ + +@Component +@RequiredArgsConstructor +public class DashboardRegionHelper { + + private final IRegionService iRegionService; + + /** + * 获取丽水区域相关信息 + */ + public Map getLiShuiRegionCodeNameMap() { + List regionList = iRegionService.list(Wrappers.lambdaQuery(Region.class) + .eq(Region::getParentCode, AnalysisBasicConstant.LS_REGION_CODE)); + Map regionCodeNameMap = regionList.stream().collect(Collectors.toMap(Region::getRegionCode, Region::getRegionName)); + return regionCodeNameMap; + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/manage/DashboardExpertManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/manage/DashboardExpertManage.java index 3c16245..7dd7a08 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/manage/DashboardExpertManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/manage/DashboardExpertManage.java @@ -1,10 +1,34 @@ package com.ningdatech.pmapi.dashboard.manage; +import cn.hutool.core.collection.CollectionUtil; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.ningdatech.pmapi.dashboard.constant.ChartTypeEnum; +import com.ningdatech.pmapi.dashboard.helper.DashboardRegionHelper; +import com.ningdatech.pmapi.dashboard.model.basic.AnalysisChart; +import com.ningdatech.pmapi.dashboard.model.basic.AnalysisData; +import com.ningdatech.pmapi.dashboard.model.basic.StarExpertBO; import com.ningdatech.pmapi.dashboard.model.po.QueryYearPO; import com.ningdatech.pmapi.dashboard.model.vo.ExpertDashboardSummaryVO; +import com.ningdatech.pmapi.expert.constant.ExpertUserInfoStepEnum; +import com.ningdatech.pmapi.expert.entity.ExpertUserFullInfo; +import com.ningdatech.pmapi.expert.service.IExpertUserFullInfoService; +import com.ningdatech.pmapi.meeting.entity.domain.Meeting; +import com.ningdatech.pmapi.meeting.entity.domain.MeetingExpertJudge; +import com.ningdatech.pmapi.meeting.entity.enumeration.MeetingStatusEnum; +import com.ningdatech.pmapi.meeting.service.IMeetingExpertJudgeService; +import com.ningdatech.pmapi.meeting.service.IMeetingService; +import com.ningdatech.pmapi.meta.constant.DictExpertInfoTypeEnum; +import com.ningdatech.pmapi.meta.helper.DictionaryCache; +import com.ningdatech.pmapi.meta.model.entity.ExpertDictionary; +import com.ningdatech.pmapi.meta.service.IExpertDictionaryService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; + /** * @author liuxinxin * @date 2023/8/2 上午10:39 @@ -14,10 +38,154 @@ import org.springframework.stereotype.Component; @RequiredArgsConstructor public class DashboardExpertManage { + private final DashboardRegionHelper dashboardRegionHelper; + private final IExpertUserFullInfoService iExpertUserFullInfoService; + private final IMeetingService iMeetingService; + private final DictionaryCache dictionaryCache; + private final IMeetingExpertJudgeService iMeetingExpertJudgeService; + private final IExpertDictionaryService iExpertDictionaryService; + public ExpertDashboardSummaryVO getExpertDashboardSummary(QueryYearPO queryYearPO) { - return null; + String queryRegionCode = queryYearPO.getRegionCode(); + List analysisChartList = new ArrayList<>(); + + // 获取丽水区域 code name Map + Map liShuiRegionCodeNameMap = dashboardRegionHelper.getLiShuiRegionCodeNameMap(); + // 获取库内所有的专家列表 + List evidenceHasBeenSubmittedExpertInfoList = iExpertUserFullInfoService.list(Wrappers.lambdaQuery(ExpertUserFullInfo.class) + .eq(ExpertUserFullInfo::getUserInfoStep, ExpertUserInfoStepEnum.EVIDENCE_HAS_BEEN_SUBMITTED.getKey())); + + // 专家regionCode分组map列表 + Map> regionCodeExpertMap = evidenceHasBeenSubmittedExpertInfoList.stream() + .collect(Collectors.groupingBy(ExpertUserFullInfo::getRegionCode)); + + // 各区域专家数量 + AnalysisChart regionExpertNumberChartAnalysisChart = new AnalysisChart(); + List regionExpertNumberChartDataList = new ArrayList<>(); + regionExpertNumberChartAnalysisChart.setChartType(ChartTypeEnum.REGION_EXPERT_NUMBER_CHART); + regionExpertNumberChartAnalysisChart.setDataList(regionExpertNumberChartDataList); + for (String regionCode : liShuiRegionCodeNameMap.keySet()) { + AnalysisData analysisData = new AnalysisData(); + String regionName = liShuiRegionCodeNameMap.get(regionCode); + List expertUserFullInfoList = regionCodeExpertMap.get(regionCode); + Integer expertCnt = 0; + if (CollectionUtil.isNotEmpty(expertUserFullInfoList)) { + expertCnt = expertUserFullInfoList.size(); + } + analysisData.setKey(regionName); + analysisData.setValue(expertCnt); + regionExpertNumberChartDataList.add(analysisData); + } + analysisChartList.add(regionExpertNumberChartAnalysisChart); + + // 查询区域的专家id 列表 + List regionDegreeExpertIdList = new ArrayList<>(); + if (StringUtils.isNotBlank(queryRegionCode)) { + List expertUserFullInfoList = regionCodeExpertMap.get(queryRegionCode); + if (CollectionUtil.isNotEmpty(expertUserFullInfoList)) { + regionDegreeExpertIdList = expertUserFullInfoList.stream() + .map(ExpertUserFullInfo::getUserId) + .collect(Collectors.toList()); + } + } else { + regionDegreeExpertIdList = evidenceHasBeenSubmittedExpertInfoList.stream() + .map(ExpertUserFullInfo::getUserId) + .collect(Collectors.toList()); + } + + if (CollectionUtil.isNotEmpty(regionDegreeExpertIdList)) { + // 区域学历分布 + List degreeExpertDictionaryList = iExpertDictionaryService + .listByUserId(regionDegreeExpertIdList, DictExpertInfoTypeEnum.DEGREE); + Map> degreeCodeMap = degreeExpertDictionaryList.stream() + .map(ExpertDictionary::getDictionaryCode) + .collect(Collectors.groupingBy(Function.identity())); + AnalysisChart regionExpertEducationChartAnalysisChart = + assemblerAnalysisChart(degreeCodeMap, ChartTypeEnum.REGION_EXPERT_EDUCATION_CHART); + analysisChartList.add(regionExpertEducationChartAnalysisChart); + + + // 区域职称级别分布 + List titleLevelExpertDictionaryList = iExpertDictionaryService + .listByUserId(regionDegreeExpertIdList, DictExpertInfoTypeEnum.TITLE_LEVEL); + Map> titleLevelCodeMap = titleLevelExpertDictionaryList.stream() + .map(ExpertDictionary::getDictionaryCode) + .collect(Collectors.groupingBy(Function.identity())); + AnalysisChart regionExpertTitleLevelChartAnalysisChart = + assemblerAnalysisChart(titleLevelCodeMap, ChartTypeEnum.REGION_EXPERT_TITLE_LEVEL_CHART); + analysisChartList.add(regionExpertTitleLevelChartAnalysisChart); + + } + + + // 评审次数 + List normalMeetingList = iMeetingService.list(Wrappers.lambdaQuery(Meeting.class) + .eq(StringUtils.isNotBlank(queryRegionCode), Meeting::getRegionCode, queryRegionCode) + .ne(Meeting::getStatus, MeetingStatusEnum.CANCELED.getCode())); + Integer meetingCnt = normalMeetingList.size(); + + // 各类型评审次数 + Map> meetingTypeMap = normalMeetingList.stream().map(Meeting::getType) + .collect(Collectors.groupingBy(Function.identity())); + AnalysisChart meetingTypeCntChartAnalysisChart = + assemblerAnalysisChart(meetingTypeMap, ChartTypeEnum.MEETING_TYPE_CNT_CHART); + analysisChartList.add(meetingTypeCntChartAnalysisChart); + + + // 明星专家列表 + List starExpertList = new ArrayList<>(); + List meetingExpertJudgeList = iMeetingExpertJudgeService.list(); + Map> expertIdMeetingExpertJudgeMap = meetingExpertJudgeList.stream() + .collect(Collectors.groupingBy(MeetingExpertJudge::getExpertId)); + Map expertIdExpertNameMap = evidenceHasBeenSubmittedExpertInfoList.stream() + .collect(Collectors.toMap(ExpertUserFullInfo::getUserId, ExpertUserFullInfo::getExpertName)); + + for (Long expertId : expertIdMeetingExpertJudgeMap.keySet()) { + String expertName = expertIdExpertNameMap.get(expertId); + List expertMeetingExpertJudgeList = expertIdMeetingExpertJudgeMap.get(expertId); + DoubleSummaryStatistics statistics = expertMeetingExpertJudgeList + .stream().filter(r -> Objects.nonNull(r.getScore())) + .map(MeetingExpertJudge::getScore).mapToDouble(Number::doubleValue).summaryStatistics(); + double average = statistics.getAverage(); + StarExpertBO starExpertBO = new StarExpertBO(); + starExpertBO.setAveragePerformanceScore(average); + starExpertBO.setExpertId(expertId); + starExpertBO.setExpertName(expertName); + starExpertList.add(starExpertBO); + starExpertList.add(starExpertBO); + } + + starExpertList = starExpertList.stream() + .sorted(Comparator.comparing(StarExpertBO::getAveragePerformanceScore) + .reversed()).collect(Collectors.toList()); + if (starExpertList.size() > 5) { + starExpertList = starExpertList.subList(0, 5); + } + + // 装配返回类 + ExpertDashboardSummaryVO expertDashboardSummaryVO = new ExpertDashboardSummaryVO(); + expertDashboardSummaryVO.setMeetingCnt(meetingCnt); + expertDashboardSummaryVO.setStarExpertList(starExpertList); + expertDashboardSummaryVO.setAnalysisChartList(analysisChartList); + return expertDashboardSummaryVO; } + + private AnalysisChart assemblerAnalysisChart(Map> dictionaryCodeIdMap + , ChartTypeEnum chartTypeEnum) { + AnalysisChart analysisChart = new AnalysisChart(); + List dataList = new ArrayList<>(); + analysisChart.setChartType(chartTypeEnum); + analysisChart.setDataList(dataList); + + for (String dictionaryCode : dictionaryCodeIdMap.keySet()) { + AnalysisData analysisData = new AnalysisData(); + analysisData.setKey(dictionaryCache.getByCode(dictionaryCode).getName()); + analysisData.setValue(dictionaryCodeIdMap.get(dictionaryCode).size()); + dataList.add(analysisData); + } + return analysisChart; + } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/manage/DashboardProjectManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/manage/DashboardProjectManage.java index 104d445..b378326 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/manage/DashboardProjectManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/manage/DashboardProjectManage.java @@ -25,6 +25,8 @@ public class DashboardProjectManage { private static String timeFormat = "%s-01-01 00:00:00"; + + /** * 查询年份BO 装配 * diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/model/basic/AnalysisData.java b/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/model/basic/AnalysisData.java index 1c3151d..448e15d 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/model/basic/AnalysisData.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/model/basic/AnalysisData.java @@ -2,12 +2,14 @@ package com.ningdatech.pmapi.dashboard.model.basic; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import lombok.Data; /** * @author liuxinxin * @date 2023/8/2 下午2:27 */ +@Data @ApiModel("分析数据基础类") public class AnalysisData { diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/model/po/QueryYearPO.java b/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/model/po/QueryYearPO.java index 6454010..6f0dae6 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/model/po/QueryYearPO.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/dashboard/model/po/QueryYearPO.java @@ -16,4 +16,6 @@ public class QueryYearPO { @ApiModelProperty("查询年份") private Integer year; + @ApiModelProperty("区域编码") + private String regionCode; }