Commit 8ae8a4a652bc140b78f2a4e7f4f766826de74260
1 parent
e3a700b2
promotion:完善优惠劵模板的单元测试、禁用功能
Showing
11 changed files
with
153 additions
and
26 deletions
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/coupon/CouponTemplateController.java
| ... | ... | @@ -2,10 +2,7 @@ package cn.iocoder.yudao.module.promotion.controller.admin.coupon; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | -import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponTemplateCreateReqVO; | |
| 6 | -import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponTemplatePageReqVO; | |
| 7 | -import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponTemplateRespVO; | |
| 8 | -import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponTemplateUpdateReqVO; | |
| 5 | +import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.*; | |
| 9 | 6 | import cn.iocoder.yudao.module.promotion.convert.coupon.CouponTemplateConvert; |
| 10 | 7 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; |
| 11 | 8 | import cn.iocoder.yudao.module.promotion.service.coupon.CouponTemplateService; |
| ... | ... | @@ -45,6 +42,14 @@ public class CouponTemplateController { |
| 45 | 42 | return success(true); |
| 46 | 43 | } |
| 47 | 44 | |
| 45 | + @PutMapping("/update-status") | |
| 46 | + @ApiOperation("更新优惠劵模板状态") | |
| 47 | + @PreAuthorize("@ss.hasPermission('promotion:coupon-template:update')") | |
| 48 | + public CommonResult<Boolean> updateCouponTemplateStatus(@Valid @RequestBody CouponTemplateUpdateStatusReqVO reqVO) { | |
| 49 | + couponTemplateService.updateCouponTemplateStatus(reqVO.getId(), reqVO.getStatus()); | |
| 50 | + return success(true); | |
| 51 | + } | |
| 52 | + | |
| 48 | 53 | @DeleteMapping("/delete") |
| 49 | 54 | @ApiOperation("删除优惠劵模板") |
| 50 | 55 | @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/coupon/vo/CouponTemplateUpdateStatusReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 4 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | |
| 5 | +import io.swagger.annotations.ApiModel; | |
| 6 | +import io.swagger.annotations.ApiModelProperty; | |
| 7 | +import lombok.Data; | |
| 8 | + | |
| 9 | +import javax.validation.constraints.NotNull; | |
| 10 | + | |
| 11 | +@ApiModel("管理后台 - 优惠劵模板更新状态 Request VO") | |
| 12 | +@Data | |
| 13 | +public class CouponTemplateUpdateStatusReqVO { | |
| 14 | + | |
| 15 | + @ApiModelProperty(value = "优惠劵模板编号", required = true, example = "1024") | |
| 16 | + @NotNull(message = "优惠劵模板编号不能为空") | |
| 17 | + private Long id; | |
| 18 | + | |
| 19 | + @ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 CommonStatusEnum 枚举") | |
| 20 | + @NotNull(message = "状态不能为空") | |
| 21 | + @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") | |
| 22 | + private Integer status; | |
| 23 | + | |
| 24 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateService.java
| ... | ... | @@ -31,6 +31,14 @@ public interface CouponTemplateService { |
| 31 | 31 | void updateCouponTemplate(@Valid CouponTemplateUpdateReqVO updateReqVO); |
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | + * 更新优惠劵模板的状态 | |
| 35 | + * | |
| 36 | + * @param id 编号 | |
| 37 | + * @param status 状态 | |
| 38 | + */ | |
| 39 | + void updateCouponTemplateStatus(Long id, Integer status); | |
| 40 | + | |
| 41 | + /** | |
| 34 | 42 | * 删除优惠劵模板 |
| 35 | 43 | * |
| 36 | 44 | * @param id 编号 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateServiceImpl.java
| ... | ... | @@ -53,6 +53,14 @@ public class CouponTemplateServiceImpl implements CouponTemplateService { |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | @Override |
| 56 | + public void updateCouponTemplateStatus(Long id, Integer status) { | |
| 57 | + // 校验存在 | |
| 58 | + validateCouponTemplateExists(id); | |
| 59 | + // 更新 | |
| 60 | + couponTemplateMapper.updateById(new CouponTemplateDO().setId(id).setStatus(status)); | |
| 61 | + } | |
| 62 | + | |
| 63 | + @Override | |
| 56 | 64 | public void deleteCouponTemplate(Long id) { |
| 57 | 65 | // 校验存在 |
| 58 | 66 | validateCouponTemplateExists(id); | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateServiceImplTest.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.service.coupon; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 5 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 5 | 6 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponTemplateCreateReqVO; |
| ... | ... | @@ -7,13 +8,17 @@ import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponTempla |
| 7 | 8 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponTemplateUpdateReqVO; |
| 8 | 9 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; |
| 9 | 10 | import cn.iocoder.yudao.module.promotion.dal.mysql.coupon.CouponTemplateMapper; |
| 10 | -import org.junit.jupiter.api.Disabled; | |
| 11 | +import cn.iocoder.yudao.module.promotion.enums.common.PromotionDiscountTypeEnum; | |
| 12 | +import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum; | |
| 13 | +import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTemplateValidityTypeEnum; | |
| 11 | 14 | import org.junit.jupiter.api.Test; |
| 12 | 15 | import org.springframework.context.annotation.Import; |
| 13 | 16 | |
| 14 | 17 | import javax.annotation.Resource; |
| 15 | 18 | import java.util.Date; |
| 16 | 19 | |
| 20 | +import static cn.hutool.core.util.RandomUtil.randomEle; | |
| 21 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime; | |
| 17 | 22 | import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; |
| 18 | 23 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| 19 | 24 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; |
| ... | ... | @@ -39,7 +44,10 @@ public class CouponTemplateServiceImplTest extends BaseDbUnitTest { |
| 39 | 44 | @Test |
| 40 | 45 | public void testCreateCouponTemplate_success() { |
| 41 | 46 | // 准备参数 |
| 42 | - CouponTemplateCreateReqVO reqVO = randomPojo(CouponTemplateCreateReqVO.class); | |
| 47 | + CouponTemplateCreateReqVO reqVO = randomPojo(CouponTemplateCreateReqVO.class, | |
| 48 | + o -> o.setProductScope(randomEle(PromotionProductScopeEnum.values()).getScope()) | |
| 49 | + .setValidityType(randomEle(CouponTemplateValidityTypeEnum.values()).getType()) | |
| 50 | + .setDiscountType(randomEle(PromotionDiscountTypeEnum.values()).getType())); | |
| 43 | 51 | |
| 44 | 52 | // 调用 |
| 45 | 53 | Long couponTemplateId = couponTemplateService.createCouponTemplate(reqVO); |
| ... | ... | @@ -58,6 +66,10 @@ public class CouponTemplateServiceImplTest extends BaseDbUnitTest { |
| 58 | 66 | // 准备参数 |
| 59 | 67 | CouponTemplateUpdateReqVO reqVO = randomPojo(CouponTemplateUpdateReqVO.class, o -> { |
| 60 | 68 | o.setId(dbCouponTemplate.getId()); // 设置更新的 ID |
| 69 | + // 其它通用字段 | |
| 70 | + o.setProductScope(randomEle(PromotionProductScopeEnum.values()).getScope()) | |
| 71 | + .setValidityType(randomEle(CouponTemplateValidityTypeEnum.values()).getType()) | |
| 72 | + .setDiscountType(randomEle(PromotionDiscountTypeEnum.values()).getType()); | |
| 61 | 73 | }); |
| 62 | 74 | |
| 63 | 75 | // 调用 |
| ... | ... | @@ -100,30 +112,29 @@ public class CouponTemplateServiceImplTest extends BaseDbUnitTest { |
| 100 | 112 | } |
| 101 | 113 | |
| 102 | 114 | @Test |
| 103 | - @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | |
| 104 | 115 | public void testGetCouponTemplatePage() { |
| 105 | 116 | // mock 数据 |
| 106 | 117 | CouponTemplateDO dbCouponTemplate = randomPojo(CouponTemplateDO.class, o -> { // 等会查询到 |
| 107 | - o.setName(null); | |
| 108 | - o.setStatus(null); | |
| 109 | - o.setDiscountType(null); | |
| 110 | - o.setCreateTime(null); | |
| 118 | + o.setName("芋艿"); | |
| 119 | + o.setStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 120 | + o.setDiscountType(PromotionDiscountTypeEnum.PERCENT.getType()); | |
| 121 | + o.setCreateTime(buildTime(2022, 2, 2)); | |
| 111 | 122 | }); |
| 112 | 123 | couponTemplateMapper.insert(dbCouponTemplate); |
| 113 | 124 | // 测试 name 不匹配 |
| 114 | - couponTemplateMapper.insert(cloneIgnoreId(dbCouponTemplate, o -> o.setName(null))); | |
| 125 | + couponTemplateMapper.insert(cloneIgnoreId(dbCouponTemplate, o -> o.setName("土豆"))); | |
| 115 | 126 | // 测试 status 不匹配 |
| 116 | - couponTemplateMapper.insert(cloneIgnoreId(dbCouponTemplate, o -> o.setStatus(null))); | |
| 127 | + couponTemplateMapper.insert(cloneIgnoreId(dbCouponTemplate, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); | |
| 117 | 128 | // 测试 type 不匹配 |
| 118 | - couponTemplateMapper.insert(cloneIgnoreId(dbCouponTemplate, o -> o.setDiscountType(null))); | |
| 129 | + couponTemplateMapper.insert(cloneIgnoreId(dbCouponTemplate, o -> o.setDiscountType(PromotionDiscountTypeEnum.PRICE.getType()))); | |
| 119 | 130 | // 测试 createTime 不匹配 |
| 120 | - couponTemplateMapper.insert(cloneIgnoreId(dbCouponTemplate, o -> o.setCreateTime(null))); | |
| 131 | + couponTemplateMapper.insert(cloneIgnoreId(dbCouponTemplate, o -> o.setCreateTime(buildTime(2022, 1, 1)))); | |
| 121 | 132 | // 准备参数 |
| 122 | 133 | CouponTemplatePageReqVO reqVO = new CouponTemplatePageReqVO(); |
| 123 | - reqVO.setName(null); | |
| 124 | - reqVO.setStatus(null); | |
| 125 | - reqVO.setDiscountType(null); | |
| 126 | - reqVO.setCreateTime((new Date[]{})); | |
| 134 | + reqVO.setName("芋艿"); | |
| 135 | + reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 136 | + reqVO.setDiscountType(PromotionDiscountTypeEnum.PERCENT.getType()); | |
| 137 | + reqVO.setCreateTime((new Date[]{buildTime(2022, 2, 1), buildTime(2022, 2, 3)})); | |
| 127 | 138 | |
| 128 | 139 | // 调用 |
| 129 | 140 | PageResult<CouponTemplateDO> pageResult = couponTemplateService.getCouponTemplatePage(reqVO); | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/test/resources/sql/clean.sql
yudao-module-mall/yudao-module-promotion-biz/src/test/resources/sql/create_tables.sql
| ... | ... | @@ -16,4 +16,33 @@ CREATE TABLE IF NOT EXISTS "market_activity" ( |
| 16 | 16 | "deleted" bit NOT NULL DEFAULT FALSE, |
| 17 | 17 | "tenant_id" bigint(20) NOT NULL, |
| 18 | 18 | PRIMARY KEY ("id") |
| 19 | - ) COMMENT '促销活动'; | |
| 20 | 19 | \ No newline at end of file |
| 20 | + ) COMMENT '促销活动'; | |
| 21 | + | |
| 22 | +CREATE TABLE IF NOT EXISTS "promotion_coupon_template" ( | |
| 23 | + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 24 | + "name" varchar NOT NULL, | |
| 25 | + "status" int NOT NULL, | |
| 26 | + "total_count" int NOT NULL, | |
| 27 | + "take_limit_count" int NOT NULL, | |
| 28 | + "take_type" int NOT NULL, | |
| 29 | + "use_price" int NOT NULL, | |
| 30 | + "product_scope" int NOT NULL, | |
| 31 | + "product_spu_ids" varchar, | |
| 32 | + "validity_type" int NOT NULL, | |
| 33 | + "valid_start_time" datetime, | |
| 34 | + "valid_end_time" datetime, | |
| 35 | + "fixed_start_term" int, | |
| 36 | + "fixed_end_term" int, | |
| 37 | + "discount_type" int NOT NULL, | |
| 38 | + "discount_percent" int, | |
| 39 | + "discount_price" int, | |
| 40 | + "discount_limit_price" int, | |
| 41 | + "take_count" int NOT NULL DEFAULT 0, | |
| 42 | + "use_count" int NOT NULL DEFAULT 0, | |
| 43 | + "creator" varchar DEFAULT '', | |
| 44 | + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 45 | + "updater" varchar DEFAULT '', | |
| 46 | + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | |
| 47 | + "deleted" bit NOT NULL DEFAULT FALSE, | |
| 48 | + PRIMARY KEY ("id") | |
| 49 | +) COMMENT '优惠劵模板'; | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleUpdateStatusReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.system.controller.admin.permission.vo.role; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 4 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | |
| 3 | 5 | import io.swagger.annotations.ApiModel; |
| 4 | 6 | import io.swagger.annotations.ApiModelProperty; |
| 5 | 7 | import lombok.Data; |
| ... | ... | @@ -16,7 +18,7 @@ public class RoleUpdateStatusReqVO { |
| 16 | 18 | |
| 17 | 19 | @ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 CommonStatusEnum 枚举") |
| 18 | 20 | @NotNull(message = "状态不能为空") |
| 19 | -// @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") | |
| 21 | + @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") | |
| 20 | 22 | private Integer status; |
| 21 | 23 | |
| 22 | 24 | } | ... | ... |
yudao-ui-admin/src/api/mall/promotion/couponTemplate.js
| ... | ... | @@ -18,6 +18,19 @@ export function updateCouponTemplate(data) { |
| 18 | 18 | }) |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | +// 更新优惠劵模板的状态 | |
| 22 | +export function updateCouponTemplateStatus(id, status) { | |
| 23 | + const data = { | |
| 24 | + id, | |
| 25 | + status | |
| 26 | + } | |
| 27 | + return request({ | |
| 28 | + url: '/promotion/coupon-template/update-status', | |
| 29 | + method: 'put', | |
| 30 | + data: data | |
| 31 | + }) | |
| 32 | +} | |
| 33 | + | |
| 21 | 34 | // 删除优惠劵模板 |
| 22 | 35 | export function deleteCouponTemplate(id) { |
| 23 | 36 | return request({ | ... | ... |
yudao-ui-admin/src/views/mall/promotion/couponTemplate/index.vue
| ... | ... | @@ -52,7 +52,7 @@ |
| 52 | 52 | <el-table-column label="有效期限" align="center" prop="validityType" width="180" :formatter="validityTypeFormat" /> |
| 53 | 53 | <el-table-column label="状态" align="center" prop="status"> |
| 54 | 54 | <template slot-scope="scope"> |
| 55 | - <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" /> | |
| 55 | + <el-switch v-model="scope.row.status" :active-value="0" :inactive-value="1" @change="handleStatusChange(scope.row)"/> | |
| 56 | 56 | </template> |
| 57 | 57 | </el-table-column> |
| 58 | 58 | <el-table-column label="创建时间" align="center" prop="createTime" width="180"> |
| ... | ... | @@ -156,10 +156,23 @@ |
| 156 | 156 | </template> |
| 157 | 157 | |
| 158 | 158 | <script> |
| 159 | -import { createCouponTemplate, updateCouponTemplate, deleteCouponTemplate, getCouponTemplate, getCouponTemplatePage } from "@/api/mall/promotion/couponTemplate"; | |
| 160 | -import { CouponTemplateValidityTypeEnum, PromotionDiscountTypeEnum, PromotionProductScopeEnum} from "@/utils/constants"; | |
| 159 | +import { | |
| 160 | + createCouponTemplate, | |
| 161 | + updateCouponTemplate, | |
| 162 | + deleteCouponTemplate, | |
| 163 | + getCouponTemplate, | |
| 164 | + getCouponTemplatePage, | |
| 165 | + updateCouponTemplateStatus | |
| 166 | +} from "@/api/mall/promotion/couponTemplate"; | |
| 167 | +import { | |
| 168 | + CommonStatusEnum, | |
| 169 | + CouponTemplateValidityTypeEnum, | |
| 170 | + PromotionDiscountTypeEnum, | |
| 171 | + PromotionProductScopeEnum | |
| 172 | +} from "@/utils/constants"; | |
| 161 | 173 | import { getSpuSimpleList } from "@/api/mall/product/spu"; |
| 162 | 174 | import { parseTime } from "@/utils/ruoyi"; |
| 175 | +import {changeRoleStatus} from "@/api/system/role"; | |
| 163 | 176 | |
| 164 | 177 | export default { |
| 165 | 178 | name: "CouponTemplate", |
| ... | ... | @@ -331,6 +344,20 @@ export default { |
| 331 | 344 | }); |
| 332 | 345 | }); |
| 333 | 346 | }, |
| 347 | + /** 优惠劵模板状态修改 */ | |
| 348 | + handleStatusChange(row) { | |
| 349 | + // 此时,row 已经变成目标状态了,所以可以直接提交请求和提示 | |
| 350 | + let text = row.status === CommonStatusEnum.ENABLE ? "启用" : "停用"; | |
| 351 | + this.$modal.confirm('确认要"' + text + '""' + row.name + '"优惠劵吗?').then(function() { | |
| 352 | + return updateCouponTemplateStatus(row.id, row.status); | |
| 353 | + }).then(() => { | |
| 354 | + this.$modal.msgSuccess(text + "成功"); | |
| 355 | + }).catch(function() { | |
| 356 | + // 异常时,需要将 row.status 状态重置回之前的 | |
| 357 | + row.status = row.status === CommonStatusEnum.ENABLE ? CommonStatusEnum.DISABLE | |
| 358 | + : CommonStatusEnum.ENABLE; | |
| 359 | + }); | |
| 360 | + }, | |
| 334 | 361 | /** 删除按钮操作 */ |
| 335 | 362 | handleDelete(row) { |
| 336 | 363 | const id = row.id; | ... | ... |
yudao-ui-admin/src/views/system/role/index.vue
| ... | ... | @@ -50,7 +50,7 @@ |
| 50 | 50 | <el-table-column label="显示顺序" prop="sort" width="100" /> |
| 51 | 51 | <el-table-column label="状态" align="center" width="100"> |
| 52 | 52 | <template slot-scope="scope"> |
| 53 | - <el-switch v-model="scope.row.status" :active-value="0" :inactive-value="1" @change="handleStatusChange(scope.row)"></el-switch> | |
| 53 | + <el-switch v-model="scope.row.status" :active-value="0" :inactive-value="1" @change="handleStatusChange(scope.row)"/> | |
| 54 | 54 | </template> |
| 55 | 55 | </el-table-column> |
| 56 | 56 | <el-table-column label="创建时间" align="center" prop="createTime" width="180"> |
| ... | ... | @@ -167,7 +167,6 @@ |
| 167 | 167 | import { |
| 168 | 168 | addRole, |
| 169 | 169 | changeRoleStatus, |
| 170 | - dataScope, | |
| 171 | 170 | delRole, |
| 172 | 171 | exportRole, |
| 173 | 172 | getRole, | ... | ... |