完善小程序绑定手机号逻辑,token去除部门、角色、职位、组等信息

This commit is contained in:
wanggeng 2021-08-03 14:50:06 +08:00
parent 23e8164b2d
commit f7d4fdb984
5 changed files with 111 additions and 60 deletions

View File

@ -53,6 +53,17 @@ public class BaseAppSignService extends DefaultBaseService {
* @throws Exception * @throws Exception
*/ */
protected String getToken(UserPO userPO) throws UnsupportedEncodingException { protected String getToken(UserPO userPO) throws UnsupportedEncodingException {
return getToken(userPO, false);
}
/**
* 获取token
*
* @param userPO 用户信息
* @param isFull 是否包含全部信息部门角色职位
* @return
*/
protected String getToken(UserPO userPO, boolean isFull) throws UnsupportedEncodingException {
Map<String, Object> userInfo = new HashMap<>(8); Map<String, Object> userInfo = new HashMap<>(8);
// 这个参数是token认证标识 // 这个参数是token认证标识
userInfo.put(ISystemConstant.APP_TOKEN_SIGN, ISystemConstant.APP_TOKEN_VERIFY + System.currentTimeMillis()); userInfo.put(ISystemConstant.APP_TOKEN_SIGN, ISystemConstant.APP_TOKEN_VERIFY + System.currentTimeMillis());
@ -63,51 +74,53 @@ public class BaseAppSignService extends DefaultBaseService {
userInfo.put("phone", userPO.getUserPhone()); userInfo.put("phone", userPO.getUserPhone());
userInfo.put("email", userPO.getUserEmail()); userInfo.put("email", userPO.getUserEmail());
LOG.debug("人员部门列表"); if (isFull) {
List<DepartmentPO> departmentPOs = departmentUserService.listDepartmentPOByUserId(userPO.getUserId()); LOG.debug("人员部门列表");
List<Map<String, Object>> departments = new ArrayList<>(); List<DepartmentPO> departmentPOs = departmentUserService.listDepartmentPOByUserId(userPO.getUserId());
for (DepartmentPO departmentPO : departmentPOs) { List<Map<String, Object>> departments = new ArrayList<>();
Map<String, Object> departmentMap = new HashMap<>(4); for (DepartmentPO departmentPO : departmentPOs) {
departmentMap.put("departmentId", departmentPO.getDepartmentId()); Map<String, Object> departmentMap = new HashMap<>(4);
departmentMap.put("departmentName", departmentPO.getDepartmentName()); departmentMap.put("departmentId", departmentPO.getDepartmentId());
departments.add(departmentMap); departmentMap.put("departmentName", departmentPO.getDepartmentName());
} departments.add(departmentMap);
userInfo.put("departments", departments);
if (roleUserBaseService != null) {
LOG.debug("人员角色列表");
List<RolePO> rolePOs = roleUserBaseService.listRolePOByUserId(userPO.getUserId());
List<Map<String, Object>> roles = new ArrayList<>();
for (RolePO rolePO : rolePOs) {
Map<String, Object> roleMap = new HashMap<>(4);
roleMap.put("roleId", rolePO.getRoleId());
roleMap.put("roleName", rolePO.getRoleName());
roles.add(roleMap);
} }
userInfo.put("roles", roles); userInfo.put("departments", departments);
} if (roleUserBaseService != null) {
if (positionUserBaseService != null) { LOG.debug("人员角色列表");
LOG.debug("人员职位列表"); List<RolePO> rolePOs = roleUserBaseService.listRolePOByUserId(userPO.getUserId());
List<PositionPO> positionPOs = positionUserBaseService.listPositionPOByUserId(userPO.getUserId()); List<Map<String, Object>> roles = new ArrayList<>();
List<Map<String, Object>> positions = new ArrayList<>(); for (RolePO rolePO : rolePOs) {
for (PositionPO positionPO : positionPOs) { Map<String, Object> roleMap = new HashMap<>(4);
Map<String, Object> positionMap = new HashMap<>(2); roleMap.put("roleId", rolePO.getRoleId());
positionMap.put("positionId", positionPO.getPositionId()); roleMap.put("roleName", rolePO.getRoleName());
positionMap.put("positionName", positionPO.getPositionName()); roles.add(roleMap);
positions.add(positionMap); }
userInfo.put("roles", roles);
} }
userInfo.put("positions", positions); if (positionUserBaseService != null) {
} LOG.debug("人员职位列表");
if (groupUserBaseService != null) { List<PositionPO> positionPOs = positionUserBaseService.listPositionPOByUserId(userPO.getUserId());
LOG.debug("人员组列表"); List<Map<String, Object>> positions = new ArrayList<>();
List<GroupPO> groupPOs = groupUserBaseService.listGroupPOByUserId(userPO.getUserId()); for (PositionPO positionPO : positionPOs) {
List<Map<String, Object>> groups = new ArrayList<>(); Map<String, Object> positionMap = new HashMap<>(2);
for (GroupPO groupPO : groupPOs) { positionMap.put("positionId", positionPO.getPositionId());
Map<String, Object> groupMap = new HashMap<>(2); positionMap.put("positionName", positionPO.getPositionName());
groupMap.put("groupId", groupPO.getGroupId()); positions.add(positionMap);
groupMap.put("groupName", groupPO.getGroupName()); }
groups.add(groupMap); userInfo.put("positions", positions);
}
if (groupUserBaseService != null) {
LOG.debug("人员组列表");
List<GroupPO> groupPOs = groupUserBaseService.listGroupPOByUserId(userPO.getUserId());
List<Map<String, Object>> groups = new ArrayList<>();
for (GroupPO groupPO : groupPOs) {
Map<String, Object> groupMap = new HashMap<>(2);
groupMap.put("groupId", groupPO.getGroupId());
groupMap.put("groupName", groupPO.getGroupName());
groups.add(groupMap);
}
userInfo.put("groups", groups);
} }
userInfo.put("groups", groups);
} }
LOG.debug("userInfo: " + userInfo); LOG.debug("userInfo: " + userInfo);
return Base64.encodeBase64String(AesUtil.aesCommonEncoder(ISystemConstant.APP_TOKEN_AES_KEY, JSONObject.toJSONString(userInfo)).getBytes("UTF-8")); return Base64.encodeBase64String(AesUtil.aesCommonEncoder(ISystemConstant.APP_TOKEN_AES_KEY, JSONObject.toJSONString(userInfo)).getBytes("UTF-8"));

View File

@ -80,16 +80,15 @@ public class MiniappSignServiceImpl extends BaseAppSignService implements IMinia
if (userPO == null) { if (userPO == null) {
throw new SearchException("用户不存在"); throw new SearchException("用户不存在");
} }
String token = getMiniappToken(userPO);
// 加入管理队列 // 加入管理队列
MiniappManager.getInstance().addUser(token.substring(0, token.length() - 2), miniAppUserInfoBO); MiniappManager.getInstance().addUser(userId, miniAppUserInfoBO);
return getMiniappToken(userPO); return getMiniappToken(userPO);
} }
@Override @Override
public String updatePhone(String token, MiniappUpdatePhoneVO miniappUpdatePhoneVO) throws UnsupportedEncodingException { public String updatePhone(String token, MiniappUpdatePhoneVO miniappUpdatePhoneVO) throws UnsupportedEncodingException {
MiniappPhoneDataBO miniappPhoneData = getMiniappPhoneData(token, miniappUpdatePhoneVO);
String userId = getAppTokenUser(token).getId(); String userId = getAppTokenUser(token).getId();
MiniappPhoneDataBO miniappPhoneData = getMiniappPhoneData(userId, miniappUpdatePhoneVO);
UserPO userPO = userService.getPO(userId); UserPO userPO = userService.getPO(userId);
if (userPO == null) { if (userPO == null) {
throw new SearchException("非系统用户,请刷新小程序"); throw new SearchException("非系统用户,请刷新小程序");
@ -103,6 +102,7 @@ public class MiniappSignServiceImpl extends BaseAppSignService implements IMinia
throw new SearchException("该手机已经绑定"); throw new SearchException("该手机已经绑定");
} }
// 是当前用户重复绑定返回token // 是当前用户重复绑定返回token
MiniappManager.getInstance().refreshUserUpdateTime(userId);
return getToken(userPO); return getToken(userPO);
} }
// 手机不存在更新手机号 // 手机不存在更新手机号
@ -114,24 +114,26 @@ public class MiniappSignServiceImpl extends BaseAppSignService implements IMinia
UpdateUsernameVO updateUsernameVO = new UpdateUsernameVO(); UpdateUsernameVO updateUsernameVO = new UpdateUsernameVO();
updateUsernameVO.setUsername(phone); updateUsernameVO.setUsername(phone);
updateUsernameVO.setUpdateReason("微信用户手动更新"); updateUsernameVO.setUpdateReason("微信用户手动更新");
userService.updateUsername(userId, updateUsernameVO); userService.updateUsername(userId, updateUsernameVO, false);
LOG.debug("返回token"); LOG.debug("返回token");
UserPO newUserPO = new UserPO(); UserPO newUserPO = new UserPO();
BeanUtils.copyProperties(userPO, newUserPO); BeanUtils.copyProperties(userPO, newUserPO);
newUserPO.setUserUsername(phone); newUserPO.setUserUsername(phone);
miniappUserService.updateIsInitAccount(userId, 0); miniappUserService.updateIsInitAccount(userId, 0);
// 更新管理队列
MiniappManager.getInstance().refreshUserUpdateTime(userId);
return getMiniappToken(userPO); return getMiniappToken(userPO);
} }
/** /**
* 解密获得手机号 * 解密获得手机号
* *
* @param token * @param userId
* @param miniappUpdatePhoneVO * @param miniappUpdatePhoneVO
* @return * @return
*/ */
private MiniappPhoneDataBO getMiniappPhoneData(String token, MiniappUpdatePhoneVO miniappUpdatePhoneVO) { private MiniappPhoneDataBO getMiniappPhoneData(String userId, MiniappUpdatePhoneVO miniappUpdatePhoneVO) {
MiniappUserInfoBO miniappUserInfoBO = MiniappManager.getInstance().get(token); MiniappUserInfoBO miniappUserInfoBO = MiniappManager.getInstance().get(userId);
if (miniappUserInfoBO == null) { if (miniappUserInfoBO == null) {
throw new SearchException("会话不存在,请重新打开小程序"); throw new SearchException("会话不存在,请重新打开小程序");
} }

View File

@ -1,5 +1,6 @@
package ink.wgink.module.wechat.manager; package ink.wgink.module.wechat.manager;
import ink.wgink.exceptions.SearchException;
import ink.wgink.module.wechat.pojo.bos.miniapp.MiniappUserInfoBO; import ink.wgink.module.wechat.pojo.bos.miniapp.MiniappUserInfoBO;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -38,22 +39,45 @@ public class MiniappManager {
/** /**
* 添加用户 * 添加用户
* *
* @param token * @param userId
* @param miniappUserInfoBO * @param miniappUserInfoBO
*/ */
public void addUser(String token, MiniappUserInfoBO miniappUserInfoBO) { public void addUser(String userId, MiniappUserInfoBO miniappUserInfoBO) {
miniappUserInfoBO.setUpdateTime(System.currentTimeMillis()); miniappUserInfoBO.setUpdateTime(System.currentTimeMillis());
users.put(token, miniappUserInfoBO); users.put(userId, miniappUserInfoBO);
}
/**
* 刷新用户更新时间
*
* @param userId
*/
public void refreshUserUpdateTime(String userId) {
MiniappUserInfoBO miniappUserInfoBO = get(userId);
if (miniappUserInfoBO == null) {
throw new SearchException("会话不存在,请重新打开小程序");
}
addUser(userId, miniappUserInfoBO);
} }
/** /**
* 获取小程序应用 * 获取小程序应用
* *
* @param userId
* @return
*/
public MiniappUserInfoBO get(String userId) {
return users.get(userId);
}
/**
* 删除小程序应用
*
* @param token * @param token
* @return * @return
*/ */
public MiniappUserInfoBO get(String token) { public MiniappUserInfoBO remove(String token) {
return users.get(token); return users.remove(token);
} }
/** /**

View File

@ -1,21 +1,17 @@
package ink.wgink.service.user.service; package ink.wgink.service.user.service;
import ink.wgink.exceptions.SearchException;
import ink.wgink.exceptions.UpdateException;
import ink.wgink.interfaces.user.IUserBaseService; import ink.wgink.interfaces.user.IUserBaseService;
import ink.wgink.interfaces.user.IUserCheckService; import ink.wgink.interfaces.user.IUserCheckService;
import ink.wgink.pojo.result.SuccessResult; import ink.wgink.pojo.result.UploadExcelResultDTO;
import ink.wgink.service.user.pojo.dtos.AppUserDTO; import ink.wgink.service.user.pojo.dtos.AppUserDTO;
import ink.wgink.service.user.pojo.pos.UserPO; import ink.wgink.service.user.pojo.pos.UserPO;
import ink.wgink.service.user.pojo.vos.*; import ink.wgink.service.user.pojo.vos.*;
import ink.wgink.pojo.result.UploadExcelResultDTO;
import ink.wgink.util.ReflectUtil; import ink.wgink.util.ReflectUtil;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -131,6 +127,15 @@ public interface IUserService extends IUserBaseService, IUserCheckService {
*/ */
void updateUsername(String userId, UpdateUsernameVO updateUsernameVO); void updateUsername(String userId, UpdateUsernameVO updateUsernameVO);
/**
* 修改用户名
*
* @param userId 用户ID
* @param updateUsernameVO 更新用户名
* @param updateAdjustment 是否添加日志
*/
void updateUsername(String userId, UpdateUsernameVO updateUsernameVO, boolean updateAdjustment);
/** /**
* 修改密码 * 修改密码
* *

View File

@ -179,6 +179,11 @@ public class UserServiceImpl extends DefaultBaseService implements IUserService
@Override @Override
public void updateUsername(String userId, UpdateUsernameVO updateUsernameVO) { public void updateUsername(String userId, UpdateUsernameVO updateUsernameVO) {
updateUsername(userId, updateUsernameVO, true);
}
@Override
public void updateUsername(String userId, UpdateUsernameVO updateUsernameVO, boolean updateAdjustment) {
UserDTO oldUserDTO = get(userId); UserDTO oldUserDTO = get(userId);
if (oldUserDTO == null) { if (oldUserDTO == null) {
throw new SearchException("用户不存在"); throw new SearchException("用户不存在");
@ -192,7 +197,9 @@ public class UserServiceImpl extends DefaultBaseService implements IUserService
params.put("userId", userId); params.put("userId", userId);
userDao.updateUsername(params); userDao.updateUsername(params);
updateUsernameAdjustment(userId, oldUserDTO.getUserUsername(), updateUsernameVO); if (updateAdjustment) {
updateUsernameAdjustment(userId, oldUserDTO.getUserUsername(), updateUsernameVO);
}
} }
@Override @Override