1.优化部分任务处理接口
Showing
9 changed files
with
65 additions
and
66 deletions
| 1 | package com.topdraw.business.module.coupon.service.impl; | 1 | package com.topdraw.business.module.coupon.service.impl; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.coupon.domain.Coupon; | 3 | import com.topdraw.business.module.coupon.domain.Coupon; |
| 4 | import com.topdraw.config.RedisKeyConstants; | ||
| 4 | import com.topdraw.exception.GlobeExceptionMsg; | 5 | import com.topdraw.exception.GlobeExceptionMsg; |
| 5 | import com.topdraw.utils.ValidationUtil; | 6 | import com.topdraw.utils.ValidationUtil; |
| 6 | import com.topdraw.business.module.coupon.repository.CouponRepository; | 7 | import com.topdraw.business.module.coupon.repository.CouponRepository; |
| ... | @@ -8,6 +9,7 @@ import com.topdraw.business.module.coupon.service.CouponService; | ... | @@ -8,6 +9,7 @@ import com.topdraw.business.module.coupon.service.CouponService; |
| 8 | import com.topdraw.business.module.coupon.service.dto.CouponDTO; | 9 | import com.topdraw.business.module.coupon.service.dto.CouponDTO; |
| 9 | import com.topdraw.business.module.coupon.service.mapper.CouponMapper; | 10 | import com.topdraw.business.module.coupon.service.mapper.CouponMapper; |
| 10 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
| 12 | import org.springframework.cache.annotation.Cacheable; | ||
| 11 | import org.springframework.stereotype.Service; | 13 | import org.springframework.stereotype.Service; |
| 12 | import org.springframework.transaction.annotation.Propagation; | 14 | import org.springframework.transaction.annotation.Propagation; |
| 13 | import org.springframework.transaction.annotation.Transactional; | 15 | import org.springframework.transaction.annotation.Transactional; |
| ... | @@ -30,9 +32,9 @@ public class CouponServiceImpl implements CouponService { | ... | @@ -30,9 +32,9 @@ public class CouponServiceImpl implements CouponService { |
| 30 | private CouponRepository couponRepository; | 32 | private CouponRepository couponRepository; |
| 31 | 33 | ||
| 32 | @Override | 34 | @Override |
| 35 | @Cacheable(cacheNames = RedisKeyConstants.cacheCouponById, key = "#id", unless = "#result.id == null") | ||
| 33 | public CouponDTO findById(Long id) { | 36 | public CouponDTO findById(Long id) { |
| 34 | Assert.notNull(id, GlobeExceptionMsg.COUPON_ID_IS_NULL); | 37 | Assert.notNull(id, GlobeExceptionMsg.COUPON_ID_IS_NULL); |
| 35 | |||
| 36 | Coupon coupon = this.couponRepository.findById(id).orElseGet(Coupon::new); | 38 | Coupon coupon = this.couponRepository.findById(id).orElseGet(Coupon::new); |
| 37 | // ValidationUtil.isNull(coupon.getId(),"Coupon","id",id); | 39 | // ValidationUtil.isNull(coupon.getId(),"Coupon","id",id); |
| 38 | return this.couponMapper.toDto(coupon); | 40 | return this.couponMapper.toDto(coupon); | ... | ... |
| ... | @@ -17,6 +17,7 @@ import lombok.extern.slf4j.Slf4j; | ... | @@ -17,6 +17,7 @@ import lombok.extern.slf4j.Slf4j; |
| 17 | import org.apache.commons.lang3.StringUtils; | 17 | import org.apache.commons.lang3.StringUtils; |
| 18 | import org.springframework.beans.BeanUtils; | 18 | import org.springframework.beans.BeanUtils; |
| 19 | import org.springframework.beans.factory.annotation.Autowired; | 19 | import org.springframework.beans.factory.annotation.Autowired; |
| 20 | import org.springframework.cache.annotation.CachePut; | ||
| 20 | import org.springframework.stereotype.Service; | 21 | import org.springframework.stereotype.Service; |
| 21 | import org.springframework.transaction.annotation.Propagation; | 22 | import org.springframework.transaction.annotation.Propagation; |
| 22 | import org.springframework.transaction.annotation.Transactional; | 23 | import org.springframework.transaction.annotation.Transactional; |
| ... | @@ -55,6 +56,7 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -55,6 +56,7 @@ public class MemberServiceImpl implements MemberService { |
| 55 | } | 56 | } |
| 56 | 57 | ||
| 57 | @Override | 58 | @Override |
| 59 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#code") | ||
| 58 | public MemberDTO findByCode(String code) { | 60 | public MemberDTO findByCode(String code) { |
| 59 | Member member = this.memberRepository.findFirstByCode(code).orElseGet(Member::new); | 61 | Member member = this.memberRepository.findFirstByCode(code).orElseGet(Member::new); |
| 60 | return this.memberMapper.toDto(member); | 62 | return this.memberMapper.toDto(member); |
| ... | @@ -92,19 +94,28 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -92,19 +94,28 @@ public class MemberServiceImpl implements MemberService { |
| 92 | 94 | ||
| 93 | @Override | 95 | @Override |
| 94 | @Transactional(rollbackFor = Exception.class) | 96 | @Transactional(rollbackFor = Exception.class) |
| 97 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#code") | ||
| 95 | public MemberDTO doUpdateMemberExpAndLevel(Member resource) { | 98 | public MemberDTO doUpdateMemberExpAndLevel(Member resource) { |
| 99 | try { | ||
| 100 | this.redisUtils.doLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); | ||
| 96 | 101 | ||
| 97 | Integer count = this.memberRepository.updateExpAndLevel(resource); | 102 | Integer count = this.memberRepository.updateExpAndLevel(resource); |
| 98 | if (Objects.nonNull(count) && count > 0) { | 103 | if (Objects.nonNull(count) && count > 0) { |
| 99 | Member member = this.memberRepository.findById(resource.getId()).orElseGet(Member::new); | 104 | Member member = this.memberRepository.findById(resource.getId()).orElseGet(Member::new); |
| 100 | return this.memberMapper.toDto(member); | 105 | return this.memberMapper.toDto(member); |
| 101 | } | 106 | } |
| 107 | } catch (Exception e) { | ||
| 108 | log.info("修改会员优惠券,"+e.getMessage()); | ||
| 109 | } finally { | ||
| 110 | this.redisUtils.doUnLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); | ||
| 111 | } | ||
| 102 | 112 | ||
| 103 | return this.memberMapper.toDto(resource); | 113 | return this.memberMapper.toDto(resource); |
| 104 | } | 114 | } |
| 105 | 115 | ||
| 106 | @Override | 116 | @Override |
| 107 | @Transactional(rollbackFor = Exception.class) | 117 | @Transactional(rollbackFor = Exception.class) |
| 118 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#code") | ||
| 108 | public MemberDTO doUpdateMemberCoupon(Member resource) { | 119 | public MemberDTO doUpdateMemberCoupon(Member resource) { |
| 109 | log.info("修改会员优惠券 =>> {}", resource); | 120 | log.info("修改会员优惠券 =>> {}", resource); |
| 110 | try { | 121 | try { |
| ... | @@ -134,6 +145,7 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -134,6 +145,7 @@ public class MemberServiceImpl implements MemberService { |
| 134 | 145 | ||
| 135 | @Override | 146 | @Override |
| 136 | @Transactional(rollbackFor = Exception.class) | 147 | @Transactional(rollbackFor = Exception.class) |
| 148 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#code") | ||
| 137 | public MemberDTO doUpdateMemberVipAndVipExpireTime(Member resource) { | 149 | public MemberDTO doUpdateMemberVipAndVipExpireTime(Member resource) { |
| 138 | log.info("修改会员vip和vip过期时间 ==>> {}", resource); | 150 | log.info("修改会员vip和vip过期时间 ==>> {}", resource); |
| 139 | try { | 151 | try { |
| ... | @@ -156,6 +168,7 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -156,6 +168,7 @@ public class MemberServiceImpl implements MemberService { |
| 156 | 168 | ||
| 157 | @Override | 169 | @Override |
| 158 | @Transactional(rollbackFor = Exception.class) | 170 | @Transactional(rollbackFor = Exception.class) |
| 171 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#code") | ||
| 159 | public MemberDTO doUpdateMemberUserIptvIdAndBindIptvPlatformAndBindIptvTime(Member resource) { | 172 | public MemberDTO doUpdateMemberUserIptvIdAndBindIptvPlatformAndBindIptvTime(Member resource) { |
| 160 | log.info("修改会员绑定大屏信息 ==>> {}", resource); | 173 | log.info("修改会员绑定大屏信息 ==>> {}", resource); |
| 161 | try { | 174 | try { |
| ... | @@ -178,6 +191,7 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -178,6 +191,7 @@ public class MemberServiceImpl implements MemberService { |
| 178 | 191 | ||
| 179 | @Override | 192 | @Override |
| 180 | @Transactional(rollbackFor = Exception.class) | 193 | @Transactional(rollbackFor = Exception.class) |
| 194 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#code") | ||
| 181 | public MemberDTO doUpdateMemberAvatarUrlAndNicknameAndGender(Member resource) { | 195 | public MemberDTO doUpdateMemberAvatarUrlAndNicknameAndGender(Member resource) { |
| 182 | log.info("修改会员头像、昵称、性别 ==>> {}", resource); | 196 | log.info("修改会员头像、昵称、性别 ==>> {}", resource); |
| 183 | try { | 197 | try { |
| ... | @@ -218,6 +232,7 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -218,6 +232,7 @@ public class MemberServiceImpl implements MemberService { |
| 218 | 232 | ||
| 219 | @Override | 233 | @Override |
| 220 | @Transactional(rollbackFor = Exception.class) | 234 | @Transactional(rollbackFor = Exception.class) |
| 235 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#code") | ||
| 221 | public MemberDTO update(Member resources) { | 236 | public MemberDTO update(Member resources) { |
| 222 | log.info("修改会员信息 ==>> {}", resources); | 237 | log.info("修改会员信息 ==>> {}", resources); |
| 223 | try { | 238 | try { |
| ... | @@ -246,7 +261,10 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -246,7 +261,10 @@ public class MemberServiceImpl implements MemberService { |
| 246 | 261 | ||
| 247 | @Override | 262 | @Override |
| 248 | @Transactional(rollbackFor = Exception.class) | 263 | @Transactional(rollbackFor = Exception.class) |
| 264 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#code") | ||
| 249 | public MemberDTO doUpdateMemberPoints(Member resources) { | 265 | public MemberDTO doUpdateMemberPoints(Member resources) { |
| 266 | try { | ||
| 267 | this.redisUtils.doLock(RedisKeyConstants.updateCacheMemberById + resources.getId()); | ||
| 250 | 268 | ||
| 251 | Integer count = this.memberRepository.updatePointAndDuePoint(resources); | 269 | Integer count = this.memberRepository.updatePointAndDuePoint(resources); |
| 252 | if (Objects.nonNull(count) && count > 0) { | 270 | if (Objects.nonNull(count) && count > 0) { |
| ... | @@ -254,6 +272,12 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -254,6 +272,12 @@ public class MemberServiceImpl implements MemberService { |
| 254 | return this.memberMapper.toDto(member); | 272 | return this.memberMapper.toDto(member); |
| 255 | } | 273 | } |
| 256 | 274 | ||
| 275 | } catch (Exception e) { | ||
| 276 | log.info(e.getMessage()); | ||
| 277 | } finally { | ||
| 278 | this.redisUtils.doUnLock(RedisKeyConstants.updateCacheMemberById + resources.getId()); | ||
| 279 | } | ||
| 280 | |||
| 257 | return this.memberMapper.toDto(resources); | 281 | return this.memberMapper.toDto(resources); |
| 258 | } | 282 | } |
| 259 | 283 | ... | ... |
| 1 | package com.topdraw.business.module.rights.service.impl; | 1 | package com.topdraw.business.module.rights.service.impl; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.rights.domain.Rights; | 3 | import com.topdraw.business.module.rights.domain.Rights; |
| 4 | import com.topdraw.config.RedisKeyConstants; | ||
| 4 | import com.topdraw.utils.*; | 5 | import com.topdraw.utils.*; |
| 5 | import com.topdraw.business.module.rights.repository.RightsRepository; | 6 | import com.topdraw.business.module.rights.repository.RightsRepository; |
| 6 | import com.topdraw.business.module.rights.service.RightsService; | 7 | import com.topdraw.business.module.rights.service.RightsService; |
| 7 | import com.topdraw.business.module.rights.service.dto.RightsDTO; | 8 | import com.topdraw.business.module.rights.service.dto.RightsDTO; |
| 8 | import com.topdraw.business.module.rights.service.mapper.RightsMapper; | 9 | import com.topdraw.business.module.rights.service.mapper.RightsMapper; |
| 9 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
| 11 | import org.springframework.cache.annotation.Cacheable; | ||
| 10 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 11 | import org.springframework.transaction.annotation.Propagation; | 13 | import org.springframework.transaction.annotation.Propagation; |
| 12 | import org.springframework.transaction.annotation.Transactional; | 14 | import org.springframework.transaction.annotation.Transactional; |
| ... | @@ -25,9 +27,9 @@ public class RightsServiceImpl implements RightsService { | ... | @@ -25,9 +27,9 @@ public class RightsServiceImpl implements RightsService { |
| 25 | private RightsMapper rightsMapper; | 27 | private RightsMapper rightsMapper; |
| 26 | 28 | ||
| 27 | @Override | 29 | @Override |
| 30 | @Cacheable(cacheNames = RedisKeyConstants.cacheRightById, key = "#id", unless = "#result.id == null") | ||
| 28 | public RightsDTO findById(Long id) { | 31 | public RightsDTO findById(Long id) { |
| 29 | Rights Rights = this.rightsRepository.findById(id).orElseGet(Rights::new); | 32 | Rights Rights = this.rightsRepository.findById(id).orElseGet(Rights::new); |
| 30 | ValidationUtil.isNull(Rights.getId(),"Rights","id",id); | ||
| 31 | return this.rightsMapper.toDto(Rights); | 33 | return this.rightsMapper.toDto(Rights); |
| 32 | } | 34 | } |
| 33 | 35 | ... | ... |
| ... | @@ -151,6 +151,9 @@ public class Task implements Serializable { | ... | @@ -151,6 +151,9 @@ public class Task implements Serializable { |
| 151 | @Transient | 151 | @Transient |
| 152 | private String attr; | 152 | private String attr; |
| 153 | 153 | ||
| 154 | @Transient | ||
| 155 | private Integer event; | ||
| 156 | |||
| 154 | /** 创建时间 */ | 157 | /** 创建时间 */ |
| 155 | @CreatedDate | 158 | @CreatedDate |
| 156 | @Column(name = "create_time") | 159 | @Column(name = "create_time") | ... | ... |
member-service-impl/src/main/java/com/topdraw/business/module/task/service/impl/TaskServiceImpl.java
| ... | @@ -72,7 +72,7 @@ public class TaskServiceImpl implements TaskService { | ... | @@ -72,7 +72,7 @@ public class TaskServiceImpl implements TaskService { |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | @Override | 74 | @Override |
| 75 | // @Cacheable(value = RedisKeyConstants.cacheTaskByTaskTemplateId, key = "#event" , unless = "#result.size() == 0") | 75 | @Cacheable(value = RedisKeyConstants.cacheTaskByEvent, key = "#event" , unless = "#result.size() == 0") |
| 76 | public List<Task> findByEvent(Integer event) { | 76 | public List<Task> findByEvent(Integer event) { |
| 77 | log.info("从数据库查询事件列表 ==>> {}", event); | 77 | log.info("从数据库查询事件列表 ==>> {}", event); |
| 78 | return Objects.nonNull(event) ? this.taskRepository.findByEvent(event) : new ArrayList<>(); | 78 | return Objects.nonNull(event) ? this.taskRepository.findByEvent(event) : new ArrayList<>(); | ... | ... |
| ... | @@ -183,7 +183,6 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -183,7 +183,6 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 183 | } | 183 | } |
| 184 | }); | 184 | }); |
| 185 | 185 | ||
| 186 | |||
| 187 | // 其他权益 | 186 | // 其他权益 |
| 188 | this.threadPoolTaskExecutor.execute(()-> { | 187 | this.threadPoolTaskExecutor.execute(()-> { |
| 189 | log.info("发放其他权益开始 ==>> [{}]", tempRightsMap); | 188 | log.info("发放其他权益开始 ==>> [{}]", tempRightsMap); |
| ... | @@ -247,7 +246,7 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -247,7 +246,7 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 247 | Long memberId = right.getMemberId(); | 246 | Long memberId = right.getMemberId(); |
| 248 | Long userId = right.getUserId(); | 247 | Long userId = right.getUserId(); |
| 249 | // 权益类型 | 248 | // 权益类型 |
| 250 | RightsDTO rightsDTO = this.getRights(rightId); | 249 | RightsDTO rightsDTO = this.rightsService.findById(rightId); |
| 251 | // 权益的实体类型 1:积分;2成长值;3优惠券 | 250 | // 权益的实体类型 1:积分;2成长值;3优惠券 |
| 252 | Integer type = rightsDTO.getEntityType(); | 251 | Integer type = rightsDTO.getEntityType(); |
| 253 | Long expireTime1 = rightsDTO.getExpireTime(); | 252 | Long expireTime1 = rightsDTO.getExpireTime(); |
| ... | @@ -261,7 +260,7 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -261,7 +260,7 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 261 | case RightTypeConstants | 260 | case RightTypeConstants |
| 262 | .DISCOUNT_COUPON: | 261 | .DISCOUNT_COUPON: |
| 263 | Long entityId = rightsDTO.getEntityId(); | 262 | Long entityId = rightsDTO.getEntityId(); |
| 264 | CouponDTO couponDTO = this.findCouponById(entityId); | 263 | CouponDTO couponDTO = this.couponService.findById(entityId); |
| 265 | if (Objects.nonNull(couponDTO)) { | 264 | if (Objects.nonNull(couponDTO)) { |
| 266 | TempCoupon tempCoupon = new TempCoupon(); | 265 | TempCoupon tempCoupon = new TempCoupon(); |
| 267 | tempCoupon.setId(couponDTO.getId()); | 266 | tempCoupon.setId(couponDTO.getId()); |
| ... | @@ -294,27 +293,6 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -294,27 +293,6 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 294 | } | 293 | } |
| 295 | 294 | ||
| 296 | /** | 295 | /** |
| 297 | * 获取优惠券信息 | ||
| 298 | * @param id | ||
| 299 | * @return | ||
| 300 | */ | ||
| 301 | private CouponDTO findCouponById(Long id) { | ||
| 302 | CouponDTO couponDTO = this.couponService.findById(id); | ||
| 303 | return couponDTO; | ||
| 304 | } | ||
| 305 | |||
| 306 | /** | ||
| 307 | * 权益详情 | ||
| 308 | * @param rightsId | ||
| 309 | * @return | ||
| 310 | */ | ||
| 311 | private RightsDTO getRights(Long rightsId) { | ||
| 312 | RightsDTO rightsDTO = this.rightsService.findById(rightsId); | ||
| 313 | return rightsDTO; | ||
| 314 | } | ||
| 315 | |||
| 316 | |||
| 317 | /** | ||
| 318 | * 添加权益领取记录 | 296 | * 添加权益领取记录 |
| 319 | * @param rightsHistories | 297 | * @param rightsHistories |
| 320 | */ | 298 | */ | ... | ... |
| ... | @@ -53,6 +53,7 @@ import org.springframework.cache.annotation.CacheEvict; | ... | @@ -53,6 +53,7 @@ import org.springframework.cache.annotation.CacheEvict; |
| 53 | import org.springframework.cache.annotation.CachePut; | 53 | import org.springframework.cache.annotation.CachePut; |
| 54 | import org.springframework.data.redis.core.StringRedisTemplate; | 54 | import org.springframework.data.redis.core.StringRedisTemplate; |
| 55 | import org.springframework.data.redis.core.ValueOperations; | 55 | import org.springframework.data.redis.core.ValueOperations; |
| 56 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
| 56 | import org.springframework.stereotype.Service; | 57 | import org.springframework.stereotype.Service; |
| 57 | import org.springframework.util.CollectionUtils; | 58 | import org.springframework.util.CollectionUtils; |
| 58 | 59 | ||
| ... | @@ -97,7 +98,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -97,7 +98,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 97 | private RightsOperationService rightsOperationService; | 98 | private RightsOperationService rightsOperationService; |
| 98 | 99 | ||
| 99 | @Autowired | 100 | @Autowired |
| 100 | private RedisUtils redisUtils; | 101 | private ThreadPoolTaskExecutor threadPoolTaskExecutor; |
| 101 | 102 | ||
| 102 | @Value("${uc.validPriorityMember}") | 103 | @Value("${uc.validPriorityMember}") |
| 103 | private int validPriorityMember; | 104 | private int validPriorityMember; |
| ... | @@ -108,6 +109,8 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -108,6 +109,8 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 108 | private static final Integer POINTS_MIN = 1; | 109 | private static final Integer POINTS_MIN = 1; |
| 109 | 110 | ||
| 110 | 111 | ||
| 112 | |||
| 113 | |||
| 111 | @AsyncMqSend | 114 | @AsyncMqSend |
| 112 | public void asyncCreateTask(Task task) {} | 115 | public void asyncCreateTask(Task task) {} |
| 113 | @AsyncMqSend | 116 | @AsyncMqSend |
| ... | @@ -116,8 +119,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -116,8 +119,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 116 | public void asyncDeleteTask(Task task) {} | 119 | public void asyncDeleteTask(Task task) {} |
| 117 | 120 | ||
| 118 | @Override | 121 | @Override |
| 119 | /* @CachePut(cacheNames = RedisKeyConstants.cacheTaskByTaskTemplateId, key = "#task.taskTemplateId", | 122 | @CacheEvict(cacheNames = RedisKeyConstants.cacheTaskByEvent, key = "#task.event") |
| 120 | unless = "#result.id == null")*/ | ||
| 121 | public TaskDTO createTask(Task task) { | 123 | public TaskDTO createTask(Task task) { |
| 122 | Long taskTemplateId = task.getTaskTemplateId(); | 124 | Long taskTemplateId = task.getTaskTemplateId(); |
| 123 | TaskTemplateDTO taskTemplateDTO = this.taskTemplateService.findById(taskTemplateId); | 125 | TaskTemplateDTO taskTemplateDTO = this.taskTemplateService.findById(taskTemplateId); |
| ... | @@ -147,8 +149,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -147,8 +149,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 147 | } | 149 | } |
| 148 | 150 | ||
| 149 | @Override | 151 | @Override |
| 150 | /*@CachePut(cacheNames = RedisKeyConstants.cacheTaskByTaskTemplateId, key = "#task.taskTemplateId", | 152 | @CacheEvict(cacheNames = RedisKeyConstants.cacheTaskByEvent, key = "#task.event") |
| 151 | unless = "#result.id == null")*/ | ||
| 152 | public TaskDTO updateTask(Task task) { | 153 | public TaskDTO updateTask(Task task) { |
| 153 | Long taskTemplateId = task.getTaskTemplateId(); | 154 | Long taskTemplateId = task.getTaskTemplateId(); |
| 154 | TaskTemplateDTO taskTemplateDTO = this.taskTemplateService.findById(taskTemplateId); | 155 | TaskTemplateDTO taskTemplateDTO = this.taskTemplateService.findById(taskTemplateId); |
| ... | @@ -179,7 +180,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -179,7 +180,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 179 | } | 180 | } |
| 180 | 181 | ||
| 181 | @Override | 182 | @Override |
| 182 | /*@CacheEvict(cacheNames = "", key = "")*/ | 183 | @CacheEvict(cacheNames = RedisKeyConstants.cacheTaskByEvent, key = "#task.event") |
| 183 | public Integer deleteTask(Task task) { | 184 | public Integer deleteTask(Task task) { |
| 184 | Long id = task.getId(); | 185 | Long id = task.getId(); |
| 185 | TaskDTO taskDTO = this.findById(id); | 186 | TaskDTO taskDTO = this.findById(id); |
| ... | @@ -267,6 +268,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -267,6 +268,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 267 | String priorityMemberCode = userTvDTO.getPriorityMemberCode(); | 268 | String priorityMemberCode = userTvDTO.getPriorityMemberCode(); |
| 268 | 269 | ||
| 269 | if (StringUtils.isNotBlank(priorityMemberCode)) { | 270 | if (StringUtils.isNotBlank(priorityMemberCode)) { |
| 271 | // TODO 是否需要将code和id都进行缓存 | ||
| 270 | memberDTO = this.memberService.findByCode(priorityMemberCode); | 272 | memberDTO = this.memberService.findByCode(priorityMemberCode); |
| 271 | log.info("查询绑定的小屏的主会员信息, member ==>> {}", memberDTO); | 273 | log.info("查询绑定的小屏的主会员信息, member ==>> {}", memberDTO); |
| 272 | } else if (Objects.nonNull(userTvDTO.getMemberId())) { | 274 | } else if (Objects.nonNull(userTvDTO.getMemberId())) { |
| ... | @@ -336,11 +338,12 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -336,11 +338,12 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 336 | 338 | ||
| 337 | } | 339 | } |
| 338 | 340 | ||
| 339 | private void saveOrUpdateTaskProcess(Long memberId, Task task, Integer currentActionAmount) { | 341 | private void saveOrUpdateTaskProcess(Long id,Long memberId, Task task, Integer currentActionAmount, Integer status) { |
| 340 | TrTaskProgress trTaskProgress = new TrTaskProgress(); | 342 | TrTaskProgress trTaskProgress = new TrTaskProgress(); |
| 343 | trTaskProgress.setId(id); | ||
| 341 | trTaskProgress.setCurrentActionAmount(currentActionAmount); | 344 | trTaskProgress.setCurrentActionAmount(currentActionAmount); |
| 342 | trTaskProgress.setCompletionTime(TimestampUtil.now()); | 345 | trTaskProgress.setCompletionTime(TimestampUtil.now()); |
| 343 | trTaskProgress.setStatus(1); | 346 | trTaskProgress.setStatus(status); |
| 344 | trTaskProgress.setTaskId(task.getId()); | 347 | trTaskProgress.setTaskId(task.getId()); |
| 345 | trTaskProgress.setMemberId(memberId); | 348 | trTaskProgress.setMemberId(memberId); |
| 346 | trTaskProgress.setTargetActionAmount(task.getActionAmount()); | 349 | trTaskProgress.setTargetActionAmount(task.getActionAmount()); |
| ... | @@ -414,7 +417,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -414,7 +417,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 414 | tasksResult.add(task); | 417 | tasksResult.add(task); |
| 415 | 418 | ||
| 416 | log.info("保存开机、登录任务进度"); | 419 | log.info("保存开机、登录任务进度"); |
| 417 | this.saveOrUpdateTaskProcess(memberDTO.getId(), task, continueLogin); | 420 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, continueLogin, TASK_FINISH_STATUS); |
| 418 | } | 421 | } |
| 419 | } | 422 | } |
| 420 | break; | 423 | break; |
| ... | @@ -427,7 +430,8 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -427,7 +430,8 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 427 | tasksResult.add(task); | 430 | tasksResult.add(task); |
| 428 | 431 | ||
| 429 | log.info("保存观影任务进度"); | 432 | log.info("保存观影任务进度"); |
| 430 | this.saveOrUpdateTaskProcess(memberDTO.getId(), task, playDuration_); | 433 | |
| 434 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, playDuration_, TASK_FINISH_STATUS); | ||
| 431 | } | 435 | } |
| 432 | } | 436 | } |
| 433 | break; | 437 | break; |
| ... | @@ -455,7 +459,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -455,7 +459,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 455 | tasksResult.add(task); | 459 | tasksResult.add(task); |
| 456 | 460 | ||
| 457 | log.info("保存签到天数任务进度"); | 461 | log.info("保存签到天数任务进度"); |
| 458 | this.saveOrUpdateTaskProcess(memberDTO.getId(), task, signDays); | 462 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, signDays, TASK_FINISH_STATUS); |
| 459 | } | 463 | } |
| 460 | } | 464 | } |
| 461 | break; | 465 | break; |
| ... | @@ -468,7 +472,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -468,7 +472,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 468 | tasksResult.add(task); | 472 | tasksResult.add(task); |
| 469 | 473 | ||
| 470 | log.info("保存完成用户信息设置任务进度"); | 474 | log.info("保存完成用户信息设置任务进度"); |
| 471 | this.saveOrUpdateTaskProcess(memberDTO.getId(), task, completeCount); | 475 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, completeCount, TASK_FINISH_STATUS); |
| 472 | } | 476 | } |
| 473 | } | 477 | } |
| 474 | break; | 478 | break; |
| ... | @@ -481,7 +485,9 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -481,7 +485,9 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 481 | tasksResult.add(task); | 485 | tasksResult.add(task); |
| 482 | 486 | ||
| 483 | log.info("保存用户播放总时长任务进度"); | 487 | log.info("保存用户播放总时长任务进度"); |
| 484 | this.saveOrUpdateTaskProcess(memberDTO.getId(), task, playDuration); | 488 | threadPoolTaskExecutor.execute(() -> { |
| 489 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, playDuration, TASK_FINISH_STATUS); | ||
| 490 | }); | ||
| 485 | } | 491 | } |
| 486 | } | 492 | } |
| 487 | break; | 493 | break; |
| ... | @@ -494,7 +500,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -494,7 +500,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 494 | tasksResult.add(task); | 500 | tasksResult.add(task); |
| 495 | 501 | ||
| 496 | log.info("保存跨屏绑定任务进度"); | 502 | log.info("保存跨屏绑定任务进度"); |
| 497 | this.saveOrUpdateTaskProcess(memberDTO.getId(), task, bindCount); | 503 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, bindCount, TASK_FINISH_STATUS); |
| 498 | } | 504 | } |
| 499 | } | 505 | } |
| 500 | break; | 506 | break; |
| ... | @@ -511,7 +517,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -511,7 +517,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 511 | tasksResult.add(task); | 517 | tasksResult.add(task); |
| 512 | 518 | ||
| 513 | log.info("保存积分兑换商品任务进度"); | 519 | log.info("保存积分兑换商品任务进度"); |
| 514 | this.saveOrUpdateTaskProcess(memberDTO.getId(), task, exchangeCount); | 520 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, exchangeCount, TASK_FINISH_STATUS); |
| 515 | } | 521 | } |
| 516 | } | 522 | } |
| 517 | 523 | ||
| ... | @@ -702,7 +708,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -702,7 +708,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 702 | String nickname = memberDTO.getNickname(); | 708 | String nickname = memberDTO.getNickname(); |
| 703 | String memberCode = memberDTO.getCode(); | 709 | String memberCode = memberDTO.getCode(); |
| 704 | // 权益详情 | 710 | // 权益详情 |
| 705 | RightsDTO rightsDTO = this.getRight(rightsId); | 711 | RightsDTO rightsDTO = this.rightsService.findById(rightsId); |
| 706 | 712 | ||
| 707 | if (Objects.nonNull(rightsDTO)){ | 713 | if (Objects.nonNull(rightsDTO)){ |
| 708 | // 用以保存权益历史 | 714 | // 用以保存权益历史 |
| ... | @@ -720,7 +726,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -720,7 +726,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 720 | case RightTypeConstants.DISCOUNT_COUPON: | 726 | case RightTypeConstants.DISCOUNT_COUPON: |
| 721 | Long entityId1 = rightsDTO.getEntityId(); | 727 | Long entityId1 = rightsDTO.getEntityId(); |
| 722 | if (Objects.nonNull(entityId1)) { | 728 | if (Objects.nonNull(entityId1)) { |
| 723 | CouponDTO couponDTO = this.findCouponById(entityId1); | 729 | CouponDTO couponDTO = this.couponService.findById(entityId1); |
| 724 | if (Objects.nonNull(couponDTO.getId())) { | 730 | if (Objects.nonNull(couponDTO.getId())) { |
| 725 | // 优惠券 | 731 | // 优惠券 |
| 726 | TempCoupon tempCoupon = this.tempCouponBuild(memberId, memberCode,rightsAmount, rightsSendStrategy, couponDTO, nickname); | 732 | TempCoupon tempCoupon = this.tempCouponBuild(memberId, memberCode,rightsAmount, rightsSendStrategy, couponDTO, nickname); |
| ... | @@ -736,7 +742,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -736,7 +742,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 736 | case RightTypeConstants.VIEW_COUPON: | 742 | case RightTypeConstants.VIEW_COUPON: |
| 737 | Long entityId2 = rightsDTO.getEntityId(); | 743 | Long entityId2 = rightsDTO.getEntityId(); |
| 738 | if (Objects.nonNull(entityId2)) { | 744 | if (Objects.nonNull(entityId2)) { |
| 739 | CouponDTO couponDTO = this.findCouponById(entityId2); | 745 | CouponDTO couponDTO = this.couponService.findById(entityId2); |
| 740 | if (Objects.nonNull(couponDTO.getId())) { | 746 | if (Objects.nonNull(couponDTO.getId())) { |
| 741 | // 优惠券 | 747 | // 优惠券 |
| 742 | TempCoupon tempCoupon = this.tempCouponBuild(memberId, memberCode,rightsAmount, rightsSendStrategy, couponDTO, nickname); | 748 | TempCoupon tempCoupon = this.tempCouponBuild(memberId, memberCode,rightsAmount, rightsSendStrategy, couponDTO, nickname); |
| ... | @@ -771,26 +777,6 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -771,26 +777,6 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 771 | } | 777 | } |
| 772 | 778 | ||
| 773 | /** | 779 | /** |
| 774 | * 获取优惠券信息 | ||
| 775 | * @param id | ||
| 776 | * @return | ||
| 777 | */ | ||
| 778 | private CouponDTO findCouponById(Long id) { | ||
| 779 | CouponDTO couponDTO = this.couponService.findById(id); | ||
| 780 | return couponDTO; | ||
| 781 | } | ||
| 782 | |||
| 783 | /** | ||
| 784 | * | ||
| 785 | * @param rightsId | ||
| 786 | * @return | ||
| 787 | */ | ||
| 788 | private RightsDTO getRight(Long rightsId) { | ||
| 789 | RightsDTO rightsDTO = this.rightsService.findById(rightsId); | ||
| 790 | return rightsDTO; | ||
| 791 | } | ||
| 792 | |||
| 793 | /** | ||
| 794 | * 成长值 | 780 | * 成长值 |
| 795 | * @param task | 781 | * @param task |
| 796 | * @return | 782 | * @return | ... | ... |
| ... | @@ -84,7 +84,7 @@ public class MemberOperationServiceImpl implements MemberOperationService { | ... | @@ -84,7 +84,7 @@ public class MemberOperationServiceImpl implements MemberOperationService { |
| 84 | 84 | ||
| 85 | 85 | ||
| 86 | @Override | 86 | @Override |
| 87 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberById, key = "#member.id") | 87 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#member.code", unless = "#result.id == null") |
| 88 | public MemberDTO doUpdateMemberCoupon(Member member) { | 88 | public MemberDTO doUpdateMemberCoupon(Member member) { |
| 89 | return this.memberService.doUpdateMemberCoupon(member); | 89 | return this.memberService.doUpdateMemberCoupon(member); |
| 90 | } | 90 | } | ... | ... |
| ... | @@ -12,6 +12,7 @@ package com.topdraw.config; | ... | @@ -12,6 +12,7 @@ package com.topdraw.config; |
| 12 | public interface RedisKeyConstants { | 12 | public interface RedisKeyConstants { |
| 13 | 13 | ||
| 14 | String cacheMemberById = "uce::member::id"; | 14 | String cacheMemberById = "uce::member::id"; |
| 15 | String cacheMemberByCode = "uce::member::code"; | ||
| 15 | String updateCacheMemberById = "uce::updateMember::id"; | 16 | String updateCacheMemberById = "uce::updateMember::id"; |
| 16 | 17 | ||
| 17 | String updateCachePointsByMemberId = "uce::updatePoints::memberId"; | 18 | String updateCachePointsByMemberId = "uce::updatePoints::memberId"; |
| ... | @@ -21,4 +22,7 @@ public interface RedisKeyConstants { | ... | @@ -21,4 +22,7 @@ public interface RedisKeyConstants { |
| 21 | String cacheUserTvByPlatformAccount = "uce::userTv::platformAccount"; | 22 | String cacheUserTvByPlatformAccount = "uce::userTv::platformAccount"; |
| 22 | String cacheTaskProcessByMemberId = "uce::taskProcess::memberId"; | 23 | String cacheTaskProcessByMemberId = "uce::taskProcess::memberId"; |
| 23 | String cacheTaskByTaskTemplateId = "uce::task::taskTemplateId"; | 24 | String cacheTaskByTaskTemplateId = "uce::task::taskTemplateId"; |
| 25 | String cacheTaskByEvent = "uce::task::event"; | ||
| 26 | String cacheCouponById = "uce::coupon::id"; | ||
| 27 | String cacheRightById = "uce::right::id"; | ||
| 24 | } | 28 | } | ... | ... |
-
Please register or sign in to post a comment