1.优化任务处理执行
2.为任务处理添加缓存
Showing
29 changed files
with
296 additions
and
482 deletions
| ... | @@ -3,6 +3,9 @@ package com.topdraw.business.module.exp.detail.repository; | ... | @@ -3,6 +3,9 @@ package com.topdraw.business.module.exp.detail.repository; |
| 3 | import com.topdraw.business.module.exp.detail.domain.ExpDetail; | 3 | import com.topdraw.business.module.exp.detail.domain.ExpDetail; |
| 4 | import org.springframework.data.jpa.repository.JpaRepository; | 4 | import org.springframework.data.jpa.repository.JpaRepository; |
| 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
| 6 | import org.springframework.data.jpa.repository.Modifying; | ||
| 7 | import org.springframework.data.jpa.repository.Query; | ||
| 8 | import org.springframework.data.repository.query.Param; | ||
| 6 | 9 | ||
| 7 | import java.util.Optional; | 10 | import java.util.Optional; |
| 8 | 11 | ||
| ... | @@ -13,4 +16,15 @@ import java.util.Optional; | ... | @@ -13,4 +16,15 @@ import java.util.Optional; |
| 13 | public interface ExpDetailRepository extends JpaRepository<ExpDetail, Long>, JpaSpecificationExecutor<ExpDetail> { | 16 | public interface ExpDetailRepository extends JpaRepository<ExpDetail, Long>, JpaSpecificationExecutor<ExpDetail> { |
| 14 | 17 | ||
| 15 | Optional<ExpDetail> findFirstByCode(String code); | 18 | Optional<ExpDetail> findFirstByCode(String code); |
| 19 | |||
| 20 | |||
| 21 | |||
| 22 | |||
| 23 | @Modifying | ||
| 24 | @Query(value = "INSERT INTO `uc_exp_detail`(`code`, `member_id`, `account_id`, `original_exp`, `result_exp`, `exp`, " + | ||
| 25 | "`device_type`, `evt_type`, `order_id`, `media_id`, `activity_id`, `description`, `app_code`, `create_time`, `update_time`)\n" + | ||
| 26 | " VALUES (:#{#resources.code}, :#{#resources.memberId}, :#{#resources.accountId}, :#{#resources.originalExp}, " + | ||
| 27 | " :#{#resources.resultExp}, :#{#resources.exp}, :#{#resources.deviceType}, :#{#resources.evtType}, " + | ||
| 28 | " :#{#resources.orderId}, :#{#resources.mediaId}, :#{#resources.activityId}, '#', NULL, now(), now())", nativeQuery = true) | ||
| 29 | void insertIntoExpDetail(@Param("resources") ExpDetail expDetail); | ||
| 16 | } | 30 | } | ... | ... |
| ... | @@ -44,7 +44,7 @@ public class ExpDetailServiceImpl implements ExpDetailService { | ... | @@ -44,7 +44,7 @@ public class ExpDetailServiceImpl implements ExpDetailService { |
| 44 | @Transactional(rollbackFor = Exception.class) | 44 | @Transactional(rollbackFor = Exception.class) |
| 45 | public void create(ExpDetail resources) { | 45 | public void create(ExpDetail resources) { |
| 46 | ExpDetail expDetail = ExpDetailBuilder.build(resources); | 46 | ExpDetail expDetail = ExpDetailBuilder.build(resources); |
| 47 | this.expDetailRepository.save(expDetail); | 47 | this.expDetailRepository.insertIntoExpDetail(expDetail); |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | @Override | 50 | @Override | ... | ... |
| ... | @@ -15,5 +15,5 @@ public interface MemberLevelRepository extends JpaRepository<MemberLevel, Long>, | ... | @@ -15,5 +15,5 @@ public interface MemberLevelRepository extends JpaRepository<MemberLevel, Long>, |
| 15 | 15 | ||
| 16 | Optional<MemberLevel> findFirstByCode(String code); | 16 | Optional<MemberLevel> findFirstByCode(String code); |
| 17 | 17 | ||
| 18 | List<MemberLevel> findByLevelAndStatus(Integer level, Integer status); | 18 | Optional<MemberLevel> findByLevelAndStatus(Integer level, Integer status); |
| 19 | } | 19 | } | ... | ... |
| ... | @@ -25,12 +25,9 @@ public interface MemberLevelService { | ... | @@ -25,12 +25,9 @@ public interface MemberLevelService { |
| 25 | MemberLevelDTO getByCode(String code); | 25 | MemberLevelDTO getByCode(String code); |
| 26 | 26 | ||
| 27 | /** | 27 | /** |
| 28 | * 通过等级和状态检索 | 28 | * |
| 29 | * @param i | 29 | * @param i |
| 30 | * @param status | ||
| 31 | * @return | 30 | * @return |
| 32 | */ | 31 | */ |
| 33 | List<MemberLevelDTO> findLevelAndStatus(Integer i, Integer status); | 32 | MemberLevelDTO findByLevel(int i); |
| 34 | |||
| 35 | |||
| 36 | } | 33 | } | ... | ... |
| ... | @@ -31,6 +31,7 @@ public class MemberLevelServiceImpl implements MemberLevelService { | ... | @@ -31,6 +31,7 @@ public class MemberLevelServiceImpl implements MemberLevelService { |
| 31 | private MemberLevelMapper memberLevelMapper; | 31 | private MemberLevelMapper memberLevelMapper; |
| 32 | 32 | ||
| 33 | @Override | 33 | @Override |
| 34 | @Transactional(readOnly = true) | ||
| 34 | public MemberLevelDTO findById(Long id) { | 35 | public MemberLevelDTO findById(Long id) { |
| 35 | MemberLevel MemberLevel = this.memberLevelRepository.findById(id).orElseGet(MemberLevel::new); | 36 | MemberLevel MemberLevel = this.memberLevelRepository.findById(id).orElseGet(MemberLevel::new); |
| 36 | ValidationUtil.isNull(MemberLevel.getId(),"MemberLevel","id",id); | 37 | ValidationUtil.isNull(MemberLevel.getId(),"MemberLevel","id",id); |
| ... | @@ -38,15 +39,18 @@ public class MemberLevelServiceImpl implements MemberLevelService { | ... | @@ -38,15 +39,18 @@ public class MemberLevelServiceImpl implements MemberLevelService { |
| 38 | } | 39 | } |
| 39 | 40 | ||
| 40 | @Override | 41 | @Override |
| 42 | @Transactional(readOnly = true) | ||
| 41 | public MemberLevelDTO getByCode(String code) { | 43 | public MemberLevelDTO getByCode(String code) { |
| 42 | return StringUtils.isNotEmpty(code) ? this.memberLevelMapper.toDto(this.memberLevelRepository.findFirstByCode(code).orElseGet(MemberLevel::new)) | 44 | return StringUtils.isNotEmpty(code) ? this.memberLevelMapper.toDto(this.memberLevelRepository.findFirstByCode(code).orElseGet(MemberLevel::new)) |
| 43 | : new MemberLevelDTO(); | 45 | : new MemberLevelDTO(); |
| 44 | } | 46 | } |
| 45 | 47 | ||
| 46 | @Override | 48 | @Override |
| 47 | @Cacheable(cacheNames = RedisKeyConstants.cacheMemberLevelByLevel, key = "#level", unless = "#result.size() == 0") | 49 | @Transactional(readOnly = true) |
| 48 | public List<MemberLevelDTO> findLevelAndStatus(Integer level, Integer status) { | 50 | @Cacheable(cacheNames = RedisKeyConstants.cacheMemberLevelByLevel, key = "#level", unless = "#result.id == null") |
| 49 | return this.memberLevelMapper.toDto(this.memberLevelRepository.findByLevelAndStatus(level, status)); | 51 | public MemberLevelDTO findByLevel(int level) { |
| 52 | MemberLevel memberLevel = this.memberLevelRepository.findByLevelAndStatus(level, 1).orElseGet(MemberLevel::new); | ||
| 53 | return this.memberLevelMapper.toDto(memberLevel); | ||
| 50 | } | 54 | } |
| 51 | 55 | ||
| 52 | } | 56 | } | ... | ... |
| ... | @@ -30,20 +30,16 @@ public interface MemberRepository extends JpaRepository<Member, Long>, JpaSpecif | ... | @@ -30,20 +30,16 @@ public interface MemberRepository extends JpaRepository<Member, Long>, JpaSpecif |
| 30 | void updateUserIptvIdById(Long id, Long userIptvId, LocalDateTime now); | 30 | void updateUserIptvIdById(Long id, Long userIptvId, LocalDateTime now); |
| 31 | 31 | ||
| 32 | @Modifying | 32 | @Modifying |
| 33 | @Query(value = "UPDATE `uc_member` SET `exp` = :#{#resources.exp}, " + | 33 | @Query(value = "UPDATE `uc_member` SET `exp` = :#{#resources.exp}, `level` = :#{#resources.level} , `update_time`= now() " + |
| 34 | "`level` = :#{#resources.level} , `update_time`= now() " + | ||
| 35 | " WHERE `id` = :#{#resources.id}", nativeQuery = true) | 34 | " WHERE `id` = :#{#resources.id}", nativeQuery = true) |
| 36 | Integer updateExpAndLevel(@Param("resources") Member member); | 35 | Integer updateExpAndLevel(@Param("resources") Member member); |
| 37 | 36 | ||
| 38 | @Modifying | 37 | @Modifying |
| 39 | @Query(value = "UPDATE `uc_member` SET `points` = :#{#resources.points}, " + | 38 | @Query(value = "UPDATE `uc_member` SET `points` = :#{#resources.points}, `update_time`= now() WHERE `id` = :#{#resources.id}", nativeQuery = true) |
| 40 | "`due_points` = :#{#resources.duePoints} , `update_time`= now() " + | ||
| 41 | " WHERE `id` = :#{#resources.id}", nativeQuery = true) | ||
| 42 | Integer updatePointAndDuePoint(@Param("resources") Member resources); | 39 | Integer updatePointAndDuePoint(@Param("resources") Member resources); |
| 43 | 40 | ||
| 44 | @Modifying | 41 | @Modifying |
| 45 | @Query(value = "UPDATE `uc_member` SET `coupon_amount` = :#{#resources.couponAmount}, " + | 42 | @Query(value = "UPDATE `uc_member` SET `coupon_amount` = :#{#resources.couponAmount}, `due_coupon_amount` = :#{#resources.dueCouponAmount} , `update_time`= now() " + |
| 46 | "`due_coupon_amount` = :#{#resources.dueCouponAmount} , `update_time`= now() " + | ||
| 47 | " WHERE `id` = :#{#resources.id}", nativeQuery = true) | 43 | " WHERE `id` = :#{#resources.id}", nativeQuery = true) |
| 48 | Integer doUpdateMemberCoupon(@Param("resources") Member member); | 44 | Integer doUpdateMemberCoupon(@Param("resources") Member member); |
| 49 | 45 | ||
| ... | @@ -52,20 +48,20 @@ public interface MemberRepository extends JpaRepository<Member, Long>, JpaSpecif | ... | @@ -52,20 +48,20 @@ public interface MemberRepository extends JpaRepository<Member, Long>, JpaSpecif |
| 52 | Optional<Member> findByPlatformAccount(String platformAccount); | 48 | Optional<Member> findByPlatformAccount(String platformAccount); |
| 53 | 49 | ||
| 54 | @Modifying | 50 | @Modifying |
| 55 | @Query(value = "UPDATE `uc_member` SET `vip` = :#{#resources.vip}, " + | 51 | @Query(value = "UPDATE `uc_member` SET `vip` = :#{#resources.vip}, `vip_expire_time` = :#{#resources.vipExpireTime} , `update_time`= now() " + |
| 56 | "`vip_expire_time` = :#{#resources.vipExpireTime} , `update_time`= now() " + | ||
| 57 | " WHERE `id` = :#{#resources.id}", nativeQuery = true) | 52 | " WHERE `id` = :#{#resources.id}", nativeQuery = true) |
| 58 | Integer updateMemberVipAndVipExpireTime(@Param("resources") Member member); | 53 | Integer updateMemberVipAndVipExpireTime(@Param("resources") Member member); |
| 59 | 54 | ||
| 60 | @Modifying | 55 | @Modifying |
| 61 | @Query(value = "UPDATE `uc_member` SET `user_iptv_id` = :#{#resources.userIptvId}, `update_time` = now() , " + | 56 | @Query(value = "UPDATE `uc_member` SET `user_iptv_id` = :#{#resources.userIptvId}, `update_time` = now() , `bind_iptv_platform_type`= :#{#resources.bindIptvPlatformType}, " + |
| 62 | " `bind_iptv_platform_type`= :#{#resources.bindIptvPlatformType}, " + | ||
| 63 | " `bind_iptv_time`=:#{#resources.bindIptvTime} WHERE `id` = :#{#resources.id}", nativeQuery = true) | 57 | " `bind_iptv_time`=:#{#resources.bindIptvTime} WHERE `id` = :#{#resources.id}", nativeQuery = true) |
| 64 | Integer updateMemberUserIptvIdAndBindIptvPlatformAndBindIptvTime(@Param("resources") Member member); | 58 | Integer updateMemberUserIptvIdAndBindIptvPlatformAndBindIptvTime(@Param("resources") Member member); |
| 65 | 59 | ||
| 66 | @Modifying | 60 | @Modifying |
| 67 | @Query(value = "UPDATE `uc_member` SET `avatar_url` = :#{#resources.avatarUrl}, `update_time` = now() , " + | 61 | @Query(value = "UPDATE `uc_member` SET `avatar_url` = :#{#resources.avatarUrl}, `update_time` = now() , `nickname`= :#{#resources.nickname}, " + |
| 68 | " `nickname`= :#{#resources.nickname}, " + | ||
| 69 | " `gender`=:#{#resources.gender} WHERE `id` = :#{#resources.id}", nativeQuery = true) | 62 | " `gender`=:#{#resources.gender} WHERE `id` = :#{#resources.id}", nativeQuery = true) |
| 70 | Integer updateMemberAvatarUrlAndNicknameAndGender(@Param("resources") Member resource); | 63 | Integer updateMemberAvatarUrlAndNicknameAndGender(@Param("resources") Member resource); |
| 64 | |||
| 65 | @Query(value = "SELECT IFNULL(`exp`,0) AS exp FROM uc_member WHERE `id` = ?1 ", nativeQuery = true) | ||
| 66 | Long findExpByMemberId(Long memberId); | ||
| 71 | } | 67 | } | ... | ... |
| ... | @@ -65,7 +65,7 @@ public interface MemberService { | ... | @@ -65,7 +65,7 @@ public interface MemberService { |
| 65 | * 修改会员积分 | 65 | * 修改会员积分 |
| 66 | * @param member 会员 | 66 | * @param member 会员 |
| 67 | */ | 67 | */ |
| 68 | MemberDTO doUpdateMemberPoints(Member member); | 68 | Integer doUpdateMemberPoints(Member member); |
| 69 | 69 | ||
| 70 | /** | 70 | /** |
| 71 | * 查询绑定了大屏会员列表 | 71 | * 查询绑定了大屏会员列表 |
| ... | @@ -92,14 +92,14 @@ public interface MemberService { | ... | @@ -92,14 +92,14 @@ public interface MemberService { |
| 92 | * @param resources | 92 | * @param resources |
| 93 | * @return | 93 | * @return |
| 94 | */ | 94 | */ |
| 95 | MemberDTO doUpdateMemberExpAndLevel(Member resources); | 95 | Integer doUpdateMemberExpAndLevel(Member resources); |
| 96 | 96 | ||
| 97 | /** | 97 | /** |
| 98 | * | 98 | * |
| 99 | * @param member | 99 | * @param member |
| 100 | * @return | 100 | * @return |
| 101 | */ | 101 | */ |
| 102 | MemberDTO doUpdateMemberCoupon(Member member); | 102 | Integer doUpdateMemberCoupon(Member member); |
| 103 | 103 | ||
| 104 | /** | 104 | /** |
| 105 | * | 105 | * |
| ... | @@ -127,4 +127,12 @@ public interface MemberService { | ... | @@ -127,4 +127,12 @@ public interface MemberService { |
| 127 | * @param member | 127 | * @param member |
| 128 | */ | 128 | */ |
| 129 | MemberDTO doUpdateMemberAvatarUrlAndNicknameAndGender(Member member); | 129 | MemberDTO doUpdateMemberAvatarUrlAndNicknameAndGender(Member member); |
| 130 | |||
| 131 | /** | ||
| 132 | * | ||
| 133 | * @param memberId | ||
| 134 | * @return | ||
| 135 | */ | ||
| 136 | Long findExpByMemberId(Long memberId); | ||
| 137 | |||
| 130 | } | 138 | } | ... | ... |
| 1 | package com.topdraw.business.module.member.service.impl; | 1 | package com.topdraw.business.module.member.service.impl; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSON; | ||
| 4 | import com.alibaba.fastjson.JSONObject; | ||
| 3 | import com.topdraw.business.module.member.domain.Member; | 5 | import com.topdraw.business.module.member.domain.Member; |
| 4 | import com.topdraw.business.module.member.domain.MemberBuilder; | 6 | import com.topdraw.business.module.member.domain.MemberBuilder; |
| 5 | import com.topdraw.business.module.member.domain.MemberSimple; | 7 | import com.topdraw.business.module.member.domain.MemberSimple; |
| ... | @@ -16,6 +18,7 @@ import com.topdraw.business.module.member.service.mapper.MemberSimpleMapper; | ... | @@ -16,6 +18,7 @@ import com.topdraw.business.module.member.service.mapper.MemberSimpleMapper; |
| 16 | import com.topdraw.config.RedisKeyConstants; | 18 | import com.topdraw.config.RedisKeyConstants; |
| 17 | import com.topdraw.exception.BadRequestException; | 19 | import com.topdraw.exception.BadRequestException; |
| 18 | import com.topdraw.exception.GlobeExceptionMsg; | 20 | import com.topdraw.exception.GlobeExceptionMsg; |
| 21 | import com.topdraw.utils.RedisUtils; | ||
| 19 | import lombok.extern.slf4j.Slf4j; | 22 | import lombok.extern.slf4j.Slf4j; |
| 20 | import org.apache.commons.lang3.StringUtils; | 23 | import org.apache.commons.lang3.StringUtils; |
| 21 | import org.springframework.beans.BeanUtils; | 24 | import org.springframework.beans.BeanUtils; |
| ... | @@ -48,6 +51,9 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -48,6 +51,9 @@ public class MemberServiceImpl implements MemberService { |
| 48 | @Autowired | 51 | @Autowired |
| 49 | private MemberSimpleMapper memberSimpleMapper; | 52 | private MemberSimpleMapper memberSimpleMapper; |
| 50 | 53 | ||
| 54 | @Autowired | ||
| 55 | private RedisUtils redisUtils; | ||
| 56 | |||
| 51 | @Override | 57 | @Override |
| 52 | @Transactional(readOnly = true) | 58 | @Transactional(readOnly = true) |
| 53 | public String findCodeById(Long id) { | 59 | public String findCodeById(Long id) { |
| ... | @@ -57,7 +63,7 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -57,7 +63,7 @@ public class MemberServiceImpl implements MemberService { |
| 57 | 63 | ||
| 58 | @Override | 64 | @Override |
| 59 | @Transactional(readOnly = true) | 65 | @Transactional(readOnly = true) |
| 60 | @Cacheable(cacheNames = RedisKeyConstants.cacheMemberById, key = "#id") | 66 | // @Cacheable(cacheNames = RedisKeyConstants.cacheMemberById, key = "#id") |
| 61 | public MemberDTO findById(Long id) { | 67 | public MemberDTO findById(Long id) { |
| 62 | Member member = this.memberRepository.findById(id).orElseGet(Member::new); | 68 | Member member = this.memberRepository.findById(id).orElseGet(Member::new); |
| 63 | return this.memberMapper.toDto(member); | 69 | return this.memberMapper.toDto(member); |
| ... | @@ -66,9 +72,19 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -66,9 +72,19 @@ public class MemberServiceImpl implements MemberService { |
| 66 | 72 | ||
| 67 | @Override | 73 | @Override |
| 68 | @Transactional(readOnly = true) | 74 | @Transactional(readOnly = true) |
| 69 | @Cacheable(cacheNames = RedisKeyConstants.cacheMemberSimpleById, key = "#id", unless = "#result.id == null") | ||
| 70 | public MemberSimpleDTO findSimpleById(Long id) { | 75 | public MemberSimpleDTO findSimpleById(Long id) { |
| 71 | return this.memberSimpleMapper.toDto(this.memberSimpleRepository.findSimpleById(id).orElseGet(MemberSimple::new)); | 76 | Object memberSimpleRedis = this.redisUtils.get(RedisKeyConstants.cacheMemberSimpleById + "::" + id); |
| 77 | if (Objects.nonNull(memberSimpleRedis)) { | ||
| 78 | return JSONObject.parseObject(JSON.toJSONString(memberSimpleRedis), MemberSimpleDTO.class); | ||
| 79 | } | ||
| 80 | |||
| 81 | MemberSimple memberSimple = this.memberSimpleRepository.findSimpleById(id).orElseGet(MemberSimple::new); | ||
| 82 | if (Objects.nonNull(memberSimple.getId())) { | ||
| 83 | MemberSimpleDTO memberSimpleDTO = new MemberSimpleDTO(); | ||
| 84 | BeanUtils.copyProperties(memberSimple, memberSimpleDTO); | ||
| 85 | this.redisUtils.set(RedisKeyConstants.cacheMemberSimpleById + "::" + id, memberSimpleDTO); | ||
| 86 | } | ||
| 87 | return this.memberSimpleMapper.toDto(memberSimple); | ||
| 72 | } | 88 | } |
| 73 | 89 | ||
| 74 | @Override | 90 | @Override |
| ... | @@ -80,7 +96,7 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -80,7 +96,7 @@ public class MemberServiceImpl implements MemberService { |
| 80 | 96 | ||
| 81 | @Override | 97 | @Override |
| 82 | @Transactional(readOnly = true) | 98 | @Transactional(readOnly = true) |
| 83 | @Cacheable(cacheNames = RedisKeyConstants.cacheMemberSimpleById, key = "#id", unless = "#result.id == null") | 99 | @Cacheable(cacheNames = RedisKeyConstants.cacheMemberSimpleByCode, key = "#code", unless = "#result.id == null") |
| 84 | public MemberSimpleDTO findSimpleByCode(String code) { | 100 | public MemberSimpleDTO findSimpleByCode(String code) { |
| 85 | return this.memberSimpleMapper.toDto(this.memberSimpleRepository.findSimpleByCode(code).orElseGet(MemberSimple::new)); | 101 | return this.memberSimpleMapper.toDto(this.memberSimpleRepository.findSimpleByCode(code).orElseGet(MemberSimple::new)); |
| 86 | } | 102 | } |
| ... | @@ -118,46 +134,15 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -118,46 +134,15 @@ public class MemberServiceImpl implements MemberService { |
| 118 | 134 | ||
| 119 | @Override | 135 | @Override |
| 120 | @Transactional(rollbackFor = Exception.class) | 136 | @Transactional(rollbackFor = Exception.class) |
| 121 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#resource.code") | 137 | public Integer doUpdateMemberExpAndLevel(Member resource) { |
| 122 | public MemberDTO doUpdateMemberExpAndLevel(Member resource) { | 138 | return this.memberRepository.updateExpAndLevel(resource); |
| 123 | try { | ||
| 124 | // this.redisUtils.doLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); | ||
| 125 | |||
| 126 | Integer count = this.memberRepository.updateExpAndLevel(resource); | ||
| 127 | if (Objects.nonNull(count) && count > 0) { | ||
| 128 | Member member = this.memberRepository.findById(resource.getId()).orElseGet(Member::new); | ||
| 129 | return this.memberMapper.toDto(member); | ||
| 130 | } | ||
| 131 | } catch (Exception e) { | ||
| 132 | log.info("修改会员优惠券,"+e.getMessage()); | ||
| 133 | } finally { | ||
| 134 | // this.redisUtils.doUnLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); | ||
| 135 | } | ||
| 136 | |||
| 137 | return this.memberMapper.toDto(resource); | ||
| 138 | } | 139 | } |
| 139 | 140 | ||
| 140 | @Override | 141 | @Override |
| 141 | @Transactional(rollbackFor = Exception.class) | 142 | @Transactional(rollbackFor = Exception.class) |
| 142 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#resource.code") | 143 | // @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#resource.code") |
| 143 | public MemberDTO doUpdateMemberCoupon(Member resource) { | 144 | public Integer doUpdateMemberCoupon(Member resource) { |
| 144 | log.info("修改会员优惠券 =>> {}", resource); | 145 | return this.memberRepository.doUpdateMemberCoupon(resource); |
| 145 | try { | ||
| 146 | // this.redisUtils.doLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); | ||
| 147 | |||
| 148 | Integer count = this.memberRepository.doUpdateMemberCoupon(resource); | ||
| 149 | if (Objects.nonNull(count) && count > 0) { | ||
| 150 | Member member = this.memberRepository.findById(resource.getId()).orElseGet(Member::new); | ||
| 151 | return this.memberMapper.toDto(member); | ||
| 152 | } | ||
| 153 | |||
| 154 | } catch (Exception e) { | ||
| 155 | log.info("修改会员优惠券,"+e.getMessage()); | ||
| 156 | } finally { | ||
| 157 | // this.redisUtils.doUnLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); | ||
| 158 | } | ||
| 159 | |||
| 160 | return this.memberMapper.toDto(resource); | ||
| 161 | } | 146 | } |
| 162 | 147 | ||
| 163 | @Override | 148 | @Override |
| ... | @@ -237,6 +222,12 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -237,6 +222,12 @@ public class MemberServiceImpl implements MemberService { |
| 237 | return this.memberMapper.toDto(resource); | 222 | return this.memberMapper.toDto(resource); |
| 238 | } | 223 | } |
| 239 | 224 | ||
| 225 | @Override | ||
| 226 | @Transactional(readOnly = true) | ||
| 227 | public Long findExpByMemberId(Long memberId) { | ||
| 228 | return this.memberRepository.findExpByMemberId(memberId); | ||
| 229 | } | ||
| 230 | |||
| 240 | 231 | ||
| 241 | @Override | 232 | @Override |
| 242 | @Transactional(rollbackFor = Exception.class) | 233 | @Transactional(rollbackFor = Exception.class) |
| ... | @@ -286,24 +277,8 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -286,24 +277,8 @@ public class MemberServiceImpl implements MemberService { |
| 286 | 277 | ||
| 287 | @Override | 278 | @Override |
| 288 | @Transactional(rollbackFor = Exception.class) | 279 | @Transactional(rollbackFor = Exception.class) |
| 289 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#resources.code") | 280 | public Integer doUpdateMemberPoints(Member resources) { |
| 290 | public MemberDTO doUpdateMemberPoints(Member resources) { | 281 | return this.memberRepository.updatePointAndDuePoint(resources); |
| 291 | try { | ||
| 292 | // this.redisUtils.doLock(RedisKeyConstants.updateCacheMemberById + resources.getId()); | ||
| 293 | |||
| 294 | Integer count = this.memberRepository.updatePointAndDuePoint(resources); | ||
| 295 | if (Objects.nonNull(count) && count > 0) { | ||
| 296 | Member member = this.memberRepository.findById(resources.getId()).orElseGet(Member::new); | ||
| 297 | return this.memberMapper.toDto(member); | ||
| 298 | } | ||
| 299 | |||
| 300 | } catch (Exception e) { | ||
| 301 | log.info(e.getMessage()); | ||
| 302 | } finally { | ||
| 303 | // this.redisUtils.doUnLock(RedisKeyConstants.updateCacheMemberById + resources.getId()); | ||
| 304 | } | ||
| 305 | |||
| 306 | return this.memberMapper.toDto(resources); | ||
| 307 | } | 282 | } |
| 308 | 283 | ||
| 309 | } | 284 | } | ... | ... |
member-service-impl/src/main/java/com/topdraw/business/module/points/detail/domain/PointsDetail.java
| ... | @@ -88,6 +88,10 @@ public class PointsDetail implements Serializable { | ... | @@ -88,6 +88,10 @@ public class PointsDetail implements Serializable { |
| 88 | @Column(name = "item_id") | 88 | @Column(name = "item_id") |
| 89 | private Long itemId; | 89 | private Long itemId; |
| 90 | 90 | ||
| 91 | // 状态:0:异常;1:正常 | ||
| 92 | @Column(name = "status") | ||
| 93 | private Long status; | ||
| 94 | |||
| 91 | // 创建时间 | 95 | // 创建时间 |
| 92 | @CreatedDate | 96 | @CreatedDate |
| 93 | @Column(name = "create_time") | 97 | @Column(name = "create_time") | ... | ... |
| ... | @@ -3,6 +3,9 @@ package com.topdraw.business.module.points.detail.repository; | ... | @@ -3,6 +3,9 @@ package com.topdraw.business.module.points.detail.repository; |
| 3 | import com.topdraw.business.module.points.detail.domain.PointsDetail; | 3 | import com.topdraw.business.module.points.detail.domain.PointsDetail; |
| 4 | import org.springframework.data.jpa.repository.JpaRepository; | 4 | import org.springframework.data.jpa.repository.JpaRepository; |
| 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
| 6 | import org.springframework.data.jpa.repository.Modifying; | ||
| 7 | import org.springframework.data.jpa.repository.Query; | ||
| 8 | import org.springframework.data.repository.query.Param; | ||
| 6 | 9 | ||
| 7 | import java.util.List; | 10 | import java.util.List; |
| 8 | import java.util.Optional; | 11 | import java.util.Optional; |
| ... | @@ -16,4 +19,14 @@ public interface PointsDetailRepository extends JpaRepository<PointsDetail, Long | ... | @@ -16,4 +19,14 @@ public interface PointsDetailRepository extends JpaRepository<PointsDetail, Long |
| 16 | Optional<PointsDetail> findFirstByCode(String code); | 19 | Optional<PointsDetail> findFirstByCode(String code); |
| 17 | 20 | ||
| 18 | List<PointsDetail> findByMemberId(Long memberId); | 21 | List<PointsDetail> findByMemberId(Long memberId); |
| 22 | |||
| 23 | |||
| 24 | @Modifying | ||
| 25 | @Query(value = "INSERT INTO `uc_points_detail`(`code`, `app_code`, `member_id`, `account_id`, `original_points`, `result_points`, " + | ||
| 26 | " `points`, `device_type`, `evt_type`, `order_id`, `media_id`, `activity_id`, `item_id`, `status`, `description`, `create_time`, `update_time`)" + | ||
| 27 | " VALUES (:#{#resources.code}, :#{#resources.appCode}, :#{#resources.memberId}, :#{#resources.accountId}," + | ||
| 28 | " :#{#resources.originalPoints}, :#{#resources.resultPoints}, :#{#resources.points}, :#{#resources.deviceType}," + | ||
| 29 | " :#{#resources.evtType}, :#{#resources.orderId}, :#{#resources.mediaId}, :#{#resources.activityId}, " + | ||
| 30 | " :#{#resources.itemId}, :#{#resources.status}, :#{#resources.description}, now(), now())", nativeQuery = true) | ||
| 31 | Integer insertPointsDetail(@Param("resources") PointsDetail pointsDetail); | ||
| 19 | } | 32 | } | ... | ... |
| ... | @@ -46,13 +46,6 @@ public interface PointsDetailService { | ... | @@ -46,13 +46,6 @@ public interface PointsDetailService { |
| 46 | PointsDetailDTO getByCode(String code); | 46 | PointsDetailDTO getByCode(String code); |
| 47 | 47 | ||
| 48 | /** | 48 | /** |
| 49 | * | ||
| 50 | * @param memberId | ||
| 51 | * @return | ||
| 52 | */ | ||
| 53 | List<PointsDetailDTO> loadListExpirePointsByMemberId(Long memberId); | ||
| 54 | |||
| 55 | /** | ||
| 56 | * 已过期的积分 | 49 | * 已过期的积分 |
| 57 | * @param memberId | 50 | * @param memberId |
| 58 | * @return | 51 | * @return |
| ... | @@ -63,5 +56,5 @@ public interface PointsDetailService { | ... | @@ -63,5 +56,5 @@ public interface PointsDetailService { |
| 63 | * | 56 | * |
| 64 | * @param pointsDetail | 57 | * @param pointsDetail |
| 65 | */ | 58 | */ |
| 66 | void create4Custom(PointsDetail pointsDetail); | 59 | void insertPointsDetail(PointsDetail pointsDetail); |
| 67 | } | 60 | } | ... | ... |
| ... | @@ -54,6 +54,9 @@ public class PointsDetailDTO implements Serializable { | ... | @@ -54,6 +54,9 @@ public class PointsDetailDTO implements Serializable { |
| 54 | // 积分变化描述,用于管理侧显示 | 54 | // 积分变化描述,用于管理侧显示 |
| 55 | private String description; | 55 | private String description; |
| 56 | 56 | ||
| 57 | // 状态:0:异常;1:正常 | ||
| 58 | private Long status; | ||
| 59 | |||
| 57 | // 商品id | 60 | // 商品id |
| 58 | private Long itemId; | 61 | private Long itemId; |
| 59 | 62 | ... | ... |
| ... | @@ -31,6 +31,7 @@ public class PointsDetailServiceImpl implements PointsDetailService { | ... | @@ -31,6 +31,7 @@ public class PointsDetailServiceImpl implements PointsDetailService { |
| 31 | private PointsDetailMapper pointsDetailMapper; | 31 | private PointsDetailMapper pointsDetailMapper; |
| 32 | 32 | ||
| 33 | @Override | 33 | @Override |
| 34 | @Transactional(readOnly = true) | ||
| 34 | public PointsDetailDTO findById(Long id) { | 35 | public PointsDetailDTO findById(Long id) { |
| 35 | PointsDetail pointsDetail = this.pointsDetailRepository.findById(id).orElseGet(PointsDetail::new); | 36 | PointsDetail pointsDetail = this.pointsDetailRepository.findById(id).orElseGet(PointsDetail::new); |
| 36 | ValidationUtil.isNull(pointsDetail.getId(),"PointsDetail","id",id); | 37 | ValidationUtil.isNull(pointsDetail.getId(),"PointsDetail","id",id); |
| ... | @@ -40,8 +41,7 @@ public class PointsDetailServiceImpl implements PointsDetailService { | ... | @@ -40,8 +41,7 @@ public class PointsDetailServiceImpl implements PointsDetailService { |
| 40 | @Override | 41 | @Override |
| 41 | @Transactional(rollbackFor = Exception.class) | 42 | @Transactional(rollbackFor = Exception.class) |
| 42 | public PointsDetailDTO create(PointsDetail resources) { | 43 | public PointsDetailDTO create(PointsDetail resources) { |
| 43 | PointsDetail pointsDetail = this.pointsDetailRepository.save(resources); | 44 | return this.pointsDetailMapper.toDto(this.pointsDetailRepository.save(resources)); |
| 44 | return this.pointsDetailMapper.toDto(pointsDetail); | ||
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | @Override | 47 | @Override |
| ... | @@ -65,17 +65,14 @@ public class PointsDetailServiceImpl implements PointsDetailService { | ... | @@ -65,17 +65,14 @@ public class PointsDetailServiceImpl implements PointsDetailService { |
| 65 | 65 | ||
| 66 | 66 | ||
| 67 | @Override | 67 | @Override |
| 68 | @Transactional(readOnly = true) | ||
| 68 | public PointsDetailDTO getByCode(String code) { | 69 | public PointsDetailDTO getByCode(String code) { |
| 69 | return StringUtils.isNotEmpty(code) ? this.pointsDetailMapper.toDto(this.pointsDetailRepository.findFirstByCode(code).orElseGet(PointsDetail::new)) | 70 | return StringUtils.isNotEmpty(code) ? this.pointsDetailMapper.toDto(this.pointsDetailRepository.findFirstByCode(code).orElseGet(PointsDetail::new)) |
| 70 | : new PointsDetailDTO(); | 71 | : new PointsDetailDTO(); |
| 71 | } | 72 | } |
| 72 | 73 | ||
| 73 | @Override | 74 | @Override |
| 74 | public List<PointsDetailDTO> loadListExpirePointsByMemberId(Long memberId) { | 75 | @Transactional(readOnly = true) |
| 75 | return null; | ||
| 76 | } | ||
| 77 | |||
| 78 | @Override | ||
| 79 | public List<PointsDetailDTO> findByMemberId(Long memberId) { | 76 | public List<PointsDetailDTO> findByMemberId(Long memberId) { |
| 80 | return Objects.nonNull(memberId)? | 77 | return Objects.nonNull(memberId)? |
| 81 | this.pointsDetailMapper.toDto(this.pointsDetailRepository.findByMemberId(memberId)) | 78 | this.pointsDetailMapper.toDto(this.pointsDetailRepository.findByMemberId(memberId)) |
| ... | @@ -83,7 +80,8 @@ public class PointsDetailServiceImpl implements PointsDetailService { | ... | @@ -83,7 +80,8 @@ public class PointsDetailServiceImpl implements PointsDetailService { |
| 83 | } | 80 | } |
| 84 | 81 | ||
| 85 | @Override | 82 | @Override |
| 86 | public void create4Custom(PointsDetail pointsDetail) { | 83 | @Transactional(rollbackFor = Exception.class) |
| 87 | this.pointsDetailRepository.save(pointsDetail); | 84 | public void insertPointsDetail(PointsDetail pointsDetail) { |
| 85 | this.pointsDetailRepository.insertPointsDetail(pointsDetail); | ||
| 88 | } | 86 | } |
| 89 | } | 87 | } | ... | ... |
| ... | @@ -96,11 +96,14 @@ public class TrTaskProgressServiceImpl implements TrTaskProgressService { | ... | @@ -96,11 +96,14 @@ public class TrTaskProgressServiceImpl implements TrTaskProgressService { |
| 96 | if (Objects.isNull(taskId)) { | 96 | if (Objects.isNull(taskId)) { |
| 97 | continue; | 97 | continue; |
| 98 | } | 98 | } |
| 99 | finishTasks.put(Long.valueOf(taskId.toString()), Integer.valueOf(map.get("finishCount").toString())); | 99 | finishTasks.put(taskId, Integer.valueOf(map.get("finishCount").toString())); |
| 100 | 100 | ||
| 101 | } | ||
| 102 | if (finishTasks.size() > 0) { | ||
| 101 | // 总记录一直存储 | 103 | // 总记录一直存储 |
| 102 | this.redisUtils.hmset(RedisKeyConstants.cacheTotalFinishTaskCount + "::" + memberId, finishTasks); | 104 | this.redisUtils.hmset(RedisKeyConstants.cacheTotalFinishTaskCount + "::" + memberId, finishTasks); |
| 103 | } | 105 | } |
| 106 | |||
| 104 | return finishTasks; | 107 | return finishTasks; |
| 105 | } | 108 | } |
| 106 | } | 109 | } |
| ... | @@ -113,7 +116,6 @@ public class TrTaskProgressServiceImpl implements TrTaskProgressService { | ... | @@ -113,7 +116,6 @@ public class TrTaskProgressServiceImpl implements TrTaskProgressService { |
| 113 | 116 | ||
| 114 | Map<Object, Object> hmget = this.redisUtils.hmget(RedisKeyConstants.cacheTodayFinishTaskCount + "::" + memberId + ":" + todayStart); | 117 | Map<Object, Object> hmget = this.redisUtils.hmget(RedisKeyConstants.cacheTodayFinishTaskCount + "::" + memberId + ":" + todayStart); |
| 115 | if (Objects.isNull(hmget)) { | 118 | if (Objects.isNull(hmget)) { |
| 116 | |||
| 117 | List<Map<String, Object>> maps = this.trTaskProgressRepository.countFinishTaskGroupByMemberIdAndToday(memberId, todayStart); | 119 | List<Map<String, Object>> maps = this.trTaskProgressRepository.countFinishTaskGroupByMemberIdAndToday(memberId, todayStart); |
| 118 | if (!CollectionUtils.isEmpty(maps)){ | 120 | if (!CollectionUtils.isEmpty(maps)){ |
| 119 | Map<Object, Object> finishTasks = new HashMap<>(); | 121 | Map<Object, Object> finishTasks = new HashMap<>(); |
| ... | @@ -123,16 +125,20 @@ public class TrTaskProgressServiceImpl implements TrTaskProgressService { | ... | @@ -123,16 +125,20 @@ public class TrTaskProgressServiceImpl implements TrTaskProgressService { |
| 123 | continue; | 125 | continue; |
| 124 | } | 126 | } |
| 125 | 127 | ||
| 126 | finishTasks.put(Long.valueOf(taskId.toString()), Integer.valueOf(map.get("finishCount").toString())); | 128 | finishTasks.put(taskId, Integer.valueOf(map.get("finishCount").toString())); |
| 129 | |||
| 130 | } | ||
| 127 | 131 | ||
| 132 | if (finishTasks.size() > 0) { | ||
| 128 | // 单天的记录只存储一天 | 133 | // 单天的记录只存储一天 |
| 129 | this.redisUtils.hmset(RedisKeyConstants.cacheTodayFinishTaskCount + "::" + memberId + ":" + LocalDate.now(), finishTasks, 24*60*60); | 134 | this.redisUtils.hmset(RedisKeyConstants.cacheTodayFinishTaskCount + "::" + memberId + ":" + LocalDate.now(), finishTasks, 24*60*60); |
| 130 | } | 135 | } |
| 136 | |||
| 131 | return finishTasks; | 137 | return finishTasks; |
| 132 | 138 | ||
| 133 | } | 139 | } |
| 134 | |||
| 135 | } | 140 | } |
| 141 | |||
| 136 | return hmget; | 142 | return hmget; |
| 137 | } | 143 | } |
| 138 | 144 | ... | ... |
member-service-impl/src/main/java/com/topdraw/business/module/task/service/impl/TaskServiceImpl.java
| 1 | package com.topdraw.business.module.task.service.impl; | 1 | package com.topdraw.business.module.task.service.impl; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.member.service.dto.MemberSimpleDTO; | 3 | import com.alibaba.fastjson.JSON; |
| 4 | import com.alibaba.fastjson.JSONArray; | ||
| 4 | import com.topdraw.business.module.task.domain.Task; | 5 | import com.topdraw.business.module.task.domain.Task; |
| 5 | import com.topdraw.business.module.task.repository.TaskRepository; | 6 | import com.topdraw.business.module.task.repository.TaskRepository; |
| 6 | import com.topdraw.business.module.task.service.TaskService; | 7 | import com.topdraw.business.module.task.service.TaskService; |
| ... | @@ -10,6 +11,7 @@ import com.topdraw.config.RedisKeyConstants; | ... | @@ -10,6 +11,7 @@ import com.topdraw.config.RedisKeyConstants; |
| 10 | import com.topdraw.utils.RedisUtils; | 11 | import com.topdraw.utils.RedisUtils; |
| 11 | import lombok.extern.slf4j.Slf4j; | 12 | import lombok.extern.slf4j.Slf4j; |
| 12 | import org.springframework.beans.factory.annotation.Autowired; | 13 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | import org.springframework.cache.annotation.CacheConfig; | ||
| 13 | import org.springframework.cache.annotation.Cacheable; | 15 | import org.springframework.cache.annotation.Cacheable; |
| 14 | import org.springframework.stereotype.Service; | 16 | import org.springframework.stereotype.Service; |
| 15 | import org.springframework.transaction.annotation.Propagation; | 17 | import org.springframework.transaction.annotation.Propagation; |
| ... | @@ -77,10 +79,25 @@ public class TaskServiceImpl implements TaskService { | ... | @@ -77,10 +79,25 @@ public class TaskServiceImpl implements TaskService { |
| 77 | } | 79 | } |
| 78 | 80 | ||
| 79 | @Override | 81 | @Override |
| 80 | @Cacheable(cacheNames = RedisKeyConstants.cacheTaskByEventAndMemberLevelAndVip, key = "#event+':'+#level+':'+#vip", | 82 | @Transactional(readOnly = true) |
| 81 | unless = "#result.size() == 0") | ||
| 82 | public List<Task> findByEventAndMemberLevelAndVip(Integer event, Integer level, Integer vip) { | 83 | public List<Task> findByEventAndMemberLevelAndVip(Integer event, Integer level, Integer vip) { |
| 84 | try { | ||
| 85 | boolean b = this.redisUtils.hasKey(RedisKeyConstants.cacheTaskByEventAndMemberLevelAndVip + "::" + event + ":" + level + ":" + vip); | ||
| 86 | if (b) { | ||
| 87 | List<Object> tasksObjs = redisUtils.lGet(RedisKeyConstants.cacheTaskByEventAndMemberLevelAndVip + "::" + event + ":" + level + ":" + vip, 0, -1); | ||
| 88 | return JSONArray.parseArray(tasksObjs.get(0).toString(), Task.class); | ||
| 89 | } | ||
| 83 | List<Task> tasks = this.taskRepository.findByEvent(event, level, vip); | 90 | List<Task> tasks = this.taskRepository.findByEvent(event, level, vip); |
| 84 | return Objects.nonNull(event) ? tasks : new ArrayList<>(); | 91 | if (!CollectionUtils.isEmpty(tasks)) { |
| 92 | this.redisUtils.lSet(RedisKeyConstants.cacheTaskByEventAndMemberLevelAndVip + "::" + event + ":" + level + ":" + vip, tasks, 45 * 60); | ||
| 93 | } | ||
| 94 | |||
| 95 | return tasks; | ||
| 96 | |||
| 97 | } catch (Exception e) { | ||
| 98 | log.error(e.getMessage()); | ||
| 99 | } | ||
| 100 | |||
| 101 | return new ArrayList<>(); | ||
| 85 | } | 102 | } |
| 86 | } | 103 | } | ... | ... |
| ... | @@ -45,6 +45,10 @@ public class UserTvSimple extends AsyncMqModule implements Serializable { | ... | @@ -45,6 +45,10 @@ public class UserTvSimple extends AsyncMqModule implements Serializable { |
| 45 | @Column(name = "priority_member_code") | 45 | @Column(name = "priority_member_code") |
| 46 | private String priorityMemberCode; | 46 | private String priorityMemberCode; |
| 47 | 47 | ||
| 48 | /** 绑定的小屏账户会员编码 */ | ||
| 49 | @Column(name = "platform_account") | ||
| 50 | private String platformAccount; | ||
| 51 | |||
| 48 | public void copy(UserTvSimple source){ | 52 | public void copy(UserTvSimple source){ |
| 49 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(false)); | 53 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(false)); |
| 50 | } | 54 | } | ... | ... |
| ... | @@ -12,7 +12,6 @@ import org.springframework.data.jpa.repository.Query; | ... | @@ -12,7 +12,6 @@ import org.springframework.data.jpa.repository.Query; |
| 12 | */ | 12 | */ |
| 13 | public interface UserTvSimpleRepository extends JpaRepository<UserTvSimple, Long>, JpaSpecificationExecutor<UserTvSimple> { | 13 | public interface UserTvSimpleRepository extends JpaRepository<UserTvSimple, Long>, JpaSpecificationExecutor<UserTvSimple> { |
| 14 | 14 | ||
| 15 | @Query(value = "SELECT `id`, `vis_user_id` , `member_id` , " + | 15 | @Query(value = "SELECT `id`, `vis_user_id` , `member_id` , `platform_account`, `priority_member_code` FROM `uc_user_tv` WHERE `platform_account` = ?1", nativeQuery = true) |
| 16 | " `priority_member_code` FROM `uc_user_tv` WHERE `platform_account` = ?1", nativeQuery = true) | ||
| 17 | UserTvSimple findSimpleByPlatformAccount(String platformAccount); | 16 | UserTvSimple findSimpleByPlatformAccount(String platformAccount); |
| 18 | } | 17 | } | ... | ... |
| 1 | package com.topdraw.business.module.user.iptv.service.impl; | 1 | package com.topdraw.business.module.user.iptv.service.impl; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSON; | ||
| 3 | import com.alibaba.fastjson.JSONObject; | 4 | import com.alibaba.fastjson.JSONObject; |
| 4 | import com.topdraw.aspect.AsyncMqSend; | 5 | import com.topdraw.aspect.AsyncMqSend; |
| 5 | import com.topdraw.business.module.member.service.MemberService; | 6 | import com.topdraw.business.module.member.service.MemberService; |
| ... | @@ -209,12 +210,12 @@ public class UserTvServiceImpl implements UserTvService { | ... | @@ -209,12 +210,12 @@ public class UserTvServiceImpl implements UserTvService { |
| 209 | 210 | ||
| 210 | UserTvSimple userTvSimple = this.userTvSimpleRepository.findSimpleByPlatformAccount(platformAccount); | 211 | UserTvSimple userTvSimple = this.userTvSimpleRepository.findSimpleByPlatformAccount(platformAccount); |
| 211 | if (Objects.nonNull(userTvSimple)) { | 212 | if (Objects.nonNull(userTvSimple)) { |
| 212 | HashMap hashMap = JSONObject.parseObject(userTvSimple.toString(), HashMap.class); | 213 | JSONObject userTvSimpleJSON = JSONObject.parseObject(JSON.toJSONString(userTvSimple), JSONObject.class); |
| 213 | this.redisUtils.set(RedisKeyConstants.cacheVisUserByPlatformAccount + "::" + platformAccount, hashMap); | 214 | this.redisUtils.set(RedisKeyConstants.cacheVisUserByPlatformAccount + "::" + platformAccount, userTvSimpleJSON); |
| 214 | return this.userTvSimpleMapper.toDto(userTvSimple); | 215 | return this.userTvSimpleMapper.toDto(userTvSimple); |
| 215 | } | 216 | } |
| 216 | 217 | ||
| 217 | return null; | 218 | return this.userTvSimpleMapper.toDto(userTvSimple); |
| 218 | } | 219 | } |
| 219 | 220 | ||
| 220 | @Override | 221 | @Override | ... | ... |
| ... | @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping; | ... | @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping; |
| 14 | import org.springframework.web.bind.annotation.RestController; | 14 | import org.springframework.web.bind.annotation.RestController; |
| 15 | 15 | ||
| 16 | import java.util.Arrays; | 16 | import java.util.Arrays; |
| 17 | import java.util.Collections; | ||
| 17 | import java.util.List; | 18 | import java.util.List; |
| 18 | import java.util.Objects; | 19 | import java.util.Objects; |
| 19 | 20 | ||
| ... | @@ -45,8 +46,7 @@ public class ExpOperationController { | ... | @@ -45,8 +46,7 @@ public class ExpOperationController { |
| 45 | log.error("发放成长值失败,参数错误,成长值为空或者小于0 ==>> {}", rewardExp); | 46 | log.error("发放成长值失败,参数错误,成长值为空或者小于0 ==>> {}", rewardExp); |
| 46 | return ResultInfo.failure("发放成长值失败,参数错误,成长值为空或者小于0"); | 47 | return ResultInfo.failure("发放成长值失败,参数错误,成长值为空或者小于0"); |
| 47 | } | 48 | } |
| 48 | List<TempExp> tempExpList = Arrays.asList(tempExp); | 49 | this.expOperationService.grantExpByManual(Collections.singletonList(tempExp)); |
| 49 | this.expOperationService.grantExpByManual(tempExpList); | ||
| 50 | return ResultInfo.success(); | 50 | return ResultInfo.success(); |
| 51 | } | 51 | } |
| 52 | 52 | ... | ... |
| ... | @@ -18,14 +18,6 @@ public interface ExpOperationService { | ... | @@ -18,14 +18,6 @@ public interface ExpOperationService { |
| 18 | void grantExpThroughTempExp( List<TempExp> tempExpList); | 18 | void grantExpThroughTempExp( List<TempExp> tempExpList); |
| 19 | 19 | ||
| 20 | /** | 20 | /** |
| 21 | * 系统手动发放优惠券 | ||
| 22 | * @param memberId | ||
| 23 | * @param userId | ||
| 24 | * @param tempExpList | ||
| 25 | */ | ||
| 26 | void grantExpByManual(Long memberId,Long userId ,List<TempExp> tempExpList); | ||
| 27 | |||
| 28 | /** | ||
| 29 | * | 21 | * |
| 30 | * @param tempExpList | 22 | * @param tempExpList |
| 31 | */ | 23 | */ | ... | ... |
| ... | @@ -101,17 +101,18 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -101,17 +101,18 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
| 101 | try { | 101 | try { |
| 102 | this.redisUtils.doLock(RedisKeyConstants.updateCacheCouponByMemberId + memberId.toString()); | 102 | this.redisUtils.doLock(RedisKeyConstants.updateCacheCouponByMemberId + memberId.toString()); |
| 103 | // 1.历史总优惠券数量 | 103 | // 1.历史总优惠券数量 |
| 104 | Long historyCouponCount = this.getTotalHistoryCoupon(memberId); | 104 | Long historyCouponCount = this.couponHistoryService.countByUserId(memberId); |
| 105 | // 1.当前总优惠券数量 | 105 | // 1.当前总优惠券数量 |
| 106 | Long totalCouponCount = this.getTotalCoupon(historyCouponCount, rightsAmount); | 106 | Long totalCouponCount = (Objects.nonNull(historyCouponCount) ? historyCouponCount: 0L) + (Objects.nonNull(rightsAmount) ? rightsAmount: 0L); |
| 107 | // 2.获取已过期的优惠券数量 | 107 | // 2.获取已过期的优惠券数量 |
| 108 | Long expireCouponCount = this.getTotalExpireCoupon(memberId); | 108 | Long expireCouponCount = this.couponHistoryService.countByUserIdAndExpireTimeBefore(memberId, LocalDateTime.now()); |
| 109 | // 3.即将过期的优惠券数量 | 109 | // 3.即将过期的优惠券数量 |
| 110 | Long expireSoonCouponCount = this.getTotalExpireSoonCoupon(memberId, EXPIRE_FACTOR_DAY); | 110 | Long expireSoonCouponCount = this.couponHistoryService.countByUserIdAndExpireTimeBetween(memberId, LocalDateTime.now(),LocalDateTime.now().plusDays(EXPIRE_FACTOR_DAY)); |
| 111 | // 4.当前优惠券数量 = 总优惠券-已过期的优惠券 | 111 | // 4.当前优惠券数量 = 总优惠券-已过期的优惠券 |
| 112 | Long currentCoupon = this.getCurrentCoupon(totalCouponCount, expireCouponCount); | 112 | Long currentCoupon = (Objects.nonNull(totalCouponCount)?totalCouponCount:0L)-(Objects.nonNull(expireCouponCount)?expireCouponCount:0L); |
| 113 | // 5.更新用户信息(优惠券数量、即将过期的优惠券数量) | 113 | // 5.更新用户信息(优惠券数量、即将过期的优惠券数量) |
| 114 | this.doUpdateMemberInfo(memberId,currentCoupon,expireSoonCouponCount); | 114 | this.doUpdateMemberInfo(memberId,currentCoupon,expireSoonCouponCount); |
| 115 | |||
| 115 | } catch (Exception e) { | 116 | } catch (Exception e) { |
| 116 | log.error(e.getMessage()); | 117 | log.error(e.getMessage()); |
| 117 | } finally { | 118 | } finally { |
| ... | @@ -119,11 +120,6 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -119,11 +120,6 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
| 119 | } | 120 | } |
| 120 | } | 121 | } |
| 121 | 122 | ||
| 122 | private Long getTotalCoupon(Long historyCouponCount, Integer rightsAmount) { | ||
| 123 | return (Objects.nonNull(historyCouponCount) ? historyCouponCount: 0L) + (Objects.nonNull(rightsAmount) ? rightsAmount: 0L); | ||
| 124 | } | ||
| 125 | |||
| 126 | |||
| 127 | /** | 123 | /** |
| 128 | * 更新当前用户优惠券信息 | 124 | * 更新当前用户优惠券信息 |
| 129 | * @param memberId | 125 | * @param memberId |
| ... | @@ -141,9 +137,10 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -141,9 +137,10 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
| 141 | member.setUpdateTime(TimestampUtil.now()); | 137 | member.setUpdateTime(TimestampUtil.now()); |
| 142 | this.memberOperationService.doUpdateMemberCoupon(member); | 138 | this.memberOperationService.doUpdateMemberCoupon(member); |
| 143 | 139 | ||
| 144 | /*this.threadPoolTaskExecutor.submit(() -> { | 140 | // ((CouponOperationServiceImpl) AopContext.currentProxy()).asyncMemberCoupon(member); |
| 141 | this.threadPoolTaskExecutor.submit(() -> { | ||
| 145 | ((CouponOperationServiceImpl) AopContext.currentProxy()).asyncMemberCoupon(member); | 142 | ((CouponOperationServiceImpl) AopContext.currentProxy()).asyncMemberCoupon(member); |
| 146 | });*/ | 143 | }); |
| 147 | } | 144 | } |
| 148 | 145 | ||
| 149 | private MemberDTO findMemberByMemberId(Long memberId) { | 146 | private MemberDTO findMemberByMemberId(Long memberId) { |
| ... | @@ -171,27 +168,7 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -171,27 +168,7 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
| 171 | */ | 168 | */ |
| 172 | private Long getTotalExpireSoonCoupon(Long userId, Integer expireFactor) { | 169 | private Long getTotalExpireSoonCoupon(Long userId, Integer expireFactor) { |
| 173 | LocalDateTime expireTime = LocalDateTime.now().plusDays(expireFactor); | 170 | LocalDateTime expireTime = LocalDateTime.now().plusDays(expireFactor); |
| 174 | return this.couponHistoryService.countByUserIdAndExpireTimeBetween(userId,LocalDateTime.now(),expireTime); | 171 | return this.couponHistoryService.countByUserIdAndExpireTimeBetween(userId,LocalDateTime.now(),LocalDateTime.now().plusDays(expireFactor)); |
| 175 | } | ||
| 176 | |||
| 177 | |||
| 178 | /** | ||
| 179 | * 获取已过期的优惠券数量 | ||
| 180 | * @param userId | ||
| 181 | * @return | ||
| 182 | */ | ||
| 183 | private Long getTotalExpireCoupon(Long userId) { | ||
| 184 | return this.couponHistoryService.countByUserIdAndExpireTimeBefore(userId, LocalDateTime.now()); | ||
| 185 | } | ||
| 186 | |||
| 187 | |||
| 188 | /** | ||
| 189 | * 获取用户领取的总优惠券 | ||
| 190 | * @param userId | ||
| 191 | * @return | ||
| 192 | */ | ||
| 193 | private Long getTotalHistoryCoupon(Long userId) { | ||
| 194 | return this.couponHistoryService.countByUserId(userId); | ||
| 195 | } | 172 | } |
| 196 | 173 | ||
| 197 | 174 | ... | ... |
| ... | @@ -7,12 +7,11 @@ import com.topdraw.business.module.member.domain.Member; | ... | @@ -7,12 +7,11 @@ import com.topdraw.business.module.member.domain.Member; |
| 7 | import com.topdraw.business.module.member.level.service.MemberLevelService; | 7 | import com.topdraw.business.module.member.level.service.MemberLevelService; |
| 8 | import com.topdraw.business.module.member.level.service.dto.MemberLevelDTO; | 8 | import com.topdraw.business.module.member.level.service.dto.MemberLevelDTO; |
| 9 | import com.topdraw.business.module.member.service.MemberService; | 9 | import com.topdraw.business.module.member.service.MemberService; |
| 10 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 10 | import com.topdraw.business.module.member.service.dto.MemberSimpleDTO; |
| 11 | import com.topdraw.business.process.service.ExpOperationService; | 11 | import com.topdraw.business.process.service.ExpOperationService; |
| 12 | import com.topdraw.business.process.service.member.MemberOperationService; | 12 | import com.topdraw.business.process.service.member.MemberOperationService; |
| 13 | import com.topdraw.business.process.domian.TempExp; | 13 | import com.topdraw.business.process.domian.TempExp; |
| 14 | import com.topdraw.config.RedisKeyConstants; | 14 | import com.topdraw.config.RedisKeyConstants; |
| 15 | import com.topdraw.util.IdWorker; | ||
| 16 | import com.topdraw.util.TimestampUtil; | 15 | import com.topdraw.util.TimestampUtil; |
| 17 | import com.topdraw.utils.RedisUtils; | 16 | import com.topdraw.utils.RedisUtils; |
| 18 | import com.topdraw.utils.StringUtils; | 17 | import com.topdraw.utils.StringUtils; |
| ... | @@ -22,10 +21,10 @@ import org.springframework.beans.BeanUtils; | ... | @@ -22,10 +21,10 @@ import org.springframework.beans.BeanUtils; |
| 22 | import org.springframework.beans.factory.annotation.Autowired; | 21 | import org.springframework.beans.factory.annotation.Autowired; |
| 23 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | 22 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| 24 | import org.springframework.stereotype.Service; | 23 | import org.springframework.stereotype.Service; |
| 25 | import org.springframework.util.CollectionUtils; | ||
| 26 | 24 | ||
| 27 | import java.util.List; | 25 | import java.util.List; |
| 28 | import java.util.Objects; | 26 | import java.util.Objects; |
| 27 | import java.util.UUID; | ||
| 29 | 28 | ||
| 30 | /** | 29 | /** |
| 31 | * | 30 | * |
| ... | @@ -56,126 +55,88 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -56,126 +55,88 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
| 56 | 55 | ||
| 57 | @Override | 56 | @Override |
| 58 | public void grantExpThroughTempExp(List<TempExp> tempExpList) { | 57 | public void grantExpThroughTempExp(List<TempExp> tempExpList) { |
| 59 | for (TempExp tempExp : tempExpList) { | 58 | this.refresh(tempExpList); |
| 60 | this.refresh(tempExp); | ||
| 61 | } | ||
| 62 | } | 59 | } |
| 63 | 60 | ||
| 64 | @Override | ||
| 65 | public void grantExpByManual(Long memberId, Long userId, List<TempExp> tempExpList) { | ||
| 66 | for (TempExp tempExp : tempExpList) { | ||
| 67 | this.refresh(tempExp); | ||
| 68 | } | ||
| 69 | } | ||
| 70 | 61 | ||
| 71 | @Override | 62 | @Override |
| 72 | public void grantExpByManual(List<TempExp> tempExpList) { | 63 | public void grantExpByManual(List<TempExp> tempExpList) { |
| 73 | for (TempExp tempExp : tempExpList) { | 64 | this.refresh(tempExpList); |
| 74 | this.refresh(tempExp); | ||
| 75 | } | ||
| 76 | } | 65 | } |
| 77 | 66 | ||
| 78 | /** | 67 | /** |
| 79 | * | 68 | * |
| 80 | * @param tempExp | 69 | * @param tempExps |
| 81 | */ | 70 | */ |
| 82 | private void refresh(TempExp tempExp) { | 71 | private void refresh(List<TempExp> tempExps) { |
| 72 | |||
| 73 | TempExp _tempExp = tempExps.get(0); | ||
| 74 | |||
| 83 | try { | 75 | try { |
| 84 | this.redisUtils.doLock(RedisKeyConstants.updateCacheExpByMemberId + tempExp.getMemberId()); | 76 | this.redisUtils.doLock(RedisKeyConstants.updateCacheExpByMemberId + _tempExp.getMemberId()); |
| 85 | 77 | ||
| 86 | // 原始经验值 | 78 | // 原始经验值 |
| 87 | long l = System.currentTimeMillis(); | 79 | long originExp = this.memberService.findExpByMemberId(_tempExp.getMemberId()); |
| 88 | long originExp = this.getExpByMemberId(tempExp); | 80 | log.info("----获取会员当前原始经验值 ==>> {}", originExp); |
| 89 | long l1 = System.currentTimeMillis(); | 81 | |
| 90 | log.info("----获取会员当前原始经验值 ==>> {}, 总耗时 -->> {}", originExp, (l1-l)); | 82 | long totalExp = originExp; |
| 83 | for (TempExp exp : tempExps) { | ||
| 91 | // 总经验值 | 84 | // 总经验值 |
| 92 | // TODO | 85 | totalExp = this.doInsertExpDetail(exp, totalExp, (exp.getRewardExp()+totalExp)); |
| 93 | long totalExp = this.calculateTotalExp(originExp, tempExp); | 86 | log.info("----保存经验值历史 -->>{}", totalExp); |
| 94 | log.info("----计算总经验值 ==>> {}", totalExp); | 87 | } |
| 95 | 88 | ||
| 96 | // 2.更新成长值与等级 | 89 | // 2.更新成长值与等级 |
| 97 | long l2 = System.currentTimeMillis(); | 90 | this.refreshMemberExpAndLevel(_tempExp, totalExp); |
| 98 | this.refreshMemberExpAndLevel(tempExp, totalExp); | 91 | log.info("----更新会员经验值与对应等级 ==>> {}", totalExp); |
| 99 | long l3 = System.currentTimeMillis(); | 92 | |
| 100 | log.info("----更新会员经验值与对应等级 ==>> {}, 总耗时 ==>> {}", totalExp, (l3-l2)); | ||
| 101 | |||
| 102 | long l4 = System.currentTimeMillis(); | ||
| 103 | this.doInsertExpDetail(tempExp, originExp, totalExp); | ||
| 104 | long l5 = System.currentTimeMillis(); | ||
| 105 | log.info("----保存经验值历史 -->> 总耗时 -->> {}", (l5-l4)); | ||
| 106 | } catch (Exception e) { | 93 | } catch (Exception e) { |
| 107 | log.error("成长值发放失败,{}",e.getMessage()); | 94 | log.error("成长值发放失败,{}",e.getMessage()); |
| 108 | } finally { | 95 | } finally { |
| 109 | this.redisUtils.doUnLock(RedisKeyConstants.updateCacheExpByMemberId + tempExp.getMemberId()); | 96 | this.redisUtils.doUnLock(RedisKeyConstants.updateCacheExpByMemberId + _tempExp.getMemberId()); |
| 110 | } | 97 | } |
| 111 | } | 98 | } |
| 112 | 99 | ||
| 113 | private long calculateTotalExp(long originalExp, TempExp tempExp) { | ||
| 114 | Long rewardExp = tempExp.getRewardExp(); | ||
| 115 | return rewardExp + originalExp; | ||
| 116 | } | ||
| 117 | |||
| 118 | /** | ||
| 119 | * | ||
| 120 | * @param tempExp | ||
| 121 | * @return | ||
| 122 | */ | ||
| 123 | private long getExpByMemberId(TempExp tempExp) { | ||
| 124 | Long memberId = tempExp.getMemberId(); | ||
| 125 | MemberDTO memberDTO = this.memberService.findById(memberId); | ||
| 126 | if (Objects.nonNull(memberDTO.getId())) { | ||
| 127 | Long exp = memberDTO.getExp(); | ||
| 128 | return Objects.isNull(exp) ? 0L : exp; | ||
| 129 | } | ||
| 130 | return 0L; | ||
| 131 | } | ||
| 132 | |||
| 133 | /** | 100 | /** |
| 134 | * 更新成长值与等级 | 101 | * 更新成长值与等级 |
| 135 | * | 102 | * |
| 136 | * @param tempExp 成长值列表 | 103 | * @param tempExp 成长值列表 |
| 137 | */ | 104 | */ |
| 138 | private void refreshMemberExpAndLevel(TempExp tempExp,long totalExp) { | 105 | private void refreshMemberExpAndLevel(TempExp tempExp, long totalExp) { |
| 139 | 106 | ||
| 140 | Integer memberLevel = tempExp.getMemberLevel(); | 107 | Integer memberLevel = tempExp.getMemberLevel(); |
| 141 | Long memberId = tempExp.getMemberId(); | 108 | Long memberId = tempExp.getMemberId(); |
| 109 | String memberCode = tempExp.getMemberCode(); | ||
| 142 | // 2.获取下一级需要的成长值 | 110 | // 2.获取下一级需要的成长值 |
| 143 | // TODO 需要缓存 | 111 | MemberLevelDTO memberLevelDTO = this.memberLevelService.findByLevel(memberLevel + 1); |
| 144 | MemberLevelDTO memberLevelDTO = this.getNextLevelExp(memberLevel + 1, 1); | ||
| 145 | // 4.成长值比较,判断是否升级 | 112 | // 4.成长值比较,判断是否升级 |
| 146 | Integer level = this.compareExp(totalExp, memberLevelDTO, memberLevel); | 113 | Integer level = this.compareExp(totalExp, memberLevelDTO, memberLevel); |
| 147 | // 5.更新用户信息 | ||
| 148 | this.updateMemberInfo(level, totalExp, memberId); | ||
| 149 | } | ||
| 150 | |||
| 151 | /** | ||
| 152 | * | ||
| 153 | * @param level | ||
| 154 | * @param totalExp 总积分 | ||
| 155 | * @param memberId 会员id | ||
| 156 | */ | ||
| 157 | private void updateMemberInfo(Integer level,Long totalExp,Long memberId) { | ||
| 158 | MemberDTO memberDTO = this.findMemberByMemberId(memberId); | ||
| 159 | 114 | ||
| 115 | // 5.更新用户信息 | ||
| 160 | Member member = new Member(); | 116 | Member member = new Member(); |
| 161 | member.setId(memberDTO.getId()); | 117 | member.setId(memberId); |
| 162 | member.setCode(memberDTO.getCode()); | 118 | member.setCode(memberCode); |
| 163 | member.setExp(totalExp); | 119 | member.setExp(totalExp); |
| 164 | member.setLevel(level); | 120 | member.setLevel(level); |
| 165 | member.setUpdateTime(TimestampUtil.now()); | 121 | member.setUpdateTime(TimestampUtil.now()); |
| 166 | this.memberOperationService.doUpdateMemberExpAndLevel(member); | 122 | this.memberOperationService.doUpdateMemberExpAndLevel(member); |
| 167 | /*this.threadPoolTaskExecutor.submit(() -> { | 123 | |
| 168 | ((ExpOperationServiceImpl) AopContext.currentProxy()).asyncMemberExpAndLevel(member); | 124 | ((ExpOperationServiceImpl) AopContext.currentProxy()).asyncMemberExpAndLevel(member); |
| 169 | });*/ | 125 | |
| 126 | if (level > memberLevel) { | ||
| 127 | MemberSimpleDTO memberSimpleDTO = this.memberService.findSimpleById(memberId); | ||
| 128 | if (Objects.nonNull(memberLevelDTO.getId())) { | ||
| 129 | memberSimpleDTO.setLevel(level); | ||
| 130 | boolean result = this.redisUtils.set(RedisKeyConstants.cacheMemberSimpleById + "::" + memberId, memberSimpleDTO); | ||
| 131 | log.info("更新redis中会员等级 ==>> {} || 更新结果 ==>>{}", memberSimpleDTO, result); | ||
| 132 | |||
| 133 | } | ||
| 170 | } | 134 | } |
| 171 | 135 | ||
| 172 | private MemberDTO findMemberByMemberId(Long memberId) { | ||
| 173 | MemberDTO memberDTO = this.memberService.findById(memberId); | ||
| 174 | return memberDTO; | ||
| 175 | } | 136 | } |
| 176 | 137 | ||
| 177 | private Integer compareExp(long newExp, MemberLevelDTO memberLevelDTO, Integer oldMemberLevel) { | 138 | private Integer compareExp(long newExp, MemberLevelDTO memberLevelDTO, Integer oldMemberLevel) { |
| 178 | if (Objects.nonNull(memberLevelDTO)) { | 139 | if (Objects.nonNull(memberLevelDTO.getId())) { |
| 179 | Long nextLevelExp = memberLevelDTO.getExpValue(); | 140 | Long nextLevelExp = memberLevelDTO.getExpValue(); |
| 180 | if (Objects.nonNull(nextLevelExp) && nextLevelExp > 0) | 141 | if (Objects.nonNull(nextLevelExp) && nextLevelExp > 0) |
| 181 | if(newExp - nextLevelExp >= 0){ | 142 | if(newExp - nextLevelExp >= 0){ |
| ... | @@ -185,38 +146,18 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -185,38 +146,18 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
| 185 | return oldMemberLevel; | 146 | return oldMemberLevel; |
| 186 | } | 147 | } |
| 187 | 148 | ||
| 188 | private MemberLevelDTO getNextLevelExp(Integer i,Integer status) { | ||
| 189 | List<MemberLevelDTO> memberLevelDTOList = this.memberLevelService.findLevelAndStatus(i, status); | ||
| 190 | if (!CollectionUtils.isEmpty(memberLevelDTOList)) { | ||
| 191 | return memberLevelDTOList.get(0); | ||
| 192 | } | ||
| 193 | return null; | ||
| 194 | } | ||
| 195 | |||
| 196 | |||
| 197 | /** | ||
| 198 | * 获取当前会员的成长值 | ||
| 199 | * @param memberId 会员id | ||
| 200 | * @return Long 当前会员成长值 | ||
| 201 | */ | ||
| 202 | private MemberDTO getMemberInfoByMemberId(Long memberId) { | ||
| 203 | MemberDTO memberDTO = this.memberOperationService.findById(memberId); | ||
| 204 | return memberDTO; | ||
| 205 | } | ||
| 206 | |||
| 207 | /** | 149 | /** |
| 208 | * 添加成长值记录 | 150 | * 添加成长值记录 |
| 209 | * | 151 | * |
| 210 | * @param tempExp 成长值列表 | 152 | * @param tempExp 成长值列表 |
| 211 | */ | 153 | */ |
| 212 | private void doInsertExpDetail(TempExp tempExp,long originalExp,long totalExp) { | 154 | private long doInsertExpDetail(TempExp tempExp, long originalExp, long totalExp) { |
| 213 | // 获得的积分 | 155 | // 获得的积分 |
| 214 | Long rewardExp = tempExp.getRewardExp(); | 156 | Long rewardExp = tempExp.getRewardExp(); |
| 215 | 157 | ||
| 216 | ExpDetail expDetail = new ExpDetail(); | 158 | ExpDetail expDetail = new ExpDetail(); |
| 217 | BeanUtils.copyProperties(tempExp,expDetail); | 159 | BeanUtils.copyProperties(tempExp, expDetail); |
| 218 | 160 | expDetail.setCode("expD_"+UUID.randomUUID().toString()); | |
| 219 | expDetail.setCode(String.valueOf(IdWorker.generator())); | ||
| 220 | // 原始积分 | 161 | // 原始积分 |
| 221 | expDetail.setOriginalExp(originalExp); | 162 | expDetail.setOriginalExp(originalExp); |
| 222 | // 总积分 | 163 | // 总积分 |
| ... | @@ -228,9 +169,9 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -228,9 +169,9 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
| 228 | } | 169 | } |
| 229 | this.expDetailService.create(expDetail); | 170 | this.expDetailService.create(expDetail); |
| 230 | 171 | ||
| 231 | /*this.threadPoolTaskExecutor.submit(() -> { | ||
| 232 | ((ExpOperationServiceImpl) AopContext.currentProxy()).asyncExpDetail(expDetail); | 172 | ((ExpOperationServiceImpl) AopContext.currentProxy()).asyncExpDetail(expDetail); |
| 233 | });*/ | 173 | |
| 174 | return totalExp; | ||
| 234 | } | 175 | } |
| 235 | 176 | ||
| 236 | } | 177 | } | ... | ... |
| ... | @@ -8,26 +8,19 @@ import com.topdraw.business.module.member.service.dto.MemberDTO; | ... | @@ -8,26 +8,19 @@ import com.topdraw.business.module.member.service.dto.MemberDTO; |
| 8 | import com.topdraw.business.module.points.available.domain.PointsAvailable; | 8 | import com.topdraw.business.module.points.available.domain.PointsAvailable; |
| 9 | import com.topdraw.business.module.points.available.service.PointsAvailableService; | 9 | import com.topdraw.business.module.points.available.service.PointsAvailableService; |
| 10 | import com.topdraw.business.module.points.available.service.dto.PointsAvailableDTO; | 10 | import com.topdraw.business.module.points.available.service.dto.PointsAvailableDTO; |
| 11 | import com.topdraw.business.module.points.detail.detailhistory.service.PointsDetailHistoryService; | ||
| 12 | import com.topdraw.business.module.points.detail.domain.PointsDetail; | 11 | import com.topdraw.business.module.points.detail.domain.PointsDetail; |
| 13 | import com.topdraw.business.module.points.detail.service.PointsDetailService; | 12 | import com.topdraw.business.module.points.detail.service.PointsDetailService; |
| 14 | import com.topdraw.business.module.points.service.PointsService; | ||
| 15 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; | ||
| 16 | import com.topdraw.business.process.service.dto.CustomPointsResult; | 13 | import com.topdraw.business.process.service.dto.CustomPointsResult; |
| 17 | import com.topdraw.business.process.service.member.MemberOperationService; | 14 | import com.topdraw.business.process.service.member.MemberOperationService; |
| 18 | import com.topdraw.business.process.service.PointsOperationService; | 15 | import com.topdraw.business.process.service.PointsOperationService; |
| 19 | import com.topdraw.business.process.domian.TempPoints; | 16 | import com.topdraw.business.process.domian.TempPoints; |
| 20 | import com.topdraw.config.RedisKeyConstants; | 17 | import com.topdraw.config.RedisKeyConstants; |
| 21 | import com.topdraw.mq.producer.MessageProducer; | ||
| 22 | import com.topdraw.util.DateUtil; | 18 | import com.topdraw.util.DateUtil; |
| 23 | import com.topdraw.util.IdWorker; | 19 | import com.topdraw.util.IdWorker; |
| 24 | import com.topdraw.util.TimestampUtil; | 20 | import com.topdraw.util.TimestampUtil; |
| 25 | import com.topdraw.utils.RedisUtils; | 21 | import com.topdraw.utils.RedisUtils; |
| 26 | import com.topdraw.utils.StringUtils; | 22 | import com.topdraw.utils.StringUtils; |
| 27 | import lombok.extern.slf4j.Slf4j; | 23 | import lombok.extern.slf4j.Slf4j; |
| 28 | import org.apache.commons.lang3.time.DateUtils; | ||
| 29 | import org.slf4j.Logger; | ||
| 30 | import org.slf4j.LoggerFactory; | ||
| 31 | import org.springframework.aop.framework.AopContext; | 24 | import org.springframework.aop.framework.AopContext; |
| 32 | import org.springframework.beans.BeanUtils; | 25 | import org.springframework.beans.BeanUtils; |
| 33 | import org.springframework.beans.factory.annotation.Autowired; | 26 | import org.springframework.beans.factory.annotation.Autowired; |
| ... | @@ -38,10 +31,7 @@ import org.springframework.transaction.annotation.Transactional; | ... | @@ -38,10 +31,7 @@ import org.springframework.transaction.annotation.Transactional; |
| 38 | import org.springframework.util.CollectionUtils; | 31 | import org.springframework.util.CollectionUtils; |
| 39 | 32 | ||
| 40 | import java.sql.Timestamp; | 33 | import java.sql.Timestamp; |
| 41 | import java.time.LocalDateTime; | ||
| 42 | import java.util.*; | 34 | import java.util.*; |
| 43 | import java.util.concurrent.TimeUnit; | ||
| 44 | import java.util.stream.Collectors; | ||
| 45 | 35 | ||
| 46 | /** | 36 | /** |
| 47 | * | 37 | * |
| ... | @@ -81,6 +71,10 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -81,6 +71,10 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 81 | @AsyncMqSend | 71 | @AsyncMqSend |
| 82 | public void asyncPointsDetail(PointsDetail pointsDetail) {} | 72 | public void asyncPointsDetail(PointsDetail pointsDetail) {} |
| 83 | 73 | ||
| 74 | /** | ||
| 75 | * uc-admin调用此接口进行发放积分 | ||
| 76 | * @param tempPoints | ||
| 77 | */ | ||
| 84 | @Override | 78 | @Override |
| 85 | public void grantPointsByManualByTempPoints(TempPoints tempPoints) { | 79 | public void grantPointsByManualByTempPoints(TempPoints tempPoints) { |
| 86 | Timestamp expireTime = tempPoints.getExpireTime(); | 80 | Timestamp expireTime = tempPoints.getExpireTime(); |
| ... | @@ -88,7 +82,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -88,7 +82,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 88 | tempPoints.setExpireTime(TimestampUtil.localDateTime2Timestamp(DateUtil.getLastDateTimeSecondYear())); | 82 | tempPoints.setExpireTime(TimestampUtil.localDateTime2Timestamp(DateUtil.getLastDateTimeSecondYear())); |
| 89 | } | 83 | } |
| 90 | 84 | ||
| 91 | this.refresh(tempPoints); | 85 | this.refresh(Arrays.asList(tempPoints)); |
| 92 | } | 86 | } |
| 93 | 87 | ||
| 94 | /** | 88 | /** |
| ... | @@ -106,6 +100,8 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -106,6 +100,8 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 106 | 100 | ||
| 107 | try { | 101 | try { |
| 108 | this.redisUtils.doLock(RedisKeyConstants.cacheMemberById + memberId.toString()); | 102 | this.redisUtils.doLock(RedisKeyConstants.cacheMemberById + memberId.toString()); |
| 103 | MemberDTO memberDTO = this.memberService.findById(memberId); | ||
| 104 | |||
| 109 | //1.删除过期的积分 | 105 | //1.删除过期的积分 |
| 110 | this.cleanInvalidAvailablePointsByMemberId(memberId); | 106 | this.cleanInvalidAvailablePointsByMemberId(memberId); |
| 111 | log.info("删除过期的积分 ==>> cleanInvalidAvailablePointsByMemberId ==>> "); | 107 | log.info("删除过期的积分 ==>> cleanInvalidAvailablePointsByMemberId ==>> "); |
| ... | @@ -115,7 +111,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -115,7 +111,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 115 | long currentPoints = this.findAvailablePointsByMemberId(memberId); | 111 | long currentPoints = this.findAvailablePointsByMemberId(memberId); |
| 116 | if (b) { | 112 | if (b) { |
| 117 | // 2.可用积分表,按照过期时间进行升序排列 | 113 | // 2.可用积分表,按照过期时间进行升序排列 |
| 118 | List<PointsAvailableDTO> pointsAvailableDTOS = this.findByMemberIdOrderByExpireTime(tempPoints); | 114 | List<PointsAvailableDTO> pointsAvailableDTOS = this.pointsAvailableService.findByMemberIdOrderByExpireTime(tempPoints.getMemberId()); |
| 119 | // 2.优先使用即将过期的积分,累加到超过需兑换积分时,需要进行拆分 | 115 | // 2.优先使用即将过期的积分,累加到超过需兑换积分时,需要进行拆分 |
| 120 | Map<String, List<PointsAvailableDTO>> customAvailablePointsMap = | 116 | Map<String, List<PointsAvailableDTO>> customAvailablePointsMap = |
| 121 | this.customAvailablePoints(tempPoints, pointsAvailableDTOS); | 117 | this.customAvailablePoints(tempPoints, pointsAvailableDTOS); |
| ... | @@ -125,11 +121,10 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -125,11 +121,10 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 125 | // 4.更新可用积分表,超过的删除,剩余的新增 | 121 | // 4.更新可用积分表,超过的删除,剩余的新增 |
| 126 | long totalPoints = this.doFreshTrPointsAvailableByAvailablePointsMap(customAvailablePointsMap, currentPoints); | 122 | long totalPoints = this.doFreshTrPointsAvailableByAvailablePointsMap(customAvailablePointsMap, currentPoints); |
| 127 | // 5.即将过期的积分 | 123 | // 5.即将过期的积分 |
| 128 | long soonExpirePoints = this.getSoonExpirePoints(memberId, tempPoints); | 124 | // long soonExpirePoints = this.getSoonExpirePoints(memberId, tempPoints); |
| 129 | |||
| 130 | 125 | ||
| 131 | // 6.更新会员积分信息 | 126 | // 6.更新会员积分信息 |
| 132 | this.freshMemberCurrentPoints(memberId, totalPoints, soonExpirePoints); | 127 | this.freshMemberCurrentPoints(memberId, memberDTO.getCode(), totalPoints); |
| 133 | 128 | ||
| 134 | customPointsResult.setResult(true); | 129 | customPointsResult.setResult(true); |
| 135 | customPointsResult.setPoint(totalPoints); | 130 | customPointsResult.setPoint(totalPoints); |
| ... | @@ -275,14 +270,6 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -275,14 +270,6 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 275 | return map; | 270 | return map; |
| 276 | } | 271 | } |
| 277 | 272 | ||
| 278 | /** | ||
| 279 | * 可用积分表,按照过期时间进行升序排列 | ||
| 280 | * @param tempPoints | ||
| 281 | * @return | ||
| 282 | */ | ||
| 283 | private List<PointsAvailableDTO> findByMemberIdOrderByExpireTime(TempPoints tempPoints) { | ||
| 284 | return this.pointsAvailableService.findByMemberIdOrderByExpireTime(tempPoints.getMemberId()); | ||
| 285 | } | ||
| 286 | 273 | ||
| 287 | /** | 274 | /** |
| 288 | * 检查当前用户可用积分是否足够 | 275 | * 检查当前用户可用积分是否足够 |
| ... | @@ -308,9 +295,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -308,9 +295,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 308 | @Override | 295 | @Override |
| 309 | @Transactional(rollbackFor = Exception.class) | 296 | @Transactional(rollbackFor = Exception.class) |
| 310 | public void grantPointsThroughTempPoint(List<TempPoints> tempPointsList){ | 297 | public void grantPointsThroughTempPoint(List<TempPoints> tempPointsList){ |
| 311 | for (TempPoints tempPoints : tempPointsList){ | 298 | this.refresh(tempPointsList); |
| 312 | this.refresh(tempPoints); | ||
| 313 | } | ||
| 314 | } | 299 | } |
| 315 | 300 | ||
| 316 | /** | 301 | /** |
| ... | @@ -372,7 +357,6 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -372,7 +357,6 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 372 | 357 | ||
| 373 | member.setPoints(currentPoints); | 358 | member.setPoints(currentPoints); |
| 374 | member.setDuePoints(soonExpirePoints); | 359 | member.setDuePoints(soonExpirePoints); |
| 375 | // this.memberOperationService.update(member); | ||
| 376 | this.memberOperationService.doUpdateMemberPoints(member); | 360 | this.memberOperationService.doUpdateMemberPoints(member); |
| 377 | } | 361 | } |
| 378 | 362 | ||
| ... | @@ -416,7 +400,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -416,7 +400,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 416 | pointsDetail.setCreateTime(TimestampUtil.now()); | 400 | pointsDetail.setCreateTime(TimestampUtil.now()); |
| 417 | pointsDetail.setUpdateTime(TimestampUtil.now()); | 401 | pointsDetail.setUpdateTime(TimestampUtil.now()); |
| 418 | pointsDetail.setMemberCode(memberDTO.getCode()); | 402 | pointsDetail.setMemberCode(memberDTO.getCode()); |
| 419 | this.pointsDetailService.create4Custom(pointsDetail); | 403 | this.pointsDetailService.insertPointsDetail(pointsDetail); |
| 420 | 404 | ||
| 421 | log.info("asyncPointsDetail ==>> pointsDetail ==>> {}",pointsDetail); | 405 | log.info("asyncPointsDetail ==>> pointsDetail ==>> {}",pointsDetail); |
| 422 | ((PointsOperationServiceImpl) AopContext.currentProxy()).asyncPointsDetail(pointsDetail); | 406 | ((PointsOperationServiceImpl) AopContext.currentProxy()).asyncPointsDetail(pointsDetail); |
| ... | @@ -425,47 +409,39 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -425,47 +409,39 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 425 | /** | 409 | /** |
| 426 | * 模板方法,提供更新积分的总体流程 | 410 | * 模板方法,提供更新积分的总体流程 |
| 427 | * | 411 | * |
| 428 | * @param tempPoints 积分 | 412 | * @param tempPointsList 积分 |
| 429 | */ | 413 | */ |
| 430 | private void refresh(TempPoints tempPoints) { | 414 | private void refresh(List<TempPoints> tempPointsList) { |
| 415 | TempPoints tempPoints = tempPointsList.get(0); | ||
| 431 | Long memberId = tempPoints.getMemberId(); | 416 | Long memberId = tempPoints.getMemberId(); |
| 432 | String memberCode = tempPoints.getMemberCode(); | 417 | String memberCode = tempPoints.getMemberCode(); |
| 433 | log.info("----------->> 会员id ===>>>>" + memberId); | ||
| 434 | try { | 418 | try { |
| 435 | this.redisUtils.doLock(RedisKeyConstants.updateCachePointsByMemberId + memberId.toString()); | 419 | this.redisUtils.doLock(RedisKeyConstants.updateCachePointsByMemberId + memberId.toString()); |
| 420 | |||
| 436 | // 1.可用总积分 | 421 | // 1.可用总积分 |
| 437 | long l = System.currentTimeMillis(); | ||
| 438 | Long currentPoints = this.findAvailablePointsByMemberId(memberId); | 422 | Long currentPoints = this.findAvailablePointsByMemberId(memberId); |
| 439 | long l1 = System.currentTimeMillis(); | 423 | log.info("----------->> 获取会员当前可用总积分 --->>>> {}", currentPoints); |
| 440 | // log.info("查询大屏信息,总耗时 ==>> {}", (l1-l)); | ||
| 441 | log.info("----------->> 获取会员当前可用总积分 --->>>> {}, 总耗时 ==>> {}", currentPoints, (l1-l)); | ||
| 442 | |||
| 443 | // 2.计算总积分 | ||
| 444 | Long totalPoints = currentPoints + tempPoints.getPoints(); | ||
| 445 | log.info("----------->> 总积分(可用总积分+获得的积分) --->>> {}", totalPoints); | ||
| 446 | 424 | ||
| 425 | Long totalPoints = currentPoints; | ||
| 426 | for (TempPoints tempPoint : tempPointsList) { | ||
| 447 | // 3.添加积分明细 | 427 | // 3.添加积分明细 |
| 448 | long l2 = System.currentTimeMillis(); | 428 | totalPoints = this.doInsertTrPointsDetail(memberId, memberCode, tempPoint, totalPoints, (totalPoints + tempPoint.getPoints())); |
| 449 | this.doInsertTrPointsDetail(memberId, memberCode, tempPoints, currentPoints, totalPoints); | 429 | log.info("----------->> 总积分(可用总积分+获得的积分) --->>> {}", totalPoints); |
| 450 | long l3 = System.currentTimeMillis(); | ||
| 451 | log.info("----------->> 添加积分明细 --->>> 总耗时 ==>> {}", (l3-l2)); | ||
| 452 | 430 | ||
| 453 | // 4.添加可用积分 | 431 | // 4.添加可用积分 |
| 454 | long l4 = System.currentTimeMillis(); | 432 | this.doInsertTrPointsAvailable(tempPoint); |
| 455 | this.doInsertTrPointsAvailable(tempPoints); | 433 | log.info("----------->> 添加可用积分结束"); |
| 456 | long l5 = System.currentTimeMillis(); | 434 | |
| 457 | log.info("----------->> 添加可用积分 -->>> 总耗时 ==>> {}", (l5-l4)); | 435 | } |
| 458 | 436 | ||
| 459 | // 5.即将过期的积分 | 437 | // 5.即将过期的积分 |
| 460 | // TODO 查询的时候再更新过期积分 | 438 | // TODO 查询的时候再更新过期积分 |
| 461 | long soonExpirePoints = this.getSoonExpirePoints(memberId, tempPoints); | 439 | // long soonExpirePoints = this.getSoonExpirePoints(memberId, tempPoints); |
| 462 | log.info("----------->> 即将过期的积分 ------->>>>> {}", soonExpirePoints); | 440 | // log.info("----------->> 即将过期的积分 ------->>>>> {}", soonExpirePoints); |
| 463 | 441 | ||
| 464 | // 6.更新会员的总积分 | 442 | // 6.更新会员的总积分 |
| 465 | long l6 = System.currentTimeMillis(); | 443 | this.freshMemberCurrentPoints(memberId, memberCode, totalPoints); |
| 466 | this.freshMemberCurrentPoints(memberId, totalPoints, soonExpirePoints); | 444 | log.info("----------->> 更新会员的总积分 ------->>>>> 总积分--->>> {}", totalPoints); |
| 467 | long l7 = System.currentTimeMillis(); | ||
| 468 | log.info("----------->> 更新会员的总积分 ------->>>>> 总积分--->>> {} -->>总耗时 ==>> {}", totalPoints, (l7-l6)); | ||
| 469 | } catch (Exception e) { | 445 | } catch (Exception e) { |
| 470 | log.error(" ==>> {}", e.getMessage()); | 446 | log.error(" ==>> {}", e.getMessage()); |
| 471 | } finally { | 447 | } finally { |
| ... | @@ -474,20 +450,6 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -474,20 +450,6 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 474 | } | 450 | } |
| 475 | 451 | ||
| 476 | /** | 452 | /** |
| 477 | * 获取总积分 | ||
| 478 | * @param tempPoints | ||
| 479 | * @param currentPoints | ||
| 480 | * @return | ||
| 481 | */ | ||
| 482 | private Long calculateTotalPoints(TempPoints tempPoints, Long currentPoints) { | ||
| 483 | // 获取的积分 | ||
| 484 | Long rewardPoints = tempPoints.getPoints(); | ||
| 485 | // 总积分 | ||
| 486 | Long totalPoints = currentPoints + tempPoints.getPoints(); | ||
| 487 | return totalPoints; | ||
| 488 | } | ||
| 489 | |||
| 490 | /** | ||
| 491 | * 获取即将过期的积分 | 453 | * 获取即将过期的积分 |
| 492 | * @param memberId | 454 | * @param memberId |
| 493 | * @return | 455 | * @return |
| ... | @@ -516,24 +478,18 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -516,24 +478,18 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 516 | /** | 478 | /** |
| 517 | * 更新会员总积分 | 479 | * 更新会员总积分 |
| 518 | * @param memberId 会员Id | 480 | * @param memberId 会员Id |
| 519 | * @param currentPoints 当前总积分 | 481 | * @param memberCode 当前总积分 |
| 520 | */ | 482 | */ |
| 521 | private void freshMemberCurrentPoints(Long memberId, Long currentPoints, long duePoints) { | 483 | private void freshMemberCurrentPoints(Long memberId, String memberCode, Long currentPoints) { |
| 522 | |||
| 523 | MemberDTO memberDTO = this.memberService.findById(memberId); | ||
| 524 | |||
| 525 | Member member = new Member(); | 484 | Member member = new Member(); |
| 526 | member.setId(memberDTO.getId()); | 485 | member.setId(memberId); |
| 527 | member.setCode(memberDTO.getCode()); | 486 | member.setCode(memberCode); |
| 528 | member.setPoints(Objects.nonNull(currentPoints) ? currentPoints:0); | 487 | member.setPoints(Objects.nonNull(currentPoints) ? currentPoints:0); |
| 529 | member.setDuePoints(duePoints); | ||
| 530 | member.setUpdateTime(TimestampUtil.now()); | 488 | member.setUpdateTime(TimestampUtil.now()); |
| 531 | try { | 489 | try { |
| 532 | this.memberOperationService.doUpdateMemberPoints(member); | 490 | this.memberOperationService.doUpdateMemberPoints(member); |
| 533 | 491 | ||
| 534 | /*this.threadPoolTaskExecutor.submit(() -> { | ||
| 535 | ((PointsOperationServiceImpl) AopContext.currentProxy()).asyncMemberPoint(member); | 492 | ((PointsOperationServiceImpl) AopContext.currentProxy()).asyncMemberPoint(member); |
| 536 | });*/ | ||
| 537 | } catch (Exception e){ | 493 | } catch (Exception e){ |
| 538 | log.error("同步会员积分异常,"+e.getMessage()); | 494 | log.error("同步会员积分异常,"+e.getMessage()); |
| 539 | } | 495 | } |
| ... | @@ -549,7 +505,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -549,7 +505,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 549 | BeanUtils.copyProperties(tempPoints,pointsAvailable); | 505 | BeanUtils.copyProperties(tempPoints,pointsAvailable); |
| 550 | 506 | ||
| 551 | String description = pointsAvailable.getDescription(); | 507 | String description = pointsAvailable.getDescription(); |
| 552 | pointsAvailable.setCode(String.valueOf(IdWorker.generator())); | 508 | pointsAvailable.setCode("pointsA_"+UUID.randomUUID().toString()); |
| 553 | pointsAvailable.setDescription(StringUtils.isEmpty(description)?"#":description); | 509 | pointsAvailable.setDescription(StringUtils.isEmpty(description)?"#":description); |
| 554 | Timestamp timestamp = tempPoints.getExpireTime(); | 510 | Timestamp timestamp = tempPoints.getExpireTime(); |
| 555 | if (Objects.nonNull(timestamp)) { | 511 | if (Objects.nonNull(timestamp)) { |
| ... | @@ -557,9 +513,9 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -557,9 +513,9 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 557 | } | 513 | } |
| 558 | 514 | ||
| 559 | this.pointsAvailableService.create4Custom(pointsAvailable); | 515 | this.pointsAvailableService.create4Custom(pointsAvailable); |
| 560 | /*this.threadPoolTaskExecutor.submit(() -> { | 516 | |
| 561 | ((PointsOperationServiceImpl) AopContext.currentProxy()).asyncPointsAvailable(pointsAvailable); | 517 | ((PointsOperationServiceImpl) AopContext.currentProxy()).asyncPointsAvailable(pointsAvailable); |
| 562 | });*/ | 518 | |
| 563 | } | 519 | } |
| 564 | 520 | ||
| 565 | /** | 521 | /** |
| ... | @@ -568,30 +524,34 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -568,30 +524,34 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 568 | * @param tempPoints 积分 | 524 | * @param tempPoints 积分 |
| 569 | * @return Integer 总积分 | 525 | * @return Integer 总积分 |
| 570 | */ | 526 | */ |
| 571 | private void doInsertTrPointsDetail(Long memberId, String memberCode, TempPoints tempPoints, Long currentPoints, Long totalPoints){ | 527 | private Long doInsertTrPointsDetail(Long memberId, String memberCode, TempPoints tempPoints, Long currentPoints, Long totalPoints){ |
| 572 | 528 | ||
| 573 | PointsDetail pointsDetail = new PointsDetail(); | 529 | PointsDetail pointsDetail = new PointsDetail(); |
| 574 | BeanUtils.copyProperties(tempPoints, pointsDetail); | ||
| 575 | pointsDetail.setId(null); | 530 | pointsDetail.setId(null); |
| 576 | pointsDetail.setMemberId(memberId); | 531 | pointsDetail.setMemberId(memberId); |
| 577 | pointsDetail.setMemberCode(memberCode); | 532 | pointsDetail.setMemberCode(memberCode); |
| 578 | pointsDetail.setCode(String.valueOf(IdWorker.generator())); | 533 | pointsDetail.setCode("pointsD_"+UUID.randomUUID().toString()); |
| 579 | pointsDetail.setPoints(tempPoints.getPoints()); | 534 | pointsDetail.setPoints(tempPoints.getPoints()); |
| 580 | pointsDetail.setOriginalPoints(currentPoints); | 535 | pointsDetail.setOriginalPoints(currentPoints); |
| 581 | pointsDetail.setResultPoints(totalPoints); | 536 | pointsDetail.setResultPoints(totalPoints); |
| 582 | pointsDetail.setCreateTime(null); | 537 | pointsDetail.setEvtType(tempPoints.getEvtType()); |
| 583 | pointsDetail.setUpdateTime(null); | 538 | pointsDetail.setDeviceType(tempPoints.getDeviceType()); |
| 584 | String description = pointsDetail.getDescription(); | 539 | pointsDetail.setOrderId(tempPoints.getOrderId()); |
| 540 | pointsDetail.setMediaId(tempPoints.getMediaId()); | ||
| 541 | pointsDetail.setAccountId(tempPoints.getAccountId()); | ||
| 542 | pointsDetail.setActivityId(tempPoints.getActivityId()); | ||
| 543 | pointsDetail.setAppCode(tempPoints.getAppCode()); | ||
| 544 | String description = tempPoints.getDescription(); | ||
| 585 | if (StringUtils.isEmpty(description)) { | 545 | if (StringUtils.isEmpty(description)) { |
| 586 | pointsDetail.setDescription("#"); | 546 | pointsDetail.setDescription("#"); |
| 587 | } | 547 | } |
| 588 | 548 | ||
| 589 | // 保存积分流水 | 549 | // 保存积分流水 |
| 590 | this.pointsDetailService.create4Custom(pointsDetail); | 550 | this.pointsDetailService.insertPointsDetail(pointsDetail); |
| 591 | 551 | ||
| 592 | /*this.threadPoolTaskExecutor.submit(() -> { | ||
| 593 | ((PointsOperationServiceImpl) AopContext.currentProxy()).asyncPointsDetail(pointsDetail); | 552 | ((PointsOperationServiceImpl) AopContext.currentProxy()).asyncPointsDetail(pointsDetail); |
| 594 | });*/ | 553 | |
| 554 | return totalPoints; | ||
| 595 | } | 555 | } |
| 596 | 556 | ||
| 597 | } | 557 | } | ... | ... |
| ... | @@ -21,12 +21,8 @@ import org.springframework.stereotype.Service; | ... | @@ -21,12 +21,8 @@ import org.springframework.stereotype.Service; |
| 21 | import org.springframework.util.CollectionUtils; | 21 | import org.springframework.util.CollectionUtils; |
| 22 | import org.springframework.util.StringUtils; | 22 | import org.springframework.util.StringUtils; |
| 23 | 23 | ||
| 24 | import javax.annotation.Resource; | ||
| 25 | import java.sql.Timestamp; | 24 | import java.sql.Timestamp; |
| 26 | import java.util.*; | 25 | import java.util.*; |
| 27 | import java.util.concurrent.ExecutionException; | ||
| 28 | import java.util.concurrent.Future; | ||
| 29 | import java.util.concurrent.ThreadPoolExecutor; | ||
| 30 | 26 | ||
| 31 | /** | 27 | /** |
| 32 | * 权益处理 | 28 | * 权益处理 |
| ... | @@ -77,31 +73,7 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -77,31 +73,7 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 77 | @Override | 73 | @Override |
| 78 | public Integer grantRights(Map<RightType, Object> tempRightsMap) { | 74 | public Integer grantRights(Map<RightType, Object> tempRightsMap) { |
| 79 | 75 | ||
| 80 | this.threadPoolTaskExecutor.execute(()-> { | ||
| 81 | // 2.创建权益历史对象 | ||
| 82 | List<RightsHistory> rightsList = this.getRightHistory(tempRightsMap); | ||
| 83 | if (!CollectionUtils.isEmpty(rightsList)) { | ||
| 84 | // log.info("异步保存权益领取历史开始 ==>> [{}]", rightsList); | ||
| 85 | long l = System.currentTimeMillis(); | ||
| 86 | // 3.保存权益历史 | ||
| 87 | this.doInsertTrRightHistory(rightsList); | ||
| 88 | long l1 = System.currentTimeMillis(); | ||
| 89 | log.info("保存权益历史,总耗时 ==>> {}", l1-l); | ||
| 90 | } | ||
| 91 | }); | ||
| 92 | |||
| 93 | // 1.权益下发 | ||
| 94 | return this.refresh(tempRightsMap); | ||
| 95 | } | ||
| 96 | |||
| 97 | /** | ||
| 98 | * | ||
| 99 | * @param tempRightsMap | ||
| 100 | * @return | ||
| 101 | */ | ||
| 102 | private List<RightsHistory> getRightHistory(Map<RightType, Object> tempRightsMap) { | ||
| 103 | List<TempRights> values = (List<TempRights>)tempRightsMap.get(RightType.RIGHTS); | 76 | List<TempRights> values = (List<TempRights>)tempRightsMap.get(RightType.RIGHTS); |
| 104 | List<RightsHistory> rightsHistoryList = new ArrayList<>(); | ||
| 105 | if (!CollectionUtils.isEmpty(values)) { | 77 | if (!CollectionUtils.isEmpty(values)) { |
| 106 | values.forEach(value -> { | 78 | values.forEach(value -> { |
| 107 | RightsHistory rightsHistory = new RightsHistory(); | 79 | RightsHistory rightsHistory = new RightsHistory(); |
| ... | @@ -111,11 +83,18 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -111,11 +83,18 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 111 | rightsHistory.setExpireTime(value.getExpireTime()); | 83 | rightsHistory.setExpireTime(value.getExpireTime()); |
| 112 | String memberCode = value.getMemberCode(); | 84 | String memberCode = value.getMemberCode(); |
| 113 | rightsHistory.setMemberCode(memberCode); | 85 | rightsHistory.setMemberCode(memberCode); |
| 114 | rightsHistoryList.add(rightsHistory); | 86 | Long operatorId = rightsHistory.getOperatorId(); |
| 87 | String operatorName = rightsHistory.getOperatorName(); | ||
| 88 | rightsHistory.setSendTime(TimestampUtil.now()); | ||
| 89 | rightsHistory.setOperatorId(Objects.nonNull(operatorId)?operatorId:0); | ||
| 90 | rightsHistory.setOperatorName(!StringUtils.isEmpty(operatorName)?operatorName:"系统发放"); | ||
| 91 | this.rightsHistoryService.create(rightsHistory); | ||
| 115 | }); | 92 | }); |
| 116 | } | 93 | } |
| 117 | 94 | ||
| 118 | return rightsHistoryList; | 95 | |
| 96 | // 1.权益下发 | ||
| 97 | return this.refresh(tempRightsMap); | ||
| 119 | } | 98 | } |
| 120 | 99 | ||
| 121 | /** | 100 | /** |
| ... | @@ -155,29 +134,22 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -155,29 +134,22 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 155 | */ | 134 | */ |
| 156 | private Integer refresh(Map<RightType, Object> tempRightsMap) { | 135 | private Integer refresh(Map<RightType, Object> tempRightsMap) { |
| 157 | 136 | ||
| 158 | // Future<?> submit = this.threadPoolTaskExecutor.submit(() -> { | ||
| 159 | List<TempPoints> tempPointsList = (List<TempPoints>) tempRightsMap.get(RightType.POINTS); | 137 | List<TempPoints> tempPointsList = (List<TempPoints>) tempRightsMap.get(RightType.POINTS); |
| 160 | if (!CollectionUtils.isEmpty(tempPointsList)) { | 138 | if (!CollectionUtils.isEmpty(tempPointsList)) { |
| 161 | // log.info("发放积分开始 ==>> [{}]", tempPointsList); | ||
| 162 | long l = System.currentTimeMillis(); | ||
| 163 | // 积分 | 139 | // 积分 |
| 140 | log.info("发放积分开始 ==>> {}", tempPointsList); | ||
| 164 | this.grantPoint(tempPointsList); | 141 | this.grantPoint(tempPointsList); |
| 165 | long l2 = System.currentTimeMillis(); | 142 | log.info("发放积分结束 ==>> {}", tempPointsList); |
| 166 | log.info("发放积分结束,总耗时 ==>> {}", (l2 - l)); | ||
| 167 | } | 143 | } |
| 168 | // }); | 144 | // }); |
| 169 | 145 | ||
| 170 | this.threadPoolTaskExecutor.submit(() -> { | ||
| 171 | List<TempExp> tempExpList = (List<TempExp>) tempRightsMap.get(RightType.EXP); | 146 | List<TempExp> tempExpList = (List<TempExp>) tempRightsMap.get(RightType.EXP); |
| 172 | if (!CollectionUtils.isEmpty(tempExpList)) { | 147 | if (!CollectionUtils.isEmpty(tempExpList)) { |
| 173 | // log.info("发放成长值开始 ==>> [{}]", tempExpList); | ||
| 174 | long l = System.currentTimeMillis(); | ||
| 175 | // 成长值 | 148 | // 成长值 |
| 149 | log.info("发放成长值开始 ==>> {}", tempExpList); | ||
| 176 | this.grantExp(tempExpList); | 150 | this.grantExp(tempExpList); |
| 177 | long l2 = System.currentTimeMillis(); | 151 | log.info("发放成长值结束 ==>> "); |
| 178 | log.info("发放成长值结束,总耗时 ==>> {}", (l2 - l)); | ||
| 179 | } | 152 | } |
| 180 | }); | ||
| 181 | 153 | ||
| 182 | // this.threadPoolTaskExecutor.submit(() -> { | 154 | // this.threadPoolTaskExecutor.submit(() -> { |
| 183 | /*List<TempCoupon> tempCouponList = (List<TempCoupon>) tempRightsMap.get(RightType.COUPON); | 155 | /*List<TempCoupon> tempCouponList = (List<TempCoupon>) tempRightsMap.get(RightType.COUPON); |
| ... | @@ -192,15 +164,8 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -192,15 +164,8 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 192 | // }); | 164 | // }); |
| 193 | 165 | ||
| 194 | // 其他权益 | 166 | // 其他权益 |
| 195 | // Future<?> submit = this.threadPoolTaskExecutor.submit(() -> { | ||
| 196 | // log.info("发放其他权益开始 ==>> [{}]", tempRightsMap); | ||
| 197 | long l = System.currentTimeMillis(); | ||
| 198 | this.grantOtherRight(tempRightsMap); | 167 | this.grantOtherRight(tempRightsMap); |
| 199 | long l2 = System.currentTimeMillis(); | 168 | log.info("发放其他权益结束 ==>>" ); |
| 200 | log.info("发放其他权益结束 ==>> 总耗时 ==>> {}", l-l2); | ||
| 201 | // }); | ||
| 202 | |||
| 203 | |||
| 204 | 169 | ||
| 205 | return tempRightsMap.keySet().size(); | 170 | return tempRightsMap.keySet().size(); |
| 206 | } | 171 | } | ... | ... |
| 1 | package com.topdraw.business.process.service.impl; | 1 | package com.topdraw.business.process.service.impl; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.map.MapUtil; | ||
| 3 | import com.alibaba.fastjson.JSON; | 4 | import com.alibaba.fastjson.JSON; |
| 4 | import com.alibaba.fastjson.JSONObject; | 5 | import com.alibaba.fastjson.JSONObject; |
| 5 | import com.topdraw.aspect.AsyncMqSend; | 6 | import com.topdraw.aspect.AsyncMqSend; |
| ... | @@ -227,25 +228,17 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -227,25 +228,17 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 227 | 228 | ||
| 228 | // 大屏侧传递的参数是platformAccount | 229 | // 大屏侧传递的参数是platformAccount |
| 229 | MemberSimpleDTO memberDTO = null; | 230 | MemberSimpleDTO memberDTO = null; |
| 230 | if (Objects.nonNull(memberIdObj)) { | 231 | if (Objects.nonNull(platformAccountObj)) { |
| 231 | // 小屏侧传递的参数是memberId | ||
| 232 | memberDTO = this.memberService.findSimpleById(Long.valueOf(memberIdObj.toString())); | ||
| 233 | |||
| 234 | } else { | ||
| 235 | 232 | ||
| 236 | String platformAccount = platformAccountObj.toString(); | 233 | String platformAccount = platformAccountObj.toString(); |
| 237 | long l = System.currentTimeMillis(); | ||
| 238 | UserTvSimpleDTO userTvDTO = this.userTvService.findSimpleByPlatformAccount(platformAccount); | 234 | UserTvSimpleDTO userTvDTO = this.userTvService.findSimpleByPlatformAccount(platformAccount); |
| 239 | long l1 = System.currentTimeMillis(); | 235 | log.info("查询大屏信息 ==>> {}", userTvDTO); |
| 240 | log.info("查询大屏信息,总耗时 ==>> {}", (l1-l)); | ||
| 241 | 236 | ||
| 242 | if (Objects.nonNull(userTvDTO)) { | 237 | if (Objects.nonNull(userTvDTO)) { |
| 243 | 238 | ||
| 244 | // 在查找任务之前对用户行为进行预处理 | ||
| 245 | this.preFindTask(platformAccount, dataSyncMsg, msgData); | ||
| 246 | |||
| 247 | // 开启积分自动同步至小屏主会员 | 239 | // 开启积分自动同步至小屏主会员 |
| 248 | if (validPriorityMember == 0) { | 240 | if (validPriorityMember == 0) { |
| 241 | |||
| 249 | String priorityMemberCode = userTvDTO.getPriorityMemberCode(); | 242 | String priorityMemberCode = userTvDTO.getPriorityMemberCode(); |
| 250 | if (StringUtils.isNotBlank(priorityMemberCode)) { | 243 | if (StringUtils.isNotBlank(priorityMemberCode)) { |
| 251 | // TODO 是否需要将code和id都进行缓存 | 244 | // TODO 是否需要将code和id都进行缓存 |
| ... | @@ -260,10 +253,8 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -260,10 +253,8 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 260 | 253 | ||
| 261 | } else { | 254 | } else { |
| 262 | 255 | ||
| 263 | long l2 = System.currentTimeMillis(); | ||
| 264 | memberDTO = this.memberService.findSimpleById(userTvDTO.getMemberId()); | 256 | memberDTO = this.memberService.findSimpleById(userTvDTO.getMemberId()); |
| 265 | long l3 = System.currentTimeMillis(); | 257 | log.info("查询大屏会员信息 ==>> {}", memberDTO); |
| 266 | log.info("查询大屏会员信息,总耗时 ==>> {}", (l3-l2)); | ||
| 267 | } | 258 | } |
| 268 | 259 | ||
| 269 | } else { | 260 | } else { |
| ... | @@ -273,6 +264,9 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -273,6 +264,9 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 273 | 264 | ||
| 274 | log.info("获取大屏会员信息 ==>> platformAccount ==>> {} || 会员信息 ==>> {}", platformAccount, memberDTO); | 265 | log.info("获取大屏会员信息 ==>> platformAccount ==>> {} || 会员信息 ==>> {}", platformAccount, memberDTO); |
| 275 | 266 | ||
| 267 | } else { | ||
| 268 | // 小屏侧传递的参数是memberId | ||
| 269 | memberDTO = this.memberService.findSimpleById(Long.valueOf(memberIdObj.toString())); | ||
| 276 | } | 270 | } |
| 277 | 271 | ||
| 278 | if (Objects.isNull(memberDTO.getId())) { | 272 | if (Objects.isNull(memberDTO.getId())) { |
| ... | @@ -299,23 +293,9 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -299,23 +293,9 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 299 | if (!CollectionUtils.isEmpty(tasks)) { | 293 | if (!CollectionUtils.isEmpty(tasks)) { |
| 300 | // 5.权益区分(积分、权益、成长值) | 294 | // 5.权益区分(积分、权益、成长值) |
| 301 | Map<RightType,Object> tempRightsMap = this.distinguishRight(memberDTO, tasks, msgData, dataSyncMsg); | 295 | Map<RightType,Object> tempRightsMap = this.distinguishRight(memberDTO, tasks, msgData, dataSyncMsg); |
| 302 | // log.info("获取当前任务对应的权益 tempRightsMap ==>> {} ", tempRightsMap); | ||
| 303 | |||
| 304 | // 6.风控检查 TODO | ||
| 305 | // boolean result = this.checkRiskManagement(memberId, tempRightsMap); | ||
| 306 | // log.info("针对各项权益检查当前会员是否达到风控值 ==>> {},true:已达到风控指标 ", result); | ||
| 307 | |||
| 308 | // if (result) throw new BadRequestException("发放失败,已达风控上限"); | ||
| 309 | |||
| 310 | // long l1 = System.currentTimeMillis(); | ||
| 311 | // log.info("各项检查总耗时 ==>> {}", (l1-l)); | ||
| 312 | 296 | ||
| 313 | // 7.权益发放 | 297 | // 7.权益发放 |
| 314 | // log.info("下发开始 ==>> {}", tempRightsMap); | ||
| 315 | // long l2 = System.currentTimeMillis(); | ||
| 316 | Integer integer = this.grantRight(tempRightsMap); | 298 | Integer integer = this.grantRight(tempRightsMap); |
| 317 | // long l3 = System.currentTimeMillis(); | ||
| 318 | // log.info("下发结束,总耗时 ==>> {}", (l3-l2)); | ||
| 319 | 299 | ||
| 320 | if (integer > 0) { | 300 | if (integer > 0) { |
| 321 | return ResultInfo.success(integer); | 301 | return ResultInfo.success(integer); |
| ... | @@ -326,42 +306,6 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -326,42 +306,6 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 326 | 306 | ||
| 327 | } | 307 | } |
| 328 | 308 | ||
| 329 | private void preFindTask(String platformAccount, DataSyncMsg dataSyncMsg, JSONObject msgData) { | ||
| 330 | |||
| 331 | switch (dataSyncMsg.getEvent()) { | ||
| 332 | |||
| 333 | case TaskEventType.PLAY: | ||
| 334 | this.calculateTotalPlayDuration(platformAccount, dataSyncMsg, msgData); | ||
| 335 | break; | ||
| 336 | |||
| 337 | } | ||
| 338 | |||
| 339 | } | ||
| 340 | |||
| 341 | private void calculateTotalPlayDuration(String platformAccount, DataSyncMsg dataSyncMsg, JSONObject msgData) { | ||
| 342 | String key = RedisKeyConstants.CACHE_PLATFROMACCOUNT_PLAYDURATION+"::"+platformAccount+"|"+dataSyncMsg.getTime().toLocalDate(); | ||
| 343 | Map<Object, Object> hmget = this.redisUtils.hmget(key); | ||
| 344 | if (Objects.nonNull(hmget)) { | ||
| 345 | Object totalPlayDuration = hmget.get("total"); | ||
| 346 | if (Objects.isNull(totalPlayDuration)) { | ||
| 347 | Map<Object, Object> map = new HashMap<>(); | ||
| 348 | map.put("total", msgData.get("playDuration")); | ||
| 349 | // 存储时间36小时 | ||
| 350 | this.redisUtils.hmset(key, map, 129600); | ||
| 351 | } else { | ||
| 352 | Map<Object, Object> map = new HashMap<>(); | ||
| 353 | // 计算播放总时长 total = 播放总时长+当前播放时长 | ||
| 354 | totalPlayDuration = Integer.parseInt(totalPlayDuration.toString()) + Integer.parseInt(msgData.get("playDuration").toString()); | ||
| 355 | map.put("total", totalPlayDuration); | ||
| 356 | this.redisUtils.hmset(key, map); | ||
| 357 | |||
| 358 | msgData.put("playDuration", totalPlayDuration); | ||
| 359 | } | ||
| 360 | |||
| 361 | } | ||
| 362 | // | ||
| 363 | } | ||
| 364 | |||
| 365 | /** | 309 | /** |
| 366 | * | 310 | * |
| 367 | * @param id 主键 | 311 | * @param id 主键 |
| ... | @@ -385,8 +329,8 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -385,8 +329,8 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 385 | TrTaskProgress _trTaskProgress = this.trTaskProgressService.create(trTaskProgress, LocalDateTimeUtil.todayStart()); | 329 | TrTaskProgress _trTaskProgress = this.trTaskProgressService.create(trTaskProgress, LocalDateTimeUtil.todayStart()); |
| 386 | 330 | ||
| 387 | if (status.equals(TASK_FINISH_STATUS) && Objects.nonNull(_trTaskProgress)) { | 331 | if (status.equals(TASK_FINISH_STATUS) && Objects.nonNull(_trTaskProgress)) { |
| 388 | Map<Object, Object> hmget = this.redisUtils.hmget(RedisKeyConstants.cacheTodayFinishTaskCount + "::" + memberId + ":" + LocalDate.now()); | 332 | boolean todayFinishCount = this.redisUtils.hHasKey(RedisKeyConstants.cacheTodayFinishTaskCount + "::" + memberId + ":" + LocalDate.now(), task.getId().toString()); |
| 389 | if (Objects.isNull(hmget)) { | 333 | if (!todayFinishCount) { |
| 390 | Map<Object, Object> finishTasks = new HashMap<>(); | 334 | Map<Object, Object> finishTasks = new HashMap<>(); |
| 391 | finishTasks.put(task.getId(), 1); | 335 | finishTasks.put(task.getId(), 1); |
| 392 | // 单天的记录只存储一天 | 336 | // 单天的记录只存储一天 |
| ... | @@ -395,6 +339,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -395,6 +339,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 395 | this.redisUtils.hincr(RedisKeyConstants.cacheTodayFinishTaskCount+"::"+memberId+":"+LocalDate.now(), task.getId().toString(), 1); | 339 | this.redisUtils.hincr(RedisKeyConstants.cacheTodayFinishTaskCount+"::"+memberId+":"+LocalDate.now(), task.getId().toString(), 1); |
| 396 | } | 340 | } |
| 397 | 341 | ||
| 342 | // 永久 | ||
| 398 | this.redisUtils.hincr(RedisKeyConstants.cacheTotalFinishTaskCount+"::"+memberId, task.getId().toString(), 1); | 343 | this.redisUtils.hincr(RedisKeyConstants.cacheTotalFinishTaskCount+"::"+memberId, task.getId().toString(), 1); |
| 399 | } | 344 | } |
| 400 | 345 | ||
| ... | @@ -426,7 +371,6 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -426,7 +371,6 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 426 | List<Task> tasksResult = new ArrayList<>(); | 371 | List<Task> tasksResult = new ArrayList<>(); |
| 427 | // 检查当前会员针对这些任务的完成情况 | 372 | // 检查当前会员针对这些任务的完成情况 |
| 428 | for (Task task : tasks) { | 373 | for (Task task : tasks) { |
| 429 | |||
| 430 | /*// 校验用户分组 | 374 | /*// 校验用户分组 |
| 431 | if (StringUtils.isNotBlank(task.getGroups()) && !task.getGroups().contains(memberDTO.getGroups())) { | 375 | if (StringUtils.isNotBlank(task.getGroups()) && !task.getGroups().contains(memberDTO.getGroups())) { |
| 432 | log.warn("此用户分组不满足任务要求,任务分组 ==>> {} || 会员分组 ==>> {}",task.getGroups(), memberDTO.getGroups()); | 376 | log.warn("此用户分组不满足任务要求,任务分组 ==>> {} || 会员分组 ==>> {}",task.getGroups(), memberDTO.getGroups()); |
| ... | @@ -439,7 +383,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -439,7 +383,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 439 | Integer taskRepeatType = task.getTaskRepeatType(); | 383 | Integer taskRepeatType = task.getTaskRepeatType(); |
| 440 | if (taskDailyReset.equals(0)) { | 384 | if (taskDailyReset.equals(0)) { |
| 441 | // 不重置,检查是否做过此任务 | 385 | // 不重置,检查是否做过此任务 |
| 442 | Object finishCount = finishTaskCount.get(task.getId()); | 386 | Object finishCount = finishTaskCount.get(task.getId().toString()); |
| 443 | if (!taskRepeatType.equals(-1) && Objects.nonNull(finishCount)) { | 387 | if (!taskRepeatType.equals(-1) && Objects.nonNull(finishCount)) { |
| 444 | if (Long.parseLong(finishCount.toString()) >= taskRepeatType) { | 388 | if (Long.parseLong(finishCount.toString()) >= taskRepeatType) { |
| 445 | continue; | 389 | continue; |
| ... | @@ -448,8 +392,8 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -448,8 +392,8 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 448 | 392 | ||
| 449 | } else { | 393 | } else { |
| 450 | 394 | ||
| 451 | Object todayFinishCount = todayFinishTask.get(task.getId()); | 395 | Object todayFinishCount = todayFinishTask.get(task.getId().toString()); |
| 452 | if (taskRepeatType > 1 && Objects.nonNull(todayFinishCount)) { | 396 | if (taskRepeatType >= 1 && Objects.nonNull(todayFinishCount)) { |
| 453 | if (Long.parseLong(todayFinishCount.toString()) >= taskRepeatType) { | 397 | if (Long.parseLong(todayFinishCount.toString()) >= taskRepeatType) { |
| 454 | continue; | 398 | continue; |
| 455 | } | 399 | } |
| ... | @@ -589,7 +533,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -589,7 +533,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 589 | private boolean doSignEvent(JSONObject msgData, Task task, MemberSimpleDTO memberDTO) { | 533 | private boolean doSignEvent(JSONObject msgData, Task task, MemberSimpleDTO memberDTO) { |
| 590 | Integer actionAmount = task.getActionAmount(); | 534 | Integer actionAmount = task.getActionAmount(); |
| 591 | // // 用户行为次数 签到天数 | 535 | // // 用户行为次数 签到天数 |
| 592 | int signDays = msgData.getInteger("SIGN"); | 536 | int signDays = msgData.getInteger("signDays"); |
| 593 | if (signDays >= actionAmount) { | 537 | if (signDays >= actionAmount) { |
| 594 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, signDays, TASK_FINISH_STATUS); | 538 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, signDays, TASK_FINISH_STATUS); |
| 595 | return true; | 539 | return true; |
| ... | @@ -625,7 +569,9 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -625,7 +569,9 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 625 | * @param paramJsonObject | 569 | * @param paramJsonObject |
| 626 | */ | 570 | */ |
| 627 | private boolean doPlayEvent(JSONObject paramJsonObject, Task task, MemberSimpleDTO memberSimpleDTO) { | 571 | private boolean doPlayEvent(JSONObject paramJsonObject, Task task, MemberSimpleDTO memberSimpleDTO) { |
| 572 | // 任务最低行为量 | ||
| 628 | Integer actionAmount = task.getActionAmount(); | 573 | Integer actionAmount = task.getActionAmount(); |
| 574 | // 用户实际播放时长 | ||
| 629 | int playDuration = paramJsonObject.getInteger("playDuration"); | 575 | int playDuration = paramJsonObject.getInteger("playDuration"); |
| 630 | if (playDuration >= actionAmount) { | 576 | if (playDuration >= actionAmount) { |
| 631 | 577 | ||
| ... | @@ -663,17 +609,17 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -663,17 +609,17 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 663 | /** | 609 | /** |
| 664 | * 权益区分 | 610 | * 权益区分 |
| 665 | * | 611 | * |
| 666 | * @param taskList 任务列表 | 612 | * @param tasks 任务列表 |
| 667 | * @return Map<RightType,Object> 权益分类 | 613 | * @return Map<RightType,Object> 权益分类 |
| 668 | */ | 614 | */ |
| 669 | private Map<RightType,Object> distinguishRight(MemberSimpleDTO memberDTO, List<Task> taskList, JSONObject msgData, DataSyncMsg dataSyncMsg) { | 615 | private Map<RightType,Object> distinguishRight(MemberSimpleDTO memberDTO, List<Task> tasks, JSONObject msgData, DataSyncMsg dataSyncMsg) { |
| 670 | 616 | ||
| 671 | Map<RightType,Object> map = new HashMap<>(); | 617 | Map<RightType,Object> map = new HashMap<>(); |
| 672 | 618 | ||
| 673 | // 区分权益类型(成长值(reward_exp)、积分(reward_points)、实体券),并发放权益 | 619 | // 区分权益类型(成长值(reward_exp)、积分(reward_points)、实体券),并发放权益 |
| 674 | List<TempPoints> tempPoints = new ArrayList<>(); | 620 | List<TempPoints> tempPoints = new ArrayList<>(); |
| 675 | List<TempExp> tempExps = new ArrayList<>(); | 621 | List<TempExp> tempExps = new ArrayList<>(); |
| 676 | for (Task task : taskList) { | 622 | for (Task task : tasks) { |
| 677 | 623 | ||
| 678 | // 积分 | 624 | // 积分 |
| 679 | this.getTempPoints(memberDTO, msgData, task, dataSyncMsg, tempPoints); | 625 | this.getTempPoints(memberDTO, msgData, task, dataSyncMsg, tempPoints); | ... | ... |
| ... | @@ -189,7 +189,7 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -189,7 +189,7 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 189 | * @return UserWeixinDTO | 189 | * @return UserWeixinDTO |
| 190 | */ | 190 | */ |
| 191 | @Override | 191 | @Override |
| 192 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | 192 | @Transactional(rollbackFor = Exception.class) |
| 193 | public UserWeixinDTO createWeixinUserAndMember(UserWeixin resources) { | 193 | public UserWeixinDTO createWeixinUserAndMember(UserWeixin resources) { |
| 194 | return this.createWeixinUserAndMember(resources, 0); | 194 | return this.createWeixinUserAndMember(resources, 0); |
| 195 | } | 195 | } |
| ... | @@ -1075,7 +1075,7 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -1075,7 +1075,7 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 1075 | UserTvSimpleDTO userTvSimpleDTO = this.userTvService.findSimpleByPlatformAccount(platformAccount); | 1075 | UserTvSimpleDTO userTvSimpleDTO = this.userTvService.findSimpleByPlatformAccount(platformAccount); |
| 1076 | if (Objects.nonNull(userTvDTO)) { | 1076 | if (Objects.nonNull(userTvDTO)) { |
| 1077 | userTvSimpleDTO.setPriorityMemberCode(memberDTO.getCode()); | 1077 | userTvSimpleDTO.setPriorityMemberCode(memberDTO.getCode()); |
| 1078 | HashMap hashMap = JSONObject.parseObject(userTvSimpleDTO.toString(), HashMap.class); | 1078 | JSONObject hashMap = JSONObject.parseObject(JSON.toJSONString(userTvDTO), JSONObject.class); |
| 1079 | this.redisUtils.set(RedisKeyConstants.cacheVisUserByPlatformAccount + "::" + platformAccount, hashMap); | 1079 | this.redisUtils.set(RedisKeyConstants.cacheVisUserByPlatformAccount + "::" + platformAccount, hashMap); |
| 1080 | } | 1080 | } |
| 1081 | return userTvDTO; | 1081 | return userTvDTO; | ... | ... |
| ... | @@ -73,19 +73,19 @@ public class MemberOperationServiceImpl implements MemberOperationService { | ... | @@ -73,19 +73,19 @@ public class MemberOperationServiceImpl implements MemberOperationService { |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | @Override | 75 | @Override |
| 76 | public MemberDTO doUpdateMemberExpAndLevel(Member resources) { | 76 | public Integer doUpdateMemberExpAndLevel(Member resources) { |
| 77 | return this.memberService.doUpdateMemberExpAndLevel(resources); | 77 | return this.memberService.doUpdateMemberExpAndLevel(resources); |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | @Override | 80 | @Override |
| 81 | public MemberDTO doUpdateMemberPoints(Member resources) { | 81 | public Integer doUpdateMemberPoints(Member resources) { |
| 82 | return this.memberService.doUpdateMemberPoints(resources); | 82 | return this.memberService.doUpdateMemberPoints(resources); |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | 85 | ||
| 86 | @Override | 86 | @Override |
| 87 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#member.code", unless = "#result.id == null") | 87 | // @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#member.code", unless = "#result.id == null") |
| 88 | public MemberDTO doUpdateMemberCoupon(Member member) { | 88 | public Integer doUpdateMemberCoupon(Member member) { |
| 89 | return this.memberService.doUpdateMemberCoupon(member); | 89 | return this.memberService.doUpdateMemberCoupon(member); |
| 90 | } | 90 | } |
| 91 | 91 | ... | ... |
| ... | @@ -47,19 +47,19 @@ public interface MemberOperationService { | ... | @@ -47,19 +47,19 @@ public interface MemberOperationService { |
| 47 | * | 47 | * |
| 48 | * @param resources | 48 | * @param resources |
| 49 | */ | 49 | */ |
| 50 | MemberDTO doUpdateMemberExpAndLevel(Member resources); | 50 | Integer doUpdateMemberExpAndLevel(Member resources); |
| 51 | 51 | ||
| 52 | /** | 52 | /** |
| 53 | * | 53 | * |
| 54 | * @param resources | 54 | * @param resources |
| 55 | */ | 55 | */ |
| 56 | MemberDTO doUpdateMemberPoints(Member resources); | 56 | Integer doUpdateMemberPoints(Member resources); |
| 57 | 57 | ||
| 58 | /** | 58 | /** |
| 59 | * | 59 | * |
| 60 | * @param resources | 60 | * @param resources |
| 61 | */ | 61 | */ |
| 62 | MemberDTO doUpdateMemberCoupon(Member resources); | 62 | Integer doUpdateMemberCoupon(Member resources); |
| 63 | 63 | ||
| 64 | /** | 64 | /** |
| 65 | * | 65 | * | ... | ... |
| ... | @@ -14,6 +14,7 @@ public interface RedisKeyConstants { | ... | @@ -14,6 +14,7 @@ public interface RedisKeyConstants { |
| 14 | String cacheMemberById = "uce::member::id"; | 14 | String cacheMemberById = "uce::member::id"; |
| 15 | // 任务处理时会员信息 | 15 | // 任务处理时会员信息 |
| 16 | String cacheMemberSimpleById = "uce::memberSimple::id"; | 16 | String cacheMemberSimpleById = "uce::memberSimple::id"; |
| 17 | String cacheMemberSimpleByCode = "uce::memberSimple::code"; | ||
| 17 | // 会员全量信息 | 18 | // 会员全量信息 |
| 18 | String cacheMemberByCode = "uce::member::code"; | 19 | String cacheMemberByCode = "uce::member::code"; |
| 19 | 20 | ||
| ... | @@ -26,7 +27,7 @@ public interface RedisKeyConstants { | ... | @@ -26,7 +27,7 @@ public interface RedisKeyConstants { |
| 26 | 27 | ||
| 27 | // 全量大屏信息 | 28 | // 全量大屏信息 |
| 28 | String cacheUserTvByPlatformAccount = "uce::userTv::platformAccount"; | 29 | String cacheUserTvByPlatformAccount = "uce::userTv::platformAccount"; |
| 29 | String cacheVisUserByPlatformAccount = "uus::visUser::platformAccount"; | 30 | String cacheVisUserByPlatformAccount = "uus::visUser"; |
| 30 | // 会员已完成的任务进度 | 31 | // 会员已完成的任务进度 |
| 31 | String cacheTaskProcessByMemberId = "uce::taskProcess::memberId"; | 32 | String cacheTaskProcessByMemberId = "uce::taskProcess::memberId"; |
| 32 | // 任务模板类型对应的全量任务 | 33 | // 任务模板类型对应的全量任务 | ... | ... |
-
Please register or sign in to post a comment