Commit 945df793 authored by 万成波's avatar 万成波

用户操作事件积分

parent 1e2257b3
......@@ -4,7 +4,7 @@
<div class="add-box">
<div class="label-box">加分设置</div>
<el-table :data="addList">
<el-table-column label="加分行为" prop="agentName" align="center"></el-table-column>
<el-table-column label="加分行为" prop="operateName" align="center"></el-table-column>
<el-table-column label="分值" prop="operatePoints" align="center">
<template #default="{row}">
<el-input v-model="row.operatePoints"></el-input>
......@@ -25,7 +25,7 @@
<div class="decrease-box">
<div class="label-box">减分设置</div>
<el-table :data="decreaseList">
<el-table-column label="减分行为" prop="agentName" align="center"></el-table-column>
<el-table-column label="减分行为" prop="operateName" align="center"></el-table-column>
<el-table-column label="分值" prop="operatePoints" align="center">
<template #default="{row}">
<el-input v-model="row.operatePoints"></el-input>
......
package com.tangguo.common.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 操作明细
*
* @author 谈笑
* @createTime 2025-08-29 17:23:29 星期五
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class OperateDetail {
/**
* 链路追踪Id
*/
private String linkTracId;
/**
* 用户名
*/
private String userName;
/**
* 操作编码 (积分配置编码)
*/
private String operateCode;
}
......@@ -15,6 +15,11 @@ public class PointsDetail implements Serializable {
private static final long serialVersionUID = 8057307839793769207L;
/**
* 链路追踪Id
*/
private String linkTracId;
/**
* 用户名 (必填)
*/
......
......@@ -17,7 +17,7 @@
<dependencies>
<dependency>
<groupId>com.tangguo</groupId>
<artifactId>safe-campus-quartz</artifactId>
<artifactId>safe-campus-common</artifactId>
</dependency>
</dependencies>
......
package com.tangguo.common.constant;
/**
* 主题常量
* 动态常量
*
* @author 谈笑
* @createTime 2025-09-04 21:19:10 星期四
*/
public interface TopicConstant {
public interface MomentConstant {
/**
* 热搜主题
*/
String HOT_SCORE_CACHE_KEY = "topic.hot";
String HOT_TOPIC = "topic.hot";
}
package com.tangguo.common.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 积分事件枚举
*
* @author 谈笑
* @createTime 2025-09-09 11:09:01 星期二
*/
@Getter
@AllArgsConstructor
public enum OperateType {
FBDT("FBTD", "发布动态"),
DZDT("DZDT", "点赞动态"),
PLDT("PLDT", "评论动态"),
TPDT("CYTP", "投票动态"),
SCDT("SCDT", "删除动态");
private final String code;
private final String desc;
}
package com.tangguo.common.listener;
import com.tangguo.common.enums.OperateType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 操作事件对象
*
* @author 谈笑
* @createTime 2025-09-09 11:27:22 星期二
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class OperateEvent {
/**
* 用户名
*/
private String userName;
/**
* 操作类型
*/
private OperateType operateType;
}
package com.tangguo.common.listener;
import cn.hutool.core.util.IdUtil;
import com.tangguo.common.constant.ActiveMQConstant;
import com.tangguo.common.domain.OperateDetail;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionalEventListener;
import javax.annotation.Resource;
/**
* 操作事件监听器
*
* @author 谈笑
* @createTime 2025-09-09 11:26:28 星期二
*/
@Slf4j
@Component
public class OperateEventListener {
@Resource
private JmsTemplate jmsTemplate;
/**
* 处理用户操作事件
*
* @param event 事件对象
*/
@TransactionalEventListener(classes = OperateEvent.class, fallbackExecution = true)
public void handle(OperateEvent event) {
OperateDetail detail = new OperateDetail();
detail.setLinkTracId(IdUtil.fastUUID());
detail.setUserName(event.getUserName());
detail.setOperateCode(event.getOperateType().getCode());
log.info("=> 开始处理用户操作事件:{}", detail);
this.jmsTemplate.convertAndSend(ActiveMQConstant.Operate.USER_OPERATE, detail);
}
}
......@@ -63,7 +63,7 @@ public class BbsMomentCommentController extends BaseController {
@Log(title = "动态评论记录", businessType = BusinessType.DELETE)
@DeleteMapping("/{id}")
public AjaxResult remove(@PathVariable Long id) {
this.bbsMomentCommentService.deleteComment(id);
this.bbsMomentCommentService.deleteMomentComments(id);
return AjaxResult.success();
}
......
......@@ -6,7 +6,7 @@ import com.tangguo.common.core.domain.AjaxResult;
import com.tangguo.common.core.page.TableDataInfo;
import com.tangguo.common.enums.BusinessType;
import com.tangguo.domain.BbsSensitiveWord;
import com.tangguo.domain.DataImportResult;
import com.tangguo.domain.vo.DataImportResult;
import com.tangguo.service.IBbsSensitiveWordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......
package com.tangguo.domain;
import lombok.Data;
/**
* 操作明细
*
* @author 谈笑
* @createTime 2025-09-04 22:33:53 星期四
*/
@Data
public class OperateDetail {
}
......@@ -32,14 +32,6 @@ public interface IBbsMomentCommentService extends IService<BbsMomentComment> {
BbsMomentComment getBbsMomentComment(Long commentId);
/**
* 删除评论
*
* @param commentId 评论Id
*/
void deleteComment(Long commentId);
/**
* 查询动态评论
*
......@@ -59,4 +51,12 @@ public interface IBbsMomentCommentService extends IService<BbsMomentComment> {
*/
List<BbsCommentDetailVO> getMomentComments(Long momentId, String userName);
/**
* 删除动态评论记录
*
* @param momentId 动态Id
*/
void deleteMomentComments(Long momentId);
}
......@@ -38,4 +38,12 @@ public interface IBbsMomentLikeService extends IService<BbsMomentLike> {
*/
void deleteMomentLike(Long momentId, String userName);
/**
* 删除动态点赞记录
*
* @param momentId 动态Id
*/
void deleteMomentLikes(Long momentId);
}
......@@ -43,14 +43,6 @@ public interface IBbsMomentVoteOptionService extends IService<BbsMomentVoteOptio
void addVoteOptions(BbsMoment moment, List<CreateMomentBO.VoteOption> voteOptions);
/**
* 删除动态投票选项
*
* @param momentId 动态Id
*/
void deleteVoteOptions(Long momentId);
/**
* 查询投票选项
*
......@@ -69,4 +61,12 @@ public interface IBbsMomentVoteOptionService extends IService<BbsMomentVoteOptio
*/
List<BbsVoteOptionVO> getVoteOptionCount(Long momentId);
/**
* 删除动态投票选项
*
* @param momentId 动态Id
*/
void deleteMomentVoteOptions(Long momentId);
}
......@@ -43,4 +43,12 @@ public interface IBbsMomentVoteService extends IService<BbsMomentVote> {
*/
List<BbsVoteVO> getMomentVotes(Long momentId, String optionCode);
/**
* 删除动态投票记录
*
* @param momentId 动态Id
*/
void deleteMomentVotes(Long momentId);
}
......@@ -2,7 +2,7 @@ package com.tangguo.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.domain.BbsSensitiveWord;
import com.tangguo.domain.DataImportResult;
import com.tangguo.domain.vo.DataImportResult;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
......
package com.tangguo.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tangguo.common.enums.CommentStatus;
import com.tangguo.common.exception.ServiceException;
import com.tangguo.domain.BbsMomentComment;
import com.tangguo.domain.vo.BbsCommentDetailVO;
import com.tangguo.mapper.BbsMomentCommentMapper;
......@@ -57,26 +56,6 @@ public class BbsMomentCommentServiceImpl extends ServiceImpl<BbsMomentCommentMap
}
/**
* 删除评论
*
* @param commentId 评论Id
*/
@Override
public void deleteComment(Long commentId) {
BbsMomentComment dbComment = this.getById(commentId);
if (Objects.isNull(dbComment)) {
throw new ServiceException("删除失败,未查询到当前评论数据。");
}
BbsMomentComment updComment = new BbsMomentComment();
updComment.setId(dbComment.getId());
updComment.setStatus(CommentStatus.SC.getStatus());
updComment.setDeleteComment("该评论已被删除");
this.updateById(updComment);
}
/**
* 查询动态评论
*
......@@ -106,4 +85,18 @@ public class BbsMomentCommentServiceImpl extends ServiceImpl<BbsMomentCommentMap
return this.baseMapper.selectMomentComments(momentId, userName);
}
/**
* 删除动态评论记录
*
* @param momentId 动态Id
*/
@Override
public void deleteMomentComments(Long momentId) {
this.count(
Wrappers.lambdaQuery(BbsMomentComment.class)
.eq(BbsMomentComment::getMomentId, momentId)
);
}
}
......@@ -69,4 +69,18 @@ public class BbsMomentLikeServiceImpl extends ServiceImpl<BbsMomentLikeMapper, B
);
}
/**
* 删除动态点赞记录
*
* @param momentId 动态Id
*/
@Override
public void deleteMomentLikes(Long momentId) {
this.remove(
Wrappers.lambdaQuery(BbsMomentLike.class)
.eq(BbsMomentLike::getMomentId, momentId)
);
}
}
......@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tangguo.common.core.domain.entity.SysUser;
import com.tangguo.common.enums.*;
import com.tangguo.common.exception.ServiceException;
import com.tangguo.common.listener.OperateEvent;
import com.tangguo.common.utils.SecurityUtils;
import com.tangguo.common.utils.SensitiveWordUtils;
import com.tangguo.domain.BbsMoment;
......@@ -19,6 +20,7 @@ import com.tangguo.domain.vo.*;
import com.tangguo.mapper.BbsMomentMapper;
import com.tangguo.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StopWatch;
......@@ -38,6 +40,9 @@ import java.util.stream.Collectors;
@Service
public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment> implements IBbsMomentService {
@Resource
private ApplicationEventPublisher eventPublisher;
@Resource
private BbsMomentMapper bbsMomentMapper;
......@@ -93,10 +98,21 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
@Transactional(rollbackFor = Exception.class)
@Override
public void deleteMoment(Long id) {
this.removeById(id);
BbsMoment dbMoment = this.getById(id);
if (Objects.isNull(dbMoment)) {
throw new ServiceException("删除失败,未查询到当前动态数据。");
}
Long dbMomentId = dbMoment.getId();
this.removeById(dbMomentId);
this.attachmentsService.deleteAttachments(dbMomentId);
this.voteService.deleteMomentVotes(dbMomentId);
this.voteOptionService.deleteMomentVoteOptions(dbMomentId);
this.commentService.deleteMomentComments(dbMomentId);
}
/**
* 查询用户动态统计
*
......@@ -179,6 +195,10 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
List<CreateMomentBO.VoteOption> voteOptions = bo.getVoteOptions();
this.voteOptionService.addVoteOptions(newMoment, voteOptions);
}
// 发布用户操作事件
OperateEvent operateEvent = new OperateEvent(username, OperateType.FBDT);
this.eventPublisher.publishEvent(operateEvent);
}
......@@ -198,7 +218,17 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
if (!dbMoment.getUserName().equals(username)) {
throw new ServiceException("删除失败,没有对当前动态数据的操作权限。");
}
// 删除动态以及相关数据
this.removeById(dbMoment.getId());
this.attachmentsService.deleteAttachments(dbMoment.getId());
this.voteService.deleteMomentVotes(dbMoment.getId());
this.voteOptionService.deleteMomentVoteOptions(dbMoment.getId());
this.commentService.deleteMomentComments(dbMoment.getId());
// 发布用户操作事件
OperateEvent operateEvent = new OperateEvent(username, OperateType.SCDT);
this.eventPublisher.publishEvent(operateEvent);
}
......@@ -215,22 +245,22 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
throw new ServiceException("点赞失败,未查询到当前动态数据。");
}
String userName = SecurityUtils.getUsername();
long likeStatus = this.likeService.getUserMomentLikeCount(dbMoment.getId(), userName);
String username = SecurityUtils.getUsername();
long likeStatus = this.likeService.getUserMomentLikeCount(dbMoment.getId(), username);
int likeCount = dbMoment.getLikeCount();
if (LikeStatus.LIKE.getStatus() == bo.getLikeStatus()) {
if (likeStatus > 0) {
throw new ServiceException("点赞失败,已对当前动态点赞。");
} else {
this.likeService.addMomentLike(dbMoment.getId(), userName);
this.likeService.addMomentLike(dbMoment.getId(), username);
likeCount++;
}
} else {
if (likeStatus < 1) {
throw new ServiceException("取消失败,没有对当前动态点赞。");
} else {
this.likeService.deleteMomentLike(dbMoment.getId(), userName);
this.likeService.deleteMomentLike(dbMoment.getId(), username);
likeCount--;
}
}
......@@ -240,6 +270,10 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
updMoment.setId(dbMoment.getId());
updMoment.setLikeCount(likeCount);
this.updateById(updMoment);
// 发布用户操作事件
OperateEvent operateEvent = new OperateEvent(username, OperateType.DZDT);
this.eventPublisher.publishEvent(operateEvent);
}
......@@ -285,6 +319,10 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
updMoment.setId(dbMoment.getId());
updMoment.setVoteCount(dbMoment.getVoteCount() + 1);
this.updateById(updMoment);
// 发布用户操作事件
OperateEvent operateEvent = new OperateEvent(username, OperateType.TPDT);
this.eventPublisher.publishEvent(operateEvent);
}
......@@ -340,6 +378,10 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
updMoment.setId(dbMoment.getId());
updMoment.setCommentCount(dbMoment.getCommentCount() + 1);
this.updateById(updMoment);
// 发布用户操作事件
OperateEvent operateEvent = new OperateEvent(dbUser.getUserName(), OperateType.TPDT);
this.eventPublisher.publishEvent(operateEvent);
}
......
......@@ -94,18 +94,6 @@ public class BbsMomentVoteOptionServiceImpl extends ServiceImpl<BbsMomentVoteOpt
}
/**
* 删除动态投票选项
*
* @param momentId 动态Id
*/
@Override
public void deleteVoteOptions(Long momentId) {
this.remove(
Wrappers.lambdaQuery(BbsMomentVoteOption.class).eq(BbsMomentVoteOption::getMomentId, momentId)
);
}
/**
* 查询投票选项
......@@ -148,4 +136,18 @@ public class BbsMomentVoteOptionServiceImpl extends ServiceImpl<BbsMomentVoteOpt
return ovs;
}
/**
* 删除动态投票选项
*
* @param momentId 动态Id
*/
@Override
public void deleteMomentVoteOptions(Long momentId) {
this.count(
Wrappers.lambdaQuery(BbsMomentVoteOption.class)
.eq(BbsMomentVoteOption::getMomentId, momentId)
);
}
}
......@@ -70,4 +70,18 @@ public class BbsMomentVoteServiceImpl extends ServiceImpl<BbsMomentVoteMapper, B
return this.baseMapper.selectVotes(momentId, optionCode);
}
/**
* 删除动态投票记录
*
* @param momentId 动态Id
*/
@Override
public void deleteMomentVotes(Long momentId) {
this.count(
Wrappers.lambdaQuery(BbsMomentVote.class)
.eq(BbsMomentVote::getMomentId, momentId)
);
}
}
......@@ -10,7 +10,7 @@ import com.tangguo.common.exception.ServiceException;
import com.tangguo.common.utils.SensitiveWordUtils;
import com.tangguo.common.utils.StringUtils;
import com.tangguo.domain.BbsSensitiveWord;
import com.tangguo.domain.DataImportResult;
import com.tangguo.domain.vo.DataImportResult;
import com.tangguo.mapper.BbsSensitiveWordMapper;
import com.tangguo.service.IBbsSensitiveWordService;
import lombok.extern.slf4j.Slf4j;
......
......@@ -6,7 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tangguo.common.constant.TopicConstant;
import com.tangguo.common.constant.MomentConstant;
import com.tangguo.common.core.redis.RedisCache;
import com.tangguo.common.enums.TopicTopStatus;
import com.tangguo.common.exception.ServiceException;
......@@ -168,7 +168,7 @@ public class BbsTopicServiceImpl extends ServiceImpl<BbsTopicMapper, BbsTopic> i
@Override
public void refreshRankingTopic() {
this.baseMapper.refreshRankingTopic();
this.redisCache.deleteObject(TopicConstant.HOT_SCORE_CACHE_KEY);
this.redisCache.deleteObject(MomentConstant.HOT_TOPIC);
}
......@@ -179,10 +179,10 @@ public class BbsTopicServiceImpl extends ServiceImpl<BbsTopicMapper, BbsTopic> i
*/
@Override
public List<BbsTopicListVO> getRankingTopic() {
List<BbsTopicListVO> topics = this.redisCache.getCacheObject(TopicConstant.HOT_SCORE_CACHE_KEY);
List<BbsTopicListVO> topics = this.redisCache.getCacheObject(MomentConstant.HOT_TOPIC);
if (CollUtil.isEmpty(topics)) {
topics = this.baseMapper.selectRankingTopic();
this.redisCache.setCacheObject(TopicConstant.HOT_SCORE_CACHE_KEY, topics, 1, TimeUnit.HOURS);
this.redisCache.setCacheObject(MomentConstant.HOT_TOPIC, topics, 1, TimeUnit.HOURS);
}
return topics;
}
......
......@@ -50,6 +50,17 @@ public class BbsUserPointsController extends BaseController {
}
/**
* 查询用户积分
*/
@ApiOperation("查询用户积分")
@GetMapping("/{userName}")
public AjaxResult list(@PathVariable String userName) {
BbsUserPoints dbPoints = this.bbsUserPointsService.selectBbsUserPoints(userName);
return AjaxResult.success(dbPoints);
}
/**
* 查询用户积分明细
*/
......
package com.tangguo.controller;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tangguo.common.annotation.Log;
import com.tangguo.common.annotation.RepeatSubmit;
import com.tangguo.common.core.controller.BaseController;
......@@ -9,9 +7,7 @@ import com.tangguo.common.core.domain.AjaxResult;
import com.tangguo.common.core.page.TableDataInfo;
import com.tangguo.common.enums.BusinessType;
import com.tangguo.common.utils.poi.ExcelUtil;
import com.tangguo.domain.BbsPointsGoods;
import com.tangguo.domain.BbsUserPointsExchange;
import com.tangguo.service.IBbsPointsGoodsService;
import com.tangguo.service.IBbsUserPointsExchangeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......
......@@ -3,6 +3,8 @@ package com.tangguo.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
/**
* 积分配置类型
*
......@@ -17,4 +19,10 @@ public enum PointsSettingType {
private final String desc;
public static PointsSettingType getSettingType(String type) {
return Arrays.stream(PointsSettingType.values())
.filter(t -> t.name().equals(type)).findFirst().orElse(null);
}
}
package com.tangguo.common.listener;
package com.tangguo.listener;
import com.tangguo.common.constant.ActiveMQConstant;
import com.tangguo.domain.OperateDetail;
import com.tangguo.common.domain.OperateDetail;
import com.tangguo.service.IBbsPointsSettingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.jms.Message;
/**
......@@ -16,16 +18,26 @@ import javax.jms.Message;
*/
@Slf4j
@Component
public class UserOperateListener {
public class OperateListener {
@Resource
private IBbsPointsSettingService pointsSettingService;
/**
* 增加用户积分消息
* 处理用户操作积分消息
*
* @param detail 积分明细
* @param detail 操作明细
*/
@JmsListener(destination = ActiveMQConstant.Operate.USER_OPERATE, containerFactory = ActiveMQConstant.QUEUE_CONTAINER_BEAN)
public void operateListener(OperateDetail detail, Message message) {
public void handleOperatePoints(OperateDetail detail, Message message) {
try {
log.info("=> 开始处理用户操作积分消息:{}", detail);
this.pointsSettingService.handleOperatePoints(detail);
message.acknowledge();
} catch (Exception e) {
log.error("=> 用户操作积分消息处理失败,操作明细:{} 错误信息:", detail, e);
}
}
}
......@@ -49,7 +49,7 @@ public class PointsListener {
@JmsListener(destination = ActiveMQConstant.Points.DECR_USER_POINTS_QUEUE, containerFactory = ActiveMQConstant.QUEUE_CONTAINER_BEAN)
public void decrUserPointsListener(PointsDetail detail, Message message) {
try {
log.info("=> 扣减用户积分消息:{}", detail);
log.info("=> 开始处理扣减用户积分消息:{}", detail);
this.userPointsService.decrUserPoints(detail);
message.acknowledge();
} catch (Exception e) {
......
......@@ -2,6 +2,7 @@ package com.tangguo.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tangguo.domain.BbsPointsSetting;
import org.apache.ibatis.annotations.Param;
/**
* 积分规则配置Mapper接口
......@@ -10,4 +11,8 @@ import com.tangguo.domain.BbsPointsSetting;
* @date 2025-08-29
*/
public interface BbsPointsSettingMapper extends BaseMapper<BbsPointsSetting> {
int selectPointsCount(@Param("userName") String userName, @Param("operateCode") String operateCode,
@Param("days") int days);
}
......@@ -17,7 +17,10 @@ public interface BbsUserPointsMapper extends BaseMapper<BbsUserPoints> {
List<BbsUserPoints> selectBbsUserPointsList(@Param("points") BbsUserPoints points);
int selectUserCount(@Param("userName") String userName);
BbsUserPoints selectBbsUserPoints(@Param("userName") String userName);
int selectSysUserCount(@Param("userName") String userName);
int refreshUserPointsGrade();
......
package com.tangguo.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.common.domain.OperateDetail;
import com.tangguo.domain.BbsPointsSetting;
import java.util.List;
......@@ -31,6 +32,14 @@ public interface IBbsPointsSettingService extends IService<BbsPointsSetting> {
Map<String, List<BbsPointsSetting>> getSettingDetails();
/**
* 查询积分规则配置
*
* @return 规则配置
*/
List<BbsPointsSetting> getEnableSettings();
/**
* 添加积分配置
*
......@@ -62,4 +71,12 @@ public interface IBbsPointsSettingService extends IService<BbsPointsSetting> {
*/
void setSettingStatus(BbsPointsSetting setting);
/**
* 处理用户操作积分
*
* @param detail 操作明细
*/
void handleOperatePoints(OperateDetail detail);
}
......@@ -23,6 +23,15 @@ public interface IBbsUserPointsService extends IService<BbsUserPoints> {
List<BbsUserPoints> selectBbsUserPointsList(BbsUserPoints bbsUserPoints);
/**
* 查询用户积分
*
* @param userName 用户名
* @return 用户积分集合
*/
BbsUserPoints selectBbsUserPoints(String userName);
/**
* 查询用户积分
*
......
......@@ -3,18 +3,20 @@ package com.tangguo.service.impl;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tangguo.common.constant.ActiveMQConstant;
import com.tangguo.common.domain.OperateDetail;
import com.tangguo.common.domain.PointsDetail;
import com.tangguo.common.exception.ServiceException;
import com.tangguo.domain.BbsPointsSetting;
import com.tangguo.enums.PointsSettingType;
import com.tangguo.mapper.BbsPointsSettingMapper;
import com.tangguo.service.IBbsPointsSettingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
/**
......@@ -23,12 +25,18 @@ import java.util.stream.Collectors;
* @author ruoyi
* @date 2025-08-29
*/
@Slf4j
@Service
public class BbsPointsSettingServiceImpl extends ServiceImpl<BbsPointsSettingMapper, BbsPointsSetting> implements IBbsPointsSettingService {
private static final Map<String, BbsPointsSetting> POINTS_SETTING = new HashMap<>(5);
@Resource
private BbsPointsSettingMapper bbsPointsSettingMapper;
@Resource
private JmsTemplate jmsTemplate;
/**
* 查询积分规则配置列表
......@@ -63,6 +71,19 @@ public class BbsPointsSettingServiceImpl extends ServiceImpl<BbsPointsSettingMap
}
/**
* 查询积分规则配置
*
* @return 规则配置
*/
@Override
public List<BbsPointsSetting> getEnableSettings() {
return this.list(
Wrappers.lambdaQuery(BbsPointsSetting.class).eq(BbsPointsSetting::getEnableStatus, 1)
);
}
/**
* 添加积分配置
*
......@@ -151,4 +172,49 @@ public class BbsPointsSettingServiceImpl extends ServiceImpl<BbsPointsSettingMap
}
}
/**
* 处理用户操作积分
*
* @param detail 操作明细
*/
@Override
public void handleOperatePoints(OperateDetail detail) {
log.info("=> 处理用户操作积分:{}", detail);
// 匹配积分规则
BbsPointsSetting setting = POINTS_SETTING.get(detail.getOperateCode());
String userName = detail.getUserName();
String operateCode = setting.getOperateCode();
int pointsCount = this.baseMapper.selectPointsCount(userName, operateCode, 7);
if (pointsCount < setting.getLimitCount()) {
// 积分消息明细
String operateName = setting.getOperateName();
Integer points = setting.getOperatePoints();
PointsDetail pointsDetail = new PointsDetail();
pointsDetail.setLinkTracId(detail.getLinkTracId());
pointsDetail.setUserName(userName);
pointsDetail.setDetailPoints(points);
pointsDetail.setDetailName(operateName);
pointsDetail.setDetailCode(operateCode);
pointsDetail.setDescription(String.format("用户【%s】操作【%s】积分【%s】", userName, operateName, points));
// 匹配积分队列
String pointsQueue;
PointsSettingType settingType = PointsSettingType.getSettingType(setting.getType());
if (PointsSettingType.ADD == settingType) {
pointsQueue = ActiveMQConstant.Points.INCR_USER_POINTS_QUEUE;
} else if (PointsSettingType.DEC == settingType) {
pointsQueue = ActiveMQConstant.Points.DECR_USER_POINTS_QUEUE;
} else {
log.error("=> 当前积分规则的设置类型错误:{}", setting);
return;
}
// 发送积分消息
this.jmsTemplate.convertAndSend(pointsQueue, pointsDetail);
}
}
}
......@@ -55,6 +55,18 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
}
/**
* 查询用户积分
*
* @param userName 用户名
* @return 用户积分集合
*/
@Override
public BbsUserPoints selectBbsUserPoints(String userName) {
return this.baseMapper.selectBbsUserPoints(userName);
}
/**
* 查询用户积分
*
......@@ -80,7 +92,7 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
public BbsUserPoints getAndInitUserPoints(String userName) {
BbsUserPoints dbUserPoints = this.getUserPoints(userName);
if (Objects.isNull(dbUserPoints)) {
int dbUserCount = this.baseMapper.selectUserCount(userName);
int dbUserCount = this.baseMapper.selectSysUserCount(userName);
if (dbUserCount > 0) {
// 初始积分
dbUserPoints = new BbsUserPoints();
......
......@@ -4,4 +4,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tangguo.mapper.BbsPointsSettingMapper">
<select id="selectPointsCount" resultType="java.lang.Integer">
SELECT
COUNT(*)
FROM
bbs_user_points_detail
WHERE
user_name = #{userName}
AND
detail_code = #{operateCode}
AND
create_time >= DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL #{days} DAY)
</select>
</mapper>
......@@ -40,7 +40,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectUserCount" resultType="java.lang.Integer">
<select id="selectBbsUserPoints" resultType="com.tangguo.domain.BbsUserPoints">
SELECT
uv.nick_name AS nick_name,
uv.user_name,
ud.dept_name,
IFNULL(p.current_points, 0) AS current_points,
IFNULL(p.accumulated_points, 0) AS accumulated_points,
IFNULL(p.grade_name, ug.name) AS grade_name
FROM
sys_user uv
LEFT JOIN
sys_dept ud ON ud.dept_id = uv.dept_id
LEFT JOIN
bbs_user_points p ON p.user_name = uv.user_name
CROSS JOIN (
SELECT (SELECT name FROM bbs_grade WHERE is_initial = 1 ORDER BY create_time DESC LIMIT 1) AS name
) ug
WHERE
uv.user_name = #{userName}
</select>
<select id="selectSysUserCount" resultType="java.lang.Integer">
SELECT COUNT(*) FROM sys_user WHERE user_name = #{userName}
</select>
......
......@@ -32,6 +32,11 @@
<groupId>com.tangguo</groupId>
<artifactId>safe-campus-system</artifactId>
</dependency>
<dependency>
<groupId>com.tangguo</groupId>
<artifactId>safe-campus-moment</artifactId>
</dependency>
</dependencies>
</project>
package com.tangguo.common.jobs;
package com.tangguo.quartz.task;
import com.tangguo.service.IBbsTopicService;
import lombok.extern.slf4j.Slf4j;
......@@ -14,7 +14,7 @@ import javax.annotation.Resource;
*/
@Slf4j
@Component
public class RefreshTopicRankingJob {
public class RefreshTopicRankingTask {
@Resource
private IBbsTopicService topicService;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment