Commit 9c15c3b7 authored by 万成波's avatar 万成波

修复Bug

parent 3734696e
...@@ -87,7 +87,7 @@ export default { ...@@ -87,7 +87,7 @@ export default {
}, },
// 增加积分 // 增加积分
handleAddPoints(row) { handleAddPoints(row) {
this.$prompt('增加积分', '提示', { this.$prompt('增加积分,当前用户可用积分:' + row.currentPoints, '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
inputPattern: /^[1-9]\d*$/, inputPattern: /^[1-9]\d*$/,
...@@ -111,7 +111,7 @@ export default { ...@@ -111,7 +111,7 @@ export default {
}, },
// 扣减积分 // 扣减积分
handleDecreasePoints(row) { handleDecreasePoints(row) {
this.$prompt('扣减积分', '提示', { this.$prompt('扣减积分,当前用户可用积分:' + row.currentPoints, '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
inputPattern: /^[1-9]\d*$/, inputPattern: /^[1-9]\d*$/,
......
...@@ -9,6 +9,7 @@ import com.tangguo.common.enums.BusinessType; ...@@ -9,6 +9,7 @@ import com.tangguo.common.enums.BusinessType;
import com.tangguo.common.utils.poi.ExcelUtil; import com.tangguo.common.utils.poi.ExcelUtil;
import com.tangguo.domain.BbsUserPoints; import com.tangguo.domain.BbsUserPoints;
import com.tangguo.domain.BbsUserPointsDetail; import com.tangguo.domain.BbsUserPointsDetail;
import com.tangguo.domain.bo.BatchUserPointsBO;
import com.tangguo.service.IBbsUserPointsDetailService; import com.tangguo.service.IBbsUserPointsDetailService;
import com.tangguo.service.IBbsUserPointsService; import com.tangguo.service.IBbsUserPointsService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -115,4 +116,32 @@ public class BbsUserPointsController extends BaseController { ...@@ -115,4 +116,32 @@ public class BbsUserPointsController extends BaseController {
return AjaxResult.success(); return AjaxResult.success();
} }
/**
* 增加用户积分
*/
@RepeatSubmit(interval = 1000)
@ApiOperation("新增用户积分")
@PreAuthorize("@ss.hasPermi('points:points:incr')")
@Log(title = "用户积分", businessType = BusinessType.UPDATE)
@PutMapping("/batch/incr")
public AjaxResult batchIncrUserPoints(@RequestBody BatchUserPointsBO bo) {
this.bbsUserPointsService.batchAddUserPoints(bo);
return AjaxResult.success();
}
/**
* 扣减用户积分
*/
@RepeatSubmit(interval = 1000)
@ApiOperation("扣减用户积分")
@PreAuthorize("@ss.hasPermi('points:points:decr')")
@Log(title = "用户积分", businessType = BusinessType.UPDATE)
@PutMapping("/batch/decr")
public AjaxResult batchDecrUserPoints(@RequestBody BatchUserPointsBO bo) {
this.bbsUserPointsService.batchDeleteUserPoints(bo);
return AjaxResult.success();
}
} }
package com.tangguo.domain.bo;
import lombok.Data;
import java.util.List;
import java.util.Set;
/**
*
*
* @author 谈笑
* @createTime 2025-11-06 10:21:06 星期四
*/
@Data
public class BatchUserPointsBO {
/**
* 用户名
*/
private Set<String> userNames;
/**
* 积分
*/
private Integer points;
/**
* 备注
*/
private String remarks;
}
...@@ -3,6 +3,7 @@ package com.tangguo.service; ...@@ -3,6 +3,7 @@ package com.tangguo.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.common.domain.PointsDetail; import com.tangguo.common.domain.PointsDetail;
import com.tangguo.domain.BbsUserPoints; import com.tangguo.domain.BbsUserPoints;
import com.tangguo.domain.bo.BatchUserPointsBO;
import java.util.List; import java.util.List;
...@@ -66,6 +67,22 @@ public interface IBbsUserPointsService extends IService<BbsUserPoints> { ...@@ -66,6 +67,22 @@ public interface IBbsUserPointsService extends IService<BbsUserPoints> {
void deleteUserPoints(BbsUserPoints points); void deleteUserPoints(BbsUserPoints points);
/**
* 增加用户积分
*
* @param bo 积分
*/
void batchAddUserPoints(BatchUserPointsBO bo);
/**
* 扣减用户积分
*
* @param bo 积分
*/
void batchDeleteUserPoints(BatchUserPointsBO bo);
/** /**
* 增加用户积分 * 增加用户积分
* *
......
...@@ -254,7 +254,7 @@ public class BbsPointsSettingServiceImpl extends ServiceImpl<BbsPointsSettingMap ...@@ -254,7 +254,7 @@ public class BbsPointsSettingServiceImpl extends ServiceImpl<BbsPointsSettingMap
pointsDetail.setDetailPoints(points); pointsDetail.setDetailPoints(points);
pointsDetail.setDetailName(operateName); pointsDetail.setDetailName(operateName);
pointsDetail.setDetailCode(operateCode); pointsDetail.setDetailCode(operateCode);
pointsDetail.setDescription(String.format("用户【%s】操作【%s】积分【%s】", userName, operateName, points)); pointsDetail.setDescription(String.format("用户【%s】操作【%s】%s【%s】", userName, operateName, settingType.getDesc(), points));
// 发送积分消息 // 发送积分消息
this.jmsTemplate.convertAndSend(pointsQueue, pointsDetail); this.jmsTemplate.convertAndSend(pointsQueue, pointsDetail);
......
package com.tangguo.service.impl; package com.tangguo.service.impl;
import cn.hutool.core.util.StrUtil;
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.tangguo.common.domain.PointsDetail; import com.tangguo.common.domain.PointsDetail;
import com.tangguo.common.exception.ServiceException; import com.tangguo.common.exception.ServiceException;
import com.tangguo.common.utils.SecurityUtils;
import com.tangguo.domain.BbsGrade; import com.tangguo.domain.BbsGrade;
import com.tangguo.domain.BbsUserPoints; import com.tangguo.domain.BbsUserPoints;
import com.tangguo.domain.BbsUserPointsDetail; import com.tangguo.domain.BbsUserPointsDetail;
import com.tangguo.domain.bo.BatchUserPointsBO;
import com.tangguo.mapper.BbsUserPointsMapper; import com.tangguo.mapper.BbsUserPointsMapper;
import com.tangguo.service.IBbsGradeService; import com.tangguo.service.IBbsGradeService;
import com.tangguo.service.IBbsUserPointsDetailService; import com.tangguo.service.IBbsUserPointsDetailService;
import com.tangguo.service.IBbsUserPointsService; import com.tangguo.service.IBbsUserPointsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionTemplate;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
/** /**
* 用户积分Service业务层处理 * 用户积分Service业务层处理
...@@ -26,6 +32,7 @@ import java.util.Objects; ...@@ -26,6 +32,7 @@ import java.util.Objects;
* @author ruoyi * @author ruoyi
* @date 2025-08-29 * @date 2025-08-29
*/ */
@Slf4j
@Service @Service
public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, BbsUserPoints> implements IBbsUserPointsService { public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, BbsUserPoints> implements IBbsUserPointsService {
...@@ -41,6 +48,10 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B ...@@ -41,6 +48,10 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
@Resource @Resource
private IBbsGradeService gradeService; private IBbsGradeService gradeService;
@Resource
private TransactionTemplate transactionTemplate;
/** /**
* 查询用户积分列表 * 查询用户积分列表
...@@ -119,7 +130,6 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B ...@@ -119,7 +130,6 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
* *
* @param points 积分 * @param points 积分
*/ */
@Transactional(rollbackFor = Exception.class)
@Override @Override
public void addUserPoints(BbsUserPoints points) { public void addUserPoints(BbsUserPoints points) {
String userName = points.getUserName(); String userName = points.getUserName();
...@@ -127,8 +137,11 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B ...@@ -127,8 +137,11 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
detail.setUserName(userName); detail.setUserName(userName);
detail.setDetailPoints(points.getIncrOrDecrPoints()); detail.setDetailPoints(points.getIncrOrDecrPoints());
detail.setDetailName("后台手动增加"); detail.setDetailName("后台手动增加");
// detail.setDescription(String.format("管理员【%s】后台手动增加用户【%s】积分", SecurityUtils.getUsername(), userName)); String remarks = points.getRemarks();
detail.setDescription(points.getRemarks()); if (StrUtil.isBlank(remarks)) {
remarks = String.format("管理员【%s】后台手动增加用户【%s】积分", SecurityUtils.getUsername(), userName);
}
detail.setDescription(remarks);
this.incrUserPoints(detail); this.incrUserPoints(detail);
} }
...@@ -138,7 +151,6 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B ...@@ -138,7 +151,6 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
* *
* @param points 积分 * @param points 积分
*/ */
@Transactional(rollbackFor = Exception.class)
@Override @Override
public void deleteUserPoints(BbsUserPoints points) { public void deleteUserPoints(BbsUserPoints points) {
String userName = points.getUserName(); String userName = points.getUserName();
...@@ -146,12 +158,69 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B ...@@ -146,12 +158,69 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
detail.setUserName(userName); detail.setUserName(userName);
detail.setDetailPoints(points.getIncrOrDecrPoints()); detail.setDetailPoints(points.getIncrOrDecrPoints());
detail.setDetailName("后台手动扣减"); detail.setDetailName("后台手动扣减");
// detail.setDescription(String.format("管理员【%s】后台手动扣减用户【%s】积分", SecurityUtils.getUsername(), userName)); String remarks = points.getRemarks();
detail.setDescription(points.getRemarks()); if (StrUtil.isBlank(remarks)) {
remarks = String.format("管理员【%s】后台手动扣减用户【%s】积分", SecurityUtils.getUsername(), userName);
}
detail.setDescription(remarks);
this.decrUserPoints(detail); this.decrUserPoints(detail);
} }
/**
* 增加用户积分
*
* @param bo 积分
*/
@Override
public void batchAddUserPoints(BatchUserPointsBO bo) {
Set<String> userNames = bo.getUserNames();
for (String userName : userNames) {
try {
PointsDetail detail = new PointsDetail();
detail.setUserName(userName);
detail.setDetailPoints(bo.getPoints());
detail.setDetailName("后台手动增加");
String remarks = bo.getRemarks();
if (StrUtil.isBlank(remarks)) {
remarks = String.format("管理员【%s】后台手动增加用户【%s】积分", SecurityUtils.getUsername(), userName);
}
detail.setDescription(remarks);
this.incrUserPoints(detail);
} catch (Exception e) {
log.error("=> 用户:{} 增加积分:{} 失败:", userName, bo.getPoints(), e);
}
}
}
/**
* 扣减用户积分
*
* @param bo 积分
*/
@Override
public void batchDeleteUserPoints(BatchUserPointsBO bo) {
Set<String> userNames = bo.getUserNames();
for (String userName : userNames) {
try {
PointsDetail detail = new PointsDetail();
detail.setUserName(userName);
detail.setDetailPoints(bo.getPoints());
detail.setDetailName("后台手动增加");
String remarks = bo.getRemarks();
if (StrUtil.isBlank(remarks)) {
remarks = String.format("管理员【%s】后台手动扣减用户【%s】积分", SecurityUtils.getUsername(), userName);
}
detail.setDescription(remarks);
this.decrUserPoints(detail);
} catch (Exception e) {
log.error("=> 用户:{} 扣减积分:{} 失败:", userName, bo.getPoints(), e);
}
}
}
/** /**
* 增加用户积分 * 增加用户积分
* *
...@@ -183,13 +252,13 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B ...@@ -183,13 +252,13 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
* *
* @param detail 积分明细 * @param detail 积分明细
*/ */
@Transactional(rollbackFor = Exception.class)
public void privIncrUserPoints(PointsDetail detail) { public void privIncrUserPoints(PointsDetail detail) {
int points = detail.getDetailPoints(); int points = detail.getDetailPoints();
if (points < 1) { if (points < 1) {
throw new ServiceException("增加用户积分失败,增加的积分分值不能小于0。"); throw new ServiceException("增加用户积分失败,增加的积分分值不能小于0。");
} }
this.transactionTemplate.executeWithoutResult(status -> {
try {
// 更新用户积分 // 更新用户积分
String userName = detail.getUserName(); String userName = detail.getUserName();
BbsUserPoints dbUserPoints = this.pointsServiceImpl.getAndInitUserPoints(userName); BbsUserPoints dbUserPoints = this.pointsServiceImpl.getAndInitUserPoints(userName);
...@@ -218,6 +287,12 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B ...@@ -218,6 +287,12 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
newDetail.setAfterPoints(afterCurrentPoints); newDetail.setAfterPoints(afterCurrentPoints);
newDetail.setDescription(detail.getDescription()); newDetail.setDescription(detail.getDescription());
this.pointsDetailService.save(newDetail); this.pointsDetailService.save(newDetail);
} catch (Exception e) {
log.error("=> 处理增加用户积分失败:", e);
status.setRollbackOnly();
}
});
} }
...@@ -226,13 +301,13 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B ...@@ -226,13 +301,13 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
* *
* @param detail 积分明细 * @param detail 积分明细
*/ */
@Transactional(rollbackFor = Exception.class)
public void privDecrUserPoints(PointsDetail detail) { public void privDecrUserPoints(PointsDetail detail) {
int points = detail.getDetailPoints(); int points = detail.getDetailPoints();
if (points < 1) { if (points < 1) {
throw new ServiceException("扣减用户积分失败,扣减的积分分值不能小于0。"); throw new ServiceException("扣减用户积分失败,扣减的积分分值不能小于0。");
} }
this.transactionTemplate.executeWithoutResult(status -> {
try {
String userName = detail.getUserName(); String userName = detail.getUserName();
BbsUserPoints dbUserPoints = this.pointsServiceImpl.getAndInitUserPoints(userName); BbsUserPoints dbUserPoints = this.pointsServiceImpl.getAndInitUserPoints(userName);
Integer beforeCurrentPoints = dbUserPoints.getCurrentPoints(); Integer beforeCurrentPoints = dbUserPoints.getCurrentPoints();
...@@ -257,6 +332,12 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B ...@@ -257,6 +332,12 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
newDetail.setAfterPoints(afterCurrentPoints); newDetail.setAfterPoints(afterCurrentPoints);
newDetail.setDescription(detail.getDescription()); newDetail.setDescription(detail.getDescription());
this.pointsDetailService.save(newDetail); this.pointsDetailService.save(newDetail);
} catch (Exception e) {
log.error("=> 处理扣减用户积分失败:", e);
status.setRollbackOnly();
}
});
} }
} }
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