Commit 62fcb78d authored by licc's avatar licc

钱包接口,累计收益明细实现

parent a7402e90
......@@ -37,10 +37,18 @@ public interface AccountMapper extends BaseMapper<AccountInfo> {
/**
* 通过userId获取账户信息
*
* @param userId 用户id
* @return 账户信息
*/
AccountInfo getByUserId(@Param("userId") String userId);
/**
* 通过userId 和 yearMonth获取账户信息
*
* @param userId 用户id
* @param yearMonth 年月
* @return 账户信息
*/
AccountInfo getByUserIdAndTime(@Param("userId") String userId, @Param("yearMonth") String yearMonth);
}
......@@ -4,6 +4,8 @@ import cn.wisenergy.model.app.TradeRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author 86187
*/
......@@ -29,4 +31,18 @@ public interface TradeRecordMapper extends BaseMapper<TradeRecord> {
* @return 1
*/
int delById(@Param("id") Integer id);
/**
* 根据用户id,获取用户交易列表
* @param userId 用户id
* @return 用户交易列表
*/
List<TradeRecord> getByUserId(@Param("userId") String userId);
/**
* 根据用户id、年月 ,获取用户本月交易列表
* @param userId 用户id
* @return 用户交易列表
*/
List<TradeRecord> getByUserIdAndTime(@Param("userId") String userId,@Param("yearMonth") String yearMonth);
}
......@@ -92,4 +92,15 @@
</where>
</select>
<select id="getByUserIdAndTime" resultType="cn.wisenergy.model.app.AccountInfo">
select
<include refid="cols_all"/>
from
<include refid="table"/>
<where>
user_id=#{userId}
and year_month=#{yearMonth}
</where>
</select>
</mapper>
\ No newline at end of file
......@@ -71,4 +71,25 @@
where id = #{id}
</delete>
<select id="getByUserId" resultType="cn.wisenergy.model.app.TradeRecord">
select
<include refid="cols_all"/>
from
<include refid="table"/>
<where>
user_id=#{userId}
</where>
</select>
<select id="getByUserIdAndTime" resultType="cn.wisenergy.model.app.TradeRecord">
select
<include refid="cols_all"/>
from
<include refid="table"/>
<where>
user_id=#{userId}
and year_time=#{yearTime}
</where>
</select>
</mapper>
\ No newline at end of file
......@@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
......@@ -48,6 +49,12 @@ public class TradeRecord implements Serializable {
@ApiModelProperty(name = "taskId", value = "定时任务id")
private Integer taskId;
/**
* 金额
*/
@ApiModelProperty(name = "money", value = "金额")
private BigDecimal money;
/**
* 创建时间
*/
......
......@@ -48,4 +48,17 @@ public enum TradeRecordEnum {
public void setDesc(String desc) {
this.desc = desc;
}
public static String getByCode(Integer code) {
if (null == code) {
return null;
}
for (TradeRecordEnum operation : TradeRecordEnum.values()) {
if (operation.getCode().intValue() == code.intValue()) {
return operation.getDesc();
}
}
return null;
}
}
package cn.wisenergy.model.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
/**
* @author 86187
* @ Description: 累计收益展示Vo
* @ Author : 86187
* @ Date : 2021/3/2 16:26
*/
@Data
@ApiModel("AccumulatedIncomeVo")
public class AccumulatedIncomeVo {
/**
* 用户id
*/
@ApiModelProperty(value = "用户id", name = "userId")
private String userId;
/**
* 时间 年月
*/
@ApiModelProperty(value = "时间 年月", name = "yearMonth")
private String yearMonth;
/**
* 收益
*/
@ApiModelProperty(value = "收益", name = "income")
private BigDecimal income;
}
package cn.wisenergy.model.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
/**
* @author 86187
* @ Description: 收益详情Vo
* @ Author : 86187
* @ Date : 2021/3/3 9:53
*/
@Data
@ApiModel("IncomeDetailVo")
public class IncomeDetailVo {
/**
* 收益类型名
*/
@ApiModelProperty(value = "收益类型名", name = "typeName")
private String typeName;
/**
* 收益时间
*/
@ApiModelProperty(value = "收益时间", name = "incomeTime")
private Date incomeTime;
/**
* 收益金额
*/
@ApiModelProperty(value = "收益金额", name = "money")
private BigDecimal money;
}
package cn.wisenergy.model.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
/**
* @author 86187
* @ Description: 钱包收益详情展示Vo
* @ Author : 86187
* @ Date : 2021/3/2 17:25
*/
@Data
@ApiModel("MoneyPackageDetailVo")
public class MoneyPackageDetailVo {
/**
* 用户id
*/
@ApiModelProperty(value = "用户id", name = "userId")
private String userId;
/**
* 收益明细
*/
@ApiModelProperty(value = "收益明细", name = "list")
List<IncomeDetailVo> list;
/**
* 累计收益
*/
@ApiModelProperty(value = "累计收益", name = "totalIncome")
private BigDecimal totalIncome;
}
package cn.wisenergy.model.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
/**
* @author 86187
* @ Description: 当月总收益Vo
* @ Description: 钱包
* @ Author : 86187
* @ Date : 2021/3/2 10:59
*/
@Data
@ApiModel("MonthTotalRevenueVo")
public class MonthTotalRevenueVo {
@ApiModel("MoneyPackageVo")
public class MoneyPackageVo {
/**
* 用户id
*/
@ApiModelProperty(value = "用户id", name = "userId")
private String userId;
/**
* 余额
* 本月收益
*/
private BigDecimal balance;
@ApiModelProperty(value = "本月收益", name = "moneyIncome")
private BigDecimal moneyIncome;
/**
* 待结算
* 本月可提现
*/
private BigDecimal waitMoney;
@ApiModelProperty(value = "本月可提现", name = "currentMoneyCan")
private BigDecimal currentMoneyCan;
/**
* 累计收益
*/
private BigDecimal accumulatedIncome;
@ApiModelProperty(value = "累计收益", name = "totalIncome")
private BigDecimal totalIncome;
}
package cn.wisenergy.model.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
/**
* @author 86187
* @ Description: 钱包可提现Vo
* @ Author : 86187
* @ Date : 2021/3/2 16:10
*/
@Data
@ApiModel("WithdrawalAmountVo")
public class WithdrawalAmountVo {
/**
* 用户id
*/
@ApiModelProperty(value = "用户id", name = "userId")
private String userId;
/**
* 上月未提
*/
@ApiModelProperty(value = "上月未提",name = "lastMoneyNot")
private BigDecimal lastMoneyNot;
/**
* 本月可提现
*/
@ApiModelProperty(value = "本月可提现",name = "currentMoneyCan")
private BigDecimal currentMoneyCan;
}
......@@ -5,7 +5,6 @@ import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.app.AccountInfo;
import cn.wisenergy.model.app.OrderInfo;
import cn.wisenergy.model.app.User;
import cn.wisenergy.model.vo.MonthTotalRevenueVo;
import java.util.List;
......
package cn.wisenergy.service.app;
import cn.wisenergy.model.vo.MonthTotalRevenueVo;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.vo.AccumulatedIncomeVo;
import cn.wisenergy.model.vo.MoneyPackageDetailVo;
import cn.wisenergy.model.vo.MoneyPackageVo;
import cn.wisenergy.model.vo.WithdrawalAmountVo;
import java.util.List;
/**
*@ Description: 钱包相关接口定义
*@ Author : 86187
*@ Date : 2021/3/2 14:33
* @author 86187
* @ Description: 钱包相关接口定义
* @ Author : 86187
* @ Date : 2021/3/2 14:33
*/
public interface WalletService {
/**
......@@ -15,5 +21,29 @@ public interface WalletService {
* @param userId 用户id
* @return 当月总收益
*/
MonthTotalRevenueVo monthTotalRevenue(String userId);
R<MoneyPackageVo> getMoneyPackage(String userId);
/**
* 获取用户钱包-可提现
*
* @param userId 用户id
* @return 钱包-可提现
*/
R<WithdrawalAmountVo> getWithdrawalAmount(String userId);
/**
* 展示用户累计收益记录
*
* @param userId 用户id
* @return 用户累计收益
*/
R<List<AccumulatedIncomeVo>> showIncomeRecord(String userId);
/**
* 用户当月总收益
*
* @param userId 用户id
* @return 当月总收益
*/
R<MoneyPackageDetailVo> queryIncomeDetail(String userId);
}
package cn.wisenergy.service.app.impl;
import cn.wisenergy.common.utils.DateUtil;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.mapper.AccountMapper;
import cn.wisenergy.model.vo.MonthTotalRevenueVo;
import cn.wisenergy.mapper.TradeRecordMapper;
import cn.wisenergy.model.app.AccountInfo;
import cn.wisenergy.model.app.TradeRecord;
import cn.wisenergy.model.enums.TradeRecordEnum;
import cn.wisenergy.model.vo.*;
import cn.wisenergy.service.app.WalletService;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* @author 86187
......@@ -13,13 +27,126 @@ import org.springframework.stereotype.Service;
@Service
@Slf4j
public class WalletServiceImpl implements WalletService {
private static final String PATTERN = "yyyy-MM";
@Autowired
private AccountMapper accountMapper;
@Autowired
private TradeRecordMapper tradeRecordMapper;
@Override
public R<MoneyPackageVo> getMoneyPackage(String userId) {
log.info("shop-mall[]WalletServiceImpl[]getMoneyPackage[]input.param.userId:" + userId);
if (StringUtils.isBlank(userId)) {
return R.error("入参为空!");
}
Date date = new Date();
String yearMonth = DateUtil.convertDateToStr(date, PATTERN);
//1、获取用户账户信息
AccountInfo accountInfo = accountMapper.getByUserIdAndTime(userId, yearMonth);
if (null == accountInfo) {
return R.error("用户账户信息不存在!");
}
MoneyPackageVo moneyPackageVo = new MoneyPackageVo();
moneyPackageVo.setUserId(accountInfo.getUserId());
moneyPackageVo.setMoneyIncome(accountInfo.getEarningsMonth());
moneyPackageVo.setTotalIncome(accountInfo.getEarningsTotal());
moneyPackageVo.setCurrentMoneyCan(accountInfo.getExtractMoney());
return R.ok(moneyPackageVo);
}
@Override
public R<WithdrawalAmountVo> getWithdrawalAmount(String userId) {
log.info("shop-mall[]WalletServiceImpl[]getWithdrawalAmount[]input.param.userId:" + userId);
if (StringUtils.isBlank(userId)) {
return R.error("入参为空!");
}
Date date = new Date();
String yearMonth = DateUtil.convertDateToStr(date, PATTERN);
//1、获取用户账户信息
AccountInfo accountInfo = accountMapper.getByUserIdAndTime(userId, yearMonth);
if (null == accountInfo) {
return R.error("用户账户信息不存在!");
}
WithdrawalAmountVo withdrawalAmountVo = new WithdrawalAmountVo();
withdrawalAmountVo.setUserId(userId);
withdrawalAmountVo.setCurrentMoneyCan(accountInfo.getExtractMoney());
//TODO 获取上月为提现
withdrawalAmountVo.setLastMoneyNot(new BigDecimal(0));
return R.ok(withdrawalAmountVo);
}
@Override
public R<List<AccumulatedIncomeVo>> showIncomeRecord(String userId) {
log.info("shop-mall[]WalletServiceImpl[]showIncomeRecord[]input.param.userId:" + userId);
if (StringUtils.isBlank(userId)) {
return R.error("入参为空!");
}
List<TradeRecord> list = tradeRecordMapper.getByUserId(userId);
if (CollectionUtils.isEmpty(list)) {
return R.ok(new ArrayList<>());
}
List<AccumulatedIncomeVo> result = new ArrayList<>();
for (TradeRecord tradeRecord : list) {
AccumulatedIncomeVo incomeVo = new AccumulatedIncomeVo();
incomeVo.setUserId(tradeRecord.getUserId());
String yearMonth = DateUtil.convertDateToStr(tradeRecord.getCreateTime(), PATTERN);
incomeVo.setYearMonth(yearMonth);
incomeVo.setIncome(tradeRecord.getMoney());
result.add(incomeVo);
}
return R.ok(result);
}
@Override
public MonthTotalRevenueVo monthTotalRevenue(String userId) {
log.info("shop-mall[]WalletServiceImpl[]monthTotalRevenue[]input.param.userId:" + userId);
return null;
public R<MoneyPackageDetailVo> queryIncomeDetail(String userId) {
log.info("shop-mall[]WalletServiceImpl[]queryIncomeDetail[]input.param.userId:" + userId);
if (StringUtils.isBlank(userId)) {
return R.error("入参为空!");
}
Date date = new Date();
String yearMonth = DateUtil.convertDateToStr(date, PATTERN);
//获取当月账户信息
AccountInfo accountInfo = accountMapper.getByUserIdAndTime(userId, yearMonth);
if (null == accountInfo) {
return R.error("账户信息为空!");
}
//获取本月交易记录
List<TradeRecord> list = tradeRecordMapper.getByUserIdAndTime(userId, yearMonth);
if (CollectionUtils.isEmpty(list)) {
return R.ok(new MoneyPackageDetailVo());
}
MoneyPackageDetailVo detailVo = new MoneyPackageDetailVo();
detailVo.setUserId(userId);
detailVo.setTotalIncome(accountInfo.getEarningsTotal());
List<IncomeDetailVo> incomeDetailVos = new ArrayList<>();
for (TradeRecord tradeRecord : list) {
IncomeDetailVo incomeDetailVo = new IncomeDetailVo();
String typeName = TradeRecordEnum.getByCode(tradeRecord.getTradeType());
incomeDetailVo.setTypeName(typeName);
incomeDetailVo.setMoney(tradeRecord.getMoney());
incomeDetailVo.setIncomeTime(tradeRecord.getCreateTime());
incomeDetailVos.add(incomeDetailVo);
}
detailVo.setList(incomeDetailVos);
return R.ok(detailVo);
}
}
package cn.wisenergy.web.admin.controller.app;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.vo.AccumulatedIncomeVo;
import cn.wisenergy.model.vo.MoneyPackageDetailVo;
import cn.wisenergy.model.vo.MoneyPackageVo;
import cn.wisenergy.model.vo.WithdrawalAmountVo;
import cn.wisenergy.service.app.WalletService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @author 86187
*/
@Api(tags = "钱包展示接口管理")
@RestController
@RequestMapping("/wallet")
@Slf4j
public class WalletController {
@Autowired
private WalletService walletService;
@ApiOperation(value = "获取用户钱包", notes = "获取用户钱包", httpMethod = "GET")
@ApiImplicitParam(name = "userId", value = "用户id", dataType = "String", required = true)
@GetMapping("/getMoneyPackage")
public R<MoneyPackageVo> getMoneyPackage(String userId) {
log.info("shop-mall[]WalletController[]getMoneyPackage[]input.param.userId:" + userId);
if (StringUtils.isBlank(userId)) {
return R.error("入参不能为空!");
}
return walletService.getMoneyPackage(userId);
}
@ApiOperation(value = "获取用户钱包-可提现", notes = "获取用户钱包-可提现", httpMethod = "GET")
@ApiImplicitParam(name = "userId", value = "用户id", dataType = "String", required = true)
@GetMapping("/getWithdrawalAmount")
public R<WithdrawalAmountVo> getWithdrawalAmount(String userId) {
log.info("shop-mall[]WalletController[]getWithdrawalAmount[]input.param.userId:" + userId);
if (StringUtils.isBlank(userId)) {
return R.error("入参不能为空!");
}
return walletService.getWithdrawalAmount(userId);
}
@ApiOperation(value = "获取用户钱包-累计收益记录", notes = "获取用户钱包-累计收益记录", httpMethod = "GET")
@ApiImplicitParam(name = "userId", value = "用户id", dataType = "String", required = true)
@GetMapping("/showIncomeRecord")
public R<List<AccumulatedIncomeVo>> showIncomeRecord(String userId) {
log.info("shop-mall[]WalletController[]showIncomeRecord[]input.param.userId:" + userId);
if (StringUtils.isBlank(userId)) {
return R.error("入参不能为空!");
}
return walletService.showIncomeRecord(userId);
}
@ApiOperation(value = "获取用户钱包-累计收益明细", notes = "获取用户钱包-累计收益明细", httpMethod = "GET")
@ApiImplicitParam(name = "userId", value = "用户id", dataType = "String", required = true)
@GetMapping("/queryIncomeDetail")
public R<MoneyPackageDetailVo> queryIncomeDetail(String userId) {
log.info("shop-mall[]WalletController[]queryIncomeDetail[]input.param.userId:" + userId);
if (StringUtils.isBlank(userId)) {
return R.error("入参不能为空!");
}
return walletService.queryIncomeDetail(userId);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment