完成用户收益统计

master
胡锐 4 weeks ago
parent fe920d33c5
commit 7470b83bfb
  1. 89
      cweb/src/main/java/com/hfkj/controller/UserCountController.java
  2. 9
      service/src/main/java/com/hfkj/dao/BsUserAccountRecordMapperExt.java
  3. 3
      service/src/main/java/com/hfkj/service/user/BsUserAccountRecordService.java
  4. 17
      service/src/main/java/com/hfkj/service/user/impl/BsUserAccountRecordServiceImpl.java
  5. 6
      service/src/main/java/com/hfkj/service/user/impl/BsUserGradeServiceImpl.java

@ -0,0 +1,89 @@
package com.hfkj.controller;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.security.SessionObject;
import com.hfkj.common.security.UserCenter;
import com.hfkj.common.utils.DateUtil;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.entity.BsUser;
import com.hfkj.entity.BsUserAccount;
import com.hfkj.model.ResponseData;
import com.hfkj.model.UserSessionObject;
import com.hfkj.service.user.BsUserAccountRecordService;
import com.hfkj.service.user.BsUserAccountService;
import com.hfkj.service.user.BsUserGradeService;
import com.hfkj.service.user.BsUserService;
import com.hfkj.service.user.impl.BsUserServiceImpl;
import com.hfkj.sysenum.user.UserGradeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* @className: ClientController
* @author: HuRui
* @date: 2024/9/6
**/
@Controller
@RequestMapping(value="/userCount")
@Api(value="用户统计业务")
public class UserCountController {
@Autowired
private UserCenter userCenter;
@Resource
private BsUserAccountRecordService userAccountRecordService;
@Resource
private BsUserAccountService userAccountService;
@RequestMapping(value = "/income", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "收益统计")
public ResponseData income() {
try {
UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class);
// 查询用户账户
BsUserAccount account = userAccountService.getAccount(userSession.getUser().getId());
if (account == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到用户账户");
}
// 今日时间
Map<String, Date> todayTime = DateUtil.getTodayTimeObj();
// 昨日时间
Map<String, Date> yesterdayTime = DateUtil.getYesterdayTimeObj();
// 本月时间
Map<String, Date> thisMonthTime = DateUtil.getThisMonthTimeObj();
// 上月时间
Map<String, Date> lastMonthTime = DateUtil.getLastMonthTimeObj();
Map<String,Object> param = new LinkedHashMap<>();
// 当前账户元宝
param.put("goldCoin", account.getGoldCoin());
// 今日元宝收益
param.put("today", userAccountRecordService.getUserTotalProfit(userSession.getUser().getId(), todayTime.get("timeS"), todayTime.get("timeE")));
// 昨日元宝收益
param.put("yesterday", userAccountRecordService.getUserTotalProfit(userSession.getUser().getId(), yesterdayTime.get("timeS"), yesterdayTime.get("timeE")));
// 本月元宝收益
param.put("thisMonth", userAccountRecordService.getUserTotalProfit(userSession.getUser().getId(), thisMonthTime.get("timeS"), thisMonthTime.get("timeE")));
// 上月元宝收益
param.put("lastMonth", userAccountRecordService.getUserTotalProfit(userSession.getUser().getId(), lastMonthTime.get("timeS"), lastMonthTime.get("timeE")));
return ResponseMsgUtil.success(param);
} catch (Exception e) {
return ResponseMsgUtil.exception(e);
}
}
}

@ -10,6 +10,11 @@ import java.math.BigDecimal;
*/ */
public interface BsUserAccountRecordMapperExt { public interface BsUserAccountRecordMapperExt {
@Select("<script> select sum(transaction_amount) from bs_user_account_record where user_id = #{userId} and type = 1 and `status` = 1 </script>") @Select("<script> select " +
BigDecimal queryUserTotalProfit(@Param("userId") Long userId); " case when sum(transaction_amount) is null then 0 else sum(transaction_amount) end" +
" from bs_user_account_record where user_id = #{userId} and type = 1 and `status` = 1 " +
" <if test='timeS != null'> <![CDATA[ and create_time >= #{timeS} ]]> </if>" +
" <if test='timeE != null'> <![CDATA[ and create_time <= #{timeE} ]]> </if>" +
"</script>")
BigDecimal queryUserTotalProfit(@Param("userId") Long userId,@Param("timeS") String timeS,@Param("timeE") String timeE);
} }

