Commit 78afd66a authored by 万成波's avatar 万成波

积分模块

parent 7109b0ae
...@@ -84,7 +84,7 @@ public class BbsUserPointsController extends BaseController { ...@@ -84,7 +84,7 @@ public class BbsUserPointsController extends BaseController {
@PreAuthorize("@ss.hasPermi('points:points:incr')") @PreAuthorize("@ss.hasPermi('points:points:incr')")
@Log(title = "用户积分", businessType = BusinessType.UPDATE) @Log(title = "用户积分", businessType = BusinessType.UPDATE)
@PutMapping("/incr") @PutMapping("/incr")
public synchronized AjaxResult incrUserPoints(@RequestBody BbsUserPoints points) { public AjaxResult incrUserPoints(@RequestBody BbsUserPoints points) {
this.bbsUserPointsService.addUserPoints(points); this.bbsUserPointsService.addUserPoints(points);
return AjaxResult.success(); return AjaxResult.success();
} }
...@@ -97,7 +97,7 @@ public class BbsUserPointsController extends BaseController { ...@@ -97,7 +97,7 @@ public class BbsUserPointsController extends BaseController {
@PreAuthorize("@ss.hasPermi('points:points:decr')") @PreAuthorize("@ss.hasPermi('points:points:decr')")
@Log(title = "用户积分", businessType = BusinessType.UPDATE) @Log(title = "用户积分", businessType = BusinessType.UPDATE)
@PutMapping("/decr") @PutMapping("/decr")
public synchronized AjaxResult decrUserPoints(@RequestBody BbsUserPoints points) { public AjaxResult decrUserPoints(@RequestBody BbsUserPoints points) {
this.bbsUserPointsService.deleteUserPoints(points); this.bbsUserPointsService.deleteUserPoints(points);
return AjaxResult.success(); return AjaxResult.success();
} }
......
...@@ -93,7 +93,9 @@ public class BbsUserPointsExchangeController extends BaseController { ...@@ -93,7 +93,9 @@ public class BbsUserPointsExchangeController extends BaseController {
@Log(title = "用户积分兑换", businessType = BusinessType.INSERT) @Log(title = "用户积分兑换", businessType = BusinessType.INSERT)
@PostMapping("/exchange") @PostMapping("/exchange")
public synchronized AjaxResult exchange(@RequestBody BbsUserPointsExchange exchange) { public synchronized AjaxResult exchange(@RequestBody BbsUserPointsExchange exchange) {
this.bbsUserPointsExchangeService.addUserPointsExchange(exchange); synchronized (exchange.getUserName().intern()) {
this.bbsUserPointsExchangeService.addUserPointsExchange(exchange);
}
return AjaxResult.success(); return AjaxResult.success();
} }
......
...@@ -2,7 +2,6 @@ package com.tangguo.service; ...@@ -2,7 +2,6 @@ package com.tangguo.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.domain.BbsUserPoints; import com.tangguo.domain.BbsUserPoints;
import com.tangguo.domain.BbsUserPointsDetail;
import com.tangguo.domain.dto.PointsDetailDTO; import com.tangguo.domain.dto.PointsDetailDTO;
import java.util.List; import java.util.List;
...@@ -36,36 +35,36 @@ public interface IBbsUserPointsService extends IService<BbsUserPoints> { ...@@ -36,36 +35,36 @@ public interface IBbsUserPointsService extends IService<BbsUserPoints> {
/** /**
* 增加用户积分 * 增加用户积分
* *
* @param userName 用户名
* @param points 积分 * @param points 积分
* @param detail 积分明细
*/ */
void incrUserPoints(String userName, int points, PointsDetailDTO detail); void addUserPoints(BbsUserPoints points);
/** /**
* 扣减用户积分 * 扣减用户积分
* *
* @param userName 用户名
* @param points 积分 * @param points 积分
* @param detail 积分明细
*/ */
void decrUserPoints(String userName, int points, PointsDetailDTO detail); void deleteUserPoints(BbsUserPoints points);
/** /**
* 增加用户积分 * 增加用户积分
* *
* @param userName 用户名
* @param points 积分 * @param points 积分
* @param detail 积分明细
*/ */
void addUserPoints(BbsUserPoints points); void incrUserPoints(String userName, int points, PointsDetailDTO detail);
/** /**
* 扣减用户积分 * 扣减用户积分
* *
* @param userName 用户名
* @param points 积分 * @param points 积分
* @param detail 积分明细
*/ */
void deleteUserPoints(BbsUserPoints points); void decrUserPoints(String userName, int points, PointsDetailDTO detail);
} }
...@@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; ...@@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tangguo.common.exception.ServiceException; import com.tangguo.common.exception.ServiceException;
import com.tangguo.domain.BbsPointsGoods; import com.tangguo.domain.BbsPointsGoods;
import com.tangguo.domain.BbsUserPoints; import com.tangguo.domain.BbsUserPoints;
import com.tangguo.domain.BbsUserPointsDetail;
import com.tangguo.domain.BbsUserPointsExchange; import com.tangguo.domain.BbsUserPointsExchange;
import com.tangguo.domain.dto.PointsDetailDTO; import com.tangguo.domain.dto.PointsDetailDTO;
import com.tangguo.mapper.BbsUserPointsExchangeMapper; import com.tangguo.mapper.BbsUserPointsExchangeMapper;
......
...@@ -33,6 +33,9 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B ...@@ -33,6 +33,9 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
@Resource @Resource
private IBbsUserPointsDetailService pointsDetailService; private IBbsUserPointsDetailService pointsDetailService;
@Resource
private BbsUserPointsServiceImpl userPointsServiceImpl;
/** /**
* 查询用户积分列表 * 查询用户积分列表
...@@ -69,6 +72,38 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B ...@@ -69,6 +72,38 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
} }
/**
* 增加用户积分
*
* @param points 积分
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void addUserPoints(BbsUserPoints points) {
String userName = points.getUserName();
PointsDetailDTO detail = new PointsDetailDTO();
detail.setDetailName("后台手动增加");
detail.setDescription(String.format("管理员【%s】后台手动增加用户【%s】积分", SecurityUtils.getUsername(), userName));
this.incrUserPoints(userName, points.getIncrOrDecrPoints(), detail);
}
/**
* 扣减用户积分
*
* @param points 积分
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void deleteUserPoints(BbsUserPoints points) {
String userName = points.getUserName();
PointsDetailDTO detail = new PointsDetailDTO();
detail.setDetailName("后台手动扣减");
detail.setDescription(String.format("管理员【%s】后台手动扣减用户【%s】积分", SecurityUtils.getUsername(), userName));
this.decrUserPoints(userName, points.getIncrOrDecrPoints(), detail);
}
/** /**
* 增加用户积分 * 增加用户积分
* *
...@@ -76,9 +111,38 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B ...@@ -76,9 +111,38 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
* @param points 积分 * @param points 积分
* @param detail 积分明细 * @param detail 积分明细
*/ */
@Transactional(rollbackFor = Exception.class)
@Override @Override
public void incrUserPoints(String userName, int points, PointsDetailDTO detail) { public void incrUserPoints(String userName, int points, PointsDetailDTO detail) {
synchronized (userName.intern()) {
this.userPointsServiceImpl.execIncrUserPoints(userName, points, detail);
}
}
/**
* 扣减用户积分
*
* @param userName 用户名
* @param points 积分
* @param detail 积分明细
*/
@Override
public void decrUserPoints(String userName, int points, PointsDetailDTO detail) {
synchronized (userName.intern()) {
this.userPointsServiceImpl.execDecrUserPoints(userName, points, detail);
}
}
/**
* 增加用户积分
*
* @param userName 用户名
* @param points 积分
* @param detail 积分明细
*/
@Transactional(rollbackFor = Exception.class)
public void execIncrUserPoints(String userName, int points, PointsDetailDTO detail) {
if (points < 1) { if (points < 1) {
throw new ServiceException("增加用户积分失败,增加的积分分值不能小于0。"); throw new ServiceException("增加用户积分失败,增加的积分分值不能小于0。");
} }
...@@ -112,8 +176,7 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B ...@@ -112,8 +176,7 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
* @param detail 积分明细 * @param detail 积分明细
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override public void execDecrUserPoints(String userName, int points, PointsDetailDTO detail) {
public void decrUserPoints(String userName, int points, PointsDetailDTO detail) {
if (points < 1) { if (points < 1) {
throw new ServiceException("扣减用户积分失败,扣减的积分分值不能小于0。"); throw new ServiceException("扣减用户积分失败,扣减的积分分值不能小于0。");
} }
...@@ -141,36 +204,4 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B ...@@ -141,36 +204,4 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
this.pointsDetailService.save(newDetail); this.pointsDetailService.save(newDetail);
} }
/**
* 增加用户积分
*
* @param points 积分
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void addUserPoints(BbsUserPoints points) {
String userName = points.getUserName();
PointsDetailDTO detail = new PointsDetailDTO();
detail.setDetailName("后台手动增加");
detail.setDescription(String.format("管理员【%s】后台手动增加用户【%s】积分", SecurityUtils.getUsername(), userName));
this.incrUserPoints(userName, points.getIncrOrDecrPoints(), detail);
}
/**
* 扣减用户积分
*
* @param points 积分
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void deleteUserPoints(BbsUserPoints points) {
String userName = points.getUserName();
PointsDetailDTO detail = new PointsDetailDTO();
detail.setDetailName("后台手动扣减");
detail.setDescription(String.format("管理员【%s】后台手动扣减用户【%s】积分", SecurityUtils.getUsername(), userName));
this.decrUserPoints(userName, points.getIncrOrDecrPoints(), detail);
}
} }
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