| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.finance.common.basic.PageDTO; |
| | | import com.finance.common.core.domain.entity.SysUser; |
| | | import com.finance.common.enums.AreaLevelEnum; |
| | | import com.finance.common.enums.UserTypeEnum; |
| | | import com.finance.common.exception.ServiceException; |
| | | import com.finance.common.utils.BeanUtils; |
| | | import com.finance.common.utils.CollUtils; |
| | | import com.finance.common.utils.DateUtils; |
| | | import com.finance.system.constants.QuarterConstant; |
| | | import com.finance.system.domain.TbBasicDataConfig; |
| | | import com.finance.system.domain.TbScore; |
| | | import com.finance.system.mapper.TbScoreMapper; |
| | |
| | | import com.finance.system.query.HistoryScoreQuery; |
| | | import com.finance.system.query.ScoreCalculateDetailQuery; |
| | | import com.finance.system.query.ScoreQuery; |
| | | import com.finance.system.service.ISysUserService; |
| | | import com.finance.system.service.TbBasicDataConfigService; |
| | | import com.finance.system.service.TbScoreService; |
| | | import com.finance.system.vo.DataScreenConfigVO; |
| | | import com.finance.system.vo.DeptCalculateDetailVO; |
| | | import com.finance.system.vo.RiskMapVO; |
| | | import com.finance.system.vo.RiskRankingVO; |
| | |
| | | import com.finance.system.vo.ScoreDetailVO; |
| | | import com.finance.system.vo.ScoreRankVO; |
| | | import com.finance.system.vo.ScoreVO; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | |
| | | TbScoreService { |
| | | |
| | | private final TbBasicDataConfigService basicDataConfigService; |
| | | private final ISysUserService sysUserService; |
| | | |
| | | @Override |
| | | public Page<ScoreVO> pageScore(ScoreQuery query, Page<ScoreVO> page) { |
| | |
| | | vo.setCalculateType(config.getCalculateType()); |
| | | Page<ScoreDetailVO> page = new Page<>(query.getPageNum(), query.getPageSize()); |
| | | String previousQuarter = DateUtils.getPreviousQuarter(); |
| | | previousQuarter = "2024年一季度"; |
| | | previousQuarter = QuarterConstant.CURRENT_QUARTER; |
| | | query.setPreviousQuarter(previousQuarter); |
| | | Page<ScoreDetailVO> pageVO = baseMapper.scoreCalculateDetail(query, page); |
| | | vo.setTotal(pageVO.getTotal()); |
| | | vo.setPages(pageVO.getPages()); |
| | | vo.setList(pageVO.getRecords()); |
| | | return vo; |
| | | } |
| | | |
| | | @Override |
| | | public ScoreCalculateDetailVO scoreCalculateHistoryDetail(ScoreCalculateDetailQuery query) |
| | | throws Exception { |
| | | // 查询计算类型 |
| | | TbBasicDataConfig config = basicDataConfigService.getById(query.getId()); |
| | | if (Objects.isNull(config)) { |
| | | throw new ServiceException("非法参数"); |
| | | } |
| | | ScoreCalculateDetailVO vo = new ScoreCalculateDetailVO(); |
| | | vo.setTypeName(config.getTypeName()); |
| | | vo.setCalculateType(config.getCalculateType()); |
| | | Page<ScoreDetailVO> page = new Page<>(query.getPageNum(), query.getPageSize()); |
| | | Page<ScoreDetailVO> pageVO = baseMapper.scoreCalculateDetail(query, page); |
| | | vo.setTotal(pageVO.getTotal()); |
| | | vo.setPages(pageVO.getPages()); |
| | |
| | | @Override |
| | | public ScoreRankVO queryRankAndScoreByAreaCode(String areaCode) throws Exception { |
| | | String previousQuarter = DateUtils.getPreviousQuarter(); |
| | | previousQuarter = "2024年一季度"; |
| | | previousQuarter = QuarterConstant.CURRENT_QUARTER; |
| | | List<ScoreRankVO> voList = baseMapper.queryRankAndScoreByAreaCode(areaCode, |
| | | previousQuarter); |
| | | if (CollUtils.isNotEmpty(voList)) { |
| | |
| | | vo.setCalculateType(config.getCalculateType()); |
| | | Page<ScoreDetailVO> page = new Page<>(query.getPageNum(), query.getPageSize()); |
| | | String previousQuarter = DateUtils.getPreviousQuarter(); |
| | | previousQuarter = "2023年一季度"; |
| | | previousQuarter = QuarterConstant.CURRENT_QUARTER; |
| | | query.setPreviousQuarter(previousQuarter); |
| | | Page<ScoreDetailVO> pageVO = baseMapper.fieldsDetail(query, page, areaCodeList); |
| | | vo.setTotal(pageVO.getTotal()); |
| | | vo.setPages(pageVO.getPages()); |
| | |
| | | public List<RiskMapVO> getScoreByYearType(String areaCode, String quarter) { |
| | | return baseMapper.getScoreByYearType(areaCode, quarter); |
| | | } |
| | | |
| | | @Override |
| | | public List<RiskMapVO> getCityScore(String previousQuarter, DataScreenConfigVO riskLevel) { |
| | | // 查询城市部门 |
| | | List<SysUser> cityList = getCityList(); |
| | | List<RiskMapVO> riskMapVOList = new ArrayList<>(); |
| | | for (SysUser sysUser : cityList) { |
| | | RiskMapVO vo = new RiskMapVO(); |
| | | vo.setAreaCode(sysUser.getAreaCode()); |
| | | vo.setAreaName(sysUser.getAreaName()); |
| | | vo.setAreaLevel(sysUser.getAreaLevel()); |
| | | String areaCode = sysUser.getAreaCode(); |
| | | areaCode = areaCode.substring(0, 4); |
| | | Double totalAverageScore = baseMapper.getCityAverageScore(areaCode, |
| | | previousQuarter); |
| | | // 查询区县的得分 |
| | | List<Double> countyScoreList = baseMapper.getCountyScoreList(areaCode, previousQuarter); |
| | | // 将风险范围解析为列表,只解析一次 |
| | | List<Double> mediumRange = Arrays.stream(riskLevel.getMediumRisk().split("_")) |
| | | .map(Double::valueOf) |
| | | .collect(Collectors.toList()); |
| | | |
| | | List<Double> noRiskRange = Arrays.stream(riskLevel.getNoRisk().split("_")) |
| | | .map(Double::valueOf) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 计算中等风险和无风险的数量 |
| | | long mediumCount = 0; |
| | | long noCount = 0; |
| | | for (Double score : countyScoreList) { |
| | | if (score >= mediumRange.get(0) && score <= mediumRange.get(1)) { |
| | | mediumCount++; |
| | | } else if (score >= noRiskRange.get(0) && score <= noRiskRange.get(1)) { |
| | | noCount++; |
| | | } |
| | | } |
| | | // 当中等风险的数量大于总数的1/3,总分减一 |
| | | if ((double) mediumCount / (double) countyScoreList.size() > 0.33) { |
| | | totalAverageScore = totalAverageScore - 1D; |
| | | } |
| | | // 当无风险的数量大于总数的1/3,总分加一 |
| | | if ((double) noCount / (double) countyScoreList.size() > 0.33) { |
| | | totalAverageScore = totalAverageScore + 1D; |
| | | } |
| | | vo.setScore(totalAverageScore); |
| | | riskMapVOList.add(vo); |
| | | } |
| | | return riskMapVOList; |
| | | } |
| | | |
| | | public List<SysUser> getCityList() { |
| | | List<SysUser> list = sysUserService.lambdaQuery() |
| | | .eq(SysUser::getAreaLevel, AreaLevelEnum.CITY) |
| | | .list(); |
| | | return list; |
| | | } |
| | | |
| | | public List<SysUser> getChildrenList(String areaCode) { |
| | | String cityCode = areaCode.substring(0, 4); |
| | | List<SysUser> list = sysUserService.lambdaQuery() |
| | | .select(SysUser::getAreaCode, SysUser::getAreaName, SysUser::getAreaAlias, |
| | | SysUser::getUserId).eq(SysUser::getUserType, |
| | | UserTypeEnum.DEPARTMENT).likeRight(SysUser::getAreaCode, cityCode).list(); |
| | | return list; |
| | | } |
| | | } |