@ -3,6 +3,7 @@ package com.hfkj.service.user;
import com.hfkj.entity.BsUserAccountRecord; import com.hfkj.entity.BsUserAccountRecord;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -38,5 +39,5 @@ public interface BsUserAccountRecordService {
* @param userId * @param userId
* @return * @return
*/ */
BigDecimal getUserTotalProfit(Long userId); BigDecimal getUserTotalProfit(Long userId, Date timeS, Date timeE);
} }

@ -1,5 +1,6 @@
package com.hfkj.service.user.impl; package com.hfkj.service.user.impl;
import com.hfkj.common.utils.DateUtil;
import com.hfkj.dao.BsUserAccountRecordMapper; import com.hfkj.dao.BsUserAccountRecordMapper;
import com.hfkj.entity.BsUserAccountRecord; import com.hfkj.entity.BsUserAccountRecord;
import com.hfkj.entity.BsUserAccountRecordExample; import com.hfkj.entity.BsUserAccountRecordExample;
@ -56,7 +57,19 @@ public class BsUserAccountRecordServiceImpl implements BsUserAccountRecordServic
} }
@Override @Override
public BigDecimal getUserTotalProfit(Long userId) { public BigDecimal getUserTotalProfit(Long userId, Date timeS, Date timeE) {
return userAccountRecordMapper.queryUserTotalProfit(userId); String timeSStr = null;
String timeEStr = null;
try {
if (timeS != null) {
timeSStr = DateUtil.date2String(timeS, DateUtil.Y_M_D_HMS);
}
if (timeE != null) {
timeEStr = DateUtil.date2String(timeE, DateUtil.Y_M_D_HMS);
}
} catch (Exception e) { }
return userAccountRecordMapper.queryUserTotalProfit(userId,timeSStr,timeEStr);
} }
} }

@ -116,7 +116,7 @@ public class BsUserGradeServiceImpl implements BsUserGradeService {
} }
// 条件二(元宝收益达到5元宝) // 条件二(元宝收益达到5元宝)
BigDecimal profit = userAccountRecordService.getUserTotalProfit(userId); BigDecimal profit = userAccountRecordService.getUserTotalProfit(userId,null,null);
map.put("condition2", profit); map.put("condition2", profit);
return map; return map;
@ -137,7 +137,7 @@ public class BsUserGradeServiceImpl implements BsUserGradeService {
map.put("condition2", subData.stream().filter(o -> o.getRelType().equals(2)).count()); map.put("condition2", subData.stream().filter(o -> o.getRelType().equals(2)).count());
// 条件三(累计元宝收益达到100元宝) // 条件三(累计元宝收益达到100元宝)
BigDecimal profit = userAccountRecordService.getUserTotalProfit(userId); BigDecimal profit = userAccountRecordService.getUserTotalProfit(userId,null,null);
map.put("condition3", profit); map.put("condition3", profit);
return map; return map;
@ -159,7 +159,7 @@ public class BsUserGradeServiceImpl implements BsUserGradeService {
map.put("condition2", directlyUnderData.stream().filter(o -> o.getRelType().equals(2)).count()); map.put("condition2", directlyUnderData.stream().filter(o -> o.getRelType().equals(2)).count());
// 条件三(累计元宝收益达到10000元宝) // 条件三(累计元宝收益达到10000元宝)
BigDecimal profit = userAccountRecordService.getUserTotalProfit(userId); BigDecimal profit = userAccountRecordService.getUserTotalProfit(userId, null, null);
map.put("condition3", profit); map.put("condition3", profit);
return map; return map;

Loading…
Cancel
Save