1.优化部分任务处理接口,修改接收任务事件模型
2.为任务处理添加缓存
Showing
46 changed files
with
1157 additions
and
1084 deletions
member-service-impl/src/main/java/com/topdraw/business/module/member/domain/MemberSimple.java
0 → 100644
| 1 | package com.topdraw.business.module.member.domain; | ||
| 2 | |||
| 3 | import cn.hutool.core.bean.BeanUtil; | ||
| 4 | import cn.hutool.core.bean.copier.CopyOptions; | ||
| 5 | import com.topdraw.business.module.common.validated.UpdateGroup; | ||
| 6 | import lombok.Data; | ||
| 7 | import lombok.experimental.Accessors; | ||
| 8 | import org.springframework.data.annotation.CreatedDate; | ||
| 9 | import org.springframework.data.annotation.LastModifiedDate; | ||
| 10 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
| 11 | |||
| 12 | import javax.persistence.*; | ||
| 13 | import javax.validation.constraints.NotNull; | ||
| 14 | import java.io.Serializable; | ||
| 15 | import java.sql.Timestamp; | ||
| 16 | |||
| 17 | /** | ||
| 18 | * @author XiangHan | ||
| 19 | * @date 2021-10-22 | ||
| 20 | */ | ||
| 21 | @Entity | ||
| 22 | @Data | ||
| 23 | @EntityListeners(AuditingEntityListener.class) | ||
| 24 | @Accessors(chain = true) | ||
| 25 | @Table(name="uc_member") | ||
| 26 | public class MemberSimple implements Serializable { | ||
| 27 | |||
| 28 | /** 主键 */ | ||
| 29 | @Id | ||
| 30 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| 31 | @Column(name = "id") | ||
| 32 | @NotNull(message = "id can't be null!!",groups = {UpdateGroup.class}) | ||
| 33 | private Long id; | ||
| 34 | |||
| 35 | /** 标识 */ | ||
| 36 | @Column(name = "code") | ||
| 37 | private String code; | ||
| 38 | |||
| 39 | /** 状态 0:不可用;1:可用 */ | ||
| 40 | @Column(name = "`status`") | ||
| 41 | private Integer status; | ||
| 42 | |||
| 43 | /** 分组信息 */ | ||
| 44 | @Column(name = "`groups`") | ||
| 45 | private String groups; | ||
| 46 | |||
| 47 | /** 是否会员 0:非会员;1:会员 */ | ||
| 48 | @Column(name = "vip") | ||
| 49 | private Integer vip; | ||
| 50 | |||
| 51 | /** 会员等级(对应level表的level字段,非id) */ | ||
| 52 | @Column(name = "`level`") | ||
| 53 | private Integer level; | ||
| 54 | |||
| 55 | /** iptv账号id */ | ||
| 56 | @Column(name = "user_iptv_id") | ||
| 57 | private Long userIptvId; | ||
| 58 | |||
| 59 | /** 是否在黑名单 1:是;0否 */ | ||
| 60 | @Column(name = "black_status") | ||
| 61 | private Long blackStatus; | ||
| 62 | |||
| 63 | public void copy(MemberSimple source){ | ||
| 64 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(false)); | ||
| 65 | } | ||
| 66 | } |
| 1 | package com.topdraw.business.module.member.level.service.impl; | 1 | package com.topdraw.business.module.member.level.service.impl; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.member.level.domain.MemberLevel; | 3 | import com.topdraw.business.module.member.level.domain.MemberLevel; |
| 4 | import com.topdraw.config.RedisKeyConstants; | ||
| 4 | import com.topdraw.utils.ValidationUtil; | 5 | import com.topdraw.utils.ValidationUtil; |
| 5 | import com.topdraw.business.module.member.level.repository.MemberLevelRepository; | 6 | import com.topdraw.business.module.member.level.repository.MemberLevelRepository; |
| 6 | import com.topdraw.business.module.member.level.service.MemberLevelService; | 7 | import com.topdraw.business.module.member.level.service.MemberLevelService; |
| 7 | import com.topdraw.business.module.member.level.service.dto.MemberLevelDTO; | 8 | import com.topdraw.business.module.member.level.service.dto.MemberLevelDTO; |
| 8 | import com.topdraw.business.module.member.level.service.mapper.MemberLevelMapper; | 9 | import com.topdraw.business.module.member.level.service.mapper.MemberLevelMapper; |
| 9 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
| 11 | import org.springframework.cache.annotation.Cacheable; | ||
| 10 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 11 | import org.springframework.transaction.annotation.Propagation; | 13 | import org.springframework.transaction.annotation.Propagation; |
| 12 | import org.springframework.transaction.annotation.Transactional; | 14 | import org.springframework.transaction.annotation.Transactional; |
| ... | @@ -42,8 +44,9 @@ public class MemberLevelServiceImpl implements MemberLevelService { | ... | @@ -42,8 +44,9 @@ public class MemberLevelServiceImpl implements MemberLevelService { |
| 42 | } | 44 | } |
| 43 | 45 | ||
| 44 | @Override | 46 | @Override |
| 47 | @Cacheable(cacheNames = RedisKeyConstants.cacheMemberLevelByLevel, key = "#level", unless = "#result.size() == 0") | ||
| 45 | public List<MemberLevelDTO> findLevelAndStatus(Integer level, Integer status) { | 48 | public List<MemberLevelDTO> findLevelAndStatus(Integer level, Integer status) { |
| 46 | return this.memberLevelMapper.toDto(this.memberLevelRepository.findByLevelAndStatus(level,status)); | 49 | return this.memberLevelMapper.toDto(this.memberLevelRepository.findByLevelAndStatus(level, status)); |
| 47 | } | 50 | } |
| 48 | 51 | ||
| 49 | } | 52 | } | ... | ... |
| 1 | package com.topdraw.business.module.member.repository; | 1 | package com.topdraw.business.module.member.repository; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.member.domain.Member; | 3 | import com.topdraw.business.module.member.domain.Member; |
| 4 | import com.topdraw.business.module.member.domain.MemberSimple; | ||
| 4 | import org.springframework.data.jpa.repository.JpaRepository; | 5 | import org.springframework.data.jpa.repository.JpaRepository; |
| 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | 6 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
| 6 | import org.springframework.data.jpa.repository.Modifying; | 7 | import org.springframework.data.jpa.repository.Modifying; | ... | ... |
| 1 | package com.topdraw.business.module.member.repository; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.member.domain.MemberSimple; | ||
| 4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
| 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
| 6 | import org.springframework.data.jpa.repository.Query; | ||
| 7 | |||
| 8 | import java.util.Optional; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * @author XiangHan | ||
| 12 | * @date 2021-10-22 | ||
| 13 | */ | ||
| 14 | public interface MemberSimpleRepository extends JpaRepository<MemberSimple, Long>, JpaSpecificationExecutor<MemberSimple> { | ||
| 15 | |||
| 16 | @Query(value = "SELECT `id`, `code`, `status`, `groups`, `vip`, `level`,`user_iptv_id`, `black_status` FROM `uc_member` WHERE `id` = ?1", nativeQuery = true) | ||
| 17 | Optional<MemberSimple> findSimpleById(Long id); | ||
| 18 | |||
| 19 | @Query(value = "SELECT `id`, `code`, `status`, `groups`, `vip`, `level`,`user_iptv_id`, `black_status` FROM `uc_member` WHERE `code` = ?1", nativeQuery = true) | ||
| 20 | Optional<MemberSimple> findSimpleByCode(String code); | ||
| 21 | } |
| ... | @@ -2,6 +2,8 @@ package com.topdraw.business.module.member.service; | ... | @@ -2,6 +2,8 @@ package com.topdraw.business.module.member.service; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.member.domain.Member; | 3 | import com.topdraw.business.module.member.domain.Member; |
| 4 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 4 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
| 5 | import com.topdraw.business.module.member.service.dto.MemberSimpleDTO; | ||
| 6 | import org.springframework.transaction.annotation.Transactional; | ||
| 5 | 7 | ||
| 6 | import java.util.List; | 8 | import java.util.List; |
| 7 | 9 | ||
| ... | @@ -26,6 +28,13 @@ public interface MemberService { | ... | @@ -26,6 +28,13 @@ public interface MemberService { |
| 26 | MemberDTO findById(Long id); | 28 | MemberDTO findById(Long id); |
| 27 | 29 | ||
| 28 | /** | 30 | /** |
| 31 | * | ||
| 32 | * @param id | ||
| 33 | * @return | ||
| 34 | */ | ||
| 35 | MemberSimpleDTO findSimpleById(Long id); | ||
| 36 | |||
| 37 | /** | ||
| 29 | * 通过code查询会员 | 38 | * 通过code查询会员 |
| 30 | * @param code 会员编码 | 39 | * @param code 会员编码 |
| 31 | * @return MemberDTO | 40 | * @return MemberDTO |
| ... | @@ -33,6 +42,13 @@ public interface MemberService { | ... | @@ -33,6 +42,13 @@ public interface MemberService { |
| 33 | MemberDTO findByCode(String code); | 42 | MemberDTO findByCode(String code); |
| 34 | 43 | ||
| 35 | /** | 44 | /** |
| 45 | * | ||
| 46 | * @param code | ||
| 47 | * @return | ||
| 48 | */ | ||
| 49 | MemberSimpleDTO findSimpleByCode(String code); | ||
| 50 | |||
| 51 | /** | ||
| 36 | * 保存 | 52 | * 保存 |
| 37 | * @param resources | 53 | * @param resources |
| 38 | * @return Long id | 54 | * @return Long id | ... | ... |
| 1 | package com.topdraw.business.module.member.service.dto; | ||
| 2 | |||
| 3 | import lombok.Data; | ||
| 4 | |||
| 5 | import java.io.Serializable; | ||
| 6 | import java.sql.Timestamp; | ||
| 7 | |||
| 8 | |||
| 9 | /** | ||
| 10 | * @author XiangHan | ||
| 11 | * @date 2021-10-22 | ||
| 12 | */ | ||
| 13 | @Data | ||
| 14 | public class MemberSimpleDTO implements Serializable { | ||
| 15 | |||
| 16 | /** 主键 */ | ||
| 17 | private Long id; | ||
| 18 | |||
| 19 | /** 标识 */ | ||
| 20 | private String code; | ||
| 21 | |||
| 22 | /** 昵称 */ | ||
| 23 | private String nickname; | ||
| 24 | |||
| 25 | /** 状态 0:不可用;1:可用 */ | ||
| 26 | private Integer status; | ||
| 27 | |||
| 28 | /** 分组信息 */ | ||
| 29 | private String groups; | ||
| 30 | |||
| 31 | /** 是否会员 0:非会员;1:会员 */ | ||
| 32 | private Integer vip; | ||
| 33 | |||
| 34 | /** 会员等级(对应level表的level字段,非id) */ | ||
| 35 | private Integer level; | ||
| 36 | |||
| 37 | /** iptv账号id */ | ||
| 38 | private Long userIptvId; | ||
| 39 | |||
| 40 | /** 是否在黑名单 1:是;0否 */ | ||
| 41 | private Long blackStatus; | ||
| 42 | |||
| 43 | } |
| ... | @@ -2,22 +2,26 @@ package com.topdraw.business.module.member.service.impl; | ... | @@ -2,22 +2,26 @@ package com.topdraw.business.module.member.service.impl; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.member.domain.Member; | 3 | import com.topdraw.business.module.member.domain.Member; |
| 4 | import com.topdraw.business.module.member.domain.MemberBuilder; | 4 | import com.topdraw.business.module.member.domain.MemberBuilder; |
| 5 | import com.topdraw.business.module.member.domain.MemberSimple; | ||
| 5 | import com.topdraw.business.module.member.profile.domain.MemberProfile; | 6 | import com.topdraw.business.module.member.profile.domain.MemberProfile; |
| 6 | import com.topdraw.business.module.member.profile.domain.MemberProfileBuilder; | 7 | import com.topdraw.business.module.member.profile.domain.MemberProfileBuilder; |
| 7 | import com.topdraw.business.module.member.profile.service.MemberProfileService; | 8 | import com.topdraw.business.module.member.profile.service.MemberProfileService; |
| 8 | import com.topdraw.business.module.member.repository.MemberRepository; | 9 | import com.topdraw.business.module.member.repository.MemberRepository; |
| 10 | import com.topdraw.business.module.member.repository.MemberSimpleRepository; | ||
| 9 | import com.topdraw.business.module.member.service.MemberService; | 11 | import com.topdraw.business.module.member.service.MemberService; |
| 10 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 12 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
| 13 | import com.topdraw.business.module.member.service.dto.MemberSimpleDTO; | ||
| 11 | import com.topdraw.business.module.member.service.mapper.MemberMapper; | 14 | import com.topdraw.business.module.member.service.mapper.MemberMapper; |
| 15 | import com.topdraw.business.module.member.service.mapper.MemberSimpleMapper; | ||
| 12 | import com.topdraw.config.RedisKeyConstants; | 16 | import com.topdraw.config.RedisKeyConstants; |
| 13 | import com.topdraw.exception.BadRequestException; | 17 | import com.topdraw.exception.BadRequestException; |
| 14 | import com.topdraw.exception.GlobeExceptionMsg; | 18 | import com.topdraw.exception.GlobeExceptionMsg; |
| 15 | import com.topdraw.utils.RedisUtils; | ||
| 16 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
| 17 | import org.apache.commons.lang3.StringUtils; | 20 | import org.apache.commons.lang3.StringUtils; |
| 18 | import org.springframework.beans.BeanUtils; | 21 | import org.springframework.beans.BeanUtils; |
| 19 | import org.springframework.beans.factory.annotation.Autowired; | 22 | import org.springframework.beans.factory.annotation.Autowired; |
| 20 | import org.springframework.cache.annotation.CachePut; | 23 | import org.springframework.cache.annotation.CachePut; |
| 24 | import org.springframework.cache.annotation.Cacheable; | ||
| 21 | import org.springframework.stereotype.Service; | 25 | import org.springframework.stereotype.Service; |
| 22 | import org.springframework.transaction.annotation.Propagation; | 26 | import org.springframework.transaction.annotation.Propagation; |
| 23 | import org.springframework.transaction.annotation.Transactional; | 27 | import org.springframework.transaction.annotation.Transactional; |
| ... | @@ -38,31 +42,51 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -38,31 +42,51 @@ public class MemberServiceImpl implements MemberService { |
| 38 | @Autowired | 42 | @Autowired |
| 39 | private MemberRepository memberRepository; | 43 | private MemberRepository memberRepository; |
| 40 | @Autowired | 44 | @Autowired |
| 45 | private MemberSimpleRepository memberSimpleRepository; | ||
| 46 | @Autowired | ||
| 41 | private MemberProfileService memberProfileService; | 47 | private MemberProfileService memberProfileService; |
| 42 | |||
| 43 | @Autowired | 48 | @Autowired |
| 44 | private RedisUtils redisUtils; | 49 | private MemberSimpleMapper memberSimpleMapper; |
| 45 | 50 | ||
| 46 | @Override | 51 | @Override |
| 52 | @Transactional(readOnly = true) | ||
| 47 | public String findCodeById(Long id) { | 53 | public String findCodeById(Long id) { |
| 48 | MemberDTO memberDTO = this.findById(id); | 54 | MemberDTO memberDTO = this.findById(id); |
| 49 | return memberDTO.getCode(); | 55 | return memberDTO.getCode(); |
| 50 | } | 56 | } |
| 51 | 57 | ||
| 52 | @Override | 58 | @Override |
| 59 | @Transactional(readOnly = true) | ||
| 60 | @Cacheable(cacheNames = RedisKeyConstants.cacheMemberById, key = "#id") | ||
| 53 | public MemberDTO findById(Long id) { | 61 | public MemberDTO findById(Long id) { |
| 54 | Member member = this.memberRepository.findById(id).orElseGet(Member::new); | 62 | Member member = this.memberRepository.findById(id).orElseGet(Member::new); |
| 55 | return this.memberMapper.toDto(member); | 63 | return this.memberMapper.toDto(member); |
| 56 | } | 64 | } |
| 57 | 65 | ||
| 66 | |||
| 58 | @Override | 67 | @Override |
| 59 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#code") | 68 | @Transactional(readOnly = true) |
| 69 | @Cacheable(cacheNames = RedisKeyConstants.cacheMemberSimpleById, key = "#id", unless = "#result.id == null") | ||
| 70 | public MemberSimpleDTO findSimpleById(Long id) { | ||
| 71 | return this.memberSimpleMapper.toDto(this.memberSimpleRepository.findSimpleById(id).orElseGet(MemberSimple::new)); | ||
| 72 | } | ||
| 73 | |||
| 74 | @Override | ||
| 75 | @Transactional(readOnly = true) | ||
| 60 | public MemberDTO findByCode(String code) { | 76 | public MemberDTO findByCode(String code) { |
| 61 | Member member = this.memberRepository.findFirstByCode(code).orElseGet(Member::new); | 77 | Member member = this.memberRepository.findFirstByCode(code).orElseGet(Member::new); |
| 62 | return this.memberMapper.toDto(member); | 78 | return this.memberMapper.toDto(member); |
| 63 | } | 79 | } |
| 64 | 80 | ||
| 65 | @Override | 81 | @Override |
| 82 | @Transactional(readOnly = true) | ||
| 83 | @Cacheable(cacheNames = RedisKeyConstants.cacheMemberSimpleById, key = "#id", unless = "#result.id == null") | ||
| 84 | public MemberSimpleDTO findSimpleByCode(String code) { | ||
| 85 | return this.memberSimpleMapper.toDto(this.memberSimpleRepository.findSimpleByCode(code).orElseGet(MemberSimple::new)); | ||
| 86 | } | ||
| 87 | |||
| 88 | @Override | ||
| 89 | @Transactional(readOnly = true) | ||
| 66 | public List<MemberDTO> findByUserIptvId(Long id) { | 90 | public List<MemberDTO> findByUserIptvId(Long id) { |
| 67 | List<Member> memberList = this.memberRepository.findByUserIptvId(id); | 91 | List<Member> memberList = this.memberRepository.findByUserIptvId(id); |
| 68 | return this.memberMapper.toDto(memberList); | 92 | return this.memberMapper.toDto(memberList); |
| ... | @@ -94,10 +118,10 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -94,10 +118,10 @@ public class MemberServiceImpl implements MemberService { |
| 94 | 118 | ||
| 95 | @Override | 119 | @Override |
| 96 | @Transactional(rollbackFor = Exception.class) | 120 | @Transactional(rollbackFor = Exception.class) |
| 97 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#code") | 121 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#resource.code") |
| 98 | public MemberDTO doUpdateMemberExpAndLevel(Member resource) { | 122 | public MemberDTO doUpdateMemberExpAndLevel(Member resource) { |
| 99 | try { | 123 | try { |
| 100 | this.redisUtils.doLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); | 124 | // this.redisUtils.doLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); |
| 101 | 125 | ||
| 102 | Integer count = this.memberRepository.updateExpAndLevel(resource); | 126 | Integer count = this.memberRepository.updateExpAndLevel(resource); |
| 103 | if (Objects.nonNull(count) && count > 0) { | 127 | if (Objects.nonNull(count) && count > 0) { |
| ... | @@ -107,7 +131,7 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -107,7 +131,7 @@ public class MemberServiceImpl implements MemberService { |
| 107 | } catch (Exception e) { | 131 | } catch (Exception e) { |
| 108 | log.info("修改会员优惠券,"+e.getMessage()); | 132 | log.info("修改会员优惠券,"+e.getMessage()); |
| 109 | } finally { | 133 | } finally { |
| 110 | this.redisUtils.doUnLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); | 134 | // this.redisUtils.doUnLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); |
| 111 | } | 135 | } |
| 112 | 136 | ||
| 113 | return this.memberMapper.toDto(resource); | 137 | return this.memberMapper.toDto(resource); |
| ... | @@ -115,11 +139,11 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -115,11 +139,11 @@ public class MemberServiceImpl implements MemberService { |
| 115 | 139 | ||
| 116 | @Override | 140 | @Override |
| 117 | @Transactional(rollbackFor = Exception.class) | 141 | @Transactional(rollbackFor = Exception.class) |
| 118 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#code") | 142 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#resource.code") |
| 119 | public MemberDTO doUpdateMemberCoupon(Member resource) { | 143 | public MemberDTO doUpdateMemberCoupon(Member resource) { |
| 120 | log.info("修改会员优惠券 =>> {}", resource); | 144 | log.info("修改会员优惠券 =>> {}", resource); |
| 121 | try { | 145 | try { |
| 122 | this.redisUtils.doLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); | 146 | // this.redisUtils.doLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); |
| 123 | 147 | ||
| 124 | Integer count = this.memberRepository.doUpdateMemberCoupon(resource); | 148 | Integer count = this.memberRepository.doUpdateMemberCoupon(resource); |
| 125 | if (Objects.nonNull(count) && count > 0) { | 149 | if (Objects.nonNull(count) && count > 0) { |
| ... | @@ -130,13 +154,14 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -130,13 +154,14 @@ public class MemberServiceImpl implements MemberService { |
| 130 | } catch (Exception e) { | 154 | } catch (Exception e) { |
| 131 | log.info("修改会员优惠券,"+e.getMessage()); | 155 | log.info("修改会员优惠券,"+e.getMessage()); |
| 132 | } finally { | 156 | } finally { |
| 133 | this.redisUtils.doUnLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); | 157 | // this.redisUtils.doUnLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); |
| 134 | } | 158 | } |
| 135 | 159 | ||
| 136 | return this.memberMapper.toDto(resource); | 160 | return this.memberMapper.toDto(resource); |
| 137 | } | 161 | } |
| 138 | 162 | ||
| 139 | @Override | 163 | @Override |
| 164 | @Transactional(readOnly = true) | ||
| 140 | public MemberDTO findByPlatformAccount(String platformAccount) { | 165 | public MemberDTO findByPlatformAccount(String platformAccount) { |
| 141 | log.info("从数据库中检索大屏账号对应的会员, platformAccount ==>> {}", platformAccount); | 166 | log.info("从数据库中检索大屏账号对应的会员, platformAccount ==>> {}", platformAccount); |
| 142 | Member member = this.memberRepository.findByPlatformAccount(platformAccount).orElseGet(Member::new); | 167 | Member member = this.memberRepository.findByPlatformAccount(platformAccount).orElseGet(Member::new); |
| ... | @@ -145,11 +170,11 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -145,11 +170,11 @@ public class MemberServiceImpl implements MemberService { |
| 145 | 170 | ||
| 146 | @Override | 171 | @Override |
| 147 | @Transactional(rollbackFor = Exception.class) | 172 | @Transactional(rollbackFor = Exception.class) |
| 148 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#code") | 173 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#resource.code") |
| 149 | public MemberDTO doUpdateMemberVipAndVipExpireTime(Member resource) { | 174 | public MemberDTO doUpdateMemberVipAndVipExpireTime(Member resource) { |
| 150 | log.info("修改会员vip和vip过期时间 ==>> {}", resource); | 175 | log.info("修改会员vip和vip过期时间 ==>> {}", resource); |
| 151 | try { | 176 | try { |
| 152 | this.redisUtils.doLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); | 177 | // this.redisUtils.doLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); |
| 153 | 178 | ||
| 154 | Integer count = this.memberRepository.updateMemberVipAndVipExpireTime(resource); | 179 | Integer count = this.memberRepository.updateMemberVipAndVipExpireTime(resource); |
| 155 | if (Objects.nonNull(count) && count > 0) { | 180 | if (Objects.nonNull(count) && count > 0) { |
| ... | @@ -160,7 +185,7 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -160,7 +185,7 @@ public class MemberServiceImpl implements MemberService { |
| 160 | } catch (Exception e) { | 185 | } catch (Exception e) { |
| 161 | log.info("修改会员vip和vip过期时间,"+e.getMessage()); | 186 | log.info("修改会员vip和vip过期时间,"+e.getMessage()); |
| 162 | } finally { | 187 | } finally { |
| 163 | this.redisUtils.doUnLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); | 188 | // this.redisUtils.doUnLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); |
| 164 | } | 189 | } |
| 165 | 190 | ||
| 166 | return this.memberMapper.toDto(resource); | 191 | return this.memberMapper.toDto(resource); |
| ... | @@ -168,11 +193,11 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -168,11 +193,11 @@ public class MemberServiceImpl implements MemberService { |
| 168 | 193 | ||
| 169 | @Override | 194 | @Override |
| 170 | @Transactional(rollbackFor = Exception.class) | 195 | @Transactional(rollbackFor = Exception.class) |
| 171 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#code") | 196 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#resource.code") |
| 172 | public MemberDTO doUpdateMemberUserIptvIdAndBindIptvPlatformAndBindIptvTime(Member resource) { | 197 | public MemberDTO doUpdateMemberUserIptvIdAndBindIptvPlatformAndBindIptvTime(Member resource) { |
| 173 | log.info("修改会员绑定大屏信息 ==>> {}", resource); | 198 | log.info("修改会员绑定大屏信息 ==>> {}", resource); |
| 174 | try { | 199 | try { |
| 175 | this.redisUtils.doLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); | 200 | // this.redisUtils.doLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); |
| 176 | 201 | ||
| 177 | Integer count = this.memberRepository.updateMemberUserIptvIdAndBindIptvPlatformAndBindIptvTime(resource); | 202 | Integer count = this.memberRepository.updateMemberUserIptvIdAndBindIptvPlatformAndBindIptvTime(resource); |
| 178 | if (Objects.nonNull(count) && count > 0) { | 203 | if (Objects.nonNull(count) && count > 0) { |
| ... | @@ -183,7 +208,7 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -183,7 +208,7 @@ public class MemberServiceImpl implements MemberService { |
| 183 | } catch (Exception e) { | 208 | } catch (Exception e) { |
| 184 | log.info("修改会员绑定大屏信息,"+e.getMessage()); | 209 | log.info("修改会员绑定大屏信息,"+e.getMessage()); |
| 185 | } finally { | 210 | } finally { |
| 186 | this.redisUtils.doUnLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); | 211 | // this.redisUtils.doUnLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); |
| 187 | } | 212 | } |
| 188 | 213 | ||
| 189 | return this.memberMapper.toDto(resource); | 214 | return this.memberMapper.toDto(resource); |
| ... | @@ -191,11 +216,11 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -191,11 +216,11 @@ public class MemberServiceImpl implements MemberService { |
| 191 | 216 | ||
| 192 | @Override | 217 | @Override |
| 193 | @Transactional(rollbackFor = Exception.class) | 218 | @Transactional(rollbackFor = Exception.class) |
| 194 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#code") | 219 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#resource.code") |
| 195 | public MemberDTO doUpdateMemberAvatarUrlAndNicknameAndGender(Member resource) { | 220 | public MemberDTO doUpdateMemberAvatarUrlAndNicknameAndGender(Member resource) { |
| 196 | log.info("修改会员头像、昵称、性别 ==>> {}", resource); | 221 | log.info("修改会员头像、昵称、性别 ==>> {}", resource); |
| 197 | try { | 222 | try { |
| 198 | this.redisUtils.doLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); | 223 | // this.redisUtils.doLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); |
| 199 | 224 | ||
| 200 | Integer count = this.memberRepository.updateMemberAvatarUrlAndNicknameAndGender(resource); | 225 | Integer count = this.memberRepository.updateMemberAvatarUrlAndNicknameAndGender(resource); |
| 201 | if (Objects.nonNull(count) && count > 0) { | 226 | if (Objects.nonNull(count) && count > 0) { |
| ... | @@ -206,7 +231,7 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -206,7 +231,7 @@ public class MemberServiceImpl implements MemberService { |
| 206 | } catch (Exception e) { | 231 | } catch (Exception e) { |
| 207 | log.info("修改会员头像、昵称、性别异常,"+e.getMessage()); | 232 | log.info("修改会员头像、昵称、性别异常,"+e.getMessage()); |
| 208 | } finally { | 233 | } finally { |
| 209 | this.redisUtils.doUnLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); | 234 | // this.redisUtils.doUnLock(RedisKeyConstants.updateCacheMemberById + resource.getId()); |
| 210 | } | 235 | } |
| 211 | 236 | ||
| 212 | return this.memberMapper.toDto(resource); | 237 | return this.memberMapper.toDto(resource); |
| ... | @@ -232,11 +257,11 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -232,11 +257,11 @@ public class MemberServiceImpl implements MemberService { |
| 232 | 257 | ||
| 233 | @Override | 258 | @Override |
| 234 | @Transactional(rollbackFor = Exception.class) | 259 | @Transactional(rollbackFor = Exception.class) |
| 235 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#code") | 260 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#resources.code") |
| 236 | public MemberDTO update(Member resources) { | 261 | public MemberDTO update(Member resources) { |
| 237 | log.info("修改会员信息 ==>> {}", resources); | 262 | log.info("修改会员信息 ==>> {}", resources); |
| 238 | try { | 263 | try { |
| 239 | this.redisUtils.doLock(RedisKeyConstants.updateCacheMemberById + resources.getId()); | 264 | // this.redisUtils.doLock(RedisKeyConstants.updateCacheMemberById + resources.getId()); |
| 240 | 265 | ||
| 241 | MemberDTO memberDTO = this.checkMember(resources); | 266 | MemberDTO memberDTO = this.checkMember(resources); |
| 242 | Member member = new Member(); | 267 | Member member = new Member(); |
| ... | @@ -248,7 +273,7 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -248,7 +273,7 @@ public class MemberServiceImpl implements MemberService { |
| 248 | } catch (Exception e) { | 273 | } catch (Exception e) { |
| 249 | log.info(e.getMessage()); | 274 | log.info(e.getMessage()); |
| 250 | } finally { | 275 | } finally { |
| 251 | this.redisUtils.doUnLock(RedisKeyConstants.updateCacheMemberById + resources.getId()); | 276 | // this.redisUtils.doUnLock(RedisKeyConstants.updateCacheMemberById + resources.getId()); |
| 252 | } | 277 | } |
| 253 | 278 | ||
| 254 | return this.memberMapper.toDto(resources); | 279 | return this.memberMapper.toDto(resources); |
| ... | @@ -261,10 +286,10 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -261,10 +286,10 @@ public class MemberServiceImpl implements MemberService { |
| 261 | 286 | ||
| 262 | @Override | 287 | @Override |
| 263 | @Transactional(rollbackFor = Exception.class) | 288 | @Transactional(rollbackFor = Exception.class) |
| 264 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#code") | 289 | @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#resources.code") |
| 265 | public MemberDTO doUpdateMemberPoints(Member resources) { | 290 | public MemberDTO doUpdateMemberPoints(Member resources) { |
| 266 | try { | 291 | try { |
| 267 | this.redisUtils.doLock(RedisKeyConstants.updateCacheMemberById + resources.getId()); | 292 | // this.redisUtils.doLock(RedisKeyConstants.updateCacheMemberById + resources.getId()); |
| 268 | 293 | ||
| 269 | Integer count = this.memberRepository.updatePointAndDuePoint(resources); | 294 | Integer count = this.memberRepository.updatePointAndDuePoint(resources); |
| 270 | if (Objects.nonNull(count) && count > 0) { | 295 | if (Objects.nonNull(count) && count > 0) { |
| ... | @@ -275,7 +300,7 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -275,7 +300,7 @@ public class MemberServiceImpl implements MemberService { |
| 275 | } catch (Exception e) { | 300 | } catch (Exception e) { |
| 276 | log.info(e.getMessage()); | 301 | log.info(e.getMessage()); |
| 277 | } finally { | 302 | } finally { |
| 278 | this.redisUtils.doUnLock(RedisKeyConstants.updateCacheMemberById + resources.getId()); | 303 | // this.redisUtils.doUnLock(RedisKeyConstants.updateCacheMemberById + resources.getId()); |
| 279 | } | 304 | } |
| 280 | 305 | ||
| 281 | return this.memberMapper.toDto(resources); | 306 | return this.memberMapper.toDto(resources); | ... | ... |
| 1 | package com.topdraw.business.module.member.service.mapper; | ||
| 2 | |||
| 3 | import com.topdraw.base.BaseMapper; | ||
| 4 | import com.topdraw.business.module.member.domain.MemberSimple; | ||
| 5 | import com.topdraw.business.module.member.service.dto.MemberSimpleDTO; | ||
| 6 | import org.mapstruct.Mapper; | ||
| 7 | import org.mapstruct.ReportingPolicy; | ||
| 8 | |||
| 9 | /** | ||
| 10 | * @author XiangHan | ||
| 11 | * @date 2021-10-22 | ||
| 12 | */ | ||
| 13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
| 14 | public interface MemberSimpleMapper extends BaseMapper<MemberSimpleDTO, MemberSimple> { | ||
| 15 | |||
| 16 | } |
| ... | @@ -101,5 +101,5 @@ public interface PointsAvailableService { | ... | @@ -101,5 +101,5 @@ public interface PointsAvailableService { |
| 101 | * | 101 | * |
| 102 | * @param pointsAvailable | 102 | * @param pointsAvailable |
| 103 | */ | 103 | */ |
| 104 | PointsAvailableDTO create4Custom(PointsAvailable pointsAvailable); | 104 | void create4Custom(PointsAvailable pointsAvailable); |
| 105 | } | 105 | } | ... | ... |
| ... | @@ -160,17 +160,8 @@ public class PointsAvailableServiceImpl implements PointsAvailableService { | ... | @@ -160,17 +160,8 @@ public class PointsAvailableServiceImpl implements PointsAvailableService { |
| 160 | } | 160 | } |
| 161 | 161 | ||
| 162 | @Override | 162 | @Override |
| 163 | public PointsAvailableDTO create4Custom(PointsAvailable resources) { | 163 | public void create4Custom(PointsAvailable resources) { |
| 164 | this.redisUtils.doLock("PointsAvailable::create::id"+resources.getMemberId().toString()); | 164 | this.pointsAvailableRepository.save(resources); |
| 165 | try { | ||
| 166 | PointsAvailable pointsAvailable = this.pointsAvailableRepository.save(resources); | ||
| 167 | return this.pointsAvailableMapper.toDto(pointsAvailable); | ||
| 168 | } catch (Exception e) { | ||
| 169 | e.printStackTrace(); | ||
| 170 | throw e; | ||
| 171 | } finally { | ||
| 172 | this.redisUtils.doUnLock("PointsAvailable::create::id"+resources.getMemberId().toString()); | ||
| 173 | } | ||
| 174 | } | 165 | } |
| 175 | 166 | ||
| 176 | } | 167 | } | ... | ... |
| ... | @@ -27,6 +27,9 @@ import java.io.Serializable; | ... | @@ -27,6 +27,9 @@ import java.io.Serializable; |
| 27 | @NoArgsConstructor | 27 | @NoArgsConstructor |
| 28 | public class TrTaskProgress implements Serializable { | 28 | public class TrTaskProgress implements Serializable { |
| 29 | 29 | ||
| 30 | @Transient | ||
| 31 | private String memberCode; | ||
| 32 | |||
| 30 | @Id | 33 | @Id |
| 31 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 34 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| 32 | @Column(name = "id") | 35 | @Column(name = "id") | ... | ... |
| ... | @@ -5,7 +5,10 @@ import org.springframework.data.jpa.repository.JpaRepository; | ... | @@ -5,7 +5,10 @@ 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.Query; | 6 | import org.springframework.data.jpa.repository.Query; |
| 7 | 7 | ||
| 8 | import java.util.HashMap; | ||
| 8 | import java.util.List; | 9 | import java.util.List; |
| 10 | import java.util.Map; | ||
| 11 | import java.util.Optional; | ||
| 9 | 12 | ||
| 10 | /** | 13 | /** |
| 11 | * @author XiangHan | 14 | * @author XiangHan |
| ... | @@ -13,8 +16,17 @@ import java.util.List; | ... | @@ -13,8 +16,17 @@ import java.util.List; |
| 13 | */ | 16 | */ |
| 14 | public interface TrTaskProgressRepository extends JpaRepository<TrTaskProgress, Long>, JpaSpecificationExecutor<TrTaskProgress> { | 17 | public interface TrTaskProgressRepository extends JpaRepository<TrTaskProgress, Long>, JpaSpecificationExecutor<TrTaskProgress> { |
| 15 | 18 | ||
| 16 | @Query(value = "select id, member_id, task_id , current_action_amount , \n" + | 19 | @Query(value = "select id, member_id, task_id, current_action_amount," + |
| 17 | " target_action_amount , `status` , completion_time,create_time,update_time from uc_tr_task_progress where member_id = ?1 \n" + | 20 | " target_action_amount, `status`, completion_time, create_time, update_time from uc_tr_task_progress where member_id = ?1 " + |
| 18 | " and task_id = ?2 and Date(completion_time) = ?3 ",nativeQuery = true) | 21 | " and task_id = ?2 and Date(completion_time) = ?3 ",nativeQuery = true) |
| 19 | TrTaskProgress findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1); | 22 | Optional<TrTaskProgress> findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1); |
| 23 | |||
| 24 | |||
| 25 | Integer countByMemberIdAndTaskId(Long memberId, Long taskId); | ||
| 26 | |||
| 27 | @Query(value = "select `task_id` AS taskId, count(*) AS finishCount from uc_tr_task_progress where member_id = ?1 and `status` = 1 GROUP BY `task_id` ", nativeQuery = true) | ||
| 28 | List<Map<String, Object>> countFinishTaskGroupByMemberId(Long memberId); | ||
| 29 | |||
| 30 | @Query(value = "select `task_id` AS taskId, count(*) AS finishCount from uc_tr_task_progress where member_id = ?1 and Date(completion_time) = ?2 and `status` = 1 GROUP BY `task_id`", nativeQuery = true) | ||
| 31 | List<Map<String, Object>> countFinishTaskGroupByMemberIdAndToday(Long memberId, String todayStart); | ||
| 20 | } | 32 | } | ... | ... |
| ... | @@ -4,7 +4,9 @@ import com.topdraw.business.module.task.progress.domain.TrTaskProgress; | ... | @@ -4,7 +4,9 @@ import com.topdraw.business.module.task.progress.domain.TrTaskProgress; |
| 4 | import com.topdraw.business.module.task.progress.service.dto.TrTaskProgressDTO; | 4 | import com.topdraw.business.module.task.progress.service.dto.TrTaskProgressDTO; |
| 5 | 5 | ||
| 6 | import java.time.LocalDateTime; | 6 | import java.time.LocalDateTime; |
| 7 | import java.util.HashMap; | ||
| 7 | import java.util.List; | 8 | import java.util.List; |
| 9 | import java.util.Map; | ||
| 8 | 10 | ||
| 9 | /** | 11 | /** |
| 10 | * @author XiangHan | 12 | * @author XiangHan |
| ... | @@ -44,6 +46,28 @@ public interface TrTaskProgressService { | ... | @@ -44,6 +46,28 @@ public interface TrTaskProgressService { |
| 44 | * @param time1 | 46 | * @param time1 |
| 45 | * @return | 47 | * @return |
| 46 | */ | 48 | */ |
| 47 | TrTaskProgressDTO findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1); | 49 | TrTaskProgress findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1); |
| 48 | 50 | ||
| 51 | /** | ||
| 52 | * | ||
| 53 | * @param memberId | ||
| 54 | * @param taskId | ||
| 55 | * @return | ||
| 56 | */ | ||
| 57 | Integer countByMemberIdAndTaskId(Long memberId, Long taskId); | ||
| 58 | |||
| 59 | /** | ||
| 60 | * | ||
| 61 | * @param id | ||
| 62 | * @return | ||
| 63 | */ | ||
| 64 | Map<Object, Object> countTotalFinishTaskByMemberId(Long id); | ||
| 65 | |||
| 66 | /** | ||
| 67 | * | ||
| 68 | * @param id | ||
| 69 | * @param todayStart | ||
| 70 | * @return | ||
| 71 | */ | ||
| 72 | Map<Object, Object> countTodayFinishTaskByMemberId(Long id, String todayStart); | ||
| 49 | } | 73 | } | ... | ... |
| 1 | package com.topdraw.business.module.task.progress.service.impl; | 1 | package com.topdraw.business.module.task.progress.service.impl; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.map.MapUtil; | ||
| 3 | import com.topdraw.business.module.task.progress.domain.TrTaskProgress; | 4 | import com.topdraw.business.module.task.progress.domain.TrTaskProgress; |
| 4 | import com.topdraw.config.RedisKeyConstants; | 5 | import com.topdraw.config.RedisKeyConstants; |
| 6 | import com.topdraw.utils.RedisUtils; | ||
| 5 | import com.topdraw.utils.ValidationUtil; | 7 | import com.topdraw.utils.ValidationUtil; |
| 6 | import com.topdraw.business.module.task.progress.repository.TrTaskProgressRepository; | 8 | import com.topdraw.business.module.task.progress.repository.TrTaskProgressRepository; |
| 7 | import com.topdraw.business.module.task.progress.service.TrTaskProgressService; | 9 | import com.topdraw.business.module.task.progress.service.TrTaskProgressService; |
| ... | @@ -16,9 +18,13 @@ import org.springframework.transaction.annotation.Propagation; | ... | @@ -16,9 +18,13 @@ import org.springframework.transaction.annotation.Propagation; |
| 16 | import org.springframework.transaction.annotation.Transactional; | 18 | import org.springframework.transaction.annotation.Transactional; |
| 17 | import org.springframework.dao.EmptyResultDataAccessException; | 19 | import org.springframework.dao.EmptyResultDataAccessException; |
| 18 | import org.springframework.util.Assert; | 20 | import org.springframework.util.Assert; |
| 21 | import org.springframework.util.CollectionUtils; | ||
| 19 | 22 | ||
| 23 | import java.time.LocalDate; | ||
| 20 | import java.time.LocalDateTime; | 24 | import java.time.LocalDateTime; |
| 21 | import java.util.List; | 25 | import java.util.*; |
| 26 | import java.util.stream.Collectors; | ||
| 27 | import java.util.stream.Stream; | ||
| 22 | 28 | ||
| 23 | /** | 29 | /** |
| 24 | * @author XiangHan | 30 | * @author XiangHan |
| ... | @@ -31,34 +37,30 @@ public class TrTaskProgressServiceImpl implements TrTaskProgressService { | ... | @@ -31,34 +37,30 @@ public class TrTaskProgressServiceImpl implements TrTaskProgressService { |
| 31 | 37 | ||
| 32 | @Autowired | 38 | @Autowired |
| 33 | private TrTaskProgressRepository trTaskProgressRepository; | 39 | private TrTaskProgressRepository trTaskProgressRepository; |
| 34 | |||
| 35 | @Autowired | 40 | @Autowired |
| 36 | private TrTaskProgressMapper trTaskProgressMapper; | 41 | private TrTaskProgressMapper trTaskProgressMapper; |
| 37 | 42 | ||
| 43 | @Autowired | ||
| 44 | private RedisUtils redisUtils; | ||
| 45 | |||
| 38 | @Override | 46 | @Override |
| 39 | public TrTaskProgressDTO findById(Long id) { | 47 | public TrTaskProgressDTO findById(Long id) { |
| 40 | TrTaskProgress TrTaskProgress = this.trTaskProgressRepository.findById(id).orElseGet(TrTaskProgress::new); | 48 | TrTaskProgress TrTaskProgress = this.trTaskProgressRepository.findById(id).orElseGet(TrTaskProgress::new); |
| 41 | ValidationUtil.isNull(TrTaskProgress.getId(),"TrTaskProgress","id",id); | ||
| 42 | return this.trTaskProgressMapper.toDto(TrTaskProgress); | 49 | return this.trTaskProgressMapper.toDto(TrTaskProgress); |
| 43 | } | 50 | } |
| 44 | 51 | ||
| 45 | @Override | 52 | @Override |
| 46 | @Transactional(rollbackFor = Exception.class) | 53 | @Transactional(rollbackFor = Exception.class) |
| 47 | @Cacheable(cacheNames = RedisKeyConstants.cacheTaskProcessByMemberId, key = "#resources.memberId+':'+#resources.taskId+':'+#date", unless = "#result == null ") | 54 | // @CachePut(cacheNames = RedisKeyConstants.cacheTaskProcessByMemberId, key = "#resources.memberId+':'+#resources.taskId+':'+#date", unless = "#result == null ") |
| 48 | public TrTaskProgress create(TrTaskProgress resources, String date) { | 55 | public TrTaskProgress create(TrTaskProgress resources, String date) { |
| 49 | TrTaskProgress trTaskProgress = this.trTaskProgressRepository.save(resources); | 56 | return this.trTaskProgressRepository.save(resources); |
| 50 | return trTaskProgress; | ||
| 51 | } | 57 | } |
| 52 | 58 | ||
| 53 | @Override | 59 | @Override |
| 54 | @Transactional(rollbackFor = Exception.class) | 60 | @Transactional(rollbackFor = Exception.class) |
| 55 | @Cacheable(cacheNames = RedisKeyConstants.cacheTaskProcessByMemberId, key = "#resources.memberId+':'+#resources.taskId+':'+#date", unless = "#result == null ") | 61 | // @CachePut(cacheNames = RedisKeyConstants.cacheTaskProcessByMemberId, key = "#resources.memberId+':'+#resources.taskId+':'+#date", unless = "#result == null ") |
| 56 | public TrTaskProgress update(TrTaskProgress resources, String date) { | 62 | public TrTaskProgress update(TrTaskProgress resources, String date) { |
| 57 | TrTaskProgress trTaskProgress = this.trTaskProgressRepository.findById(resources.getId()).orElseGet(TrTaskProgress::new); | 63 | return this.trTaskProgressRepository.save(resources); |
| 58 | ValidationUtil.isNull( trTaskProgress.getId(),"TrTaskProgress","id",resources.getId()); | ||
| 59 | trTaskProgress.copy(resources); | ||
| 60 | TrTaskProgress save = this.trTaskProgressRepository.save(trTaskProgress); | ||
| 61 | return save; | ||
| 62 | } | 64 | } |
| 63 | 65 | ||
| 64 | @Override | 66 | @Override |
| ... | @@ -71,12 +73,68 @@ public class TrTaskProgressServiceImpl implements TrTaskProgressService { | ... | @@ -71,12 +73,68 @@ public class TrTaskProgressServiceImpl implements TrTaskProgressService { |
| 71 | } | 73 | } |
| 72 | 74 | ||
| 73 | @Override | 75 | @Override |
| 74 | @Cacheable(cacheNames = RedisKeyConstants.cacheTaskProcessByMemberId, key = "#memberId+':'+#taskId+':'+#time1", unless = "#result == null") | 76 | // @Cacheable(cacheNames = RedisKeyConstants.cacheTaskProcessByMemberId, key = "#memberId+':'+#taskId+':'+#time1", unless = "#result.id == null") |
| 75 | public TrTaskProgressDTO findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1) { | 77 | public TrTaskProgress findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1) { |
| 76 | log.info("从数据库查询当前会员今天是否完成了此任务, memberId ==>> {} || taskId ==>> {}", memberId, taskId); | 78 | log.info("从数据库查询当前会员今天是否完成了此任务, memberId ==>> {} || taskId ==>> {}", memberId, taskId); |
| 77 | return this.trTaskProgressMapper.toDto(this.trTaskProgressRepository.findByMemberIdAndTaskIdAndCompletionTime(memberId,taskId,time1)); | 79 | return this.trTaskProgressRepository.findByMemberIdAndTaskIdAndCompletionTime(memberId, taskId, time1).orElseGet(TrTaskProgress::new); |
| 80 | } | ||
| 81 | |||
| 82 | @Override | ||
| 83 | public Integer countByMemberIdAndTaskId(Long memberId, Long taskId) { | ||
| 84 | return this.trTaskProgressRepository.countByMemberIdAndTaskId(memberId, taskId); | ||
| 78 | } | 85 | } |
| 79 | 86 | ||
| 87 | @Override | ||
| 88 | public Map<Object, Object> countTotalFinishTaskByMemberId(Long memberId) { | ||
| 89 | Map<Object, Object> hmget = this.redisUtils.hmget(RedisKeyConstants.cacheTotalFinishTaskCount + "::" + memberId); | ||
| 90 | if (Objects.isNull(hmget)) { | ||
| 91 | List<Map<String, Object>> maps = this.trTaskProgressRepository.countFinishTaskGroupByMemberId(memberId); | ||
| 92 | if (!CollectionUtils.isEmpty(maps)) { | ||
| 93 | Map<Object, Object> finishTasks = new HashMap<>(); | ||
| 94 | for (Map<String, Object> map : maps) { | ||
| 95 | Object taskId = map.get("taskId"); | ||
| 96 | if (Objects.isNull(taskId)) { | ||
| 97 | continue; | ||
| 98 | } | ||
| 99 | finishTasks.put(Long.valueOf(taskId.toString()), Integer.valueOf(map.get("finishCount").toString())); | ||
| 100 | |||
| 101 | // 总记录一直存储 | ||
| 102 | this.redisUtils.hmset(RedisKeyConstants.cacheTotalFinishTaskCount + "::" + memberId, finishTasks); | ||
| 103 | } | ||
| 104 | return finishTasks; | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | return hmget; | ||
| 109 | } | ||
| 110 | |||
| 111 | @Override | ||
| 112 | public Map<Object, Object> countTodayFinishTaskByMemberId(Long memberId, String todayStart) { | ||
| 113 | |||
| 114 | Map<Object, Object> hmget = this.redisUtils.hmget(RedisKeyConstants.cacheTodayFinishTaskCount + "::" + memberId + ":" + todayStart); | ||
| 115 | if (Objects.isNull(hmget)) { | ||
| 116 | |||
| 117 | List<Map<String, Object>> maps = this.trTaskProgressRepository.countFinishTaskGroupByMemberIdAndToday(memberId, todayStart); | ||
| 118 | if (!CollectionUtils.isEmpty(maps)){ | ||
| 119 | Map<Object, Object> finishTasks = new HashMap<>(); | ||
| 120 | for (Map<String, Object> map : maps) { | ||
| 121 | Object taskId = map.get("taskId"); | ||
| 122 | if (Objects.isNull(taskId)) { | ||
| 123 | continue; | ||
| 124 | } | ||
| 125 | |||
| 126 | finishTasks.put(Long.valueOf(taskId.toString()), Integer.valueOf(map.get("finishCount").toString())); | ||
| 127 | |||
| 128 | // 单天的记录只存储一天 | ||
| 129 | this.redisUtils.hmset(RedisKeyConstants.cacheTodayFinishTaskCount + "::" + memberId + ":" + LocalDate.now(), finishTasks, 24*60*60); | ||
| 130 | } | ||
| 131 | return finishTasks; | ||
| 132 | |||
| 133 | } | ||
| 134 | |||
| 135 | } | ||
| 136 | return hmget; | ||
| 137 | } | ||
| 80 | 138 | ||
| 81 | 139 | ||
| 82 | } | 140 | } | ... | ... |
| ... | @@ -28,6 +28,6 @@ public interface TaskRepository extends JpaRepository<Task, Long>, JpaSpecificat | ... | @@ -28,6 +28,6 @@ public interface TaskRepository extends JpaRepository<Task, Long>, JpaSpecificat |
| 28 | @Query(value = "SELECT ta.*, attr.attr_str AS attr FROM tr_task ta LEFT JOIN tr_task_template tm ON ta.task_template_id = tm.id " + | 28 | @Query(value = "SELECT ta.*, attr.attr_str AS attr FROM tr_task ta LEFT JOIN tr_task_template tm ON ta.task_template_id = tm.id " + |
| 29 | " LEFT JOIN tr_task_attr attr ON attr.task_id = ta.id " + | 29 | " LEFT JOIN tr_task_attr attr ON attr.task_id = ta.id " + |
| 30 | " WHERE ta.`status` = 1 AND ta.valid_time <= now() and ta.expire_time >= now() AND ta.delete_mark = 0 AND " + | 30 | " WHERE ta.`status` = 1 AND ta.valid_time <= now() and ta.expire_time >= now() AND ta.delete_mark = 0 AND " + |
| 31 | " tm.type = ?1 ", nativeQuery = true) | 31 | " tm.type = ?1 AND ta.`member_level` <= ?2 and ta.`member_vip` <= ?3", nativeQuery = true) |
| 32 | List<Task> findByEvent(Integer event); | 32 | List<Task> findByEvent(Integer event, Integer level, Integer vip); |
| 33 | } | 33 | } | ... | ... |
| 1 | package com.topdraw.business.module.task.service; | 1 | package com.topdraw.business.module.task.service; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.member.service.dto.MemberSimpleDTO; | ||
| 3 | import com.topdraw.business.module.task.domain.Task; | 4 | import com.topdraw.business.module.task.domain.Task; |
| 4 | import com.topdraw.business.module.task.progress.service.dto.TrTaskProgressDTO; | 5 | import com.topdraw.business.module.task.progress.service.dto.TrTaskProgressDTO; |
| 5 | import com.topdraw.business.module.task.service.dto.TaskDTO; | 6 | import com.topdraw.business.module.task.service.dto.TaskDTO; |
| ... | @@ -63,6 +64,6 @@ public interface TaskService { | ... | @@ -63,6 +64,6 @@ public interface TaskService { |
| 63 | * @param event | 64 | * @param event |
| 64 | * @return | 65 | * @return |
| 65 | */ | 66 | */ |
| 66 | List<Task> findByEvent(Integer event); | 67 | List<Task> findByEventAndMemberLevelAndVip(Integer event, Integer level, Integer vip); |
| 67 | 68 | ||
| 68 | } | 69 | } | ... | ... |
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.topdraw.business.module.task.domain.Task; | 4 | import com.topdraw.business.module.task.domain.Task; |
| 4 | import com.topdraw.business.module.task.repository.TaskRepository; | 5 | import com.topdraw.business.module.task.repository.TaskRepository; |
| 5 | import com.topdraw.business.module.task.service.TaskService; | 6 | import com.topdraw.business.module.task.service.TaskService; |
| 6 | import com.topdraw.business.module.task.service.dto.TaskDTO; | 7 | import com.topdraw.business.module.task.service.dto.TaskDTO; |
| 7 | import com.topdraw.business.module.task.service.mapper.TaskMapper; | 8 | import com.topdraw.business.module.task.service.mapper.TaskMapper; |
| 8 | import com.topdraw.config.RedisKeyConstants; | 9 | import com.topdraw.config.RedisKeyConstants; |
| 10 | import com.topdraw.utils.RedisUtils; | ||
| 9 | import lombok.extern.slf4j.Slf4j; | 11 | import lombok.extern.slf4j.Slf4j; |
| 10 | import org.springframework.beans.factory.annotation.Autowired; | 12 | import org.springframework.beans.factory.annotation.Autowired; |
| 11 | import org.springframework.cache.annotation.Cacheable; | 13 | import org.springframework.cache.annotation.Cacheable; |
| 12 | import org.springframework.stereotype.Service; | 14 | import org.springframework.stereotype.Service; |
| 13 | import org.springframework.transaction.annotation.Propagation; | 15 | import org.springframework.transaction.annotation.Propagation; |
| 14 | import org.springframework.transaction.annotation.Transactional; | 16 | import org.springframework.transaction.annotation.Transactional; |
| 17 | import org.springframework.util.CollectionUtils; | ||
| 15 | 18 | ||
| 16 | import java.util.ArrayList; | 19 | import java.util.ArrayList; |
| 17 | import java.util.List; | 20 | import java.util.List; |
| ... | @@ -30,6 +33,8 @@ public class TaskServiceImpl implements TaskService { | ... | @@ -30,6 +33,8 @@ public class TaskServiceImpl implements TaskService { |
| 30 | private TaskMapper taskMapper; | 33 | private TaskMapper taskMapper; |
| 31 | @Autowired | 34 | @Autowired |
| 32 | private TaskRepository taskRepository; | 35 | private TaskRepository taskRepository; |
| 36 | @Autowired | ||
| 37 | private RedisUtils redisUtils; | ||
| 33 | 38 | ||
| 34 | @Override | 39 | @Override |
| 35 | public TaskDTO findById(Long id) { | 40 | public TaskDTO findById(Long id) { |
| ... | @@ -72,9 +77,10 @@ public class TaskServiceImpl implements TaskService { | ... | @@ -72,9 +77,10 @@ public class TaskServiceImpl implements TaskService { |
| 72 | } | 77 | } |
| 73 | 78 | ||
| 74 | @Override | 79 | @Override |
| 75 | @Cacheable(value = RedisKeyConstants.cacheTaskByEvent, key = "#event" , unless = "#result.size() == 0") | 80 | @Cacheable(cacheNames = RedisKeyConstants.cacheTaskByEventAndMemberLevelAndVip, key = "#event+':'+#level+':'+#vip", |
| 76 | public List<Task> findByEvent(Integer event) { | 81 | unless = "#result.size() == 0") |
| 77 | log.info("从数据库查询事件列表 ==>> {}", event); | 82 | public List<Task> findByEventAndMemberLevelAndVip(Integer event, Integer level, Integer vip) { |
| 78 | return Objects.nonNull(event) ? this.taskRepository.findByEvent(event) : new ArrayList<>(); | 83 | List<Task> tasks = this.taskRepository.findByEvent(event, level, vip); |
| 84 | return Objects.nonNull(event) ? tasks : new ArrayList<>(); | ||
| 79 | } | 85 | } |
| 80 | } | 86 | } | ... | ... |
member-service-impl/src/main/java/com/topdraw/business/module/user/iptv/domain/UserTvSimple.java
0 → 100644
| 1 | package com.topdraw.business.module.user.iptv.domain; | ||
| 2 | |||
| 3 | import cn.hutool.core.bean.BeanUtil; | ||
| 4 | import cn.hutool.core.bean.copier.CopyOptions; | ||
| 5 | import com.topdraw.business.module.common.domain.AsyncMqModule; | ||
| 6 | import com.topdraw.business.module.common.validated.CreateGroup; | ||
| 7 | import com.topdraw.business.module.common.validated.UpdateGroup; | ||
| 8 | import lombok.Data; | ||
| 9 | import lombok.experimental.Accessors; | ||
| 10 | import org.springframework.data.annotation.CreatedDate; | ||
| 11 | import org.springframework.data.annotation.LastModifiedDate; | ||
| 12 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
| 13 | |||
| 14 | import javax.persistence.*; | ||
| 15 | import javax.validation.constraints.NotNull; | ||
| 16 | import java.io.Serializable; | ||
| 17 | import java.sql.Timestamp; | ||
| 18 | |||
| 19 | /** | ||
| 20 | * @author XiangHan | ||
| 21 | * @date 2021-12-16 | ||
| 22 | */ | ||
| 23 | @Entity | ||
| 24 | @Data | ||
| 25 | @EntityListeners(AuditingEntityListener.class) | ||
| 26 | @Accessors(chain = true) | ||
| 27 | @Table(name="uc_user_tv") | ||
| 28 | public class UserTvSimple extends AsyncMqModule implements Serializable { | ||
| 29 | |||
| 30 | /** ID */ | ||
| 31 | @Id | ||
| 32 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| 33 | @Column(name = "id") | ||
| 34 | private Long id; | ||
| 35 | |||
| 36 | /** 会员id */ | ||
| 37 | @Column(name = "member_id") | ||
| 38 | private Long memberId; | ||
| 39 | |||
| 40 | /** 原vis_user_id */ | ||
| 41 | @Column(name = "vis_user_id") | ||
| 42 | private Long visUserId; | ||
| 43 | |||
| 44 | /** 绑定的小屏账户会员编码 */ | ||
| 45 | @Column(name = "priority_member_code") | ||
| 46 | private String priorityMemberCode; | ||
| 47 | |||
| 48 | public void copy(UserTvSimple source){ | ||
| 49 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(false)); | ||
| 50 | } | ||
| 51 | } |
| 1 | package com.topdraw.business.module.user.iptv.repository; | 1 | package com.topdraw.business.module.user.iptv.repository; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.user.iptv.domain.UserTv; | 3 | import com.topdraw.business.module.user.iptv.domain.UserTv; |
| 4 | import com.topdraw.business.module.user.iptv.service.dto.UserTvSimpleDTO; | ||
| 4 | import org.springframework.data.jpa.repository.JpaRepository; | 5 | import org.springframework.data.jpa.repository.JpaRepository; |
| 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | 6 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
| 6 | import org.springframework.data.jpa.repository.Modifying; | 7 | import org.springframework.data.jpa.repository.Modifying; | ... | ... |
| 1 | package com.topdraw.business.module.user.iptv.repository; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.user.iptv.domain.UserTvSimple; | ||
| 4 | import com.topdraw.business.module.user.iptv.service.dto.UserTvSimpleDTO; | ||
| 5 | import org.springframework.data.jpa.repository.JpaRepository; | ||
| 6 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
| 7 | import org.springframework.data.jpa.repository.Query; | ||
| 8 | |||
| 9 | /** | ||
| 10 | * @author XiangHan | ||
| 11 | * @date 2021-12-16 | ||
| 12 | */ | ||
| 13 | public interface UserTvSimpleRepository extends JpaRepository<UserTvSimple, Long>, JpaSpecificationExecutor<UserTvSimple> { | ||
| 14 | |||
| 15 | @Query(value = "SELECT `id`, `vis_user_id` , `member_id` , " + | ||
| 16 | " `priority_member_code` FROM `uc_user_tv` WHERE `platform_account` = ?1", nativeQuery = true) | ||
| 17 | UserTvSimple findSimpleByPlatformAccount(String platformAccount); | ||
| 18 | } |
| ... | @@ -3,6 +3,7 @@ package com.topdraw.business.module.user.iptv.service; | ... | @@ -3,6 +3,7 @@ package com.topdraw.business.module.user.iptv.service; |
| 3 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 3 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
| 4 | import com.topdraw.business.module.user.iptv.domain.UserTv; | 4 | import com.topdraw.business.module.user.iptv.domain.UserTv; |
| 5 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; | 5 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; |
| 6 | import com.topdraw.business.module.user.iptv.service.dto.UserTvSimpleDTO; | ||
| 6 | 7 | ||
| 7 | /** | 8 | /** |
| 8 | * @author XiangHan | 9 | * @author XiangHan |
| ... | @@ -51,6 +52,13 @@ public interface UserTvService { | ... | @@ -51,6 +52,13 @@ public interface UserTvService { |
| 51 | 52 | ||
| 52 | /** | 53 | /** |
| 53 | * | 54 | * |
| 55 | * @param platformAccount | ||
| 56 | * @return | ||
| 57 | */ | ||
| 58 | UserTvSimpleDTO findSimpleByPlatformAccount(String platformAccount); | ||
| 59 | |||
| 60 | /** | ||
| 61 | * | ||
| 54 | * @param memberCode | 62 | * @param memberCode |
| 55 | * @return | 63 | * @return |
| 56 | */ | 64 | */ | ... | ... |
| 1 | package com.topdraw.business.module.user.iptv.service.dto; | ||
| 2 | |||
| 3 | import lombok.Data; | ||
| 4 | |||
| 5 | import java.io.Serializable; | ||
| 6 | |||
| 7 | |||
| 8 | /** | ||
| 9 | * @author XiangHan | ||
| 10 | * @date 2021-12-16 | ||
| 11 | */ | ||
| 12 | @Data | ||
| 13 | public class UserTvSimpleDTO implements Serializable { | ||
| 14 | |||
| 15 | private Long visUserId; | ||
| 16 | /** 绑定的小屏账户会员编码 */ | ||
| 17 | private String priorityMemberCode; | ||
| 18 | /** 会员id */ | ||
| 19 | private Long memberId; | ||
| 20 | |||
| 21 | private String platformAccount; | ||
| 22 | } | ||
| 23 | |||
| 24 |
| 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.JSONObject; | ||
| 3 | import com.topdraw.aspect.AsyncMqSend; | 4 | import com.topdraw.aspect.AsyncMqSend; |
| 4 | import com.topdraw.business.module.member.service.MemberService; | 5 | import com.topdraw.business.module.member.service.MemberService; |
| 5 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 6 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
| 6 | import com.topdraw.business.module.user.iptv.domain.UserTv; | 7 | import com.topdraw.business.module.user.iptv.domain.UserTv; |
| 7 | import com.topdraw.business.process.service.impl.UserOperationServiceImpl; | 8 | import com.topdraw.business.module.user.iptv.domain.UserTvSimple; |
| 9 | import com.topdraw.business.module.user.iptv.repository.UserTvSimpleRepository; | ||
| 10 | import com.topdraw.business.module.user.iptv.service.dto.UserTvSimpleDTO; | ||
| 11 | import com.topdraw.business.module.user.iptv.service.mapper.UserTvSimpleMapper; | ||
| 8 | import com.topdraw.config.RedisKeyConstants; | 12 | import com.topdraw.config.RedisKeyConstants; |
| 9 | import com.topdraw.exception.EntityNotFoundException; | 13 | import com.topdraw.exception.EntityNotFoundException; |
| 10 | import com.topdraw.exception.GlobeExceptionMsg; | 14 | import com.topdraw.exception.GlobeExceptionMsg; |
| 15 | import com.topdraw.utils.RedisUtils; | ||
| 11 | import com.topdraw.utils.ValidationUtil; | 16 | import com.topdraw.utils.ValidationUtil; |
| 12 | import com.topdraw.business.module.user.iptv.repository.UserTvRepository; | 17 | import com.topdraw.business.module.user.iptv.repository.UserTvRepository; |
| 13 | import com.topdraw.business.module.user.iptv.service.UserTvService; | 18 | import com.topdraw.business.module.user.iptv.service.UserTvService; |
| ... | @@ -16,6 +21,7 @@ import com.topdraw.business.module.user.iptv.service.mapper.UserTvMapper; | ... | @@ -16,6 +21,7 @@ import com.topdraw.business.module.user.iptv.service.mapper.UserTvMapper; |
| 16 | import lombok.extern.slf4j.Slf4j; | 21 | import lombok.extern.slf4j.Slf4j; |
| 17 | import org.apache.commons.lang3.StringUtils; | 22 | import org.apache.commons.lang3.StringUtils; |
| 18 | import org.springframework.aop.framework.AopContext; | 23 | import org.springframework.aop.framework.AopContext; |
| 24 | import org.springframework.beans.BeanUtils; | ||
| 19 | import org.springframework.beans.factory.annotation.Autowired; | 25 | import org.springframework.beans.factory.annotation.Autowired; |
| 20 | import org.springframework.cache.annotation.Cacheable; | 26 | import org.springframework.cache.annotation.Cacheable; |
| 21 | import org.springframework.stereotype.Service; | 27 | import org.springframework.stereotype.Service; |
| ... | @@ -25,6 +31,8 @@ import org.springframework.dao.EmptyResultDataAccessException; | ... | @@ -25,6 +31,8 @@ import org.springframework.dao.EmptyResultDataAccessException; |
| 25 | import org.springframework.util.Assert; | 31 | import org.springframework.util.Assert; |
| 26 | 32 | ||
| 27 | import java.time.LocalDateTime; | 33 | import java.time.LocalDateTime; |
| 34 | import java.util.HashMap; | ||
| 35 | import java.util.Map; | ||
| 28 | import java.util.Objects; | 36 | import java.util.Objects; |
| 29 | import java.util.Optional; | 37 | import java.util.Optional; |
| 30 | 38 | ||
| ... | @@ -41,9 +49,16 @@ public class UserTvServiceImpl implements UserTvService { | ... | @@ -41,9 +49,16 @@ public class UserTvServiceImpl implements UserTvService { |
| 41 | @Autowired | 49 | @Autowired |
| 42 | private UserTvMapper userTvMapper; | 50 | private UserTvMapper userTvMapper; |
| 43 | @Autowired | 51 | @Autowired |
| 52 | private UserTvSimpleMapper userTvSimpleMapper; | ||
| 53 | @Autowired | ||
| 44 | private MemberService memberService; | 54 | private MemberService memberService; |
| 45 | @Autowired | 55 | @Autowired |
| 46 | private UserTvRepository userTvRepository; | 56 | private UserTvRepository userTvRepository; |
| 57 | @Autowired | ||
| 58 | private UserTvSimpleRepository userTvSimpleRepository; | ||
| 59 | |||
| 60 | @Autowired | ||
| 61 | private RedisUtils redisUtils; | ||
| 47 | 62 | ||
| 48 | @AsyncMqSend | 63 | @AsyncMqSend |
| 49 | public void asyncUpdateUserTvVisUserId(UserTvDTO userTvDTO) {} | 64 | public void asyncUpdateUserTvVisUserId(UserTvDTO userTvDTO) {} |
| ... | @@ -57,6 +72,7 @@ public class UserTvServiceImpl implements UserTvService { | ... | @@ -57,6 +72,7 @@ public class UserTvServiceImpl implements UserTvService { |
| 57 | * @return | 72 | * @return |
| 58 | */ | 73 | */ |
| 59 | @Override | 74 | @Override |
| 75 | @Transactional(readOnly = true) | ||
| 60 | public MemberDTO findMemberByPlatformAccount(String platformAccount){ | 76 | public MemberDTO findMemberByPlatformAccount(String platformAccount){ |
| 61 | // 大屏账户 | 77 | // 大屏账户 |
| 62 | UserTvDTO userTvDTO = this.findByPlatformAccount(platformAccount); | 78 | UserTvDTO userTvDTO = this.findByPlatformAccount(platformAccount); |
| ... | @@ -119,6 +135,7 @@ public class UserTvServiceImpl implements UserTvService { | ... | @@ -119,6 +135,7 @@ public class UserTvServiceImpl implements UserTvService { |
| 119 | } | 135 | } |
| 120 | 136 | ||
| 121 | @Override | 137 | @Override |
| 138 | @Transactional(readOnly = true) | ||
| 122 | public UserTvDTO findById(Long id) { | 139 | public UserTvDTO findById(Long id) { |
| 123 | UserTv UserTv = this.userTvRepository.findById(id).orElseGet(UserTv::new); | 140 | UserTv UserTv = this.userTvRepository.findById(id).orElseGet(UserTv::new); |
| 124 | ValidationUtil.isNull(UserTv.getId(),"UserTv","id",id); | 141 | ValidationUtil.isNull(UserTv.getId(),"UserTv","id",id); |
| ... | @@ -169,18 +186,39 @@ public class UserTvServiceImpl implements UserTvService { | ... | @@ -169,18 +186,39 @@ public class UserTvServiceImpl implements UserTvService { |
| 169 | } | 186 | } |
| 170 | 187 | ||
| 171 | @Override | 188 | @Override |
| 172 | @Cacheable(cacheNames = RedisKeyConstants.cacheUserTvByPlatformAccount, key = "#platformAccount") | 189 | @Cacheable(cacheNames = RedisKeyConstants.cacheUserTvByPlatformAccount, key = "#platformAccount", unless = "#result.id == null") |
| 190 | @Transactional(readOnly = true) | ||
| 173 | public UserTvDTO findByPlatformAccount(String platformAccount) { | 191 | public UserTvDTO findByPlatformAccount(String platformAccount) { |
| 174 | log.info("从数据库通过大屏账号检索大屏账号信息"); | 192 | UserTv userTv = this.userTvRepository.findByPlatformAccount(platformAccount).orElseGet(UserTv::new); |
| 175 | Optional<UserTv> userTv = this.userTvRepository.findByPlatformAccount(platformAccount); | 193 | return this.userTvMapper.toDto(userTv); |
| 176 | if (userTv.isPresent()) { | 194 | } |
| 177 | ValidationUtil.isNull( userTv.get().getId(),"UserTv","id",userTv.get().getId()); | 195 | |
| 178 | return this.userTvMapper.toDto(userTv.get()); | 196 | @Override |
| 197 | // @Cacheable(cacheNames = RedisKeyConstants.cacheUserTvByPlatformAccount, key = "#platformAccount") | ||
| 198 | public UserTvSimpleDTO findSimpleByPlatformAccount(String platformAccount) { | ||
| 199 | |||
| 200 | Object userTvSimpleObj = this.redisUtils.get(RedisKeyConstants.cacheVisUserByPlatformAccount + "::" + platformAccount); | ||
| 201 | if (Objects.nonNull(userTvSimpleObj)) { | ||
| 202 | Map<String, Object> map = (Map<String, Object>)userTvSimpleObj; | ||
| 203 | UserTvSimpleDTO userTvSimpleDTO = new UserTvSimpleDTO(); | ||
| 204 | userTvSimpleDTO.setPlatformAccount(map.get("platformAccount").toString()); | ||
| 205 | userTvSimpleDTO.setMemberId(Long.valueOf(map.get("memberId").toString())); | ||
| 206 | userTvSimpleDTO.setPriorityMemberCode(map.get("priorityMemberCode") == null ? "" : map.get("priorityMemberCode").toString()); | ||
| 207 | return userTvSimpleDTO; | ||
| 179 | } | 208 | } |
| 209 | |||
| 210 | UserTvSimple userTvSimple = this.userTvSimpleRepository.findSimpleByPlatformAccount(platformAccount); | ||
| 211 | if (Objects.nonNull(userTvSimple)) { | ||
| 212 | HashMap hashMap = JSONObject.parseObject(userTvSimple.toString(), HashMap.class); | ||
| 213 | this.redisUtils.set(RedisKeyConstants.cacheVisUserByPlatformAccount + "::" + platformAccount, hashMap); | ||
| 214 | return this.userTvSimpleMapper.toDto(userTvSimple); | ||
| 215 | } | ||
| 216 | |||
| 180 | return null; | 217 | return null; |
| 181 | } | 218 | } |
| 182 | 219 | ||
| 183 | @Override | 220 | @Override |
| 221 | @Transactional(readOnly = true) | ||
| 184 | public UserTvDTO findByPriorityMemberCode(String memberCode) { | 222 | public UserTvDTO findByPriorityMemberCode(String memberCode) { |
| 185 | Optional<UserTv> userTv = this.userTvRepository.findByPriorityMemberCode(memberCode); | 223 | Optional<UserTv> userTv = this.userTvRepository.findByPriorityMemberCode(memberCode); |
| 186 | if (userTv.isPresent()) { | 224 | if (userTv.isPresent()) { |
| ... | @@ -191,6 +229,7 @@ public class UserTvServiceImpl implements UserTvService { | ... | @@ -191,6 +229,7 @@ public class UserTvServiceImpl implements UserTvService { |
| 191 | } | 229 | } |
| 192 | 230 | ||
| 193 | @Override | 231 | @Override |
| 232 | @Transactional(readOnly = true) | ||
| 194 | public UserTvDTO findByMemberId(Long memberId) { | 233 | public UserTvDTO findByMemberId(Long memberId) { |
| 195 | Optional<UserTv> userTv = this.userTvRepository.findByMemberId(memberId); | 234 | Optional<UserTv> userTv = this.userTvRepository.findByMemberId(memberId); |
| 196 | if (userTv.isPresent()) { | 235 | if (userTv.isPresent()) { |
| ... | @@ -201,6 +240,7 @@ public class UserTvServiceImpl implements UserTvService { | ... | @@ -201,6 +240,7 @@ public class UserTvServiceImpl implements UserTvService { |
| 201 | } | 240 | } |
| 202 | 241 | ||
| 203 | @Override | 242 | @Override |
| 243 | @Transactional(readOnly = true) | ||
| 204 | public boolean checkPriorityMemberByMemberIdOrMemberCode(Long memberId, String memberCode) { | 244 | public boolean checkPriorityMemberByMemberIdOrMemberCode(Long memberId, String memberCode) { |
| 205 | // 检查会员是否存在 | 245 | // 检查会员是否存在 |
| 206 | this.checkMember(memberId, memberCode); | 246 | this.checkMember(memberId, memberCode); | ... | ... |
| 1 | package com.topdraw.business.module.user.iptv.service.mapper; | ||
| 2 | |||
| 3 | import com.topdraw.base.BaseMapper; | ||
| 4 | import com.topdraw.business.module.user.iptv.domain.UserTv; | ||
| 5 | import com.topdraw.business.module.user.iptv.domain.UserTvSimple; | ||
| 6 | import com.topdraw.business.module.user.iptv.service.dto.UserTvSimpleDTO; | ||
| 7 | import org.mapstruct.Mapper; | ||
| 8 | import org.mapstruct.ReportingPolicy; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * @author XiangHan | ||
| 12 | * @date 2021-12-16 | ||
| 13 | */ | ||
| 14 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
| 15 | public interface UserTvSimpleMapper extends BaseMapper<UserTvSimpleDTO, UserTvSimple> { | ||
| 16 | |||
| 17 | } |
| ... | @@ -35,6 +35,9 @@ public class TempRights { | ... | @@ -35,6 +35,9 @@ public class TempRights { |
| 35 | @Transient | 35 | @Transient |
| 36 | protected String memberCode; | 36 | protected String memberCode; |
| 37 | 37 | ||
| 38 | @Transient | ||
| 39 | protected Integer memberLevel; | ||
| 40 | |||
| 38 | /** 账号id */ | 41 | /** 账号id */ |
| 39 | @Transient | 42 | @Transient |
| 40 | protected Long userId; | 43 | protected Long userId; | ... | ... |
| ... | @@ -51,7 +51,7 @@ public class TaskOperationController { | ... | @@ -51,7 +51,7 @@ public class TaskOperationController { |
| 51 | 51 | ||
| 52 | /** | 52 | /** |
| 53 | * 新增任务 | 53 | * 新增任务 |
| 54 | * | 54 | *uc_tr_task_progress |
| 55 | * @param task 消息 | 55 | * @param task 消息 |
| 56 | */ | 56 | */ |
| 57 | @PostMapping(value = "/createTask") | 57 | @PostMapping(value = "/createTask") | ... | ... |
| ... | @@ -473,8 +473,12 @@ public class UserOperationController { | ... | @@ -473,8 +473,12 @@ public class UserOperationController { |
| 473 | @ApiOperation("保存大屏账户同时创建会员信息") | 473 | @ApiOperation("保存大屏账户同时创建会员信息") |
| 474 | @AnonymousAccess | 474 | @AnonymousAccess |
| 475 | public ResultInfo createTvUserAndMember(@Validated(value = {CreateGroup.class}) @RequestBody UserTv resources) { | 475 | public ResultInfo createTvUserAndMember(@Validated(value = {CreateGroup.class}) @RequestBody UserTv resources) { |
| 476 | log.info("UserOperationController ==> createUserAndCreateMember ==>> param ==> [{}]",resources); | 476 | log.info("UserOperationController ==> createTvUserAndMember ==>> param ==> [{}]",resources); |
| 477 | 477 | String platformAccount = resources.getPlatformAccount(); | |
| 478 | if (StringUtils.isBlank(platformAccount)) { | ||
| 479 | log.error("保存大屏账户同时创建会员信息异常,参数错误,大屏账号不存在"); | ||
| 480 | return ResultInfo.failure("参数错误,大屏账号不存在"); | ||
| 481 | } | ||
| 478 | UserTvDTO result = this.userOperationService.createTvUserAndMember(resources); | 482 | UserTvDTO result = this.userOperationService.createTvUserAndMember(resources); |
| 479 | return ResultInfo.success(result); | 483 | return ResultInfo.success(result); |
| 480 | } | 484 | } | ... | ... |
member-service-impl/src/main/java/com/topdraw/business/process/service/AsyncTaskService.java
0 → 100644
| 1 | package com.topdraw.business.process.service; | ||
| 2 | |||
| 3 | import lombok.extern.slf4j.Slf4j; | ||
| 4 | import org.springframework.stereotype.Service; | ||
| 5 | |||
| 6 | /** | ||
| 7 | * @author : | ||
| 8 | * @description: | ||
| 9 | * @function : | ||
| 10 | * @date :Created in 2022/6/22 14:05 | ||
| 11 | * @version: : | ||
| 12 | * @modified By: | ||
| 13 | * @since : modified in 2022/6/22 14:05 | ||
| 14 | */ | ||
| 15 | @Service | ||
| 16 | @Slf4j | ||
| 17 | public class AsyncTaskService { | ||
| 18 | |||
| 19 | |||
| 20 | |||
| 21 | } |
| ... | @@ -23,5 +23,5 @@ public interface RightsOperationService { | ... | @@ -23,5 +23,5 @@ public interface RightsOperationService { |
| 23 | * 任务完成自动发放权益 | 23 | * 任务完成自动发放权益 |
| 24 | * @param tempRightsMap | 24 | * @param tempRightsMap |
| 25 | */ | 25 | */ |
| 26 | void grantRights(Map<RightType, Object> tempRightsMap); | 26 | Integer grantRights(Map<RightType, Object> tempRightsMap); |
| 27 | } | 27 | } | ... | ... |
| ... | @@ -19,6 +19,7 @@ import lombok.extern.slf4j.Slf4j; | ... | @@ -19,6 +19,7 @@ import lombok.extern.slf4j.Slf4j; |
| 19 | import org.springframework.aop.framework.AopContext; | 19 | import org.springframework.aop.framework.AopContext; |
| 20 | import org.springframework.beans.BeanUtils; | 20 | import org.springframework.beans.BeanUtils; |
| 21 | import org.springframework.beans.factory.annotation.Autowired; | 21 | import org.springframework.beans.factory.annotation.Autowired; |
| 22 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
| 22 | import org.springframework.stereotype.Service; | 23 | import org.springframework.stereotype.Service; |
| 23 | 24 | ||
| 24 | import java.time.LocalDate; | 25 | import java.time.LocalDate; |
| ... | @@ -43,6 +44,9 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -43,6 +44,9 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
| 43 | MemberService memberService; | 44 | MemberService memberService; |
| 44 | 45 | ||
| 45 | @Autowired | 46 | @Autowired |
| 47 | private ThreadPoolTaskExecutor threadPoolTaskExecutor; | ||
| 48 | |||
| 49 | @Autowired | ||
| 46 | private RedisUtils redisUtils; | 50 | private RedisUtils redisUtils; |
| 47 | 51 | ||
| 48 | // 过期阀值(默认一个月) | 52 | // 过期阀值(默认一个月) |
| ... | @@ -137,7 +141,9 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -137,7 +141,9 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
| 137 | member.setUpdateTime(TimestampUtil.now()); | 141 | member.setUpdateTime(TimestampUtil.now()); |
| 138 | this.memberOperationService.doUpdateMemberCoupon(member); | 142 | this.memberOperationService.doUpdateMemberCoupon(member); |
| 139 | 143 | ||
| 140 | ((CouponOperationServiceImpl) AopContext.currentProxy()).asyncMemberCoupon(member); | 144 | /*this.threadPoolTaskExecutor.submit(() -> { |
| 145 | ((CouponOperationServiceImpl) AopContext.currentProxy()).asyncMemberCoupon(member); | ||
| 146 | });*/ | ||
| 141 | } | 147 | } |
| 142 | 148 | ||
| 143 | private MemberDTO findMemberByMemberId(Long memberId) { | 149 | private MemberDTO findMemberByMemberId(Long memberId) { | ... | ... |
| ... | @@ -20,6 +20,7 @@ import lombok.extern.slf4j.Slf4j; | ... | @@ -20,6 +20,7 @@ import lombok.extern.slf4j.Slf4j; |
| 20 | import org.springframework.aop.framework.AopContext; | 20 | import org.springframework.aop.framework.AopContext; |
| 21 | import org.springframework.beans.BeanUtils; | 21 | import org.springframework.beans.BeanUtils; |
| 22 | import org.springframework.beans.factory.annotation.Autowired; | 22 | import org.springframework.beans.factory.annotation.Autowired; |
| 23 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
| 23 | import org.springframework.stereotype.Service; | 24 | import org.springframework.stereotype.Service; |
| 24 | import org.springframework.util.CollectionUtils; | 25 | import org.springframework.util.CollectionUtils; |
| 25 | 26 | ||
| ... | @@ -43,6 +44,9 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -43,6 +44,9 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
| 43 | MemberService memberService; | 44 | MemberService memberService; |
| 44 | 45 | ||
| 45 | @Autowired | 46 | @Autowired |
| 47 | private ThreadPoolTaskExecutor threadPoolTaskExecutor; | ||
| 48 | |||
| 49 | @Autowired | ||
| 46 | private RedisUtils redisUtils; | 50 | private RedisUtils redisUtils; |
| 47 | 51 | ||
| 48 | @AsyncMqSend | 52 | @AsyncMqSend |
| ... | @@ -80,21 +84,27 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -80,21 +84,27 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
| 80 | this.redisUtils.doLock(RedisKeyConstants.updateCacheExpByMemberId + tempExp.getMemberId()); | 84 | this.redisUtils.doLock(RedisKeyConstants.updateCacheExpByMemberId + tempExp.getMemberId()); |
| 81 | 85 | ||
| 82 | // 原始经验值 | 86 | // 原始经验值 |
| 87 | long l = System.currentTimeMillis(); | ||
| 83 | long originExp = this.getExpByMemberId(tempExp); | 88 | long originExp = this.getExpByMemberId(tempExp); |
| 84 | log.info("----获取会员当前原始经验值 ==>> {}", originExp); | 89 | long l1 = System.currentTimeMillis(); |
| 90 | log.info("----获取会员当前原始经验值 ==>> {}, 总耗时 -->> {}", originExp, (l1-l)); | ||
| 85 | // 总经验值 | 91 | // 总经验值 |
| 92 | // TODO | ||
| 86 | long totalExp = this.calculateTotalExp(originExp, tempExp); | 93 | long totalExp = this.calculateTotalExp(originExp, tempExp); |
| 87 | log.info("----计算总经验值 ==>> {}", totalExp); | 94 | log.info("----计算总经验值 ==>> {}", totalExp); |
| 88 | 95 | ||
| 89 | // 2.更新成长值与等级 | 96 | // 2.更新成长值与等级 |
| 90 | log.info("----更新会员经验值与对应等级 ==>> {}", totalExp); | 97 | long l2 = System.currentTimeMillis(); |
| 91 | this.refreshMemberExpAndLevel(tempExp, totalExp); | 98 | this.refreshMemberExpAndLevel(tempExp, totalExp); |
| 99 | long l3 = System.currentTimeMillis(); | ||
| 100 | log.info("----更新会员经验值与对应等级 ==>> {}, 总耗时 ==>> {}", totalExp, (l3-l2)); | ||
| 92 | 101 | ||
| 93 | log.info("----保存经验值历史 "); | 102 | long l4 = System.currentTimeMillis(); |
| 94 | this.doInsertExpDetail(tempExp, originExp, totalExp); | 103 | this.doInsertExpDetail(tempExp, originExp, totalExp); |
| 95 | 104 | long l5 = System.currentTimeMillis(); | |
| 105 | log.info("----保存经验值历史 -->> 总耗时 -->> {}", (l5-l4)); | ||
| 96 | } catch (Exception e) { | 106 | } catch (Exception e) { |
| 97 | log.error("成长值发放失败,"+e.getMessage()); | 107 | log.error("成长值发放失败,{}",e.getMessage()); |
| 98 | } finally { | 108 | } finally { |
| 99 | this.redisUtils.doUnLock(RedisKeyConstants.updateCacheExpByMemberId + tempExp.getMemberId()); | 109 | this.redisUtils.doUnLock(RedisKeyConstants.updateCacheExpByMemberId + tempExp.getMemberId()); |
| 100 | } | 110 | } |
| ... | @@ -112,8 +122,8 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -112,8 +122,8 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
| 112 | */ | 122 | */ |
| 113 | private long getExpByMemberId(TempExp tempExp) { | 123 | private long getExpByMemberId(TempExp tempExp) { |
| 114 | Long memberId = tempExp.getMemberId(); | 124 | Long memberId = tempExp.getMemberId(); |
| 115 | MemberDTO memberDTO = this.memberOperationService.findById(memberId); | 125 | MemberDTO memberDTO = this.memberService.findById(memberId); |
| 116 | if (Objects.nonNull(memberDTO)) { | 126 | if (Objects.nonNull(memberDTO.getId())) { |
| 117 | Long exp = memberDTO.getExp(); | 127 | Long exp = memberDTO.getExp(); |
| 118 | return Objects.isNull(exp) ? 0L : exp; | 128 | return Objects.isNull(exp) ? 0L : exp; |
| 119 | } | 129 | } |
| ... | @@ -127,13 +137,13 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -127,13 +137,13 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
| 127 | */ | 137 | */ |
| 128 | private void refreshMemberExpAndLevel(TempExp tempExp,long totalExp) { | 138 | private void refreshMemberExpAndLevel(TempExp tempExp,long totalExp) { |
| 129 | 139 | ||
| 140 | Integer memberLevel = tempExp.getMemberLevel(); | ||
| 130 | Long memberId = tempExp.getMemberId(); | 141 | Long memberId = tempExp.getMemberId(); |
| 131 | // 1.获取当前成长值 | ||
| 132 | MemberDTO memberDTO = this.getMemberInfoByMemberId(memberId); | ||
| 133 | // 2.获取下一级需要的成长值 | 142 | // 2.获取下一级需要的成长值 |
| 134 | MemberLevelDTO memberLevelDTO = this.getNextLevelExp(memberDTO.getLevel() + 1, 1); | 143 | // TODO 需要缓存 |
| 144 | MemberLevelDTO memberLevelDTO = this.getNextLevelExp(memberLevel + 1, 1); | ||
| 135 | // 4.成长值比较,判断是否升级 | 145 | // 4.成长值比较,判断是否升级 |
| 136 | Integer level = this.compareExp(totalExp, memberLevelDTO,memberDTO); | 146 | Integer level = this.compareExp(totalExp, memberLevelDTO, memberLevel); |
| 137 | // 5.更新用户信息 | 147 | // 5.更新用户信息 |
| 138 | this.updateMemberInfo(level, totalExp, memberId); | 148 | this.updateMemberInfo(level, totalExp, memberId); |
| 139 | } | 149 | } |
| ... | @@ -154,8 +164,9 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -154,8 +164,9 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
| 154 | member.setLevel(level); | 164 | member.setLevel(level); |
| 155 | member.setUpdateTime(TimestampUtil.now()); | 165 | member.setUpdateTime(TimestampUtil.now()); |
| 156 | this.memberOperationService.doUpdateMemberExpAndLevel(member); | 166 | this.memberOperationService.doUpdateMemberExpAndLevel(member); |
| 157 | 167 | /*this.threadPoolTaskExecutor.submit(() -> { | |
| 158 | ((ExpOperationServiceImpl) AopContext.currentProxy()).asyncMemberExpAndLevel(member); | 168 | ((ExpOperationServiceImpl) AopContext.currentProxy()).asyncMemberExpAndLevel(member); |
| 169 | });*/ | ||
| 159 | } | 170 | } |
| 160 | 171 | ||
| 161 | private MemberDTO findMemberByMemberId(Long memberId) { | 172 | private MemberDTO findMemberByMemberId(Long memberId) { |
| ... | @@ -163,7 +174,7 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -163,7 +174,7 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
| 163 | return memberDTO; | 174 | return memberDTO; |
| 164 | } | 175 | } |
| 165 | 176 | ||
| 166 | private Integer compareExp(long newExp, MemberLevelDTO memberLevelDTO,MemberDTO memberDTO) { | 177 | private Integer compareExp(long newExp, MemberLevelDTO memberLevelDTO, Integer oldMemberLevel) { |
| 167 | if (Objects.nonNull(memberLevelDTO)) { | 178 | if (Objects.nonNull(memberLevelDTO)) { |
| 168 | Long nextLevelExp = memberLevelDTO.getExpValue(); | 179 | Long nextLevelExp = memberLevelDTO.getExpValue(); |
| 169 | if (Objects.nonNull(nextLevelExp) && nextLevelExp > 0) | 180 | if (Objects.nonNull(nextLevelExp) && nextLevelExp > 0) |
| ... | @@ -171,11 +182,11 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -171,11 +182,11 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
| 171 | return memberLevelDTO.getLevel(); | 182 | return memberLevelDTO.getLevel(); |
| 172 | } | 183 | } |
| 173 | } | 184 | } |
| 174 | return memberDTO.getLevel(); | 185 | return oldMemberLevel; |
| 175 | } | 186 | } |
| 176 | 187 | ||
| 177 | private MemberLevelDTO getNextLevelExp(Integer i,Integer status) { | 188 | private MemberLevelDTO getNextLevelExp(Integer i,Integer status) { |
| 178 | List<MemberLevelDTO> memberLevelDTOList = this.memberLevelService.findLevelAndStatus(i,status); | 189 | List<MemberLevelDTO> memberLevelDTOList = this.memberLevelService.findLevelAndStatus(i, status); |
| 179 | if (!CollectionUtils.isEmpty(memberLevelDTOList)) { | 190 | if (!CollectionUtils.isEmpty(memberLevelDTOList)) { |
| 180 | return memberLevelDTOList.get(0); | 191 | return memberLevelDTOList.get(0); |
| 181 | } | 192 | } |
| ... | @@ -217,8 +228,9 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -217,8 +228,9 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
| 217 | } | 228 | } |
| 218 | this.expDetailService.create(expDetail); | 229 | this.expDetailService.create(expDetail); |
| 219 | 230 | ||
| 220 | 231 | /*this.threadPoolTaskExecutor.submit(() -> { | |
| 221 | ((ExpOperationServiceImpl) AopContext.currentProxy()).asyncExpDetail(expDetail); | 232 | ((ExpOperationServiceImpl) AopContext.currentProxy()).asyncExpDetail(expDetail); |
| 233 | });*/ | ||
| 222 | } | 234 | } |
| 223 | 235 | ||
| 224 | } | 236 | } | ... | ... |
| ... | @@ -52,22 +52,19 @@ import java.util.stream.Collectors; | ... | @@ -52,22 +52,19 @@ import java.util.stream.Collectors; |
| 52 | public class PointsOperationServiceImpl implements PointsOperationService { | 52 | public class PointsOperationServiceImpl implements PointsOperationService { |
| 53 | 53 | ||
| 54 | @Autowired | 54 | @Autowired |
| 55 | private PointsService pointsService; | ||
| 56 | @Autowired | ||
| 57 | private PointsDetailService pointsDetailService; | 55 | private PointsDetailService pointsDetailService; |
| 58 | @Autowired | 56 | @Autowired |
| 59 | private PointsAvailableService pointsAvailableService; | 57 | private PointsAvailableService pointsAvailableService; |
| 60 | @Autowired | 58 | @Autowired |
| 61 | private PointsDetailHistoryService pointsDetailHistoryService; | ||
| 62 | @Autowired | ||
| 63 | private MemberOperationService memberOperationService; | 59 | private MemberOperationService memberOperationService; |
| 64 | @Autowired | 60 | @Autowired |
| 65 | private MemberService memberService; | 61 | private MemberService memberService; |
| 66 | 62 | ||
| 67 | @Autowired | 63 | @Autowired |
| 68 | private RedisUtils redisUtils; | 64 | private ThreadPoolTaskExecutor threadPoolTaskExecutor; |
| 65 | |||
| 69 | @Autowired | 66 | @Autowired |
| 70 | ThreadPoolTaskExecutor threadPoolTaskExecutor; | 67 | private RedisUtils redisUtils; |
| 71 | 68 | ||
| 72 | // 过期阈值 30天 | 69 | // 过期阈值 30天 |
| 73 | private static final Integer EXPIRE_FACTOR = 30; | 70 | private static final Integer EXPIRE_FACTOR = 30; |
| ... | @@ -200,6 +197,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -200,6 +197,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 200 | long currentPoints) { | 197 | long currentPoints) { |
| 201 | // 兑换的积分 | 198 | // 兑换的积分 |
| 202 | Long points = tempPoints.getPoints(); | 199 | Long points = tempPoints.getPoints(); |
| 200 | String memberCode = tempPoints.getMemberCode(); | ||
| 203 | 201 | ||
| 204 | List<PointsAvailableDTO> pointsAvailableDTOS = customAvailablePointsMap.get(DELETE_AVAILABLE_POINTS); | 202 | List<PointsAvailableDTO> pointsAvailableDTOS = customAvailablePointsMap.get(DELETE_AVAILABLE_POINTS); |
| 205 | 203 | ||
| ... | @@ -211,9 +209,9 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -211,9 +209,9 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 211 | BeanUtils.copyProperties(pointsAvailableDTO, _tempPoints); | 209 | BeanUtils.copyProperties(pointsAvailableDTO, _tempPoints); |
| 212 | BeanUtils.copyProperties(tempPoints, _tempPoints); | 210 | BeanUtils.copyProperties(tempPoints, _tempPoints); |
| 213 | _tempPoints.setPoints(-(Math.abs(points))); | 211 | _tempPoints.setPoints(-(Math.abs(points))); |
| 214 | Long totalPoints = this.calculateTotalPoints(_tempPoints, currentPoints); | 212 | Long totalPoints = currentPoints + tempPoints.getPoints(); |
| 215 | 213 | ||
| 216 | this.doInsertTrPointsDetail(memberId, _tempPoints, currentPoints, totalPoints); | 214 | this.doInsertTrPointsDetail(memberId, memberCode, _tempPoints, currentPoints, totalPoints); |
| 217 | } | 215 | } |
| 218 | } | 216 | } |
| 219 | 217 | ||
| ... | @@ -429,39 +427,47 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -429,39 +427,47 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 429 | * | 427 | * |
| 430 | * @param tempPoints 积分 | 428 | * @param tempPoints 积分 |
| 431 | */ | 429 | */ |
| 432 | |||
| 433 | private void refresh(TempPoints tempPoints) { | 430 | private void refresh(TempPoints tempPoints) { |
| 434 | Long memberId = tempPoints.getMemberId(); | 431 | Long memberId = tempPoints.getMemberId(); |
| 432 | String memberCode = tempPoints.getMemberCode(); | ||
| 435 | log.info("----------->> 会员id ===>>>>" + memberId); | 433 | log.info("----------->> 会员id ===>>>>" + memberId); |
| 436 | try { | 434 | try { |
| 437 | this.redisUtils.doLock(RedisKeyConstants.updateCachePointsByMemberId + memberId.toString()); | 435 | this.redisUtils.doLock(RedisKeyConstants.updateCachePointsByMemberId + memberId.toString()); |
| 438 | // 1.可用总积分 | 436 | // 1.可用总积分 |
| 437 | long l = System.currentTimeMillis(); | ||
| 439 | Long currentPoints = this.findAvailablePointsByMemberId(memberId); | 438 | Long currentPoints = this.findAvailablePointsByMemberId(memberId); |
| 440 | log.info("----------->> 获取会员当前可用总积分 --->>>> {}", currentPoints); | 439 | long l1 = System.currentTimeMillis(); |
| 440 | // log.info("查询大屏信息,总耗时 ==>> {}", (l1-l)); | ||
| 441 | log.info("----------->> 获取会员当前可用总积分 --->>>> {}, 总耗时 ==>> {}", currentPoints, (l1-l)); | ||
| 441 | 442 | ||
| 442 | // 2.计算总积分 | 443 | // 2.计算总积分 |
| 443 | Long totalPoints = this.calculateTotalPoints(tempPoints, currentPoints); | 444 | Long totalPoints = currentPoints + tempPoints.getPoints(); |
| 444 | log.info("----------->> 总积分(可用总积分+获得的积分) --->>> {}", totalPoints); | 445 | log.info("----------->> 总积分(可用总积分+获得的积分) --->>> {}", totalPoints); |
| 445 | 446 | ||
| 446 | // 3.添加积分明细 | 447 | // 3.添加积分明细 |
| 447 | this.doInsertTrPointsDetail(memberId, tempPoints, currentPoints, totalPoints); | 448 | long l2 = System.currentTimeMillis(); |
| 448 | log.info("----------->> 添加积分明细 --->>> "); | 449 | this.doInsertTrPointsDetail(memberId, memberCode, tempPoints, currentPoints, totalPoints); |
| 450 | long l3 = System.currentTimeMillis(); | ||
| 451 | log.info("----------->> 添加积分明细 --->>> 总耗时 ==>> {}", (l3-l2)); | ||
| 449 | 452 | ||
| 450 | // 4.添加可用积分 | 453 | // 4.添加可用积分 |
| 454 | long l4 = System.currentTimeMillis(); | ||
| 451 | this.doInsertTrPointsAvailable(tempPoints); | 455 | this.doInsertTrPointsAvailable(tempPoints); |
| 452 | log.info("----------->> 添加可用积分 -->>> "); | 456 | long l5 = System.currentTimeMillis(); |
| 457 | log.info("----------->> 添加可用积分 -->>> 总耗时 ==>> {}", (l5-l4)); | ||
| 453 | 458 | ||
| 454 | // 5.即将过期的积分 | 459 | // 5.即将过期的积分 |
| 460 | // TODO 查询的时候再更新过期积分 | ||
| 455 | long soonExpirePoints = this.getSoonExpirePoints(memberId, tempPoints); | 461 | long soonExpirePoints = this.getSoonExpirePoints(memberId, tempPoints); |
| 456 | log.info("----------->> 即将过期的积分 ------->>>>> {}", soonExpirePoints); | 462 | log.info("----------->> 即将过期的积分 ------->>>>> {}", soonExpirePoints); |
| 457 | 463 | ||
| 458 | // 6.更新会员的总积分 | 464 | // 6.更新会员的总积分 |
| 459 | log.info("----------->> 更新会员的总积分 ------->>>>> 总积分--->>> {}", totalPoints); | 465 | long l6 = System.currentTimeMillis(); |
| 460 | this.freshMemberCurrentPoints(memberId, totalPoints, soonExpirePoints); | 466 | this.freshMemberCurrentPoints(memberId, totalPoints, soonExpirePoints); |
| 461 | 467 | long l7 = System.currentTimeMillis(); | |
| 468 | log.info("----------->> 更新会员的总积分 ------->>>>> 总积分--->>> {} -->>总耗时 ==>> {}", totalPoints, (l7-l6)); | ||
| 462 | } catch (Exception e) { | 469 | } catch (Exception e) { |
| 463 | e.printStackTrace(); | 470 | log.error(" ==>> {}", e.getMessage()); |
| 464 | throw e; | ||
| 465 | } finally { | 471 | } finally { |
| 466 | this.redisUtils.doUnLock(RedisKeyConstants.updateCachePointsByMemberId + memberId.toString()); | 472 | this.redisUtils.doUnLock(RedisKeyConstants.updateCachePointsByMemberId + memberId.toString()); |
| 467 | } | 473 | } |
| ... | @@ -477,7 +483,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -477,7 +483,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 477 | // 获取的积分 | 483 | // 获取的积分 |
| 478 | Long rewardPoints = tempPoints.getPoints(); | 484 | Long rewardPoints = tempPoints.getPoints(); |
| 479 | // 总积分 | 485 | // 总积分 |
| 480 | Long totalPoints = currentPoints + rewardPoints; | 486 | Long totalPoints = currentPoints + tempPoints.getPoints(); |
| 481 | return totalPoints; | 487 | return totalPoints; |
| 482 | } | 488 | } |
| 483 | 489 | ||
| ... | @@ -514,7 +520,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -514,7 +520,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 514 | */ | 520 | */ |
| 515 | private void freshMemberCurrentPoints(Long memberId, Long currentPoints, long duePoints) { | 521 | private void freshMemberCurrentPoints(Long memberId, Long currentPoints, long duePoints) { |
| 516 | 522 | ||
| 517 | MemberDTO memberDTO = this.findMemberByMemberId(memberId); | 523 | MemberDTO memberDTO = this.memberService.findById(memberId); |
| 518 | 524 | ||
| 519 | Member member = new Member(); | 525 | Member member = new Member(); |
| 520 | member.setId(memberDTO.getId()); | 526 | member.setId(memberDTO.getId()); |
| ... | @@ -525,17 +531,14 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -525,17 +531,14 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 525 | try { | 531 | try { |
| 526 | this.memberOperationService.doUpdateMemberPoints(member); | 532 | this.memberOperationService.doUpdateMemberPoints(member); |
| 527 | 533 | ||
| 528 | ((PointsOperationServiceImpl) AopContext.currentProxy()).asyncMemberPoint(member); | 534 | /*this.threadPoolTaskExecutor.submit(() -> { |
| 535 | ((PointsOperationServiceImpl) AopContext.currentProxy()).asyncMemberPoint(member); | ||
| 536 | });*/ | ||
| 529 | } catch (Exception e){ | 537 | } catch (Exception e){ |
| 530 | log.error("同步会员积分异常,"+e.getMessage()); | 538 | log.error("同步会员积分异常,"+e.getMessage()); |
| 531 | } | 539 | } |
| 532 | } | 540 | } |
| 533 | 541 | ||
| 534 | private MemberDTO findMemberByMemberId(Long memberId) { | ||
| 535 | MemberDTO memberDTO = this.memberService.findById(memberId); | ||
| 536 | return memberDTO; | ||
| 537 | } | ||
| 538 | |||
| 539 | /** | 542 | /** |
| 540 | * 更新可用积分表 | 543 | * 更新可用积分表 |
| 541 | * @param tempPoints | 544 | * @param tempPoints |
| ... | @@ -554,8 +557,9 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -554,8 +557,9 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 554 | } | 557 | } |
| 555 | 558 | ||
| 556 | this.pointsAvailableService.create4Custom(pointsAvailable); | 559 | this.pointsAvailableService.create4Custom(pointsAvailable); |
| 557 | 560 | /*this.threadPoolTaskExecutor.submit(() -> { | |
| 558 | ((PointsOperationServiceImpl) AopContext.currentProxy()).asyncPointsAvailable(pointsAvailable); | 561 | ((PointsOperationServiceImpl) AopContext.currentProxy()).asyncPointsAvailable(pointsAvailable); |
| 562 | });*/ | ||
| 559 | } | 563 | } |
| 560 | 564 | ||
| 561 | /** | 565 | /** |
| ... | @@ -564,15 +568,13 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -564,15 +568,13 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 564 | * @param tempPoints 积分 | 568 | * @param tempPoints 积分 |
| 565 | * @return Integer 总积分 | 569 | * @return Integer 总积分 |
| 566 | */ | 570 | */ |
| 567 | private void doInsertTrPointsDetail(Long memberId, TempPoints tempPoints, Long currentPoints, Long totalPoints){ | 571 | private void doInsertTrPointsDetail(Long memberId, String memberCode, TempPoints tempPoints, Long currentPoints, Long totalPoints){ |
| 568 | |||
| 569 | MemberDTO memberDTO = this.memberService.findById(memberId); | ||
| 570 | 572 | ||
| 571 | PointsDetail pointsDetail = new PointsDetail(); | 573 | PointsDetail pointsDetail = new PointsDetail(); |
| 572 | BeanUtils.copyProperties(tempPoints, pointsDetail); | 574 | BeanUtils.copyProperties(tempPoints, pointsDetail); |
| 573 | pointsDetail.setId(null); | 575 | pointsDetail.setId(null); |
| 574 | pointsDetail.setMemberId(memberId); | 576 | pointsDetail.setMemberId(memberId); |
| 575 | pointsDetail.setMemberCode(memberDTO.getCode()); | 577 | pointsDetail.setMemberCode(memberCode); |
| 576 | pointsDetail.setCode(String.valueOf(IdWorker.generator())); | 578 | pointsDetail.setCode(String.valueOf(IdWorker.generator())); |
| 577 | pointsDetail.setPoints(tempPoints.getPoints()); | 579 | pointsDetail.setPoints(tempPoints.getPoints()); |
| 578 | pointsDetail.setOriginalPoints(currentPoints); | 580 | pointsDetail.setOriginalPoints(currentPoints); |
| ... | @@ -587,7 +589,9 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -587,7 +589,9 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 587 | // 保存积分流水 | 589 | // 保存积分流水 |
| 588 | this.pointsDetailService.create4Custom(pointsDetail); | 590 | this.pointsDetailService.create4Custom(pointsDetail); |
| 589 | 591 | ||
| 590 | ((PointsOperationServiceImpl) AopContext.currentProxy()).asyncPointsDetail(pointsDetail); | 592 | /*this.threadPoolTaskExecutor.submit(() -> { |
| 593 | ((PointsOperationServiceImpl) AopContext.currentProxy()).asyncPointsDetail(pointsDetail); | ||
| 594 | });*/ | ||
| 591 | } | 595 | } |
| 592 | 596 | ||
| 593 | } | 597 | } | ... | ... |
| ... | @@ -21,8 +21,12 @@ import org.springframework.stereotype.Service; | ... | @@ -21,8 +21,12 @@ 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; | ||
| 24 | import java.sql.Timestamp; | 25 | import java.sql.Timestamp; |
| 25 | import java.util.*; | 26 | import java.util.*; |
| 27 | import java.util.concurrent.ExecutionException; | ||
| 28 | import java.util.concurrent.Future; | ||
| 29 | import java.util.concurrent.ThreadPoolExecutor; | ||
| 26 | 30 | ||
| 27 | /** | 31 | /** |
| 28 | * 权益处理 | 32 | * 权益处理 |
| ... | @@ -71,20 +75,23 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -71,20 +75,23 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 71 | * @param tempRightsMap 权益类型 | 75 | * @param tempRightsMap 权益类型 |
| 72 | */ | 76 | */ |
| 73 | @Override | 77 | @Override |
| 74 | public void grantRights(Map<RightType, Object> tempRightsMap) { | 78 | public Integer grantRights(Map<RightType, Object> tempRightsMap) { |
| 75 | 79 | ||
| 76 | this.threadPoolTaskExecutor.execute(()-> { | 80 | this.threadPoolTaskExecutor.execute(()-> { |
| 77 | // 2.创建权益历史对象 | 81 | // 2.创建权益历史对象 |
| 78 | List<RightsHistory> rightsList = this.getRightHistory(tempRightsMap); | 82 | List<RightsHistory> rightsList = this.getRightHistory(tempRightsMap); |
| 79 | if (!CollectionUtils.isEmpty(rightsList)) { | 83 | if (!CollectionUtils.isEmpty(rightsList)) { |
| 80 | log.info("异步保存权益领取历史开始 ==>> [{}]", rightsList); | 84 | // log.info("异步保存权益领取历史开始 ==>> [{}]", rightsList); |
| 85 | long l = System.currentTimeMillis(); | ||
| 81 | // 3.保存权益历史 | 86 | // 3.保存权益历史 |
| 82 | this.doInsertTrRightHistory(rightsList); | 87 | this.doInsertTrRightHistory(rightsList); |
| 88 | long l1 = System.currentTimeMillis(); | ||
| 89 | log.info("保存权益历史,总耗时 ==>> {}", l1-l); | ||
| 83 | } | 90 | } |
| 84 | }); | 91 | }); |
| 85 | 92 | ||
| 86 | // 1.权益下发 | 93 | // 1.权益下发 |
| 87 | this.refresh(tempRightsMap); | 94 | return this.refresh(tempRightsMap); |
| 88 | } | 95 | } |
| 89 | 96 | ||
| 90 | /** | 97 | /** |
| ... | @@ -141,28 +148,29 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -141,28 +148,29 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 141 | this.couponOperationService.grantCouponThroughTempCoupon(tempCouponList); | 148 | this.couponOperationService.grantCouponThroughTempCoupon(tempCouponList); |
| 142 | } | 149 | } |
| 143 | 150 | ||
| 151 | |||
| 144 | /** | 152 | /** |
| 145 | * 权益发放 | 153 | * 权益发放 |
| 146 | * @param tempRightsMap | 154 | * @param tempRightsMap |
| 147 | */ | 155 | */ |
| 148 | private void refresh(Map<RightType, Object> tempRightsMap) { | 156 | private Integer refresh(Map<RightType, Object> tempRightsMap) { |
| 149 | 157 | ||
| 150 | this.threadPoolTaskExecutor.execute(() -> { | 158 | // Future<?> submit = this.threadPoolTaskExecutor.submit(() -> { |
| 151 | List<TempPoints> tempPointsList = (List<TempPoints>) tempRightsMap.get(RightType.POINTS); | 159 | List<TempPoints> tempPointsList = (List<TempPoints>) tempRightsMap.get(RightType.POINTS); |
| 152 | if (!CollectionUtils.isEmpty(tempPointsList)) { | 160 | if (!CollectionUtils.isEmpty(tempPointsList)) { |
| 153 | log.info("发放积分开始 ==>> [{}]", tempPointsList); | 161 | // log.info("发放积分开始 ==>> [{}]", tempPointsList); |
| 154 | long l = System.currentTimeMillis(); | 162 | long l = System.currentTimeMillis(); |
| 155 | // 积分 | 163 | // 积分 |
| 156 | this.grantPoint(tempPointsList); | 164 | this.grantPoint(tempPointsList); |
| 157 | long l2 = System.currentTimeMillis(); | 165 | long l2 = System.currentTimeMillis(); |
| 158 | log.info("发放积分结束,总耗时 ==>> {}", (l2 - l)); | 166 | log.info("发放积分结束,总耗时 ==>> {}", (l2 - l)); |
| 159 | } | 167 | } |
| 160 | }); | 168 | // }); |
| 161 | 169 | ||
| 162 | this.threadPoolTaskExecutor.execute(()-> { | 170 | this.threadPoolTaskExecutor.submit(() -> { |
| 163 | List<TempExp> tempExpList = (List<TempExp>) tempRightsMap.get(RightType.EXP); | 171 | List<TempExp> tempExpList = (List<TempExp>) tempRightsMap.get(RightType.EXP); |
| 164 | if (!CollectionUtils.isEmpty(tempExpList)) { | 172 | if (!CollectionUtils.isEmpty(tempExpList)) { |
| 165 | log.info("发放成长值开始 ==>> [{}]", tempExpList); | 173 | // log.info("发放成长值开始 ==>> [{}]", tempExpList); |
| 166 | long l = System.currentTimeMillis(); | 174 | long l = System.currentTimeMillis(); |
| 167 | // 成长值 | 175 | // 成长值 |
| 168 | this.grantExp(tempExpList); | 176 | this.grantExp(tempExpList); |
| ... | @@ -171,25 +179,30 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -171,25 +179,30 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 171 | } | 179 | } |
| 172 | }); | 180 | }); |
| 173 | 181 | ||
| 174 | this.threadPoolTaskExecutor.execute(()-> { | 182 | // this.threadPoolTaskExecutor.submit(() -> { |
| 175 | List<TempCoupon> tempCouponList = (List<TempCoupon>) tempRightsMap.get(RightType.COUPON); | 183 | /*List<TempCoupon> tempCouponList = (List<TempCoupon>) tempRightsMap.get(RightType.COUPON); |
| 176 | if (!CollectionUtils.isEmpty(tempCouponList)) { | 184 | if (!CollectionUtils.isEmpty(tempCouponList)) { |
| 177 | log.info("发放优惠券开始 ==>> [{}]", tempCouponList); | 185 | // log.info("发放优惠券开始 ==>> [{}]", tempCouponList); |
| 178 | long l = System.currentTimeMillis(); | 186 | long l = System.currentTimeMillis(); |
| 179 | // 优惠券 | 187 | // 优惠券 |
| 180 | this.grantCoupon(tempCouponList); | 188 | this.grantCoupon(tempCouponList); |
| 181 | long l2 = System.currentTimeMillis(); | 189 | long l2 = System.currentTimeMillis(); |
| 182 | log.info("发放优惠券结束,总耗时 ==>> {}", (l2 - l)); | 190 | log.info("发放优惠券结束,总耗时 ==>> {}", (l2 - l)); |
| 183 | } | 191 | }*/ |
| 184 | }); | 192 | // }); |
| 185 | 193 | ||
| 186 | // 其他权益 | 194 | // 其他权益 |
| 187 | this.threadPoolTaskExecutor.execute(()-> { | 195 | // Future<?> submit = this.threadPoolTaskExecutor.submit(() -> { |
| 188 | log.info("发放其他权益开始 ==>> [{}]", tempRightsMap); | 196 | // log.info("发放其他权益开始 ==>> [{}]", tempRightsMap); |
| 197 | long l = System.currentTimeMillis(); | ||
| 189 | this.grantOtherRight(tempRightsMap); | 198 | this.grantOtherRight(tempRightsMap); |
| 190 | log.info("发放其他权益结束 ==>> [{}]", tempRightsMap); | 199 | long l2 = System.currentTimeMillis(); |
| 191 | }); | 200 | log.info("发放其他权益结束 ==>> 总耗时 ==>> {}", l-l2); |
| 201 | // }); | ||
| 202 | |||
| 203 | |||
| 192 | 204 | ||
| 205 | return tempRightsMap.keySet().size(); | ||
| 193 | } | 206 | } |
| 194 | 207 | ||
| 195 | private void grantOtherRight(Map<RightType, Object> tempRightsMap) { | 208 | private void grantOtherRight(Map<RightType, Object> tempRightsMap) { | ... | ... |
| 1 | package com.topdraw.business.process.service.impl; | 1 | package com.topdraw.business.process.service.impl; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
| 4 | import com.alibaba.fastjson.JSONArray; | ||
| 5 | import com.alibaba.fastjson.JSONObject; | 4 | import com.alibaba.fastjson.JSONObject; |
| 6 | import com.topdraw.aspect.AsyncMqSend; | 5 | import com.topdraw.aspect.AsyncMqSend; |
| 7 | import com.topdraw.business.module.coupon.service.CouponService; | 6 | import com.topdraw.business.module.coupon.service.CouponService; |
| 8 | import com.topdraw.business.module.coupon.service.dto.CouponDTO; | 7 | import com.topdraw.business.module.coupon.service.dto.CouponDTO; |
| 9 | import com.topdraw.business.module.member.group.service.MemberGroupService; | 8 | import com.topdraw.business.module.member.service.dto.MemberSimpleDTO; |
| 10 | import com.topdraw.business.module.member.group.service.dto.MemberGroupDTO; | ||
| 11 | import com.topdraw.business.module.rights.service.RightsService; | 9 | import com.topdraw.business.module.rights.service.RightsService; |
| 12 | import com.topdraw.business.module.rights.service.dto.RightsDTO; | 10 | import com.topdraw.business.module.rights.service.dto.RightsDTO; |
| 13 | import com.topdraw.business.module.task.attribute.domain.TaskAttr; | 11 | import com.topdraw.business.module.task.attribute.domain.TaskAttr; |
| ... | @@ -16,13 +14,12 @@ import com.topdraw.business.module.task.attribute.service.dto.TaskAttrDTO; | ... | @@ -16,13 +14,12 @@ import com.topdraw.business.module.task.attribute.service.dto.TaskAttrDTO; |
| 16 | import com.topdraw.business.module.task.domain.TaskBuilder; | 14 | import com.topdraw.business.module.task.domain.TaskBuilder; |
| 17 | import com.topdraw.business.module.task.progress.domain.TrTaskProgress; | 15 | import com.topdraw.business.module.task.progress.domain.TrTaskProgress; |
| 18 | import com.topdraw.business.module.task.progress.service.TrTaskProgressService; | 16 | import com.topdraw.business.module.task.progress.service.TrTaskProgressService; |
| 19 | import com.topdraw.business.module.task.progress.service.dto.TrTaskProgressDTO; | ||
| 20 | import com.topdraw.business.module.task.service.dto.TaskDTO; | 17 | import com.topdraw.business.module.task.service.dto.TaskDTO; |
| 21 | import com.topdraw.business.module.task.template.service.dto.TaskTemplateDTO; | 18 | import com.topdraw.business.module.task.template.service.dto.TaskTemplateDTO; |
| 22 | import com.topdraw.business.module.user.iptv.domain.UserTv; | 19 | import com.topdraw.business.module.user.iptv.domain.UserTv; |
| 23 | import com.topdraw.business.module.user.iptv.service.UserTvService; | 20 | import com.topdraw.business.module.user.iptv.service.UserTvService; |
| 24 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; | 21 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; |
| 25 | import com.topdraw.business.process.domian.constant.TaskTemplateType; | 22 | import com.topdraw.business.module.user.iptv.service.dto.UserTvSimpleDTO; |
| 26 | import com.topdraw.business.module.rights.constant.RightType; | 23 | import com.topdraw.business.module.rights.constant.RightType; |
| 27 | import com.topdraw.business.process.service.PointsOperationService; | 24 | import com.topdraw.business.process.service.PointsOperationService; |
| 28 | import com.topdraw.business.process.service.RightsOperationService; | 25 | import com.topdraw.business.process.service.RightsOperationService; |
| ... | @@ -31,7 +28,6 @@ import com.topdraw.business.module.member.service.MemberService; | ... | @@ -31,7 +28,6 @@ import com.topdraw.business.module.member.service.MemberService; |
| 31 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 28 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
| 32 | import com.topdraw.business.module.task.domain.Task; | 29 | import com.topdraw.business.module.task.domain.Task; |
| 33 | import com.topdraw.business.module.task.service.TaskService; | 30 | import com.topdraw.business.module.task.service.TaskService; |
| 34 | import com.topdraw.business.module.task.template.domain.TaskTemplate; | ||
| 35 | import com.topdraw.business.module.task.template.service.TaskTemplateService; | 31 | import com.topdraw.business.module.task.template.service.TaskTemplateService; |
| 36 | import com.topdraw.business.process.domian.*; | 32 | import com.topdraw.business.process.domian.*; |
| 37 | import com.topdraw.business.process.service.UserOperationService; | 33 | import com.topdraw.business.process.service.UserOperationService; |
| ... | @@ -50,10 +46,8 @@ import org.springframework.beans.BeanUtils; | ... | @@ -50,10 +46,8 @@ import org.springframework.beans.BeanUtils; |
| 50 | import org.springframework.beans.factory.annotation.Autowired; | 46 | import org.springframework.beans.factory.annotation.Autowired; |
| 51 | import org.springframework.beans.factory.annotation.Value; | 47 | import org.springframework.beans.factory.annotation.Value; |
| 52 | import org.springframework.cache.annotation.CacheEvict; | 48 | import org.springframework.cache.annotation.CacheEvict; |
| 53 | import org.springframework.cache.annotation.CachePut; | ||
| 54 | import org.springframework.data.redis.core.StringRedisTemplate; | 49 | import org.springframework.data.redis.core.StringRedisTemplate; |
| 55 | import org.springframework.data.redis.core.ValueOperations; | 50 | import org.springframework.data.redis.core.ValueOperations; |
| 56 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
| 57 | import org.springframework.stereotype.Service; | 51 | import org.springframework.stereotype.Service; |
| 58 | import org.springframework.util.CollectionUtils; | 52 | import org.springframework.util.CollectionUtils; |
| 59 | 53 | ||
| ... | @@ -63,7 +57,6 @@ import java.time.LocalDateTime; | ... | @@ -63,7 +57,6 @@ import java.time.LocalDateTime; |
| 63 | import java.util.*; | 57 | import java.util.*; |
| 64 | import java.util.concurrent.TimeUnit; | 58 | import java.util.concurrent.TimeUnit; |
| 65 | 59 | ||
| 66 | import static java.util.stream.Collectors.toList; | ||
| 67 | 60 | ||
| 68 | /** | 61 | /** |
| 69 | * 任务处理 | 62 | * 任务处理 |
| ... | @@ -89,35 +82,21 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -89,35 +82,21 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 89 | @Autowired | 82 | @Autowired |
| 90 | private TaskAttrService taskAttrService; | 83 | private TaskAttrService taskAttrService; |
| 91 | @Autowired | 84 | @Autowired |
| 92 | private MemberGroupService memberGroupService; | ||
| 93 | @Autowired | ||
| 94 | private TaskTemplateService taskTemplateService; | 85 | private TaskTemplateService taskTemplateService; |
| 95 | @Autowired | 86 | @Autowired |
| 96 | private TrTaskProgressService trTaskProgressService; | 87 | private TrTaskProgressService trTaskProgressService; |
| 97 | @Autowired | 88 | @Autowired |
| 98 | private RightsOperationService rightsOperationService; | 89 | private RightsOperationService rightsOperationService; |
| 99 | |||
| 100 | @Autowired | 90 | @Autowired |
| 101 | private ThreadPoolTaskExecutor threadPoolTaskExecutor; | 91 | private RedisUtils redisUtils; |
| 102 | 92 | ||
| 103 | @Value("${uc.validPriorityMember}") | 93 | @Value("${uc.validPriorityMember}") |
| 104 | private int validPriorityMember; | 94 | private int validPriorityMember; |
| 105 | 95 | ||
| 106 | private static final Integer TASK_FINISH_STATUS = 1; | 96 | private static final Integer TASK_FINISH_STATUS = 1; |
| 107 | private static final Integer TASK_UNFINISH_STATUS = 2; | ||
| 108 | private static final Integer POINTS_TYPE_RANDOM = 1; | 97 | private static final Integer POINTS_TYPE_RANDOM = 1; |
| 109 | private static final Integer POINTS_MIN = 1; | 98 | private static final Integer POINTS_MIN = 1; |
| 110 | 99 | ||
| 111 | |||
| 112 | |||
| 113 | |||
| 114 | @AsyncMqSend | ||
| 115 | public void asyncCreateTask(Task task) {} | ||
| 116 | @AsyncMqSend | ||
| 117 | public void asyncUpdateTask(Task task) {} | ||
| 118 | @AsyncMqSend | ||
| 119 | public void asyncDeleteTask(Task task) {} | ||
| 120 | |||
| 121 | @Override | 100 | @Override |
| 122 | @CacheEvict(cacheNames = RedisKeyConstants.cacheTaskByEvent, key = "#task.event") | 101 | @CacheEvict(cacheNames = RedisKeyConstants.cacheTaskByEvent, key = "#task.event") |
| 123 | public TaskDTO createTask(Task task) { | 102 | public TaskDTO createTask(Task task) { |
| ... | @@ -139,12 +118,12 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -139,12 +118,12 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 139 | 118 | ||
| 140 | /** | 119 | /** |
| 141 | * | 120 | * |
| 142 | * @param task_ | 121 | * @param task 任务 |
| 143 | */ | 122 | */ |
| 144 | private void createTaskAttr(Task task_) { | 123 | private void createTaskAttr(Task task) { |
| 145 | TaskAttr taskAttr = new TaskAttr(); | 124 | TaskAttr taskAttr = new TaskAttr(); |
| 146 | taskAttr.setAttrStr(task_.getAttr()); | 125 | taskAttr.setAttrStr(task.getAttr()); |
| 147 | taskAttr.setTaskId(task_.getId()); | 126 | taskAttr.setTaskId(task.getId()); |
| 148 | this.taskAttrService.create(taskAttr); | 127 | this.taskAttrService.create(taskAttr); |
| 149 | } | 128 | } |
| 150 | 129 | ||
| ... | @@ -166,15 +145,15 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -166,15 +145,15 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 166 | 145 | ||
| 167 | /** | 146 | /** |
| 168 | * | 147 | * |
| 169 | * @param task_ | 148 | * @param task 任务 |
| 170 | */ | 149 | */ |
| 171 | private void updateTaskAttr(Task task_) { | 150 | private void updateTaskAttr(Task task) { |
| 172 | 151 | ||
| 173 | TaskAttrDTO taskAttrDTO = this.findTaskAttrByTaskId(task_.getId()); | 152 | TaskAttrDTO taskAttrDTO = this.taskAttrService.findByTaskId(task.getId()); |
| 174 | if (Objects.nonNull(taskAttrDTO.getId())) { | 153 | if (Objects.nonNull(taskAttrDTO.getId())) { |
| 175 | TaskAttr taskAttr = new TaskAttr(); | 154 | TaskAttr taskAttr = new TaskAttr(); |
| 176 | BeanUtils.copyProperties(taskAttrDTO, taskAttr); | 155 | BeanUtils.copyProperties(taskAttrDTO, taskAttr); |
| 177 | taskAttr.setAttrStr(task_.getAttr()); | 156 | taskAttr.setAttrStr(task.getAttr()); |
| 178 | this.taskAttrService.update(taskAttr); | 157 | this.taskAttrService.update(taskAttr); |
| 179 | } | 158 | } |
| 180 | } | 159 | } |
| ... | @@ -223,8 +202,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -223,8 +202,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 223 | 202 | ||
| 224 | @Override | 203 | @Override |
| 225 | public TaskDTO findByCode(String code) { | 204 | public TaskDTO findByCode(String code) { |
| 226 | TaskDTO taskDTO = this.taskService.findByCode(code); | 205 | return this.taskService.findByCode(code); |
| 227 | return taskDTO; | ||
| 228 | } | 206 | } |
| 229 | 207 | ||
| 230 | @Override | 208 | @Override |
| ... | @@ -232,54 +210,60 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -232,54 +210,60 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 232 | 210 | ||
| 233 | DataSyncMsg dataSyncMsg = JSONUtil.parseMsg2Object(content, DataSyncMsg.class); | 211 | DataSyncMsg dataSyncMsg = JSONUtil.parseMsg2Object(content, DataSyncMsg.class); |
| 234 | log.info("事件dataSyncMsg ==>> {}", dataSyncMsg); | 212 | log.info("事件dataSyncMsg ==>> {}", dataSyncMsg); |
| 235 | DataSyncMsg.MsgData msgData = JSON.parseObject(dataSyncMsg.getMsgData(), DataSyncMsg.MsgData.class); | 213 | |
| 236 | log.info("事件消息体解析后msgData ==>> {}", msgData); | 214 | if (StringUtils.isBlank(dataSyncMsg.getMsgData())) { |
| 237 | if (Objects.isNull(msgData)) { | ||
| 238 | log.error("参数错误,事件消息体为空"); | 215 | log.error("参数错误,事件消息体为空"); |
| 239 | return ResultInfo.failure("参数错误,事件消息体为空"); | 216 | return ResultInfo.failure("参数错误,事件消息体为空"); |
| 240 | } | 217 | } |
| 241 | 218 | ||
| 242 | // 小屏侧传递的参数是memberId | 219 | JSONObject msgData = JSON.parseObject(dataSyncMsg.getMsgData(), JSONObject.class); |
| 243 | Long memberId = msgData.getMemberId(); | ||
| 244 | // 大屏侧传递的参数是platformAccount | ||
| 245 | String platformAccount = msgData.getPlatformAccount(); | ||
| 246 | 220 | ||
| 247 | // 参数校验 | 221 | Object memberIdObj = msgData.get("memberId"); |
| 248 | if (Objects.isNull(memberId) && StringUtils.isBlank(platformAccount)) { | 222 | Object platformAccountObj = msgData.get("platformAccount"); |
| 249 | log.error("参数错误,memberId 和 platformAccount 都为null"); | 223 | if (Objects.isNull(memberIdObj) && Objects.isNull(platformAccountObj)) { |
| 250 | return ResultInfo.failure("参数错误"); | 224 | log.error("参数错误,会员id和platformAccount都为空"); |
| 225 | return ResultInfo.failure("参数错误,会员id和platformAccount都为空"); | ||
| 251 | } | 226 | } |
| 252 | 227 | ||
| 253 | // 获取会员信息,小屏会员信息通过memberId进行检索,大屏会员信息通过platformAccount进行检索 | 228 | // 大屏侧传递的参数是platformAccount |
| 254 | long l = System.currentTimeMillis(); | 229 | MemberSimpleDTO memberDTO = null; |
| 255 | MemberDTO memberDTO = null; | 230 | if (Objects.nonNull(memberIdObj)) { |
| 256 | if (Objects.nonNull(memberId)) { | 231 | // 小屏侧传递的参数是memberId |
| 232 | memberDTO = this.memberService.findSimpleById(Long.valueOf(memberIdObj.toString())); | ||
| 233 | |||
| 234 | } else { | ||
| 235 | |||
| 236 | String platformAccount = platformAccountObj.toString(); | ||
| 237 | long l = System.currentTimeMillis(); | ||
| 238 | UserTvSimpleDTO userTvDTO = this.userTvService.findSimpleByPlatformAccount(platformAccount); | ||
| 239 | long l1 = System.currentTimeMillis(); | ||
| 240 | log.info("查询大屏信息,总耗时 ==>> {}", (l1-l)); | ||
| 257 | 241 | ||
| 258 | memberDTO = this.memberService.findById(memberId); | 242 | if (Objects.nonNull(userTvDTO)) { |
| 259 | log.info("获取小屏会员信息 ==>> memberId ==>> {} || 会员信息 ==>> {}",memberId, memberDTO); | ||
| 260 | 243 | ||
| 261 | } else if (StringUtils.isNotBlank(platformAccount)) { | 244 | // 在查找任务之前对用户行为进行预处理 |
| 245 | this.preFindTask(platformAccount, dataSyncMsg, msgData); | ||
| 262 | 246 | ||
| 263 | UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); | ||
| 264 | if (Objects.nonNull(userTvDTO.getId())) { | ||
| 265 | // 开启积分自动同步至小屏主会员 | 247 | // 开启积分自动同步至小屏主会员 |
| 266 | if (validPriorityMember == 0) { | 248 | if (validPriorityMember == 0) { |
| 267 | |||
| 268 | String priorityMemberCode = userTvDTO.getPriorityMemberCode(); | 249 | String priorityMemberCode = userTvDTO.getPriorityMemberCode(); |
| 269 | |||
| 270 | if (StringUtils.isNotBlank(priorityMemberCode)) { | 250 | if (StringUtils.isNotBlank(priorityMemberCode)) { |
| 271 | // TODO 是否需要将code和id都进行缓存 | 251 | // TODO 是否需要将code和id都进行缓存 |
| 272 | memberDTO = this.memberService.findByCode(priorityMemberCode); | 252 | memberDTO = this.memberService.findSimpleByCode(priorityMemberCode); |
| 273 | log.info("查询绑定的小屏的主会员信息, member ==>> {}", memberDTO); | 253 | log.info("查询绑定的小屏的主会员信息, member ==>> {}", memberDTO); |
| 274 | } else if (Objects.nonNull(userTvDTO.getMemberId())) { | 254 | } else if (Objects.nonNull(userTvDTO.getMemberId())) { |
| 275 | memberDTO = this.memberService.findById(userTvDTO.getMemberId()); | 255 | long l4 = System.currentTimeMillis(); |
| 276 | log.info("查询大屏自身的会员信息, member ==>> {}", memberDTO); | 256 | memberDTO = this.memberService.findSimpleById(userTvDTO.getMemberId()); |
| 257 | long l5 = System.currentTimeMillis(); | ||
| 258 | log.info("查询大屏自身的会员信息, memberId ==>> {} , 总耗时 ==>> {}", userTvDTO.getMemberId(), (l5-l4)); | ||
| 277 | } | 259 | } |
| 278 | 260 | ||
| 279 | } else { | 261 | } else { |
| 280 | 262 | ||
| 281 | memberDTO = this.memberService.findById(userTvDTO.getMemberId()); | 263 | long l2 = System.currentTimeMillis(); |
| 282 | 264 | memberDTO = this.memberService.findSimpleById(userTvDTO.getMemberId()); | |
| 265 | long l3 = System.currentTimeMillis(); | ||
| 266 | log.info("查询大屏会员信息,总耗时 ==>> {}", (l3-l2)); | ||
| 283 | } | 267 | } |
| 284 | 268 | ||
| 285 | } else { | 269 | } else { |
| ... | @@ -292,31 +276,30 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -292,31 +276,30 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 292 | } | 276 | } |
| 293 | 277 | ||
| 294 | if (Objects.isNull(memberDTO.getId())) { | 278 | if (Objects.isNull(memberDTO.getId())) { |
| 295 | log.error("会员信息不存在 ==>> {}" + memberDTO); | 279 | log.error("会员信息不存在 ==>> {}", memberDTO); |
| 296 | return ResultInfo.failure("会员信息不存在"); | 280 | return ResultInfo.failure("会员信息不存在"); |
| 297 | } | 281 | } |
| 298 | 282 | ||
| 299 | // 检查黑名单状态 0:正常 1:黑名单 | 283 | // 检查黑名单状态 0:正常 1:黑名单 |
| 300 | Long blackStatus = memberDTO.getBlackStatus(); | 284 | Long blackStatus = memberDTO.getBlackStatus(); |
| 301 | if (Objects.nonNull(blackStatus) && blackStatus.equals(LocalConstants.BLACK_STATUS)) { | 285 | if (Objects.nonNull(blackStatus) && blackStatus.equals(LocalConstants.BLACK_STATUS)) { |
| 302 | log.error("会员已被加入黑名单 ==>> {}" + memberDTO); | 286 | log.error("会员已被加入黑名单 ==>> {}", memberDTO); |
| 303 | return ResultInfo.forbidden("会员已被加入黑名单"); | 287 | return ResultInfo.forbidden("会员已被加入黑名单"); |
| 304 | } | 288 | } |
| 305 | 289 | ||
| 306 | // 检索满足条件的任务 1.先检查redis中是否存在符合条件的任务 2.从redis中获取当前会员未完成的任务 | 290 | // 检索满足条件的任务 1.先检查redis中是否存在符合条件的任务 2.从redis中获取当前会员未完成的任务 |
| 307 | List<Task> tasks = this.findValidTasksAndRefreshTaskProcess(memberDTO, dataSyncMsg.getEvent(), msgData); | 291 | List<Task> tasks = this.findValidTasksAndRefreshTaskProcess(memberDTO, dataSyncMsg.getEvent(), msgData); |
| 308 | log.info("查询出来的任务列表 tasks ==>> [{}] ", tasks); | 292 | log.info("当前用户可执行的任务详情 ==>> {}", tasks); |
| 309 | if (CollectionUtils.isEmpty(tasks)) { | 293 | if (CollectionUtils.isEmpty(tasks)) { |
| 310 | // 类型 1:登录;2:观影;3:参加活动;4:订购;5:优享会员;6:签到;7:完成设置;8:播放记录; | 294 | // 类型 1:登录;2:观影;3:参加活动;4:订购;5:优享会员;6:签到;7:完成设置;8:播放记录; |
| 311 | // 10:跨屏绑定;11:积分转移;30:积分兑换商品;98:系统操作;99:其他 | 295 | // 10:跨屏绑定;11:积分转移;30:积分兑换商品;98:系统操作;99:其他 |
| 312 | log.warn("无可执行的任务, 请检查配置,任务模板类型 eventType ==>> {} || 消息体 ==>> msgData {}", dataSyncMsg.getEvent(), msgData); | ||
| 313 | return ResultInfo.failure("无可执行的任务"); | 296 | return ResultInfo.failure("无可执行的任务"); |
| 314 | } | 297 | } |
| 315 | 298 | ||
| 316 | if (!CollectionUtils.isEmpty(tasks)) { | 299 | if (!CollectionUtils.isEmpty(tasks)) { |
| 317 | // 5.权益区分(积分、权益、成长值) | 300 | // 5.权益区分(积分、权益、成长值) |
| 318 | Map<RightType,Object> tempRightsMap = this.distinguishRight(memberDTO, tasks, msgData, dataSyncMsg); | 301 | Map<RightType,Object> tempRightsMap = this.distinguishRight(memberDTO, tasks, msgData, dataSyncMsg); |
| 319 | log.info("获取当前任务对应的权益 tempRightsMap ==>> {} ", tempRightsMap); | 302 | // log.info("获取当前任务对应的权益 tempRightsMap ==>> {} ", tempRightsMap); |
| 320 | 303 | ||
| 321 | // 6.风控检查 TODO | 304 | // 6.风控检查 TODO |
| 322 | // boolean result = this.checkRiskManagement(memberId, tempRightsMap); | 305 | // boolean result = this.checkRiskManagement(memberId, tempRightsMap); |
| ... | @@ -324,20 +307,69 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -324,20 +307,69 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 324 | 307 | ||
| 325 | // if (result) throw new BadRequestException("发放失败,已达风控上限"); | 308 | // if (result) throw new BadRequestException("发放失败,已达风控上限"); |
| 326 | 309 | ||
| 327 | long l1 = System.currentTimeMillis(); | 310 | // long l1 = System.currentTimeMillis(); |
| 328 | log.info("各项检查总耗时 ==>> {}", (l1-l)); | 311 | // log.info("各项检查总耗时 ==>> {}", (l1-l)); |
| 329 | 312 | ||
| 330 | // 7.权益发放 | 313 | // 7.权益发放 |
| 331 | log.info("下发开始 ==>> {}", tempRightsMap); | 314 | // log.info("下发开始 ==>> {}", tempRightsMap); |
| 332 | long l2 = System.currentTimeMillis(); | 315 | // long l2 = System.currentTimeMillis(); |
| 333 | this.grantRight(tempRightsMap); | 316 | Integer integer = this.grantRight(tempRightsMap); |
| 334 | long l3 = System.currentTimeMillis(); | 317 | // long l3 = System.currentTimeMillis(); |
| 335 | log.info("下发结束,总耗时 ==>> {}", (l3-l2)); | 318 | // log.info("下发结束,总耗时 ==>> {}", (l3-l2)); |
| 319 | |||
| 320 | if (integer > 0) { | ||
| 321 | return ResultInfo.success(integer); | ||
| 322 | } | ||
| 323 | } | ||
| 324 | |||
| 325 | return ResultInfo.failure("任务处理失败"); | ||
| 326 | |||
| 327 | } | ||
| 328 | |||
| 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 | |||
| 336 | } | 337 | } |
| 337 | return ResultInfo.success(); | ||
| 338 | 338 | ||
| 339 | } | 339 | } |
| 340 | 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 | /** | ||
| 366 | * | ||
| 367 | * @param id 主键 | ||
| 368 | * @param memberId 会员id | ||
| 369 | * @param task 任务 | ||
| 370 | * @param currentActionAmount 当前行为量 | ||
| 371 | * @param status 完成状态 | ||
| 372 | */ | ||
| 341 | private void saveOrUpdateTaskProcess(Long id,Long memberId, Task task, Integer currentActionAmount, Integer status) { | 373 | private void saveOrUpdateTaskProcess(Long id,Long memberId, Task task, Integer currentActionAmount, Integer status) { |
| 342 | TrTaskProgress trTaskProgress = new TrTaskProgress(); | 374 | TrTaskProgress trTaskProgress = new TrTaskProgress(); |
| 343 | trTaskProgress.setId(id); | 375 | trTaskProgress.setId(id); |
| ... | @@ -347,10 +379,25 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -347,10 +379,25 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 347 | trTaskProgress.setTaskId(task.getId()); | 379 | trTaskProgress.setTaskId(task.getId()); |
| 348 | trTaskProgress.setMemberId(memberId); | 380 | trTaskProgress.setMemberId(memberId); |
| 349 | trTaskProgress.setTargetActionAmount(task.getActionAmount()); | 381 | trTaskProgress.setTargetActionAmount(task.getActionAmount()); |
| 382 | trTaskProgress.setUpdateTime(TimestampUtil.now()); | ||
| 350 | 383 | ||
| 351 | // 更新任务完成情况 | ||
| 352 | log.info("更新任务完成情况 ==>> {}", trTaskProgress); | 384 | log.info("更新任务完成情况 ==>> {}", trTaskProgress); |
| 353 | this.doRefreshTrTaskProcess(trTaskProgress); | 385 | TrTaskProgress _trTaskProgress = this.trTaskProgressService.create(trTaskProgress, LocalDateTimeUtil.todayStart()); |
| 386 | |||
| 387 | if (status.equals(TASK_FINISH_STATUS) && Objects.nonNull(_trTaskProgress)) { | ||
| 388 | Map<Object, Object> hmget = this.redisUtils.hmget(RedisKeyConstants.cacheTodayFinishTaskCount + "::" + memberId + ":" + LocalDate.now()); | ||
| 389 | if (Objects.isNull(hmget)) { | ||
| 390 | Map<Object, Object> finishTasks = new HashMap<>(); | ||
| 391 | finishTasks.put(task.getId(), 1); | ||
| 392 | // 单天的记录只存储一天 | ||
| 393 | this.redisUtils.hmset(RedisKeyConstants.cacheTodayFinishTaskCount + "::" + memberId + ":" + LocalDate.now(), finishTasks, 24*60*60); | ||
| 394 | } else { | ||
| 395 | this.redisUtils.hincr(RedisKeyConstants.cacheTodayFinishTaskCount+"::"+memberId+":"+LocalDate.now(), task.getId().toString(), 1); | ||
| 396 | } | ||
| 397 | |||
| 398 | this.redisUtils.hincr(RedisKeyConstants.cacheTotalFinishTaskCount+"::"+memberId, task.getId().toString(), 1); | ||
| 399 | } | ||
| 400 | |||
| 354 | } | 401 | } |
| 355 | 402 | ||
| 356 | /** | 403 | /** |
| ... | @@ -360,20 +407,21 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -360,20 +407,21 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 360 | * @param event 任务模板类型 | 407 | * @param event 任务模板类型 |
| 361 | * @return | 408 | * @return |
| 362 | */ | 409 | */ |
| 363 | private List<Task> findValidTasksAndRefreshTaskProcess(MemberDTO memberDTO, Integer event, DataSyncMsg.MsgData msgData) { | 410 | private List<Task> findValidTasksAndRefreshTaskProcess(MemberSimpleDTO memberDTO, Integer event, JSONObject msgData) { |
| 364 | 411 | ||
| 365 | // 任务是否存在 | 412 | // 任务是否存在 |
| 366 | List<Task> tasks = this.taskService.findByEvent(event); | 413 | long l = System.currentTimeMillis(); |
| 414 | List<Task> tasks = this.taskService.findByEventAndMemberLevelAndVip(event, memberDTO.getLevel(), memberDTO.getVip()); | ||
| 415 | long l1 = System.currentTimeMillis(); | ||
| 416 | log.info("查询任务列表,任务详情 ==>> {}, 总耗时 ==>> {}",tasks, (l1-l)); | ||
| 367 | if (Objects.isNull(tasks) || CollectionUtils.isEmpty(tasks)) { | 417 | if (Objects.isNull(tasks) || CollectionUtils.isEmpty(tasks)) { |
| 368 | return Collections.singletonList(null); | 418 | return Collections.singletonList(null); |
| 369 | } | 419 | } |
| 370 | 420 | ||
| 371 | // 用户行为量 | 421 | // 获取当前会员所有任务的完成进度 |
| 372 | String param = msgData.getParam(); | 422 | Map<Object, Object> todayFinishTask = |
| 373 | JSONObject paramJsonObject = null; | 423 | this.trTaskProgressService.countTodayFinishTaskByMemberId(memberDTO.getId(), LocalDateTimeUtil.todayStart()); |
| 374 | if (StringUtils.isNotBlank(param)) { | 424 | Map<Object, Object> finishTaskCount = this.trTaskProgressService.countTotalFinishTaskByMemberId(memberDTO.getId()); |
| 375 | paramJsonObject = JSONObject.parseObject(param, JSONObject.class); | ||
| 376 | } | ||
| 377 | 425 | ||
| 378 | List<Task> tasksResult = new ArrayList<>(); | 426 | List<Task> tasksResult = new ArrayList<>(); |
| 379 | // 检查当前会员针对这些任务的完成情况 | 427 | // 检查当前会员针对这些任务的完成情况 |
| ... | @@ -383,159 +431,215 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -383,159 +431,215 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 383 | if (StringUtils.isNotBlank(task.getGroups()) && !task.getGroups().contains(memberDTO.getGroups())) { | 431 | if (StringUtils.isNotBlank(task.getGroups()) && !task.getGroups().contains(memberDTO.getGroups())) { |
| 384 | log.warn("此用户分组不满足任务要求,任务分组 ==>> {} || 会员分组 ==>> {}",task.getGroups(), memberDTO.getGroups()); | 432 | log.warn("此用户分组不满足任务要求,任务分组 ==>> {} || 会员分组 ==>> {}",task.getGroups(), memberDTO.getGroups()); |
| 385 | continue; | 433 | continue; |
| 386 | } | ||
| 387 | // 校验会员等级 | ||
| 388 | if (Objects.nonNull(task.getMemberLevel()) && task.getMemberLevel() < memberDTO.getLevel()) { | ||
| 389 | log.warn("此用户等级不满足任务要求,任务要求会员等级 ==>> {} || 会员等级 ==>> {}",task.getMemberLevel(), memberDTO.getLevel()); | ||
| 390 | continue; | ||
| 391 | } | ||
| 392 | // 校验会员vip | ||
| 393 | if (Objects.nonNull(task.getMemberVip()) && task.getMemberVip() < memberDTO.getVip()) { | ||
| 394 | log.warn("此用户vip不满足任务要求,任务要求会员vip ==>> {} || 会员vip ==>> {}",task.getMemberVip(), memberDTO.getVip()); | ||
| 395 | continue; | ||
| 396 | }*/ | 434 | }*/ |
| 397 | 435 | ||
| 398 | TrTaskProgressDTO trTaskProgressDTO = | 436 | // 任务每日重置 0:不重置;1:重置 |
| 399 | this.trTaskProgressService.findByMemberIdAndTaskIdAndCompletionTime(memberDTO.getId(), task.getId(), LocalDateTimeUtil.todayStart()); | 437 | Integer taskDailyReset = task.getTaskDailyReset(); |
| 400 | log.info("当前任务完成的情况,trTaskProgressDTO ==>> {}", trTaskProgressDTO); | 438 | // 任务重复类型,-1:不限次;1:单次;>1:多次 |
| 401 | 439 | Integer taskRepeatType = task.getTaskRepeatType(); | |
| 402 | // 任务未完成 | 440 | if (taskDailyReset.equals(0)) { |
| 403 | if (Objects.isNull(trTaskProgressDTO) || !trTaskProgressDTO.getStatus().equals(TASK_FINISH_STATUS)) { | 441 | // 不重置,检查是否做过此任务 |
| 404 | 442 | Object finishCount = finishTaskCount.get(task.getId()); | |
| 405 | // 任务最低行为量 | 443 | if (!taskRepeatType.equals(-1) && Objects.nonNull(finishCount)) { |
| 406 | int actionAmount = task.getActionAmount(); | 444 | if (Long.parseLong(finishCount.toString()) >= taskRepeatType) { |
| 407 | // 任务属性 | 445 | continue; |
| 408 | String attr = task.getAttr(); | 446 | } |
| 409 | 447 | } | |
| 410 | switch (event) { | ||
| 411 | // 开机、登录 | ||
| 412 | case TaskEventType.LOGIN: | ||
| 413 | if (Objects.nonNull(paramJsonObject)) { | ||
| 414 | // 登录天数 | ||
| 415 | int continueLogin = paramJsonObject.getInteger("CONTINUE_LOGIN"); | ||
| 416 | if (continueLogin >= actionAmount) { | ||
| 417 | tasksResult.add(task); | ||
| 418 | |||
| 419 | log.info("保存开机、登录任务进度"); | ||
| 420 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, continueLogin, TASK_FINISH_STATUS); | ||
| 421 | } | ||
| 422 | } | ||
| 423 | break; | ||
| 424 | // 观影 | ||
| 425 | case TaskEventType.VIEW: | ||
| 426 | if (Objects.nonNull(paramJsonObject)) { | ||
| 427 | // 观影总时长 | ||
| 428 | int playDuration_ = paramJsonObject.getInteger("PLAYDURATION"); | ||
| 429 | if (playDuration_ >= actionAmount) { | ||
| 430 | tasksResult.add(task); | ||
| 431 | |||
| 432 | log.info("保存观影任务进度"); | ||
| 433 | |||
| 434 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, playDuration_, TASK_FINISH_STATUS); | ||
| 435 | } | ||
| 436 | } | ||
| 437 | break; | ||
| 438 | // 参加活动 | ||
| 439 | case TaskEventType.ACTIVITY: | ||
| 440 | if (Objects.nonNull(paramJsonObject)) { | ||
| 441 | } | ||
| 442 | break; | ||
| 443 | // 订购 | ||
| 444 | case TaskEventType.ORDER: | ||
| 445 | if (Objects.nonNull(paramJsonObject)) { | ||
| 446 | } | ||
| 447 | break; | ||
| 448 | // 优享会员 | ||
| 449 | case TaskEventType.MEMBER_PRIORITY: | ||
| 450 | if (Objects.nonNull(paramJsonObject)) { | ||
| 451 | } | ||
| 452 | break; | ||
| 453 | // 签到 | ||
| 454 | case TaskEventType.SIGN: | ||
| 455 | if (Objects.nonNull(paramJsonObject)) { | ||
| 456 | // 签到天数 | ||
| 457 | int signDays = paramJsonObject.getInteger("SIGN"); | ||
| 458 | if (signDays >= actionAmount) { | ||
| 459 | tasksResult.add(task); | ||
| 460 | |||
| 461 | log.info("保存签到天数任务进度"); | ||
| 462 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, signDays, TASK_FINISH_STATUS); | ||
| 463 | } | ||
| 464 | } | ||
| 465 | break; | ||
| 466 | // 完成设置 | ||
| 467 | case TaskEventType.COMPLETE_INFO: | ||
| 468 | if (Objects.nonNull(paramJsonObject)) { | ||
| 469 | // 完成设置次数 | ||
| 470 | int completeCount = paramJsonObject.getInteger("COMPLETECOUNT"); | ||
| 471 | if (completeCount >= actionAmount) { | ||
| 472 | tasksResult.add(task); | ||
| 473 | |||
| 474 | log.info("保存完成用户信息设置任务进度"); | ||
| 475 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, completeCount, TASK_FINISH_STATUS); | ||
| 476 | } | ||
| 477 | } | ||
| 478 | break; | ||
| 479 | // 播放时长 | ||
| 480 | case TaskEventType.PLAY: | ||
| 481 | // 用户播放总时长 | ||
| 482 | if (Objects.nonNull(paramJsonObject)) { | ||
| 483 | int playDuration = paramJsonObject.getInteger("PLAYDURATION"); | ||
| 484 | if (playDuration >= actionAmount) { | ||
| 485 | tasksResult.add(task); | ||
| 486 | |||
| 487 | log.info("保存用户播放总时长任务进度"); | ||
| 488 | threadPoolTaskExecutor.execute(() -> { | ||
| 489 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, playDuration, TASK_FINISH_STATUS); | ||
| 490 | }); | ||
| 491 | } | ||
| 492 | } | ||
| 493 | break; | ||
| 494 | // 跨屏绑定 | ||
| 495 | case TaskEventType.BINDING: | ||
| 496 | // 跨屏绑定次数 | ||
| 497 | if (Objects.nonNull(paramJsonObject)) { | ||
| 498 | int bindCount = paramJsonObject.getInteger("BINDCOUNT"); | ||
| 499 | if (bindCount >= actionAmount) { | ||
| 500 | tasksResult.add(task); | ||
| 501 | |||
| 502 | log.info("保存跨屏绑定任务进度"); | ||
| 503 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, bindCount, TASK_FINISH_STATUS); | ||
| 504 | } | ||
| 505 | } | ||
| 506 | break; | ||
| 507 | // 积分转移 | ||
| 508 | case TaskEventType.POINTS_TRANS: | ||
| 509 | |||
| 510 | break; | ||
| 511 | // 积分兑换商品 | ||
| 512 | case TaskEventType.POINTS_EXCHANGE_GOODS: | ||
| 513 | // 完成设置次数 | ||
| 514 | if (Objects.nonNull(paramJsonObject)) { | ||
| 515 | int exchangeCount = paramJsonObject.getInteger("EXCHANGCOUNT"); | ||
| 516 | if (exchangeCount >= actionAmount) { | ||
| 517 | tasksResult.add(task); | ||
| 518 | |||
| 519 | log.info("保存积分兑换商品任务进度"); | ||
| 520 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, exchangeCount, TASK_FINISH_STATUS); | ||
| 521 | } | ||
| 522 | } | ||
| 523 | 448 | ||
| 524 | break; | 449 | } else { |
| 525 | // 系统操作 | 450 | |
| 526 | case TaskEventType.SYSTEM_OPERATE: | 451 | Object todayFinishCount = todayFinishTask.get(task.getId()); |
| 527 | break; | 452 | if (taskRepeatType > 1 && Objects.nonNull(todayFinishCount)) { |
| 528 | default: | 453 | if (Long.parseLong(todayFinishCount.toString()) >= taskRepeatType) { |
| 529 | log.warn("没有找到对应的任务,findValidTasks"); | 454 | continue; |
| 530 | break; | 455 | } |
| 531 | } | 456 | } |
| 457 | |||
| 532 | } | 458 | } |
| 533 | } | ||
| 534 | 459 | ||
| 460 | switch (event) { | ||
| 461 | // 开机、登录 | ||
| 462 | case TaskEventType.LOGIN: | ||
| 463 | if (this.doLoginEvent(msgData, task, memberDTO)) { | ||
| 464 | tasksResult.add(task); | ||
| 465 | } | ||
| 466 | break; | ||
| 467 | // 观影 | ||
| 468 | case TaskEventType.VIEW: | ||
| 469 | if (this.doViewEvent(msgData, task, memberDTO)) { | ||
| 470 | tasksResult.add(task); | ||
| 471 | } | ||
| 472 | break; | ||
| 473 | // 参加活动 | ||
| 474 | case TaskEventType.ACTIVITY: | ||
| 475 | |||
| 476 | break; | ||
| 477 | // 订购 | ||
| 478 | case TaskEventType.ORDER: | ||
| 479 | break; | ||
| 480 | // 优享会员 | ||
| 481 | case TaskEventType.MEMBER_PRIORITY: | ||
| 482 | break; | ||
| 483 | // 签到 | ||
| 484 | case TaskEventType.SIGN: | ||
| 485 | if (this.doSignEvent(msgData, task, memberDTO)) { | ||
| 486 | tasksResult.add(task); | ||
| 487 | } | ||
| 488 | break; | ||
| 489 | // 完成设置 | ||
| 490 | case TaskEventType.COMPLETE_INFO: | ||
| 491 | if (this.doCompleteMemberInfoEvent(msgData, task, memberDTO)) { | ||
| 492 | tasksResult.add(task); | ||
| 493 | } | ||
| 494 | break; | ||
| 495 | // 播放时长 | ||
| 496 | case TaskEventType.PLAY: | ||
| 497 | // 用户播放总时长 | ||
| 498 | if (this.doPlayEvent(msgData, task, memberDTO)) { | ||
| 499 | tasksResult.add(task); | ||
| 500 | } | ||
| 501 | break; | ||
| 502 | // 跨屏绑定 | ||
| 503 | case TaskEventType.BINDING: | ||
| 504 | // 跨屏绑定次数 | ||
| 505 | if (this.doBindingEvent(msgData, task, memberDTO)) { | ||
| 506 | tasksResult.add(task); | ||
| 507 | } | ||
| 508 | break; | ||
| 509 | // 积分转移 | ||
| 510 | case TaskEventType.POINTS_TRANS: | ||
| 511 | if (this.doPointsTransEvent(msgData, task, memberDTO)) { | ||
| 512 | tasksResult.add(task); | ||
| 513 | } | ||
| 514 | break; | ||
| 515 | // 积分兑换商品 | ||
| 516 | case TaskEventType.POINTS_EXCHANGE_GOODS: | ||
| 517 | // 完成设置次数 | ||
| 518 | if (this.doPointsExchangeGoodsEvent(msgData, task, memberDTO)) { | ||
| 519 | tasksResult.add(task); | ||
| 520 | } | ||
| 521 | break; | ||
| 522 | // 其他 | ||
| 523 | case TaskEventType.SYSTEM_OPERATE: | ||
| 524 | break; | ||
| 525 | default: | ||
| 526 | log.info("没有找到对应的任务"); | ||
| 527 | break; | ||
| 528 | } | ||
| 529 | |||
| 530 | } | ||
| 535 | 531 | ||
| 536 | return tasksResult; | 532 | return tasksResult; |
| 537 | } | 533 | } |
| 538 | 534 | ||
| 535 | private boolean doPointsExchangeGoodsEvent(JSONObject msgData, Task task, MemberSimpleDTO memberDTO) { | ||
| 536 | Integer actionAmount = task.getActionAmount(); | ||
| 537 | // 用户行为次数 | ||
| 538 | // TODO 后续需要按照业务对用户行为数据进行修改 | ||
| 539 | int completeCount = 1; | ||
| 540 | if (completeCount >= actionAmount) { | ||
| 541 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, completeCount, TASK_FINISH_STATUS); | ||
| 542 | return true; | ||
| 543 | } | ||
| 544 | return false; | ||
| 545 | } | ||
| 546 | |||
| 547 | private boolean doPointsTransEvent(JSONObject msgData, Task task, MemberSimpleDTO memberDTO) { | ||
| 548 | Integer actionAmount = task.getActionAmount(); | ||
| 549 | // 用户行为次数 | ||
| 550 | // TODO 后续需要按照业务对用户行为数据进行修改 | ||
| 551 | int completeCount = 1; | ||
| 552 | if (completeCount >= actionAmount) { | ||
| 553 | |||
| 554 | log.info("保存完成用户信息设置任务进度"); | ||
| 555 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, completeCount, TASK_FINISH_STATUS); | ||
| 556 | return true; | ||
| 557 | } | ||
| 558 | return false; | ||
| 559 | } | ||
| 560 | |||
| 561 | private boolean doBindingEvent(JSONObject msgData, Task task, MemberSimpleDTO memberDTO) { | ||
| 562 | Integer actionAmount = task.getActionAmount(); | ||
| 563 | // 用户行为次数 | ||
| 564 | // TODO 后续需要按照业务对用户行为数据进行修改 | ||
| 565 | int completeCount = 1; | ||
| 566 | if (completeCount >= actionAmount) { | ||
| 567 | |||
| 568 | log.info("保存完成用户信息设置任务进度"); | ||
| 569 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, completeCount, TASK_FINISH_STATUS); | ||
| 570 | return true; | ||
| 571 | } | ||
| 572 | return false; | ||
| 573 | } | ||
| 574 | |||
| 575 | private boolean doCompleteMemberInfoEvent(JSONObject msgData, Task task, MemberSimpleDTO memberDTO) { | ||
| 576 | Integer actionAmount = task.getActionAmount(); | ||
| 577 | // 用户行为次数 | ||
| 578 | // TODO 后续需要按照业务对用户行为数据进行修改 | ||
| 579 | int completeCount = 1; | ||
| 580 | if (completeCount >= actionAmount) { | ||
| 581 | |||
| 582 | log.info("保存完成用户信息设置任务进度"); | ||
| 583 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, completeCount, TASK_FINISH_STATUS); | ||
| 584 | return true; | ||
| 585 | } | ||
| 586 | return false; | ||
| 587 | } | ||
| 588 | |||
| 589 | private boolean doSignEvent(JSONObject msgData, Task task, MemberSimpleDTO memberDTO) { | ||
| 590 | Integer actionAmount = task.getActionAmount(); | ||
| 591 | // // 用户行为次数 签到天数 | ||
| 592 | int signDays = msgData.getInteger("SIGN"); | ||
| 593 | if (signDays >= actionAmount) { | ||
| 594 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, signDays, TASK_FINISH_STATUS); | ||
| 595 | return true; | ||
| 596 | } | ||
| 597 | |||
| 598 | return false; | ||
| 599 | } | ||
| 600 | |||
| 601 | private boolean doViewEvent(JSONObject msgData, Task task, MemberSimpleDTO memberDTO) { | ||
| 602 | Integer actionAmount = task.getActionAmount(); | ||
| 603 | // 观影总时长 | ||
| 604 | int playDuration_ = msgData.getInteger("playDuration"); | ||
| 605 | if (playDuration_ >= actionAmount) { | ||
| 606 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, playDuration_, TASK_FINISH_STATUS); | ||
| 607 | return true; | ||
| 608 | } | ||
| 609 | return false; | ||
| 610 | } | ||
| 611 | |||
| 612 | private boolean doLoginEvent(JSONObject msgData, Task task, MemberSimpleDTO memberDTO) { | ||
| 613 | Integer actionAmount = task.getActionAmount(); | ||
| 614 | // 登录天数 | ||
| 615 | int continueLogin = msgData.getInteger("CONTINUE_LOGIN"); | ||
| 616 | if (continueLogin >= actionAmount) { | ||
| 617 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, continueLogin, TASK_FINISH_STATUS); | ||
| 618 | return true; | ||
| 619 | } | ||
| 620 | return false; | ||
| 621 | } | ||
| 622 | |||
| 623 | /** | ||
| 624 | * 播放时长 | ||
| 625 | * @param paramJsonObject | ||
| 626 | */ | ||
| 627 | private boolean doPlayEvent(JSONObject paramJsonObject, Task task, MemberSimpleDTO memberSimpleDTO) { | ||
| 628 | Integer actionAmount = task.getActionAmount(); | ||
| 629 | int playDuration = paramJsonObject.getInteger("playDuration"); | ||
| 630 | if (playDuration >= actionAmount) { | ||
| 631 | |||
| 632 | long l4 = System.currentTimeMillis(); | ||
| 633 | this.saveOrUpdateTaskProcess(null, memberSimpleDTO.getId(), task, playDuration, TASK_FINISH_STATUS); | ||
| 634 | long l5 = System.currentTimeMillis(); | ||
| 635 | log.info("保存任务进度信息,总耗时 ==>> {}", (l5-l4)); | ||
| 636 | |||
| 637 | return true; | ||
| 638 | } | ||
| 639 | |||
| 640 | return false; | ||
| 641 | } | ||
| 642 | |||
| 539 | 643 | ||
| 540 | /** | 644 | /** |
| 541 | * 风控检查 | 645 | * 风控检查 |
| ... | @@ -549,26 +653,11 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -549,26 +653,11 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 549 | } | 653 | } |
| 550 | 654 | ||
| 551 | /** | 655 | /** |
| 552 | * 任务完成情况 | ||
| 553 | * @param resources 任务完成情况 | ||
| 554 | */ | ||
| 555 | private void doRefreshTrTaskProcess(TrTaskProgress resources) { | ||
| 556 | String date = LocalDateTimeUtil.todayStart(); | ||
| 557 | Long id = resources.getId(); | ||
| 558 | if (Objects.nonNull(id)) { | ||
| 559 | resources.setUpdateTime(TimestampUtil.now()); | ||
| 560 | this.trTaskProgressService.update(resources, date); | ||
| 561 | } else { | ||
| 562 | this.trTaskProgressService.create(resources, date); | ||
| 563 | } | ||
| 564 | } | ||
| 565 | |||
| 566 | /** | ||
| 567 | * 权益发放 | 656 | * 权益发放 |
| 568 | * @param tempRightsMap 权益 | 657 | * @param tempRightsMap 权益 |
| 569 | */ | 658 | */ |
| 570 | private void grantRight(Map<RightType,Object> tempRightsMap) { | 659 | private Integer grantRight(Map<RightType,Object> tempRightsMap) { |
| 571 | this.rightsOperationService.grantRights(tempRightsMap); | 660 | return this.rightsOperationService.grantRights(tempRightsMap); |
| 572 | } | 661 | } |
| 573 | 662 | ||
| 574 | /** | 663 | /** |
| ... | @@ -577,7 +666,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -577,7 +666,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 577 | * @param taskList 任务列表 | 666 | * @param taskList 任务列表 |
| 578 | * @return Map<RightType,Object> 权益分类 | 667 | * @return Map<RightType,Object> 权益分类 |
| 579 | */ | 668 | */ |
| 580 | private Map<RightType,Object> distinguishRight(MemberDTO memberDTO, List<Task> taskList, DataSyncMsg.MsgData msgData, DataSyncMsg dataSyncMsg) { | 669 | private Map<RightType,Object> distinguishRight(MemberSimpleDTO memberDTO, List<Task> taskList, JSONObject msgData, DataSyncMsg dataSyncMsg) { |
| 581 | 670 | ||
| 582 | Map<RightType,Object> map = new HashMap<>(); | 671 | Map<RightType,Object> map = new HashMap<>(); |
| 583 | 672 | ||
| ... | @@ -592,7 +681,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -592,7 +681,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 592 | map.put(RightType.POINTS, tempPoints); | 681 | map.put(RightType.POINTS, tempPoints); |
| 593 | 682 | ||
| 594 | // 成长值 | 683 | // 成长值 |
| 595 | this.getTempExp(memberDTO,msgData,task, dataSyncMsg, tempExps); | 684 | this.getTempExp(memberDTO, msgData, task, dataSyncMsg, tempExps); |
| 596 | if (!CollectionUtils.isEmpty(tempExps)) | 685 | if (!CollectionUtils.isEmpty(tempExps)) |
| 597 | map.put(RightType.EXP, tempExps); | 686 | map.put(RightType.EXP, tempExps); |
| 598 | 687 | ||
| ... | @@ -652,7 +741,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -652,7 +741,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 652 | * @param map 权益分类 | 741 | * @param map 权益分类 |
| 653 | * @return | 742 | * @return |
| 654 | */ | 743 | */ |
| 655 | private Map<RightType,Object> getTempRight(MemberDTO memberDTO, Task task, Map<RightType,Object> map) { | 744 | private Map<RightType,Object> getTempRight(MemberSimpleDTO memberDTO, Task task, Map<RightType,Object> map) { |
| 656 | 745 | ||
| 657 | // 优惠券 | 746 | // 优惠券 |
| 658 | List<TempCoupon> tempCouponList = new ArrayList<>(); | 747 | List<TempCoupon> tempCouponList = new ArrayList<>(); |
| ... | @@ -701,16 +790,18 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -701,16 +790,18 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 701 | * @param tempCouponList | 790 | * @param tempCouponList |
| 702 | * @param rightsList | 791 | * @param rightsList |
| 703 | */ | 792 | */ |
| 704 | private void getTempRightType(MemberDTO memberDTO , Long rightsId, Integer rightsAmount,Integer rightsSendStrategy,List<TempCoupon> tempCouponList, | 793 | private void getTempRightType(MemberSimpleDTO memberDTO , Long rightsId, Integer rightsAmount,Integer rightsSendStrategy,List<TempCoupon> tempCouponList, |
| 705 | List<TempRights> rightsList,Map<RightType,Object> map) { | 794 | List<TempRights> rightsList,Map<RightType,Object> map) { |
| 706 | 795 | ||
| 707 | Long memberId = memberDTO.getId(); | 796 | Long memberId = memberDTO.getId(); |
| 708 | String nickname = memberDTO.getNickname(); | 797 | String nickname = memberDTO.getNickname(); |
| 709 | String memberCode = memberDTO.getCode(); | 798 | String memberCode = memberDTO.getCode(); |
| 710 | // 权益详情 | 799 | // 权益详情 |
| 800 | long l = System.currentTimeMillis(); | ||
| 711 | RightsDTO rightsDTO = this.rightsService.findById(rightsId); | 801 | RightsDTO rightsDTO = this.rightsService.findById(rightsId); |
| 712 | 802 | long l1 = System.currentTimeMillis(); | |
| 713 | if (Objects.nonNull(rightsDTO)){ | 803 | log.info("查询权益信息,总耗时 ==>> {}", (l1-l)); |
| 804 | if (Objects.nonNull(rightsDTO.getId())){ | ||
| 714 | // 用以保存权益历史 | 805 | // 用以保存权益历史 |
| 715 | TempRights tempRights = this.tmpRightsBuild(memberId,memberCode,rightsAmount,rightsDTO); | 806 | TempRights tempRights = this.tmpRightsBuild(memberId,memberCode,rightsAmount,rightsDTO); |
| 716 | rightsList.add(tempRights); | 807 | rightsList.add(tempRights); |
| ... | @@ -781,23 +872,24 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -781,23 +872,24 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 781 | * @param task | 872 | * @param task |
| 782 | * @return | 873 | * @return |
| 783 | */ | 874 | */ |
| 784 | private void getTempExp(MemberDTO memberDTO, DataSyncMsg.MsgData msgData, Task task, DataSyncMsg dataSyncMsg, List<TempExp> tempExps) { | 875 | private void getTempExp(MemberSimpleDTO memberDTO, JSONObject msgData, Task task, DataSyncMsg dataSyncMsg, List<TempExp> tempExps) { |
| 785 | 876 | ||
| 786 | Long rewardExp = task.getRewardExp(); | 877 | Long rewardExp = task.getRewardExp(); |
| 787 | if (Objects.nonNull(rewardExp) && rewardExp > 0L) { | 878 | if (Objects.nonNull(rewardExp) && rewardExp > 0L) { |
| 788 | 879 | ||
| 789 | TempExp tempExp = new TempExp(); | 880 | TempExp tempExp = new TempExp(); |
| 790 | tempExp.setMemberId(memberDTO.getId()); | 881 | tempExp.setMemberId(memberDTO.getId()); |
| 791 | tempExp.setAppCode(msgData.getAppCode()); | 882 | tempExp.setAppCode(msgData.getString("appCode")); |
| 792 | tempExp.setMemberCode(memberDTO.getCode()); | 883 | tempExp.setMemberCode(memberDTO.getCode()); |
| 793 | tempExp.setItemId(msgData.getItemId()); | 884 | tempExp.setMemberLevel(memberDTO.getLevel()); |
| 794 | tempExp.setAccountId(msgData.getAccountId()); | 885 | tempExp.setItemId(msgData.getLong("itemId")); |
| 886 | tempExp.setAccountId(msgData.getLong("accountId")); | ||
| 795 | tempExp.setRewardExp(task.getRewardExp()); | 887 | tempExp.setRewardExp(task.getRewardExp()); |
| 796 | tempExp.setDeviceType(dataSyncMsg.getDeviceType()); | 888 | tempExp.setDeviceType(dataSyncMsg.getDeviceType()); |
| 797 | tempExp.setEvtType(dataSyncMsg.getEvent()); | 889 | tempExp.setEvtType(dataSyncMsg.getEvent()); |
| 798 | tempExp.setOrderId(msgData.getOrderId()); | 890 | tempExp.setOrderId(msgData.getLong("orderId")); |
| 799 | tempExp.setMediaId(msgData.getMediaId()); | 891 | tempExp.setMediaId(msgData.getLong("mediaId")); |
| 800 | tempExp.setActivityId(msgData.getOrderId()); | 892 | tempExp.setActivityId(msgData.getLong("activityId")); |
| 801 | Integer rightsSendStrategy = task.getRightsSendStrategy(); | 893 | Integer rightsSendStrategy = task.getRightsSendStrategy(); |
| 802 | tempExp.setRightsSendStrategy(Objects.isNull(rightsSendStrategy) ? 0 : rightsSendStrategy); | 894 | tempExp.setRightsSendStrategy(Objects.isNull(rightsSendStrategy) ? 0 : rightsSendStrategy); |
| 803 | tempExps.add(tempExp); | 895 | tempExps.add(tempExp); |
| ... | @@ -809,7 +901,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -809,7 +901,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 809 | * @param task | 901 | * @param task |
| 810 | * @return | 902 | * @return |
| 811 | */ | 903 | */ |
| 812 | private void getTempPoints(MemberDTO memberDTO, DataSyncMsg.MsgData msgData, Task task, | 904 | private void getTempPoints(MemberSimpleDTO memberDTO, JSONObject msgData, Task task, |
| 813 | DataSyncMsg dataSyncMsg, List<TempPoints> tempPoints) { | 905 | DataSyncMsg dataSyncMsg, List<TempPoints> tempPoints) { |
| 814 | // 积分: 数值、过期时间、积分类型(定值、随机)、随机积分最大值 | 906 | // 积分: 数值、过期时间、积分类型(定值、随机)、随机积分最大值 |
| 815 | Long rewardPoints = task.getRewardPoints(); | 907 | Long rewardPoints = task.getRewardPoints(); |
| ... | @@ -829,16 +921,16 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -829,16 +921,16 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 829 | tempPoint.setRewardPointsExpireTime(rewardPointsExpireTime); | 921 | tempPoint.setRewardPointsExpireTime(rewardPointsExpireTime); |
| 830 | tempPoint.setMemberId(memberDTO.getId()); | 922 | tempPoint.setMemberId(memberDTO.getId()); |
| 831 | tempPoint.setMemberCode(memberDTO.getCode()); | 923 | tempPoint.setMemberCode(memberDTO.getCode()); |
| 832 | tempPoint.setAppCode(msgData.getAppCode()); | 924 | tempPoint.setAppCode(msgData.getString("appCode")); |
| 833 | tempPoint.setPoints(rewardPoints); | 925 | tempPoint.setPoints(rewardPoints); |
| 834 | tempPoint.setPointsType(pointsType); | 926 | tempPoint.setPointsType(pointsType); |
| 835 | tempPoint.setDeviceType(dataSyncMsg.getDeviceType()); | 927 | tempPoint.setDeviceType(dataSyncMsg.getDeviceType()); |
| 836 | tempPoint.setExpireTime(expireTime); | 928 | tempPoint.setExpireTime(expireTime); |
| 837 | tempPoint.setOrderId(msgData.getOrderId()); | 929 | tempPoint.setOrderId(msgData.getLong("orderId")); |
| 838 | tempPoint.setActivityId(msgData.getActivityId()); | 930 | tempPoint.setActivityId(msgData.getLong("activityId")); |
| 839 | tempPoint.setMediaId(msgData.getMediaId()); | 931 | tempPoint.setMediaId(msgData.getLong("mediaId")); |
| 840 | tempPoint.setItemId(msgData.getItemId()); | 932 | tempPoint.setItemId(msgData.getLong("itemId")); |
| 841 | tempPoint.setAccountId(msgData.getAccountId()); | 933 | tempPoint.setAccountId(msgData.getLong("accountId")); |
| 842 | tempPoint.setEvtType(dataSyncMsg.getEvent()); | 934 | tempPoint.setEvtType(dataSyncMsg.getEvent()); |
| 843 | Integer rightsSendStrategy = task.getRightsSendStrategy(); | 935 | Integer rightsSendStrategy = task.getRightsSendStrategy(); |
| 844 | tempPoint.setRightsSendStrategy(Objects.isNull(rightsSendStrategy) ? 0 : rightsSendStrategy); | 936 | tempPoint.setRightsSendStrategy(Objects.isNull(rightsSendStrategy) ? 0 : rightsSendStrategy); |
| ... | @@ -848,542 +940,14 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -848,542 +940,14 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 848 | 940 | ||
| 849 | } | 941 | } |
| 850 | 942 | ||
| 851 | /** | 943 | @AsyncMqSend |
| 852 | * 判断任务是否完成 | 944 | public void asyncCreateTask(Task task) {} |
| 853 | * 完成的条件如下:-> | 945 | @AsyncMqSend |
| 854 | * 1. status 当前任务的状态 0:失效;1:生效 | 946 | public void asyncUpdateTask(Task task) {} |
| 855 | * 2. valid_time 任务生效时间 | 947 | @AsyncMqSend |
| 856 | * 3. expire_time 任务失效时间 | 948 | public void asyncDeleteTask(Task task) {} |
| 857 | * 1. task_repeat_type 任务重复类型,-1:不限次;1:单次;>1:多次 | ||
| 858 | * 5. member_level 会员等级门槛(0表示无门槛) | ||
| 859 | * 6. member_vip 会员vip门槛(0表示没有门槛) | ||
| 860 | * 7. groups 能够获取该任务的用户分组,为空则都能获取 , 0 | ||
| 861 | * 8. action_amount 行为量(完成此任务需要多少次相同行为的触发) | ||
| 862 | * | ||
| 863 | * @param taskList 任务列表 | ||
| 864 | * @return boolean true:success false:fail | ||
| 865 | */ | ||
| 866 | //<taskId,boolean> | ||
| 867 | private boolean checkTaskCompletion(Long memberId , List<Task> taskList, Integer event, DataSyncMsg.MsgData msgData) { | ||
| 868 | if (!CollectionUtils.isEmpty(taskList)) { | ||
| 869 | // 会员信息 | ||
| 870 | MemberDTO memberDTO = this.memberService.findById(memberId); | ||
| 871 | |||
| 872 | // 判断是否完成任务 | ||
| 873 | CompareTaskCondition compareTaskCondition =(MemberDTO memberDTO1,List<Task> taskList1) -> { | ||
| 874 | |||
| 875 | List<Task> taskStream = taskList1.stream().filter(task1 -> | ||
| 876 | task1.getStatus() == 1 && | ||
| 877 | (Objects.isNull(task1.getExpireTime()) || task1.getExpireTime().compareTo(TimestampUtil.now()) >= 0) && | ||
| 878 | (Objects.isNull(task1.getValidTime()) || task1.getValidTime().compareTo(TimestampUtil.now()) <= 0) && | ||
| 879 | (Objects.isNull(task1.getMemberLevel()) || task1.getMemberLevel() <= memberDTO1.getLevel()) && | ||
| 880 | (Objects.isNull(task1.getMemberVip()) || task1.getMemberVip() <= memberDTO1.getVip()) | ||
| 881 | ).collect(toList()); | ||
| 882 | |||
| 883 | // 没有满足条件的数据 | ||
| 884 | if (!CollectionUtils.isEmpty(taskStream)) { | ||
| 885 | |||
| 886 | // 验证会员分组 | ||
| 887 | boolean result1 = this.validatedMemberGroup(memberId,taskList); | ||
| 888 | log.info("验证会员分组结果,==>> {}, true:验证通过", result1); | ||
| 889 | if (!result1) | ||
| 890 | return false; | ||
| 891 | |||
| 892 | // 获取当前任务的完成情况 | ||
| 893 | boolean result = this.checkAndRefreshTaskCompletion(memberId,taskList,event,msgData); | ||
| 894 | |||
| 895 | return result; | ||
| 896 | |||
| 897 | } else { | ||
| 898 | |||
| 899 | return false; | ||
| 900 | |||
| 901 | } | ||
| 902 | |||
| 903 | }; | ||
| 904 | |||
| 905 | return compareTaskCondition.compareCondition(memberDTO,taskList); | ||
| 906 | } | ||
| 907 | |||
| 908 | return false; | ||
| 909 | } | ||
| 910 | |||
| 911 | /** | ||
| 912 | * 验证会员分组 | ||
| 913 | * @param memberId | ||
| 914 | * @param taskList | ||
| 915 | * @return | ||
| 916 | */ | ||
| 917 | private boolean validatedMemberGroup(Long memberId,List<Task> taskList) { | ||
| 918 | List<MemberGroupDTO> groupDTO = this.findGroupByMemberId(memberId); | ||
| 919 | |||
| 920 | if (!CollectionUtils.isEmpty(groupDTO)) { | ||
| 921 | |||
| 922 | // 会员分组 | ||
| 923 | List<String> list = new ArrayList<>(); | ||
| 924 | for (MemberGroupDTO memberGroupDTO : groupDTO) { | ||
| 925 | String groupId = memberGroupDTO.getGroupId().toString(); | ||
| 926 | list.add(groupId); | ||
| 927 | } | ||
| 928 | |||
| 929 | // 任务分组 | ||
| 930 | List<String> strings = new ArrayList<>(); | ||
| 931 | for (Task task : taskList) { | ||
| 932 | String groups = task.getGroups(); | ||
| 933 | List<String> strings1 = UcStringUtils.parse2StrList(groups); | ||
| 934 | if (StringUtils.isEmpty(groups)) { | ||
| 935 | return true; | ||
| 936 | } | ||
| 937 | strings.addAll(strings1); | ||
| 938 | break; | ||
| 939 | } | ||
| 940 | |||
| 941 | // 如果任务分组为null或者空字符,则放过所有的会员 | ||
| 942 | if (CollectionUtils.isEmpty(strings)) { | ||
| 943 | return true; | ||
| 944 | } | ||
| 945 | |||
| 946 | // 如果任务分组为0,则放过所有的分组 | ||
| 947 | if (!CollectionUtils.isEmpty(strings) && (!CollectionUtils.isEmpty(list) && strings.contains("0")) ) { | ||
| 948 | return true; | ||
| 949 | } | ||
| 950 | |||
| 951 | if (!CollectionUtils.isEmpty(list)) { | ||
| 952 | // 只要会员分组满足任务分组之一就满足要求 | ||
| 953 | if (list.size() > strings.size()) { | ||
| 954 | for (String s : list) { | ||
| 955 | boolean contains = strings.contains(s); | ||
| 956 | if (contains) { | ||
| 957 | return true; | ||
| 958 | } | ||
| 959 | } | ||
| 960 | } | ||
| 961 | } | ||
| 962 | |||
| 963 | if (!CollectionUtils.isEmpty(strings)) { | ||
| 964 | for (String s : strings) { | ||
| 965 | boolean contains = list.contains(s); | ||
| 966 | if (contains) { | ||
| 967 | return true; | ||
| 968 | } | ||
| 969 | } | ||
| 970 | } | ||
| 971 | |||
| 972 | } else { | ||
| 973 | return true; | ||
| 974 | } | ||
| 975 | return false; | ||
| 976 | } | ||
| 977 | |||
| 978 | |||
| 979 | /** | ||
| 980 | * | ||
| 981 | * @param memberId | ||
| 982 | * @return | ||
| 983 | */ | ||
| 984 | private List<MemberGroupDTO> findGroupByMemberId(Long memberId) { | ||
| 985 | return this.memberGroupService.findByMemberId(memberId); | ||
| 986 | } | ||
| 987 | |||
| 988 | /** | ||
| 989 | * 通过会员id获取分组 | ||
| 990 | * @param memberId | ||
| 991 | * @return | ||
| 992 | */ | ||
| 993 | /*private List<GroupDTO> findGroupByMemberId(Long memberId) { | ||
| 994 | GroupQueryCriteria groupQueryCriteria = new GroupQueryCriteria(); | ||
| 995 | groupQueryCriteria.setUserId(memberId); | ||
| 996 | List<GroupDTO> groupDTO = this.groupService.queryAll(groupQueryCriteria); | ||
| 997 | return groupDTO; | ||
| 998 | }*/ | ||
| 999 | |||
| 1000 | /** | ||
| 1001 | * 检查并更新当前任务的完成情况 | ||
| 1002 | * | ||
| 1003 | * 1.每天都能做,但要求总次数达到行为量 | ||
| 1004 | * | ||
| 1005 | * @param memberId | ||
| 1006 | * @param taskStream | ||
| 1007 | * @return boolean false:失败 true:成功 | ||
| 1008 | */ | ||
| 1009 | private boolean checkAndRefreshTaskCompletion(Long memberId , List<Task> taskStream, Integer event, DataSyncMsg.MsgData msgData) { | ||
| 1010 | String time1 = LocalDateTimeUtil.todayStart(); | ||
| 1011 | for (Task task : taskStream) { | ||
| 1012 | |||
| 1013 | Long taskId = task.getId(); | ||
| 1014 | // 任务完成记录 | ||
| 1015 | List<TrTaskProgressDTO> trTaskProgressDTOS = | ||
| 1016 | null;//this.trTaskProgressService.findByMemberIdAndTaskIdAndCompletionTime(memberId,taskId,time1); | ||
| 1017 | |||
| 1018 | Long id = null; | ||
| 1019 | Integer currentActionAmount = null; | ||
| 1020 | Timestamp completionTime = null; | ||
| 1021 | Integer status = 0; | ||
| 1022 | |||
| 1023 | // 行为量(完成此任务需要多少次相同行为的触发) | ||
| 1024 | Integer actionAmount = task.getActionAmount(); | ||
| 1025 | |||
| 1026 | switch (event) { | ||
| 1027 | // 播放记录 | ||
| 1028 | case 8: | ||
| 1029 | if (!CollectionUtils.isEmpty(trTaskProgressDTOS)) { | ||
| 1030 | TrTaskProgressDTO trTaskProgressDTO_0 = trTaskProgressDTOS.get(0); | ||
| 1031 | id = trTaskProgressDTO_0.getId(); | ||
| 1032 | Integer status_0 = trTaskProgressDTO_0.getStatus(); | ||
| 1033 | Integer currentActionAmount_0 = trTaskProgressDTO_0.getCurrentActionAmount(); | ||
| 1034 | Timestamp completionTime_0 = trTaskProgressDTO_0.getCompletionTime(); | ||
| 1035 | log.info("当前任务完成情况,trTaskProgressDTO_0 ==>> {}", trTaskProgressDTO_0); | ||
| 1036 | if (status_0 == 1 && currentActionAmount_0 != null && Objects.nonNull(completionTime_0)) { | ||
| 1037 | log.info("任务已完成,返回false"); | ||
| 1038 | return false; | ||
| 1039 | } | ||
| 1040 | } | ||
| 1041 | String param = msgData.getParam(); | ||
| 1042 | JSONObject jsonObject = JSON.parseObject(param); | ||
| 1043 | Integer value = Integer.valueOf(jsonObject.get("playDuration").toString()); | ||
| 1044 | if (value >= actionAmount) { | ||
| 1045 | currentActionAmount = value; | ||
| 1046 | completionTime = TimestampUtil.now(); | ||
| 1047 | status = TASK_FINISH_STATUS; | ||
| 1048 | } | ||
| 1049 | |||
| 1050 | break; | ||
| 1051 | |||
| 1052 | default: | ||
| 1053 | // 行为量 1 | ||
| 1054 | if (actionAmount == 1) { | ||
| 1055 | |||
| 1056 | if (CollectionUtils.isEmpty(trTaskProgressDTOS)) { | ||
| 1057 | currentActionAmount = 1; | ||
| 1058 | completionTime = TimestampUtil.now(); | ||
| 1059 | status = TASK_FINISH_STATUS; | ||
| 1060 | } | ||
| 1061 | |||
| 1062 | if (!CollectionUtils.isEmpty(trTaskProgressDTOS)) { | ||
| 1063 | // 此任务做过,但未完成 | ||
| 1064 | TrTaskProgressDTO trTaskProgressDTO = trTaskProgressDTOS.get(0); | ||
| 1065 | Long id_ = trTaskProgressDTO.getId(); | ||
| 1066 | Integer status_ = trTaskProgressDTO.getStatus(); | ||
| 1067 | Integer currentActionAmount_ = trTaskProgressDTO.getCurrentActionAmount(); | ||
| 1068 | Timestamp completionTime1 = trTaskProgressDTO.getCompletionTime(); | ||
| 1069 | |||
| 1070 | // 任务已做,不成功 | ||
| 1071 | if (Objects.nonNull(status_) && status_ == 1 && | ||
| 1072 | Objects.nonNull(currentActionAmount_) && currentActionAmount_ == 1 && | ||
| 1073 | Objects.nonNull(completionTime1) && | ||
| 1074 | completionTime1.toLocalDateTime().toLocalDate().compareTo(LocalDate.now()) == 0) { | ||
| 1075 | |||
| 1076 | // 任务重复类型 | ||
| 1077 | Integer taskDailyReset = task.getTaskDailyReset(); | ||
| 1078 | if (taskDailyReset == -1) { | ||
| 1079 | return true; | ||
| 1080 | } else if (currentActionAmount_ < taskDailyReset){ | ||
| 1081 | return true; | ||
| 1082 | } | ||
| 1083 | |||
| 1084 | |||
| 1085 | return false; | ||
| 1086 | |||
| 1087 | // 未做,成功 | ||
| 1088 | } else { | ||
| 1089 | id = id_; | ||
| 1090 | currentActionAmount = 1; | ||
| 1091 | completionTime = TimestampUtil.now(); | ||
| 1092 | status = TASK_FINISH_STATUS; | ||
| 1093 | } | ||
| 1094 | |||
| 1095 | } | ||
| 1096 | } | ||
| 1097 | |||
| 1098 | // 行为量非1 | ||
| 1099 | if (actionAmount != 1) { | ||
| 1100 | |||
| 1101 | if (!CollectionUtils.isEmpty(trTaskProgressDTOS)) { | ||
| 1102 | // 此任务做过,但未完成 | ||
| 1103 | TrTaskProgressDTO trTaskProgressDTO = trTaskProgressDTOS.get(0); | ||
| 1104 | |||
| 1105 | Long id_ = trTaskProgressDTO.getId(); | ||
| 1106 | // 状态 0:未完成;1:已完成 | ||
| 1107 | Integer status_ = trTaskProgressDTO.getStatus(); | ||
| 1108 | Timestamp completionTime_ = trTaskProgressDTO.getCompletionTime(); | ||
| 1109 | Integer currentActionAmount_ = trTaskProgressDTO.getCurrentActionAmount(); | ||
| 1110 | // 行为量达到,完成 | ||
| 1111 | if (status_ != 1 && Objects.isNull(completionTime_) && actionAmount == currentActionAmount_+1) { | ||
| 1112 | id = id_; | ||
| 1113 | currentActionAmount = actionAmount; | ||
| 1114 | completionTime = TimestampUtil.now(); | ||
| 1115 | status = TASK_FINISH_STATUS; | ||
| 1116 | } else { | ||
| 1117 | // 行为量未达到,未完成 | ||
| 1118 | id = id_; | ||
| 1119 | currentActionAmount = currentActionAmount_+1; | ||
| 1120 | } | ||
| 1121 | |||
| 1122 | } | ||
| 1123 | |||
| 1124 | // 未达到行为量,未完成 | ||
| 1125 | if (CollectionUtils.isEmpty(trTaskProgressDTOS)) { | ||
| 1126 | currentActionAmount = 1; | ||
| 1127 | status = TASK_UNFINISH_STATUS; | ||
| 1128 | } | ||
| 1129 | |||
| 1130 | } | ||
| 1131 | |||
| 1132 | break; | ||
| 1133 | |||
| 1134 | } | ||
| 1135 | |||
| 1136 | |||
| 1137 | |||
| 1138 | TrTaskProgress trTaskProgress = new TrTaskProgress(); | ||
| 1139 | trTaskProgress.setId(id); | ||
| 1140 | trTaskProgress.setCurrentActionAmount(currentActionAmount); | ||
| 1141 | trTaskProgress.setCompletionTime(completionTime); | ||
| 1142 | trTaskProgress.setStatus(status); | ||
| 1143 | trTaskProgress.setTaskId(taskId); | ||
| 1144 | trTaskProgress.setMemberId(memberId); | ||
| 1145 | trTaskProgress.setTargetActionAmount(actionAmount); | ||
| 1146 | |||
| 1147 | // 更新任务完成情况 | ||
| 1148 | log.info("更新任务完成情况 ==>> {}", trTaskProgress); | ||
| 1149 | this.doRefreshTrTaskProcess(trTaskProgress); | ||
| 1150 | if (status == TASK_FINISH_STATUS) { | ||
| 1151 | log.info("任务已完成, trTaskProgress ==>> {}", trTaskProgress); | ||
| 1152 | return true; | ||
| 1153 | } | ||
| 1154 | |||
| 1155 | return false; | ||
| 1156 | } | ||
| 1157 | |||
| 1158 | return false; | ||
| 1159 | } | ||
| 1160 | |||
| 1161 | /** | ||
| 1162 | * 获取任务模板对应的任务列表 | ||
| 1163 | * | ||
| 1164 | * @param taskTemplate 任务模板 | ||
| 1165 | * @return List<task> 任务列表 | ||
| 1166 | */ | ||
| 1167 | @Deprecated | ||
| 1168 | private List<Task> loadListTaskByTaskTemplate(TaskTemplate taskTemplate, DataSyncMsg dataSyncMsg) { | ||
| 1169 | |||
| 1170 | if (Objects.nonNull(taskTemplate)) { | ||
| 1171 | |||
| 1172 | Long taskTemplateId = taskTemplate.getId(); | ||
| 1173 | |||
| 1174 | List<Task> taskList = this.taskService.findByTemplateId(taskTemplateId); | ||
| 1175 | |||
| 1176 | Integer type = taskTemplate.getType(); | ||
| 1177 | taskList = this.pickUpTask(taskList, dataSyncMsg, type); | ||
| 1178 | |||
| 1179 | return taskList; | ||
| 1180 | |||
| 1181 | } | ||
| 1182 | |||
| 1183 | return null; | ||
| 1184 | } | ||
| 1185 | |||
| 1186 | /** | ||
| 1187 | * 通过参数确定具体任务 | ||
| 1188 | * @param taskList | ||
| 1189 | * @param dataSyncMsg | ||
| 1190 | * @return | ||
| 1191 | */ | ||
| 1192 | private List<Task> pickUpTask(List<Task> taskList,DataSyncMsg dataSyncMsg,Integer type) { | ||
| 1193 | |||
| 1194 | List<Task> taskList1 = new ArrayList<>(); | ||
| 1195 | String msgData1 = null;//dataSyncMsg.getMsgData(); | ||
| 1196 | DataSyncMsg.MsgData msgData = JSON.parseObject(msgData1, DataSyncMsg.MsgData.class); | ||
| 1197 | |||
| 1198 | if (Objects.nonNull(msgData.getParam())) { | ||
| 1199 | |||
| 1200 | String param = msgData.getParam(); | ||
| 1201 | Map<String,String> jsonObjectMap = JSONObject.parseObject(param, Map.class); | ||
| 1202 | Collection<String> values = jsonObjectMap.values(); | ||
| 1203 | |||
| 1204 | for (Task task : taskList) { | ||
| 1205 | |||
| 1206 | Long taskId = task.getId(); | ||
| 1207 | TaskAttrDTO taskAttrDTO = this.findTaskAttrByTaskId(taskId); | ||
| 1208 | if (Objects.isNull(taskAttrDTO.getId())) | ||
| 1209 | continue; | ||
| 1210 | |||
| 1211 | String attrStr = taskAttrDTO.getAttrStr(); | ||
| 1212 | if (StringUtils.isNotBlank(attrStr)) { | ||
| 1213 | JSONObject jsonObject = JSONObject.parseObject(attrStr); | ||
| 1214 | JSONArray values_0 = jsonObject.getJSONArray("value"); | ||
| 1215 | |||
| 1216 | switch (type) { | ||
| 1217 | // 登录 | ||
| 1218 | case TaskTemplateType.TYPE_1: | ||
| 1219 | |||
| 1220 | Integer o1 = (Integer)values_0.get(0); | ||
| 1221 | Integer o2 = (Integer)values_0.get(1); | ||
| 1222 | List<Integer> list = Arrays.asList(o1, o2); | ||
| 1223 | String s = values.toArray()[0].toString(); | ||
| 1224 | Integer i = Integer.valueOf(s); | ||
| 1225 | boolean b = UcListUtils.compareIntegerList(i, list); | ||
| 1226 | if (b) | ||
| 1227 | taskList1.add(task); | ||
| 1228 | break; | ||
| 1229 | |||
| 1230 | // 观影 | ||
| 1231 | case TaskTemplateType.TYPE_2: | ||
| 1232 | Integer view0 = (Integer)values_0.get(0); | ||
| 1233 | Integer view1 = (Integer)values_0.get(1); | ||
| 1234 | List<Integer> view0List = Arrays.asList(view0, view1); | ||
| 1235 | String view_0 = values.toArray()[0].toString(); | ||
| 1236 | Integer view0_ = Integer.valueOf(view_0); | ||
| 1237 | boolean view = UcListUtils.compareIntegerList(view0_, view0List); | ||
| 1238 | if (view) | ||
| 1239 | taskList1.add(task); | ||
| 1240 | break; | ||
| 1241 | |||
| 1242 | // 参加活动 | ||
| 1243 | case TaskTemplateType.TYPE_3: | ||
| 1244 | /*String activityCode = values_0.get(0).toString(); | ||
| 1245 | String activityCode_ = values.toArray()[0].toString(); | ||
| 1246 | if (activityCode_.equalsIgnoreCase(activityCode)) { | ||
| 1247 | taskList1.add(task); | ||
| 1248 | }*/ | ||
| 1249 | if (values_0.containsAll(values)) | ||
| 1250 | taskList1.add(task); | ||
| 1251 | break; | ||
| 1252 | |||
| 1253 | // 订购 | ||
| 1254 | case TaskTemplateType.TYPE_4: | ||
| 1255 | if (values_0.containsAll(values)) | ||
| 1256 | taskList1.add(task); | ||
| 1257 | break; | ||
| 1258 | |||
| 1259 | // 签到 | ||
| 1260 | case TaskTemplateType.TYPE_6: | ||
| 1261 | Integer sign0 = (Integer)values_0.get(0); | ||
| 1262 | Integer sign1 = (Integer)values_0.get(1); | ||
| 1263 | List<Integer> signi0List = Arrays.asList(sign0, sign1); | ||
| 1264 | String signs0 = values.toArray()[0].toString(); | ||
| 1265 | Integer signi0 = Integer.valueOf(signs0); | ||
| 1266 | boolean signb0 = UcListUtils.compareIntegerList(signi0, signi0List); | ||
| 1267 | if (signb0) | ||
| 1268 | taskList1.add(task); | ||
| 1269 | break; | ||
| 1270 | |||
| 1271 | // 播放记录 | ||
| 1272 | case TaskTemplateType.TYPE_8: | ||
| 1273 | Integer play0 = (Integer)values_0.get(0); | ||
| 1274 | Integer play1 = (Integer)values_0.get(1); | ||
| 1275 | List<Integer> playList = Arrays.asList(play0, play1); | ||
| 1276 | String s0 = values.toArray()[0].toString(); | ||
| 1277 | Integer i0 = Integer.valueOf(s0); | ||
| 1278 | boolean b0 = UcListUtils.compareIntegerList(i0, playList); | ||
| 1279 | if (b0) | ||
| 1280 | taskList1.add(task); | ||
| 1281 | break; | ||
| 1282 | |||
| 1283 | default: | ||
| 1284 | break; | ||
| 1285 | } | ||
| 1286 | |||
| 1287 | |||
| 1288 | } | ||
| 1289 | |||
| 1290 | } | ||
| 1291 | |||
| 1292 | } else { | ||
| 1293 | return taskList; | ||
| 1294 | } | ||
| 1295 | |||
| 1296 | return taskList1; | ||
| 1297 | |||
| 1298 | } | ||
| 1299 | |||
| 1300 | private TaskAttrDTO findTaskAttrByTaskId(Long taskId) { | ||
| 1301 | return this.taskAttrService.findByTaskId(taskId); | ||
| 1302 | } | ||
| 1303 | |||
| 1304 | |||
| 1305 | /** | ||
| 1306 | * 获取任务模板对应的任务列表 | ||
| 1307 | * | ||
| 1308 | * @param taskTemplate 任务模板 | ||
| 1309 | * @return List<task> 任务列表 | ||
| 1310 | */ | ||
| 1311 | private List<Task> loadListTaskByTaskTemplate(TaskTemplate taskTemplate) { | ||
| 1312 | |||
| 1313 | if (Objects.nonNull(taskTemplate)) { | ||
| 1314 | Long taskTemplateId = taskTemplate.getId(); | ||
| 1315 | return this.taskService.findByTemplateId(taskTemplateId); | ||
| 1316 | } | ||
| 1317 | |||
| 1318 | return null; | ||
| 1319 | } | ||
| 1320 | |||
| 1321 | /** | ||
| 1322 | * 获取任务模板 | ||
| 1323 | * @param event 任务 | ||
| 1324 | * @return TaskTemplate 任务模板 | ||
| 1325 | */ | ||
| 1326 | private TaskTemplate getTaskTemplate(Integer event, DataSyncMsg dataSyncMsg) { | ||
| 1327 | String msgData1 = null;//dataSyncMsg.getMsgData(); | ||
| 1328 | DataSyncMsg.MsgData msg = JSON.parseObject(msgData1, DataSyncMsg.MsgData.class); | ||
| 1329 | |||
| 1330 | if (Objects.nonNull(msg.getParam())) { | ||
| 1331 | |||
| 1332 | return this.findByTypeAndParam(event,msg); | ||
| 1333 | |||
| 1334 | } else { | ||
| 1335 | |||
| 1336 | TaskTemplateDTO taskTemplateDTO = this.taskTemplateService.findByType(event); | ||
| 1337 | |||
| 1338 | if (Objects.nonNull(taskTemplateDTO)) { | ||
| 1339 | |||
| 1340 | TaskTemplate taskTemplate = new TaskTemplate(); | ||
| 1341 | BeanUtils.copyProperties(taskTemplateDTO, taskTemplate); | ||
| 1342 | return taskTemplate; | ||
| 1343 | |||
| 1344 | } else { | ||
| 1345 | |||
| 1346 | return null; | ||
| 1347 | |||
| 1348 | } | ||
| 1349 | |||
| 1350 | } | ||
| 1351 | } | ||
| 1352 | |||
| 1353 | private TaskTemplate findByTypeAndParam(Integer event, DataSyncMsg.MsgData taskTemplateParam) { | ||
| 1354 | String param = taskTemplateParam.getParam(); | ||
| 1355 | if (StringUtils.isNotBlank(param)) { | ||
| 1356 | |||
| 1357 | Map<String,String> jsonObject = JSONObject.parseObject(param,Map.class); | ||
| 1358 | |||
| 1359 | TaskTemplateDTO taskTemplateDTO = this.taskTemplateService.findByType(event); | ||
| 1360 | if (Objects.nonNull(taskTemplateDTO)) { | ||
| 1361 | |||
| 1362 | String templateParams = taskTemplateDTO.getParams(); | ||
| 1363 | if(StringUtils.isNotBlank(templateParams)) { | ||
| 1364 | String templateParamsUpperCase = templateParams.toUpperCase(); | ||
| 1365 | Set<String> keySet = jsonObject.keySet(); | ||
| 1366 | for (String key : keySet) { | ||
| 1367 | String s = key.toUpperCase(); | ||
| 1368 | if (s.equals(templateParamsUpperCase)) { | ||
| 1369 | TaskTemplate taskTemplate = new TaskTemplate(); | ||
| 1370 | BeanUtils.copyProperties(taskTemplateDTO, taskTemplate); | ||
| 1371 | return taskTemplate; | ||
| 1372 | } | ||
| 1373 | continue; | ||
| 1374 | } | ||
| 1375 | } | ||
| 1376 | |||
| 1377 | } | ||
| 1378 | |||
| 1379 | } | ||
| 1380 | |||
| 1381 | |||
| 1382 | return null; | ||
| 1383 | } | ||
| 1384 | |||
| 1385 | 949 | ||
| 1386 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// | 950 | //////////////////////////////////////2021-11 为支持重数《反贪风暴5》活动上线临时做法需要删除////////////////////////////////////////////////////////////////////// |
| 1387 | 951 | ||
| 1388 | @Autowired | 952 | @Autowired |
| 1389 | private StringRedisTemplate stringRedisTemplate; | 953 | private StringRedisTemplate stringRedisTemplate; | ... | ... |
| ... | @@ -10,11 +10,13 @@ import com.topdraw.business.module.member.domain.Member; | ... | @@ -10,11 +10,13 @@ import com.topdraw.business.module.member.domain.Member; |
| 10 | import com.topdraw.business.module.member.domain.MemberBuilder; | 10 | import com.topdraw.business.module.member.domain.MemberBuilder; |
| 11 | import com.topdraw.business.module.member.service.MemberService; | 11 | import com.topdraw.business.module.member.service.MemberService; |
| 12 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 12 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
| 13 | import com.topdraw.business.module.member.service.dto.MemberSimpleDTO; | ||
| 13 | import com.topdraw.business.module.user.iptv.domain.UserConstant; | 14 | import com.topdraw.business.module.user.iptv.domain.UserConstant; |
| 14 | import com.topdraw.business.module.user.iptv.domain.UserTv; | 15 | import com.topdraw.business.module.user.iptv.domain.UserTv; |
| 15 | import com.topdraw.business.module.user.iptv.domain.UserTvBuilder; | 16 | import com.topdraw.business.module.user.iptv.domain.UserTvBuilder; |
| 16 | import com.topdraw.business.module.user.iptv.service.UserTvService; | 17 | import com.topdraw.business.module.user.iptv.service.UserTvService; |
| 17 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; | 18 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; |
| 19 | import com.topdraw.business.module.user.iptv.service.dto.UserTvSimpleDTO; | ||
| 18 | import com.topdraw.business.module.user.weixin.collection.domain.UserCollection; | 20 | import com.topdraw.business.module.user.weixin.collection.domain.UserCollection; |
| 19 | import com.topdraw.business.module.user.weixin.collection.domain.UserCollectionDetail; | 21 | import com.topdraw.business.module.user.weixin.collection.domain.UserCollectionDetail; |
| 20 | import com.topdraw.business.module.user.weixin.collection.repository.UserCollectionDetailRepository; | 22 | import com.topdraw.business.module.user.weixin.collection.repository.UserCollectionDetailRepository; |
| ... | @@ -34,6 +36,7 @@ import com.topdraw.business.process.service.dto.MemberAndUserTvDTO; | ... | @@ -34,6 +36,7 @@ import com.topdraw.business.process.service.dto.MemberAndUserTvDTO; |
| 34 | import com.topdraw.business.process.service.dto.MemberAndWeixinUserDTO; | 36 | import com.topdraw.business.process.service.dto.MemberAndWeixinUserDTO; |
| 35 | import com.topdraw.business.process.service.mapper.CollectionMq2DetailMapper; | 37 | import com.topdraw.business.process.service.mapper.CollectionMq2DetailMapper; |
| 36 | import com.topdraw.config.LocalConstants; | 38 | import com.topdraw.config.LocalConstants; |
| 39 | import com.topdraw.config.RedisKeyConstants; | ||
| 37 | import com.topdraw.config.RedisKeyUtil; | 40 | import com.topdraw.config.RedisKeyUtil; |
| 38 | import com.topdraw.exception.BadRequestException; | 41 | import com.topdraw.exception.BadRequestException; |
| 39 | import com.topdraw.exception.EntityNotFoundException; | 42 | import com.topdraw.exception.EntityNotFoundException; |
| ... | @@ -49,6 +52,7 @@ import org.springframework.aop.framework.AopContext; | ... | @@ -49,6 +52,7 @@ import org.springframework.aop.framework.AopContext; |
| 49 | import org.springframework.beans.BeanUtils; | 52 | import org.springframework.beans.BeanUtils; |
| 50 | import org.springframework.beans.factory.annotation.Autowired; | 53 | import org.springframework.beans.factory.annotation.Autowired; |
| 51 | import org.springframework.beans.factory.annotation.Value; | 54 | import org.springframework.beans.factory.annotation.Value; |
| 55 | import org.springframework.cache.annotation.CachePut; | ||
| 52 | import org.springframework.data.domain.PageRequest; | 56 | import org.springframework.data.domain.PageRequest; |
| 53 | import org.springframework.data.domain.Sort; | 57 | import org.springframework.data.domain.Sort; |
| 54 | import org.springframework.stereotype.Service; | 58 | import org.springframework.stereotype.Service; |
| ... | @@ -119,8 +123,9 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -119,8 +123,9 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 119 | UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); | 123 | UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); |
| 120 | 124 | ||
| 121 | // 无账号 | 125 | // 无账号 |
| 122 | if (Objects.isNull(userTvDTO)) { | 126 | if (Objects.isNull(userTvDTO.getId())) { |
| 123 | 127 | ||
| 128 | // 会员昵称默认采用大屏账号,昵称通过base64加密与小屏保持一致 | ||
| 124 | String platformAccountEncode = Base64Utils.encodeToString(platformAccount.getBytes()); | 129 | String platformAccountEncode = Base64Utils.encodeToString(platformAccount.getBytes()); |
| 125 | 130 | ||
| 126 | // x_member | 131 | // x_member |
| ... | @@ -133,14 +138,15 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -133,14 +138,15 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 133 | 138 | ||
| 134 | UserTv userTv = UserTvBuilder.build(memberDTO.getId(), memberDTO.getCode(), resources); | 139 | UserTv userTv = UserTvBuilder.build(memberDTO.getId(), memberDTO.getCode(), resources); |
| 135 | // 创建大屏账户 | 140 | // 创建大屏账户 |
| 136 | UserTvDTO tvUserDTO = this.createTvUser(userTv, memberDTO.getId(), memberDTO.getCode()); | 141 | UserTvDTO _tvUserDTO = this.createTvUser(userTv, memberDTO.getId(), memberDTO.getCode()); |
| 137 | 142 | ||
| 138 | ((UserOperationServiceImpl)AopContext.currentProxy()).asyncMemberAndUserTv4Iptv(new MemberAndUserTvDTO(memberDTO, tvUserDTO)); | 143 | ((UserOperationServiceImpl)AopContext.currentProxy()).asyncMemberAndUserTv4Iptv(new MemberAndUserTvDTO(memberDTO, _tvUserDTO)); |
| 139 | 144 | ||
| 140 | return tvUserDTO; | 145 | return _tvUserDTO; |
| 141 | 146 | ||
| 142 | } | 147 | } |
| 143 | 148 | ||
| 149 | log.error("保存大屏账号信息异常,无法创建大屏账号对应的会员,platoformAccount ==> {}", platformAccount); | ||
| 144 | throw new EntityNotFoundException(MemberDTO.class, "code", GlobeExceptionMsg.MEMBER_ID_IS_NULL); | 150 | throw new EntityNotFoundException(MemberDTO.class, "code", GlobeExceptionMsg.MEMBER_ID_IS_NULL); |
| 145 | 151 | ||
| 146 | // 有账号 | 152 | // 有账号 |
| ... | @@ -165,10 +171,10 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -165,10 +171,10 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 165 | UserTv userTv = new UserTv(); | 171 | UserTv userTv = new UserTv(); |
| 166 | BeanUtils.copyProperties(userTvDTO, userTv); | 172 | BeanUtils.copyProperties(userTvDTO, userTv); |
| 167 | 173 | ||
| 168 | UserTvDTO userTvDTO1 = this.updateUserTvUnsyncIptv(userTv); | 174 | UserTvDTO _userTvDTO = this.userTvService.update(userTv); |
| 169 | ((UserOperationServiceImpl)AopContext.currentProxy()).asyncMemberAndUserTv4Iptv(new MemberAndUserTvDTO(memberDTO, userTvDTO1)); | 175 | ((UserOperationServiceImpl)AopContext.currentProxy()).asyncMemberAndUserTv4Iptv(new MemberAndUserTvDTO(memberDTO, _userTvDTO)); |
| 170 | 176 | ||
| 171 | return userTvDTO1; | 177 | return _userTvDTO; |
| 172 | } | 178 | } |
| 173 | 179 | ||
| 174 | } | 180 | } |
| ... | @@ -1065,6 +1071,13 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -1065,6 +1071,13 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 1065 | // 同步至iptv | 1071 | // 同步至iptv |
| 1066 | ((UserOperationServiceImpl)AopContext.currentProxy()).asyncMinaBind(new MemberAndUserTvDTO(memberDTO, userTvDTO)); | 1072 | ((UserOperationServiceImpl)AopContext.currentProxy()).asyncMinaBind(new MemberAndUserTvDTO(memberDTO, userTvDTO)); |
| 1067 | 1073 | ||
| 1074 | // 修改缓存中MemberSimple的大屏主账号信息,因为执行任务之前会去检查主会员d | ||
| 1075 | UserTvSimpleDTO userTvSimpleDTO = this.userTvService.findSimpleByPlatformAccount(platformAccount); | ||
| 1076 | if (Objects.nonNull(userTvDTO)) { | ||
| 1077 | userTvSimpleDTO.setPriorityMemberCode(memberDTO.getCode()); | ||
| 1078 | HashMap hashMap = JSONObject.parseObject(userTvSimpleDTO.toString(), HashMap.class); | ||
| 1079 | this.redisUtils.set(RedisKeyConstants.cacheVisUserByPlatformAccount + "::" + platformAccount, hashMap); | ||
| 1080 | } | ||
| 1068 | return userTvDTO; | 1081 | return userTvDTO; |
| 1069 | } | 1082 | } |
| 1070 | 1083 | ||
| ... | @@ -1088,15 +1101,6 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -1088,15 +1101,6 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 1088 | } | 1101 | } |
| 1089 | 1102 | ||
| 1090 | /** | 1103 | /** |
| 1091 | * | ||
| 1092 | * @param userTv 大屏账号 | ||
| 1093 | * @return UserTvDTO | ||
| 1094 | */ | ||
| 1095 | private UserTvDTO updateUserTvUnsyncIptv(UserTv userTv){ | ||
| 1096 | return this.userTvService.update(userTv); | ||
| 1097 | } | ||
| 1098 | |||
| 1099 | /** | ||
| 1100 | * 重置主账号 | 1104 | * 重置主账号 |
| 1101 | * @param memberDTO 会员code | 1105 | * @param memberDTO 会员code |
| 1102 | * @param userTvDTO 大屏id | 1106 | * @param userTvDTO 大屏id |
| ... | @@ -1242,8 +1246,14 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -1242,8 +1246,14 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 1242 | * @param member 会员信息 | 1246 | * @param member 会员信息 |
| 1243 | * @return MemberDTO | 1247 | * @return MemberDTO |
| 1244 | */ | 1248 | */ |
| 1245 | private MemberDTO createMember(Member member){ | 1249 | public MemberDTO createMember(Member member){ |
| 1246 | return this.memberService.create(member); | 1250 | MemberDTO memberDTO = this.memberService.create(member); |
| 1251 | if (Objects.nonNull(memberDTO.getId())) { | ||
| 1252 | MemberSimpleDTO memberSimpleDTO = new MemberSimpleDTO(); | ||
| 1253 | BeanUtils.copyProperties(memberDTO, memberSimpleDTO); | ||
| 1254 | this.redisUtils.set(RedisKeyConstants.cacheMemberSimpleById+"::"+memberDTO.getId(), memberSimpleDTO); | ||
| 1255 | } | ||
| 1256 | return memberDTO; | ||
| 1247 | } | 1257 | } |
| 1248 | 1258 | ||
| 1249 | /** | 1259 | /** | ... | ... |
| ... | @@ -10,19 +10,49 @@ package com.topdraw.config; | ... | @@ -10,19 +10,49 @@ package com.topdraw.config; |
| 10 | * @since : modified in 2022/6/18 13:25 | 10 | * @since : modified in 2022/6/18 13:25 |
| 11 | */ | 11 | */ |
| 12 | public interface RedisKeyConstants { | 12 | public interface RedisKeyConstants { |
| 13 | 13 | // 全量会员信息 | |
| 14 | String cacheMemberById = "uce::member::id"; | 14 | String cacheMemberById = "uce::member::id"; |
| 15 | // 任务处理时会员信息 | ||
| 16 | String cacheMemberSimpleById = "uce::memberSimple::id"; | ||
| 17 | // 会员全量信息 | ||
| 15 | String cacheMemberByCode = "uce::member::code"; | 18 | String cacheMemberByCode = "uce::member::code"; |
| 16 | String updateCacheMemberById = "uce::updateMember::id"; | ||
| 17 | 19 | ||
| 20 | // 修改会员积分时的分布式锁 | ||
| 18 | String updateCachePointsByMemberId = "uce::updatePoints::memberId"; | 21 | String updateCachePointsByMemberId = "uce::updatePoints::memberId"; |
| 22 | // 修改会员成长值时的分布式锁 | ||
| 19 | String updateCacheExpByMemberId = "uce::updateExp::memberId"; | 23 | String updateCacheExpByMemberId = "uce::updateExp::memberId"; |
| 24 | // 修改会员优惠券时的分布式锁 | ||
| 20 | String updateCacheCouponByMemberId = "uce::updateCoupon::memberId"; | 25 | String updateCacheCouponByMemberId = "uce::updateCoupon::memberId"; |
| 21 | 26 | ||
| 27 | // 全量大屏信息 | ||
| 22 | String cacheUserTvByPlatformAccount = "uce::userTv::platformAccount"; | 28 | String cacheUserTvByPlatformAccount = "uce::userTv::platformAccount"; |
| 29 | String cacheVisUserByPlatformAccount = "uus::visUser::platformAccount"; | ||
| 30 | // 会员已完成的任务进度 | ||
| 23 | String cacheTaskProcessByMemberId = "uce::taskProcess::memberId"; | 31 | String cacheTaskProcessByMemberId = "uce::taskProcess::memberId"; |
| 24 | String cacheTaskByTaskTemplateId = "uce::task::taskTemplateId"; | 32 | // 任务模板类型对应的全量任务 |
| 25 | String cacheTaskByEvent = "uce::task::event"; | 33 | String cacheTaskByEvent = "uce::task::event"; |
| 34 | // 全量优惠券信息 | ||
| 26 | String cacheCouponById = "uce::coupon::id"; | 35 | String cacheCouponById = "uce::coupon::id"; |
| 36 | |||
| 37 | // 权益全量信息 | ||
| 27 | String cacheRightById = "uce::right::id"; | 38 | String cacheRightById = "uce::right::id"; |
| 39 | |||
| 40 | // 会员可以做的任务 | ||
| 41 | String cacheTaskByEventAndMemberLevelAndVip = "uce::task::eventAndMemberLevelAndVip"; | ||
| 42 | |||
| 43 | // 全量会员等级 | ||
| 44 | String cacheMemberLevelByLevel = "uce::memberLevel::level"; | ||
| 45 | |||
| 46 | // 今天处理完成任务数量 | ||
| 47 | String cacheTodayFinishTaskCount = "uce::todayCount::memberId"; | ||
| 48 | // 历史完成的任务数量 | ||
| 49 | String cacheTotalFinishTaskCount = "uce::totalCount::memberId"; | ||
| 50 | |||
| 51 | |||
| 52 | |||
| 53 | String CACHE_PLATFROMACCOUNT_PLAYDURATION = "uce::eventPlay::playduration"; | ||
| 54 | |||
| 55 | |||
| 56 | String CACHE_TODAY_FINISH_COUNT = "todayFinishCount"; | ||
| 57 | String CACHE_TOTAL_FINISH_COUNT = "totalFinishCount"; | ||
| 28 | } | 58 | } | ... | ... |
member-service-impl/src/main/java/com/topdraw/config/TheadPoolTaskExecutorConfiguration.java
0 → 100644
| 1 | package com.topdraw.config; | ||
| 2 | |||
| 3 | import org.springframework.beans.factory.annotation.Value; | ||
| 4 | import org.springframework.context.annotation.Bean; | ||
| 5 | import org.springframework.context.annotation.Configuration; | ||
| 6 | import org.springframework.context.annotation.Primary; | ||
| 7 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
| 8 | |||
| 9 | import java.util.concurrent.ArrayBlockingQueue; | ||
| 10 | import java.util.concurrent.Executor; | ||
| 11 | import java.util.concurrent.ThreadPoolExecutor; | ||
| 12 | import java.util.concurrent.TimeUnit; | ||
| 13 | |||
| 14 | /** | ||
| 15 | * @author : | ||
| 16 | * @description: | ||
| 17 | * @function : | ||
| 18 | * @date :Created in 2022/6/22 11:06 | ||
| 19 | * @version: : | ||
| 20 | * @modified By: | ||
| 21 | * @since : modified in 2022/6/22 11:06 | ||
| 22 | */ | ||
| 23 | @Configuration | ||
| 24 | public class TheadPoolTaskExecutorConfiguration { | ||
| 25 | |||
| 26 | @Value("${task.pool.core-pool-size}") | ||
| 27 | private Integer corePoolSize; | ||
| 28 | @Value("${task.pool.core-pool-size}") | ||
| 29 | private Integer maxPoolSize; | ||
| 30 | @Value("${task.pool.keep-alive-seconds}") | ||
| 31 | private Integer keepAliveSeconds; | ||
| 32 | @Value("${task.pool.queue-capacity}") | ||
| 33 | private Integer queueCapacity; | ||
| 34 | |||
| 35 | @Bean | ||
| 36 | @Primary | ||
| 37 | public ThreadPoolTaskExecutor getThreadPoolTaskExecutor() { | ||
| 38 | ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor(); | ||
| 39 | threadPoolTaskExecutor.setCorePoolSize(corePoolSize); | ||
| 40 | threadPoolTaskExecutor.setMaxPoolSize(maxPoolSize); | ||
| 41 | threadPoolTaskExecutor.setKeepAliveSeconds(keepAliveSeconds); | ||
| 42 | threadPoolTaskExecutor.setQueueCapacity(queueCapacity); | ||
| 43 | threadPoolTaskExecutor.setWaitForTasksToCompleteOnShutdown(true); | ||
| 44 | threadPoolTaskExecutor.initialize(); | ||
| 45 | return threadPoolTaskExecutor; | ||
| 46 | } | ||
| 47 | |||
| 48 | |||
| 49 | /*@Bean | ||
| 50 | public ThreadPoolExecutor getThreadPoolTaskExecutor() { | ||
| 51 | ArrayBlockingQueue arrayBlockingQueue = new ArrayBlockingQueue(queueCapacity); | ||
| 52 | ThreadPoolExecutor threadPoolTaskExecutor = new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveSeconds, TimeUnit.SECONDS, arrayBlockingQueue); | ||
| 53 | return threadPoolTaskExecutor; | ||
| 54 | }*/ | ||
| 55 | |||
| 56 | } |
| 1 | package com.topdraw.config; | ||
| 2 | |||
| 3 | |||
| 4 | import com.fasterxml.jackson.annotation.JsonAutoDetect; | ||
| 5 | import com.fasterxml.jackson.annotation.PropertyAccessor; | ||
| 6 | import com.fasterxml.jackson.databind.ObjectMapper; | ||
| 7 | import lombok.extern.slf4j.Slf4j; | ||
| 8 | import org.springframework.beans.factory.annotation.Autowired; | ||
| 9 | import org.springframework.cache.annotation.CachingConfigurerSupport; | ||
| 10 | import org.springframework.context.annotation.Bean; | ||
| 11 | import org.springframework.context.annotation.Configuration; | ||
| 12 | import org.springframework.context.annotation.Primary; | ||
| 13 | import org.springframework.data.redis.cache.RedisCacheConfiguration; | ||
| 14 | import org.springframework.data.redis.cache.RedisCacheManager; | ||
| 15 | import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
| 16 | import org.springframework.data.redis.core.RedisTemplate; | ||
| 17 | import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; | ||
| 18 | |||
| 19 | import java.time.Duration; | ||
| 20 | import java.util.HashSet; | ||
| 21 | import java.util.Set; | ||
| 22 | import java.util.concurrent.ConcurrentHashMap; | ||
| 23 | |||
| 24 | /** | ||
| 25 | * @author : | ||
| 26 | * @description: | ||
| 27 | * @function : | ||
| 28 | * @date :Created in 2022/6/19 16:30 | ||
| 29 | * @version: : | ||
| 30 | * @modified By: | ||
| 31 | * @since : modified in 2022/6/19 16:30 | ||
| 32 | */ | ||
| 33 | @Slf4j | ||
| 34 | @Configuration | ||
| 35 | public class UceRedisConfig { | ||
| 36 | |||
| 37 | @Autowired | ||
| 38 | private RedisConfig redisConfig; | ||
| 39 | @Autowired | ||
| 40 | private RedisConnectionFactory redisConnectionFactory; | ||
| 41 | |||
| 42 | @Bean(value = "uceRedisTemplate") | ||
| 43 | public RedisTemplate<Object, Object> uceRedisTemplate() { | ||
| 44 | return redisConfig.redisTemplate(redisConnectionFactory); | ||
| 45 | } | ||
| 46 | /** | ||
| 47 | * 自定义缓存管理器 | ||
| 48 | */ | ||
| 49 | @Bean(value = "uceCacheManagemer") | ||
| 50 | @Primary | ||
| 51 | public RedisCacheManager cacheManager(RedisConnectionFactory factory) { | ||
| 52 | RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig(); | ||
| 53 | Set<String> cacheNames = new HashSet<>(); | ||
| 54 | // cacheNames.add("car"); | ||
| 55 | // cacheNames.add(RedisKeyConstants.cacheTaskByEvent); | ||
| 56 | cacheNames.add(RedisKeyConstants.cacheTaskProcessByMemberId); | ||
| 57 | ConcurrentHashMap<String, RedisCacheConfiguration> configMap = new ConcurrentHashMap<>(); | ||
| 58 | // configMap.put("car", config.entryTtl(Duration.ofMinutes(6L))); | ||
| 59 | configMap.put(RedisKeyConstants.cacheTaskProcessByMemberId, config.entryTtl(Duration.ofDays(1))); | ||
| 60 | // configMap.put(RedisKeyConstants.cacheTaskByEvent, config); | ||
| 61 | |||
| 62 | //需要先初始化缓存名称,再初始化其它的配置。 | ||
| 63 | RedisCacheManager cacheManager = RedisCacheManager.builder(factory). | ||
| 64 | initialCacheNames(cacheNames).withInitialCacheConfigurations(configMap).build(); | ||
| 65 | return cacheManager; | ||
| 66 | } | ||
| 67 | } |
| ... | @@ -6,7 +6,6 @@ import lombok.NoArgsConstructor; | ... | @@ -6,7 +6,6 @@ import lombok.NoArgsConstructor; |
| 6 | 6 | ||
| 7 | import javax.validation.constraints.NotNull; | 7 | import javax.validation.constraints.NotNull; |
| 8 | import java.io.Serializable; | 8 | import java.io.Serializable; |
| 9 | import java.sql.Timestamp; | ||
| 10 | import java.time.LocalDateTime; | 9 | import java.time.LocalDateTime; |
| 11 | 10 | ||
| 12 | /** | 11 | /** |
| ... | @@ -25,43 +24,8 @@ public class DataSyncMsg implements Serializable { | ... | @@ -25,43 +24,8 @@ public class DataSyncMsg implements Serializable { |
| 25 | //设备类型 1:大屏;2:小屏(微信)3.小屏(xx) | 24 | //设备类型 1:大屏;2:小屏(微信)3.小屏(xx) |
| 26 | private Integer deviceType; | 25 | private Integer deviceType; |
| 27 | // 发送时间 | 26 | // 发送时间 |
| 28 | private String time; | 27 | private LocalDateTime time; |
| 29 | // 消息体 | 28 | // 消息体 |
| 30 | private String msgData; | 29 | private String msgData; |
| 31 | 30 | ||
| 32 | /** | ||
| 33 | * 消息体 | ||
| 34 | */ | ||
| 35 | @Data | ||
| 36 | @AllArgsConstructor | ||
| 37 | @NoArgsConstructor | ||
| 38 | public static class MsgData { | ||
| 39 | /**备注*/ | ||
| 40 | private String remarks; | ||
| 41 | // 会员id | ||
| 42 | private Long memberId; | ||
| 43 | // 账户id | ||
| 44 | private Long userId; | ||
| 45 | //用户对应的应用code | ||
| 46 | private String appCode; | ||
| 47 | // 会员code | ||
| 48 | private String memberCode; | ||
| 49 | // 账号id | ||
| 50 | private Long accountId; | ||
| 51 | // 订单Id | ||
| 52 | private Long orderId; | ||
| 53 | // 活动id | ||
| 54 | private Long activityId; | ||
| 55 | // 节目id | ||
| 56 | private Long mediaId; | ||
| 57 | // 产品id | ||
| 58 | private Long itemId; | ||
| 59 | // 模板参数 | ||
| 60 | private String param; | ||
| 61 | // 描述 | ||
| 62 | private String description; | ||
| 63 | // 大屏账号 | ||
| 64 | private String platformAccount; | ||
| 65 | } | ||
| 66 | |||
| 67 | } | 31 | } | ... | ... |
| ... | @@ -5,7 +5,7 @@ spring: | ... | @@ -5,7 +5,7 @@ spring: |
| 5 | url: jdbc:log4jdbc:mysql://122.112.214.149:3306/tj_user_admin?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false | 5 | url: jdbc:log4jdbc:mysql://122.112.214.149:3306/tj_user_admin?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false |
| 6 | username: root | 6 | username: root |
| 7 | password: root | 7 | password: root |
| 8 | # url: jdbc:log4jdbc:mysql://139.196.145.150:3306/ucs-small-sichuan?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false | 8 | # url: jdbc:log4jdbc:mysql://139.196.145.150:3306/ucs_admin_chongshu?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false |
| 9 | # username: root | 9 | # username: root |
| 10 | # password: Tjlh@2021 | 10 | # password: Tjlh@2021 |
| 11 | 11 | ||
| ... | @@ -20,7 +20,7 @@ spring: | ... | @@ -20,7 +20,7 @@ spring: |
| 20 | # 最大连接数 | 20 | # 最大连接数 |
| 21 | max-active: 15 | 21 | max-active: 15 |
| 22 | # 获取连接超时时间 | 22 | # 获取连接超时时间 |
| 23 | max-wait: 5000 | 23 | max-wait: 5000000 |
| 24 | # 连接有效性检测时间 | 24 | # 连接有效性检测时间 |
| 25 | time-between-eviction-runs-millis: 90000 | 25 | time-between-eviction-runs-millis: 90000 |
| 26 | # 最大空闲时间 | 26 | # 最大空闲时间 | ... | ... |
| ... | @@ -25,13 +25,13 @@ spring: | ... | @@ -25,13 +25,13 @@ spring: |
| 25 | task: | 25 | task: |
| 26 | pool: | 26 | pool: |
| 27 | # 核心线程池大小 | 27 | # 核心线程池大小 |
| 28 | core-pool-size: 10 | 28 | core-pool-size: 16 |
| 29 | # 最大线程数 | 29 | # 最大线程数 |
| 30 | max-pool-size: 30 | 30 | max-pool-size: 35 |
| 31 | # 活跃时间 | 31 | # 活跃时间 |
| 32 | keep-alive-seconds: 60 | 32 | keep-alive-seconds: 10 |
| 33 | # 队列容量 | 33 | # 队列容量 |
| 34 | queue-capacity: 50 | 34 | queue-capacity: 300 |
| 35 | 35 | ||
| 36 | #登录图形验证码有效时间/分钟 | 36 | #登录图形验证码有效时间/分钟 |
| 37 | loginCode: | 37 | loginCode: | ... | ... |
| ... | @@ -64,7 +64,7 @@ | ... | @@ -64,7 +64,7 @@ |
| 64 | 64 | ||
| 65 | 65 | ||
| 66 | <!--监控sql日志输出 --> | 66 | <!--监控sql日志输出 --> |
| 67 | <logger name="jdbc.sqlonly" level="INFO" additivity="false"> | 67 | <logger name="jdbc.sqlonly" level="OFF" additivity="false"> |
| 68 | <appender-ref ref="console" /> | 68 | <appender-ref ref="console" /> |
| 69 | <appender-ref ref="info" /> | 69 | <appender-ref ref="info" /> |
| 70 | </logger> | 70 | </logger> | ... | ... |
| ... | @@ -96,11 +96,12 @@ public class TaskOperationControllerTest extends BaseTest { | ... | @@ -96,11 +96,12 @@ public class TaskOperationControllerTest extends BaseTest { |
| 96 | public void play() { | 96 | public void play() { |
| 97 | try { | 97 | try { |
| 98 | String s = "{\"evt\":\"PLAY\",\"event\":8,\"time\":\"2022-05-03 23:10:09\",\"deviceType\":1," + | 98 | String s = "{\"evt\":\"PLAY\",\"event\":8,\"time\":\"2022-05-03 23:10:09\",\"deviceType\":1," + |
| 99 | "\"msgData\":{\"memberCode\":\"1537253277861699584\",\"param\":\"{\\\"playDuration\\\":60}\"}}"; | 99 | "\"msgData\":{\"platformAccount\":\"1537253277861699584\",\"param\":\"{\\\"playDuration\\\":60}\"}}"; |
| 100 | TaskOperationQueryCriteria pointsQueryCriteria = new TaskOperationQueryCriteria(); | 100 | TaskOperationQueryCriteria pointsQueryCriteria = new TaskOperationQueryCriteria(); |
| 101 | pointsQueryCriteria.setContent(s); | 101 | pointsQueryCriteria.setContent(s); |
| 102 | String s1 = JSON.toJSONString(pointsQueryCriteria); | 102 | String s1 = JSON.toJSONString(pointsQueryCriteria); |
| 103 | this.taskOperationController.dealTask(pointsQueryCriteria); | 103 | System.out.println(s1); |
| 104 | // this.taskOperationController.dealTask(pointsQueryCriteria); | ||
| 104 | } catch (Exception e) { | 105 | } catch (Exception e) { |
| 105 | e.printStackTrace(); | 106 | e.printStackTrace(); |
| 106 | } | 107 | } | ... | ... |
| ... | @@ -2,6 +2,8 @@ package com.topdraw.test.business.process.service; | ... | @@ -2,6 +2,8 @@ package com.topdraw.test.business.process.service; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
| 4 | import com.topdraw.business.module.member.domain.Member; | 4 | import com.topdraw.business.module.member.domain.Member; |
| 5 | import com.topdraw.business.module.member.service.MemberService; | ||
| 6 | import com.topdraw.business.module.member.service.dto.MemberSimpleDTO; | ||
| 5 | import com.topdraw.business.process.service.member.MemberOperationService; | 7 | import com.topdraw.business.process.service.member.MemberOperationService; |
| 6 | import com.topdraw.BaseTest; | 8 | import com.topdraw.BaseTest; |
| 7 | import com.topdraw.util.IdWorker; | 9 | import com.topdraw.util.IdWorker; |
| ... | @@ -16,6 +18,15 @@ public class MemberOperationServiceTest extends BaseTest { | ... | @@ -16,6 +18,15 @@ public class MemberOperationServiceTest extends BaseTest { |
| 16 | @Autowired | 18 | @Autowired |
| 17 | MemberOperationService memberOperationService; | 19 | MemberOperationService memberOperationService; |
| 18 | 20 | ||
| 21 | @Autowired | ||
| 22 | MemberService memberService; | ||
| 23 | |||
| 24 | @Test | ||
| 25 | public void findMemberSimpleTest(){ | ||
| 26 | MemberSimpleDTO memberSimpleDTO = this.memberService.findSimpleById(20718L); | ||
| 27 | System.out.println(memberSimpleDTO); | ||
| 28 | } | ||
| 29 | |||
| 19 | @Test | 30 | @Test |
| 20 | public void findById() { | 31 | public void findById() { |
| 21 | Long memberId = 2L; | 32 | Long memberId = 2L; | ... | ... |
| ... | @@ -19,11 +19,7 @@ public class TaskOperationServiceTest extends BaseTest { | ... | @@ -19,11 +19,7 @@ public class TaskOperationServiceTest extends BaseTest { |
| 19 | DataSyncMsg dataSyncMsg = new DataSyncMsg(); | 19 | DataSyncMsg dataSyncMsg = new DataSyncMsg(); |
| 20 | // dataSyncMsg.setEntityType(EntityType.MEMBER); | 20 | // dataSyncMsg.setEntityType(EntityType.MEMBER); |
| 21 | dataSyncMsg.setEvt(EventType.LOGIN.name()); | 21 | dataSyncMsg.setEvt(EventType.LOGIN.name()); |
| 22 | DataSyncMsg.MsgData msgData = new DataSyncMsg.MsgData(); | ||
| 23 | msgData.setRemarks("remark"); | ||
| 24 | msgData.setMemberId(memberId); | ||
| 25 | 22 | ||
| 26 | msgData.setAppCode("WEI_XIN_GOLD_PANDA"); | ||
| 27 | // dataSyncMsg.setMsgData(msgData); | 23 | // dataSyncMsg.setMsgData(msgData); |
| 28 | 24 | ||
| 29 | String s = JSON.toJSONString(dataSyncMsg); | 25 | String s = JSON.toJSONString(dataSyncMsg); | ... | ... |
| ... | @@ -22,10 +22,10 @@ public class MqTest extends BaseTest { | ... | @@ -22,10 +22,10 @@ public class MqTest extends BaseTest { |
| 22 | DataSyncMsg dataSyncMsg = new DataSyncMsg(); | 22 | DataSyncMsg dataSyncMsg = new DataSyncMsg(); |
| 23 | // dataSyncMsg.setEventType(EventType.LOGIN.name()); | 23 | // dataSyncMsg.setEventType(EventType.LOGIN.name()); |
| 24 | dataSyncMsg.setEvt(EventType.LOGIN.name()); | 24 | dataSyncMsg.setEvt(EventType.LOGIN.name()); |
| 25 | DataSyncMsg.MsgData msgData = new DataSyncMsg.MsgData(); | 25 | /* DataSyncMsg.MsgData msgData = new DataSyncMsg.MsgData(); |
| 26 | msgData.setRemarks("remark"); | 26 | msgData.setRemarks("remark"); |
| 27 | msgData.setMemberId(1L); | 27 | msgData.setMemberId(1L); |
| 28 | msgData.setAppCode("WEI_XIN_GOLD_PANDA"); | 28 | msgData.setAppCode("WEI_XIN_GOLD_PANDA");*/ |
| 29 | // dataSyncMsg.setMsgData(msgData); | 29 | // dataSyncMsg.setMsgData(msgData); |
| 30 | String s = JSON.toJSONString(dataSyncMsg); | 30 | String s = JSON.toJSONString(dataSyncMsg); |
| 31 | amqpTemplate.convertAndSend( "uc.route.key.direct.event.aaa", s); | 31 | amqpTemplate.convertAndSend( "uc.route.key.direct.event.aaa", s); | ... | ... |
-
Please register or sign in to post a comment