1.优化部分会员信息与会员属性逻辑
Showing
101 changed files
with
1948 additions
and
3081 deletions
1 | package com.topdraw.business.module.common.domain; | 1 | package com.topdraw.business.module.common.domain; |
2 | 2 | ||
3 | import com.topdraw.business.common.CreateGroup; | 3 | import com.topdraw.business.module.common.validated.CreateGroup; |
4 | import com.topdraw.business.common.UpdateGroup; | 4 | import com.topdraw.business.module.common.validated.UpdateGroup; |
5 | import lombok.Data; | 5 | import lombok.Data; |
6 | import lombok.experimental.Accessors; | 6 | import lombok.experimental.Accessors; |
7 | 7 | ||
... | @@ -19,10 +19,13 @@ import javax.validation.constraints.NotNull; | ... | @@ -19,10 +19,13 @@ import javax.validation.constraints.NotNull; |
19 | */ | 19 | */ |
20 | @Data | 20 | @Data |
21 | @Accessors(chain = true) | 21 | @Accessors(chain = true) |
22 | public class DefaultAsyncMqModule { | 22 | public class AsyncMqModule { |
23 | 23 | ||
24 | @Transient | 24 | @Transient |
25 | @NotNull(message = "memberCode can't be null" , groups = {CreateGroup.class, UpdateGroup.class}) | 25 | @NotNull(message = "memberCode can't be null" , groups = {CreateGroup.class, UpdateGroup.class}) |
26 | private String memberCode; | 26 | private String memberCode; |
27 | 27 | ||
28 | /** 运营商平台账号 */ | ||
29 | @Transient | ||
30 | private String platformAccount; | ||
28 | } | 31 | } | ... | ... |
1 | package com.topdraw.business.module.member.address.domain; | 1 | package com.topdraw.business.module.member.address.domain; |
2 | 2 | ||
3 | import com.topdraw.business.common.CreateGroup; | 3 | import com.topdraw.business.module.common.domain.AsyncMqModule; |
4 | import com.topdraw.business.common.UpdateGroup; | ||
5 | import lombok.Data; | 4 | import lombok.Data; |
6 | import lombok.experimental.Accessors; | 5 | import lombok.experimental.Accessors; |
7 | import cn.hutool.core.bean.BeanUtil; | 6 | import cn.hutool.core.bean.BeanUtil; |
8 | import cn.hutool.core.bean.copier.CopyOptions; | 7 | import cn.hutool.core.bean.copier.CopyOptions; |
9 | import javax.persistence.*; | 8 | import javax.persistence.*; |
10 | import javax.validation.constraints.NotNull; | ||
11 | 9 | ||
12 | import org.springframework.data.annotation.CreatedDate; | 10 | import org.springframework.data.annotation.CreatedDate; |
13 | import org.springframework.data.annotation.LastModifiedDate; | 11 | import org.springframework.data.annotation.LastModifiedDate; |
... | @@ -25,7 +23,7 @@ import java.time.LocalDateTime; | ... | @@ -25,7 +23,7 @@ import java.time.LocalDateTime; |
25 | @EntityListeners(AuditingEntityListener.class) | 23 | @EntityListeners(AuditingEntityListener.class) |
26 | @Accessors(chain = true) | 24 | @Accessors(chain = true) |
27 | @Table(name="uc_member_address") | 25 | @Table(name="uc_member_address") |
28 | public class MemberAddress implements Serializable { | 26 | public class MemberAddress extends AsyncMqModule implements Serializable { |
29 | 27 | ||
30 | /** 主键 */ | 28 | /** 主键 */ |
31 | @Id | 29 | @Id |
... | @@ -37,10 +35,6 @@ public class MemberAddress implements Serializable { | ... | @@ -37,10 +35,6 @@ public class MemberAddress implements Serializable { |
37 | @Column(name = "member_id", nullable = false) | 35 | @Column(name = "member_id", nullable = false) |
38 | private Long memberId; | 36 | private Long memberId; |
39 | 37 | ||
40 | @Transient | ||
41 | @NotNull(message = "memberCode can't be null" , groups= {CreateGroup.class}) | ||
42 | private String memberCode; | ||
43 | |||
44 | /** 类型 1:家;2:公司;3:学校 */ | 38 | /** 类型 1:家;2:公司;3:学校 */ |
45 | @Column(name = "type", nullable = false) | 39 | @Column(name = "type", nullable = false) |
46 | private Integer type; | 40 | private Integer type; | ... | ... |
1 | package com.topdraw.business.module.member.address.domain; | ||
2 | |||
3 | import com.topdraw.business.module.member.domain.Member; | ||
4 | import org.apache.commons.lang3.StringUtils; | ||
5 | |||
6 | import java.util.Objects; | ||
7 | |||
8 | /** | ||
9 | * @author : | ||
10 | * @description: | ||
11 | * @function : | ||
12 | * @date :Created in 2022/3/11 11:08 | ||
13 | * @version: : | ||
14 | * @modified By: | ||
15 | * @since : modified in 2022/3/11 11:08 | ||
16 | */ | ||
17 | public class MemberAddressBuilder { | ||
18 | |||
19 | private static final Integer DEFAULT_VALUE_0 = 0; | ||
20 | private static final Integer DEFAULT_VALUE_1 = 1; | ||
21 | |||
22 | public static MemberAddress build(MemberAddress memberAddress, Long memberId,String memberCode){ | ||
23 | Long id = memberAddress.getId(); | ||
24 | Integer type = memberAddress.getType(); | ||
25 | Integer isDefault = memberAddress.getIsDefault(); | ||
26 | Integer sequence = memberAddress.getSequence(); | ||
27 | Integer status= memberAddress.getStatus(); | ||
28 | String contactor = memberAddress.getContactor(); | ||
29 | String cellphone = memberAddress.getCellphone(); | ||
30 | String country = memberAddress.getCountry(); | ||
31 | String province = memberAddress.getProvince(); | ||
32 | String city = memberAddress.getCity(); | ||
33 | String district = memberAddress.getDistrict(); | ||
34 | String address = memberAddress.getAddress(); | ||
35 | String zipCode = memberAddress.getZipCode(); | ||
36 | return build(id,memberId,memberCode,type,isDefault,sequence,status, | ||
37 | contactor,cellphone,country,province,city,district,address,zipCode); | ||
38 | } | ||
39 | |||
40 | public static MemberAddress build(MemberAddress memberAddress, Member member){ | ||
41 | Long id = memberAddress.getId(); | ||
42 | Long memberId = member.getId(); | ||
43 | String memberCode = member.getCode(); | ||
44 | Integer type = memberAddress.getType(); | ||
45 | Integer isDefault = memberAddress.getIsDefault(); | ||
46 | Integer sequence = memberAddress.getSequence(); | ||
47 | Integer status= memberAddress.getStatus(); | ||
48 | String contactor = memberAddress.getContactor(); | ||
49 | String cellphone = memberAddress.getCellphone(); | ||
50 | String country = memberAddress.getCountry(); | ||
51 | String province = memberAddress.getProvince(); | ||
52 | String city = memberAddress.getCity(); | ||
53 | String district = memberAddress.getDistrict(); | ||
54 | String address = memberAddress.getAddress(); | ||
55 | String zipCode = memberAddress.getZipCode(); | ||
56 | return build(id,memberId,memberCode,type,isDefault,sequence,status, | ||
57 | contactor,cellphone,country,province,city,district,address,zipCode); | ||
58 | } | ||
59 | |||
60 | public static MemberAddress build(MemberAddress memberAddress){ | ||
61 | Long id = memberAddress.getId(); | ||
62 | Long memberId = memberAddress.getMemberId(); | ||
63 | String memberCode = memberAddress.getMemberCode(); | ||
64 | Integer type = memberAddress.getType(); | ||
65 | Integer isDefault = memberAddress.getIsDefault(); | ||
66 | Integer sequence = memberAddress.getSequence(); | ||
67 | Integer status= memberAddress.getStatus(); | ||
68 | String contactor = memberAddress.getContactor(); | ||
69 | String cellphone = memberAddress.getCellphone(); | ||
70 | String country = memberAddress.getCountry(); | ||
71 | String province = memberAddress.getProvince(); | ||
72 | String city = memberAddress.getCity(); | ||
73 | String district = memberAddress.getDistrict(); | ||
74 | String address = memberAddress.getAddress(); | ||
75 | String zipCode = memberAddress.getZipCode(); | ||
76 | return build(id,memberId,memberCode,type,isDefault,sequence,status, | ||
77 | contactor,cellphone,country,province,city,district,address,zipCode); | ||
78 | } | ||
79 | |||
80 | |||
81 | public static MemberAddress build(Long id , Long memberId,String memberCode, | ||
82 | Integer sequence,Integer type ,Integer isDefault , Integer status, | ||
83 | String contactor,String cellphone, | ||
84 | String country,String province,String city, | ||
85 | String district,String address,String zipCode){ | ||
86 | |||
87 | MemberAddress memberAddress = new MemberAddress(); | ||
88 | memberAddress.setId(Objects.nonNull(id)?null:id); | ||
89 | memberAddress.setMemberId(Objects.nonNull(memberId)?null:memberId); | ||
90 | memberAddress.setMemberCode(stringIsNull(memberCode)); | ||
91 | |||
92 | memberAddress.setSequence(Objects.nonNull(sequence)?null:DEFAULT_VALUE_1); | ||
93 | memberAddress.setType(Objects.nonNull(type)?null:DEFAULT_VALUE_0); | ||
94 | memberAddress.setIsDefault(Objects.nonNull(isDefault)?null:DEFAULT_VALUE_0); | ||
95 | memberAddress.setStatus(Objects.nonNull(status)?null:DEFAULT_VALUE_1); | ||
96 | |||
97 | memberAddress.setContactor(stringIsNull(contactor)); | ||
98 | memberAddress.setCellphone(stringIsNull(cellphone)); | ||
99 | |||
100 | memberAddress.setCountry(stringIsNull(country)); | ||
101 | memberAddress.setProvince(stringIsNull(province)); | ||
102 | memberAddress.setCity(stringIsNull(city)); | ||
103 | memberAddress.setDistrict(stringIsNull(district)); | ||
104 | memberAddress.setAddress(stringIsNull(address)); | ||
105 | memberAddress.setZipCode(stringIsNull(zipCode)); | ||
106 | |||
107 | return memberAddress; | ||
108 | |||
109 | } | ||
110 | |||
111 | |||
112 | private static String stringIsNull(String s){ | ||
113 | return StringUtils.isBlank(s)?"":s; | ||
114 | } | ||
115 | |||
116 | private static Object objectIsNull(Object s){ | ||
117 | return Objects.nonNull(s)?null:s; | ||
118 | } | ||
119 | } |
1 | package com.topdraw.business.module.member.address.rest; | 1 | package com.topdraw.business.module.member.address.rest; |
2 | 2 | ||
3 | import com.topdraw.aop.log.Log; | 3 | import com.topdraw.aop.log.Log; |
4 | import com.topdraw.business.common.CreateGroup; | 4 | import com.topdraw.business.module.common.validated.CreateGroup; |
5 | import com.topdraw.business.common.UpdateGroup; | 5 | import com.topdraw.business.module.common.validated.UpdateGroup; |
6 | import com.topdraw.common.ResultInfo; | 6 | import com.topdraw.common.ResultInfo; |
7 | import com.topdraw.business.module.member.address.domain.MemberAddress; | 7 | import com.topdraw.business.module.member.address.domain.MemberAddress; |
8 | import com.topdraw.business.module.member.address.service.MemberAddressService; | 8 | import com.topdraw.business.module.member.address.service.MemberAddressService; | ... | ... |
... | @@ -2,10 +2,6 @@ package com.topdraw.business.module.member.address.service; | ... | @@ -2,10 +2,6 @@ package com.topdraw.business.module.member.address.service; |
2 | 2 | ||
3 | import com.topdraw.business.module.member.address.domain.MemberAddress; | 3 | import com.topdraw.business.module.member.address.domain.MemberAddress; |
4 | import com.topdraw.business.module.member.address.service.dto.MemberAddressDTO; | 4 | import com.topdraw.business.module.member.address.service.dto.MemberAddressDTO; |
5 | import com.topdraw.business.module.member.address.service.dto.MemberAddressQueryCriteria; | ||
6 | import org.springframework.data.domain.Pageable; | ||
7 | import java.util.Map; | ||
8 | import java.util.List; | ||
9 | 5 | ||
10 | /** | 6 | /** |
11 | * @author XiangHan | 7 | * @author XiangHan |
... | @@ -15,10 +11,10 @@ public interface MemberAddressService { | ... | @@ -15,10 +11,10 @@ public interface MemberAddressService { |
15 | 11 | ||
16 | /** | 12 | /** |
17 | * 根据ID查询 | 13 | * 根据ID查询 |
18 | * @param id ID | 14 | * @param resources ID |
19 | * @return MemberAddressDTO | 15 | * @return MemberAddressDTO |
20 | */ | 16 | */ |
21 | MemberAddressDTO findById(Long id); | 17 | MemberAddressDTO findById(Long resources); |
22 | 18 | ||
23 | /** | 19 | /** |
24 | * 保存会员地址 | 20 | * 保存会员地址 | ... | ... |
1 | package com.topdraw.business.module.member.address.service.dto; | 1 | package com.topdraw.business.module.member.address.service.dto; |
2 | 2 | ||
3 | import lombok.Data; | 3 | import lombok.Data; |
4 | import java.sql.Timestamp; | ||
5 | import java.io.Serializable; | 4 | import java.io.Serializable; |
6 | import java.time.LocalDateTime; | 5 | import java.time.LocalDateTime; |
7 | 6 | ||
... | @@ -13,51 +12,51 @@ import java.time.LocalDateTime; | ... | @@ -13,51 +12,51 @@ import java.time.LocalDateTime; |
13 | @Data | 12 | @Data |
14 | public class MemberAddressDTO implements Serializable { | 13 | public class MemberAddressDTO implements Serializable { |
15 | 14 | ||
16 | // 主键 | 15 | /** 主键 */ |
17 | private Long id; | 16 | private Long id; |
18 | 17 | ||
19 | // 会员id | 18 | /** 会员id */ |
20 | private Long memberId; | 19 | private Long memberId; |
21 | 20 | ||
22 | // 类型 1:家;2:公司;3:学校 | 21 | /** 类型 1:家;2:公司;3:学校 */ |
23 | private Integer type; | 22 | private Integer type; |
24 | 23 | ||
25 | // 是否默认地址 | 24 | /** 是否默认地址 */ |
26 | private Integer isDefault; | 25 | private Integer isDefault; |
27 | 26 | ||
28 | // 显示顺序 | 27 | /** 显示顺序 */ |
29 | private Integer sequence; | 28 | private Integer sequence; |
30 | 29 | ||
31 | // 状态 0:不可用;1-可用 | 30 | /** 状态 0:不可用;1-可用 */ |
32 | private Integer status; | 31 | private Integer status; |
33 | 32 | ||
34 | // 联系人姓名 | 33 | /** 联系人姓名 */ |
35 | private String contactor; | 34 | private String contactor; |
36 | 35 | ||
37 | // 联系人电话 | 36 | /** 联系人电话 */ |
38 | private String cellphone; | 37 | private String cellphone; |
39 | 38 | ||
40 | // 国家 | 39 | /** 国家 */ |
41 | private String country; | 40 | private String country; |
42 | 41 | ||
43 | // 省份 | 42 | /** 省份 */ |
44 | private String province; | 43 | private String province; |
45 | 44 | ||
46 | // 城市 | 45 | /** 城市 */ |
47 | private String city; | 46 | private String city; |
48 | 47 | ||
49 | // 区县 | 48 | /** 区县 */ |
50 | private String district; | 49 | private String district; |
51 | 50 | ||
52 | // 地址 | 51 | /** 地址 */ |
53 | private String address; | 52 | private String address; |
54 | 53 | ||
55 | // 邮编 | 54 | /** 邮编 */ |
56 | private String zipCode; | 55 | private String zipCode; |
57 | 56 | ||
58 | // 创建时间 | 57 | /** 创建时间 */ |
59 | private LocalDateTime createTime; | 58 | private LocalDateTime createTime; |
60 | 59 | ||
61 | // 更新时间 | 60 | /** 更新时间 */ |
62 | private LocalDateTime updateTime; | 61 | private LocalDateTime updateTime; |
63 | } | 62 | } | ... | ... |
... | @@ -2,28 +2,24 @@ package com.topdraw.business.module.member.address.service.impl; | ... | @@ -2,28 +2,24 @@ package com.topdraw.business.module.member.address.service.impl; |
2 | 2 | ||
3 | import com.topdraw.aspect.AsyncMqSend; | 3 | import com.topdraw.aspect.AsyncMqSend; |
4 | import com.topdraw.business.module.member.address.domain.MemberAddress; | 4 | import com.topdraw.business.module.member.address.domain.MemberAddress; |
5 | import com.topdraw.business.module.member.address.domain.MemberAddressBuilder; | ||
5 | import com.topdraw.business.module.member.service.MemberService; | 6 | import com.topdraw.business.module.member.service.MemberService; |
6 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 7 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
8 | import com.topdraw.util.RedissonUtil; | ||
7 | import com.topdraw.utils.ValidationUtil; | 9 | import com.topdraw.utils.ValidationUtil; |
8 | import com.topdraw.business.module.member.address.repository.MemberAddressRepository; | 10 | import com.topdraw.business.module.member.address.repository.MemberAddressRepository; |
9 | import com.topdraw.business.module.member.address.service.MemberAddressService; | 11 | import com.topdraw.business.module.member.address.service.MemberAddressService; |
10 | import com.topdraw.business.module.member.address.service.dto.MemberAddressDTO; | 12 | import com.topdraw.business.module.member.address.service.dto.MemberAddressDTO; |
11 | import com.topdraw.business.module.member.address.service.dto.MemberAddressQueryCriteria; | ||
12 | import com.topdraw.business.module.member.address.service.mapper.MemberAddressMapper; | 13 | import com.topdraw.business.module.member.address.service.mapper.MemberAddressMapper; |
14 | import lombok.extern.slf4j.Slf4j; | ||
15 | import org.redisson.api.RLock; | ||
16 | import org.redisson.api.RedissonClient; | ||
13 | import org.springframework.beans.factory.annotation.Autowired; | 17 | import org.springframework.beans.factory.annotation.Autowired; |
14 | import org.springframework.stereotype.Service; | 18 | import org.springframework.stereotype.Service; |
15 | import org.springframework.transaction.annotation.Propagation; | 19 | import org.springframework.transaction.annotation.Propagation; |
16 | import org.springframework.transaction.annotation.Transactional; | 20 | import org.springframework.transaction.annotation.Transactional; |
17 | import org.springframework.dao.EmptyResultDataAccessException; | 21 | import org.springframework.dao.EmptyResultDataAccessException; |
18 | import org.springframework.data.domain.Page; | ||
19 | import org.springframework.data.domain.Pageable; | ||
20 | import org.springframework.util.Assert; | 22 | import org.springframework.util.Assert; |
21 | import com.topdraw.utils.PageUtil; | ||
22 | import com.topdraw.utils.QueryHelp; | ||
23 | |||
24 | import java.util.List; | ||
25 | import java.util.Map; | ||
26 | import java.util.Objects; | ||
27 | 23 | ||
28 | /** | 24 | /** |
29 | * @author XiangHan | 25 | * @author XiangHan |
... | @@ -31,53 +27,62 @@ import java.util.Objects; | ... | @@ -31,53 +27,62 @@ import java.util.Objects; |
31 | */ | 27 | */ |
32 | @Service | 28 | @Service |
33 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | 29 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) |
30 | @Slf4j | ||
34 | public class MemberAddressServiceImpl implements MemberAddressService { | 31 | public class MemberAddressServiceImpl implements MemberAddressService { |
35 | 32 | ||
36 | @Autowired | 33 | @Autowired |
37 | private MemberAddressRepository MemberAddressRepository; | 34 | private MemberService memberService; |
38 | @Autowired | 35 | @Autowired |
39 | private MemberAddressMapper MemberAddressMapper; | 36 | private MemberAddressMapper memberAddressMapper; |
40 | @Autowired | 37 | @Autowired |
41 | private MemberService memberService; | 38 | private MemberAddressRepository memberAddressRepository; |
39 | |||
40 | @Autowired | ||
41 | private RedissonClient redissonClient; | ||
42 | 42 | ||
43 | @Override | 43 | @Override |
44 | public MemberAddressDTO findById(Long id) { | 44 | public MemberAddressDTO findById(Long id) { |
45 | MemberAddress MemberAddress = MemberAddressRepository.findById(id).orElseGet(MemberAddress::new); | 45 | Assert.notNull(id,"id can't be null"); |
46 | MemberAddress MemberAddress = this.memberAddressRepository.findById(id).orElseGet(MemberAddress::new); | ||
46 | ValidationUtil.isNull(MemberAddress.getId(),"MemberAddress","id",id); | 47 | ValidationUtil.isNull(MemberAddress.getId(),"MemberAddress","id",id); |
47 | return MemberAddressMapper.toDto(MemberAddress); | 48 | return this.memberAddressMapper.toDto(MemberAddress); |
48 | } | 49 | } |
49 | 50 | ||
50 | @Override | 51 | @Override |
51 | @Transactional(rollbackFor = Exception.class) | 52 | @Transactional(rollbackFor = Exception.class) |
52 | @AsyncMqSend() | 53 | @AsyncMqSend() |
53 | public void create(MemberAddress resources) { | 54 | public void create(MemberAddress resources) { |
54 | Long memberId = resources.getMemberId(); | 55 | log.info("MemberAddressServiceImpl ==>> create ==>> param ==>> [{}]",resources); |
55 | MemberDTO memberDTO = this.memberService.findById(memberId); | 56 | MemberDTO memberDTO = this.checkMember(resources); |
56 | String code = memberDTO.getCode(); | 57 | MemberAddress memberAddress = MemberAddressBuilder.build(resources, memberDTO.getId(), memberDTO.getCode()); |
57 | resources.setMemberCode(code); | 58 | this.memberAddressRepository.save(memberAddress); |
58 | MemberAddressRepository.save(resources); | 59 | log.info("MemberAddressServiceImpl ==>> create ==>> result ==>> [{}]",resources); |
59 | } | 60 | } |
60 | 61 | ||
61 | @Override | 62 | @Override |
62 | @Transactional(rollbackFor = Exception.class) | 63 | @Transactional(rollbackFor = Exception.class) |
63 | @AsyncMqSend() | 64 | @AsyncMqSend() |
64 | public void update(MemberAddress resources) { | 65 | public void update(MemberAddress resources) { |
66 | log.info("MemberAddressServiceImpl ==>> update ==>> param ==>> [{}]",resources); | ||
67 | Assert.notNull(resources.getId(),"id can't be null"); | ||
68 | RLock rLock = this.redissonClient.getLock("MemberAddress::update::code" + resources.getId()); | ||
69 | try { | ||
70 | RedissonUtil.lock(rLock); | ||
71 | |||
72 | MemberDTO memberDTO = this.checkMember(resources); | ||
73 | resources.setMemberCode(memberDTO.getCode()); | ||
65 | 74 | ||
66 | Long memberId = resources.getMemberId(); | 75 | MemberAddress MemberAddress = this.memberAddressRepository.findById(resources.getId()).orElseGet(MemberAddress::new); |
67 | Integer sequence = resources.getSequence(); | ||
68 | Assert.notNull(memberId,"memberId can't be null"); | ||
69 | Assert.notNull(sequence,"sequence can't be null"); | ||
70 | MemberDTO memberDTO = this.memberService.findById(memberId); | ||
71 | if (Objects.nonNull(memberDTO)) { | ||
72 | String code = memberDTO.getCode(); | ||
73 | Assert.notNull(code,"code can't be null"); | ||
74 | resources.setMemberCode(code); | ||
75 | MemberAddress MemberAddress = MemberAddressRepository.findById(resources.getId()).orElseGet(MemberAddress::new); | ||
76 | ValidationUtil.isNull( MemberAddress.getId(),"MemberAddress","id",resources.getId()); | 76 | ValidationUtil.isNull( MemberAddress.getId(),"MemberAddress","id",resources.getId()); |
77 | MemberAddress.copy(resources); | 77 | MemberAddress.copy(resources); |
78 | MemberAddressRepository.save(MemberAddress); | 78 | this.memberAddressRepository.save(MemberAddress); |
79 | } | ||
80 | 79 | ||
80 | } catch (Exception e) { | ||
81 | e.printStackTrace(); | ||
82 | throw e; | ||
83 | } finally { | ||
84 | RedissonUtil.unlock(rLock); | ||
85 | } | ||
81 | } | 86 | } |
82 | 87 | ||
83 | @Override | 88 | @Override |
... | @@ -85,10 +90,30 @@ public class MemberAddressServiceImpl implements MemberAddressService { | ... | @@ -85,10 +90,30 @@ public class MemberAddressServiceImpl implements MemberAddressService { |
85 | @AsyncMqSend() | 90 | @AsyncMqSend() |
86 | public void delete(Long id) { | 91 | public void delete(Long id) { |
87 | Assert.notNull(id, "The given id must not be null!"); | 92 | Assert.notNull(id, "The given id must not be null!"); |
88 | MemberAddress MemberAddress = MemberAddressRepository.findById(id).orElseThrow( | 93 | MemberAddress MemberAddress = this.memberAddressRepository.findById(id).orElseThrow( |
89 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", MemberAddress.class, id), 1)); | 94 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", MemberAddress.class, id), 1)); |
90 | MemberAddressRepository.delete(MemberAddress); | 95 | this.memberAddressRepository.delete(MemberAddress); |
96 | } | ||
97 | |||
98 | /** | ||
99 | * 检查会员 | ||
100 | * @param memberAddress | ||
101 | * @return | ||
102 | */ | ||
103 | private MemberDTO checkMember(MemberAddress memberAddress){ | ||
104 | Long memberId = memberAddress.getMemberId(); | ||
105 | String memberCode = memberAddress.getMemberCode(); | ||
106 | return this.checkMember(memberId,memberCode); | ||
91 | } | 107 | } |
92 | 108 | ||
109 | /** | ||
110 | * 检查会员 | ||
111 | * @param memberId 会员id | ||
112 | * @param memberCode 会员code | ||
113 | * @return | ||
114 | */ | ||
115 | private MemberDTO checkMember(Long memberId, String memberCode) { | ||
116 | return this.memberService.checkMember(memberId, memberCode); | ||
117 | } | ||
93 | 118 | ||
94 | } | 119 | } | ... | ... |
... | @@ -2,7 +2,7 @@ package com.topdraw.business.module.member.domain; | ... | @@ -2,7 +2,7 @@ package com.topdraw.business.module.member.domain; |
2 | 2 | ||
3 | import cn.hutool.core.bean.BeanUtil; | 3 | import cn.hutool.core.bean.BeanUtil; |
4 | import cn.hutool.core.bean.copier.CopyOptions; | 4 | import cn.hutool.core.bean.copier.CopyOptions; |
5 | import com.topdraw.business.module.member.relatedinfo.domain.UpdateGroup; | 5 | import com.topdraw.business.module.common.validated.UpdateGroup; |
6 | import lombok.Data; | 6 | import lombok.Data; |
7 | import lombok.experimental.Accessors; | 7 | import lombok.experimental.Accessors; |
8 | import org.springframework.data.annotation.CreatedDate; | 8 | import org.springframework.data.annotation.CreatedDate; |
... | @@ -37,11 +37,11 @@ public class Member implements Serializable { | ... | @@ -37,11 +37,11 @@ public class Member implements Serializable { |
37 | @Id | 37 | @Id |
38 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 38 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
39 | @Column(name = "id") | 39 | @Column(name = "id") |
40 | @NotNull(message = "code can't be null!!",groups = {UpdateGroup.class}) | ||
40 | private Long id; | 41 | private Long id; |
41 | 42 | ||
42 | /** 标识 */ | 43 | /** 标识 */ |
43 | @Column(name = "code", nullable = false) | 44 | @Column(name = "code", nullable = false) |
44 | @NotNull(message = "code can't be null!!",groups = {UpdateGroup.class}) | ||
45 | private String code; | 45 | private String code; |
46 | 46 | ||
47 | /** 类型 1:大屏;2:小屏 */ | 47 | /** 类型 1:大屏;2:小屏 */ | ... | ... |
member-service-impl/src/main/java/com/topdraw/business/module/member/group/domain/Group.java
0 → 100644
1 | package com.topdraw.business.module.member.group.domain; | ||
2 | |||
3 | import cn.hutool.core.bean.BeanUtil; | ||
4 | import cn.hutool.core.bean.copier.CopyOptions; | ||
5 | import lombok.Data; | ||
6 | import lombok.experimental.Accessors; | ||
7 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
8 | |||
9 | import javax.persistence.*; | ||
10 | import java.io.Serializable; | ||
11 | |||
12 | /** | ||
13 | * @author luerlong | ||
14 | * @date 2021-09-27 | ||
15 | */ | ||
16 | @Entity | ||
17 | @Data | ||
18 | @EntityListeners(AuditingEntityListener.class) | ||
19 | @Accessors(chain = true) | ||
20 | @Table(name="uc_group") | ||
21 | public class Group implements Serializable { | ||
22 | |||
23 | /** ID */ | ||
24 | @Id | ||
25 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
26 | @Column(name = "id") | ||
27 | private Long id; | ||
28 | |||
29 | /** CODE */ | ||
30 | @Column(name = "code") | ||
31 | private String code; | ||
32 | |||
33 | /** 名称 */ | ||
34 | @Column(name = "name") | ||
35 | private String name; | ||
36 | |||
37 | /** 状态 0-下线 1-上线 */ | ||
38 | @Column(name = "status") | ||
39 | private Integer status; | ||
40 | |||
41 | /** 权限 0-测试分组 1-鉴权通过(白名单) 2-不允许精准(黑名单)3-可以精准(金名单) */ | ||
42 | @Column(name = "permission_type") | ||
43 | private Integer permissionType; | ||
44 | |||
45 | public void copy(Group source){ | ||
46 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
47 | } | ||
48 | } |
... | @@ -23,58 +23,58 @@ import java.io.Serializable; | ... | @@ -23,58 +23,58 @@ import java.io.Serializable; |
23 | @Table(name="uc_member_group") | 23 | @Table(name="uc_member_group") |
24 | public class MemberGroup implements Serializable { | 24 | public class MemberGroup implements Serializable { |
25 | 25 | ||
26 | // ID ID | 26 | /** ID */ |
27 | @Id | 27 | @Id |
28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 28 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
29 | @Column(name = "id") | 29 | @Column(name = "id") |
30 | private Long id; | 30 | private Long id; |
31 | 31 | ||
32 | // 分组ID | 32 | /** 分组ID */ |
33 | @Column(name = "group_id") | 33 | @Column(name = "group_id") |
34 | private Long groupId; | 34 | private Long groupId; |
35 | 35 | ||
36 | // 会员ID | 36 | /** 会员ID */ |
37 | @Column(name = "member_id") | 37 | @Column(name = "member_id") |
38 | private Long memberId; | 38 | private Long memberId; |
39 | 39 | ||
40 | // 运营商平台账号 | 40 | /** 运营商平台账号 */ |
41 | @Column(name = "platform_account") | 41 | @Column(name = "platform_account") |
42 | private String platformAccount; | 42 | private String platformAccount; |
43 | 43 | ||
44 | // 手机号 | 44 | /** 手机号 */ |
45 | @Column(name = "cellphone") | 45 | @Column(name = "cellphone") |
46 | private String cellphone; | 46 | private String cellphone; |
47 | 47 | ||
48 | // 设备 | 48 | /** 设备 */ |
49 | @Column(name = "stb_id") | 49 | @Column(name = "stb_id") |
50 | private String stbId; | 50 | private String stbId; |
51 | 51 | ||
52 | // 有线MAC地址 | 52 | /** 有线MAC地址 */ |
53 | @Column(name = "eth_mac") | 53 | @Column(name = "eth_mac") |
54 | private String ethMac; | 54 | private String ethMac; |
55 | 55 | ||
56 | // 无线MAC地址 | 56 | /** 无线MAC地址 */ |
57 | @Column(name = "wifi_mac") | 57 | @Column(name = "wifi_mac") |
58 | private String wifiMac; | 58 | private String wifiMac; |
59 | 59 | ||
60 | // 描述 | 60 | /** 描述 */ |
61 | @Column(name = "description") | 61 | @Column(name = "description") |
62 | private String description; | 62 | private String description; |
63 | 63 | ||
64 | // 创建者 | 64 | /** 创建者 */ |
65 | @Column(name = "create_by") | 65 | @Column(name = "create_by") |
66 | private String createBy; | 66 | private String createBy; |
67 | 67 | ||
68 | // 创建时间 | 68 | /** 创建时间 */ |
69 | @CreatedDate | 69 | @CreatedDate |
70 | @Column(name = "create_time") | 70 | @Column(name = "create_time") |
71 | private Timestamp createTime; | 71 | private Timestamp createTime; |
72 | 72 | ||
73 | // 更新者 | 73 | /** 更新者 */ |
74 | @Column(name = "update_by") | 74 | @Column(name = "update_by") |
75 | private String updateBy; | 75 | private String updateBy; |
76 | 76 | ||
77 | // 更新时间 | 77 | /** 更新时间 */ |
78 | @LastModifiedDate | 78 | @LastModifiedDate |
79 | @Column(name = "update_time") | 79 | @Column(name = "update_time") |
80 | private Timestamp updateTime; | 80 | private Timestamp updateTime; | ... | ... |
1 | package com.topdraw.business.module.member.group.repository; | ||
2 | |||
3 | import com.topdraw.business.module.member.group.domain.Group; | ||
4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
6 | import org.springframework.data.jpa.repository.Query; | ||
7 | |||
8 | import java.util.List; | ||
9 | import java.util.Map; | ||
10 | import java.util.Optional; | ||
11 | |||
12 | /** | ||
13 | * @author luerlong | ||
14 | * @date 2021-09-27 | ||
15 | */ | ||
16 | public interface GroupRepository extends JpaRepository<Group, Long>, JpaSpecificationExecutor<Group> { | ||
17 | |||
18 | Optional<Group> findFirstByCode(String code); | ||
19 | |||
20 | List<Group> findByName(String name); | ||
21 | |||
22 | @Query(value = "select t1.id from uc_group t1 left join uc_user__group t2 on t1.id = t2.group_id where t2.user_id = ?1 and t1.permission_type = ?2 ", nativeQuery = true) | ||
23 | List<Map<String, Object>> findByUserIdAndPermissionType(Long userId, Integer type); | ||
24 | } |
1 | package com.topdraw.business.module.member.group.rest; | ||
2 | |||
3 | import com.topdraw.aop.log.Log; | ||
4 | import com.topdraw.common.ResultInfo; | ||
5 | import com.topdraw.business.module.member.group.domain.MemberGroup; | ||
6 | import com.topdraw.business.module.member.group.service.MemberGroupService; | ||
7 | import lombok.extern.slf4j.Slf4j; | ||
8 | import org.springframework.beans.factory.annotation.Autowired; | ||
9 | import org.springframework.validation.annotation.Validated; | ||
10 | import org.springframework.web.bind.annotation.*; | ||
11 | import io.swagger.annotations.*; | ||
12 | |||
13 | /** | ||
14 | * @author XiangHan | ||
15 | * @date 2021-11-17 | ||
16 | */ | ||
17 | @Api(tags = "会员分组管理") | ||
18 | @RestController | ||
19 | @RequestMapping("/ucEngine/api/memberGroup") | ||
20 | @CrossOrigin | ||
21 | @Slf4j | ||
22 | public class MemberGroupController { | ||
23 | |||
24 | @Autowired | ||
25 | private MemberGroupService memberGroupService; | ||
26 | |||
27 | @Log("新增会员分组") | ||
28 | @RequestMapping(value = "/create") | ||
29 | @ApiOperation("新增会员分组") | ||
30 | public ResultInfo create(@Validated @RequestBody MemberGroup resources) { | ||
31 | log.info("memberGroup ==>> create ==>> param ==>> [{}]",resources); | ||
32 | this.memberGroupService.create(resources); | ||
33 | log.info("memberGroup ==>> create ==>> result ==>> [{}]",resources); | ||
34 | return ResultInfo.success(); | ||
35 | } | ||
36 | |||
37 | @Log("修改会员分组") | ||
38 | @RequestMapping(value = "/update") | ||
39 | @ApiOperation("修改会员分组") | ||
40 | public ResultInfo update(@Validated @RequestBody MemberGroup resources) { | ||
41 | log.info("memberGroup ==>> update ==>> param ==>> [{}]",resources); | ||
42 | this.memberGroupService.update(resources); | ||
43 | log.info("memberGroup ==>> update ==>> result ==>> [{}]",resources); | ||
44 | return ResultInfo.success(); | ||
45 | } | ||
46 | |||
47 | @Log("删除会员分组") | ||
48 | @RequestMapping(value = "/{id}") | ||
49 | @ApiOperation("删除会员分组") | ||
50 | public ResultInfo delete(@PathVariable(value = "id") Long resources) { | ||
51 | log.info("memberGroup ==>> delete ==>> param ==>> [{}]",resources); | ||
52 | this.memberGroupService.delete(resources); | ||
53 | log.info("memberGroup ==>> delete ==>> result ==>> [{}]",resources); | ||
54 | return ResultInfo.success(); | ||
55 | } | ||
56 | |||
57 | } |
member-service-impl/src/main/java/com/topdraw/business/module/member/group/service/GroupService.java
0 → 100644
1 | package com.topdraw.business.module.member.group.service; | ||
2 | |||
3 | import com.topdraw.business.module.member.group.service.dto.GroupDTO; | ||
4 | |||
5 | |||
6 | /** | ||
7 | * @author luerlong | ||
8 | * @date 2021-09-27 | ||
9 | */ | ||
10 | public interface GroupService { | ||
11 | |||
12 | |||
13 | /** | ||
14 | * 根据ID查询 | ||
15 | * @param id ID | ||
16 | * @return GroupDTO | ||
17 | */ | ||
18 | GroupDTO findById(Long id); | ||
19 | |||
20 | /** | ||
21 | * Code校验 | ||
22 | * @param code | ||
23 | * @return GroupDTO | ||
24 | */ | ||
25 | GroupDTO getByCode(String code); | ||
26 | } |
... | @@ -25,22 +25,4 @@ public interface MemberGroupService { | ... | @@ -25,22 +25,4 @@ public interface MemberGroupService { |
25 | */ | 25 | */ |
26 | MemberGroupDTO findById(Long id); | 26 | MemberGroupDTO findById(Long id); |
27 | 27 | ||
28 | /** | ||
29 | * 创建会员分组 | ||
30 | * @param resources | ||
31 | */ | ||
32 | void create(MemberGroup resources); | ||
33 | |||
34 | /** | ||
35 | * 修改会员分组 | ||
36 | * @param resources | ||
37 | */ | ||
38 | void update(MemberGroup resources); | ||
39 | |||
40 | /** | ||
41 | * 删除会员分组 | ||
42 | * @param id | ||
43 | */ | ||
44 | void delete(Long id); | ||
45 | |||
46 | } | 28 | } | ... | ... |
member-service-impl/src/main/java/com/topdraw/business/module/member/group/service/dto/GroupDTO.java
0 → 100644
1 | package com.topdraw.business.module.member.group.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | |||
5 | import java.io.Serializable; | ||
6 | |||
7 | |||
8 | /** | ||
9 | * @author luerlong | ||
10 | * @date 2021-09-27 | ||
11 | */ | ||
12 | @Data | ||
13 | public class GroupDTO implements Serializable { | ||
14 | |||
15 | /** ID */ | ||
16 | private Long id; | ||
17 | |||
18 | /** CODE */ | ||
19 | private String code; | ||
20 | |||
21 | /** 名称 */ | ||
22 | private String name; | ||
23 | |||
24 | /** 状态 0-下线 1-上线 */ | ||
25 | private Integer status; | ||
26 | |||
27 | /** 权限 0-测试分组 1-鉴权通过(白名单) 2-不允许精准(黑名单)3-可以精准(金名单) */ | ||
28 | private Integer permissionType; | ||
29 | |||
30 | } |
... | @@ -3,6 +3,7 @@ package com.topdraw.business.module.member.group.service.dto; | ... | @@ -3,6 +3,7 @@ package com.topdraw.business.module.member.group.service.dto; |
3 | import lombok.Data; | 3 | import lombok.Data; |
4 | import java.sql.Timestamp; | 4 | import java.sql.Timestamp; |
5 | import java.io.Serializable; | 5 | import java.io.Serializable; |
6 | import java.util.Set; | ||
6 | 7 | ||
7 | 8 | ||
8 | /** | 9 | /** |
... | @@ -12,42 +13,43 @@ import java.io.Serializable; | ... | @@ -12,42 +13,43 @@ import java.io.Serializable; |
12 | @Data | 13 | @Data |
13 | public class MemberGroupDTO implements Serializable { | 14 | public class MemberGroupDTO implements Serializable { |
14 | 15 | ||
15 | // ID ID | 16 | /** ID */ |
16 | private Long id; | 17 | private Long id; |
17 | 18 | ||
18 | // 分组ID | 19 | /** 分组ID */ |
19 | private Long groupId; | 20 | private Long groupId; |
20 | 21 | ||
21 | // 会员ID | 22 | /** 会员ID */ |
22 | private Long memberId; | 23 | private Long memberId; |
23 | 24 | ||
24 | // 运营商平台账号 | 25 | /** 运营商平台账号 */ |
25 | private String platformAccount; | 26 | private String platformAccount; |
26 | 27 | ||
27 | // 手机号 | 28 | /** 手机号 */ |
28 | private String cellphone; | 29 | private String cellphone; |
29 | 30 | ||
30 | // 设备 | 31 | /** 设备 */ |
31 | private String stbId; | 32 | private String stbId; |
32 | 33 | ||
33 | // 有线MAC地址 | 34 | /** 有线MAC地址 */ |
34 | private String ethMac; | 35 | private String ethMac; |
35 | 36 | ||
36 | // 无线MAC地址 | 37 | /** 无线MAC地址 */ |
37 | private String wifiMac; | 38 | private String wifiMac; |
38 | 39 | ||
39 | // 描述 | 40 | /** 描述 */ |
40 | private String description; | 41 | private String description; |
41 | 42 | ||
42 | // 创建者 | 43 | /** 创建者 */ |
43 | private String createBy; | 44 | private String createBy; |
44 | 45 | ||
45 | // 创建时间 | 46 | /** 创建时间 */ |
46 | private Timestamp createTime; | 47 | private Timestamp createTime; |
47 | 48 | ||
48 | // 更新者 | 49 | /** 更新者 */ |
49 | private String updateBy; | 50 | private String updateBy; |
50 | 51 | ||
51 | // 更新时间 | 52 | /** 更新时间 */ |
52 | private Timestamp updateTime; | 53 | private Timestamp updateTime; |
54 | |||
53 | } | 55 | } | ... | ... |
1 | package com.topdraw.business.module.member.group.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | import com.topdraw.annotation.Query; | ||
5 | |||
6 | /** | ||
7 | * @author XiangHan | ||
8 | * @date 2021-11-17 | ||
9 | */ | ||
10 | @Data | ||
11 | public class MemberGroupQueryCriteria{ | ||
12 | |||
13 | @Query(type = Query.Type.EQUAL) | ||
14 | private Long memberId; | ||
15 | } |
1 | package com.topdraw.business.module.member.group.service.impl; | ||
2 | |||
3 | import com.topdraw.business.module.member.group.domain.Group; | ||
4 | import com.topdraw.business.module.member.group.repository.GroupRepository; | ||
5 | import com.topdraw.business.module.member.group.service.GroupService; | ||
6 | import com.topdraw.business.module.member.group.service.dto.GroupDTO; | ||
7 | import com.topdraw.business.module.member.group.service.mapper.GroupMapper; | ||
8 | import com.topdraw.utils.*; | ||
9 | import org.springframework.beans.factory.annotation.Autowired; | ||
10 | import org.springframework.stereotype.Service; | ||
11 | import org.springframework.transaction.annotation.Propagation; | ||
12 | import org.springframework.transaction.annotation.Transactional; | ||
13 | |||
14 | /** | ||
15 | * @author luerlong | ||
16 | * @date 2021-09-27 | ||
17 | */ | ||
18 | @Service | ||
19 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
20 | public class GroupServiceImpl implements GroupService { | ||
21 | |||
22 | @Autowired | ||
23 | private GroupRepository groupRepository; | ||
24 | |||
25 | @Autowired | ||
26 | private GroupMapper groupMapper; | ||
27 | |||
28 | @Override | ||
29 | public GroupDTO findById(Long id) { | ||
30 | Group group = groupRepository.findById(id).orElseGet(Group::new); | ||
31 | ValidationUtil.isNull(group.getId(),"Group","id",id); | ||
32 | return groupMapper.toDto(group); | ||
33 | } | ||
34 | |||
35 | @Override | ||
36 | public GroupDTO getByCode(String code) { | ||
37 | return StringUtils.isNotEmpty(code) ? groupMapper.toDto(groupRepository.findFirstByCode(code).orElseGet(Group::new)) | ||
38 | : new GroupDTO(); | ||
39 | } | ||
40 | } |
... | @@ -40,29 +40,4 @@ public class MemberGroupServiceImpl implements MemberGroupService { | ... | @@ -40,29 +40,4 @@ public class MemberGroupServiceImpl implements MemberGroupService { |
40 | return this.memberGroupMapper.toDto(memberGroup); | 40 | return this.memberGroupMapper.toDto(memberGroup); |
41 | } | 41 | } |
42 | 42 | ||
43 | @Override | ||
44 | @Transactional(rollbackFor = Exception.class) | ||
45 | public void create(MemberGroup resources) { | ||
46 | this.memberGroupRepository.save(resources); | ||
47 | } | ||
48 | |||
49 | @Override | ||
50 | @Transactional(rollbackFor = Exception.class) | ||
51 | public void update(MemberGroup resources) { | ||
52 | MemberGroup memberGroup = this.memberGroupRepository.findById(resources.getId()).orElseGet(MemberGroup::new); | ||
53 | ValidationUtil.isNull(memberGroup.getId(),"MemberGroup","id",resources.getId()); | ||
54 | memberGroup.copy(resources); | ||
55 | this.memberGroupRepository.save(memberGroup); | ||
56 | } | ||
57 | |||
58 | @Override | ||
59 | @Transactional(rollbackFor = Exception.class) | ||
60 | public void delete(Long id) { | ||
61 | Assert.notNull(id, "The given id must not be null!"); | ||
62 | MemberGroup MemberGroup = this.memberGroupRepository.findById(id).orElseThrow( | ||
63 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", MemberGroup.class, id), 1)); | ||
64 | this.memberGroupRepository.delete(MemberGroup); | ||
65 | } | ||
66 | |||
67 | |||
68 | } | 43 | } | ... | ... |
1 | package com.topdraw.business.module.weixin.service.mapper; | 1 | package com.topdraw.business.module.member.group.service.mapper; |
2 | 2 | ||
3 | import com.topdraw.base.BaseMapper; | 3 | import com.topdraw.base.BaseMapper; |
4 | import com.topdraw.business.module.weixin.domain.WeixinMessageTemplate; | 4 | import com.topdraw.business.module.member.group.domain.Group; |
5 | import com.topdraw.business.module.weixin.service.dto.WeixinMessageTemplateDTO; | 5 | import com.topdraw.business.module.member.group.service.dto.GroupDTO; |
6 | import org.mapstruct.Mapper; | 6 | import org.mapstruct.Mapper; |
7 | import org.mapstruct.ReportingPolicy; | 7 | import org.mapstruct.ReportingPolicy; |
8 | 8 | ||
9 | /** | 9 | /** |
10 | * @author pengmengqing | 10 | * @author luerlong |
11 | * @date 2021-01-28 | 11 | * @date 2021-09-27 |
12 | */ | 12 | */ |
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | 13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) |
14 | public interface WeixinMessageTemplateMapper extends BaseMapper<WeixinMessageTemplateDTO, WeixinMessageTemplate> { | 14 | public interface GroupMapper extends BaseMapper<GroupDTO, Group> { |
15 | 15 | ||
16 | } | 16 | } | ... | ... |
1 | package com.topdraw.business.module.member.level.domain; | 1 | package com.topdraw.business.module.member.level.domain; |
2 | 2 | ||
3 | import com.topdraw.business.common.CreateGroup; | 3 | import com.topdraw.business.module.common.validated.CreateGroup; |
4 | import com.topdraw.business.common.UpdateGroup; | 4 | import com.topdraw.business.module.common.validated.UpdateGroup; |
5 | import lombok.Data; | 5 | import lombok.Data; |
6 | import lombok.experimental.Accessors; | 6 | import lombok.experimental.Accessors; |
7 | import cn.hutool.core.bean.BeanUtil; | 7 | import cn.hutool.core.bean.BeanUtil; | ... | ... |
1 | package com.topdraw.business.module.member.level.rest; | ||
2 | |||
3 | import com.topdraw.aop.log.Log; | ||
4 | import com.topdraw.business.common.CreateGroup; | ||
5 | import com.topdraw.business.common.UpdateGroup; | ||
6 | import com.topdraw.business.module.member.level.domain.MemberLevel; | ||
7 | import com.topdraw.common.ResultInfo; | ||
8 | import com.topdraw.business.module.member.level.service.MemberLevelService; | ||
9 | import lombok.extern.slf4j.Slf4j; | ||
10 | import org.springframework.beans.factory.annotation.Autowired; | ||
11 | import org.springframework.validation.annotation.Validated; | ||
12 | import org.springframework.web.bind.annotation.*; | ||
13 | import io.swagger.annotations.*; | ||
14 | |||
15 | /** | ||
16 | * @author XiangHan | ||
17 | * @date 2021-10-22 | ||
18 | */ | ||
19 | @Api(tags = "等级管理") | ||
20 | @RestController | ||
21 | @RequestMapping("/ucEngine/api/memberLevel") | ||
22 | @CrossOrigin | ||
23 | @Slf4j | ||
24 | public class MemberLevelController { | ||
25 | |||
26 | @Autowired | ||
27 | private MemberLevelService memberLevelService; | ||
28 | |||
29 | @Log("新增会员等级") | ||
30 | @RequestMapping(value = "/create") | ||
31 | @ApiOperation("新增会员等级") | ||
32 | public ResultInfo create(@Validated(value = {CreateGroup.class}) @RequestBody MemberLevel resources) { | ||
33 | log.info("memberLevel ==>> update ==>> param ==>> [{}]",resources); | ||
34 | this.memberLevelService.update(resources); | ||
35 | log.info("memberLevel ==>> update ==>> result ==>> [{}]",resources); | ||
36 | return ResultInfo.success(); | ||
37 | } | ||
38 | |||
39 | @Log("修改等级") | ||
40 | @RequestMapping(value = "/update") | ||
41 | @ApiOperation("修改等级") | ||
42 | public ResultInfo update(@Validated(value = {UpdateGroup.class}) @RequestBody MemberLevel resources) { | ||
43 | log.info("memberLevel ==>> update ==>> param ==>> [{}]",resources); | ||
44 | this.memberLevelService.update(resources); | ||
45 | log.info("memberLevel ==>> update ==>> result ==>> [{}]",resources); | ||
46 | return ResultInfo.success(); | ||
47 | } | ||
48 | |||
49 | @Log("删除等级") | ||
50 | @DeleteMapping(value = "/delete/{id}") | ||
51 | @ApiOperation("删除等级") | ||
52 | public ResultInfo delete(@PathVariable Long resources) { | ||
53 | log.info("memberLevel ==>> delete ==>> param ==>> [{}]",resources); | ||
54 | this.memberLevelService.delete(resources); | ||
55 | log.info("memberLevel ==>> delete ==>> result ==>> [{}]",resources); | ||
56 | return ResultInfo.success(); | ||
57 | } | ||
58 | } |
1 | package com.topdraw.business.module.member.level.service; | 1 | package com.topdraw.business.module.member.level.service; |
2 | 2 | ||
3 | import com.topdraw.business.module.member.level.domain.MemberLevel; | ||
4 | import com.topdraw.business.module.member.level.service.dto.MemberLevelDTO; | 3 | import com.topdraw.business.module.member.level.service.dto.MemberLevelDTO; |
5 | 4 | ||
6 | import java.util.List; | 5 | import java.util.List; |
... | @@ -10,6 +9,7 @@ import java.util.List; | ... | @@ -10,6 +9,7 @@ import java.util.List; |
10 | * @date 2021-10-22 | 9 | * @date 2021-10-22 |
11 | */ | 10 | */ |
12 | public interface MemberLevelService { | 11 | public interface MemberLevelService { |
12 | |||
13 | /** | 13 | /** |
14 | * 根据ID查询 | 14 | * 根据ID查询 |
15 | * @param id ID | 15 | * @param id ID |
... | @@ -18,12 +18,6 @@ public interface MemberLevelService { | ... | @@ -18,12 +18,6 @@ public interface MemberLevelService { |
18 | MemberLevelDTO findById(Long id); | 18 | MemberLevelDTO findById(Long id); |
19 | 19 | ||
20 | /** | 20 | /** |
21 | * | ||
22 | * @param resources | ||
23 | */ | ||
24 | void update(MemberLevel resources); | ||
25 | |||
26 | /** | ||
27 | * Code校验 | 21 | * Code校验 |
28 | * @param code | 22 | * @param code |
29 | * @return MemberLevelDTO | 23 | * @return MemberLevelDTO |
... | @@ -31,13 +25,12 @@ public interface MemberLevelService { | ... | @@ -31,13 +25,12 @@ public interface MemberLevelService { |
31 | MemberLevelDTO getByCode(String code); | 25 | MemberLevelDTO getByCode(String code); |
32 | 26 | ||
33 | /** | 27 | /** |
34 | * | 28 | * 通过等级和状态检索 |
35 | * @param i | 29 | * @param i |
36 | * @param status | 30 | * @param status |
37 | * @return | 31 | * @return |
38 | */ | 32 | */ |
39 | List<MemberLevelDTO> findLevelAndStatus(Integer i, Integer status); | 33 | List<MemberLevelDTO> findLevelAndStatus(Integer i, Integer status); |
40 | 34 | ||
41 | void delete(Long resources); | ||
42 | 35 | ||
43 | } | 36 | } | ... | ... |
... | @@ -12,36 +12,36 @@ import java.io.Serializable; | ... | @@ -12,36 +12,36 @@ import java.io.Serializable; |
12 | @Data | 12 | @Data |
13 | public class MemberLevelDTO implements Serializable { | 13 | public class MemberLevelDTO implements Serializable { |
14 | 14 | ||
15 | // 主键 | 15 | /** 主键 */ |
16 | private Long id; | 16 | private Long id; |
17 | 17 | ||
18 | // 标识 | 18 | /** 标识 */ |
19 | private String code; | 19 | private String code; |
20 | 20 | ||
21 | // 名称 | 21 | /** 名称 */ |
22 | private String name; | 22 | private String name; |
23 | 23 | ||
24 | // 状态 0:未启用;1:启用 | 24 | /** 状态 0:未启用;1:启用 */ |
25 | private Integer status; | 25 | private Integer status; |
26 | 26 | ||
27 | // 对应成长值 | 27 | /** 对应成长值 */ |
28 | private Long expValue; | 28 | private Long expValue; |
29 | 29 | ||
30 | // 等级(不可重复,数字越大等级越高) | 30 | /** 等级(不可重复,数字越大等级越高) */ |
31 | private Integer level; | 31 | private Integer level; |
32 | 32 | ||
33 | // 会员徽标 | 33 | /** 会员徽标 */ |
34 | private String iconUrl; | 34 | private String iconUrl; |
35 | 35 | ||
36 | // 描述 | 36 | /** 描述 */ |
37 | private String description; | 37 | private String description; |
38 | 38 | ||
39 | // 对应任务id,通过此字段可获得该等级所对应的权益 | 39 | /** 对应任务id,通过此字段可获得该等级所对应的权益 */ |
40 | private Long taskId; | 40 | private Long taskId; |
41 | 41 | ||
42 | // 创建时间 | 42 | /** 创建时间 */ |
43 | private Timestamp createTime; | 43 | private Timestamp createTime; |
44 | 44 | ||
45 | // 更新时间 | 45 | /** 更新时间 */ |
46 | private Timestamp updateTime; | 46 | private Timestamp updateTime; |
47 | } | 47 | } | ... | ... |
1 | package com.topdraw.business.module.member.level.service.impl; | 1 | package com.topdraw.business.module.member.level.service.impl; |
2 | 2 | ||
3 | import com.topdraw.aspect.AsyncMqSend; | ||
4 | import com.topdraw.business.module.member.level.domain.MemberLevel; | 3 | import com.topdraw.business.module.member.level.domain.MemberLevel; |
5 | import com.topdraw.utils.ValidationUtil; | 4 | import com.topdraw.utils.ValidationUtil; |
6 | import com.topdraw.business.module.member.level.repository.MemberLevelRepository; | 5 | import com.topdraw.business.module.member.level.repository.MemberLevelRepository; |
7 | import com.topdraw.business.module.member.level.service.MemberLevelService; | 6 | import com.topdraw.business.module.member.level.service.MemberLevelService; |
8 | import com.topdraw.business.module.member.level.service.dto.MemberLevelDTO; | 7 | import com.topdraw.business.module.member.level.service.dto.MemberLevelDTO; |
9 | import com.topdraw.business.module.member.level.service.dto.MemberLevelQueryCriteria; | ||
10 | import com.topdraw.business.module.member.level.service.mapper.MemberLevelMapper; | 8 | import com.topdraw.business.module.member.level.service.mapper.MemberLevelMapper; |
11 | import org.springframework.beans.factory.annotation.Autowired; | 9 | import org.springframework.beans.factory.annotation.Autowired; |
12 | import org.springframework.stereotype.Service; | 10 | import org.springframework.stereotype.Service; |
13 | import org.springframework.transaction.annotation.Propagation; | 11 | import org.springframework.transaction.annotation.Propagation; |
14 | import org.springframework.transaction.annotation.Transactional; | 12 | import org.springframework.transaction.annotation.Transactional; |
15 | import org.springframework.dao.EmptyResultDataAccessException; | ||
16 | import org.springframework.data.domain.Page; | ||
17 | import org.springframework.data.domain.Pageable; | ||
18 | import org.springframework.util.Assert; | ||
19 | import com.topdraw.utils.PageUtil; | ||
20 | import com.topdraw.utils.QueryHelp; | ||
21 | import com.topdraw.utils.StringUtils; | 13 | import com.topdraw.utils.StringUtils; |
22 | 14 | ||
23 | import java.util.List; | 15 | import java.util.List; |
24 | import java.util.Map; | ||
25 | 16 | ||
26 | /** | 17 | /** |
27 | * @author XiangHan | 18 | * @author XiangHan |
... | @@ -32,41 +23,27 @@ import java.util.Map; | ... | @@ -32,41 +23,27 @@ import java.util.Map; |
32 | public class MemberLevelServiceImpl implements MemberLevelService { | 23 | public class MemberLevelServiceImpl implements MemberLevelService { |
33 | 24 | ||
34 | @Autowired | 25 | @Autowired |
35 | private MemberLevelRepository MemberLevelRepository; | 26 | private MemberLevelRepository memberLevelRepository; |
36 | 27 | ||
37 | @Autowired | 28 | @Autowired |
38 | private MemberLevelMapper MemberLevelMapper; | 29 | private MemberLevelMapper memberLevelMapper; |
39 | 30 | ||
40 | @Override | 31 | @Override |
41 | public MemberLevelDTO findById(Long id) { | 32 | public MemberLevelDTO findById(Long id) { |
42 | MemberLevel MemberLevel = MemberLevelRepository.findById(id).orElseGet(MemberLevel::new); | 33 | MemberLevel MemberLevel = this.memberLevelRepository.findById(id).orElseGet(MemberLevel::new); |
43 | ValidationUtil.isNull(MemberLevel.getId(),"MemberLevel","id",id); | 34 | ValidationUtil.isNull(MemberLevel.getId(),"MemberLevel","id",id); |
44 | return MemberLevelMapper.toDto(MemberLevel); | 35 | return this.memberLevelMapper.toDto(MemberLevel); |
45 | } | ||
46 | |||
47 | @Override | ||
48 | @Transactional(rollbackFor = Exception.class) | ||
49 | @AsyncMqSend() | ||
50 | public void update(MemberLevel resources) { | ||
51 | MemberLevel MemberLevel = MemberLevelRepository.findById(resources.getId()).orElseGet(MemberLevel::new); | ||
52 | ValidationUtil.isNull( MemberLevel.getId(),"MemberLevel","id",resources.getId()); | ||
53 | MemberLevel.copy(resources); | ||
54 | MemberLevelRepository.save(MemberLevel); | ||
55 | } | 36 | } |
56 | 37 | ||
57 | @Override | 38 | @Override |
58 | public MemberLevelDTO getByCode(String code) { | 39 | public MemberLevelDTO getByCode(String code) { |
59 | return StringUtils.isNotEmpty(code) ? MemberLevelMapper.toDto(MemberLevelRepository.findFirstByCode(code).orElseGet(MemberLevel::new)) | 40 | return StringUtils.isNotEmpty(code) ? this.memberLevelMapper.toDto(this.memberLevelRepository.findFirstByCode(code).orElseGet(MemberLevel::new)) |
60 | : new MemberLevelDTO(); | 41 | : new MemberLevelDTO(); |
61 | } | 42 | } |
62 | 43 | ||
63 | @Override | 44 | @Override |
64 | public List<MemberLevelDTO> findLevelAndStatus(Integer level, Integer status) { | 45 | public List<MemberLevelDTO> findLevelAndStatus(Integer level, Integer status) { |
65 | return MemberLevelMapper.toDto(MemberLevelRepository.findByLevelAndStatus(level,status)); | 46 | return this.memberLevelMapper.toDto(this.memberLevelRepository.findByLevelAndStatus(level,status)); |
66 | } | 47 | } |
67 | 48 | ||
68 | @Override | ||
69 | public void delete(Long resources) { | ||
70 | MemberLevelRepository.deleteById(resources); | ||
71 | } | ||
72 | } | 49 | } | ... | ... |
1 | package com.topdraw.business.module.member.profile.domain; | 1 | package com.topdraw.business.module.member.profile.domain; |
2 | 2 | ||
3 | import com.topdraw.business.common.CreateGroup; | 3 | import com.topdraw.business.module.common.validated.CreateGroup; |
4 | import com.topdraw.business.common.UpdateGroup; | 4 | import com.topdraw.business.module.common.validated.UpdateGroup; |
5 | import lombok.Data; | 5 | import lombok.Data; |
6 | import lombok.experimental.Accessors; | 6 | import lombok.experimental.Accessors; |
7 | import cn.hutool.core.bean.BeanUtil; | 7 | import cn.hutool.core.bean.BeanUtil; |
... | @@ -15,7 +15,6 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ... | @@ -15,7 +15,6 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; |
15 | import java.sql.Timestamp; | 15 | import java.sql.Timestamp; |
16 | 16 | ||
17 | import java.io.Serializable; | 17 | import java.io.Serializable; |
18 | import java.time.LocalDate; | ||
19 | 18 | ||
20 | /** | 19 | /** |
21 | * @author XiangHan | 20 | * @author XiangHan | ... | ... |
... | @@ -5,7 +5,7 @@ import org.apache.commons.lang3.StringUtils; | ... | @@ -5,7 +5,7 @@ import org.apache.commons.lang3.StringUtils; |
5 | 5 | ||
6 | import java.util.Objects; | 6 | import java.util.Objects; |
7 | 7 | ||
8 | public class MemberProfileBuild { | 8 | public class MemberProfileBuilder { |
9 | 9 | ||
10 | public static MemberProfile build(Member member){ | 10 | public static MemberProfile build(Member member){ |
11 | MemberProfile memberProfile = build(member.getId(),member.getNickname(),member.getGender(),"","","","","","", | 11 | MemberProfile memberProfile = build(member.getId(),member.getNickname(),member.getGender(),"","","","","","", |
... | @@ -61,10 +61,6 @@ public class MemberProfileBuild { | ... | @@ -61,10 +61,6 @@ public class MemberProfileBuild { |
61 | return StringUtils.isBlank(s)?"":s; | 61 | return StringUtils.isBlank(s)?"":s; |
62 | } | 62 | } |
63 | 63 | ||
64 | private static Object objectIsNull(Object s){ | ||
65 | return Objects.nonNull(s)?null:s; | ||
66 | } | ||
67 | |||
68 | public static MemberProfile build(MemberProfile resources) { | 64 | public static MemberProfile build(MemberProfile resources) { |
69 | if (resources.getMemberId() == null) | 65 | if (resources.getMemberId() == null) |
70 | throw new NullPointerException("memberId is null"); | 66 | throw new NullPointerException("memberId is null"); | ... | ... |
... | @@ -3,11 +3,10 @@ package com.topdraw.business.module.member.profile.service.impl; | ... | @@ -3,11 +3,10 @@ package com.topdraw.business.module.member.profile.service.impl; |
3 | import com.topdraw.aspect.AsyncMqSend; | 3 | import com.topdraw.aspect.AsyncMqSend; |
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.profile.domain.MemberProfile; | 5 | import com.topdraw.business.module.member.profile.domain.MemberProfile; |
6 | import com.topdraw.business.module.member.profile.domain.MemberProfileBuild; | 6 | import com.topdraw.business.module.member.profile.domain.MemberProfileBuilder; |
7 | import com.topdraw.business.module.member.repository.MemberRepository; | ||
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.exception.BadRequestException; | 9 | import com.topdraw.util.Base64Util; |
11 | import com.topdraw.util.RedissonUtil; | 10 | import com.topdraw.util.RedissonUtil; |
12 | import com.topdraw.utils.StringUtils; | 11 | import com.topdraw.utils.StringUtils; |
13 | import com.topdraw.utils.ValidationUtil; | 12 | import com.topdraw.utils.ValidationUtil; |
... | @@ -26,8 +25,6 @@ import org.springframework.transaction.annotation.Transactional; | ... | @@ -26,8 +25,6 @@ import org.springframework.transaction.annotation.Transactional; |
26 | import org.springframework.dao.EmptyResultDataAccessException; | 25 | import org.springframework.dao.EmptyResultDataAccessException; |
27 | import org.springframework.util.Assert; | 26 | import org.springframework.util.Assert; |
28 | 27 | ||
29 | import java.nio.charset.StandardCharsets; | ||
30 | import java.util.*; | ||
31 | 28 | ||
32 | /** | 29 | /** |
33 | * @author XiangHan | 30 | * @author XiangHan |
... | @@ -75,13 +72,11 @@ public class MemberProfileServiceImpl implements MemberProfileService { | ... | @@ -75,13 +72,11 @@ public class MemberProfileServiceImpl implements MemberProfileService { |
75 | @Transactional(rollbackFor = Exception.class) | 72 | @Transactional(rollbackFor = Exception.class) |
76 | @AsyncMqSend() | 73 | @AsyncMqSend() |
77 | public MemberProfile create(MemberProfile resources) { | 74 | public MemberProfile create(MemberProfile resources) { |
78 | |||
79 | log.info("MemberProfileServiceImpl ==>> update ==>> resources ===>> [{}]",resources); | 75 | log.info("MemberProfileServiceImpl ==>> update ==>> resources ===>> [{}]",resources); |
80 | Long memberId = resources.getMemberId(); | ||
81 | Assert.notNull(memberId,"memberId can't be null !!"); | ||
82 | 76 | ||
83 | MemberDTO memberDTO = this.memberService.findById(memberId); | 77 | // 检查会员 |
84 | if (Objects.nonNull(memberDTO.getCode())) | 78 | this.checkMember(resources); |
79 | |||
85 | this.memberProfileRepository.save(resources); | 80 | this.memberProfileRepository.save(resources); |
86 | 81 | ||
87 | return resources; | 82 | return resources; |
... | @@ -90,62 +85,53 @@ public class MemberProfileServiceImpl implements MemberProfileService { | ... | @@ -90,62 +85,53 @@ public class MemberProfileServiceImpl implements MemberProfileService { |
90 | @Override | 85 | @Override |
91 | @Transactional(rollbackFor = Exception.class) | 86 | @Transactional(rollbackFor = Exception.class) |
92 | public MemberProfile createDefault(MemberProfile resources) { | 87 | public MemberProfile createDefault(MemberProfile resources) { |
93 | MemberProfile memberProfile = MemberProfileBuild.build(); | 88 | MemberProfile memberProfile = MemberProfileBuilder.build(); |
94 | return this.create(memberProfile); | 89 | return this.create(memberProfile); |
95 | } | 90 | } |
96 | 91 | ||
97 | @Override | 92 | @Override |
98 | @Transactional(rollbackFor = Exception.class) | 93 | @Transactional(rollbackFor = Exception.class) |
99 | public MemberProfile createDefault(Member resources) { | 94 | public MemberProfile createDefault(Member resources) { |
100 | MemberProfile memberProfile = MemberProfileBuild.build(resources); | 95 | MemberProfile memberProfile = MemberProfileBuilder.build(resources); |
101 | return this.create(memberProfile); | 96 | return this.create(memberProfile); |
102 | } | 97 | } |
103 | 98 | ||
104 | @Override | 99 | @Override |
105 | public MemberProfile createDefaultByMemberId(Long resources) { | 100 | public MemberProfile createDefaultByMemberId(Long resources) { |
106 | MemberProfile memberProfile = MemberProfileBuild.build(resources); | 101 | MemberProfile memberProfile = MemberProfileBuilder.build(resources); |
107 | return this.create(memberProfile); | 102 | return this.create(memberProfile); |
108 | } | 103 | } |
109 | 104 | ||
110 | @Override | 105 | private MemberDTO checkMember(MemberProfile resources){ |
111 | @Transactional(rollbackFor = Exception.class) | ||
112 | @AsyncMqSend() | ||
113 | public void update(MemberProfile resources) { | ||
114 | log.info("MemberProfileServiceImpl ==>> update ==>> resources ===>> [{}]",resources); | ||
115 | |||
116 | Long memberId = resources.getMemberId(); | 106 | Long memberId = resources.getMemberId(); |
117 | String memberCode = resources.getMemberCode(); | 107 | String memberCode = resources.getMemberCode(); |
118 | if (Objects.isNull(memberId) && StringUtils.isBlank(memberCode)) | ||
119 | throw new BadRequestException("memberId Or memberCode both null !!"); | ||
120 | 108 | ||
121 | String realName = resources.getRealname(); | 109 | return this.memberService.checkMember(memberId,memberCode); |
122 | if (StringUtils.isNotBlank(realName)) { | ||
123 | resources.setRealname(new String(Base64.getEncoder().encode(realName.getBytes(StandardCharsets.UTF_8)))); | ||
124 | } | 110 | } |
125 | 111 | ||
112 | @Override | ||
113 | @Transactional(rollbackFor = Exception.class) | ||
114 | @AsyncMqSend() | ||
115 | public void update(MemberProfile resources) { | ||
116 | |||
117 | log.info("MemberProfileServiceImpl ==>> update ==>> resources ===>> [{}]",resources); | ||
126 | RLock rLock = this.redissonClient.getLock("memberProfile::update::id" + resources.getId()); | 118 | RLock rLock = this.redissonClient.getLock("memberProfile::update::id" + resources.getId()); |
127 | try { | 119 | try { |
128 | RedissonUtil.lock(rLock); | 120 | RedissonUtil.lock(rLock); |
129 | 121 | ||
130 | this.memberService.findByIdOrCode(memberId, memberCode); | 122 | // 检查会员是否存在 |
131 | 123 | this.checkMember(resources); | |
132 | MemberProfileDTO memberProfile = this.findByMemberId(memberId); | 124 | // 真实姓名(加密) |
133 | if (Objects.nonNull(memberProfile)) { | 125 | String realName = resources.getRealname(); |
134 | resources.setId(memberProfile.getId()); | 126 | if (StringUtils.isNotBlank(realName)) { |
135 | 127 | resources.setRealname(Base64Util.encode(realName)); | |
136 | MemberProfile memberProfile1 = new MemberProfile(); | 128 | } |
137 | BeanUtils.copyProperties(memberProfile,memberProfile1); | ||
138 | this.memberProfileRepository.save(memberProfile1); | ||
139 | 129 | ||
130 | MemberProfile memberProfile = new MemberProfile(); | ||
131 | BeanUtils.copyProperties(resources,memberProfile); | ||
132 | this.memberProfileRepository.save(memberProfile); | ||
140 | // 同步会员信息 | 133 | // 同步会员信息 |
141 | this.synchronizedMemberData(resources); | 134 | this.synchronizedMemberData(resources); |
142 | |||
143 | } else { | ||
144 | resources.setId(null); | ||
145 | MemberProfile memberProfile1 = MemberProfileBuild.build(resources); | ||
146 | this.create(memberProfile1); | ||
147 | } | ||
148 | |||
149 | } catch (Exception e) { | 135 | } catch (Exception e) { |
150 | e.printStackTrace(); | 136 | e.printStackTrace(); |
151 | throw e; | 137 | throw e; |
... | @@ -169,22 +155,20 @@ public class MemberProfileServiceImpl implements MemberProfileService { | ... | @@ -169,22 +155,20 @@ public class MemberProfileServiceImpl implements MemberProfileService { |
169 | @Transactional(rollbackFor = Exception.class) | 155 | @Transactional(rollbackFor = Exception.class) |
170 | public void updateMemberProfileAndMember(MemberProfile resources) { | 156 | public void updateMemberProfileAndMember(MemberProfile resources) { |
171 | log.info("MemberProfileServiceImpl ==>> updateMemberProfileAndMember ==>> resources ===>> [{}]",resources); | 157 | log.info("MemberProfileServiceImpl ==>> updateMemberProfileAndMember ==>> resources ===>> [{}]",resources); |
172 | |||
173 | this.update(resources); | 158 | this.update(resources); |
174 | |||
175 | } | 159 | } |
176 | 160 | ||
177 | 161 | /** | |
162 | * 同步会员信息 | ||
163 | * @param nickName | ||
164 | * @param gender | ||
165 | * @param birthday | ||
166 | * @param avatarUrl | ||
167 | * @param member | ||
168 | */ | ||
178 | private void synchronizedMemberData(String nickName , Integer gender , String birthday, | 169 | private void synchronizedMemberData(String nickName , Integer gender , String birthday, |
179 | String avatarUrl,Member member) { | 170 | String avatarUrl,Member member) { |
180 | MemberProfile memberProfile = new MemberProfile(); | 171 | this.synchronizedMemberData(nickName,gender,birthday,avatarUrl,member.getId(),member.getCode()); |
181 | memberProfile.setMemberId(member.getId()); | ||
182 | memberProfile.setMemberCode(member.getCode()); | ||
183 | memberProfile.setRealname(nickName); | ||
184 | memberProfile.setGender(gender); | ||
185 | memberProfile.setBirthday(birthday); | ||
186 | memberProfile.setAvatarUrl(avatarUrl); | ||
187 | this.synchronizedMemberData(memberProfile); | ||
188 | } | 172 | } |
189 | 173 | ||
190 | private void synchronizedMemberData(String nickName , Integer gender , String birthday, | 174 | private void synchronizedMemberData(String nickName , Integer gender , String birthday, |
... | @@ -201,17 +185,17 @@ public class MemberProfileServiceImpl implements MemberProfileService { | ... | @@ -201,17 +185,17 @@ public class MemberProfileServiceImpl implements MemberProfileService { |
201 | 185 | ||
202 | private void synchronizedMemberData(MemberProfile resources) { | 186 | private void synchronizedMemberData(MemberProfile resources) { |
203 | 187 | ||
204 | MemberDTO memberDTO = this.memberService.findByIdOrCode(resources.getMemberId(),resources.getMemberCode()); | 188 | log.info("updateMemberProfileAndMember ==>> resources ==>> [{}]",resources); |
205 | 189 | ||
206 | Member member = new Member(); | 190 | Member member = new Member(); |
207 | BeanUtils.copyProperties(memberDTO,member); | 191 | member.setId(resources.getMemberId()); |
192 | member.setCode(resources.getMemberCode()); | ||
208 | member.setNickname(resources.getRealname()); | 193 | member.setNickname(resources.getRealname()); |
209 | member.setGender(resources.getGender()); | 194 | member.setGender(resources.getGender()); |
210 | member.setBirthday(resources.getBirthday()); | 195 | member.setBirthday(resources.getBirthday()); |
211 | member.setAvatarUrl(resources.getAvatarUrl()); | 196 | member.setAvatarUrl(resources.getAvatarUrl()); |
212 | 197 | ||
213 | log.info("updateMemberProfileAndMember ==>> member ==>> [{}]",member); | 198 | this.memberService.update(member); |
214 | memberService.update(member); | ||
215 | } | 199 | } |
216 | 200 | ||
217 | } | 201 | } | ... | ... |
1 | package com.topdraw.business.module.member.relatedinfo.domain; | 1 | package com.topdraw.business.module.member.relatedinfo.domain; |
2 | 2 | ||
3 | import com.topdraw.business.module.common.domain.DefaultAsyncMqModule; | 3 | import com.topdraw.business.module.common.validated.UpdateGroup; |
4 | import com.topdraw.business.module.common.domain.AsyncMqModule; | ||
4 | import lombok.Data; | 5 | import lombok.Data; |
5 | import lombok.experimental.Accessors; | 6 | import lombok.experimental.Accessors; |
6 | import cn.hutool.core.bean.BeanUtil; | 7 | import cn.hutool.core.bean.BeanUtil; |
... | @@ -25,53 +26,53 @@ import java.time.LocalDate; | ... | @@ -25,53 +26,53 @@ import java.time.LocalDate; |
25 | @EntityListeners(AuditingEntityListener.class) | 26 | @EntityListeners(AuditingEntityListener.class) |
26 | @Accessors(chain = true) | 27 | @Accessors(chain = true) |
27 | @Table(name="uc_member_related_info") | 28 | @Table(name="uc_member_related_info") |
28 | public class MemberRelatedInfo extends DefaultAsyncMqModule implements Serializable { | 29 | public class MemberRelatedInfo extends AsyncMqModule implements Serializable { |
29 | 30 | ||
30 | // ID | 31 | /** ID */ |
31 | @Id | 32 | @Id |
32 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 33 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
33 | @Column(name = "id") | 34 | @Column(name = "id") |
34 | @NotNull(groups = {UpdateGroup.class}) | 35 | @NotNull(message = "id can't be null" , groups = {UpdateGroup.class}) |
35 | private Long id; | 36 | private Long id; |
36 | 37 | ||
37 | // 会员id | 38 | /** 会员id */ |
38 | @Column(name = "member_id", nullable = false) | 39 | @Column(name = "member_id", nullable = false) |
39 | private Long memberId; | 40 | private Long memberId; |
40 | 41 | ||
41 | // 人物关系 0:子女;1:父母 | 42 | /** 人物关系 0:子女;1:父母 */ |
42 | @Column(name = "type") | 43 | @Column(name = "type") |
43 | private Integer type; | 44 | private Integer type; |
44 | 45 | ||
45 | // 手机号 | 46 | /** 手机号 */ |
46 | @Column(name = "cellphone") | 47 | @Column(name = "cellphone") |
47 | private String cellphone; | 48 | private String cellphone; |
48 | 49 | ||
49 | // 身份证号 | 50 | /** 身份证号 */ |
50 | @Column(name = "id_card") | 51 | @Column(name = "id_card") |
51 | private String idCard; | 52 | private String idCard; |
52 | 53 | ||
53 | // 姓名 | 54 | /** 姓名 */ |
54 | @Column(name = "name") | 55 | @Column(name = "name") |
55 | private String name; | 56 | private String name; |
56 | 57 | ||
57 | // 性别 0:女;1:男;-1:未知 | 58 | /** 性别 0:女;1:男;-1:未知 */ |
58 | @Column(name = "sex") | 59 | @Column(name = "sex") |
59 | private Integer sex; | 60 | private Integer sex; |
60 | 61 | ||
61 | // 生日 | 62 | /** 生日 */ |
62 | @Column(name = "birthday") | 63 | @Column(name = "birthday") |
63 | private LocalDate birthday; | 64 | private LocalDate birthday; |
64 | 65 | ||
65 | // 头像地址 | 66 | /** 头像地址 */ |
66 | @Column(name = "avatar_url") | 67 | @Column(name = "avatar_url") |
67 | private String avatarUrl; | 68 | private String avatarUrl; |
68 | 69 | ||
69 | // 创建时间 | 70 | /** 创建时间 */ |
70 | @CreatedDate | 71 | @CreatedDate |
71 | @Column(name = "create_time") | 72 | @Column(name = "create_time") |
72 | private Timestamp createTime; | 73 | private Timestamp createTime; |
73 | 74 | ||
74 | // 更新时间 | 75 | /** 更新时间 */ |
75 | @LastModifiedDate | 76 | @LastModifiedDate |
76 | @Column(name = "update_time") | 77 | @Column(name = "update_time") |
77 | private Timestamp updateTime; | 78 | private Timestamp updateTime; | ... | ... |
1 | package com.topdraw.business.module.member.relatedinfo.domain; | ||
2 | |||
3 | import com.topdraw.business.module.member.domain.Member; | ||
4 | import org.apache.commons.lang3.StringUtils; | ||
5 | |||
6 | import java.time.LocalDate; | ||
7 | import java.util.Objects; | ||
8 | |||
9 | /** | ||
10 | * @author : | ||
11 | * @description: | ||
12 | * @function : | ||
13 | * @date :Created in 2022/3/11 13:56 | ||
14 | * @version: : | ||
15 | * @modified By: | ||
16 | * @since : modified in 2022/3/11 13:56 | ||
17 | */ | ||
18 | public class MemberRelatedInfoBuilder { | ||
19 | |||
20 | private static final Integer DEFAULT_VALUE_ = -1; | ||
21 | private static final Integer DEFAULT_VALUE_0 = 0; | ||
22 | |||
23 | public static MemberRelatedInfo build(MemberRelatedInfo memberRelatedInfo){ | ||
24 | return build(memberRelatedInfo.getId(),memberRelatedInfo.getMemberCode(),memberRelatedInfo.getId(),memberRelatedInfo.getName(),memberRelatedInfo.getSex(), | ||
25 | memberRelatedInfo.getCellphone(),memberRelatedInfo.getIdCard(),memberRelatedInfo.getBirthday(),memberRelatedInfo.getAvatarUrl(),memberRelatedInfo.getType()); | ||
26 | } | ||
27 | |||
28 | public static MemberRelatedInfo build(Member member , MemberRelatedInfo memberRelatedInfo){ | ||
29 | return build(member.getId(),member.getCode(),memberRelatedInfo.getId(),memberRelatedInfo.getName(),memberRelatedInfo.getSex(), | ||
30 | memberRelatedInfo.getCellphone(),memberRelatedInfo.getIdCard(),memberRelatedInfo.getBirthday(),memberRelatedInfo.getAvatarUrl(),memberRelatedInfo.getType()); | ||
31 | } | ||
32 | |||
33 | public static MemberRelatedInfo build(Long memberId , String memberCode , Long id , String name , Integer sex , | ||
34 | String cellphone , String idCard, LocalDate birthday , String avatarUrl , Integer type){ | ||
35 | MemberRelatedInfo memberRelatedInfo = new MemberRelatedInfo(); | ||
36 | memberRelatedInfo.setMemberId(memberId); | ||
37 | memberRelatedInfo.setMemberCode(memberCode); | ||
38 | |||
39 | memberRelatedInfo.setId(id); | ||
40 | memberRelatedInfo.setName(stringIsNull(name)); | ||
41 | memberRelatedInfo.setSex(Objects.isNull(sex)?DEFAULT_VALUE_:sex); | ||
42 | memberRelatedInfo.setCellphone(stringIsNull(cellphone)); | ||
43 | memberRelatedInfo.setIdCard(StringUtils.isBlank(idCard)?"000000000000000000":idCard); | ||
44 | |||
45 | memberRelatedInfo.setBirthday(Objects.isNull(birthday)? LocalDate.of(1990,01,01):birthday); | ||
46 | memberRelatedInfo.setAvatarUrl(stringIsNull(avatarUrl)); | ||
47 | |||
48 | memberRelatedInfo.setType(Objects.isNull(type)?DEFAULT_VALUE_0:type); | ||
49 | return memberRelatedInfo; | ||
50 | } | ||
51 | |||
52 | private static String stringIsNull(String s){ | ||
53 | return StringUtils.isBlank(s)?"":s; | ||
54 | } | ||
55 | |||
56 | } |
... | @@ -4,10 +4,17 @@ import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo; | ... | @@ -4,10 +4,17 @@ import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo; |
4 | import org.springframework.data.jpa.repository.JpaRepository; | 4 | import org.springframework.data.jpa.repository.JpaRepository; |
5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
6 | 6 | ||
7 | |||
7 | /** | 8 | /** |
8 | * @author XiangHan | 9 | * @author XiangHan |
9 | * @date 2021-10-22 | 10 | * @date 2021-10-22 |
10 | */ | 11 | */ |
11 | public interface MemberRelatedInfoRepository extends JpaRepository<MemberRelatedInfo, Long>, JpaSpecificationExecutor<MemberRelatedInfo> { | 12 | public interface MemberRelatedInfoRepository extends JpaRepository<MemberRelatedInfo, Long>, JpaSpecificationExecutor<MemberRelatedInfo> { |
12 | 13 | ||
14 | |||
15 | MemberRelatedInfo findByIdCard(String idCard); | ||
16 | |||
17 | MemberRelatedInfo findByMemberIdAndIdCard(Long memberId , String idCard); | ||
18 | |||
19 | MemberRelatedInfo findByIdOrIdCard(Long id, String idCard); | ||
13 | } | 20 | } | ... | ... |
1 | package com.topdraw.business.module.member.relatedinfo.rest; | 1 | package com.topdraw.business.module.member.relatedinfo.rest; |
2 | 2 | ||
3 | import com.topdraw.aop.log.Log; | 3 | import com.topdraw.aop.log.Log; |
4 | import com.topdraw.business.common.CreateGroup; | 4 | import com.topdraw.business.module.common.validated.CreateGroup; |
5 | import com.topdraw.business.module.member.relatedinfo.domain.UpdateGroup; | 5 | import com.topdraw.business.module.common.validated.UpdateGroup; |
6 | import com.topdraw.business.module.member.relatedinfo.service.dto.MemberRelatedInfoDTO; | 6 | import com.topdraw.business.module.member.relatedinfo.service.dto.MemberRelatedInfoDTO; |
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.common.ResultInfo; | 9 | import com.topdraw.common.ResultInfo; |
10 | import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo; | 10 | import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo; |
11 | import com.topdraw.business.module.member.relatedinfo.service.MemberRelatedInfoService; | 11 | import com.topdraw.business.module.member.relatedinfo.service.MemberRelatedInfoService; |
12 | import com.topdraw.exception.BadRequestException; | ||
13 | import com.topdraw.util.Base64Util; | ||
14 | import lombok.extern.slf4j.Slf4j; | 12 | import lombok.extern.slf4j.Slf4j; |
15 | import org.springframework.beans.factory.annotation.Autowired; | 13 | import org.springframework.beans.factory.annotation.Autowired; |
16 | import org.springframework.util.Assert; | 14 | import org.springframework.util.Assert; |
17 | import org.springframework.util.StringUtils; | ||
18 | import org.springframework.validation.annotation.Validated; | 15 | import org.springframework.validation.annotation.Validated; |
19 | import org.springframework.web.bind.annotation.*; | 16 | import org.springframework.web.bind.annotation.*; |
20 | import io.swagger.annotations.*; | 17 | import io.swagger.annotations.*; |
... | @@ -42,13 +39,9 @@ public class MemberRelatedInfoController { | ... | @@ -42,13 +39,9 @@ public class MemberRelatedInfoController { |
42 | @ApiOperation("新增相关人员") | 39 | @ApiOperation("新增相关人员") |
43 | public ResultInfo create(@Validated(value = {CreateGroup.class}) @RequestBody MemberRelatedInfo resources) { | 40 | public ResultInfo create(@Validated(value = {CreateGroup.class}) @RequestBody MemberRelatedInfo resources) { |
44 | log.info("memberRelatedInfo ==>> create ==>> resources ===>> [{}]",resources); | 41 | log.info("memberRelatedInfo ==>> create ==>> resources ===>> [{}]",resources); |
45 | String name = resources.getName(); | ||
46 | if (StringUtils.hasText(name)) { | ||
47 | String nickNameEncode = Base64Util.encode(name); | ||
48 | resources.setName(nickNameEncode); | ||
49 | } | ||
50 | 42 | ||
51 | this.memberRelatedInfoService.create(resources); | 43 | this.memberRelatedInfoService.create(resources); |
44 | |||
52 | return ResultInfo.success(); | 45 | return ResultInfo.success(); |
53 | } | 46 | } |
54 | 47 | ||
... | @@ -59,21 +52,10 @@ public class MemberRelatedInfoController { | ... | @@ -59,21 +52,10 @@ public class MemberRelatedInfoController { |
59 | 52 | ||
60 | log.info("memberRelatedInfo ==>> update ==>> resources ===>> [{}]",resources); | 53 | log.info("memberRelatedInfo ==>> update ==>> resources ===>> [{}]",resources); |
61 | 54 | ||
62 | String name = resources.getName(); | ||
63 | if (StringUtils.hasText(name)) { | ||
64 | String nickNameEncode = Base64Util.encode(name); | ||
65 | resources.setName(nickNameEncode); | ||
66 | } | ||
67 | |||
68 | Long id = resources.getId(); | 55 | Long id = resources.getId(); |
69 | MemberRelatedInfoDTO memberRelatedInfoDTO = this.memberRelatedInfoService.findById(id); | 56 | MemberRelatedInfoDTO memberRelatedInfoDTO = this.memberRelatedInfoService.findById(id); |
70 | if (memberRelatedInfoDTO.getId() != null) { | 57 | if (memberRelatedInfoDTO.getId() != null) { |
71 | Long memberId = memberRelatedInfoDTO.getMemberId(); | 58 | Long memberId = memberRelatedInfoDTO.getMemberId(); |
72 | if (Objects.isNull(memberId)) { | ||
73 | log.info("id ==>> [{}]",id); | ||
74 | throw new BadRequestException("memberId is null! please check member info"); | ||
75 | } | ||
76 | |||
77 | MemberDTO memberDTO = this.memberService.findById(memberId); | 59 | MemberDTO memberDTO = this.memberService.findById(memberId); |
78 | if (Objects.nonNull(memberDTO)) { | 60 | if (Objects.nonNull(memberDTO)) { |
79 | String code = memberDTO.getCode(); | 61 | String code = memberDTO.getCode(); | ... | ... |
1 | package com.topdraw.business.module.member.relatedinfo.service; | 1 | package com.topdraw.business.module.member.relatedinfo.service; |
2 | 2 | ||
3 | import com.topdraw.business.module.member.domain.Member; | ||
3 | import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo; | 4 | import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo; |
4 | import com.topdraw.business.module.member.relatedinfo.service.dto.MemberRelatedInfoDTO; | 5 | import com.topdraw.business.module.member.relatedinfo.service.dto.MemberRelatedInfoDTO; |
5 | 6 | ||
... | @@ -16,10 +17,66 @@ public interface MemberRelatedInfoService { | ... | @@ -16,10 +17,66 @@ public interface MemberRelatedInfoService { |
16 | */ | 17 | */ |
17 | MemberRelatedInfoDTO findById(Long id); | 18 | MemberRelatedInfoDTO findById(Long id); |
18 | 19 | ||
20 | /** | ||
21 | * 新增 | ||
22 | * @param resources | ||
23 | */ | ||
19 | void create(MemberRelatedInfo resources); | 24 | void create(MemberRelatedInfo resources); |
20 | 25 | ||
26 | /** | ||
27 | * 修改 | ||
28 | * @param resources | ||
29 | */ | ||
21 | void update(MemberRelatedInfo resources); | 30 | void update(MemberRelatedInfo resources); |
22 | 31 | ||
32 | /** | ||
33 | * 删除 | ||
34 | * @param id | ||
35 | */ | ||
23 | void delete(Long id); | 36 | void delete(Long id); |
24 | 37 | ||
38 | /** | ||
39 | * 通过身份证查询 | ||
40 | * @param resources | ||
41 | * @return | ||
42 | */ | ||
43 | MemberRelatedInfo findByIdCard(MemberRelatedInfo resources); | ||
44 | |||
45 | /** | ||
46 | * 通过身份证查询 | ||
47 | * @param idCard 身份证 | ||
48 | * @return | ||
49 | */ | ||
50 | MemberRelatedInfo findByIdCard(String idCard); | ||
51 | |||
52 | /** | ||
53 | * | ||
54 | * @param memberId | ||
55 | * @param idCard | ||
56 | * @return | ||
57 | */ | ||
58 | MemberRelatedInfo findByMemberIdAndIdCard(Long memberId , String idCard); | ||
59 | |||
60 | /** | ||
61 | * | ||
62 | * @param memberCode | ||
63 | * @param idCard | ||
64 | * @return | ||
65 | */ | ||
66 | MemberRelatedInfo findByMemberCodeAndIdCard(String memberCode , String idCard); | ||
67 | |||
68 | /** | ||
69 | * | ||
70 | * @param resources | ||
71 | * @return | ||
72 | */ | ||
73 | MemberRelatedInfo findByMemberIdAndIdCard(MemberRelatedInfo resources); | ||
74 | |||
75 | /** | ||
76 | * | ||
77 | * @param member | ||
78 | * @param resources | ||
79 | * @return | ||
80 | */ | ||
81 | MemberRelatedInfo findByMemberIdAndIdCard(Member member , MemberRelatedInfo resources); | ||
25 | } | 82 | } | ... | ... |
1 | package com.topdraw.business.module.member.relatedinfo.service.impl; | 1 | package com.topdraw.business.module.member.relatedinfo.service.impl; |
2 | 2 | ||
3 | import com.topdraw.aspect.AsyncMqSend; | 3 | import com.topdraw.business.module.member.domain.Member; |
4 | import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo; | 4 | import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo; |
5 | import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfoBuilder; | ||
6 | import com.topdraw.business.module.member.service.MemberService; | ||
7 | import com.topdraw.business.module.member.service.dto.MemberDTO; | ||
8 | import com.topdraw.exception.BadRequestException; | ||
9 | import com.topdraw.exception.GlobeExceptionMsg; | ||
10 | import com.topdraw.util.Base64Util; | ||
11 | import com.topdraw.util.RedissonUtil; | ||
5 | import com.topdraw.utils.ValidationUtil; | 12 | import com.topdraw.utils.ValidationUtil; |
6 | import com.topdraw.business.module.member.relatedinfo.repository.MemberRelatedInfoRepository; | 13 | import com.topdraw.business.module.member.relatedinfo.repository.MemberRelatedInfoRepository; |
7 | import com.topdraw.business.module.member.relatedinfo.service.MemberRelatedInfoService; | 14 | import com.topdraw.business.module.member.relatedinfo.service.MemberRelatedInfoService; |
8 | import com.topdraw.business.module.member.relatedinfo.service.dto.MemberRelatedInfoDTO; | 15 | import com.topdraw.business.module.member.relatedinfo.service.dto.MemberRelatedInfoDTO; |
9 | import com.topdraw.business.module.member.relatedinfo.service.dto.MemberRelatedInfoQueryCriteria; | ||
10 | import com.topdraw.business.module.member.relatedinfo.service.mapper.MemberRelatedInfoMapper; | 16 | import com.topdraw.business.module.member.relatedinfo.service.mapper.MemberRelatedInfoMapper; |
17 | import lombok.extern.slf4j.Slf4j; | ||
18 | import org.redisson.api.RLock; | ||
19 | import org.redisson.api.RedissonClient; | ||
11 | import org.springframework.beans.factory.annotation.Autowired; | 20 | import org.springframework.beans.factory.annotation.Autowired; |
12 | import org.springframework.stereotype.Service; | 21 | import org.springframework.stereotype.Service; |
13 | import org.springframework.transaction.annotation.Propagation; | 22 | import org.springframework.transaction.annotation.Propagation; |
14 | import org.springframework.transaction.annotation.Transactional; | 23 | import org.springframework.transaction.annotation.Transactional; |
15 | import org.springframework.dao.EmptyResultDataAccessException; | 24 | import org.springframework.dao.EmptyResultDataAccessException; |
16 | import org.springframework.data.domain.Page; | ||
17 | import org.springframework.data.domain.Pageable; | ||
18 | import org.springframework.util.Assert; | 25 | import org.springframework.util.Assert; |
19 | import com.topdraw.utils.PageUtil; | 26 | import org.springframework.util.StringUtils; |
20 | import com.topdraw.utils.QueryHelp; | ||
21 | 27 | ||
22 | import java.util.List; | 28 | import java.util.Objects; |
23 | import java.util.Map; | ||
24 | 29 | ||
25 | /** | 30 | /** |
26 | * @author XiangHan | 31 | * @author XiangHan |
... | @@ -28,47 +33,175 @@ import java.util.Map; | ... | @@ -28,47 +33,175 @@ import java.util.Map; |
28 | */ | 33 | */ |
29 | @Service | 34 | @Service |
30 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | 35 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) |
36 | @Slf4j | ||
31 | public class MemberRelatedInfoServiceImpl implements MemberRelatedInfoService { | 37 | public class MemberRelatedInfoServiceImpl implements MemberRelatedInfoService { |
32 | 38 | ||
33 | @Autowired | 39 | @Autowired |
34 | private MemberRelatedInfoRepository MemberRelatedInfoRepository; | 40 | private MemberService memberService; |
41 | @Autowired | ||
42 | private MemberRelatedInfoMapper memberRelatedInfoMapper; | ||
43 | @Autowired | ||
44 | private MemberRelatedInfoRepository memberRelatedInfoRepository; | ||
35 | 45 | ||
36 | @Autowired | 46 | @Autowired |
37 | private MemberRelatedInfoMapper MemberRelatedInfoMapper; | 47 | private RedissonClient redissonClient; |
48 | |||
49 | |||
50 | private static final String DEFAULT_IDCARD = "000000000000000000"; | ||
38 | 51 | ||
39 | @Override | 52 | @Override |
40 | public MemberRelatedInfoDTO findById(Long id) { | 53 | public MemberRelatedInfoDTO findById(Long id) { |
41 | MemberRelatedInfo MemberRelatedInfo = MemberRelatedInfoRepository.findById(id).orElseGet(MemberRelatedInfo::new); | 54 | log.info("MemberRelatedInfoServiceImpl ==>> findById ==>> param ==>> [{}]",id); |
42 | ValidationUtil.isNull(MemberRelatedInfo.getId(),"MemberRelatedInfo","id",id); | 55 | MemberRelatedInfo memberRelatedInfo = this.memberRelatedInfoRepository.findById(id).orElseGet(MemberRelatedInfo::new); |
43 | return MemberRelatedInfoMapper.toDto(MemberRelatedInfo); | 56 | ValidationUtil.isNull(memberRelatedInfo.getId(),"MemberRelatedInfo","id",id); |
57 | return this.memberRelatedInfoMapper.toDto(memberRelatedInfo); | ||
44 | } | 58 | } |
45 | 59 | ||
46 | @Override | 60 | @Override |
47 | @Transactional(rollbackFor = Exception.class) | 61 | @Transactional(rollbackFor = Exception.class) |
48 | @AsyncMqSend() | ||
49 | public void create(MemberRelatedInfo resources) { | 62 | public void create(MemberRelatedInfo resources) { |
50 | MemberRelatedInfoRepository.save(resources); | 63 | log.info("MemberRelatedInfoServiceImpl ==>> create ==>> param ==>> [{}]",resources); |
64 | String idCard = resources.getIdCard(); | ||
65 | Long memberId = resources.getMemberId(); | ||
66 | if (Objects.nonNull(memberId) && !StringUtils.hasText(idCard) && !idCard.equalsIgnoreCase(DEFAULT_IDCARD) ) { | ||
67 | MemberRelatedInfo memberRelatedInfo = this.findByMemberIdAndIdCard(resources); | ||
68 | if (Objects.nonNull(memberRelatedInfo)) | ||
69 | // 数据已存在 | ||
70 | throw new BadRequestException(GlobeExceptionMsg.ENTITY_ALREADY_EXISTS); | ||
71 | } | ||
72 | |||
73 | this.checkMemberAndEncodeRealname(resources); | ||
74 | |||
75 | MemberRelatedInfo memberRelatedInfo = MemberRelatedInfoBuilder.build(resources); | ||
76 | this.memberRelatedInfoRepository.save(memberRelatedInfo); | ||
77 | log.info("MemberRelatedInfoServiceImpl ==>> create ==>> result ==>> [{}]",memberRelatedInfo); | ||
78 | } | ||
79 | |||
80 | /** | ||
81 | * 检查会员是否存在,加密真实姓名 | ||
82 | * @param resources | ||
83 | */ | ||
84 | private void checkMemberAndEncodeRealname(MemberRelatedInfo resources) { | ||
85 | |||
86 | // 检查会员是否存在 | ||
87 | this.checkMember(resources); | ||
88 | |||
89 | // 加密真实姓名 | ||
90 | this.encodeRealname(resources); | ||
91 | } | ||
92 | |||
93 | /** | ||
94 | * 加密真实姓名 | ||
95 | * @param resources | ||
96 | * @return | ||
97 | */ | ||
98 | private void encodeRealname(MemberRelatedInfo resources){ | ||
99 | String name = resources.getName(); | ||
100 | if (StringUtils.hasText(name)) { | ||
101 | String nickNameEncode = Base64Util.encode(name); | ||
102 | if (!nickNameEncode.equalsIgnoreCase(name)) | ||
103 | resources.setName(nickNameEncode); | ||
104 | } | ||
51 | } | 105 | } |
52 | 106 | ||
53 | @Override | 107 | @Override |
54 | @Transactional(rollbackFor = Exception.class) | 108 | @Transactional(rollbackFor = Exception.class) |
55 | @AsyncMqSend() | ||
56 | public void update(MemberRelatedInfo resources) { | 109 | public void update(MemberRelatedInfo resources) { |
57 | MemberRelatedInfo MemberRelatedInfo = MemberRelatedInfoRepository.findById(resources.getId()).orElseGet(MemberRelatedInfo::new); | 110 | log.info("MemberRelatedInfoServiceImpl ==>> update ==>> param ==>> [{}]",resources); |
58 | ValidationUtil.isNull( MemberRelatedInfo.getId(),"MemberRelatedInfo","id",resources.getId()); | 111 | RLock rLock = this.redissonClient.getLock("memberRelatedInfo::update::id" + resources.getId()); |
59 | MemberRelatedInfo.copy(resources); | 112 | try { |
60 | MemberRelatedInfoRepository.save(MemberRelatedInfo); | 113 | RedissonUtil.lock(rLock); |
114 | |||
115 | this.checkMemberAndEncodeRealname(resources); | ||
116 | |||
117 | MemberRelatedInfo memberRelatedInfo = this.memberRelatedInfoRepository.findById(resources.getId()).orElseGet(MemberRelatedInfo::new); | ||
118 | ValidationUtil.isNull(memberRelatedInfo.getId(), "MemberRelatedInfo", "id", resources.getId()); | ||
119 | memberRelatedInfo.copy(resources); | ||
120 | |||
121 | this.memberRelatedInfoRepository.save(memberRelatedInfo); | ||
122 | |||
123 | log.info("MemberRelatedInfoServiceImpl ==>> update ==>> param ==>> [{}]", resources); | ||
124 | |||
125 | } catch (Exception e) { | ||
126 | e.printStackTrace(); | ||
127 | throw e; | ||
128 | } finally { | ||
129 | RedissonUtil.unlock(rLock); | ||
130 | } | ||
61 | } | 131 | } |
62 | 132 | ||
63 | @Override | 133 | @Override |
64 | @Transactional(rollbackFor = Exception.class) | 134 | @Transactional(rollbackFor = Exception.class) |
65 | @AsyncMqSend() | ||
66 | public void delete(Long id) { | 135 | public void delete(Long id) { |
67 | Assert.notNull(id, "The given id must not be null!"); | 136 | Assert.notNull(id, "The given id must not be null!"); |
68 | MemberRelatedInfo MemberRelatedInfo = MemberRelatedInfoRepository.findById(id).orElseThrow( | 137 | MemberRelatedInfo MemberRelatedInfo = this.memberRelatedInfoRepository.findById(id).orElseThrow( |
69 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", MemberRelatedInfo.class, id), 1)); | 138 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", MemberRelatedInfo.class, id), 1)); |
70 | MemberRelatedInfoRepository.delete(MemberRelatedInfo); | 139 | this.memberRelatedInfoRepository.delete(MemberRelatedInfo); |
71 | } | 140 | } |
72 | 141 | ||
142 | @Override | ||
143 | public MemberRelatedInfo findByIdCard(MemberRelatedInfo resources){ | ||
144 | log.info("MemberRelatedInfoServiceImpl ==>> findByIdCard ==>> param ==>> [{}]",resources); | ||
145 | String idCard = resources.getIdCard(); | ||
146 | Assert.notNull(idCard,"idCard can't be null"); | ||
147 | |||
148 | if (!idCard.equalsIgnoreCase(DEFAULT_IDCARD)) { | ||
149 | MemberRelatedInfo memberRelatedInfo = this.findByIdCard(idCard); | ||
150 | ValidationUtil.isNull(memberRelatedInfo.getId(),"MemberRelatedInfo","id",resources.getId()); | ||
151 | log.info("MemberRelatedInfoServiceImpl ==>> findByIdCard ==>> result ==>> [{}]",memberRelatedInfo); | ||
152 | return memberRelatedInfo; | ||
153 | } | ||
154 | |||
155 | return null; | ||
156 | |||
157 | } | ||
158 | |||
159 | @Override | ||
160 | public MemberRelatedInfo findByIdCard(String idCard) { | ||
161 | log.info("MemberRelatedInfoServiceImpl ==>> findByIdCard ==>> param ==>> [{}]",idCard); | ||
162 | MemberRelatedInfo memberRelatedInfo = this.memberRelatedInfoRepository.findByIdCard(idCard); | ||
163 | log.info("MemberRelatedInfoServiceImpl ==>> findByIdCard ==>> result ==>> [{}]",memberRelatedInfo); | ||
164 | return memberRelatedInfo; | ||
165 | } | ||
166 | |||
167 | @Override | ||
168 | public MemberRelatedInfo findByMemberCodeAndIdCard(String memberCode, String idCard) { | ||
169 | Assert.notNull(memberCode,"memberCode can't be null"); | ||
170 | Assert.notNull(idCard,"idCard can't be null"); | ||
171 | MemberDTO memberDTO = this.checkMember(null, memberCode); | ||
172 | return this.findByMemberIdAndIdCard(memberDTO.getId(),idCard); | ||
173 | } | ||
174 | |||
175 | @Override | ||
176 | public MemberRelatedInfo findByMemberIdAndIdCard(Long memberId, String idCard) { | ||
177 | log.info("MemberRelatedInfoServiceImpl ==>> findByMemberIdAndIdCard ==>> param ==>> [{}]",memberId+","+idCard); | ||
178 | MemberRelatedInfo memberRelatedInfo = this.memberRelatedInfoRepository.findByMemberIdAndIdCard(memberId, idCard); | ||
179 | log.info("MemberRelatedInfoServiceImpl ==>> findByMemberIdAndIdCard ==>> result ==>> [{}]",memberRelatedInfo); | ||
180 | return memberRelatedInfo; | ||
181 | } | ||
182 | |||
183 | @Override | ||
184 | public MemberRelatedInfo findByMemberIdAndIdCard(MemberRelatedInfo resources) { | ||
185 | Long memberId = resources.getMemberId(); | ||
186 | String idCard = resources.getIdCard(); | ||
187 | return this.findByMemberIdAndIdCard(memberId,idCard); | ||
188 | } | ||
189 | |||
190 | @Override | ||
191 | public MemberRelatedInfo findByMemberIdAndIdCard(Member member, MemberRelatedInfo resources) { | ||
192 | Long memberId = member.getId(); | ||
193 | String idCard = resources.getIdCard(); | ||
194 | return this.findByMemberIdAndIdCard(memberId,idCard); | ||
195 | } | ||
196 | |||
197 | private MemberDTO checkMember(MemberRelatedInfo resources){ | ||
198 | Long memberId = resources.getMemberId(); | ||
199 | String code = resources.getMemberCode(); | ||
200 | return this.memberService.checkMember(memberId, code); | ||
201 | } | ||
202 | |||
203 | private MemberDTO checkMember(Long memberId , String memberCode){ | ||
204 | return this.memberService.checkMember(memberId, memberCode); | ||
205 | } | ||
73 | 206 | ||
74 | } | 207 | } | ... | ... |
1 | package com.topdraw.business.module.member.rest; | 1 | package com.topdraw.business.module.member.rest; |
2 | 2 | ||
3 | import com.topdraw.aop.log.Log; | 3 | import com.topdraw.aop.log.Log; |
4 | import com.topdraw.business.common.CreateGroup; | 4 | import com.topdraw.business.module.common.validated.CreateGroup; |
5 | import com.topdraw.business.common.UpdateGroup; | 5 | import com.topdraw.business.module.common.validated.UpdateGroup; |
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.user.iptv.domain.UserTv; | 8 | import com.topdraw.business.module.user.iptv.domain.UserTv; |
... | @@ -34,24 +34,15 @@ public class MemberController { | ... | @@ -34,24 +34,15 @@ public class MemberController { |
34 | @Log("为大屏账户创建会员") | 34 | @Log("为大屏账户创建会员") |
35 | @RequestMapping(value = "/createMemberByUserTv") | 35 | @RequestMapping(value = "/createMemberByUserTv") |
36 | @ApiOperation("为大屏账户创建会员") | 36 | @ApiOperation("为大屏账户创建会员") |
37 | @Deprecated | ||
37 | public ResultInfo createMemberByUserTv(@Validated(value = {CreateGroup.class}) @RequestBody UserTv resources) { | 38 | public ResultInfo createMemberByUserTv(@Validated(value = {CreateGroup.class}) @RequestBody UserTv resources) { |
38 | // todo 此接口废弃,将移动至UserTvController中,AppEngine也要同步修改 | 39 | // todo 此接口废弃,将移动至UserTvController中,AppEngine也要同步修改 |
39 | log.info("member ==>> createMemberByUserTv ==>> param ==>> [{}]",resources); | 40 | log.info("member ==>> createMemberByUserTv ==>> param ==>> [{}]",resources); |
40 | boolean result = this.userTvOperationService.createMemberByUserTv(resources); | 41 | boolean result = this.userTvOperationService.createTvUserAndCreateMember(resources); |
41 | log.info("member ==>> createMemberByUserTv ==>> result ==>> [{}]",result); | 42 | log.info("member ==>> createMemberByUserTv ==>> result ==>> [{}]",result); |
42 | return ResultInfo.success(result); | 43 | return ResultInfo.success(result); |
43 | } | 44 | } |
44 | 45 | ||
45 | @Log("新增会员") | ||
46 | @RequestMapping(value = "/create") | ||
47 | @ApiOperation("新增会员") | ||
48 | public ResultInfo create(@Validated @RequestBody Member resources) { | ||
49 | log.info("member ==>> create ==>> param ==>> [{}]",resources); | ||
50 | Long id = memberService.create(resources); | ||
51 | log.info("member ==>> create ==>> result ==>> [{}]",resources); | ||
52 | return ResultInfo.success(id); | ||
53 | } | ||
54 | |||
55 | @Log("手动修改vip") | 46 | @Log("手动修改vip") |
56 | @RequestMapping(value = "/doUpdateVipByCode") | 47 | @RequestMapping(value = "/doUpdateVipByCode") |
57 | @ApiOperation("手动修改vip") | 48 | @ApiOperation("手动修改vip") |
... | @@ -61,14 +52,4 @@ public class MemberController { | ... | @@ -61,14 +52,4 @@ public class MemberController { |
61 | log.info("member ==>> doUpdateVipByCode ==>> result ==>> [{}]",resources); | 52 | log.info("member ==>> doUpdateVipByCode ==>> result ==>> [{}]",resources); |
62 | return ResultInfo.success(); | 53 | return ResultInfo.success(); |
63 | } | 54 | } |
64 | |||
65 | @Log("修改会员") | ||
66 | @RequestMapping(value = "/update") | ||
67 | @ApiOperation("修改会员") | ||
68 | public ResultInfo update(@Validated(value = {UpdateGroup.class}) @RequestBody Member resources) { | ||
69 | log.info("member ==>> update ==>> param ==>> [{}]",resources); | ||
70 | memberService.update(resources); | ||
71 | log.info("member ==>> update ==>> result ==>> [{}]",resources); | ||
72 | return ResultInfo.success(); | ||
73 | } | ||
74 | } | 55 | } | ... | ... |
... | @@ -26,14 +26,6 @@ public interface MemberService { | ... | @@ -26,14 +26,6 @@ public interface MemberService { |
26 | MemberDTO findByCode(String code); | 26 | MemberDTO findByCode(String code); |
27 | 27 | ||
28 | /** | 28 | /** |
29 | * | ||
30 | * @param id | ||
31 | * @param code | ||
32 | * @return | ||
33 | */ | ||
34 | MemberDTO findByIdOrCode(Long id,String code); | ||
35 | |||
36 | /** | ||
37 | * 保存 | 29 | * 保存 |
38 | * @param resources | 30 | * @param resources |
39 | * @return Long id | 31 | * @return Long id |
... | @@ -54,13 +46,6 @@ public interface MemberService { | ... | @@ -54,13 +46,6 @@ public interface MemberService { |
54 | void update(Member resources); | 46 | void update(Member resources); |
55 | 47 | ||
56 | /** | 48 | /** |
57 | * 解绑 | ||
58 | * @param resources 会员 | ||
59 | * @return Map<String,Object> | ||
60 | */ | ||
61 | void unbind(Member resources); | ||
62 | |||
63 | /** | ||
64 | * 修改会员积分 | 49 | * 修改会员积分 |
65 | * @param member 会员 | 50 | * @param member 会员 |
66 | */ | 51 | */ |
... | @@ -72,4 +57,17 @@ public interface MemberService { | ... | @@ -72,4 +57,17 @@ public interface MemberService { |
72 | * @return Map<String,Object> | 57 | * @return Map<String,Object> |
73 | */ | 58 | */ |
74 | List<MemberDTO> findByUserIptvId(Long id); | 59 | List<MemberDTO> findByUserIptvId(Long id); |
60 | |||
61 | /** | ||
62 | * 检查会员信息 | ||
63 | * @param id 会员id | ||
64 | * @param memberCode 会员编码 | ||
65 | */ | ||
66 | MemberDTO checkMember(Long id , String memberCode); | ||
67 | |||
68 | /** | ||
69 | * 检查会员信息 | ||
70 | * @param member 会员 | ||
71 | */ | ||
72 | MemberDTO checkMember(Member member); | ||
75 | } | 73 | } | ... | ... |
1 | package com.topdraw.business.module.member.service.dto; | ||
2 | |||
3 | import com.topdraw.annotation.Query; | ||
4 | import lombok.Data; | ||
5 | |||
6 | /** | ||
7 | * @author XiangHan | ||
8 | * @date 2021-10-22 | ||
9 | */ | ||
10 | @Data | ||
11 | public class MemberQueryCriteria{ | ||
12 | |||
13 | @Query(type = Query.Type.LEFT_LIKE) | ||
14 | private String code; | ||
15 | |||
16 | // 类型 1:大屏;2:小屏 | ||
17 | @Query(type = Query.Type.EQUAL) | ||
18 | private Integer type; | ||
19 | |||
20 | // 状态 0:不可用;1:可用 | ||
21 | @Query(type = Query.Type.EQUAL) | ||
22 | private Integer status; | ||
23 | |||
24 | // 昵称 base64 | ||
25 | @Query(type = Query.Type.LEFT_LIKE) | ||
26 | private String nickname; | ||
27 | |||
28 | // 性别 0:女;1:男;-1:未知 | ||
29 | @Query(type = Query.Type.EQUAL) | ||
30 | private Integer gender; | ||
31 | |||
32 | // 分组信息 | ||
33 | @Query(type = Query.Type.EQUAL) | ||
34 | private String groups; | ||
35 | |||
36 | // 标签 | ||
37 | @Query(type = Query.Type.IN) | ||
38 | private String tags; | ||
39 | |||
40 | // 是否会员 0:非会员;1:会员 | ||
41 | @Query(type = Query.Type.EQUAL) | ||
42 | private Integer vip; | ||
43 | |||
44 | // 会员等级(对应level表的level字段,非id) | ||
45 | @Query(type = Query.Type.EQUAL) | ||
46 | private Integer level; | ||
47 | |||
48 | // iptv账号id | ||
49 | @Query(type = Query.Type.EQUAL) | ||
50 | private Long userIptvId; | ||
51 | |||
52 | // 绑定IPTV平台 0:未知;1:电信;2:移动;3:联通 | ||
53 | @Query(type = Query.Type.IN) | ||
54 | private Integer bindIptvPlatformType; | ||
55 | |||
56 | } |
... | @@ -9,12 +9,14 @@ import com.topdraw.business.module.member.service.MemberService; | ... | @@ -9,12 +9,14 @@ import com.topdraw.business.module.member.service.MemberService; |
9 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 9 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
10 | import com.topdraw.business.module.member.service.mapper.MemberMapper; | 10 | import com.topdraw.business.module.member.service.mapper.MemberMapper; |
11 | import com.topdraw.exception.BadRequestException; | 11 | import com.topdraw.exception.BadRequestException; |
12 | import com.topdraw.exception.GlobeExceptionMsg; | ||
12 | import com.topdraw.util.RedissonUtil; | 13 | import com.topdraw.util.RedissonUtil; |
13 | import com.topdraw.utils.StringUtils; | ||
14 | import com.topdraw.utils.ValidationUtil; | 14 | import com.topdraw.utils.ValidationUtil; |
15 | import lombok.extern.slf4j.Slf4j; | 15 | import lombok.extern.slf4j.Slf4j; |
16 | import org.apache.commons.lang3.StringUtils; | ||
16 | import org.redisson.api.RLock; | 17 | import org.redisson.api.RLock; |
17 | import org.redisson.api.RedissonClient; | 18 | import org.redisson.api.RedissonClient; |
19 | import org.springframework.beans.BeanUtils; | ||
18 | import org.springframework.beans.factory.annotation.Autowired; | 20 | import org.springframework.beans.factory.annotation.Autowired; |
19 | import org.springframework.stereotype.Service; | 21 | import org.springframework.stereotype.Service; |
20 | import org.springframework.transaction.annotation.Propagation; | 22 | import org.springframework.transaction.annotation.Propagation; |
... | @@ -42,35 +44,66 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -42,35 +44,66 @@ public class MemberServiceImpl implements MemberService { |
42 | 44 | ||
43 | @Override | 45 | @Override |
44 | public MemberDTO findById(Long id) { | 46 | public MemberDTO findById(Long id) { |
47 | |||
45 | Member member = this.memberRepository.findById(id).orElseGet(Member::new); | 48 | Member member = this.memberRepository.findById(id).orElseGet(Member::new); |
46 | ValidationUtil.isNull(member.getId(),"Member","id",id); | 49 | ValidationUtil.isNull(member.getId(),"Member","id",id); |
50 | |||
47 | return memberMapper.toDto(member); | 51 | return memberMapper.toDto(member); |
52 | |||
48 | } | 53 | } |
49 | 54 | ||
50 | @Override | 55 | @Override |
51 | public MemberDTO findByCode(String code) { | 56 | public MemberDTO findByCode(String code) { |
57 | |||
52 | Member member = this.memberRepository.findFirstByCode(code).orElseGet(Member::new); | 58 | Member member = this.memberRepository.findFirstByCode(code).orElseGet(Member::new); |
53 | ValidationUtil.isNull(member.getId(),"Member","id",code); | 59 | ValidationUtil.isNull(member.getId(),"Member","id",code); |
60 | |||
54 | return memberMapper.toDto(member); | 61 | return memberMapper.toDto(member); |
62 | |||
55 | } | 63 | } |
56 | 64 | ||
57 | @Override | 65 | private MemberDTO findByIdOrCode(Long id,String code) { |
58 | public MemberDTO findByIdOrCode(Long id,String code) { | 66 | |
59 | Member member = this.memberRepository.findByIdOrCode(id,code).orElseGet(Member::new); | 67 | Member member = this.memberRepository.findByIdOrCode(id,code).orElseGet(Member::new); |
60 | ValidationUtil.isNull(member.getId(),"Member","param",code); | 68 | ValidationUtil.isNull(member.getId(),"Member","param",code); |
69 | |||
61 | return memberMapper.toDto(member); | 70 | return memberMapper.toDto(member); |
71 | |||
62 | } | 72 | } |
63 | 73 | ||
64 | @Override | 74 | @Override |
65 | public List<MemberDTO> findByUserIptvId(Long id) { | 75 | public List<MemberDTO> findByUserIptvId(Long id) { |
76 | |||
66 | List<Member> memberList = this.memberRepository.findByUserIptvId(id); | 77 | List<Member> memberList = this.memberRepository.findByUserIptvId(id); |
78 | |||
67 | return memberMapper.toDto(memberList); | 79 | return memberMapper.toDto(memberList); |
80 | |||
81 | } | ||
82 | |||
83 | @Override | ||
84 | public MemberDTO checkMember(Long id, String memberCode) { | ||
85 | |||
86 | if(Objects.isNull(id) && StringUtils.isBlank(memberCode)) | ||
87 | throw new BadRequestException(GlobeExceptionMsg.MEMBER_ID_AND_CODE_ARE_NULL); | ||
88 | |||
89 | return this.findByIdOrCode(id, memberCode); | ||
90 | } | ||
91 | |||
92 | @Override | ||
93 | public MemberDTO checkMember(Member member) { | ||
94 | |||
95 | String memberCode = member.getCode(); | ||
96 | Long memberId = member.getId(); | ||
97 | |||
98 | return this.checkMember(memberId,memberCode); | ||
99 | |||
68 | } | 100 | } |
69 | 101 | ||
70 | @Override | 102 | @Override |
71 | @Transactional(rollbackFor = Exception.class) | 103 | @Transactional(rollbackFor = Exception.class) |
72 | @AsyncMqSend() | 104 | @AsyncMqSend() |
73 | public Long create(Member resources) { | 105 | public Long create(Member resources) { |
106 | |||
74 | Member member = MemberBuilder.build(resources); | 107 | Member member = MemberBuilder.build(resources); |
75 | Long memberId = this.save(member); | 108 | Long memberId = this.save(member); |
76 | 109 | ||
... | @@ -79,15 +112,18 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -79,15 +112,18 @@ public class MemberServiceImpl implements MemberService { |
79 | this.memberProfileService.createDefault(member); | 112 | this.memberProfileService.createDefault(member); |
80 | 113 | ||
81 | return member.getId(); | 114 | return member.getId(); |
115 | |||
82 | } | 116 | } |
83 | 117 | ||
84 | @Override | 118 | @Override |
85 | @Transactional(rollbackFor = Exception.class) | 119 | @Transactional(rollbackFor = Exception.class) |
86 | @AsyncMqSend() | 120 | @AsyncMqSend() |
87 | public Member createAndReturnMember(Member resources) { | 121 | public Member createAndReturnMember(Member resources) { |
88 | Member member = MemberBuilder.build(resources); | 122 | |
89 | this.create(member); | 123 | this.create(MemberBuilder.build(resources)); |
124 | |||
90 | return resources; | 125 | return resources; |
126 | |||
91 | } | 127 | } |
92 | 128 | ||
93 | @Override | 129 | @Override |
... | @@ -96,43 +132,24 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -96,43 +132,24 @@ public class MemberServiceImpl implements MemberService { |
96 | public void update(Member resources) { | 132 | public void update(Member resources) { |
97 | 133 | ||
98 | log.info("MemberServiceImpl ==>> update ==>> resources ==>> [{}]" , resources); | 134 | log.info("MemberServiceImpl ==>> update ==>> resources ==>> [{}]" , resources); |
99 | String code = resources.getCode(); | ||
100 | if (StringUtils.isBlank(code)) | ||
101 | throw new BadRequestException("memberCode can't be null!!"); | ||
102 | |||
103 | RLock rLock = this.redissonClient.getLock("member::update::code" + resources.getCode()); | 135 | RLock rLock = this.redissonClient.getLock("member::update::code" + resources.getCode()); |
104 | try { | 136 | try { |
105 | RedissonUtil.lock(rLock); | 137 | RedissonUtil.lock(rLock); |
106 | Member member = this.memberRepository.findFirstByCode(code).orElseGet(Member::new); | 138 | MemberDTO memberDTO = this.checkMember(resources); |
107 | ValidationUtil.isNull(member.getCode(), "Member", "code", resources.getCode()); | 139 | |
140 | Member member = new Member(); | ||
141 | BeanUtils.copyProperties(memberDTO,member); | ||
108 | member.copy(resources); | 142 | member.copy(resources); |
109 | 143 | ||
110 | this.save(member); | 144 | this.save(member); |
111 | } catch (Exception e) { | ||
112 | e.printStackTrace(); | ||
113 | throw e; | ||
114 | } finally { | ||
115 | RedissonUtil.unlock(rLock); | ||
116 | } | ||
117 | } | ||
118 | 145 | ||
119 | @Override | ||
120 | @Transactional(rollbackFor = Exception.class) | ||
121 | @AsyncMqSend() | ||
122 | public void unbind(Member resources) { | ||
123 | RLock rLock = this.redissonClient.getLock("member::update::code" + resources.getCode()); | ||
124 | try { | ||
125 | RedissonUtil.lock(rLock); | ||
126 | Member member = this.memberRepository.findById(resources.getId()).orElseGet(Member::new); | ||
127 | ValidationUtil.isNull(member.getId(), "Member", "id", resources.getId()); | ||
128 | member.copy(resources); | ||
129 | this.save(member); | ||
130 | } catch (Exception e) { | 146 | } catch (Exception e) { |
131 | e.printStackTrace(); | 147 | e.printStackTrace(); |
132 | throw e; | 148 | throw e; |
133 | } finally { | 149 | } finally { |
134 | RedissonUtil.unlock(rLock); | 150 | RedissonUtil.unlock(rLock); |
135 | } | 151 | } |
152 | |||
136 | } | 153 | } |
137 | 154 | ||
138 | @Transactional(propagation = Propagation.REQUIRES_NEW) | 155 | @Transactional(propagation = Propagation.REQUIRES_NEW) |
... | @@ -160,6 +177,4 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -160,6 +177,4 @@ public class MemberServiceImpl implements MemberService { |
160 | } | 177 | } |
161 | } | 178 | } |
162 | 179 | ||
163 | |||
164 | |||
165 | } | 180 | } | ... | ... |
... | @@ -2,6 +2,7 @@ package com.topdraw.business.module.member.viphistory.domain; | ... | @@ -2,6 +2,7 @@ package com.topdraw.business.module.member.viphistory.domain; |
2 | 2 | ||
3 | import cn.hutool.core.bean.BeanUtil; | 3 | import cn.hutool.core.bean.BeanUtil; |
4 | import cn.hutool.core.bean.copier.CopyOptions; | 4 | import cn.hutool.core.bean.copier.CopyOptions; |
5 | import com.topdraw.business.module.common.domain.AsyncMqModule; | ||
5 | import lombok.Data; | 6 | import lombok.Data; |
6 | import lombok.experimental.Accessors; | 7 | import lombok.experimental.Accessors; |
7 | import org.springframework.data.annotation.CreatedDate; | 8 | import org.springframework.data.annotation.CreatedDate; |
... | @@ -22,7 +23,7 @@ import java.time.LocalDateTime; | ... | @@ -22,7 +23,7 @@ import java.time.LocalDateTime; |
22 | @EntityListeners(AuditingEntityListener.class) | 23 | @EntityListeners(AuditingEntityListener.class) |
23 | @Accessors(chain = true) | 24 | @Accessors(chain = true) |
24 | @Table(name="uc_member_vip_history") | 25 | @Table(name="uc_member_vip_history") |
25 | public class MemberVipHistory implements Serializable { | 26 | public class MemberVipHistory extends AsyncMqModule implements Serializable { |
26 | 27 | ||
27 | // 主键 | 28 | // 主键 |
28 | @Id | 29 | @Id | ... | ... |
1 | package com.topdraw.business.module.member.viphistory.rest; | ||
2 | |||
3 | import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory; | ||
4 | import com.topdraw.business.module.member.viphistory.service.MemberVipHistoryService; | ||
5 | import com.topdraw.business.module.member.viphistory.service.dto.MemberVipHistoryQueryCriteria; | ||
6 | import com.topdraw.common.ResultInfo; | ||
7 | import io.swagger.annotations.Api; | ||
8 | import io.swagger.annotations.ApiOperation; | ||
9 | import org.springframework.beans.factory.annotation.Autowired; | ||
10 | import org.springframework.data.domain.Pageable; | ||
11 | import org.springframework.validation.annotation.Validated; | ||
12 | import org.springframework.web.bind.annotation.*; | ||
13 | |||
14 | /** | ||
15 | * @author luerlong | ||
16 | * @date 2021-12-10 | ||
17 | */ | ||
18 | @Api(tags = "MemberVipHistory管理") | ||
19 | @RestController | ||
20 | @RequestMapping("/api/memberVipHistory") | ||
21 | public class MemberVipHistoryController { | ||
22 | |||
23 | @Autowired | ||
24 | private MemberVipHistoryService memberVipHistoryService; | ||
25 | |||
26 | @PostMapping | ||
27 | @ApiOperation("新增MemberVipHistory") | ||
28 | public ResultInfo create(@Validated @RequestBody MemberVipHistory resources) { | ||
29 | memberVipHistoryService.create(resources); | ||
30 | return ResultInfo.success(); | ||
31 | } | ||
32 | |||
33 | @PutMapping | ||
34 | @ApiOperation("修改MemberVipHistory") | ||
35 | public ResultInfo update(@Validated @RequestBody MemberVipHistory resources) { | ||
36 | memberVipHistoryService.update(resources); | ||
37 | return ResultInfo.success(); | ||
38 | } | ||
39 | |||
40 | @DeleteMapping(value = "/{id}") | ||
41 | @ApiOperation("删除MemberVipHistory") | ||
42 | public ResultInfo delete(@PathVariable Long id) { | ||
43 | memberVipHistoryService.delete(id); | ||
44 | return ResultInfo.success(); | ||
45 | } | ||
46 | |||
47 | } |
... | @@ -2,13 +2,8 @@ package com.topdraw.business.module.member.viphistory.service; | ... | @@ -2,13 +2,8 @@ package com.topdraw.business.module.member.viphistory.service; |
2 | 2 | ||
3 | import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory; | 3 | import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory; |
4 | import com.topdraw.business.module.member.viphistory.service.dto.MemberVipHistoryDTO; | 4 | import com.topdraw.business.module.member.viphistory.service.dto.MemberVipHistoryDTO; |
5 | import com.topdraw.business.module.member.viphistory.service.dto.MemberVipHistoryQueryCriteria; | ||
6 | import org.springframework.data.domain.Pageable; | ||
7 | 5 | ||
8 | import java.time.LocalDateTime; | 6 | import java.time.LocalDateTime; |
9 | import java.util.List; | ||
10 | import java.util.Map; | ||
11 | import java.util.Optional; | ||
12 | 7 | ||
13 | /** | 8 | /** |
14 | * @author luerlong | 9 | * @author luerlong |
... | @@ -17,32 +12,35 @@ import java.util.Optional; | ... | @@ -17,32 +12,35 @@ import java.util.Optional; |
17 | public interface MemberVipHistoryService { | 12 | public interface MemberVipHistoryService { |
18 | 13 | ||
19 | /** | 14 | /** |
20 | * 查询数据分页 | ||
21 | * @param criteria 条件参数 | ||
22 | * @param pageable 分页参数 | ||
23 | * @return Map<String,Object> | ||
24 | */ | ||
25 | Map<String,Object> queryAll(MemberVipHistoryQueryCriteria criteria, Pageable pageable); | ||
26 | |||
27 | /** | ||
28 | * 查询所有数据不分页 | ||
29 | * @param criteria 条件参数 | ||
30 | * @return List<MemberVipHistoryDTO> | ||
31 | */ | ||
32 | List<MemberVipHistoryDTO> queryAll(MemberVipHistoryQueryCriteria criteria); | ||
33 | |||
34 | /** | ||
35 | * 根据ID查询 | 15 | * 根据ID查询 |
36 | * @param id ID | 16 | * @param id ID |
37 | * @return MemberVipHistoryDTO | 17 | * @return MemberVipHistoryDTO |
38 | */ | 18 | */ |
39 | MemberVipHistoryDTO findById(Long id); | 19 | MemberVipHistoryDTO findById(Long id); |
40 | 20 | ||
21 | /** | ||
22 | * | ||
23 | * @param resources | ||
24 | */ | ||
41 | void create(MemberVipHistory resources); | 25 | void create(MemberVipHistory resources); |
42 | 26 | ||
27 | /** | ||
28 | * | ||
29 | * @param resources | ||
30 | */ | ||
43 | void update(MemberVipHistory resources); | 31 | void update(MemberVipHistory resources); |
44 | 32 | ||
33 | /** | ||
34 | * | ||
35 | * @param id | ||
36 | */ | ||
45 | void delete(Long id); | 37 | void delete(Long id); |
46 | 38 | ||
39 | /** | ||
40 | * | ||
41 | * @param id | ||
42 | * @param nowTime | ||
43 | * @return | ||
44 | */ | ||
47 | MemberVipHistory findByTime(Long id, LocalDateTime nowTime); | 45 | MemberVipHistory findByTime(Long id, LocalDateTime nowTime); |
48 | } | 46 | } | ... | ... |
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.business.module.member.service.MemberService; | ||
5 | import com.topdraw.business.module.member.service.dto.MemberDTO; | ||
4 | import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory; | 6 | import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory; |
5 | import com.topdraw.business.module.member.viphistory.repository.MemberVipHistoryRepository; | 7 | import com.topdraw.business.module.member.viphistory.repository.MemberVipHistoryRepository; |
6 | import com.topdraw.business.module.member.viphistory.service.MemberVipHistoryService; | 8 | import com.topdraw.business.module.member.viphistory.service.MemberVipHistoryService; |
7 | import com.topdraw.business.module.member.viphistory.service.dto.MemberVipHistoryDTO; | 9 | import com.topdraw.business.module.member.viphistory.service.dto.MemberVipHistoryDTO; |
8 | import com.topdraw.business.module.member.viphistory.service.dto.MemberVipHistoryQueryCriteria; | ||
9 | import com.topdraw.business.module.member.viphistory.service.mapper.MemberVipHistoryMapper; | 10 | import com.topdraw.business.module.member.viphistory.service.mapper.MemberVipHistoryMapper; |
10 | import com.topdraw.utils.PageUtil; | ||
11 | import com.topdraw.utils.QueryHelp; | ||
12 | import com.topdraw.utils.ValidationUtil; | 11 | import com.topdraw.utils.ValidationUtil; |
12 | import lombok.extern.slf4j.Slf4j; | ||
13 | import org.springframework.beans.factory.annotation.Autowired; | 13 | import org.springframework.beans.factory.annotation.Autowired; |
14 | import org.springframework.dao.EmptyResultDataAccessException; | 14 | import org.springframework.dao.EmptyResultDataAccessException; |
15 | import org.springframework.data.domain.Page; | ||
16 | import org.springframework.data.domain.Pageable; | ||
17 | import org.springframework.stereotype.Service; | 15 | import org.springframework.stereotype.Service; |
18 | import org.springframework.transaction.annotation.Propagation; | 16 | import org.springframework.transaction.annotation.Propagation; |
19 | import org.springframework.transaction.annotation.Transactional; | 17 | import org.springframework.transaction.annotation.Transactional; |
20 | import org.springframework.util.Assert; | 18 | import org.springframework.util.Assert; |
21 | 19 | ||
22 | import java.time.LocalDateTime; | 20 | import java.time.LocalDateTime; |
23 | import java.util.List; | ||
24 | import java.util.Map; | ||
25 | import java.util.Optional; | ||
26 | 21 | ||
27 | /** | 22 | /** |
28 | * @author luerlong | 23 | * @author luerlong |
... | @@ -30,35 +25,31 @@ import java.util.Optional; | ... | @@ -30,35 +25,31 @@ import java.util.Optional; |
30 | */ | 25 | */ |
31 | @Service | 26 | @Service |
32 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | 27 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) |
28 | @Slf4j | ||
33 | public class MemberVipHistoryServiceImpl implements MemberVipHistoryService { | 29 | public class MemberVipHistoryServiceImpl implements MemberVipHistoryService { |
34 | 30 | ||
35 | @Autowired | 31 | @Autowired |
36 | private MemberVipHistoryRepository memberVipHistoryRepository; | 32 | private MemberService memberService; |
37 | 33 | ||
38 | @Autowired | 34 | @Autowired |
39 | private MemberVipHistoryMapper memberVipHistoryMapper; | 35 | private MemberVipHistoryMapper memberVipHistoryMapper; |
40 | 36 | @Autowired | |
41 | @Override | 37 | private MemberVipHistoryRepository memberVipHistoryRepository; |
42 | public Map<String, Object> queryAll(MemberVipHistoryQueryCriteria criteria, Pageable pageable) { | ||
43 | Page<MemberVipHistory> page = memberVipHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
44 | return PageUtil.toPage(page.map(memberVipHistoryMapper::toDto)); | ||
45 | } | ||
46 | |||
47 | @Override | ||
48 | public List<MemberVipHistoryDTO> queryAll(MemberVipHistoryQueryCriteria criteria) { | ||
49 | return memberVipHistoryMapper.toDto(memberVipHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
50 | } | ||
51 | 38 | ||
52 | @Override | 39 | @Override |
53 | public MemberVipHistoryDTO findById(Long id) { | 40 | public MemberVipHistoryDTO findById(Long id) { |
41 | log.info("MemberVipHistoryServiceImpl ==>> findById ==>> param ==>> [{}]",id); | ||
54 | MemberVipHistory memberVipHistory = memberVipHistoryRepository.findById(id).orElseGet(MemberVipHistory::new); | 42 | MemberVipHistory memberVipHistory = memberVipHistoryRepository.findById(id).orElseGet(MemberVipHistory::new); |
55 | ValidationUtil.isNull(memberVipHistory.getId(),"MemberVipHistory","id",id); | 43 | ValidationUtil.isNull(memberVipHistory.getId(),"MemberVipHistory","id",id); |
44 | log.info("MemberVipHistoryServiceImpl ==>> findById ==>> result ==>> [{}]",memberVipHistory); | ||
56 | return memberVipHistoryMapper.toDto(memberVipHistory); | 45 | return memberVipHistoryMapper.toDto(memberVipHistory); |
57 | } | 46 | } |
58 | 47 | ||
59 | @Override | 48 | @Override |
60 | @Transactional(rollbackFor = Exception.class) | 49 | @Transactional(rollbackFor = Exception.class) |
61 | public void create(MemberVipHistory resources) { | 50 | public void create(MemberVipHistory resources) { |
51 | log.info("MemberVipHistoryServiceImpl ==>> MemberVipHistoryServiceImpl ==>> param ==>> [{}]",resources); | ||
52 | this.checkMember(resources); | ||
62 | memberVipHistoryRepository.save(resources); | 53 | memberVipHistoryRepository.save(resources); |
63 | } | 54 | } |
64 | 55 | ||
... | @@ -86,5 +77,10 @@ public class MemberVipHistoryServiceImpl implements MemberVipHistoryService { | ... | @@ -86,5 +77,10 @@ public class MemberVipHistoryServiceImpl implements MemberVipHistoryService { |
86 | return memberVipHistory; | 77 | return memberVipHistory; |
87 | } | 78 | } |
88 | 79 | ||
80 | private MemberDTO checkMember(MemberVipHistory resources){ | ||
81 | Long memberId = resources.getMemberId(); | ||
82 | String code = resources.getMemberCode(); | ||
83 | return this.memberService.checkMember(memberId, code); | ||
84 | } | ||
89 | 85 | ||
90 | } | 86 | } | ... | ... |
1 | package com.topdraw.business.module.points.available.domain; | 1 | package com.topdraw.business.module.points.available.domain; |
2 | 2 | ||
3 | import com.topdraw.business.module.common.domain.DefaultAsyncMqModule; | 3 | import com.topdraw.business.module.common.domain.AsyncMqModule; |
4 | import lombok.Data; | 4 | import lombok.Data; |
5 | import lombok.experimental.Accessors; | 5 | import lombok.experimental.Accessors; |
6 | import cn.hutool.core.bean.BeanUtil; | 6 | import cn.hutool.core.bean.BeanUtil; |
... | @@ -25,7 +25,7 @@ import java.io.Serializable; | ... | @@ -25,7 +25,7 @@ import java.io.Serializable; |
25 | @EntityListeners(AuditingEntityListener.class) | 25 | @EntityListeners(AuditingEntityListener.class) |
26 | @Accessors(chain = true) | 26 | @Accessors(chain = true) |
27 | @Table(name="uc_points_available") | 27 | @Table(name="uc_points_available") |
28 | public class PointsAvailable extends DefaultAsyncMqModule implements Serializable { | 28 | public class PointsAvailable extends AsyncMqModule implements Serializable { |
29 | 29 | ||
30 | // 主键 | 30 | // 主键 |
31 | @Id | 31 | @Id | ... | ... |
1 | package com.topdraw.business.module.rights.history.domain; | 1 | package com.topdraw.business.module.rights.history.domain; |
2 | 2 | ||
3 | import com.topdraw.business.module.common.domain.DefaultAsyncMqModule; | 3 | import com.topdraw.business.module.common.domain.AsyncMqModule; |
4 | import lombok.Data; | 4 | import lombok.Data; |
5 | import lombok.experimental.Accessors; | 5 | import lombok.experimental.Accessors; |
6 | import cn.hutool.core.bean.BeanUtil; | 6 | import cn.hutool.core.bean.BeanUtil; |
... | @@ -23,7 +23,7 @@ import java.time.LocalDateTime; | ... | @@ -23,7 +23,7 @@ import java.time.LocalDateTime; |
23 | @EntityListeners(AuditingEntityListener.class) | 23 | @EntityListeners(AuditingEntityListener.class) |
24 | @Accessors(chain = true) | 24 | @Accessors(chain = true) |
25 | @Table(name="tr_rights_histroy") | 25 | @Table(name="tr_rights_histroy") |
26 | public class RightsHistory extends DefaultAsyncMqModule implements Serializable { | 26 | public class RightsHistory extends AsyncMqModule implements Serializable { |
27 | 27 | ||
28 | // 主键id | 28 | // 主键id |
29 | @Id | 29 | @Id | ... | ... |
1 | package com.topdraw.business.module.user.iptv.domain; | 1 | package com.topdraw.business.module.user.iptv.domain; |
2 | 2 | ||
3 | import com.topdraw.business.common.CreateGroup; | 3 | import com.topdraw.business.module.common.domain.AsyncMqModule; |
4 | import com.topdraw.business.common.UpdateGroup; | 4 | import com.topdraw.business.module.common.validated.CreateGroup; |
5 | import lombok.Data; | 5 | import lombok.Data; |
6 | import lombok.experimental.Accessors; | 6 | import lombok.experimental.Accessors; |
7 | import cn.hutool.core.bean.BeanUtil; | 7 | import cn.hutool.core.bean.BeanUtil; |
... | @@ -25,15 +25,11 @@ import java.io.Serializable; | ... | @@ -25,15 +25,11 @@ import java.io.Serializable; |
25 | @EntityListeners(AuditingEntityListener.class) | 25 | @EntityListeners(AuditingEntityListener.class) |
26 | @Accessors(chain = true) | 26 | @Accessors(chain = true) |
27 | @Table(name="uc_user_tv") | 27 | @Table(name="uc_user_tv") |
28 | public class UserTv implements Serializable { | 28 | public class UserTv extends AsyncMqModule implements Serializable { |
29 | 29 | ||
30 | /** 绑定的小屏账户会员编码 */ | 30 | /** 绑定的小屏账户会员编码 */ |
31 | @Column(name = "priority_member_code") | 31 | @Column(name = "priority_member_code") |
32 | private String priorityMemberCode; | 32 | private String priorityMemberCode; |
33 | |||
34 | @Transient | ||
35 | private String memberCode; | ||
36 | |||
37 | // ID | 33 | // ID |
38 | @Id | 34 | @Id |
39 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 35 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ... | ... |
member-service-impl/src/main/java/com/topdraw/business/module/user/iptv/domain/UserTvBuilder.java
0 → 100644
1 | package com.topdraw.business.module.user.iptv.domain; | ||
2 | |||
3 | import com.topdraw.business.module.member.domain.Member; | ||
4 | import com.topdraw.exception.BadRequestException; | ||
5 | import com.topdraw.exception.GlobeExceptionMsg; | ||
6 | import com.topdraw.util.TimestampUtil; | ||
7 | import org.apache.commons.lang3.StringUtils; | ||
8 | |||
9 | /** | ||
10 | * @author : | ||
11 | * @description: | ||
12 | * @function : | ||
13 | * @date :Created in 2022/3/14 14:36 | ||
14 | * @version: : | ||
15 | * @modified By: | ||
16 | * @since : modified in 2022/3/14 14:36 | ||
17 | */ | ||
18 | public class UserTvBuilder { | ||
19 | |||
20 | public static UserTv build(UserTv userTv){ | ||
21 | return build(userTv.getMemberCode(),userTv.getId(),userTv.getPlatformAccount(),userTv.getNickname(),userTv.getUsername(), | ||
22 | userTv.getLoginDays(),userTv.getStatus(),userTv.getContinueDays(),userTv.getCreateBy(),userTv.getUpdateBy()); | ||
23 | } | ||
24 | |||
25 | public static UserTv build(String memberCode , UserTv userTv){ | ||
26 | return build(memberCode,userTv.getId(),userTv.getPlatformAccount(),userTv.getNickname(),userTv.getUsername(), | ||
27 | userTv.getLoginDays(),userTv.getStatus(),userTv.getContinueDays(),userTv.getCreateBy(),userTv.getUpdateBy()); | ||
28 | } | ||
29 | |||
30 | public static UserTv build(Member member ,UserTv userTv){ | ||
31 | return build(member.getCode(),userTv.getId(),userTv.getPlatformAccount(),userTv.getNickname(),userTv.getUsername(), | ||
32 | userTv.getLoginDays(),userTv.getStatus(),userTv.getContinueDays(),userTv.getCreateBy(),userTv.getUpdateBy()); | ||
33 | } | ||
34 | |||
35 | public static UserTv build(String memberCode , Long id , String platformAccount , String nickname , String username, | ||
36 | int loginDays , int status ,int continueDays , String createBy , String updateBy){ | ||
37 | |||
38 | if (StringUtils.isBlank(platformAccount)) | ||
39 | throw new BadRequestException(GlobeExceptionMsg.IPTV_PLATFORM_ACCOUNT_IS_NULL); | ||
40 | |||
41 | // todo 原型模式 | ||
42 | |||
43 | UserTv userTv = new UserTv(); | ||
44 | userTv.setId(id); | ||
45 | userTv.setPlatformAccount(platformAccount); | ||
46 | userTv.setMemberCode(memberCode); | ||
47 | userTv.setNickname(StringUtils.isBlank(nickname)?platformAccount:nickname); | ||
48 | userTv.setUsername(StringUtils.isBlank(username)?platformAccount:username); | ||
49 | userTv.setLoginDays(loginDays); | ||
50 | userTv.setStatus(status); | ||
51 | userTv.setActiveTime(TimestampUtil.now()); | ||
52 | userTv.setContinueDays(continueDays); | ||
53 | userTv.setCreateBy(StringUtils.isBlank(createBy)?"system":createBy); | ||
54 | userTv.setUpdateBy(StringUtils.isBlank(updateBy)?"system":updateBy); | ||
55 | return userTv; | ||
56 | } | ||
57 | |||
58 | } |
1 | package com.topdraw.business.module.user.iptv.rest; | ||
2 | |||
3 | import com.topdraw.annotation.AnonymousAccess; | ||
4 | import com.topdraw.common.ResultInfo; | ||
5 | import com.topdraw.business.module.user.iptv.domain.UserTv; | ||
6 | import com.topdraw.business.module.user.iptv.service.UserTvService; | ||
7 | import com.topdraw.business.module.user.iptv.service.dto.UserTvQueryCriteria; | ||
8 | import org.springframework.beans.factory.annotation.Autowired; | ||
9 | import org.springframework.data.domain.Pageable; | ||
10 | import org.springframework.validation.annotation.Validated; | ||
11 | import org.springframework.web.bind.annotation.*; | ||
12 | import io.swagger.annotations.*; | ||
13 | |||
14 | /** | ||
15 | * @author XiangHan | ||
16 | * @date 2021-12-16 | ||
17 | */ | ||
18 | @Api(tags = "UserTv管理") | ||
19 | @RestController | ||
20 | @RequestMapping("/ucEngine/api/userTv") | ||
21 | public class UserTvController { | ||
22 | |||
23 | @Autowired | ||
24 | private UserTvService UserTvService; | ||
25 | |||
26 | @GetMapping | ||
27 | @ApiOperation("查询UserTv") | ||
28 | public ResultInfo getUserTvs(UserTvQueryCriteria criteria, Pageable pageable) { | ||
29 | return ResultInfo.successPage(UserTvService.queryAll(criteria,pageable)); | ||
30 | } | ||
31 | |||
32 | @GetMapping(value = "/all") | ||
33 | @ApiOperation("查询所有UserTv") | ||
34 | public ResultInfo getUserTvs(UserTvQueryCriteria criteria) { | ||
35 | return ResultInfo.success(UserTvService.queryAll(criteria)); | ||
36 | } | ||
37 | |||
38 | @PostMapping(value = "/create") | ||
39 | @ApiOperation("新增UserTv") | ||
40 | @AnonymousAccess | ||
41 | public ResultInfo create(@Validated @RequestBody UserTv resources) { | ||
42 | UserTvService.create(resources); | ||
43 | return ResultInfo.success(); | ||
44 | } | ||
45 | |||
46 | @PutMapping | ||
47 | @ApiOperation("修改UserTv") | ||
48 | @AnonymousAccess | ||
49 | public ResultInfo update(@Validated @RequestBody UserTv resources) { | ||
50 | UserTvService.update(resources); | ||
51 | return ResultInfo.success(); | ||
52 | } | ||
53 | |||
54 | @DeleteMapping(value = "/{id}") | ||
55 | @ApiOperation("删除UserTv") | ||
56 | public ResultInfo delete(@PathVariable Long id) { | ||
57 | UserTvService.delete(id); | ||
58 | return ResultInfo.success(); | ||
59 | } | ||
60 | |||
61 | } |
1 | package com.topdraw.business.module.user.iptv.service; | 1 | package com.topdraw.business.module.user.iptv.service; |
2 | 2 | ||
3 | import com.topdraw.aspect.AsyncMqSend; | 3 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
4 | import com.topdraw.business.module.user.iptv.domain.UserTv; | 4 | import com.topdraw.business.module.user.iptv.domain.UserTv; |
5 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; | 5 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; |
6 | import com.topdraw.business.module.user.iptv.service.dto.UserTvQueryCriteria; | ||
7 | import org.springframework.data.domain.Pageable; | ||
8 | import org.springframework.transaction.annotation.Transactional; | ||
9 | |||
10 | import java.util.Map; | ||
11 | import java.util.List; | ||
12 | 6 | ||
13 | /** | 7 | /** |
14 | * @author XiangHan | 8 | * @author XiangHan |
... | @@ -17,38 +11,65 @@ import java.util.List; | ... | @@ -17,38 +11,65 @@ import java.util.List; |
17 | public interface UserTvService { | 11 | public interface UserTvService { |
18 | 12 | ||
19 | /** | 13 | /** |
20 | * 查询数据分页 | ||
21 | * @param criteria 条件参数 | ||
22 | * @param pageable 分页参数 | ||
23 | * @return Map<String,Object> | ||
24 | */ | ||
25 | Map<String,Object> queryAll(UserTvQueryCriteria criteria, Pageable pageable); | ||
26 | |||
27 | /** | ||
28 | * 查询所有数据不分页 | ||
29 | * @param criteria 条件参数 | ||
30 | * @return List<UserTvDTO> | ||
31 | */ | ||
32 | List<UserTvDTO> queryAll(UserTvQueryCriteria criteria); | ||
33 | |||
34 | /** | ||
35 | * 根据ID查询 | 14 | * 根据ID查询 |
36 | * @param id ID | 15 | * @param id ID |
37 | * @return UserTvDTO | 16 | * @return UserTvDTO |
38 | */ | 17 | */ |
39 | UserTvDTO findById(Long id); | 18 | UserTvDTO findById(Long id); |
40 | 19 | ||
41 | Long create(UserTv resources); | 20 | /** |
21 | * | ||
22 | * @param resources | ||
23 | * @return | ||
24 | */ | ||
25 | UserTv create(UserTv resources); | ||
42 | 26 | ||
27 | /** | ||
28 | * | ||
29 | * @param resources | ||
30 | */ | ||
43 | void update(UserTv resources); | 31 | void update(UserTv resources); |
44 | 32 | ||
33 | /** | ||
34 | * | ||
35 | * @param resources | ||
36 | */ | ||
45 | void unbindPriorityMemberCode(UserTv resources); | 37 | void unbindPriorityMemberCode(UserTv resources); |
46 | 38 | ||
39 | /** | ||
40 | * | ||
41 | * @param id | ||
42 | */ | ||
47 | void delete(Long id); | 43 | void delete(Long id); |
48 | 44 | ||
45 | /** | ||
46 | * | ||
47 | * @param platformAccount | ||
48 | * @return | ||
49 | */ | ||
49 | UserTvDTO findByPlatformAccount(String platformAccount); | 50 | UserTvDTO findByPlatformAccount(String platformAccount); |
50 | 51 | ||
52 | /** | ||
53 | * | ||
54 | * @param memberCode | ||
55 | * @return | ||
56 | */ | ||
51 | UserTvDTO findByPriorityMemberCode(String memberCode); | 57 | UserTvDTO findByPriorityMemberCode(String memberCode); |
52 | 58 | ||
59 | /** | ||
60 | * 通过会员 | ||
61 | * @param memberId | ||
62 | * @return | ||
63 | */ | ||
53 | UserTvDTO findByMemberId(Long memberId); | 64 | UserTvDTO findByMemberId(Long memberId); |
65 | |||
66 | /** | ||
67 | * 检查会员是否是主账号 | ||
68 | * @param memberId | ||
69 | * @param memberCode | ||
70 | * @return | ||
71 | */ | ||
72 | boolean checkPriorityMemberByMemberIdOrMemberCode(Long memberId,String memberCode); | ||
73 | |||
74 | MemberDTO findMemberByPlatformAccount(String platformAccount); | ||
54 | } | 75 | } | ... | ... |
1 | package com.topdraw.business.module.user.iptv.service.impl; | 1 | package com.topdraw.business.module.user.iptv.service.impl; |
2 | 2 | ||
3 | import com.topdraw.aspect.AsyncMqSend; | ||
4 | import com.topdraw.business.module.member.service.MemberService; | 3 | import com.topdraw.business.module.member.service.MemberService; |
5 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 4 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
6 | import com.topdraw.business.module.user.iptv.domain.UserTv; | 5 | import com.topdraw.business.module.user.iptv.domain.UserTv; |
6 | import com.topdraw.exception.EntityNotFoundException; | ||
7 | import com.topdraw.exception.GlobeExceptionMsg; | ||
7 | import com.topdraw.utils.ValidationUtil; | 8 | import com.topdraw.utils.ValidationUtil; |
8 | import com.topdraw.business.module.user.iptv.repository.UserTvRepository; | 9 | import com.topdraw.business.module.user.iptv.repository.UserTvRepository; |
9 | import com.topdraw.business.module.user.iptv.service.UserTvService; | 10 | import com.topdraw.business.module.user.iptv.service.UserTvService; |
10 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; | 11 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; |
11 | import com.topdraw.business.module.user.iptv.service.dto.UserTvQueryCriteria; | ||
12 | import com.topdraw.business.module.user.iptv.service.mapper.UserTvMapper; | 12 | import com.topdraw.business.module.user.iptv.service.mapper.UserTvMapper; |
13 | import org.apache.commons.lang3.StringUtils; | ||
13 | import org.springframework.beans.factory.annotation.Autowired; | 14 | import org.springframework.beans.factory.annotation.Autowired; |
14 | import org.springframework.stereotype.Service; | 15 | import org.springframework.stereotype.Service; |
15 | import org.springframework.transaction.annotation.Propagation; | 16 | import org.springframework.transaction.annotation.Propagation; |
16 | import org.springframework.transaction.annotation.Transactional; | 17 | import org.springframework.transaction.annotation.Transactional; |
17 | import org.springframework.dao.EmptyResultDataAccessException; | 18 | import org.springframework.dao.EmptyResultDataAccessException; |
18 | import org.springframework.data.domain.Page; | ||
19 | import org.springframework.data.domain.Pageable; | ||
20 | import org.springframework.util.Assert; | 19 | import org.springframework.util.Assert; |
21 | import com.topdraw.utils.PageUtil; | ||
22 | import com.topdraw.utils.QueryHelp; | ||
23 | 20 | ||
24 | import java.util.List; | ||
25 | import java.util.Map; | ||
26 | import java.util.Objects; | 21 | import java.util.Objects; |
27 | import java.util.Optional; | 22 | import java.util.Optional; |
28 | 23 | ||
... | @@ -34,106 +29,141 @@ import java.util.Optional; | ... | @@ -34,106 +29,141 @@ import java.util.Optional; |
34 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | 29 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) |
35 | public class UserTvServiceImpl implements UserTvService { | 30 | public class UserTvServiceImpl implements UserTvService { |
36 | 31 | ||
37 | @Autowired | ||
38 | private UserTvRepository UserTvRepository; | ||
39 | 32 | ||
40 | @Autowired | 33 | @Autowired |
41 | private UserTvMapper UserTvMapper; | 34 | private UserTvMapper userTvMapper; |
42 | |||
43 | @Autowired | 35 | @Autowired |
44 | private MemberService memberService; | 36 | private MemberService memberService; |
45 | 37 | @Autowired | |
38 | private UserTvRepository userTvRepository; | ||
39 | |||
40 | /** | ||
41 | * 获取大屏账户对应的会员 | ||
42 | * <Waring> | ||
43 | * 如果绑定了小屏,则获取对应主账号对应的会员信息,如果没有绑定小屏会员则默认获取大屏自己的会员(x_member) | ||
44 | * </Waring> | ||
45 | * @param platformAccount | ||
46 | * @return | ||
47 | */ | ||
46 | @Override | 48 | @Override |
47 | public Map<String, Object> queryAll(UserTvQueryCriteria criteria, Pageable pageable) { | 49 | public MemberDTO findMemberByPlatformAccount(String platformAccount){ |
48 | Page<UserTv> page = UserTvRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | 50 | // 大屏账户 |
49 | return PageUtil.toPage(page.map(UserTvMapper::toDto)); | 51 | UserTvDTO userTvDTO = this.findByPlatformAccount(platformAccount); |
52 | |||
53 | if (Objects.nonNull(userTvDTO)) { | ||
54 | |||
55 | // 主账号会员code | ||
56 | String priorityMemberCode = userTvDTO.getPriorityMemberCode(); | ||
57 | if (StringUtils.isNotBlank(platformAccount)) | ||
58 | return this.findMemberByMemberCode(priorityMemberCode); | ||
59 | else | ||
60 | return this.findMemberByMemberId(userTvDTO.getMemberId()); | ||
61 | |||
50 | } | 62 | } |
51 | 63 | ||
52 | @Override | 64 | throw new EntityNotFoundException(UserTvDTO.class,"platformAccount", GlobeExceptionMsg.IPTV_IS_NULL); |
53 | public List<UserTvDTO> queryAll(UserTvQueryCriteria criteria) { | 65 | } |
54 | return UserTvMapper.toDto(UserTvRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | 66 | |
67 | private MemberDTO findMemberByMemberCode(String memberCode) { | ||
68 | return this.memberService.findByCode(memberCode); | ||
69 | } | ||
70 | |||
71 | private MemberDTO findMemberByMemberId(Long memberId) { | ||
72 | return this.memberService.findById(memberId); | ||
55 | } | 73 | } |
56 | 74 | ||
57 | @Override | 75 | @Override |
58 | public UserTvDTO findById(Long id) { | 76 | public UserTvDTO findById(Long id) { |
59 | UserTv UserTv = UserTvRepository.findById(id).orElseGet(UserTv::new); | 77 | UserTv UserTv = this.userTvRepository.findById(id).orElseGet(UserTv::new); |
60 | ValidationUtil.isNull(UserTv.getId(),"UserTv","id",id); | 78 | ValidationUtil.isNull(UserTv.getId(),"UserTv","id",id); |
61 | return UserTvMapper.toDto(UserTv); | 79 | return this.userTvMapper.toDto(UserTv); |
62 | } | 80 | } |
63 | 81 | ||
64 | @Override | 82 | @Override |
65 | @Transactional(rollbackFor = Exception.class) | 83 | @Transactional(rollbackFor = Exception.class) |
66 | @AsyncMqSend | 84 | public UserTv create(UserTv resources) { |
67 | public Long create(UserTv resources) { | ||
68 | MemberDTO memberDTO = memberService.findByCode(resources.getMemberCode()); | 85 | MemberDTO memberDTO = memberService.findByCode(resources.getMemberCode()); |
69 | if (Objects.nonNull(memberDTO)) { | 86 | if (Objects.nonNull(memberDTO)) { |
70 | Long id = memberDTO.getId(); | 87 | Long id = memberDTO.getId(); |
71 | resources.setMemberId(id); | 88 | resources.setMemberId(id); |
72 | UserTvRepository.save(resources); | 89 | this.userTvRepository.save(resources); |
73 | return resources.getId(); | 90 | return resources; |
74 | } | 91 | } |
75 | return null; | 92 | return null; |
76 | } | 93 | } |
77 | 94 | ||
78 | @Override | 95 | @Override |
79 | @Transactional(rollbackFor = Exception.class) | 96 | @Transactional(rollbackFor = Exception.class) |
80 | @AsyncMqSend | ||
81 | public void update(UserTv resources) { | 97 | public void update(UserTv resources) { |
82 | UserTv UserTv = UserTvRepository.findById(resources.getId()).orElseGet(UserTv::new); | 98 | UserTv UserTv = this.userTvRepository.findById(resources.getId()).orElseGet(UserTv::new); |
83 | ValidationUtil.isNull( UserTv.getId(),"UserTv","id",resources.getId()); | 99 | ValidationUtil.isNull( UserTv.getId(),"UserTv","id",resources.getId()); |
84 | UserTv.copy(resources); | 100 | UserTv.copy(resources); |
85 | UserTvRepository.save(UserTv); | 101 | this.userTvRepository.save(UserTv); |
86 | } | 102 | } |
87 | 103 | ||
88 | @Override | 104 | @Override |
89 | @Transactional(rollbackFor = Exception.class) | 105 | @Transactional(rollbackFor = Exception.class) |
90 | @AsyncMqSend | ||
91 | public void unbindPriorityMemberCode(UserTv resources) { | 106 | public void unbindPriorityMemberCode(UserTv resources) { |
92 | UserTv UserTv = UserTvRepository.findById(resources.getId()).orElseGet(UserTv::new); | 107 | UserTv UserTv = this.userTvRepository.findById(resources.getId()).orElseGet(UserTv::new); |
93 | ValidationUtil.isNull( UserTv.getId(),"UserTv","id",resources.getId()); | 108 | ValidationUtil.isNull( UserTv.getId(),"UserTv","id",resources.getId()); |
94 | UserTv.copy(resources); | 109 | UserTv.copy(resources); |
95 | UserTvRepository.save(UserTv); | 110 | this.userTvRepository.save(UserTv); |
96 | } | 111 | } |
97 | 112 | ||
98 | @Override | 113 | @Override |
99 | @Transactional(rollbackFor = Exception.class) | 114 | @Transactional(rollbackFor = Exception.class) |
100 | @AsyncMqSend | ||
101 | public void delete(Long id) { | 115 | public void delete(Long id) { |
102 | Assert.notNull(id, "The given id must not be null!"); | 116 | Assert.notNull(id, "The given id must not be null!"); |
103 | UserTv UserTv = UserTvRepository.findById(id).orElseThrow( | 117 | UserTv UserTv = this.userTvRepository.findById(id).orElseThrow( |
104 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", UserTv.class, id), 1)); | 118 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", UserTv.class, id), 1)); |
105 | UserTvRepository.delete(UserTv); | 119 | this.userTvRepository.delete(UserTv); |
106 | } | 120 | } |
107 | 121 | ||
108 | @Override | 122 | @Override |
109 | public UserTvDTO findByPlatformAccount(String platformAccount) { | 123 | public UserTvDTO findByPlatformAccount(String platformAccount) { |
110 | Optional<UserTv> userTv = UserTvRepository.findByPlatformAccount(platformAccount); | 124 | Optional<UserTv> userTv = this.userTvRepository.findByPlatformAccount(platformAccount); |
111 | if (userTv.isPresent()) { | 125 | if (userTv.isPresent()) { |
112 | ValidationUtil.isNull( userTv.get().getId(),"UserTv","id",userTv.get().getId()); | 126 | ValidationUtil.isNull( userTv.get().getId(),"UserTv","id",userTv.get().getId()); |
113 | return UserTvMapper.toDto(userTv.get()); | 127 | return this.userTvMapper.toDto(userTv.get()); |
114 | } | 128 | } |
115 | return null; | 129 | return null; |
116 | } | 130 | } |
117 | 131 | ||
118 | @Override | 132 | @Override |
119 | public UserTvDTO findByPriorityMemberCode(String memberCode) { | 133 | public UserTvDTO findByPriorityMemberCode(String memberCode) { |
120 | Optional<UserTv> userTv = UserTvRepository.findByPriorityMemberCode(memberCode); | 134 | Optional<UserTv> userTv = this.userTvRepository.findByPriorityMemberCode(memberCode); |
121 | if (userTv.isPresent()) { | 135 | if (userTv.isPresent()) { |
122 | ValidationUtil.isNull( userTv.get().getId(),"UserTv","id",userTv.get().getId()); | 136 | ValidationUtil.isNull( userTv.get().getId(),"UserTv","id",userTv.get().getId()); |
123 | return UserTvMapper.toDto(userTv.get()); | 137 | return this.userTvMapper.toDto(userTv.get()); |
124 | } | 138 | } |
125 | return null; | 139 | return null; |
126 | } | 140 | } |
127 | 141 | ||
128 | @Override | 142 | @Override |
129 | public UserTvDTO findByMemberId(Long memberId) { | 143 | public UserTvDTO findByMemberId(Long memberId) { |
130 | Optional<UserTv> userTv = UserTvRepository.findByMemberId(memberId); | 144 | Optional<UserTv> userTv = this.userTvRepository.findByMemberId(memberId); |
131 | if (userTv.isPresent()) { | 145 | if (userTv.isPresent()) { |
132 | ValidationUtil.isNull( userTv.get().getId(),"UserTv","id",userTv.get().getId()); | 146 | ValidationUtil.isNull( userTv.get().getId(),"UserTv","id",userTv.get().getId()); |
133 | return UserTvMapper.toDto(userTv.get()); | 147 | return this.userTvMapper.toDto(userTv.get()); |
134 | } | 148 | } |
135 | return null; | 149 | return null; |
136 | } | 150 | } |
137 | 151 | ||
152 | @Override | ||
153 | public boolean checkPriorityMemberByMemberIdOrMemberCode(Long memberId, String memberCode) { | ||
154 | // 检查会员是否存在 | ||
155 | this.checkMember(memberId, memberCode); | ||
156 | // | ||
157 | UserTvDTO userTvDTO = this.findByPriorityMemberCode(memberCode); | ||
158 | if (Objects.nonNull(userTvDTO)) { | ||
159 | return true; | ||
160 | } | ||
161 | return false; | ||
162 | } | ||
163 | |||
164 | private void checkMember(Long memberId, String memberCode){ | ||
165 | this.memberService.checkMember(memberId, memberCode); | ||
166 | } | ||
167 | |||
138 | 168 | ||
139 | } | 169 | } | ... | ... |
1 | package com.topdraw.business.module.user.weixin.domain; | 1 | package com.topdraw.business.module.user.weixin.domain; |
2 | 2 | ||
3 | import com.topdraw.business.module.common.domain.DefaultAsyncMqModule; | 3 | import com.topdraw.business.module.common.domain.AsyncMqModule; |
4 | import com.topdraw.business.module.common.validated.CreateGroup; | ||
4 | import lombok.Data; | 5 | import lombok.Data; |
5 | import lombok.experimental.Accessors; | 6 | import lombok.experimental.Accessors; |
6 | import cn.hutool.core.bean.BeanUtil; | 7 | import cn.hutool.core.bean.BeanUtil; |
7 | import cn.hutool.core.bean.copier.CopyOptions; | 8 | import cn.hutool.core.bean.copier.CopyOptions; |
8 | import javax.persistence.*; | 9 | import javax.persistence.*; |
10 | import javax.validation.constraints.NotNull; | ||
11 | |||
9 | import org.springframework.data.annotation.CreatedDate; | 12 | import org.springframework.data.annotation.CreatedDate; |
10 | import org.springframework.data.annotation.LastModifiedDate; | 13 | import org.springframework.data.annotation.LastModifiedDate; |
11 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | 14 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; |
... | @@ -22,7 +25,7 @@ import java.io.Serializable; | ... | @@ -22,7 +25,7 @@ import java.io.Serializable; |
22 | @EntityListeners(AuditingEntityListener.class) | 25 | @EntityListeners(AuditingEntityListener.class) |
23 | @Accessors(chain = true) | 26 | @Accessors(chain = true) |
24 | @Table(name="uc_user_weixin") | 27 | @Table(name="uc_user_weixin") |
25 | public class UserWeixin extends DefaultAsyncMqModule implements Serializable { | 28 | public class UserWeixin extends AsyncMqModule implements Serializable { |
26 | 29 | ||
27 | // ID | 30 | // ID |
28 | @Id | 31 | @Id |
... | @@ -36,14 +39,17 @@ public class UserWeixin extends DefaultAsyncMqModule implements Serializable { | ... | @@ -36,14 +39,17 @@ public class UserWeixin extends DefaultAsyncMqModule implements Serializable { |
36 | 39 | ||
37 | // 微信unionid,针对开发者 | 40 | // 微信unionid,针对开发者 |
38 | @Column(name = "unionid") | 41 | @Column(name = "unionid") |
42 | @NotNull(message = "unionid can't be null",groups = {CreateGroup.class}) | ||
39 | private String unionid; | 43 | private String unionid; |
40 | 44 | ||
41 | // 微信appid | 45 | // 微信appid |
42 | @Column(name = "appid") | 46 | @Column(name = "appid") |
47 | @NotNull(message = "appid can't be null",groups = {CreateGroup.class}) | ||
43 | private String appid; | 48 | private String appid; |
44 | 49 | ||
45 | // 微信openid,针对微信app | 50 | // 微信openid,针对微信app |
46 | @Column(name = "openid") | 51 | @Column(name = "openid") |
52 | @NotNull(message = "openid can't be null",groups = {CreateGroup.class}) | ||
47 | private String openid; | 53 | private String openid; |
48 | 54 | ||
49 | // 关注状态 0 -未关注 1 - 已关注 | 55 | // 关注状态 0 -未关注 1 - 已关注 | ... | ... |
1 | package com.topdraw.business.module.user.weixin.domain; | ||
2 | |||
3 | import com.topdraw.business.module.member.domain.Member; | ||
4 | import com.topdraw.exception.BadRequestException; | ||
5 | import com.topdraw.exception.GlobeExceptionMsg; | ||
6 | import com.topdraw.util.TimestampUtil; | ||
7 | import org.apache.commons.lang3.StringUtils; | ||
8 | |||
9 | import java.sql.Timestamp; | ||
10 | import java.util.Objects; | ||
11 | |||
12 | /** | ||
13 | * @author : | ||
14 | * @description: | ||
15 | * @function : | ||
16 | * @date :Created in 2022/3/14 17:02 | ||
17 | * @version: : | ||
18 | * @modified By: | ||
19 | * @since : modified in 2022/3/14 17:02 | ||
20 | */ | ||
21 | public class UserWeixinBuilder { | ||
22 | |||
23 | public static UserWeixin build(Long memberId,String appId,String openId,String unionId,String nickname,String headimgurl){ | ||
24 | UserWeixin userWeixin = new UserWeixin(); | ||
25 | userWeixin.setAppid(appId); | ||
26 | userWeixin.setOpenid(openId); | ||
27 | userWeixin.setUnionid(unionId); | ||
28 | userWeixin.setNickname(nickname); | ||
29 | userWeixin.setHeadimgurl(headimgurl); | ||
30 | return build(memberId,userWeixin); | ||
31 | } | ||
32 | |||
33 | public static UserWeixin build(Long memberId,String appId,String openId,String unionId){ | ||
34 | UserWeixin userWeixin = new UserWeixin(); | ||
35 | userWeixin.setAppid(appId); | ||
36 | userWeixin.setOpenid(openId); | ||
37 | userWeixin.setUnionid(unionId); | ||
38 | return build(memberId,userWeixin); | ||
39 | } | ||
40 | |||
41 | public static UserWeixin build(UserWeixin userWeixin){ | ||
42 | return build(userWeixin.getId(), | ||
43 | userWeixin.getMemberId(), | ||
44 | userWeixin.getUnionid(),userWeixin.getAppid(),userWeixin.getOpenid(), | ||
45 | userWeixin.getStatus(),userWeixin.getSyncStatus(), | ||
46 | userWeixin.getNickname(),userWeixin.getHeadimgurl(), | ||
47 | userWeixin.getPrivilege(), userWeixin.getRefreshToken(),userWeixin.getAccessToken(), | ||
48 | userWeixin.getExpiresIn(),userWeixin.getExpiresTime(),userWeixin.getDescription(), | ||
49 | userWeixin.getCreateBy(),userWeixin.getUpdateBy(),userWeixin.getSourceType(),userWeixin.getSourceId(), | ||
50 | userWeixin.getSourceDesc(),userWeixin.getSourceUser(),userWeixin.getSourceEntity(),userWeixin.getCountry(),userWeixin.getProvince(), | ||
51 | userWeixin.getCity(),userWeixin.getSex()); | ||
52 | } | ||
53 | |||
54 | |||
55 | public static UserWeixin build(Long memberId , UserWeixin userWeixin){ | ||
56 | return build(userWeixin.getId(), | ||
57 | memberId, | ||
58 | userWeixin.getUnionid(),userWeixin.getAppid(),userWeixin.getOpenid(), | ||
59 | userWeixin.getStatus(),userWeixin.getSyncStatus(), | ||
60 | userWeixin.getNickname(),userWeixin.getHeadimgurl(), | ||
61 | userWeixin.getPrivilege(), userWeixin.getRefreshToken(),userWeixin.getAccessToken(), | ||
62 | userWeixin.getExpiresIn(),userWeixin.getExpiresTime(),userWeixin.getDescription(), | ||
63 | userWeixin.getCreateBy(),userWeixin.getUpdateBy(),userWeixin.getSourceType(),userWeixin.getSourceId(), | ||
64 | userWeixin.getSourceDesc(),userWeixin.getSourceUser(),userWeixin.getSourceEntity(),userWeixin.getCountry(),userWeixin.getProvince(), | ||
65 | userWeixin.getCity(),userWeixin.getSex()); | ||
66 | } | ||
67 | |||
68 | public static UserWeixin build(Member member , UserWeixin userWeixin) { | ||
69 | return build(userWeixin.getId(), | ||
70 | member.getId(), | ||
71 | userWeixin.getUnionid(),userWeixin.getAppid(),userWeixin.getOpenid(), | ||
72 | userWeixin.getStatus(),userWeixin.getSyncStatus(), | ||
73 | userWeixin.getNickname(),userWeixin.getHeadimgurl(), | ||
74 | userWeixin.getPrivilege(), userWeixin.getRefreshToken(),userWeixin.getAccessToken(), | ||
75 | userWeixin.getExpiresIn(),userWeixin.getExpiresTime(),userWeixin.getDescription(), | ||
76 | userWeixin.getCreateBy(),userWeixin.getUpdateBy(),userWeixin.getSourceType(),userWeixin.getSourceId(), | ||
77 | userWeixin.getSourceDesc(),userWeixin.getSourceUser(),userWeixin.getSourceEntity(),userWeixin.getCountry(),userWeixin.getProvince(), | ||
78 | userWeixin.getCity(),userWeixin.getSex()); | ||
79 | } | ||
80 | |||
81 | |||
82 | public static UserWeixin build(Long id , | ||
83 | Long memberId, | ||
84 | String unionId, String appId,String openId, | ||
85 | Integer status, Integer syncStatus, | ||
86 | String nickname,String headimgurl, | ||
87 | String privilege,String refreshToken, | ||
88 | String accessToken,Integer expiresIn,Timestamp expiresTime,String description, | ||
89 | String createBy,String updateBy, | ||
90 | String sourceType,String sourceId, | ||
91 | String sourceDesc, | ||
92 | Long sourceUser,String sourceEntity, | ||
93 | String country,String province,String city, | ||
94 | Integer sex){ | ||
95 | |||
96 | if (Objects.isNull(memberId)) { | ||
97 | throw new BadRequestException(GlobeExceptionMsg.MEMBER_ID_IS_NULL); | ||
98 | } | ||
99 | |||
100 | UserWeixin userWeixin = new UserWeixin(); | ||
101 | userWeixin.setId(Objects.nonNull(id)?id:null); | ||
102 | userWeixin.setMemberId(memberId); | ||
103 | userWeixin.setUnionid(StringUtils.isNotBlank(unionId)?unionId:""); | ||
104 | userWeixin.setAppid(StringUtils.isNotBlank(appId)?appId:""); | ||
105 | userWeixin.setOpenid(StringUtils.isNotBlank(openId)?openId:""); | ||
106 | userWeixin.setStatus(Objects.nonNull(status)?status:0); | ||
107 | userWeixin.setSyncStatus(Objects.nonNull(syncStatus)?syncStatus:0); | ||
108 | userWeixin.setNickname(StringUtils.isNotBlank(nickname)?nickname:""); | ||
109 | userWeixin.setHeadimgurl(StringUtils.isNotBlank(headimgurl)?headimgurl:""); | ||
110 | userWeixin.setPrivilege(StringUtils.isNotBlank(privilege)?privilege:""); | ||
111 | userWeixin.setRefreshToken(StringUtils.isNotBlank(refreshToken)?refreshToken:""); | ||
112 | userWeixin.setAccessToken(StringUtils.isNotBlank(accessToken)?accessToken:""); | ||
113 | userWeixin.setExpiresIn(expiresIn); | ||
114 | userWeixin.setExpiresTime(expiresTime); | ||
115 | userWeixin.setDescription(StringUtils.isNotBlank(description)?description:""); | ||
116 | userWeixin.setCreateBy(StringUtils.isNotBlank(createBy)?createBy:"system"); | ||
117 | userWeixin.setUpdateBy(StringUtils.isNotBlank(updateBy)?updateBy:"system"); | ||
118 | userWeixin.setSourceType(StringUtils.isNotBlank(sourceType)?sourceType:""); | ||
119 | userWeixin.setSourceId(StringUtils.isNotBlank(sourceId)?sourceId:""); | ||
120 | userWeixin.setSourceDesc(StringUtils.isNotBlank(sourceDesc)?sourceId:""); | ||
121 | userWeixin.setSourceUser(Objects.nonNull(sourceUser)?sourceUser:0L); | ||
122 | userWeixin.setSourceEntity(StringUtils.isNotBlank(sourceEntity)?sourceEntity:""); | ||
123 | userWeixin.setAuthTime(TimestampUtil.now()); | ||
124 | userWeixin.setCountry(StringUtils.isNotBlank(country)?country:""); | ||
125 | userWeixin.setProvince(StringUtils.isNotBlank(province)?province:""); | ||
126 | userWeixin.setCity(StringUtils.isNotBlank(city)?city:""); | ||
127 | userWeixin.setSex(Objects.nonNull(sex)?sex:-1); | ||
128 | return userWeixin; | ||
129 | } | ||
130 | |||
131 | } |
... | @@ -4,7 +4,6 @@ import com.topdraw.annotation.AnonymousAccess; | ... | @@ -4,7 +4,6 @@ import com.topdraw.annotation.AnonymousAccess; |
4 | import com.topdraw.common.ResultInfo; | 4 | import com.topdraw.common.ResultInfo; |
5 | import com.topdraw.business.module.user.weixin.domain.UserWeixin; | 5 | import com.topdraw.business.module.user.weixin.domain.UserWeixin; |
6 | import com.topdraw.business.module.user.weixin.service.UserWeixinService; | 6 | import com.topdraw.business.module.user.weixin.service.UserWeixinService; |
7 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinQueryCriteria; | ||
8 | import org.springframework.beans.factory.annotation.Autowired; | 7 | import org.springframework.beans.factory.annotation.Autowired; |
9 | import org.springframework.data.domain.Pageable; | 8 | import org.springframework.data.domain.Pageable; |
10 | import org.springframework.validation.annotation.Validated; | 9 | import org.springframework.validation.annotation.Validated; |
... | @@ -23,18 +22,6 @@ public class UserWeixinController { | ... | @@ -23,18 +22,6 @@ public class UserWeixinController { |
23 | @Autowired | 22 | @Autowired |
24 | private UserWeixinService UserWeixinService; | 23 | private UserWeixinService UserWeixinService; |
25 | 24 | ||
26 | @GetMapping | ||
27 | @ApiOperation("查询UserWeixin") | ||
28 | public ResultInfo getUserWeixins(UserWeixinQueryCriteria criteria, Pageable pageable) { | ||
29 | return ResultInfo.successPage(UserWeixinService.queryAll(criteria,pageable)); | ||
30 | } | ||
31 | |||
32 | @GetMapping(value = "/all") | ||
33 | @ApiOperation("查询所有UserWeixin") | ||
34 | public ResultInfo getUserWeixins(UserWeixinQueryCriteria criteria) { | ||
35 | return ResultInfo.success(UserWeixinService.queryAll(criteria)); | ||
36 | } | ||
37 | |||
38 | @PostMapping(value = "/create") | 25 | @PostMapping(value = "/create") |
39 | @ApiOperation("新增UserWeixin") | 26 | @ApiOperation("新增UserWeixin") |
40 | @AnonymousAccess | 27 | @AnonymousAccess | ... | ... |
... | @@ -2,11 +2,6 @@ package com.topdraw.business.module.user.weixin.service; | ... | @@ -2,11 +2,6 @@ package com.topdraw.business.module.user.weixin.service; |
2 | 2 | ||
3 | import com.topdraw.business.module.user.weixin.domain.UserWeixin; | 3 | import com.topdraw.business.module.user.weixin.domain.UserWeixin; |
4 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; | 4 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; |
5 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinQueryCriteria; | ||
6 | import org.springframework.data.domain.Pageable; | ||
7 | import java.util.Map; | ||
8 | import java.util.List; | ||
9 | import java.util.Optional; | ||
10 | 5 | ||
11 | /** | 6 | /** |
12 | * @author XiangHan | 7 | * @author XiangHan |
... | @@ -15,21 +10,6 @@ import java.util.Optional; | ... | @@ -15,21 +10,6 @@ import java.util.Optional; |
15 | public interface UserWeixinService { | 10 | public interface UserWeixinService { |
16 | 11 | ||
17 | /** | 12 | /** |
18 | * 查询数据分页 | ||
19 | * @param criteria 条件参数 | ||
20 | * @param pageable 分页参数 | ||
21 | * @return Map<String,Object> | ||
22 | */ | ||
23 | Map<String,Object> queryAll(UserWeixinQueryCriteria criteria, Pageable pageable); | ||
24 | |||
25 | /** | ||
26 | * 查询所有数据不分页 | ||
27 | * @param criteria 条件参数 | ||
28 | * @return List<UserWeixinDTO> | ||
29 | */ | ||
30 | List<UserWeixinDTO> queryAll(UserWeixinQueryCriteria criteria); | ||
31 | |||
32 | /** | ||
33 | * 根据ID查询 | 13 | * 根据ID查询 |
34 | * @param id ID | 14 | * @param id ID |
35 | * @return UserWeixinDTO | 15 | * @return UserWeixinDTO | ... | ... |
... | @@ -2,25 +2,18 @@ package com.topdraw.business.module.user.weixin.service.impl; | ... | @@ -2,25 +2,18 @@ package com.topdraw.business.module.user.weixin.service.impl; |
2 | 2 | ||
3 | import com.topdraw.aspect.AsyncMqSend; | 3 | import com.topdraw.aspect.AsyncMqSend; |
4 | import com.topdraw.business.module.user.weixin.domain.UserWeixin; | 4 | import com.topdraw.business.module.user.weixin.domain.UserWeixin; |
5 | import com.topdraw.business.module.user.weixin.domain.UserWeixinBuilder; | ||
5 | import com.topdraw.utils.ValidationUtil; | 6 | import com.topdraw.utils.ValidationUtil; |
6 | import com.topdraw.business.module.user.weixin.repository.UserWeixinRepository; | 7 | import com.topdraw.business.module.user.weixin.repository.UserWeixinRepository; |
7 | import com.topdraw.business.module.user.weixin.service.UserWeixinService; | 8 | import com.topdraw.business.module.user.weixin.service.UserWeixinService; |
8 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; | 9 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; |
9 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinQueryCriteria; | ||
10 | import com.topdraw.business.module.user.weixin.service.mapper.UserWeixinMapper; | 10 | import com.topdraw.business.module.user.weixin.service.mapper.UserWeixinMapper; |
11 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
12 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
13 | import org.springframework.transaction.annotation.Propagation; | 13 | import org.springframework.transaction.annotation.Propagation; |
14 | import org.springframework.transaction.annotation.Transactional; | 14 | import org.springframework.transaction.annotation.Transactional; |
15 | import org.springframework.dao.EmptyResultDataAccessException; | 15 | import org.springframework.dao.EmptyResultDataAccessException; |
16 | import org.springframework.data.domain.Page; | ||
17 | import org.springframework.data.domain.Pageable; | ||
18 | import org.springframework.util.Assert; | 16 | import org.springframework.util.Assert; |
19 | import com.topdraw.utils.PageUtil; | ||
20 | import com.topdraw.utils.QueryHelp; | ||
21 | |||
22 | import java.util.List; | ||
23 | import java.util.Map; | ||
24 | 17 | ||
25 | /** | 18 | /** |
26 | * @author XiangHan | 19 | * @author XiangHan |
... | @@ -37,17 +30,6 @@ public class UserWeixinServiceImpl implements UserWeixinService { | ... | @@ -37,17 +30,6 @@ public class UserWeixinServiceImpl implements UserWeixinService { |
37 | private UserWeixinMapper UserWeixinMapper; | 30 | private UserWeixinMapper UserWeixinMapper; |
38 | 31 | ||
39 | @Override | 32 | @Override |
40 | public Map<String, Object> queryAll(UserWeixinQueryCriteria criteria, Pageable pageable) { | ||
41 | Page<UserWeixin> page = UserWeixinRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
42 | return PageUtil.toPage(page.map(UserWeixinMapper::toDto)); | ||
43 | } | ||
44 | |||
45 | @Override | ||
46 | public List<UserWeixinDTO> queryAll(UserWeixinQueryCriteria criteria) { | ||
47 | return UserWeixinMapper.toDto(UserWeixinRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
48 | } | ||
49 | |||
50 | @Override | ||
51 | public UserWeixinDTO findById(Long id) { | 33 | public UserWeixinDTO findById(Long id) { |
52 | UserWeixin UserWeixin = UserWeixinRepository.findById(id).orElseGet(UserWeixin::new); | 34 | UserWeixin UserWeixin = UserWeixinRepository.findById(id).orElseGet(UserWeixin::new); |
53 | ValidationUtil.isNull(UserWeixin.getId(),"UserWeixin","id",id); | 35 | ValidationUtil.isNull(UserWeixin.getId(),"UserWeixin","id",id); |
... | @@ -58,7 +40,8 @@ public class UserWeixinServiceImpl implements UserWeixinService { | ... | @@ -58,7 +40,8 @@ public class UserWeixinServiceImpl implements UserWeixinService { |
58 | @Transactional(rollbackFor = Exception.class) | 40 | @Transactional(rollbackFor = Exception.class) |
59 | @AsyncMqSend | 41 | @AsyncMqSend |
60 | public UserWeixin create(UserWeixin resources) { | 42 | public UserWeixin create(UserWeixin resources) { |
61 | UserWeixinRepository.save(resources); | 43 | UserWeixin build = UserWeixinBuilder.build(resources); |
44 | UserWeixinRepository.save(build); | ||
62 | return resources; | 45 | return resources; |
63 | } | 46 | } |
64 | 47 | ... | ... |
1 | package com.topdraw.business.module.weixin.domain; | ||
2 | |||
3 | import cn.hutool.core.bean.BeanUtil; | ||
4 | import cn.hutool.core.bean.copier.CopyOptions; | ||
5 | import lombok.Data; | ||
6 | import lombok.experimental.Accessors; | ||
7 | import org.springframework.data.annotation.CreatedDate; | ||
8 | import org.springframework.data.annotation.LastModifiedDate; | ||
9 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
10 | |||
11 | import javax.persistence.*; | ||
12 | import java.io.Serializable; | ||
13 | import java.sql.Timestamp; | ||
14 | |||
15 | /** | ||
16 | * @author pengmengqing | ||
17 | * @date 2021-01-28 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="uc_user_weixin__weixin_message_template") | ||
24 | public class UserWeixinWeixinMessageTemplate implements Serializable { | ||
25 | |||
26 | // ID | ||
27 | @Id | ||
28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
29 | @Column(name = "id") | ||
30 | private Long id; | ||
31 | |||
32 | // 用户id | ||
33 | @Column(name = "user_weixin_id", nullable = false) | ||
34 | private Long userWeixinId; | ||
35 | |||
36 | // 微信消息模板id | ||
37 | @Column(name = "weixin_message_template_id", nullable = false) | ||
38 | private Long weixinMessageTemplateId; | ||
39 | |||
40 | // 用户是否订阅: 0-否, 1-是 | ||
41 | @Column(name = "status", nullable = false) | ||
42 | private Integer status; | ||
43 | |||
44 | // 创建时间 | ||
45 | @CreatedDate | ||
46 | @Column(name = "create_time") | ||
47 | private Timestamp createTime; | ||
48 | |||
49 | // 更新时间 | ||
50 | @LastModifiedDate | ||
51 | @Column(name = "update_time") | ||
52 | private Timestamp updateTime; | ||
53 | |||
54 | public void copy(UserWeixinWeixinMessageTemplate source){ | ||
55 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
56 | } | ||
57 | } |
1 | package com.topdraw.business.module.weixin.domain; | ||
2 | |||
3 | import cn.hutool.core.bean.BeanUtil; | ||
4 | import cn.hutool.core.bean.copier.CopyOptions; | ||
5 | import lombok.Data; | ||
6 | import lombok.experimental.Accessors; | ||
7 | import org.springframework.data.annotation.CreatedDate; | ||
8 | import org.springframework.data.annotation.LastModifiedDate; | ||
9 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
10 | |||
11 | import javax.persistence.*; | ||
12 | import java.io.Serializable; | ||
13 | import java.sql.Timestamp; | ||
14 | |||
15 | /** | ||
16 | * @author pengmengqing | ||
17 | * @date 2021-01-28 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="uc_weixin_message_template") | ||
24 | public class WeixinMessageTemplate implements Serializable { | ||
25 | |||
26 | // ID | ||
27 | @Id | ||
28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
29 | @Column(name = "id") | ||
30 | private Long id; | ||
31 | |||
32 | // 标识 order-下单成功通知,cancellation-核销成功通知 | ||
33 | @Column(name = "code", nullable = false) | ||
34 | private String code; | ||
35 | |||
36 | // 微信appid | ||
37 | @Column(name = "appid", nullable = false) | ||
38 | private String appid; | ||
39 | |||
40 | // 微信模板id | ||
41 | @Column(name = "template_id", nullable = false) | ||
42 | private String templateId; | ||
43 | |||
44 | // 状态:0-无效,1-有效 | ||
45 | @Column(name = "status", nullable = false) | ||
46 | private Integer status; | ||
47 | |||
48 | // 描述 | ||
49 | @Column(name = "description") | ||
50 | private String description; | ||
51 | |||
52 | // 创建时间 | ||
53 | @CreatedDate | ||
54 | @Column(name = "create_time") | ||
55 | private Timestamp createTime; | ||
56 | |||
57 | // 更新时间 | ||
58 | @LastModifiedDate | ||
59 | @Column(name = "update_time") | ||
60 | private Timestamp updateTime; | ||
61 | |||
62 | public void copy(WeixinMessageTemplate source){ | ||
63 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
64 | } | ||
65 | } |
1 | package com.topdraw.business.module.weixin.repository; | ||
2 | |||
3 | import com.topdraw.business.module.weixin.domain.UserWeixinWeixinMessageTemplate; | ||
4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
6 | |||
7 | |||
8 | /** | ||
9 | * @author pengmengqing | ||
10 | * @date 2021-01-28 | ||
11 | */ | ||
12 | public interface UserWeixinWeixinMessageTemplateRepository extends JpaRepository<UserWeixinWeixinMessageTemplate, Long>, JpaSpecificationExecutor<UserWeixinWeixinMessageTemplate> { | ||
13 | |||
14 | } |
1 | package com.topdraw.business.module.weixin.repository; | ||
2 | |||
3 | |||
4 | import com.topdraw.business.module.weixin.domain.WeixinMessageTemplate; | ||
5 | import org.springframework.data.jpa.repository.JpaRepository; | ||
6 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
7 | |||
8 | import java.util.Optional; | ||
9 | |||
10 | /** | ||
11 | * @author pengmengqing | ||
12 | * @date 2021-01-28 | ||
13 | */ | ||
14 | public interface WeixinMessageTemplateRepository extends JpaRepository<WeixinMessageTemplate, Long>, JpaSpecificationExecutor<WeixinMessageTemplate> { | ||
15 | |||
16 | Optional<WeixinMessageTemplate> findFirstByCode(String code); | ||
17 | |||
18 | Optional<WeixinMessageTemplate> findFirstByCodeAndAppid(String code, String appid); | ||
19 | |||
20 | Optional<WeixinMessageTemplate> findFirstByTemplateId(String templateId); | ||
21 | } |
1 | package com.topdraw.business.module.weixin.rest; | ||
2 | |||
3 | import com.topdraw.annotation.AnonymousAccess; | ||
4 | import com.topdraw.business.module.weixin.service.UserWeixinWeixinMessageTemplateService; | ||
5 | import com.topdraw.business.module.weixin.service.dto.UpdateUserWeixinWeixinMessageTemplateQueryCriteria; | ||
6 | import com.topdraw.common.ResultInfo; | ||
7 | import io.swagger.annotations.Api; | ||
8 | import io.swagger.annotations.ApiOperation; | ||
9 | import org.springframework.beans.factory.annotation.Autowired; | ||
10 | import org.springframework.web.bind.annotation.PostMapping; | ||
11 | import org.springframework.web.bind.annotation.RequestBody; | ||
12 | import org.springframework.web.bind.annotation.RequestMapping; | ||
13 | import org.springframework.web.bind.annotation.RestController; | ||
14 | |||
15 | import java.util.ArrayList; | ||
16 | |||
17 | /** | ||
18 | * @author pengmengqing | ||
19 | * @date 2021-01-28 | ||
20 | */ | ||
21 | @Api(tags = "UserWeixinWeixinMessageTemplate管理") | ||
22 | @RestController | ||
23 | @RequestMapping("/ucEngine/api/UserWeixinWeixinMessageTemplate") | ||
24 | public class UserWeixinWeixinMessageTemplateController { | ||
25 | |||
26 | @Autowired | ||
27 | private UserWeixinWeixinMessageTemplateService userWeixinWeixinMessageTemplateService; | ||
28 | |||
29 | @AnonymousAccess | ||
30 | @PostMapping | ||
31 | @ApiOperation("新增或修改MemberWeixinMessageTemplate") | ||
32 | public ResultInfo createOrUpdate(@RequestBody UpdateUserWeixinWeixinMessageTemplateQueryCriteria criteria) { | ||
33 | userWeixinWeixinMessageTemplateService.createOrUpdate(criteria); | ||
34 | return ResultInfo.success(new ArrayList<>()); | ||
35 | } | ||
36 | |||
37 | } |
1 | package com.topdraw.business.module.weixin.service; | ||
2 | |||
3 | |||
4 | import com.topdraw.business.module.weixin.domain.UserWeixinWeixinMessageTemplate; | ||
5 | import com.topdraw.business.module.weixin.service.dto.UpdateUserWeixinWeixinMessageTemplateQueryCriteria; | ||
6 | import com.topdraw.business.module.weixin.service.dto.UserWeixinWeixinMessageTemplateDTO; | ||
7 | import com.topdraw.business.module.weixin.service.dto.UserWeixinWeixinMessageTemplateQueryCriteria; | ||
8 | import org.springframework.data.domain.Pageable; | ||
9 | |||
10 | import javax.servlet.http.HttpServletResponse; | ||
11 | import java.io.IOException; | ||
12 | import java.util.List; | ||
13 | import java.util.Map; | ||
14 | |||
15 | /** | ||
16 | * @author pengmengqing | ||
17 | * @date 2021-01-28 | ||
18 | */ | ||
19 | public interface UserWeixinWeixinMessageTemplateService { | ||
20 | |||
21 | void createOrUpdate(UpdateUserWeixinWeixinMessageTemplateQueryCriteria criteria); | ||
22 | } |
1 | package com.topdraw.business.module.weixin.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | |||
5 | import java.io.Serializable; | ||
6 | import java.sql.Timestamp; | ||
7 | |||
8 | |||
9 | /** | ||
10 | * @author pengmengqing | ||
11 | * @date 2021-01-28 | ||
12 | */ | ||
13 | @Data | ||
14 | public class UserWeixinWeixinMessageTemplateDTO implements Serializable { | ||
15 | |||
16 | // ID | ||
17 | private Long id; | ||
18 | |||
19 | // 用户id | ||
20 | private Long userWeixinId; | ||
21 | |||
22 | // 微信消息模板id | ||
23 | private Long weixinMessageTemplateId; | ||
24 | |||
25 | // 用户是否订阅: 0-否, 1-是 | ||
26 | private Integer status; | ||
27 | |||
28 | // 创建时间 | ||
29 | private Timestamp createTime; | ||
30 | |||
31 | // 更新时间 | ||
32 | private Timestamp updateTime; | ||
33 | } |
1 | package com.topdraw.business.module.weixin.service.dto; | ||
2 | |||
3 | import com.topdraw.annotation.Query; | ||
4 | import lombok.Data; | ||
5 | |||
6 | /** | ||
7 | * @author pengmengqing | ||
8 | * @date 2021-01-28 | ||
9 | */ | ||
10 | @Data | ||
11 | public class UserWeixinWeixinMessageTemplateQueryCriteria { | ||
12 | // 用户id | ||
13 | @Query(propName = "userWeixinId") | ||
14 | private Long memberId; | ||
15 | |||
16 | // 微信消息模板id | ||
17 | @Query | ||
18 | private Long weixinMessageTemplateId; | ||
19 | |||
20 | // 用户是否订阅: 0-否, 1-是 | ||
21 | @Query | ||
22 | private Integer status = 1; | ||
23 | |||
24 | private String templateId; | ||
25 | } |
1 | package com.topdraw.business.module.weixin.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | |||
5 | import java.io.Serializable; | ||
6 | |||
7 | |||
8 | /** | ||
9 | * @author pengmengqing | ||
10 | * @date 2021-01-28 | ||
11 | */ | ||
12 | @Data | ||
13 | public class WeixinMessageTemplateDTO implements Serializable { | ||
14 | |||
15 | // ID | ||
16 | private Long id; | ||
17 | |||
18 | // 标识 order-下单成功通知,cancellation-核销成功通知 | ||
19 | private String code; | ||
20 | |||
21 | // 微信模板id | ||
22 | private String templateId; | ||
23 | |||
24 | // 描述 | ||
25 | private String description; | ||
26 | } |
1 | package com.topdraw.business.module.weixin.service.dto; | ||
2 | |||
3 | import com.topdraw.annotation.Query; | ||
4 | import lombok.Data; | ||
5 | |||
6 | import java.util.List; | ||
7 | |||
8 | /** | ||
9 | * @author pengmengqing | ||
10 | * @date 2021-01-28 | ||
11 | */ | ||
12 | @Data | ||
13 | public class WeixinMessageTemplateQueryCriteria{ | ||
14 | |||
15 | private String codes; | ||
16 | |||
17 | @Query(propName = "code", type = Query.Type.IN) | ||
18 | private List<String> codeList; | ||
19 | |||
20 | @Query | ||
21 | private String appid; | ||
22 | |||
23 | @Query | ||
24 | private Integer status = 1; | ||
25 | } |
1 | package com.topdraw.business.module.weixin.service.impl; | ||
2 | |||
3 | |||
4 | import com.topdraw.business.module.weixin.domain.UserWeixinWeixinMessageTemplate; | ||
5 | import com.topdraw.business.module.weixin.domain.WeixinMessageTemplate; | ||
6 | import com.topdraw.business.module.weixin.repository.UserWeixinWeixinMessageTemplateRepository; | ||
7 | import com.topdraw.business.module.weixin.repository.WeixinMessageTemplateRepository; | ||
8 | import com.topdraw.business.module.weixin.service.UserWeixinWeixinMessageTemplateService; | ||
9 | import com.topdraw.business.module.weixin.service.dto.UpdateUserWeixinWeixinMessageTemplateQueryCriteria; | ||
10 | import com.topdraw.business.module.weixin.service.dto.UserWeixinWeixinMessageTemplateDTO; | ||
11 | import com.topdraw.business.module.weixin.service.dto.UserWeixinWeixinMessageTemplateQueryCriteria; | ||
12 | import com.topdraw.business.module.weixin.service.mapper.UserWeixinWeixinMessageTemplateMapper; | ||
13 | import com.topdraw.utils.FileUtil; | ||
14 | import com.topdraw.utils.PageUtil; | ||
15 | import com.topdraw.utils.QueryHelp; | ||
16 | import com.topdraw.utils.ValidationUtil; | ||
17 | import lombok.extern.slf4j.Slf4j; | ||
18 | import org.springframework.beans.factory.annotation.Autowired; | ||
19 | import org.springframework.dao.EmptyResultDataAccessException; | ||
20 | import org.springframework.data.domain.Page; | ||
21 | import org.springframework.data.domain.Pageable; | ||
22 | import org.springframework.stereotype.Service; | ||
23 | import org.springframework.transaction.annotation.Propagation; | ||
24 | import org.springframework.transaction.annotation.Transactional; | ||
25 | import org.springframework.util.Assert; | ||
26 | |||
27 | import javax.servlet.http.HttpServletResponse; | ||
28 | import java.io.IOException; | ||
29 | import java.util.*; | ||
30 | |||
31 | /** | ||
32 | * @author pengmengqing | ||
33 | * @date 2021-01-28 | ||
34 | */ | ||
35 | @Service | ||
36 | @Slf4j | ||
37 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
38 | public class UserWeixinWeixinMessageTemplateServiceImpl implements UserWeixinWeixinMessageTemplateService { | ||
39 | |||
40 | @Autowired | ||
41 | private UserWeixinWeixinMessageTemplateRepository userWeixinWeixinMessageTemplateRepository; | ||
42 | |||
43 | @Autowired | ||
44 | private WeixinMessageTemplateRepository weixinMessageTemplateRepository; | ||
45 | |||
46 | @Override | ||
47 | @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class) | ||
48 | public void createOrUpdate(UpdateUserWeixinWeixinMessageTemplateQueryCriteria criteria) { | ||
49 | for (UserWeixinWeixinMessageTemplateQueryCriteria queryCriteria : criteria.getTemplateList()) { | ||
50 | queryCriteria.setMemberId(criteria.getMemberId()); | ||
51 | Integer status = queryCriteria.getStatus(); | ||
52 | queryCriteria.setStatus(null); | ||
53 | String templateId = queryCriteria.getTemplateId(); | ||
54 | Optional<WeixinMessageTemplate> templateOptional = weixinMessageTemplateRepository.findFirstByTemplateId(templateId); | ||
55 | if (!templateOptional.isPresent()) { | ||
56 | log.info("template " + templateId + " not exist"); | ||
57 | continue; | ||
58 | } | ||
59 | Long id = templateOptional.get().getId(); | ||
60 | queryCriteria.setWeixinMessageTemplateId(id); | ||
61 | Optional<UserWeixinWeixinMessageTemplate> optional = userWeixinWeixinMessageTemplateRepository.findOne(((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, queryCriteria, criteriaBuilder))); | ||
62 | if (!optional.isPresent()) { | ||
63 | UserWeixinWeixinMessageTemplate userWeixinWeixinMessageTemplate = new UserWeixinWeixinMessageTemplate(); | ||
64 | userWeixinWeixinMessageTemplate.setUserWeixinId(queryCriteria.getMemberId()) | ||
65 | .setWeixinMessageTemplateId(queryCriteria.getWeixinMessageTemplateId()) | ||
66 | .setStatus(status); | ||
67 | userWeixinWeixinMessageTemplateRepository.save(userWeixinWeixinMessageTemplate); | ||
68 | } else { | ||
69 | UserWeixinWeixinMessageTemplate UserWeixinWeixinMessageTemplate = optional.get(); | ||
70 | if (!status.equals(UserWeixinWeixinMessageTemplate.getStatus())) { | ||
71 | UserWeixinWeixinMessageTemplate.setStatus(status); | ||
72 | userWeixinWeixinMessageTemplateRepository.save(UserWeixinWeixinMessageTemplate); | ||
73 | } | ||
74 | } | ||
75 | } | ||
76 | } | ||
77 | } |
1 | package com.topdraw.business.module.weixin.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import com.topdraw.business.module.weixin.domain.UserWeixinWeixinMessageTemplate; | ||
5 | import com.topdraw.business.module.weixin.service.dto.UserWeixinWeixinMessageTemplateDTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author pengmengqing | ||
11 | * @date 2021-01-28 | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface UserWeixinWeixinMessageTemplateMapper extends BaseMapper<UserWeixinWeixinMessageTemplateDTO, UserWeixinWeixinMessageTemplate> { | ||
15 | |||
16 | } |
1 | package com.topdraw.business.process.domian; | 1 | package com.topdraw.business.process.domian; |
2 | 2 | ||
3 | import com.topdraw.business.module.common.validated.CreateGroup; | ||
3 | import lombok.AllArgsConstructor; | 4 | import lombok.AllArgsConstructor; |
4 | import lombok.Data; | 5 | import lombok.Data; |
5 | import lombok.NoArgsConstructor; | 6 | import lombok.NoArgsConstructor; |
... | @@ -15,76 +16,76 @@ public class TempIptvUser { | ... | @@ -15,76 +16,76 @@ public class TempIptvUser { |
15 | 16 | ||
16 | private String unionid; | 17 | private String unionid; |
17 | 18 | ||
18 | // 账户 | 19 | /** 账户 */ |
19 | @Transient | 20 | @Transient |
21 | @NotNull(message = "platformAccount can't be null" , groups = {CreateGroup.class}) | ||
20 | private String platformAccount; | 22 | private String platformAccount; |
21 | 23 | ||
22 | // 分数 | 24 | /** 分数 */ |
23 | @Transient | 25 | @Transient |
24 | private Long points; | 26 | private Long points; |
25 | 27 | ||
26 | 28 | /** ID */ | |
27 | // ID | ||
28 | private Long id; | 29 | private Long id; |
29 | 30 | ||
30 | // 人ID | 31 | /** 人ID */ |
31 | private Long personId; | 32 | private Long personId; |
32 | 33 | ||
33 | // 运营商平台 | 34 | /** 运营商平台 */ |
34 | private String platform; | 35 | private String platform; |
35 | 36 | ||
36 | // 手机号 | 37 | /** 手机号 */ |
37 | private String cellphone; | 38 | private String cellphone; |
38 | 39 | ||
39 | // 用户名 | 40 | /** 用户名 */ |
40 | private String username; | 41 | private String username; |
41 | 42 | ||
42 | // 密码 MD5 | 43 | /** 密码 MD5 */ |
43 | private String password; | 44 | private String password; |
44 | 45 | ||
45 | // 昵称 Base64 | 46 | /** 昵称 Base64 */ |
46 | private String nickname; | 47 | private String nickname; |
47 | 48 | ||
48 | // 头像 | 49 | /** 头像 */ |
49 | private String image; | 50 | private String image; |
50 | 51 | ||
51 | // 登录天数(总天数) | 52 | /** 登录天数(总天数) */ |
52 | private Integer loginDays; | 53 | private Integer loginDays; |
53 | 54 | ||
54 | // 连续登录天数 | 55 | /** 连续登录天数 */ |
55 | private Integer continueDays; | 56 | private Integer continueDays; |
56 | 57 | ||
57 | // 活跃时间 | 58 | /** 活跃时间 */ |
58 | private Timestamp activeTime; | 59 | private Timestamp activeTime; |
59 | 60 | ||
60 | // 分组 分组ID用逗号分隔 | 61 | /** 分组 分组ID用逗号分隔 */ |
61 | private String groups; | 62 | private String groups; |
62 | 63 | ||
63 | // 标签 标签用逗号分隔 | 64 | /** 标签 标签用逗号分隔 */ |
64 | private String tags; | 65 | private String tags; |
65 | 66 | ||
66 | // 登录类型 1-运营商隐式登录 2-手机验证登录 3-微信登录 4-QQ登录 5-微博登录 6-苹果登录 | 67 | /** 登录类型 1-运营商隐式登录 2-手机验证登录 3-微信登录 4-QQ登录 5-微博登录 6-苹果登录 */ |
67 | private Integer loginType; | 68 | private Integer loginType; |
68 | 69 | ||
69 | // 状态 0-下线 1-上线 | 70 | /** 状态 0-下线 1-上线 */ |
70 | private Integer status; | 71 | private Integer status; |
71 | 72 | ||
72 | // 描述 | 73 | /** 描述 */ |
73 | private String description; | 74 | private String description; |
74 | 75 | ||
75 | // 创建者 | 76 | /** 创建者 */ |
76 | private String createBy; | 77 | private String createBy; |
77 | 78 | ||
78 | // 创建时间 | 79 | /** 创建时间 */ |
79 | private Timestamp createTime; | 80 | private Timestamp createTime; |
80 | 81 | ||
81 | // 更新者 | 82 | /** 更新者 */ |
82 | private String updateBy; | 83 | private String updateBy; |
83 | 84 | ||
84 | // 更新时间 | 85 | /** 更新时间 */ |
85 | private Timestamp updateTime; | 86 | private Timestamp updateTime; |
86 | 87 | ||
87 | // 会员id | 88 | /** 会员id */ |
88 | private Long memberId; | 89 | private Long memberId; |
89 | 90 | ||
90 | private String memberCode; | 91 | private String memberCode; | ... | ... |
... | @@ -9,14 +9,11 @@ import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory; | ... | @@ -9,14 +9,11 @@ import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory; |
9 | import com.topdraw.business.module.member.viphistory.service.MemberVipHistoryService; | 9 | import com.topdraw.business.module.member.viphistory.service.MemberVipHistoryService; |
10 | import com.topdraw.business.module.user.weixin.service.UserWeixinService; | 10 | import com.topdraw.business.module.user.weixin.service.UserWeixinService; |
11 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; | 11 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; |
12 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinQueryCriteria; | ||
13 | import com.topdraw.business.process.domian.weixin.BuyVipBean; | 12 | import com.topdraw.business.process.domian.weixin.BuyVipBean; |
14 | import com.topdraw.business.process.domian.weixin.WeiXinUserBean; | ||
15 | import com.topdraw.business.process.service.MemberOperationService; | 13 | import com.topdraw.business.process.service.MemberOperationService; |
16 | import com.topdraw.common.IResultInfo; | 14 | import com.topdraw.common.IResultInfo; |
17 | import com.topdraw.common.ResultInfo; | 15 | import com.topdraw.common.ResultInfo; |
18 | import com.topdraw.exception.BadRequestException; | 16 | import com.topdraw.exception.BadRequestException; |
19 | import com.topdraw.weixin.util.WeChatConstants; | ||
20 | import io.swagger.annotations.Api; | 17 | import io.swagger.annotations.Api; |
21 | import io.swagger.annotations.ApiOperation; | 18 | import io.swagger.annotations.ApiOperation; |
22 | import org.springframework.beans.factory.annotation.Autowired; | 19 | import org.springframework.beans.factory.annotation.Autowired; | ... | ... |
... | @@ -14,7 +14,7 @@ import com.topdraw.business.module.user.weixin.service.UserWeixinService; | ... | @@ -14,7 +14,7 @@ import com.topdraw.business.module.user.weixin.service.UserWeixinService; |
14 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; | 14 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; |
15 | import com.topdraw.business.process.domian.TempCustomPointBean; | 15 | import com.topdraw.business.process.domian.TempCustomPointBean; |
16 | import com.topdraw.business.process.domian.TempPoints; | 16 | import com.topdraw.business.process.domian.TempPoints; |
17 | import com.topdraw.business.process.domian.result.CustomPointsResult; | 17 | import com.topdraw.business.process.service.dto.CustomPointsResult; |
18 | import com.topdraw.business.process.service.PointsOperationService; | 18 | import com.topdraw.business.process.service.PointsOperationService; |
19 | import com.topdraw.common.ResultInfo; | 19 | import com.topdraw.common.ResultInfo; |
20 | import com.topdraw.config.LocalConstants; | 20 | import com.topdraw.config.LocalConstants; | ... | ... |
... | @@ -3,6 +3,7 @@ package com.topdraw.business.process.rest; | ... | @@ -3,6 +3,7 @@ package com.topdraw.business.process.rest; |
3 | import com.topdraw.annotation.AnonymousAccess; | 3 | import com.topdraw.annotation.AnonymousAccess; |
4 | import com.topdraw.business.process.domian.TempIptvUser; | 4 | import com.topdraw.business.process.domian.TempIptvUser; |
5 | import com.topdraw.business.process.service.TaskOperationService; | 5 | import com.topdraw.business.process.service.TaskOperationService; |
6 | import com.topdraw.business.process.service.dto.TaskOperationQueryCriteria; | ||
6 | import com.topdraw.common.ResultInfo; | 7 | import com.topdraw.common.ResultInfo; |
7 | import io.swagger.annotations.Api; | 8 | import io.swagger.annotations.Api; |
8 | import io.swagger.annotations.ApiOperation; | 9 | import io.swagger.annotations.ApiOperation; | ... | ... |
... | @@ -5,16 +5,15 @@ import cn.hutool.core.util.StrUtil; | ... | @@ -5,16 +5,15 @@ import cn.hutool.core.util.StrUtil; |
5 | 5 | ||
6 | import com.alibaba.fastjson.JSONObject; | 6 | import com.alibaba.fastjson.JSONObject; |
7 | import com.topdraw.annotation.AnonymousAccess; | 7 | import com.topdraw.annotation.AnonymousAccess; |
8 | import com.topdraw.business.module.member.profile.domain.MemberProfile; | 8 | import com.topdraw.aop.log.Log; |
9 | import com.topdraw.business.module.common.validated.CreateGroup; | ||
10 | import com.topdraw.business.module.common.validated.UpdateGroup; | ||
9 | import com.topdraw.business.module.member.service.MemberService; | 11 | import com.topdraw.business.module.member.service.MemberService; |
10 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 12 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
11 | import com.topdraw.business.module.user.iptv.domain.UserTv; | 13 | import com.topdraw.business.module.user.iptv.domain.UserTv; |
12 | import com.topdraw.business.module.user.iptv.service.UserTvService; | 14 | import com.topdraw.business.module.user.iptv.service.UserTvService; |
13 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; | 15 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; |
14 | import com.topdraw.business.module.user.weixin.domain.UserWeixin; | ||
15 | import com.topdraw.business.module.user.weixin.service.UserWeixinService; | ||
16 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; | 16 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; |
17 | import com.topdraw.business.process.domian.TempIptvUser; | ||
18 | import com.topdraw.business.process.domian.weixin.BindBean; | 17 | import com.topdraw.business.process.domian.weixin.BindBean; |
19 | import com.topdraw.business.process.domian.weixin.SubscribeBean; | 18 | import com.topdraw.business.process.domian.weixin.SubscribeBean; |
20 | import com.topdraw.business.process.domian.weixin.SubscribeBeanEvent; | 19 | import com.topdraw.business.process.domian.weixin.SubscribeBeanEvent; |
... | @@ -23,18 +22,15 @@ import com.topdraw.business.process.service.UserOperationService; | ... | @@ -23,18 +22,15 @@ import com.topdraw.business.process.service.UserOperationService; |
23 | import com.topdraw.common.ResultInfo; | 22 | import com.topdraw.common.ResultInfo; |
24 | import com.topdraw.config.RedisKeyUtil; | 23 | import com.topdraw.config.RedisKeyUtil; |
25 | import com.topdraw.exception.BadRequestException; | 24 | import com.topdraw.exception.BadRequestException; |
26 | import com.topdraw.exception.EntityNotFoundException; | ||
27 | import com.topdraw.util.Base64Util; | 25 | import com.topdraw.util.Base64Util; |
28 | import com.topdraw.util.JSONUtil; | 26 | import com.topdraw.util.JSONUtil; |
29 | import com.topdraw.utils.RedisUtils; | 27 | import com.topdraw.utils.RedisUtils; |
30 | import com.topdraw.utils.StringUtils; | ||
31 | import com.topdraw.weixin.util.WeChatConstants; | 28 | import com.topdraw.weixin.util.WeChatConstants; |
32 | import com.topdraw.weixin.util.WeixinUtil; | 29 | import com.topdraw.weixin.util.WeixinUtil; |
33 | import io.swagger.annotations.Api; | 30 | import io.swagger.annotations.Api; |
34 | import io.swagger.annotations.ApiOperation; | 31 | import io.swagger.annotations.ApiOperation; |
35 | import lombok.extern.slf4j.Slf4j; | 32 | import lombok.extern.slf4j.Slf4j; |
36 | import org.assertj.core.util.Arrays; | 33 | import org.apache.commons.lang3.StringUtils; |
37 | import org.springframework.beans.BeanUtils; | ||
38 | import org.springframework.beans.factory.annotation.Autowired; | 34 | import org.springframework.beans.factory.annotation.Autowired; |
39 | import org.springframework.util.Assert; | 35 | import org.springframework.util.Assert; |
40 | import org.springframework.validation.annotation.Validated; | 36 | import org.springframework.validation.annotation.Validated; |
... | @@ -42,7 +38,6 @@ import org.springframework.web.bind.annotation.*; | ... | @@ -42,7 +38,6 @@ import org.springframework.web.bind.annotation.*; |
42 | 38 | ||
43 | import java.io.IOException; | 39 | import java.io.IOException; |
44 | import java.net.URLDecoder; | 40 | import java.net.URLDecoder; |
45 | import java.time.LocalDateTime; | ||
46 | import java.util.*; | 41 | import java.util.*; |
47 | 42 | ||
48 | @Api("账户处理") | 43 | @Api("账户处理") |
... | @@ -52,180 +47,83 @@ import java.util.*; | ... | @@ -52,180 +47,83 @@ import java.util.*; |
52 | public class UserOperationController { | 47 | public class UserOperationController { |
53 | 48 | ||
54 | @Autowired | 49 | @Autowired |
55 | private UserOperationService userTvOperationService; | ||
56 | @Autowired | ||
57 | private UserWeixinService userWeixinService; | ||
58 | @Autowired | ||
59 | private UserTvService userTvService; | 50 | private UserTvService userTvService; |
60 | @Autowired | 51 | @Autowired |
61 | private MemberService memberService; | 52 | private MemberService memberService; |
62 | @Autowired | 53 | @Autowired |
63 | private RedisUtils redisUtils; | ||
64 | @Autowired | ||
65 | private UserOperationService userOperationService; | 54 | private UserOperationService userOperationService; |
55 | @Autowired | ||
56 | private UserOperationService userTvOperationService; | ||
57 | |||
58 | @Autowired | ||
59 | private RedisUtils redisUtils; | ||
66 | 60 | ||
67 | private static final String SUBSCRIBE = "subscribe"; | 61 | private static final String SUBSCRIBE = "subscribe"; |
68 | private static final String UNSUBSCRIBE = "unsubscribe"; | 62 | private static final String UNSUBSCRIBE = "unsubscribe"; |
69 | private static final Integer SUBSCRIBE_STATUS = 1; | 63 | private static final Integer SUBSCRIBE_STATUS = 1; |
70 | 64 | ||
65 | @Log("保存大屏账户同时创建会员") | ||
71 | @PostMapping(value = "/createUserAndCreateMember") | 66 | @PostMapping(value = "/createUserAndCreateMember") |
72 | @ApiOperation("新增大屏账户同时创建会员信息") | 67 | @ApiOperation("保存大屏账户同时创建会员信息") |
73 | @AnonymousAccess | ||
74 | public ResultInfo createUserAndCreateMember(@Validated @RequestBody TempIptvUser resources) { | ||
75 | |||
76 | log.info("createUserAndCreateMember ==> input ==> [{}]",resources); | ||
77 | |||
78 | UserTv userTv = new UserTv(); | ||
79 | BeanUtils.copyProperties(resources,userTv); | ||
80 | boolean result = this.userTvOperationService.createMemberByUserTv(userTv); | ||
81 | return ResultInfo.success(result); | ||
82 | } | ||
83 | |||
84 | @PostMapping(value = "/createWeixinUserAndCreateMember") | ||
85 | @ApiOperation("新增小屏账户同时创建会员信息") | ||
86 | @AnonymousAccess | ||
87 | public ResultInfo createWeixinUserAndCreateMember(@Validated @RequestBody UserWeixin resources) { | ||
88 | |||
89 | log.info("createWeixinUserAndCreateMember ==> input ==> [{}]",resources); | ||
90 | |||
91 | String appId = resources.getAppid(); | ||
92 | if (StringUtils.isBlank(appId)) | ||
93 | throw new NullPointerException("appId is null !"); | ||
94 | |||
95 | String openId = resources.getOpenid(); | ||
96 | if (StringUtils.isBlank(openId)) | ||
97 | throw new NullPointerException("openId is null !"); | ||
98 | |||
99 | String unionId = resources.getUnionid(); | ||
100 | if (StringUtils.isBlank(unionId)) | ||
101 | throw new NullPointerException("unionId is null !"); | ||
102 | |||
103 | UserWeixinDTO result = this.userTvOperationService.createWeixinUserAndCreateMember(resources); | ||
104 | |||
105 | return ResultInfo.success(result); | ||
106 | } | ||
107 | |||
108 | @GetMapping(value = "/findBindByPlatformAccount/{platformAccount}") | ||
109 | @AnonymousAccess | 68 | @AnonymousAccess |
110 | public ResultInfo findBindByPlatformAccount(@PathVariable("platformAccount") String platformAccount) { | 69 | public ResultInfo createTvUserAndCreateMember(@Validated(value = {CreateGroup.class}) @RequestBody UserTv resources) { |
111 | log.info("findBindByPlatformAccount ==> input ==> [{}]",platformAccount); | 70 | log.info("UserOperationController ==> createUserAndCreateMember ==>> param ==> [{}]",resources); |
112 | 71 | ||
113 | List<MemberDTO> result = this.userTvOperationService.findBindByPlatformAccount(platformAccount); | 72 | boolean result = this.userTvOperationService.createTvUserAndCreateMember(resources); |
114 | return ResultInfo.success(result); | ||
115 | } | ||
116 | |||
117 | @PostMapping(value = "/sendQrCodeMessage") | ||
118 | @ApiOperation("带参二维码") | ||
119 | @AnonymousAccess | ||
120 | public ResultInfo sendQrCodeMessage(@RequestBody String content) { | ||
121 | log.info("sendQrCodeMessage ==> input ==> [{}]",content); | ||
122 | boolean result = this.userTvOperationService.sendQrCodeMessage(content); | ||
123 | return ResultInfo.success(result); | ||
124 | } | ||
125 | |||
126 | @PostMapping(value = "/deleteAllCollection") | ||
127 | @ApiOperation("删除全部收藏") | ||
128 | @AnonymousAccess | ||
129 | public ResultInfo deleteAllCollection(@RequestBody String content) { | ||
130 | log.info("deleteAllCollection ==> input ==> [{}]",content); | ||
131 | boolean result = this.userTvOperationService.deleteAllCollection(content); | ||
132 | return ResultInfo.success(result); | ||
133 | } | ||
134 | |||
135 | @PostMapping(value = "/deleteCollection") | ||
136 | @ApiOperation("删除收藏") | ||
137 | @AnonymousAccess | ||
138 | public ResultInfo deleteCollection(@RequestBody String content) { | ||
139 | log.info("deleteCollection ==> input ==> [{}]",content); | ||
140 | boolean result = this.userTvOperationService.deleteCollection(content); | ||
141 | return ResultInfo.success(result); | ||
142 | } | ||
143 | |||
144 | @PostMapping(value = "/addCollection") | ||
145 | @ApiOperation("添加收藏") | ||
146 | @AnonymousAccess | ||
147 | public ResultInfo addCollection(@RequestBody String content) { | ||
148 | log.info("addCollection ==> input ==> [{}]",content); | ||
149 | boolean result = this.userTvOperationService.addCollection(content); | ||
150 | return ResultInfo.success(result); | 73 | return ResultInfo.success(result); |
151 | } | 74 | } |
152 | 75 | ||
76 | @Log("大屏用户解绑") | ||
153 | @RequestMapping(value = "/unbind") | 77 | @RequestMapping(value = "/unbind") |
154 | @ApiOperation("大屏用户解绑") | 78 | @ApiOperation("大屏用户解绑") |
155 | @AnonymousAccess | 79 | @AnonymousAccess |
156 | public ResultInfo unbind(@Validated @RequestBody TempIptvUser resources) { | 80 | public ResultInfo unbind(@Validated(value = {UpdateGroup.class}) @RequestBody UserTv resources) { |
157 | 81 | log.info("UserOperationController ==> unbind ==>> param ==> [{}]",resources); | |
158 | log.info("unbind ==> input ==> [{}]",resources); | ||
159 | |||
160 | UserTv userTv = new UserTv(); | ||
161 | BeanUtils.copyProperties(resources,userTv); | ||
162 | String unionid = resources.getUnionid(); | ||
163 | String memberCode1 = resources.getMemberCode(); | ||
164 | if (Objects.nonNull(memberCode1)) { | ||
165 | |||
166 | MemberDTO memberDTO = this.memberService.findByCode(memberCode1); | ||
167 | String memberCode = memberDTO.getCode(); | ||
168 | if (StringUtils.isNotBlank(memberCode)) { | ||
169 | userTv.setMemberCode(memberCode); | ||
170 | this.userTvOperationService.unbind(userTv); | ||
171 | } | ||
172 | |||
173 | } | ||
174 | 82 | ||
83 | this.userTvOperationService.unbind(resources); | ||
175 | return ResultInfo.success(); | 84 | return ResultInfo.success(); |
176 | } | 85 | } |
177 | 86 | ||
87 | @Log("大屏更换主账号") | ||
178 | @RequestMapping(value = "/changeMainAccount") | 88 | @RequestMapping(value = "/changeMainAccount") |
179 | @ApiOperation("大屏更换主账号") | 89 | @ApiOperation("大屏更换主账号") |
180 | @AnonymousAccess | 90 | @AnonymousAccess |
181 | public ResultInfo changeMainAccount(@Validated @RequestBody TempIptvUser resources) { | 91 | public ResultInfo changeMainAccount(@Validated @RequestBody UserTv resources) { |
182 | 92 | log.info("UserOperationController ==> changeMainAccount ==>> param ==> [{}]",resources); | |
183 | log.info("changeMainAccount ==> input ==> [{}]",resources); | ||
184 | 93 | ||
185 | UserTv userTv = new UserTv(); | 94 | this.userTvOperationService.changeMainAccount(resources); |
186 | BeanUtils.copyProperties(resources,userTv); | 95 | return ResultInfo.success(); |
187 | Long memberId = resources.getMemberId(); | ||
188 | String memberCode1 = resources.getMemberCode(); | ||
189 | if (Objects.nonNull(memberCode1)) { | ||
190 | |||
191 | MemberDTO memberDTO = this.memberService.findByCode(memberCode1); | ||
192 | |||
193 | String memberCode = memberDTO.getCode(); | ||
194 | if (StringUtils.isNotBlank(memberCode)) { | ||
195 | userTv.setMemberCode(memberCode); | ||
196 | this.userTvOperationService.changeMainAccount(userTv); | ||
197 | } | ||
198 | |||
199 | } else { | ||
200 | String unionid = resources.getUnionid(); | ||
201 | this.userTvOperationService.changeMainAccountByUnionId(userTv,unionid); | ||
202 | } | ||
203 | |||
204 | return ResultInfo.success("update success"); | ||
205 | } | 96 | } |
206 | 97 | ||
98 | @Log("微信服务号(H5)登录") | ||
207 | @PostMapping("/serviceLogin") | 99 | @PostMapping("/serviceLogin") |
208 | @ApiOperation("微信服务号(H5)登录") | 100 | @ApiOperation("微信服务号(H5)登录") |
209 | @AnonymousAccess | 101 | @AnonymousAccess |
210 | public ResultInfo serviceLogin(@Validated @RequestBody WeiXinUserBean resources) { | 102 | public ResultInfo serviceLogin(@Validated @RequestBody WeiXinUserBean resources) { |
103 | log.info("UserOperationController ==> serviceLogin ==>> param ==> [{}]",resources); | ||
104 | |||
211 | Object o = this.userTvOperationService.serviceLogin(resources); | 105 | Object o = this.userTvOperationService.serviceLogin(resources); |
212 | return ResultInfo.success(o); | 106 | return ResultInfo.success(o); |
213 | } | 107 | } |
214 | 108 | ||
109 | @Log("微信小程序登录") | ||
215 | @PostMapping("/appletLogin") | 110 | @PostMapping("/appletLogin") |
216 | @ApiOperation("微信小程序登录") | 111 | @ApiOperation("微信小程序登录") |
217 | @AnonymousAccess | 112 | @AnonymousAccess |
218 | public ResultInfo appletLogin(@Validated @RequestBody WeiXinUserBean resources) { | 113 | public ResultInfo appletLogin(@Validated @RequestBody WeiXinUserBean resources) { |
219 | log.info("appletLogin ==> input ==> [{}]",resources); | 114 | log.info("UserOperationController ==> appletLogin ==>> param ==> [{}]",resources); |
115 | |||
220 | UserWeixinDTO result = this.userTvOperationService.appletLogin(resources); | 116 | UserWeixinDTO result = this.userTvOperationService.appletLogin(resources); |
221 | return ResultInfo.success(result); | 117 | return ResultInfo.success(result); |
222 | } | 118 | } |
223 | 119 | ||
120 | @Log("微信小程序绑定大屏") | ||
224 | @PostMapping("/appletBind") | 121 | @PostMapping("/appletBind") |
225 | @ApiOperation("微信小程序绑定大屏") | 122 | @ApiOperation("微信小程序绑定大屏") |
226 | @AnonymousAccess | 123 | @AnonymousAccess |
227 | public ResultInfo appletBind(@Validated @RequestBody BindBean resources) { | 124 | public ResultInfo appletBind(@Validated @RequestBody BindBean resources) { |
228 | log.info("appletBind ==> input ==> [{}]",resources); | 125 | log.info("UserOperationController ==> appletBind ==>> param ==> [{}]",resources); |
126 | |||
229 | String unionId = resources.getUnionid(); | 127 | String unionId = resources.getUnionid(); |
230 | if (StringUtils.isBlank(unionId)) | 128 | if (StringUtils.isBlank(unionId)) |
231 | Assert.state(StrUtil.isNotBlank(unionId), "跨屏绑定,请先进行授权"); | 129 | Assert.state(StrUtil.isNotBlank(unionId), "跨屏绑定,请先进行授权"); |
... | @@ -242,14 +140,14 @@ public class UserOperationController { | ... | @@ -242,14 +140,14 @@ public class UserOperationController { |
242 | return ResultInfo.success(result); | 140 | return ResultInfo.success(result); |
243 | } | 141 | } |
244 | 142 | ||
143 | @Log("微信公众号关注") | ||
245 | @PostMapping("/subscribe") | 144 | @PostMapping("/subscribe") |
246 | @ApiOperation("微信公众号关注") | 145 | @ApiOperation("微信公众号关注") |
247 | @AnonymousAccess | 146 | @AnonymousAccess |
248 | public ResultInfo subscribe(@Validated @RequestBody SubscribeBeanEvent data) throws IOException { | 147 | public ResultInfo subscribe(@Validated @RequestBody SubscribeBeanEvent data) throws IOException { |
249 | String content = data.getContent(); | 148 | log.info("UserOperationController ==> subscribe ==>> param ==> [{}]",data); |
250 | log.info("subscribe ==> input ==> [{}]",content); | ||
251 | 149 | ||
252 | SubscribeBean subscribeBean = JSONUtil.parseMsg2Object(content, SubscribeBean.class); | 150 | SubscribeBean subscribeBean = JSONUtil.parseMsg2Object(data.getContent(), SubscribeBean.class); |
253 | this.parseSubscribe(subscribeBean); | 151 | this.parseSubscribe(subscribeBean); |
254 | boolean result = this.userTvOperationService.subscribe(subscribeBean); | 152 | boolean result = this.userTvOperationService.subscribe(subscribeBean); |
255 | return ResultInfo.success(result); | 153 | return ResultInfo.success(result); |
... | @@ -334,45 +232,26 @@ public class UserOperationController { | ... | @@ -334,45 +232,26 @@ public class UserOperationController { |
334 | } | 232 | } |
335 | } | 233 | } |
336 | 234 | ||
235 | @Log("微信公众号取关") | ||
337 | @PostMapping("/unsubscribe") | 236 | @PostMapping("/unsubscribe") |
338 | @ApiOperation("微信公众号取关") | 237 | @ApiOperation("微信公众号取关") |
339 | @AnonymousAccess | 238 | @AnonymousAccess |
340 | public ResultInfo unsubscribe(@Validated @RequestBody SubscribeBeanEvent data) { | 239 | public ResultInfo unsubscribe(@Validated @RequestBody SubscribeBeanEvent data) { |
341 | String content = data.getContent(); | 240 | log.info("UserOperationController ==> unsubscribe ==>> param ==> [{}]",data); |
342 | log.info("unsubscribe ==> input ==> [{}]",content); | ||
343 | 241 | ||
344 | SubscribeBean subscribeBean = JSONUtil.parseMsg2Object(content, SubscribeBean.class); | 242 | SubscribeBean subscribeBean = JSONUtil.parseMsg2Object(data.getContent(), SubscribeBean.class); |
345 | boolean result = this.userTvOperationService.unsubscribe(subscribeBean); | 243 | boolean result = this.userTvOperationService.unsubscribe(subscribeBean); |
346 | return ResultInfo.success(result); | 244 | return ResultInfo.success(result); |
347 | } | 245 | } |
348 | 246 | ||
349 | /** | 247 | @Log("暂存大小屏信息并检查关注与绑定状态") |
350 | * @param data | ||
351 | * @description 通过大屏关注的订阅号,因为订阅号不支持带参二维码, | ||
352 | * 所以需要先跳到H5(带大屏参数), | ||
353 | * 再做服务号授权(订阅号只能按钮触发获取信息), | ||
354 | * 再将服务号信息和大屏参数缓存下来(该接口的功能) | ||
355 | * 然后跳转到订阅号关注页 | ||
356 | * 关注后回调处理时,根据unionid进行相关逻辑 | ||
357 | * | ||
358 | * 业务场景: | ||
359 | * 1.未关注-绑定 | ||
360 | * 新用户 | ||
361 | * 2.先关注-绑定 | ||
362 | * 1).未绑定 | ||
363 | * 2).已绑定 | ||
364 | * 2.1).已绑定当前大屏账户 | ||
365 | * 2.2).换绑 | ||
366 | * 2.2.1). | ||
367 | * @author Hongyan Wang | ||
368 | * @date 2021/8/24 4:54 下午 | ||
369 | */ | ||
370 | @PostMapping(value = "/saveUserInfo") | 248 | @PostMapping(value = "/saveUserInfo") |
371 | @ApiOperation("保存大屏侧信息") | 249 | @ApiOperation("暂存大小屏信息并检查关注与绑定状态") |
372 | @AnonymousAccess | 250 | @AnonymousAccess |
373 | public ResultInfo saveUserInfo(@RequestBody String data) { | 251 | public ResultInfo saveUserInfo(@RequestBody String data) { |
374 | 252 | ||
375 | log.info("saveUserInfo ==> input ==> [{}]",data); | 253 | log.info("UserOperationController ==> saveUserInfo ==>> param ==> [{}]",data); |
254 | |||
376 | Assert.notNull(data, "用户数据不可为空"); | 255 | Assert.notNull(data, "用户数据不可为空"); |
377 | 256 | ||
378 | JSONObject json = JSONObject.parseObject(data); | 257 | JSONObject json = JSONObject.parseObject(data); |
... | @@ -445,20 +324,39 @@ public class UserOperationController { | ... | @@ -445,20 +324,39 @@ public class UserOperationController { |
445 | return success; | 324 | return success; |
446 | } | 325 | } |
447 | 326 | ||
448 | /** | 327 | |
449 | * | 328 | @Log("删除全部收藏") |
450 | * @param resources | 329 | @PostMapping(value = "/deleteAllCollection") |
451 | * @return | 330 | @ApiOperation("删除全部收藏") |
452 | */ | 331 | @AnonymousAccess |
453 | @PostMapping(value = "/saveUserWeixinPhone") | 332 | public ResultInfo deleteAllCollection(@RequestBody String content) { |
454 | @ApiOperation("保存用户手机号信息") | 333 | log.info("UserOperationController ==> deleteAllCollection ==> param ==> [{}]",content); |
334 | |||
335 | boolean result = this.userTvOperationService.deleteAllCollection(content); | ||
336 | return ResultInfo.success(result); | ||
337 | } | ||
338 | |||
339 | @Log("删除收藏") | ||
340 | @PostMapping(value = "/deleteCollection") | ||
341 | @ApiOperation("删除收藏") | ||
455 | @AnonymousAccess | 342 | @AnonymousAccess |
456 | public ResultInfo saveUserWeixinPhone(@RequestBody WeiXinUserBean resources) { | 343 | public ResultInfo deleteCollection(@RequestBody String content) { |
457 | log.info("saveUserWeixinPhone ==> input ==> [{}]",resources); | 344 | log.info("UserOperationController ==> deleteCollection ==> param ==> [{}]",content); |
458 | MemberProfile s = this.userTvOperationService.saveUserWeixinPhone(resources); | 345 | |
459 | return ResultInfo.success(s); | 346 | boolean result = this.userTvOperationService.deleteCollection(content); |
347 | return ResultInfo.success(result); | ||
460 | } | 348 | } |
461 | 349 | ||
350 | @Log("添加收藏") | ||
351 | @PostMapping(value = "/addCollection") | ||
352 | @ApiOperation("添加收藏") | ||
353 | @AnonymousAccess | ||
354 | public ResultInfo addCollection(@RequestBody String content) { | ||
355 | log.info("UserOperationController ==> addCollection ==>> param ==> [{}]",content); | ||
356 | |||
357 | boolean result = this.userTvOperationService.addCollection(content); | ||
358 | return ResultInfo.success(result); | ||
359 | } | ||
462 | 360 | ||
463 | } | 361 | } |
464 | 362 | ... | ... |
... | @@ -3,9 +3,7 @@ package com.topdraw.business.process.service; | ... | @@ -3,9 +3,7 @@ package com.topdraw.business.process.service; |
3 | import com.topdraw.business.module.member.domain.Member; | 3 | import com.topdraw.business.module.member.domain.Member; |
4 | import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO; | 4 | import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO; |
5 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 5 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
6 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinQueryCriteria; | ||
7 | import com.topdraw.business.process.domian.weixin.BuyVipBean; | 6 | import com.topdraw.business.process.domian.weixin.BuyVipBean; |
8 | import com.topdraw.business.process.domian.weixin.WeiXinUserBean; | ||
9 | 7 | ||
10 | public interface MemberOperationService { | 8 | public interface MemberOperationService { |
11 | 9 | ... | ... |
1 | package com.topdraw.business.process.service; | 1 | package com.topdraw.business.process.service; |
2 | 2 | ||
3 | import com.topdraw.business.process.domian.TempPoints; | 3 | import com.topdraw.business.process.domian.TempPoints; |
4 | import com.topdraw.business.process.domian.result.CustomPointsResult; | 4 | import com.topdraw.business.process.service.dto.CustomPointsResult; |
5 | 5 | ||
6 | import java.util.List; | 6 | import java.util.List; |
7 | 7 | ... | ... |
1 | package com.topdraw.business.process.service; | 1 | package com.topdraw.business.process.service; |
2 | 2 | ||
3 | import com.topdraw.business.module.rights.history.domain.RightsHistory; | 3 | import com.topdraw.business.module.rights.history.domain.RightsHistory; |
4 | import com.topdraw.business.process.domian.RightType; | 4 | import com.topdraw.business.process.domian.constant.RightType; |
5 | 5 | ||
6 | import java.util.List; | 6 | import java.util.List; |
7 | import java.util.Map; | 7 | import java.util.Map; | ... | ... |
1 | package com.topdraw.business.process.service; | 1 | package com.topdraw.business.process.service; |
2 | 2 | ||
3 | import com.alibaba.fastjson.JSONObject; | ||
4 | import com.topdraw.business.module.member.profile.domain.MemberProfile; | ||
5 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 3 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
6 | import com.topdraw.business.module.user.iptv.domain.UserTv; | 4 | import com.topdraw.business.module.user.iptv.domain.UserTv; |
7 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; | 5 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; |
8 | import com.topdraw.business.module.user.weixin.domain.UserWeixin; | 6 | import com.topdraw.business.module.user.weixin.domain.UserWeixin; |
9 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; | 7 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; |
10 | import com.topdraw.business.process.domian.weixin.BindBean; | 8 | import com.topdraw.business.process.domian.weixin.BindBean; |
11 | import com.topdraw.business.process.domian.weixin.BuyVipBean; | ||
12 | import com.topdraw.business.process.domian.weixin.SubscribeBean; | 9 | import com.topdraw.business.process.domian.weixin.SubscribeBean; |
13 | import com.topdraw.business.process.domian.weixin.WeiXinUserBean; | 10 | import com.topdraw.business.process.domian.weixin.WeiXinUserBean; |
14 | 11 | ||
15 | import java.util.List; | ||
16 | import java.util.Map; | ||
17 | 12 | ||
18 | public interface UserOperationService { | 13 | public interface UserOperationService { |
19 | 14 | ||
... | @@ -22,20 +17,20 @@ public interface UserOperationService { | ... | @@ -22,20 +17,20 @@ public interface UserOperationService { |
22 | * @param resources | 17 | * @param resources |
23 | * @return | 18 | * @return |
24 | */ | 19 | */ |
25 | boolean createMemberByUserTv(UserTv resources); | 20 | boolean createTvUserAndCreateMember(UserTv resources); |
26 | 21 | ||
27 | /** | 22 | /** |
28 | * 大屏解绑 | 23 | * 保存小屏账户并创建会员 |
29 | * @param userTv | 24 | * @param resources |
25 | * @return | ||
30 | */ | 26 | */ |
31 | void unbind(UserTv userTv); | 27 | UserWeixinDTO createWeixinUserAndCreateMember(UserWeixin resources); |
32 | 28 | ||
33 | /** | 29 | /** |
34 | * | 30 | * 大屏解绑 |
35 | * @param userTv | 31 | * @param userTv |
36 | * @param unionId | ||
37 | */ | 32 | */ |
38 | void unbindByUnionId(UserTv userTv,String unionId); | 33 | void unbind(UserTv userTv); |
39 | 34 | ||
40 | /** | 35 | /** |
41 | * 大屏切换主账户(会员) | 36 | * 大屏切换主账户(会员) |
... | @@ -44,13 +39,6 @@ public interface UserOperationService { | ... | @@ -44,13 +39,6 @@ public interface UserOperationService { |
44 | void changeMainAccount(UserTv userTv); | 39 | void changeMainAccount(UserTv userTv); |
45 | 40 | ||
46 | /** | 41 | /** |
47 | * | ||
48 | * @param userTv | ||
49 | * @param unionId | ||
50 | */ | ||
51 | void changeMainAccountByUnionId(UserTv userTv,String unionId); | ||
52 | |||
53 | /** | ||
54 | * 微信小程序登录 | 42 | * 微信小程序登录 |
55 | * @param resources | 43 | * @param resources |
56 | * @return | 44 | * @return |
... | @@ -82,20 +70,6 @@ public interface UserOperationService { | ... | @@ -82,20 +70,6 @@ public interface UserOperationService { |
82 | UserWeixinDTO saveUserInfo(String data); | 70 | UserWeixinDTO saveUserInfo(String data); |
83 | 71 | ||
84 | /** | 72 | /** |
85 | * 获取用户授权并解析、保存用户手机号 | ||
86 | * @param resources | ||
87 | * @return | ||
88 | */ | ||
89 | MemberProfile saveUserWeixinPhone(WeiXinUserBean resources); | ||
90 | |||
91 | /** | ||
92 | * | ||
93 | * @param content | ||
94 | * @return | ||
95 | */ | ||
96 | boolean sendQrCodeMessage(String content); | ||
97 | |||
98 | /** | ||
99 | * 大屏删除所有收藏 | 73 | * 大屏删除所有收藏 |
100 | * @param content | 74 | * @param content |
101 | * @return | 75 | * @return |
... | @@ -117,13 +91,6 @@ public interface UserOperationService { | ... | @@ -117,13 +91,6 @@ public interface UserOperationService { |
117 | boolean addCollection(String content); | 91 | boolean addCollection(String content); |
118 | 92 | ||
119 | /** | 93 | /** |
120 | * 获取大屏绑定的小屏会员列表 | ||
121 | * @param platformAccount | ||
122 | * @return | ||
123 | */ | ||
124 | List<MemberDTO> findBindByPlatformAccount(String platformAccount); | ||
125 | |||
126 | /** | ||
127 | * 服务号(H5)登录 | 94 | * 服务号(H5)登录 |
128 | * @param resources | 95 | * @param resources |
129 | * @return | 96 | * @return |
... | @@ -138,14 +105,27 @@ public interface UserOperationService { | ... | @@ -138,14 +105,27 @@ public interface UserOperationService { |
138 | boolean appletBind(BindBean resources); | 105 | boolean appletBind(BindBean resources); |
139 | 106 | ||
140 | 107 | ||
141 | JSONObject getUnionIdByAppIdAndOpenId(String appId,String secret,String code); | ||
142 | |||
143 | UserWeixinDTO createWeixinUserAndCreateMember(UserWeixin resources); | ||
144 | 108 | ||
109 | /** | ||
110 | * | ||
111 | * @param memberCode | ||
112 | * @param platformAccount | ||
113 | */ | ||
145 | void bind(String memberCode, String platformAccount); | 114 | void bind(String memberCode, String platformAccount); |
146 | 115 | ||
116 | /** | ||
117 | * | ||
118 | * @param memberDTO | ||
119 | * @param userTvDTO | ||
120 | */ | ||
147 | void bind(MemberDTO memberDTO, UserTvDTO userTvDTO); | 121 | void bind(MemberDTO memberDTO, UserTvDTO userTvDTO); |
148 | 122 | ||
123 | /** | ||
124 | * | ||
125 | * @param memberDTO | ||
126 | * @param platformAccount | ||
127 | * @return | ||
128 | */ | ||
149 | UserTvDTO bind(MemberDTO memberDTO, String platformAccount); | 129 | UserTvDTO bind(MemberDTO memberDTO, String platformAccount); |
150 | 130 | ||
151 | } | 131 | } | ... | ... |
1 | package com.topdraw.business.process.rest; | 1 | package com.topdraw.business.process.service.dto; |
2 | 2 | ||
3 | import lombok.Data; | 3 | import lombok.Data; |
4 | 4 | ||
... | @@ -12,7 +12,7 @@ import javax.validation.constraints.NotNull; | ... | @@ -12,7 +12,7 @@ import javax.validation.constraints.NotNull; |
12 | @Data | 12 | @Data |
13 | public class TaskOperationQueryCriteria { | 13 | public class TaskOperationQueryCriteria { |
14 | 14 | ||
15 | @NotNull(message = "【content】 not be null !!!") | 15 | @NotNull(message = "content not be null !!!") |
16 | private String content; | 16 | private String content; |
17 | 17 | ||
18 | } | 18 | } | ... | ... |
... | @@ -4,7 +4,6 @@ import cn.hutool.core.util.ObjectUtil; | ... | @@ -4,7 +4,6 @@ import cn.hutool.core.util.ObjectUtil; |
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.profile.service.MemberProfileService; | 5 | import com.topdraw.business.module.member.profile.service.MemberProfileService; |
6 | import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO; | 6 | import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO; |
7 | import com.topdraw.business.module.member.profile.service.dto.MemberProfileQueryCriteria; | ||
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.module.member.viphistory.domain.MemberVipHistory; | 9 | import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory; |
... | @@ -12,29 +11,18 @@ import com.topdraw.business.module.member.viphistory.service.MemberVipHistorySer | ... | @@ -12,29 +11,18 @@ import com.topdraw.business.module.member.viphistory.service.MemberVipHistorySer |
12 | import com.topdraw.business.module.user.weixin.domain.UserWeixin; | 11 | import com.topdraw.business.module.user.weixin.domain.UserWeixin; |
13 | import com.topdraw.business.module.user.weixin.service.UserWeixinService; | 12 | import com.topdraw.business.module.user.weixin.service.UserWeixinService; |
14 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; | 13 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; |
15 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinQueryCriteria; | ||
16 | import com.topdraw.business.process.domian.weixin.BuyVipBean; | 14 | import com.topdraw.business.process.domian.weixin.BuyVipBean; |
17 | import com.topdraw.business.process.domian.weixin.WeiXinUserBean; | ||
18 | import com.topdraw.business.process.service.MemberOperationService; | 15 | import com.topdraw.business.process.service.MemberOperationService; |
19 | import com.topdraw.exception.EntityNotFoundException; | 16 | import com.topdraw.exception.EntityNotFoundException; |
20 | import com.topdraw.util.LocalDateTimeUtil; | ||
21 | import com.topdraw.util.TimestampUtil; | ||
22 | import com.topdraw.utils.StringUtils; | ||
23 | import com.topdraw.utils.ValidationUtil; | ||
24 | import org.springframework.beans.BeanUtils; | 17 | import org.springframework.beans.BeanUtils; |
25 | import org.springframework.beans.factory.annotation.Autowired; | 18 | import org.springframework.beans.factory.annotation.Autowired; |
26 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | 19 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
27 | import org.springframework.stereotype.Service; | 20 | import org.springframework.stereotype.Service; |
28 | import org.springframework.util.Assert; | 21 | import org.springframework.util.Assert; |
29 | 22 | ||
30 | import java.nio.charset.StandardCharsets; | ||
31 | import java.time.LocalDateTime; | 23 | import java.time.LocalDateTime; |
32 | import java.time.ZoneOffset; | 24 | import java.time.ZoneOffset; |
33 | import java.util.Base64; | ||
34 | import java.util.Objects; | 25 | import java.util.Objects; |
35 | import java.util.Optional; | ||
36 | |||
37 | import static org.bouncycastle.asn1.x500.style.RFC4519Style.member; | ||
38 | 26 | ||
39 | @Service | 27 | @Service |
40 | public class MemberOperationServiceImpl implements MemberOperationService { | 28 | public class MemberOperationServiceImpl implements MemberOperationService { | ... | ... |
... | @@ -12,7 +12,7 @@ import com.topdraw.business.module.points.detail.detailhistory.service.PointsDet | ... | @@ -12,7 +12,7 @@ import com.topdraw.business.module.points.detail.detailhistory.service.PointsDet |
12 | import com.topdraw.business.module.points.detail.domain.PointsDetail; | 12 | import com.topdraw.business.module.points.detail.domain.PointsDetail; |
13 | import com.topdraw.business.module.points.detail.service.PointsDetailService; | 13 | import com.topdraw.business.module.points.detail.service.PointsDetailService; |
14 | import com.topdraw.business.module.points.service.PointsService; | 14 | import com.topdraw.business.module.points.service.PointsService; |
15 | import com.topdraw.business.process.domian.result.CustomPointsResult; | 15 | import com.topdraw.business.process.service.dto.CustomPointsResult; |
16 | import com.topdraw.business.process.service.MemberOperationService; | 16 | import com.topdraw.business.process.service.MemberOperationService; |
17 | import com.topdraw.business.process.service.PointsOperationService; | 17 | import com.topdraw.business.process.service.PointsOperationService; |
18 | import com.topdraw.business.process.domian.TempPoints; | 18 | import com.topdraw.business.process.domian.TempPoints; |
... | @@ -33,7 +33,6 @@ import org.springframework.transaction.annotation.Propagation; | ... | @@ -33,7 +33,6 @@ import org.springframework.transaction.annotation.Propagation; |
33 | import org.springframework.transaction.annotation.Transactional; | 33 | import org.springframework.transaction.annotation.Transactional; |
34 | import org.springframework.util.CollectionUtils; | 34 | import org.springframework.util.CollectionUtils; |
35 | 35 | ||
36 | import java.sql.Timestamp; | ||
37 | import java.time.LocalDateTime; | 36 | import java.time.LocalDateTime; |
38 | import java.util.*; | 37 | import java.util.*; |
39 | import java.util.stream.Collectors; | 38 | import java.util.stream.Collectors; | ... | ... |
... | @@ -6,6 +6,7 @@ import com.topdraw.business.module.rights.history.domain.RightsHistory; | ... | @@ -6,6 +6,7 @@ import com.topdraw.business.module.rights.history.domain.RightsHistory; |
6 | import com.topdraw.business.module.rights.history.service.RightsHistoryService; | 6 | import com.topdraw.business.module.rights.history.service.RightsHistoryService; |
7 | import com.topdraw.business.module.rights.service.RightsService; | 7 | import com.topdraw.business.module.rights.service.RightsService; |
8 | import com.topdraw.business.module.rights.service.dto.RightsDTO; | 8 | import com.topdraw.business.module.rights.service.dto.RightsDTO; |
9 | import com.topdraw.business.process.domian.constant.RightType; | ||
9 | import com.topdraw.business.process.service.CouponOperationService; | 10 | import com.topdraw.business.process.service.CouponOperationService; |
10 | import com.topdraw.business.process.service.ExpOperationService; | 11 | import com.topdraw.business.process.service.ExpOperationService; |
11 | import com.topdraw.business.process.service.PointsOperationService; | 12 | import com.topdraw.business.process.service.PointsOperationService; | ... | ... |
... | @@ -6,7 +6,6 @@ import com.topdraw.business.module.coupon.service.CouponService; | ... | @@ -6,7 +6,6 @@ import com.topdraw.business.module.coupon.service.CouponService; |
6 | import com.topdraw.business.module.coupon.service.dto.CouponDTO; | 6 | import com.topdraw.business.module.coupon.service.dto.CouponDTO; |
7 | import com.topdraw.business.module.member.group.service.MemberGroupService; | 7 | import com.topdraw.business.module.member.group.service.MemberGroupService; |
8 | import com.topdraw.business.module.member.group.service.dto.MemberGroupDTO; | 8 | import com.topdraw.business.module.member.group.service.dto.MemberGroupDTO; |
9 | import com.topdraw.business.module.member.group.service.dto.MemberGroupQueryCriteria; | ||
10 | import com.topdraw.business.module.rights.permanentrights.service.PermanentRightsService; | 9 | import com.topdraw.business.module.rights.permanentrights.service.PermanentRightsService; |
11 | import com.topdraw.business.module.rights.permanentrights.service.dto.PermanentRightsDTO; | 10 | import com.topdraw.business.module.rights.permanentrights.service.dto.PermanentRightsDTO; |
12 | import com.topdraw.business.module.rights.service.RightsService; | 11 | import com.topdraw.business.module.rights.service.RightsService; |
... | @@ -20,7 +19,8 @@ import com.topdraw.business.module.task.progress.service.dto.TrTaskProgressQuery | ... | @@ -20,7 +19,8 @@ import com.topdraw.business.module.task.progress.service.dto.TrTaskProgressQuery |
20 | import com.topdraw.business.module.user.iptv.domain.UserTv; | 19 | import com.topdraw.business.module.user.iptv.domain.UserTv; |
21 | import com.topdraw.business.module.user.iptv.service.UserTvService; | 20 | import com.topdraw.business.module.user.iptv.service.UserTvService; |
22 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; | 21 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; |
23 | import com.topdraw.business.process.domian.result.TaskTemplateType; | 22 | import com.topdraw.business.process.domian.constant.TaskTemplateType; |
23 | import com.topdraw.business.process.domian.constant.RightType; | ||
24 | import com.topdraw.business.process.service.PointsOperationService; | 24 | import com.topdraw.business.process.service.PointsOperationService; |
25 | import com.topdraw.business.process.service.RightsOperationService; | 25 | import com.topdraw.business.process.service.RightsOperationService; |
26 | import com.topdraw.business.process.service.TaskOperationService; | 26 | import com.topdraw.business.process.service.TaskOperationService; |
... | @@ -981,7 +981,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -981,7 +981,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
981 | 981 | ||
982 | long l = System.currentTimeMillis(); | 982 | long l = System.currentTimeMillis(); |
983 | 983 | ||
984 | this.userTvOperationService.createMemberByUserTv(this.checkUserTv(platformAccount)); | 984 | this.userTvOperationService.createTvUserAndCreateMember(this.checkUserTv(platformAccount)); |
985 | 985 | ||
986 | UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); | 986 | UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); |
987 | if (Objects.nonNull(userTvDTO)) { | 987 | if (Objects.nonNull(userTvDTO)) { | ... | ... |
1 | package com.topdraw.business.process.service.impl; | 1 | package com.topdraw.business.process.service.impl; |
2 | 2 | ||
3 | import cn.hutool.core.collection.CollUtil; | ||
4 | import cn.hutool.core.date.DateUtil; | 3 | import cn.hutool.core.date.DateUtil; |
5 | import cn.hutool.core.util.ObjectUtil; | 4 | import cn.hutool.core.util.ObjectUtil; |
6 | import cn.hutool.core.util.StrUtil; | 5 | import cn.hutool.core.util.StrUtil; |
7 | import cn.hutool.http.HttpUtil; | ||
8 | import com.alibaba.fastjson.JSON; | 6 | import com.alibaba.fastjson.JSON; |
9 | import com.alibaba.fastjson.JSONObject; | 7 | import com.alibaba.fastjson.JSONObject; |
10 | import com.topdraw.aspect.AsyncMqSend; | 8 | import com.topdraw.aspect.AsyncMqSend; |
11 | import com.topdraw.business.module.member.domain.Member; | 9 | import com.topdraw.business.module.member.domain.Member; |
12 | import com.topdraw.business.module.member.domain.MemberBuilder; | 10 | import com.topdraw.business.module.member.domain.MemberBuilder; |
13 | import com.topdraw.business.module.member.profile.domain.MemberProfile; | ||
14 | import com.topdraw.business.module.member.profile.domain.MemberProfileBuild; | ||
15 | import com.topdraw.business.module.member.profile.service.MemberProfileService; | ||
16 | import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO; | ||
17 | import com.topdraw.business.module.member.service.MemberService; | 11 | import com.topdraw.business.module.member.service.MemberService; |
18 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 12 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
19 | import com.topdraw.business.module.member.service.dto.MemberQueryCriteria; | ||
20 | import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory; | ||
21 | import com.topdraw.business.module.member.viphistory.service.MemberVipHistoryService; | ||
22 | import com.topdraw.business.module.user.iptv.domain.UserConstant; | 13 | import com.topdraw.business.module.user.iptv.domain.UserConstant; |
23 | import com.topdraw.business.module.user.iptv.domain.UserTv; | 14 | import com.topdraw.business.module.user.iptv.domain.UserTv; |
24 | import com.topdraw.business.module.user.iptv.service.UserTvService; | 15 | import com.topdraw.business.module.user.iptv.service.UserTvService; |
... | @@ -40,35 +31,24 @@ import com.topdraw.config.LocalConstants; | ... | @@ -40,35 +31,24 @@ import com.topdraw.config.LocalConstants; |
40 | import com.topdraw.config.RedisKeyUtil; | 31 | import com.topdraw.config.RedisKeyUtil; |
41 | import com.topdraw.exception.BadRequestException; | 32 | import com.topdraw.exception.BadRequestException; |
42 | import com.topdraw.exception.EntityNotFoundException; | 33 | import com.topdraw.exception.EntityNotFoundException; |
43 | import com.topdraw.security.AESUtil; | 34 | import com.topdraw.exception.GlobeExceptionMsg; |
44 | import com.topdraw.util.IdWorker; | ||
45 | import com.topdraw.util.TimestampUtil; | 35 | import com.topdraw.util.TimestampUtil; |
46 | import com.topdraw.utils.QueryHelp; | 36 | import com.topdraw.utils.QueryHelp; |
47 | import com.topdraw.utils.RedisUtils; | 37 | import com.topdraw.utils.RedisUtils; |
48 | import com.topdraw.utils.StringUtils; | 38 | import com.topdraw.utils.StringUtils; |
49 | import com.topdraw.weixin.beans.*; | ||
50 | import com.topdraw.weixin.beans.config.WeiXinAppListConfig; | ||
51 | import com.topdraw.weixin.util.WeChatConstants; | ||
52 | import com.topdraw.weixin.util.WeiXinRequestUtil; | ||
53 | import com.topdraw.weixin.util.WeixinUtil; | ||
54 | import lombok.extern.slf4j.Slf4j; | 39 | import lombok.extern.slf4j.Slf4j; |
55 | import org.redisson.api.RedissonClient; | ||
56 | import org.springframework.beans.BeanUtils; | 40 | import org.springframework.beans.BeanUtils; |
57 | import org.springframework.beans.factory.annotation.Autowired; | 41 | import org.springframework.beans.factory.annotation.Autowired; |
58 | import org.springframework.beans.factory.annotation.Value; | 42 | import org.springframework.beans.factory.annotation.Value; |
59 | import org.springframework.context.annotation.Bean; | ||
60 | import org.springframework.data.domain.PageRequest; | 43 | import org.springframework.data.domain.PageRequest; |
61 | import org.springframework.data.domain.Sort; | 44 | import org.springframework.data.domain.Sort; |
62 | import org.springframework.stereotype.Service; | 45 | import org.springframework.stereotype.Service; |
63 | import org.springframework.transaction.annotation.Propagation; | 46 | import org.springframework.transaction.annotation.Propagation; |
64 | import org.springframework.transaction.annotation.Transactional; | 47 | import org.springframework.transaction.annotation.Transactional; |
65 | import org.springframework.util.CollectionUtils; | ||
66 | 48 | ||
67 | import java.nio.charset.StandardCharsets; | 49 | import java.nio.charset.StandardCharsets; |
68 | import java.sql.Timestamp; | ||
69 | import java.time.LocalDateTime; | 50 | import java.time.LocalDateTime; |
70 | import java.util.*; | 51 | import java.util.*; |
71 | import java.util.concurrent.TimeUnit; | ||
72 | import java.util.stream.Collectors; | 52 | import java.util.stream.Collectors; |
73 | 53 | ||
74 | @Service | 54 | @Service |
... | @@ -76,7 +56,6 @@ import java.util.stream.Collectors; | ... | @@ -76,7 +56,6 @@ import java.util.stream.Collectors; |
76 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | 56 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) |
77 | public class UserOperationServiceImpl implements UserOperationService { | 57 | public class UserOperationServiceImpl implements UserOperationService { |
78 | 58 | ||
79 | |||
80 | @Autowired | 59 | @Autowired |
81 | private MemberService memberService; | 60 | private MemberService memberService; |
82 | @Autowired | 61 | @Autowired |
... | @@ -84,46 +63,26 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -84,46 +63,26 @@ public class UserOperationServiceImpl implements UserOperationService { |
84 | @Autowired | 63 | @Autowired |
85 | private UserWeixinService userWeixinService; | 64 | private UserWeixinService userWeixinService; |
86 | @Autowired | 65 | @Autowired |
87 | private RedisUtils redisUtils; | 66 | private UserWeixinRepository userWeixinRepository; |
88 | @Autowired | 67 | |
89 | private WeiXinAppListConfig weiXinAppListConfig; | ||
90 | @Autowired | ||
91 | private MemberProfileService memberProfileService; | ||
92 | @Autowired | ||
93 | private WeiXinRequestUtil weixinRequestUtil; | ||
94 | @Autowired | 68 | @Autowired |
95 | private UserCollectionService userCollectionService; | 69 | private UserCollectionService userCollectionService; |
96 | @Autowired | 70 | @Autowired |
97 | private UserCollectionDetailService userCollectionDetailService; | 71 | private UserCollectionDetailService userCollectionDetailService; |
98 | @Autowired | 72 | @Autowired |
99 | private UserCollectionDetailRepository userCollectionDetailRepository; | ||
100 | @Autowired | ||
101 | private CollectionMq2DetailMapper collectionMq2DetailMapper; | 73 | private CollectionMq2DetailMapper collectionMq2DetailMapper; |
102 | @Autowired | 74 | @Autowired |
103 | private UserWeixinRepository userWeixinRepository; | 75 | private UserCollectionDetailRepository userCollectionDetailRepository; |
104 | @Autowired | ||
105 | private MemberVipHistoryService memberVipHistoryService; | ||
106 | 76 | ||
77 | @Autowired | ||
78 | private RedisUtils redisUtils; | ||
107 | 79 | ||
108 | 80 | ||
109 | /** 取消关注 */ | 81 | /** 取消关注 */ |
110 | private static final Integer UNSUBSCRIBE_STATUS = 0; | 82 | private static final Integer UNSUBSCRIBE_STATUS = 0; |
111 | private static final Integer SUBSCRIBE_STATUS = 1; | 83 | private static final Integer SUBSCRIBE_STATUS = 1; |
112 | private static final String SUBSCRIBE = "subscribe"; | ||
113 | private static final String UNSUBSCRIBE = "unsubscribe"; | ||
114 | private static final Integer[] PLATFORM_LIST = new Integer[]{0,1,2,3}; | ||
115 | private static final Integer[] IPTV_MAJOR = new Integer[]{0,1}; | ||
116 | |||
117 | private static final String QR_CODE_URL = "QR_CODE_URL_"; | ||
118 | 84 | ||
119 | @Value("${uc.service.platform:}") | 85 | private static final Integer[] PLATFORM_LIST = new Integer[]{0,1,2,3}; |
120 | private String platform; | ||
121 | |||
122 | @Value("${key:}") | ||
123 | private String key; | ||
124 | |||
125 | @Value("${uc.app.subAppId:wx05f35931270014be}") | ||
126 | private String subAppId; | ||
127 | 86 | ||
128 | @Value("${uc.app.h5AppId:wxca962918dfeed88c}") | 87 | @Value("${uc.app.h5AppId:wxca962918dfeed88c}") |
129 | private String h5AppId; | 88 | private String h5AppId; |
... | @@ -131,174 +90,205 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -131,174 +90,205 @@ public class UserOperationServiceImpl implements UserOperationService { |
131 | @Value("${uc.app.appletAppid:wxc57d42de3d351cec}") | 90 | @Value("${uc.app.appletAppid:wxc57d42de3d351cec}") |
132 | private String appletAppid; | 91 | private String appletAppid; |
133 | 92 | ||
134 | @Value("${file.upload:upload}") | 93 | /** |
135 | private String filePath; | 94 | * 保存大屏账户同时创建会员 |
95 | * | ||
96 | * @param resources 大屏账户 | ||
97 | * @return boolean | ||
98 | */ | ||
99 | @Override | ||
100 | @Transactional | ||
101 | @AsyncMqSend | ||
102 | public boolean createTvUserAndCreateMember(UserTv resources) { | ||
103 | // 大屏账户 | ||
104 | String platformAccount = resources.getPlatformAccount(); | ||
105 | |||
106 | UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); | ||
107 | |||
108 | if (Objects.isNull(userTvDTO)) { | ||
109 | |||
110 | // x_member | ||
111 | Member member = | ||
112 | MemberBuilder.build(LocalConstants.MEMBER_PLATFORM_TYPE_VIS, | ||
113 | null, platformAccount, 0); | ||
136 | 114 | ||
115 | UserTvDTO _userTvDTO = new UserTvDTO(); | ||
116 | BeanUtils.copyProperties(resources, _userTvDTO); | ||
137 | 117 | ||
118 | // 创建大屏账户 | ||
119 | this.createTvUser(_userTvDTO, member); | ||
120 | |||
121 | return true; | ||
122 | } | ||
123 | |||
124 | throw new BadRequestException(GlobeExceptionMsg.ENTITY_ALREADY_EXISTS); | ||
125 | |||
126 | } | ||
138 | 127 | ||
139 | /** | 128 | /** |
140 | * 微信公众号关注 | 129 | * |
141 | * 1.未扫描大屏二维码 | ||
142 | * 1). 保存、修改小屏账户,创建小屏账户会员 | ||
143 | * 2.扫描大屏二维码 | ||
144 | * 1). 从redis中获取大屏信息 | ||
145 | * 2). 大屏账户保存小屏会员的code | ||
146 | * 3). 小屏会员中保存大屏的id | ||
147 | * @description 大小屏绑定,大屏账户保存小屏会员编码 | ||
148 | * @param resources | 130 | * @param resources |
149 | * @return | 131 | * @return |
150 | */ | 132 | */ |
151 | @Override | 133 | @Override |
152 | public boolean subscribe(SubscribeBean resources) { | 134 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) |
135 | @AsyncMqSend | ||
136 | public UserWeixinDTO createWeixinUserAndCreateMember(UserWeixin resources) { | ||
137 | |||
138 | String appId = resources.getAppid(); | ||
139 | String openId = resources.getOpenid(); | ||
153 | String unionId = resources.getUnionid(); | 140 | String unionId = resources.getUnionid(); |
154 | String appId = resources.getAppId(); | ||
155 | String openId = resources.getOpenId(); | ||
156 | String nickname = resources.getNickname(); | ||
157 | String headImgUrl = resources.getHeadimgurl(); | ||
158 | 141 | ||
159 | // 小屏账户 | 142 | // 检查小屏账户是否存在 |
160 | UserWeixinDTO userWeixinDTO = this.findFirstByUnionIdAndAppIdAndOpenId(unionId,appId, openId); | 143 | UserWeixinDTO userWeixinDTO = this.findFirstByUnionIdAndAppIdAndOpenId(unionId,appId, openId); |
144 | if (Objects.nonNull(userWeixinDTO.getId())) | ||
145 | return userWeixinDTO; | ||
161 | 146 | ||
162 | if (Objects.isNull(userWeixinDTO.getId())) { | 147 | // 当前用户的任意微信app,因为同一unionId的会员是唯一的 |
148 | UserWeixinDTO userWeixinDTO1 = this.findFirstByUnionId(unionId); | ||
163 | 149 | ||
164 | DefaultWeiXinBeanDefinition weiXinBeanDefinition = new DefaultWeiXinBeanDefinition(); | 150 | UserWeixinDTO _userWeixinDTO = new UserWeixinDTO(); |
165 | weiXinBeanDefinition.setUnionId(unionId); | 151 | Member member = null; |
166 | weiXinBeanDefinition.setAppid(appId); | ||
167 | weiXinBeanDefinition.setOpenId(openId); | ||
168 | weiXinBeanDefinition.setNickname(nickname); | ||
169 | weiXinBeanDefinition.setHeadImgUrl(headImgUrl); | ||
170 | // 创建会员和账户 | ||
171 | this.doCreateUserWeiXinAndMember(weiXinBeanDefinition); | ||
172 | 152 | ||
173 | } else { | 153 | if (Objects.nonNull(userWeixinDTO1.getId())) { |
174 | 154 | ||
175 | // 修改账户和会员信息 | 155 | Long memberId = userWeixinDTO1.getMemberId(); |
176 | this.doUpdateUserWeiXinAndMember(userWeixinDTO,appId,openId,headImgUrl,nickname); | 156 | resources.setMemberId(memberId); |
157 | BeanUtils.copyProperties(resources,_userWeixinDTO); | ||
158 | |||
159 | } else { | ||
160 | // x_member | ||
161 | member = | ||
162 | MemberBuilder.build(LocalConstants.MEMBER_PLATFORM_TYPE_WEIXIN, | ||
163 | null, "", 0); | ||
177 | 164 | ||
165 | BeanUtils.copyProperties(resources,_userWeixinDTO); | ||
178 | } | 166 | } |
179 | 167 | ||
180 | // 大屏信息 | 168 | this.createWeixinUser(_userWeixinDTO,member); |
181 | JSONObject iptvUserInfo = resources.getIptvUserInfo(); | ||
182 | if (Objects.nonNull(iptvUserInfo)) { | ||
183 | 169 | ||
184 | // 小屏会员 | 170 | return null; |
185 | MemberDTO memberDTO = this.findMemberByAppIdAndOpenId(appId,openId); | 171 | } |
186 | 172 | ||
187 | // 账户 | ||
188 | String platformAccount = iptvUserInfo.getString("platformAccount"); | ||
189 | 173 | ||
190 | this.bind(memberDTO,platformAccount); | 174 | @Override |
175 | public Object serviceLogin(WeiXinUserBean resources) { | ||
176 | String unionId = resources.getUnionid(); | ||
177 | String appId = resources.getAppid(); | ||
178 | String openId = resources.getOpenid(); | ||
191 | 179 | ||
192 | } | 180 | // 小屏账户 |
181 | UserWeixinDTO userWeixinDTO = this.findFirstByUnionIdAndAppIdAndOpenId(unionId,appId, openId); | ||
193 | 182 | ||
194 | // 关注历史记录,用于恢复VIP等级(0:普通 1:团粉 其他:会员(过期后vip恢复到最高等级)) | 183 | if (Objects.isNull(userWeixinDTO.getId())) { |
195 | this.doInsertSubscribeHistory(appId,openId,WeChatConstants.EVENT_SUBSCRIBE); | ||
196 | 184 | ||
197 | return true; | 185 | // member |
186 | Member member = | ||
187 | MemberBuilder.build(LocalConstants.MEMBER_PLATFORM_TYPE_WEIXIN, | ||
188 | resources.getHeadimgurl(), resources.getNikename(), 0); | ||
198 | 189 | ||
199 | } | 190 | userWeixinDTO = new UserWeixinDTO(); |
191 | BeanUtils.copyProperties(resources,userWeixinDTO); | ||
200 | 192 | ||
201 | /** | 193 | UserWeixin weixinUser = this.createWeixinUser(userWeixinDTO, member); |
202 | * | 194 | userWeixinDTO.setId(weixinUser.getId()); |
203 | * @param appId | ||
204 | * @param openId | ||
205 | */ | ||
206 | private void doInsertSubscribeHistory(String appId, String openId,String event) { | ||
207 | // 小屏会员 | ||
208 | MemberDTO member = this.findMemberByAppIdAndOpenId(appId,openId); | ||
209 | 195 | ||
210 | MemberVipHistory memberVipHistory = new MemberVipHistory(); | ||
211 | memberVipHistory.setMemberId(member.getId()).setStatus(1); | ||
212 | //小屏侧,理论上大屏不会收到该事件 | ||
213 | if (WeChatConstants.EVENT_SUBSCRIBE.equals(event)) {//关注 | ||
214 | memberVipHistory.setVip(1); | ||
215 | if (member.getVip() == 0) { | ||
216 | member.setVip(1); | ||
217 | memberVipHistory.setBeforeVip(0); | ||
218 | } | ||
219 | } else if (WeChatConstants.EVENT_UNSUBSCRIBE.equals(event)) {// 取消关注 | ||
220 | memberVipHistory.setVip(0); | ||
221 | if (member.getVip() == 1) { | ||
222 | member.setVip(0); | ||
223 | memberVipHistory.setBeforeVip(1); | ||
224 | } | 196 | } |
225 | } | 197 | |
226 | memberVipHistory.setVipExpireTime(LocalDateTime.now()); | 198 | // 为了保证返回的同一用户 |
227 | memberVipHistoryService.create(memberVipHistory); | 199 | UserWeixinDTO userWeixinDTO_0 = this.getFirstId(userWeixinDTO); |
200 | return userWeixinDTO_0; | ||
228 | } | 201 | } |
229 | 202 | ||
230 | /** | 203 | /** |
231 | * 获取小屏账户 | 204 | * 小程序登录 |
232 | * @param unionId | 205 | * @param resources |
233 | * @param appId | ||
234 | * @param openId | ||
235 | * @return | 206 | * @return |
236 | */ | 207 | */ |
237 | private UserWeixinDTO findFirstByUnionIdAndAppIdAndOpenId( String unionId,String appId, String openId) { | 208 | @Override |
238 | return this.userWeixinService.findFirstByUnionIdAndAppIdAndOpenId(unionId,appId,openId); | 209 | @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = Exception.class) |
239 | } | 210 | public UserWeixinDTO appletLogin(WeiXinUserBean resources) { |
211 | String unionId = resources.getUnionid(); | ||
212 | String appId = resources.getAppid(); | ||
213 | String openId = resources.getOpenid(); | ||
240 | 214 | ||
241 | /** | 215 | // 小屏账户 |
242 | * | 216 | UserWeixinDTO userWeixinDTO = this.findFirstByUnionIdAndAppIdAndOpenId(unionId,appId, openId); |
243 | * @param userWeixinDTO | ||
244 | * @param appId | ||
245 | * @param openId | ||
246 | */ | ||
247 | private void doUpdateUserWeiXinAndMember(UserWeixinDTO userWeixinDTO,String appId,String openId,String headImgUrl,String nickName) { | ||
248 | 217 | ||
249 | userWeixinDTO.setAppid(appId); | 218 | if (Objects.isNull(userWeixinDTO.getId())) { |
250 | userWeixinDTO.setOpenid(openId); | 219 | // member |
251 | userWeixinDTO.setNickname(nickName); | 220 | Member member = |
252 | userWeixinDTO.setHeadimgurl(headImgUrl); | 221 | MemberBuilder.build(LocalConstants.MEMBER_PLATFORM_TYPE_WEIXIN, |
253 | // 修改微信账户关注状态 | 222 | resources.getHeadimgurl(), resources.getNikename(), 0); |
254 | this.doUpdateUserWeiXinStatus(userWeixinDTO,SUBSCRIBE_STATUS); | ||
255 | 223 | ||
256 | // 小屏会员 | 224 | userWeixinDTO = new UserWeixinDTO(); |
257 | MemberDTO memberDTO_0 = this.findMemberByAppIdAndOpenId(appId,openId); | 225 | BeanUtils.copyProperties(resources, userWeixinDTO); |
258 | 226 | ||
259 | if (StringUtils.isNotBlank(headImgUrl) && StringUtils.isNotBlank(nickName)) { | 227 | UserWeixin weixinUser = this.createWeixinUser(userWeixinDTO, member); |
260 | memberDTO_0.setAvatarUrl(headImgUrl); | 228 | userWeixinDTO.setId(weixinUser.getId()); |
261 | memberDTO_0.setNickname(nickName); | ||
262 | } | 229 | } |
263 | 230 | ||
264 | this.doUpdateMemberVip(memberDTO_0,1); | 231 | return this.getFirstId(userWeixinDTO); |
265 | } | 232 | } |
266 | 233 | ||
267 | /** | 234 | /** |
268 | * 创建会员和账户 | 235 | * 微信公众号关注 |
269 | * @param weiXinBeanDefinition | 236 | * 1.未扫描大屏二维码 |
237 | * 1). 保存、修改小屏账户,创建小屏账户会员 | ||
238 | * 2.扫描大屏二维码 | ||
239 | * 1). 从redis中获取大屏信息 | ||
240 | * 2). 大屏账户保存小屏会员的code | ||
241 | * 3). 小屏会员中保存大屏的id | ||
242 | * @description 大小屏绑定,大屏账户保存小屏会员编码 | ||
243 | * @param resources | ||
244 | * @return | ||
270 | */ | 245 | */ |
271 | private void doCreateUserWeiXinAndMember(DefaultWeiXinBeanDefinition weiXinBeanDefinition) { | 246 | @Override |
247 | public boolean subscribe(SubscribeBean resources) { | ||
248 | String unionId = resources.getUnionid(); | ||
249 | String appId = resources.getAppId(); | ||
250 | String openId = resources.getOpenId(); | ||
251 | String nickname = resources.getNickname(); | ||
252 | String headImgUrl = resources.getHeadimgurl(); | ||
272 | 253 | ||
273 | // 小屏账户 | 254 | // 小屏账户 |
274 | UserWeixin userWeixin = this.generateUserWeiXin(weiXinBeanDefinition,SUBSCRIBE_STATUS); | 255 | UserWeixinDTO userWeixinDTO = this.findFirstByUnionIdAndAppIdAndOpenId(unionId,appId, openId); |
275 | 256 | ||
276 | // 保存会员 | 257 | if (Objects.isNull(userWeixinDTO.getId())) { |
277 | // Long memberId = this.doCreateMember(userWeixin,1); | ||
278 | Member member = this.doCreateMemberAndReturnMember(userWeixin,1); | ||
279 | 258 | ||
280 | if (Objects.isNull(member.getId())) { | 259 | // member |
281 | throw new BadRequestException("会员创建保存失败"); | 260 | Member member = |
282 | } | 261 | MemberBuilder.build(LocalConstants.MEMBER_PLATFORM_TYPE_WEIXIN, |
262 | resources.getHeadimgurl(), resources.getNikename(), 1); | ||
263 | |||
264 | UserWeixinDTO _userWeixinDTO = new UserWeixinDTO(); | ||
265 | BeanUtils.copyProperties(resources,_userWeixinDTO); | ||
266 | |||
267 | this.createWeixinUser(_userWeixinDTO,member); | ||
283 | 268 | ||
284 | // 保存或者修改,微信账户信息 | 269 | } else { |
285 | this.doCreateUserWeiXin(userWeixin,member); | 270 | |
271 | // 修改账 status =1 , 会员 vip = 1 | ||
272 | this.doUpdateUserWeiXinAndMember(userWeixinDTO,appId,openId,headImgUrl,nickname); | ||
286 | 273 | ||
287 | } | 274 | } |
288 | 275 | ||
289 | /** | 276 | // 大屏信息 |
290 | * 获取小屏会员 | 277 | JSONObject iptvUserInfo = resources.getIptvUserInfo(); |
291 | * @param appId | 278 | if (Objects.nonNull(iptvUserInfo)) { |
292 | * @param openId | 279 | |
293 | * @return | 280 | // 小屏会员 |
294 | */ | 281 | MemberDTO memberDTO = this.findMemberByAppIdAndOpenId(appId,openId); |
295 | private MemberDTO findMemberByAppIdAndOpenId(String appId, String openId) { | 282 | |
296 | UserWeixinDTO userWeixinDTO = this.findUserWeiXinByOpenIdAndAppId(appId, openId); | 283 | // 账户 |
297 | if (Objects.nonNull(userWeixinDTO)) { | 284 | String platformAccount = iptvUserInfo.getString("platformAccount"); |
298 | Long memberId = userWeixinDTO.getMemberId(); | 285 | |
299 | return this.findMemberById(memberId); | 286 | this.bind(memberDTO,platformAccount); |
287 | |||
300 | } | 288 | } |
301 | return null; | 289 | |
290 | return true; | ||
291 | |||
302 | } | 292 | } |
303 | 293 | ||
304 | /** | 294 | /** |
... | @@ -321,9 +311,6 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -321,9 +311,6 @@ public class UserOperationServiceImpl implements UserOperationService { |
321 | // 修改会员vip,如果没有购买会员则取消团粉 | 311 | // 修改会员vip,如果没有购买会员则取消团粉 |
322 | this.doUpdateMemberVip(memberDTO,0); | 312 | this.doUpdateMemberVip(memberDTO,0); |
323 | 313 | ||
324 | // 关注历史记录 | ||
325 | this.doInsertSubscribeHistory(appId,openId,WeChatConstants.EVENT_UNSUBSCRIBE); | ||
326 | |||
327 | return true; | 314 | return true; |
328 | } | 315 | } |
329 | 316 | ||
... | @@ -363,807 +350,49 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -363,807 +350,49 @@ public class UserOperationServiceImpl implements UserOperationService { |
363 | return null; | 350 | return null; |
364 | } | 351 | } |
365 | 352 | ||
366 | |||
367 | /** | 353 | /** |
368 | * | 354 | * 大屏更换主账号 |
369 | * @param unionid | 355 | * @param resources |
370 | * @param appId | ||
371 | * @return | ||
372 | */ | 356 | */ |
373 | private UserWeixinDTO findUserWeiXinByUnionIdAndAppId(String unionid, String appId) { | 357 | @Override |
374 | return this.userWeixinService.findFirstByUnionidAndAppid(unionid,appId); | 358 | public void changeMainAccount(UserTv resources) { |
375 | } | ||
376 | 359 | ||
377 | /** | 360 | // 会员编码 |
378 | * 修改会员vip状态 | 361 | String memberCode = resources.getMemberCode(); |
379 | */ | ||
380 | private void doUpdateMemberVip(MemberDTO memberDTO,Integer vip1) { | ||
381 | if (memberDTO != null) { | ||
382 | Integer vip = memberDTO.getVip(); | ||
383 | vip = (vip == null ? 0 : vip); | ||
384 | // 未购买付费会员 | ||
385 | if (vip <= 1) { | ||
386 | 362 | ||
387 | memberDTO.setVip(vip1); | 363 | UserTvDTO userTvDTO = this.findByPriorityMemberCode(memberCode); |
388 | 364 | ||
389 | Member member = new Member(); | 365 | if (Objects.nonNull(userTvDTO)) { |
390 | BeanUtils.copyProperties(memberDTO, member); | 366 | |
391 | this.memberService.update(member); | 367 | if (userTvDTO.getPriorityMemberCode().equalsIgnoreCase(memberCode)) |
392 | } | 368 | throw new BadRequestException("会员已是主账户"); |
393 | } | 369 | |
394 | } | 370 | throw new BadRequestException("该会员已绑定其他账户"); |
395 | 371 | ||
396 | /** | ||
397 | * 获取小屏会员 | ||
398 | * @param userWeixinDTO | ||
399 | * @return | ||
400 | */ | ||
401 | private MemberDTO findMemberByUserWeixinDTO(UserWeixinDTO userWeixinDTO) { | ||
402 | Long memberId = userWeixinDTO.getMemberId(); | ||
403 | if (Objects.nonNull(memberId)) { | ||
404 | MemberDTO memberDTO = this.findMemberById(memberId); | ||
405 | return memberDTO; | ||
406 | } | 372 | } |
407 | return null; | 373 | |
374 | // 设置主会员 | ||
375 | this.bondPriorityMember(userTvDTO, memberCode,"manual"); | ||
376 | |||
408 | } | 377 | } |
409 | 378 | ||
410 | /** | 379 | /** |
411 | * 修改微信公众号关注状态 | 380 | * 大屏解绑 |
412 | * @param status 0:取消关注 1:关注 | 381 | * @param resources |
413 | */ | 382 | */ |
414 | private UserWeixinDTO doUpdateUserWeiXinStatus(String appId, String openId, Integer status) { | 383 | @Override |
415 | 384 | public void unbind(UserTv resources) { | |
416 | UserWeixinDTO userWeixinDTO = this.userWeixinService.findFirstByAppIdAndOpenId(appId, openId); | ||
417 | |||
418 | if (Objects.nonNull(userWeixinDTO.getId())) { | ||
419 | 385 | ||
420 | userWeixinDTO.setStatus(status); | 386 | String memberCode = resources.getMemberCode(); |
421 | 387 | ||
422 | UserWeixin userWeixin = new UserWeixin(); | 388 | // 大屏会员 |
423 | BeanUtils.copyProperties(userWeixinDTO,userWeixin); | 389 | MemberDTO memberDTOS = this.findMemberByCode(memberCode); |
424 | 390 | ||
425 | this.userWeixinService.update(userWeixin); | 391 | // 解绑(置空大屏信息) |
426 | 392 | this.resetIptvColumn(memberDTOS); | |
427 | } | ||
428 | |||
429 | return userWeixinDTO; | ||
430 | |||
431 | } | ||
432 | |||
433 | /** | ||
434 | * 修改微信公众号关注状态 | ||
435 | * @param status 0:取消关注 1:关注 | ||
436 | */ | ||
437 | private UserWeixinDTO doUpdateUserWeiXinStatus(UserWeixinDTO userWeixinDTO, Integer status) { | ||
438 | |||
439 | userWeixinDTO.setStatus(status); | ||
440 | |||
441 | UserWeixin userWeixin = new UserWeixin(); | ||
442 | BeanUtils.copyProperties(userWeixinDTO,userWeixin); | ||
443 | |||
444 | this.userWeixinService.update(userWeixin); | ||
445 | |||
446 | |||
447 | return userWeixinDTO; | ||
448 | |||
449 | } | ||
450 | |||
451 | /** | ||
452 | * 通过openId和appId获取微信信息 | ||
453 | * @param appId | ||
454 | * @param openId | ||
455 | * @return | ||
456 | */ | ||
457 | private UserWeixinDTO findUserWeiXinByOpenIdAndAppId(String appId, String openId) { | ||
458 | UserWeixinDTO userWeixinDTO = this.userWeixinService.findFirstByAppIdAndOpenId(appId,openId); | ||
459 | return userWeixinDTO; | ||
460 | } | ||
461 | |||
462 | /** | ||
463 | * 获取会员 | ||
464 | * @param memberId | ||
465 | * @return | ||
466 | */ | ||
467 | private MemberDTO findMemberById(Long memberId) { | ||
468 | MemberDTO memberDTO = this.memberService.findById(memberId); | ||
469 | return memberDTO; | ||
470 | } | ||
471 | |||
472 | /** | ||
473 | * 小程序登录 | ||
474 | * @param resources | ||
475 | * @return | ||
476 | */ | ||
477 | @Override | ||
478 | @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = Exception.class) | ||
479 | public UserWeixinDTO appletLogin(WeiXinUserBean resources) { | ||
480 | String appid = resources.getAppid(); | ||
481 | String openid = resources.getOpenid(); | ||
482 | String headimgurl = resources.getHeadimgurl(); | ||
483 | String unionid = resources.getUnionid(); | ||
484 | |||
485 | |||
486 | // 解析 | ||
487 | DefaultWeiXinBeanDefinition weiXinBeanDefinition = new DefaultWeiXinBeanDefinition();//this.parseAppletInfo(resources); | ||
488 | weiXinBeanDefinition.setAppid(appid); | ||
489 | weiXinBeanDefinition.setOpenId(openid); | ||
490 | weiXinBeanDefinition.setHeadImgUrl(headimgurl); | ||
491 | weiXinBeanDefinition.setUnionId(unionid); | ||
492 | |||
493 | if (Objects.isNull(weiXinBeanDefinition.getAppId())) { | ||
494 | throw new RuntimeException("微信信息解析失败!"); | ||
495 | } | ||
496 | |||
497 | // 链接微信服务器获取用户信息,创建UserWeixin | ||
498 | UserWeixin userWeixin = this.generateUserWeiXin(weiXinBeanDefinition,UNSUBSCRIBE_STATUS); | ||
499 | |||
500 | // 保存会员 | ||
501 | Long memberId = this.doCreateMember(userWeixin,0); | ||
502 | |||
503 | // 保存或者修改,微信账户信息 | ||
504 | UserWeixinDTO userWeixinDTO = this.doCreateUserWeiXin(userWeixin, memberId); | ||
505 | |||
506 | // 为了保证返回的同一用户 | ||
507 | UserWeixinDTO userWeixinDTO_0 = this.getFirstId(userWeixinDTO); | ||
508 | return userWeixinDTO_0; | ||
509 | } | ||
510 | |||
511 | /** | ||
512 | * | ||
513 | * @param userWeixinDTO | ||
514 | * @param vip | ||
515 | * @return | ||
516 | */ | ||
517 | private Long doCreateMember(UserWeixinDTO userWeixinDTO,Integer vip) { | ||
518 | UserWeixin userWeixin = new UserWeixin(); | ||
519 | BeanUtils.copyProperties(userWeixinDTO,userWeixin); | ||
520 | Long memberId = this.doCreateMember(userWeixin, vip); | ||
521 | return memberId; | ||
522 | } | ||
523 | |||
524 | /** | ||
525 | * | ||
526 | * @param userWeixin | ||
527 | * @param vip | ||
528 | * @return | ||
529 | */ | ||
530 | private Member doCreateMemberAndReturnMember(UserWeixin userWeixin,Integer vip) { | ||
531 | Member memberReturn = null; | ||
532 | |||
533 | if(Objects.nonNull(userWeixin)) { | ||
534 | |||
535 | String unionid = userWeixin.getUnionid(); | ||
536 | |||
537 | // 新创建的小屏账户 | ||
538 | if(Objects.nonNull(unionid)) { | ||
539 | |||
540 | // 查询第一个账户是否关联了会员 | ||
541 | UserWeixinDTO userWeixinDTO = this.userWeixinService.findFirstByUnionId(unionid); | ||
542 | |||
543 | // 无账号,没有绑定会员 | ||
544 | if (Objects.isNull(userWeixinDTO.getMemberId())) { | ||
545 | // 默认会员 | ||
546 | Member member = MemberBuilder.build(LocalConstants.DEVICE_MOBILE,userWeixin.getHeadimgurl(), | ||
547 | userWeixin.getNickname(),vip); | ||
548 | |||
549 | memberReturn = this.memberService.createAndReturnMember(member); | ||
550 | |||
551 | } | ||
552 | |||
553 | // 如果绑定了会员 | ||
554 | if (Objects.nonNull(userWeixinDTO.getMemberId())) { | ||
555 | Long memberId = userWeixinDTO.getMemberId(); | ||
556 | MemberDTO memberDTO = this.findMemberById(memberId); | ||
557 | memberReturn = new Member(); | ||
558 | BeanUtils.copyProperties(memberDTO,memberReturn); | ||
559 | } | ||
560 | |||
561 | } | ||
562 | |||
563 | } | ||
564 | |||
565 | return memberReturn; | ||
566 | } | ||
567 | |||
568 | /** | ||
569 | * 创建会员 | ||
570 | * @description 同一用户只有一个会员,通过unionId查询任意账户是否关联了会员,如果关联了就不用再创建 | ||
571 | * @param userWeixin | ||
572 | * @param vip | ||
573 | * @return | ||
574 | */ | ||
575 | private Long doCreateMember(UserWeixin userWeixin,Integer vip) { | ||
576 | |||
577 | Long memberId = null; | ||
578 | |||
579 | if(Objects.nonNull(userWeixin)) { | ||
580 | |||
581 | String unionid = userWeixin.getUnionid(); | ||
582 | |||
583 | // 新创建的小屏账户 | ||
584 | if(Objects.nonNull(unionid)) { | ||
585 | |||
586 | // 查询第一个账户是否关联了会员 | ||
587 | UserWeixinDTO userWeixinDTO = this.userWeixinService.findFirstByUnionId(unionid); | ||
588 | |||
589 | // 无账号,没有绑定会员 | ||
590 | if (Objects.isNull(userWeixinDTO.getMemberId())) { | ||
591 | // 默认会员 | ||
592 | Member member = MemberBuilder.build(LocalConstants.DEVICE_MOBILE,userWeixin.getHeadimgurl(), | ||
593 | userWeixin.getNickname(),vip); | ||
594 | |||
595 | memberId = this.memberService.create(member); | ||
596 | |||
597 | } | ||
598 | |||
599 | // 如果绑定了会员 | ||
600 | if (Objects.nonNull(userWeixinDTO.getMemberId())) { | ||
601 | memberId = userWeixinDTO.getMemberId(); | ||
602 | } | ||
603 | |||
604 | } | ||
605 | |||
606 | } | ||
607 | |||
608 | return memberId; | ||
609 | } | ||
610 | |||
611 | private UserWeixinDTO doCreateUserWeiXin(UserWeixinDTO userWeixin,Long memberId) { | ||
612 | if (Objects.isNull(memberId)) | ||
613 | throw new NullPointerException("memberId is null !"); | ||
614 | |||
615 | UserWeixin userWeixin1 = new UserWeixin(); | ||
616 | BeanUtils.copyProperties(userWeixin,userWeixin1); | ||
617 | UserWeixinDTO userWeixinDTO = this.doCreateUserWeiXin(userWeixin1, memberId); | ||
618 | return userWeixinDTO; | ||
619 | } | ||
620 | |||
621 | |||
622 | private UserWeixinDTO doCreateUserWeiXin(UserWeixin userWeixin,Member member) { | ||
623 | Long memberId = member.getId(); | ||
624 | String code = member.getCode(); | ||
625 | UserWeixinDTO userWeixinDTO = new UserWeixinDTO(); | ||
626 | if(Objects.isNull(userWeixin.getId()) && Objects.nonNull(memberId)) { | ||
627 | userWeixin.setMemberId(memberId); | ||
628 | userWeixin.setStatus(SUBSCRIBE_STATUS); | ||
629 | userWeixin.setSyncStatus(0); | ||
630 | userWeixin.setCreateBy("system"); | ||
631 | userWeixin.setUpdateBy("system"); | ||
632 | userWeixin.setAuthTime(TimestampUtil.now()); | ||
633 | userWeixin.setMemberCode(code); | ||
634 | userWeixin = this.userWeixinService.create(userWeixin); | ||
635 | } | ||
636 | |||
637 | BeanUtils.copyProperties(userWeixin,userWeixinDTO); | ||
638 | return userWeixinDTO; | ||
639 | } | ||
640 | |||
641 | /** | ||
642 | * 保存微信账户信息 | ||
643 | * @param userWeixin | ||
644 | * @param memberId | ||
645 | */ | ||
646 | private UserWeixinDTO doCreateUserWeiXin(UserWeixin userWeixin,Long memberId) { | ||
647 | |||
648 | MemberDTO memberDTO = this.findMemberById(memberId); | ||
649 | |||
650 | UserWeixinDTO userWeixinDTO = new UserWeixinDTO(); | ||
651 | if(Objects.isNull(userWeixin.getId()) && Objects.nonNull(memberId)) { | ||
652 | userWeixin.setMemberId(memberId); | ||
653 | userWeixin.setStatus(SUBSCRIBE_STATUS); | ||
654 | userWeixin.setSyncStatus(0); | ||
655 | userWeixin.setCreateBy("system"); | ||
656 | userWeixin.setUpdateBy("system"); | ||
657 | userWeixin.setAuthTime(TimestampUtil.now()); | ||
658 | userWeixin.setMemberCode(memberDTO.getCode()); | ||
659 | userWeixin = this.userWeixinService.create(userWeixin); | ||
660 | |||
661 | } | ||
662 | |||
663 | // 避免账户存在但会员不存在的情况 | ||
664 | if(Objects.nonNull(userWeixin.getId()) && Objects.isNull(userWeixin.getMemberId()) && Objects.nonNull(userWeixin.getUnionid())) { | ||
665 | |||
666 | userWeixin.setMemberId(memberId); | ||
667 | this.userWeixinService.update(userWeixin); | ||
668 | } | ||
669 | |||
670 | BeanUtils.copyProperties(userWeixin,userWeixinDTO); | ||
671 | return userWeixinDTO; | ||
672 | } | ||
673 | |||
674 | /** | ||
675 | * 链接微信服务器,创建或者修改UserWeiXinDTO | ||
676 | * @param weiXinBeanDefinition | ||
677 | * @return | ||
678 | */ | ||
679 | private UserWeixin generateUserWeiXin(WeiXinBeanDefinition weiXinBeanDefinition,Integer status) { | ||
680 | |||
681 | String appId = weiXinBeanDefinition.getAppId(); | ||
682 | String openId = weiXinBeanDefinition.getOpenId(); | ||
683 | String unionId = weiXinBeanDefinition.getUnionId(); | ||
684 | String nickname = weiXinBeanDefinition.getNickname(); | ||
685 | String headImgUrl = weiXinBeanDefinition.getHeadImgUrl(); | ||
686 | |||
687 | // 微信 | ||
688 | UserWeixinDTO weixinDTO = this.userWeixinService.findFirstByAppIdAndOpenId(appId,openId); | ||
689 | |||
690 | if (Objects.isNull(weixinDTO.getId())) { | ||
691 | |||
692 | UserWeixin userWeixin = new UserWeixin() | ||
693 | .setAppid(appId) | ||
694 | .setOpenid(openId) | ||
695 | .setUnionid(unionId) | ||
696 | .setNickname(nickname) | ||
697 | .setHeadimgurl(headImgUrl) | ||
698 | .setStatus(status) | ||
699 | .setAuthTime(TimestampUtil.now()); | ||
700 | |||
701 | return userWeixin; | ||
702 | |||
703 | } | ||
704 | |||
705 | UserWeixin userWeixin = new UserWeixin(); | ||
706 | BeanUtils.copyProperties(weixinDTO,userWeixin); | ||
707 | |||
708 | return userWeixin; | ||
709 | |||
710 | } | ||
711 | |||
712 | /** | ||
713 | * 解析小程序 | ||
714 | * @param resources | ||
715 | * @return | ||
716 | */ | ||
717 | private DefaultWeiXinBeanDefinition parseAppletInfo(WeiXinUserBean resources) { | ||
718 | return this.parse(resources); | ||
719 | } | ||
720 | |||
721 | /** | ||
722 | * 解析微信信息 | ||
723 | * @param resources | ||
724 | * @return | ||
725 | */ | ||
726 | private DefaultWeiXinBeanDefinition parse(WeiXinUserBean resources) { | ||
727 | Map<String, String> weixinInfoMap = null; | ||
728 | String appId = resources.getWxAppid(); | ||
729 | String code = resources.getWxCode(); | ||
730 | String encryptedData = resources.getEncryptedData(); | ||
731 | String iv = resources.getIv(); | ||
732 | String userInfo = null; | ||
733 | |||
734 | if (StringUtils.isNotBlank(appId)) { | ||
735 | String decrypt = AESUtil.decrypt(appId, this.key); | ||
736 | if (decrypt != null) { | ||
737 | appId = decrypt.substring(16); | ||
738 | } | ||
739 | weixinInfoMap = this.getWeixinInfoByAppid(appId); | ||
740 | } | ||
741 | |||
742 | if (StringUtils.isNotBlank(code)) { | ||
743 | String decrypt = AESUtil.decrypt(code, this.key); | ||
744 | if (decrypt != null) { | ||
745 | code = decrypt.substring(16); | ||
746 | } | ||
747 | } | ||
748 | |||
749 | String appId_ = weixinInfoMap.get("appid"); | ||
750 | String secret = weixinInfoMap.get("secret"); | ||
751 | |||
752 | // 链接微信服务器 | ||
753 | String url = WeChatConstants.CODE2SESSION.replace("APPID", appId_) | ||
754 | .replace("SECRET", secret).replace("JSCODE", code); | ||
755 | |||
756 | String entityBody = HttpUtil.get(url); | ||
757 | log.info("entityBody [{}]",entityBody); | ||
758 | |||
759 | JSONObject jsonObject = JSONObject.parseObject(entityBody); | ||
760 | |||
761 | String errCode = jsonObject.getString("errcode"); | ||
762 | |||
763 | if (StringUtils.isNotEmpty(errCode)) { | ||
764 | String nameStr = jsonObject.getString("errmsg"); | ||
765 | throw new BadRequestException(nameStr); | ||
766 | } | ||
767 | |||
768 | String openId = jsonObject.getString("openid"); | ||
769 | String unionId = jsonObject.getString("unionid"); | ||
770 | String sessionKey = jsonObject.getString("session_key"); | ||
771 | |||
772 | JSONObject userInfoWxJo = null; | ||
773 | |||
774 | if (StringUtils.isNotBlank(encryptedData) && StringUtils.isNotBlank(iv) && StringUtils.isNotBlank(sessionKey)) { | ||
775 | |||
776 | String userInfoWeixin = AESUtil.decryptJsUserInfo(encryptedData, iv, sessionKey); | ||
777 | log.info("userInfoWeixin [{}]",userInfoWeixin); | ||
778 | |||
779 | if (StringUtils.isNotEmpty(userInfoWeixin)) | ||
780 | userInfoWxJo = JSONObject.parseObject(userInfoWeixin); | ||
781 | |||
782 | } | ||
783 | |||
784 | String phoneNumber = ""; | ||
785 | if (StringUtils.isNotBlank(encryptedData)) { | ||
786 | |||
787 | JSONObject userInfoJo = JSONObject.parseObject(userInfo); | ||
788 | if (Objects.nonNull(userInfoJo)) { | ||
789 | encryptedData = userInfoJo.getString("encryptedData"); | ||
790 | iv = userInfoJo.getString("iv"); | ||
791 | String sessionkey = jsonObject.getString("session_key"); | ||
792 | JSONObject userInfoPhone = AESUtil.decryptJsUserPhone(encryptedData, iv, sessionkey); | ||
793 | if (ObjectUtil.isNull(userInfoPhone)) { | ||
794 | throw new BadRequestException("decrypt phone error..."); | ||
795 | } | ||
796 | |||
797 | phoneNumber = userInfoPhone.getString("phoneNumber"); | ||
798 | if (StringUtils.isBlank(phoneNumber)) { | ||
799 | throw new BadRequestException("phoneNumber is null..."); | ||
800 | } | ||
801 | |||
802 | } | ||
803 | } | ||
804 | |||
805 | DefaultWeiXinBeanDefinition weiXinBeanDefinition = | ||
806 | new DefaultWeiXinBeanDefinition(appId,code,unionId,openId,userInfoWxJo,phoneNumber); | ||
807 | |||
808 | return weiXinBeanDefinition; | ||
809 | } | ||
810 | |||
811 | /** | ||
812 | * | ||
813 | * @param appid | ||
814 | * @return | ||
815 | */ | ||
816 | private Map<String, String> getWeixinInfoByAppid(String appid) { | ||
817 | if (StringUtils.isBlank(appid)) { | ||
818 | throw new RuntimeException("wxAppid can not be null"); | ||
819 | } | ||
820 | List<Map<String, String>> list = this.weiXinAppListConfig.getList(); | ||
821 | Optional<Map<String, String>> weixinInfoOptional = list.stream().filter(o -> o.get("appid").equals(appid)).findFirst(); | ||
822 | if (!weixinInfoOptional.isPresent()) { | ||
823 | throw new RuntimeException("wxAppid error, appid is : " + appid); | ||
824 | } | ||
825 | return weixinInfoOptional.get(); | ||
826 | } | ||
827 | |||
828 | /** | ||
829 | * 大屏更换主账号 | ||
830 | * @param resources | ||
831 | */ | ||
832 | @Override | ||
833 | public void changeMainAccount(UserTv resources) { | ||
834 | |||
835 | // 会员编码 | ||
836 | String memberCode = resources.getMemberCode(); | ||
837 | |||
838 | UserTvDTO userTvDTO_0 = this.findByPriorityMemberCode(memberCode); | ||
839 | |||
840 | if (Objects.nonNull(userTvDTO_0)) { | ||
841 | |||
842 | if (userTvDTO_0.getPriorityMemberCode().equalsIgnoreCase(memberCode)) | ||
843 | throw new BadRequestException("会员已是主账户"); | ||
844 | |||
845 | throw new BadRequestException("该会员已绑定其他账户"); | ||
846 | } | ||
847 | |||
848 | // 大屏账户 | ||
849 | UserTvDTO userTvDTO = this.findByUserTv(resources); | ||
850 | |||
851 | // 会员 | ||
852 | MemberDTO memberDTO = this.findMemberByMemberCode(memberCode); | ||
853 | |||
854 | // 设置主会员 | ||
855 | this.bondPriorityMember(userTvDTO, memberDTO,"manual"); | ||
856 | |||
857 | } | ||
858 | |||
859 | @Override | ||
860 | public void changeMainAccountByUnionId(UserTv userTv, String unionId) { | ||
861 | UserWeixinDTO userWeixinDTO = this.userWeixinService.findFirstByUnionId(unionId); | ||
862 | Long memberId = userWeixinDTO.getMemberId(); | ||
863 | MemberDTO memberDTO = this.findMemberById(memberId); | ||
864 | String code = memberDTO.getCode(); | ||
865 | userTv.setMemberCode(code); | ||
866 | this.changeMainAccount(userTv); | ||
867 | } | ||
868 | |||
869 | /** | ||
870 | * | ||
871 | * @param memberCode | ||
872 | * @return | ||
873 | */ | ||
874 | private UserTvDTO findByPriorityMemberCode(String memberCode) { | ||
875 | UserTvDTO userTvDTO = this.userTvService.findByPriorityMemberCode(memberCode); | ||
876 | return userTvDTO; | ||
877 | } | ||
878 | |||
879 | /** | ||
880 | * 设置主会员 | ||
881 | * @description 检查大屏账户有没有绑定小屏会员,如果没有绑定就将当前会员的code保存到大屏账户中 | ||
882 | * @param userTvDTO | ||
883 | * @param memberDTO | ||
884 | * @param auto manual:手动 auto:自动 | ||
885 | */ | ||
886 | private void bondPriorityMember(UserTvDTO userTvDTO, MemberDTO memberDTO,String auto) { | ||
887 | |||
888 | if (auto.equalsIgnoreCase("auto")) { | ||
889 | // 主账户 | ||
890 | String priorityMemberCode = userTvDTO.getPriorityMemberCode(); | ||
891 | if (StringUtils.isNotEmpty(priorityMemberCode)) { | ||
892 | return; | ||
893 | } | ||
894 | } | ||
895 | |||
896 | String memberCode = memberDTO.getCode(); | ||
897 | |||
898 | // 绑定了小屏,结束 | ||
899 | if (StringUtils.isNotEmpty(memberCode)) { | ||
900 | userTvDTO.setPriorityMemberCode(memberCode); | ||
901 | } | ||
902 | |||
903 | UserTv userTv = new UserTv(); | ||
904 | BeanUtils.copyProperties(userTvDTO,userTv); | ||
905 | this.userTvService.update(userTv); | ||
906 | |||
907 | } | ||
908 | |||
909 | /** | ||
910 | * 通过编码获取会员 | ||
911 | * @param memberCode | ||
912 | * @return | ||
913 | */ | ||
914 | private MemberDTO findMemberByMemberCode(String memberCode) { | ||
915 | return this.memberService.findByCode(memberCode); | ||
916 | } | ||
917 | |||
918 | /** | ||
919 | * 大屏解绑 | ||
920 | * @param resources | ||
921 | */ | ||
922 | @Override | ||
923 | public void unbind(UserTv resources) { | ||
924 | // 大屏账户 | ||
925 | UserTvDTO userTvDTO = this.findByUserTv(resources); | ||
926 | |||
927 | Long id = userTvDTO.getId(); | ||
928 | |||
929 | String memberCode = resources.getMemberCode(); | ||
930 | |||
931 | // 大屏会员 | ||
932 | MemberDTO memberDTOS = this.findMemberByCodeAndUserIptvId(id,memberCode); | ||
933 | |||
934 | // 解绑(置空大屏信息) | ||
935 | this.resetIptvColumn(memberDTOS); | ||
936 | |||
937 | // 置空主账号 | ||
938 | this.resetMainAccount(memberCode); | ||
939 | } | ||
940 | |||
941 | @Override | ||
942 | public void unbindByUnionId(UserTv userTv, String unionId) { | ||
943 | UserWeixinDTO userWeixinDTO = this.userWeixinService.findFirstByUnionId(unionId); | ||
944 | Long memberId = userWeixinDTO.getMemberId(); | ||
945 | MemberDTO memberDTO = this.findMemberById(memberId); | ||
946 | String code = memberDTO.getCode(); | ||
947 | userTv.setMemberCode(code); | ||
948 | this.unbind(userTv); | ||
949 | } | ||
950 | |||
951 | /** | ||
952 | * 置空主账号 | ||
953 | * @param memberCode | ||
954 | */ | ||
955 | private void resetMainAccount(String memberCode) { | ||
956 | UserTvDTO userTvDTO = this.userTvService.findByPriorityMemberCode(memberCode); | ||
957 | if (Objects.nonNull(userTvDTO)) { | ||
958 | userTvDTO.setPriorityMemberCode(null); | ||
959 | |||
960 | UserTv userTv = new UserTv(); | ||
961 | BeanUtils.copyProperties(userTvDTO,userTv); | ||
962 | |||
963 | this.userTvService.unbindPriorityMemberCode(userTv); | ||
964 | } | ||
965 | } | ||
966 | |||
967 | /** | ||
968 | * 解绑(置空大屏信息) | ||
969 | * @param memberDTOS | ||
970 | */ | ||
971 | private void resetIptvColumn(MemberDTO memberDTOS) { | ||
972 | // 若无关系,不做处理 | ||
973 | if (Objects.nonNull(memberDTOS)) | ||
974 | return; | ||
975 | |||
976 | Member member = new Member(); | ||
977 | memberDTOS.setBindIptvTime(null); | ||
978 | memberDTOS.setUserIptvId(null); | ||
979 | memberDTOS.setBindIptvPlatformType(null); | ||
980 | BeanUtils.copyProperties(memberDTOS, member); | ||
981 | this.memberService.unbind(member); | ||
982 | } | ||
983 | |||
984 | /** | ||
985 | * | ||
986 | * @param tvUserId 大屏ic | ||
987 | * @param memberCode 会员编码 | ||
988 | * @return | ||
989 | */ | ||
990 | private MemberDTO findMemberByCodeAndUserIptvId(Long tvUserId,String memberCode) { | ||
991 | MemberDTO memberDTO = memberService.findByCode(memberCode); | ||
992 | return memberDTO; | ||
993 | } | ||
994 | |||
995 | /** | ||
996 | * 通过大屏账户查询大屏信息 | ||
997 | * @param resources | ||
998 | * @return | ||
999 | */ | ||
1000 | private UserTvDTO findByUserTv(UserTv resources) { | ||
1001 | String platformAccount = resources.getPlatformAccount(); | ||
1002 | UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); | ||
1003 | return userTvDTO; | ||
1004 | } | ||
1005 | |||
1006 | /** | ||
1007 | * 创建大屏会员 | ||
1008 | * @param resources | ||
1009 | * @return | ||
1010 | */ | ||
1011 | @Override | ||
1012 | @Transactional | ||
1013 | public boolean createMemberByUserTv(UserTv resources) { | ||
1014 | String platformAccount = resources.getPlatformAccount(); | ||
1015 | UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); | ||
1016 | |||
1017 | if (Objects.isNull(userTvDTO)) { | ||
1018 | |||
1019 | Member member = new Member(); | ||
1020 | // 大屏 | ||
1021 | member.setType(LocalConstants.MEMBER_PLATFORM_TYPE_VIS); | ||
1022 | String code = member.getCode(); | ||
1023 | member.setCode(StringUtils.isEmpty(code)?String.valueOf(IdWorker.generator()):code); | ||
1024 | member.setNickname(platformAccount); | ||
1025 | member.setType(1); | ||
1026 | Long memberId = this.memberService.create(member); | ||
1027 | |||
1028 | UserTv userTv = new UserTv(); | ||
1029 | |||
1030 | if (Objects.nonNull(memberId)) { | ||
1031 | |||
1032 | BeanUtils.copyProperties(resources,userTv); | ||
1033 | userTv.setPlatformAccount(platformAccount); | ||
1034 | userTv.setMemberCode(member.getCode()); | ||
1035 | userTv.setNickname(platformAccount); | ||
1036 | userTv.setUsername(platformAccount); | ||
1037 | userTv.setLoginDays(1); | ||
1038 | userTv.setStatus(1); | ||
1039 | userTv.setActiveTime(TimestampUtil.now()); | ||
1040 | userTv.setContinueDays(1); | ||
1041 | userTv.setCreateBy("system"); | ||
1042 | userTv.setUpdateBy("system"); | ||
1043 | this.userTvService.create(userTv); | ||
1044 | return true; | ||
1045 | } | ||
1046 | |||
1047 | return false; | ||
1048 | |||
1049 | } else { | ||
1050 | |||
1051 | UserTv userTv = new UserTv(); | ||
1052 | BeanUtils.copyProperties(userTvDTO,userTv); | ||
1053 | return true; | ||
1054 | |||
1055 | } | ||
1056 | |||
1057 | } | ||
1058 | |||
1059 | /** | ||
1060 | * 绑定会员中的userIptvId字段 | ||
1061 | * @param memberDTO | ||
1062 | * @param userTvDTO | ||
1063 | */ | ||
1064 | private MemberDTO bindIptvId(MemberDTO memberDTO,UserTvDTO userTvDTO) { | ||
1065 | String platform = userTvDTO.getPlatform(); | ||
1066 | // 绑定IPTV平台 0:未知;1:电信;2:移动;3:联通 | ||
1067 | Integer bindIptvPlatformType = 0; | ||
1068 | |||
1069 | // 联通 | ||
1070 | if (UserConstant.platform_lt.contains(platform)) { | ||
1071 | bindIptvPlatformType = PLATFORM_LIST[3]; | ||
1072 | } | ||
1073 | |||
1074 | // 移动 | ||
1075 | if (UserConstant.platform_yd.contains(platform)) { | ||
1076 | bindIptvPlatformType = PLATFORM_LIST[2]; | ||
1077 | } | ||
1078 | |||
1079 | // 电信 | ||
1080 | if (UserConstant.platform_dx.contains(platform)) { | ||
1081 | bindIptvPlatformType = PLATFORM_LIST[1]; | ||
1082 | } | ||
1083 | |||
1084 | memberDTO.setUserIptvId(userTvDTO.getId()); | ||
1085 | memberDTO.setBindIptvTime(LocalDateTime.now()); | ||
1086 | memberDTO.setBindIptvPlatformType(bindIptvPlatformType); | ||
1087 | |||
1088 | return memberDTO; | ||
1089 | } | ||
1090 | |||
1091 | /** | ||
1092 | * 修改会员 | ||
1093 | * @param memberDTO | ||
1094 | */ | ||
1095 | private void doUpdateMemberByMemberDTO(MemberDTO memberDTO){ | ||
1096 | Member member = new Member(); | ||
1097 | BeanUtils.copyProperties(memberDTO,member); | ||
1098 | member.setUpdateTime(LocalDateTime.now()); | ||
1099 | log.info("doUpdateMemberByMemberDTO=====?>>member ==>> [{}]",member); | ||
1100 | this.doUpdateMember(member); | ||
1101 | } | ||
1102 | |||
1103 | /** | ||
1104 | * 修改会员 | ||
1105 | * @param member | ||
1106 | */ | ||
1107 | private void doUpdateMember(Member member){ | ||
1108 | this.memberService.update(member); | ||
1109 | } | ||
1110 | |||
1111 | /** | ||
1112 | * 解析微信信息 | ||
1113 | * @param resources | ||
1114 | * @return | ||
1115 | */ | ||
1116 | @Override | ||
1117 | public MemberProfile saveUserWeixinPhone(WeiXinUserBean resources) { | ||
1118 | DefaultWeiXinBeanDefinition weiXinBeanDefinition = this.parseAppletInfo(resources); | ||
1119 | |||
1120 | if (Objects.nonNull(weiXinBeanDefinition.getOpenId())) { | ||
1121 | throw new RuntimeException("微信信息解析失败!"); | ||
1122 | } | ||
1123 | |||
1124 | // 保存、修改会员加密信息 | ||
1125 | return this.doSaveOrUpdateMemberProfile(weiXinBeanDefinition,resources); | ||
1126 | 393 | ||
1127 | } | 394 | // 置空主账号 |
1128 | 395 | this.resetMainAccount(memberCode); | |
1129 | @Override | ||
1130 | public boolean sendQrCodeMessage(String content) { | ||
1131 | try { | ||
1132 | log.info("receive get qrCode message, content {}", content); | ||
1133 | JSONObject jsonObject = JSONObject.parseObject(content); | ||
1134 | String appid = jsonObject.getString("appid"); | ||
1135 | String IPTVappid = jsonObject.getString("IPTVappid"); | ||
1136 | String platformAccount = jsonObject.getString("platformAccount"); | ||
1137 | String sessionId = jsonObject.getString("sessionId"); | ||
1138 | String key = QR_CODE_URL + appid + "_" + platformAccount + "_" + sessionId; | ||
1139 | String url = (String) this.redisUtils.get(key); | ||
1140 | if (StringUtils.isBlank(url)) { | ||
1141 | Map<String, String> wxInfo = WeixinUtil.getWeixinInfoByAppid(appid); | ||
1142 | String appType = wxInfo.get("appType"); | ||
1143 | // 订阅号不支持带参二维码,直接返回 | ||
1144 | if (StrUtil.isNotEmpty(appType) && ObjectUtil.equals(appType, WeChatConstants.WX_SUBSCRIPTION)) { | ||
1145 | log.error("订阅号不支持带参二维码 || {} || {}", appid, content); | ||
1146 | return false; | ||
1147 | } | ||
1148 | QrCode qrCode = new QrCode(); | ||
1149 | qrCode.setActionName(WeChatConstants.QR_STR_SCENE); | ||
1150 | if (StringUtils.isNotBlank(wxInfo.get("qrCodeExpireSeconds"))) { | ||
1151 | qrCode.setExpireSeconds(Integer.valueOf(wxInfo.get("qrCodeExpireSeconds"))); | ||
1152 | } | ||
1153 | ActionInfo actionInfo = new ActionInfo(); | ||
1154 | Scene scene = new Scene(); | ||
1155 | scene.setSceneStr(content); | ||
1156 | actionInfo.setScene(scene); | ||
1157 | qrCode.setActionInfo(actionInfo); | ||
1158 | JSONObject jsonQrCode = this.weixinRequestUtil.getQrCode(wxInfo, qrCode); | ||
1159 | url = jsonQrCode.getString("url"); | ||
1160 | Integer expireSeconds = jsonQrCode.getInteger("expire_seconds"); | ||
1161 | this.redisUtils.set(key, url, expireSeconds, TimeUnit.SECONDS); | ||
1162 | } | ||
1163 | } catch (Exception e) { | ||
1164 | log.error("GetQrCodeConsumer || get qrCode error || {}", e.toString(), e); | ||
1165 | } | ||
1166 | return true; | ||
1167 | } | 396 | } |
1168 | 397 | ||
1169 | @Override | 398 | @Override |
... | @@ -1335,79 +564,7 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -1335,79 +564,7 @@ public class UserOperationServiceImpl implements UserOperationService { |
1335 | } | 564 | } |
1336 | 565 | ||
1337 | @Override | 566 | @Override |
1338 | public List<MemberDTO> findBindByPlatformAccount(String platformAccount) { | 567 | @AsyncMqSend |
1339 | |||
1340 | UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); | ||
1341 | |||
1342 | if (Objects.nonNull(userTvDTO.getId())) { | ||
1343 | |||
1344 | Long id = userTvDTO.getId(); | ||
1345 | String priorityMemberCode = userTvDTO.getPriorityMemberCode(); | ||
1346 | List<MemberDTO> memberDTOList = this.memberService.findByUserIptvId(id); | ||
1347 | |||
1348 | if (!CollectionUtils.isEmpty(memberDTOList)) { | ||
1349 | |||
1350 | for (MemberDTO memberDTO : memberDTOList) { | ||
1351 | |||
1352 | String code = memberDTO.getCode(); | ||
1353 | if (code.equalsIgnoreCase(priorityMemberCode)) { | ||
1354 | memberDTO.setIptvMajor(IPTV_MAJOR[1]); | ||
1355 | } else { | ||
1356 | memberDTO.setIptvMajor(IPTV_MAJOR[0]); | ||
1357 | } | ||
1358 | |||
1359 | } | ||
1360 | |||
1361 | } | ||
1362 | |||
1363 | return memberDTOList; | ||
1364 | |||
1365 | } | ||
1366 | |||
1367 | return null; | ||
1368 | } | ||
1369 | |||
1370 | @Override | ||
1371 | public Object serviceLogin(WeiXinUserBean resources) { | ||
1372 | String unionId = resources.getUnionid(); | ||
1373 | String appId = resources.getAppid(); | ||
1374 | String openId = resources.getOpenid(); | ||
1375 | |||
1376 | // if (org.apache.commons.lang3.StringUtils.isBlank(unionId)) { | ||
1377 | |||
1378 | // TODO 需要商量是否需要创建微信账户 | ||
1379 | /*UserWeixinDTO userWeixinDTO = this.findUserWeiXinByOpenIdAndAppId(appId, openId); | ||
1380 | if (ObjectUtil.isNotEmpty(userWeixinDTO)) | ||
1381 | return userWeixinDTO;*/ | ||
1382 | |||
1383 | // } | ||
1384 | |||
1385 | // 小屏账户 | ||
1386 | UserWeixinDTO userWeixinDTO = this.findFirstByUnionIdAndAppIdAndOpenId(unionId,appId, openId); | ||
1387 | |||
1388 | if (Objects.isNull(userWeixinDTO.getId())) { | ||
1389 | |||
1390 | DefaultWeiXinBeanDefinition weiXinBeanDefinition = new DefaultWeiXinBeanDefinition(); | ||
1391 | weiXinBeanDefinition.setUnionId(unionId); | ||
1392 | weiXinBeanDefinition.setAppid(appId); | ||
1393 | weiXinBeanDefinition.setOpenId(openId); | ||
1394 | |||
1395 | // 创建会员和账户 | ||
1396 | this.doCreateUserWeiXinAndMember(weiXinBeanDefinition); | ||
1397 | |||
1398 | } else { | ||
1399 | |||
1400 | // 修改账户和会员信息 | ||
1401 | this.doUpdateUserWeiXinAndMember(userWeixinDTO,appId,openId,"",""); | ||
1402 | |||
1403 | } | ||
1404 | |||
1405 | // 为了保证返回的同一用户 | ||
1406 | UserWeixinDTO userWeixinDTO_0 = this.getFirstId(userWeixinDTO); | ||
1407 | return userWeixinDTO_0; | ||
1408 | } | ||
1409 | |||
1410 | @Override | ||
1411 | public boolean appletBind(BindBean resources) { | 568 | public boolean appletBind(BindBean resources) { |
1412 | 569 | ||
1413 | Long id = resources.getId(); | 570 | Long id = resources.getId(); |
... | @@ -1451,171 +608,371 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -1451,171 +608,371 @@ public class UserOperationServiceImpl implements UserOperationService { |
1451 | throw new EntityNotFoundException(MemberDTO.class, "id", memberId.toString()); | 608 | throw new EntityNotFoundException(MemberDTO.class, "id", memberId.toString()); |
1452 | } | 609 | } |
1453 | 610 | ||
1454 | // 主账户 | 611 | // 主账户 |
1455 | String priorityMemberCode = userTvDTO.getPriorityMemberCode(); | 612 | String priorityMemberCode = userTvDTO.getPriorityMemberCode(); |
613 | |||
614 | if (StringUtils.isBlank(priorityMemberCode)) { | ||
615 | // 主账户会员 | ||
616 | String code = memberDTO.getCode(); | ||
617 | // 设置主账号 | ||
618 | userTvDTO.setPriorityMemberCode(code); | ||
619 | } | ||
620 | |||
621 | // 更新小屏账户更新时间,epg需要根据修改时间来让绑定的二维码消失 | ||
622 | this.doUpdateUserWeiXinUpdateTime(userWeixinDTO); | ||
623 | |||
624 | |||
625 | // 更新大屏信息,同步大屏信息时使用 | ||
626 | userTvDTO.setMemberCode(memberDTO.getCode()); | ||
627 | this.doUpdateUserTv(userTvDTO); | ||
628 | |||
629 | |||
630 | String platform = userTvDTO.getPlatform(); | ||
631 | // 绑定IPTV平台 0:未知;1:电信;2:移动;3:联通 | ||
632 | Integer bindIptvPlatformType = 0; | ||
633 | // 联通 | ||
634 | if (UserConstant.platform_lt.contains(platform)) { | ||
635 | bindIptvPlatformType = PLATFORM_LIST[3]; | ||
636 | } | ||
637 | // 移动 | ||
638 | if (UserConstant.platform_yd.contains(platform)) { | ||
639 | bindIptvPlatformType = PLATFORM_LIST[2]; | ||
640 | } | ||
641 | // 电信 | ||
642 | if (UserConstant.platform_dx.contains(platform)) { | ||
643 | bindIptvPlatformType = PLATFORM_LIST[1]; | ||
644 | } | ||
645 | memberDTO.setUserIptvId(userTvDTO.getId()); | ||
646 | memberDTO.setBindIptvTime(LocalDateTime.now()); | ||
647 | memberDTO.setBindIptvPlatformType(bindIptvPlatformType); | ||
648 | memberDTO.setPlatformAccount(platformAccount); | ||
649 | // 修改会员信息 | ||
650 | this.doUpdateMemberByMemberDTO(memberDTO); | ||
651 | return true; | ||
652 | } | ||
653 | |||
654 | |||
655 | @Override | ||
656 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
657 | public void bind(String memberCode, String platformAccount) { | ||
658 | MemberDTO memberDTO = this.memberService.findByCode(memberCode); | ||
659 | this.bind(memberDTO,platformAccount); | ||
660 | } | ||
661 | |||
662 | /** | ||
663 | * | ||
664 | * @param memberDTO | ||
665 | * @param userTvDTO | ||
666 | */ | ||
667 | @Override | ||
668 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
669 | public void bind(MemberDTO memberDTO, UserTvDTO userTvDTO) { | ||
670 | String platformAccount = userTvDTO.getPlatformAccount(); | ||
671 | // 绑定 | ||
672 | this.bind(memberDTO,platformAccount); | ||
673 | } | ||
674 | |||
675 | /** | ||
676 | * | ||
677 | * @param memberDTO | ||
678 | * @param platformAccount | ||
679 | * @return | ||
680 | */ | ||
681 | @Override | ||
682 | public UserTvDTO bind(MemberDTO memberDTO, String platformAccount) { | ||
683 | |||
684 | MemberDTO memberDTO1 = this.memberService.findByCode(memberDTO.getCode()); | ||
685 | if (Objects.nonNull(memberDTO1.getUserIptvId())) { | ||
686 | UserTvDTO userTvDTO = this.userTvService.findById(memberDTO1.getUserIptvId()); | ||
687 | return userTvDTO; | ||
688 | } | ||
689 | |||
690 | // 大屏账户 | ||
691 | UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); | ||
692 | if (Objects.isNull(userTvDTO)) { | ||
693 | throw new BadRequestException("大屏信息不存在!"); | ||
694 | } | ||
695 | |||
696 | // mq同步数据时使用 | ||
697 | memberDTO.setPlatformAccount(platformAccount); | ||
698 | |||
699 | // 大屏是否绑定主账号,如果绑定了主账户则不操作大屏账户表 | ||
700 | this.bondPriorityMember(userTvDTO,memberDTO.getCode(),"auto"); | ||
701 | |||
702 | // 构建小屏会员对象,绑定user_iptv_id字段 | ||
703 | String platform = userTvDTO.getPlatform(); | ||
704 | // 绑定IPTV平台 0:未知;1:电信;2:移动;3:联通 | ||
705 | Integer bindIptvPlatformType = 0; | ||
706 | // 联通 | ||
707 | if (UserConstant.platform_lt.contains(platform)) { | ||
708 | bindIptvPlatformType = PLATFORM_LIST[3]; | ||
709 | } | ||
710 | // 移动 | ||
711 | if (UserConstant.platform_yd.contains(platform)) { | ||
712 | bindIptvPlatformType = PLATFORM_LIST[2]; | ||
713 | } | ||
714 | // 电信 | ||
715 | if (UserConstant.platform_dx.contains(platform)) { | ||
716 | bindIptvPlatformType = PLATFORM_LIST[1]; | ||
717 | } | ||
718 | memberDTO.setUserIptvId(userTvDTO.getId()); | ||
719 | memberDTO.setBindIptvTime(LocalDateTime.now()); | ||
720 | memberDTO.setBindIptvPlatformType(bindIptvPlatformType); | ||
721 | memberDTO.setPlatformAccount(platformAccount); | ||
722 | |||
723 | // 修改会员 | ||
724 | this.doUpdateMemberByMemberDTO(memberDTO); | ||
725 | |||
726 | return null; | ||
727 | } | ||
728 | |||
729 | /** | ||
730 | * | ||
731 | * @param unionid | ||
732 | * @param appId | ||
733 | * @return | ||
734 | */ | ||
735 | private UserWeixinDTO findUserWeiXinByUnionIdAndAppId(String unionid, String appId) { | ||
736 | return this.userWeixinService.findFirstByUnionidAndAppid(unionid,appId); | ||
737 | } | ||
738 | |||
739 | /** | ||
740 | * 修改会员vip状态 | ||
741 | */ | ||
742 | private void doUpdateMemberVip(MemberDTO memberDTO,Integer vip1) { | ||
743 | if (memberDTO != null) { | ||
744 | Integer vip = memberDTO.getVip(); | ||
745 | vip = (vip == null ? 0 : vip); | ||
746 | // 未购买付费会员 | ||
747 | if (vip <= 1) { | ||
748 | |||
749 | memberDTO.setVip(vip1); | ||
750 | |||
751 | Member member = new Member(); | ||
752 | BeanUtils.copyProperties(memberDTO, member); | ||
753 | this.memberService.update(member); | ||
754 | } | ||
755 | } | ||
756 | } | ||
757 | |||
758 | /** | ||
759 | * 获取小屏会员 | ||
760 | * @param userWeixinDTO | ||
761 | * @return | ||
762 | */ | ||
763 | private MemberDTO findMemberByUserWeixinDTO(UserWeixinDTO userWeixinDTO) { | ||
764 | Long memberId = userWeixinDTO.getMemberId(); | ||
765 | if (Objects.nonNull(memberId)) { | ||
766 | MemberDTO memberDTO = this.findMemberById(memberId); | ||
767 | return memberDTO; | ||
768 | } | ||
769 | return null; | ||
770 | } | ||
771 | |||
772 | /** | ||
773 | * 修改微信公众号关注状态 | ||
774 | * @param status 0:取消关注 1:关注 | ||
775 | */ | ||
776 | private UserWeixinDTO doUpdateUserWeiXinStatus(String appId, String openId, Integer status) { | ||
777 | |||
778 | UserWeixinDTO userWeixinDTO = this.userWeixinService.findFirstByAppIdAndOpenId(appId, openId); | ||
1456 | 779 | ||
1457 | if (StringUtils.isBlank(priorityMemberCode)) { | 780 | if (Objects.nonNull(userWeixinDTO.getId())) { |
1458 | // 主账户会员 | ||
1459 | String code = memberDTO.getCode(); | ||
1460 | userTvDTO.setPriorityMemberCode(code); | ||
1461 | } | ||
1462 | 781 | ||
1463 | // 更新小屏账户更新时间,epg需要根据修改时间来让绑定的二维码消失 | 782 | userWeixinDTO.setStatus(status); |
1464 | this.doUpdateUserWeiXinUpdateTime(userWeixinDTO); | ||
1465 | 783 | ||
784 | UserWeixin userWeixin = new UserWeixin(); | ||
785 | BeanUtils.copyProperties(userWeixinDTO,userWeixin); | ||
1466 | 786 | ||
1467 | // 更新大屏信息 | 787 | this.userWeixinService.update(userWeixin); |
1468 | userTvDTO.setMemberCode(memberDTO.getCode()); | ||
1469 | this.doUpdateUserTv(userTvDTO); | ||
1470 | 788 | ||
789 | } | ||
1471 | 790 | ||
1472 | memberDTO.setPlatformAccount(platformAccount); | 791 | return userWeixinDTO; |
1473 | // 会员绑定大屏 | ||
1474 | this.bindIptvId(memberDTO,userTvDTO); | ||
1475 | 792 | ||
1476 | this.doUpdateMemberByMemberDTO(memberDTO); | ||
1477 | return true; | ||
1478 | } | 793 | } |
1479 | 794 | ||
1480 | /** | 795 | /** |
1481 | * 更新微信用户修改的时间 | 796 | * 修改微信公众号关注状态 |
1482 | * @param userWeixinDTO | 797 | * @param status 0:取消关注 1:关注 |
1483 | */ | 798 | */ |
1484 | private void doUpdateUserWeiXinUpdateTime(UserWeixinDTO userWeixinDTO) { | 799 | private UserWeixinDTO doUpdateUserWeiXinStatus(UserWeixinDTO userWeixinDTO, Integer status) { |
1485 | UserWeixin userWeixin = new UserWeixin(); | ||
1486 | userWeixin.setAppid(userWeixinDTO.getAppid()); | ||
1487 | userWeixin.setOpenid(userWeixinDTO.getOpenid()); | ||
1488 | userWeixin.setUpdateTime(TimestampUtil.now()); | ||
1489 | this.userWeixinService.updateTime(userWeixin); | ||
1490 | } | ||
1491 | 800 | ||
1492 | @Override | 801 | userWeixinDTO.setStatus(status); |
1493 | public JSONObject getUnionIdByAppIdAndOpenId(String appId,String secret,String code) { | ||
1494 | // 链接微信服务器 | ||
1495 | String url = WeChatConstants.CODE2SESSION.replace("APPID", appId) | ||
1496 | .replace("SECRET", secret).replace("JSCODE", code); | ||
1497 | 802 | ||
1498 | String entityBody = HttpUtil.get(url); | 803 | UserWeixin userWeixin = new UserWeixin(); |
804 | BeanUtils.copyProperties(userWeixinDTO,userWeixin); | ||
1499 | 805 | ||
1500 | JSONObject jsonObject = JSONObject.parseObject(entityBody); | 806 | this.userWeixinService.update(userWeixin); |
1501 | 807 | ||
1502 | String errCode = jsonObject.getString("errcode"); | ||
1503 | 808 | ||
1504 | if (StringUtils.isNotEmpty(errCode)) { | 809 | return userWeixinDTO; |
1505 | String nameStr = jsonObject.getString("errmsg"); | ||
1506 | throw new BadRequestException(nameStr); | ||
1507 | } | ||
1508 | 810 | ||
1509 | return jsonObject; | ||
1510 | } | 811 | } |
1511 | 812 | ||
1512 | @Override | 813 | /** |
1513 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | 814 | * 获取会员 |
1514 | public UserWeixinDTO createWeixinUserAndCreateMember(UserWeixin resources) { | 815 | * @param memberId |
816 | * @return | ||
817 | */ | ||
818 | private MemberDTO findMemberById(Long memberId) { | ||
819 | MemberDTO memberDTO = this.memberService.findById(memberId); | ||
820 | return memberDTO; | ||
821 | } | ||
1515 | 822 | ||
1516 | String appId = resources.getAppid(); | 823 | /** |
1517 | String openId = resources.getOpenid(); | 824 | * |
1518 | String unionId = resources.getUnionid(); | 825 | * @param userWeixinDTO |
826 | * @param appId | ||
827 | * @param openId | ||
828 | */ | ||
829 | private void doUpdateUserWeiXinAndMember(UserWeixinDTO userWeixinDTO,String appId,String openId,String headImgUrl,String nickName) { | ||
1519 | 830 | ||
1520 | // 检查账户是否存在 | 831 | // 修改微信账户关注状态 |
1521 | UserWeixinDTO userWeixinDTO = this.findFirstByUnionIdAndAppIdAndOpenId(unionId,appId, openId); | 832 | this.doUpdateUserWeiXinStatus(userWeixinDTO,SUBSCRIBE_STATUS); |
1522 | if (Objects.nonNull(userWeixinDTO.getId())) | ||
1523 | return userWeixinDTO; | ||
1524 | 833 | ||
1525 | // 当前用户的任意微信app | 834 | // 小屏会员 |
1526 | UserWeixinDTO userWeixinDTO1 = this.findFirstByUnionId(unionId); | 835 | MemberDTO memberDTO_0 = this.findMemberByAppIdAndOpenId(appId,openId); |
1527 | 836 | ||
1528 | Long memberId = null; | 837 | if (StringUtils.isNotBlank(headImgUrl) && StringUtils.isNotBlank(nickName)) { |
1529 | Integer vip = 0; | 838 | memberDTO_0.setAvatarUrl(headImgUrl); |
1530 | if (Objects.nonNull(userWeixinDTO1.getId()) && Objects.nonNull(userWeixinDTO1.getMemberId())) { | 839 | memberDTO_0.setNickname(nickName); |
840 | } | ||
1531 | 841 | ||
1532 | memberId = userWeixinDTO1.getMemberId(); | 842 | this.doUpdateMemberVip(memberDTO_0,1); |
843 | } | ||
1533 | 844 | ||
1534 | } else { | 845 | /** |
846 | * 获取小屏会员 | ||
847 | * @param appId | ||
848 | * @param openId | ||
849 | * @return | ||
850 | */ | ||
851 | private MemberDTO findMemberByAppIdAndOpenId(String appId, String openId) { | ||
852 | UserWeixinDTO userWeixinDTO = this.userWeixinService.findFirstByAppIdAndOpenId(appId,openId); | ||
853 | if (Objects.nonNull(userWeixinDTO)) { | ||
854 | Long memberId = userWeixinDTO.getMemberId(); | ||
855 | return this.findMemberById(memberId); | ||
856 | } | ||
857 | return null; | ||
858 | } | ||
1535 | 859 | ||
1536 | userWeixinDTO1 = new UserWeixinDTO(); | 860 | /** |
1537 | BeanUtils.copyProperties(resources,userWeixinDTO1); | 861 | * |
862 | * @param memberCode | ||
863 | * @return | ||
864 | */ | ||
865 | private UserTvDTO findByPriorityMemberCode(String memberCode) { | ||
866 | UserTvDTO userTvDTO = this.userTvService.findByPriorityMemberCode(memberCode); | ||
867 | return userTvDTO; | ||
868 | } | ||
1538 | 869 | ||
1539 | // 创建会员 | 870 | /** |
1540 | memberId = this.doCreateMember(userWeixinDTO1,vip); | 871 | * 设置主会员 |
872 | * @description 检查大屏账户有没有绑定小屏会员,如果没有绑定就将当前会员的code保存到大屏账户中 | ||
873 | * @param userTvDTO | ||
874 | * @param memberCode | ||
875 | * @param auto manual:手动 auto:自动 | ||
876 | */ | ||
877 | private void bondPriorityMember(UserTvDTO userTvDTO, String memberCode,String auto) { | ||
1541 | 878 | ||
879 | if (auto.equalsIgnoreCase("auto")) { | ||
880 | // 主账户 | ||
881 | String priorityMemberCode = userTvDTO.getPriorityMemberCode(); | ||
882 | if (StringUtils.isNotEmpty(priorityMemberCode)) { | ||
883 | return; | ||
884 | } | ||
1542 | } | 885 | } |
1543 | 886 | ||
1544 | userWeixinDTO1.setId(null); | 887 | userTvDTO.setPriorityMemberCode(memberCode); |
1545 | userWeixinDTO1.setAppid(appId); | ||
1546 | userWeixinDTO1.setOpenid(openId); | ||
1547 | userWeixinDTO1.setUnionid(unionId); | ||
1548 | log.info("createWeixinUserAndCreateMember ==>> [{}]",userWeixinDTO1); | ||
1549 | // 保存微信账户 | ||
1550 | userWeixinDTO1 = this.doCreateUserWeiXin(userWeixinDTO1,memberId); | ||
1551 | |||
1552 | log.info("userWeixinDTO1 ==>> [{}]",userWeixinDTO1); | ||
1553 | 888 | ||
1554 | MemberProfileDTO memberProfileDTO = this.memberProfileService.findByMemberId(memberId); | 889 | UserTv userTv = new UserTv(); |
1555 | if (Objects.isNull(memberProfileDTO)) | 890 | BeanUtils.copyProperties(userTvDTO,userTv); |
1556 | // 创建会员属性信息 | 891 | this.userTvService.update(userTv); |
1557 | this.createMemberProfile(userWeixinDTO1); | ||
1558 | 892 | ||
1559 | return userWeixinDTO1; | ||
1560 | } | 893 | } |
1561 | 894 | ||
1562 | @Override | 895 | /** |
1563 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | 896 | * 置空主账号 |
1564 | public void bind(String memberCode, String platformAccount) { | 897 | * @param memberCode |
1565 | MemberDTO memberDTO = this.memberService.findByCode(memberCode); | 898 | */ |
1566 | this.bind(memberDTO,platformAccount); | 899 | private void resetMainAccount(String memberCode) { |
1567 | } | 900 | UserTvDTO userTvDTO = this.userTvService.findByPriorityMemberCode(memberCode); |
901 | if (Objects.nonNull(userTvDTO)) { | ||
902 | userTvDTO.setPriorityMemberCode(null); | ||
1568 | 903 | ||
1569 | @Override | 904 | UserTv userTv = new UserTv(); |
1570 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | 905 | BeanUtils.copyProperties(userTvDTO,userTv); |
1571 | public void bind(MemberDTO memberDTO, UserTvDTO userTvDTO) { | 906 | |
1572 | String platformAccount = userTvDTO.getPlatformAccount(); | 907 | this.userTvService.unbindPriorityMemberCode(userTv); |
1573 | // 绑定 | 908 | } |
1574 | this.bind(memberDTO,platformAccount); | ||
1575 | } | 909 | } |
1576 | 910 | ||
1577 | @Override | 911 | /** |
1578 | public UserTvDTO bind(MemberDTO memberDTO, String platformAccount) { | 912 | * 解绑(置空大屏信息) |
913 | * @param memberDTOS | ||
914 | */ | ||
915 | private void resetIptvColumn(MemberDTO memberDTOS) { | ||
916 | // 若无关系,不做处理 | ||
917 | if (Objects.nonNull(memberDTOS)) | ||
918 | return; | ||
1579 | 919 | ||
1580 | MemberDTO memberDTO1 = this.memberService.findByCode(memberDTO.getCode()); | 920 | Member member = new Member(); |
1581 | if (Objects.nonNull(memberDTO1.getUserIptvId())) { | 921 | memberDTOS.setBindIptvTime(null); |
1582 | UserTvDTO userTvDTO = this.userTvService.findById(memberDTO1.getUserIptvId()); | 922 | memberDTOS.setUserIptvId(null); |
1583 | return userTvDTO; | 923 | memberDTOS.setBindIptvPlatformType(null); |
924 | BeanUtils.copyProperties(memberDTOS, member); | ||
925 | this.memberService.update(member); | ||
1584 | } | 926 | } |
1585 | 927 | ||
1586 | // 大屏账户 | 928 | /** |
1587 | UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); | 929 | * |
1588 | if (Objects.isNull(userTvDTO)) { | 930 | * @param memberCode 会员编码 |
1589 | throw new BadRequestException("大屏信息不存在!"); | 931 | * @return |
932 | */ | ||
933 | private MemberDTO findMemberByCode(String memberCode) { | ||
934 | MemberDTO memberDTO = memberService.findByCode(memberCode); | ||
935 | return memberDTO; | ||
1590 | } | 936 | } |
1591 | 937 | ||
1592 | // mq同步数据时使用 | 938 | /** |
1593 | memberDTO.setPlatformAccount(platformAccount); | 939 | * 修改会员 |
1594 | 940 | * @param memberDTO | |
1595 | // 大屏是否绑定主账号,如果绑定了主账户则不操作大屏账户表 | 941 | */ |
1596 | this.bondPriorityMember(userTvDTO,memberDTO,"auto"); | 942 | private void doUpdateMemberByMemberDTO(MemberDTO memberDTO){ |
943 | Member member = new Member(); | ||
944 | BeanUtils.copyProperties(memberDTO,member); | ||
945 | member.setUpdateTime(LocalDateTime.now()); | ||
946 | log.info("doUpdateMemberByMemberDTO=====?>>member ==>> [{}]",member); | ||
947 | this.doUpdateMember(member); | ||
948 | } | ||
1597 | 949 | ||
1598 | // 构建小屏会员对象,绑定user_iptv_id字段 | 950 | /** |
1599 | MemberDTO memberDTO0 = this.bindIptvId(memberDTO,userTvDTO); | 951 | * 修改会员 |
952 | * @param member | ||
953 | */ | ||
954 | private void doUpdateMember(Member member){ | ||
955 | this.memberService.update(member); | ||
956 | } | ||
1600 | 957 | ||
1601 | // 修改会员 | ||
1602 | this.doUpdateMemberByMemberDTO(memberDTO0); | ||
1603 | 958 | ||
1604 | return null; | 959 | /** |
960 | * 更新微信用户修改的时间 | ||
961 | * @param userWeixinDTO | ||
962 | */ | ||
963 | private void doUpdateUserWeiXinUpdateTime(UserWeixinDTO userWeixinDTO) { | ||
964 | UserWeixin userWeixin = new UserWeixin(); | ||
965 | userWeixin.setAppid(userWeixinDTO.getAppid()); | ||
966 | userWeixin.setOpenid(userWeixinDTO.getOpenid()); | ||
967 | userWeixin.setUpdateTime(TimestampUtil.now()); | ||
968 | this.userWeixinService.updateTime(userWeixin); | ||
1605 | } | 969 | } |
1606 | 970 | ||
1607 | /** | 971 | /** |
1608 | * | 972 | * |
1609 | * @param userWeixinDTO1 | 973 | * @param unionId |
974 | * @return | ||
1610 | */ | 975 | */ |
1611 | private void createMemberProfile(UserWeixinDTO userWeixinDTO1) { | ||
1612 | Long memberId = userWeixinDTO1.getMemberId(); | ||
1613 | String nickname = userWeixinDTO1.getNickname(); | ||
1614 | Integer sex = userWeixinDTO1.getGender(); | ||
1615 | MemberProfile memberProfile = MemberProfileBuild.build(memberId, nickname, sex, null); | ||
1616 | this.memberProfileService.create(memberProfile); | ||
1617 | } | ||
1618 | |||
1619 | private UserWeixinDTO findFirstByUnionId(String unionId) { | 976 | private UserWeixinDTO findFirstByUnionId(String unionId) { |
1620 | return this.userWeixinService.findFirstByUnionId(unionId); | 977 | return this.userWeixinService.findFirstByUnionId(unionId); |
1621 | } | 978 | } |
... | @@ -1690,52 +1047,61 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -1690,52 +1047,61 @@ public class UserOperationServiceImpl implements UserOperationService { |
1690 | } | 1047 | } |
1691 | 1048 | ||
1692 | /** | 1049 | /** |
1693 | * 保存、修改会员加密信息 | 1050 | * 获取小屏账户 |
1694 | * @param resources | 1051 | * @param unionId |
1052 | * @param appId | ||
1053 | * @param openId | ||
1695 | * @return | 1054 | * @return |
1696 | */ | 1055 | */ |
1697 | private MemberProfile doSaveOrUpdateMemberProfile(DefaultWeiXinBeanDefinition resources,WeiXinUserBean weiXinUserBean) { | 1056 | private UserWeixinDTO findFirstByUnionIdAndAppIdAndOpenId( String unionId,String appId, String openId) { |
1698 | 1057 | return this.userWeixinService.findFirstByUnionIdAndAppIdAndOpenId(unionId,appId,openId); | |
1699 | // 会员 | ||
1700 | MemberDTO memberDTO = this.findMemberById(weiXinUserBean.getMemberId()); | ||
1701 | |||
1702 | if (Objects.nonNull(memberDTO)) { | ||
1703 | |||
1704 | Long memberId = memberDTO.getId(); | ||
1705 | |||
1706 | // 会员加密信息 | ||
1707 | MemberProfileDTO memberProfileDTO = this.findMemberProfileByMemberId(memberId); | ||
1708 | |||
1709 | MemberProfile memberProfile = new MemberProfile(); | ||
1710 | if (Objects.nonNull(memberProfileDTO)) { | ||
1711 | BeanUtils.copyProperties(memberProfileDTO , memberProfile); | ||
1712 | } | 1058 | } |
1713 | 1059 | ||
1714 | memberProfile.setMemberId(memberId); | 1060 | /** |
1715 | memberProfile.setPhone(resources.getPhoneNumber()); | 1061 | * |
1716 | 1062 | * @param member | |
1717 | // 保存、更新会员加密信息 | 1063 | * @return |
1718 | MemberProfile memberProfile1 = this.saveMemberProfile(memberProfile); | 1064 | */ |
1719 | 1065 | private Long createMember(Member member){ | |
1720 | return memberProfile1; | 1066 | return this.memberService.create(member); |
1721 | |||
1722 | } | 1067 | } |
1723 | 1068 | ||
1724 | return null; | 1069 | /** |
1725 | 1070 | * | |
1726 | } | 1071 | * @param resources |
1072 | * @param member | ||
1073 | * @return | ||
1074 | */ | ||
1075 | private UserTv createTvUser(UserTvDTO resources,Member member){ | ||
1727 | 1076 | ||
1728 | private MemberProfileDTO findMemberProfileByMemberId(Long memberId) { | 1077 | if (member != null) { |
1729 | MemberProfileDTO memberProfileDTO = this.memberProfileService.findByMemberId(memberId); | 1078 | Long memberId = this.createMember(member); |
1730 | return memberProfileDTO; | 1079 | resources.setMemberId(memberId); |
1731 | } | 1080 | } |
1732 | 1081 | ||
1733 | private MemberProfile saveMemberProfile(MemberProfile memberProfile) { | 1082 | UserTv _userTv = new UserTv(); |
1734 | return this.memberProfileService.create(memberProfile); | 1083 | BeanUtils.copyProperties(resources,_userTv); |
1084 | return this.userTvService.create(_userTv); | ||
1735 | } | 1085 | } |
1736 | 1086 | ||
1087 | /** | ||
1088 | * | ||
1089 | * @param userWeixinDTO | ||
1090 | * @param member | ||
1091 | * @return | ||
1092 | */ | ||
1093 | private UserWeixin createWeixinUser(UserWeixinDTO userWeixinDTO,Member member){ | ||
1737 | 1094 | ||
1095 | if (member != null) { | ||
1096 | // 创建会员 | ||
1097 | Long memberId = this.createMember(member); | ||
1098 | userWeixinDTO.setMemberId(memberId); | ||
1099 | } | ||
1738 | 1100 | ||
1101 | UserWeixin _userWeixin = new UserWeixin(); | ||
1102 | BeanUtils.copyProperties(userWeixinDTO,_userWeixin); | ||
1739 | 1103 | ||
1104 | return this.userWeixinService.create(_userWeixin); | ||
1105 | } | ||
1740 | 1106 | ||
1741 | } | 1107 | } | ... | ... |
1 | package com.topdraw.exception; | ||
2 | |||
3 | /** | ||
4 | * @author : | ||
5 | * @description: | ||
6 | * @function : | ||
7 | * @date :Created in 2022/3/10 17:16 | ||
8 | * @version: : | ||
9 | * @modified By: | ||
10 | * @since : modified in 2022/3/10 17:16 | ||
11 | */ | ||
12 | public interface GlobeExceptionMsg { | ||
13 | |||
14 | /**************************************************************/ | ||
15 | /** 系统 */ | ||
16 | String OPERATION_FORBID = "operation forbid"; | ||
17 | String ENTITY_ALREADY_EXISTS = "entity already exists"; | ||
18 | |||
19 | /**************************************************************/ | ||
20 | |||
21 | /** 会员管理 */ | ||
22 | String MEMBER_CODE_IS_NULL = "memberCode is null"; | ||
23 | String MEMBER_ID_IS_NULL = "memberId is null"; | ||
24 | String MEMBER_ID_AND_CODE_ARE_NULL = "memberId and memberCode both null"; | ||
25 | String MEMBER_INFO_ERROR = "member info is error"; | ||
26 | String MEMBER_BLOCK_STATUS = "member status is block"; | ||
27 | |||
28 | /**************************************************************/ | ||
29 | |||
30 | /** 账户管理 **/ | ||
31 | String IPTV_ID_IS_NULL = "iptvId is null"; | ||
32 | String IPTV_PLATFORM_ACCOUNT_IS_NULL = "platformAccount is null"; | ||
33 | String IPTV_IS_NULL = "iptv is null"; | ||
34 | |||
35 | } |
member-service-impl/src/main/java/com/topdraw/resttemplate/RestTemplateClient.java
deleted
100644 → 0
1 | package com.topdraw.resttemplate; | ||
2 | |||
3 | import com.alibaba.fastjson.JSONObject; | ||
4 | import com.topdraw.business.module.member.address.domain.MemberAddress; | ||
5 | import com.topdraw.business.module.member.domain.Member; | ||
6 | import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo; | ||
7 | import lombok.extern.slf4j.Slf4j; | ||
8 | import org.springframework.beans.factory.annotation.Autowired; | ||
9 | import org.springframework.core.env.Environment; | ||
10 | import org.springframework.http.ResponseEntity; | ||
11 | import org.springframework.http.client.SimpleClientHttpRequestFactory; | ||
12 | import org.springframework.stereotype.Component; | ||
13 | import org.springframework.web.client.RestTemplate; | ||
14 | |||
15 | import javax.annotation.PostConstruct; | ||
16 | import java.util.Map; | ||
17 | |||
18 | @Slf4j | ||
19 | @Component | ||
20 | public class RestTemplateClient { | ||
21 | |||
22 | private static RestTemplate restTemplate; | ||
23 | |||
24 | private static String BASE_URL; | ||
25 | |||
26 | @Autowired | ||
27 | private Environment environment; | ||
28 | |||
29 | @PostConstruct | ||
30 | private void init() { | ||
31 | BASE_URL = environment.getProperty("api.baseUrl"); | ||
32 | SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); | ||
33 | // 设置连接超时 | ||
34 | factory.setConnectTimeout(5000); | ||
35 | // 设置读取超时 | ||
36 | factory.setReadTimeout(8000); | ||
37 | restTemplate = new RestTemplate(factory); | ||
38 | } | ||
39 | |||
40 | public static JSONObject getMemberInfo(Long memberId) { | ||
41 | JSONObject resultSet = null; | ||
42 | String url = BASE_URL + "/api/member/findById/" + memberId; | ||
43 | log.info("request uc : url is " + url + ", memberId is " + memberId); | ||
44 | ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class); | ||
45 | if (responseEntity.getStatusCode().is2xxSuccessful()) { | ||
46 | String entityBody = responseEntity.getBody(); | ||
47 | JSONObject jsonObject = JSONObject.parseObject(entityBody); | ||
48 | if (jsonObject.getInteger("businessCode").equals(200)) { | ||
49 | resultSet = jsonObject.getJSONArray("resultSet").getJSONObject(0); | ||
50 | } | ||
51 | } | ||
52 | log.info("uc response: " + resultSet.toJSONString()); | ||
53 | return resultSet; | ||
54 | } | ||
55 | |||
56 | public static String createMember(Member member) { | ||
57 | String entityBody = ""; | ||
58 | String url = BASE_URL + "/api/member/create"; | ||
59 | log.info("request uc : url is " + url + ", memberId is " + com.alibaba.fastjson.JSONObject.toJSONString(member)); | ||
60 | ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, member, String.class); | ||
61 | if (responseEntity.getStatusCode().is2xxSuccessful()) { | ||
62 | entityBody = responseEntity.getBody(); | ||
63 | |||
64 | } | ||
65 | return entityBody; | ||
66 | } | ||
67 | |||
68 | public static String updateMember(Member member) { | ||
69 | String entityBody = ""; | ||
70 | String url = BASE_URL + "/api/member/update"; | ||
71 | log.info("request uc : url is " + url + ", memberId is " + com.alibaba.fastjson.JSONObject.toJSONString(member)); | ||
72 | restTemplate.put(url, member); | ||
73 | |||
74 | return entityBody; | ||
75 | } | ||
76 | |||
77 | public static String createMemberAddress(MemberAddress member) { | ||
78 | JSONObject resultSet = null; | ||
79 | String url = BASE_URL + "/api/MemberAddress/create"; | ||
80 | log.info("request uc : url is " + url + ", memberId is " + com.alibaba.fastjson.JSONObject.toJSONString(member)); | ||
81 | ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, member, String.class); | ||
82 | String entityBody = ""; | ||
83 | if (responseEntity.getStatusCode().is2xxSuccessful()) { | ||
84 | entityBody = responseEntity.getBody(); | ||
85 | } | ||
86 | log.info("uc response: " + entityBody); | ||
87 | return entityBody; | ||
88 | } | ||
89 | |||
90 | public static void updateMemberAddress(MemberAddress member) { | ||
91 | String url = BASE_URL + "/api/MemberAddress/update"; | ||
92 | log.info("request uc : url is " + url + ", memberId is " + com.alibaba.fastjson.JSONObject.toJSONString(member)); | ||
93 | restTemplate.put(url, member); | ||
94 | |||
95 | } | ||
96 | |||
97 | public static void deleteMemberAddress(Long id) { | ||
98 | String url = BASE_URL + "/api/MemberAddress/delete/" + id; | ||
99 | log.info("request uc : url is " + url + ", memberId is " + id); | ||
100 | restTemplate.delete(url); | ||
101 | |||
102 | } | ||
103 | |||
104 | public static JSONObject getMemberProfile(Long memberId) { | ||
105 | JSONObject resultSet = null; | ||
106 | String url = BASE_URL + "/api/MemberRelatedInfo/getMemberRelatedInfos"; | ||
107 | log.info("request uc : url is " + url + ", memberId is " + memberId); | ||
108 | ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class); | ||
109 | if (responseEntity.getStatusCode().is2xxSuccessful()) { | ||
110 | String entityBody = responseEntity.getBody(); | ||
111 | JSONObject jsonObject = JSONObject.parseObject(entityBody); | ||
112 | if (jsonObject.getInteger("businessCode").equals(200)) { | ||
113 | resultSet = jsonObject.getJSONArray("resultSet").getJSONObject(0); | ||
114 | } | ||
115 | } | ||
116 | log.info("uc response: " + resultSet.toJSONString()); | ||
117 | return resultSet; | ||
118 | } | ||
119 | |||
120 | public static String getMemberAddress(Map<String, Object> param) { | ||
121 | String entityBody = ""; | ||
122 | String url = BASE_URL + "/api/MemberAddress/pageMemberAddress?page=" + param.get("page") + "&size=" + param.get("size") + "&memberId=" + param.get("memberId"); | ||
123 | log.info("request uc : url is " + url + ", param is " + param); | ||
124 | ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class); | ||
125 | if (responseEntity.getStatusCode().is2xxSuccessful()) { | ||
126 | entityBody = responseEntity.getBody(); | ||
127 | } | ||
128 | log.info("uc response: " + entityBody); | ||
129 | return entityBody; | ||
130 | } | ||
131 | |||
132 | public static String getMemberRelatedInfo(Map<String, Object> param) { | ||
133 | String entityBody = ""; | ||
134 | String url = BASE_URL + "/api/MemberRelatedInfo/pageMemberRelatedInfos?page=" + param.get("page") + "&size=" + param.get("size") + "&memberId=" + param.get("memberId"); | ||
135 | log.info("request uc : url is " + url + ", memberId is " + param); | ||
136 | ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class); | ||
137 | if (responseEntity.getStatusCode().is2xxSuccessful()) { | ||
138 | entityBody = responseEntity.getBody(); | ||
139 | } | ||
140 | log.info("uc response: " + entityBody); | ||
141 | return entityBody; | ||
142 | } | ||
143 | |||
144 | public static void deleteMemberRelatedInfo(Long memberRelatedId) { | ||
145 | String url = BASE_URL + "/api/MemberRelatedInfo/delete/" + memberRelatedId; | ||
146 | log.info("request uc : url is " + url + ", memberId is " + memberRelatedId); | ||
147 | restTemplate.delete(url, String.class); | ||
148 | } | ||
149 | |||
150 | public static String addMemberRelatedInfo(MemberRelatedInfo resources) { | ||
151 | String entityBody = null; | ||
152 | String url = BASE_URL + "/api/MemberRelatedInfo/create"; | ||
153 | log.info("request uc : url is " + url + ", memberRelatedId is " + com.alibaba.fastjson.JSONObject.toJSONString(resources)); | ||
154 | ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, resources, String.class); | ||
155 | if (responseEntity.getStatusCode().is2xxSuccessful()) { | ||
156 | entityBody = responseEntity.getBody(); | ||
157 | // JSONObject jsonObject = JSONObject.parseObject(entityBody); | ||
158 | // if (jsonObject.getInteger("businessCode").equals(200)) { | ||
159 | // resultSet = jsonObject.getJSONArray("resultSet").getJSONObject(0); | ||
160 | // } | ||
161 | } | ||
162 | log.info("uc response: " + entityBody); | ||
163 | return entityBody; | ||
164 | } | ||
165 | |||
166 | public static String updateMemberRelatedInfo(MemberRelatedInfo resources) { | ||
167 | String resultSet = ""; | ||
168 | String url = BASE_URL + "/api/MemberRelatedInfo/update"; | ||
169 | log.info("request uc : url is " + url + ", memberRelatedId is " + com.alibaba.fastjson.JSONObject.toJSONString(resources)); | ||
170 | restTemplate.put(url, resources); | ||
171 | |||
172 | return resultSet; | ||
173 | } | ||
174 | } |
member-service-impl/src/main/java/com/topdraw/weixin/applet/WeiXinAppletUserParser.java
deleted
100644 → 0
1 | package com.topdraw.weixin.applet; | ||
2 | |||
3 | import cn.hutool.http.HttpUtil; | ||
4 | import com.alibaba.fastjson.JSONObject; | ||
5 | import com.topdraw.business.process.domian.weixin.WeiXinUserBean; | ||
6 | import com.topdraw.security.AESUtil; | ||
7 | import com.topdraw.utils.StringUtils; | ||
8 | import com.topdraw.weixin.beans.DefaultWeiXinBeanDefinition; | ||
9 | import com.topdraw.weixin.beans.WeiXinUserParser; | ||
10 | import com.topdraw.weixin.beans.config.WeiXinAppListConfig; | ||
11 | import com.topdraw.weixin.util.WeChatConstants; | ||
12 | import com.topdraw.weixin.util.WeiXinRequestUtil; | ||
13 | import org.springframework.beans.factory.annotation.Autowired; | ||
14 | import org.springframework.beans.factory.annotation.Value; | ||
15 | import org.springframework.http.HttpMethod; | ||
16 | import org.springframework.http.ResponseEntity; | ||
17 | import org.springframework.stereotype.Component; | ||
18 | import org.springframework.web.client.RestTemplate; | ||
19 | |||
20 | import java.util.List; | ||
21 | import java.util.Map; | ||
22 | import java.util.Optional; | ||
23 | |||
24 | @Component | ||
25 | public class WeiXinAppletUserParser implements WeiXinUserParser { | ||
26 | |||
27 | @Autowired | ||
28 | private WeiXinAppListConfig weiXinAppListConfig; | ||
29 | |||
30 | @Autowired | ||
31 | private WeiXinRequestUtil weixinRequestUtil; | ||
32 | |||
33 | @Value("${uc.service.platform:}") | ||
34 | private String platform; | ||
35 | |||
36 | @Value("${key:}") | ||
37 | private String key; | ||
38 | |||
39 | @Value("${uc.app.subAppId:wx05f35931270014be}") | ||
40 | private String subAppId; | ||
41 | |||
42 | @Value("${uc.app.h5AppId:wxca962918dfeed88c}") | ||
43 | private String h5AppId; | ||
44 | |||
45 | @Value("${uc.app.appletAppid:wxc57d42de3d351cec}") | ||
46 | private String appletAppid; | ||
47 | |||
48 | @Value("${file.upload:upload}") | ||
49 | private String filePath; | ||
50 | |||
51 | @Override | ||
52 | public DefaultWeiXinBeanDefinition parse(WeiXinUserBean resources) { | ||
53 | String key = this.key; | ||
54 | Map<String, String> weixinInfoMap = null; | ||
55 | String appId = resources.getWxAppid(); | ||
56 | String code = resources.getWxCode(); | ||
57 | String userInfo = null; | ||
58 | |||
59 | if (StringUtils.isNotBlank(appId)) { | ||
60 | |||
61 | String decrypt = AESUtil.decrypt(appId, key); | ||
62 | |||
63 | if (decrypt != null) { | ||
64 | appId = decrypt.substring(16); | ||
65 | } | ||
66 | |||
67 | weixinInfoMap = getWeixinInfoByAppid(appId); | ||
68 | } | ||
69 | |||
70 | if (StringUtils.isNotBlank(code)) { | ||
71 | String decrypt = AESUtil.decrypt(code, key); | ||
72 | if (decrypt != null) { | ||
73 | code = decrypt.substring(16); | ||
74 | } | ||
75 | } | ||
76 | |||
77 | if (StringUtils.isNotBlank(userInfo)) { | ||
78 | String decrypt = AESUtil.decrypt(userInfo, key); | ||
79 | if (decrypt != null) { | ||
80 | userInfo = decrypt.substring(16); | ||
81 | } | ||
82 | } | ||
83 | |||
84 | return this.generateWeiXinBeanDefinition(code,userInfo,weixinInfoMap); | ||
85 | } | ||
86 | |||
87 | /** | ||
88 | * | ||
89 | * @param code | ||
90 | * @param userInfo | ||
91 | * @param weixinInfoMap | ||
92 | * @return | ||
93 | */ | ||
94 | private DefaultWeiXinBeanDefinition generateWeiXinBeanDefinition(String code, String userInfo, Map<String, String> weixinInfoMap) { | ||
95 | String appId = weixinInfoMap.get("appid"); | ||
96 | String secret = weixinInfoMap.get("secret"); | ||
97 | JSONObject userInfoWxJo = null; | ||
98 | |||
99 | // 链接微信服务器 | ||
100 | /*ResponseEntity<String> responseEntity1 = null;*//*restTemplate.exchange(WeChatConstants.CODE2SESSION.replace("APPID", appId) | ||
101 | .replace("SECRET", secret).replace("JSCODE", code), | ||
102 | HttpMethod.GET, null, String.class);*//* | ||
103 | |||
104 | String entityBody1 = responseEntity1.getBody();*/ | ||
105 | |||
106 | String url = WeChatConstants.CODE2SESSION.replace("APPID", appId) | ||
107 | .replace("SECRET", secret).replace("JSCODE", code); | ||
108 | String entityBody = HttpUtil.get(url); | ||
109 | |||
110 | JSONObject jsonObject = JSONObject.parseObject(entityBody); | ||
111 | |||
112 | String openId = jsonObject.getString("openid"); | ||
113 | String unionId = jsonObject.getString("unionid"); | ||
114 | |||
115 | if (StringUtils.isEmpty(unionId)) { | ||
116 | try { | ||
117 | userInfoWxJo = this.weixinRequestUtil.getUserInfo(weixinInfoMap, openId,code); | ||
118 | } catch (Exception e) { | ||
119 | e.printStackTrace(); | ||
120 | } | ||
121 | } | ||
122 | |||
123 | if (StringUtils.isNotBlank(userInfo)) { | ||
124 | |||
125 | JSONObject userInfoJo = JSONObject.parseObject(userInfo); | ||
126 | String encryptedData = userInfoJo.getString("encryptedData"); | ||
127 | String iv = userInfoJo.getString("iv"); | ||
128 | String key = jsonObject.getString("session_key"); | ||
129 | String userInfoWeixin = AESUtil.decryptJsUserInfo(encryptedData, iv, key); | ||
130 | if (StringUtils.isNotEmpty(userInfoWeixin)) | ||
131 | userInfoWxJo = JSONObject.parseObject(userInfoWeixin); | ||
132 | } | ||
133 | |||
134 | DefaultWeiXinBeanDefinition weiXinBeanDefinition = | ||
135 | new DefaultWeiXinBeanDefinition(appId,code,unionId,openId,userInfoWxJo,null); | ||
136 | return weiXinBeanDefinition; | ||
137 | } | ||
138 | |||
139 | /** | ||
140 | * | ||
141 | * @param appid | ||
142 | * @return | ||
143 | */ | ||
144 | private Map<String, String> getWeixinInfoByAppid(String appid) { | ||
145 | if (StringUtils.isBlank(appid)) { | ||
146 | throw new RuntimeException("wxAppid can not be null"); | ||
147 | } | ||
148 | List<Map<String, String>> list = this.weiXinAppListConfig.getList(); | ||
149 | Optional<Map<String, String>> weixinInfoOptional = list.stream().filter(o -> o.get("appid").equals(appid)).findFirst(); | ||
150 | if (!weixinInfoOptional.isPresent()) { | ||
151 | throw new RuntimeException("wxAppid error, appid is : " + appid); | ||
152 | } | ||
153 | return weixinInfoOptional.get(); | ||
154 | } | ||
155 | |||
156 | } |
... | @@ -3,13 +3,10 @@ package com.topdraw.test.business.basicdata.member.rest; | ... | @@ -3,13 +3,10 @@ package com.topdraw.test.business.basicdata.member.rest; |
3 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
4 | import com.topdraw.business.module.member.address.domain.MemberAddress; | 4 | import com.topdraw.business.module.member.address.domain.MemberAddress; |
5 | import com.topdraw.business.module.member.address.rest.MemberAddressController; | 5 | import com.topdraw.business.module.member.address.rest.MemberAddressController; |
6 | import com.topdraw.business.module.member.address.service.dto.MemberAddressQueryCriteria; | ||
7 | import com.topdraw.common.ResultInfo; | 6 | import com.topdraw.common.ResultInfo; |
8 | import com.topdraw.BaseTest; | 7 | import com.topdraw.BaseTest; |
9 | import org.junit.Test; | 8 | import org.junit.Test; |
10 | import org.springframework.beans.factory.annotation.Autowired; | 9 | import org.springframework.beans.factory.annotation.Autowired; |
11 | import org.springframework.data.domain.PageRequest; | ||
12 | import org.springframework.data.domain.Pageable; | ||
13 | 10 | ||
14 | public class MemberAddressControllerTest extends BaseTest { | 11 | public class MemberAddressControllerTest extends BaseTest { |
15 | 12 | ... | ... |
... | @@ -51,7 +51,7 @@ public class MemberControllerTest extends BaseTest { | ... | @@ -51,7 +51,7 @@ public class MemberControllerTest extends BaseTest { |
51 | member.setUserIptvId(1L); | 51 | member.setUserIptvId(1L); |
52 | member.setBindIptvPlatformType(0); | 52 | member.setBindIptvPlatformType(0); |
53 | String s = JSON.toJSONString(member); | 53 | String s = JSON.toJSONString(member); |
54 | ResultInfo byId = this.memberController.update(member); | 54 | ResultInfo byId = null; |
55 | LOG.info("===>>>"+byId); | 55 | LOG.info("===>>>"+byId); |
56 | } | 56 | } |
57 | 57 | ||
... | @@ -79,7 +79,7 @@ public class MemberControllerTest extends BaseTest { | ... | @@ -79,7 +79,7 @@ public class MemberControllerTest extends BaseTest { |
79 | member.setBindIptvPlatformType(0); | 79 | member.setBindIptvPlatformType(0); |
80 | member.setUpdateTime(LocalDateTime.now()); | 80 | member.setUpdateTime(LocalDateTime.now()); |
81 | String s = JSON.toJSONString(member); | 81 | String s = JSON.toJSONString(member); |
82 | ResultInfo byId = this.memberController.create(member); | 82 | ResultInfo byId = null;//this.memberController.create(member); |
83 | LOG.info("===>>>"+byId); | 83 | LOG.info("===>>>"+byId); |
84 | } | 84 | } |
85 | 85 | ... | ... |
... | @@ -3,13 +3,10 @@ package com.topdraw.test.business.basicdata.member.rest; | ... | @@ -3,13 +3,10 @@ package com.topdraw.test.business.basicdata.member.rest; |
3 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
4 | import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo; | 4 | import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo; |
5 | import com.topdraw.business.module.member.relatedinfo.rest.MemberRelatedInfoController; | 5 | import com.topdraw.business.module.member.relatedinfo.rest.MemberRelatedInfoController; |
6 | import com.topdraw.business.module.member.relatedinfo.service.dto.MemberRelatedInfoQueryCriteria; | ||
7 | import com.topdraw.common.ResultInfo; | 6 | import com.topdraw.common.ResultInfo; |
8 | import com.topdraw.BaseTest; | 7 | import com.topdraw.BaseTest; |
9 | import org.junit.Test; | 8 | import org.junit.Test; |
10 | import org.springframework.beans.factory.annotation.Autowired; | 9 | import org.springframework.beans.factory.annotation.Autowired; |
11 | import org.springframework.data.domain.PageRequest; | ||
12 | import org.springframework.data.domain.Pageable; | ||
13 | 10 | ||
14 | import java.time.LocalDate; | 11 | import java.time.LocalDate; |
15 | 12 | ... | ... |
... | @@ -2,7 +2,7 @@ package com.topdraw.test.business.process.rest; | ... | @@ -2,7 +2,7 @@ package com.topdraw.test.business.process.rest; |
2 | 2 | ||
3 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
4 | import com.topdraw.business.process.rest.TaskOperationController; | 4 | import com.topdraw.business.process.rest.TaskOperationController; |
5 | import com.topdraw.business.process.rest.TaskOperationQueryCriteria; | 5 | import com.topdraw.business.process.service.dto.TaskOperationQueryCriteria; |
6 | import com.topdraw.module.mq.DataSyncMsg; | 6 | import com.topdraw.module.mq.DataSyncMsg; |
7 | import com.topdraw.module.mq.EventType; | 7 | import com.topdraw.module.mq.EventType; |
8 | import com.topdraw.BaseTest; | 8 | import com.topdraw.BaseTest; | ... | ... |
-
Please register or sign in to post a comment