Commit b48dc662 authored by zhangfeng's avatar zhangfeng

Merge branch 'refs/heads/feature_member_score_zhangfeng' into feature_member_score

# Conflicts:
#	yudao-module-reward/yudao-module-reward-impl/src/main/java/cn/iocoder/yudao/module/reward/controller/admin/redeem/RedeemRewardController.java
parents 19bbf09b d5fc0620
......@@ -44,5 +44,11 @@ public interface ErrorCodeConstants {
ErrorCode SCORE_COUNT_ERROR = new ErrorCode(1004008002, "score.count.error");
ErrorCode MEMBER_SCORE_NOT_ENOUGH = new ErrorCode(1004008002, "member.score.not.enough");
ErrorCode MEMBER_SCORE_NOT_ENOUGH = new ErrorCode(1004008003, "member.score.not.enough");
ErrorCode SCORE_RULE_NOT_EXISTS = new ErrorCode(1004008004, "score.rule.not.exists");
ErrorCode SCORE_RULE_DELETE_ERROR = new ErrorCode(1004008005, "score.rule.delete.error");
ErrorCode SCORE_RULE_UPDATE_ERROR = new ErrorCode(1004008005, "score.rule.update.error");
}
package cn.iocoder.yudao.module.member.enums;
public enum PlatformTypeEnum {
BACKEND(1, "后台"),
APP(2, "APP"),
WEB(3, "WEB");
private final int value;
private final String name;
PlatformTypeEnum(int value, String name) {
this.value = value;
this.name = name;
}
public int getValue() {
return value;
}
public String getName() {
return name;
}
}
package cn.iocoder.yudao.module.member.enums;
public enum ScoreRuleStatusEnum {
ENABLED(1, "已启用"),
DISABLED(2, "未启用"),
CLOSED(3, "已关闭"),
EXPIRED(4, "已过期");
private final int value;
private final String name;
ScoreRuleStatusEnum(int value, String name) {
this.value = value;
this.name = name;
}
public int getValue() {
return value;
}
public String getName() {
return name;
}
}
package cn.iocoder.yudao.module.member.enums;
public enum ScoreRuleTypeEnum {
ORDER_V(1, "订单V值"),
REGISTER(2, "注册"),
RECOMMEND(3, "推荐"),
SHARE(4, "分享活动");
private final int value;
private final String name;
ScoreRuleTypeEnum(int value, String name) {
this.value = value;
this.name = name;
}
public int getValue() {
return value;
}
public String getName() {
return name;
}
}
package cn.iocoder.yudao.module.member.enums;
public enum YesOrNoTypeEnum {
YES,
NO;
}
package cn.iocoder.yudao.module.member.controller.admin.scoreRule;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.util.ExcelUtils;
import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.member.convert.scoreRule.ScoreRuleConvert;
import cn.iocoder.yudao.module.member.dal.dataobject.scoreRule.ScoreRuleDO;
import cn.iocoder.yudao.module.member.service.scoreRule.ScoreRuleService;
import cn.iocoder.yudao.module.member.vo.scoreRule.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
@Validated
@RestController
@Api(tags = "管理后台 - 积分规则")
@RequestMapping("/member/score-rule")
public class ScoreRuleController {
@Resource
private ScoreRuleService scoreRuleService;
@PostMapping("/create")
@ApiOperation("创建积分规则")
@PreAuthorize("@ss.hasPermission('member:score-rule:create')")
public CommonResult<Long> createScoreRule(@Valid @RequestBody ScoreRuleCreateReqVO createReqVO) {
return success(scoreRuleService.createScoreRule(createReqVO));
}
@PostMapping("/update")
@ApiOperation("更新积分规则")
@PreAuthorize("@ss.hasPermission('member:score-rule:update')")
public CommonResult<Boolean> updateScoreRule(@Valid @RequestBody ScoreRuleUpdateReqVO updateReqVO) {
scoreRuleService.updateScoreRule(updateReqVO);
return success(true);
}
@PostMapping("/delete")
@ApiOperation("删除积分规则")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('member:score-rule:delete')")
public CommonResult<Boolean> deleteScoreRule(@NotNull @RequestBody Long id) {
scoreRuleService.deleteScoreRule(id);
return success(true);
}
@PostMapping("/get")
@ApiOperation("获得积分规则详情")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('member:score-rule:query')")
public CommonResult<ScoreRuleBackVO> getScoreRule(@NotNull @RequestBody Long id) {
ScoreRuleBackVO scoreRuleBackVO = scoreRuleService.getScoreRule(id);
return success(scoreRuleBackVO);
}
@PostMapping("/list")
@ApiOperation("获得积分规则列表")
@ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
@PreAuthorize("@ss.hasPermission('member:score-rule:query')")
public CommonResult<List<ScoreRuleBackVO>> getScoreRuleList(@NotNull @RequestBody Collection<Long> ids) {
List<ScoreRuleBackVO> list = scoreRuleService.getScoreRuleList(ids);
return success(list);
}
@PostMapping("/page")
@ApiOperation("获得积分规则分页")
@PreAuthorize("@ss.hasPermission('member:score-rule:query')")
public CommonResult<PageResult<ScoreRuleBackVO>> getScoreRulePage(@Valid @RequestBody ScoreRuleQueryVO query, PageVO page) {
PageResult<ScoreRuleBackVO> pageResult = scoreRuleService.getScoreRulePage(query, page);
return success(pageResult);
}
@PostMapping("/status")
@ApiOperation("启用关闭")
@PreAuthorize("@ss.hasPermission('member:score-rule:update')")
public CommonResult<Boolean> updateStatus(@Valid @RequestBody ScoreRuleStatusReqVO scoreRuleStatusReqVO) {
Boolean res = scoreRuleService.updateStatus(scoreRuleStatusReqVO);
return success(res);
}
@PostMapping("/copy")
@ApiOperation("复制规则")
@PreAuthorize("@ss.hasPermission('member:score-rule:create')")
public CommonResult<Long> copyScoreRule(@NotNull @RequestBody Long id) {
Long newId = scoreRuleService.copyScoreRule(id);
return success(id);
}
@PostMapping("/delay")
@ApiOperation("延期规则")
@PreAuthorize("@ss.hasPermission('member:score-rule:update')")
public CommonResult<Boolean> delayScoreRule(@Valid @RequestBody ScoreDelayReqVO scoreDelayReqVO) {
Boolean res = scoreRuleService.delayScoreRule(scoreDelayReqVO);
return success(res);
}
@GetMapping("/export-excel")
@ApiOperation("导出积分规则Excel")
@PreAuthorize("@ss.hasPermission('member:score-rule:export')")
@OperateLog(type = EXPORT)
public void exportScoreRuleExcel(@Valid ScoreRuleQueryVO query,
HttpServletResponse response) throws IOException {
List<ScoreRuleDO> list = scoreRuleService.getScoreRuleList(query);
// 导出 Excel
List<ScoreRuleBackVO> datas = ScoreRuleConvert.INSTANCE.convertList(list);
ExcelUtils.write(response, "积分规则.xls", "数据", ScoreRuleBackVO.class, datas);
}
}
package cn.iocoder.yudao.module.member.convert.scoreRule;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.vo.scoreRule.ScoreRuleBackVO;
import cn.iocoder.yudao.module.member.vo.scoreRule.ScoreRuleCreateReqVO;
import cn.iocoder.yudao.module.member.vo.scoreRule.ScoreRuleUpdateReqVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.member.dal.dataobject.scoreRule.ScoreRuleDO;
/**
* 积分规则 DO Convert
* @author 系统管理员
*/
@Mapper
public interface ScoreRuleConvert {
/*****转换MapStruct*****/
ScoreRuleConvert INSTANCE = Mappers.getMapper(ScoreRuleConvert.class);
/***
* 创建VO转实体
* @param bean
* @return
*/
ScoreRuleDO convert(ScoreRuleCreateReqVO bean);
/***
* 修改VO转实体
* @param bean
* @return
*/
ScoreRuleDO convert(ScoreRuleUpdateReqVO bean);
/***
* 实体转返回VO
* @param bean
* @return
*/
ScoreRuleBackVO convert(ScoreRuleDO bean);
/***
* 实体列表转返回VO列表
* @param list
* @return
*/
List<ScoreRuleBackVO> convertList(List<ScoreRuleDO> list);
/***
* 实体分页转返回分页
* @param page
* @return
*/
PageResult<ScoreRuleBackVO> convertPage(PageResult<ScoreRuleDO> page);
}
package cn.iocoder.yudao.module.member.dal.dataobject.scoreRule;
import lombok.*;
import java.util.*;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 积分规则 DO
*
* @author 系统管理员
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("score_rule")
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ScoreRuleDO extends BaseDO {
/**
* 主键
*/
@TableId
private Long id;
/**
* 指标类型
*/
private Integer type;
/**
* 规则标题中文
*/
private String titleZh;
/**
* 规则标题英文
*/
private String titleEn;
/**
* 规则说明中文
*/
private String descZh;
/**
* 规则说明英文
*/
private String descEn;
/**
* 封面图中文
*/
private String coverImageZh;
/**
* 封面图英文
*/
private String coverImageEn;
/**
* 单次获取积分数
*/
private Integer getScoreOnce;
/**
* 累积最高积分
*/
private Integer maxScoreTotal;
/**
* 活动开始时间
*/
private Date startTime;
/**
* 活动结束时间
*/
private Date endTime;
/**
* 积分有效期
*/
private Integer socrePeriod;
/**
* 排序值
*/
private Integer orderNum;
/**
* 是否推送
*/
private Integer pushActivity;
/**
* 展示平台
*/
private String showPlatform;
/**
* 活动状态
*/
private Integer status;
/**
* 扩展字段
*/
private String extra;
}
package cn.iocoder.yudao.module.member.dal.mysql.scoreRule;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQuery;
import cn.iocoder.yudao.framework.mybatis.core.mapper.AbstractMapper;
import cn.iocoder.yudao.module.member.dal.dataobject.scoreRule.ScoreRuleDO;
import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO;
import cn.iocoder.yudao.module.member.vo.scoreRule.ScoreRuleQueryVO;
import org.apache.ibatis.annotations.Mapper;
/**
* 积分规则 DO Mapper
* @author 系统管理员
*/
@Mapper
public interface ScoreRuleMapper extends AbstractMapper<ScoreRuleDO> {
@Override
default PageResult<ScoreRuleDO> selectPage(PageVO page, Object object) {
if (object instanceof ScoreRuleQueryVO) {
ScoreRuleQueryVO vo = (ScoreRuleQueryVO)object;
return selectPage(page, new LambdaQuery<ScoreRuleDO>()
.eqIfPresent(ScoreRuleDO::getType, vo.getType())
.eqIfPresent(ScoreRuleDO::getTitleZh, vo.getTitleZh())
.eqIfPresent(ScoreRuleDO::getTitleEn, vo.getTitleEn())
.eqIfPresent(ScoreRuleDO::getDescZh, vo.getDescZh())
.eqIfPresent(ScoreRuleDO::getDescEn, vo.getDescEn())
.eqIfPresent(ScoreRuleDO::getCoverImageZh, vo.getCoverImageZh())
.eqIfPresent(ScoreRuleDO::getCoverImageEn, vo.getCoverImageEn())
.eqIfPresent(ScoreRuleDO::getGetScoreOnce, vo.getGetScoreOnce())
.eqIfPresent(ScoreRuleDO::getMaxScoreTotal, vo.getMaxScoreTotal())
.betweenIfPresent(ScoreRuleDO::getStartTime, vo.getBeginStartTime(), vo.getEndStartTime())
.betweenIfPresent(ScoreRuleDO::getEndTime, vo.getBeginEndTime(), vo.getEndEndTime())
.eqIfPresent(ScoreRuleDO::getSocrePeriod, vo.getSocrePeriod())
.eqIfPresent(ScoreRuleDO::getOrderNum, vo.getOrderNum())
.eqIfPresent(ScoreRuleDO::getPushActivity, vo.getPushActivity())
.eqIfPresent(ScoreRuleDO::getShowPlatform, vo.getShowPlatform())
.eqIfPresent(ScoreRuleDO::getStatus, vo.getStatus())
.eqIfPresent(ScoreRuleDO::getExtra, vo.getExtra())
.betweenIfPresent(ScoreRuleDO::getCreateTime, vo.getBeginCreateTime(), vo.getEndCreateTime())
.orderByDesc(ScoreRuleDO::getId));
}
return null;
}
@Override
default List<ScoreRuleDO> selectList(Object object) {
if (object instanceof ScoreRuleQueryVO) {
ScoreRuleQueryVO vo = (ScoreRuleQueryVO)object;
return selectList(new LambdaQuery<ScoreRuleDO>()
.eqIfPresent(ScoreRuleDO::getType, vo.getType())
.eqIfPresent(ScoreRuleDO::getTitleZh, vo.getTitleZh())
.eqIfPresent(ScoreRuleDO::getTitleEn, vo.getTitleEn())
.eqIfPresent(ScoreRuleDO::getDescZh, vo.getDescZh())
.eqIfPresent(ScoreRuleDO::getDescEn, vo.getDescEn())
.eqIfPresent(ScoreRuleDO::getCoverImageZh, vo.getCoverImageZh())
.eqIfPresent(ScoreRuleDO::getCoverImageEn, vo.getCoverImageEn())
.eqIfPresent(ScoreRuleDO::getGetScoreOnce, vo.getGetScoreOnce())
.eqIfPresent(ScoreRuleDO::getMaxScoreTotal, vo.getMaxScoreTotal())
.betweenIfPresent(ScoreRuleDO::getStartTime, vo.getBeginStartTime(), vo.getEndStartTime())
.betweenIfPresent(ScoreRuleDO::getEndTime, vo.getBeginEndTime(), vo.getEndEndTime())
.eqIfPresent(ScoreRuleDO::getSocrePeriod, vo.getSocrePeriod())
.eqIfPresent(ScoreRuleDO::getOrderNum, vo.getOrderNum())
.eqIfPresent(ScoreRuleDO::getPushActivity, vo.getPushActivity())
.eqIfPresent(ScoreRuleDO::getShowPlatform, vo.getShowPlatform())
.eqIfPresent(ScoreRuleDO::getStatus, vo.getStatus())
.eqIfPresent(ScoreRuleDO::getExtra, vo.getExtra())
.betweenIfPresent(ScoreRuleDO::getCreateTime, vo.getBeginCreateTime(), vo.getEndCreateTime())
.orderByDesc(ScoreRuleDO::getId));
}
return null;
}
}
package cn.iocoder.yudao.module.member.service.scoreRule;
import java.util.*;
import javax.validation.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.service.IService;
import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO;
import cn.iocoder.yudao.module.member.dal.dataobject.scoreRule.ScoreRuleDO;
import cn.iocoder.yudao.module.member.vo.scoreRule.*;
/**
* 积分规则 Service 接口
*
* @author 系统管理员
*/
public interface ScoreRuleService extends IService<ScoreRuleDO> {
/**
* 创建积分规则
* @param createReqVO 创建信息
* @return 编号
*/
Long createScoreRule(@Valid ScoreRuleCreateReqVO createReqVO);
/**
* 更新积分规则
* @param updateReqVO 更新信息
*/
void updateScoreRule(@Valid ScoreRuleUpdateReqVO updateReqVO);
/**
* 删除积分规则
* @param id 编号
*/
void deleteScoreRule(Long id);
/**
* 获得积分规则
*
* @param id 编号
* @return 积分规则
*/
ScoreRuleBackVO getScoreRule(Long id);
/**
* 获得积分规则列表
*
* @param ids 编号
* @return 积分规则列表
*/
List<ScoreRuleBackVO> getScoreRuleList(Collection<Long> ids);
/**
* 获得积分规则分页
*
* @param page 分页查询
* @param query 查询
* @return 积分规则分页
*/
PageResult<ScoreRuleBackVO> getScoreRulePage(ScoreRuleQueryVO query, PageVO page);
/**
* 获得积分规则列表, 用于 Excel 导出
* @param query 查询
* @return 积分规则列表
*/
List<ScoreRuleDO> getScoreRuleList(ScoreRuleQueryVO query);
/**
* 积分规则启用关闭
* @param scoreRuleStatusReqVO 积分规则状态
* @return
*/
Boolean updateStatus(ScoreRuleStatusReqVO scoreRuleStatusReqVO);
/**
* 积分规则复制
* @param id
* @return
*/
Long copyScoreRule(Long id);
/**
* 积分规则延期
* @param scoreDelayReqVO 积分规则延期
* @return
*/
Boolean delayScoreRule(ScoreDelayReqVO scoreDelayReqVO);
}
package cn.iocoder.yudao.module.member.service.scoreRule;
import java.time.Instant;
import java.util.*;
import javax.annotation.Resource;
import cn.hutool.json.JSONUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.service.AbstractService;
import cn.iocoder.yudao.module.member.convert.scoreRule.ScoreRuleConvert;
import cn.iocoder.yudao.module.member.dal.dataobject.scoreRule.ScoreRuleDO;
import cn.iocoder.yudao.module.member.dal.mysql.scoreRule.ScoreRuleMapper;
import cn.iocoder.yudao.module.member.enums.ScoreRuleStatusEnum;
import cn.iocoder.yudao.module.member.enums.ScoreRuleTypeEnum;
import cn.iocoder.yudao.module.member.vo.scoreRule.*;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleOrderVExtraVO;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleRegisterExtraVO;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleShareExtraVO;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRulerRecommendExtraVO;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*;
/**
* 积分规则 Service 实现类
*
* @author 系统管理员
*/
@Service
@Validated
public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, ScoreRuleDO> implements ScoreRuleService {
@Resource
private ScoreRuleMapper scoreRuleMapper;
@Override
public Long createScoreRule(ScoreRuleCreateReqVO createReqVO) {
ScoreRuleDO scoreRule = ScoreRuleConvert.INSTANCE.convert(createReqVO);
Integer scoreRuleType = scoreRule.getType();
setExtraDO(createReqVO, scoreRuleType, scoreRule);
scoreRuleMapper.insert(scoreRule);
// 返回
return scoreRule.getId();
}
@Override
public void updateScoreRule(ScoreRuleUpdateReqVO updateReqVO) {
// 校验存在
this.validateScoreRuleExists(updateReqVO.getId());
ScoreRuleDO scoreRule = ScoreRuleConvert.INSTANCE.convert(updateReqVO);
setExtraDO(updateReqVO, updateReqVO.getType(), scoreRule);
// 更新
ScoreRuleDO updateObj = ScoreRuleConvert.INSTANCE.convert(updateReqVO);
scoreRuleMapper.updateById(updateObj);
}
/**
* 设置额外信息
*
* @param reqVO 请求实体
* @param scoreRuleType 指标类型
* @param scoreRule 需要填充额外字段的DO
*/
private void setExtraDO(ScoreRuleBaseVO reqVO, Integer scoreRuleType, ScoreRuleDO scoreRule) {
if (scoreRuleType == ScoreRuleTypeEnum.ORDER_V.getValue()) {
scoreRule.setExtra(JSONUtil.toJsonStr(reqVO.getExtraOrderV()));
} else if (scoreRuleType == ScoreRuleTypeEnum.REGISTER.getValue()) {
scoreRule.setExtra(JSONUtil.toJsonStr(reqVO.getExtraRegister()));
} else if (scoreRuleType == ScoreRuleTypeEnum.RECOMMEND.getValue()) {
scoreRule.setExtra(JSONUtil.toJsonStr(reqVO.getExtraRecommend()));
} else if (scoreRuleType == ScoreRuleTypeEnum.SHARE.getValue()) {
scoreRule.setExtra(JSONUtil.toJsonStr(reqVO.getExtraShare()));
} else {
throw exception(SCORE_RULE_NOT_EXISTS);
}
}
@Override
public void deleteScoreRule(Long id) {
ScoreRuleDO scoreRuleDO = scoreRuleMapper.selectById(id);
if (scoreRuleDO == null) {
throw exception(SCORE_RULE_NOT_EXISTS);
}
if (scoreRuleDO.getStatus() == ScoreRuleStatusEnum.ENABLED.getValue()) {
throw exception(SCORE_RULE_DELETE_ERROR);
}
// 删除
scoreRuleMapper.deleteById(id);
}
private void validateScoreRuleExists(Long id) {
if (scoreRuleMapper.selectById(id) == null) {
throw exception(SCORE_RULE_NOT_EXISTS);
}
}
@Override
public ScoreRuleBackVO getScoreRule(Long id) {
ScoreRuleDO scoreRuleDO = scoreRuleMapper.selectById(id);
if (scoreRuleDO == null) {
throw exception(SCORE_RULE_NOT_EXISTS);
}
ScoreRuleBackVO scoreRuleBackVO = ScoreRuleConvert.INSTANCE.convert(scoreRuleDO);
setExtraVO(scoreRuleBackVO);
return scoreRuleBackVO;
}
@Override
public List<ScoreRuleBackVO> getScoreRuleList(Collection<Long> ids) {
List<ScoreRuleDO> scoreRuleDOS = scoreRuleMapper.selectBatchIds(ids);
List<ScoreRuleBackVO> scoreRuleBackVOS = ScoreRuleConvert.INSTANCE.convertList(scoreRuleDOS);
scoreRuleBackVOS.forEach(this::setExtraVO);
return scoreRuleBackVOS;
}
@Override
public PageResult<ScoreRuleBackVO> getScoreRulePage(ScoreRuleQueryVO query, PageVO page) {
PageResult<ScoreRuleDO> pageResult = scoreRuleMapper.selectPage(page, query);
PageResult<ScoreRuleBackVO> scoreRuleBackVOPageResult = ScoreRuleConvert.INSTANCE.convertPage(pageResult);
scoreRuleBackVOPageResult.getList().forEach(this::setExtraVO);
return scoreRuleBackVOPageResult;
}
/**
* 设置返回VO额外信息
*
* @param scoreRuleBackVO VO
*/
private void setExtraVO(ScoreRuleBackVO scoreRuleBackVO) {
if (scoreRuleBackVO.getType() == ScoreRuleTypeEnum.ORDER_V.getValue()) {
scoreRuleBackVO.setExtraOrderV(JSONUtil.toBean(scoreRuleBackVO.getExtra(), ScoreRuleOrderVExtraVO.class));
} else if (scoreRuleBackVO.getType() == ScoreRuleTypeEnum.REGISTER.getValue()) {
scoreRuleBackVO.setExtraRegister(JSONUtil.toBean(scoreRuleBackVO.getExtra(), ScoreRuleRegisterExtraVO.class));
} else if (scoreRuleBackVO.getType() == ScoreRuleTypeEnum.RECOMMEND.getValue()) {
scoreRuleBackVO.setExtraRecommend(JSONUtil.toBean(scoreRuleBackVO.getExtra(), ScoreRulerRecommendExtraVO.class));
} else if (scoreRuleBackVO.getType() == ScoreRuleTypeEnum.SHARE.getValue()) {
scoreRuleBackVO.setExtraShare(JSONUtil.toBean(scoreRuleBackVO.getExtra(), ScoreRuleShareExtraVO.class));
} else {
throw exception(SCORE_RULE_NOT_EXISTS);
}
}
@Override
public List<ScoreRuleDO> getScoreRuleList(ScoreRuleQueryVO query) {
return scoreRuleMapper.selectList(query);
}
@Override
public Boolean updateStatus(ScoreRuleStatusReqVO scoreRuleStatusReqVO) {
ScoreRuleDO scoreRuleDO = scoreRuleMapper.selectById(scoreRuleStatusReqVO.getId());
if (scoreRuleDO == null) {
throw exception(SCORE_RULE_NOT_EXISTS);
}
ScoreRuleDO upScoreRuleDO = new ScoreRuleDO();
upScoreRuleDO.setId(scoreRuleStatusReqVO.getId());
upScoreRuleDO.setStatus(scoreRuleStatusReqVO.getStatus());
int updated = scoreRuleMapper.updateById(upScoreRuleDO);
return updated > 0;
}
@Override
public Long copyScoreRule(Long id) {
ScoreRuleDO scoreRuleDO = scoreRuleMapper.selectById(id);
if (scoreRuleDO == null) {
throw exception(SCORE_RULE_NOT_EXISTS);
}
scoreRuleDO.setStatus(ScoreRuleStatusEnum.DISABLED.getValue());
scoreRuleDO.setId(null);
scoreRuleDO.setCreateTime(null);
scoreRuleDO.setUpdateTime(null);
scoreRuleMapper.insert(scoreRuleDO);
return scoreRuleDO.getId();
}
@Override
public Boolean delayScoreRule(ScoreDelayReqVO delayReqVO) {
ScoreRuleDO scoreRuleDO = scoreRuleMapper.selectById(delayReqVO.getId());
if (scoreRuleDO == null) {
throw exception(SCORE_RULE_NOT_EXISTS);
}
if (scoreRuleDO.getStatus() != ScoreRuleStatusEnum.ENABLED.getValue()) {
throw exception(SCORE_RULE_UPDATE_ERROR);
}
Instant now = Instant.now();
//结束时间不能小于当前时间
if (!delayReqVO.getEndTime().toInstant().isAfter(now)) {
throw exception(SCORE_RULE_UPDATE_ERROR);
}
ScoreRuleDO upScoreRuleDO = new ScoreRuleDO();
upScoreRuleDO.setId(delayReqVO.getId());
upScoreRuleDO.setEndTime(delayReqVO.getEndTime());
int updated = scoreRuleMapper.updateById(upScoreRuleDO);
return updated > 0;
}
}
package cn.iocoder.yudao.module.member.vo.scoreRule;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotNull;
import java.util.Date;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Data
@ApiModel("管理后台 - 积分规则延期 Response VO")
public class ScoreDelayReqVO {
@ApiModelProperty(value = "主键", required = true)
@NotNull(message = "主键不能为空")
private Long id;
@ApiModelProperty(value = "结束时间", required = true)
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@NotNull(message = "结束时间不能为空")
private Date endTime;
}
package cn.iocoder.yudao.module.member.vo.scoreRule;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleOrderVExtraVO;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleRegisterExtraVO;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleShareExtraVO;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRulerRecommendExtraVO;
import com.baomidou.dynamic.datasource.annotation.DS;
import lombok.*;
import java.util.*;
import io.swagger.annotations.*;
import com.alibaba.excel.annotation.ExcelProperty;
import org.springframework.format.annotation.DateTimeFormat;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
/**
* 积分规则 Response VO
* @author 系统管理员
*/
@Data
@ApiModel("管理后台 - 积分规则 Response VO")
public class ScoreRuleBackVO {
@ExcelProperty("主键")
@ApiModelProperty(value = "主键", required = true)
private Long id;
@ExcelProperty("指标类型")
@ApiModelProperty(value = "指标类型", required = true)
private Integer type;
@ExcelProperty("规则标题中文")
@ApiModelProperty(value = "规则标题中文", required = true)
private String titleZh;
@ExcelProperty("规则标题英文")
@ApiModelProperty(value = "规则标题英文", required = true)
private String titleEn;
@ExcelProperty("规则说明中文")
@ApiModelProperty(value = "规则说明中文", required = true)
private String descZh;
@ExcelProperty("规则说明英文")
@ApiModelProperty(value = "规则说明英文", required = true)
private String descEn;
@ExcelProperty("封面图中文")
@ApiModelProperty(value = "封面图中文")
private String coverImageZh;
@ExcelProperty("封面图英文")
@ApiModelProperty(value = "封面图英文")
private String coverImageEn;
@ExcelProperty("单次获取积分数")
@ApiModelProperty(value = "单次获取积分数", required = true)
private Integer getScoreOnce;
@ExcelProperty("累积最高积分")
@ApiModelProperty(value = "累积最高积分", required = true)
private Integer maxScoreTotal;
@ExcelProperty("活动开始时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "活动开始时间", required = true)
private Date startTime;
@ExcelProperty("活动结束时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "活动结束时间", required = true)
private Date endTime;
@ExcelProperty("积分有效期")
@ApiModelProperty(value = "积分有效期", required = true)
private Integer socrePeriod;
@ExcelProperty("排序值")
@ApiModelProperty(value = "排序值", required = true)
private Integer orderNum;
@ExcelProperty("是否推送")
@ApiModelProperty(value = "是否推送", required = true)
private Integer pushActivity;
@ExcelProperty("展示平台")
@ApiModelProperty(value = "展示平台", required = true)
private String showPlatform;
@ExcelProperty("活动状态")
@ApiModelProperty(value = "活动状态", required = true)
private Integer status;
@ExcelProperty("创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "创建时间", required = true)
private Date createTime;
@ApiModelProperty(value = "扩展字段原始")
private String extra;
@ApiModelProperty(value = "订单V值扩展字段")
private ScoreRuleOrderVExtraVO extraOrderV;
@ApiModelProperty(value = "注册扩展字段")
private ScoreRuleRegisterExtraVO extraRegister;
@ApiModelProperty(value = "推荐扩展字段")
private ScoreRulerRecommendExtraVO extraRecommend;
@ApiModelProperty(value = "分享扩展字段")
private ScoreRuleShareExtraVO extraShare;
}
package cn.iocoder.yudao.module.member.vo.scoreRule;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleOrderVExtraVO;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleRegisterExtraVO;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleShareExtraVO;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRulerRecommendExtraVO;
import lombok.*;
import java.util.*;
import io.swagger.annotations.*;
import javax.validation.constraints.*;
import org.springframework.format.annotation.DateTimeFormat;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
/**
* 积分规则 Base VO,提供给添加、修改、详细的子 VO 使用
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
*/
@Data
public class ScoreRuleBaseVO {
@ApiModelProperty(value = "指标类型(1订单V值,2注册,3推荐,4分享)", required = true)
@NotNull(message = "指标类型不能为空")
private Integer type;
@ApiModelProperty(value = "规则标题中文", required = true)
@NotNull(message = "规则标题中文不能为空")
private String titleZh;
@ApiModelProperty(value = "规则标题英文", required = true)
@NotNull(message = "规则标题英文不能为空")
private String titleEn;
@ApiModelProperty(value = "规则说明中文", required = true)
@NotNull(message = "规则说明中文不能为空")
private String descZh;
@ApiModelProperty(value = "规则说明英文", required = true)
@NotNull(message = "规则说明英文不能为空")
private String descEn;
@ApiModelProperty(value = "封面图中文")
private String coverImageZh;
@ApiModelProperty(value = "封面图英文")
private String coverImageEn;
@ApiModelProperty(value = "单次获取积分数,订单V值中代表单次最高获取积分数", required = true)
@NotNull(message = "单次获取积分数不能为空")
private Integer getScoreOnce;
@ApiModelProperty(value = "累积最高积分(注册直接传null)", required = true)
private Integer maxScoreTotal;
@ApiModelProperty(value = "活动开始时间", required = true)
@NotNull(message = "活动开始时间不能为空")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private Date startTime;
@ApiModelProperty(value = "活动结束时间", required = true)
@NotNull(message = "活动结束时间不能为空")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private Date endTime;
@ApiModelProperty(value = "积分有效期(天)", required = true)
@NotNull(message = "积分有效期不能为空")
private Integer scorePeriod;
@ApiModelProperty(value = "排序值", required = true)
@NotNull(message = "排序值不能为空")
private Integer orderNum;
@ApiModelProperty(value = "是否推送(0是,1否)", required = true)
@NotNull(message = "是否推送不能为空")
private Integer pushActivity = 0;
@ApiModelProperty(value = "展示平台(1后台,2APP,3WEB)可多选,示例(1,2,3)", required = true)
@NotNull(message = "展示平台不能为空")
private String showPlatform;
@ApiModelProperty(value = "活动状态(1已启用,2未启用,3已关闭,4已过期)", required = true)
@NotNull(message = "活动状态不能为空")
private Integer status;
@ApiModelProperty(value = "订单V值扩展字段")
private ScoreRuleOrderVExtraVO extraOrderV;
@ApiModelProperty(value = "注册扩展字段")
private ScoreRuleRegisterExtraVO extraRegister;
@ApiModelProperty(value = "推荐扩展字段")
private ScoreRulerRecommendExtraVO extraRecommend;
@ApiModelProperty(value = "分享扩展字段")
private ScoreRuleShareExtraVO extraShare;
}
package cn.iocoder.yudao.module.member.vo.scoreRule;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleOrderVExtraVO;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleRegisterExtraVO;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleShareExtraVO;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRulerRecommendExtraVO;
import lombok.*;
import java.util.*;
import io.swagger.annotations.*;
import javax.validation.constraints.*;
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@ApiModel("管理后台 - 积分规则创建 Request VO")
public class ScoreRuleCreateReqVO extends ScoreRuleBaseVO {
}
package cn.iocoder.yudao.module.member.vo.scoreRule;
import lombok.*;
import java.util.*;
import io.swagger.annotations.*;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Data
@ApiModel("管理后台 - 积分规则查询 VO")
public class ScoreRuleQueryVO {
@ApiModelProperty(value = "指标类型")
private Integer type;
@ApiModelProperty(value = "规则标题中文")
private String titleZh;
@ApiModelProperty(value = "规则标题英文")
private String titleEn;
@ApiModelProperty(value = "规则说明中文")
private String descZh;
@ApiModelProperty(value = "规则说明英文")
private String descEn;
@ApiModelProperty(value = "封面图中文")
private String coverImageZh;
@ApiModelProperty(value = "封面图英文")
private String coverImageEn;
@ApiModelProperty(value = "单次获取积分数")
private Integer getScoreOnce;
@ApiModelProperty(value = "累积最高积分")
private Integer maxScoreTotal;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "开始活动开始时间")
private Date beginStartTime;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "结束活动开始时间")
private Date endStartTime;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "开始活动结束时间")
private Date beginEndTime;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "结束活动结束时间")
private Date endEndTime;
@ApiModelProperty(value = "积分有效期")
private Integer socrePeriod;
@ApiModelProperty(value = "排序值")
private Integer orderNum;
@ApiModelProperty(value = "是否推送")
private Integer pushActivity;
@ApiModelProperty(value = "展示平台")
private String showPlatform;
@ApiModelProperty(value = "活动状态")
private Integer status;
@ApiModelProperty(value = "扩展字段")
private String extra;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "开始创建时间")
private Date beginCreateTime;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "结束创建时间")
private Date endCreateTime;
}
package cn.iocoder.yudao.module.member.vo.scoreRule;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Data
@ApiModel("管理后台 - 启用关闭规则 VO")
public class ScoreRuleStatusReqVO {
@ApiModelProperty(value = "主键", required = true)
@NotNull(message = "主键不能为空")
private Long id;
@ApiModelProperty(value = "状态(1已启用,2未启用,3已关闭,4已过期)", required = true)
@NotNull(message = "状态不能为空")
private Integer status;
}
package cn.iocoder.yudao.module.member.vo.scoreRule;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleOrderVExtraVO;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleRegisterExtraVO;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleShareExtraVO;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRulerRecommendExtraVO;
import lombok.*;
import java.util.*;
import io.swagger.annotations.*;
import javax.validation.constraints.*;
@ApiModel("管理后台 - 积分规则更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ScoreRuleUpdateReqVO extends ScoreRuleBaseVO {
@ApiModelProperty(value = "主键", required = true)
@NotNull(message = "主键不能为空")
private Long id;
}
package cn.iocoder.yudao.module.member.vo.scoreRule.extra;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Data
@ApiModel("管理后台 - 订单V值额外字段 VO")
public class ScoreRuleOrderVExtraVO {
@ApiModelProperty(value = "是否首单(0是,1否)默认否", required = true)
private Integer firstOrder = 1;
@ApiModelProperty(value = "运输方式(1海运拼柜,3专线空运)字典有", required = true)
private Integer transportType;
@ApiModelProperty(value = "目的国,可多选,逗号拼接", required = true)
private String targetCountry;
@ApiModelProperty(value = "目的城市,可多选,逗号拼接", required = true)
private String targetCity;
@ApiModelProperty(value = "提货点,可多选,逗号拼接", required = true)
private String receiveAddr;
@ApiModelProperty(value = "渠道,运输方式选择海运时,渠道隐藏,可多选,逗号拼接")
private String channel;
@ApiModelProperty(value = "积分规则列表", required = true)
private List<OrderVRule> orderVRule;
@ApiModelProperty(value = "订单入口(1后台,2APP,3WEB)可多选,逗号拼", required = true)
private String orderEntry;
@Data
public static class OrderVRule {
@ApiModelProperty(value = "起始重量/体积")
private Integer low;
@ApiModelProperty(value = "截止重量/体积")
private Integer high;
@ApiModelProperty(value = "积分")
private Integer score;
}
}
package cn.iocoder.yudao.module.member.vo.scoreRule.extra;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel("管理后台 - 注册额外字段 VO")
public class ScoreRuleRegisterExtraVO {
@ApiModelProperty(value = "注册平台(2APP,3WEB)可多选,逗号拼", required = true)
private String registerPlatform ;
}
package cn.iocoder.yudao.module.member.vo.scoreRule.extra;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel("管理后台 - 分享额外字段 VO")
public class ScoreRuleShareExtraVO {
@ApiModelProperty(value = "中文活动内容", required = true)
private String activityDescZh ;
@ApiModelProperty(value = "英文活动内容", required = true)
private String activityDescEn ;
@ApiModelProperty(value = "活动链接", required = true)
private String activityUrl ;
@ApiModelProperty(value = "是否分享(0是,1否)默认是", required = true)
private String shareStatus ;
}
package cn.iocoder.yudao.module.member.vo.scoreRule.extra;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel("管理后台 - 推荐额外字段 VO")
public class ScoreRulerRecommendExtraVO {
@ApiModelProperty(value = "中文分享文案", required = true)
private String shareContentZh ;
@ApiModelProperty(value = "英文分享文案", required = true)
private String shareContentEn ;
@ApiModelProperty(value = "是否分享(0是,1否)默认是", required = true)
private Integer shareStatus = 0;
}
package cn.iocoder.yudao.module.reward.enums;
public enum QuantitativeRelationSymbolEnum {
GT(1, "大于"),
EQ(2, "等于"),
LT(3, "小于");
private final int value;
private final String name;
QuantitativeRelationSymbolEnum(int value, String name) {
this.value = value;
this.name = name;
}
public int getValue() {
return value;
}
public String getName() {
return name;
}
}
package cn.iocoder.yudao.module.reward.enums;
public enum RewardPickMethedEnum {
PICKUP(1, "上门领取"),
SELF_PICKUP(1, "上门领取"),
SEND_HOME_FREE(2, "包邮到家"),
SEND_HOME_PAY(3, "邮寄到付")
;
......
package cn.iocoder.yudao.module.reward.enums;
public enum RewardStatusEnum {
ENABLED(1, "已启用"),
DISABLED(2, "未启用"),
CLOSED(3, "已关闭"),
EXPIRED(4, "已过期");
private final int value;
private final String name;
RewardStatusEnum(int value, String name) {
this.value = value;
this.name = name;
}
public int getValue() {
return value;
}
public String getName() {
return name;
}
}
......@@ -62,9 +62,6 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
throw exception(REWARD_COUNT_NOT_ENOUGH);
}
// 兑换方式不匹配
// if (!Objects.equals(rewardDO.getPickMethod(), redeemRewardReqVO.getRedeemType())) {
// throw exception(REWARD_PICK_METHOD_NOT_ALLOW_CREATE);
// }
String pickMethod = rewardDO.getPickMethod();
String[] split = pickMethod.split(",");
if (!Arrays.asList(split).contains(String.valueOf(redeemRewardReqVO.getRedeemType()))) {
......@@ -91,15 +88,15 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
return null;
}
private void redeemReward(RewardDO rewardDO, Integer rewardCount) {
private void redeemReward(RewardDO reward, Integer rewardCount) {
// 更新时校验礼品数量是否足够
RewardDO rewardDO1 = rewardMapper.selectById(rewardDO.getId());
if (rewardDO1.getQuantityRemain() < rewardCount) {
RewardDO rewardDO = rewardMapper.selectById(reward.getId());
if (rewardDO.getQuantityRemain() < rewardCount) {
throw exception(REWARD_COUNT_NOT_ENOUGH);
}
rewardDO.setExchangeCount(rewardDO.getExchangeCount() + 1);
rewardDO.setQuantityRemain(rewardDO.getQuantityRemain() - rewardCount);
rewardMapper.updateById(rewardDO);
reward.setExchangeCount(reward.getExchangeCount() + 1);
reward.setQuantityRemain(reward.getQuantityRemain() - rewardCount);
rewardMapper.updateById(reward);
}
private void updateMemberScore(RedeemRewardReqVO redeemRewardReqVO, RewardDO rewardDO, Long redeemId) {
......@@ -139,9 +136,6 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
for (RedeemRewardReqVO redeemRewardReqVO : redeemRewardReqVOList) {
// 每个兑换VO校验一遍
// 兑换方式不匹配
// if (!Objects.equals(rewardDO.getPickMethod(), redeemRewardReqVO.getRedeemType())) {
// throw exception(REWARD_PICK_METHOD_NOT_ALLOW_CREATE);
// }
String pickMethod = rewardDO.getPickMethod();
String[] split = pickMethod.split(",");
if (!Arrays.asList(split).contains(String.valueOf(redeemRewardReqVO.getRedeemType()))) {
......
......@@ -7,8 +7,11 @@ import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardReqVO;
import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardRespDTO;
import cn.iocoder.yudao.module.reward.service.redeem.RewardRedeemService;
import cn.iocoder.yudao.module.reward.vo.reward.*;
import cn.iocoder.yudao.module.reward.vo.reward.RewardRedeemPageReqVO;
import cn.iocoder.yudao.module.reward.vo.reward.RewardRedeemPageRespVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -60,14 +63,14 @@ public class RedeemRewardController {
@PostMapping("/single")
@ApiOperation("兑换礼品")
//@PreAuthorize("@ss.hasPermission('reward::redeem')")
@PreAuthorize("@ss.hasPermission('ecw:giftManagement:exchange')")
public CommonResult<RedeemRewardRespDTO> redeemReward(@Valid @RequestBody RedeemRewardReqVO redeemRewardReqVO) {
return success(redeemRewardApi.redeemReward(redeemRewardReqVO));
}
@PostMapping("/batch")
@ApiOperation("批量兑换礼品")
//@PreAuthorize("@ss.hasPermission('reward::redeem')")
@PreAuthorize("@ss.hasPermission('ecw:giftManagement:exchange')")
public CommonResult<List<RedeemRewardRespDTO>> redeemRewards(@Valid @RequestBody List<RedeemRewardReqVO> redeemRewardReqVOList) {
return success(redeemRewardApi.redeemRewards(redeemRewardReqVOList));
}
......
......@@ -9,10 +9,10 @@ import cn.iocoder.yudao.module.reward.convert.reward.RewardConvert;
import cn.iocoder.yudao.module.reward.dal.dataobject.reward.RewardDO;
import cn.iocoder.yudao.module.reward.service.reward.RewardService;
import cn.iocoder.yudao.module.reward.vo.reward.*;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
......@@ -38,14 +38,14 @@ public class RewardController {
@PostMapping("/create")
@ApiOperation("创建礼品")
//@PreAuthorize("@ss.hasPermission('reward::create')")
@PreAuthorize("@ss.hasPermission('ecw:giftManagement:add')")
public CommonResult<Long> create(@Valid @RequestBody RewardCreateReqVO createReqVO) {
return success(rewardService.create(createReqVO));
}
@PostMapping("/update")
@ApiOperation("更新礼品")
//@PreAuthorize("@ss.hasPermission('reward::update')")
@PreAuthorize("@ss.hasPermission('ecw:giftManagement:edit')")
public CommonResult<Boolean> update(@Valid @RequestBody RewardUpdateReqVO updateReqVO) {
rewardService.update(updateReqVO);
return success(true);
......@@ -54,7 +54,7 @@ public class RewardController {
@DeleteMapping("/delete")
@ApiOperation("删除礼品")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
//@PreAuthorize("@ss.hasPermission('reward::delete')")
@PreAuthorize("@ss.hasPermission('ecw:giftManagement:delete')")
public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
rewardService.delete(id);
return success(true);
......@@ -63,7 +63,7 @@ public class RewardController {
@GetMapping("/get")
@ApiOperation("获得礼品详情")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
//@PreAuthorize("@ss.hasPermission('reward::query')")
@PreAuthorize("@ss.hasPermission('ecw:giftManagement:check')")
public CommonResult<RewardBackVO> get(@RequestParam("id") Long id) {
RewardDO rewardDO = rewardService.get(id);
RewardBackVO rewardBackVO = RewardConvert.INSTANCE.convert(rewardDO);
......@@ -91,7 +91,7 @@ public class RewardController {
@PostMapping("/status")
@ApiOperation("礼品状态变更")
//@PreAuthorize("@ss.hasPermission('reward::query')")
@PreAuthorize("@ss.hasPermission('ecw:giftManagement:close')")
public CommonResult<Boolean> updateStatus(@Valid @RequestBody RewardStatusReqVO statusVO) {
rewardService.updateStatus(statusVO);
return success(true);
......@@ -99,12 +99,14 @@ public class RewardController {
@PostMapping("/copy/{id}")
@ApiOperation("复制礼品")
@PreAuthorize("@ss.hasPermission('ecw:giftManagement:copy')")
public CommonResult<Long> copyReward(@NotNull @PathVariable Long id) {
return success(rewardService.copyReward(id));
}
@PostMapping("/delay")
@ApiOperation("礼品延期")
@PreAuthorize("@ss.hasPermission('ecw:giftManagement:postpone')")
public CommonResult<Boolean> delayReward(@Valid @RequestBody RewardDelayReqVO delayVO) {
rewardService.delayReward(delayVO);
return success(true);
......
......@@ -7,6 +7,8 @@ import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO;
import cn.iocoder.yudao.module.reward.convert.reward.RewardConvert;
import cn.iocoder.yudao.module.reward.dal.dataobject.reward.RewardDO;
import cn.iocoder.yudao.module.reward.dal.mysql.reward.RewardMapper;
import cn.iocoder.yudao.module.reward.enums.QuantitativeRelationSymbolEnum;
import cn.iocoder.yudao.module.reward.enums.RewardStatusEnum;
import cn.iocoder.yudao.module.reward.vo.reward.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
......@@ -49,13 +51,9 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
throw exception(REWARD_START_OR_END_TIME_NOT_ALLOW_CREATE);
}
// 创建的礼品状态只能是启用或未启用
if (createReqVO.getStatus() != 1 && createReqVO.getStatus() != 2) {
if (createReqVO.getStatus() != RewardStatusEnum.ENABLED.getValue() && createReqVO.getStatus() != RewardStatusEnum.DISABLED.getValue()) {
throw exception(REWARD_STATUS_NOT_ALLOW_CREATE);
}
//领取方式只能是1,2,3
// if (createReqVO.getPickMethod() != 1 && createReqVO.getPickMethod() != 2 && createReqVO.getPickMethod() != 3) {
// throw exception(REWARD_PICK_METHOD_NOT_ALLOW_CREATE);
// }
// 插入
RewardDO rewardDO = RewardConvert.INSTANCE.convert(createReqVO);
rewardDO.setCode(generateRewardCode());
......@@ -75,7 +73,6 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
}
@Override
// TODO :完善校验
public void update(RewardUpdateReqVO updateReqVO) {
// 校验存在
RewardDO rewardDO = rewardMapper.selectById(updateReqVO.getId());
......@@ -84,7 +81,7 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
}
RewardDO updateObj = new RewardDO();
//未启用可编辑所有内容
if (rewardDO.getStatus() == 2) {
if (rewardDO.getStatus() == RewardStatusEnum.DISABLED.getValue()) {
if (ObjectUtils.allNotNull(updateReqVO.getStartTime(), updateReqVO.getEndTime())) {
if (updateReqVO.getStartTime().after((updateReqVO.getEndTime())) || updateReqVO.getEndTime().before(Date.from(Instant.now()))) {
throw exception(REWARD_START_OR_END_TIME_NOT_ALLOW_CREATE);
......@@ -93,12 +90,8 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
} else {
throw exception(REWARD_START_OR_END_TIME_NOT_ALLOW_CREATE);
}
//领取方式只能是1,2,3
// if (updateReqVO.getPickMethod() != 1 && updateReqVO.getPickMethod() != 2 && updateReqVO.getPickMethod() != 3) {
// throw exception(REWARD_PICK_METHOD_NOT_ALLOW_CREATE);
// }
updateObj = RewardConvert.INSTANCE.convert(updateReqVO);
} else if (rewardDO.getStatus() == 1) { //已启用可编辑剩余数量和备注
} else if (rewardDO.getStatus() == RewardStatusEnum.ENABLED.getValue()) { //已启用可编辑剩余数量和备注
updateObj.setQuantityRemain(updateReqVO.getQuantityRemain());
updateObj.setRemarkEn(updateReqVO.getRemarkEn());
updateObj.setRemarkFr(updateReqVO.getRemarkFr());
......@@ -117,7 +110,7 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
throw exception(REWARD_NOT_EXISTS);
}
//只有未启用可以删除
if (rewardDO.getStatus() != 2) {
if (rewardDO.getStatus() != RewardStatusEnum.DISABLED.getValue()) {
throw exception(REWARD_STATUS_NOT_ALLOW_DELETE);
}
// 删除
......@@ -166,9 +159,9 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
}
//兑换积分
if (query.getPointsRequireSymbol() != null && query.getPointsRequire() != null) {
lambdaQuery.gt(query.getPointsRequireSymbol() == 1, RewardDO::getPointsRequire, query.getPointsRequire())
.eq(query.getPointsRequireSymbol() == 2, RewardDO::getPointsRequire, query.getPointsRequire())
.lt(query.getPointsRequireSymbol() == 3, RewardDO::getPointsRequire, query.getPointsRequire());
lambdaQuery.gt(query.getPointsRequireSymbol() == QuantitativeRelationSymbolEnum.GT.getValue(), RewardDO::getPointsRequire, query.getPointsRequire())
.eq(query.getPointsRequireSymbol() == QuantitativeRelationSymbolEnum.EQ.getValue(), RewardDO::getPointsRequire, query.getPointsRequire())
.lt(query.getPointsRequireSymbol() == QuantitativeRelationSymbolEnum.LT.getValue(), RewardDO::getPointsRequire, query.getPointsRequire());
}
//兑换网点id,领取方式,状态
lambdaQuery.eqIfPresent(RewardDO::getNodeId, query.getNodeId())
......@@ -186,9 +179,9 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
}
//剩余数量
if (query.getQuantityRemainSymbol() != null && query.getQuantityRemain() != null) {
lambdaQuery.gt(query.getQuantityRemainSymbol() == 1, RewardDO::getQuantityRemain, query.getQuantityRemain())
.eq(query.getQuantityRemainSymbol() == 2, RewardDO::getQuantityRemain, query.getQuantityRemain())
.lt(query.getQuantityRemainSymbol() == 3, RewardDO::getQuantityRemain, query.getQuantityRemain());
lambdaQuery.gt(query.getQuantityRemainSymbol() == QuantitativeRelationSymbolEnum.GT.getValue(), RewardDO::getQuantityRemain, query.getQuantityRemain())
.eq(query.getQuantityRemainSymbol() == QuantitativeRelationSymbolEnum.EQ.getValue(), RewardDO::getQuantityRemain, query.getQuantityRemain())
.lt(query.getQuantityRemainSymbol() == QuantitativeRelationSymbolEnum.LT.getValue(), RewardDO::getQuantityRemain, query.getQuantityRemain());
}
//创建时间
lambdaQuery.betweenIfPresent(RewardDO::getCreateTime, query.getBeginCreateTime(), query.getEndCreateTime())
......@@ -213,7 +206,7 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
//重新生成礼品ID
reward.setCode(generateRewardCode());
//设置为未启用
reward.setStatus(2);
reward.setStatus(RewardStatusEnum.DISABLED.getValue());
reward.setId(null);
reward.setCreateTime(null);
......@@ -235,7 +228,7 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
throw exception(REWARD_NOT_EXISTS);
}
//只允许延期已启用状态礼品
if (reward.getStatus() != 1) {
if (reward.getStatus() != RewardStatusEnum.ENABLED.getValue()) {
throw exception(REWARD_STATUS_NOT_ALLOW_DELAY);
}
Instant now = Instant.now();
......@@ -253,15 +246,17 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
Integer oldStatus = rewardDO.getStatus();
Integer newStatus = statusVO.getStatus();
switch (newStatus) {
case 3://关闭:未启用情况下,不可进行关闭;点击关闭需要有二次弹窗提示;关闭后状态为已关闭,不支持兑换
if (oldStatus == 2) {
//关闭:未启用情况下,不可进行关闭;关闭后状态为已关闭,不支持兑换
case 3:
if (oldStatus == RewardStatusEnum.DISABLED.getValue()) {
throw exception(REWARD_STATUS_NOT_ALLOW_ClOSE);
} else {
rewardMapper.updateById(RewardConvert.INSTANCE.convertStatusReqVO(statusVO));
}
break;
case 1://启用:有效期有效且未启用可进行点击启用,需要有二次确认弹窗
if (oldStatus == 2) {
//启用:有效期有效且未启用可进行点击启用
case 1:
if (oldStatus == RewardStatusEnum.DISABLED.getValue()) {
if (rewardDO.getEndTime().toInstant().isBefore(Instant.now())) {
throw exception(REWARD_STATUS_NOT_ALLOW_ENABLE);
}
......@@ -273,19 +268,23 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
}
}
//生成礼品ID
/**
* 生成礼品ID
*/
private String generateRewardCode() {
return RandomStringUtils.randomAlphanumeric(12).toUpperCase();
}
//校验礼品是否过期并修改礼品状态
//TODO:异步更新礼品状态
/**
* 校验礼品是否过期并修改礼品状态
*/
private void validateExpire(RewardDO rewardDO) {
if (rewardDO.getEndTime() != null){
if (rewardDO.getStatus() == 1 && rewardDO.getEndTime().toInstant().isBefore(Instant.now())) {
//TODO:异步更新礼品状态
if (rewardDO.getEndTime() != null) {
if (rewardDO.getStatus() == RewardStatusEnum.DISABLED.getValue() && rewardDO.getEndTime().toInstant().isBefore(Instant.now())) {
RewardDO expireReward = new RewardDO();
expireReward.setId(rewardDO.getId());
expireReward.setStatus(4);
expireReward.setStatus(RewardStatusEnum.EXPIRED.getValue());
rewardMapper.updateById(expireReward);
}
}
......
......@@ -10,7 +10,6 @@ import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;
import java.util.List;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
......@@ -20,7 +19,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
public class RewardUpdateReqVO {
@ApiModelProperty(value = "", required = true)
@NotNull(message = "不能为空")
@NotNull(message = "id不能为空")
private Long id;
@ApiModelProperty(value = "中文名称")
......@@ -52,7 +51,6 @@ public class RewardUpdateReqVO {
private Integer nodeId;
@ApiModelProperty(value = "剩余数量")
@NotNull(message = "剩余数量不能为空")
@Min(value = 0)
private Integer quantityRemain;
......
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