首页报表更新

This commit is contained in:
墨大叔 2024-09-07 16:43:49 +08:00
parent edd6232433
commit a9b169b1d0
32 changed files with 430 additions and 53 deletions

View File

@ -16,6 +16,11 @@
</description>
<dependencies>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-typehandlers-jsr310</artifactId>
<version>1.0.0</version>
</dependency>
<!-- jackson-->
<dependency>

View File

@ -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();
}
}

View File

@ -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 <T> List<T> fillVoids(List<? extends T> list, Function<? super T, LocalDate> getDateFunction, Function<LocalDate, ? extends T> function, LocalDate start, LocalDate end) {
// 输入验证
if (start.isAfter(end)) {
throw new IllegalArgumentException("起始日期必须早于结束日期");
}
// 使用Map优化查找性能
Map<String, T> fillAbleMap = new HashMap<>();
for (T item : list) {
fillAbleMap.put(DateUtils.getYYYY_MM_DD(getDateFunction.apply(item)), item);
}
// 构建结果列表并确保线程安全
List<T> 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;
}
}

View File

@ -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<ServiceIncomeVO> getServiceIncome(ServiceIncomeQuery query) {
// 查询订单
TransactionBillQuery billQuery = new TransactionBillQuery();
billQuery.setStartDate(query.getStartDate());
billQuery.setEndDate(query.getEndDate());
billQuery.setStatusList(TransactionBillStatus.payedOrder());
List<TransactionAmountVO<Date>> amountList = transactionBillService.selectCommonSumOfMoney(billQuery, TransactionBillGroupBy.create_date.name());
// 查询月费收入
ReceiveBillQuery receiveQuery = new ReceiveBillQuery();
receiveQuery.setStartDate(query.getStartDate());
receiveQuery.setEndDate(query.getEndDate());
List<ReceiveAmountVO<Date>> receiveList = receiveBillService.selectCommonSumOfAmount(receiveQuery, ReceiveBillGroupBy.create_date.name());
// 拼接结果集
List<ServiceIncomeVO> 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<Date> 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<Date> 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;
}
}

View File

@ -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;

View File

@ -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;
}

View File

@ -13,6 +13,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="rechargeCount" column="recharge_count" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullIntegerTyperHandler"/>
<result property="totalMonth" column="total_month" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
<result property="userBalance" column="user_balance" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
<result property="todayRechargeCount" column="today_recharge_count" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullIntegerTyperHandler" />
<result property="todayRechargeAmount" column="today_recharge_amount" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler" />
<result property="deviceCount" column="device_count" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullIntegerTyperHandler" />
</resultMap>
<sql id="selectSmBusinessRecordVo">
@ -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
</sql>
@ -47,7 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectSmBusinessRecordById" parameterType="Long" resultMap="SmBusinessRecordResult">
<include refid="selectSmBusinessRecordVo"/>
where id = #{id}
where sbr.id = #{id}
</select>
<select id="selectLatest" resultMap="SmBusinessRecordResult">
@ -97,6 +103,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="rechargeCount != null">recharge_count,</if>
<if test="totalMonth != null">total_month,</if>
<if test="userBalance != null">user_balance,</if>
<if test="todayRechargeCount != null">today_recharge_count,</if>
<if test="todayRechargeAmount != null">today_recharge_amount,</if>
<if test="deviceCount != null">device_count,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="totalDevice != null">#{totalDevice},</if>
@ -108,6 +117,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="rechargeCount != null">#{rechargeCount},</if>
<if test="totalMonth != null">#{totalMonth},</if>
<if test="userBalance != null">#{userBalance},</if>
<if test="todayRechargeCount != null">#{todayRechargeCount},</if>
<if test="todayRechargeAmount != null">#{todayRechargeAmount},</if>
<if test="deviceCount != null">#{deviceCount},</if>
</trim>
</insert>
@ -120,9 +132,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="totalUser != null">total_user = #{totalUser},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="totalRecharge != null">total_recharge = #{totalRecharge},</if>
<if test="data.rechargeCount != null">recharge_count = #{data.rechargeCount},</if>
<if test="data.totalMonth != null">total_month = #{data.totalMonth},</if>
<if test="data.userBalance != null">user_balance = #{data.userBalance},</if>
<if test="rechargeCount != null">recharge_count = #{rechargeCount},</if>
<if test="totalMonth != null">total_month = #{totalMonth},</if>
<if test="userBalance != null">user_balance = #{userBalance},</if>
<if test="todayRechargeCount != null">today_recharge_count = #{todayRechargeCount},</if>
<if test="todayRechargeAmount != null">today_recharge_amount = #{todayRechargeAmount},</if>
<if test="deviceCount != null">device_count = #{deviceCount},</if>
</trim>
where id = #{id}
</update>

