diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderStatisticsServiceImpl.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderStatisticsServiceImpl.java index f9fa580ff..46bec2495 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderStatisticsServiceImpl.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderStatisticsServiceImpl.java @@ -1,6 +1,7 @@ package com.cf.imes.module.executor.service.order; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ObjectUtil; import co.elastic.clients.elasticsearch.ElasticsearchClient; import co.elastic.clients.elasticsearch._types.FieldValue; @@ -654,7 +655,7 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService { LocalDate startTime = null; LocalDate endTime; LocalDate now = LocalDate.now(); - if (ObjectUtil.isNull(createTime) || ObjectUtil.isNull(createTime[0]) || ObjectUtil.isNull(createTime[1])) { + if (ArrayUtil.isEmpty(createTime) || ObjectUtil.isNull(createTime[0]) || ObjectUtil.isNull(createTime[1])) { endTime = now; switch (OrderStatisticsUnit.fromValue(reqVO.getUnit())) { case QUARTER: diff --git a/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/controller/admin/funds/organamount/OrganAmountController.java b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/controller/admin/funds/organamount/OrganAmountController.java index 763508744..791b24135 100644 --- a/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/controller/admin/funds/organamount/OrganAmountController.java +++ b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/controller/admin/funds/organamount/OrganAmountController.java @@ -4,19 +4,20 @@ package com.cf.imes.module.system.controller.admin.funds.organamount; import com.cf.imes.framework.common.pojo.CommonResult; import com.cf.imes.module.system.controller.admin.funds.organamount.vo.AllOrganAmountRespVO; import com.cf.imes.module.system.controller.admin.funds.organamount.vo.OrganAmountRespVO; +import com.cf.imes.module.system.controller.admin.funds.organamount.vo.OrganFundsStatisticsReqVO; import com.cf.imes.module.system.service.funds.organamount.OrganAmountService; import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import jakarta.annotation.Resource; import jakarta.validation.Valid; +import java.util.Map; + import static com.cf.imes.framework.common.pojo.CommonResult.success; /** @@ -33,26 +34,21 @@ public class OrganAmountController { private OrganAmountService organAmountService; - @GetMapping("") @Operation(summary = "获取组织余额数据") - @Parameter(name = "organId", description = "组织ID", required = true) - public CommonResult getOrganAmount(@Valid @RequestParam("organId") Long organId) { - - return success(organAmountService.getOrganAmount(organId)); - + public CommonResult getOrganAmount() { + return success(organAmountService.getOrganAmount()); } - - - - @GetMapping("/all") - @Operation(summary = "获取全部组织的余额数据") - public CommonResult getOrganAmountAll() { - + @GetMapping("/manage") + @Operation(summary = "获取管理端账户现金总额") + public CommonResult getManageOrganAmount() { return success(organAmountService.getOrganAmountAll()); - } - + @GetMapping("/statistics/consumptionTrend") + @Operation(summary = "获取组织消费趋势") + public CommonResult> getOrganConsumptionTrend(@Valid OrganFundsStatisticsReqVO reqVO) { + return success(organAmountService.getOrganConsumptionTrend(reqVO)); + } } diff --git a/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/controller/admin/funds/organamount/vo/OrganAmountGroupByCreateTimeRespVO.java b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/controller/admin/funds/organamount/vo/OrganAmountGroupByCreateTimeRespVO.java new file mode 100644 index 000000000..789a13be0 --- /dev/null +++ b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/controller/admin/funds/organamount/vo/OrganAmountGroupByCreateTimeRespVO.java @@ -0,0 +1,57 @@ +package com.cf.imes.module.system.controller.admin.funds.organamount.vo; + +import lombok.Data; +import org.jetbrains.annotations.NotNull; + +import java.math.BigDecimal; + +/** + * 组织收支趋势按创建时间分组 Resp VO + * + * @author Gqr + * @since 2025/9/1 15:58 + */ +@Data +public class OrganAmountGroupByCreateTimeRespVO implements Comparable { + /** + * 金额 + */ + private BigDecimal amount; + + /** + * 时间 + */ + private String date; + + @Override + public int compareTo(@NotNull OrganAmountGroupByCreateTimeRespVO other) { + // 解析 orderDate 字符串为年、月、周 + String[] partsThis = date.split("-"); + String[] partsOther = other.date.split("-"); + + // 比较年份 + int yearComparison = Integer.compare(Integer.parseInt(partsThis[0]), Integer.parseInt(partsOther[0])); + if (yearComparison != 0) { + return yearComparison; + } + + // 比较月份 + if (partsThis.length > 1 && partsOther.length > 1) { + int monthComparison = Integer.compare(Integer.parseInt(partsThis[1]), Integer.parseInt(partsOther[1])); + if (monthComparison != 0) { + return monthComparison; + } + } + + // 比较周数 + if (partsThis.length > 2 && partsOther.length > 2) { + int weekComparison = Integer.compare(Integer.parseInt(partsThis[2]), Integer.parseInt(partsOther[2])); + if (weekComparison != 0) { + return weekComparison; + } + } + + // 如果所有部分都相同,则按金额排序 + return this.amount.compareTo(other.amount); + } +} diff --git a/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/controller/admin/funds/organamount/vo/OrganFundsStatisticsReqVO.java b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/controller/admin/funds/organamount/vo/OrganFundsStatisticsReqVO.java new file mode 100644 index 000000000..fe48b0251 --- /dev/null +++ b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/controller/admin/funds/organamount/vo/OrganFundsStatisticsReqVO.java @@ -0,0 +1,28 @@ +package com.cf.imes.module.system.controller.admin.funds.organamount.vo; + +import com.cf.imes.module.system.validation.pay.FundsStatisticsUnitInEnum; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDate; + +/** + * @author Gqr + * @since 2024/8/5 17:10 + */ +@Schema(description = "管理后台 - 资金统计趋势 Request VO") +@Data +public class OrganFundsStatisticsReqVO { + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = "yyyy-MM-dd") + private LocalDate[] createTime; + + /** + * 统计维度单位 + */ + @Schema(description = "统计维度单位", example = "0", allowableValues = {"0", "1", "2", "3"}, type = "integer") + @FundsStatisticsUnitInEnum + private Integer unit; +} diff --git a/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/dal/mysql/funds/organamount/OrganAmountMapper.java b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/dal/mysql/funds/organamount/OrganAmountMapper.java index ab27bde95..e9ea0be67 100644 --- a/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/dal/mysql/funds/organamount/OrganAmountMapper.java +++ b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/dal/mysql/funds/organamount/OrganAmountMapper.java @@ -1,18 +1,22 @@ package com.cf.imes.module.system.dal.mysql.funds.organamount; - import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX; +import com.cf.imes.module.system.controller.admin.funds.organamount.vo.OrganAmountGroupByCreateTimeRespVO; +import com.cf.imes.module.system.controller.admin.funds.organamount.vo.OrganFundsStatisticsReqVO; import com.cf.imes.module.system.dal.dataobject.funds.organamount.OrganAmountDO; import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Param; -import java.math.BigDecimal; +import java.util.List; @Mapper public interface OrganAmountMapper extends BaseMapperX { - - @Select("select sum(amount) from organ_amount where deleted = false") - BigDecimal selectAllOrganAmount(); - + /** + * 查询基于创建时间的组织收支趋势 + * + * @param reqVO + * @return + */ + List selectOrganIncomeExpenseTrendGroupByCreateTime(@Param("req") OrganFundsStatisticsReqVO reqVO, @Param("organId") Long organId); } diff --git a/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/funds/organamount/OrganAmountService.java b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/funds/organamount/OrganAmountService.java index 6e4646ad8..67d06e7e7 100644 --- a/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/funds/organamount/OrganAmountService.java +++ b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/funds/organamount/OrganAmountService.java @@ -3,10 +3,12 @@ package com.cf.imes.module.system.service.funds.organamount; import com.cf.imes.module.system.controller.admin.funds.organamount.vo.AllOrganAmountRespVO; import com.cf.imes.module.system.controller.admin.funds.organamount.vo.OrganAmountRespVO; +import com.cf.imes.module.system.controller.admin.funds.organamount.vo.OrganFundsStatisticsReqVO; import com.cf.imes.module.system.controller.admin.funds.organamount.vo.OrganRechargeAmountRespVO; import com.cf.imes.module.system.dal.dataobject.funds.organamount.OrganAmountDO; import java.math.BigDecimal; +import java.util.Map; /** * @author 资金管理接口 @@ -47,9 +49,24 @@ public interface OrganAmountService { */ OrganRechargeAmountRespVO refundProductOrganAmountBalanceAndGift(Long organId, BigDecimal balance, BigDecimal gift); - OrganAmountRespVO getOrganAmount(Long organId); - + /** + * 获取组织余额数据 + * + * @return + */ + OrganAmountRespVO getOrganAmount(); + /** + * 获取全部组织的余额数据 + * + * @return + */ AllOrganAmountRespVO getOrganAmountAll(); + /** + * 获取组织消费趋势 + * + * @return + */ + Map getOrganConsumptionTrend(OrganFundsStatisticsReqVO reqVO); } diff --git a/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/funds/organamount/OrganAmountServiceImpl.java b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/funds/organamount/OrganAmountServiceImpl.java index 8c0585762..1c28296aa 100644 --- a/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/funds/organamount/OrganAmountServiceImpl.java +++ b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/funds/organamount/OrganAmountServiceImpl.java @@ -1,18 +1,24 @@ package com.cf.imes.module.system.service.funds.organamount; - import cn.hutool.core.date.LocalDateTimeUtil; +import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.cf.imes.framework.common.exception.ServiceException; import com.cf.imes.framework.common.util.Assert.AssertUtils; import com.cf.imes.framework.common.util.object.BeanUtils; import com.cf.imes.framework.mybatis.core.query.LambdaUpdateWrapperX; -import com.cf.imes.module.executor.api.funds.ExecutorFundsApi; +import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils; +import com.cf.imes.module.executor.enums.OrderStatisticsUnit; +import com.cf.imes.module.system.controller.admin.funds.invoice.vo.InvoiceAmountRespVO; import com.cf.imes.module.system.controller.admin.funds.organamount.vo.AllOrganAmountRespVO; +import com.cf.imes.module.system.controller.admin.funds.organamount.vo.OrganAmountGroupByCreateTimeRespVO; import com.cf.imes.module.system.controller.admin.funds.organamount.vo.OrganAmountRespVO; +import com.cf.imes.module.system.controller.admin.funds.organamount.vo.OrganFundsStatisticsReqVO; import com.cf.imes.module.system.controller.admin.funds.organamount.vo.OrganRechargeAmountRespVO; +import com.cf.imes.module.system.service.funds.invoice.InvoiceService; import com.cf.imes.module.system.service.funds.purchase.PurchaseService; import com.cf.imes.module.system.controller.admin.funds.purchase.vo.OrgEarliestPurchaseProductRespVO; import com.cf.imes.module.system.dal.dataobject.funds.organamount.OrganAmountDO; @@ -26,6 +32,16 @@ import org.springframework.stereotype.Service; import jakarta.annotation.Resource; import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.temporal.TemporalAdjusters; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; import static cn.hutool.core.date.DatePattern.NORM_DATETIME_FORMATTER; import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -48,11 +64,17 @@ public class OrganAmountServiceImpl implements OrganAmountService { private OrganService organService; @Resource - private ExecutorFundsApi executorFundsApi; + private InvoiceService invoiceService; @Resource private PurchaseService purchaseService; + // 常用的字段key + private static final String DATELIST_FIELD_NAME = "dateList"; + private static final String SERIES_FIELD_NAME = "series"; + private static final String DATE_TIME_FORMATTER_PATTERN_YEAR_MONTH = "yyyy-M"; + private static final String DATE_TIME_FORMATTER_PATTERN_YEAR_MONTH_DAY = "yyyy-M-d"; + @Override public OrganAmountDO validOrganAmount(Long organId) { OrganAmountDO organAmountDO = organAmountMapper.selectOne(new LambdaQueryWrapper().eq(OrganAmountDO::getOrganId, organId)); @@ -147,7 +169,9 @@ public class OrganAmountServiceImpl implements OrganAmountService { } @Override - public OrganAmountRespVO getOrganAmount(Long organId) { + public OrganAmountRespVO getOrganAmount() { + + Long organId = SecurityFrameworkUtils.getUserOrganId(); organService.validOrgan(organId); @@ -182,16 +206,240 @@ public class OrganAmountServiceImpl implements OrganAmountService { AllOrganAmountRespVO respVO = new AllOrganAmountRespVO(); - BigDecimal allOrganAmount = organAmountMapper.selectAllOrganAmount(); - - BigDecimal examineAmount = executorFundsApi.getToExamineAmount().getCheckedData(); + // 所有账户的总额 + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.select("sum(amount) as total"); + Map result = organAmountMapper.selectMaps(wrapper).get(0); + BigDecimal allOrganAmount = (BigDecimal) result.get("total"); + // 管理端查看可开票金额 + InvoiceAmountRespVO invoiceAmount = invoiceService.getManageInvoiceAmount(); respVO.setAllOrganAmount(allOrganAmount); - respVO.setToExamineAmount(examineAmount); + respVO.setToExamineAmount(invoiceAmount.getPendingInvoice()); return respVO; } + @Override + public Map getOrganConsumptionTrend(OrganFundsStatisticsReqVO reqVO) { + Map resultMap = new HashMap<>(); + // 所有的日期集合 + List dateList = getDateList(reqVO); + Long organId = SecurityFrameworkUtils.getUserOrganId(); + List> series = new ArrayList<>(); + Map orgAmountSeriesItem = new HashMap<>(); + + // 查询组织收支趋势统计 + Map> organIncomeExpenseGroupByCreateTimeRespMap = organAmountMapper.selectOrganIncomeExpenseTrendGroupByCreateTime(reqVO, organId).stream() + .sorted(Comparator.naturalOrder()) + .collect(Collectors.groupingBy(OrganAmountGroupByCreateTimeRespVO::getDate, LinkedHashMap::new, Collectors.toList())); + + BigDecimal[] amountArr = new BigDecimal[dateList.size()]; + // 遍历时间跨度列表,匹配数量存入数组,没有补0存入数组 + for (int i = 0; i < dateList.size(); i++) { + String dateStr = dateList.get(i); + + List organIncomeExpenseGroupByCreateTimeRespVOS = organIncomeExpenseGroupByCreateTimeRespMap.get(dateStr); + amountArr[i] = organIncomeExpenseGroupByCreateTimeRespVOS != null && !organIncomeExpenseGroupByCreateTimeRespVOS.isEmpty() ? organIncomeExpenseGroupByCreateTimeRespVOS.get(0).getAmount() : BigDecimal.ZERO; + } + + orgAmountSeriesItem.put("data", amountArr); + orgAmountSeriesItem.put("name", "收支金额"); + series.add(orgAmountSeriesItem); + + // x轴时间区间字符串 + resultMap.put(DATELIST_FIELD_NAME, dateList.stream().map(date -> generateDateRangeAxis(date, reqVO.getUnit())).toList()); + // 类别:类别:平方数数组 + resultMap.put(SERIES_FIELD_NAME, series); + + return resultMap; + } + + /** + * 获取日期区间格式下的所有日期字符串 + * 1、reqVO设置机构id + * 2、计算时间跨度设置到reqVO + * 3、返回所有日期的集合 + * @param reqVO + * @return + */ + private List getDateList(OrganFundsStatisticsReqVO reqVO) { + // 计算时间跨度 + getTimeSpan(reqVO); + + // 重新计算开始时间喝结束时间 + countTimeSpan(reqVO); + + // 所有的日期集合 + return generateDateRange(reqVO); + } + + /** + * 获取统计的时间跨度 + * 计算起止时间:前端不传入时间就根据维度单位从当前日期计算 + * + * @param reqVO + */ + private void getTimeSpan(OrganFundsStatisticsReqVO reqVO) { + LocalDate[] createTime = reqVO.getCreateTime(); + LocalDate startTime = null; + LocalDate endTime; + LocalDate now = LocalDate.now(); + if (ArrayUtil.isEmpty(createTime) || ObjectUtil.isNull(createTime[0]) || ObjectUtil.isNull(createTime[1])) { + endTime = now; + switch (OrderStatisticsUnit.fromValue(reqVO.getUnit())) { + case QUARTER: + // 从now往前的1年 + startTime = now.minusYears(1); + break; + case MONTH: + // 包含now往前的12个月 + startTime = now.minusMonths(11); + break; + case WEEK: + // 包含now往前的12周 + startTime = now.minusWeeks(11); + break; + case DAY: + // 包含now往前的15天 + startTime = now.minusDays(14); + break; + default: + break; + } + // 声明一个LocalDateTime的数组,把startTime和endTime放进去 + reqVO.setCreateTime(new LocalDate[]{startTime, endTime}); + } + } + + /** + * 根据传入信息重新计算时间范围 + * + * @param reqVO + */ + private void countTimeSpan(OrganFundsStatisticsReqVO reqVO) { + Integer unit = reqVO.getUnit(); + // 计算时间跨度 + getTimeSpan(reqVO); + // 计算后的开始和结束时间 + LocalDate startDate = ObjectUtil.clone(reqVO.getCreateTime()[0]); + LocalDate endDate = ObjectUtil.clone(reqVO.getCreateTime()[1]); + + if (startDate.isAfter(endDate)) { + startDate = ObjectUtil.clone(reqVO.getCreateTime()[1]); + endDate = ObjectUtil.clone(reqVO.getCreateTime()[0]); + } + LocalDate first = startDate; + LocalDate end = endDate; + switch (OrderStatisticsUnit.fromValue(unit)) { + case QUARTER -> { + first = firstDayOfQuarter(startDate); + end = lastDayOfQuarter(endDate); + } + case MONTH -> { + first = startDate.with(TemporalAdjusters.firstDayOfMonth()); + end = endDate.with(TemporalAdjusters.lastDayOfMonth()); + } + case WEEK -> { + first = startDate.with(TemporalAdjusters.previousOrSame(java.time.DayOfWeek.MONDAY)); + end = endDate.with(TemporalAdjusters.nextOrSame(java.time.DayOfWeek.SUNDAY)); + } + default -> { + return; + } + } + reqVO.setCreateTime(new LocalDate[]{first, end}); + } + + private LocalDate firstDayOfQuarter(LocalDate date) { + int month = date.getMonthValue(); + int quarter = (month - 1) / 3 + 1; + int startMonth = (quarter - 1) * 3 + 1; + return LocalDate.of(date.getYear(), startMonth, 1); + } + + private LocalDate lastDayOfQuarter(LocalDate date) { + int month = date.getMonthValue(); + int quarter = (month - 1) / 3 + 1; + int endMonth = (quarter - 1) * 3 + 3; + return LocalDate.of(date.getYear(), endMonth, 1).with(TemporalAdjusters.lastDayOfMonth()); + } + + /** + * 获取日期范围内的所有格式字符串 + * + * @param reqVO + * @return + */ + private List generateDateRange(OrganFundsStatisticsReqVO reqVO) { + Integer unit = reqVO.getUnit(); + // 计算时间跨度 + getTimeSpan(reqVO); + // 计算后的开始和结束时间 + LocalDate startDate = ObjectUtil.clone(reqVO.getCreateTime()[0]); + LocalDate endDate = ObjectUtil.clone(reqVO.getCreateTime()[1]); + + List dates = new ArrayList<>(); + while (!startDate.isAfter(endDate)) { + String dateStr; + switch (OrderStatisticsUnit.fromValue(unit)) { + case QUARTER: + dateStr = startDate.format(DateTimeFormatter.ofPattern("yyyy-Q")); + // 加一季度(3个月) + startDate = startDate.plusMonths(3); + break; + case MONTH: + dateStr = startDate.format(DateTimeFormatter.ofPattern(DATE_TIME_FORMATTER_PATTERN_YEAR_MONTH)); + // 加一月 + startDate = startDate.plusMonths(1); + break; + case WEEK: + dateStr = startDate.format(DateTimeFormatter.ofPattern("yyyy-M-ww")); + // 加一周 + startDate = startDate.plusWeeks(1); + break; + case DAY: + dateStr = startDate.format(DateTimeFormatter.ofPattern(DATE_TIME_FORMATTER_PATTERN_YEAR_MONTH_DAY)); + // 加一天 + startDate = startDate.plusDays(1); + break; + default: + throw new IllegalArgumentException("Unsupported unit: " + unit); + } + dates.add(dateStr); + } + return dates; + } + + /** + * 构建日期格式到图标横轴可用格式 + * 2024-1 -> 2024年第1季度 + * 2024-1-1 -> 2024年1月 + * ... + * @param unit + * @return + */ + private String generateDateRangeAxis(String date, Integer unit) { + OrderStatisticsUnit orderStatisticsUnit = OrderStatisticsUnit.fromValue(unit); + StringBuilder newDateStrBuffer = new StringBuilder(); + String[] dateSplit = date.split("-"); + switch (orderStatisticsUnit) { + case QUARTER: + newDateStrBuffer.append("第").append(dateSplit[1]).append("季度"); + break; + case MONTH: + newDateStrBuffer.append(dateSplit[1]).append("月"); + break; + case WEEK: + newDateStrBuffer.append("第").append(dateSplit[2]).append("周"); + break; + case DAY: + newDateStrBuffer.append(dateSplit[2]).append("日"); + break; + default: + } + return newDateStrBuffer.toString(); + } } diff --git a/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/validation/pay/FundsStatisticsUnitInEnum.java b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/validation/pay/FundsStatisticsUnitInEnum.java new file mode 100644 index 000000000..a61d363bd --- /dev/null +++ b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/validation/pay/FundsStatisticsUnitInEnum.java @@ -0,0 +1,37 @@ +package com.cf.imes.module.system.validation.pay; + +import jakarta.validation.Constraint; +import jakarta.validation.Payload; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 资金统计维度单位入参校验注解 + * + * @author Gqr + * @since 2024/7/17 9:33 + */ +@Target({ + ElementType.METHOD, + ElementType.FIELD, + ElementType.ANNOTATION_TYPE, + ElementType.CONSTRUCTOR, + ElementType.PARAMETER, + ElementType.TYPE_USE +}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Constraint( + validatedBy = {FundsStatisticsUnitInEnumValidator.class} +) +public @interface FundsStatisticsUnitInEnum { + String message() default "资金账户统计维度单位[unit]错误,请检查"; + + Class[] groups() default {}; + + Class[] payload() default {}; +} diff --git a/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/validation/pay/FundsStatisticsUnitInEnumValidator.java b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/validation/pay/FundsStatisticsUnitInEnumValidator.java new file mode 100644 index 000000000..5a902f26c --- /dev/null +++ b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/validation/pay/FundsStatisticsUnitInEnumValidator.java @@ -0,0 +1,35 @@ +package com.cf.imes.module.system.validation.pay; + +import cn.hutool.core.util.ObjectUtil; +import com.cf.imes.module.executor.enums.OrderStatisticsUnit; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; + +/** + * 资金统计维度单位入参校验器 + * + * @author Gqr + * @since 2024/7/17 9:33 + */ +public class FundsStatisticsUnitInEnumValidator implements ConstraintValidator { + + @Override + public void initialize(FundsStatisticsUnitInEnum constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + } + + @Override + public boolean isValid(Integer value, ConstraintValidatorContext context) { + if (ObjectUtil.isNull(value)) { + return true; + } + OrderStatisticsUnit unit = OrderStatisticsUnit.fromValue(value); + if (ObjectUtil.isNotNull(unit)) { + return true; + } else { + return false; + } + } + +} + diff --git a/cf-module-system/cf-module-system-biz/src/main/resources/mapper/funds/amount/OrganAmountMapper.xml b/cf-module-system/cf-module-system-biz/src/main/resources/mapper/funds/amount/OrganAmountMapper.xml new file mode 100644 index 000000000..52b9a0f21 --- /dev/null +++ b/cf-module-system/cf-module-system-biz/src/main/resources/mapper/funds/amount/OrganAmountMapper.xml @@ -0,0 +1,29 @@ + + + + + + ,CONCAT(YEAR(create_time), '-', QUARTER(create_time)) as date + + + ,CONCAT(YEAR(create_time), '-', MONTH(create_time)) as date + + + ,CONCAT(YEAR(create_time), '-', MONTH(create_time), '-', WEEK(create_time, 1)) AS date + + + ,CONCAT(YEAR(create_time), '-', MONTH(create_time), '-', DAY(create_time)) as date + + + + + + \ No newline at end of file