Commit 5810f480 authored by yuwenwen's avatar yuwenwen
parents dad21b04 84996912
......@@ -37,6 +37,12 @@
<groupId>com.tangguo</groupId>
<artifactId>safe-campus-moment</artifactId>
</dependency>
<!-- 积分模块 -->
<dependency>
<groupId>com.tangguo</groupId>
<artifactId>safe-campus-points</artifactId>
</dependency>
</dependencies>
<build>
......
# 项目相关配置
zuoyoucare:
profile: /home/zuoyoucare/service/resources
ruoyi:
profile: E:\Company\TangGuo\safe-campus-bbs\resources
# 数据源配置
spring:
......@@ -33,7 +33,7 @@ spring:
# 配置网络超时时间
socketTimeout: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis: 60000
timeBetweenEvictionRunsMillis: 10000
# 配置一个连接在池中最小生存的时间,单位是毫秒
minEvictableIdleTimeMillis: 300000
# 配置一个连接在池中最大生存的时间,单位是毫秒
......
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
......@@ -27,7 +23,7 @@ import com.tangguo.common.core.page.TableDataInfo;
*/
@Api(tags="动态评论记录管理")
@RestController
@RequestMapping("/comment/comment")
@RequestMapping("/bbs/moment/comment")
public class BbsMomentCommentController extends BaseController {
@Resource
......@@ -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);
}
......
package com.tangguo.controller;
import com.tangguo.common.annotation.Log;
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.domain.BbsPointsGoods;
import com.tangguo.service.IBbsPointsGoodsService;
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
*
* @author ruoyi
* @date 2025-08-28
*/
@Api(tags = "积分商品管理")
@RestController
@RequestMapping("/bbs/moment/goods")
public class BbsPointsGoodsController extends BaseController {
@Resource
private IBbsPointsGoodsService bbsPointsGoodsService;
/**
* 查询积分商品列表
*/
@ApiOperation("查询积分商品列表")
@PreAuthorize("@ss.hasPermi('goods:goods:list')")
@GetMapping("/list")
public TableDataInfo list(BbsPointsGoods bbsPointsGoods) {
startPage();
List<BbsPointsGoods> list = bbsPointsGoodsService.selectBbsPointsGoodsList(bbsPointsGoods);
return getDataTable(list);
}
/**
* 获取积分商品详细信息
*/
@ApiOperation("获取积分商品详细信息")
@PreAuthorize("@ss.hasPermi('goods:goods:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) {
return success(bbsPointsGoodsService.getById(id));
}
/**
* 新增积分商品
*/
@ApiOperation("新增积分商品")
@PreAuthorize("@ss.hasPermi('goods:goods:add')")
@Log(title = "积分商品", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody BbsPointsGoods goods) {
this.bbsPointsGoodsService.addGoods(goods);
return AjaxResult.success();
}
/**
* 修改积分商品
*/
@ApiOperation("修改积分商品")
@PreAuthorize("@ss.hasPermi('goods:goods:edit')")
@Log(title = "积分商品", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody BbsPointsGoods goods) {
this.bbsPointsGoodsService.editGoods(goods);
return AjaxResult.success();
}
/**
* 删除积分商品
*/
@ApiOperation("删除积分商品")
@PreAuthorize("@ss.hasPermi('goods:goods:remove')")
@Log(title = "积分商品", businessType = BusinessType.DELETE)
@DeleteMapping("/{id}")
public AjaxResult remove(@PathVariable Long id) {
this.bbsPointsGoodsService.deleteGoods(id);
return AjaxResult.success();
}
}
......@@ -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.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 商品上下架状态
*
* @author 谈笑
* @createTime 2025-08-28 16:32:15 星期四
*/
@Getter
@AllArgsConstructor
public enum ShowStatus {
SJ(1, "上架"), XJ(0, "下架");
private final int status;
private final String desc;
}
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 com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.domain.BbsPointsGoods;
/**
* 积分商品Service接口
*
* @author ruoyi
* @date 2025-08-28
*/
public interface IBbsPointsGoodsService extends IService<BbsPointsGoods> {
/**
* 查询积分商品列表
*
* @param bbsPointsGoods 积分商品
* @return 积分商品集合
*/
List<BbsPointsGoods> selectBbsPointsGoodsList(BbsPointsGoods bbsPointsGoods);
/**
* 添加积分商品
*
* @param goods 积分商品
*/
void addGoods(BbsPointsGoods goods);
/**
* 修改积分商品
*
* @param goods 积分商品
*/
void editGoods(BbsPointsGoods goods);
/**
* 删除积分商品
*
* @param goodsId 积分商品Id
*/
void deleteGoods(Long goodsId);
}
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接口
*
......
......@@ -111,6 +111,9 @@ public class BbsGradeServiceImpl extends ServiceImpl<BbsGradeMapper, BbsGrade> i
List<BbsGrade> dbGrades = this.list();
for (BbsGrade g : dbGrades) {
if (g.getId().equals(dbGrade.getId())) {
continue;
}
if (!(e1 < g.getMinPoints() || s1 > g.getMaxPoints())) {
throw new ServiceException("修改失败,当前等级积分范围和等级【" + g.getName() + "】积分范围冲突。");
}
......@@ -122,7 +125,7 @@ public class BbsGradeServiceImpl extends ServiceImpl<BbsGradeMapper, BbsGrade> i
updGrade.setSort(grade.getSort());
updGrade.setMinPoints(grade.getMinPoints());
updGrade.setMaxPoints(grade.getMaxPoints());
this.save(updGrade);
this.updateById(updGrade);
}
......
......@@ -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);
}
......
package com.tangguo.service.impl;
import cn.hutool.core.util.IdUtil;
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.StringUtils;
import com.tangguo.domain.BbsPointsGoods;
import com.tangguo.mapper.BbsPointsGoodsMapper;
import com.tangguo.service.IBbsPointsGoodsService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
/**
* 积分商品Service业务层处理
*
* @author ruoyi
* @date 2025-08-28
*/
@Service
public class BbsPointsGoodsServiceImpl extends ServiceImpl<BbsPointsGoodsMapper, BbsPointsGoods> implements IBbsPointsGoodsService {
@Resource
private BbsPointsGoodsMapper bbsPointsGoodsMapper;
/**
* 查询积分商品列表
*
* @param goods 积分商品
* @return 积分商品
*/
@Override
public List<BbsPointsGoods> selectBbsPointsGoodsList(BbsPointsGoods goods) {
LambdaQueryWrapper<BbsPointsGoods> lqw = Wrappers.lambdaQuery();
lqw.orderByDesc(BbsPointsGoods::getCreateTime);
lqw.like(StringUtils.isNotBlank(goods.getName()), BbsPointsGoods::getName, goods.getName());
lqw.eq(StringUtils.isNotBlank(goods.getCode()), BbsPointsGoods::getCode, goods.getCode());
lqw.eq(StringUtils.isNotBlank(goods.getImgsUrl()), BbsPointsGoods::getImgsUrl, goods.getImgsUrl());
lqw.eq(goods.getSalesPrice() != null, BbsPointsGoods::getSalesPrice, goods.getSalesPrice());
lqw.eq(goods.getExchangePoints() != null, BbsPointsGoods::getExchangePoints, goods.getExchangePoints());
lqw.eq(goods.getStockNum() != null, BbsPointsGoods::getStockNum, goods.getStockNum());
lqw.eq(goods.getSalesNum() != null, BbsPointsGoods::getSalesNum, goods.getSalesNum());
lqw.eq(goods.getShowStatus() != null, BbsPointsGoods::getShowStatus, goods.getShowStatus());
return bbsPointsGoodsMapper.selectList(lqw);
}
/**
* 添加积分商品
*
* @param goods 积分商品
*/
@Override
public void addGoods(BbsPointsGoods goods) {
long nameCount = this.count(
Wrappers.lambdaQuery(BbsPointsGoods.class).eq(BbsPointsGoods::getName, goods.getName())
);
if (nameCount > 0) {
throw new ServiceException("添加失败,当前商品名称已存在。");
}
BbsPointsGoods addGoods = new BbsPointsGoods();
addGoods.setName(goods.getName());
addGoods.setCode(IdUtil.fastSimpleUUID());
addGoods.setImgsUrl(goods.getImgsUrl());
addGoods.setSalesPrice(goods.getSalesPrice());
addGoods.setExchangePoints(goods.getExchangePoints());
addGoods.setStockNum(goods.getStockNum());
addGoods.setSalesNum(0);
addGoods.setShowStatus(goods.getShowStatus());
this.save(addGoods);
}
/**
* 修改积分商品
*
* @param goods 积分商品
*/
@Override
public void editGoods(BbsPointsGoods goods) {
BbsPointsGoods dbGoods = this.getById(goods.getId());
if (Objects.isNull(dbGoods)) {
throw new ServiceException("修改失败,未查询到当前商品数据。");
}
if (!dbGoods.getName().equals(goods.getName())) {
long nameCount = this.count(
Wrappers.lambdaQuery(BbsPointsGoods.class).eq(BbsPointsGoods::getName, goods.getName())
);
if (nameCount > 0) {
throw new ServiceException("修改失败,当前商品名称已存在。");
}
}
BbsPointsGoods addGoods = new BbsPointsGoods();
addGoods.setId(dbGoods.getId());
addGoods.setName(goods.getName());
addGoods.setImgsUrl(goods.getImgsUrl());
addGoods.setSalesPrice(goods.getSalesPrice());
addGoods.setExchangePoints(goods.getExchangePoints());
addGoods.setStockNum(goods.getStockNum());
addGoods.setShowStatus(goods.getShowStatus());
this.updateById(addGoods);
}
/**
* 删除积分商品
*
* @param goodsId 积分商品Id
*/
@Override
public void deleteGoods(Long goodsId) {
this.removeById(goodsId);
}
}
......@@ -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>
package com.tangguo.controller;
import com.tangguo.common.annotation.Log;
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.BbsPointsSetting;
import com.tangguo.service.IBbsPointsSettingService;
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 javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;
/**
* 积分规则配置Controller
*
* @author ruoyi
* @date 2025-08-29
*/
@Api(tags = "积分规则配置管理")
@RestController
@RequestMapping("/bbs/points/setting")
public class BbsPointsSettingController extends BaseController {
@Resource
private IBbsPointsSettingService bbsPointsSettingService;
/**
* 查询积分规则配置列表
*/
@ApiOperation("查询积分规则配置列表")
@PreAuthorize("@ss.hasPermi('points:points:list')")
@GetMapping("/list")
public TableDataInfo list(BbsPointsSetting bbsPointsSetting) {
startPage();
List<BbsPointsSetting> list = bbsPointsSettingService.selectBbsPointsSettingList(bbsPointsSetting);
return getDataTable(list);
}
/**
* 导出积分规则配置列表
*/
@ApiOperation("导出积分规则配置列表")
@PreAuthorize("@ss.hasPermi('points:points:export')")
@Log(title = "积分规则配置", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, BbsPointsSetting bbsPointsSetting) {
List<BbsPointsSetting> list = bbsPointsSettingService.selectBbsPointsSettingList(bbsPointsSetting);
ExcelUtil<BbsPointsSetting> util = new ExcelUtil<BbsPointsSetting>(BbsPointsSetting.class);
util.exportExcel(response, list, "积分规则配置数据");
}
/**
* 获取积分规则配置详细信息
*/
@ApiOperation("获取积分规则配置详细信息")
@PreAuthorize("@ss.hasPermi('points:points:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) {
return success(bbsPointsSettingService.getById(id));
}
/**
* 新增积分规则配置
*/
@ApiOperation("新增积分规则配置")
@PreAuthorize("@ss.hasPermi('points:points:add')")
@Log(title = "积分规则配置", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody BbsPointsSetting bbsPointsSetting) {
return toAjax(bbsPointsSettingService.save(bbsPointsSetting));
}
/**
* 修改积分规则配置
*/
@ApiOperation("修改积分规则配置")
@PreAuthorize("@ss.hasPermi('points:points:edit')")
@Log(title = "积分规则配置", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody BbsPointsSetting bbsPointsSetting) {
return toAjax(bbsPointsSettingService.updateById(bbsPointsSetting));
}
/**
* 删除积分规则配置
*/
@ApiOperation("删除积分规则配置")
@PreAuthorize("@ss.hasPermi('points:points:remove')")
@Log(title = "积分规则配置", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) {
return toAjax(bbsPointsSettingService.removeByIds(Arrays.asList(ids)));
}
}
package com.tangguo.controller;
import com.tangguo.common.annotation.Log;
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.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;
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;
/**
* 用户积分Controller
*
* @author ruoyi
* @date 2025-08-29
*/
@Api(tags = "用户积分管理")
@RestController
@RequestMapping("/bbs/points/user/points")
public class BbsUserPointsController extends BaseController {
@Resource
private IBbsUserPointsService bbsUserPointsService;
@Resource
private IBbsUserPointsDetailService pointsDetailService;
/**
* 查询用户积分列表
*/
@ApiOperation("查询用户积分列表")
@PreAuthorize("@ss.hasPermi('points:points:list')")
@GetMapping("/list")
public TableDataInfo list(BbsUserPoints points) {
startPage();
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);
}
/**
* 导出用户积分列表
*/
@ApiOperation("导出用户积分列表")
@PreAuthorize("@ss.hasPermi('points:points:export')")
@Log(title = "用户积分", businessType = BusinessType.EXPORT)
@PostMapping("/export")
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:incr')")
@Log(title = "用户积分", businessType = BusinessType.UPDATE)
@PutMapping("/incr")
public AjaxResult incrUserPoints(@RequestBody BbsUserPoints points) {
this.bbsUserPointsService.addUserPoints(points);
return AjaxResult.success();
}
/**
* 扣减用户积分
*/
@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();
}
}
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.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;
import com.tangguo.mapper.BbsUserPointsExchangeMapper;
import com.tangguo.service.IBbsPointsGoodsService;
import com.tangguo.service.IBbsUserPointsExchangeService;
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
*
* @author ruoyi
* @date 2025-08-29
*/
@Api(tags = "用户积分兑换管理")
@RestController
@RequestMapping("/bbs/points/exchange")
public class BbsUserPointsExchangeController extends BaseController {
@Resource
private BbsUserPointsExchangeMapper userPointsExchangeMapper;
@Resource
private IBbsUserPointsExchangeService bbsUserPointsExchangeService;
@Resource
private IBbsPointsGoodsService pointsGoodsService;
/**
* 查询兑换人
*/
@ApiOperation("查询兑换人")
@PreAuthorize("@ss.hasPermi('points:points:list')")
@GetMapping("/select/users")
public AjaxResult selectUsers(String keyword) {
List<QwmhSysUserVO> users = this.userPointsExchangeMapper.selectPointsUsers(keyword);
return AjaxResult.success(users);
}
/**
* 查询兑换商品
*/
@ApiOperation("查询兑换人")
@PreAuthorize("@ss.hasPermi('points:points:list')")
@GetMapping("/select/goods")
public AjaxResult selectGoods(String keyword) {
LambdaQueryWrapper<BbsPointsGoods> wrapper = new LambdaQueryWrapper<>();
wrapper.like(StrUtil.isNotBlank(keyword), BbsPointsGoods::getName, keyword);
wrapper.or();
wrapper.like(StrUtil.isNotBlank(keyword), BbsPointsGoods::getCode, keyword);
wrapper.orderByDesc(BbsPointsGoods::getCreateTime);
List<BbsPointsGoods> goods = this.pointsGoodsService.list(wrapper);
return AjaxResult.success(goods);
}
/**
* 查询用户积分兑换列表
*/
@ApiOperation("查询用户积分兑换列表")
@PreAuthorize("@ss.hasPermi('points:points:list')")
@GetMapping("/list")
public TableDataInfo list(BbsUserPointsExchange exchange) {
startPage();
List<BbsUserPointsExchange> list = bbsUserPointsExchangeService.selectBbsUserPointsExchangeList(exchange);
return getDataTable(list);
}
/**
* 用户积分兑换
*/
@ApiOperation("用户积分兑换")
@PreAuthorize("@ss.hasPermi('points:points:exchange')")
@Log(title = "用户积分兑换", businessType = BusinessType.INSERT)
@PostMapping("/exchange")
public synchronized AjaxResult exchange(@RequestBody BbsUserPointsExchange exchange) {
synchronized (exchange.getUserName().intern()) {
this.bbsUserPointsExchangeService.addUserPointsExchange(exchange);
}
return AjaxResult.success();
}
}
package com.tangguo.domain;
import com.baomidou.mybatisplus.annotation.IdType;
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;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
/**
* 积分规则配置对象 bbs_points_setting
*
* @author ruoyi
* @date 2025-08-29
*/
@Data
@ToString
@NoArgsConstructor
@Accessors(chain = true)
@TableName("bbs_points_setting")
@ApiModel(value = "BbsPointsSetting", description = "积分规则配置实体")
public class BbsPointsSetting extends BaseEntity {
private static final long serialVersionUID = 1L;
/** ID */
@TableId(type = IdType.AUTO)
@ApiModelProperty("ID")
private Long id;
/** 设置类型:ADD 增加积分、DEC 减少积分 */
@Excel(name = "设置类型:ADD 增加积分、DEC 减少积分")
@ApiModelProperty("设置类型:ADD 增加积分、DEC 减少积分")
private String type;
/** 应用名称 */
@Excel(name = "应用名称")
@ApiModelProperty("应用名称")
private String agentName;
/** 应用ID */
@Excel(name = "应用ID")
@ApiModelProperty("应用ID")
private String agentId;
/** 行为名称 */
@Excel(name = "行为名称")
@ApiModelProperty("行为名称")
private String operateName;
/** 行为编码 */
@Excel(name = "行为编码")
@ApiModelProperty("行为编码")
private String operateCode;
/** 行为积分 */
@Excel(name = "行为积分")
@ApiModelProperty("行为积分")
private Integer operatePoints;
/** 行为上限次数(周) */
@Excel(name = "行为上限次数", readConverterExp = "周=")
@ApiModelProperty("行为上限次数(周)")
private Integer limitCount;
/** 启用状态:0 禁用、1 启用 */
@Excel(name = "启用状态:0 禁用、1 启用")
@ApiModelProperty("启用状态:0 禁用、1 启用")
private Integer enableStatus;
}
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;
import com.tangguo.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
/**
* 用户积分对象 bbs_user_points
*
* @author ruoyi
* @date 2025-08-29
*/
@Data
@ToString
@NoArgsConstructor
@Accessors(chain = true)
@TableName("bbs_user_points")
@ApiModel(value = "BbsUserPoints", description = "用户积分实体")
public class BbsUserPoints extends BaseEntity {
private static final long serialVersionUID = 1L;
/** ID */
@TableId(type = IdType.AUTO)
@ApiModelProperty("ID")
private Long id;
/** 用户名 */
@Excel(name = "用户名")
@ApiModelProperty("用户名")
private String userName;
/** 累计积分 */
@Excel(name = "累计积分")
@ApiModelProperty("累计积分")
private Integer accumulatedPoints;
/** 当前积分 */
@Excel(name = "当前积分")
@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;
}
package com.tangguo.domain;
import com.baomidou.mybatisplus.annotation.IdType;
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;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
/**
* 用户积分明细对象 bbs_user_points_detail
*
* @author ruoyi
* @date 2025-08-29
*/
@Data
@ToString
@NoArgsConstructor
@Accessors(chain = true)
@TableName("bbs_user_points_detail")
@ApiModel(value = "BbsUserPointsDetail", description = "用户积分明细实体")
public class BbsUserPointsDetail extends BaseEntity {
private static final long serialVersionUID = 1L;
/** ID */
@TableId(type = IdType.AUTO)
@ApiModelProperty("ID")
private Long id;
/** 用户名 */
@Excel(name = "用户名")
@ApiModelProperty("用户名")
private String userName;
/** 明细名称 */
@Excel(name = "明细名称")
@ApiModelProperty("明细名称")
private String detailName;
/** 明细编码 */
@Excel(name = "明细编码")
@ApiModelProperty("明细编码")
private String detailCode;
/** 明细积分 */
@Excel(name = "明细积分")
@ApiModelProperty("明细积分")
private Integer detailPoints;
/** 计算前积分 */
@Excel(name = "计算前积分")
@ApiModelProperty("计算前积分")
private Integer beforePoints;
/** 计算后积分 */
@Excel(name = "计算后积分")
@ApiModelProperty("计算后积分")
private Integer afterPoints;
/** 积分明细描述 */
@Excel(name = "积分明细描述")
@ApiModelProperty("积分明细描述")
private String description;
}
......@@ -12,21 +12,19 @@ import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
import java.math.BigDecimal;
/**
* 积分商品对象 bbs_points_goods
* 用户积分兑换对象 bbs_user_points_exchange
*
* @author ruoyi
* @date 2025-08-28
* @date 2025-08-29
*/
@Data
@ToString
@NoArgsConstructor
@Accessors(chain = true)
@TableName("bbs_points_goods")
@ApiModel(value = "BbsPointsGoods", description = "积分商品实体")
public class BbsPointsGoods extends BaseEntity {
@TableName("bbs_user_points_exchange")
@ApiModel(value = "BbsUserPointsExchange", description = "用户积分兑换实体")
public class BbsUserPointsExchange extends BaseEntity {
private static final long serialVersionUID = 1L;
/** ID */
......@@ -34,44 +32,39 @@ public class BbsPointsGoods extends BaseEntity {
@ApiModelProperty("ID")
private Long id;
/** 用户姓名 */
@Excel(name = "用户姓名")
@ApiModelProperty("用户姓名")
private String nikeName;
/** 用户名 */
@Excel(name = "用户名")
@ApiModelProperty("用户名")
private String userName;
/** 用户等级名称 */
@Excel(name = "用户等级名称")
@ApiModelProperty("用户等级名称")
private String userGradeName;
/** 商品名称 */
@Excel(name = "商品名称")
@ApiModelProperty("商品名称")
private String name;
private String goodsName;
/** 商品编码 */
@Excel(name = "商品编码")
@ApiModelProperty("商品编码")
private String code;
/** 商品图片地址 */
@Excel(name = "商品图片地址")
@ApiModelProperty("商品图片地址")
private String imgsUrl;
/** 销售价格 */
@Excel(name = "销售价格")
@ApiModelProperty("销售价格")
private BigDecimal salesPrice;
/** 兑换积分 */
@Excel(name = "兑换积分")
@ApiModelProperty("兑换积分")
private Integer exchangePoints;
/** 库存数量 */
@Excel(name = "库存数量")
@ApiModelProperty("库存数量")
private Integer stockNum;
private String goodsCode;
/** 已兑数量 */
@Excel(name = "已兑数量")
@ApiModelProperty("已兑数量")
private Integer salesNum;
/** 商品兑换积分 */
@Excel(name = "商品兑换积分")
@ApiModelProperty("商品兑换积分")
private Integer goodsExchangePoints;
/** 上架状态:0 下架、1 上架 */
@Excel(name = "上架状态:0 下架、1 上架")
@ApiModelProperty("上架状态:0 下架、1 上架")
private Integer showStatus;
/** 用户剩余积分 */
@Excel(name = "用户剩余积分")
@ApiModelProperty("用户剩余积分")
private Integer userRemainingPoints;
}
package com.tangguo.domain.dto;
import lombok.Data;
/**
* 积分明细DTO
*
* @author 谈笑
* @createTime 2025-08-29 17:23:29 星期五
*/
@Data
public class PointsDetailDTO {
/**
* 明细名称
*/
private String detailName;
/**
* 明细编码
*/
private String detailCode;
/**
* 明细积分
*/
private Integer detailPoints;
/**
* 明细说明
*/
private String description;
}
package com.tangguo.domain.vo;
import com.tangguo.common.annotation.Excel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 企微门户用户VO
*
* @author 谈笑
* @createTime 2025-08-29 16:13:32 星期五
*/
@Data
public class QwmhSysUserVO {
/**
* 用户Id
*/
private String userId;
/**
* 用户名
*/
private String userName;
/**
* 用户姓名
*/
private String nikeName;
/**
* 部门名称
*/
private String deptName;
/**
* 用户等级
*/
private String gradeName;
/**
* 当前积分
*/
private Integer currentPoints;
/**
* 累计积分
*/
private Integer accumulatedPoints;
}
......@@ -2,6 +2,7 @@ package com.tangguo.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tangguo.domain.BbsPointsGoods;
import org.apache.ibatis.annotations.Param;
/**
* 积分商品Mapper接口
......@@ -10,4 +11,10 @@ import com.tangguo.domain.BbsPointsGoods;
* @date 2025-08-28
*/
public interface BbsPointsGoodsMapper extends BaseMapper<BbsPointsGoods> {
int decrGoodsStock(@Param("goodsId") long goodsId, @Param("goodsNum") int goodsNum);
int incrGoodsSales(@Param("goodsId") long goodsId, @Param("goodsNum") int goodsNum);
}
package com.tangguo.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tangguo.domain.BbsPointsGoods;
import com.tangguo.domain.BbsPointsSetting;
/**
* 积分商品Mapper接口
* 积分规则配置Mapper接口
*
* @author ruoyi
* @date 2025-08-28
* @date 2025-08-29
*/
public interface BbsPointsGoodsMapper extends BaseMapper<BbsPointsGoods> {
public interface BbsPointsSettingMapper extends BaseMapper<BbsPointsSetting> {
}
package com.tangguo.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tangguo.domain.BbsUserPointsDetail;
/**
* 用户积分明细Mapper接口
*
* @author ruoyi
* @date 2025-08-29
*/
public interface BbsUserPointsDetailMapper extends BaseMapper<BbsUserPointsDetail> {
}
package com.tangguo.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tangguo.domain.BbsUserPointsExchange;
import com.tangguo.domain.vo.QwmhSysUserVO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 用户积分兑换Mapper接口
*
* @author ruoyi
* @date 2025-08-29
*/
public interface BbsUserPointsExchangeMapper extends BaseMapper<BbsUserPointsExchange> {
List<QwmhSysUserVO> selectPointsUsers(@Param("keyword") String keyword);
List<BbsUserPointsExchange> selectBbsUserPointsExchangeList(@Param("exchange") BbsUserPointsExchange exchange);
}
package com.tangguo.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tangguo.domain.BbsUserPoints;
import com.tangguo.domain.vo.QwmhSysUserVO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 用户积分Mapper接口
*
* @author ruoyi
* @date 2025-08-29
*/
public interface BbsUserPointsMapper extends BaseMapper<BbsUserPoints> {
List<BbsUserPoints> selectBbsUserPointsList(@Param("points") BbsUserPoints points);
}
......@@ -45,4 +45,32 @@ public interface IBbsPointsGoodsService extends IService<BbsPointsGoods> {
*/
void deleteGoods(Long goodsId);
/**
* 查询积分商品
*
* @param goodsCode 商品编码
* @return 商品
*/
BbsPointsGoods getByGoodsCode(String goodsCode);
/**
* 扣减积分商品库存数量
*
* @param goodsId 商品Id
* @param goodsNum 商品数量
* @return
*/
boolean decrGoodsStock(long goodsId, int goodsNum);
/**
* 扣减积分商品库存数量
*
* @param goodsId 商品Id
* @param goodsNum 商品数量
*/
void incrGoodsSales(long goodsId, int goodsNum);
}
package com.tangguo.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.domain.BbsPointsSetting;
import java.util.List;
/**
* 积分规则配置Service接口
*
* @author ruoyi
* @date 2025-08-29
*/
public interface IBbsPointsSettingService extends IService<BbsPointsSetting> {
/**
* 查询积分规则配置列表
*
* @param bbsPointsSetting 积分规则配置
* @return 积分规则配置集合
*/
List<BbsPointsSetting> selectBbsPointsSettingList(BbsPointsSetting bbsPointsSetting);
}
package com.tangguo.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.domain.BbsUserPointsDetail;
import java.util.List;
/**
* 用户积分明细Service接口
*
* @author ruoyi
* @date 2025-08-29
*/
public interface IBbsUserPointsDetailService extends IService<BbsUserPointsDetail> {
/**
* 查询用户积分明细
*
* @param userName 用户名
* @return 积分明细
*/
List<BbsUserPointsDetail> getUserPointsDetail(String userName);
}
package com.tangguo.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.domain.BbsUserPointsExchange;
import java.util.List;
/**
* 用户积分兑换Service接口
*
* @author ruoyi
* @date 2025-08-29
*/
public interface IBbsUserPointsExchangeService extends IService<BbsUserPointsExchange> {
/**
* 查询用户积分兑换列表
*
* @param bbsUserPointsExchange 用户积分兑换
* @return 用户积分兑换集合
*/
List<BbsUserPointsExchange> selectBbsUserPointsExchangeList(BbsUserPointsExchange bbsUserPointsExchange);
/**
* 添加用户积分兑换记录
*
* @param exchange 兑换
*/
void addUserPointsExchange(BbsUserPointsExchange exchange);
}
package com.tangguo.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.domain.BbsUserPoints;
import com.tangguo.domain.dto.PointsDetailDTO;
import java.util.List;
/**
* 用户积分Service接口
*
* @author ruoyi
* @date 2025-08-29
*/
public interface IBbsUserPointsService extends IService<BbsUserPoints> {
/**
* 查询用户积分列表
*
* @param bbsUserPoints 用户积分
* @return 用户积分集合
*/
List<BbsUserPoints> selectBbsUserPointsList(BbsUserPoints bbsUserPoints);
/**
* 查询用户积分
*
* @param userName 用户名
* @return 积分
*/
BbsUserPoints getUserPoints(String userName);
/**
* 增加用户积分
*
* @param points 积分
*/
void addUserPoints(BbsUserPoints points);
/**
* 扣减用户积分
*
* @param points 积分
*/
void deleteUserPoints(BbsUserPoints points);
/**
* 增加用户积分
*
* @param userName 用户名
* @param points 积分
* @param detail 积分明细
*/
void incrUserPoints(String userName, int points, PointsDetailDTO detail);
/**
* 扣减用户积分
*
* @param userName 用户名
* @param points 积分
* @param detail 积分明细
*/
void decrUserPoints(String userName, int points, PointsDetailDTO detail);
}
......@@ -10,6 +10,7 @@ import com.tangguo.domain.BbsPointsGoods;
import com.tangguo.mapper.BbsPointsGoodsMapper;
import com.tangguo.service.IBbsPointsGoodsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
......@@ -64,6 +65,10 @@ public class BbsPointsGoodsServiceImpl extends ServiceImpl<BbsPointsGoodsMapper,
throw new ServiceException("添加失败,当前商品名称已存在。");
}
if (goods.getStockNum() < 0) {
throw new ServiceException("增加失败,商品库存数量不能小于0。");
}
BbsPointsGoods addGoods = new BbsPointsGoods();
addGoods.setName(goods.getName());
addGoods.setCode(IdUtil.fastSimpleUUID());
......@@ -89,6 +94,10 @@ public class BbsPointsGoodsServiceImpl extends ServiceImpl<BbsPointsGoodsMapper,
throw new ServiceException("修改失败,未查询到当前商品数据。");
}
if (goods.getStockNum() < 0) {
throw new ServiceException("修改失败,商品库存数量不能小于0。");
}
if (!dbGoods.getName().equals(goods.getName())) {
long nameCount = this.count(
Wrappers.lambdaQuery(BbsPointsGoods.class).eq(BbsPointsGoods::getName, goods.getName())
......@@ -120,4 +129,45 @@ public class BbsPointsGoodsServiceImpl extends ServiceImpl<BbsPointsGoodsMapper,
this.removeById(goodsId);
}
/**
* 查询积分商品
*
* @param goodsCode 商品编码
* @return 商品
*/
@Override
public BbsPointsGoods getByGoodsCode(String goodsCode) {
return this.getOne(
Wrappers.lambdaQuery(BbsPointsGoods.class).eq(BbsPointsGoods::getCode, goodsCode)
);
}
/**
* 扣减积分商品库存数量
*
* @param goodsId 商品Id
* @param goodsNum 商品数量
* @return 扣减结果
*/
@Transactional(rollbackFor = Exception.class)
@Override
public boolean decrGoodsStock(long goodsId, int goodsNum) {
return this.baseMapper.decrGoodsStock(goodsId, goodsNum) > 0;
}
/**
* 扣减积分商品库存数量
*
* @param goodsId 商品Id
* @param goodsNum 商品数量
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void incrGoodsSales(long goodsId, int goodsNum) {
this.baseMapper.incrGoodsSales(goodsId, goodsNum);
}
}
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 javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
* 积分规则配置Service业务层处理
*
* @author ruoyi
* @date 2025-08-29
*/
@Service
public class BbsPointsSettingServiceImpl extends ServiceImpl<BbsPointsSettingMapper, BbsPointsSetting> implements IBbsPointsSettingService {
@Resource
private BbsPointsSettingMapper bbsPointsSettingMapper;
/**
* 查询积分规则配置列表
*
* @param bbsPointsSetting 积分规则配置
* @return 积分规则配置
*/
@Override
public List<BbsPointsSetting> selectBbsPointsSettingList(BbsPointsSetting bbsPointsSetting) {
return bbsPointsSettingMapper.selectList(buildQueryWrapper(bbsPointsSetting));
}
private LambdaQueryWrapper<BbsPointsSetting> buildQueryWrapper(BbsPointsSetting query) {
Map<String, Object> params = query.getParams();
LambdaQueryWrapper<BbsPointsSetting> lqw = Wrappers.lambdaQuery();
lqw.orderByDesc(BbsPointsSetting::getCreateTime);
lqw.eq(StringUtils.isNotBlank(query.getType()), BbsPointsSetting::getType, query.getType());
lqw.like(StringUtils.isNotBlank(query.getAgentName()), BbsPointsSetting::getAgentName, query.getAgentName());
lqw.eq(StringUtils.isNotBlank(query.getAgentId()), BbsPointsSetting::getAgentId, query.getAgentId());
lqw.like(StringUtils.isNotBlank(query.getOperateName()), BbsPointsSetting::getOperateName, query.getOperateName());
lqw.eq(StringUtils.isNotBlank(query.getOperateCode()), BbsPointsSetting::getOperateCode, query.getOperateCode());
lqw.eq(query.getOperatePoints() != null, BbsPointsSetting::getOperatePoints, query.getOperatePoints());
lqw.eq(query.getLimitCount() != null, BbsPointsSetting::getLimitCount, query.getLimitCount());
lqw.eq(query.getEnableStatus() != null, BbsPointsSetting::getEnableStatus, query.getEnableStatus());
return lqw;
}
}
package com.tangguo.service.impl;
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 org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
/**
* 用户积分明细Service业务层处理
*
* @author ruoyi
* @date 2025-08-29
*/
@Service
public class BbsUserPointsDetailServiceImpl extends ServiceImpl<BbsUserPointsDetailMapper, BbsUserPointsDetail> implements IBbsUserPointsDetailService {
@Resource
private BbsUserPointsDetailMapper bbsUserPointsDetailMapper;
/**
* 查询用户积分明细
*
* @param userName 用户名
* @return 积分明细
*/
@Override
public List<BbsUserPointsDetail> getUserPointsDetail(String userName) {
return this.list(
Wrappers.lambdaQuery(BbsUserPointsDetail.class)
.eq(BbsUserPointsDetail::getUserName, userName)
);
}
}
package com.tangguo.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tangguo.common.exception.ServiceException;
import com.tangguo.domain.BbsPointsGoods;
import com.tangguo.domain.BbsUserPoints;
import com.tangguo.domain.BbsUserPointsExchange;
import com.tangguo.domain.dto.PointsDetailDTO;
import com.tangguo.mapper.BbsUserPointsExchangeMapper;
import com.tangguo.service.IBbsPointsGoodsService;
import com.tangguo.service.IBbsUserPointsExchangeService;
import com.tangguo.service.IBbsUserPointsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
/**
* 用户积分兑换Service业务层处理
*
* @author ruoyi
* @date 2025-08-29
*/
@Service
public class BbsUserPointsExchangeServiceImpl extends ServiceImpl<BbsUserPointsExchangeMapper, BbsUserPointsExchange> implements IBbsUserPointsExchangeService {
@Resource
private BbsUserPointsExchangeMapper bbsUserPointsExchangeMapper;
@Resource
private IBbsUserPointsService userPointsService;
@Resource
private IBbsPointsGoodsService pointsGoodsService;
/**
* 查询用户积分兑换列表
*
* @param exchange 用户积分兑换
* @return 用户积分兑换
*/
@Override
public List<BbsUserPointsExchange> selectBbsUserPointsExchangeList(BbsUserPointsExchange exchange) {
return this.baseMapper.selectBbsUserPointsExchangeList(exchange);
}
/**
* 添加用户积分兑换记录
*
* @param exchange 兑换
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void addUserPointsExchange(BbsUserPointsExchange exchange) {
// 积分商品校验
BbsPointsGoods dbGoods = this.pointsGoodsService.getByGoodsCode(exchange.getGoodsCode());
if (Objects.isNull(dbGoods)) {
throw new ServiceException("兑换失败,未查询到当前兑换的商品数据。");
}
if (dbGoods.getStockNum() < 1) {
throw new ServiceException("兑换失败,当前兑换的商品库存数量不足。");
}
// 用户积分校验
String userName = exchange.getUserName();
Integer exchangePoints = dbGoods.getExchangePoints();
BbsUserPoints dbUserPoints = this.userPointsService.getUserPoints(userName);
int currentPoints = dbUserPoints.getCurrentPoints() - dbGoods.getExchangePoints();
if (currentPoints < 0) {
throw new ServiceException("兑换失败,当前用户可用积分不足。");
}
// 扣减商品库存
Long goodsId = dbGoods.getId();
boolean decrResult = this.pointsGoodsService.decrGoodsStock(goodsId, 1);
if (!decrResult) {
throw new ServiceException("兑换失败,当前兑换的商品库存数量不足。");
}
// 增加商品销量
this.pointsGoodsService.incrGoodsSales(goodsId, 1);
// 扣减用户积分
PointsDetailDTO detail = new PointsDetailDTO();
detail.setDetailName(dbGoods.getName());
detail.setDetailCode(dbGoods.getCode());
detail.setDescription(String.format("用户【%s】兑换积分商品【%s-%s】", userName, dbGoods.getName(), dbGoods.getCode()));
this.userPointsService.decrUserPoints(userName, exchangePoints, detail);
// 添加兑换记录
BbsUserPointsExchange addExchange = new BbsUserPointsExchange();
addExchange.setNikeName(exchange.getNikeName());
addExchange.setUserName(exchange.getUserName());
addExchange.setUserGradeName(exchange.getUserGradeName());
addExchange.setGoodsName(dbGoods.getName());
addExchange.setGoodsCode(dbGoods.getCode());
addExchange.setGoodsExchangePoints(dbGoods.getExchangePoints());
addExchange.setUserRemainingPoints(currentPoints);
this.save(addExchange);
}
}
package com.tangguo.service.impl;
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.domain.dto.PointsDetailDTO;
import com.tangguo.mapper.BbsUserPointsMapper;
import com.tangguo.service.IBbsUserPointsDetailService;
import com.tangguo.service.IBbsUserPointsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionManager;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
/**
* 用户积分Service业务层处理
*
* @author ruoyi
* @date 2025-08-29
*/
@Service
public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, BbsUserPoints> implements IBbsUserPointsService {
@Resource
private BbsUserPointsMapper bbsUserPointsMapper;
@Resource
private IBbsUserPointsDetailService pointsDetailService;
@Resource
private BbsUserPointsServiceImpl userPointsServiceImpl;
/**
* 查询用户积分列表
*
* @param points 用户积分
* @return 用户积分
*/
@Override
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 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);
}
/**
* 增加用户积分
*
* @param userName 用户名
* @param points 积分
* @param detail 积分明细
*/
@Override
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) {
throw new ServiceException("增加用户积分失败,增加的积分分值不能小于0。");
}
// 更新用户积分
BbsUserPoints userPoints = this.userPointsServiceImpl.getUserPoints(userName);
Integer currentPoints = userPoints.getCurrentPoints();
int incrCurrentPoints = currentPoints + points;
userPoints.setCurrentPoints(incrCurrentPoints);
userPoints.setAccumulatedPoints(userPoints.getAccumulatedPoints() + points);
this.updateById(userPoints);
// 添加用户积分明细
BbsUserPointsDetail newDetail = new BbsUserPointsDetail();
newDetail.setUserName(userName);
newDetail.setDetailName(detail.getDetailName());
newDetail.setDetailCode(detail.getDetailCode());
newDetail.setDetailPoints(points);
newDetail.setBeforePoints(currentPoints);
newDetail.setAfterPoints(incrCurrentPoints);
newDetail.setDescription(detail.getDescription());
this.pointsDetailService.save(newDetail);
}
/**
* 扣减用户积分
*
* @param userName 用户名
* @param points 积分
* @param detail 积分明细
*/
@Transactional(rollbackFor = Exception.class)
public void execDecrUserPoints(String userName, int points, PointsDetailDTO detail) {
if (points < 1) {
throw new ServiceException("扣减用户积分失败,扣减的积分分值不能小于0。");
}
// 更新用户积分
BbsUserPoints userPoints = this.userPointsServiceImpl.getUserPoints(userName);
Integer currentPoints = userPoints.getCurrentPoints();
if (points > currentPoints) {
throw new ServiceException("扣减用户积分失败,当前用户可用积分不足。");
}
int decrCurrentPoints = currentPoints - points;
userPoints.setCurrentPoints(decrCurrentPoints);
this.updateById(userPoints);
// 添加用户积分明细
BbsUserPointsDetail newDetail = new BbsUserPointsDetail();
newDetail.setUserName(userName);
newDetail.setDetailName(detail.getDetailName());
newDetail.setDetailCode(detail.getDetailCode());
newDetail.setDetailPoints(points);
newDetail.setBeforePoints(currentPoints);
newDetail.setAfterPoints(decrCurrentPoints);
newDetail.setDescription(detail.getDescription());
this.pointsDetailService.save(newDetail);
}
}
......@@ -3,7 +3,24 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tangguo.mapper.BbsPointsGoodsMapper">
<update id="decrGoodsStock">
UPDATE
bbs_points_goods
SET
stock_num = stock_num - #{goodsNum}
WHERE
id = #{goodsId}
</update>
<update id="incrGoodsSales">
UPDATE
bbs_points_goods
SET
sales_num = sales_num + #{goodsNum}
WHERE
id = #{goodsId}
</update>
</mapper>
......@@ -2,8 +2,7 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tangguo.mapper.BbsPointsGoodsMapper">
<mapper namespace="com.tangguo.mapper.BbsPointsSettingMapper">
</mapper>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tangguo.mapper.BbsUserPointsDetailMapper">
</mapper>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tangguo.mapper.BbsUserPointsExchangeMapper">
<select id="selectPointsUsers" resultType="com.tangguo.domain.vo.QwmhSysUserVO">
SELECT
uv.*,
g.grade_name,
IFNULL(p.current_points, 0) AS current_points,
IFNULL(p.accumulated_points, 0) AS accumulated_points
FROM
qwmh_sys_user_view uv
LEFT JOIN
bbs_user_grade g ON g.user_name = uv.user_name
LEFT JOIN
bbs_user_points p ON p.user_name = uv.user_name
<where>
<if test="keyword != null and keyword != ''">
nike_name LIKE CONCAT('%', #{keyword}, '%') OR user_name LIKE CONCAT('%', #{keyword}, '%')
</if>
</where>
ORDER BY
uv.user_id
</select>
<select id="selectBbsUserPointsExchangeList" resultType="com.tangguo.domain.BbsUserPointsExchange">
SELECT
e.*
FROM
bbs_user_points_exchange e
<where>
<if test="exchange.nikeName != null and exchange.nikeName != ''">
e.nike_name LIKE CONCAT('%', #{exchange.nikeName}, '%')
</if>
<if test="exchange.userName != null and exchange.userName != ''">
AND e.user_name LIKE CONCAT('%', #{exchange.userName}, '%')
</if>
<if test="exchange.goodsName != null and exchange.goodsName != ''">
AND e.goods_name LIKE CONCAT('%', #{exchange.goodsName}, '%')
</if>
<if test="exchange.goodsCode != null and exchange.goodsCode != ''">
AND e.goods_code LIKE CONCAT('%', #{exchange.goodsCode}, '%')
</if>
<if test="exchange.params.startTime != null and exchange.params.startTime != ''">
AND DATE_FORMAT(create_time, '%Y-%m-%d') >= #{exchange.params.startTime}
</if>
<if test="exchange.params.endTime != null and exchange.params.endTime != ''">
AND DATE_FORMAT(create_time, '%Y-%m-%d') &lt;= #{exchange.params.endTime}
</if>
</where>
ORDER BY
e.create_time DESC
</select>
</mapper>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
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