处理并发情况下的数据安全问题
Showing
19 changed files
with
179 additions
and
161 deletions
... | @@ -121,7 +121,7 @@ public class Member implements Serializable { | ... | @@ -121,7 +121,7 @@ public class Member implements Serializable { |
121 | 121 | ||
122 | // 是否在黑名单 1:是;0否 | 122 | // 是否在黑名单 1:是;0否 |
123 | @Column(name = "black_status") | 123 | @Column(name = "black_status") |
124 | private Integer blackStatus; | 124 | private Long blackStatus; |
125 | 125 | ||
126 | public void copy(Member source){ | 126 | public void copy(Member source){ |
127 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | 127 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ... | ... |
... | @@ -9,6 +9,7 @@ import com.topdraw.business.basicdata.member.level.service.dto.MemberLevelDTO; | ... | @@ -9,6 +9,7 @@ import com.topdraw.business.basicdata.member.level.service.dto.MemberLevelDTO; |
9 | import com.topdraw.business.basicdata.member.level.service.dto.MemberLevelQueryCriteria; | 9 | import com.topdraw.business.basicdata.member.level.service.dto.MemberLevelQueryCriteria; |
10 | import com.topdraw.business.basicdata.member.level.service.mapper.MemberLevelMapper; | 10 | import com.topdraw.business.basicdata.member.level.service.mapper.MemberLevelMapper; |
11 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
12 | import org.springframework.cache.annotation.Cacheable; | ||
12 | import org.springframework.stereotype.Service; | 13 | import org.springframework.stereotype.Service; |
13 | import org.springframework.transaction.annotation.Propagation; | 14 | import org.springframework.transaction.annotation.Propagation; |
14 | import org.springframework.transaction.annotation.Transactional; | 15 | import org.springframework.transaction.annotation.Transactional; |
... | @@ -89,6 +90,7 @@ public class MemberLevelServiceImpl implements MemberLevelService { | ... | @@ -89,6 +90,7 @@ public class MemberLevelServiceImpl implements MemberLevelService { |
89 | : new MemberLevelDTO(); | 90 | : new MemberLevelDTO(); |
90 | } | 91 | } |
91 | 92 | ||
93 | @Cacheable(cacheNames = "uc-member_level",key = "#level") | ||
92 | @Override | 94 | @Override |
93 | public List<MemberLevelDTO> findLevelAndStatus(Integer level, Integer status) { | 95 | public List<MemberLevelDTO> findLevelAndStatus(Integer level, Integer status) { |
94 | return MemberLevelMapper.toDto(MemberLevelRepository.findByLevelAndStatus(level,status)); | 96 | return MemberLevelMapper.toDto(MemberLevelRepository.findByLevelAndStatus(level,status)); | ... | ... |
... | @@ -83,5 +83,5 @@ public class MemberDTO implements Serializable { | ... | @@ -83,5 +83,5 @@ public class MemberDTO implements Serializable { |
83 | private Timestamp updateTime; | 83 | private Timestamp updateTime; |
84 | 84 | ||
85 | // 是否在黑名单 1:是;0否 | 85 | // 是否在黑名单 1:是;0否 |
86 | private Integer blackStatus; | 86 | private Long blackStatus; |
87 | } | 87 | } | ... | ... |
... | @@ -19,13 +19,18 @@ import org.redisson.api.RLock; | ... | @@ -19,13 +19,18 @@ import org.redisson.api.RLock; |
19 | import org.redisson.api.RedissonClient; | 19 | import org.redisson.api.RedissonClient; |
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.cache.annotation.CacheConfig; | ||
22 | import org.springframework.cache.annotation.Cacheable; | 23 | import org.springframework.cache.annotation.Cacheable; |
23 | import org.springframework.dao.EmptyResultDataAccessException; | 24 | import org.springframework.dao.EmptyResultDataAccessException; |
24 | import org.springframework.data.domain.Page; | 25 | import org.springframework.data.domain.Page; |
25 | import org.springframework.data.domain.Pageable; | 26 | import org.springframework.data.domain.Pageable; |
26 | import org.springframework.stereotype.Service; | 27 | import org.springframework.stereotype.Service; |
28 | import org.springframework.transaction.PlatformTransactionManager; | ||
29 | import org.springframework.transaction.TransactionDefinition; | ||
30 | import org.springframework.transaction.TransactionStatus; | ||
27 | import org.springframework.transaction.annotation.Propagation; | 31 | import org.springframework.transaction.annotation.Propagation; |
28 | import org.springframework.transaction.annotation.Transactional; | 32 | import org.springframework.transaction.annotation.Transactional; |
33 | import org.springframework.transaction.support.DefaultTransactionDefinition; | ||
29 | import org.springframework.util.Assert; | 34 | import org.springframework.util.Assert; |
30 | 35 | ||
31 | import java.util.List; | 36 | import java.util.List; |
... | @@ -38,6 +43,7 @@ import java.util.Objects; | ... | @@ -38,6 +43,7 @@ import java.util.Objects; |
38 | */ | 43 | */ |
39 | @Service | 44 | @Service |
40 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | 45 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) |
46 | //@CacheConfig(cacheNames = "uc-member-info") | ||
41 | public class MemberServiceImpl implements MemberService { | 47 | public class MemberServiceImpl implements MemberService { |
42 | 48 | ||
43 | @Autowired | 49 | @Autowired |
... | @@ -61,12 +67,12 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -61,12 +67,12 @@ public class MemberServiceImpl implements MemberService { |
61 | return memberMapper.toDto(memberRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | 67 | return memberMapper.toDto(memberRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); |
62 | } | 68 | } |
63 | 69 | ||
64 | // @Cacheable(cacheNames = "",key = "") | ||
65 | @Override | 70 | @Override |
66 | public MemberDTO findById(Long id) { | 71 | public MemberDTO findById(Long id) { |
67 | Member member = memberRepository.findById(id).orElseGet(Member::new); | 72 | Member member = memberRepository.findById(id).orElseGet(Member::new); |
68 | ValidationUtil.isNull(member.getId(),"Member","id",id); | 73 | ValidationUtil.isNull(member.getId(),"Member","id",id); |
69 | return memberMapper.toDto(member); | 74 | return memberMapper.toDto(member); |
75 | |||
70 | } | 76 | } |
71 | 77 | ||
72 | @Override | 78 | @Override |
... | @@ -99,6 +105,9 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -99,6 +105,9 @@ public class MemberServiceImpl implements MemberService { |
99 | return member; | 105 | return member; |
100 | } | 106 | } |
101 | 107 | ||
108 | @Autowired | ||
109 | PlatformTransactionManager platformTransactionManager; | ||
110 | |||
102 | @Override | 111 | @Override |
103 | @Transactional(rollbackFor = Exception.class) | 112 | @Transactional(rollbackFor = Exception.class) |
104 | @AsyncMqSend() | 113 | @AsyncMqSend() |
... | @@ -106,18 +115,31 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -106,18 +115,31 @@ public class MemberServiceImpl implements MemberService { |
106 | RLock rLock = this.redissonClient.getLock("updateMember" + resources.getId().toString()); | 115 | RLock rLock = this.redissonClient.getLock("updateMember" + resources.getId().toString()); |
107 | try { | 116 | try { |
108 | RedissonUtil.lock(rLock); | 117 | RedissonUtil.lock(rLock); |
118 | String name = Thread.currentThread().getName(); | ||
119 | System.out.println("=============>>>>【name】 ===== >> " + name + " =======>> start ===>> "); | ||
120 | System.out.println("=============>>>>【name】 ===== >> " + name + " =======>> 【resources】 ===>> " + resources); | ||
109 | Member member = memberRepository.findById(resources.getId()).orElseGet(Member::new); | 121 | Member member = memberRepository.findById(resources.getId()).orElseGet(Member::new); |
110 | ValidationUtil.isNull(member.getId(), "Member", "id", resources.getId()); | 122 | ValidationUtil.isNull(member.getId(), "Member", "id", resources.getId()); |
123 | System.out.println("=============>>>>【name】 ===== >> " + name + " =======>> 【member-search】 ===>> " + member); | ||
111 | member.copy(resources); | 124 | member.copy(resources); |
112 | memberRepository.save(member); | 125 | this.save(member); |
126 | // platformTransactionManager.commit(transaction); | ||
127 | System.out.println("=============>>>>【name】 ===== >> " + name + " =======>> 【exp】 ===>> " + member.getExp()); | ||
128 | System.out.println("=============>>>>【name】 ===== >> " + name + " =======>> 【point】 ===>> " + member.getPoints()); | ||
129 | System.out.println("=============>>>>【name】 ===== >> " + name + " =======>> 【member】 ===>> " + member); | ||
113 | } catch (Exception e) { | 130 | } catch (Exception e) { |
114 | e.printStackTrace(); | 131 | e.printStackTrace(); |
115 | throw e; | 132 | throw e; |
116 | } finally { | 133 | } finally { |
117 | RedissonUtil.unlock(rLock); | 134 | RedissonUtil.unlock(rLock); |
118 | } | 135 | } |
119 | } | 136 | } |
120 | 137 | ||
138 | @Transactional(propagation = Propagation.REQUIRES_NEW) | ||
139 | public void save(Member member){ | ||
140 | memberRepository.save(member); | ||
141 | } | ||
142 | |||
121 | @Override | 143 | @Override |
122 | @Transactional(rollbackFor = Exception.class) | 144 | @Transactional(rollbackFor = Exception.class) |
123 | @AsyncMqSend() | 145 | @AsyncMqSend() | ... | ... |
... | @@ -9,6 +9,7 @@ import com.topdraw.business.basicdata.task.service.dto.TaskDTO; | ... | @@ -9,6 +9,7 @@ import com.topdraw.business.basicdata.task.service.dto.TaskDTO; |
9 | import com.topdraw.business.basicdata.task.service.dto.TaskQueryCriteria; | 9 | import com.topdraw.business.basicdata.task.service.dto.TaskQueryCriteria; |
10 | import com.topdraw.business.basicdata.task.service.mapper.TaskMapper; | 10 | import com.topdraw.business.basicdata.task.service.mapper.TaskMapper; |
11 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
12 | import org.springframework.cache.annotation.Cacheable; | ||
12 | import org.springframework.stereotype.Service; | 13 | import org.springframework.stereotype.Service; |
13 | import org.springframework.transaction.annotation.Propagation; | 14 | import org.springframework.transaction.annotation.Propagation; |
14 | import org.springframework.transaction.annotation.Transactional; | 15 | import org.springframework.transaction.annotation.Transactional; |
... | @@ -79,6 +80,7 @@ public class TaskServiceImpl implements TaskService { | ... | @@ -79,6 +80,7 @@ public class TaskServiceImpl implements TaskService { |
79 | TaskRepository.delete(Task); | 80 | TaskRepository.delete(Task); |
80 | } | 81 | } |
81 | 82 | ||
83 | @Cacheable(cacheNames = "uc-admin_taskList" , key = "#taskTemplateId") | ||
82 | @Override | 84 | @Override |
83 | public List<Task> findByTemplateId(Long taskTemplateId) { | 85 | public List<Task> findByTemplateId(Long taskTemplateId) { |
84 | return Objects.nonNull(taskTemplateId) ? this.TaskRepository.findByTaskTemplateId(taskTemplateId) : null; | 86 | return Objects.nonNull(taskTemplateId) ? this.TaskRepository.findByTaskTemplateId(taskTemplateId) : null; | ... | ... |
... | @@ -87,14 +87,16 @@ public class TaskTemplateServiceImpl implements TaskTemplateService { | ... | @@ -87,14 +87,16 @@ public class TaskTemplateServiceImpl implements TaskTemplateService { |
87 | : new TaskTemplateDTO(); | 87 | : new TaskTemplateDTO(); |
88 | } | 88 | } |
89 | 89 | ||
90 | // @Cacheable(cacheNames = "uc.taskTemplate" , key = "event") | 90 | |
91 | @Override | 91 | @Override |
92 | public TaskTemplate findByEvent(String event) { | 92 | public TaskTemplate findByEvent(String event) { |
93 | return StringUtils.isNotEmpty(event) ? this.TaskTemplateRepository.findByEvent(event) : null; | 93 | return StringUtils.isNotEmpty(event) ? this.TaskTemplateRepository.findByEvent(event) : null; |
94 | } | 94 | } |
95 | 95 | ||
96 | @Cacheable(cacheNames = "uc-admin_taskTemplate" , key = "#event") | ||
96 | @Override | 97 | @Override |
97 | public TaskTemplate findByType(Integer event) { | 98 | public TaskTemplate findByType(Integer event) { |
99 | System.out.println("查询数据库了!!"); | ||
98 | return Objects.nonNull(event) ? this.TaskTemplateRepository.findByType(event) : null; | 100 | return Objects.nonNull(event) ? this.TaskTemplateRepository.findByType(event) : null; |
99 | } | 101 | } |
100 | } | 102 | } | ... | ... |
... | @@ -20,6 +20,14 @@ public class TempRights { | ... | @@ -20,6 +20,14 @@ public class TempRights { |
20 | @Transient | 20 | @Transient |
21 | protected Long id; | 21 | protected Long id; |
22 | 22 | ||
23 | /** 编号 */ | ||
24 | @Transient | ||
25 | protected String code; | ||
26 | |||
27 | /** 权益名称 */ | ||
28 | @Transient | ||
29 | protected String name; | ||
30 | |||
23 | /** 会员ID */ | 31 | /** 会员ID */ |
24 | @Transient | 32 | @Transient |
25 | @NotNull(message = "") | 33 | @NotNull(message = "") | ... | ... |
... | @@ -5,6 +5,7 @@ import com.topdraw.business.basicdata.task.domain.Task; | ... | @@ -5,6 +5,7 @@ import com.topdraw.business.basicdata.task.domain.Task; |
5 | import com.topdraw.business.process.domian.TempPoints; | 5 | import com.topdraw.business.process.domian.TempPoints; |
6 | 6 | ||
7 | import java.util.List; | 7 | import java.util.List; |
8 | import java.util.Map; | ||
8 | 9 | ||
9 | /** | 10 | /** |
10 | * @description 积分操作接口 | 11 | * @description 积分操作接口 | ... | ... |
... | @@ -19,10 +19,14 @@ import org.springframework.beans.factory.annotation.Autowired; | ... | @@ -19,10 +19,14 @@ import org.springframework.beans.factory.annotation.Autowired; |
19 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | 19 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
20 | import org.springframework.stereotype.Service; | 20 | import org.springframework.stereotype.Service; |
21 | 21 | ||
22 | import javax.annotation.Resource; | ||
22 | import java.sql.Timestamp; | 23 | import java.sql.Timestamp; |
23 | import java.time.LocalDateTime; | 24 | import java.time.LocalDateTime; |
25 | import java.util.HashMap; | ||
24 | import java.util.List; | 26 | import java.util.List; |
27 | import java.util.Map; | ||
25 | import java.util.Objects; | 28 | import java.util.Objects; |
29 | import java.util.concurrent.ConcurrentHashMap; | ||
26 | import java.util.concurrent.locks.ReentrantLock; | 30 | import java.util.concurrent.locks.ReentrantLock; |
27 | 31 | ||
28 | 32 | ||
... | @@ -41,11 +45,11 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -41,11 +45,11 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
41 | RightsOperationService rightsOperationService; | 45 | RightsOperationService rightsOperationService; |
42 | @Autowired | 46 | @Autowired |
43 | RedissonClient redissonClient; | 47 | RedissonClient redissonClient; |
44 | @Autowired | 48 | @Resource(name = "executorTask") |
45 | ThreadPoolTaskExecutor threadPoolTaskExecutor; | 49 | ThreadPoolTaskExecutor threadPoolTaskExecutor; |
46 | 50 | ||
47 | // 过期阀值(默认一个月) | 51 | // 过期阀值(默认一个月) |
48 | private static final Integer EXPIRE_FACTOR_MONTH = 1; | 52 | private static final Integer EXPIRE_FACTOR_DAY = 30; |
49 | 53 | ||
50 | 54 | ||
51 | 55 | ||
... | @@ -80,10 +84,10 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -80,10 +84,10 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
80 | * @param tempCoupon 领取的优惠券 | 84 | * @param tempCoupon 领取的优惠券 |
81 | */ | 85 | */ |
82 | private void refresh(TempCoupon tempCoupon) { | 86 | private void refresh(TempCoupon tempCoupon) { |
83 | // 1.保存优惠券领取、使用历史记录表 | 87 | // 1.更新会员优惠券数量 |
84 | this.threadPoolTaskExecutor.execute(()->this.doInsertCouponHistory(tempCoupon)); | ||
85 | // 2.更新会员优惠券数量 | ||
86 | this.refreshMemberCoupon(tempCoupon); | 88 | this.refreshMemberCoupon(tempCoupon); |
89 | // 2.保存优惠券领取、使用历史记录表 | ||
90 | this.doInsertCouponHistory(tempCoupon); | ||
87 | } | 91 | } |
88 | 92 | ||
89 | 93 | ||
... | @@ -92,17 +96,20 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -92,17 +96,20 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
92 | * @param tempCoupon 账号id | 96 | * @param tempCoupon 账号id |
93 | */ | 97 | */ |
94 | private void refreshMemberCoupon(TempCoupon tempCoupon) { | 98 | private void refreshMemberCoupon(TempCoupon tempCoupon) { |
95 | Long userId = tempCoupon.getUserId(); | 99 | // Long userId = tempCoupon.getUserId(); |
96 | Long memberId = tempCoupon.getMemberId(); | 100 | Long memberId = tempCoupon.getMemberId(); |
97 | RLock rLock = this.redissonClient.getLock("refreshMemberCoupon:" + memberId.toString()); | 101 | Integer rightsAmount = tempCoupon.getRightsAmount(); |
102 | // RLock rLock = this.redissonClient.getLock("refreshMemberCoupon:" + memberId.toString()); | ||
98 | try { | 103 | try { |
99 | RedissonUtil.lock(rLock); | 104 | // RedissonUtil.lock(rLock); |
100 | // 1.获取用户领取的总优惠券 | 105 | // 1.历史总优惠券数量 |
101 | Long totalCouponCount = this.getTotalCoupon(userId); | 106 | Long historyCouponCount = this.getTotalHistoryCoupon(memberId); |
107 | // 1.当前总优惠券数量 | ||
108 | Long totalCouponCount = this.getTotalCoupon(historyCouponCount,rightsAmount); | ||
102 | // 2.获取已过期的优惠券数量 | 109 | // 2.获取已过期的优惠券数量 |
103 | Long expireCouponCount = this.getTotalExpireCoupon(userId); | 110 | Long expireCouponCount = this.getTotalExpireCoupon(memberId); |
104 | // 3.即将过期的优惠券数量 | 111 | // 3.即将过期的优惠券数量 |
105 | Long expireSoonCouponCount = this.getTotalExpireSoonCoupon(userId,EXPIRE_FACTOR_MONTH); | 112 | Long expireSoonCouponCount = this.getTotalExpireSoonCoupon(memberId,EXPIRE_FACTOR_DAY); |
106 | // 4.当前优惠券数量 = 总优惠券-已过期的优惠券 | 113 | // 4.当前优惠券数量 = 总优惠券-已过期的优惠券 |
107 | Long currentCoupon = this.getCurrentCoupon(totalCouponCount,expireCouponCount); | 114 | Long currentCoupon = this.getCurrentCoupon(totalCouponCount,expireCouponCount); |
108 | // 5.更新用户信息(优惠券数量、即将过期的优惠券数量) | 115 | // 5.更新用户信息(优惠券数量、即将过期的优惠券数量) |
... | @@ -111,10 +118,14 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -111,10 +118,14 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
111 | e.printStackTrace(); | 118 | e.printStackTrace(); |
112 | throw e; | 119 | throw e; |
113 | } finally { | 120 | } finally { |
114 | RedissonUtil.unlock(rLock); | 121 | // RedissonUtil.unlock(rLock); |
115 | } | 122 | } |
116 | } | 123 | } |
117 | 124 | ||
125 | private Long getTotalCoupon(Long historyCouponCount, Integer rightsAmount) { | ||
126 | return (Objects.nonNull(historyCouponCount) ? historyCouponCount: 0L) + (Objects.nonNull(rightsAmount) ? rightsAmount: 0L); | ||
127 | } | ||
128 | |||
118 | 129 | ||
119 | /** | 130 | /** |
120 | * 更新当前用户优惠券信息 | 131 | * 更新当前用户优惠券信息 |
... | @@ -149,28 +160,7 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -149,28 +160,7 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
149 | * @return | 160 | * @return |
150 | */ | 161 | */ |
151 | private Long getTotalExpireSoonCoupon(Long userId, Integer expireFactor) { | 162 | private Long getTotalExpireSoonCoupon(Long userId, Integer expireFactor) { |
152 | LocalDateTime localDateTime = LocalDateTime.now(); | 163 | Timestamp expireTime = TimestampUtil.localDateTime2Timestamp1(LocalDateTime.now().plusDays(expireFactor)); |
153 | String s = EXPIRE_FACTOR_MONTH.toString(); | ||
154 | String[] s1 = s.split("_"); | ||
155 | String s2 = s1[s1.length-1]; | ||
156 | switch (s2) { | ||
157 | case "YEAR": | ||
158 | localDateTime.plusYears(expireFactor); | ||
159 | break; | ||
160 | case "MONTH": | ||
161 | localDateTime.plusMonths(expireFactor); | ||
162 | break; | ||
163 | case "DAY": | ||
164 | localDateTime.plusDays(expireFactor); | ||
165 | break; | ||
166 | case "HOUR": | ||
167 | localDateTime.plusHours(expireFactor); | ||
168 | break; | ||
169 | default: | ||
170 | break; | ||
171 | } | ||
172 | |||
173 | Timestamp expireTime = TimestampUtil.now(localDateTime); | ||
174 | return this.couponHistoryService.countByUserIdAndExpireTimeBetween(userId,TimestampUtil.now(),expireTime); | 164 | return this.couponHistoryService.countByUserIdAndExpireTimeBetween(userId,TimestampUtil.now(),expireTime); |
175 | } | 165 | } |
176 | 166 | ||
... | @@ -190,7 +180,7 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -190,7 +180,7 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
190 | * @param userId | 180 | * @param userId |
191 | * @return | 181 | * @return |
192 | */ | 182 | */ |
193 | private Long getTotalCoupon(Long userId) { | 183 | private Long getTotalHistoryCoupon(Long userId) { |
194 | return this.couponHistoryService.countByUserId(userId); | 184 | return this.couponHistoryService.countByUserId(userId); |
195 | } | 185 | } |
196 | 186 | ||
... | @@ -204,10 +194,12 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -204,10 +194,12 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
204 | BeanUtils.copyProperties(tempCoupon,couponHistory); | 194 | BeanUtils.copyProperties(tempCoupon,couponHistory); |
205 | couponHistory.setId(null); | 195 | couponHistory.setId(null); |
206 | couponHistory.setCouponId(tempCoupon.getId()); | 196 | couponHistory.setCouponId(tempCoupon.getId()); |
207 | couponHistory.setUserId(tempCoupon.getUserId()); | 197 | couponHistory.setUserId(tempCoupon.getMemberId()); |
208 | couponHistory.setCouponCode(tempCoupon.getCode()); | 198 | couponHistory.setCouponCode(tempCoupon.getCode()); |
209 | couponHistory.setUserNickname(tempCoupon.getUserNickname()); | 199 | couponHistory.setUserNickname(tempCoupon.getUserNickname()); |
210 | couponHistory.setOrderDetailId(tempCoupon.getOrderId()); | 200 | couponHistory.setOrderDetailId(tempCoupon.getOrderId()); |
201 | couponHistory.setReceiveTime(TimestampUtil.now()); | ||
202 | couponHistory.setUseStatus(Objects.nonNull(couponHistory.getUseStatus()) ? couponHistory.getUseStatus():0); | ||
211 | this.couponHistoryService.create(couponHistory); | 203 | this.couponHistoryService.create(couponHistory); |
212 | } | 204 | } |
213 | 205 | ... | ... |
... | @@ -75,19 +75,18 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -75,19 +75,18 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
75 | * @param tempExp | 75 | * @param tempExp |
76 | */ | 76 | */ |
77 | private void refresh(TempExp tempExp) { | 77 | private void refresh(TempExp tempExp) { |
78 | RLock lock = this.redissonClient.getLock("refresh_exp:" + tempExp.getMemberId()); | 78 | RLock lock = this.redissonClient.getLock("uc-refresh-exp:" + tempExp.getMemberId()); |
79 | try { | 79 | try { |
80 | RedissonUtil.lock(lock); | 80 | RedissonUtil.lock(lock); |
81 | // 原始积分 | 81 | // 原始积分 |
82 | long originExp = this.getExpByMemberId(tempExp); | 82 | long originExp = this.getExpByMemberId(tempExp); |
83 | // 总积分 | 83 | // 总积分 |
84 | long totalExp = this.calculateTotalExp(originExp, tempExp); | 84 | long totalExp = this.calculateTotalExp(originExp, tempExp); |
85 | |||
86 | // 1.添加成长值记录 | 85 | // 1.添加成长值记录 |
87 | this.threadPoolTaskExecutor.execute(() -> this.doInsertExpDetail(tempExp, originExp, totalExp)); | 86 | this.threadPoolTaskExecutor.execute(() -> this.doInsertExpDetail(tempExp, originExp, totalExp)); |
87 | // this.doInsertExpDetail(tempExp, originExp, totalExp); | ||
88 | // 2.更新成长值与等级 | 88 | // 2.更新成长值与等级 |
89 | this.refreshMemberExpAndLevel(tempExp); | 89 | this.refreshMemberExpAndLevel(tempExp,totalExp); |
90 | |||
91 | } catch (Exception e) { | 90 | } catch (Exception e) { |
92 | e.printStackTrace(); | 91 | e.printStackTrace(); |
93 | throw e; | 92 | throw e; |
... | @@ -98,7 +97,7 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -98,7 +97,7 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
98 | 97 | ||
99 | private long calculateTotalExp(long originalExp,TempExp tempExp) { | 98 | private long calculateTotalExp(long originalExp,TempExp tempExp) { |
100 | Long rewardExp = tempExp.getRewardExp(); | 99 | Long rewardExp = tempExp.getRewardExp(); |
101 | return (Objects.nonNull(rewardExp) ? rewardExp : 0L) + (Objects.nonNull(originalExp) ? originalExp : 0L); | 100 | return rewardExp + originalExp; |
102 | } | 101 | } |
103 | 102 | ||
104 | private long getExpByMemberId(TempExp tempExp) { | 103 | private long getExpByMemberId(TempExp tempExp) { |
... | @@ -114,57 +113,53 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -114,57 +113,53 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
114 | * | 113 | * |
115 | * @param tempExp 成长值列表 | 114 | * @param tempExp 成长值列表 |
116 | */ | 115 | */ |
117 | private void refreshMemberExpAndLevel(TempExp tempExp) { | 116 | private void refreshMemberExpAndLevel(TempExp tempExp,long totalExp) { |
118 | 117 | ||
119 | Long memberId = tempExp.getMemberId(); | 118 | Long memberId = tempExp.getMemberId(); |
120 | 119 | ||
121 | RLock rLock = this.redissonClient.getLock("refreshMemberExpAndLevel" + memberId.toString()); | 120 | // RLock rLock = this.redissonClient.getLock("refresh" + memberId.toString()); |
122 | try { | 121 | try { |
123 | RedissonUtil.lock(rLock); | 122 | // RedissonUtil.lock(rLock); |
124 | // 1.获取当前成长值 | 123 | // 1.获取当前成长值 |
125 | MemberDTO memberDTO = this.getMemberInfoByMemberId(memberId); | 124 | MemberDTO memberDTO = this.getMemberInfoByMemberId(memberId); |
126 | // 2.获取下一级需要的成长值 | 125 | // 2.获取下一级需要的成长值 |
127 | MemberLevelDTO memberLevelDTO = this.getNextLevelExp(memberDTO.getLevel() + 1, 1); | 126 | MemberLevelDTO memberLevelDTO = this.getNextLevelExp(memberDTO.getLevel() + 1, 1); |
128 | // 3.成长值累加 | ||
129 | Long newExp = memberDTO.getExp() + tempExp.getRewardExp(); | ||
130 | // 4.成长值比较,判断是否升级 | 127 | // 4.成长值比较,判断是否升级 |
131 | long i = this.compareExp(newExp, memberLevelDTO); | 128 | Integer level = this.compareExp(totalExp, memberLevelDTO,memberDTO); |
132 | // 5.更新用户信息 | 129 | // 5.更新用户信息 |
133 | this.updateMemberInfo(i, newExp, memberLevelDTO, memberId); | 130 | this.updateMemberInfo(level, totalExp, memberId); |
134 | } catch (Exception e) { | 131 | } catch (Exception e) { |
135 | e.printStackTrace(); | 132 | e.printStackTrace(); |
136 | throw e; | 133 | throw e; |
137 | } finally { | 134 | } finally { |
138 | RedissonUtil.unlock(rLock); | 135 | // RedissonUtil.unlock(rLock); |
139 | } | 136 | } |
140 | } | 137 | } |
141 | 138 | ||
142 | /** | 139 | /** |
143 | * | 140 | * |
144 | * @param i | 141 | * @param level |
145 | * @param newExp 总积分 | 142 | * @param totalExp 总积分 |
146 | * @param memberLevelDTO 下一级 | ||
147 | * @param memberId 会员id | 143 | * @param memberId 会员id |
148 | */ | 144 | */ |
149 | private void updateMemberInfo(long i,Long newExp,MemberLevelDTO memberLevelDTO,Long memberId) { | 145 | private void updateMemberInfo(Integer level,Long totalExp,Long memberId) { |
150 | Member member = new Member(); | 146 | Member member = new Member(); |
151 | member.setId(memberId); | 147 | member.setId(memberId); |
152 | member.setExp(newExp); | 148 | member.setExp(totalExp); |
153 | if (i > 0) { | 149 | member.setLevel(level); |
154 | Integer level = memberLevelDTO.getLevel(); | ||
155 | member.setLevel(level); | ||
156 | } | ||
157 | member.setUpdateTime(TimestampUtil.now()); | 150 | member.setUpdateTime(TimestampUtil.now()); |
158 | this.memberOperationService.doUpdateMemberInfo(member); | 151 | this.memberOperationService.doUpdateMemberInfo(member); |
159 | } | 152 | } |
160 | 153 | ||
161 | private long compareExp(long newExp, MemberLevelDTO memberLevelDTO) { | 154 | private Integer compareExp(long newExp, MemberLevelDTO memberLevelDTO,MemberDTO memberDTO) { |
162 | if (Objects.nonNull(memberLevelDTO)) { | 155 | if (Objects.nonNull(memberLevelDTO)) { |
163 | Long nextLevelExp = memberLevelDTO.getExpValue(); | 156 | Long nextLevelExp = memberLevelDTO.getExpValue(); |
164 | if (Objects.nonNull(nextLevelExp) && nextLevelExp > 0) | 157 | if (Objects.nonNull(nextLevelExp) && nextLevelExp > 0) |
165 | return newExp - nextLevelExp; | 158 | if(newExp - nextLevelExp >= 0){ |
159 | return memberLevelDTO.getLevel(); | ||
160 | } | ||
166 | } | 161 | } |
167 | return -1; | 162 | return memberDTO.getLevel(); |
168 | } | 163 | } |
169 | 164 | ||
170 | private MemberLevelDTO getNextLevelExp(Integer i,Integer status) { | 165 | private MemberLevelDTO getNextLevelExp(Integer i,Integer status) { |
... | @@ -200,7 +195,7 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -200,7 +195,7 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
200 | 195 | ||
201 | expDetail.setCode(String.valueOf(IdWorker.generator())); | 196 | expDetail.setCode(String.valueOf(IdWorker.generator())); |
202 | // 原始积分 | 197 | // 原始积分 |
203 | expDetail.setOriginalExp(Objects.nonNull(originalExp) ? originalExp : 0L); | 198 | expDetail.setOriginalExp(originalExp); |
204 | // 总积分 | 199 | // 总积分 |
205 | expDetail.setResultExp(totalExp); | 200 | expDetail.setResultExp(totalExp); |
206 | // 获得的积分 | 201 | // 获得的积分 | ... | ... |
... | @@ -344,19 +344,24 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -344,19 +344,24 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
344 | */ | 344 | */ |
345 | private void refresh(TempPoints tempPoints) { | 345 | private void refresh(TempPoints tempPoints) { |
346 | Long memberId = tempPoints.getMemberId(); | 346 | Long memberId = tempPoints.getMemberId(); |
347 | RLock rLock = this.redissonClient.getLock("refresh_point:" + memberId.toString()); | 347 | RLock rLock = this.redissonClient.getLock("uc-refresh-points:" + memberId.toString()); |
348 | try { | 348 | try { |
349 | RedissonUtil.lock(rLock); | 349 | RedissonUtil.lock(rLock); |
350 | // 1.可用总积分 | 350 | // 1.可用总积分 |
351 | long currentPoints = this.findAvailablePointsByMemberId(memberId); | 351 | long currentPoints = this.findAvailablePointsByMemberId(memberId); |
352 | // 2.计算总积分 | 352 | // 2.计算总积分 |
353 | long totalPoints = this.calculateTotalPoints(tempPoints, currentPoints); | 353 | long totalPoints = this.calculateTotalPoints(tempPoints, currentPoints); |
354 | // 2.添加积分明细,并计算总积分 | 354 | |
355 | // 3.添加积分明细,并计算总积分 | ||
355 | this.threadPoolTaskExecutor.execute(()->this.doInsertTrPointsDetail(memberId, tempPoints, currentPoints,totalPoints)); | 356 | this.threadPoolTaskExecutor.execute(()->this.doInsertTrPointsDetail(memberId, tempPoints, currentPoints,totalPoints)); |
356 | // 4.更新会员的总积分 | 357 | // this.doInsertTrPointsDetail(memberId, tempPoints, currentPoints,totalPoints); |
357 | this.freshMemberCurrentPoints(memberId, totalPoints); | 358 | |
358 | // 5.添加可用积分 | 359 | // 4.添加可用积分 |
359 | this.doInsertTrPointsAvailable(tempPoints); | 360 | this.doInsertTrPointsAvailable(tempPoints); |
361 | |||
362 | // 6.更新会员的总积分 | ||
363 | this.freshMemberCurrentPoints(memberId, totalPoints); | ||
364 | |||
360 | } catch (Exception e) { | 365 | } catch (Exception e) { |
361 | e.printStackTrace(); | 366 | e.printStackTrace(); |
362 | throw e; | 367 | throw e; |
... | @@ -468,21 +473,13 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -468,21 +473,13 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
468 | * @param tempPoints 积分 | 473 | * @param tempPoints 积分 |
469 | * @return Integer 总积分 | 474 | * @return Integer 总积分 |
470 | */ | 475 | */ |
471 | private void doInsertTrPointsDetail(Long memberId, TempPoints tempPoints,long totalPoints,long currentPoints){ | 476 | private void doInsertTrPointsDetail(Long memberId, TempPoints tempPoints,long currentPoints,long totalPoints){ |
472 | 477 | ||
473 | PointsDetail pointsDetail = new PointsDetail(); | 478 | PointsDetail pointsDetail = new PointsDetail(); |
474 | BeanUtils.copyProperties(tempPoints,pointsDetail); | 479 | BeanUtils.copyProperties(tempPoints,pointsDetail); |
475 | |||
476 | /* // 获取的积分 | ||
477 | long rewardPoints = tempPoints.getPoints(); | ||
478 | // 原始积分 | ||
479 | long originalPoints = currentPoints; | ||
480 | // 总积分 | ||
481 | long totalPoints = originalPoints + rewardPoints;*/ | ||
482 | |||
483 | pointsDetail.setMemberId(memberId); | 480 | pointsDetail.setMemberId(memberId); |
484 | pointsDetail.setCode(String.valueOf(IdWorker.generator())); | 481 | pointsDetail.setCode(String.valueOf(IdWorker.generator())); |
485 | 482 | pointsDetail.setPoints(tempPoints.getPoints()); | |
486 | pointsDetail.setOriginalPoints(currentPoints); | 483 | pointsDetail.setOriginalPoints(currentPoints); |
487 | pointsDetail.setResultPoints(totalPoints); | 484 | pointsDetail.setResultPoints(totalPoints); |
488 | String description = pointsDetail.getDescription(); | 485 | String description = pointsDetail.getDescription(); | ... | ... |
... | @@ -17,10 +17,12 @@ import org.springframework.beans.factory.annotation.Autowired; | ... | @@ -17,10 +17,12 @@ import org.springframework.beans.factory.annotation.Autowired; |
17 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | 17 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
18 | import org.springframework.stereotype.Service; | 18 | import org.springframework.stereotype.Service; |
19 | import org.springframework.util.CollectionUtils; | 19 | import org.springframework.util.CollectionUtils; |
20 | import org.springframework.util.StringUtils; | ||
20 | 21 | ||
21 | import javax.annotation.Resource; | 22 | import javax.annotation.Resource; |
22 | import java.sql.Timestamp; | 23 | import java.sql.Timestamp; |
23 | import java.util.*; | 24 | import java.util.*; |
25 | import java.util.concurrent.Future; | ||
24 | 26 | ||
25 | /** | 27 | /** |
26 | * 权益处理 | 28 | * 权益处理 |
... | @@ -144,24 +146,14 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -144,24 +146,14 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
144 | */ | 146 | */ |
145 | private void refresh(Map<RightType, Object> tempRightsMap) { | 147 | private void refresh(Map<RightType, Object> tempRightsMap) { |
146 | 148 | ||
147 | this.threadPoolTaskExecutor.execute(()->{ | 149 | this.threadPoolTaskExecutor.submit(() -> { |
148 | // 积分 | 150 | // 积分 |
149 | this.grantPoint((List<TempPoints>)tempRightsMap.get(RightType.POINTS)); | 151 | this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS)); |
152 | // 成长值 | ||
153 | this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP)); | ||
154 | // 优惠券 | ||
155 | this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON)); | ||
150 | }); | 156 | }); |
151 | |||
152 | this.threadPoolTaskExecutor.execute(()->{ | ||
153 | // 成长值 | ||
154 | this.grantExp((List<TempExp>)tempRightsMap.get(RightType.EXP)); | ||
155 | }); | ||
156 | |||
157 | this.threadPoolTaskExecutor.execute(()->{ | ||
158 | // 优惠券 | ||
159 | this.grantCoupon((List<TempCoupon>)tempRightsMap.get(RightType.COUPON)); | ||
160 | }); | ||
161 | |||
162 | /*this.grantPoint((List<TempPoints>)tempRightsMap.get(RightType.POINTS)); | ||
163 | this.grantExp((List<TempExp>)tempRightsMap.get(RightType.EXP)); | ||
164 | this.grantCoupon((List<TempCoupon>)tempRightsMap.get(RightType.COUPON));*/ | ||
165 | } | 157 | } |
166 | 158 | ||
167 | /** | 159 | /** |
... | @@ -260,8 +252,11 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -260,8 +252,11 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
260 | if (!CollectionUtils.isEmpty(rightsHistories)) { | 252 | if (!CollectionUtils.isEmpty(rightsHistories)) { |
261 | 253 | ||
262 | for (RightsHistory rightsHistory : rightsHistories) { | 254 | for (RightsHistory rightsHistory : rightsHistories) { |
255 | Long operatorId = rightsHistory.getOperatorId(); | ||
256 | String operatorName = rightsHistory.getOperatorName(); | ||
263 | rightsHistory.setSendTime(TimestampUtil.now()); | 257 | rightsHistory.setSendTime(TimestampUtil.now()); |
264 | 258 | rightsHistory.setOperatorId(Objects.nonNull(operatorId)?operatorId:0); | |
259 | rightsHistory.setOperatorName(!StringUtils.isEmpty(operatorName)?operatorName:"系统发放"); | ||
265 | this.rightsHistoryService.create(rightsHistory); | 260 | this.rightsHistoryService.create(rightsHistory); |
266 | } | 261 | } |
267 | 262 | ... | ... |
... | @@ -24,22 +24,17 @@ import com.topdraw.util.*; | ... | @@ -24,22 +24,17 @@ import com.topdraw.util.*; |
24 | import lombok.extern.slf4j.Slf4j; | 24 | import lombok.extern.slf4j.Slf4j; |
25 | import org.slf4j.Logger; | 25 | import org.slf4j.Logger; |
26 | import org.slf4j.LoggerFactory; | 26 | import org.slf4j.LoggerFactory; |
27 | import org.springframework.beans.BeanUtils; | ||
27 | import org.springframework.beans.factory.annotation.Autowired; | 28 | import org.springframework.beans.factory.annotation.Autowired; |
28 | import org.springframework.cache.annotation.CacheEvict; | ||
29 | import org.springframework.cache.annotation.Cacheable; | ||
30 | import org.springframework.cache.annotation.EnableCaching; | ||
31 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
32 | import org.springframework.stereotype.Service; | 29 | import org.springframework.stereotype.Service; |
33 | import org.springframework.util.CollectionUtils; | 30 | import org.springframework.util.CollectionUtils; |
34 | import org.springframework.util.StringUtils; | 31 | import org.springframework.util.StringUtils; |
35 | 32 | ||
36 | import javax.annotation.Resource; | ||
37 | import java.math.BigDecimal; | 33 | import java.math.BigDecimal; |
38 | import java.math.RoundingMode; | 34 | import java.math.RoundingMode; |
39 | import java.sql.Timestamp; | 35 | import java.sql.Timestamp; |
40 | import java.time.LocalDate; | 36 | import java.time.LocalDate; |
41 | import java.util.*; | 37 | import java.util.*; |
42 | import java.util.concurrent.locks.ReentrantLock; | ||
43 | import java.util.concurrent.locks.ReentrantReadWriteLock; | 38 | import java.util.concurrent.locks.ReentrantReadWriteLock; |
44 | import java.util.stream.Collectors; | 39 | import java.util.stream.Collectors; |
45 | 40 | ||
... | @@ -56,21 +51,19 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -56,21 +51,19 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
56 | private static final Logger LOG = LoggerFactory.getLogger(PointsOperationServiceImpl.class); | 51 | private static final Logger LOG = LoggerFactory.getLogger(PointsOperationServiceImpl.class); |
57 | 52 | ||
58 | @Autowired | 53 | @Autowired |
59 | private TaskService taskService; | 54 | TaskService taskService; |
60 | @Autowired | 55 | @Autowired |
61 | private MemberService memberService; | 56 | MemberService memberService; |
62 | @Autowired | 57 | @Autowired |
63 | private RightsService rightsService; | 58 | RightsService rightsService; |
64 | @Autowired | 59 | @Autowired |
65 | private TaskTemplateService taskTemplateService; | 60 | TaskTemplateService taskTemplateService; |
66 | @Autowired | 61 | @Autowired |
67 | private RightsOperationService rightsOperationService; | 62 | RightsOperationService rightsOperationService; |
68 | @Autowired | 63 | @Autowired |
69 | private TrTaskProgressService trTaskProgressService; | 64 | TrTaskProgressService trTaskProgressService; |
70 | @Autowired | 65 | @Autowired |
71 | private PermanentRightsService permanentRightsService; | 66 | PermanentRightsService permanentRightsService; |
72 | |||
73 | private ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock(); | ||
74 | 67 | ||
75 | private static final Integer TASK_FINISH_STATUS = 1; | 68 | private static final Integer TASK_FINISH_STATUS = 1; |
76 | private static final Integer TASK_UNFINISH_STATUS = 2; | 69 | private static final Integer TASK_UNFINISH_STATUS = 2; |
... | @@ -87,10 +80,10 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -87,10 +80,10 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
87 | 80 | ||
88 | long l = System.currentTimeMillis(); | 81 | long l = System.currentTimeMillis(); |
89 | // 验证会员信息 | 82 | // 验证会员信息 |
90 | boolean b = this.validatedMember(memberId); | 83 | /*boolean b = this.validatedMember(memberId); |
91 | if (b) { | 84 | if (!b) { |
92 | throw new BadRequestException("【member status exception!!】"); | 85 | throw new BadRequestException("【member status exception!!】"); |
93 | } | 86 | }*/ |
94 | 87 | ||
95 | // 1.通过任务标识获取任务模板,通过模板参数获取具体的模板 | 88 | // 1.通过任务标识获取任务模板,通过模板参数获取具体的模板 |
96 | TaskTemplate taskTemplate = this.getTaskTemplate(event); | 89 | TaskTemplate taskTemplate = this.getTaskTemplate(event); |
... | @@ -101,10 +94,8 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -101,10 +94,8 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
101 | if (checkResult) { | 94 | if (checkResult) { |
102 | // 5.权益区分(积分、权益、成长值) | 95 | // 5.权益区分(积分、权益、成长值) |
103 | Map<RightType,Object> tempRightsMap = this.distinguishRight(memberId,taskList,msgData); | 96 | Map<RightType,Object> tempRightsMap = this.distinguishRight(memberId,taskList,msgData); |
104 | |||
105 | // 6.权益发放 | 97 | // 6.权益发放 |
106 | this.grantRight(tempRightsMap); | 98 | this.grantRight(tempRightsMap); |
107 | |||
108 | } | 99 | } |
109 | 100 | ||
110 | long r = System.currentTimeMillis(); | 101 | long r = System.currentTimeMillis(); |
... | @@ -120,12 +111,13 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -120,12 +111,13 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
120 | private boolean validatedMember(Long memberId) { | 111 | private boolean validatedMember(Long memberId) { |
121 | log.info("validatedMember -->>【memberId】 -->> " + memberId); | 112 | log.info("validatedMember -->>【memberId】 -->> " + memberId); |
122 | MemberDTO memberDTO = this.memberService.findById(memberId); | 113 | MemberDTO memberDTO = this.memberService.findById(memberId); |
123 | Integer blackStatus = memberDTO.getBlackStatus(); | 114 | Long blackStatus = memberDTO.getBlackStatus(); |
124 | if (Objects.nonNull(blackStatus) && blackStatus == 1) { | 115 | // TODO 检查balckStatus无法获取的原因 |
125 | log.error("validatedMember -->> 会员已被加入黑名单 【blackStatus】 -->> " + blackStatus); | 116 | if (Objects.isNull(blackStatus) || blackStatus == 1) { |
117 | log.error("validatedMember -->> 会员不存在或者已被加入黑名单 【blackStatus】 -->> " + blackStatus); | ||
126 | return false; | 118 | return false; |
127 | } | 119 | } |
128 | return Objects.nonNull(memberDTO) ? true:false; | 120 | return true; |
129 | } | 121 | } |
130 | 122 | ||
131 | /** | 123 | /** |
... | @@ -133,6 +125,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -133,6 +125,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
133 | * @param memberId 会员id | 125 | * @param memberId 会员id |
134 | * @return PermanentRightsDTO 永久权益 | 126 | * @return PermanentRightsDTO 永久权益 |
135 | */ | 127 | */ |
128 | @Deprecated | ||
136 | private PermanentRightsDTO getPermanentRights(Long memberId) { | 129 | private PermanentRightsDTO getPermanentRights(Long memberId) { |
137 | PermanentRightsDTO permanentRights = null; | 130 | PermanentRightsDTO permanentRights = null; |
138 | MemberDTO memberDTO = this.memberService.findById(memberId); | 131 | MemberDTO memberDTO = this.memberService.findById(memberId); |
... | @@ -149,6 +142,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -149,6 +142,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
149 | * @param taskTemplate 任务模板 | 142 | * @param taskTemplate 任务模板 |
150 | * @return Map<String, Object> 模板参数解析结果 | 143 | * @return Map<String, Object> 模板参数解析结果 |
151 | */ | 144 | */ |
145 | @Deprecated | ||
152 | private Map<String, Object> parseTaskTemplateParam(TaskTemplate taskTemplate) { | 146 | private Map<String, Object> parseTaskTemplateParam(TaskTemplate taskTemplate) { |
153 | if (Objects.nonNull(taskTemplate)) { | 147 | if (Objects.nonNull(taskTemplate)) { |
154 | String params = taskTemplate.getParams(); | 148 | String params = taskTemplate.getParams(); |
... | @@ -166,19 +160,11 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -166,19 +160,11 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
166 | */ | 160 | */ |
167 | private void doRefreshTrTaskProcess(TrTaskProgress resources) { | 161 | private void doRefreshTrTaskProcess(TrTaskProgress resources) { |
168 | Long id = resources.getId(); | 162 | Long id = resources.getId(); |
169 | ReentrantReadWriteLock.WriteLock writeLock = this.reentrantReadWriteLock.writeLock(); | 163 | if (Objects.nonNull(id)) { |
170 | try { | 164 | resources.setUpdateTime(TimestampUtil.now()); |
171 | writeLock.lock(); | 165 | this.trTaskProgressService.update(resources); |
172 | if (Objects.nonNull(id)) { | 166 | } else { |
173 | resources.setUpdateTime(TimestampUtil.now()); | 167 | this.trTaskProgressService.create(resources); |
174 | this.trTaskProgressService.update(resources); | ||
175 | } else { | ||
176 | this.trTaskProgressService.create(resources); | ||
177 | } | ||
178 | } catch (Exception e) { | ||
179 | e.printStackTrace(); | ||
180 | } finally { | ||
181 | writeLock.unlock(); | ||
182 | } | 168 | } |
183 | } | 169 | } |
184 | 170 | ||
... | @@ -326,16 +312,15 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -326,16 +312,15 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
326 | /** | 312 | /** |
327 | * 创建权益 | 313 | * 创建权益 |
328 | * @param memberId | 314 | * @param memberId |
329 | * @param rightsId | ||
330 | * @param rightsAmount | 315 | * @param rightsAmount |
331 | * @param expireTime | ||
332 | * @return | 316 | * @return |
333 | */ | 317 | */ |
334 | private TempRights tmpRightsBuild(Long memberId ,Long rightsId, Integer rightsAmount,Long expireTime){ | 318 | private TempRights tmpRightsBuild(Long memberId ,Integer rightsAmount,RightsDTO rightsDTO){ |
335 | TempRights tempRights = new TempRights(); | 319 | TempRights tempRights = new TempRights(); |
320 | BeanUtils.copyProperties(rightsDTO,tempRights); | ||
336 | tempRights.setMemberId(memberId); | 321 | tempRights.setMemberId(memberId); |
337 | tempRights.setRightsAmount(rightsAmount); | 322 | tempRights.setRightsAmount(rightsAmount); |
338 | tempRights.setId(rightsId); | 323 | Long expireTime = rightsDTO.getExpireTime(); |
339 | if (Objects.nonNull(expireTime)) | 324 | if (Objects.nonNull(expireTime)) |
340 | tempRights.setExpireTime(TimestampUtil.long2Timestamp(expireTime)); | 325 | tempRights.setExpireTime(TimestampUtil.long2Timestamp(expireTime)); |
341 | return tempRights; | 326 | return tempRights; |
... | @@ -344,17 +329,17 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -344,17 +329,17 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
344 | /** | 329 | /** |
345 | * 优惠券 | 330 | * 优惠券 |
346 | * @param memberId | 331 | * @param memberId |
347 | * @param rightsId | ||
348 | * @param rightsAmount | 332 | * @param rightsAmount |
349 | * @param rightsSendStrategy | 333 | * @param rightsSendStrategy |
350 | * @return | 334 | * @return |
351 | */ | 335 | */ |
352 | private TempCoupon tempCouponBuild(Long memberId ,Long rightsId, Integer rightsAmount,Integer rightsSendStrategy){ | 336 | private TempCoupon tempCouponBuild(Long memberId ,Integer rightsAmount,Integer rightsSendStrategy,TempRights tempRights,String nickname){ |
353 | TempCoupon tempCoupon = new TempCoupon(); | 337 | TempCoupon tempCoupon = new TempCoupon(); |
338 | BeanUtils.copyProperties(tempRights,tempCoupon); | ||
354 | tempCoupon.setMemberId(memberId); | 339 | tempCoupon.setMemberId(memberId); |
355 | tempCoupon.setId(rightsId); | ||
356 | tempCoupon.setRightsAmount(rightsAmount); | 340 | tempCoupon.setRightsAmount(rightsAmount); |
357 | tempCoupon.setRightsSendStrategy(Objects.isNull(rightsSendStrategy) ? 0 : rightsSendStrategy); | 341 | tempCoupon.setRightsSendStrategy(Objects.isNull(rightsSendStrategy) ? 0 : rightsSendStrategy); |
342 | tempCoupon.setUserNickname(nickname); | ||
358 | return tempCoupon; | 343 | return tempCoupon; |
359 | } | 344 | } |
360 | 345 | ||
... | @@ -369,6 +354,8 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -369,6 +354,8 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
369 | List<TempCoupon> tempCouponList = new ArrayList<>(); | 354 | List<TempCoupon> tempCouponList = new ArrayList<>(); |
370 | // 权益列表,用以保存权益记录 | 355 | // 权益列表,用以保存权益记录 |
371 | List<TempRights> rightsList = new ArrayList<>(); | 356 | List<TempRights> rightsList = new ArrayList<>(); |
357 | // 会员信息 | ||
358 | MemberDTO memberDTO = this.findMemberById(memberId); | ||
372 | 359 | ||
373 | // 权益1 | 360 | // 权益1 |
374 | Long rights1Id = task.getRightsId(); | 361 | Long rights1Id = task.getRightsId(); |
... | @@ -378,7 +365,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -378,7 +365,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
378 | // TODO 权益1发放的策略 | 365 | // TODO 权益1发放的策略 |
379 | Integer rightsSendStrategy = task.getRightsSendStrategy(); | 366 | Integer rightsSendStrategy = task.getRightsSendStrategy(); |
380 | // 权益分类 | 367 | // 权益分类 |
381 | this.getTempRightType(memberId,rights1Id,rights1Amount,rightsSendStrategy,tempCouponList,rightsList); | 368 | this.getTempRightType(memberDTO,rights1Id,rights1Amount,rightsSendStrategy,tempCouponList,rightsList); |
382 | } | 369 | } |
383 | 370 | ||
384 | // 权益2 | 371 | // 权益2 |
... | @@ -388,7 +375,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -388,7 +375,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
388 | // TODO 权益2发放的策略 | 375 | // TODO 权益2发放的策略 |
389 | Integer rightsSendStrategy = task.getRightsSendStrategy(); | 376 | Integer rightsSendStrategy = task.getRightsSendStrategy(); |
390 | // 权权益分类 | 377 | // 权权益分类 |
391 | this.getTempRightType(memberId,rights2Id,rights2Amount,rightsSendStrategy,tempCouponList,rightsList); | 378 | this.getTempRightType(memberDTO,rights2Id,rights2Amount,rightsSendStrategy,tempCouponList,rightsList); |
392 | } | 379 | } |
393 | 380 | ||
394 | // 权益3 | 381 | // 权益3 |
... | @@ -398,7 +385,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -398,7 +385,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
398 | // TODO 权益3发放的策略 | 385 | // TODO 权益3发放的策略 |
399 | Integer rightsSendStrategy = task.getRightsSendStrategy(); | 386 | Integer rightsSendStrategy = task.getRightsSendStrategy(); |
400 | // 权益分类 | 387 | // 权益分类 |
401 | this.getTempRightType(memberId,rights3Id,rights3Amount,rightsSendStrategy,tempCouponList,rightsList); | 388 | this.getTempRightType(memberDTO,rights3Id,rights3Amount,rightsSendStrategy,tempCouponList,rightsList); |
402 | } | 389 | } |
403 | // 优惠券 | 390 | // 优惠券 |
404 | map.put(RightType.COUPON,tempCouponList); | 391 | map.put(RightType.COUPON,tempCouponList); |
... | @@ -406,26 +393,36 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -406,26 +393,36 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
406 | return map; | 393 | return map; |
407 | } | 394 | } |
408 | 395 | ||
396 | |||
409 | /** | 397 | /** |
410 | * 权益分类 | 398 | * 会员对象 |
411 | * @param memberId | 399 | * @param memberId |
400 | * @return | ||
401 | */ | ||
402 | private MemberDTO findMemberById(Long memberId) { | ||
403 | return this.memberService.findById(memberId); | ||
404 | } | ||
405 | |||
406 | /** | ||
407 | * 权益分类 | ||
408 | * @param memberDTO | ||
412 | * @param rightsId | 409 | * @param rightsId |
413 | * @param rightsAmount | 410 | * @param rightsAmount |
414 | * @param rightsSendStrategy | 411 | * @param rightsSendStrategy |
415 | * @param tempCouponList | 412 | * @param tempCouponList |
416 | * @param rightsList | 413 | * @param rightsList |
417 | */ | 414 | */ |
418 | private void getTempRightType(Long memberId , Long rightsId, Integer rightsAmount,Integer rightsSendStrategy,List<TempCoupon> tempCouponList, | 415 | private void getTempRightType(MemberDTO memberDTO , Long rightsId, Integer rightsAmount,Integer rightsSendStrategy,List<TempCoupon> tempCouponList, |
419 | List<TempRights> rightsList) { | 416 | List<TempRights> rightsList) { |
420 | 417 | ||
421 | 418 | Long memberId = memberDTO.getId(); | |
419 | String nickname = memberDTO.getNickname(); | ||
422 | // 权益详情 | 420 | // 权益详情 |
423 | RightsDTO rightsDTO = this.getRight(rightsId); | 421 | RightsDTO rightsDTO = this.getRight(rightsId); |
424 | 422 | ||
425 | if (Objects.nonNull(rightsDTO)){ | 423 | if (Objects.nonNull(rightsDTO)){ |
426 | // 用以保存权益历史 | 424 | // 用以保存权益历史 |
427 | Long expireTime = rightsDTO.getExpireTime(); | 425 | TempRights tempRights = this.tmpRightsBuild(memberId,rightsAmount,rightsDTO); |
428 | TempRights tempRights = this.tmpRightsBuild(memberId,rightsId,rightsAmount,expireTime); | ||
429 | rightsList.add(tempRights); | 426 | rightsList.add(tempRights); |
430 | 427 | ||
431 | // 权益类型 | 428 | // 权益类型 |
... | @@ -433,7 +430,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -433,7 +430,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
433 | switch (type) { | 430 | switch (type) { |
434 | case "1": | 431 | case "1": |
435 | // 优惠券 | 432 | // 优惠券 |
436 | TempCoupon tempCoupon = this.tempCouponBuild(memberId,rightsId,rightsAmount,rightsSendStrategy); | 433 | TempCoupon tempCoupon = this.tempCouponBuild(memberId,rightsAmount,rightsSendStrategy,tempRights,nickname); |
437 | tempCouponList.add(tempCoupon); | 434 | tempCouponList.add(tempCoupon); |
438 | break; | 435 | break; |
439 | default: | 436 | default: | ... | ... |
... | @@ -21,6 +21,10 @@ public class TimestampUtil { | ... | @@ -21,6 +21,10 @@ public class TimestampUtil { |
21 | return epochSecond; | 21 | return epochSecond; |
22 | } | 22 | } |
23 | 23 | ||
24 | public static Timestamp localDateTime2Timestamp1(LocalDateTime localDateTime){ | ||
25 | long epochSecond = localDateTime.atZone(ZoneOffset.systemDefault()).toEpochSecond(); | ||
26 | return long2Timestamp(epochSecond); | ||
27 | } | ||
24 | public static Timestamp long2Timestamp(long timestamp){ | 28 | public static Timestamp long2Timestamp(long timestamp){ |
25 | Timestamp timestamp1 = Timestamp.from(Instant.ofEpochSecond(timestamp)); | 29 | Timestamp timestamp1 = Timestamp.from(Instant.ofEpochSecond(timestamp)); |
26 | return timestamp1; | 30 | return timestamp1; | ... | ... |
... | @@ -13,7 +13,7 @@ public class MemberServiceTest extends BaseTest { | ... | @@ -13,7 +13,7 @@ public class MemberServiceTest extends BaseTest { |
13 | 13 | ||
14 | @Test | 14 | @Test |
15 | public void findById(){ | 15 | public void findById(){ |
16 | Long memberId = 1L; | 16 | Long memberId = 3L; |
17 | MemberDTO memberDTO = this.memberService.findById(memberId); | 17 | MemberDTO memberDTO = this.memberService.findById(memberId); |
18 | LOG.info("=====>>>" + memberDTO); | 18 | LOG.info("=====>>>" + memberDTO); |
19 | 19 | ... | ... |
... | @@ -21,12 +21,11 @@ public class ExpOperationControllerTest extends BaseTest { | ... | @@ -21,12 +21,11 @@ public class ExpOperationControllerTest extends BaseTest { |
21 | 21 | ||
22 | @Test | 22 | @Test |
23 | public void grantExpByManual(){ | 23 | public void grantExpByManual(){ |
24 | Long memberId = 2L; | 24 | Long memberId = 3L; |
25 | Long userId = 2L; | 25 | Long userId = 2L; |
26 | TempExp tempExp = new TempExp(); | 26 | TempExp tempExp = new TempExp(); |
27 | tempExp.setMemberId(memberId); | 27 | tempExp.setMemberId(memberId); |
28 | tempExp.setRewardExp(10L); | 28 | tempExp.setRewardExp(10L); |
29 | tempExp.setMemberId(2L); | ||
30 | tempExp.setRightsSendStrategy(0); | 29 | tempExp.setRightsSendStrategy(0); |
31 | tempExp.setAccountId(userId); | 30 | tempExp.setAccountId(userId); |
32 | tempExp.setExpireTime(Timestamp.valueOf("2021-10-28 09:00:00")); | 31 | tempExp.setExpireTime(Timestamp.valueOf("2021-10-28 09:00:00")); | ... | ... |
... | @@ -58,14 +58,14 @@ public class PointsOperationControllerTest extends BaseTest { | ... | @@ -58,14 +58,14 @@ public class PointsOperationControllerTest extends BaseTest { |
58 | tempPoints.setMemberId(3L); | 58 | tempPoints.setMemberId(3L); |
59 | tempPoints.setRightsSendStrategy(0); | 59 | tempPoints.setRightsSendStrategy(0); |
60 | tempPoints.setAccountId(2L); | 60 | tempPoints.setAccountId(2L); |
61 | tempPoints.setExpireTime(Timestamp.valueOf("2021-10-27 09:00:00")); | 61 | tempPoints.setExpireTime(Timestamp.valueOf("2021-11-27 09:00:00")); |
62 | tempPoints.setDeviceType(2); | 62 | tempPoints.setDeviceType(2); |
63 | tempPoints.setAppCode("WEI_XIN_GOLD_PANDA"); | 63 | tempPoints.setAppCode("WEI_XIN_GOLD_PANDA"); |
64 | tempPoints.setOrderId(null); | 64 | tempPoints.setOrderId(null); |
65 | tempPoints.setMediaId(null); | 65 | tempPoints.setMediaId(null); |
66 | tempPoints.setActivityId(null); | 66 | tempPoints.setActivityId(null); |
67 | tempPoints.setItemId(null); | 67 | tempPoints.setItemId(null); |
68 | tempPoints.setDescription("#"); | 68 | tempPoints.setDescription("系统发放"); |
69 | tempPoints.setEvtType(1); | 69 | tempPoints.setEvtType(1); |
70 | String s = JSON.toJSONString(tempPoints); | 70 | String s = JSON.toJSONString(tempPoints); |
71 | ResultInfo byId = this.pointsOperationController.grantPointsByManual(tempPoints); | 71 | ResultInfo byId = this.pointsOperationController.grantPointsByManual(tempPoints); | ... | ... |
... | @@ -18,7 +18,7 @@ public class RightOperationControllerTest extends BaseTest { | ... | @@ -18,7 +18,7 @@ public class RightOperationControllerTest extends BaseTest { |
18 | public void grantRightsByManual(){ | 18 | public void grantRightsByManual(){ |
19 | RightsHistory rightsHistory = new RightsHistory(); | 19 | RightsHistory rightsHistory = new RightsHistory(); |
20 | rightsHistory.setRightsId(1L); | 20 | rightsHistory.setRightsId(1L); |
21 | rightsHistory.setMemberId(5L); | 21 | rightsHistory.setMemberId(3L); |
22 | rightsHistory.setOperatorId(3L); | 22 | rightsHistory.setOperatorId(3L); |
23 | rightsHistory.setOperatorName("鲁二龙"); | 23 | rightsHistory.setOperatorName("鲁二龙"); |
24 | rightsHistory.setExpireTime(TimestampUtil.now()); | 24 | rightsHistory.setExpireTime(TimestampUtil.now()); | ... | ... |
-
Please register or sign in to post a comment