|
|
@@ -1,28 +1,24 @@
|
|
|
package com.txz.cif.web;
|
|
|
+
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
import com.txz.cif.core.*;
|
|
|
import com.txz.cif.core.cache.CacheKey;
|
|
|
import com.txz.cif.core.cache.CacheType;
|
|
|
import com.txz.cif.model.RedEnvelope;
|
|
|
import com.txz.cif.model.User;
|
|
|
import com.txz.cif.service.RedEnvelopeService;
|
|
|
-
|
|
|
-import com.github.pagehelper.PageHelper;
|
|
|
-import com.github.pagehelper.PageInfo;
|
|
|
import com.txz.cif.service.UserService;
|
|
|
import com.txz.cif.web.bo.TopBO;
|
|
|
-import com.txz.cif.web.bo.UserDetailBo;
|
|
|
import com.txz.cif.web.bo.UserTopBo;
|
|
|
import com.txz.cif.web.para.RedEnvelopeListParam;
|
|
|
-import com.txz.cif.web.para.RedEnvelopeParam;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import com.txz.core.ServiceException;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
-
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
import tk.mybatis.mapper.entity.Condition;
|
|
|
import tk.mybatis.mapper.entity.Example.Criteria;
|
|
|
|
|
|
@@ -33,110 +29,108 @@ import java.util.List;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
-import org.apache.commons.lang.StringUtils;
|
|
|
-
|
|
|
/**
|
|
|
-* Created by CodeGenerator on 2025/07/15.
|
|
|
-*/
|
|
|
+ * Created by CodeGenerator on 2025/07/15.
|
|
|
+ */
|
|
|
@Api(tags = "[api]redEnvelope管理")
|
|
|
@RestController
|
|
|
@RequestMapping("/api/red/envelope")
|
|
|
public class RedEnvelopeApiController {
|
|
|
-
|
|
|
- private static Logger log = LoggerFactory.getLogger(RedEnvelopeApiController.class);
|
|
|
-
|
|
|
+
|
|
|
+ private static Logger log = LoggerFactory.getLogger(RedEnvelopeApiController.class);
|
|
|
+
|
|
|
@Resource
|
|
|
private RedEnvelopeService redEnvelopeService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private AuthService authService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private RedisUtil redisUtil;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private UserService userService;
|
|
|
-
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AuthService authService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private RedisUtil redisUtil;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
@PostMapping("/list")
|
|
|
- @ApiOperation(value = "redEnvelope获取列表",httpMethod = "POST")
|
|
|
+ @ApiOperation(value = "redEnvelope获取列表", httpMethod = "POST")
|
|
|
public Result<List<RedEnvelope>> list(@RequestBody RedEnvelopeListParam param, HttpServletRequest request) {
|
|
|
- Long userId = authService.getTokenUserId(request);
|
|
|
- if (userId == null ){
|
|
|
- return ResultGenerator.genFailResult(ResultCode.OAUTH_INVALID_ACCESS_TOKEN);
|
|
|
- }
|
|
|
-
|
|
|
- PageHelper.startPage(param.getPage(), param.getSize());
|
|
|
-
|
|
|
+ Long userId = authService.getTokenUserId(request);
|
|
|
+ if (userId == null) {
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.OAUTH_INVALID_ACCESS_TOKEN);
|
|
|
+ }
|
|
|
+
|
|
|
+ PageHelper.startPage(param.getPage(), param.getSize());
|
|
|
+
|
|
|
Condition condition = new Condition(RedEnvelope.class);
|
|
|
Criteria criteria = condition.createCriteria();
|
|
|
- criteria.andEqualTo("userId",userId);
|
|
|
- if (param.getType() == 1 ){
|
|
|
- Date todayStart = DateUtil.beginOfDay(DateUtil.date());
|
|
|
- criteria.andGreaterThanOrEqualTo("createTime", todayStart);
|
|
|
- } else if (param.getType() == 2){
|
|
|
- Date yesterdayStart = DateUtil.beginOfDay(DateUtil.yesterday());
|
|
|
- Date todayStart = DateUtil.beginOfDay(DateUtil.date());
|
|
|
- criteria.andBetween("createTime", yesterdayStart,todayStart);
|
|
|
- } else if (param.getType() == 3){
|
|
|
- Date start = DateUtil.beginOfDay(DateUtil.offsetDay(DateUtil.date(),-7));
|
|
|
- criteria.andGreaterThanOrEqualTo("createTime",start);
|
|
|
- } else if (param.getType() == 4){
|
|
|
- Date start = DateUtil.beginOfMonth(DateUtil.date());
|
|
|
- criteria.andGreaterThanOrEqualTo("createTime",start);
|
|
|
- } else if (param.getType() == 5){
|
|
|
- Date start = DateUtil.beginOfYear(DateUtil.date());
|
|
|
- criteria.andGreaterThanOrEqualTo("createTime",start);
|
|
|
- }
|
|
|
- PageInfo pageInfo = null;
|
|
|
- try {
|
|
|
- condition.setOrderByClause("create_time desc");
|
|
|
- List<RedEnvelope> list = redEnvelopeService.findByCondition(condition);
|
|
|
- pageInfo = new PageInfo(list);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("查询对象操作异常e:{}",e);
|
|
|
- return ResultGenerator.genFailResult(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
- }
|
|
|
+ criteria.andEqualTo("userId", userId);
|
|
|
+ if (param.getType() == 1) {
|
|
|
+ Date todayStart = DateUtil.beginOfDay(DateUtil.date());
|
|
|
+ criteria.andGreaterThanOrEqualTo("createTime", todayStart);
|
|
|
+ } else if (param.getType() == 2) {
|
|
|
+ Date yesterdayStart = DateUtil.beginOfDay(DateUtil.yesterday());
|
|
|
+ Date todayStart = DateUtil.beginOfDay(DateUtil.date());
|
|
|
+ criteria.andBetween("createTime", yesterdayStart, todayStart);
|
|
|
+ } else if (param.getType() == 3) {
|
|
|
+ Date start = DateUtil.beginOfDay(DateUtil.offsetDay(DateUtil.date(), -7));
|
|
|
+ criteria.andGreaterThanOrEqualTo("createTime", start);
|
|
|
+ } else if (param.getType() == 4) {
|
|
|
+ Date start = DateUtil.beginOfMonth(DateUtil.date());
|
|
|
+ criteria.andGreaterThanOrEqualTo("createTime", start);
|
|
|
+ } else if (param.getType() == 5) {
|
|
|
+ Date start = DateUtil.beginOfYear(DateUtil.date());
|
|
|
+ criteria.andGreaterThanOrEqualTo("createTime", start);
|
|
|
+ }
|
|
|
+ PageInfo pageInfo = null;
|
|
|
+ try {
|
|
|
+ condition.setOrderByClause("create_time desc");
|
|
|
+ List<RedEnvelope> list = redEnvelopeService.findByCondition(condition);
|
|
|
+ pageInfo = new PageInfo(list);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询对象操作异常e:{}", e);
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
return ResultGenerator.genSuccessResult(pageInfo);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- @GetMapping("/top")
|
|
|
- @ApiOperation(value = "排行榜type 1 7天收益排行",httpMethod = "GET")
|
|
|
- public Result<TopBO> top(@RequestParam(defaultValue = "1") Integer type, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) {
|
|
|
- String key = CacheKey.generateKey(CacheType.Top4,type+":"+page+":"+size).toString();
|
|
|
- Object o = redisUtil.get(key);
|
|
|
- if (o != null){
|
|
|
- return ResultGenerator.genSuccessResult(JSONUtil.toBean(o.toString(),TopBO.class));
|
|
|
- }
|
|
|
- List<UserTopBo> tops= redEnvelopeService.top(type,page,size);
|
|
|
- PageInfo pageInfo = new PageInfo(tops);
|
|
|
- TopBO bo = new TopBO();
|
|
|
- pageInfo.setList(tops.stream().map(e->{
|
|
|
- User user = userService.findById(e.getUserId());
|
|
|
- if (user != null){
|
|
|
- e.setHeadPic(user.getHeadPic());
|
|
|
- e.setNickname(user.getNickname());
|
|
|
- e.setName(user.getName());
|
|
|
- e.setVipLevel(user.getVipLevel());
|
|
|
- e.setUserNo(user.getUserNo());
|
|
|
- }
|
|
|
- Condition c = new Condition(User.class);
|
|
|
- c.createCriteria().andEqualTo("pid",e.getUserId());
|
|
|
- Integer invited = userService.countByCondition(c);
|
|
|
- if (invited != null){
|
|
|
- e.setInviteNum(invited);
|
|
|
- }
|
|
|
- c = new Condition(User.class);
|
|
|
- c.createCriteria().andEqualTo("ppid",e.getUserId());
|
|
|
- Integer invited2 = userService.countByCondition(c);
|
|
|
- if (invited != null && invited2 != null){
|
|
|
- e.setTeamNum(invited+invited2);
|
|
|
- }
|
|
|
- return e;
|
|
|
- }).collect(Collectors.toList()));
|
|
|
- bo.setUsers(pageInfo);
|
|
|
- bo.setUpdateTime(DateUtil.date());
|
|
|
- redisUtil.set(key,JSONUtil.toJsonStr(bo),5, TimeUnit.MINUTES);
|
|
|
- return ResultGenerator.genSuccessResult(bo);
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping("/top")
|
|
|
+ @ApiOperation(value = "排行榜type 1 7天收益排行", httpMethod = "GET")
|
|
|
+ public Result<TopBO> top(@RequestParam(defaultValue = "1") Integer type, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) {
|
|
|
+ String key = CacheKey.generateKey(CacheType.Top4, type + ":" + page + ":" + size).toString();
|
|
|
+ Object o = redisUtil.get(key);
|
|
|
+ if (o != null) {
|
|
|
+ return ResultGenerator.genSuccessResult(JSONUtil.toBean(o.toString(), TopBO.class));
|
|
|
+ }
|
|
|
+ List<UserTopBo> tops = redEnvelopeService.top(type, page, size);
|
|
|
+ PageInfo pageInfo = new PageInfo(tops);
|
|
|
+ TopBO bo = new TopBO();
|
|
|
+ pageInfo.setList(tops.stream().map(e -> {
|
|
|
+ User user = userService.findById(e.getUserId());
|
|
|
+ if (user != null) {
|
|
|
+ e.setHeadPic(user.getHeadPic());
|
|
|
+ e.setNickname(user.getNickname());
|
|
|
+ e.setName(user.getName());
|
|
|
+ e.setVipLevel(user.getVipLevel());
|
|
|
+ e.setUserNo(user.getUserNo());
|
|
|
+ }
|
|
|
+ Condition c = new Condition(User.class);
|
|
|
+ c.createCriteria().andEqualTo("pid", e.getUserId());
|
|
|
+ Integer invited = userService.countByCondition(c);
|
|
|
+ if (invited != null) {
|
|
|
+ e.setInviteNum(invited);
|
|
|
+ }
|
|
|
+ c = new Condition(User.class);
|
|
|
+ c.createCriteria().andEqualTo("ppid", e.getUserId());
|
|
|
+ Integer invited2 = userService.countByCondition(c);
|
|
|
+ if (invited != null && invited2 != null) {
|
|
|
+ e.setTeamNum(invited + invited2);
|
|
|
+ }
|
|
|
+ return e;
|
|
|
+ }).collect(Collectors.toList()));
|
|
|
+ bo.setUsers(pageInfo);
|
|
|
+ bo.setUpdateTime(DateUtil.date());
|
|
|
+ redisUtil.set(key, JSONUtil.toJsonStr(bo), 5, TimeUnit.MINUTES);
|
|
|
+ return ResultGenerator.genSuccessResult(bo);
|
|
|
+ }
|
|
|
}
|