View File

@ -3,7 +3,7 @@ package com.ruoyi.ss.businessRecord.service;
import com.ruoyi.ss.businessRecord.domain.SmBusinessRecord;
import com.ruoyi.ss.businessRecord.domain.SmBusinessRecordQuery;
import com.ruoyi.ss.businessRecord.domain.SmBusinessRecordVo;
import com.ruoyi.ss.dashboard.BriefVo;
import com.ruoyi.ss.dashboard.vo.BriefVo;
import java.util.Date;
import java.util.List;

View File

@ -7,13 +7,11 @@ import com.ruoyi.ss.businessRecord.domain.SmBusinessRecord;
import com.ruoyi.ss.businessRecord.domain.SmBusinessRecordQuery;
import com.ruoyi.ss.businessRecord.domain.SmBusinessRecordVo;
import com.ruoyi.ss.businessRecord.mapper.SmBusinessRecordMapper;
import com.ruoyi.ss.dashboard.BillCountVo;
import com.ruoyi.ss.dashboard.BriefVo;
import com.ruoyi.ss.dashboard.vo.BillCountVo;
import com.ruoyi.ss.dashboard.vo.BriefVo;
import com.ruoyi.ss.device.domain.DeviceQuery;
import com.ruoyi.ss.device.domain.enums.DeviceOnlineStatus;
import com.ruoyi.ss.device.service.DeviceService;
import com.ruoyi.ss.model.domain.SmModelQuery;
import com.ruoyi.ss.model.service.ModelService;
import com.ruoyi.ss.receiveBill.domain.ReceiveBillQuery;
import com.ruoyi.ss.receiveBill.domain.enums.ReceiveBillType;
import com.ruoyi.ss.receiveBill.service.ReceiveBillService;
@ -169,18 +167,21 @@ public class SmBusinessRecordServiceImpl implements ISmBusinessRecordService
todayQuery.setCreateDate(now);
brief.setTodayRechargeCount(transactionBillService.selectSimpleCount(todayQuery));
// 设备总数
// 用户设备总数
DeviceQuery deviceDto = new DeviceQuery();
deviceDto.setDeleted(false);
deviceDto.setIsBind(true);
brief.setDeviceCount(deviceService.selectCount(deviceDto));
// 用户在线设备总数
deviceDto.setOnlineStatus(DeviceOnlineStatus.ONLINE.getStatus());
brief.setOnlineCount(deviceService.selectCount(deviceDto));
// 在线设备总数
DeviceQuery onlineDto = new DeviceQuery();
onlineDto.setOnlineStatus(DeviceOnlineStatus.ONLINE.getStatus());
onlineDto.setDeleted(false);
onlineDto.setIsBind(true);
brief.setOnlineCount(deviceService.selectCount(onlineDto));
// 总设备数量
DeviceQuery totalDeviceQuery = new DeviceQuery();
brief.setTotalDeviceCount(deviceService.selectCount(totalDeviceQuery));
// 总设备在线数量
totalDeviceQuery.setOnlineStatus(DeviceOnlineStatus.ONLINE.getStatus());
brief.setTotalOnlineCount(deviceService.selectCount(totalDeviceQuery));
// 商户总数
SmUserQuery userDto = new SmUserQuery();
@ -203,10 +204,10 @@ public class SmBusinessRecordServiceImpl implements ISmBusinessRecordService
}
// 今日充值金额总数
TransactionBillQuery todayRechargeAmountQuery = new TransactionBillQuery();
todayRechargeAmountQuery.setStatus(TransactionBillStatus.SUCCESS.getStatus());
todayRechargeAmountQuery.setCreateDate(now);
List<BillCountVo> todayBillCount = transactionBillService.selectCount(todayRechargeAmountQuery);
TransactionBillQuery todayRechargeQuery = new TransactionBillQuery();
todayRechargeQuery.setStatusList(TransactionBillStatus.payedOrder());
todayRechargeQuery.setCreateDate(now);
List<BillCountVo> todayBillCount = transactionBillService.selectCount(todayRechargeQuery);
if (!CollectionUtils.isEmpty(todayBillCount) && todayBillCount.get(0).getRecharge() != null) {
brief.setTodayRechargeAmount(todayBillCount.get(0).getRecharge());
} else {
@ -238,7 +239,6 @@ public class SmBusinessRecordServiceImpl implements ISmBusinessRecordService
@Override
public void record() {
BriefVo brief = this.selectBrief();
SmBusinessRecord data = new SmBusinessRecord();
data.setTotalDevice(brief.getDeviceCount());
data.setTotalOnline(brief.getOnlineCount());
@ -247,6 +247,9 @@ public class SmBusinessRecordServiceImpl implements ISmBusinessRecordService
data.setRechargeCount(brief.getRechargeCount());
data.setTotalMonth(brief.getTotalMonthAmount());
data.setUserBalance(brief.getTotalUserBalance());
data.setTodayRechargeAmount(brief.getTodayRechargeAmount());
data.setTodayRechargeCount(brief.getTodayRechargeCount());
data.setDeviceCount(brief.getTotalDeviceCount());
this.insertSmBusinessRecord(data);
}
}

