1.优化
Showing
14 changed files
with
79 additions
and
471 deletions
... | @@ -23,6 +23,9 @@ import java.time.LocalDateTime; | ... | @@ -23,6 +23,9 @@ import java.time.LocalDateTime; |
23 | @Table(name="m_coupon_history") | 23 | @Table(name="m_coupon_history") |
24 | public class CouponHistory implements Serializable { | 24 | public class CouponHistory implements Serializable { |
25 | 25 | ||
26 | @Transient | ||
27 | private String memberCode; | ||
28 | |||
26 | /** 主键 */ | 29 | /** 主键 */ |
27 | @Id | 30 | @Id |
28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 31 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ... | ... |
... | @@ -23,6 +23,9 @@ import java.sql.Timestamp; | ... | @@ -23,6 +23,9 @@ import java.sql.Timestamp; |
23 | @Table(name="uc_exp_detail") | 23 | @Table(name="uc_exp_detail") |
24 | public class ExpDetail implements Serializable { | 24 | public class ExpDetail implements Serializable { |
25 | 25 | ||
26 | @Transient | ||
27 | private String memberCode; | ||
28 | |||
26 | /** 主键 */ | 29 | /** 主键 */ |
27 | @Id | 30 | @Id |
28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 31 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ... | ... |
... | @@ -72,4 +72,10 @@ public interface MemberService { | ... | @@ -72,4 +72,10 @@ public interface MemberService { |
72 | * @param member 会员 | 72 | * @param member 会员 |
73 | */ | 73 | */ |
74 | MemberDTO checkMember(Member member); | 74 | MemberDTO checkMember(Member member); |
75 | |||
76 | /** | ||
77 | * | ||
78 | * @param resources | ||
79 | */ | ||
80 | MemberDTO doUpdateMemberExpAndLevel(Member resources); | ||
75 | } | 81 | } | ... | ... |
... | @@ -105,6 +105,12 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -105,6 +105,12 @@ public class MemberServiceImpl implements MemberService { |
105 | } | 105 | } |
106 | 106 | ||
107 | @Override | 107 | @Override |
108 | public MemberDTO doUpdateMemberExpAndLevel(Member resources) { | ||
109 | MemberDTO memberDTO = this.update(resources); | ||
110 | return memberDTO; | ||
111 | } | ||
112 | |||
113 | @Override | ||
108 | @Transactional(rollbackFor = Exception.class) | 114 | @Transactional(rollbackFor = Exception.class) |
109 | public MemberDTO create(Member resources) { | 115 | public MemberDTO create(Member resources) { |
110 | 116 | ... | ... |
1 | package com.topdraw.business.process.service; | 1 | package com.topdraw.business.process.service; |
2 | 2 | ||
3 | import com.topdraw.business.process.domian.TempCoupon; | ||
4 | |||
5 | import java.util.List; | ||
6 | |||
7 | /** | 3 | /** |
8 | * @description 权益操作接口 | 4 | * @description 权益操作接口 |
9 | * @author XiangHan | 5 | * @author XiangHan |
... | @@ -12,15 +8,4 @@ import java.util.List; | ... | @@ -12,15 +8,4 @@ import java.util.List; |
12 | 8 | ||
13 | public interface CouponOperationService { | 9 | public interface CouponOperationService { |
14 | 10 | ||
15 | /** | ||
16 | * 基于已完成的任务发放优惠券 | ||
17 | * @param tempCouponList | ||
18 | */ | ||
19 | void grantCouponThroughTempCoupon(List<TempCoupon> tempCouponList); | ||
20 | |||
21 | /** | ||
22 | * 系统手动发放优惠券 | ||
23 | * @param tempCouponList | ||
24 | */ | ||
25 | void grantCouponByManual(List<TempCoupon> tempCouponList); | ||
26 | } | 11 | } | ... | ... |
... | @@ -11,20 +11,5 @@ import java.util.List; | ... | @@ -11,20 +11,5 @@ import java.util.List; |
11 | */ | 11 | */ |
12 | public interface ExpOperationService { | 12 | public interface ExpOperationService { |
13 | 13 | ||
14 | /** | ||
15 | * 任务完成后自动发放成长值 | ||
16 | * @param tempExpList | ||
17 | */ | ||
18 | void grantPointsThroughTempExp(List<TempExp> tempExpList); | ||
19 | |||
20 | /** | ||
21 | * 系统手动发放优惠券 | ||
22 | * @param memberId | ||
23 | * @param userId | ||
24 | * @param tempExpList | ||
25 | */ | ||
26 | void grantExpByManual(Long memberId, Long userId, List<TempExp> tempExpList); | ||
27 | |||
28 | void grantExpByManual(List<TempExp> tempExpList); | ||
29 | 14 | ||
30 | } | 15 | } | ... | ... |
... | @@ -11,38 +11,4 @@ import java.util.List; | ... | @@ -11,38 +11,4 @@ import java.util.List; |
11 | */ | 11 | */ |
12 | public interface PointsOperationService { | 12 | public interface PointsOperationService { |
13 | 13 | ||
14 | /** | ||
15 | * 手动发放积分 | ||
16 | * @param memberId 会员id | ||
17 | * @param tempPoints 积分详情 | ||
18 | */ | ||
19 | void grantPointsByManual(Long memberId , TempPoints tempPoints); | ||
20 | |||
21 | /** | ||
22 | * | ||
23 | * @param tempPoints | ||
24 | */ | ||
25 | void grantPointsByManualByTempPoints(TempPoints tempPoints); | ||
26 | |||
27 | |||
28 | /** | ||
29 | * 积分扣减 | ||
30 | * @param tempPoints 积分对象 | ||
31 | */ | ||
32 | boolean customPoints(TempPoints tempPoints); | ||
33 | |||
34 | |||
35 | /** | ||
36 | * 积分发放,基于已获得的权益 | ||
37 | * @param tempPointsList 已获得的权益 | ||
38 | */ | ||
39 | void grantPointsThroughTempRightsList(List<TempPoints> tempPointsList); | ||
40 | |||
41 | |||
42 | /** | ||
43 | * 清理过期并计算可用总积分 | ||
44 | * @param memberId | ||
45 | * @return | ||
46 | */ | ||
47 | Long cleanInvalidPointsAndCalculateCurrentPoints(Long memberId); | ||
48 | } | 14 | } | ... | ... |
1 | package com.topdraw.business.process.service; | ||
2 | |||
3 | import com.topdraw.business.module.rights.history.domain.RightsHistory; | ||
4 | import com.topdraw.business.process.domian.RightType; | ||
5 | |||
6 | import java.util.List; | ||
7 | import java.util.Map; | ||
8 | |||
9 | /** | ||
10 | * @description 权益操作接口 | ||
11 | * @author XiangHan | ||
12 | * @date 2021.10.22 | ||
13 | */ | ||
14 | public interface RightsOperationService { | ||
15 | |||
16 | /** | ||
17 | * 系统手动发放权益 | ||
18 | * @param rightsHistories | ||
19 | */ | ||
20 | void grantRightsByManual(List<RightsHistory> rightsHistories); | ||
21 | |||
22 | /** | ||
23 | * 任务完成自动发放权益 | ||
24 | * @param tempRightsMap | ||
25 | */ | ||
26 | void grantRights(Map<RightType, Object> tempRightsMap); | ||
27 | } |
... | @@ -6,193 +6,33 @@ import com.topdraw.business.module.coupon.service.CouponService; | ... | @@ -6,193 +6,33 @@ import com.topdraw.business.module.coupon.service.CouponService; |
6 | import com.topdraw.business.module.member.domain.Member; | 6 | import com.topdraw.business.module.member.domain.Member; |
7 | import com.topdraw.business.module.member.service.MemberService; | 7 | import com.topdraw.business.module.member.service.MemberService; |
8 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 8 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
9 | import com.topdraw.business.process.domian.TempCoupon; | ||
10 | import com.topdraw.business.process.service.CouponOperationService; | 9 | import com.topdraw.business.process.service.CouponOperationService; |
11 | import com.topdraw.business.process.service.RightsOperationService; | ||
12 | import com.topdraw.business.process.service.member.MemberOperationService; | 10 | import com.topdraw.business.process.service.member.MemberOperationService; |
13 | import org.slf4j.Logger; | ||
14 | import org.slf4j.LoggerFactory; | ||
15 | import org.springframework.beans.BeanUtils; | ||
16 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
17 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
18 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
19 | 13 | ||
20 | import java.time.LocalDateTime; | ||
21 | import java.util.List; | ||
22 | import java.util.Objects; | ||
23 | |||
24 | |||
25 | @Service | 14 | @Service |
26 | public class CouponOperationServiceImpl implements CouponOperationService { | 15 | public class CouponOperationServiceImpl implements CouponOperationService { |
27 | 16 | ||
28 | private static final Logger LOG = LoggerFactory.getLogger(CouponOperationServiceImpl.class); | ||
29 | |||
30 | @Autowired | ||
31 | CouponService couponService; | ||
32 | @Autowired | ||
33 | CouponHistoryService couponHistoryService; | ||
34 | @Autowired | 17 | @Autowired |
35 | MemberOperationService memberOperationService; | 18 | private CouponHistoryService couponHistoryService; |
36 | @Autowired | 19 | @Autowired |
37 | RightsOperationService rightsOperationService; | 20 | private MemberOperationService memberOperationService; |
38 | @Autowired | 21 | @Autowired |
39 | MemberService memberService; | 22 | private MemberService memberService; |
40 | @Autowired | ||
41 | ThreadPoolTaskExecutor threadPoolTaskExecutor; | ||
42 | |||
43 | // 过期阀值(默认一个月) | ||
44 | private static final Integer EXPIRE_FACTOR_DAY = 30; | ||
45 | |||
46 | @Override | ||
47 | public void grantCouponThroughTempCoupon(List<TempCoupon> tempCouponList) { | ||
48 | // 优惠券领取、使用历史记录表 | ||
49 | for (TempCoupon tempCoupon : tempCouponList) { | ||
50 | this.refresh(tempCoupon); | ||
51 | } | ||
52 | } | ||
53 | |||
54 | /** | ||
55 | * 手动发放优惠券 | ||
56 | * @param tempCouponList | ||
57 | */ | ||
58 | @Override | ||
59 | public void grantCouponByManual(List<TempCoupon> tempCouponList) { | ||
60 | // 优惠券领取、使用历史记录表 | ||
61 | for (TempCoupon tempCoupon : tempCouponList) { | ||
62 | this.refresh(tempCoupon); | ||
63 | } | ||
64 | } | ||
65 | |||
66 | |||
67 | /** | ||
68 | * 优惠券领取历史记录表 | ||
69 | * | ||
70 | * @param tempCoupon 领取的优惠券 | ||
71 | */ | ||
72 | private void refresh(TempCoupon tempCoupon) { | ||
73 | // 1.更新会员优惠券数量 | ||
74 | this.refreshMemberCoupon(tempCoupon); | ||
75 | // 2.保存优惠券领取、使用历史记录表 | ||
76 | this.doInsertCouponHistory(tempCoupon); | ||
77 | } | ||
78 | |||
79 | |||
80 | /** | ||
81 | * 更新会员优惠券信息 | ||
82 | * @param tempCoupon 账号id | ||
83 | */ | ||
84 | private void refreshMemberCoupon(TempCoupon tempCoupon) { | ||
85 | // Long userId = tempCoupon.getUserId(); | ||
86 | Long memberId = tempCoupon.getMemberId(); | ||
87 | Integer rightsAmount = tempCoupon.getRightsAmount(); | ||
88 | try { | ||
89 | // 1.历史总优惠券数量 | ||
90 | Long historyCouponCount = this.getTotalHistoryCoupon(memberId); | ||
91 | // 1.当前总优惠券数量 | ||
92 | Long totalCouponCount = this.getTotalCoupon(historyCouponCount,rightsAmount); | ||
93 | // 2.获取已过期的优惠券数量 | ||
94 | Long expireCouponCount = this.getTotalExpireCoupon(memberId); | ||
95 | // 3.即将过期的优惠券数量 | ||
96 | Long expireSoonCouponCount = this.getTotalExpireSoonCoupon(memberId,EXPIRE_FACTOR_DAY); | ||
97 | // 4.当前优惠券数量 = 总优惠券-已过期的优惠券 | ||
98 | Long currentCoupon = this.getCurrentCoupon(totalCouponCount,expireCouponCount); | ||
99 | // 5.更新用户信息(优惠券数量、即将过期的优惠券数量) | ||
100 | this.doUpdateMemberInfo(memberId,currentCoupon,expireSoonCouponCount); | ||
101 | } catch (Exception e) { | ||
102 | e.printStackTrace(); | ||
103 | throw e; | ||
104 | } | ||
105 | } | ||
106 | |||
107 | private Long getTotalCoupon(Long historyCouponCount, Integer rightsAmount) { | ||
108 | return (Objects.nonNull(historyCouponCount) ? historyCouponCount: 0L) + (Objects.nonNull(rightsAmount) ? rightsAmount: 0L); | ||
109 | } | ||
110 | |||
111 | 23 | ||
112 | /** | 24 | public void asyncMemberCoupon(Member member) { |
113 | * 更新当前用户优惠券信息 | 25 | String memberCode = member.getCode(); |
114 | * @param memberId | 26 | MemberDTO memberDTO = this.memberService.findByCode(memberCode); |
115 | * @param currentCoupon | 27 | member.setId(memberDTO.getId()); |
116 | * @param expireSoonCouponCount | ||
117 | */ | ||
118 | private void doUpdateMemberInfo(Long memberId, Long currentCoupon, Long expireSoonCouponCount) { | ||
119 | MemberDTO memberDTO = this.findMemberByMemberId(memberId); | ||
120 | |||
121 | Member member = new Member(); | ||
122 | BeanUtils.copyProperties(memberDTO,member); | ||
123 | |||
124 | member.setCouponAmount(currentCoupon); | ||
125 | member.setDueCouponAmount(expireSoonCouponCount); | ||
126 | member.setUpdateTime(LocalDateTime.now()); | ||
127 | this.memberOperationService.doUpdateMember(member); | 28 | this.memberOperationService.doUpdateMember(member); |
128 | } | 29 | } |
129 | 30 | ||
130 | private MemberDTO findMemberByMemberId(Long memberId) { | 31 | public void asyncCouponHistory(CouponHistory couponHistory) { |
131 | MemberDTO memberDTO = this.memberService.findById(memberId); | 32 | String memberCode = couponHistory.getMemberCode(); |
132 | return memberDTO; | 33 | MemberDTO memberDTO = this.memberService.findByCode(memberCode); |
133 | } | 34 | couponHistory.setUserId(memberDTO.getId()); |
134 | |||
135 | |||
136 | |||
137 | /** | ||
138 | * 当前优惠券数量 = 总优惠券-已过期的优惠券 | ||
139 | * @param totalCouponCount 总数 | ||
140 | * @param expireCouponCount 已过期总数 | ||
141 | * @return | ||
142 | */ | ||
143 | private Long getCurrentCoupon(Long totalCouponCount, Long expireCouponCount) { | ||
144 | return (Objects.nonNull(totalCouponCount)?totalCouponCount:0L)-(Objects.nonNull(expireCouponCount)?expireCouponCount:0L); | ||
145 | } | ||
146 | |||
147 | |||
148 | /** | ||
149 | * 即将过期的优惠券数量 | ||
150 | * @param expireFactor | ||
151 | * @return | ||
152 | */ | ||
153 | private Long getTotalExpireSoonCoupon(Long userId, Integer expireFactor) { | ||
154 | LocalDateTime expireTime = LocalDateTime.now().plusDays(expireFactor); | ||
155 | return this.couponHistoryService.countByUserIdAndExpireTimeBetween(userId,LocalDateTime.now(),expireTime); | ||
156 | } | ||
157 | 35 | ||
158 | |||
159 | /** | ||
160 | * 获取已过期的优惠券数量 | ||
161 | * @param userId | ||
162 | * @return | ||
163 | */ | ||
164 | private Long getTotalExpireCoupon(Long userId) { | ||
165 | return this.couponHistoryService.countByUserIdAndExpireTimeBefore(userId,LocalDateTime.now()); | ||
166 | } | ||
167 | |||
168 | |||
169 | /** | ||
170 | * 获取用户领取的总优惠券 | ||
171 | * @param userId | ||
172 | * @return | ||
173 | */ | ||
174 | private Long getTotalHistoryCoupon(Long userId) { | ||
175 | return this.couponHistoryService.countByUserId(userId); | ||
176 | } | ||
177 | |||
178 | |||
179 | /** | ||
180 | * 优惠券领取、使用历史记录表 | ||
181 | * @param tempCoupon 优惠券 | ||
182 | */ | ||
183 | private void doInsertCouponHistory(TempCoupon tempCoupon) { | ||
184 | CouponHistory couponHistory = new CouponHistory(); | ||
185 | BeanUtils.copyProperties(tempCoupon,couponHistory); | ||
186 | couponHistory.setId(null); | ||
187 | couponHistory.setCouponId(tempCoupon.getId()); | ||
188 | couponHistory.setUserId(tempCoupon.getMemberId()); | ||
189 | couponHistory.setCouponCode(tempCoupon.getCode()); | ||
190 | couponHistory.setUserNickname(tempCoupon.getUserNickname()); | ||
191 | couponHistory.setOrderDetailId(tempCoupon.getOrderId()); | ||
192 | couponHistory.setReceiveTime(LocalDateTime.now()); | ||
193 | couponHistory.setUseStatus(Objects.nonNull(couponHistory.getUseStatus()) ? couponHistory.getUseStatus():0); | ||
194 | this.couponHistoryService.create(couponHistory); | 36 | this.couponHistoryService.create(couponHistory); |
195 | } | 37 | } |
196 | |||
197 | |||
198 | } | 38 | } | ... | ... |
... | @@ -4,25 +4,13 @@ import com.topdraw.business.module.exp.detail.domain.ExpDetail; | ... | @@ -4,25 +4,13 @@ import com.topdraw.business.module.exp.detail.domain.ExpDetail; |
4 | import com.topdraw.business.module.exp.detail.service.ExpDetailService; | 4 | import com.topdraw.business.module.exp.detail.service.ExpDetailService; |
5 | import com.topdraw.business.module.member.domain.Member; | 5 | import com.topdraw.business.module.member.domain.Member; |
6 | import com.topdraw.business.module.member.level.service.MemberLevelService; | 6 | 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.service.MemberService; | 7 | import com.topdraw.business.module.member.service.MemberService; |
9 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 8 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
10 | import com.topdraw.business.process.domian.TempExp; | ||
11 | import com.topdraw.business.process.service.ExpOperationService; | 9 | import com.topdraw.business.process.service.ExpOperationService; |
12 | import com.topdraw.business.process.service.member.MemberOperationService; | 10 | import com.topdraw.business.process.service.member.MemberOperationService; |
13 | import com.topdraw.util.IdWorker; | ||
14 | import com.topdraw.utils.StringUtils; | ||
15 | import org.slf4j.Logger; | ||
16 | import org.slf4j.LoggerFactory; | ||
17 | import org.springframework.beans.BeanUtils; | ||
18 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
19 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | 12 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
20 | import org.springframework.stereotype.Service; | 13 | import org.springframework.stereotype.Service; |
21 | import org.springframework.util.CollectionUtils; | ||
22 | |||
23 | import java.time.LocalDateTime; | ||
24 | import java.util.List; | ||
25 | import java.util.Objects; | ||
26 | 14 | ||
27 | /** | 15 | /** |
28 | * | 16 | * |
... | @@ -30,180 +18,30 @@ import java.util.Objects; | ... | @@ -30,180 +18,30 @@ import java.util.Objects; |
30 | @Service | 18 | @Service |
31 | public class ExpOperationServiceImpl implements ExpOperationService { | 19 | public class ExpOperationServiceImpl implements ExpOperationService { |
32 | 20 | ||
33 | private static final Logger LOG = LoggerFactory.getLogger(ExpOperationServiceImpl.class); | ||
34 | |||
35 | @Autowired | 21 | @Autowired |
36 | ExpDetailService expDetailService; | 22 | private ExpDetailService expDetailService; |
37 | @Autowired | 23 | @Autowired |
38 | MemberOperationService memberOperationService; | 24 | private MemberOperationService memberOperationService; |
39 | @Autowired | 25 | @Autowired |
40 | MemberLevelService memberLevelService; | 26 | private MemberLevelService memberLevelService; |
41 | @Autowired | 27 | @Autowired |
42 | MemberService memberService; | 28 | private MemberService memberService; |
43 | @Autowired | 29 | @Autowired |
44 | ThreadPoolTaskExecutor threadPoolTaskExecutor; | 30 | ThreadPoolTaskExecutor threadPoolTaskExecutor; |
45 | 31 | ||
46 | @Override | 32 | public void asyncMemberExpAndLevel(Member member) { |
47 | public void grantPointsThroughTempExp(List<TempExp> tempExpList) { | 33 | String code = member.getCode(); |
48 | 34 | MemberDTO memberDTO = this.memberService.findByCode(code); | |
49 | for (TempExp tempExp : tempExpList) { | 35 | member.setId(memberDTO.getId()); |
50 | this.refresh(tempExp); | ||
51 | } | ||
52 | |||
53 | } | ||
54 | |||
55 | @Override | ||
56 | public void grantExpByManual(Long memberId, Long userId, List<TempExp> tempExpList) { | ||
57 | for (TempExp tempExp : tempExpList) { | ||
58 | this.refresh(tempExp); | ||
59 | } | ||
60 | } | ||
61 | |||
62 | @Override | ||
63 | public void grantExpByManual(List<TempExp> tempExpList) { | ||
64 | for (TempExp tempExp : tempExpList) { | ||
65 | this.refresh(tempExp); | ||
66 | } | ||
67 | } | ||
68 | |||
69 | |||
70 | /** | ||
71 | * | ||
72 | * @param tempExp | ||
73 | */ | ||
74 | private void refresh(TempExp tempExp) { | ||
75 | String memberCode = tempExp.getMemberCode(); | ||
76 | MemberDTO memberDTO = this.memberService.findByCode(memberCode); | ||
77 | Long id = memberDTO.getId(); | ||
78 | tempExp.setId(id); | ||
79 | try { | ||
80 | // 原始积分 | ||
81 | long originExp = this.getExpByMemberId(tempExp); | ||
82 | // 总积分 | ||
83 | long totalExp = this.calculateTotalExp(originExp, tempExp); | ||
84 | // 1.添加成长值记录 | ||
85 | // this.threadPoolTaskExecutor.execute(() -> this.doInsertExpDetail(tempExp, originExp, totalExp)); | ||
86 | // 2.更新成长值与等级 | ||
87 | this.refreshMemberExpAndLevel(tempExp,totalExp); | ||
88 | |||
89 | this.doInsertExpDetail(tempExp, originExp, totalExp); | ||
90 | 36 | ||
91 | } catch (Exception e) { | 37 | this.memberService.doUpdateMemberExpAndLevel(member); |
92 | e.printStackTrace(); | ||
93 | throw e; | ||
94 | } | ||
95 | } | 38 | } |
96 | 39 | ||
97 | private long calculateTotalExp(long originalExp, TempExp tempExp) { | 40 | public void asyncExpDetail(ExpDetail expDetail) { |
98 | Long rewardExp = tempExp.getRewardExp(); | 41 | String code = expDetail.getMemberCode(); |
99 | return rewardExp + originalExp; | 42 | MemberDTO memberDTO = this.memberService.findByCode(code); |
100 | } | 43 | expDetail.setMemberId(memberDTO.getId()); |
101 | 44 | ||
102 | private long getExpByMemberId(TempExp tempExp) { | ||
103 | Long memberId = tempExp.getMemberId(); | ||
104 | MemberDTO memberDTO = this.memberOperationService.findById(memberId); | ||
105 | if (Objects.nonNull(memberDTO)) { | ||
106 | Long exp = memberDTO.getExp(); | ||
107 | return Objects.isNull(exp) ? 0L : exp; | ||
108 | } | ||
109 | return 0L; | ||
110 | } | ||
111 | |||
112 | |||
113 | /** | ||
114 | * 更新成长值与等级 | ||
115 | * | ||
116 | * @param tempExp 成长值列表 | ||
117 | */ | ||
118 | private void refreshMemberExpAndLevel(TempExp tempExp, long totalExp) { | ||
119 | |||
120 | Long memberId = tempExp.getMemberId(); | ||
121 | // 1.获取当前成长值 | ||
122 | MemberDTO memberDTO = this.getMemberInfoByMemberId(memberId); | ||
123 | // 2.获取下一级需要的成长值 | ||
124 | MemberLevelDTO memberLevelDTO = this.getNextLevelExp(memberDTO.getLevel() + 1, 1); | ||
125 | // 4.成长值比较,判断是否升级 | ||
126 | Integer level = this.compareExp(totalExp, memberLevelDTO,memberDTO); | ||
127 | // 5.更新用户信息 | ||
128 | this.updateMemberInfo(level, totalExp, memberId); | ||
129 | } | ||
130 | |||
131 | /** | ||
132 | * | ||
133 | * @param level | ||
134 | * @param totalExp 总积分 | ||
135 | * @param memberId 会员id | ||
136 | */ | ||
137 | private void updateMemberInfo(Integer level,Long totalExp,Long memberId) { | ||
138 | MemberDTO memberDTO = this.findMemberByMemberId(memberId); | ||
139 | |||
140 | Member member = new Member(); | ||
141 | BeanUtils.copyProperties(memberDTO,member); | ||
142 | |||
143 | member.setExp(totalExp); | ||
144 | member.setLevel(level); | ||
145 | member.setUpdateTime(LocalDateTime.now()); | ||
146 | this.memberOperationService.doUpdateMember(member); | ||
147 | } | ||
148 | |||
149 | private MemberDTO findMemberByMemberId(Long memberId) { | ||
150 | MemberDTO memberDTO = this.memberService.findById(memberId); | ||
151 | return memberDTO; | ||
152 | } | ||
153 | |||
154 | private Integer compareExp(long newExp, MemberLevelDTO memberLevelDTO, MemberDTO memberDTO) { | ||
155 | if (Objects.nonNull(memberLevelDTO)) { | ||
156 | Long nextLevelExp = memberLevelDTO.getExpValue(); | ||
157 | if (Objects.nonNull(nextLevelExp) && nextLevelExp > 0) | ||
158 | if(newExp - nextLevelExp >= 0){ | ||
159 | return memberLevelDTO.getLevel(); | ||
160 | } | ||
161 | } | ||
162 | return memberDTO.getLevel(); | ||
163 | } | ||
164 | |||
165 | private MemberLevelDTO getNextLevelExp(Integer i, Integer status) { | ||
166 | List<MemberLevelDTO> memberLevelDTOList = this.memberLevelService.findLevelAndStatus(i,status); | ||
167 | if (!CollectionUtils.isEmpty(memberLevelDTOList)) { | ||
168 | return memberLevelDTOList.get(0); | ||
169 | } | ||
170 | return null; | ||
171 | } | ||
172 | |||
173 | |||
174 | /** | ||
175 | * 获取当前会员的成长值 | ||
176 | * @param memberId 会员id | ||
177 | * @return Long 当前会员成长值 | ||
178 | */ | ||
179 | private MemberDTO getMemberInfoByMemberId(Long memberId) { | ||
180 | MemberDTO memberDTO = this.memberOperationService.findById(memberId); | ||
181 | return memberDTO; | ||
182 | } | ||
183 | |||
184 | /** | ||
185 | * 添加成长值记录 | ||
186 | * | ||
187 | * @param tempExp 成长值列表 | ||
188 | */ | ||
189 | private void doInsertExpDetail(TempExp tempExp, long originalExp, long totalExp) { | ||
190 | // 获得的积分 | ||
191 | Long rewardExp = tempExp.getRewardExp(); | ||
192 | |||
193 | ExpDetail expDetail = new ExpDetail(); | ||
194 | BeanUtils.copyProperties(tempExp,expDetail); | ||
195 | |||
196 | expDetail.setCode(String.valueOf(IdWorker.generator())); | ||
197 | // 原始积分 | ||
198 | expDetail.setOriginalExp(originalExp); | ||
199 | // 总积分 | ||
200 | expDetail.setResultExp(totalExp); | ||
201 | // 获得的积分 | ||
202 | expDetail.setExp(rewardExp); | ||
203 | if (StringUtils.isEmpty(expDetail.getDescription())) { | ||
204 | expDetail.setDescription("#"); | ||
205 | } | ||
206 | this.expDetailService.create(expDetail); | 45 | this.expDetailService.create(expDetail); |
207 | } | 46 | } |
208 | |||
209 | } | 47 | } | ... | ... |
This diff is collapsed.
Click to expand it.
src/main/java/com/topdraw/business/process/service/impl/RightsOperationServiceImpl.java
deleted
100644 → 0
This diff is collapsed.
Click to expand it.
... | @@ -138,7 +138,8 @@ public class RabbitMqConfig { | ... | @@ -138,7 +138,8 @@ public class RabbitMqConfig { |
138 | 138 | ||
139 | public static final String UC_DIRECT_MANAGEMENT = "uc.direct.management"; | 139 | public static final String UC_DIRECT_MANAGEMENT = "uc.direct.management"; |
140 | // uc-service-management 2 uc-consumer-iptv | 140 | // uc-service-management 2 uc-consumer-iptv |
141 | public static final String ENGINE_TO_SERVICE_DIRECT = "uc.engine.service.direct"; | 141 | // public static final String ENGINE_TO_SERVICE_DIRECT = "uc.engine.service.direct"; |
142 | public static final String ENGINE_TO_SERVICE_DIRECT = "uc.engine.service.direct.local"; | ||
142 | 143 | ||
143 | @Bean | 144 | @Bean |
144 | public Queue managementDirect() { | 145 | public Queue managementDirect() { |
... | @@ -184,18 +185,18 @@ public class RabbitMqConfig { | ... | @@ -184,18 +185,18 @@ public class RabbitMqConfig { |
184 | 185 | ||
185 | 186 | ||
186 | /**************************************************数据基座*************************************************************/ | 187 | /**************************************************数据基座*************************************************************/ |
187 | public static final String UC_EVENTBUS = "uc.eventbus"; | 188 | public static final String UC_EVENTBUS_EXCHANGE = "uc.eventbus.local"; |
188 | public static final String UC_EVENTBUS_KEY = "uc.eventbus.*.topic"; | 189 | public static final String UC_EVENTBUS_KEY = "uc.eventbus.*.topic"; |
189 | public static final String UC_EVENTBUS_TOPIC = "uc.eventbus"; | 190 | public static final String UC_EVENTBUS_QUEUE = "uc.eventbus.local"; |
190 | 191 | ||
191 | @Bean | 192 | @Bean |
192 | public Queue eventBusQueue() { | 193 | public Queue eventBusQueue() { |
193 | return new Queue(UC_EVENTBUS_TOPIC); | 194 | return new Queue(UC_EVENTBUS_QUEUE); |
194 | } | 195 | } |
195 | 196 | ||
196 | @Bean | 197 | @Bean |
197 | TopicExchange eventBusExchange() { | 198 | TopicExchange eventBusExchange() { |
198 | return ExchangeBuilder.topicExchange(UC_EVENTBUS) | 199 | return ExchangeBuilder.topicExchange(UC_EVENTBUS_EXCHANGE) |
199 | .durable(true).build(); | 200 | .durable(true).build(); |
200 | } | 201 | } |
201 | 202 | ... | ... |
... | @@ -2,34 +2,35 @@ package com.topdraw.mq.consumer; | ... | @@ -2,34 +2,35 @@ package com.topdraw.mq.consumer; |
2 | 2 | ||
3 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
4 | import com.alibaba.fastjson.JSONObject; | 4 | import com.alibaba.fastjson.JSONObject; |
5 | import com.fasterxml.jackson.annotation.JsonFormat; | 5 | import com.topdraw.business.module.member.service.MemberService; |
6 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 6 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
7 | import com.topdraw.business.module.user.iptv.service.UserTvService; | 7 | import com.topdraw.business.module.user.iptv.service.UserTvService; |
8 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; | 8 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; |
9 | import com.topdraw.config.RabbitMqConfig; | 9 | import com.topdraw.config.RabbitMqConfig; |
10 | import com.topdraw.exception.BadRequestException; | ||
11 | import com.topdraw.exception.EntityNotFoundException; | ||
10 | import com.topdraw.mq.domain.DataSyncMsg; | 12 | import com.topdraw.mq.domain.DataSyncMsg; |
11 | import com.topdraw.resttemplate.RestTemplateClient; | 13 | import com.topdraw.resttemplate.RestTemplateClient; |
12 | import com.topdraw.util.JSONUtil; | 14 | import com.topdraw.util.JSONUtil; |
13 | import lombok.Data; | 15 | import lombok.Data; |
14 | import lombok.extern.slf4j.Slf4j; | 16 | import lombok.extern.slf4j.Slf4j; |
15 | import org.apache.commons.lang3.StringUtils; | 17 | import org.apache.commons.lang3.StringUtils; |
16 | import org.springframework.amqp.core.ExchangeTypes; | ||
17 | import org.springframework.amqp.rabbit.annotation.*; | 18 | import org.springframework.amqp.rabbit.annotation.*; |
18 | import org.springframework.beans.factory.annotation.Autowired; | 19 | import org.springframework.beans.factory.annotation.Autowired; |
19 | import org.springframework.stereotype.Component; | 20 | import org.springframework.stereotype.Component; |
20 | import org.springframework.util.Assert; | ||
21 | 21 | ||
22 | import java.sql.Timestamp; | ||
23 | import java.util.Objects; | 22 | import java.util.Objects; |
24 | 23 | ||
25 | @Component | 24 | @Component |
26 | @Slf4j | 25 | @Slf4j |
27 | public class UcEventBusIptv2IptvConsumer { | 26 | public class UcEventBusIptv2ManagementUcEngine { |
28 | 27 | ||
29 | @Autowired | 28 | @Autowired |
30 | RestTemplateClient restTemplateClient; | 29 | private RestTemplateClient restTemplateClient; |
31 | @Autowired | 30 | @Autowired |
32 | private UserTvService userTvService; | 31 | private UserTvService userTvService; |
32 | @Autowired | ||
33 | private MemberService memberService; | ||
33 | 34 | ||
34 | /** | 35 | /** |
35 | * 事件 | 36 | * 事件 |
... | @@ -39,7 +40,7 @@ public class UcEventBusIptv2IptvConsumer { | ... | @@ -39,7 +40,7 @@ public class UcEventBusIptv2IptvConsumer { |
39 | * @date 2021/9/7 11:26 上午 | 40 | * @date 2021/9/7 11:26 上午 |
40 | */ | 41 | */ |
41 | @RabbitHandler | 42 | @RabbitHandler |
42 | @RabbitListener(queues = RabbitMqConfig.UC_EVENTBUS_TOPIC, | 43 | @RabbitListener(queues = RabbitMqConfig.UC_EVENTBUS_QUEUE, |
43 | containerFactory = "managementRabbitListenerContainerFactory") | 44 | containerFactory = "managementRabbitListenerContainerFactory") |
44 | public void ucEventConsumer(String content) { | 45 | public void ucEventConsumer(String content) { |
45 | log.info(" receive dataSync msg , content is : {} ", content); | 46 | log.info(" receive dataSync msg , content is : {} ", content); |
... | @@ -53,18 +54,6 @@ public class UcEventBusIptv2IptvConsumer { | ... | @@ -53,18 +54,6 @@ public class UcEventBusIptv2IptvConsumer { |
53 | * @param content | 54 | * @param content |
54 | * @return | 55 | * @return |
55 | */ | 56 | */ |
56 | /*{ | ||
57 | "evt": "play”, // 表示播放 | ||
58 | "deviceType": 1, // 1代表大屏 | ||
59 | "time": "2022-04-01 00:10:09”, | ||
60 | "msgData": { | ||
61 | "platformAccount": "itv094430@“, // 大屏用户账号 | ||
62 | "playDuration": 60, // 播放时长,单位分钟 | ||
63 | "mediaId": 3433, // 节目id,此次是累计计算,可不传 | ||
64 | "mediaCode": "media_123”, // 节目标识,同上 | ||
65 | "mediaName": "白宫陷落” // 节目名称,同上 | ||
66 | } | ||
67 | }*/ | ||
68 | private DataSyncMsg parseContent(String content) { | 57 | private DataSyncMsg parseContent(String content) { |
69 | 58 | ||
70 | CommonMsg commonMsg = JSONUtil.parseMsg2Object(content, CommonMsg.class); | 59 | CommonMsg commonMsg = JSONUtil.parseMsg2Object(content, CommonMsg.class); |
... | @@ -91,22 +80,35 @@ public class UcEventBusIptv2IptvConsumer { | ... | @@ -91,22 +80,35 @@ public class UcEventBusIptv2IptvConsumer { |
91 | DataSyncMsg.MsgData msgData1 = new DataSyncMsg.MsgData(); | 80 | DataSyncMsg.MsgData msgData1 = new DataSyncMsg.MsgData(); |
92 | 81 | ||
93 | if (StringUtils.isNotBlank(platformAccount)) { | 82 | if (StringUtils.isNotBlank(platformAccount)) { |
94 | MemberDTO memberDTO = this.userTvService.findMemberByPlatformAccount(platformAccount); | 83 | UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); |
95 | Long memberId = memberDTO.getId(); | 84 | String priorityMemberCode = userTvDTO.getPriorityMemberCode(); |
96 | String memberCode = memberDTO.getCode(); | 85 | String memberCode = ""; |
86 | if (StringUtils.isNotBlank(priorityMemberCode)) { | ||
87 | memberCode = priorityMemberCode; | ||
88 | } else { | ||
89 | memberCode = this.memberService.findById(userTvDTO.getMemberId()).getCode(); | ||
90 | } | ||
91 | |||
92 | if (StringUtils.isBlank(memberCode)) | ||
93 | throw new EntityNotFoundException(MemberDTO.class, "memberCode", "memberCode is null"); | ||
94 | |||
97 | msgData1.setMemberCode(memberCode); | 95 | msgData1.setMemberCode(memberCode); |
98 | } | 96 | } |
99 | 97 | ||
100 | msgData1.setEvent(8); | 98 | msgData1.setEvent(8); |
101 | msgData1.setDeviceType(deviceType); | 99 | msgData1.setDeviceType(deviceType); |
102 | msgData1.setMediaId(mediaId); | 100 | msgData1.setMediaId(mediaId); |
103 | JSONObject jsonObject = new JSONObject(); | 101 | |
104 | jsonObject.put("mediaId", mediaId); | 102 | JSONObject param = new JSONObject(); |
105 | jsonObject.put("mediaName", mediaName); | 103 | param.put("playDuration", playDuration); |
106 | jsonObject.put("playDuration", playDuration); | 104 | msgData1.setParam(JSON.toJSONString(param)); |
107 | jsonObject.put("mediaCode", mediaCode); | 105 | JSONObject description = new JSONObject(); |
108 | jsonObject.put("time", time); | 106 | description.put("mediaId", mediaId); |
109 | msgData1.setDescription(JSON.toJSONString(jsonObject)); | 107 | description.put("mediaName", mediaName); |
108 | description.put("playDuration", playDuration); | ||
109 | description.put("mediaCode", mediaCode); | ||
110 | description.put("time", time); | ||
111 | msgData1.setDescription(JSON.toJSONString(description)); | ||
110 | 112 | ||
111 | dataSyncMsg.setMsg(msgData1); | 113 | dataSyncMsg.setMsg(msgData1); |
112 | return dataSyncMsg; | 114 | return dataSyncMsg; | ... | ... |
-
Please register or sign in to post a comment