1.优化
Showing
3 changed files
with
141 additions
and
9 deletions
| ... | @@ -13,6 +13,8 @@ import java.sql.Timestamp; | ... | @@ -13,6 +13,8 @@ import java.sql.Timestamp; |
| 13 | @Data | 13 | @Data |
| 14 | public class UserWeixinDTO implements Serializable { | 14 | public class UserWeixinDTO implements Serializable { |
| 15 | 15 | ||
| 16 | private String memberCode; | ||
| 17 | |||
| 16 | /** ID */ | 18 | /** ID */ |
| 17 | private Long id; | 19 | private Long id; |
| 18 | 20 | ... | ... |
| ... | @@ -13,6 +13,8 @@ import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; | ... | @@ -13,6 +13,8 @@ import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; |
| 13 | import com.topdraw.business.process.service.UserOperationService; | 13 | import com.topdraw.business.process.service.UserOperationService; |
| 14 | import com.topdraw.business.process.service.dto.MemberAndUserTvDTO; | 14 | import com.topdraw.business.process.service.dto.MemberAndUserTvDTO; |
| 15 | import com.topdraw.business.process.service.dto.MemberAndWeixinUserDTO; | 15 | import com.topdraw.business.process.service.dto.MemberAndWeixinUserDTO; |
| 16 | import com.topdraw.exception.EntityNotFoundException; | ||
| 17 | import com.topdraw.exception.GlobeExceptionMsg; | ||
| 16 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
| 17 | import org.apache.commons.lang3.StringUtils; | 19 | import org.apache.commons.lang3.StringUtils; |
| 18 | import org.springframework.beans.BeanUtils; | 20 | import org.springframework.beans.BeanUtils; |
| ... | @@ -54,13 +56,24 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -54,13 +56,24 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 54 | 56 | ||
| 55 | } else { | 57 | } else { |
| 56 | 58 | ||
| 59 | // 会员不存在 | ||
| 57 | MemberDTO memberDTO = memberAndWeixinUserDTO.getMemberDTO(); | 60 | MemberDTO memberDTO = memberAndWeixinUserDTO.getMemberDTO(); |
| 58 | MemberDTO _memberDTO = this.createMember(memberDTO); | 61 | MemberDTO _memberDTO = this.createMember(memberDTO); |
| 62 | |||
| 59 | userWeixinDTO.setMemberId(_memberDTO.getId()); | 63 | userWeixinDTO.setMemberId(_memberDTO.getId()); |
| 60 | this.createWeixin(userWeixinDTO); | 64 | this.createWeixin(userWeixinDTO); |
| 61 | 65 | ||
| 62 | } | 66 | } |
| 63 | 67 | ||
| 68 | } else { | ||
| 69 | |||
| 70 | // 账号存在,修改账号和会员 | ||
| 71 | this.updateWeixin(_userWeixinDTO, userWeixinDTO); | ||
| 72 | MemberDTO _memberDTO = this.memberService.findById(_userWeixinDTO.getMemberId()); | ||
| 73 | |||
| 74 | MemberDTO memberDTO = memberAndWeixinUserDTO.getMemberDTO(); | ||
| 75 | this.updateMember(_memberDTO, memberDTO); | ||
| 76 | |||
| 64 | } | 77 | } |
| 65 | 78 | ||
| 66 | } | 79 | } |
| ... | @@ -68,26 +81,93 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -68,26 +81,93 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 68 | @Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class) | 81 | @Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class) |
| 69 | public void asyncMemberAndUserTv4Iptv(MemberAndUserTvDTO memberAndUserTvDTO) { | 82 | public void asyncMemberAndUserTv4Iptv(MemberAndUserTvDTO memberAndUserTvDTO) { |
| 70 | UserTvDTO userTvDTO = memberAndUserTvDTO.getUserTvDTO(); | 83 | UserTvDTO userTvDTO = memberAndUserTvDTO.getUserTvDTO(); |
| 84 | MemberDTO memberDTO = memberAndUserTvDTO.getMemberDTO(); | ||
| 85 | |||
| 71 | String platformAccount = userTvDTO.getPlatformAccount(); | 86 | String platformAccount = userTvDTO.getPlatformAccount(); |
| 72 | UserTvDTO _userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); | 87 | UserTvDTO _userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); |
| 73 | if (Objects.isNull(_userTvDTO)) { | 88 | if (Objects.isNull(_userTvDTO)) { |
| 89 | |||
| 74 | // 创建大屏会员 | 90 | // 创建大屏会员 |
| 75 | MemberDTO memberDTO = this.createMember(memberAndUserTvDTO.getMemberDTO()); | 91 | MemberDTO _memberDTO = this.createMember(memberAndUserTvDTO.getMemberDTO()); |
| 76 | userTvDTO.setMemberId(memberDTO.getId()); | 92 | userTvDTO.setMemberId(_memberDTO.getId()); |
| 77 | // 创建大屏账号 | 93 | // 创建大屏账号 |
| 78 | this.createUserTv(userTvDTO); | 94 | this.createUserTv(userTvDTO); |
| 95 | |||
| 96 | } else { | ||
| 97 | |||
| 98 | this.updateUserTv(_userTvDTO, userTvDTO); | ||
| 99 | |||
| 100 | String code = memberDTO.getCode(); | ||
| 101 | MemberDTO _memberDTO = this.memberService.findByCode(code); | ||
| 102 | this.updateMember(_memberDTO, memberDTO); | ||
| 103 | |||
| 79 | } | 104 | } |
| 80 | } | 105 | } |
| 81 | 106 | ||
| 82 | @Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class) | 107 | @Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class) |
| 108 | public void asyncAppletBind(MemberAndUserTvDTO memberAndUserTvDTO) { | ||
| 109 | UserTvDTO userTvDTO = memberAndUserTvDTO.getUserTvDTO(); | ||
| 110 | MemberDTO memberDTO = memberAndUserTvDTO.getMemberDTO(); | ||
| 111 | |||
| 112 | String platformAccount = userTvDTO.getPlatformAccount(); | ||
| 113 | UserTvDTO _userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); | ||
| 114 | if (Objects.nonNull(_userTvDTO)) { | ||
| 115 | |||
| 116 | // | ||
| 117 | this.updateUserTv(_userTvDTO, userTvDTO); | ||
| 118 | |||
| 119 | String code = memberDTO.getCode(); | ||
| 120 | MemberDTO _memberDTO = this.memberService.findByCode(code); | ||
| 121 | |||
| 122 | memberDTO.setUserIptvId(_userTvDTO.getId()); | ||
| 123 | this.updateMember(_memberDTO, memberDTO); | ||
| 124 | |||
| 125 | } else { | ||
| 126 | |||
| 127 | throw new EntityNotFoundException(UserTvDTO.class, "id", GlobeExceptionMsg.IPTV_IS_NULL); | ||
| 128 | |||
| 129 | } | ||
| 130 | } | ||
| 131 | |||
| 132 | @Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class) | ||
| 133 | public void asyncUnbind(MemberAndUserTvDTO memberAndUserTvDTO) { | ||
| 134 | UserTvDTO userTvDTO = memberAndUserTvDTO.getUserTvDTO(); | ||
| 135 | MemberDTO memberDTO = memberAndUserTvDTO.getMemberDTO(); | ||
| 136 | |||
| 137 | String platformAccount = userTvDTO.getPlatformAccount(); | ||
| 138 | UserTvDTO _userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); | ||
| 139 | if (Objects.nonNull(_userTvDTO)) { | ||
| 140 | |||
| 141 | // | ||
| 142 | this.updateUserTv(_userTvDTO, userTvDTO); | ||
| 143 | |||
| 144 | String code = memberDTO.getCode(); | ||
| 145 | MemberDTO _memberDTO = this.memberService.findByCode(code); | ||
| 146 | this.updateMember(_memberDTO, memberDTO); | ||
| 147 | } | ||
| 148 | |||
| 149 | } | ||
| 150 | |||
| 151 | @Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class) | ||
| 83 | public void asyncWeixin(UserWeixinDTO userWeixinDTO) { | 152 | public void asyncWeixin(UserWeixinDTO userWeixinDTO) { |
| 84 | String openid = userWeixinDTO.getOpenid(); | 153 | String openid = userWeixinDTO.getOpenid(); |
| 85 | String unionid = userWeixinDTO.getUnionid(); | 154 | String unionid = userWeixinDTO.getUnionid(); |
| 86 | String appid = userWeixinDTO.getAppid(); | 155 | String appid = userWeixinDTO.getAppid(); |
| 87 | UserWeixinDTO _userWeixinDTO = this.userWeixinService.findFirstByUnionIdAndAppIdAndOpenId(unionid, appid, openid); | 156 | UserWeixinDTO _userWeixinDTO = this.userWeixinService.findFirstByUnionIdAndAppIdAndOpenId(unionid, appid, openid); |
| 88 | if (Objects.nonNull(_userWeixinDTO)) { | 157 | if (Objects.nonNull(_userWeixinDTO.getId())) { |
| 158 | |||
| 89 | userWeixinDTO.setId(_userWeixinDTO.getId()); | 159 | userWeixinDTO.setId(_userWeixinDTO.getId()); |
| 90 | this.updateWeixin(userWeixinDTO); | 160 | this.updateWeixin(_userWeixinDTO, userWeixinDTO); |
| 161 | |||
| 162 | } else { | ||
| 163 | |||
| 164 | userWeixinDTO.setId(null); | ||
| 165 | String memberCode = userWeixinDTO.getMemberCode(); | ||
| 166 | MemberDTO memberDTO = this.memberService.findByCode(memberCode); | ||
| 167 | userWeixinDTO.setMemberId(memberDTO.getId()); | ||
| 168 | |||
| 169 | this.createWeixin(userWeixinDTO); | ||
| 170 | |||
| 91 | } | 171 | } |
| 92 | 172 | ||
| 93 | } | 173 | } |
| ... | @@ -99,7 +179,7 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -99,7 +179,7 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 99 | if (Objects.nonNull(_userTvDTO)) { | 179 | if (Objects.nonNull(_userTvDTO)) { |
| 100 | Long id = _userTvDTO.getId(); | 180 | Long id = _userTvDTO.getId(); |
| 101 | userTvDTO.setId(id); | 181 | userTvDTO.setId(id); |
| 102 | this.updateUserTv(userTvDTO); | 182 | this.updateUserTv(_userTvDTO, userTvDTO); |
| 103 | } | 183 | } |
| 104 | 184 | ||
| 105 | } | 185 | } |
| ... | @@ -112,11 +192,44 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -112,11 +192,44 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 112 | if (Objects.nonNull(_memberDTO)) { | 192 | if (Objects.nonNull(_memberDTO)) { |
| 113 | Long id = _memberDTO.getId(); | 193 | Long id = _memberDTO.getId(); |
| 114 | memberDTO.setId(id); | 194 | memberDTO.setId(id); |
| 115 | this.updateMember(memberDTO); | 195 | this.updateMember(_memberDTO, memberDTO); |
| 116 | } | 196 | } |
| 117 | } | 197 | } |
| 118 | } | 198 | } |
| 119 | 199 | ||
| 200 | @Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class) | ||
| 201 | public void asyncUnsubscribe(MemberAndWeixinUserDTO memberAndWeixinUserDTO) { | ||
| 202 | UserWeixinDTO userWeixinDTO = memberAndWeixinUserDTO.getUserWeixinDTO(); | ||
| 203 | String openid = userWeixinDTO.getOpenid(); | ||
| 204 | String unionid = userWeixinDTO.getUnionid(); | ||
| 205 | String appid = userWeixinDTO.getAppid(); | ||
| 206 | MemberDTO memberDTO = memberAndWeixinUserDTO.getMemberDTO(); | ||
| 207 | |||
| 208 | UserWeixinDTO _userWeixinDTO = this.userWeixinService.findFirstByUnionIdAndAppIdAndOpenId(unionid, appid, openid); | ||
| 209 | if (Objects.nonNull(_userWeixinDTO)) { | ||
| 210 | |||
| 211 | // 账号存在,修改账号和会员 | ||
| 212 | this.updateWeixin(_userWeixinDTO, userWeixinDTO); | ||
| 213 | |||
| 214 | MemberDTO _memberDTO = this.memberService.findById(_userWeixinDTO.getMemberId()); | ||
| 215 | if (Objects.nonNull(_memberDTO)) { | ||
| 216 | |||
| 217 | memberDTO.setUserIptvId(_memberDTO.getUserIptvId()); | ||
| 218 | this.updateMember(_memberDTO, memberDTO); | ||
| 219 | |||
| 220 | } else { | ||
| 221 | |||
| 222 | throw new EntityNotFoundException(MemberDTO.class, "id", GlobeExceptionMsg.MEMBER_ID_IS_NULL); | ||
| 223 | |||
| 224 | } | ||
| 225 | |||
| 226 | } else { | ||
| 227 | |||
| 228 | throw new EntityNotFoundException(UserWeixinDTO.class, "id", GlobeExceptionMsg.WEIXIN_IS_NULL); | ||
| 229 | |||
| 230 | } | ||
| 231 | |||
| 232 | } | ||
| 120 | 233 | ||
| 121 | private MemberDTO createMember(MemberDTO memberDTO){ | 234 | private MemberDTO createMember(MemberDTO memberDTO){ |
| 122 | Member member = new Member(); | 235 | Member member = new Member(); |
| ... | @@ -124,7 +237,11 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -124,7 +237,11 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 124 | return this.memberService.create(member); | 237 | return this.memberService.create(member); |
| 125 | } | 238 | } |
| 126 | 239 | ||
| 127 | private MemberDTO updateMember(MemberDTO memberDTO){ | 240 | private MemberDTO updateMember(MemberDTO _memberDTO, MemberDTO memberDTO){ |
| 241 | |||
| 242 | memberDTO.setId(_memberDTO.getId()); | ||
| 243 | memberDTO.setCode(_memberDTO.getCode()); | ||
| 244 | |||
| 128 | Member member = new Member(); | 245 | Member member = new Member(); |
| 129 | BeanUtils.copyProperties(memberDTO, member); | 246 | BeanUtils.copyProperties(memberDTO, member); |
| 130 | return this.memberService.update(member); | 247 | return this.memberService.update(member); |
| ... | @@ -136,7 +253,13 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -136,7 +253,13 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 136 | this.userWeixinService.create(userWeixin); | 253 | this.userWeixinService.create(userWeixin); |
| 137 | } | 254 | } |
| 138 | 255 | ||
| 139 | private void updateWeixin(UserWeixinDTO weixinDTO){ | 256 | private void updateWeixin(UserWeixinDTO _userWeixinDTO, UserWeixinDTO weixinDTO){ |
| 257 | weixinDTO.setId(_userWeixinDTO.getId()); | ||
| 258 | weixinDTO.setMemberId(_userWeixinDTO.getMemberId()); | ||
| 259 | weixinDTO.setUnionid(_userWeixinDTO.getUnionid()); | ||
| 260 | weixinDTO.setAppid(_userWeixinDTO.getAppid()); | ||
| 261 | weixinDTO.setOpenid(_userWeixinDTO.getOpenid()); | ||
| 262 | |||
| 140 | UserWeixin userWeixin = new UserWeixin(); | 263 | UserWeixin userWeixin = new UserWeixin(); |
| 141 | BeanUtils.copyProperties(weixinDTO, userWeixin); | 264 | BeanUtils.copyProperties(weixinDTO, userWeixin); |
| 142 | this.userWeixinService.update(userWeixin); | 265 | this.userWeixinService.update(userWeixin); |
| ... | @@ -148,7 +271,13 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -148,7 +271,13 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 148 | this.userTvService.create(userTv); | 271 | this.userTvService.create(userTv); |
| 149 | } | 272 | } |
| 150 | 273 | ||
| 151 | private void updateUserTv(UserTvDTO userTvDTO){ | 274 | private void updateUserTv(UserTvDTO _userTvDTO, UserTvDTO userTvDTO){ |
| 275 | userTvDTO.setId(_userTvDTO.getId()); | ||
| 276 | userTvDTO.setVisUserId(_userTvDTO.getVisUserId()); | ||
| 277 | userTvDTO.setMemberId(_userTvDTO.getMemberId()); | ||
| 278 | userTvDTO.setPlatformAccount(_userTvDTO.getPlatformAccount()); | ||
| 279 | userTvDTO.setCreateTime(_userTvDTO.getCreateTime()); | ||
| 280 | |||
| 152 | UserTv userTv = new UserTv(); | 281 | UserTv userTv = new UserTv(); |
| 153 | BeanUtils.copyProperties(userTvDTO, userTv); | 282 | BeanUtils.copyProperties(userTvDTO, userTv); |
| 154 | this.userTvService.update(userTv); | 283 | this.userTvService.update(userTv); | ... | ... |
| ... | @@ -47,4 +47,5 @@ public interface GlobeExceptionMsg { | ... | @@ -47,4 +47,5 @@ public interface GlobeExceptionMsg { |
| 47 | String OPEN_ID_IS_NULL = "openId is null"; | 47 | String OPEN_ID_IS_NULL = "openId is null"; |
| 48 | String UNION_ID_IS_NULL = "unionId is null"; | 48 | String UNION_ID_IS_NULL = "unionId is null"; |
| 49 | String ALREADY_BIND = "already bind"; | 49 | String ALREADY_BIND = "already bind"; |
| 50 | String WEIXIN_IS_NULL = "weixin is null"; | ||
| 50 | } | 51 | } | ... | ... |
-
Please register or sign in to post a comment