View File

@ -0,0 +1,24 @@
package com.ruoyi.ss.dashboard;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDate;
import java.util.List;
/**
* @author wjh
* 2024/9/7
*/
@Data
public class ServiceIncomeQuery {
@ApiModelProperty("起始日期")
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate startDate;
@ApiModelProperty("结束日期")
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate endDate;
}

View File

@ -1,4 +1,4 @@
package com.ruoyi.ss.dashboard;
package com.ruoyi.ss.dashboard.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;

View File

@ -1,4 +1,4 @@
package com.ruoyi.ss.dashboard;
package com.ruoyi.ss.dashboard.vo;
import com.ruoyi.ss.businessRecord.domain.SmBusinessRecordVo;
import lombok.Data;
@ -13,8 +13,11 @@ import java.util.List;
*/
@Data
public class BriefVo {
private Integer deviceCount; // 设备数量
private Integer onlineCount; // 在线数量
private Integer deviceCount; // 用户设备数量
private Integer onlineCount; // 用户设备在线数量
private Integer totalDeviceCount; // 总设备数量
private Integer totalOnlineCount; // 总设备在线数量
private Integer userCount; // 商户用户数量
private Integer tenantCount; // 租户用户数量

View File

@ -0,0 +1,28 @@
package com.ruoyi.ss.dashboard.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDate;
/**
* @author wjh
* 2024/9/7
*/
@Data
public class ServiceIncomeVO {
@ApiModelProperty("日期")
private LocalDate date;
@ApiModelProperty("月费收入")
private BigDecimal monthAmount;
@ApiModelProperty("服务费收入")
private BigDecimal serviceAmount;
@ApiModelProperty("成本")
private BigDecimal channelCost;
}

View File

@ -1,4 +1,4 @@
package com.ruoyi.ss.dashboard;
package com.ruoyi.ss.dashboard.vo;
import lombok.Data;

View File

@ -1,11 +1,7 @@
package com.ruoyi.ss.device.service.impl;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.iot.domain.IotDeviceInfo;
import com.ruoyi.iot.service.IotService;
import com.ruoyi.ss.dashboard.BillCountVo;
import com.ruoyi.ss.device.domain.enums.DeviceOnlineStatus;
import com.ruoyi.ss.dashboard.vo.BillCountVo;
import com.ruoyi.ss.device.domain.vo.DeviceVO;
import com.ruoyi.ss.device.service.DeviceAssembler;
import com.ruoyi.ss.deviceSuit.domain.DeviceSuitQuery;
@ -14,7 +10,6 @@ import com.ruoyi.ss.deviceSuit.service.DeviceSuitService;
import com.ruoyi.ss.store.domain.StoreQuery;
import com.ruoyi.ss.store.domain.StoreVo;
import com.ruoyi.ss.store.service.StoreService;
import com.ruoyi.ss.suit.service.SuitService;
import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery;
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillGroupBy;
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillStatus;

View File

@ -2,6 +2,7 @@ package com.ruoyi.ss.receiveBill.domain;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDate;
@ -28,6 +29,14 @@ public class ReceiveBillQuery extends ReceiveBill{
private String deviceName;
@ApiModelProperty("设备SN")
private String deviceNo;;
private String deviceNo;
@ApiModelProperty("起始日期")
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate startDate;
@ApiModelProperty("结束日期")
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate endDate;
}

View File

@ -0,0 +1,9 @@
package com.ruoyi.ss.receiveBill.domain.enums;
/**
* @author wjh
* 2024/9/7
*/
public enum ReceiveBillGroupBy {
create_date; // 创建日期
}

View File

@ -0,0 +1,18 @@
package com.ruoyi.ss.receiveBill.domain.vo;
import lombok.Data;
import java.math.BigDecimal;
/**
* @author wjh
* 2024/9/7
*/
@Data
public class ReceiveAmountVO<K> {
private K key;
private BigDecimal amount; // 账单金额
private BigDecimal receivedAmount; // 已收金额
}

View File

@ -5,6 +5,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 org.apache.ibatis.annotations.Param;
/**
@ -72,4 +73,6 @@ public interface ReceiveBillMapper
* 查询账单金额总额
*/
BigDecimal selectSumOfAmount(@Param("query") ReceiveBillQuery query);
<K> List<ReceiveAmountVO<K>> selectCommonSumOfAmount(@Param("query") ReceiveBillQuery query, @Param("groupBy") String groupBy);
}

