init
This commit is contained in:
@@ -1,22 +1,24 @@
|
|||||||
package com.ruoyi.cai.controller.app;
|
package com.ruoyi.cai.controller.app;
|
||||||
|
|
||||||
import com.ruoyi.cai.domain.User;
|
import com.ruoyi.cai.domain.User;
|
||||||
import com.ruoyi.cai.dto.app.vo.rank.RankLoveRemark;
|
import com.ruoyi.cai.dto.app.RankIdReq;
|
||||||
|
import com.ruoyi.cai.dto.app.vo.rank.RankRemark;
|
||||||
import com.ruoyi.cai.dto.app.vo.rank.RankNodeInvite;
|
import com.ruoyi.cai.dto.app.vo.rank.RankNodeInvite;
|
||||||
import com.ruoyi.cai.dto.app.vo.rank.RankNodeLove;
|
import com.ruoyi.cai.dto.app.vo.rank.RankNodeLove;
|
||||||
import com.ruoyi.cai.enums.GenderEnum;
|
import com.ruoyi.cai.enums.GenderEnum;
|
||||||
|
import com.ruoyi.cai.manager.AwardManager;
|
||||||
import com.ruoyi.cai.rank.RankManager;
|
import com.ruoyi.cai.rank.RankManager;
|
||||||
import com.ruoyi.cai.rank.RankNode;
|
import com.ruoyi.cai.rank.RankNode;
|
||||||
|
import com.ruoyi.cai.service.RankService;
|
||||||
import com.ruoyi.cai.service.UserService;
|
import com.ruoyi.cai.service.UserService;
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.common.helper.LoginHelper;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@@ -31,11 +33,14 @@ public class RankAppController {
|
|||||||
private RankManager rankManager;
|
private RankManager rankManager;
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
@Autowired
|
||||||
|
private RankService rankService;
|
||||||
|
@Autowired
|
||||||
|
private AwardManager awardManager;
|
||||||
|
|
||||||
@GetMapping("/loveRemark")
|
@GetMapping("/loveRemark")
|
||||||
@Operation(summary = "榜单说明")
|
@Operation(summary = "魅力榜榜单说明")
|
||||||
public R<RankLoveRemark> remark(){
|
public R<RankRemark> loveRemark(){
|
||||||
String remark =
|
String remark =
|
||||||
"(魅力上周榜排名奖励)\n" +
|
"(魅力上周榜排名奖励)\n" +
|
||||||
"第一名:888元\n" +
|
"第一名:888元\n" +
|
||||||
@@ -52,11 +57,43 @@ public class RankAppController {
|
|||||||
"第五名:38元\n" +
|
"第五名:38元\n" +
|
||||||
"第六至十名:28元\n" +
|
"第六至十名:28元\n" +
|
||||||
"提示:凡是刷魅力榜的封号,平台拥有对本次活动的最终解释权。";
|
"提示:凡是刷魅力榜的封号,平台拥有对本次活动的最终解释权。";
|
||||||
RankLoveRemark res = new RankLoveRemark();
|
RankRemark res = new RankRemark();
|
||||||
res.setRemark(remark);
|
res.setRemark(remark);
|
||||||
return R.ok(res);
|
return R.ok(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/inviteRemark")
|
||||||
|
@Operation(summary = "邀请榜榜单说明")
|
||||||
|
public R<RankRemark> inviteRemark(){
|
||||||
|
String remark =
|
||||||
|
"(邀请上周榜排名奖励)\n" +
|
||||||
|
"第一名:888元\n" +
|
||||||
|
"第二名:588元\n" +
|
||||||
|
"第三名:388元\n" +
|
||||||
|
"第四名:288元\n" +
|
||||||
|
"第五名:188元\n" +
|
||||||
|
"第六至十名:138元\n" +
|
||||||
|
"(邀请昨日榜排名奖励)\n" +
|
||||||
|
"第一名:138元\n" +
|
||||||
|
"第二名:108元\n" +
|
||||||
|
"第三名:88元\n" +
|
||||||
|
"第四名:58元\n" +
|
||||||
|
"第五名:38元\n" +
|
||||||
|
"第六至十名:28元\n" +
|
||||||
|
"提示:凡是刷邀请榜的封号,平台拥有对本次活动的最终解释权。";
|
||||||
|
RankRemark res = new RankRemark();
|
||||||
|
res.setRemark(remark);
|
||||||
|
return R.ok(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/giveRank")
|
||||||
|
@Operation(summary = "领取榜单")
|
||||||
|
public R<Void> inviteRank(@RequestBody RankIdReq rankIdReq){
|
||||||
|
Long userId = LoginHelper.getUserId();
|
||||||
|
awardManager.giveRank(rankIdReq.getRankId(),userId);
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/love")
|
@GetMapping("/love")
|
||||||
@Operation(summary = "魅力榜")
|
@Operation(summary = "魅力榜")
|
||||||
public R<List<RankNodeLove>> loveRank(
|
public R<List<RankNodeLove>> loveRank(
|
||||||
@@ -66,9 +103,9 @@ public class RankAppController {
|
|||||||
}
|
}
|
||||||
List<RankNode> rankNodeList;
|
List<RankNode> rankNodeList;
|
||||||
if(type == 1){
|
if(type == 1){
|
||||||
rankNodeList = rankManager.getLoveRankLastWeek(10);
|
rankNodeList = rankService.getLoveRankLastWeek(10);
|
||||||
}else if(type == 2){
|
}else if(type == 2){
|
||||||
rankNodeList = rankManager.getLoveRankLastDay(10);
|
rankNodeList = rankService.getLoveRankLastDay(10);
|
||||||
}else if(type == 3){
|
}else if(type == 3){
|
||||||
rankNodeList = rankManager.getLoveRankToday(30);
|
rankNodeList = rankManager.getLoveRankToday(30);
|
||||||
}else if(type == 4){
|
}else if(type == 4){
|
||||||
@@ -99,6 +136,8 @@ public class RankAppController {
|
|||||||
love.setAvatar(user.getAvatar());
|
love.setAvatar(user.getAvatar());
|
||||||
love.setNickname(user.getNickname());
|
love.setNickname(user.getNickname());
|
||||||
love.setValue(rankNode.getScore());
|
love.setValue(rankNode.getScore());
|
||||||
|
love.setDraw(rankNode.getDraw());
|
||||||
|
love.setRankId(rankNode.getRankId());
|
||||||
love.setHide(false);
|
love.setHide(false);
|
||||||
if(i == 0){
|
if(i == 0){
|
||||||
love.setDiffLastValue(0L);
|
love.setDiffLastValue(0L);
|
||||||
@@ -120,9 +159,9 @@ public class RankAppController {
|
|||||||
}
|
}
|
||||||
List<RankNode> rankNodeList;
|
List<RankNode> rankNodeList;
|
||||||
if(type == 1){
|
if(type == 1){
|
||||||
rankNodeList = rankManager.getInviteRankLastWeek(10);
|
rankNodeList = rankService.getInviteRankLastWeek(10);
|
||||||
}else if(type == 2){
|
}else if(type == 2){
|
||||||
rankNodeList = rankManager.getInviteRankLastDay(10);
|
rankNodeList = rankService.getInviteRankLastDay(10);
|
||||||
}else if(type == 3){
|
}else if(type == 3){
|
||||||
rankNodeList = rankManager.getInviteRankToday(30);
|
rankNodeList = rankManager.getInviteRankToday(30);
|
||||||
}else if(type == 4){
|
}else if(type == 4){
|
||||||
@@ -152,6 +191,8 @@ public class RankAppController {
|
|||||||
invite.setAvatar(GenderEnum.WOMEN.getDefaultAvatar());
|
invite.setAvatar(GenderEnum.WOMEN.getDefaultAvatar());
|
||||||
invite.setNickname(minNickname(user.getNickname()));
|
invite.setNickname(minNickname(user.getNickname()));
|
||||||
invite.setValue(rankNode.getScore());
|
invite.setValue(rankNode.getScore());
|
||||||
|
invite.setDraw(rankNode.getDraw());
|
||||||
|
invite.setRankId(rankNode.getRankId());
|
||||||
if(i == 0){
|
if(i == 0){
|
||||||
invite.setDiffLastValue(0L);
|
invite.setDiffLastValue(0L);
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class Rank implements Serializable {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@TableId(value = "id")
|
@TableId(value = "id")
|
||||||
private Integer id;
|
private Long id;
|
||||||
/**
|
/**
|
||||||
* 类型 1-魅力榜 2-邀请榜
|
* 类型 1-魅力榜 2-邀请榜
|
||||||
*/
|
*/
|
||||||
@@ -43,6 +43,7 @@ public class Rank implements Serializable {
|
|||||||
private LocalDate rankBeginTime;
|
private LocalDate rankBeginTime;
|
||||||
private LocalDate rankEndTime;
|
private LocalDate rankEndTime;
|
||||||
private Integer orderRank;
|
private Integer orderRank;
|
||||||
|
private Long traceId;
|
||||||
/**
|
/**
|
||||||
* 数值
|
* 数值
|
||||||
*/
|
*/
|
||||||
@@ -54,5 +55,5 @@ public class Rank implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 是否领取奖励
|
* 是否领取奖励
|
||||||
*/
|
*/
|
||||||
private boolean draw;
|
private Boolean draw;
|
||||||
}
|
}
|
||||||
|
|||||||
13
ruoyi-cai/src/main/java/com/ruoyi/cai/dto/app/RankIdReq.java
Normal file
13
ruoyi-cai/src/main/java/com/ruoyi/cai/dto/app/RankIdReq.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package com.ruoyi.cai.dto.app;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class RankIdReq {
|
||||||
|
@Schema(description = "rankId")
|
||||||
|
@NotNull(message = "参数异常")
|
||||||
|
private Long rankId;
|
||||||
|
}
|
||||||
@@ -14,6 +14,8 @@ public class RankNodeInvite {
|
|||||||
private Long value;
|
private Long value;
|
||||||
@Schema(description = "距离上一名差距")
|
@Schema(description = "距离上一名差距")
|
||||||
private Long diffLastValue;
|
private Long diffLastValue;
|
||||||
@Schema(description = "是否已经领取奖励(该字段仅限昨日榜单有用)")
|
@Schema(description = "是否已经领取奖励(该字段仅限昨日榜单,上周榜单有用)")
|
||||||
private boolean draw = true;
|
private boolean draw = true;
|
||||||
|
@Schema(description = "榜单ID,领取榜单使用")
|
||||||
|
private Long rankId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ public class RankNodeLove {
|
|||||||
private Long diffLastValue;
|
private Long diffLastValue;
|
||||||
@Schema(description = "是否开启隐身模式")
|
@Schema(description = "是否开启隐身模式")
|
||||||
private boolean hide;
|
private boolean hide;
|
||||||
@Schema(description = "是否已经领取奖励(该字段仅限昨日榜单有用)")
|
@Schema(description = "是否已经领取奖励(该字段仅限昨日榜单,上周榜单有用)")
|
||||||
private boolean draw = true;
|
private boolean draw = true;
|
||||||
|
@Schema(description = "榜单ID,领取榜单使用")
|
||||||
|
private Long rankId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.ruoyi.cai.dto.app.vo.rank;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class RankLoveRemark {
|
public class RankRemark {
|
||||||
|
|
||||||
private String remark;
|
private String remark;
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,10 @@ import lombok.Getter;
|
|||||||
* @author ZL
|
* @author ZL
|
||||||
*/
|
*/
|
||||||
public enum SystemConfigEnum {
|
public enum SystemConfigEnum {
|
||||||
|
RANK_LOVE_DAY_AWARD("138,,108,88,58,38,28,28,28,28,28,28", "魅力榜日榜奖励",SystemConfigGroupEnum.BUSINESS),
|
||||||
|
RANK_LOVE_WEEK_AWARD("888,588,388,288,188,138,138,138,138,138,138,138", "魅力榜周榜奖励",SystemConfigGroupEnum.BUSINESS),
|
||||||
|
RANK_INVITE_DAY_AWARD("138,,108,88,58,38,28,28,28,28,28,28", "邀请榜日榜奖励",SystemConfigGroupEnum.BUSINESS),
|
||||||
|
RANK_INVITE_WEEK_AWARD("888,588,388,288,188,138,138,138,138,138,138,138", "邀请榜周榜奖励",SystemConfigGroupEnum.BUSINESS),
|
||||||
REGISTER_AWARD("88", "注册奖励",SystemConfigGroupEnum.BUSINESS),
|
REGISTER_AWARD("88", "注册奖励",SystemConfigGroupEnum.BUSINESS),
|
||||||
FAST_PAY_AWARD("300", "首充奖励",SystemConfigGroupEnum.BUSINESS),
|
FAST_PAY_AWARD("300", "首充奖励",SystemConfigGroupEnum.BUSINESS),
|
||||||
GUARD_PRICE("1314", "守护价格",SystemConfigGroupEnum.BUSINESS),
|
GUARD_PRICE("1314", "守护价格",SystemConfigGroupEnum.BUSINESS),
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public enum AccountChangeCodeEnum {
|
|||||||
GIFT_INVITE(504,AccountCateEnum.SYSTEM,"邀请奖励(礼物)",AccountTypeEnum.INCOME_COIN,"",true),
|
GIFT_INVITE(504,AccountCateEnum.SYSTEM,"邀请奖励(礼物)",AccountTypeEnum.INCOME_COIN,"",true),
|
||||||
GUARD_INVITE(505,AccountCateEnum.SYSTEM,"邀请奖励(守护)",AccountTypeEnum.INCOME_COIN,"",true),
|
GUARD_INVITE(505,AccountCateEnum.SYSTEM,"邀请奖励(守护)",AccountTypeEnum.INCOME_COIN,"",true),
|
||||||
REGISTER_AWARD(506,AccountCateEnum.SYSTEM,"注册奖励",AccountTypeEnum.INCOME_COIN,"",null),
|
REGISTER_AWARD(506,AccountCateEnum.SYSTEM,"注册奖励",AccountTypeEnum.INCOME_COIN,"",null),
|
||||||
RAKE_AWARD(507,AccountCateEnum.SYSTEM,"排行榜奖励",AccountTypeEnum.INCOME_COIN,"",null),
|
RANK_AWARD(507,AccountCateEnum.SYSTEM,"排行榜奖励",AccountTypeEnum.INCOME_COIN,"",null),
|
||||||
|
|
||||||
IM_INCOME(701,AccountCateEnum.IM,"收到私信",AccountTypeEnum.INCOME_COIN,"",true),
|
IM_INCOME(701,AccountCateEnum.IM,"收到私信",AccountTypeEnum.INCOME_COIN,"",true),
|
||||||
IM_COIN_OUT(702,AccountCateEnum.IM,"私信支出",AccountTypeEnum.COIN,"",false),
|
IM_COIN_OUT(702,AccountCateEnum.IM,"私信支出",AccountTypeEnum.COIN,"",false),
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.ruoyi.cai.manager;
|
|||||||
|
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.ruoyi.cai.domain.Rank;
|
||||||
import com.ruoyi.cai.domain.User;
|
import com.ruoyi.cai.domain.User;
|
||||||
import com.ruoyi.cai.domain.UserInfo;
|
import com.ruoyi.cai.domain.UserInfo;
|
||||||
import com.ruoyi.cai.enums.SystemConfigEnum;
|
import com.ruoyi.cai.enums.SystemConfigEnum;
|
||||||
@@ -9,8 +10,11 @@ import com.ruoyi.cai.enums.account.AccountChangeCodeEnum;
|
|||||||
import com.ruoyi.cai.executor.ExecutorConstant;
|
import com.ruoyi.cai.executor.ExecutorConstant;
|
||||||
import com.ruoyi.cai.mapper.AccountMapper;
|
import com.ruoyi.cai.mapper.AccountMapper;
|
||||||
import com.ruoyi.cai.service.AccountChangeLogService;
|
import com.ruoyi.cai.service.AccountChangeLogService;
|
||||||
|
import com.ruoyi.cai.service.RankService;
|
||||||
import com.ruoyi.cai.service.UserInfoService;
|
import com.ruoyi.cai.service.UserInfoService;
|
||||||
import com.ruoyi.cai.service.UserService;
|
import com.ruoyi.cai.service.UserService;
|
||||||
|
import com.ruoyi.cai.util.CaiDateUtil;
|
||||||
|
import com.ruoyi.common.exception.ServiceException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.BooleanUtils;
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -18,6 +22,7 @@ import org.springframework.stereotype.Component;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -33,6 +38,8 @@ public class AwardManager {
|
|||||||
private UserService userService;
|
private UserService userService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserInfoService userInfoService;
|
private UserInfoService userInfoService;
|
||||||
|
@Autowired
|
||||||
|
private RankService rankService;
|
||||||
|
|
||||||
public void giveRegisterAsync(Long userId){
|
public void giveRegisterAsync(Long userId){
|
||||||
AwardManager bean = SpringUtil.getBean(AwardManager.class);
|
AwardManager bean = SpringUtil.getBean(AwardManager.class);
|
||||||
@@ -89,4 +96,31 @@ public class AwardManager {
|
|||||||
accountMapper.incsIncomeCoin(userId,price);
|
accountMapper.incsIncomeCoin(userId,price);
|
||||||
accountChangeLogService.saveLogNoAdmin(user.getId(),user.getUsercode(), AccountChangeCodeEnum.FAST_PAY_AWARD,price,traceId);
|
accountChangeLogService.saveLogNoAdmin(user.getId(),user.getUsercode(), AccountChangeCodeEnum.FAST_PAY_AWARD,price,traceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void giveRank(Long rankId,Long userId){
|
||||||
|
Rank rank = rankService.getById(rankId);
|
||||||
|
if(rank == null){
|
||||||
|
throw new ServiceException("领取失败,奖励不存在");
|
||||||
|
}
|
||||||
|
if(!rank.getUserId().equals(userId)){
|
||||||
|
throw new ServiceException("只能领取自己的奖励哦");
|
||||||
|
}
|
||||||
|
if(rank.getOrderRank() > 10){
|
||||||
|
throw new ServiceException("只有前10名可以领取奖励");
|
||||||
|
}
|
||||||
|
if(rank.getDataType().equals(1)){ // 日榜
|
||||||
|
LocalDate lastDay = LocalDate.now().plusDays(-1);
|
||||||
|
if(!rank.getRankBeginTime().equals(lastDay)){
|
||||||
|
throw new ServiceException("领奖时间已过");
|
||||||
|
}
|
||||||
|
rankService.giveRank(rankId);
|
||||||
|
}else if(rank.getDataType().equals(2)){ // 周榜
|
||||||
|
LocalDate date = CaiDateUtil.getLastWeekOne(LocalDate.now());
|
||||||
|
if(!rank.getRankBeginTime().equals(date)){
|
||||||
|
throw new ServiceException("领奖时间已过");
|
||||||
|
}
|
||||||
|
rankService.giveRank(rankId);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import org.redisson.client.protocol.ScoredEntry;
|
|||||||
public class RankNode {
|
public class RankNode {
|
||||||
private Long score;
|
private Long score;
|
||||||
private Long userId;
|
private Long userId;
|
||||||
|
private Long rankId;
|
||||||
|
private Boolean draw;
|
||||||
|
|
||||||
public RankNode() {
|
public RankNode() {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ package com.ruoyi.cai.service;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.ruoyi.cai.domain.Rank;
|
import com.ruoyi.cai.domain.Rank;
|
||||||
|
import com.ruoyi.cai.rank.RankNode;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 榜单Service接口
|
* 榜单Service接口
|
||||||
@@ -18,4 +20,14 @@ public interface RankService extends IService<Rank> {
|
|||||||
void saveWeekRank(LocalDate date,Integer type);
|
void saveWeekRank(LocalDate date,Integer type);
|
||||||
|
|
||||||
void saveMonthRank(LocalDate date,Integer type);
|
void saveMonthRank(LocalDate date,Integer type);
|
||||||
|
|
||||||
|
void giveRank(Long rankId);
|
||||||
|
|
||||||
|
List<RankNode> getLoveRankLastWeek(int limit);
|
||||||
|
|
||||||
|
List<RankNode> getLoveRankLastDay(int limit);
|
||||||
|
|
||||||
|
List<RankNode> getInviteRankLastWeek(int limit);
|
||||||
|
|
||||||
|
List<RankNode> getInviteRankLastDay(int limit);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,37 @@
|
|||||||
package com.ruoyi.cai.service.impl;
|
package com.ruoyi.cai.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.ruoyi.cai.domain.Rank;
|
import com.ruoyi.cai.domain.Rank;
|
||||||
|
import com.ruoyi.cai.domain.User;
|
||||||
|
import com.ruoyi.cai.enums.SystemConfigEnum;
|
||||||
|
import com.ruoyi.cai.enums.account.AccountChangeCodeEnum;
|
||||||
|
import com.ruoyi.cai.manager.IdManager;
|
||||||
|
import com.ruoyi.cai.manager.SystemConfigManager;
|
||||||
|
import com.ruoyi.cai.mapper.AccountMapper;
|
||||||
import com.ruoyi.cai.mapper.RankMapper;
|
import com.ruoyi.cai.mapper.RankMapper;
|
||||||
import com.ruoyi.cai.rank.RankManager;
|
import com.ruoyi.cai.rank.RankManager;
|
||||||
import com.ruoyi.cai.rank.RankNode;
|
import com.ruoyi.cai.rank.RankNode;
|
||||||
|
import com.ruoyi.cai.service.AccountChangeLogService;
|
||||||
import com.ruoyi.cai.service.RankService;
|
import com.ruoyi.cai.service.RankService;
|
||||||
import com.ruoyi.cai.service.UserService;
|
import com.ruoyi.cai.service.UserService;
|
||||||
|
import com.ruoyi.cai.util.CaiDateUtil;
|
||||||
import com.ruoyi.common.exception.ServiceException;
|
import com.ruoyi.common.exception.ServiceException;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 榜单Service业务层处理
|
* 榜单Service业务层处理
|
||||||
@@ -36,6 +48,12 @@ public class RankServiceImpl extends ServiceImpl<RankMapper,Rank> implements Ran
|
|||||||
private RankManager rankManager;
|
private RankManager rankManager;
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
@Resource
|
||||||
|
private AccountMapper accountMapper;
|
||||||
|
@Autowired
|
||||||
|
private SystemConfigManager systemConfigManager;
|
||||||
|
@Autowired
|
||||||
|
private AccountChangeLogService accountChangeLogService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveDayRank(LocalDate date, Integer type) {
|
public void saveDayRank(LocalDate date, Integer type) {
|
||||||
@@ -190,4 +208,127 @@ public class RankServiceImpl extends ServiceImpl<RankMapper,Rank> implements Ran
|
|||||||
lock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void giveRank(Long rankId) {
|
||||||
|
Rank rank = this.getById(rankId);
|
||||||
|
if(rank == null){
|
||||||
|
throw new ServiceException("领取失败,请联系客服");
|
||||||
|
}
|
||||||
|
User user = userService.getById(rank.getUserId());
|
||||||
|
if(user == null){
|
||||||
|
throw new ServiceException("用户不存在");
|
||||||
|
}
|
||||||
|
List<String> priceList = null;
|
||||||
|
if(rank.getType().equals(1)){ // 魅力
|
||||||
|
if(rank.getDataType().equals(1)){
|
||||||
|
priceList = systemConfigManager.getSystemConfigOfList(SystemConfigEnum.RANK_LOVE_DAY_AWARD);
|
||||||
|
}else if(rank.getDataType().equals(2)){
|
||||||
|
priceList = systemConfigManager.getSystemConfigOfList(SystemConfigEnum.RANK_LOVE_WEEK_AWARD);
|
||||||
|
}
|
||||||
|
}else if(rank.getType().equals(2)){ // 邀请
|
||||||
|
if(rank.getDataType().equals(1)){
|
||||||
|
priceList = systemConfigManager.getSystemConfigOfList(SystemConfigEnum.RANK_INVITE_DAY_AWARD);
|
||||||
|
}else if(rank.getDataType().equals(2)){
|
||||||
|
priceList = systemConfigManager.getSystemConfigOfList(SystemConfigEnum.RANK_INVITE_WEEK_AWARD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(priceList == null){
|
||||||
|
throw new ServiceException("领取失败,请联系客服");
|
||||||
|
}
|
||||||
|
Long traceId = IdManager.nextId();
|
||||||
|
boolean update = this.update(Wrappers.lambdaUpdate(Rank.class)
|
||||||
|
.eq(Rank::getId, rankId)
|
||||||
|
.eq(Rank::getDraw, false)
|
||||||
|
.set(Rank::getTraceId,traceId)
|
||||||
|
.set(Rank::getDraw, true));
|
||||||
|
if(!update){
|
||||||
|
throw new ServiceException("您已经领取奖励哦");
|
||||||
|
}
|
||||||
|
String priceStr = priceList.get(rank.getOrderRank() - 1);
|
||||||
|
Long price = Long.valueOf(priceStr);
|
||||||
|
accountMapper.incsIncomeCoin(rank.getUserId(),price);
|
||||||
|
accountChangeLogService.saveLogNoAdmin(user.getId(),user.getUsercode(), AccountChangeCodeEnum.RANK_AWARD,price,traceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<RankNode> getLoveRankLastWeek(int limit) {
|
||||||
|
LocalDate beginDate = CaiDateUtil.getLastWeekOne(LocalDate.now());
|
||||||
|
List<Rank> list = this.list(Wrappers.lambdaQuery(Rank.class)
|
||||||
|
.eq(Rank::getRankBeginTime, beginDate)
|
||||||
|
.eq(Rank::getType, 1)
|
||||||
|
.eq(Rank::getDataType, 2)
|
||||||
|
.le(Rank::getOrderRank,limit)
|
||||||
|
.orderByDesc(Rank::getOrderRank)
|
||||||
|
.last("limit " + limit));
|
||||||
|
return list.stream().map(i -> {
|
||||||
|
RankNode rankNode = new RankNode();
|
||||||
|
rankNode.setScore(i.getNum());
|
||||||
|
rankNode.setUserId(i.getUserId());
|
||||||
|
rankNode.setRankId(i.getId());
|
||||||
|
rankNode.setDraw(i.getDraw());
|
||||||
|
return rankNode;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<RankNode> getLoveRankLastDay(int limit) {
|
||||||
|
LocalDate beginDate = LocalDate.now().plusDays(-1);
|
||||||
|
List<Rank> list = this.list(Wrappers.lambdaQuery(Rank.class)
|
||||||
|
.eq(Rank::getRankBeginTime, beginDate)
|
||||||
|
.eq(Rank::getType, 1)
|
||||||
|
.eq(Rank::getDataType, 1)
|
||||||
|
.le(Rank::getOrderRank,limit)
|
||||||
|
.orderByDesc(Rank::getOrderRank)
|
||||||
|
.last("limit " + limit));
|
||||||
|
return list.stream().map(i -> {
|
||||||
|
RankNode rankNode = new RankNode();
|
||||||
|
rankNode.setScore(i.getNum());
|
||||||
|
rankNode.setUserId(i.getUserId());
|
||||||
|
rankNode.setRankId(i.getId());
|
||||||
|
rankNode.setDraw(i.getDraw());
|
||||||
|
return rankNode;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<RankNode> getInviteRankLastWeek(int limit) {
|
||||||
|
LocalDate beginDate = CaiDateUtil.getLastWeekOne(LocalDate.now());
|
||||||
|
List<Rank> list = this.list(Wrappers.lambdaQuery(Rank.class)
|
||||||
|
.eq(Rank::getRankBeginTime, beginDate)
|
||||||
|
.eq(Rank::getType, 2)
|
||||||
|
.eq(Rank::getDataType, 2)
|
||||||
|
.le(Rank::getOrderRank,limit)
|
||||||
|
.orderByDesc(Rank::getOrderRank)
|
||||||
|
.last("limit " + limit));
|
||||||
|
return list.stream().map(i -> {
|
||||||
|
RankNode rankNode = new RankNode();
|
||||||
|
rankNode.setScore(i.getNum());
|
||||||
|
rankNode.setUserId(i.getUserId());
|
||||||
|
rankNode.setRankId(i.getId());
|
||||||
|
rankNode.setDraw(i.getDraw());
|
||||||
|
return rankNode;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<RankNode> getInviteRankLastDay(int limit) {
|
||||||
|
LocalDate beginDate = LocalDate.now().plusDays(-1);
|
||||||
|
List<Rank> list = this.list(Wrappers.lambdaQuery(Rank.class)
|
||||||
|
.eq(Rank::getRankBeginTime, beginDate)
|
||||||
|
.eq(Rank::getType, 2)
|
||||||
|
.eq(Rank::getDataType, 1)
|
||||||
|
.le(Rank::getOrderRank,limit)
|
||||||
|
.orderByDesc(Rank::getOrderRank)
|
||||||
|
.last("limit " + limit));
|
||||||
|
return list.stream().map(i -> {
|
||||||
|
RankNode rankNode = new RankNode();
|
||||||
|
rankNode.setScore(i.getNum());
|
||||||
|
rankNode.setUserId(i.getUserId());
|
||||||
|
rankNode.setRankId(i.getId());
|
||||||
|
rankNode.setDraw(i.getDraw());
|
||||||
|
return rankNode;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
22
ruoyi-cai/src/main/java/com/ruoyi/cai/util/CaiDateUtil.java
Normal file
22
ruoyi-cai/src/main/java/com/ruoyi/cai/util/CaiDateUtil.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package com.ruoyi.cai.util;
|
||||||
|
|
||||||
|
|
||||||
|
import java.time.DayOfWeek;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.time.temporal.TemporalAdjusters;
|
||||||
|
|
||||||
|
public class CaiDateUtil {
|
||||||
|
|
||||||
|
|
||||||
|
public static LocalDate getLastWeekOne(LocalDate date){
|
||||||
|
return date.plusWeeks(-1)
|
||||||
|
.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
LocalDate one = getLastWeekOne(LocalDate.now());
|
||||||
|
System.out.println(one.format(DateTimeFormatter.ofPattern("yyyyMMdd")));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user