Commit 6cc54ad5 authored by 万成波's avatar 万成波

积分模块集成ActiveMQ

parent 79fc45f3
package com.tangguo;
import com.tangguo.common.constant.ActiveMQConstant;
import com.tangguo.domain.dto.PointsDetail;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jms.core.JmsTemplate;
import javax.annotation.Resource;
/**
*
*
* @author 谈笑
* @createTime 2025-09-01 16:18:29 星期一
*/
@SpringBootTest
public class ApplicationTest {
@Resource
private JmsTemplate jmsTemplate;
@Test
public void test() {
PointsDetail detail = new PointsDetail();
detail.setUserName("TanXiao");
detail.setDetailPoints(10);
detail.setDetailName("外部系统");
detail.setDescription("外部系统");
this.jmsTemplate.convertAndSend(ActiveMQConstant.Points.INCR_USER_POINTS_QUEUE, detail);
this.jmsTemplate.convertAndSend(ActiveMQConstant.Points.DECR_USER_POINTS_QUEUE, detail);
}
}
package com.tangguo.common.constant;
/**
* ActiveMQ常量
*
* @author 谈笑
* @createTime 2025-09-01 15:54:26 星期一
*/
public interface ActiveMQConstant{
/**
* 点对点 (队列) 模式
*/
String QUEUE_CONTAINER_BEAN = "queueContainer";
interface Points {
/**
* 增加用户积分队列名
*/
String INCR_USER_POINTS_QUEUE = "points.user.incr";
/**
* 扣减用户积分队列名
*/
String DECR_USER_POINTS_QUEUE = "points.user.decr";
}
}
......@@ -33,6 +33,11 @@
<artifactId>druid-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<!-- 系统模块-->
<dependency>
<groupId>com.tangguo</groupId>
......
package com.tangguo.framework.activemq;
import com.tangguo.common.constant.ActiveMQConstant;
import org.apache.activemq.ActiveMQSession;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
import org.springframework.jms.config.JmsListenerContainerFactory;
import javax.jms.ConnectionFactory;
import javax.jms.Queue;
/**
* ActiveMQ队列配置
*
* @author 谈笑
* @createTime 2025-09-01 15:53:31 星期一
*/
@EnableJms
@Configuration
public class ActiveMQConfig {
/**
* 增加用户积分队列
*/
@Bean
public Queue incrUserPointsQueue() {
return new ActiveMQQueue(ActiveMQConstant.Points.INCR_USER_POINTS_QUEUE);
}
/**
* 扣减用户积分队列
*/
@Bean
public Queue decrUserPointsQueue() {
return new ActiveMQQueue(ActiveMQConstant.Points.DECR_USER_POINTS_QUEUE);
}
/**
* 点对点 (队列) 模式
*/
@Bean(ActiveMQConstant.QUEUE_CONTAINER_BEAN)
public JmsListenerContainerFactory<?> queueContainer(ConnectionFactory connectionFactory) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setPubSubDomain(false);
factory.setSessionAcknowledgeMode(ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE);
factory.setSessionTransacted(false);
factory.setConnectionFactory(connectionFactory);
return factory;
}
}
package com.tangguo.framework.config;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpStatus;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.tangguo.common.core.domain.BaseEntity;
import com.tangguo.common.exception.ServiceException;
import com.tangguo.common.utils.SecurityUtils;
import com.tangguo.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
......@@ -38,7 +36,8 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler {
baseEntity.setUpdateBy(username);
}
} catch (Exception e) {
throw new ServiceException("自动注入异常 => " + e.getMessage(), HttpStatus.HTTP_UNAUTHORIZED);
log.error("=> 自动注入异常:", e);
// throw new ServiceException("自动注入异常 => " + e.getMessage(), HttpStatus.HTTP_UNAUTHORIZED);
}
}
......@@ -57,7 +56,8 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler {
}
}
} catch (Exception e) {
throw new ServiceException("自动注入异常 => " + e.getMessage(), HttpStatus.HTTP_UNAUTHORIZED);
log.error("=> 自动注入异常:", e);
// throw new ServiceException("自动注入异常 => " + e.getMessage(), HttpStatus.HTTP_UNAUTHORIZED);
}
}
......
......@@ -6,7 +6,6 @@ import com.tangguo.common.core.domain.AjaxResult;
import com.tangguo.common.core.page.TableDataInfo;
import com.tangguo.common.enums.BusinessType;
import com.tangguo.domain.BbsMoment;
import com.tangguo.domain.BbsMomentComment;
import com.tangguo.service.IBbsMomentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......
......@@ -7,6 +7,7 @@ import com.tangguo.common.core.controller.BaseController;
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.domain.vo.QwmhSysUserVO;
......@@ -19,6 +20,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
......@@ -84,6 +86,21 @@ public class BbsUserPointsExchangeController extends BaseController {
}
/**
* 导出用户积分列表
*/
@ApiOperation("导出用户积分列表")
@PreAuthorize("@ss.hasPermi('points:points:export')")
@Log(title = "用户积分", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, BbsUserPointsExchange exchange) {
List<BbsUserPointsExchange> list = bbsUserPointsExchangeService.selectBbsUserPointsExchangeList(exchange);
ExcelUtil<BbsUserPointsExchange> util = new ExcelUtil<>(BbsUserPointsExchange.class);
util.exportExcel(response, list, "用户积分数据");
}
/**
* 用户积分兑换
*/
......
......@@ -2,6 +2,8 @@ package com.tangguo.domain.dto;
import lombok.Data;
import java.io.Serializable;
/**
* 积分明细DTO
*
......@@ -9,20 +11,22 @@ import lombok.Data;
* @createTime 2025-08-29 17:23:29 星期五
*/
@Data
public class PointsDetail {
public class PointsDetail implements Serializable {
private static final long serialVersionUID = 8057307839793769207L;
/**
* 用户名
* 用户名 (必填)
*/
private String userName;
/**
* 积分
* 明细积分 (必填)
*/
private int points;
private int detailPoints;
/**
* 明细名称
* 明细名称 (必填)
*/
private String detailName;
......@@ -32,12 +36,7 @@ public class PointsDetail {
private String detailCode;
/**
* 明细积分
*/
private Integer detailPoints;
/**
* 明细说明
* 明细说明 (必填)
*/
private String description;
......
package com.tangguo.event;
import com.tangguo.common.constant.ActiveMQConstant;
import com.tangguo.domain.dto.PointsDetail;
import com.tangguo.service.IBbsUserPointsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.jms.Message;
/**
* 用户积分增加扣减消息时间监听器
*
* @author 谈笑
* @createTime 2025-09-01 16:03:08 星期一
*/
@Slf4j
@Component
public class UserPointsListener {
@Resource
private IBbsUserPointsService userPointsService;
/**
* 增加用户积分消息
*
* @param detail 积分明细
*/
@JmsListener(destination = ActiveMQConstant.Points.INCR_USER_POINTS_QUEUE, containerFactory = ActiveMQConstant.QUEUE_CONTAINER_BEAN)
public void incrUserPointsListener(PointsDetail detail, Message message) {
try {
log.info("=> 开始处理增加用户积分消息:{}", detail);
this.userPointsService.incrUserPoints(detail);
message.acknowledge();
} catch (Exception e) {
log.error("=> 增加用户积分消息处理失败,积分明细:{} 错误信息:", detail, e);
}
}
/**
* 扣减用户积分消息
*
* @param detail 积分明细
*/
@JmsListener(destination = ActiveMQConstant.Points.DECR_USER_POINTS_QUEUE, containerFactory = ActiveMQConstant.QUEUE_CONTAINER_BEAN)
public void decrUserPoints(PointsDetail detail, Message message) {
try {
log.info("=> 扣减用户积分消息:{}", detail);
this.userPointsService.decrUserPoints(detail);
message.acknowledge();
} catch (Exception e) {
log.error("=> 扣减用户积分消息处理失败,积分明细:{} 错误信息:", detail, e);
}
}
}
......@@ -87,7 +87,7 @@ public class BbsUserPointsExchangeServiceImpl extends ServiceImpl<BbsUserPointsE
// 扣减用户积分
PointsDetail detail = new PointsDetail();
detail.setUserName(userName);
detail.setPoints(exchangePoints);
detail.setDetailPoints(exchangePoints);
detail.setDetailName(dbGoods.getName());
detail.setDetailCode(dbGoods.getCode());
detail.setDescription(String.format("用户【%s】兑换积分商品【%s-%s】", userName, dbGoods.getName(), dbGoods.getCode()));
......
......@@ -83,7 +83,7 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
String userName = points.getUserName();
PointsDetail detail = new PointsDetail();
detail.setUserName(userName);
detail.setPoints(points.getIncrOrDecrPoints());
detail.setDetailPoints(points.getIncrOrDecrPoints());
detail.setDetailName("后台手动增加");
detail.setDescription(String.format("管理员【%s】后台手动增加用户【%s】积分", SecurityUtils.getUsername(), userName));
this.incrUserPoints(detail);
......@@ -101,7 +101,7 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
String userName = points.getUserName();
PointsDetail detail = new PointsDetail();
detail.setUserName(userName);
detail.setPoints(points.getIncrOrDecrPoints());
detail.setDetailPoints(points.getIncrOrDecrPoints());
detail.setDetailName("后台手动扣减");
detail.setDescription(String.format("管理员【%s】后台手动扣减用户【%s】积分", SecurityUtils.getUsername(), userName));
this.decrUserPoints(detail);
......@@ -141,7 +141,7 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
*/
@Transactional(rollbackFor = Exception.class)
public void privIncrUserPoints(PointsDetail detail) {
int points = detail.getPoints();
int points = detail.getDetailPoints();
if (points < 1) {
throw new ServiceException("增加用户积分失败,增加的积分分值不能小于0。");
}
......@@ -175,7 +175,7 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
*/
@Transactional(rollbackFor = Exception.class)
public void privDecrUserPoints(PointsDetail detail) {
int points = detail.getPoints();
int points = detail.getDetailPoints();
if (points < 1) {
throw new ServiceException("扣减用户积分失败,扣减的积分分值不能小于0。");
}
......
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