View File

@ -43,6 +43,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="query.deviceName != null and query.deviceName != ''"> and sd.device_name like concat('%', #{query.deviceName}, '%')</if>
<if test="query.deviceNo != null and query.deviceNo != ''"> and sd.device_no like concat('%', #{query.deviceNo}, '%')</if>
<if test="query.description != null and query.description != ''"> and srb.description like concat('%', #{query.description}, '%')</if>
<if test="query.startDate != null">
and date(srb.create_time) >= #{query.startDate}
</if>
<if test="query.endDate != null">
and date(srb.create_time) &lt;= #{query.endDate}
</if>
</sql>
<select id="selectReceiveBillList" parameterType="ReceiveBillQuery" resultMap="ReceiveBillResult">
@ -73,6 +79,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where>
</select>
<resultMap id="ReceiveAmountVO" type="ReceiveAmountVO">
<result property="amount" column="amount" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
<result property="receivedAmount" column="received_amount" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
</resultMap>
<select id="selectCommonSumOfAmount" resultMap="ReceiveAmountVO">
select
<if test="groupBy != null and groupBy != ''">
<if test="groupBy == 'create_date'">
date(srb.create_time) as `key`,
</if>
</if>
srb.amount,
srb.received_amount
from <include refid="selectTables"/>
<where>
<include refid="searchCondition"/>
</where>
<if test="groupBy != null and groupBy != ''">
group by `key`
</if>
</select>
<insert id="insertReceiveBill" parameterType="ReceiveBill" useGeneratedKeys="true" keyProperty="billId">
<selectKey keyProperty="billId" resultType="Long" order="AFTER">
SELECT LAST_INSERT_ID()

View File

@ -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);
<K> List<ReceiveAmountVO<K>> selectCommonSumOfAmount(ReceiveBillQuery receiveQuery, String groupBy);
}

View File

@ -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 <K> List<ReceiveAmountVO<K>> selectCommonSumOfAmount(ReceiveBillQuery query, String groupBy) {
return receiveBillMapper.selectCommonSumOfAmount(query, groupBy);
}
}

