Commit a9a99391 authored by zhaobiyan's avatar zhaobiyan

兑换记录批量核准接口

parents 57807f35 1bdde0be
......@@ -24,7 +24,8 @@ public interface ErrorCodeConstants {
ErrorCode REWARD_REDEEM_COUNT_NOT_ALLOW = new ErrorCode(1001011016, "批量兑换每次最多十条");
ErrorCode REWARD_REDEEM_ALLOW_COUNT_ERROR = new ErrorCode(1001011017, "超出允许兑换次数");
ErrorCode REWARD_REDEEM_NOT_EXIST = new ErrorCode(1001011018, "reward.redeem.not.exist");
ErrorCode REWARD_REDEEM_STATUS_ERROR = new ErrorCode(1001011018, "reward.redeem.status.error");
ErrorCode REWARD_REDEEM_VERIFY_NO_PARAM = new ErrorCode(1001011018, "reward.redeem.verify.no.param");
ErrorCode REWARD_REDEEM_STATUS_ERROR = new ErrorCode(1001011019, "reward.redeem.status.error");
ErrorCode REWARD_REDEEM_VERIFY_NO_PARAM = new ErrorCode(1001011020, "reward.redeem.verify.no.param");
ErrorCode REWARD_REDEEM_BATCH_VERIFY_ERROR = new ErrorCode(1001011021, "reward.redeem.batch.verify.error");
}
......@@ -50,16 +50,22 @@ public class RedeemRewardController {
@PostMapping("record/update")
@ApiOperation("兑换记录更新")
public CommonResult<Boolean> update(@Valid @RequestBody RewardRedeemUpdateVO request) {
public CommonResult<Boolean> update(@Valid @RequestBody RewardRedeemUpdateReqVO request) {
return success(rewardRedeemService.updateRecord(request));
}
@PostMapping("record/verify")
@ApiOperation("兑换记录核销")
public CommonResult<Boolean> verify(@Valid @RequestBody RewardRedeemVerifyVO request) {
public CommonResult<Boolean> verify(@Valid @RequestBody RewardRedeemVerifyReqVO request) {
return success(rewardRedeemService.verify(request));
}
@PostMapping("record/batch/verify")
@ApiOperation("兑换记录核销")
public CommonResult<Boolean> batchVerify(@Valid @RequestBody RewardRedeemBatchVerifyReqVO request) {
return success(rewardRedeemService.batchVerify(request));
}
@PostMapping("/single")
@ApiOperation("兑换礼品")
......
package cn.iocoder.yudao.module.reward.dto;
import lombok.Builder;
import lombok.Data;
import java.util.Date;
@Data
@Builder
public class RewardRedeemVerifyDTO {
private Long id;
private Integer status;
private Integer redeemType;
private Integer courierCompany;
/**
* 收件人地址
*/
private String recipientAddress;
/**
* 快递单号
*/
private String expressNo;
/**
* 快递日期
*/
private Date expressDate;
/**
* 快递寄出人
*/
private String expressSender;
}
......@@ -3,10 +3,9 @@ package cn.iocoder.yudao.module.reward.service.redeem;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.service.IService;
import cn.iocoder.yudao.module.reward.dal.dataobject.redeem.RewardRedeemDO;
import cn.iocoder.yudao.module.reward.vo.reward.RewardRedeemPageReqVO;
import cn.iocoder.yudao.module.reward.vo.reward.RewardRedeemPageRespVO;
import cn.iocoder.yudao.module.reward.vo.reward.RewardRedeemUpdateVO;
import cn.iocoder.yudao.module.reward.vo.reward.RewardRedeemVerifyVO;
import cn.iocoder.yudao.module.reward.vo.reward.*;
import java.util.List;
/**
* 礼品兑换 Service 接口
......@@ -19,7 +18,9 @@ public interface RewardRedeemService extends IService<RewardRedeemDO> {
RewardRedeemPageRespVO detail(Long id);
Boolean updateRecord(RewardRedeemUpdateVO request);
Boolean updateRecord(RewardRedeemUpdateReqVO request);
Boolean verify(RewardRedeemVerifyReqVO request);
Boolean verify(RewardRedeemVerifyVO request);
Boolean batchVerify(RewardRedeemBatchVerifyReqVO request);
}
......@@ -5,15 +5,14 @@ import cn.iocoder.yudao.framework.mybatis.core.service.AbstractService;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.reward.dal.dataobject.redeem.RewardRedeemDO;
import cn.iocoder.yudao.module.reward.dal.mysql.redeem.RewardRedeemMapper;
import cn.iocoder.yudao.module.reward.dto.RewardRedeemVerifyDTO;
import cn.iocoder.yudao.module.reward.enums.ErrorCodeConstants;
import cn.iocoder.yudao.module.reward.enums.RewardPickMethedEnum;
import cn.iocoder.yudao.module.reward.enums.RewardRedeemStatusEnum;
import cn.iocoder.yudao.module.reward.service.reward.RewardService;
import cn.iocoder.yudao.module.reward.vo.reward.RewardRedeemPageReqVO;
import cn.iocoder.yudao.module.reward.vo.reward.RewardRedeemPageRespVO;
import cn.iocoder.yudao.module.reward.vo.reward.RewardRedeemUpdateVO;
import cn.iocoder.yudao.module.reward.vo.reward.RewardRedeemVerifyVO;
import cn.iocoder.yudao.module.reward.vo.reward.*;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.micrometer.core.instrument.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
......@@ -22,6 +21,10 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
......@@ -42,7 +45,7 @@ public class RewardRedeemServiceImpl extends AbstractService<RewardRedeemMapper,
public PageResult<RewardRedeemPageRespVO> pageInfo(RewardRedeemPageReqVO reqVO) {
int start = (reqVO.getPageNo() - 1) * reqVO.getPageSize();
int size = reqVO.getPageSize();
List<RewardRedeemPageRespVO > result = rewardRedeemMapper.pageInfo(start, size, reqVO);
List<RewardRedeemPageRespVO> result = rewardRedeemMapper.pageInfo(start, size, reqVO);
int total = rewardRedeemMapper.pageCount(reqVO);
return new PageResult<>(result, total, reqVO.getPageSize(), reqVO.getPageNo(), (total + reqVO.getPageSize() - 1) / reqVO.getPageSize());
}
......@@ -56,7 +59,7 @@ public class RewardRedeemServiceImpl extends AbstractService<RewardRedeemMapper,
}
@Override
public Boolean updateRecord(RewardRedeemUpdateVO request) {
public Boolean updateRecord(RewardRedeemUpdateReqVO request) {
updateValidateParam(request);
LambdaUpdateWrapper<RewardRedeemDO> wrapper = Wrappers.lambdaUpdate();
wrapper.eq(RewardRedeemDO::getId, request.getId());
......@@ -81,8 +84,10 @@ public class RewardRedeemServiceImpl extends AbstractService<RewardRedeemMapper,
}
@Override
public Boolean verify(RewardRedeemVerifyVO request) {
verifyValidateParam(request);
public Boolean verify(RewardRedeemVerifyReqVO request) {
if (!checkVerifyParam(request)){
throw exception(ErrorCodeConstants.REWARD_REDEEM_STATUS_ERROR);
}
LambdaUpdateWrapper<RewardRedeemDO> wrapper = Wrappers.lambdaUpdate();
wrapper.eq(RewardRedeemDO::getId, request.getId());
wrapper.set(RewardRedeemDO::getStatus, RewardRedeemStatusEnum.REDEEMED.getValue());
......@@ -101,35 +106,93 @@ public class RewardRedeemServiceImpl extends AbstractService<RewardRedeemMapper,
return true;
}
private void verifyValidateParam(RewardRedeemVerifyVO request) {
@Override
public Boolean batchVerify(RewardRedeemBatchVerifyReqVO request) {
if (CollectionUtils.isEmpty(request.getIds())) {
throw exception(ErrorCodeConstants.REWARD_REDEEM_NOT_EXIST);
}
List<Long> errorIds = checkBatchVerifyParam(request);
if (CollectionUtils.isNotEmpty(errorIds)) {
throw exception(ErrorCodeConstants.REWARD_REDEEM_BATCH_VERIFY_ERROR, errorIds);
}
LambdaUpdateWrapper<RewardRedeemDO> updateWrapper = Wrappers.lambdaUpdate();
updateWrapper.in(RewardRedeemDO::getId, request.getIds());
updateWrapper.set(RewardRedeemDO::getStatus, RewardRedeemStatusEnum.REDEEMED.getValue());
updateWrapper.set(RewardRedeemDO::getVerifyUser, request.getVerifyUser());
updateWrapper.set(RewardRedeemDO::getVerifyTime, request.getVerifyTime());
updateWrapper.set(RewardRedeemDO::getUpdater, SecurityFrameworkUtils.getLoginUserId());
updateWrapper.set(RewardRedeemDO::getUpdateTime, new Date());
this.update(null, updateWrapper);
return true;
}
private List<Long> checkBatchVerifyParam(RewardRedeemBatchVerifyReqVO request) {
LambdaUpdateWrapper<RewardRedeemDO> wrapper = Wrappers.lambdaUpdate();
wrapper.in(RewardRedeemDO::getId, request.getIds());
Map<Long, RewardRedeemDO> idRewardRedeemMap = this.list(wrapper).stream()
.collect(Collectors.toMap(RewardRedeemDO::getId, Function.identity(), (c1, c2) -> c1));
List<Long> errorIds = idRewardRedeemMap.keySet().stream().filter(id -> {
RewardRedeemDO rewardRedeemDO = idRewardRedeemMap.get(id);
if (rewardRedeemDO == null) {
return true;
}
return !canVerify(RewardRedeemVerifyDTO.builder()
.id(rewardRedeemDO.getId())
.status(rewardRedeemDO.getStatus())
.redeemType(rewardRedeemDO.getRedeemType())
.courierCompany(rewardRedeemDO.getCourierCompany())
.expressDate(rewardRedeemDO.getExpressDate())
.recipientAddress(rewardRedeemDO.getRecipientAddress())
.expressNo(rewardRedeemDO.getExpressNo())
.expressSender(rewardRedeemDO.getExpressSender())
.build());
}).collect(Collectors.toList());
return errorIds;
}
private boolean checkVerifyParam(RewardRedeemVerifyReqVO request) {
RewardRedeemDO rewardRedeemDO = getById(request.getId());
if (rewardRedeemDO == null) {
throw exception(ErrorCodeConstants.REWARD_REDEEM_NOT_EXIST);
}
if (rewardRedeemDO.getStatus() != RewardRedeemStatusEnum.REDEEMING.getValue()) {
throw exception(ErrorCodeConstants.REWARD_REDEEM_STATUS_ERROR);
return canVerify(RewardRedeemVerifyDTO.builder()
.id(rewardRedeemDO.getId())
.status(rewardRedeemDO.getStatus())
.redeemType(rewardRedeemDO.getRedeemType())
.courierCompany(request.getCourierCompany())
.expressDate(request.getExpressDate())
.recipientAddress(request.getRecipientAddress())
.expressNo(request.getExpressNo())
.expressSender(request.getExpressSender())
.build());
}
private boolean canVerify(RewardRedeemVerifyDTO rewardRedeemVerifyDTO) {
if (rewardRedeemVerifyDTO.getStatus() != RewardRedeemStatusEnum.REDEEMING.getValue()) {
return false;
}
if (rewardRedeemDO.getRedeemType() != RewardPickMethedEnum.SELF_PICKUP.getValue()) {
if (rewardRedeemVerifyDTO.getRedeemType() != RewardPickMethedEnum.SELF_PICKUP.getValue()) {
//除上门领取状态外,其他方式需要验证 courierCompany, expressNo, expressDate, expressSender, recipientAddress 不能为空
if (request.getCourierCompany() == null) {
throw exception(ErrorCodeConstants.REWARD_REDEEM_VERIFY_NO_PARAM);
if (rewardRedeemVerifyDTO.getCourierCompany() == null) {
return false;
}
if (StringUtils.isBlank(request.getExpressNo())) {
throw exception(ErrorCodeConstants.REWARD_REDEEM_VERIFY_NO_PARAM);
if (StringUtils.isBlank(rewardRedeemVerifyDTO.getExpressNo())) {
return false;
}
if (request.getExpressDate() == null) {
throw exception(ErrorCodeConstants.REWARD_REDEEM_VERIFY_NO_PARAM);
if (rewardRedeemVerifyDTO.getExpressDate() == null) {
return false;
}
if (StringUtils.isBlank(request.getExpressSender())) {
throw exception(ErrorCodeConstants.REWARD_REDEEM_VERIFY_NO_PARAM);
if (StringUtils.isBlank(rewardRedeemVerifyDTO.getExpressSender())) {
return false;
}
if (StringUtils.isBlank(request.getRecipientAddress())) {
throw exception(ErrorCodeConstants.REWARD_REDEEM_VERIFY_NO_PARAM);
if (StringUtils.isBlank(rewardRedeemVerifyDTO.getRecipientAddress())) {
return false;
}
}
return true;
}
private void updateValidateParam(RewardRedeemUpdateVO request) {
private void updateValidateParam(RewardRedeemUpdateReqVO request) {
RewardRedeemDO rewardRedeemDO = getById(request.getId());
if (rewardRedeemDO == null) {
throw exception(ErrorCodeConstants.REWARD_REDEEM_NOT_EXIST);
......
package cn.iocoder.yudao.module.reward.vo.reward;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;
@Data
public class RewardRedeemBatchVerifyReqVO {
@NotNull(message = "ids is not null")
@ApiModelProperty(value = "id")
private List<Long> ids;
@ApiModelProperty(value = "核销人")
@NotNull(message = "verifyUser is not null")
private String verifyUser;
/**
* 核销时间
*/
@NotNull(message = "verify time is not null")
@ApiModelProperty(value = "核销时间")
private Date verifyTime;
}
......@@ -8,7 +8,7 @@ import java.math.BigDecimal;
import java.util.Date;
@Data
public class RewardRedeemUpdateVO {
public class RewardRedeemUpdateReqVO {
@NotNull(message = "id is not null")
@ApiModelProperty(value = "id")
private Long id;
......
......@@ -7,7 +7,7 @@ import javax.validation.constraints.NotNull;
import java.util.Date;
@Data
public class RewardRedeemVerifyVO {
public class RewardRedeemVerifyReqVO {
@NotNull(message = "id is not null")
@ApiModelProperty(value = "id")
private Long id;
......
......@@ -1014,3 +1014,4 @@ get.lock.failed = The service is busy, please try again later
reward.redeem.not.exist = reward redeem record does not exist
reward.redeem.status.error = reward redeem record that is redeeming can edit or verify
reward.redeem.verify.no.param = In addition to collect at home, the delivery company/delivery number/delivery time/delivery sender/recipient address must be filled in
reward.redeem.batch.verify.error = reward redeem record verify failed, please check record data : {}
\ No newline at end of file
......@@ -1018,3 +1018,4 @@ get.lock.failed = \u670D\u52A1\u7E41\u5FD9\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5
reward.redeem.not.exist = \u793C\u54C1\u5151\u6362\u8BB0\u5F55\u4E0D\u5B58\u5728
reward.redeem.status.error = \u53EA\u6709\u5151\u6362\u4E2D\u72B6\u6001\u7684\u8BB0\u5F55\u624D\u5141\u8BB8\u7F16\u8F91\u6216\u6838\u9500
reward.redeem.verify.no.param = \u9664\u4E0A\u95E8\u9886\u53D6\u5916\uFF0C\u5FEB\u9012\u516C\u53F8/\u5FEB\u9012\u5355\u53F7/\u5FEB\u9012\u65F6\u95F4/\u5FEB\u9012\u53D1\u9001\u4EBA/\u6536\u4EF6\u4EBA\u5730\u5740\uFF0C\u5FC5\u987B\u586B\u5199
reward.redeem.batch.verify.error = \u793C\u54C1\u8BB0\u5F55\u6279\u91CF\u6838\u9500\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u6570\u636E\u662F\u5426\u6B63\u786E:{}
\ No newline at end of file
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