Commit fa5c49d6 authored by 王亮's avatar 王亮

remove user_attached.

parent 01e0cadc
...@@ -12,7 +12,8 @@ CREATE TABLE `xyqb_user`.`user_info` ( ...@@ -12,7 +12,8 @@ CREATE TABLE `xyqb_user`.`user_info` (
`gender` TINYINT(3) NULL COMMENT '性别', `gender` TINYINT(3) NULL COMMENT '性别',
`email` VARCHAR(45) NULL COMMENT '邮箱', `email` VARCHAR(45) NULL COMMENT '邮箱',
`qq` VARCHAR(20) NULL COMMENT '腾讯qq', `qq` VARCHAR(20) NULL COMMENT '腾讯qq',
`name` VARCHAR(45) NULL COMMENT '昵称', `name` VARCHAR(45) NULL COMMENT '名称',
`nick_name` VARCHAR(45) NULL COMMENT '昵称',
`photo` VARCHAR(255) NULL COMMENT '头像地址', `photo` VARCHAR(255) NULL COMMENT '头像地址',
`birthday` DATE NULL COMMENT '生日', `birthday` DATE NULL COMMENT '生日',
`province_id` INT NULL COMMENT '地址省份id', `province_id` INT NULL COMMENT '地址省份id',
......
...@@ -26,7 +26,6 @@ import cn.quantgroup.xyqb.service.sms.ISmsService; ...@@ -26,7 +26,6 @@ import cn.quantgroup.xyqb.service.sms.ISmsService;
import cn.quantgroup.xyqb.service.user.ILockIpv4Service; import cn.quantgroup.xyqb.service.user.ILockIpv4Service;
import cn.quantgroup.xyqb.service.user.ILoginRecordService; import cn.quantgroup.xyqb.service.user.ILoginRecordService;
import cn.quantgroup.xyqb.service.user.IUserService; import cn.quantgroup.xyqb.service.user.IUserService;
import cn.quantgroup.xyqb.service.user.UserCenterService;
import cn.quantgroup.xyqb.service.wechat.IWechatService; import cn.quantgroup.xyqb.service.wechat.IWechatService;
import cn.quantgroup.xyqb.session.XyqbSessionContextHolder; import cn.quantgroup.xyqb.session.XyqbSessionContextHolder;
import cn.quantgroup.xyqb.util.*; import cn.quantgroup.xyqb.util.*;
...@@ -62,8 +61,6 @@ public class UserController implements IBaseController { ...@@ -62,8 +61,6 @@ public class UserController implements IBaseController {
@Autowired @Autowired
private IUserService userService; private IUserService userService;
@Autowired @Autowired
private UserCenterService userCenterService;
@Autowired
private ILockIpv4Service lockIpv4Service; private ILockIpv4Service lockIpv4Service;
@Autowired @Autowired
@Qualifier("stringRedisTemplate") @Qualifier("stringRedisTemplate")
...@@ -653,14 +650,11 @@ public class UserController implements IBaseController { ...@@ -653,14 +650,11 @@ public class UserController implements IBaseController {
UserBrief brief = new UserBrief(); UserBrief brief = new UserBrief();
//TODO:he 返回"",待解决 //TODO:he 返回"",待解决
Long userId = getCurrentUserFromRedis().getId(); Long userId = getCurrentUserFromRedis().getId();
UserAttached userAttached = userCenterService.searchUserAttachedByUserId(userId);
if (userAttached != null) {
brief.setAvatar(userAttached.getAvatar());
brief.setNick(userAttached.getNick());
}
UserInfoEntity userDetail = userInfoRepository.findByUserIdAndTenantId(userId, tenantId); UserInfoEntity userDetail = userInfoRepository.findByUserIdAndTenantId(userId, tenantId);
if (userDetail != null) { if (userDetail != null) {
brief.setName(userDetail.getName()); brief.setName(userDetail.getName());
brief.setAvatar(userDetail.getPhoto());
brief.setNick(userDetail.getNickName());
brief.setSex(Optional.ofNullable(userDetail.getGender()).orElse(cn.quantgroup.xyqb.model.Gender.UNKNOWN).ordinal() + ""); brief.setSex(Optional.ofNullable(userDetail.getGender()).orElse(cn.quantgroup.xyqb.model.Gender.UNKNOWN).ordinal() + "");
brief.setPhoneNo(userDetail.getPhoneNo().substring(0, 3) + "****" + userDetail.getPhoneNo().substring(7, 11)); brief.setPhoneNo(userDetail.getPhoneNo().substring(0, 3) + "****" + userDetail.getPhoneNo().substring(7, 11));
} else { } else {
......
...@@ -33,6 +33,9 @@ public class UserInfoEntity extends BaseEntity implements Serializable { ...@@ -33,6 +33,9 @@ public class UserInfoEntity extends BaseEntity implements Serializable {
@Column(name = "name") @Column(name = "name")
private String name; private String name;
@Column(name = "nick_name")
private String nickName;
@Column(name = "photo") @Column(name = "photo")
private String photo; private String photo;
@Column(name = "birthday") @Column(name = "birthday")
......
...@@ -56,7 +56,7 @@ public class UserInfoRet implements Serializable { ...@@ -56,7 +56,7 @@ public class UserInfoRet implements Serializable {
userDetailRet.setId(userInfoEntity.getId()); userDetailRet.setId(userInfoEntity.getId());
userDetailRet.setUserId(userInfoEntity.getUserId()); userDetailRet.setUserId(userInfoEntity.getUserId());
userDetailRet.setPhoneNo(userInfoEntity.getPhoneNo()); userDetailRet.setPhoneNo(userInfoEntity.getPhoneNo());
userDetailRet.setNickName(userInfoEntity.getName()); userDetailRet.setNickName(userInfoEntity.getNickName());
userDetailRet.setGender(userInfoEntity.getGender()); userDetailRet.setGender(userInfoEntity.getGender());
userDetailRet.setEmail(StringUtils.defaultIfEmpty(userInfoEntity.getEmail(), "")); userDetailRet.setEmail(StringUtils.defaultIfEmpty(userInfoEntity.getEmail(), ""));
userDetailRet.setQq(StringUtils.defaultIfEmpty(userInfoEntity.getQq(), "")); userDetailRet.setQq(StringUtils.defaultIfEmpty(userInfoEntity.getQq(), ""));
......
...@@ -10,15 +10,7 @@ import java.util.List; ...@@ -10,15 +10,7 @@ import java.util.List;
/** /**
* Created by 11 on 2017/3/22. * Created by 11 on 2017/3/22.
*/ */
@Deprecated
public interface IUserAttachedRepository extends JpaRepository<UserAttached, Long> { public interface IUserAttachedRepository extends JpaRepository<UserAttached, Long> {
UserAttached findByUserId(Long userId);
List<UserAttached> findByUserIdIn(List<Long> userId);
@Transactional
void deleteByUserId(Long userId);
@Query(value = "select * from user_attached where id>?1 limit 500" ,nativeQuery = true)
List<UserAttached> findALlAttached(Long id);
} }
package cn.quantgroup.xyqb.service.user;
import cn.quantgroup.xyqb.entity.UserAttached;
import java.util.List;
/**
* Created by 11 on 2017/3/22.
*/
public interface UserCenterService {
/**
* 查询用户附加信息
*
* @param userId
* @return
*/
UserAttached searchUserAttachedByUserId(long userId);
/**
* 查询用户附加信息
* @param userIds
* @return
*/
List<UserAttached> searchUserAttachedListByUserId(List<Long> userIds, Integer tenantId);
/**
* 保存用户头像
*
* @param userId - 用户主键
* @param avatar - 头像url地址
* @param tenantId 租户ID
* @return
*/
UserAttached saveUserAvatar(long userId, String avatar,Integer tenantId);
/**
* 保存用户昵称
*
* @param userId - 用户主键
* @param nick - 昵称
* @param tenantId - 租户ID
* @return
*/
UserAttached saveUserNick(long userId, String nick,Integer tenantId);
List<UserAttached> queryUserAttachListLimit(Long id);
}
package cn.quantgroup.xyqb.service.user.impl;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.UserAttached;
import cn.quantgroup.xyqb.entity.UserInfoEntity;
import cn.quantgroup.xyqb.repository.IUserAttachedRepository;
import cn.quantgroup.xyqb.repository.IUserInfoRepository;
import cn.quantgroup.xyqb.repository.IUserRepository;
import cn.quantgroup.xyqb.service.user.IUserService;
import cn.quantgroup.xyqb.service.user.UserCenterService;
import cn.quantgroup.xyqb.util.EmojiUtil;
import cn.quantgroup.xyqb.util.TenantUtil;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.exception.ConstraintViolationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* Created by 11 on 2017/3/22.
*/
@Slf4j
@Service
public class UserCenterServiceImpl implements UserCenterService {
@Autowired
private IUserAttachedRepository userAttachedRepository;
@Autowired
private IUserInfoRepository userInfoRepository;
@Autowired
private IUserRepository userRepository;
@Override
// @Cacheable(value = "userAttachedCache", key = "'xyqbUserAttached' + #userId", unless = "#result == null", cacheManager = "cacheManager")
public UserAttached searchUserAttachedByUserId(long userId) {
return userAttachedRepository.findByUserId(userId);
}
@Override
public List<UserAttached> searchUserAttachedListByUserId(List<Long> userIds, Integer tenantId) {
List<UserInfoEntity> userInfoEntityList = userInfoRepository.findByTenantIdAndUserIdIn(tenantId, userIds);
if (CollectionUtils.isEmpty(userInfoEntityList)) {
return Lists.newArrayList();
}
List<UserAttached> list = Lists.newArrayList();
userInfoEntityList.stream().forEach(e -> {
UserAttached userAttached = new UserAttached();
userAttached.setUserId(e.getUserId());
userAttached.setNick(e.getName());
userAttached.setAvatar(e.getPhoto());
list.add(userAttached);
});
return list;
}
@Override
@CacheEvict(value = "userAttachedCache", key = "'xyqbUserAttached' + #userId +'-'+#tenantId+'-'+#tenantId", cacheManager = "cacheManager")
public UserAttached saveUserAvatar(long userId, String avatar, Integer tenantId) {
UserInfoEntity userAttached = userInfoRepository.findByUserIdAndTenantId(userId, tenantId);
if (Objects.isNull(userAttached)) {
userAttached = createUserAttached(tenantId, userId, avatar, null);
}
if (!Objects.equals(avatar, userAttached.getPhoto())) {
userAttached.setPhoto(avatar);
userAttached = userInfoRepository.save(userAttached);
}
UserAttached attached = new UserAttached();
attached.setUserId(userAttached.getUserId());
attached.setAvatar(userAttached.getPhoto());
attached.setNick(userAttached.getName());
return attached;
}
@Override
@CacheEvict(value = "userAttachedCache", key = "'xyqbUserAttached' + #userId +'-'+#tenantId", cacheManager = "cacheManager")
public UserAttached saveUserNick(long userId, String nick,Integer tenantId) {
UserInfoEntity userAttached = userInfoRepository.findByUserIdAndTenantId(userId, tenantId);
// 替换所有,UTF-8编码时4字节的Emoji表情字符
nick = EmojiUtil.filterUnicode4(nick);
if (Objects.isNull(userAttached)) {
userAttached = createUserAttached(tenantId,userId, null, nick);
}
UserAttached attached = null;
if (!Objects.equals(nick, userAttached.getName())) {
userAttached.setName(nick);
try {
userAttached = userInfoRepository.save(userAttached);
attached = new UserAttached();
attached.setUserId(userAttached.getUserId());
attached.setAvatar(userAttached.getPhoto());
attached.setNick(userAttached.getName());
} catch (ConstraintViolationException e) {
// Sql唯一约束异常(诱因是Form重复提交,因为该操作是幂等的,故此不需额外处理,可返回成功)
log.error("Sql约束异常[uni_idx_user_id]重复提交Form是幂等操作,不影响处理结果", e);
}
}
return attached;
}
@Override
public List<UserAttached> queryUserAttachListLimit(Long id) {
return userAttachedRepository.findALlAttached(id);
}
/**
* 创建用户附加信息实体
*
* @param userId - 用户主键
* @param avatar - 头像url地址
* @param nick - 昵称
* @return
*/
private synchronized UserInfoEntity createUserAttached(Integer tenantId, Long userId, String avatar, String nick) {
//UserAttached userAttached = userAttachedRepository.findByUserId(userId);
UserInfoEntity userAttached = userInfoRepository.findByUserIdAndTenantId(userId, tenantId);
// 更新实例
userAttached = Optional.ofNullable(userAttached).orElse(new UserInfoEntity());
userAttached.setUserId(userId);
if (StringUtils.isBlank(userAttached.getPhoto())) {
userAttached.setPhoto(avatar);
}
if (StringUtils.isBlank(userAttached.getName())) {
userAttached.setName(nick);
}
return userInfoRepository.save(userAttached);
}
}
...@@ -95,10 +95,6 @@ public class UserServiceImpl implements IUserService, IBaseController { ...@@ -95,10 +95,6 @@ public class UserServiceImpl implements IUserService, IBaseController {
@Autowired @Autowired
private IUserDeregisterService userDeregisterService; private IUserDeregisterService userDeregisterService;
@Autowired
private IUserAttachedRepository userAttachedRepository;
@Autowired @Autowired
private IUserTagRepository userTagRepository; private IUserTagRepository userTagRepository;
@Autowired @Autowired
...@@ -509,8 +505,6 @@ public class UserServiceImpl implements IUserService, IBaseController { ...@@ -509,8 +505,6 @@ public class UserServiceImpl implements IUserService, IBaseController {
/* 删除用户tag*/ /* 删除用户tag*/
userTagRepository.deleteByUserIdAndTenantId(userId, tenantId); userTagRepository.deleteByUserIdAndTenantId(userId, tenantId);
/* 删除用户附加信息 */
userAttachedRepository.deleteByUserId(userId);
/* 删除 user_bt_register 信息 */ /* 删除 user_bt_register 信息 */
userBtRegisterRepository.deleteByUserId(userId); userBtRegisterRepository.deleteByUserId(userId);
......
...@@ -3,7 +3,6 @@ package cn.quantgroup.xyqb.service.v2; ...@@ -3,7 +3,6 @@ package cn.quantgroup.xyqb.service.v2;
import cn.quantgroup.xyqb.constant.enums.LoginType; import cn.quantgroup.xyqb.constant.enums.LoginType;
import cn.quantgroup.xyqb.controller.req.v2.LoginReq; import cn.quantgroup.xyqb.controller.req.v2.LoginReq;
import cn.quantgroup.xyqb.entity.User; import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.WechatUserInfo;
import cn.quantgroup.xyqb.exception.BizException; import cn.quantgroup.xyqb.exception.BizException;
import cn.quantgroup.xyqb.exception.BizExceptionEnum; import cn.quantgroup.xyqb.exception.BizExceptionEnum;
import cn.quantgroup.xyqb.model.AuthBean; import cn.quantgroup.xyqb.model.AuthBean;
...@@ -13,19 +12,14 @@ import cn.quantgroup.xyqb.model.session.SessionStruct; ...@@ -13,19 +12,14 @@ import cn.quantgroup.xyqb.model.session.SessionStruct;
import cn.quantgroup.xyqb.model.v2.login.BaseLoginParam; import cn.quantgroup.xyqb.model.v2.login.BaseLoginParam;
import cn.quantgroup.xyqb.model.v2.login.PhonePasswordLoginParam; import cn.quantgroup.xyqb.model.v2.login.PhonePasswordLoginParam;
import cn.quantgroup.xyqb.repository.IUserRepository; import cn.quantgroup.xyqb.repository.IUserRepository;
import cn.quantgroup.xyqb.service.captcha.IGeetestLogService;
import cn.quantgroup.xyqb.service.session.ISessionService; import cn.quantgroup.xyqb.service.session.ISessionService;
import cn.quantgroup.xyqb.service.user.ILockIpv4Service; import cn.quantgroup.xyqb.service.user.ILockIpv4Service;
import cn.quantgroup.xyqb.service.wechat.IWechatService;
import cn.quantgroup.xyqb.session.XyqbSessionContextHolder; import cn.quantgroup.xyqb.session.XyqbSessionContextHolder;
import cn.quantgroup.xyqb.util.BctyptPasswordUtil; import cn.quantgroup.xyqb.util.BctyptPasswordUtil;
import cn.quantgroup.xyqb.util.PasswordUtil; import cn.quantgroup.xyqb.util.PasswordUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
/** /**
* 账号密码登录 * 账号密码登录
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment