| | |
| | | package com.everyday.word.service.impl.user; |
| | | |
| | | import com.everyday.word.config.CosFilePathEnum; |
| | | import com.everyday.word.dao.user.UserAuthMapper; |
| | | import com.everyday.word.dao.user.UserMapper; |
| | | import com.everyday.word.dto.QQUserInfo; |
| | |
| | | import com.everyday.word.entity.user.User; |
| | | import com.everyday.word.entity.user.UserAuth; |
| | | import com.everyday.word.exception.user.UserException; |
| | | import com.everyday.word.factory.user.UserAuthFactory; |
| | | import com.everyday.word.factory.user.UserFactory; |
| | | import com.everyday.word.service.inter.user.UserService; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import org.yeshi.utils.StringUtil; |
| | | import org.yeshi.utils.entity.wx.WeiXinUser; |
| | | import org.yeshi.utils.tencentcloud.COSManager; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.IOException; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | |
| | | private UserMapper userMapper; |
| | | @Resource |
| | | private UserAuthMapper userAuthMapper; |
| | | @Resource |
| | | private COSManager cosManager; |
| | | |
| | | @Override |
| | | public User loginByWX(WeiXinUser user, SystemEnum system) { |
| | |
| | | user.setNickName(authInfo.getNickName()); |
| | | user.setPortrait(authInfo.getPortrait()); |
| | | user.setCreateTime(new Date()); |
| | | user.setSystem(authInfo.getSystem()); |
| | | userMapper.insertSelective(user); |
| | | authInfo.setUserId(user.getId()); |
| | | authInfo.setCreateTime(new Date()); |
| | |
| | | daoQuery.system = system; |
| | | daoQuery.count = 1; |
| | | List<UserAuth> authList = userAuthMapper.list(daoQuery); |
| | | if (authList.size() < 1) { |
| | | if (authList.isEmpty()) { |
| | | return null; |
| | | } |
| | | return authList.get(0); |
| | |
| | | daoQuery.userId = uid; |
| | | daoQuery.count = 1; |
| | | List<UserAuth> authList = userAuthMapper.list(daoQuery); |
| | | if (authList.size() < 1) { |
| | | if (authList.isEmpty()) { |
| | | return null; |
| | | } |
| | | return authList.get(0); |
| | |
| | | if (user == null) { |
| | | throw new UserException("用户不存在"); |
| | | } |
| | | UserAuth userAuth = UserAuthFactory.create(weiXinUser); |
| | | UserAuth userAuth = UserFactory.createAuth(weiXinUser, user.getSystem()); |
| | | if (selectUserAuth(userAuth.getIdentityType(), userAuth.getIdentifier(), user.getSystem()) != null) { |
| | | throw new UserException("微信已被绑定"); |
| | | } |
| | |
| | | if (user == null) { |
| | | throw new UserException("用户不存在"); |
| | | } |
| | | UserAuth userAuth = UserAuthFactory.create(qqUserInfo); |
| | | UserAuth userAuth = UserFactory.createAuth(qqUserInfo, user.getSystem()); |
| | | if (selectUserAuth(userAuth.getIdentityType(), userAuth.getIdentifier(), user.getSystem()) != null) { |
| | | throw new UserException("QQ已被绑定"); |
| | | } |
| | |
| | | if (user == null) { |
| | | throw new UserException("用户不存在"); |
| | | } |
| | | UserAuth userAuth = UserAuthFactory.create(phone); |
| | | UserAuth userAuth = UserFactory.createAuth(phone, user.getSystem()); |
| | | if (selectUserAuth(userAuth.getIdentityType(), userAuth.getIdentifier(), user.getSystem()) != null) { |
| | | throw new UserException("手机号已被绑定"); |
| | | } |
| | | bind(userId, userAuth); |
| | | } |
| | | |
| | | @Override |
| | | public void uploadPortrait(MultipartFile file, Long uid) throws UserException, IOException { |
| | | String fileUrl = cosManager.uploadFile(file.getInputStream(), CosFilePathEnum.userPortrait.getWholePath(uid + ".jpg")).getUrl(); |
| | | User user = User.builder() |
| | | .id(uid) |
| | | .portrait(fileUrl) |
| | | .updateTime(new Date()) |
| | | .build(); |
| | | userMapper.updateByPrimaryKeySelective(user); |
| | | } |
| | | |
| | | private void bind(Long userId, UserAuth userAuth) { |
| | | // 查询是否为更换绑定 |
| | | UserAuth oldAuth = selectUserAuth(userId, userAuth.getIdentityType()); |