Commit 6723cae78153d1ca580d64f367848742da994dce
1 parent
ec27a1ba
营销活动:完善 review 提到的问题
Showing
17 changed files
with
130 additions
and
109 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-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/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/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/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.signin.MemberSignInRecordDO |
| 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,33 @@ 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> signInConfigs) { | |
| 47 | + // 1. 获取最大签到天数积分配置 | |
| 48 | + signInConfigs.sort(Comparator.comparing(MemberSignInConfigDO::getDay)); | |
| 49 | + MemberSignInConfigDO lastConfig = signInConfigs.get(signInConfigs.size() - 1); // 最大签到天数配置 | |
| 50 | + // 1.2. 计算今天是第几天签到 | |
| 51 | + int day = 1; | |
| 52 | + if (lastRecord != null) { | |
| 53 | + day = lastRecord.getDay() + 1; | |
| 54 | + } | |
| 55 | + // 1.3 判断是否超出了最大签到配置 | |
| 56 | + if (day > lastConfig.getDay()) { | |
| 57 | + day = 1; // 超过最大配置的天数,重置到第一天。(也就是说开启下一轮签到) | |
| 63 | 58 | } |
| 64 | - // TODO @puhui999:signInConfig 可以改成 config; | |
| 65 | - MemberSignInConfigDO signInConfig = CollUtil.findOne(signInConfigs, config -> ObjUtil.equal(config.getDay(), day)); | |
| 66 | - if (signInConfig == null) { | |
| 67 | - return signInRecord; | |
| 59 | + // 1.4 初始化签到信息 | |
| 60 | + MemberSignInRecordDO record = new MemberSignInRecordDO().setUserId(userId) | |
| 61 | + .setDay(day) // 设置签到天数 | |
| 62 | + .setPoint(0) // 设置签到积分默认为 0 | |
| 63 | + .setExperience(0); // 设置签到经验默认为 0 | |
| 64 | + | |
| 65 | + // 2. 获取签到对应的积分 | |
| 66 | + MemberSignInConfigDO config = CollUtil.findOne(signInConfigs, item -> ObjUtil.equal(item.getDay(), record.getDay())); | |
| 67 | + if (config == null) { | |
| 68 | + return record; | |
| 68 | 69 | } |
| 69 | - signInRecord.setPoint(signInConfig.getPoint()); | |
| 70 | - signInRecord.setExperience(signInConfig.getExperience()); | |
| 71 | - return signInRecord; | |
| 70 | + record.setPoint(config.getPoint()); | |
| 71 | + record.setExperience(config.getExperience()); | |
| 72 | + return record; | |
| 72 | 73 | } |
| 73 | 74 | |
| 74 | 75 | } | ... | ... |
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,37 @@ 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 | 88 | List<MemberSignInRecordDO> signInRecords = signInRecordMapper.selectListByUserId(userId); |
| 89 | - vo.setContinuousDay(calculateConsecutiveDays(signInRecords)); | |
| 90 | - return vo; | |
| 89 | + signInRecords.sort(Comparator.comparing(MemberSignInRecordDO::getCreateTime).reversed()); // 根据签到时间倒序 | |
| 90 | + summary.setContinuousDay(calculateConsecutiveDays(signInRecords)); | |
| 91 | + return summary; | |
| 91 | 92 | } |
| 92 | 93 | |
| 93 | 94 | /** |
| ... | ... | @@ -144,17 +145,14 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService |
| 144 | 145 | @Transactional(rollbackFor = Exception.class) |
| 145 | 146 | public MemberSignInRecordDO createSignRecord(Long userId) { |
| 146 | 147 | // 1. 获取当前用户最近的签到 |
| 147 | - MemberSignInRecordDO lastRecord = signInRecordMapper.selectLastRecordByUserIdDesc(userId); | |
| 148 | + MemberSignInRecordDO lastRecord = signInRecordMapper.selectLastRecordByUserId(userId); | |
| 148 | 149 | // 1.1. 判断是否重复签到 |
| 149 | 150 | validateSigned(lastRecord); |
| 150 | 151 | |
| 151 | - // 2. 获取当前用户最早的一次前端记录,用于计算今天是第几天签到 | |
| 152 | - MemberSignInRecordDO firstRecord = signInRecordMapper.selectLastRecordByUserIdAsc(userId); | |
| 153 | 152 | // 2.1. 获取所有的签到规则 |
| 154 | 153 | List<MemberSignInConfigDO> signInConfigs = signInConfigService.getSignInConfigList(CommonStatusEnum.ENABLE.getStatus()); |
| 155 | - signInConfigs.sort(Comparator.comparing(MemberSignInConfigDO::getDay)); | |
| 156 | 154 | // 2.2. 组合数据 |
| 157 | - MemberSignInRecordDO record = MemberSignInRecordConvert.INSTANCE.convert(userId, firstRecord, signInConfigs); | |
| 155 | + MemberSignInRecordDO record = MemberSignInRecordConvert.INSTANCE.convert(userId, lastRecord, signInConfigs); | |
| 158 | 156 | |
| 159 | 157 | // 3. 插入签到记录 |
| 160 | 158 | 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
| ... | ... | @@ -27,7 +27,6 @@ import org.springframework.util.Assert; |
| 27 | 27 | import javax.annotation.Resource; |
| 28 | 28 | import java.util.List; |
| 29 | 29 | import java.util.Map; |
| 30 | -import java.util.Objects; | |
| 31 | 30 | import java.util.regex.Pattern; |
| 32 | 31 | |
| 33 | 32 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| ... | ... | @@ -144,7 +143,7 @@ public class SmsTemplateServiceImpl implements SmsTemplateService { |
| 144 | 143 | if (channelDO == null) { |
| 145 | 144 | throw exception(SMS_CHANNEL_NOT_EXISTS); |
| 146 | 145 | } |
| 147 | - if (!Objects.equals(channelDO.getStatus(), CommonStatusEnum.ENABLE.getStatus())) { | |
| 146 | + if (CommonStatusEnum.isDisable(channelDO.getStatus())) { | |
| 148 | 147 | throw exception(SMS_CHANNEL_DISABLE); |
| 149 | 148 | } |
| 150 | 149 | return channelDO; | ... | ... |