View File

@ -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;

View File

@ -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<Long> billIds;

View File

@ -71,4 +71,11 @@ public enum TransactionBillStatus {
public static List<String> canClose() {
return asList(SUCCESS, SUCCESS_DEPOSIT);
}
/**
* 已支付过的订单状态
*/
public static List<String> payedOrder() {
return asList(SUCCESS, REFUNDED, REFUNDING);
}
}

View File

@ -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<T> {
private T key; // 分组依据
private BigDecimal money; // 订单金额
private BigDecimal serviceAmount; // 服务费
private BigDecimal arrivalAmount; // 到账金额
private BigDecimal channelCost; // 渠道成本
}

View File

@ -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);
/**
* 查询金额统计
*/
<T> List<TransactionAmountVO<T>> selectCommonSumOfMoney(@Param("query") TransactionBillQuery query, @Param("groupBy") String groupBy);
}

View File

@ -245,7 +245,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where stb.bill_id = #{billId}
</select>
<resultMap id="BillCountVo" type="com.ruoyi.ss.dashboard.BillCountVo" autoMapping="true">
<resultMap id="BillCountVo" type="com.ruoyi.ss.dashboard.vo.BillCountVo" autoMapping="true">
<result property="createDate" column="create_date"/>
<result property="createHour" column="create_hour"/>
<result property="createYear" column="create_year"/>
@ -337,6 +337,33 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where>
</select>
<resultMap id="TransactionAmountVO" type="TransactionAmountVO">
<result property="money" column="money" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
<result property="serviceAmount" column="service_amount" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
<result property="arrivalAmount" column="arrival_amount" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
<result property="channelCost" column="channel_cost" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
</resultMap>
<select id="selectCommonSumOfMoney" resultMap="TransactionAmountVO">
select
<if test="groupBy != null and groupBy != ''">
<if test="groupBy == 'create_date'">
date(stb.create_time) as `key`,
</if>
</if>
sum(stb.money) as money,
sum(stb.service_charge) as service_amount,
sum(stb.arrival_amount) as arrival_amount,
sum(stb.channel_cost) as channel_cost
from <include refid="rechargeTables"/>
<where>
<include refid="searchCondition"/>
</where>
<if test="groupBy != null and groupBy != ''">
group by `key`
</if>
</select>
<insert id="insertSmTransactionBill" parameterType="TransactionBill" useGeneratedKeys="true" keyProperty="billId">
insert into sm_transaction_bill
<trim prefix="(" suffix=")" suffixOverrides=",">

View File

@ -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);
/**
* 查询所有关于金额的总和
*/
<T> List<TransactionAmountVO<T>> selectCommonSumOfMoney(TransactionBillQuery query, String groupBy);
}

View File

@ -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<BillCountVo> 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 <T> List<TransactionAmountVO<T>> selectCommonSumOfMoney(TransactionBillQuery query, String groupBy) {
return transactionBillMapper.selectCommonSumOfMoney(query, groupBy);
}
@Override
public UserWithdrawServiceVO getUserWithdrawService(Long userId, Long channelId) {
SmUserVo user = userService.selectSmUserByUserId(userId);

View File

@ -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());

View File

@ -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));
}
}