Commit 52e735f36031a2ef237b6017dc83bf3214a840a4
Merge branch 'feature/mall_product' of https://gitee.com/zhijiantianya/ruoyi-vue-pro
# Conflicts: # yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/coupon/CouponTemplateApiImpl.java
Showing
31 changed files
with
146 additions
and
282 deletions
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/enums/CommonStatusEnum.java
| 1 | 1 | package cn.iocoder.yudao.framework.common.enums; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.util.ObjUtil; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.core.IntArrayValuable; |
| 4 | 5 | import lombok.AllArgsConstructor; |
| 5 | 6 | import lombok.Getter; |
| ... | ... | @@ -34,4 +35,12 @@ public enum CommonStatusEnum implements IntArrayValuable { |
| 34 | 35 | return ARRAYS; |
| 35 | 36 | } |
| 36 | 37 | |
| 38 | + public static boolean isEnable(Integer status) { | |
| 39 | + return ObjUtil.equal(ENABLE.status, status); | |
| 40 | + } | |
| 41 | + | |
| 42 | + public static boolean isDisable(Integer status) { | |
| 43 | + return ObjUtil.equal(DISABLE.status, status); | |
| 44 | + } | |
| 45 | + | |
| 37 | 46 | } | ... | ... |
yudao-module-mall/yudao-module-product-biz/pom.xml
| ... | ... | @@ -28,11 +28,6 @@ |
| 28 | 28 | <artifactId>yudao-module-member-api</artifactId> |
| 29 | 29 | <version>${revision}</version> |
| 30 | 30 | </dependency> |
| 31 | - <dependency> | |
| 32 | - <groupId>cn.iocoder.boot</groupId> | |
| 33 | - <artifactId>yudao-module-promotion-api</artifactId> | |
| 34 | - <version>${revision}</version> | |
| 35 | - </dependency> | |
| 36 | 31 | |
| 37 | 32 | <!-- 业务组件 --> |
| 38 | 33 | <dependency> | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/ProductSpuController.java
| ... | ... | @@ -11,8 +11,6 @@ import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; |
| 11 | 11 | import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum; |
| 12 | 12 | import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; |
| 13 | 13 | import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; |
| 14 | -import cn.iocoder.yudao.module.promotion.api.coupon.CouponTemplateApi; | |
| 15 | -import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponTemplateRespDTO; | |
| 16 | 14 | import io.swagger.v3.oas.annotations.Operation; |
| 17 | 15 | import io.swagger.v3.oas.annotations.Parameter; |
| 18 | 16 | import io.swagger.v3.oas.annotations.tags.Tag; |
| ... | ... | @@ -45,9 +43,6 @@ public class ProductSpuController { |
| 45 | 43 | @Resource |
| 46 | 44 | private ProductSkuService productSkuService; |
| 47 | 45 | |
| 48 | - @Resource | |
| 49 | - private CouponTemplateApi couponTemplateApi; | |
| 50 | - | |
| 51 | 46 | @PostMapping("/create") |
| 52 | 47 | @Operation(summary = "创建商品 SPU") |
| 53 | 48 | @PreAuthorize("@ss.hasPermission('product:spu:create')") |
| ... | ... | @@ -92,11 +87,7 @@ public class ProductSpuController { |
| 92 | 87 | } |
| 93 | 88 | // 查询商品 SKU |
| 94 | 89 | List<ProductSkuDO> skus = productSkuService.getSkuListBySpuId(spu.getId()); |
| 95 | - // 查询优惠卷 | |
| 96 | - // TODO @puhui999:优惠劵的信息,要不交给前端读取?主要是为了避免商品依赖 promotion 模块哈; | |
| 97 | - List<CouponTemplateRespDTO> couponTemplateList = couponTemplateApi.getCouponTemplateListByIds( | |
| 98 | - spu.getGiveCouponTemplateIds()); | |
| 99 | - return success(ProductSpuConvert.INSTANCE.convertForSpuDetailRespVO(spu, skus, couponTemplateList)); | |
| 90 | + return success(ProductSpuConvert.INSTANCE.convertForSpuDetailRespVO(spu, skus)); | |
| 100 | 91 | } |
| 101 | 92 | |
| 102 | 93 | @GetMapping("/list-all-simple") | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuBaseVO.java
| ... | ... | @@ -96,9 +96,6 @@ public class ProductSpuBaseVO { |
| 96 | 96 | @NotNull(message = "商品赠送积分不能为空") |
| 97 | 97 | private Integer giveIntegral; |
| 98 | 98 | |
| 99 | - @Schema(description = "赠送的优惠劵数组包含优惠券编号和名称") | |
| 100 | - private List<GiveCouponTemplate> giveCouponTemplates; | |
| 101 | - | |
| 102 | 99 | @Schema(description = "分销类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") |
| 103 | 100 | @NotNull(message = "商品分销类型不能为空") |
| 104 | 101 | private Boolean subCommissionType; |
| ... | ... | @@ -111,16 +108,4 @@ public class ProductSpuBaseVO { |
| 111 | 108 | @Schema(description = "虚拟销量", example = "66") |
| 112 | 109 | private Integer virtualSalesCount; |
| 113 | 110 | |
| 114 | - @Schema(description = "管理后台 - 商品 SPU 赠送的优惠卷") | |
| 115 | - @Data | |
| 116 | - public static class GiveCouponTemplate { | |
| 117 | - | |
| 118 | - @Schema(description = "模板编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 119 | - private Long id; | |
| 120 | - | |
| 121 | - @Schema(description = "优惠劵名", requiredMode = Schema.RequiredMode.REQUIRED, example = "春节送送送") | |
| 122 | - private String name; | |
| 123 | - | |
| 124 | - } | |
| 125 | - | |
| 126 | 111 | } | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java
| ... | ... | @@ -12,7 +12,6 @@ import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; |
| 12 | 12 | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; |
| 13 | 13 | import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; |
| 14 | 14 | import cn.iocoder.yudao.module.product.enums.DictTypeConstants; |
| 15 | -import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponTemplateRespDTO; | |
| 16 | 15 | import org.mapstruct.Mapper; |
| 17 | 16 | import org.mapstruct.Mapping; |
| 18 | 17 | import org.mapstruct.Named; |
| ... | ... | @@ -101,14 +100,8 @@ public interface ProductSpuConvert { |
| 101 | 100 | |
| 102 | 101 | List<AppProductSpuDetailRespVO.Sku> convertListForGetSpuDetail(List<ProductSkuDO> skus); |
| 103 | 102 | |
| 104 | - List<ProductSpuDetailRespVO.GiveCouponTemplate> convertList04(List<CouponTemplateRespDTO> couponTemplateList); | |
| 105 | - | |
| 106 | - default ProductSpuDetailRespVO convertForSpuDetailRespVO(ProductSpuDO spu, List<ProductSkuDO> skus, | |
| 107 | - List<CouponTemplateRespDTO> couponTemplateList) { | |
| 108 | - ProductSpuDetailRespVO respVO = convert03(spu); | |
| 109 | - respVO.setSkus(ProductSkuConvert.INSTANCE.convertList(skus)); | |
| 110 | - respVO.setGiveCouponTemplates(convertList04(couponTemplateList)); | |
| 111 | - return respVO; | |
| 103 | + default ProductSpuDetailRespVO convertForSpuDetailRespVO(ProductSpuDO spu, List<ProductSkuDO> skus) { | |
| 104 | + return convert03(spu).setSkus(ProductSkuConvert.INSTANCE.convertList(skus)); | |
| 112 | 105 | } |
| 113 | 106 | |
| 114 | 107 | default List<ProductSpuDetailRespVO> convertForSpuDetailRespListVO(List<ProductSpuDO> spus, List<ProductSkuDO> skus) { | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java
| ... | ... | @@ -17,9 +17,6 @@ import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum; |
| 17 | 17 | import cn.iocoder.yudao.module.product.service.brand.ProductBrandService; |
| 18 | 18 | import cn.iocoder.yudao.module.product.service.category.ProductCategoryService; |
| 19 | 19 | import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; |
| 20 | -import cn.iocoder.yudao.module.promotion.api.coupon.CouponTemplateApi; | |
| 21 | -import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponTemplateRespDTO; | |
| 22 | -import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; | |
| 23 | 20 | import com.google.common.collect.Maps; |
| 24 | 21 | import org.springframework.context.annotation.Lazy; |
| 25 | 22 | import org.springframework.stereotype.Service; |
| ... | ... | @@ -28,10 +25,10 @@ import org.springframework.validation.annotation.Validated; |
| 28 | 25 | |
| 29 | 26 | import javax.annotation.Resource; |
| 30 | 27 | import java.util.*; |
| 31 | -import java.util.stream.Collectors; | |
| 32 | 28 | |
| 33 | 29 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 34 | -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; | |
| 30 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getMinValue; | |
| 31 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue; | |
| 35 | 32 | import static cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO.CATEGORY_LEVEL; |
| 36 | 33 | import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; |
| 37 | 34 | |
| ... | ... | @@ -55,19 +52,12 @@ public class ProductSpuServiceImpl implements ProductSpuService { |
| 55 | 52 | @Resource |
| 56 | 53 | private ProductCategoryService categoryService; |
| 57 | 54 | |
| 58 | - @Resource | |
| 59 | - @Lazy | |
| 60 | - private CouponTemplateApi couponTemplateApi; | |
| 61 | - | |
| 62 | 55 | @Override |
| 63 | 56 | @Transactional(rollbackFor = Exception.class) |
| 64 | 57 | public Long createSpu(ProductSpuCreateReqVO createReqVO) { |
| 65 | 58 | // 校验分类、品牌 |
| 66 | 59 | validateCategory(createReqVO.getCategoryId()); |
| 67 | 60 | brandService.validateProductBrand(createReqVO.getBrandId()); |
| 68 | - // 校验优惠券 | |
| 69 | - Set<Long> giveCouponTemplateIds = convertSet(createReqVO.getGiveCouponTemplates(), ProductSpuCreateReqVO.GiveCouponTemplate::getId); | |
| 70 | - validateCouponTemplate(giveCouponTemplateIds); | |
| 71 | 61 | // 校验 SKU |
| 72 | 62 | List<ProductSkuCreateOrUpdateReqVO> skuSaveReqList = createReqVO.getSkus(); |
| 73 | 63 | productSkuService.validateSkuList(skuSaveReqList, createReqVO.getSpecType()); |
| ... | ... | @@ -75,8 +65,6 @@ public class ProductSpuServiceImpl implements ProductSpuService { |
| 75 | 65 | ProductSpuDO spu = ProductSpuConvert.INSTANCE.convert(createReqVO); |
| 76 | 66 | // 初始化 SPU 中 SKU 相关属性 |
| 77 | 67 | initSpuFromSkus(spu, skuSaveReqList); |
| 78 | - // 设置优惠券 | |
| 79 | - spu.setGiveCouponTemplateIds(CollUtil.newArrayList(giveCouponTemplateIds)); | |
| 80 | 68 | // 插入 SPU |
| 81 | 69 | productSpuMapper.insert(spu); |
| 82 | 70 | // 插入 SKU |
| ... | ... | @@ -93,9 +81,6 @@ public class ProductSpuServiceImpl implements ProductSpuService { |
| 93 | 81 | // 校验分类、品牌 |
| 94 | 82 | validateCategory(updateReqVO.getCategoryId()); |
| 95 | 83 | brandService.validateProductBrand(updateReqVO.getBrandId()); |
| 96 | - // 校验优惠券 | |
| 97 | - Set<Long> giveCouponTemplateIds = convertSet(updateReqVO.getGiveCouponTemplates(), ProductSpuUpdateReqVO.GiveCouponTemplate::getId); | |
| 98 | - validateCouponTemplate(giveCouponTemplateIds); | |
| 99 | 84 | // 校验SKU |
| 100 | 85 | List<ProductSkuCreateOrUpdateReqVO> skuSaveReqList = updateReqVO.getSkus(); |
| 101 | 86 | productSkuService.validateSkuList(skuSaveReqList, updateReqVO.getSpecType()); |
| ... | ... | @@ -103,8 +88,6 @@ public class ProductSpuServiceImpl implements ProductSpuService { |
| 103 | 88 | // 更新 SPU |
| 104 | 89 | ProductSpuDO updateObj = ProductSpuConvert.INSTANCE.convert(updateReqVO); |
| 105 | 90 | initSpuFromSkus(updateObj, skuSaveReqList); |
| 106 | - // 设置优惠券 | |
| 107 | - updateObj.setGiveCouponTemplateIds(CollUtil.newArrayList(giveCouponTemplateIds)); | |
| 108 | 91 | productSpuMapper.updateById(updateObj); |
| 109 | 92 | // 批量更新 SKU |
| 110 | 93 | productSkuService.updateSkuList(updateObj.getId(), updateReqVO.getSkus()); |
| ... | ... | @@ -138,10 +121,6 @@ public class ProductSpuServiceImpl implements ProductSpuService { |
| 138 | 121 | // 默认商品浏览量 |
| 139 | 122 | spu.setBrowseCount(0); |
| 140 | 123 | } |
| 141 | - // 如果活动顺序为空则默认初始化 | |
| 142 | - if (CollUtil.isEmpty(spu.getActivityOrders())) { | |
| 143 | - spu.setActivityOrders(Arrays.stream(PromotionTypeEnum.ARRAYS).boxed().collect(Collectors.toList())); | |
| 144 | - } | |
| 145 | 124 | } |
| 146 | 125 | |
| 147 | 126 | /** |
| ... | ... | @@ -157,13 +136,6 @@ public class ProductSpuServiceImpl implements ProductSpuService { |
| 157 | 136 | } |
| 158 | 137 | } |
| 159 | 138 | |
| 160 | - private void validateCouponTemplate(Collection<Long> ids) { | |
| 161 | - List<CouponTemplateRespDTO> couponTemplateList = couponTemplateApi.getCouponTemplateListByIds(ids); | |
| 162 | - if (couponTemplateList.size() != ids.size()) { | |
| 163 | - throw exception(SPU_SAVE_FAIL_COUPON_TEMPLATE_NOT_EXISTS); | |
| 164 | - } | |
| 165 | - } | |
| 166 | - | |
| 167 | 139 | @Override |
| 168 | 140 | public List<ProductSpuDO> validateSpuList(Collection<Long> ids) { |
| 169 | 141 | if (CollUtil.isEmpty(ids)) { | ... | ... |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/coupon/CouponTemplateApi.java deleted
| 1 | -package cn.iocoder.yudao.module.promotion.api.coupon; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponTemplateRespDTO; | |
| 4 | - | |
| 5 | -import java.util.Collection; | |
| 6 | -import java.util.List; | |
| 7 | - | |
| 8 | -/** | |
| 9 | - * 优惠劵模版 API 接口 | |
| 10 | - * | |
| 11 | - * @author HUIHUI | |
| 12 | - */ | |
| 13 | -public interface CouponTemplateApi { | |
| 14 | - | |
| 15 | - /** | |
| 16 | - * 获得优惠券模版的精简信息列表 | |
| 17 | - * | |
| 18 | - * @param ids 优惠券模版编号 | |
| 19 | - * @return 优惠券模版的精简信息列表 | |
| 20 | - */ | |
| 21 | - List<CouponTemplateRespDTO> getCouponTemplateListByIds(Collection<Long> ids); | |
| 22 | - | |
| 23 | -} |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/coupon/dto/CouponTemplateRespDTO.java deleted
| 1 | -package cn.iocoder.yudao.module.promotion.api.coupon.dto; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 4 | -import lombok.Data; | |
| 5 | - | |
| 6 | -/** | |
| 7 | - * 优惠券模版 Response DTO | |
| 8 | - * | |
| 9 | - * @author HUIHUI | |
| 10 | - */ | |
| 11 | -@Data | |
| 12 | -public class CouponTemplateRespDTO { | |
| 13 | - /** | |
| 14 | - * 模板编号,自增唯一 | |
| 15 | - */ | |
| 16 | - | |
| 17 | - private Long id; | |
| 18 | - /** | |
| 19 | - * 优惠劵名 | |
| 20 | - */ | |
| 21 | - private String name; | |
| 22 | - | |
| 23 | - /** | |
| 24 | - * 状态 | |
| 25 | - * | |
| 26 | - * 枚举 {@link CommonStatusEnum} | |
| 27 | - */ | |
| 28 | - private Integer status; | |
| 29 | - | |
| 30 | -} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/coupon/CouponTemplateApiImpl.java
| 1 | -package cn.iocoder.yudao.module.promotion.api.coupon; | |
| 2 | - | |
| 3 | -import cn.hutool.core.collection.CollUtil; | |
| 4 | -import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponTemplateRespDTO; | |
| 5 | -import cn.iocoder.yudao.module.promotion.convert.coupon.CouponTemplateConvert; | |
| 6 | -import cn.iocoder.yudao.module.promotion.service.coupon.CouponTemplateService; | |
| 7 | -import org.springframework.stereotype.Service; | |
| 8 | -import org.springframework.validation.annotation.Validated; | |
| 9 | - | |
| 10 | -import javax.annotation.Resource; | |
| 11 | -import java.util.Collection; | |
| 12 | -import java.util.Collections; | |
| 13 | -import java.util.List; | |
| 14 | - | |
| 15 | -/** | |
| 16 | - * 优惠劵模版 API 接口实现类 | |
| 17 | - * | |
| 18 | - * @author HUIHUI | |
| 19 | - */ | |
| 20 | -@Service | |
| 21 | -@Validated | |
| 22 | -public class CouponTemplateApiImpl implements CouponTemplateApi { | |
| 23 | - | |
| 24 | - @Resource | |
| 25 | - private CouponTemplateService couponTemplateService; | |
| 26 | - | |
| 27 | - @Override | |
| 28 | - public List<CouponTemplateRespDTO> getCouponTemplateListByIds(Collection<Long> ids) { | |
| 29 | - if (CollUtil.isEmpty(ids)) { // 防御一下 | |
| 30 | - return Collections.emptyList(); | |
| 31 | - } | |
| 32 | - return CouponTemplateConvert.INSTANCE.convertList(couponTemplateService.getCouponTemplateListByIds(ids)); | |
| 33 | - } | |
| 34 | - | |
| 35 | -} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/banner/BannerController.java
| ... | ... | @@ -23,7 +23,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 23 | 23 | |
| 24 | 24 | @Tag(name = "管理后台 - Banner 管理") |
| 25 | 25 | @RestController |
| 26 | -@RequestMapping("/market/banner") | |
| 26 | +@RequestMapping("/promotion/banner") | |
| 27 | 27 | @Validated |
| 28 | 28 | public class BannerController { |
| 29 | 29 | |
| ... | ... | @@ -32,14 +32,14 @@ public class BannerController { |
| 32 | 32 | |
| 33 | 33 | @PostMapping("/create") |
| 34 | 34 | @Operation(summary = "创建 Banner") |
| 35 | - @PreAuthorize("@ss.hasPermission('market:banner:create')") | |
| 35 | + @PreAuthorize("@ss.hasPermission('promotion:banner:create')") | |
| 36 | 36 | public CommonResult<Long> createBanner(@Valid @RequestBody BannerCreateReqVO createReqVO) { |
| 37 | 37 | return success(bannerService.createBanner(createReqVO)); |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | @PutMapping("/update") |
| 41 | 41 | @Operation(summary = "更新 Banner") |
| 42 | - @PreAuthorize("@ss.hasPermission('market:banner:update')") | |
| 42 | + @PreAuthorize("@ss.hasPermission('promotion:banner:update')") | |
| 43 | 43 | public CommonResult<Boolean> updateBanner(@Valid @RequestBody BannerUpdateReqVO updateReqVO) { |
| 44 | 44 | bannerService.updateBanner(updateReqVO); |
| 45 | 45 | return success(true); |
| ... | ... | @@ -48,7 +48,7 @@ public class BannerController { |
| 48 | 48 | @DeleteMapping("/delete") |
| 49 | 49 | @Operation(summary = "删除 Banner") |
| 50 | 50 | @Parameter(name = "id", description = "编号", required = true) |
| 51 | - @PreAuthorize("@ss.hasPermission('market:banner:delete')") | |
| 51 | + @PreAuthorize("@ss.hasPermission('promotion:banner:delete')") | |
| 52 | 52 | public CommonResult<Boolean> deleteBanner(@RequestParam("id") Long id) { |
| 53 | 53 | bannerService.deleteBanner(id); |
| 54 | 54 | return success(true); |
| ... | ... | @@ -57,7 +57,7 @@ public class BannerController { |
| 57 | 57 | @GetMapping("/get") |
| 58 | 58 | @Operation(summary = "获得 Banner") |
| 59 | 59 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| 60 | - @PreAuthorize("@ss.hasPermission('market:banner:query')") | |
| 60 | + @PreAuthorize("@ss.hasPermission('promotion:banner:query')") | |
| 61 | 61 | public CommonResult<BannerRespVO> getBanner(@RequestParam("id") Long id) { |
| 62 | 62 | BannerDO banner = bannerService.getBanner(id); |
| 63 | 63 | return success(BannerConvert.INSTANCE.convert(banner)); |
| ... | ... | @@ -65,7 +65,7 @@ public class BannerController { |
| 65 | 65 | |
| 66 | 66 | @GetMapping("/page") |
| 67 | 67 | @Operation(summary = "获得 Banner 分页") |
| 68 | - @PreAuthorize("@ss.hasPermission('market:banner:query')") | |
| 68 | + @PreAuthorize("@ss.hasPermission('promotion:banner:query')") | |
| 69 | 69 | public CommonResult<PageResult<BannerRespVO>> getBannerPage(@Valid BannerPageReqVO pageVO) { |
| 70 | 70 | PageResult<BannerDO> pageResult = bannerService.getBannerPage(pageVO); |
| 71 | 71 | return success(BannerConvert.INSTANCE.convertPage(pageResult)); | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/banner/vo/BannerBaseVO.java
| ... | ... | @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.promotion.controller.admin.banner.vo; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.validation.InEnum; |
| 5 | +import cn.iocoder.yudao.module.promotion.enums.banner.BannerPositionEnum; | |
| 5 | 6 | import io.swagger.v3.oas.annotations.media.Schema; |
| 6 | 7 | import lombok.Data; |
| 7 | 8 | |
| ... | ... | @@ -29,6 +30,7 @@ public class BannerBaseVO { |
| 29 | 30 | |
| 30 | 31 | @Schema(description = "position", requiredMode = Schema.RequiredMode.REQUIRED) |
| 31 | 32 | @NotNull(message = "position 不能为空") |
| 33 | + @InEnum(BannerPositionEnum.class) | |
| 32 | 34 | private Integer position; |
| 33 | 35 | |
| 34 | 36 | @Schema(description = "排序", requiredMode = Schema.RequiredMode.REQUIRED) | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/BargainActivityController.java
| ... | ... | @@ -59,6 +59,15 @@ public class BargainActivityController { |
| 59 | 59 | return success(true); |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | + @PutMapping("/close") | |
| 63 | + @Operation(summary = "关闭砍价活动") | |
| 64 | + @Parameter(name = "id", description = "编号", required = true) | |
| 65 | + @PreAuthorize("@ss.hasPermission('promotion:bargain-activity:close')") | |
| 66 | + public CommonResult<Boolean> closeSeckillActivity(@RequestParam("id") Long id) { | |
| 67 | + bargainActivityService.closeBargainActivityById(id); | |
| 68 | + return success(true); | |
| 69 | + } | |
| 70 | + | |
| 62 | 71 | @DeleteMapping("/delete") |
| 63 | 72 | @Operation(summary = "删除砍价活动") |
| 64 | 73 | @Parameter(name = "id", description = "编号", required = true) | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java
| ... | ... | @@ -59,6 +59,15 @@ public class CombinationActivityController { |
| 59 | 59 | return success(true); |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | + @PutMapping("/close") | |
| 63 | + @Operation(summary = "关闭拼团活动") | |
| 64 | + @Parameter(name = "id", description = "编号", required = true) | |
| 65 | + @PreAuthorize("@ss.hasPermission('promotion:combination-activity:close')") | |
| 66 | + public CommonResult<Boolean> closeSeckillActivity(@RequestParam("id") Long id) { | |
| 67 | + combinationActivityService.closeCombinationActivityById(id); | |
| 68 | + return success(true); | |
| 69 | + } | |
| 70 | + | |
| 62 | 71 | @DeleteMapping("/delete") |
| 63 | 72 | @Operation(summary = "删除拼团活动") |
| 64 | 73 | @Parameter(name = "id", description = "编号", required = true) | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/banner/AppBannerController.java
| ... | ... | @@ -5,8 +5,6 @@ import cn.iocoder.yudao.module.promotion.controller.app.banner.vo.AppBannerRespV |
| 5 | 5 | import cn.iocoder.yudao.module.promotion.convert.banner.BannerConvert; |
| 6 | 6 | import cn.iocoder.yudao.module.promotion.dal.dataobject.banner.BannerDO; |
| 7 | 7 | import cn.iocoder.yudao.module.promotion.service.banner.BannerService; |
| 8 | -import com.google.common.cache.CacheLoader; | |
| 9 | -import com.google.common.cache.LoadingCache; | |
| 10 | 8 | import io.swagger.v3.oas.annotations.Operation; |
| 11 | 9 | import io.swagger.v3.oas.annotations.Parameter; |
| 12 | 10 | import io.swagger.v3.oas.annotations.tags.Tag; |
| ... | ... | @@ -14,11 +12,9 @@ import org.springframework.validation.annotation.Validated; |
| 14 | 12 | import org.springframework.web.bind.annotation.*; |
| 15 | 13 | |
| 16 | 14 | import javax.annotation.Resource; |
| 17 | -import java.time.Duration; | |
| 18 | 15 | import java.util.List; |
| 19 | 16 | |
| 20 | 17 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 21 | -import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsyncReloadingCache; | |
| 22 | 18 | |
| 23 | 19 | @RestController |
| 24 | 20 | @RequestMapping("/promotion/banner") |
| ... | ... | @@ -26,20 +22,6 @@ import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsync |
| 26 | 22 | @Validated |
| 27 | 23 | public class AppBannerController { |
| 28 | 24 | |
| 29 | - // TODO @puhui999:这个目前不缓存,也没问题,因为首页没用到。 | |
| 30 | - /** | |
| 31 | - * {@link AppBannerRespVO} 缓存,通过它异步刷新 {@link #getBannerList0(Integer)} 所要的首页数据 | |
| 32 | - */ | |
| 33 | - private final LoadingCache<Integer, List<AppBannerRespVO>> bannerListCache = buildAsyncReloadingCache(Duration.ofSeconds(10L), | |
| 34 | - new CacheLoader<Integer, List<AppBannerRespVO>>() { | |
| 35 | - | |
| 36 | - @Override | |
| 37 | - public List<AppBannerRespVO> load(Integer position) { | |
| 38 | - return getBannerList0(position); | |
| 39 | - } | |
| 40 | - | |
| 41 | - }); | |
| 42 | - | |
| 43 | 25 | @Resource |
| 44 | 26 | private BannerService bannerService; |
| 45 | 27 | |
| ... | ... | @@ -47,12 +29,8 @@ public class AppBannerController { |
| 47 | 29 | @Operation(summary = "获得 banner 列表") |
| 48 | 30 | @Parameter(name = "position", description = "Banner position", example = "1") |
| 49 | 31 | public CommonResult<List<AppBannerRespVO>> getBannerList(@RequestParam("position") Integer position) { |
| 50 | - return success(bannerListCache.getUnchecked(position)); | |
| 51 | - } | |
| 52 | - | |
| 53 | - private List<AppBannerRespVO> getBannerList0(Integer position) { | |
| 54 | 32 | List<BannerDO> bannerList = bannerService.getBannerListByPosition(position); |
| 55 | - return BannerConvert.INSTANCE.convertList01(bannerList); | |
| 33 | + return success(BannerConvert.INSTANCE.convertList01(bannerList)); | |
| 56 | 34 | } |
| 57 | 35 | |
| 58 | 36 | @PutMapping("/add-browse-count") | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/coupon/CouponTemplateConvert.java
| ... | ... | @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.promotion.convert.coupon; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.map.MapUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | -import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponTemplateRespDTO; | |
| 6 | 5 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplateCreateReqVO; |
| 7 | 6 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplatePageReqVO; |
| 8 | 7 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplateRespVO; |
| ... | ... | @@ -59,6 +58,4 @@ public interface CouponTemplateConvert { |
| 59 | 58 | } |
| 60 | 59 | } |
| 61 | 60 | |
| 62 | - List<CouponTemplateRespDTO> convertList(List<CouponTemplateDO> list); | |
| 63 | - | |
| 64 | 61 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/banner/BannerDO.java
| ... | ... | @@ -6,13 +6,12 @@ import cn.iocoder.yudao.module.promotion.enums.banner.BannerPositionEnum; |
| 6 | 6 | import com.baomidou.mybatisplus.annotation.TableName; |
| 7 | 7 | import lombok.*; |
| 8 | 8 | |
| 9 | -// TODO @puhui999:表名改成 promotion_banner,然后有序加下;另外,sql 给我下哈;还有那个 position 字典,嘿嘿。 | |
| 10 | 9 | /** |
| 11 | 10 | * banner DO |
| 12 | 11 | * |
| 13 | 12 | * @author xia |
| 14 | 13 | */ |
| 15 | -@TableName("market_banner") | |
| 14 | +@TableName("promotion_banner") | |
| 16 | 15 | @Data |
| 17 | 16 | @EqualsAndHashCode(callSuper = true) |
| 18 | 17 | @ToString(callSuper = true) | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/coupon/CouponTemplateMapper.java
| ... | ... | @@ -75,8 +75,4 @@ public interface CouponTemplateMapper extends BaseMapperX<CouponTemplateDO> { |
| 75 | 75 | return canTakeConsumer; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - default List<CouponTemplateDO> selectListByIds(Collection<Long> ids) { | |
| 79 | - return selectList(new LambdaQueryWrapperX<CouponTemplateDO>().in(CouponTemplateDO::getId, ids)); | |
| 80 | - } | |
| 81 | - | |
| 82 | 78 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java
| ... | ... | @@ -46,6 +46,13 @@ public interface BargainActivityService { |
| 46 | 46 | void updateBargainActivityStock(Long id, Integer count); |
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | + * 关闭砍价活动 | |
| 50 | + * | |
| 51 | + * @param id 砍价活动编号 | |
| 52 | + */ | |
| 53 | + void closeBargainActivityById(Long id); | |
| 54 | + | |
| 55 | + /** | |
| 49 | 56 | * 删除砍价活动 |
| 50 | 57 | * |
| 51 | 58 | * @param id 编号 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java
| ... | ... | @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.promotion.service.bargain; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.map.MapUtil; |
| 5 | -import cn.hutool.core.util.ObjUtil; | |
| 6 | 5 | import cn.hutool.core.util.ObjectUtil; |
| 7 | 6 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 8 | 7 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| ... | ... | @@ -96,6 +95,19 @@ public class BargainActivityServiceImpl implements BargainActivityService { |
| 96 | 95 | } |
| 97 | 96 | } |
| 98 | 97 | |
| 98 | + @Override | |
| 99 | + @Transactional(rollbackFor = Exception.class) | |
| 100 | + public void closeBargainActivityById(Long id) { | |
| 101 | + // 校验砍价活动是否存在 | |
| 102 | + BargainActivityDO activity = validateBargainActivityExists(id); | |
| 103 | + if (CommonStatusEnum.isDisable(activity.getStatus())) { | |
| 104 | + throw exception(BARGAIN_ACTIVITY_STATUS_DISABLE); | |
| 105 | + } | |
| 106 | + | |
| 107 | + bargainActivityMapper.updateById(new BargainActivityDO().setId(id) | |
| 108 | + .setStatus(CommonStatusEnum.DISABLE.getStatus())); | |
| 109 | + } | |
| 110 | + | |
| 99 | 111 | private void validateBargainConflict(Long spuId, Long activityId) { |
| 100 | 112 | // 查询所有开启的砍价活动 |
| 101 | 113 | List<BargainActivityDO> activityList = bargainActivityMapper.selectListByStatus(CommonStatusEnum.ENABLE.getStatus()); |
| ... | ... | @@ -121,7 +133,7 @@ public class BargainActivityServiceImpl implements BargainActivityService { |
| 121 | 133 | // 校验存在 |
| 122 | 134 | BargainActivityDO activityDO = validateBargainActivityExists(id); |
| 123 | 135 | // 校验状态 |
| 124 | - if (ObjectUtil.equal(activityDO.getStatus(), CommonStatusEnum.ENABLE.getStatus())) { | |
| 136 | + if (CommonStatusEnum.isEnable(activityDO.getStatus())) { | |
| 125 | 137 | throw exception(BARGAIN_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END); |
| 126 | 138 | } |
| 127 | 139 | |
| ... | ... | @@ -153,7 +165,7 @@ public class BargainActivityServiceImpl implements BargainActivityService { |
| 153 | 165 | if (activity == null) { |
| 154 | 166 | throw exception(BARGAIN_ACTIVITY_NOT_EXISTS); |
| 155 | 167 | } |
| 156 | - if (ObjUtil.notEqual(activity.getStatus(), CommonStatusEnum.ENABLE.getStatus())) { | |
| 168 | + if (CommonStatusEnum.isDisable(activity.getStatus())) { | |
| 157 | 169 | throw exception(BARGAIN_ACTIVITY_STATUS_CLOSED); |
| 158 | 170 | } |
| 159 | 171 | if (activity.getStock() <= 0) { | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java
| ... | ... | @@ -36,7 +36,12 @@ public interface CombinationActivityService { |
| 36 | 36 | */ |
| 37 | 37 | void updateCombinationActivity(@Valid CombinationActivityUpdateReqVO updateReqVO); |
| 38 | 38 | |
| 39 | - // TODO @puhui999:这里少了一个关闭活动的接口;因为关闭的活动,才可以删除 | |
| 39 | + /** | |
| 40 | + * 关闭拼团活动 | |
| 41 | + * | |
| 42 | + * @param id 拼团活动编号 | |
| 43 | + */ | |
| 44 | + void closeCombinationActivityById(Long id); | |
| 40 | 45 | |
| 41 | 46 | /** |
| 42 | 47 | * 删除拼团活动 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java
| ... | ... | @@ -138,6 +138,20 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic |
| 138 | 138 | updateCombinationProduct(updateObj, updateReqVO.getProducts()); |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | + @Override | |
| 142 | + @Transactional(rollbackFor = Exception.class) | |
| 143 | + public void closeCombinationActivityById(Long id) { | |
| 144 | + // 校验活动是否存在 | |
| 145 | + CombinationActivityDO activity = validateCombinationActivityExists(id); | |
| 146 | + if (CommonStatusEnum.isDisable(activity.getStatus())) { | |
| 147 | + throw exception(COMBINATION_ACTIVITY_STATUS_DISABLE_NOT_UPDATE); | |
| 148 | + } | |
| 149 | + | |
| 150 | + // 关闭活动 | |
| 151 | + combinationActivityMapper.updateById(new CombinationActivityDO().setId(id) | |
| 152 | + .setStatus(CommonStatusEnum.DISABLE.getStatus())); | |
| 153 | + } | |
| 154 | + | |
| 141 | 155 | /** |
| 142 | 156 | * 更新拼团商品 |
| 143 | 157 | * |
| ... | ... | @@ -172,9 +186,9 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic |
| 172 | 186 | @Transactional(rollbackFor = Exception.class) |
| 173 | 187 | public void deleteCombinationActivity(Long id) { |
| 174 | 188 | // 校验存在 |
| 175 | - CombinationActivityDO activityDO = validateCombinationActivityExists(id); | |
| 189 | + CombinationActivityDO activity = validateCombinationActivityExists(id); | |
| 176 | 190 | // 校验状态 |
| 177 | - if (ObjectUtil.equal(activityDO.getStatus(), CommonStatusEnum.ENABLE.getStatus())) { | |
| 191 | + if (CommonStatusEnum.isEnable(activity.getStatus())) { | |
| 178 | 192 | throw exception(COMBINATION_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END); |
| 179 | 193 | } |
| 180 | 194 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateService.java
| ... | ... | @@ -98,6 +98,6 @@ public interface CouponTemplateService { |
| 98 | 98 | * @param ids 优惠券模版编号 |
| 99 | 99 | * @return 优惠券模版列表 |
| 100 | 100 | */ |
| 101 | - List<CouponTemplateDO> getCouponTemplateListByIds(Collection<Long> ids); | |
| 101 | + List<CouponTemplateDO> getCouponTemplateList(Collection<Long> ids); | |
| 102 | 102 | |
| 103 | 103 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateServiceImpl.java
| ... | ... | @@ -128,8 +128,8 @@ public class CouponTemplateServiceImpl implements CouponTemplateService { |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | @Override |
| 131 | - public List<CouponTemplateDO> getCouponTemplateListByIds(Collection<Long> ids) { | |
| 132 | - return couponTemplateMapper.selectListByIds(ids); | |
| 131 | + public List<CouponTemplateDO> getCouponTemplateList(Collection<Long> ids) { | |
| 132 | + return couponTemplateMapper.selectBatchIds(ids); | |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/discount/DiscountActivityServiceImpl.java
| ... | ... | @@ -147,8 +147,8 @@ public class DiscountActivityServiceImpl implements DiscountActivityService { |
| 147 | 147 | @Override |
| 148 | 148 | public void deleteDiscountActivity(Long id) { |
| 149 | 149 | // 校验存在 |
| 150 | - DiscountActivityDO discountActivity = validateDiscountActivityExists(id); | |
| 151 | - if (!discountActivity.getStatus().equals(CommonStatusEnum.ENABLE.getStatus())) { // 未关闭的活动,不能删除噢 | |
| 150 | + DiscountActivityDO activity = validateDiscountActivityExists(id); | |
| 151 | + if (CommonStatusEnum.isEnable(activity.getStatus())) { // 未关闭的活动,不能删除噢 | |
| 152 | 152 | throw exception(DISCOUNT_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED); |
| 153 | 153 | } |
| 154 | 154 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java
| ... | ... | @@ -296,7 +296,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { |
| 296 | 296 | public SeckillValidateJoinRespDTO validateJoinSeckill(Long activityId, Long skuId, Integer count) { |
| 297 | 297 | // 1.1 校验秒杀活动是否存在 |
| 298 | 298 | SeckillActivityDO activity = validateSeckillActivityExists(activityId); |
| 299 | - if (ObjectUtil.notEqual(activity.getStatus(), CommonStatusEnum.ENABLE.getStatus())) { | |
| 299 | + if (CommonStatusEnum.isDisable(activity.getStatus())) { | |
| 300 | 300 | throw exception(SECKILL_JOIN_ACTIVITY_STATUS_CLOSED); |
| 301 | 301 | } |
| 302 | 302 | // 1.2 是否在活动时间范围内 | ... | ... |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/signin/MemberSignInRecordConvert.java
| ... | ... | @@ -12,8 +12,7 @@ import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; |
| 12 | 12 | import org.mapstruct.Mapper; |
| 13 | 13 | import org.mapstruct.factory.Mappers; |
| 14 | 14 | |
| 15 | -import java.time.LocalDateTime; | |
| 16 | -import java.time.temporal.ChronoUnit; | |
| 15 | +import java.util.Comparator; | |
| 17 | 16 | import java.util.List; |
| 18 | 17 | import java.util.Map; |
| 19 | 18 | |
| ... | ... | @@ -44,31 +43,32 @@ public interface MemberSignInRecordConvert { |
| 44 | 43 | |
| 45 | 44 | AppMemberSignInRecordRespVO coverRecordToAppRecordVo(MemberSignInRecordDO memberSignInRecordDO); |
| 46 | 45 | |
| 47 | - default MemberSignInRecordDO convert(Long userId, MemberSignInRecordDO firstRecord, List<MemberSignInConfigDO> signInConfigs) { | |
| 48 | - // 1. 计算今天是第几天签到 | |
| 49 | - long day = ChronoUnit.DAYS.between(firstRecord.getCreateTime(), LocalDateTime.now()); | |
| 50 | - // 2. 初始化签到信息 | |
| 51 | - // TODO @puhui999:signInRecord=》record | |
| 52 | - MemberSignInRecordDO signInRecord = new MemberSignInRecordDO().setUserId(userId) | |
| 53 | - .setDay(Integer.parseInt(Long.toString(day))) // 设置签到天数 TODO @puhui999:day 应该跟着第几天签到走;不是累加哈;另外 long 转 int,应该 (int) day 就可以了。。。 | |
| 54 | - .setPoint(0) // 设置签到积分默认为 | |
| 55 | - .setExperience(0); // 设置签到经验默认为 0 | |
| 56 | - // 3. 获取签到对应的积分数 | |
| 57 | - MemberSignInConfigDO lastConfig = signInConfigs.get(signInConfigs.size() - 1); // 最大签到天数 | |
| 58 | - if (day > lastConfig.getDay()) { // 超出范围按第一天的经验计算 | |
| 59 | - // TODO @puhui999:不能直接取 0,万一它 day 不匹配哈。就是第一天没奖励。。。 | |
| 60 | - signInRecord.setPoint(signInConfigs.get(0).getPoint()); | |
| 61 | - signInRecord.setExperience(signInConfigs.get(0).getExperience()); | |
| 62 | - return signInRecord; | |
| 46 | + default MemberSignInRecordDO convert(Long userId, MemberSignInRecordDO lastRecord, List<MemberSignInConfigDO> configs) { | |
| 47 | + // 1. 计算是第几天签到 | |
| 48 | + configs.sort(Comparator.comparing(MemberSignInConfigDO::getDay)); | |
| 49 | + MemberSignInConfigDO lastConfig = CollUtil.getLast(configs); // 最大签到天数配置 | |
| 50 | + // 1.2. 计算今天是第几天签到 | |
| 51 | + int day = 1; | |
| 52 | + // TODO @puhui999:要判断是不是昨天签到的;是否是昨天的判断,可以抽个方法到 util 里 | |
| 53 | + if (lastRecord != null) { | |
| 54 | + day = lastRecord.getDay() + 1; | |
| 63 | 55 | } |
| 64 | - // TODO @puhui999:signInConfig 可以改成 config; | |
| 65 | - MemberSignInConfigDO signInConfig = CollUtil.findOne(signInConfigs, config -> ObjUtil.equal(config.getDay(), day)); | |
| 66 | - if (signInConfig == null) { | |
| 67 | - return signInRecord; | |
| 56 | + // 1.3 判断是否超出了最大签到配置 | |
| 57 | + if (day > lastConfig.getDay()) { | |
| 58 | + day = 1; // 超过最大配置的天数,重置到第一天。(也就是说开启下一轮签到) | |
| 68 | 59 | } |
| 69 | - signInRecord.setPoint(signInConfig.getPoint()); | |
| 70 | - signInRecord.setExperience(signInConfig.getExperience()); | |
| 71 | - return signInRecord; | |
| 60 | + | |
| 61 | + // 2.1 初始化签到信息 | |
| 62 | + MemberSignInRecordDO record = new MemberSignInRecordDO().setUserId(userId) | |
| 63 | + .setDay(day).setPoint(0).setExperience(0); | |
| 64 | + // 2.2 获取签到对应的积分 | |
| 65 | + MemberSignInConfigDO config = CollUtil.findOne(configs, item -> ObjUtil.equal(item.getDay(), record.getDay())); | |
| 66 | + if (config == null) { | |
| 67 | + return record; | |
| 68 | + } | |
| 69 | + record.setPoint(config.getPoint()); | |
| 70 | + record.setExperience(config.getExperience()); | |
| 71 | + return record; | |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | } | ... | ... |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/signin/MemberSignInRecordMapper.java
| ... | ... | @@ -35,50 +35,31 @@ public interface MemberSignInRecordMapper extends BaseMapperX<MemberSignInRecord |
| 35 | 35 | .orderByDesc(MemberSignInRecordDO::getId)); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - // TODO @puhui999:这 2 个方法,是不是一个 first;一个 last 就可以了。。 | |
| 39 | 38 | /** |
| 40 | 39 | * 获取用户最近的签到记录信息,根据签到时间倒序 |
| 41 | 40 | * |
| 42 | 41 | * @param userId 用户编号 |
| 43 | 42 | * @return 签到记录列表 |
| 44 | 43 | */ |
| 45 | - default MemberSignInRecordDO selectLastRecordByUserIdDesc(Long userId) { | |
| 44 | + default MemberSignInRecordDO selectLastRecordByUserId(Long userId) { | |
| 46 | 45 | return selectOne(new QueryWrapper<MemberSignInRecordDO>() |
| 47 | 46 | .eq("user_id", userId) |
| 48 | 47 | .orderByDesc("create_time") |
| 49 | 48 | .last("limit 1")); |
| 50 | 49 | } |
| 51 | 50 | |
| 52 | - /** | |
| 53 | - * 获取用户最早的签到记录信息,根据签到时间倒序 | |
| 54 | - * | |
| 55 | - * @param userId 用户编号 | |
| 56 | - * @return 签到记录列表 | |
| 57 | - */ | |
| 58 | - default MemberSignInRecordDO selectLastRecordByUserIdAsc(Long userId) { | |
| 59 | - return selectOne(new QueryWrapper<MemberSignInRecordDO>() | |
| 60 | - .eq("user_id", userId) | |
| 61 | - .orderByAsc("create_time") | |
| 62 | - .last("limit 1")); | |
| 63 | - } | |
| 64 | - | |
| 65 | 51 | default Long selectCountByUserId(Long userId) { |
| 66 | - // TODO @puhui999:可以使用 selectCount 里面允许传递字段的方法 | |
| 67 | - return selectCount(new LambdaQueryWrapperX<MemberSignInRecordDO>() | |
| 68 | - .eq(MemberSignInRecordDO::getUserId, userId)); | |
| 52 | + return selectCount(MemberSignInRecordDO::getUserId, userId); | |
| 69 | 53 | } |
| 70 | 54 | |
| 71 | 55 | /** |
| 72 | - * 获取用户的签到记录列表信息,根据签到时间倒序 | |
| 56 | + * 获取用户的签到记录列表信息 | |
| 73 | 57 | * |
| 74 | 58 | * @param userId 用户编号 |
| 75 | 59 | * @return 签到记录信息 |
| 76 | 60 | */ |
| 77 | - // TODO @puhui999:这个排序,可以交给 service 哈; | |
| 78 | 61 | default List<MemberSignInRecordDO> selectListByUserId(Long userId) { |
| 79 | - return selectList(new LambdaQueryWrapperX<MemberSignInRecordDO>() | |
| 80 | - .eq(MemberSignInRecordDO::getUserId, userId) | |
| 81 | - .orderByDesc(MemberSignInRecordDO::getCreateTime)); | |
| 62 | + return selectList(MemberSignInRecordDO::getUserId, userId); | |
| 82 | 63 | } |
| 83 | 64 | |
| 84 | 65 | } | ... | ... |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/signin/MemberSignInRecordServiceImpl.java
| ... | ... | @@ -58,36 +58,38 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService |
| 58 | 58 | @Override |
| 59 | 59 | public AppMemberSignInRecordSummaryRespVO getSignInRecordSummary(Long userId) { |
| 60 | 60 | // 1. 初始化默认返回信息 |
| 61 | - // TODO @puhui999:这里 vo 改成 summary 会更好理解; | |
| 62 | - AppMemberSignInRecordSummaryRespVO vo = new AppMemberSignInRecordSummaryRespVO(); | |
| 63 | - vo.setTotalDay(0); | |
| 64 | - vo.setContinuousDay(0); | |
| 65 | - vo.setTodaySignIn(false); | |
| 61 | + AppMemberSignInRecordSummaryRespVO summary = new AppMemberSignInRecordSummaryRespVO(); | |
| 62 | + summary.setTotalDay(0); | |
| 63 | + summary.setContinuousDay(0); | |
| 64 | + summary.setTodaySignIn(false); | |
| 66 | 65 | |
| 67 | 66 | // 2. 获取用户签到的记录数 |
| 68 | 67 | Long signCount = signInRecordMapper.selectCountByUserId(userId); |
| 69 | 68 | if (ObjUtil.equal(signCount, 0L)) { |
| 70 | - return vo; | |
| 69 | + return summary; | |
| 71 | 70 | } |
| 72 | - vo.setTotalDay(signCount.intValue()); // 设置总签到天数 | |
| 71 | + summary.setTotalDay(signCount.intValue()); // 设置总签到天数 | |
| 73 | 72 | |
| 74 | 73 | // 3. 校验当天是否有签到 |
| 75 | - // TODO @puhui999:是不是 signInRecord 可以精简成 record 哈;另外,Desc 貌似可以去掉哈;最后一条了; | |
| 76 | - MemberSignInRecordDO signInRecord = signInRecordMapper.selectLastRecordByUserIdDesc(userId); | |
| 77 | - if (signInRecord == null) { | |
| 78 | - return vo; | |
| 74 | + MemberSignInRecordDO lastRecord = signInRecordMapper.selectLastRecordByUserId(userId); | |
| 75 | + if (lastRecord == null) { | |
| 76 | + return summary; | |
| 79 | 77 | } |
| 80 | - vo.setTodaySignIn(DateUtils.isToday(signInRecord.getCreateTime())); | |
| 78 | + summary.setTodaySignIn(DateUtils.isToday(lastRecord.getCreateTime())); | |
| 81 | 79 | |
| 82 | 80 | // 4. 校验今天是否签到,没有签到则直接返回 |
| 83 | - if (!vo.getTodaySignIn()) { | |
| 84 | - return vo; | |
| 81 | + if (!summary.getTodaySignIn()) { | |
| 82 | + return summary; | |
| 85 | 83 | } |
| 86 | 84 | // 4.1. 判断连续签到天数 |
| 87 | - // TODO @puhui999:连续签到,可以基于 signInRecord 的 day 和当前时间判断呀? | |
| 85 | + // TODO @puhui999:连续签到,可以基于 lastRecord 的 day 和当前时间判断呀?按 day 统计连续签到天数可能不准确 | |
| 86 | + // 1. day 只是记录第几天签到的有可能不连续,比如第一次签到是周一,第二次签到是周三这样 lastRecord 的 day 为 2 但是并不是连续的两天 | |
| 87 | + // 2. day 超出签到规则的最大天数会重置到从第一天开始签到(我理解为开始下一轮,类似一周签到七天七天结束下周又从周一开始签到) | |
| 88 | + // 1. 回复:周三签到,day 要归 1 呀。连续签到哈; | |
| 88 | 89 | List<MemberSignInRecordDO> signInRecords = signInRecordMapper.selectListByUserId(userId); |
| 89 | - vo.setContinuousDay(calculateConsecutiveDays(signInRecords)); | |
| 90 | - return vo; | |
| 90 | + signInRecords.sort(Comparator.comparing(MemberSignInRecordDO::getCreateTime).reversed()); // 根据签到时间倒序 | |
| 91 | + summary.setContinuousDay(calculateConsecutiveDays(signInRecords)); | |
| 92 | + return summary; | |
| 91 | 93 | } |
| 92 | 94 | |
| 93 | 95 | /** |
| ... | ... | @@ -144,17 +146,14 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService |
| 144 | 146 | @Transactional(rollbackFor = Exception.class) |
| 145 | 147 | public MemberSignInRecordDO createSignRecord(Long userId) { |
| 146 | 148 | // 1. 获取当前用户最近的签到 |
| 147 | - MemberSignInRecordDO lastRecord = signInRecordMapper.selectLastRecordByUserIdDesc(userId); | |
| 149 | + MemberSignInRecordDO lastRecord = signInRecordMapper.selectLastRecordByUserId(userId); | |
| 148 | 150 | // 1.1. 判断是否重复签到 |
| 149 | 151 | validateSigned(lastRecord); |
| 150 | 152 | |
| 151 | - // 2. 获取当前用户最早的一次前端记录,用于计算今天是第几天签到 | |
| 152 | - MemberSignInRecordDO firstRecord = signInRecordMapper.selectLastRecordByUserIdAsc(userId); | |
| 153 | 153 | // 2.1. 获取所有的签到规则 |
| 154 | 154 | List<MemberSignInConfigDO> signInConfigs = signInConfigService.getSignInConfigList(CommonStatusEnum.ENABLE.getStatus()); |
| 155 | - signInConfigs.sort(Comparator.comparing(MemberSignInConfigDO::getDay)); | |
| 156 | 155 | // 2.2. 组合数据 |
| 157 | - MemberSignInRecordDO record = MemberSignInRecordConvert.INSTANCE.convert(userId, firstRecord, signInConfigs); | |
| 156 | + MemberSignInRecordDO record = MemberSignInRecordConvert.INSTANCE.convert(userId, lastRecord, signInConfigs); | |
| 158 | 157 | |
| 159 | 158 | // 3. 插入签到记录 |
| 160 | 159 | signInRecordMapper.insert(record); | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java
| ... | ... | @@ -23,10 +23,10 @@ import cn.iocoder.yudao.module.system.service.member.MemberService; |
| 23 | 23 | import cn.iocoder.yudao.module.system.service.oauth2.OAuth2TokenService; |
| 24 | 24 | import cn.iocoder.yudao.module.system.service.social.SocialUserService; |
| 25 | 25 | import cn.iocoder.yudao.module.system.service.user.AdminUserService; |
| 26 | +import com.google.common.annotations.VisibleForTesting; | |
| 26 | 27 | import com.xingyuv.captcha.model.common.ResponseModel; |
| 27 | 28 | import com.xingyuv.captcha.model.vo.CaptchaVO; |
| 28 | 29 | import com.xingyuv.captcha.service.CaptchaService; |
| 29 | -import com.google.common.annotations.VisibleForTesting; | |
| 30 | 30 | import lombok.extern.slf4j.Slf4j; |
| 31 | 31 | import org.springframework.beans.factory.annotation.Value; |
| 32 | 32 | import org.springframework.stereotype.Service; |
| ... | ... | @@ -85,7 +85,7 @@ public class AdminAuthServiceImpl implements AdminAuthService { |
| 85 | 85 | throw exception(AUTH_LOGIN_BAD_CREDENTIALS); |
| 86 | 86 | } |
| 87 | 87 | // 校验是否禁用 |
| 88 | - if (ObjectUtil.notEqual(user.getStatus(), CommonStatusEnum.ENABLE.getStatus())) { | |
| 88 | + if (CommonStatusEnum.isDisable(user.getStatus())) { | |
| 89 | 89 | createLoginLog(user.getId(), username, logTypeEnum, LoginResultEnum.USER_DISABLED); |
| 90 | 90 | throw exception(AUTH_LOGIN_USER_DISABLED); |
| 91 | 91 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientServiceImpl.java
| ... | ... | @@ -119,7 +119,7 @@ public class OAuth2ClientServiceImpl implements OAuth2ClientService { |
| 119 | 119 | if (client == null) { |
| 120 | 120 | throw exception(OAUTH2_CLIENT_NOT_EXISTS); |
| 121 | 121 | } |
| 122 | - if (ObjectUtil.notEqual(client.getStatus(), CommonStatusEnum.ENABLE.getStatus())) { | |
| 122 | + if (CommonStatusEnum.isDisable(client.getStatus())) { | |
| 123 | 123 | throw exception(OAUTH2_CLIENT_DISABLE); |
| 124 | 124 | } |
| 125 | 125 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceImpl.java
| ... | ... | @@ -26,7 +26,6 @@ import org.springframework.util.Assert; |
| 26 | 26 | import javax.annotation.Resource; |
| 27 | 27 | import java.util.List; |
| 28 | 28 | import java.util.Map; |
| 29 | -import java.util.Objects; | |
| 30 | 29 | import java.util.regex.Pattern; |
| 31 | 30 | |
| 32 | 31 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| ... | ... | @@ -140,7 +139,7 @@ public class SmsTemplateServiceImpl implements SmsTemplateService { |
| 140 | 139 | if (channelDO == null) { |
| 141 | 140 | throw exception(SMS_CHANNEL_NOT_EXISTS); |
| 142 | 141 | } |
| 143 | - if (!Objects.equals(channelDO.getStatus(), CommonStatusEnum.ENABLE.getStatus())) { | |
| 142 | + if (CommonStatusEnum.isDisable(channelDO.getStatus())) { | |
| 144 | 143 | throw exception(SMS_CHANNEL_DISABLE); |
| 145 | 144 | } |
| 146 | 145 | return channelDO; | ... | ... |