This commit is contained in:
张良(004796)
2024-03-19 14:05:14 +08:00
parent 2b50c4b67c
commit 56df980731
4 changed files with 57 additions and 8 deletions

View File

@@ -10,9 +10,11 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import java.time.DayOfWeek; import java.time.DayOfWeek;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
@Component @Component
@Slf4j @Slf4j
@@ -29,10 +31,12 @@ public class RankJob {
@Autowired @Autowired
private AnchorService anchorService; private AnchorService anchorService;
// 凌晨0点1分执行一次 // 凌晨0点1分执行一次
@Scheduled(cron = "0 1 0 * * ? ") @Scheduled(cron = "0 1 0 * * ? ")
public void persistentDb() { public void persistentDb() {
LocalDate date = LocalDate.now().plusDays(-1); LocalDate now = LocalDate.now();
LocalDate date = now.plusDays(-1);
try { try {
rankService.saveDayRank(date,1); rankService.saveDayRank(date,1);
} catch (Exception e) { } catch (Exception e) {
@@ -43,29 +47,30 @@ public class RankJob {
} catch (Exception e) { } catch (Exception e) {
log.error("保存邀请 日榜失败", e); log.error("保存邀请 日榜失败", e);
} }
DayOfWeek week = date.getDayOfWeek(); DayOfWeek week = now.getDayOfWeek();
if (week.getValue() == 1) { // 昨天是周一 做一下持久化 if (week.getValue() == 1) { // 昨天是周一 做一下持久化
LocalDate lastWeekDate = now.plusDays(-7);
try { try {
rankService.saveWeekRank(date,1); rankService.saveWeekRank(lastWeekDate,1);
} catch (Exception e) { } catch (Exception e) {
log.error("保存魅力 周榜失败", e); log.error("保存魅力 周榜失败", e);
} }
try { try {
rankService.saveWeekRank(date,2); rankService.saveWeekRank(lastWeekDate,2);
} catch (Exception e) { } catch (Exception e) {
log.error("保存邀请 周榜失败", e); log.error("保存邀请 周榜失败", e);
} }
} }
int month = date.getDayOfMonth(); int month = now.getDayOfMonth();
if (month == 1) { // 昨天是1号 if (month == 1) { // 昨天是1号
LocalDate lastMonthDate = now.plusMonths(-1);
try { try {
rankService.saveMonthRank(date,1); rankService.saveMonthRank(lastMonthDate,1);
} catch (Exception e) { } catch (Exception e) {
log.error("保存魅力 月榜失败", e); log.error("保存魅力 月榜失败", e);
} }
try { try {
rankService.saveMonthRank(lastMonthDate,2);
rankService.saveMonthRank(date,2);
} catch (Exception e) { } catch (Exception e) {
log.error("保存邀请 月榜失败", e); log.error("保存邀请 月榜失败", e);
} }

View File

@@ -11,7 +11,9 @@ 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.RankService;
import com.ruoyi.cai.service.UserService; import com.ruoyi.cai.service.UserService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.helper.LoginHelper; 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;
@@ -96,6 +98,7 @@ public class RankAppController {
@GetMapping("/love") @GetMapping("/love")
@Operation(summary = "魅力榜") @Operation(summary = "魅力榜")
@Log(title = "魅力榜单查询", businessType = BusinessType.OTHER, isSaveDb = true)
public R<List<RankNodeLove>> loveRank( public R<List<RankNodeLove>> loveRank(
@Parameter(description = "类型 1-上周 2-昨日 3-日榜 4-周榜 5-月榜 6-总榜") Integer type){ @Parameter(description = "类型 1-上周 2-昨日 3-日榜 4-周榜 5-月榜 6-总榜") Integer type){
if(type == null){ if(type == null){
@@ -152,6 +155,7 @@ public class RankAppController {
@GetMapping("/invite") @GetMapping("/invite")
@Operation(summary = "邀请榜") @Operation(summary = "邀请榜")
@Log(title = "邀请榜单查询", businessType = BusinessType.OTHER, isSaveDb = true)
public R<List<RankNodeInvite>> inviteRank( public R<List<RankNodeInvite>> inviteRank(
@Parameter(description = "类型 1-上周 2-昨日 3-日榜 4-周榜 5-月榜 6-总榜") Integer type){ @Parameter(description = "类型 1-上周 2-昨日 3-日榜 4-周榜 5-月榜 6-总榜") Integer type){
if(type == null){ if(type == null){

View File

@@ -1,5 +1,6 @@
package com.ruoyi.web.controller.cai.app; package com.ruoyi.web.controller.cai.app;
import cn.dev33.satoken.annotation.SaIgnore;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.cai.domain.Gift; import com.ruoyi.cai.domain.Gift;
import com.ruoyi.cai.domain.Goods; import com.ruoyi.cai.domain.Goods;
@@ -108,6 +109,7 @@ public class SettingAppController {
@GetMapping("/agreement/user") @GetMapping("/agreement/user")
@Operation(summary = "获取用户协议") @Operation(summary = "获取用户协议")
@Log(title = "获取用户协议", businessType = BusinessType.OTHER, isSaveDb = false) @Log(title = "获取用户协议", businessType = BusinessType.OTHER, isSaveDb = false)
@SaIgnore
public R<AgreementDTO> userAgreement() { public R<AgreementDTO> userAgreement() {
String userAgreement = agreementSettingService.getAgreementSetting().getUserAgreement(); String userAgreement = agreementSettingService.getAgreementSetting().getUserAgreement();
return R.ok(new AgreementDTO(userAgreement)); return R.ok(new AgreementDTO(userAgreement));
@@ -116,6 +118,7 @@ public class SettingAppController {
@GetMapping("/agreement/privacy") @GetMapping("/agreement/privacy")
@Operation(summary = "获取隐私协议") @Operation(summary = "获取隐私协议")
@Log(title = "获取隐私协议", businessType = BusinessType.OTHER, isSaveDb = false) @Log(title = "获取隐私协议", businessType = BusinessType.OTHER, isSaveDb = false)
@SaIgnore
public R<AgreementDTO> privacyAgreement() { public R<AgreementDTO> privacyAgreement() {
String privacyAgreement = agreementSettingService.getAgreementSetting().getPrivacyAgreement(); String privacyAgreement = agreementSettingService.getAgreementSetting().getPrivacyAgreement();
return R.ok(new AgreementDTO(privacyAgreement)); return R.ok(new AgreementDTO(privacyAgreement));

View File

@@ -0,0 +1,37 @@
package com.ruoyi.test.business;
import com.ruoyi.cai.service.RankService;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
@SpringBootTest
@Slf4j
public class RankTest {
@Autowired
private RankService rankService;
@Test
public void runkJobTest(){
LocalDate date = LocalDate.parse("2024-03-18", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
DayOfWeek week = date.getDayOfWeek();
if (week.getValue() == 1) { // 昨天是周一 做一下持久化
LocalDate lastWeekDate = date.plusDays(-7);
try {
rankService.saveWeekRank(lastWeekDate,1);
} catch (Exception e) {
log.error("保存魅力 周榜失败", e);
}
try {
rankService.saveWeekRank(lastWeekDate,2);
} catch (Exception e) {
log.error("保存邀请 周榜失败", e);
}
}
}
}