mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 02:08:43 +08:00 
			
		
		
		
	code review:sign 签到逻辑
This commit is contained in:
		| @@ -1,23 +0,0 @@ | |||||||
| package cn.iocoder.yudao.module.promotion.api.coupon; |  | ||||||
|  |  | ||||||
| import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponTemplateRespDTO; |  | ||||||
|  |  | ||||||
| import java.util.Collection; |  | ||||||
| import java.util.List; |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * 优惠劵模版 API 接口 |  | ||||||
|  * |  | ||||||
|  * @author HUIHUI |  | ||||||
|  */ |  | ||||||
| public interface CouponTemplateApi { |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 获得优惠券模版的精简信息列表 |  | ||||||
|      * |  | ||||||
|      * @param ids 优惠券模版编号 |  | ||||||
|      * @return 优惠券模版的精简信息列表 |  | ||||||
|      */ |  | ||||||
|     List<CouponTemplateRespDTO> getCouponTemplateListByIds(Collection<Long> ids); |  | ||||||
|  |  | ||||||
| } |  | ||||||
| @@ -1,30 +0,0 @@ | |||||||
| package cn.iocoder.yudao.module.promotion.api.coupon.dto; |  | ||||||
|  |  | ||||||
| import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |  | ||||||
| import lombok.Data; |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * 优惠券模版 Response DTO |  | ||||||
|  * |  | ||||||
|  * @author HUIHUI |  | ||||||
|  */ |  | ||||||
| @Data |  | ||||||
| public class CouponTemplateRespDTO { |  | ||||||
|     /** |  | ||||||
|      * 模板编号,自增唯一 |  | ||||||
|      */ |  | ||||||
|  |  | ||||||
|     private Long id; |  | ||||||
|     /** |  | ||||||
|      * 优惠劵名 |  | ||||||
|      */ |  | ||||||
|     private String name; |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 状态 |  | ||||||
|      * |  | ||||||
|      * 枚举 {@link CommonStatusEnum} |  | ||||||
|      */ |  | ||||||
|     private Integer status; |  | ||||||
|  |  | ||||||
| } |  | ||||||
| @@ -1,33 +0,0 @@ | |||||||
| package cn.iocoder.yudao.module.promotion.api.coupon; |  | ||||||
|  |  | ||||||
| import cn.hutool.core.collection.CollUtil; |  | ||||||
| import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponTemplateRespDTO; |  | ||||||
| import cn.iocoder.yudao.module.promotion.convert.coupon.CouponTemplateConvert; |  | ||||||
| import cn.iocoder.yudao.module.promotion.service.coupon.CouponTemplateService; |  | ||||||
| import org.springframework.stereotype.Service; |  | ||||||
|  |  | ||||||
| import javax.annotation.Resource; |  | ||||||
| import java.util.Collection; |  | ||||||
| import java.util.Collections; |  | ||||||
| import java.util.List; |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * 优惠劵模版 API 接口实现类 |  | ||||||
|  * |  | ||||||
|  * @author HUIHUI |  | ||||||
|  */ |  | ||||||
| @Service |  | ||||||
| public class CouponTemplateApiImpl implements CouponTemplateApi { |  | ||||||
|  |  | ||||||
|     @Resource |  | ||||||
|     private CouponTemplateService couponTemplateService; |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     public List<CouponTemplateRespDTO> getCouponTemplateListByIds(Collection<Long> ids) { |  | ||||||
|         if (CollUtil.isEmpty(ids)) { // 防御一下 |  | ||||||
|             return Collections.emptyList(); |  | ||||||
|         } |  | ||||||
|         return CouponTemplateConvert.INSTANCE.convertList(couponTemplateService.getCouponTemplateListByIds(ids)); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
| } |  | ||||||
| @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.promotion.convert.coupon; | |||||||
|  |  | ||||||
| import cn.hutool.core.map.MapUtil; | import cn.hutool.core.map.MapUtil; | ||||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||||
| import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponTemplateRespDTO; |  | ||||||
| import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplateCreateReqVO; | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplateCreateReqVO; | ||||||
| import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplatePageReqVO; | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplatePageReqVO; | ||||||
| import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplateRespVO; | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplateRespVO; | ||||||
| @@ -59,6 +58,4 @@ public interface CouponTemplateConvert { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     List<CouponTemplateRespDTO> convertList(List<CouponTemplateDO> list); |  | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -75,8 +75,4 @@ public interface CouponTemplateMapper extends BaseMapperX<CouponTemplateDO> { | |||||||
|         return canTakeConsumer; |         return canTakeConsumer; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     default List<CouponTemplateDO> selectListByIds(Collection<Long> ids) { |  | ||||||
|         return selectList(new LambdaQueryWrapperX<CouponTemplateDO>().in(CouponTemplateDO::getId, ids)); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -98,6 +98,6 @@ public interface CouponTemplateService { | |||||||
|      * @param ids 优惠券模版编号 |      * @param ids 优惠券模版编号 | ||||||
|      * @return 优惠券模版列表 |      * @return 优惠券模版列表 | ||||||
|      */ |      */ | ||||||
|     List<CouponTemplateDO> getCouponTemplateListByIds(Collection<Long> ids); |     List<CouponTemplateDO> getCouponTemplateList(Collection<Long> ids); | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -128,8 +128,8 @@ public class CouponTemplateServiceImpl implements CouponTemplateService { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public List<CouponTemplateDO> getCouponTemplateListByIds(Collection<Long> ids) { |     public List<CouponTemplateDO> getCouponTemplateList(Collection<Long> ids) { | ||||||
|         return couponTemplateMapper.selectListByIds(ids); |         return couponTemplateMapper.selectBatchIds(ids); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -43,12 +43,13 @@ public interface MemberSignInRecordConvert { | |||||||
|  |  | ||||||
|     AppMemberSignInRecordRespVO coverRecordToAppRecordVo(MemberSignInRecordDO memberSignInRecordDO); |     AppMemberSignInRecordRespVO coverRecordToAppRecordVo(MemberSignInRecordDO memberSignInRecordDO); | ||||||
|  |  | ||||||
|     default MemberSignInRecordDO convert(Long userId, MemberSignInRecordDO lastRecord, List<MemberSignInConfigDO> signInConfigs) { |     default MemberSignInRecordDO convert(Long userId, MemberSignInRecordDO lastRecord, List<MemberSignInConfigDO> configs) { | ||||||
|         // 1. 获取最大签到天数积分配置 |         // 1. 计算是第几天签到 | ||||||
|         signInConfigs.sort(Comparator.comparing(MemberSignInConfigDO::getDay)); |         configs.sort(Comparator.comparing(MemberSignInConfigDO::getDay)); | ||||||
|         MemberSignInConfigDO lastConfig = signInConfigs.get(signInConfigs.size() - 1); // 最大签到天数配置 |         MemberSignInConfigDO lastConfig = CollUtil.getLast(configs); // 最大签到天数配置 | ||||||
|         // 1.2. 计算今天是第几天签到 |         // 1.2. 计算今天是第几天签到 | ||||||
|         int day = 1; |         int day = 1; | ||||||
|  |         // TODO @puhui999:要判断是不是昨天签到的;是否是昨天的判断,可以抽个方法到 util 里 | ||||||
|         if (lastRecord != null) { |         if (lastRecord != null) { | ||||||
|             day = lastRecord.getDay() + 1; |             day = lastRecord.getDay() + 1; | ||||||
|         } |         } | ||||||
| @@ -56,14 +57,12 @@ public interface MemberSignInRecordConvert { | |||||||
|         if (day > lastConfig.getDay()) { |         if (day > lastConfig.getDay()) { | ||||||
|             day = 1; // 超过最大配置的天数,重置到第一天。(也就是说开启下一轮签到) |             day = 1; // 超过最大配置的天数,重置到第一天。(也就是说开启下一轮签到) | ||||||
|         } |         } | ||||||
|         // 1.4 初始化签到信息 |  | ||||||
|         MemberSignInRecordDO record = new MemberSignInRecordDO().setUserId(userId) |  | ||||||
|                 .setDay(day) // 设置签到天数 |  | ||||||
|                 .setPoint(0)  // 设置签到积分默认为 0 |  | ||||||
|                 .setExperience(0);  // 设置签到经验默认为 0 |  | ||||||
|  |  | ||||||
|         // 2. 获取签到对应的积分 |         // 2.1 初始化签到信息 | ||||||
|         MemberSignInConfigDO config = CollUtil.findOne(signInConfigs, item -> ObjUtil.equal(item.getDay(), record.getDay())); |         MemberSignInRecordDO record = new MemberSignInRecordDO().setUserId(userId) | ||||||
|  |                 .setDay(day).setPoint(0).setExperience(0); | ||||||
|  |         // 2.2 获取签到对应的积分 | ||||||
|  |         MemberSignInConfigDO config = CollUtil.findOne(configs, item -> ObjUtil.equal(item.getDay(), record.getDay())); | ||||||
|         if (config == null) { |         if (config == null) { | ||||||
|             return record; |             return record; | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -85,6 +85,7 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService | |||||||
|         // TODO @puhui999:连续签到,可以基于 lastRecord 的 day 和当前时间判断呀?按 day 统计连续签到天数可能不准确 |         // TODO @puhui999:连续签到,可以基于 lastRecord 的 day 和当前时间判断呀?按 day 统计连续签到天数可能不准确 | ||||||
|         //      1. day 只是记录第几天签到的有可能不连续,比如第一次签到是周一,第二次签到是周三这样 lastRecord 的 day 为 2 但是并不是连续的两天 |         //      1. day 只是记录第几天签到的有可能不连续,比如第一次签到是周一,第二次签到是周三这样 lastRecord 的 day 为 2 但是并不是连续的两天 | ||||||
|         //      2. day 超出签到规则的最大天数会重置到从第一天开始签到(我理解为开始下一轮,类似一周签到七天七天结束下周又从周一开始签到) |         //      2. day 超出签到规则的最大天数会重置到从第一天开始签到(我理解为开始下一轮,类似一周签到七天七天结束下周又从周一开始签到) | ||||||
|  |         // 1. 回复:周三签到,day 要归 1 呀。连续签到哈; | ||||||
|         List<MemberSignInRecordDO> signInRecords = signInRecordMapper.selectListByUserId(userId); |         List<MemberSignInRecordDO> signInRecords = signInRecordMapper.selectListByUserId(userId); | ||||||
|         signInRecords.sort(Comparator.comparing(MemberSignInRecordDO::getCreateTime).reversed()); // 根据签到时间倒序 |         signInRecords.sort(Comparator.comparing(MemberSignInRecordDO::getCreateTime).reversed()); // 根据签到时间倒序 | ||||||
|         summary.setContinuousDay(calculateConsecutiveDays(signInRecords)); |         summary.setContinuousDay(calculateConsecutiveDays(signInRecords)); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV