Commit c32fef46 authored by zhaobiyan's avatar zhaobiyan

会员操作积分接口

parents a8c785a5 00d72aad
......@@ -10,11 +10,17 @@ import cn.iocoder.yudao.module.member.service.memberUserScore.MemberUserScoreSer
import cn.iocoder.yudao.module.member.service.memberUserScoreDetail.MemberUserScoreDetailService;
import cn.iocoder.yudao.module.member.service.memberUserScoreLog.MemberUserScoreLogService;
import cn.iocoder.yudao.module.member.vo.memberUserScoreLog.MemberUserScoreLogCreateReq;
import com.alibaba.excel.util.CollectionUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.MEMBER_ID_IS_NULL;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.SCORE_COUNT_ERROR;
@Slf4j
@Service
public class MemberUserScoreApiImpl implements MemberUserScoreApi{
......@@ -30,6 +36,12 @@ public class MemberUserScoreApiImpl implements MemberUserScoreApi{
@Override
@Transactional(rollbackFor = Exception.class)
public MemberUserScoreOperateRespDTO operateScore(MemberUserScoreOperateReqDTO req) {
if (req.getMemberId() == null) {
throw exception(MEMBER_ID_IS_NULL);
}
if (req.getScoreCount() <= 0) {
throw exception(SCORE_COUNT_ERROR);
}
//todo 校验
String lockKey = "member:operate:socre:" + req.getMemberId();
boolean lock = redisDistributedLock.lock(lockKey, 5000, 3, 100);
......
......@@ -2,6 +2,11 @@ package cn.iocoder.yudao.module.member.controller.admin.memberUserScore;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.api.score.MemberUserScoreApiImpl;
import cn.iocoder.yudao.module.member.api.score.dto.MemberUserScoreOperateReqDTO;
import cn.iocoder.yudao.module.member.api.score.dto.MemberUserScoreOperateRespDTO;
import cn.iocoder.yudao.module.member.enums.ScoreOperateTypeEnum;
import cn.iocoder.yudao.module.member.enums.ScoreSourceTypeEnum;
import cn.iocoder.yudao.module.member.service.memberUserScore.MemberUserScoreService;
import cn.iocoder.yudao.module.member.vo.memberUserScore.MemberUserScoreBackVO;
import cn.iocoder.yudao.module.member.vo.memberUserScore.MemberUserScoreOperateQueryVO;
......@@ -18,6 +23,9 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Validated
......@@ -28,6 +36,9 @@ public class MemberUserScoreController {
@Resource
private MemberUserScoreService userScoreService;
@Resource
private MemberUserScoreApiImpl scoreApi;
@PostMapping("/page")
@ApiOperation("获得会员积分分页")
......@@ -41,7 +52,17 @@ public class MemberUserScoreController {
@ApiOperation("操作积分")
@PreAuthorize("@ss.hasPermission('member:user-score:operate')")
public CommonResult<Boolean> operate(@Valid @RequestBody MemberUserScoreOperateQueryVO query) {
userScoreService.operate(query);
query.getMemberIds().forEach(memberId -> {
Map<String,Object> extParam = new HashMap<>();
extParam.put("comment", query.getComment());
MemberUserScoreOperateRespDTO memberUserScoreOperateRespDTO = scoreApi.operateScore(MemberUserScoreOperateReqDTO.builder()
.memberId(memberId)
.scoreCount(query.getScoreCount())
.operateType(ScoreOperateTypeEnum.parseByValue(query.getOperateType()))
.sourceType(ScoreSourceTypeEnum.MANUAL_OPERATE)
.extParam(extParam)
.build());
});
return success(null);
}
}
......@@ -49,7 +49,5 @@ public interface MemberUserScoreService extends IService<MemberUserScoreDO> {
*/
List<MemberUserScoreDO> getUserScoreList(MemberUserScoreQueryVO query);
void operate(MemberUserScoreOperateQueryVO query);
void updateUserScore(MemberUserScoreUpdateReqDTO query);
}
......@@ -2,32 +2,25 @@ package cn.iocoder.yudao.module.member.service.memberUserScore;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.service.AbstractService;
import cn.iocoder.yudao.module.member.api.score.MemberUserScoreApi;
import cn.iocoder.yudao.module.member.api.score.MemberUserScoreApiImpl;
import cn.iocoder.yudao.module.member.api.score.dto.MemberUserScoreOperateReqDTO;
import cn.iocoder.yudao.module.member.api.score.dto.MemberUserScoreOperateRespDTO;
import cn.iocoder.yudao.module.member.api.score.dto.MemberUserScoreUpdateReqDTO;
import cn.iocoder.yudao.module.member.dal.dataobject.memberUserScore.MemberUserScoreDO;
import cn.iocoder.yudao.module.member.dal.mysql.memberUserScore.MemberUserScoreMapper;
import cn.iocoder.yudao.module.member.enums.ScoreOperateTypeEnum;
import cn.iocoder.yudao.module.member.enums.ScoreSourceTypeEnum;
import cn.iocoder.yudao.module.member.vo.memberUserScore.MemberUserScoreBackVO;
import cn.iocoder.yudao.module.member.vo.memberUserScore.MemberUserScoreOperateQueryVO;
import cn.iocoder.yudao.module.member.vo.memberUserScore.MemberUserScoreQueryVO;
import com.alibaba.excel.util.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.MEMBER_ID_IS_NULL;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.MEMBER_SCORE_NOT_ENOUGH;
/**
* 会员积分 Service 实现类
......@@ -42,9 +35,6 @@ public class MemberUserScoreServiceImpl extends AbstractService<MemberUserScoreM
@Resource
private MemberUserScoreMapper userScoreMapper;
@Resource
private MemberUserScoreApiImpl scoreApi;
@Override
public void deleteUserScore(Long id) {
// 删除
......@@ -74,38 +64,6 @@ public class MemberUserScoreServiceImpl extends AbstractService<MemberUserScoreM
public List<MemberUserScoreDO> getUserScoreList(MemberUserScoreQueryVO query) {
return userScoreMapper.selectList(query);
}
@Transactional(rollbackFor = Exception.class)
@Override
public void operate(MemberUserScoreOperateQueryVO query) {
if (CollectionUtils.isEmpty(query.getMemberIds())) {
throw exception(MEMBER_ID_IS_NULL);
}
if (query.getScoreCount() <= 0) {
throw exception(SCORE_COUNT_ERROR);
}
// 校验用户当前积分是否满足扣减要求
if (query.getOperateType() == 2) {
LambdaQueryWrapper<MemberUserScoreDO> wrapper = Wrappers.lambdaQuery();
wrapper.in(MemberUserScoreDO::getMemberId, query.getMemberIds());
List<MemberUserScoreDO> userScoreDOList = this.list(wrapper);
List<MemberUserScoreDO> notEnoughScoreList = userScoreDOList.stream()
.filter(item -> item.getHoldScore() < query.getScoreCount()).collect(Collectors.toList());
if (!notEnoughScoreList.isEmpty()) {
throw exception(MEMBER_SCORE_NOT_ENOUGH);
}
}
query.getMemberIds().forEach(memberId -> {
Map<String,Object> extParam = new HashMap<>();
extParam.put("comment", query.getComment());
MemberUserScoreOperateRespDTO memberUserScoreOperateRespDTO = scoreApi.operateScore(MemberUserScoreOperateReqDTO.builder()
.memberId(memberId)
.scoreCount(query.getScoreCount())
.operateType(ScoreOperateTypeEnum.parseByValue(query.getOperateType()))
.sourceType(ScoreSourceTypeEnum.MANUAL_OPERATE)
.extParam(extParam)
.build());
});
}
@Override
public void updateUserScore(MemberUserScoreUpdateReqDTO query) {
......
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