mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-26 09:11:52 +08:00
【代码优化】商城: 满减送活动
This commit is contained in:
parent
81e3866665
commit
fdaf5e50ca
@ -2,23 +2,22 @@ package cn.iocoder.yudao.module.promotion.controller.admin.reward;
|
|||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityCreateReqVO;
|
import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityCreateReqVO;
|
||||||
import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityPageReqVO;
|
import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityPageReqVO;
|
||||||
import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityRespVO;
|
import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityRespVO;
|
||||||
import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityUpdateReqVO;
|
import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityUpdateReqVO;
|
||||||
import cn.iocoder.yudao.module.promotion.convert.reward.RewardActivityConvert;
|
|
||||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO;
|
import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO;
|
||||||
import cn.iocoder.yudao.module.promotion.service.reward.RewardActivityService;
|
import cn.iocoder.yudao.module.promotion.service.reward.RewardActivityService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import jakarta.validation.Valid;
|
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
@Tag(name = "管理后台 - 满减送活动")
|
@Tag(name = "管理后台 - 满减送活动")
|
||||||
@ -69,7 +68,7 @@ public class RewardActivityController {
|
|||||||
@PreAuthorize("@ss.hasPermission('promotion:reward-activity:query')")
|
@PreAuthorize("@ss.hasPermission('promotion:reward-activity:query')")
|
||||||
public CommonResult<RewardActivityRespVO> getRewardActivity(@RequestParam("id") Long id) {
|
public CommonResult<RewardActivityRespVO> getRewardActivity(@RequestParam("id") Long id) {
|
||||||
RewardActivityDO rewardActivity = rewardActivityService.getRewardActivity(id);
|
RewardActivityDO rewardActivity = rewardActivityService.getRewardActivity(id);
|
||||||
return success(RewardActivityConvert.INSTANCE.convert(rewardActivity));
|
return success(BeanUtils.toBean(rewardActivity, RewardActivityRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/page")
|
@GetMapping("/page")
|
||||||
@ -77,7 +76,7 @@ public class RewardActivityController {
|
|||||||
@PreAuthorize("@ss.hasPermission('promotion:reward-activity:query')")
|
@PreAuthorize("@ss.hasPermission('promotion:reward-activity:query')")
|
||||||
public CommonResult<PageResult<RewardActivityRespVO>> getRewardActivityPage(@Valid RewardActivityPageReqVO pageVO) {
|
public CommonResult<PageResult<RewardActivityRespVO>> getRewardActivityPage(@Valid RewardActivityPageReqVO pageVO) {
|
||||||
PageResult<RewardActivityDO> pageResult = rewardActivityService.getRewardActivityPage(pageVO);
|
PageResult<RewardActivityDO> pageResult = rewardActivityService.getRewardActivityPage(pageVO);
|
||||||
return success(RewardActivityConvert.INSTANCE.convertPage(pageResult));
|
return success(BeanUtils.toBean(pageResult, RewardActivityRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -79,13 +79,13 @@ public class RewardActivityBaseVO {
|
|||||||
@Schema(description = "赠送的积分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
|
@Schema(description = "赠送的积分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
|
||||||
private Integer point;
|
private Integer point;
|
||||||
|
|
||||||
@Schema(description = "赠送的优惠劵编号的数组", example = "1,2,3")
|
@Schema(description = "赠送的优惠劵编号的数组")
|
||||||
private Map<Long, Integer> giveCouponsMap;
|
private Map<Long, Integer> giveCoupons;
|
||||||
|
|
||||||
@AssertTrue(message = "赠送的积分不能小于 1")
|
@AssertTrue(message = "赠送的积分不能小于 0")
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public boolean isPointValid() {
|
public boolean isPointValid() {
|
||||||
return point == null || point >= 1;
|
return point == null || point >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
package cn.iocoder.yudao.module.promotion.convert.reward;
|
package cn.iocoder.yudao.module.promotion.convert.reward;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
||||||
import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityCreateReqVO;
|
|
||||||
import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityRespVO;
|
|
||||||
import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityUpdateReqVO;
|
|
||||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO;
|
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.factory.Mappers;
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
@ -18,12 +13,4 @@ public interface RewardActivityConvert {
|
|||||||
|
|
||||||
RewardActivityConvert INSTANCE = Mappers.getMapper(RewardActivityConvert.class);
|
RewardActivityConvert INSTANCE = Mappers.getMapper(RewardActivityConvert.class);
|
||||||
|
|
||||||
RewardActivityDO convert(RewardActivityCreateReqVO bean);
|
|
||||||
|
|
||||||
RewardActivityDO convert(RewardActivityUpdateReqVO bean);
|
|
||||||
|
|
||||||
RewardActivityRespVO convert(RewardActivityDO bean);
|
|
||||||
|
|
||||||
PageResult<RewardActivityRespVO> convertPage(PageResult<RewardActivityDO> page);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -107,9 +107,9 @@ public class RewardActivityDO extends BaseDO {
|
|||||||
/**
|
/**
|
||||||
* 赠送的优惠劵
|
* 赠送的优惠劵
|
||||||
*
|
*
|
||||||
* key: 优惠劵编号,value:对应的优惠券数量
|
* key: 优惠劵模版编号,value:对应的数量
|
||||||
*/
|
*/
|
||||||
private Map<Long, Integer> giveCouponsMap;
|
private Map<Long, Integer> giveCoupons;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,6 @@ import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivi
|
|||||||
import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityCreateReqVO;
|
import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityCreateReqVO;
|
||||||
import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityPageReqVO;
|
import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityPageReqVO;
|
||||||
import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityUpdateReqVO;
|
import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityUpdateReqVO;
|
||||||
import cn.iocoder.yudao.module.promotion.convert.reward.RewardActivityConvert;
|
|
||||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO;
|
import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO;
|
||||||
import cn.iocoder.yudao.module.promotion.dal.mysql.reward.RewardActivityMapper;
|
import cn.iocoder.yudao.module.promotion.dal.mysql.reward.RewardActivityMapper;
|
||||||
import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum;
|
import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum;
|
||||||
@ -54,7 +53,7 @@ public class RewardActivityServiceImpl implements RewardActivityService {
|
|||||||
validateRewardActivitySpuConflicts(null, createReqVO);
|
validateRewardActivitySpuConflicts(null, createReqVO);
|
||||||
|
|
||||||
// 2. 插入
|
// 2. 插入
|
||||||
RewardActivityDO rewardActivity = RewardActivityConvert.INSTANCE.convert(createReqVO)
|
RewardActivityDO rewardActivity = BeanUtils.toBean(createReqVO, RewardActivityDO.class)
|
||||||
.setStatus(PromotionUtils.calculateActivityStatus(createReqVO.getEndTime()));
|
.setStatus(PromotionUtils.calculateActivityStatus(createReqVO.getEndTime()));
|
||||||
rewardActivityMapper.insert(rewardActivity);
|
rewardActivityMapper.insert(rewardActivity);
|
||||||
// 返回
|
// 返回
|
||||||
@ -74,7 +73,7 @@ public class RewardActivityServiceImpl implements RewardActivityService {
|
|||||||
validateRewardActivitySpuConflicts(updateReqVO.getId(), updateReqVO);
|
validateRewardActivitySpuConflicts(updateReqVO.getId(), updateReqVO);
|
||||||
|
|
||||||
// 2. 更新
|
// 2. 更新
|
||||||
RewardActivityDO updateObj = RewardActivityConvert.INSTANCE.convert(updateReqVO)
|
RewardActivityDO updateObj = BeanUtils.toBean(updateReqVO, RewardActivityDO.class)
|
||||||
.setStatus(PromotionUtils.calculateActivityStatus(updateReqVO.getEndTime()));
|
.setStatus(PromotionUtils.calculateActivityStatus(updateReqVO.getEndTime()));
|
||||||
rewardActivityMapper.updateById(updateObj);
|
rewardActivityMapper.updateById(updateObj);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user