4 changed files with 396 additions and 0 deletions
@ -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); |
||||||
|
} |
||||||
@ -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<T> queryWhere = getAuthWrapper(param.getMenuId()); |
||||||
|
if (ObjectUtil.isEmpty(queryWhere)) { |
||||||
|
return response; |
||||||
|
} |
||||||
|
assert queryWhere != null; |
||||||
|
List<IndicatorStatisticsDto.Indicator> indicatorList = biddingProjectSubscribeService.getProjectsNumberByType(param, queryWhere.getParamNameValuePairs(), queryWhere.getSqlSegment().replace("paramNameValuePairs.", "")); |
||||||
|
checkResult(response, indicatorList); |
||||||
|
|
||||||
|
return response; |
||||||
|
} |
||||||
|
|
||||||
|
private void checkResult(IndicatorStatisticsDto.ProjectsNumberResponse response, List<IndicatorStatisticsDto.Indicator> indicatorList) { |
||||||
|
List<IndicatorStatisticsDto.Indicator> responseIndicatorList = response.getIndicatorList(); |
||||||
|
if (CollectionUtil.isEmpty(responseIndicatorList)) { |
||||||
|
response.setIndicatorList(indicatorList); |
||||||
|
return; |
||||||
|
} |
||||||
|
for (IndicatorStatisticsDto.Indicator indicator : responseIndicatorList) { |
||||||
|
Optional<IndicatorStatisticsDto.Indicator> first = indicatorList.stream().filter(item -> item.getXData().equals(indicator.getXData())).findFirst(); |
||||||
|
first.ifPresent(value -> BeanUtil.copyProperties(value, indicator)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private QueryWrapper<T> getAuthWrapper(String menuId) { |
||||||
|
if (!userProvider.get().getIsAdministrator()) { |
||||||
|
QueryWrapper<T> 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<T>) 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<T> queryWhere = getAuthWrapper(param.getMenuId()); |
||||||
|
if (ObjectUtil.isEmpty(queryWhere)) { |
||||||
|
return response; |
||||||
|
} |
||||||
|
assert queryWhere != null; |
||||||
|
List<IndicatorStatisticsDto.MoneyAndProjectsNumberChild> 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<IndicatorStatisticsDto.MoneyAndProjectsNumberChild> dataList) { |
||||||
|
// <if test="param.classificationType=='2'.toString()">
|
||||||
|
// 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
|
||||||
|
// </if>
|
||||||
|
// <if test="param.classificationType=='3'.toString()">
|
||||||
|
// 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
|
||||||
|
// </if>
|
||||||
|
// <if test="param.classificationType=='4'.toString()">
|
||||||
|
// 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
|
||||||
|
// </if>
|
||||||
|
String classificationType = param.getClassificationType(); |
||||||
|
List<String> oldNameList = dataList.stream().map(IndicatorStatisticsDto.MoneyAndProjectsNumberChild::getYName).collect(Collectors.toList()); |
||||||
|
List<String> 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; |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
@ -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<IndicatorStatisticsDto.ProjectsNumberResponse> projectsNumber(IndicatorStatisticsDto.ProjectsNumberParam param) { |
||||||
|
return ActionResult.success(indicatorStatisticsService.projectsNumber(param)); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Operation(summary = "项目数 金额") |
||||||
|
@GetMapping("/moneyAndProjectsNumber") |
||||||
|
public ActionResult<IndicatorStatisticsDto.MoneyAndProjectsNumberResponse> moneyAndProjectsNumber(IndicatorStatisticsDto.MoneyAndProjectsNumberParam param) { |
||||||
|
return ActionResult.success(indicatorStatisticsService.moneyAndProjectsNumber(param)); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
@ -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<Indicator> 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<MoneyAndProjectsNumberChild> dataList=new ArrayList<>(); |
||||||
|
} |
||||||
|
|
||||||
|
@Data |
||||||
|
public static class MoneyAndProjectsNumberChild { |
||||||
|
/** |
||||||
|
* 类型名称 |
||||||
|
*/ |
||||||
|
private String yName; |
||||||
|
/** |
||||||
|
* 项目数量 |
||||||
|
*/ |
||||||
|
private String projectsNumber; |
||||||
|
/** |
||||||
|
* 金额 |
||||||
|
*/ |
||||||
|
private String money; |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue