Commit 0d8d3ea7 authored by libin's avatar libin

后台*钱包

parent a48502d5
package com.github.wxiaoqi.security.admin.dto;
import lombok.Data;
import java.math.BigDecimal;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/7/18 15:59
*/
@Data
public class PersonalConsumptionDTO {
private Integer userId;
private BigDecimal totalConsumption;
}
......@@ -12,7 +12,7 @@ import lombok.Data;
@Data
public class WalletCathFindDTO extends PageParam {
private String userName;
private String username;
private String phone;
......
package com.github.wxiaoqi.security.admin.dto;
import com.github.wxiaoqi.security.common.vo.PageParam;
import lombok.Data;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/7/18 11:12
*/
@Data
public class WalletDetailFindDTO extends PageParam {
private String username;
private String phone;
private Integer source;
}
......@@ -25,25 +25,28 @@ public class WalletDetailListDTO {
private String phone;
@ApiModelProperty(value = "来源:0-活动,1-佣金,2-会员充值,10-提现,11-转账,12-购买")
private Integer sourceType;
private Integer source;
@ApiModelProperty("活动名称或佣金商品名称")
private String source;
@ApiModelProperty("佣金商品名称")
private String title;
@ApiModelProperty(value = "收入/支出:0-收入,1-支出")
private Integer itype;
@ApiModelProperty("商品价格")
private BigDecimal price;
@ApiModelProperty(value = "收入/支出的金额(分)")
private BigDecimal amount;
@ApiModelProperty("提成比例")
private Integer extract;
@ApiModelProperty("入帐状态")
private Integer waiting;
@ApiModelProperty(value = "活动类型")
private Integer type;
@ApiModelProperty(value = "收入/支出的金额(分)")
private BigDecimal amount;
@ApiModelProperty(value = "活动id")
private Integer activityId;
@ApiModelProperty(value = "0 收入 1 支出")
private Integer itype;
@ApiModelProperty("活动名称")
private String activityName;
......@@ -52,11 +55,6 @@ public class WalletDetailListDTO {
@ApiModelProperty(value = "单号")
private Integer cono;
@ApiModelProperty(value = "加上当时的收入的余额")
private BigDecimal balance;
@ApiModelProperty(value = "操作时间", hidden = true )
private Long crtTime;
......
package com.github.wxiaoqi.security.admin.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/7/18 10:50
*/
@Data
public class WalletDetailAdminVo {
private Integer id;
private String username;
private String phone;
@ApiModelProperty(value = "来源:0-活动,1-佣金,2-会员充值,10-提现,11-转账,12-购买")
private Integer source;
@ApiModelProperty("佣金商品名称")
private String title;
@ApiModelProperty("商品价格")
private BigDecimal price;
@ApiModelProperty("提成比例")
private Integer extract;
@ApiModelProperty("入帐状态")
private Integer waiting;
@ApiModelProperty(value = "收入/支出的金额(分)")
private BigDecimal amount;
@ApiModelProperty(value = "0收入 1支出")
private Integer itype;
@ApiModelProperty("活动名称")
private String activityName;
@ApiModelProperty(value = "单号")
private Integer cono;
@ApiModelProperty(value = "操作时间", hidden = true )
private Long crtTime;
}
......@@ -30,12 +30,15 @@ public class WalletPageVo {
@ApiModelProperty(value = "已提现金额")
private BigDecimal withdrawals;
@ApiModelProperty(value = "总消费")
private BigDecimal totalConsumption;
@ApiModelProperty(value = "进账总额(元)")
private BigDecimal totalAmount;
@ApiModelProperty(value = "进账总额(元)")
@ApiModelProperty(value = "日收益总额(元)")
private BigDecimal todayAmount;
......
......@@ -10,14 +10,15 @@ import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author libin
......@@ -29,6 +30,8 @@ import java.util.List;
@Service
public class MyWalletBiz extends BaseBiz<MyWalletMapper, MyWallet> {
@Autowired
private MyWalletDetailBiz myWalletDetailBiz;
public AppletWalletVo findMyWallet(Integer userId) {
......@@ -62,6 +65,14 @@ public class MyWalletBiz extends BaseBiz<MyWalletMapper, MyWallet> {
walletpg.setPhone(wallet.getUsername());
walletPageVos.add(walletpg);
}
List<Integer> userIds = wallets.stream().map(WalletListDTO::getUserId).collect(Collectors.toList());
Map<Integer, BigDecimal> userIdAndTotalConsumptionMap = myWalletDetailBiz.finduserIdAndPersonalTotalConsumptionMapByUserIds(userIds);
Optional.ofNullable(userIdAndTotalConsumptionMap).ifPresent(x->{
for (WalletPageVo wtpg : walletPageVos) {
wtpg.setTotalConsumption(x.get(wtpg.getUserId()));
}
});
walletPageVos.sort(Comparator.comparing(WalletPageVo::getTotalAmount).reversed());
walletPageVo.setPageNum(walletFindDTO.getPage());
walletPageVo.setPageSize(walletFindDTO.getLimit());
......
......@@ -87,7 +87,7 @@ public class MyWalletCathBiz extends BaseBiz<MyWalletCathMapper, MyWalletCath> {
// List<WalletCathListDTO> walletCathListDTOS = mapper.selectByUserNameOrPhoneOrWithDrawSate(walletCathFindDTO.getUserName(), walletCathFindDTO.getPhone(), walletCathFindDTO.getState());
PageDataVO<WalletCathListDTO> walletCathListDTOPage = PageDataVO.pageInfo(walletCathFindDTO.getPage(),
walletCathFindDTO.getLimit(),
() -> mapper.selectByUserNameOrPhoneOrWithDrawSate(walletCathFindDTO.getUserName(), walletCathFindDTO.getPhone(), walletCathFindDTO.getState()));
() -> mapper.selectByUserNameOrPhoneOrWithDrawSate(walletCathFindDTO.getUsername(), walletCathFindDTO.getPhone(), walletCathFindDTO.getState()));
List<WalletCathListDTO> walletCathListDTOList = walletCathListDTOPage.getData();
if (CollectionUtils.isEmpty(walletCathListDTOList)){
......@@ -111,4 +111,5 @@ public class MyWalletCathBiz extends BaseBiz<MyWalletCathMapper, MyWalletCath> {
return walletCathAdminVoPage;
}
}
package com.github.wxiaoqi.security.admin.biz;
import com.github.wxiaoqi.security.admin.dto.PersonalConsumptionDTO;
import com.github.wxiaoqi.security.admin.dto.WalletDetailFindDTO;
import com.github.wxiaoqi.security.admin.dto.WalletDetailListDTO;
import com.github.wxiaoqi.security.admin.entity.MyWalletDetail;
import com.github.wxiaoqi.security.admin.mapper.MyWalletDetailMapper;
import com.github.wxiaoqi.security.admin.vo.WalletDetailAdminVo;
import com.github.wxiaoqi.security.admin.vo.WalletDetailPageVo;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
......@@ -23,6 +31,7 @@ import java.util.List;
*/
@Transactional
@Service
@Data
public class MyWalletDetailBiz extends BaseBiz<MyWalletDetailMapper, MyWalletDetail> {
......@@ -53,4 +62,36 @@ public class MyWalletDetailBiz extends BaseBiz<MyWalletDetailMapper, MyWalletDet
return walletDetailPageVo;
}
public PageDataVO<WalletDetailAdminVo> findWalletDetailPage(WalletDetailFindDTO walletDetailFindDTO){
PageDataVO<WalletDetailAdminVo> pageDataVO = new PageDataVO<>();
PageDataVO<WalletDetailListDTO> walletDetailPage = PageDataVO.pageInfo(walletDetailFindDTO.getPage(),
walletDetailFindDTO.getLimit(),
()->mapper.findWalletDetailsByUserNameOrPhoneOrsourceType(walletDetailFindDTO.getUsername(),walletDetailFindDTO.getPhone(),walletDetailFindDTO.getSource()));
List<WalletDetailListDTO> detailListDTOS = walletDetailPage.getData();
if (CollectionUtils.isEmpty(detailListDTOS)){
return pageDataVO;
}
List<WalletDetailAdminVo> walletDetailAdminVos = new ArrayList<>();
WalletDetailAdminVo walletDetailAdminVo;
for (WalletDetailListDTO detailListDTO : detailListDTOS) {
walletDetailAdminVo = new WalletDetailAdminVo();
BeanUtils.copyProperties(detailListDTO,walletDetailAdminVo);
walletDetailAdminVos.add(walletDetailAdminVo);
}
pageDataVO.setPageNum(walletDetailFindDTO.getPage());
pageDataVO.setPageSize(walletDetailFindDTO.getLimit());
pageDataVO.setTotalCount(walletDetailPage.getTotalCount());
pageDataVO.setTotalPage(walletDetailPage.getTotalPage());
pageDataVO.setData(walletDetailAdminVos);
return pageDataVO;
}
public Map<Integer, BigDecimal> finduserIdAndPersonalTotalConsumptionMapByUserIds(List<Integer> userIds) {
List<PersonalConsumptionDTO> personalConsumptions = mapper.findpersonalConsumptionsByUserIds(userIds);
Map<Integer, BigDecimal> userIdAndPersonalConsumptionMap = personalConsumptions.stream().collect(Collectors.toMap(PersonalConsumptionDTO::getUserId, PersonalConsumptionDTO::getTotalConsumption));
return userIdAndPersonalConsumptionMap;
}
}
......@@ -19,4 +19,5 @@ public interface MyWalletCathMapper extends Mapper<MyWalletCath> {
List<WalletCathListDTO> selectByUserNameOrPhoneOrWithDrawSate(@Param("userName") String userName,
@Param("phone") String phone,
@Param("state") Integer state);
}
package com.github.wxiaoqi.security.admin.mapper;
import com.github.wxiaoqi.security.admin.dto.PersonalConsumptionDTO;
import com.github.wxiaoqi.security.admin.dto.WalletDetailListDTO;
import com.github.wxiaoqi.security.admin.entity.MyWalletDetail;
import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;
/**
* 收入/支持明细表,每笔的进账,出账的详细记录
*
......@@ -11,5 +16,8 @@ import tk.mybatis.mapper.common.Mapper;
* @date 2019-07-11 14:14:54
*/
public interface MyWalletDetailMapper extends Mapper<MyWalletDetail> {
List<WalletDetailListDTO> findWalletDetailsByUserNameOrPhoneOrsourceType(@Param("userName") String userName, @Param("phone") String phone, @Param("sourceType") Integer sourceType);
List<PersonalConsumptionDTO> findpersonalConsumptionsByUserIds(@Param("userIds") List<Integer> userIds);
}
package com.github.wxiaoqi.security.admin.rest.admin;
import com.github.wxiaoqi.security.admin.biz.MyWalletDetailBiz;
import com.github.wxiaoqi.security.admin.dto.WalletDetailFindDTO;
import com.github.wxiaoqi.security.admin.vo.WalletDetailAdminVo;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
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;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/7/18 13:30
*/
@RestController
@RequestMapping("/walletdetail/admin")
public class WalletDetailAdminController {
@Autowired
private MyWalletDetailBiz myWalletDetailBiz;
@GetMapping("/page")
public ObjectRestResponse<PageDataVO<WalletDetailAdminVo>> findWalletDetailPage(WalletDetailFindDTO walletDetailFindDTO){
PageDataVO<WalletDetailAdminVo> walletDetailPage = myWalletDetailBiz.findWalletDetailPage(walletDetailFindDTO);
return ObjectRestResponse.succ(walletDetailPage);
}
}
......@@ -3,7 +3,7 @@
<mapper namespace="com.github.wxiaoqi.security.admin.mapper.MyWalletCathMapper">
<select id="selectByUserNameOrPhoneOrWithDrawSate" resultType="com.github.wxiaoqi.security.admin.dto.WalletListDTO">
<select id="selectByUserNameOrPhoneOrWithDrawSate" resultType="com.github.wxiaoqi.security.admin.dto.WalletCathListDTO">
SELECT
wc.id,
aud.nickname,
......@@ -20,10 +20,10 @@
</if>) AS `wc`
INNER JOIN ( SELECT `id`, `username` FROM `app_user_login` <if test="phone != null and phone != ''">
WHERE `username`=#{phone}
</if> ) AS `aul` ON aul.id = w.user_id
</if> ) AS `aul` ON aul.id = wc.user_id
INNER JOIN ( SELECT `userid`, `nickname`, `realname` FROM `app_user_detail` <if
test="userName != null and userName != ''">
WHERE nickname =#{username} OR realname =#{userName}
WHERE nickname =#{userName} OR realname =#{userName}
</if> ) AS `aud` ON aud.userid = aul.id
</select>
</mapper>
\ No newline at end of file
<?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.github.wxiaoqi.security.admin.mapper.MyWalletDetailMapper">
<select id="findWalletDetailsByUserNameOrPhoneOrsourceType" resultType="com.github.wxiaoqi.security.admin.dto.WalletDetailListDTO">
SELECT
wd.id,
wd.source,
wd.amount,
wd.cono,
wd.itype,
wd.activity_id AS `activityId`,
wd.activity_name AS `activityName`,
aul.username,
aud.nickname,
aud.realname,
ausw.price,
ausw.extract,
ausw.waiting,
ausw.title
FROM
(select id,user_id,source,amount,cono,itype,activity_id,activity_name FROM `my_wallet_detail` <if test="sourceType != null">
WHERE `source`=#{sourceType}
</if>) AS `wd`
LEFT JOIN (SELECT id,username FROM `app_user_login`<if test="phone != null and phone != ''">
WHERE `username`=#{phone}
</if>) AS `aul` ON aul.id = wd.user_id
LEFT JOIN (SELECT userid,nickname,realname FROM `app_user_detail`<if test="userName != null and userName != ''">
WHERE `nickname`=#{userName} OR `realname`=#{userName}
</if>) AS `aud` ON aud.userid = aul.id
LEFT JOIN (SELECT DISTINCT order_id,id,price,extract,waiting,title FROM `app_user_selling_water`) AS `ausw` ON ausw.order_id = wd.cono
</select>
<select id="findpersonalConsumptionsByUserIds" resultType="com.github.wxiaoqi.security.admin.dto.PersonalConsumptionDTO">
select `user_id` AS `userId`,SUM(amount) AS `totalConsumption` FROM my_wallet_cath <if test="userIds != null and userIds.size() != 0">
WHERE `user_id` IN
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
</if>GROUP BY user_id;
</select>
</mapper>
\ No newline at end of file
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