1.添加修改会员vip接口
Showing
10 changed files
with
97 additions
and
27 deletions
... | @@ -4,6 +4,7 @@ import com.topdraw.annotation.AnonymousAccess; | ... | @@ -4,6 +4,7 @@ import com.topdraw.annotation.AnonymousAccess; |
4 | import com.topdraw.business.module.member.domain.Member; | 4 | import com.topdraw.business.module.member.domain.Member; |
5 | import com.topdraw.business.module.member.service.MemberService; | 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.member.viphistory.service.MemberVipHistoryService; | ||
7 | import com.topdraw.business.module.user.iptv.domain.UserTv; | 8 | import com.topdraw.business.module.user.iptv.domain.UserTv; |
8 | import com.topdraw.business.process.service.UserOperationService; | 9 | import com.topdraw.business.process.service.UserOperationService; |
9 | import com.topdraw.common.ResultInfo; | 10 | import com.topdraw.common.ResultInfo; |
... | @@ -31,7 +32,6 @@ public class MemberController { | ... | @@ -31,7 +32,6 @@ public class MemberController { |
31 | 32 | ||
32 | @Autowired | 33 | @Autowired |
33 | private MemberService memberService; | 34 | private MemberService memberService; |
34 | |||
35 | @Autowired | 35 | @Autowired |
36 | private UserOperationService userTvOperationService; | 36 | private UserOperationService userTvOperationService; |
37 | 37 | ||
... | @@ -59,13 +59,31 @@ public class MemberController { | ... | @@ -59,13 +59,31 @@ public class MemberController { |
59 | return ResultInfo.success(id); | 59 | return ResultInfo.success(id); |
60 | } | 60 | } |
61 | 61 | ||
62 | @PostMapping(value = "/doUpdateVip") | 62 | @PostMapping(value = "/doUpdateVipAndSaveHistory") |
63 | @ApiOperation("修改Member等级") | ||
64 | public ResultInfo doUpdateVipAndSaveVipHistory(@RequestBody Member member) { | ||
65 | memberService.doUpdateVipAndSaveVipHistory(member); | ||
66 | return ResultInfo.success(); | ||
67 | } | ||
68 | |||
69 | @RequestMapping(value = "/doUpdateVip") | ||
63 | @ApiOperation("修改Member等级") | 70 | @ApiOperation("修改Member等级") |
71 | @AnonymousAccess | ||
64 | public ResultInfo doUpdateVip(@RequestBody Member member) { | 72 | public ResultInfo doUpdateVip(@RequestBody Member member) { |
65 | memberService.update(member); | 73 | memberService.update(member); |
66 | return ResultInfo.success(); | 74 | return ResultInfo.success(); |
67 | } | 75 | } |
68 | 76 | ||
77 | @RequestMapping(value = "/doUpdateVipByCode") | ||
78 | @ApiOperation("修改Member等级") | ||
79 | @AnonymousAccess | ||
80 | public ResultInfo doUpdateVipByCode(@RequestBody Member member) { | ||
81 | String code = member.getCode(); | ||
82 | Assert.notNull(code,"code can't be null !"); | ||
83 | memberService.doUpdateVipByCode(member); | ||
84 | return ResultInfo.success(); | ||
85 | } | ||
86 | |||
69 | @PutMapping(value = "/update") | 87 | @PutMapping(value = "/update") |
70 | @ApiOperation("修改Member") | 88 | @ApiOperation("修改Member") |
71 | @AnonymousAccess | 89 | @AnonymousAccess | ... | ... |
... | @@ -77,4 +77,8 @@ public interface MemberService { | ... | @@ -77,4 +77,8 @@ public interface MemberService { |
77 | void doUpdateMemberPoints(Member member); | 77 | void doUpdateMemberPoints(Member member); |
78 | 78 | ||
79 | List<MemberDTO> findByUserIptvId(Long id); | 79 | List<MemberDTO> findByUserIptvId(Long id); |
80 | |||
81 | void doUpdateVipByCode(Member member); | ||
82 | |||
83 | void doUpdateVipAndSaveVipHistory(Member member); | ||
80 | } | 84 | } | ... | ... |
... | @@ -7,6 +7,9 @@ import com.topdraw.business.module.member.service.MemberService; | ... | @@ -7,6 +7,9 @@ import com.topdraw.business.module.member.service.MemberService; |
7 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 7 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
8 | import com.topdraw.business.module.member.service.dto.MemberQueryCriteria; | 8 | import com.topdraw.business.module.member.service.dto.MemberQueryCriteria; |
9 | import com.topdraw.business.module.member.service.mapper.MemberMapper; | 9 | import com.topdraw.business.module.member.service.mapper.MemberMapper; |
10 | import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory; | ||
11 | import com.topdraw.business.module.member.viphistory.service.MemberVipHistoryService; | ||
12 | import com.topdraw.business.module.member.viphistory.service.impl.MemberVipHistoryBuilder; | ||
10 | import com.topdraw.util.IdWorker; | 13 | import com.topdraw.util.IdWorker; |
11 | import com.topdraw.util.RedissonUtil; | 14 | import com.topdraw.util.RedissonUtil; |
12 | import com.topdraw.utils.PageUtil; | 15 | import com.topdraw.utils.PageUtil; |
... | @@ -16,6 +19,7 @@ import com.topdraw.utils.ValidationUtil; | ... | @@ -16,6 +19,7 @@ import com.topdraw.utils.ValidationUtil; |
16 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
17 | import org.redisson.api.RLock; | 20 | import org.redisson.api.RLock; |
18 | import org.redisson.api.RedissonClient; | 21 | import org.redisson.api.RedissonClient; |
22 | import org.springframework.beans.BeanUtils; | ||
19 | import org.springframework.beans.factory.annotation.Autowired; | 23 | import org.springframework.beans.factory.annotation.Autowired; |
20 | import org.springframework.cache.annotation.CacheEvict; | 24 | import org.springframework.cache.annotation.CacheEvict; |
21 | import org.springframework.dao.EmptyResultDataAccessException; | 25 | import org.springframework.dao.EmptyResultDataAccessException; |
... | @@ -41,19 +45,15 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -41,19 +45,15 @@ public class MemberServiceImpl implements MemberService { |
41 | 45 | ||
42 | @Autowired | 46 | @Autowired |
43 | private MemberRepository memberRepository; | 47 | private MemberRepository memberRepository; |
44 | 48 | @Autowired | |
49 | private MemberVipHistoryService memberVipHistoryService; | ||
45 | @Autowired | 50 | @Autowired |
46 | private MemberMapper memberMapper; | 51 | private MemberMapper memberMapper; |
47 | |||
48 | @Autowired | 52 | @Autowired |
49 | private RedissonClient redissonClient; | 53 | private RedissonClient redissonClient; |
50 | |||
51 | @Autowired | 54 | @Autowired |
52 | PlatformTransactionManager platformTransactionManager; | 55 | PlatformTransactionManager platformTransactionManager; |
53 | 56 | ||
54 | @Autowired | ||
55 | private com.topdraw.business.module.user.iptv.service.UserTvService UserTvService; | ||
56 | |||
57 | @Override | 57 | @Override |
58 | public Map<String, Object> queryAll(MemberQueryCriteria criteria, Pageable pageable) { | 58 | public Map<String, Object> queryAll(MemberQueryCriteria criteria, Pageable pageable) { |
59 | Page<Member> page = memberRepository.findAll((root, criteriaQuery, criteriaBuilder) | 59 | Page<Member> page = memberRepository.findAll((root, criteriaQuery, criteriaBuilder) |
... | @@ -212,5 +212,30 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -212,5 +212,30 @@ public class MemberServiceImpl implements MemberService { |
212 | return memberMapper.toDto(memberList); | 212 | return memberMapper.toDto(memberList); |
213 | } | 213 | } |
214 | 214 | ||
215 | @Override | ||
216 | public void doUpdateVipByCode(Member member) { | ||
217 | MemberDTO memberDTO = this.getByCode(member.getCode()); | ||
218 | ValidationUtil.isNull(member.getId(), "Member", "id", memberDTO.getId()); | ||
219 | Member member1 = new Member(); | ||
220 | BeanUtils.copyProperties(memberDTO,member1); | ||
221 | member1.setVip(member.getVip()); | ||
222 | this.update(member1); | ||
223 | } | ||
224 | |||
225 | @Override | ||
226 | @Transactional(rollbackFor = Exception.class) | ||
227 | @AsyncMqSend | ||
228 | public void doUpdateVipAndSaveVipHistory(Member member) { | ||
229 | MemberDTO memberDTO = this.getByCode(member.getCode()); | ||
230 | MemberVipHistory memberVipHistory = MemberVipHistoryBuilder.build(memberDTO.getId(), | ||
231 | memberDTO.getVip(),memberDTO.getStatus(),memberDTO.getVipExpireTime(),member.getVip()); | ||
232 | this.memberVipHistoryService.create(memberVipHistory); | ||
233 | |||
234 | Member member1 = new Member(); | ||
235 | BeanUtils.copyProperties(memberDTO,member1); | ||
236 | member1.setVip(member.getVip()); | ||
237 | this.update(member); | ||
238 | } | ||
239 | |||
215 | 240 | ||
216 | } | 241 | } | ... | ... |
... | @@ -34,6 +34,9 @@ public class MemberVipHistory implements Serializable { | ... | @@ -34,6 +34,9 @@ public class MemberVipHistory implements Serializable { |
34 | @Column(name = "member_id") | 34 | @Column(name = "member_id") |
35 | private Long memberId; | 35 | private Long memberId; |
36 | 36 | ||
37 | @Transient | ||
38 | private String memberCode; | ||
39 | |||
37 | // 会员vip等级 | 40 | // 会员vip等级 |
38 | @Column(name = "vip") | 41 | @Column(name = "vip") |
39 | private Integer vip; | 42 | private Integer vip; | ... | ... |
1 | package com.topdraw.business.module.member.viphistory.service.impl; | ||
2 | |||
3 | import com.topdraw.business.module.member.domain.Member; | ||
4 | import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory; | ||
5 | |||
6 | import java.time.LocalDateTime; | ||
7 | |||
8 | /** | ||
9 | * @author : | ||
10 | * @description: | ||
11 | * @function : | ||
12 | * @date :Created in 2022/3/8 13:25 | ||
13 | * @version: : | ||
14 | * @modified By: | ||
15 | * @since : modified in 2022/3/8 13:25 | ||
16 | */ | ||
17 | public class MemberVipHistoryBuilder { | ||
18 | |||
19 | |||
20 | public static MemberVipHistory build(Long memberId , int oldVip , int status , LocalDateTime vipExpireTime, int vip){ | ||
21 | MemberVipHistory memberVipHistory = new MemberVipHistory(); | ||
22 | memberVipHistory.setBeforeVip(oldVip); | ||
23 | memberVipHistory.setVipExpireTime(vipExpireTime); | ||
24 | memberVipHistory.setMemberId(memberId); | ||
25 | memberVipHistory.setStatus(status); | ||
26 | memberVipHistory.setVip(vip); | ||
27 | return memberVipHistory; | ||
28 | } | ||
29 | |||
30 | } |
1 | package com.topdraw.business.module.member.viphistory.service.impl; | 1 | package com.topdraw.business.module.member.viphistory.service.impl; |
2 | 2 | ||
3 | 3 | ||
4 | import com.topdraw.aspect.AsyncMqSend; | ||
4 | import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory; | 5 | import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory; |
5 | import com.topdraw.business.module.member.viphistory.repository.MemberVipHistoryRepository; | 6 | import com.topdraw.business.module.member.viphistory.repository.MemberVipHistoryRepository; |
6 | import com.topdraw.business.module.member.viphistory.service.MemberVipHistoryService; | 7 | import com.topdraw.business.module.member.viphistory.service.MemberVipHistoryService; |
... | @@ -58,6 +59,7 @@ public class MemberVipHistoryServiceImpl implements MemberVipHistoryService { | ... | @@ -58,6 +59,7 @@ public class MemberVipHistoryServiceImpl implements MemberVipHistoryService { |
58 | 59 | ||
59 | @Override | 60 | @Override |
60 | @Transactional(rollbackFor = Exception.class) | 61 | @Transactional(rollbackFor = Exception.class) |
62 | @AsyncMqSend | ||
61 | public void create(MemberVipHistory resources) { | 63 | public void create(MemberVipHistory resources) { |
62 | memberVipHistoryRepository.save(resources); | 64 | memberVipHistoryRepository.save(resources); |
63 | } | 65 | } | ... | ... |
... | @@ -65,7 +65,7 @@ public class MemberOperationController { | ... | @@ -65,7 +65,7 @@ public class MemberOperationController { |
65 | MemberDTO memberDTO = memberOperationService.buyVip(buyVipBean); | 65 | MemberDTO memberDTO = memberOperationService.buyVip(buyVipBean); |
66 | 66 | ||
67 | LocalDateTime vipExpireTime = buyVipBean.getVipExpireTime(); | 67 | LocalDateTime vipExpireTime = buyVipBean.getVipExpireTime(); |
68 | this.doInsertVipHistory(id,vip,vipExpireTime); | 68 | // this.doInsertVipHistory(id,vip,vipExpireTime); |
69 | return ResultInfo.success(memberDTO); | 69 | return ResultInfo.success(memberDTO); |
70 | } | 70 | } |
71 | 71 | ... | ... |
... | @@ -87,23 +87,6 @@ public class MemberOperationServiceImpl implements MemberOperationService { | ... | @@ -87,23 +87,6 @@ public class MemberOperationServiceImpl implements MemberOperationService { |
87 | memberDTO.setVip(vip1); | 87 | memberDTO.setVip(vip1); |
88 | memberDTO.setVipExpireTime(vipExpireTime); | 88 | memberDTO.setVipExpireTime(vipExpireTime); |
89 | 89 | ||
90 | /*if (){ | ||
91 | //购买过 判断当前时间有没有过vip过期时间,没有过,失效时间加一年; 过了,当前时间加一年 | ||
92 | //区分是当前vip续费 还是买新的vip | ||
93 | if (ObjectUtil.equal(vip1, memberDTO.getVip())) { | ||
94 | if (now.isBefore(vipExpireTime)) { | ||
95 | LocalDateTime localDateTime = vipExpireTime.plusYears(1L); | ||
96 | memberDTO.setVipExpireTime(localDateTime); | ||
97 | } else { | ||
98 | LocalDateTime localDateTime = now.plusYears(1L); | ||
99 | memberDTO.setVipExpireTime(localDateTime); | ||
100 | } | ||
101 | } else { | ||
102 | LocalDateTime localDateTime = now.plusYears(1L); | ||
103 | memberDTO.setVipExpireTime(localDateTime); | ||
104 | } | ||
105 | }*/ | ||
106 | |||
107 | Member member = new Member(); | 90 | Member member = new Member(); |
108 | BeanUtils.copyProperties(memberDTO,member); | 91 | BeanUtils.copyProperties(memberDTO,member); |
109 | this.memberService.create(member); | 92 | this.memberService.create(member); |
... | @@ -113,6 +96,7 @@ public class MemberOperationServiceImpl implements MemberOperationService { | ... | @@ -113,6 +96,7 @@ public class MemberOperationServiceImpl implements MemberOperationService { |
113 | if (ObjectUtil.equal(vip1,vip)) { | 96 | if (ObjectUtil.equal(vip1,vip)) { |
114 | memberVipHistory.setStatus(1); | 97 | memberVipHistory.setStatus(1); |
115 | } | 98 | } |
99 | memberVipHistory.setMemberCode(member.getCode()); | ||
116 | memberVipHistory.setVipExpireTime(member.getVipExpireTime()); | 100 | memberVipHistory.setVipExpireTime(member.getVipExpireTime()); |
117 | memberVipHistoryService.create(memberVipHistory); | 101 | memberVipHistoryService.create(memberVipHistory); |
118 | 102 | ... | ... |
... | @@ -24,7 +24,7 @@ public class MemberControllerTest extends BaseTest { | ... | @@ -24,7 +24,7 @@ public class MemberControllerTest extends BaseTest { |
24 | member.setId(5L); | 24 | member.setId(5L); |
25 | member.setVip(4); | 25 | member.setVip(4); |
26 | String s = JSON.toJSONString(member); | 26 | String s = JSON.toJSONString(member); |
27 | ResultInfo byId = this.memberController.doUpdateVip(member); | 27 | ResultInfo byId = this.memberController.doUpdateVipAndSaveVipHistory(member); |
28 | LOG.info("===>>>"+byId); | 28 | LOG.info("===>>>"+byId); |
29 | } | 29 | } |
30 | 30 | ... | ... |
-
Please register or sign in to post a comment