From 891b320cd39b660239370c7978edef39a9acda3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0tr?= Date: Fri, 16 Aug 2024 11:00:11 +0800 Subject: [PATCH] aa --- .../service/IndicatorStatisticsService.java | 9 + .../impl/IndicatorStatisticsServiceImpl.java | 245 ++++++++++++++++++ .../IndicatorStatisticsController.java | 45 ++++ .../model/dto/IndicatorStatisticsDto.java | 97 +++++++ 4 files changed, 396 insertions(+) create mode 100644 jnpf-tendering-biz/src/main/java/jnpf/service/IndicatorStatisticsService.java create mode 100644 jnpf-tendering-biz/src/main/java/jnpf/service/impl/IndicatorStatisticsServiceImpl.java create mode 100644 jnpf-tendering-controller/src/main/java/jnpf/controller/IndicatorStatisticsController.java create mode 100644 jnpf-tendering-entity/src/main/java/jnpf/model/dto/IndicatorStatisticsDto.java diff --git a/jnpf-tendering-biz/src/main/java/jnpf/service/IndicatorStatisticsService.java b/jnpf-tendering-biz/src/main/java/jnpf/service/IndicatorStatisticsService.java new file mode 100644 index 0000000..d5d3563 --- /dev/null +++ b/jnpf-tendering-biz/src/main/java/jnpf/service/IndicatorStatisticsService.java @@ -0,0 +1,9 @@ +package jnpf.service; + +import jnpf.model.dto.IndicatorStatisticsDto; + +public interface IndicatorStatisticsService { + IndicatorStatisticsDto.ProjectsNumberResponse projectsNumber(IndicatorStatisticsDto.ProjectsNumberParam param); + + IndicatorStatisticsDto.MoneyAndProjectsNumberResponse moneyAndProjectsNumber(IndicatorStatisticsDto.MoneyAndProjectsNumberParam param); +} diff --git a/jnpf-tendering-biz/src/main/java/jnpf/service/impl/IndicatorStatisticsServiceImpl.java b/jnpf-tendering-biz/src/main/java/jnpf/service/impl/IndicatorStatisticsServiceImpl.java new file mode 100644 index 0000000..e94a99a --- /dev/null +++ b/jnpf-tendering-biz/src/main/java/jnpf/service/impl/IndicatorStatisticsServiceImpl.java @@ -0,0 +1,245 @@ +package jnpf.service.impl; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.date.LocalDateTimeUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import jnpf.base.DictionaryDataApi; +import jnpf.base.entity.DictionaryDataEntity; +import jnpf.entity.Bidding_project_statisticsEntity; +import jnpf.exception.DataException; +import jnpf.model.dto.IndicatorStatisticsDto; +import jnpf.permission.model.authorize.AuthorizeConditionModel; +import jnpf.service.BiddingProjectSubscribeService; +import jnpf.service.CustomAuthService; +import jnpf.service.IndicatorStatisticsService; +import jnpf.util.ServletUtil; +import jnpf.util.UserProvider; +import lombok.AllArgsConstructor; +import org.apache.poi.ss.formula.functions.T; +import org.springframework.stereotype.Service; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.YearMonth; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +@Service +@AllArgsConstructor +public class IndicatorStatisticsServiceImpl implements IndicatorStatisticsService { + + private final BiddingProjectSubscribeService biddingProjectSubscribeService; + private final CustomAuthService customAuthService; + private final UserProvider userProvider; + private final DictionaryDataApi dictionaryDataApi; + + + @Override + public IndicatorStatisticsDto.ProjectsNumberResponse projectsNumber(IndicatorStatisticsDto.ProjectsNumberParam param) { + //校验参数 + IndicatorStatisticsDto.ProjectsNumberResponse response = checkProjectsNumber(param); + QueryWrapper queryWhere = getAuthWrapper(param.getMenuId()); + if (ObjectUtil.isEmpty(queryWhere)) { + return response; + } + assert queryWhere != null; + List indicatorList = biddingProjectSubscribeService.getProjectsNumberByType(param, queryWhere.getParamNameValuePairs(), queryWhere.getSqlSegment().replace("paramNameValuePairs.", "")); + checkResult(response, indicatorList); + + return response; + } + + private void checkResult(IndicatorStatisticsDto.ProjectsNumberResponse response, List indicatorList) { + List responseIndicatorList = response.getIndicatorList(); + if (CollectionUtil.isEmpty(responseIndicatorList)) { + response.setIndicatorList(indicatorList); + return; + } + for (IndicatorStatisticsDto.Indicator indicator : responseIndicatorList) { + Optional first = indicatorList.stream().filter(item -> item.getXData().equals(indicator.getXData())).findFirst(); + first.ifPresent(value -> BeanUtil.copyProperties(value, indicator)); + } + } + + private QueryWrapper getAuthWrapper(String menuId) { + if (!userProvider.get().getIsAdministrator()) { + QueryWrapper queryWhere = new QueryWrapper<>(); + Object bidding_project_statisticsObj = customAuthService.getCondition(new AuthorizeConditionModel(queryWhere, menuId, "bidding_project_subscribe")); + System.out.println("---------------" + JSON.toJSONString(bidding_project_statisticsObj)); + return (QueryWrapper) bidding_project_statisticsObj; + } + return null; + } + + private IndicatorStatisticsDto.ProjectsNumberResponse checkProjectsNumber(IndicatorStatisticsDto.ProjectsNumberParam param) { + IndicatorStatisticsDto.ProjectsNumberResponse response = new IndicatorStatisticsDto.ProjectsNumberResponse(); + if (StrUtil.isBlank(param.getMenuId())) { + throw new DataException("请传入menuId"); + } + if (StrUtil.isBlank(param.getType())) { + throw new DataException("请选择查询类型"); + } + //查询类型 1-本月:到日。2-当年:按月。3-累计:按年 + //赋予默认值 查询每月天数/查询每年月数 + switch (param.getType()) { + case "1": + if (StrUtil.isBlank(param.getCorresponding())) { + String format = LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM"); + param.setCorresponding(format); + response.setCorresponding(LocalDateTimeUtil.parse(format, "yyyy-MM")); + } else { + //校验时间格式 + try { + response.setCorresponding(LocalDateTimeUtil.parse(param.getCorresponding(), "yyyy-MM")); + } catch (Exception e) { + throw new DataException("dataTime parse error, must be yyyy-MM"); + } + } + LocalDateTime month = LocalDateTimeUtil.parse(param.getCorresponding(), "yyyy-MM"); + YearMonth yearMonth = YearMonth.from(month); + int i = yearMonth.lengthOfMonth(); + if (LocalDateTimeUtil.parse(LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM"), "yyyy-MM").isEqual(LocalDateTimeUtil.parse(param.getCorresponding(), "yyyy-MM"))){ + i=LocalDateTime.now().getDayOfMonth(); + } + for (int day = 1; day <= i; day++) { + IndicatorStatisticsDto.Indicator indicator = new IndicatorStatisticsDto.Indicator(); + indicator.setYData("0"); + // 创建代表该日期的LocalDate对象 + LocalDate date = yearMonth.atDay(day); + // 使用DateTimeFormatter来格式化日期为字符串 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd日"); + indicator.setXData(date.format(formatter)); + response.getIndicatorList().add(indicator); + } + break; + case "2": + int value = LocalDateTime.now().getMonth().getValue(); + if (StrUtil.isBlank(param.getCorresponding())) { + String yyyy = LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy"); + param.setCorresponding(yyyy); + response.setCorresponding(LocalDateTimeUtil.parse(yyyy, "yyyy")); + } else { + //校验时间格式 + try { + response.setCorresponding(LocalDateTimeUtil.parse(param.getCorresponding(), "yyyy")); + if (LocalDateTime.now().getYear()>LocalDateTimeUtil.parse(param.getCorresponding(), "yyyy").getYear()){ + value = 12; + } + } catch (Exception e) { + throw new DataException("dataTime parse error, must be yyyy"); + } + } + for (int monthCount = 1; monthCount <= value; monthCount++) { + IndicatorStatisticsDto.Indicator indicator = new IndicatorStatisticsDto.Indicator(); + indicator.setYData("0"); + String monthString = String.format("%02d", monthCount); + indicator.setXData(monthString + "月"); + response.getIndicatorList().add(indicator); + } + break; + case "3": + break; + default: + throw new DataException("查询类型错误: " + param.getType()); + } + return response; + } + + @Override + public IndicatorStatisticsDto.MoneyAndProjectsNumberResponse moneyAndProjectsNumber(IndicatorStatisticsDto.MoneyAndProjectsNumberParam param) { + IndicatorStatisticsDto.MoneyAndProjectsNumberResponse response = checkMoneyAndProjectsNumberParam(param); + QueryWrapper queryWhere = getAuthWrapper(param.getMenuId()); + if (ObjectUtil.isEmpty(queryWhere)) { + return response; + } + assert queryWhere != null; + List dataList = biddingProjectSubscribeService.moneyAndProjectsNumber(param, queryWhere.getParamNameValuePairs(), queryWhere.getSqlSegment().replace("paramNameValuePairs.", "")); + checkMoneyAndProjectsNumberResult(param,dataList); + response.setDataList(dataList); + return response; + } + + private void checkMoneyAndProjectsNumberResult(IndicatorStatisticsDto.MoneyAndProjectsNumberParam param, List dataList) { +// +// count(organizational_form) projectsNumber, +// (select f_full_name from base_dictionary_data where f_dictionary_type_id='539393647729185989' and f_en_code=main.organizational_form limit 1) yName +// +// +// count(Item_classification) projectsNumber, +// (select f_full_name from base_dictionary_data where f_dictionary_type_id='539390743437907141' and f_en_code=main.item_classification limit 1) yName +// +// +// count(bidding_method) projectsNumber, +// (select f_full_name from base_dictionary_data where f_dictionary_type_id='539394095383057605' and f_en_code=main.bidding_method limit 1) yName +// + String classificationType = param.getClassificationType(); + List oldNameList = dataList.stream().map(IndicatorStatisticsDto.MoneyAndProjectsNumberChild::getYName).collect(Collectors.toList()); + List newNameList=new ArrayList<>(); + switch (classificationType){ + case "1": + break; + case "2": + newNameList = dictionaryDataApi.getList("539393647729185989") + .stream() + .map(DictionaryDataEntity::getFullName) + .filter(fullName -> !oldNameList.contains(fullName)) + .collect(Collectors.toList()); + break; + case "3": + newNameList = dictionaryDataApi.getList("539390743437907141") + .stream() + .map(DictionaryDataEntity::getFullName) + .filter(fullName -> !oldNameList.contains(fullName)) + .collect(Collectors.toList()); + break; + case "4": + newNameList = dictionaryDataApi.getList("539394095383057605") + .stream() + .map(DictionaryDataEntity::getFullName) + .filter(fullName -> !oldNameList.contains(fullName)) + .collect(Collectors.toList()); + break; + + } + if (CollectionUtil.isEmpty(newNameList)){ + return; + } + for (String name : newNameList) { + IndicatorStatisticsDto.MoneyAndProjectsNumberChild data = new IndicatorStatisticsDto.MoneyAndProjectsNumberChild(); + data.setYName(name); + data.setProjectsNumber("0"); + data.setMoney("0.0"); + dataList.add(data); + } + } + + private IndicatorStatisticsDto.MoneyAndProjectsNumberResponse checkMoneyAndProjectsNumberParam(IndicatorStatisticsDto.MoneyAndProjectsNumberParam param) { + IndicatorStatisticsDto.MoneyAndProjectsNumberResponse response = new IndicatorStatisticsDto.MoneyAndProjectsNumberResponse(); + if (StrUtil.isBlank(param.getMenuId())) { + throw new DataException("请传入menuId"); + } + switch (param.getQueryDateType()) { + case "1": + String format = LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM"); + param.setCorresponding(format); + break; + case "2": + String yyyy = LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy"); + param.setCorresponding(yyyy); + case "3": + break; + default: + throw new DataException("查询类型错误: " + param.getQueryDateType()); + } + response.setClassificationType(param.getClassificationType()); + return response; + + } +} diff --git a/jnpf-tendering-controller/src/main/java/jnpf/controller/IndicatorStatisticsController.java b/jnpf-tendering-controller/src/main/java/jnpf/controller/IndicatorStatisticsController.java new file mode 100644 index 0000000..d25047f --- /dev/null +++ b/jnpf-tendering-controller/src/main/java/jnpf/controller/IndicatorStatisticsController.java @@ -0,0 +1,45 @@ +package jnpf.controller; + + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jnpf.base.ActionResult; +import jnpf.base.Pagination; +import jnpf.base.vo.PageListVO; +import jnpf.base.vo.PaginationVO; +import jnpf.entity.ContractEntity; +import jnpf.model.ContractListVO; +import jnpf.model.dto.IndicatorStatisticsDto; +import jnpf.service.BiddingProjectSubscribeService; +import jnpf.service.IndicatorStatisticsService; +import jnpf.util.JsonUtil; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@Tag(name = "指标统计接口", description = "indicator") +@RequestMapping("/indicator") +@AllArgsConstructor +public class IndicatorStatisticsController { + private final IndicatorStatisticsService indicatorStatisticsService; + + + @Operation(summary = "审批/备案项目数") + @GetMapping("/projectsNumber") + public ActionResult projectsNumber(IndicatorStatisticsDto.ProjectsNumberParam param) { + return ActionResult.success(indicatorStatisticsService.projectsNumber(param)); + } + + + @Operation(summary = "项目数 金额") + @GetMapping("/moneyAndProjectsNumber") + public ActionResult moneyAndProjectsNumber(IndicatorStatisticsDto.MoneyAndProjectsNumberParam param) { + return ActionResult.success(indicatorStatisticsService.moneyAndProjectsNumber(param)); + } + + +} diff --git a/jnpf-tendering-entity/src/main/java/jnpf/model/dto/IndicatorStatisticsDto.java b/jnpf-tendering-entity/src/main/java/jnpf/model/dto/IndicatorStatisticsDto.java new file mode 100644 index 0000000..6b20b4d --- /dev/null +++ b/jnpf-tendering-entity/src/main/java/jnpf/model/dto/IndicatorStatisticsDto.java @@ -0,0 +1,97 @@ +package jnpf.model.dto; + +import lombok.Data; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +@Data +public class IndicatorStatisticsDto { + @Data + public static class ProjectsNumberParam { + /** + * 查询类型 1-本月(默认本月):到日。2-当年:按月。3-累计:按年 + */ + private String type="1"; + /** + * 权限控制 + */ + private String menuId; + /** + * 根据type 传入对应参数 eg:月份查询传入某年某月 不传入默认为当年当月 返回当月当月日统计 + * 月份传入 yyyy-MM + * 年份传入 yyyy + * 累计无需传入 + */ + private String corresponding; + + } + + @Data + public static class ProjectsNumberResponse { + /** + * 返回时间类型 用于前端展示使用 + */ + private LocalDateTime corresponding; + /** + * 根据type 传入对应参数 eg:月份查询传入某年某月 不传入默认为当年当月 返回当月当月日统计 + */ + private List indicatorList = new ArrayList<>(); + } + + @Data + public static class Indicator { + /** + * x轴数据 + */ + private String xData; + /** + * y轴数据 + */ + private String yData; + } + + + @Data + public static class MoneyAndProjectsNumberParam { + /** + * 查询类型 1-本月 默认本月。2-当年。3-累计 + */ + private String queryDateType = "1"; + /** + * 查询类型 1-所有(默认所有) 2-按组织形式分布 3-按事项分类分布 4-按招标方式分布 + */ + private String classificationType = "1"; + /** + * 权限控制 + */ + private String menuId; + private String corresponding; + } + + @Data + public static class MoneyAndProjectsNumberResponse { + /** + * 1-所有(默认所有) 2-按组织形式分布 3-按事项分类分布 4-按招标方式分布 + */ + private String classificationType; + private List dataList=new ArrayList<>(); + } + + @Data + public static class MoneyAndProjectsNumberChild { + /** + * 类型名称 + */ + private String yName; + /** + * 项目数量 + */ + private String projectsNumber; + /** + * 金额 + */ + private String money; + } +}