Commit 776895b4 authored by 万成波's avatar 万成波

积分模块

parent a33627eb
# 项目相关配置
zuoyoucare:
profile: /home/zuoyoucare/service/resources
ruoyi:
profile: E:\Company\TangGuo\safe-campus-bbs\resources
# 数据源配置
spring:
......
package com.tangguo.controller;
import java.util.List;
import javax.annotation.Resource;
import com.tangguo.domain.BbsMomentComment;
import com.tangguo.service.IBbsMomentCommentService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.tangguo.common.annotation.Log;
import com.tangguo.common.core.controller.BaseController;
import com.tangguo.common.core.domain.AjaxResult;
import com.tangguo.common.enums.BusinessType;
import com.tangguo.common.core.page.TableDataInfo;
import com.tangguo.common.enums.BusinessType;
import com.tangguo.domain.BbsMomentComment;
import com.tangguo.service.IBbsMomentCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* 动态评论记录Controller
......@@ -54,7 +50,8 @@ public class BbsMomentCommentController extends BaseController {
@PreAuthorize("@ss.hasPermi('comment:comment:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) {
return success(bbsMomentCommentService.getById(id));
BbsMomentComment comment = this.bbsMomentCommentService.getBbsMomentComment(id);
return success(comment);
}
......
......@@ -5,7 +5,6 @@ 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.BbsSensitiveWord;
import com.tangguo.domain.result.DataImportResult;
import com.tangguo.service.IBbsSensitiveWordService;
......@@ -16,8 +15,6 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;
/**
......
......@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.tangguo.common.annotation.Excel;
import com.tangguo.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
......@@ -11,7 +12,6 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
import com.tangguo.common.annotation.Excel;
import java.util.List;
......@@ -88,7 +88,7 @@ public class BbsMomentComment extends BaseEntity {
/** 删除评论内容 */
@Excel(name = "删除评论内容")
@ApiModelProperty("删除评论内容")
private String deleteContent;
private String deleteComment;
/**
* 动态内容
......
package com.tangguo.domain.result;
import lombok.Data;
import org.apache.poi.ss.formula.functions.T;
import java.io.Serializable;
import java.util.ArrayList;
......
package com.tangguo.service;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.domain.BbsGrade;
import java.util.List;
/**
* 用户等级Service接口
*
......
package com.tangguo.service;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.domain.BbsMomentComment;
import java.util.List;
/**
* 动态评论记录Service接口
*
......
package com.tangguo.service;
import java.util.List;
import java.util.Set;
import com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.domain.BbsSensitiveWord;
import com.tangguo.domain.result.DataImportResult;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Set;
/**
* 敏感词库Service接口
*
......
package com.tangguo.service;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.domain.BbsTopic;
import java.util.List;
/**
* 话题Service接口
*
......
......@@ -6,15 +6,12 @@ import com.tangguo.domain.BbsMomentComment;
import com.tangguo.enums.CommentStatus;
import com.tangguo.mapper.BbsMomentCommentMapper;
import com.tangguo.service.IBbsMomentCommentService;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;
import java.util.Collections;
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
import javax.annotation.Resource;
/**
* 动态评论记录Service业务层处理
*
......@@ -72,7 +69,7 @@ public class BbsMomentCommentServiceImpl extends ServiceImpl<BbsMomentCommentMap
BbsMomentComment updComment = new BbsMomentComment();
updComment.setId(dbComment.getId());
updComment.setStatus(CommentStatus.SC.getStatus());
updComment.setDeleteContent("该评论已被删除");
updComment.setDeleteComment("该评论已被删除");
this.updateById(updComment);
}
......
......@@ -18,7 +18,8 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.io.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
/**
......
......@@ -27,15 +27,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectBbsMomentComments" resultType="com.tangguo.domain.BbsMomentComment">
SELECT
c1.*
r.*
FROM
bbs_moment_comment c1
bbs_moment_comment r
LEFT JOIN
bbs_moment_comment c2 ON c2.id = c1.parent_id
bbs_moment_comment c ON c.id = r.parent_id
WHERE
FIND_IN_SET(#{commentId}, c1.ancestor_path)
FIND_IN_SET(#{commentId}, r.ancestor_path) AND r.id != #{commentId}
ORDER BY
c1.create_time
r.create_time
</select>
</mapper>
......@@ -26,7 +26,7 @@ import java.util.List;
*/
@Api(tags = "积分规则配置管理")
@RestController
@RequestMapping("/points/points")
@RequestMapping("/bbs/points/setting")
public class BbsPointsSettingController extends BaseController {
@Resource
......
......@@ -7,6 +7,8 @@ import com.tangguo.common.core.page.TableDataInfo;
import com.tangguo.common.enums.BusinessType;
import com.tangguo.common.utils.poi.ExcelUtil;
import com.tangguo.domain.BbsUserPoints;
import com.tangguo.domain.BbsUserPointsDetail;
import com.tangguo.service.IBbsUserPointsDetailService;
import com.tangguo.service.IBbsUserPointsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -15,7 +17,6 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;
/**
......@@ -26,12 +27,15 @@ import java.util.List;
*/
@Api(tags = "用户积分管理")
@RestController
@RequestMapping("/points/points")
@RequestMapping("/bbs/points/user/points")
public class BbsUserPointsController extends BaseController {
@Resource
private IBbsUserPointsService bbsUserPointsService;
@Resource
private IBbsUserPointsDetailService pointsDetailService;
/**
* 查询用户积分列表
......@@ -39,13 +43,26 @@ public class BbsUserPointsController extends BaseController {
@ApiOperation("查询用户积分列表")
@PreAuthorize("@ss.hasPermi('points:points:list')")
@GetMapping("/list")
public TableDataInfo list(BbsUserPoints bbsUserPoints) {
public TableDataInfo list(BbsUserPoints points) {
startPage();
List<BbsUserPoints> list = bbsUserPointsService.selectBbsUserPointsList(bbsUserPoints);
List<BbsUserPoints> list = bbsUserPointsService.selectBbsUserPointsList(points);
return getDataTable(list);
}
/**
* 查询用户积分明细
*/
@ApiOperation("查询用户积分明细")
@PreAuthorize("@ss.hasPermi('points:points:list')")
@GetMapping("/details")
public TableDataInfo details(String userName) {
startPage();
List<BbsUserPointsDetail> details = this.pointsDetailService.getUserPointsDetail(userName);
return getDataTable(details);
}
/**
* 导出用户积分列表
*/
......@@ -53,57 +70,36 @@ public class BbsUserPointsController extends BaseController {
@PreAuthorize("@ss.hasPermi('points:points:export')")
@Log(title = "用户积分", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, BbsUserPoints bbsUserPoints) {
List<BbsUserPoints> list = bbsUserPointsService.selectBbsUserPointsList(bbsUserPoints);
ExcelUtil<BbsUserPoints> util = new ExcelUtil<BbsUserPoints>(BbsUserPoints.class);
public void export(HttpServletResponse response, BbsUserPoints points) {
List<BbsUserPoints> list = bbsUserPointsService.selectBbsUserPointsList(points);
ExcelUtil<BbsUserPoints> util = new ExcelUtil<>(BbsUserPoints.class);
util.exportExcel(response, list, "用户积分数据");
}
/**
* 获取用户积分详细信息
*/
@ApiOperation("获取用户积分详细信息")
@PreAuthorize("@ss.hasPermi('points:points:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) {
return success(bbsUserPointsService.getById(id));
}
/**
* 新增用户积分
* 增加用户积分
*/
@ApiOperation("新增用户积分")
@PreAuthorize("@ss.hasPermi('points:points:add')")
@Log(title = "用户积分", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody BbsUserPoints bbsUserPoints) {
return toAjax(bbsUserPointsService.save(bbsUserPoints));
}
/**
* 修改用户积分
*/
@ApiOperation("修改用户积分")
@PreAuthorize("@ss.hasPermi('points:points:edit')")
@PreAuthorize("@ss.hasPermi('points:points:incr')")
@Log(title = "用户积分", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody BbsUserPoints bbsUserPoints) {
return toAjax(bbsUserPointsService.updateById(bbsUserPoints));
@PutMapping("/incr")
public AjaxResult incrUserPoints(@RequestBody BbsUserPoints points) {
this.bbsUserPointsService.addUserPoints(points);
return AjaxResult.success();
}
/**
* 删除用户积分
* 扣减用户积分
*/
@ApiOperation("删除用户积分")
@PreAuthorize("@ss.hasPermi('points:points:remove')")
@Log(title = "用户积分", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) {
return toAjax(bbsUserPointsService.removeByIds(Arrays.asList(ids)));
@ApiOperation("扣减用户积分")
@PreAuthorize("@ss.hasPermi('points:points:decr')")
@Log(title = "用户积分", businessType = BusinessType.UPDATE)
@PutMapping("/decr")
public AjaxResult decrUserPoints(@RequestBody BbsUserPoints points) {
this.bbsUserPointsService.deleteUserPoints(points);
return AjaxResult.success();
}
}
......@@ -26,7 +26,7 @@ import java.util.List;
*/
@Api(tags = "用户积分兑换管理")
@RestController
@RequestMapping("/points/points")
@RequestMapping("/bbs/points/exchange")
public class BbsUserPointsExchangeController extends BaseController {
@Resource
......
package com.tangguo.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.tangguo.common.annotation.Excel;
......@@ -32,11 +33,6 @@ public class BbsUserPoints extends BaseEntity {
@ApiModelProperty("ID")
private Long id;
/** 用户姓名 */
@Excel(name = "用户姓名")
@ApiModelProperty("用户姓名")
private String nikeName;
/** 用户名 */
@Excel(name = "用户名")
@ApiModelProperty("用户名")
......@@ -52,4 +48,37 @@ public class BbsUserPoints extends BaseEntity {
@ApiModelProperty("当前积分")
private Integer currentPoints;
/**
* 用户姓名
*/
@Excel(name = "用户姓名")
@TableField(exist = false)
private String nikeName;
/**
* 用户部门名称
*/
@Excel(name = "部门名称")
@TableField(exist = false)
private String deptName;
/**
* 起始积分
*/
@TableField(exist = false)
private Integer startPoints;
/**
* 截至积分
*/
@TableField(exist = false)
private Integer endPoints;
/**
* 增加或扣减积分
*/
@TableField(exist = false)
private Integer incrOrDecrPoints;
}
......@@ -2,6 +2,9 @@ package com.tangguo.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tangguo.domain.BbsUserPoints;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 用户积分Mapper接口
......@@ -10,4 +13,7 @@ import com.tangguo.domain.BbsUserPoints;
* @date 2025-08-29
*/
public interface BbsUserPointsMapper extends BaseMapper<BbsUserPoints> {
List<BbsUserPoints> selectBbsUserPointsList(@Param("points") BbsUserPoints points);
}
package com.tangguo.service;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.domain.BbsPointsSetting;
import java.util.List;
/**
* 积分规则配置Service接口
*
......
package com.tangguo.service;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.domain.BbsUserPointsDetail;
import java.util.List;
/**
* 用户积分明细Service接口
*
......@@ -12,12 +13,21 @@ import com.tangguo.domain.BbsUserPointsDetail;
*/
public interface IBbsUserPointsDetailService extends IService<BbsUserPointsDetail> {
/**
* 查询用户积分明细
*
* @param userName 用户名
* @return 积分明细
*/
List<BbsUserPointsDetail> getUserPointsDetail(String userName);
/**
* 查询用户积分明细列表
* 添加用户积分明细
*
* @param bbsUserPointsDetail 用户积分明细
* @return 用户积分明细集合
* @param detail 积分明细
*/
List<BbsUserPointsDetail> selectBbsUserPointsDetailList(BbsUserPointsDetail bbsUserPointsDetail);
void addUsrePointsDetail(BbsUserPointsDetail detail);
}
package com.tangguo.service;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.domain.BbsUserPointsExchange;
import java.util.List;
/**
* 用户积分兑换Service接口
*
......
package com.tangguo.service;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.domain.BbsUserPoints;
import com.tangguo.domain.BbsUserPointsDetail;
import java.util.List;
/**
* 用户积分Service接口
......@@ -20,4 +22,49 @@ public interface IBbsUserPointsService extends IService<BbsUserPoints> {
*/
List<BbsUserPoints> selectBbsUserPointsList(BbsUserPoints bbsUserPoints);
/**
* 查询用户积分
*
* @param userName 用户名
* @return 积分
*/
BbsUserPoints getUserPoints(String userName);
/**
* 增加用户积分
*
* @param userName 用户名
* @param points 积分
* @param detail 积分明细
*/
void incrUserPoints(String userName, int points, BbsUserPointsDetail detail);
/**
* 扣减用户积分
*
* @param userName 用户名
* @param points 积分
* @param detail 积分明细
*/
void decrUserPoints(String userName, int points, BbsUserPointsDetail detail);
/**
* 增加用户积分
*
* @param points 积分
*/
void addUserPoints(BbsUserPoints points);
/**
* 扣减用户积分
*
* @param points 积分
*/
void deleteUserPoints(BbsUserPoints points);
}
......@@ -3,11 +3,11 @@ package com.tangguo.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tangguo.common.utils.StringUtils;
import com.tangguo.domain.BbsPointsSetting;
import com.tangguo.mapper.BbsPointsSettingMapper;
import com.tangguo.service.IBbsPointsSettingService;
import org.springframework.stereotype.Service;
import com.tangguo.common.utils.StringUtils;
import javax.annotation.Resource;
import java.util.List;
......
package com.tangguo.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tangguo.domain.BbsUserPointsDetail;
import com.tangguo.mapper.BbsUserPointsDetailMapper;
import com.tangguo.service.IBbsUserPointsDetailService;
import org.springframework.stereotype.Service;
import com.tangguo.common.utils.StringUtils;
import java.util.List;
import java.util.Map;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
/**
* 用户积分明细Service业务层处理
......@@ -25,30 +23,39 @@ public class BbsUserPointsDetailServiceImpl extends ServiceImpl<BbsUserPointsDet
@Resource
private BbsUserPointsDetailMapper bbsUserPointsDetailMapper;
/**
* 查询用户积分明细列表
* 查询用户积分明细
*
* @param bbsUserPointsDetail 用户积分明细
* @return 用户积分明细
* @param userName 用户名
* @return 积分明细
*/
@Override
public List<BbsUserPointsDetail> selectBbsUserPointsDetailList(BbsUserPointsDetail bbsUserPointsDetail) {
return bbsUserPointsDetailMapper.selectList(buildQueryWrapper(bbsUserPointsDetail));
public List<BbsUserPointsDetail> getUserPointsDetail(String userName) {
return this.list(
Wrappers.lambdaQuery(BbsUserPointsDetail.class)
.eq(BbsUserPointsDetail::getUserName, userName)
);
}
private LambdaQueryWrapper<BbsUserPointsDetail> buildQueryWrapper(BbsUserPointsDetail query) {
Map<String, Object> params = query.getParams();
LambdaQueryWrapper<BbsUserPointsDetail> lqw = Wrappers.lambdaQuery();
lqw.orderByDesc(BbsUserPointsDetail::getCreateTime);
lqw.like(StringUtils.isNotBlank(query.getUserName()), BbsUserPointsDetail::getUserName, query.getUserName());
lqw.like(StringUtils.isNotBlank(query.getDetailName()), BbsUserPointsDetail::getDetailName, query.getDetailName());
lqw.eq(StringUtils.isNotBlank(query.getDetailCode()), BbsUserPointsDetail::getDetailCode, query.getDetailCode());
lqw.eq(query.getDetailPoints() != null, BbsUserPointsDetail::getDetailPoints, query.getDetailPoints());
lqw.eq(query.getBeforePoints() != null, BbsUserPointsDetail::getBeforePoints, query.getBeforePoints());
lqw.eq(query.getAfterPoints() != null, BbsUserPointsDetail::getAfterPoints, query.getAfterPoints());
lqw.eq(StringUtils.isNotBlank(query.getDescription()), BbsUserPointsDetail::getDescription, query.getDescription());
return lqw;
/**
* 添加用户积分明细
*
* @param detail 积分明细
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void addUsrePointsDetail(BbsUserPointsDetail detail) {
BbsUserPointsDetail addDetail = new BbsUserPointsDetail();
addDetail.setUserName(detail.getUserName());
addDetail.setDetailName(detail.getDetailName());
addDetail.setDetailCode(detail.getDetailCode());
addDetail.setDetailPoints(detail.getDetailPoints());
addDetail.setBeforePoints(detail.getBeforePoints());
addDetail.setAfterPoints(detail.getAfterPoints());
addDetail.setDescription(detail.getDescription());
this.save(addDetail);
}
}
......@@ -3,15 +3,15 @@ package com.tangguo.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tangguo.common.utils.StringUtils;
import com.tangguo.domain.BbsUserPointsExchange;
import com.tangguo.mapper.BbsUserPointsExchangeMapper;
import com.tangguo.service.IBbsUserPointsExchangeService;
import org.springframework.stereotype.Service;
import com.tangguo.common.utils.StringUtils;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
* 用户积分兑换Service业务层处理
......
package com.tangguo.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tangguo.common.exception.ServiceException;
import com.tangguo.common.utils.SecurityUtils;
import com.tangguo.domain.BbsUserPoints;
import com.tangguo.domain.BbsUserPointsDetail;
import com.tangguo.mapper.BbsUserPointsMapper;
import com.tangguo.service.IBbsUserPointsDetailService;
import com.tangguo.service.IBbsUserPointsService;
import org.springframework.stereotype.Service;
import com.tangguo.common.utils.StringUtils;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionTemplate;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* 用户积分Service业务层处理
......@@ -25,27 +30,140 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
@Resource
private BbsUserPointsMapper bbsUserPointsMapper;
@Resource
private IBbsUserPointsDetailService pointsDetailService;
/**
* 查询用户积分列表
*
* @param bbsUserPoints 用户积分
* @param points 用户积分
* @return 用户积分
*/
@Override
public List<BbsUserPoints> selectBbsUserPointsList(BbsUserPoints bbsUserPoints) {
return bbsUserPointsMapper.selectList(buildQueryWrapper(bbsUserPoints));
public List<BbsUserPoints> selectBbsUserPointsList(BbsUserPoints points) {
return this.baseMapper.selectBbsUserPointsList(points);
}
/**
* 查询用户积分
*
* @param userName 用户名
* @return 积分
*/
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
@Override
public BbsUserPoints getUserPoints(String userName) {
BbsUserPoints dbUserPoints = this.getOne(
Wrappers.lambdaQuery(BbsUserPoints.class).eq(BbsUserPoints::getUserName, userName)
);
if (Objects.isNull(dbUserPoints)) {
dbUserPoints = new BbsUserPoints();
dbUserPoints.setUserName(userName);
dbUserPoints.setAccumulatedPoints(0);
dbUserPoints.setCurrentPoints(0);
this.save(dbUserPoints);
}
return dbUserPoints;
}
/**
* 增加用户积分
*
* @param userName 用户名
* @param points 积分
* @param detail 积分明细
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void incrUserPoints(String userName, int points, BbsUserPointsDetail detail) {
if (points < 1) {
throw new ServiceException("增加用户积分失败,增加的积分分值不能小于0。");
}
// 更新用户积分
BbsUserPoints userPoints = this.getUserPoints(userName);
Integer currentPoints = userPoints.getCurrentPoints();
int incrCurrentPoints = currentPoints + points;
userPoints.setCurrentPoints(incrCurrentPoints);
userPoints.setAccumulatedPoints(userPoints.getAccumulatedPoints() + points);
this.updateById(userPoints);
// 添加用户积分明细
detail.setUserName(userName);
detail.setDetailPoints(points);
detail.setBeforePoints(currentPoints);
detail.setAfterPoints(incrCurrentPoints);
this.pointsDetailService.addUsrePointsDetail(detail);
}
/**
* 扣减用户积分
*
* @param userName 用户名
* @param points 积分
* @param detail 积分明细
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void decrUserPoints(String userName, int points, BbsUserPointsDetail detail) {
if (points < 1) {
throw new ServiceException("扣减用户积分失败,扣减的积分分值不能小于0。");
}
// 更新用户积分
BbsUserPoints userPoints = this.getUserPoints(userName);
Integer currentPoints = userPoints.getCurrentPoints();
if (points > currentPoints) {
throw new ServiceException("扣减用户积分失败,当前用户可用积分不足。");
}
int decrCurrentPoints = currentPoints - points;
userPoints.setCurrentPoints(decrCurrentPoints);
userPoints.setAccumulatedPoints(userPoints.getAccumulatedPoints() - points);
this.updateById(userPoints);
// 添加用户积分明细
detail.setUserName(userName);
detail.setDetailPoints(points);
detail.setBeforePoints(currentPoints);
detail.setAfterPoints(decrCurrentPoints);
this.pointsDetailService.addUsrePointsDetail(detail);
}
/**
* 增加用户积分
*
* @param points 积分
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void addUserPoints(BbsUserPoints points) {
String userName = points.getUserName();
BbsUserPointsDetail detail = new BbsUserPointsDetail();
detail.setDetailName("后台手动增加");
detail.setDescription(String.format("管理员【%s】后台手动增加用户【%s】积分", SecurityUtils.getUsername(), userName));
this.incrUserPoints(userName, points.getIncrOrDecrPoints(), detail);
}
private LambdaQueryWrapper<BbsUserPoints> buildQueryWrapper(BbsUserPoints query) {
Map<String, Object> params = query.getParams();
LambdaQueryWrapper<BbsUserPoints> lqw = Wrappers.lambdaQuery();
lqw.orderByDesc(BbsUserPoints::getCreateTime);
lqw.like(StringUtils.isNotBlank(query.getNikeName()), BbsUserPoints::getNikeName, query.getNikeName());
lqw.like(StringUtils.isNotBlank(query.getUserName()), BbsUserPoints::getUserName, query.getUserName());
lqw.eq(query.getAccumulatedPoints() != null, BbsUserPoints::getAccumulatedPoints, query.getAccumulatedPoints());
lqw.eq(query.getCurrentPoints() != null, BbsUserPoints::getCurrentPoints, query.getCurrentPoints());
return lqw;
/**
* 扣减用户积分
*
* @param points 积分
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void deleteUserPoints(BbsUserPoints points) {
String userName = points.getUserName();
BbsUserPointsDetail detail = new BbsUserPointsDetail();
detail.setDetailName("后台手动扣减");
detail.setDescription(String.format("管理员【%s】后台手动扣减用户【%s】积分", SecurityUtils.getUsername(), userName));
this.decrUserPoints(userName, points.getIncrOrDecrPoints(), detail);
}
}
......@@ -3,5 +3,35 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tangguo.mapper.BbsUserPointsMapper">
<select id="selectBbsUserPointsList" resultType="com.tangguo.domain.BbsUserPoints">
SELECT
p.id,
IFNULL(p.accumulated_points, 0) AS accumulated_points,
IFNULL(p.current_points, 0) AS current_points,
uv.user_name,
uv.nike_name,
uv.dept_name
FROM
qwmh_sys_user_view uv
LEFT JOIN
bbs_user_points p ON p.user_name = uv.user_name
<where>
<if test="points.nikeName != null and points.nikeName != ''">
uv.nike_name LIKE CONCAT('%', #{points.nikeName}, '%')
</if>
<if test="points.userName != null and points.userName != ''">
AND uv.user_name LIKE CONCAT('%', #{points.userName}, '%')
</if>
<if test="points.startPoints != null">
AND p.current_points >= #{points.startPoints}
</if>
<if test="points.endPoints != null">
AND p.current_points &lt;= #{points.endPoints}
</if>
</where>
ORDER BY
p.accumulated_points DESC
</select>
</mapper>
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