init
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
package com.ruoyi.cai.controller.admin;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.ruoyi.cai.domain.Rank;
|
||||
import com.ruoyi.cai.service.RankService;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.PageQuery;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 榜单
|
||||
*
|
||||
* @author 77
|
||||
* @date 2024-01-20
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/cai/rank")
|
||||
public class RankController extends BaseController {
|
||||
|
||||
private final RankService rankService;
|
||||
|
||||
/**
|
||||
* 查询榜单列表
|
||||
*/
|
||||
@SaCheckPermission("cai:rank:list")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo<Rank> list(Rank bo, PageQuery pageQuery) {
|
||||
Page<Rank> page = rankService.page(pageQuery.build(), Wrappers.lambdaQuery(bo));
|
||||
return TableDataInfo.build(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取榜单详细信息
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@SaCheckPermission("cai:rank:query")
|
||||
@GetMapping("/{id}")
|
||||
public R<Rank> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Integer id) {
|
||||
return R.ok(rankService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除榜单
|
||||
*
|
||||
* @param ids 主键串
|
||||
*/
|
||||
@SaCheckPermission("cai:rank:remove")
|
||||
@Log(title = "榜单", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
||||
@PathVariable Integer[] ids) {
|
||||
return toAjax(rankService.removeBatchByIds(Arrays.asList(ids)));
|
||||
}
|
||||
}
|
||||
58
ruoyi-cai/src/main/java/com/ruoyi/cai/domain/Rank.java
Normal file
58
ruoyi-cai/src/main/java/com/ruoyi/cai/domain/Rank.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package com.ruoyi.cai.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Date;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 榜单对象 cai_rank
|
||||
*
|
||||
* @author 77
|
||||
* @date 2024-01-20
|
||||
*/
|
||||
@Data
|
||||
@TableName("cai_rank")
|
||||
public class Rank implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableId(value = "id")
|
||||
private Integer id;
|
||||
/**
|
||||
* 类型 1-魅力榜 2-邀请榜
|
||||
*/
|
||||
private Integer type;
|
||||
/**
|
||||
* 日期类型 1-日榜 2-周榜 3-月榜
|
||||
*/
|
||||
private Integer dataType;
|
||||
/**
|
||||
* 榜单期数
|
||||
*/
|
||||
private String rankTime;
|
||||
|
||||
private LocalDate rankBeginTime;
|
||||
private LocalDate rankEndTime;
|
||||
private Integer orderRank;
|
||||
/**
|
||||
* 数值
|
||||
*/
|
||||
private Long num;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Long userId;
|
||||
/**
|
||||
* 是否领取奖励
|
||||
*/
|
||||
private boolean draw;
|
||||
}
|
||||
14
ruoyi-cai/src/main/java/com/ruoyi/cai/mapper/RankMapper.java
Normal file
14
ruoyi-cai/src/main/java/com/ruoyi/cai/mapper/RankMapper.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.ruoyi.cai.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.ruoyi.cai.domain.Rank;
|
||||
|
||||
/**
|
||||
* 榜单Mapper接口
|
||||
*
|
||||
* @author 77
|
||||
* @date 2024-01-20
|
||||
*/
|
||||
public interface RankMapper extends BaseMapper<Rank> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.ruoyi.cai.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.ruoyi.cai.domain.Rank;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* 榜单Service接口
|
||||
*
|
||||
* @author 77
|
||||
* @date 2024-01-20
|
||||
*/
|
||||
public interface RankService extends IService<Rank> {
|
||||
|
||||
void saveDayRank(LocalDate date,Integer type);
|
||||
|
||||
void saveWeekRank(LocalDate date,Integer type);
|
||||
|
||||
void saveMonthRank(LocalDate date,Integer type);
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
package com.ruoyi.cai.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ruoyi.cai.domain.Rank;
|
||||
import com.ruoyi.cai.mapper.RankMapper;
|
||||
import com.ruoyi.cai.rank.RankManager;
|
||||
import com.ruoyi.cai.rank.RankNode;
|
||||
import com.ruoyi.cai.service.RankService;
|
||||
import com.ruoyi.cai.service.UserService;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
/**
|
||||
* 榜单Service业务层处理
|
||||
*
|
||||
* @author 77
|
||||
* @date 2024-01-20
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
@Slf4j
|
||||
public class RankServiceImpl extends ServiceImpl<RankMapper,Rank> implements RankService {
|
||||
|
||||
@Autowired
|
||||
private RankManager rankManager;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Override
|
||||
public void saveDayRank(LocalDate date, Integer type) {
|
||||
List<RankNode> rank;
|
||||
if(type == 1){
|
||||
rank = rankManager.getLoveRankDay(date, 30);
|
||||
}else if(type == 2){
|
||||
rank = rankManager.getInviteRankDay(date, 30);
|
||||
}else{
|
||||
throw new ServiceException("type 参数错误");
|
||||
}
|
||||
if(CollectionUtil.isEmpty(rank)){
|
||||
return;
|
||||
}
|
||||
boolean exists = this.exists(Wrappers.lambdaQuery(Rank.class)
|
||||
.eq(Rank::getType, type)
|
||||
.eq(Rank::getRankBeginTime, date));
|
||||
if(exists){
|
||||
log.error("本期榜单已经持久化 date={},type={}",date,type);
|
||||
return;
|
||||
}
|
||||
ReentrantLock lock = new ReentrantLock();
|
||||
try {
|
||||
lock.lock();
|
||||
exists = this.exists(Wrappers.lambdaQuery(Rank.class)
|
||||
.eq(Rank::getType, type)
|
||||
.eq(Rank::getRankBeginTime, date));
|
||||
if(exists){
|
||||
log.error("本期榜单已经持久化 date={},type={}",date,type);
|
||||
return;
|
||||
}
|
||||
List<Rank> res = new ArrayList<>();
|
||||
for (int i = 0; i < rank.size(); i++) {
|
||||
RankNode rankNode = rank.get(i);
|
||||
Rank db = new Rank();
|
||||
db.setType(type);
|
||||
db.setDataType(1);
|
||||
db.setRankTime(date.format(DateTimeFormatter.ofPattern("yyyyMMdd")));
|
||||
db.setRankBeginTime(date);
|
||||
db.setRankEndTime(date);
|
||||
db.setOrderRank(i+1);
|
||||
db.setNum(rankNode.getScore());
|
||||
db.setUserId(rankNode.getUserId());
|
||||
res.add(db);
|
||||
}
|
||||
this.saveBatch(res);
|
||||
}finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveWeekRank(LocalDate date, Integer type) {
|
||||
List<RankNode> rank;
|
||||
if(type == 1){
|
||||
rank = rankManager.getLoveRankWeek(date, 30);
|
||||
}else if(type == 2){
|
||||
rank = rankManager.getInviteRankWeek(date, 30);
|
||||
}else{
|
||||
throw new ServiceException("type 参数错误");
|
||||
}
|
||||
if(CollectionUtil.isEmpty(rank)){
|
||||
return;
|
||||
}
|
||||
boolean exists = this.exists(Wrappers.lambdaQuery(Rank.class)
|
||||
.eq(Rank::getType, type)
|
||||
.eq(Rank::getRankBeginTime, date));
|
||||
if(exists){
|
||||
log.error("本期榜单已经持久化 date={},type={}",date,type);
|
||||
return;
|
||||
}
|
||||
ReentrantLock lock = new ReentrantLock();
|
||||
try {
|
||||
lock.lock();
|
||||
exists = this.exists(Wrappers.lambdaQuery(Rank.class)
|
||||
.eq(Rank::getType, type)
|
||||
.eq(Rank::getRankBeginTime, date));
|
||||
if(exists){
|
||||
log.error("本期榜单已经持久化 date={},type={}",date,type);
|
||||
return;
|
||||
}
|
||||
List<Rank> res = new ArrayList<>();
|
||||
LocalDate endDate = date.plusDays(7);
|
||||
String rankTime = date.format(DateTimeFormatter.ofPattern("yyyyMMdd")) +"-"+endDate.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
||||
for (int i = 0; i < rank.size(); i++) {
|
||||
RankNode rankNode = rank.get(i);
|
||||
Rank db = new Rank();
|
||||
db.setType(type);
|
||||
db.setDataType(2);
|
||||
db.setRankTime(rankTime);
|
||||
db.setRankBeginTime(date);
|
||||
db.setRankEndTime(endDate);
|
||||
db.setOrderRank(i+1);
|
||||
db.setNum(rankNode.getScore());
|
||||
db.setUserId(rankNode.getUserId());
|
||||
res.add(db);
|
||||
}
|
||||
this.saveBatch(res);
|
||||
}finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveMonthRank(LocalDate date, Integer type) {
|
||||
List<RankNode> rank;
|
||||
if(type == 1){
|
||||
rank = rankManager.getLoveRankDay(date, 30);
|
||||
}else if(type == 2){
|
||||
rank = rankManager.getInviteRankDay(date, 30);
|
||||
}else{
|
||||
throw new ServiceException("type 参数错误");
|
||||
}
|
||||
if(CollectionUtil.isEmpty(rank)){
|
||||
return;
|
||||
}
|
||||
boolean exists = this.exists(Wrappers.lambdaQuery(Rank.class)
|
||||
.eq(Rank::getType, type)
|
||||
.eq(Rank::getRankBeginTime, date));
|
||||
if(exists){
|
||||
log.error("本期榜单已经持久化 date={},type={}",date,type);
|
||||
return;
|
||||
}
|
||||
ReentrantLock lock = new ReentrantLock();
|
||||
try {
|
||||
lock.lock();
|
||||
exists = this.exists(Wrappers.lambdaQuery(Rank.class)
|
||||
.eq(Rank::getType, type)
|
||||
.eq(Rank::getRankBeginTime, date));
|
||||
if(exists){
|
||||
log.error("本期榜单已经持久化 date={},type={}",date,type);
|
||||
return;
|
||||
}
|
||||
LocalDate endDate = date.plusMonths(1).plusDays(-1);
|
||||
List<Rank> res = new ArrayList<>();
|
||||
for (int i = 0; i < rank.size(); i++) {
|
||||
RankNode rankNode = rank.get(i);
|
||||
Rank db = new Rank();
|
||||
db.setType(type);
|
||||
db.setDataType(3);
|
||||
db.setRankTime(date.format(DateTimeFormatter.ofPattern("yyMM")));
|
||||
db.setRankBeginTime(date);
|
||||
db.setRankEndTime(endDate);
|
||||
db.setOrderRank(i+1);
|
||||
db.setNum(rankNode.getScore());
|
||||
db.setUserId(rankNode.getUserId());
|
||||
res.add(db);
|
||||
}
|
||||
this.saveBatch(res);
|
||||
}finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user