账户明细
This commit is contained in:
parent
ad580e3f99
commit
68dd5db747
@ -0,0 +1,48 @@
|
||||
package com.wzj.soopin.member.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.wzj.soopin.member.domain.bo.AccountDetailQueryBO;
|
||||
import com.wzj.soopin.member.domain.vo.AccountDetailVO;
|
||||
import com.wzj.soopin.member.service.IAccountDetailService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
/**
|
||||
* 账户明细查询控制器
|
||||
*/
|
||||
@Tag(name = "账户明细查询")
|
||||
@RestController
|
||||
@RequestMapping("/account/detail")
|
||||
@RequiredArgsConstructor
|
||||
public class AccountDetailController {
|
||||
|
||||
private final IAccountDetailService accountDetailService;
|
||||
|
||||
/**
|
||||
* 分页查询账户明细
|
||||
*/
|
||||
@Operation(summary = "分页查询账户明细")
|
||||
@PostMapping("/page")
|
||||
public R<IPage<AccountDetailVO>> queryAccountDetailPage(@Validated @RequestBody AccountDetailQueryBO queryBO) {
|
||||
IPage<AccountDetailVO> result = accountDetailService.queryAccountDetailPage(queryBO);
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前登录用户的账户明细
|
||||
*/
|
||||
@Operation(summary = "查询当前登录用户的账户明细")
|
||||
@PostMapping("/current")
|
||||
public R<IPage<AccountDetailVO>> queryCurrentUserAccountDetailPage(@Validated @RequestBody AccountDetailQueryBO queryBO) {
|
||||
IPage<AccountDetailVO> result = accountDetailService.queryCurrentUserAccountDetailPage(queryBO);
|
||||
return R.ok(result);
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.wzj.soopin.member.domain.bo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 账户明细查询对象
|
||||
*/
|
||||
@Schema(description = "账户明细查询对象")
|
||||
@Data
|
||||
public class AccountDetailQueryBO {
|
||||
|
||||
@Schema(description = "会员ID")
|
||||
private Long memberId;
|
||||
|
||||
@Schema(description = "账户ID")
|
||||
private Long accountId;
|
||||
|
||||
@Schema(description = "变动类型")
|
||||
private Integer changeType;
|
||||
|
||||
@Schema(description = "变动来源")
|
||||
private Integer source;
|
||||
|
||||
@Schema(description = "开始时间")
|
||||
private LocalDateTime startTime;
|
||||
|
||||
@Schema(description = "结束时间")
|
||||
private LocalDateTime endTime;
|
||||
|
||||
@Schema(description = "页码", defaultValue = "1")
|
||||
private Long pageNum = 1L;
|
||||
|
||||
@Schema(description = "每页大小", defaultValue = "10")
|
||||
private Long pageSize = 10L;
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package com.wzj.soopin.member.domain.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 账户明细返回对象
|
||||
*/
|
||||
@Schema(description = "账户明细返回对象")
|
||||
@Data
|
||||
public class AccountDetailVO {
|
||||
|
||||
@Schema(description = "记录ID")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "会员ID")
|
||||
private Long memberId;
|
||||
|
||||
@Schema(description = "账户ID")
|
||||
private Long accountId;
|
||||
|
||||
@Schema(description = "账户类型 1-用户 2-商家 3-代理 4-平台")
|
||||
private Integer accountType;
|
||||
|
||||
@Schema(description = "账户类型描述")
|
||||
private String accountTypeDesc;
|
||||
|
||||
@Schema(description = "用户类型 1-租户 2-会员")
|
||||
private Integer userType;
|
||||
|
||||
@Schema(description = "用户类型描述")
|
||||
private String userTypeDesc;
|
||||
|
||||
@Schema(description = "余额")
|
||||
private BigDecimal moneyBalance;
|
||||
|
||||
@Schema(description = "变动前余额")
|
||||
private BigDecimal beforeBalance;
|
||||
|
||||
@Schema(description = "变动后余额")
|
||||
private BigDecimal afterBalance;
|
||||
|
||||
@Schema(description = "变动金额")
|
||||
private BigDecimal changeAmount;
|
||||
|
||||
@Schema(description = "变动类型")
|
||||
private Integer changeType;
|
||||
|
||||
@Schema(description = "变动类型描述")
|
||||
private String changeTypeDesc;
|
||||
|
||||
@Schema(description = "变动描述")
|
||||
private String changeDesc;
|
||||
|
||||
@Schema(description = "变动来源")
|
||||
private Integer source;
|
||||
|
||||
@Schema(description = "变动来源描述")
|
||||
private String sourceDesc;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.wzj.soopin.member.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 账户类型枚举
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum AccountTypeEnum {
|
||||
|
||||
USER(1, "用户"),
|
||||
MERCHANT(2, "商家"),
|
||||
AGENT(3, "代理"),
|
||||
PLATFORM(4, "平台");
|
||||
|
||||
private final Integer code;
|
||||
private final String desc;
|
||||
|
||||
public static String getDesc(Integer code) {
|
||||
if (code == null) {
|
||||
return "";
|
||||
}
|
||||
for (AccountTypeEnum type : values()) {
|
||||
if (type.getCode().equals(code)) {
|
||||
return type.getDesc();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.wzj.soopin.member.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 用户类型枚举
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum UserTypeEnum {
|
||||
|
||||
TENANT(1, "租户"),
|
||||
MEMBER(2, "会员");
|
||||
|
||||
private final Integer code;
|
||||
private final String desc;
|
||||
|
||||
public static String getDesc(Integer code) {
|
||||
if (code == null) {
|
||||
return "";
|
||||
}
|
||||
for (UserTypeEnum type : values()) {
|
||||
if (type.getCode().equals(code)) {
|
||||
return type.getDesc();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据账户类型判断用户类型
|
||||
* 1-用户 -> 会员, 2-商家 -> 租户, 3-代理 -> 租户, 4-平台 -> 租户
|
||||
*/
|
||||
public static Integer getUserTypeByAccountType(Integer accountType) {
|
||||
if (accountType == null) {
|
||||
return MEMBER.getCode();
|
||||
}
|
||||
// 1-用户是会员,其他都是租户
|
||||
return accountType == 1 ? MEMBER.getCode() : TENANT.getCode();
|
||||
}
|
||||
}
|
@ -1,18 +1,23 @@
|
||||
package com.wzj.soopin.member.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.wzj.soopin.member.domain.po.MemberAccount;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.wzj.soopin.member.domain.po.MemberAccountChangeRecord;
|
||||
import com.wzj.soopin.member.domain.vo.AccountDetailVO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
|
||||
/**
|
||||
* 会员账户表Mapper接口
|
||||
*
|
||||
* @author zcc
|
||||
* 会员账户变动记录Mapper接口
|
||||
*/
|
||||
public interface MemberAccountChangeRecordMapper extends BaseMapper<MemberAccountChangeRecord> {
|
||||
public interface MemberAccountChangeRecordMapper extends BaseMapperPlus<MemberAccountChangeRecord, AccountDetailVO> {
|
||||
|
||||
/**
|
||||
* 分页查询账户明细(关联账户表获取账户类型)
|
||||
*/
|
||||
IPage<AccountDetailVO> selectAccountDetailPage(Page<AccountDetailVO> page, @Param("memberId") Long memberId,
|
||||
@Param("accountId") Long accountId, @Param("changeType") Integer changeType,
|
||||
@Param("source") Integer source, @Param("startTime") String startTime,
|
||||
@Param("endTime") String endTime);
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
package com.wzj.soopin.member.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.wzj.soopin.member.domain.bo.AccountDetailQueryBO;
|
||||
import com.wzj.soopin.member.domain.vo.AccountDetailVO;
|
||||
|
||||
/**
|
||||
* 账户明细查询服务接口
|
||||
*/
|
||||
public interface IAccountDetailService {
|
||||
|
||||
/**
|
||||
* 分页查询账户明细
|
||||
*/
|
||||
IPage<AccountDetailVO> queryAccountDetailPage(AccountDetailQueryBO queryBO);
|
||||
|
||||
/**
|
||||
* 根据账户类型判断用户类型
|
||||
*/
|
||||
Integer getUserTypeByAccountType(Integer accountType);
|
||||
|
||||
/**
|
||||
* 查询当前登录用户的账户明细
|
||||
*/
|
||||
IPage<AccountDetailVO> queryCurrentUserAccountDetailPage(AccountDetailQueryBO queryBO);
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
package com.wzj.soopin.member.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.wzj.soopin.member.domain.bo.AccountDetailQueryBO;
|
||||
import com.wzj.soopin.member.domain.vo.AccountDetailVO;
|
||||
import com.wzj.soopin.member.enums.AccountTypeEnum;
|
||||
import com.wzj.soopin.member.enums.UserTypeEnum;
|
||||
import com.wzj.soopin.member.mapper.MemberAccountChangeRecordMapper;
|
||||
import com.wzj.soopin.member.service.IAccountDetailService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.dromara.common.core.domain.model.LoginUser;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 账户明细查询服务实现类
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AccountDetailServiceImpl implements IAccountDetailService {
|
||||
|
||||
private final MemberAccountChangeRecordMapper accountChangeRecordMapper;
|
||||
|
||||
@Override
|
||||
public IPage<AccountDetailVO> queryAccountDetailPage(AccountDetailQueryBO queryBO) {
|
||||
// 构建分页对象
|
||||
Page<AccountDetailVO> page = new Page<>(queryBO.getPageNum(), queryBO.getPageSize());
|
||||
|
||||
// 处理时间格式
|
||||
String startTime = null;
|
||||
String endTime = null;
|
||||
if (queryBO.getStartTime() != null) {
|
||||
startTime = queryBO.getStartTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
}
|
||||
if (queryBO.getEndTime() != null) {
|
||||
endTime = queryBO.getEndTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
IPage<AccountDetailVO> result = accountChangeRecordMapper.selectAccountDetailPage(
|
||||
page, queryBO.getMemberId(), queryBO.getAccountId(),
|
||||
queryBO.getChangeType(), queryBO.getSource(), startTime, endTime
|
||||
);
|
||||
|
||||
// 补充账户类型和用户类型描述
|
||||
List<AccountDetailVO> records = result.getRecords();
|
||||
for (AccountDetailVO record : records) {
|
||||
// 设置账户类型描述
|
||||
record.setAccountTypeDesc(AccountTypeEnum.getDesc(record.getAccountType()));
|
||||
|
||||
// 根据账户类型判断用户类型
|
||||
Integer userType = getUserTypeByAccountType(record.getAccountType());
|
||||
record.setUserType(userType);
|
||||
record.setUserTypeDesc(UserTypeEnum.getDesc(userType));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getUserTypeByAccountType(Integer accountType) {
|
||||
return UserTypeEnum.getUserTypeByAccountType(accountType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<AccountDetailVO> queryCurrentUserAccountDetailPage(AccountDetailQueryBO queryBO) {
|
||||
// 获取当前登录用户信息
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
if (loginUser == null) {
|
||||
throw new RuntimeException("用户未登录");
|
||||
}
|
||||
|
||||
// 设置当前登录用户的会员ID
|
||||
queryBO.setMemberId(loginUser.getUserId());
|
||||
|
||||
// 调用原有的分页查询方法
|
||||
return queryAccountDetailPage(queryBO);
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.wzj.soopin.member.mapper.MemberAccountChangeRecordMapper">
|
||||
|
||||
<!-- 分页查询账户明细(关联账户表获取账户类型) -->
|
||||
<select id="selectAccountDetailPage" resultType="com.wzj.soopin.member.domain.vo.AccountDetailVO">
|
||||
SELECT
|
||||
r.id,
|
||||
r.member_id as memberId,
|
||||
r.account_id as accountId,
|
||||
a.type as accountType,
|
||||
r.money_balance as moneyBalance,
|
||||
r.before_balance as beforeBalance,
|
||||
r.after_balance as afterBalance,
|
||||
r.change_amount as changeAmount,
|
||||
r.change_type as changeType,
|
||||
r.change_desc as changeDesc,
|
||||
r.source,
|
||||
r.create_time as createTime
|
||||
FROM ums_account_change_record r
|
||||
LEFT JOIN ums_account a ON r.account_id = a.id
|
||||
<where>
|
||||
<if test="memberId != null">
|
||||
AND r.member_id = #{memberId}
|
||||
</if>
|
||||
<if test="accountId != null">
|
||||
AND r.account_id = #{accountId}
|
||||
</if>
|
||||
<if test="changeType != null">
|
||||
AND r.change_type = #{changeType}
|
||||
</if>
|
||||
<if test="source != null">
|
||||
AND r.source = #{source}
|
||||
</if>
|
||||
<if test="startTime != null and startTime != ''">
|
||||
AND r.create_time >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null and endTime != ''">
|
||||
AND r.create_time <= #{endTime}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY r.create_time DESC
|
||||
</select>
|
||||
|
||||
</mapper>
|
Loading…
x
Reference in New Issue
Block a user