完善小程序绑定手机号逻辑,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
*/
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);
// 这个参数是token认证标识
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("email", userPO.getUserEmail());
LOG.debug("人员部门列表");
List<DepartmentPO> departmentPOs = departmentUserService.listDepartmentPOByUserId(userPO.getUserId());
List<Map<String, Object>> departments = new ArrayList<>();
for (DepartmentPO departmentPO : departmentPOs) {
Map<String, Object> departmentMap = new HashMap<>(4);
departmentMap.put("departmentId", departmentPO.getDepartmentId());
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);
if (isFull) {
LOG.debug("人员部门列表");
List<DepartmentPO> departmentPOs = departmentUserService.listDepartmentPOByUserId(userPO.getUserId());
List<Map<String, Object>> departments = new ArrayList<>();
for (DepartmentPO departmentPO : departmentPOs) {
Map<String, Object> departmentMap = new HashMap<>(4);
departmentMap.put("departmentId", departmentPO.getDepartmentId());
departmentMap.put("departmentName", departmentPO.getDepartmentName());
departments.add(departmentMap);
}
userInfo.put("roles", roles);
}
if (positionUserBaseService != null) {
LOG.debug("人员职位列表");
List<PositionPO> positionPOs = positionUserBaseService.listPositionPOByUserId(userPO.getUserId());
List<Map<String, Object>> positions = new ArrayList<>();
for (PositionPO positionPO : positionPOs) {
Map<String, Object> positionMap = new HashMap<>(2);
positionMap.put("positionId", positionPO.getPositionId());
positionMap.put("positionName", positionPO.getPositionName());
positions.add(positionMap);
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("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);
if (positionUserBaseService != null) {
LOG.debug("人员职位列表");
List<PositionPO> positionPOs = positionUserBaseService.listPositionPOByUserId(userPO.getUserId());
List<Map<String, Object>> positions = new ArrayList<>();
for (PositionPO positionPO : positionPOs) {
Map<String, Object> positionMap = new HashMap<>(2);
positionMap.put("positionId", positionPO.getPositionId());
positionMap.put("positionName", positionPO.getPositionName());
positions.add(positionMap);
}
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);
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) {
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);
}
@Override
public String updatePhone(String token, MiniappUpdatePhoneVO miniappUpdatePhoneVO) throws UnsupportedEncodingException {
MiniappPhoneDataBO miniappPhoneData = getMiniappPhoneData(token, miniappUpdatePhoneVO);
String userId = getAppTokenUser(token).getId();
MiniappPhoneDataBO miniappPhoneData = getMiniappPhoneData(userId, miniappUpdatePhoneVO);
UserPO userPO = userService.getPO(userId);
if (userPO == null) {
throw new SearchException("非系统用户,请刷新小程序");
@ -103,6 +102,7 @@ public class MiniappSignServiceImpl extends BaseAppSignService implements IMinia
throw new SearchException("该手机已经绑定");
}
// 是当前用户重复绑定返回token
MiniappManager.getInstance().refreshUserUpdateTime(userId);
return getToken(userPO);
}
// 手机不存在更新手机号
@ -114,24 +114,26 @@ public class MiniappSignServiceImpl extends BaseAppSignService implements IMinia
UpdateUsernameVO updateUsernameVO = new UpdateUsernameVO();
updateUsernameVO.setUsername(phone);
updateUsernameVO.setUpdateReason("微信用户手动更新");
userService.updateUsername(userId, updateUsernameVO);
userService.updateUsername(userId, updateUsernameVO, false);
LOG.debug("返回token");
UserPO newUserPO = new UserPO();
BeanUtils.copyProperties(userPO, newUserPO);
newUserPO.setUserUsername(phone);
miniappUserService.updateIsInitAccount(userId, 0);
// 更新管理队列
MiniappManager.getInstance().refreshUserUpdateTime(userId);
return getMiniappToken(userPO);
}
/**
* 解密获得手机号
*
* @param token
* @param userId
* @param miniappUpdatePhoneVO
* @return
*/
private MiniappPhoneDataBO getMiniappPhoneData(String token, MiniappUpdatePhoneVO miniappUpdatePhoneVO) {
MiniappUserInfoBO miniappUserInfoBO = MiniappManager.getInstance().get(token);
private MiniappPhoneDataBO getMiniappPhoneData(String userId, MiniappUpdatePhoneVO miniappUpdatePhoneVO) {
MiniappUserInfoBO miniappUserInfoBO = MiniappManager.getInstance().get(userId);
if (miniappUserInfoBO == null) {
throw new SearchException("会话不存在,请重新打开小程序");
}

View File

@ -1,5 +1,6 @@
package ink.wgink.module.wechat.manager;
import ink.wgink.exceptions.SearchException;
import ink.wgink.module.wechat.pojo.bos.miniapp.MiniappUserInfoBO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -38,22 +39,45 @@ public class MiniappManager {
/**
* 添加用户
*
* @param token
* @param userId
* @param miniappUserInfoBO
*/
public void addUser(String token, MiniappUserInfoBO miniappUserInfoBO) {
public void addUser(String userId, MiniappUserInfoBO miniappUserInfoBO) {
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
* @return
*/
public MiniappUserInfoBO get(String token) {
return users.get(token);
public MiniappUserInfoBO remove(String token) {
return users.remove(token);
}
/**

View File

@ -1,21 +1,17 @@
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.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.pos.UserPO;
import ink.wgink.service.user.pojo.vos.*;
import ink.wgink.pojo.result.UploadExcelResultDTO;
import ink.wgink.util.ReflectUtil;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;
@ -131,6 +127,15 @@ public interface IUserService extends IUserBaseService, IUserCheckService {
*/
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
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);
if (oldUserDTO == null) {
throw new SearchException("用户不存在");
@ -192,7 +197,9 @@ public class UserServiceImpl extends DefaultBaseService implements IUserService
params.put("userId", userId);
userDao.updateUsername(params);
updateUsernameAdjustment(userId, oldUserDTO.getUserUsername(), updateUsernameVO);
if (updateAdjustment) {
updateUsernameAdjustment(userId, oldUserDTO.getUserUsername(), updateUsernameVO);
}
}
@Override