1 changed files with 178 additions and 0 deletions
@ -0,0 +1,178 @@ |
|||||||
|
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.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; |
||||||
|
|
||||||
|
@Service |
||||||
|
@AllArgsConstructor |
||||||
|
public class IndicatorStatisticsServiceImpl implements IndicatorStatisticsService { |
||||||
|
|
||||||
|
private final BiddingProjectSubscribeService biddingProjectSubscribeService; |
||||||
|
private final CustomAuthService customAuthService; |
||||||
|
private final UserProvider userProvider; |
||||||
|
|
||||||
|
|
||||||
|
@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); |
||||||
|
for (int day = 1; day <= yearMonth.lengthOfMonth(); 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": |
||||||
|
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")); |
||||||
|
} catch (Exception e) { |
||||||
|
throw new DataException("dataTime parse error, must be yyyy"); |
||||||
|
} |
||||||
|
} |
||||||
|
for (int monthCount = 1; monthCount <= 12; 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.", "")); |
||||||
|
response.setDataList(dataList); |
||||||
|
return response; |
||||||
|
} |
||||||
|
|
||||||
|
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; |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue