积分变动记录

This commit is contained in:
PQZ 2025-03-29 15:36:06 +08:00
parent cde077cf73
commit bfca023285
8 changed files with 144 additions and 68 deletions

View File

@ -4,16 +4,13 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.member.vo.MemberUserVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
@ -25,61 +22,49 @@ import com.ruoyi.common.core.page.TableDataInfo;
/**
* 博主积分变动明细Controller
*
*
* @author pqz
* @date 2025-03-17
*/
@RestController
@RequestMapping("/member/points")
public class MemberPointsController extends BaseController
{
public class MemberPointsController extends BaseController {
@Autowired
private IMemberPointsService memberPointsService;
/**
* 查询博主积分变动明细列表
*/
@PreAuthorize("@ss.hasPermi('member:points:list')")
* 分页查询积分变动明细
*
* @param userId 用户id
* @param pageNum 分页参数
* @param pageSize 分页参数
* @return com.ruoyi.common.core.domain.AjaxResult
* @author PQZ
* @date 15:24 2025/3/29
**/
@GetMapping("/list")
public AjaxResult list(MemberPoints memberPoints)
{
List<MemberPoints> list = memberPointsService.list();
public AjaxResult list(@RequestParam(name = "userId") Long userId,
@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
Page<MemberPoints> page = new Page<>(pageNum, pageSize);
IPage<MemberPoints> list = memberPointsService.queryListPage(userId, page);
return success(list);
}
/**
* 导出博主积分变动明细列表
*/
@PreAuthorize("@ss.hasPermi('member:points:export')")
@Log(title = "博主积分变动明细", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, MemberPoints memberPoints)
{
List<MemberPoints> list = memberPointsService.list();
ExcelUtil<MemberPoints> util = new ExcelUtil<MemberPoints>(MemberPoints.class);
util.exportExcel(response, list, "博主积分变动明细数据");
}
/**
* 获取博主积分变动明细详细信息
*/
@PreAuthorize("@ss.hasPermi('member:points:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") String id)
{
return success(memberPointsService.getById(id));
}
/**
* 新增博主积分变动明细
*/
@PreAuthorize("@ss.hasPermi('member:points:add')")
* 新增博主积分变动记录
*
* @param memberPoints {@link MemberPoints}
* @return com.ruoyi.common.core.domain.AjaxResult
* @author PQZ
* @date 15:29 2025/3/29
**/
@Log(title = "博主积分变动明细", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody MemberPoints memberPoints)
{
return toAjax(memberPointsService.save(memberPoints));
public AjaxResult add(@RequestBody MemberPoints memberPoints) {
memberPointsService.savePoints(memberPoints);
return success();
}
/**
@ -88,8 +73,7 @@ public class MemberPointsController extends BaseController
@PreAuthorize("@ss.hasPermi('member:points:edit')")
@Log(title = "博主积分变动明细", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody MemberPoints memberPoints)
{
public AjaxResult edit(@RequestBody MemberPoints memberPoints) {
return toAjax(memberPointsService.updateById(memberPoints));
}
@ -98,9 +82,8 @@ public class MemberPointsController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('member:points:remove')")
@Log(title = "博主积分变动明细", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable String[] ids)
{
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable String[] ids) {
List<String> list = new ArrayList<>(Arrays.asList(ids));
return toAjax(memberPointsService.removeByIds(list));
}

View File

@ -50,7 +50,7 @@ public class MemberPoints extends DlBaseEntity
/** 剩余 */
@Excel(name = "剩余")
private Long balance;
private Integer balance;
/** 备注 */
@Excel(name = "备注")

View File

@ -1,18 +1,28 @@
package com.ruoyi.member.mapper;
import java.util.List;
import com.ruoyi.member.domain.MemberPoints;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.member.domain.MemberPoints;
import org.apache.ibatis.annotations.Mapper;
/**
* 博主积分变动明细Mapper接口
*
*
* @author pqz
* @date 2025-03-17
*/
@Mapper
public interface MemberPointsMapper extends BaseMapper<MemberPoints>
{
public interface MemberPointsMapper extends BaseMapper<MemberPoints> {
/**
* 根据用户id查询积分变动明细
*
* @param userId 用户id
* @param page 分页参数
* @return com.baomidou.mybatisplus.core.metadata.IPage<com.ruoyi.member.domain.MemberPoints>
* @author PQZ
* @date 15:25 2025/3/29
**/
IPage<MemberPoints> queryListPage(Long userId, Page<MemberPoints> page);
}

View File

@ -1,5 +1,7 @@
package com.ruoyi.member.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.member.domain.MemberPoints;
@ -13,5 +15,22 @@ import java.util.List;
*/
public interface IMemberPointsService extends IService<MemberPoints> {
// void dealMemberPoints(Long userId);
/**
* 分页查询积分变动明细
*
* @param userId 用户id
* @param page 分页参数
* @return com.baomidou.mybatisplus.core.metadata.IPage<com.ruoyi.member.domain.MemberPoints>
* @author PQZ
* @date 15:24 2025/3/29
**/
IPage<MemberPoints> queryListPage(Long userId, Page<MemberPoints> page);
/**
* 新增积分变动记录
* @author PQZ
* @date 15:29 2025/3/29
* @param memberPoints {@link MemberPoints}
**/
void savePoints(MemberPoints memberPoints);
}

View File

@ -1,25 +1,74 @@
package com.ruoyi.member.service.impl;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.DlBaseEntity;
import com.ruoyi.member.domain.MemberPoints;
import com.ruoyi.member.mapper.MemberPointsMapper;
import com.ruoyi.member.service.IMemberPointsService;
import io.lettuce.core.LMoveArgs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.member.mapper.MemberPointsMapper;
import com.ruoyi.member.domain.MemberPoints;
import com.ruoyi.member.service.IMemberPointsService;
import java.util.List;
/**
* 博主积分变动明细Service业务层处理
*
*
* @author pqz
* @date 2025-03-17
*/
@Service
public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper,MemberPoints> implements IMemberPointsService
{
public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper, MemberPoints> implements IMemberPointsService {
@Autowired
private MemberPointsMapper memberPointsMapper;
/**
* 分页查询积分变动明细
*
* @param userId 用户id
* @param page 分页参数
* @return com.baomidou.mybatisplus.core.metadata.IPage<com.ruoyi.member.domain.MemberPoints>
* @author PQZ
* @date 15:24 2025/3/29
**/
@Override
public IPage<MemberPoints> queryListPage(Long userId, Page<MemberPoints> page) {
return memberPointsMapper.queryListPage(userId,page);
}
/**
* 新增积分变动记录
*
* @param memberPoints {@link MemberPoints}
* @author PQZ
* @date 15:29 2025/3/29
**/
@Override
public void savePoints(MemberPoints memberPoints) {
//查询当前用户最近变动记录
LambdaQueryWrapper<MemberPoints> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(DlBaseEntity::getDelFlag,0)
.eq(MemberPoints::getUserId,memberPoints.getUserId())
.orderByDesc(DlBaseEntity::getCreateTime);
List<MemberPoints> list = list(lambdaQueryWrapper);
//如果没有记录则为初始新增
if (list.isEmpty()) {
memberPoints.setBalance(memberPoints.getPoints());
} else {
//如果有记录则取最新记录中的剩余值进行计算后得出新值
Integer oldBalance = list.get(0).getBalance();
Integer newBalance;
if ("1".equals(memberPoints.getType())) {
newBalance = oldBalance + memberPoints.getPoints();
} else {
newBalance = oldBalance - memberPoints.getPoints();
}
memberPoints.setBalance(newBalance);
}
save(memberPoints);
}
}

View File

@ -16,6 +16,7 @@ import com.ruoyi.constant.DictConstants;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.member.domain.MemberUser;
import com.ruoyi.member.mapper.MemberUserMapper;
import com.ruoyi.member.service.IMemberAddressService;
import com.ruoyi.member.service.IMemberBusiCardService;
import com.ruoyi.member.service.IMemberCardService;
import com.ruoyi.member.service.IMemberUserService;
@ -51,6 +52,8 @@ public class MemberUserServiceImpl extends ServiceImpl<MemberUserMapper, MemberU
private SysUserMapper userMapper;
@Autowired
private DlRightsConfig dlRightsConfig;
@Resource
private IMemberAddressService addressService;
/**
@ -102,6 +105,10 @@ public class MemberUserServiceImpl extends ServiceImpl<MemberUserMapper, MemberU
MemberUserVO result = memberUserMapper.queryByUserId(userId, "02");
//名片信息
result.setBusiCards(busiCardService.queryListByUserId(userId));
//地址信息
result.setAddresses(addressService.listByUserId(userId));
//会员开通记录
result.setCards(cardService.listByUserId(userId, "02"));
//报名的通告
// result.setNoticeVos(noticeService.queryListByUserId(userId));
return result;

View File

@ -4,6 +4,7 @@ import com.ruoyi.busi.domain.BusiEvaluate;
import com.ruoyi.busi.domain.BusiNotice;
import com.ruoyi.busi.vo.BusiEvaluateVO;
import com.ruoyi.busi.vo.BusiNoticeVo;
import com.ruoyi.member.domain.MemberAddress;
import com.ruoyi.member.domain.MemberBusiCard;
import com.ruoyi.member.domain.MemberCard;
import com.ruoyi.member.domain.MemberUser;
@ -33,4 +34,6 @@ public class MemberUserVO extends MemberUser {
List<BusiNoticeVo> noticeVos;
/**名片信息*/
List<MemberBusiCard> busiCards;
/**地址信息*/
List<MemberAddress> addresses;
}

View File

@ -24,5 +24,10 @@
select id, user_id, from_code, type, title, points, balance, remark, creator, create_time, updater, update_time, del_flag from dl_member_points
</sql>
<select id="queryListPage" parameterType="MemberPoints" resultMap="MemberPointsResult">
<include refid="selectMemberPointsVo"/>
<where>
<if test="entity.userId != null"> and user_id = #{entity.userId}</if>
</where>
</select>
</mapper>