From a9b169b1d0f4752f56db1e5f7a16ac96e48dd2cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A2=A8=E5=A4=A7=E5=8F=94?= <494979559@qq.com> Date: Sat, 7 Sep 2024 16:43:49 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=8A=A5=E8=A1=A8=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smart-switch-common/pom.xml | 5 ++ .../com/ruoyi/common/utils/DateUtils.java | 21 +++++- .../utils/collection/CollectionUtils.java | 44 ++++++++++++ .../com/ruoyi/dashboard/DashboardService.java | 70 +++++++++++++++++++ .../service/SmBalancePeriodServiceImpl.java | 2 +- .../domain/SmBusinessRecord.java | 12 ++++ .../mapper/SmBusinessRecordMapper.xml | 25 +++++-- .../service/ISmBusinessRecordService.java | 2 +- .../service/SmBusinessRecordServiceImpl.java | 35 +++++----- .../ss/dashboard/ServiceIncomeQuery.java | 24 +++++++ .../ss/dashboard/{ => vo}/BillCountVo.java | 2 +- .../ruoyi/ss/dashboard/{ => vo}/BriefVo.java | 9 ++- .../ss/dashboard/vo/ServiceIncomeVO.java | 28 ++++++++ .../ss/dashboard/{ => vo}/SmUserCountVo.java | 2 +- .../service/impl/DeviceAssemblerImpl.java | 7 +- .../receiveBill/domain/ReceiveBillQuery.java | 11 ++- .../domain/enums/ReceiveBillGroupBy.java | 9 +++ .../domain/vo/ReceiveAmountVO.java | 18 +++++ .../receiveBill/mapper/ReceiveBillMapper.java | 3 + .../receiveBill/mapper/ReceiveBillMapper.xml | 29 ++++++++ .../service/ReceiveBillService.java | 3 + .../service/impl/ReceiveBillServiceImpl.java | 7 ++ .../service/impl/StoreAssemblerImpl.java | 2 +- .../domain/TransactionBillQuery.java | 4 +- .../domain/enums/TransactionBillStatus.java | 7 ++ .../domain/vo/TransactionAmountVO.java | 19 +++++ .../mapper/TransactionBillMapper.java | 8 ++- .../mapper/TransactionBillMapper.xml | 29 +++++++- .../service/TransactionBillService.java | 7 +- .../impl/TransactionBillServiceImpl.java | 17 +++-- .../app/AppTransactionBillController.java | 9 +-- .../controller/ss/SmDashboardController.java | 13 +++- 32 files changed, 430 insertions(+), 53 deletions(-) create mode 100644 smart-switch-service/src/main/java/com/ruoyi/ss/dashboard/ServiceIncomeQuery.java rename smart-switch-service/src/main/java/com/ruoyi/ss/dashboard/{ => vo}/BillCountVo.java (98%) rename smart-switch-service/src/main/java/com/ruoyi/ss/dashboard/{ => vo}/BriefVo.java (75%) create mode 100644 smart-switch-service/src/main/java/com/ruoyi/ss/dashboard/vo/ServiceIncomeVO.java rename smart-switch-service/src/main/java/com/ruoyi/ss/dashboard/{ => vo}/SmUserCountVo.java (76%) create mode 100644 smart-switch-service/src/main/java/com/ruoyi/ss/receiveBill/domain/enums/ReceiveBillGroupBy.java create mode 100644 smart-switch-service/src/main/java/com/ruoyi/ss/receiveBill/domain/vo/ReceiveAmountVO.java create mode 100644 smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/vo/TransactionAmountVO.java diff --git a/smart-switch-ruoyi/smart-switch-common/pom.xml b/smart-switch-ruoyi/smart-switch-common/pom.xml index e74e04b4..8d1443c2 100644 --- a/smart-switch-ruoyi/smart-switch-common/pom.xml +++ b/smart-switch-ruoyi/smart-switch-common/pom.xml @@ -16,6 +16,11 @@ + + org.mybatis + mybatis-typehandlers-jsr310 + 1.0.0 + diff --git a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/utils/DateUtils.java b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/utils/DateUtils.java index e47b696d..9026ed27 100644 --- a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/utils/DateUtils.java +++ b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/utils/DateUtils.java @@ -221,6 +221,21 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils return format(date, YYYY_MM_DD); } + public static String getYYYY_MM_DD(LocalDate localDate) { + return format(localDate, YYYY_MM_DD); + } + + private static String format(Date date, String format) { + return org.apache.commons.lang3.time.DateFormatUtils.format(date, format); + } + + private static String format(LocalDate localDate, String format) { + if (localDate == null) { + return null; + } + DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format); + return localDate.format(formatter); + } public static Integer getYear(Date date) { Calendar c = Calendar.getInstance(); c.setTime(date); @@ -263,7 +278,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils * @param year 年 * @param month 月 */ - public static Date getMonthFirstDate(Integer year, Integer month) { + public static Date getMonthFirstDate(int year, int month) { Date firstDay = new Date(); firstDay.setYear(year - 1900); firstDay.setMonth(month - 1); @@ -288,4 +303,8 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils OffsetDateTime dateTime = OffsetDateTime.parse(str, formatter); return Date.from(dateTime.toInstant()); } + + public static LocalDate toLocalDate(Date date) { + return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + } } diff --git a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/utils/collection/CollectionUtils.java b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/utils/collection/CollectionUtils.java index 872c918d..6a4f2698 100644 --- a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/utils/collection/CollectionUtils.java +++ b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/utils/collection/CollectionUtils.java @@ -3,6 +3,7 @@ package com.ruoyi.common.utils.collection; import com.ruoyi.common.utils.DateUtils; import java.math.BigDecimal; +import java.time.LocalDate; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @@ -125,4 +126,47 @@ public class CollectionUtils extends org.springframework.util.CollectionUtils { } return true; } + + + /** + * 填充空值 + * @param list 原始列表 + * @param getDateFunction 获取日期的方法 + * @param function 获取填充物的方法 + * @param start 起始日期 + * @param end 结束日期 + * @return 填充后的列表 + */ + public static List fillVoids(List list, Function getDateFunction, Function function, LocalDate start, LocalDate end) { + // 输入验证 + if (start.isAfter(end)) { + throw new IllegalArgumentException("起始日期必须早于结束日期"); + } + + // 使用Map优化查找性能 + Map fillAbleMap = new HashMap<>(); + for (T item : list) { + fillAbleMap.put(DateUtils.getYYYY_MM_DD(getDateFunction.apply(item)), item); + } + + // 构建结果列表,并确保线程安全 + List result = Collections.synchronizedList(new ArrayList<>()); + LocalDate current = start; + while (!current.isAfter(end)) { + T currentItem = fillAbleMap.get(DateUtils.getYYYY_MM_DD(current)); + if (currentItem == null) { + try { + currentItem = function.apply(current); + } catch (Exception e) { + // 异常处理逻辑,例如记录日志或抛出自定义异常 + System.err.println("处理日期 " + current + " 时发生异常: " + e.getMessage()); + } + } + if (currentItem != null) { + result.add(currentItem); + } + current = current.plusDays(1); + } + return result; + } } diff --git a/smart-switch-service/src/main/java/com/ruoyi/dashboard/DashboardService.java b/smart-switch-service/src/main/java/com/ruoyi/dashboard/DashboardService.java index 91d65ed0..ea116581 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/dashboard/DashboardService.java +++ b/smart-switch-service/src/main/java/com/ruoyi/dashboard/DashboardService.java @@ -1,26 +1,42 @@ package com.ruoyi.dashboard; +import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.common.utils.collection.CollectionUtils; import com.ruoyi.dashboard.vo.TodoListVO; import com.ruoyi.ss.abnormal.domain.AbnormalQuery; import com.ruoyi.ss.abnormal.domain.enums.AbnormalStatus; import com.ruoyi.ss.abnormal.service.AbnormalService; import com.ruoyi.ss.complaint.domain.SmComplaintQuery; import com.ruoyi.ss.complaint.service.ISmComplaintService; +import com.ruoyi.ss.dashboard.ServiceIncomeQuery; +import com.ruoyi.ss.dashboard.vo.ServiceIncomeVO; import com.ruoyi.ss.device.domain.DeviceQuery; import com.ruoyi.ss.device.service.DeviceService; import com.ruoyi.ss.mchApply.domain.MchApplyQuery; import com.ruoyi.ss.mchApply.domain.enums.MchApplyStatus; import com.ruoyi.ss.mchApply.service.IMchApplyService; +import com.ruoyi.ss.receiveBill.domain.ReceiveBillQuery; +import com.ruoyi.ss.receiveBill.domain.enums.ReceiveBillGroupBy; +import com.ruoyi.ss.receiveBill.domain.vo.ReceiveAmountVO; +import com.ruoyi.ss.receiveBill.service.ReceiveBillService; import com.ruoyi.ss.storeApply.domain.StoreApplyQuery; import com.ruoyi.ss.storeApply.domain.enums.StoreApplyStatus; import com.ruoyi.ss.storeApply.service.StoreApplyService; import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery; +import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillGroupBy; import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillStatus; import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillType; +import com.ruoyi.ss.transactionBill.domain.vo.TransactionAmountVO; import com.ruoyi.ss.transactionBill.service.TransactionBillService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.math.BigDecimal; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + /** * @author wjh * 2024/8/6 @@ -46,6 +62,9 @@ public class DashboardService { @Autowired private StoreApplyService storeApplyService; + @Autowired + private ReceiveBillService receiveBillService; + public TodoListVO getTodoList() { TodoListVO vo = new TodoListVO(); @@ -80,4 +99,55 @@ public class DashboardService { return vo; } + + public List getServiceIncome(ServiceIncomeQuery query) { + + // 查询订单 + TransactionBillQuery billQuery = new TransactionBillQuery(); + billQuery.setStartDate(query.getStartDate()); + billQuery.setEndDate(query.getEndDate()); + billQuery.setStatusList(TransactionBillStatus.payedOrder()); + List> amountList = transactionBillService.selectCommonSumOfMoney(billQuery, TransactionBillGroupBy.create_date.name()); + + // 查询月费收入 + ReceiveBillQuery receiveQuery = new ReceiveBillQuery(); + receiveQuery.setStartDate(query.getStartDate()); + receiveQuery.setEndDate(query.getEndDate()); + List> receiveList = receiveBillService.selectCommonSumOfAmount(receiveQuery, ReceiveBillGroupBy.create_date.name()); + + // 拼接结果集 + List result = new ArrayList<>(); + if (query.getStartDate() != null && query.getEndDate() != null) { + result = CollectionUtils.fillVoids(result, ServiceIncomeVO::getDate, (date) -> { + ServiceIncomeVO vo = new ServiceIncomeVO(); + vo.setDate(date); + + // 订单服务费收入及成本 + TransactionAmountVO transaction = amountList.stream() + .filter(item -> item.getKey().compareTo(DateUtils.toDate(date)) == 0) + .findFirst().orElse(null); + if (transaction != null) { + vo.setServiceAmount(transaction.getServiceAmount()); + vo.setChannelCost(transaction.getChannelCost()); + } else { + vo.setServiceAmount(BigDecimal.ZERO); + vo.setChannelCost(BigDecimal.ZERO); + } + + // 月费收入 + ReceiveAmountVO receive = receiveList.stream() + .filter(item -> item.getKey().compareTo(DateUtils.toDate(date)) == 0) + .findFirst() + .orElse(null); + if (receive != null) { + vo.setMonthAmount(receive.getReceivedAmount()); + } else { + vo.setMonthAmount(BigDecimal.ZERO); + } + + return vo; + }, query.getStartDate(), query.getEndDate()); + } + return result; + } } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/balancePeriod/service/SmBalancePeriodServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/balancePeriod/service/SmBalancePeriodServiceImpl.java index 0370dd91..6413d90d 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/balancePeriod/service/SmBalancePeriodServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/balancePeriod/service/SmBalancePeriodServiceImpl.java @@ -4,7 +4,7 @@ import com.ruoyi.common.utils.DateUtils; import com.ruoyi.ss.balancePeriod.domain.SmBalancePeriod; import com.ruoyi.ss.balancePeriod.domain.SmBalancePeriodQuery; import com.ruoyi.ss.balancePeriod.mapper.SmBalancePeriodMapper; -import com.ruoyi.ss.dashboard.BillCountVo; +import com.ruoyi.ss.dashboard.vo.BillCountVo; import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery; import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillGroupBy; import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillStatus; diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/businessRecord/domain/SmBusinessRecord.java b/smart-switch-service/src/main/java/com/ruoyi/ss/businessRecord/domain/SmBusinessRecord.java index c8062b5c..e16a1cb2 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/businessRecord/domain/SmBusinessRecord.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/businessRecord/domain/SmBusinessRecord.java @@ -53,4 +53,16 @@ public class SmBusinessRecord extends BaseEntity @ApiModelProperty("用户总余额") private BigDecimal userBalance; + + @Excel(name = "今日订单总数") + @ApiModelProperty("今日订单总数") + private Integer todayRechargeCount; + + @Excel(name = "今日订单金额") + @ApiModelProperty("今日订单金额") + private BigDecimal todayRechargeAmount; + + @Excel(name = "设备总数") + @ApiModelProperty("设备总数") + private Integer deviceCount; } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/businessRecord/mapper/SmBusinessRecordMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/businessRecord/mapper/SmBusinessRecordMapper.xml index 426f87ca..d36dc062 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/businessRecord/mapper/SmBusinessRecordMapper.xml +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/businessRecord/mapper/SmBusinessRecordMapper.xml @@ -13,6 +13,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + @@ -26,7 +29,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" sbr.total_recharge, sbr.recharge_count, sbr.total_month, - sbr.user_balance + sbr.user_balance, + sbr.today_recharge_count, + sbr.today_recharge_amount, + device_count from sm_business_record sbr @@ -47,7 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -73,6 +79,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + + + SELECT LAST_INSERT_ID() diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/receiveBill/service/ReceiveBillService.java b/smart-switch-service/src/main/java/com/ruoyi/ss/receiveBill/service/ReceiveBillService.java index 9e612a79..b7515a5d 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/receiveBill/service/ReceiveBillService.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/receiveBill/service/ReceiveBillService.java @@ -6,6 +6,7 @@ import java.util.List; import com.ruoyi.ss.receiveBill.domain.ReceiveBill; import com.ruoyi.ss.receiveBill.domain.ReceiveBillVO; import com.ruoyi.ss.receiveBill.domain.ReceiveBillQuery; +import com.ruoyi.ss.receiveBill.domain.vo.ReceiveAmountVO; import com.ruoyi.ss.transactionBill.domain.dto.RechargePayBO; /** @@ -81,4 +82,6 @@ public interface ReceiveBillService * 查询账单金额总额 */ BigDecimal selectSumOfAmount(ReceiveBillQuery query); + + List> selectCommonSumOfAmount(ReceiveBillQuery receiveQuery, String groupBy); } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/receiveBill/service/impl/ReceiveBillServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/receiveBill/service/impl/ReceiveBillServiceImpl.java index 2d60a0c7..23d1f114 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/receiveBill/service/impl/ReceiveBillServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/receiveBill/service/impl/ReceiveBillServiceImpl.java @@ -2,6 +2,7 @@ package com.ruoyi.ss.receiveBill.service.impl; import java.math.BigDecimal; import java.time.LocalDateTime; +import java.util.Collections; import java.util.List; import java.util.concurrent.TimeUnit; @@ -11,6 +12,7 @@ import com.ruoyi.ss.device.domain.vo.DeviceVO; import com.ruoyi.ss.device.service.DeviceService; import com.ruoyi.ss.receiveBill.domain.enums.ReceiveBillStatus; import com.ruoyi.ss.receiveBill.domain.enums.ReceiveBillType; +import com.ruoyi.ss.receiveBill.domain.vo.ReceiveAmountVO; import com.ruoyi.ss.recordBalance.domain.enums.RecordBalanceBstType; import com.ruoyi.ss.transactionBill.domain.TransactionBill; import com.ruoyi.ss.transactionBill.domain.dto.RechargePayBO; @@ -179,4 +181,9 @@ public class ReceiveBillServiceImpl implements ReceiveBillService return receiveBillMapper.selectSumOfAmount(query); } + @Override + public List> selectCommonSumOfAmount(ReceiveBillQuery query, String groupBy) { + return receiveBillMapper.selectCommonSumOfAmount(query, groupBy); + } + } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/store/service/impl/StoreAssemblerImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/store/service/impl/StoreAssemblerImpl.java index 23b066ac..f243b96e 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/store/service/impl/StoreAssemblerImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/store/service/impl/StoreAssemblerImpl.java @@ -2,7 +2,7 @@ package com.ruoyi.ss.store.service.impl; import com.ruoyi.common.utils.collection.CollectionUtils; import com.ruoyi.common.utils.DateUtils; -import com.ruoyi.ss.dashboard.BillCountVo; +import com.ruoyi.ss.dashboard.vo.BillCountVo; import com.ruoyi.ss.device.domain.DeviceCountVO; import com.ruoyi.ss.device.domain.DeviceQuery; import com.ruoyi.ss.device.domain.enums.DeviceGroupBy; diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/TransactionBillQuery.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/TransactionBillQuery.java index 5b4334a4..4debcc45 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/TransactionBillQuery.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/TransactionBillQuery.java @@ -57,10 +57,10 @@ public class TransactionBillQuery extends TransactionBill { private Boolean expire; @DateTimeFormat(pattern = "yyyy-MM-dd") - private Date startDate; + private LocalDate startDate; @DateTimeFormat(pattern = "yyyy-MM-dd") - private Date endDate; + private LocalDate endDate; @ApiModelProperty("订单id列表") private List billIds; diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/enums/TransactionBillStatus.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/enums/TransactionBillStatus.java index 086736b0..d7e34c12 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/enums/TransactionBillStatus.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/enums/TransactionBillStatus.java @@ -71,4 +71,11 @@ public enum TransactionBillStatus { public static List canClose() { return asList(SUCCESS, SUCCESS_DEPOSIT); } + + /** + * 已支付过的订单状态 + */ + public static List payedOrder() { + return asList(SUCCESS, REFUNDED, REFUNDING); + } } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/vo/TransactionAmountVO.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/vo/TransactionAmountVO.java new file mode 100644 index 00000000..b405aef0 --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/vo/TransactionAmountVO.java @@ -0,0 +1,19 @@ +package com.ruoyi.ss.transactionBill.domain.vo; + +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @author wjh + * 2024/9/7 + */ +@Data +public class TransactionAmountVO { + private T key; // 分组依据 + + private BigDecimal money; // 订单金额 + private BigDecimal serviceAmount; // 服务费 + private BigDecimal arrivalAmount; // 到账金额 + private BigDecimal channelCost; // 渠道成本 +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.java index 9e5bda4a..74d3d6d0 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.java @@ -1,8 +1,9 @@ package com.ruoyi.ss.transactionBill.mapper; -import com.ruoyi.ss.dashboard.BillCountVo; +import com.ruoyi.ss.dashboard.vo.BillCountVo; import com.ruoyi.ss.transactionBill.domain.TransactionBill; import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery; +import com.ruoyi.ss.transactionBill.domain.vo.TransactionAmountVO; import com.ruoyi.ss.transactionBill.domain.vo.TransactionBillVO; import org.apache.ibatis.annotations.Param; @@ -191,4 +192,9 @@ public interface TransactionBillMapper * @return */ BigDecimal selectSumOfMoney(@Param("query") TransactionBillQuery query); + + /** + * 查询金额统计 + */ + List> selectCommonSumOfMoney(@Param("query") TransactionBillQuery query, @Param("groupBy") String groupBy); } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.xml index 654342e7..992c83b1 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.xml +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.xml @@ -245,7 +245,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where stb.bill_id = #{billId} - + @@ -337,6 +337,33 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + + + + + insert into sm_transaction_bill diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/TransactionBillService.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/TransactionBillService.java index 12e1aa81..c12374b3 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/TransactionBillService.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/TransactionBillService.java @@ -1,12 +1,13 @@ package com.ruoyi.ss.transactionBill.service; -import com.ruoyi.ss.dashboard.BillCountVo; +import com.ruoyi.ss.dashboard.vo.BillCountVo; import com.ruoyi.ss.device.domain.vo.DeviceVO; import com.ruoyi.ss.payBill.domain.vo.DoPayVO; import com.ruoyi.ss.transactionBill.domain.TransactionBill; import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery; import com.ruoyi.ss.transactionBill.domain.bo.*; import com.ruoyi.ss.transactionBill.domain.dto.RechargePayBO; +import com.ruoyi.ss.transactionBill.domain.vo.TransactionAmountVO; import com.ruoyi.ss.transactionBill.domain.vo.TransactionBillVO; import com.ruoyi.ss.transactionBill.domain.dto.BillRefundDTO; import com.ruoyi.ss.transactionBill.domain.dto.WithdrawApprovalDTO; @@ -281,4 +282,8 @@ public interface TransactionBillService */ int endUse(EndUseBO bo, boolean withDevice); + /** + * 查询所有关于金额的总和 + */ + List> selectCommonSumOfMoney(TransactionBillQuery query, String groupBy); } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java index 4c4bfe6d..678fb5bf 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java @@ -13,7 +13,7 @@ import com.ruoyi.ss.account.domain.AccountVO; import com.ruoyi.ss.channel.domain.ChannelVO; import com.ruoyi.ss.channelWithdraw.domain.ChannelWithdrawVO; import com.ruoyi.ss.channelWithdraw.service.ChannelWithdrawService; -import com.ruoyi.ss.dashboard.BillCountVo; +import com.ruoyi.ss.dashboard.vo.BillCountVo; import com.ruoyi.ss.device.domain.enums.DeviceOnlineStatus; import com.ruoyi.ss.device.domain.vo.DeviceVO; import com.ruoyi.ss.device.service.DeviceService; @@ -39,6 +39,7 @@ import com.ruoyi.ss.transactionBill.domain.TransactionBill; import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery; import com.ruoyi.ss.transactionBill.domain.bo.*; import com.ruoyi.ss.transactionBill.domain.dto.*; +import com.ruoyi.ss.transactionBill.domain.vo.TransactionAmountVO; import com.ruoyi.ss.transactionBill.domain.vo.TransactionBillVO; import com.ruoyi.ss.transactionBill.domain.vo.UserRechargeServiceVO; import com.ruoyi.ss.transactionBill.domain.vo.UserWithdrawServiceVO; @@ -68,6 +69,7 @@ import org.springframework.transaction.support.TransactionTemplate; import java.math.BigDecimal; import java.math.RoundingMode; import java.time.Duration; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.*; import java.util.concurrent.ScheduledExecutorService; @@ -648,9 +650,9 @@ public class TransactionBillServiceImpl implements TransactionBillService, After // 若startDate与endDate不为空,则将其中间数据补全,不让其为空 if (dto.getStartDate() != null && dto.getEndDate() != null && Objects.equals(dto.getGroupBy(), TransactionBillGroupBy.create_date.name())) { List newList = new ArrayList<>(); - Date i = dto.getStartDate(); - while (i.compareTo(dto.getEndDate()) <= 0) { - Date finalI = i; + LocalDate i = dto.getStartDate(); + while (i.isBefore(dto.getEndDate())) { + Date finalI = DateUtils.toDate(i); BillCountVo count = list.stream().filter(item -> DateUtils.getYYYY_MM_DD(item.getCreateDate()).equals(DateUtils.getYYYY_MM_DD(finalI))).findFirst().orElse(null); if (count == null) { count = new BillCountVo(); @@ -664,7 +666,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After count.setCreateYearMonth(DateUtils.getYYYY_MM(finalI)); } newList.add(count); - i = DateUtils.addDays(i,1); + i = i.plusDays(1); } // 列表排序 @@ -1558,6 +1560,11 @@ public class TransactionBillServiceImpl implements TransactionBillService, After return 0; } + @Override + public List> selectCommonSumOfMoney(TransactionBillQuery query, String groupBy) { + return transactionBillMapper.selectCommonSumOfMoney(query, groupBy); + } + @Override public UserWithdrawServiceVO getUserWithdrawService(Long userId, Long channelId) { SmUserVo user = userService.selectSmUserByUserId(userId); diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppTransactionBillController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppTransactionBillController.java index 7ee7708f..e8918461 100644 --- a/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppTransactionBillController.java +++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppTransactionBillController.java @@ -9,7 +9,7 @@ import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.ServiceUtil; -import com.ruoyi.ss.dashboard.BillCountVo; +import com.ruoyi.ss.dashboard.vo.BillCountVo; import com.ruoyi.ss.device.service.DeviceValidator; import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery; import com.ruoyi.ss.transactionBill.domain.bo.EndUseBO; @@ -31,6 +31,7 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.math.BigDecimal; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.Collections; import java.util.Date; @@ -149,15 +150,15 @@ public class AppTransactionBillController extends BaseController @JsonView(JsonViewProfile.AppMch.class) @GetMapping("/landlordCount") public AjaxResult landlordCount(@Validated({ValidGroup.Query.class}) TransactionBillQuery dto) { - Date now = new Date(); + LocalDate now = LocalDate.now(); if (dto.getEndDate() == null) { dto.setEndDate(now); } // 如果按日查询 if (Objects.equals(dto.getGroupBy(), TransactionBillGroupBy.create_date.name())) { // 以下是新的需求,如果按日分组,则查询当月第一天到最后一天的数据,并补全中间缺少的数据 - dto.setStartDate(DateUtils.getMonthFirstDate(dto.getYear(), dto.getMonth())); - dto.setEndDate(DateUtils.getMonthLastDate(dto.getYear(), dto.getMonth())); + dto.setStartDate(DateUtils.toLocalDate(DateUtils.getMonthFirstDate(dto.getYear(), dto.getMonth()))); + dto.setEndDate(DateUtils.toLocalDate(DateUtils.getMonthLastDate(dto.getYear(), dto.getMonth()))); } dto.setMchId(getUserId()); dto.setStatus(TransactionBillStatus.SUCCESS.getStatus()); diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/SmDashboardController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/SmDashboardController.java index 1e403bfd..0003018b 100644 --- a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/SmDashboardController.java +++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/SmDashboardController.java @@ -3,18 +3,18 @@ package com.ruoyi.web.controller.ss; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.ValidGroup; -import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.dashboard.DashboardService; import com.ruoyi.ss.balancePeriod.domain.SmBalancePeriodQuery; import com.ruoyi.ss.balancePeriod.service.ISmBalancePeriodService; import com.ruoyi.ss.businessRecord.service.ISmBusinessRecordService; +import com.ruoyi.ss.dashboard.ServiceIncomeQuery; import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery; import com.ruoyi.ss.transactionBill.service.TransactionBillService; import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillGroupBy; import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillStatus; import com.ruoyi.ss.businessRecord.domain.SmBusinessRecordVo; -import com.ruoyi.ss.dashboard.BriefVo; +import com.ruoyi.ss.dashboard.vo.BriefVo; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; @@ -90,4 +90,13 @@ public class SmDashboardController extends BaseController { public AjaxResult getTodoList() { return success(dashboardService.getTodoList()); } + + /** + * 获取服务费、收入及成本 + */ + @GetMapping("/serviceIncome") + public AjaxResult getServiceIncome(ServiceIncomeQuery query) { + return success(dashboardService.getServiceIncome(query)); + } + }