diff --git a/cweb/src/main/java/com/hfkj/controller/UserCountController.java b/cweb/src/main/java/com/hfkj/controller/UserCountController.java new file mode 100644 index 0000000..153a886 --- /dev/null +++ b/cweb/src/main/java/com/hfkj/controller/UserCountController.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 todayTime = DateUtil.getTodayTimeObj(); + // 昨日时间 + Map yesterdayTime = DateUtil.getYesterdayTimeObj(); + // 本月时间 + Map thisMonthTime = DateUtil.getThisMonthTimeObj(); + // 上月时间 + Map lastMonthTime = DateUtil.getLastMonthTimeObj(); + + Map 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); + } + } + + +} diff --git a/service/src/main/java/com/hfkj/dao/BsUserAccountRecordMapperExt.java b/service/src/main/java/com/hfkj/dao/BsUserAccountRecordMapperExt.java index 703f40b..61b5604 100644 --- a/service/src/main/java/com/hfkj/dao/BsUserAccountRecordMapperExt.java +++ b/service/src/main/java/com/hfkj/dao/BsUserAccountRecordMapperExt.java @@ -10,6 +10,11 @@ import java.math.BigDecimal; */ public interface BsUserAccountRecordMapperExt { - @Select("") - BigDecimal queryUserTotalProfit(@Param("userId") Long userId); + @Select("") + BigDecimal queryUserTotalProfit(@Param("userId") Long userId,@Param("timeS") String timeS,@Param("timeE") String timeE); } diff --git a/service/src/main/java/com/hfkj/service/user/BsUserAccountRecordService.java b/service/src/main/java/com/hfkj/service/user/BsUserAccountRecordService.java index d62a0fd..a00dedc 100644 --- a/service/src/main/java/com/hfkj/service/user/BsUserAccountRecordService.java +++ b/service/src/main/java/com/hfkj/service/user/BsUserAccountRecordService.java @@ -3,6 +3,7 @@ package com.hfkj.service.user; import com.hfkj.entity.BsUserAccountRecord; import java.math.BigDecimal; +import java.util.Date; import java.util.List; import java.util.Map; @@ -38,5 +39,5 @@ public interface BsUserAccountRecordService { * @param userId * @return */ - BigDecimal getUserTotalProfit(Long userId); + BigDecimal getUserTotalProfit(Long userId, Date timeS, Date timeE); } diff --git a/service/src/main/java/com/hfkj/service/user/impl/BsUserAccountRecordServiceImpl.java b/service/src/main/java/com/hfkj/service/user/impl/BsUserAccountRecordServiceImpl.java index 49dc2df..2064df9 100644 --- a/service/src/main/java/com/hfkj/service/user/impl/BsUserAccountRecordServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/user/impl/BsUserAccountRecordServiceImpl.java @@ -1,5 +1,6 @@ package com.hfkj.service.user.impl; +import com.hfkj.common.utils.DateUtil; import com.hfkj.dao.BsUserAccountRecordMapper; import com.hfkj.entity.BsUserAccountRecord; import com.hfkj.entity.BsUserAccountRecordExample; @@ -56,7 +57,19 @@ public class BsUserAccountRecordServiceImpl implements BsUserAccountRecordServic } @Override - public BigDecimal getUserTotalProfit(Long userId) { - return userAccountRecordMapper.queryUserTotalProfit(userId); + public BigDecimal getUserTotalProfit(Long userId, Date timeS, Date timeE) { + 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); } } diff --git a/service/src/main/java/com/hfkj/service/user/impl/BsUserGradeServiceImpl.java b/service/src/main/java/com/hfkj/service/user/impl/BsUserGradeServiceImpl.java index 787a941..3969910 100644 --- a/service/src/main/java/com/hfkj/service/user/impl/BsUserGradeServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/user/impl/BsUserGradeServiceImpl.java @@ -116,7 +116,7 @@ public class BsUserGradeServiceImpl implements BsUserGradeService { } // 条件二(元宝收益达到5元宝) - BigDecimal profit = userAccountRecordService.getUserTotalProfit(userId); + BigDecimal profit = userAccountRecordService.getUserTotalProfit(userId,null,null); map.put("condition2", profit); return map; @@ -137,7 +137,7 @@ public class BsUserGradeServiceImpl implements BsUserGradeService { map.put("condition2", subData.stream().filter(o -> o.getRelType().equals(2)).count()); // 条件三(累计元宝收益达到100元宝) - BigDecimal profit = userAccountRecordService.getUserTotalProfit(userId); + BigDecimal profit = userAccountRecordService.getUserTotalProfit(userId,null,null); map.put("condition3", profit); return map; @@ -159,7 +159,7 @@ public class BsUserGradeServiceImpl implements BsUserGradeService { map.put("condition2", directlyUnderData.stream().filter(o -> o.getRelType().equals(2)).count()); // 条件三(累计元宝收益达到10000元宝) - BigDecimal profit = userAccountRecordService.getUserTotalProfit(userId); + BigDecimal profit = userAccountRecordService.getUserTotalProfit(userId, null, null); map.put("condition3", profit); return map;