This commit is contained in:
DU 2021-04-13 16:59:55 +08:00
commit 011ffd5ccf
6 changed files with 101 additions and 197 deletions

View File

@ -1,6 +1,7 @@
package club.joylink.rtss.services; package club.joylink.rtss.services;
import club.joylink.rtss.constants.Project; import club.joylink.rtss.constants.Project;
import club.joylink.rtss.entity.Org;
import club.joylink.rtss.entity.SysUser; import club.joylink.rtss.entity.SysUser;
import club.joylink.rtss.vo.UserQueryVO; import club.joylink.rtss.vo.UserQueryVO;
import club.joylink.rtss.vo.UserVO; import club.joylink.rtss.vo.UserVO;
@ -31,6 +32,16 @@ public interface ISysUserService {
*/ */
UserVO findUserById(Long id); UserVO findUserById(Long id);
/**
* 设置用户的与项目{project}关联的组织信息
*/
void setOrgInfoOfOrgRelWithTheProject(Project project, UserVO userVO);
/**
* 设置用户与该组织的关联信息
*/
void setOrgInfoOfThisOrg(Org topOrg, UserVO userVO);
SysUser findEntity(@NonNull String account, long orgId); SysUser findEntity(@NonNull String account, long orgId);
boolean isExist(@NonNull String account, long orgId); boolean isExist(@NonNull String account, long orgId);

View File

@ -15,10 +15,7 @@ import club.joylink.rtss.services.org.IOrgService;
import club.joylink.rtss.services.org.IOrgUserService; import club.joylink.rtss.services.org.IOrgUserService;
import club.joylink.rtss.util.EncryptUtil; import club.joylink.rtss.util.EncryptUtil;
import club.joylink.rtss.util.RandomGenerator; import club.joylink.rtss.util.RandomGenerator;
import club.joylink.rtss.vo.SmsResponse; import club.joylink.rtss.vo.*;
import club.joylink.rtss.vo.UserQueryVO;
import club.joylink.rtss.vo.UserVO;
import club.joylink.rtss.vo.VdCode;
import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.map.MapVO; import club.joylink.rtss.vo.client.map.MapVO;
import club.joylink.rtss.vo.client.org.CompanyVO; import club.joylink.rtss.vo.client.org.CompanyVO;
@ -114,19 +111,38 @@ public class SysUserService implements ISysUserService {
} }
} }
/* 如果用户属于该顶级组织,设置相关属性 */ /* 如果用户属于该顶级组织,设置相关属性 */
userVO.setRolesByString(); setOrgInfoOfThisOrg(topOrg, userVO);
if (topOrg != null) { return userVO;
}
@Override
public void setOrgInfoOfOrgRelWithTheProject(Project project, UserVO userVO) {
if (project != null) {
Org topOrg = iOrgService.findEntity(project, BusinessConsts.Org.Status.VALID);
setOrgInfoOfThisOrg(topOrg, userVO);
}
}
@Override
public void setOrgInfoOfThisOrg(Org topOrg, UserVO userVO) {
if (topOrg != null && userVO != null && topOrg.getId() != null && userVO.getId() != null) {
boolean flag = false; boolean flag = false;
if (Objects.equals(topOrg.getId(), userVO.getOrgId())) { if (Objects.equals(topOrg.getId(), userVO.getOrgId())) {
flag = true; flag = true;
} else { } else {
List<OrgUser> orgUsers = iOrgUserService.findEntitiesByUserId(userVO.getId(), null); List<OrgUser> orgUsers = iOrgUserService.findEntitiesByUserId(userVO.getId(), null);
if (CollectionUtils.isEmpty(orgUsers))
return;
if (orgUsers.stream().anyMatch(ou -> Objects.equals(ou.getOrgId(), topOrg.getId()))) { if (orgUsers.stream().anyMatch(ou -> Objects.equals(ou.getOrgId(), topOrg.getId()))) {
flag = true; flag = true;
} else { } else {
Set<Long> userRelTopOrgId = iOrgService.findEntities(orgUsers.stream().map(OrgUser::getOrgId) List<Long> orgIds = orgUsers.stream().map(OrgUser::getOrgId).collect(Collectors.toList());
.collect(Collectors.toList()), BusinessConsts.Org.Status.VALID) if (CollectionUtils.isEmpty(orgIds))
.stream().map(Org::getRootId).collect(Collectors.toSet()); //用户直接或间接关联的所有顶级组织id return;
List<Org> orgs = iOrgService.findEntities(orgIds, BusinessConsts.Org.Status.VALID);
if (CollectionUtils.isEmpty(orgs))
return;
Set<Long> userRelTopOrgId = orgs.stream().map(Org::getRootId).collect(Collectors.toSet()); //用户直接或间接关联的所有顶级组织id
if (userRelTopOrgId.contains(topOrg.getId())) { if (userRelTopOrgId.contains(topOrg.getId())) {
flag = true; flag = true;
} }
@ -136,7 +152,6 @@ public class SysUserService implements ISysUserService {
userVO.setOrgInfo(topOrg, iOrgUserService.isTheRoleInThisOrg(userVO.getId(), topOrg.getId(), BusinessConsts.OrgRole.Admin)); userVO.setOrgInfo(topOrg, iOrgUserService.isTheRoleInThisOrg(userVO.getId(), topOrg.getId(), BusinessConsts.OrgRole.Admin));
} }
} }
return userVO;
} }
@Override @Override
@ -285,8 +300,7 @@ public class SysUserService implements ISysUserService {
if (!user.getRoles().equals(userVO.getRolesStr())) { if (!user.getRoles().equals(userVO.getRolesStr())) {
user.setRoles(userVO.getRolesStr()); user.setRoles(userVO.getRolesStr());
this.sysUserDAO.updateByPrimaryKey(user); this.sysUserDAO.updateByPrimaryKey(user);
UserVO newUserVO = queryUserInfoWithOrgInfo(id); this.updateLoginUserInfoWithOrgInfo(user);
this.loginSessionManager.updateLoginUser(newUserVO);
} }
} }
@ -442,9 +456,10 @@ public class SysUserService implements ISysUserService {
if (CollectionUtils.isEmpty(list)) { if (CollectionUtils.isEmpty(list)) {
return null; return null;
} }
UserVO userVO = this.queryUserInfoWithOrgInfo(list.get(0).getId()); return new UserVO(list.get(0));
userVO.setRolesByString(); // UserVO userVO = this.queryUserInfoWithOrgInfo(list.get(0).getId());
return userVO; // userVO.setRolesByString();
// return userVO;
} }
@Override @Override
@ -454,9 +469,10 @@ public class SysUserService implements ISysUserService {
example.createCriteria().andWmOpenIdEqualTo(wmOpenId); example.createCriteria().andWmOpenIdEqualTo(wmOpenId);
List<SysUser> userList = this.sysUserDAO.selectByExample(example); List<SysUser> userList = this.sysUserDAO.selectByExample(example);
if (!CollectionUtils.isEmpty(userList)) { if (!CollectionUtils.isEmpty(userList)) {
UserVO userVO = queryUserInfoWithOrgInfo(userList.get(0).getId()); return new UserVO(userList.get(0));
userVO.setRolesByString(); // UserVO userVO = queryUserInfoWithOrgInfo(userList.get(0).getId());
return userVO; // userVO.setRolesByString();
// return userVO;
} }
return null; return null;
} }
@ -584,8 +600,7 @@ public class SysUserService implements ISysUserService {
user.setName(name); user.setName(name);
user.setUpdateTime(LocalDateTime.now()); user.setUpdateTime(LocalDateTime.now());
this.sysUserDAO.updateByPrimaryKey(user); this.sysUserDAO.updateByPrimaryKey(user);
UserVO userVO = this.queryUserInfoWithOrgInfo(id); this.updateLoginUserInfoWithOrgInfo(user);
this.loginSessionManager.updateLoginUser(userVO);
} }
} }
@ -598,8 +613,7 @@ public class SysUserService implements ISysUserService {
user.setNickname(nickname); user.setNickname(nickname);
user.setUpdateTime(LocalDateTime.now()); user.setUpdateTime(LocalDateTime.now());
this.sysUserDAO.updateByPrimaryKey(user); this.sysUserDAO.updateByPrimaryKey(user);
UserVO userVO = this.queryUserInfoWithOrgInfo(id); this.updateLoginUserInfoWithOrgInfo(user);
this.loginSessionManager.updateLoginUser(userVO);
} }
} }
@ -610,8 +624,7 @@ public class SysUserService implements ISysUserService {
user.setAvatarPath(avatarPath); user.setAvatarPath(avatarPath);
user.setUpdateTime(LocalDateTime.now()); user.setUpdateTime(LocalDateTime.now());
this.sysUserDAO.updateByPrimaryKey(user); this.sysUserDAO.updateByPrimaryKey(user);
UserVO userVO = queryUserInfoWithOrgInfo(id); this.updateLoginUserInfoWithOrgInfo(user);
this.loginSessionManager.updateLoginUser(userVO);
} }
} }
@ -628,8 +641,7 @@ public class SysUserService implements ISysUserService {
user.setMobile(updateMobileVO.getMobile()); user.setMobile(updateMobileVO.getMobile());
user.setUpdateTime(LocalDateTime.now()); user.setUpdateTime(LocalDateTime.now());
this.sysUserDAO.updateByPrimaryKey(user); this.sysUserDAO.updateByPrimaryKey(user);
UserVO userVO = this.queryUserInfoWithOrgInfo(id); this.updateLoginUserInfoWithOrgInfo(user);
this.loginSessionManager.updateLoginUser(userVO);
} }
} }
@ -645,8 +657,7 @@ public class SysUserService implements ISysUserService {
user.setEmail(updateEmailVO.getEmail()); user.setEmail(updateEmailVO.getEmail());
user.setUpdateTime(LocalDateTime.now()); user.setUpdateTime(LocalDateTime.now());
this.sysUserDAO.updateByPrimaryKey(user); this.sysUserDAO.updateByPrimaryKey(user);
UserVO userVO = this.queryUserInfoWithOrgInfo(id); this.updateLoginUserInfoWithOrgInfo(user);
this.loginSessionManager.updateLoginUser(userVO);
} }
} }
@ -782,8 +793,8 @@ public class SysUserService implements ISysUserService {
user.setRoles(updateUserVO.getRolesStr()); user.setRoles(updateUserVO.getRolesStr());
user.setUpdateTime(LocalDateTime.now()); user.setUpdateTime(LocalDateTime.now());
this.sysUserDAO.updateByPrimaryKey(user); this.sysUserDAO.updateByPrimaryKey(user);
UserVO newUserVO = this.queryUserInfoWithOrgInfo(userId); // UserVO newUserVO = this.queryUserInfoWithOrgInfo(userId);
this.loginSessionManager.updateLoginUser(newUserVO); // this.loginSessionManager.updateLoginUser(newUserVO);
} }
// //更新所属公司 // //更新所属公司
// Integer companyId = updateUserVO.getCompanyId(); // Integer companyId = updateUserVO.getCompanyId();
@ -842,4 +853,20 @@ public class SysUserService implements ISysUserService {
} }
return userVO; return userVO;
} }
/**
* 更新登录用户信息包含组织信息
* @param user
*/
private void updateLoginUserInfoWithOrgInfo(SysUser user) {
List<LoginUserInfoVO> loginUserInfoVOS = loginSessionManager.queryLoginInfoByUserId(user.getId());
if (!CollectionUtils.isEmpty(loginUserInfoVOS)) {
for (LoginUserInfoVO loginInfo : loginUserInfoVOS) {
UserVO oldUserVO = loginInfo.getUserVO();
UserVO newUserVO = new UserVO(user);
newUserVO.copyOrgInfo(oldUserVO);
loginInfo.setUserVO(newUserVO);
}
}
}
} }

View File

@ -107,6 +107,7 @@ public class AuthenticateService implements IAuthenticateService {
LoginStatusVO loginStatusVo = getLoginStatus(param.getSessionId()); LoginStatusVO loginStatusVo = getLoginStatus(param.getSessionId());
BusinessExceptionAssertEnum.LOGIN_EXPIRED.assertTrue(null != loginStatusVo && loginStatusVo.isWaiting()); BusinessExceptionAssertEnum.LOGIN_EXPIRED.assertTrue(null != loginStatusVo && loginStatusVo.isWaiting());
UserVO userVO = getOrCreateUserByWmcode(code); UserVO userVO = getOrCreateUserByWmcode(code);
loginStatusVo.setStatus(LoginStatusVO.ScanLoginStatus.SCAN); loginStatusVo.setStatus(LoginStatusVO.ScanLoginStatus.SCAN);
return userVO; return userVO;
} }
@ -208,6 +209,8 @@ public class AuthenticateService implements IAuthenticateService {
LoginUserInfoVO loginUserInfo = LoginUserInfoVO loginUserInfo =
new LoginUserInfoVO(user, loginStatusVo.getClient(), new LoginUserInfoVO(user, loginStatusVo.getClient(),
loginStatusVo.getProject(), loginStatusVo.getDeviceVO()); loginStatusVo.getProject(), loginStatusVo.getDeviceVO());
// 设置组织信息
iSysUserService.setOrgInfoOfOrgRelWithTheProject(loginUserInfo.getProject(), user);
// 登陆 // 登陆
login(loginUserInfo, true); login(loginUserInfo, true);
// 更新登陆状态 // 更新登陆状态
@ -220,6 +223,7 @@ public class AuthenticateService implements IAuthenticateService {
/** /**
* 登录逻辑 * 登录逻辑
*
* @param loginUserInfo * @param loginUserInfo
* @param force 是否强制登录true-登出之前登录的相同系统;false-若存在相同已登录系统此次登录失败 * @param force 是否强制登录true-登出之前登录的相同系统;false-若存在相同已登录系统此次登录失败
*/ */
@ -346,6 +350,7 @@ public class AuthenticateService implements IAuthenticateService {
/** /**
* 处理项目设备登出连带其他设备登出逻辑 * 处理项目设备登出连带其他设备登出逻辑
*
* @param event * @param event
*/ */
@EventListener @EventListener

View File

@ -383,7 +383,7 @@ public class OrgUserService implements IOrgUserService {
public void userBindCompanyManager(UserVO userVO, Long topOrgId) { public void userBindCompanyManager(UserVO userVO, Long topOrgId) {
Org topOrg = iOrgService.getEntity(topOrgId); Org topOrg = iOrgService.getEntity(topOrgId);
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNull(topOrg.getParentId(), "所选组织不是顶级组织"); BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNull(topOrg.getParentId(), "所选组织不是顶级组织");
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNotTrue(isTheRoleInThisOrg(userVO.getId(), topOrgId, BusinessConsts.OrgRole.Admin), BusinessExceptionAssertEnum.OPERATION_REPEAT.assertNotTrue(isTheRoleInThisOrg(userVO.getId(), topOrgId, BusinessConsts.OrgRole.Admin),
"已经是所选组织管理员"); "已经是所选组织管理员");
/* 如果是其它组织的管理员,删除关系 */ /* 如果是其它组织的管理员,删除关系 */
List<OrgUser> orgUsers = findEntitiesByUserId(userVO.getId(), BusinessConsts.OrgRole.Admin); List<OrgUser> orgUsers = findEntitiesByUserId(userVO.getId(), BusinessConsts.OrgRole.Admin);

View File

@ -647,154 +647,6 @@ public class InterlockBuilder2 {
right, necessarySections, leftStation, leftFrontTurnBack, rightStation, rightFrontTurnBack, necessaryRoutes, runPath, routes); right, necessarySections, leftStation, leftFrontTurnBack, rightStation, rightFrontTurnBack, necessaryRoutes, runPath, routes);
destinationMap.put(code, destinationCodeDefinition); destinationMap.put(code, destinationCodeDefinition);
} }
// Set<String> checkCodeDuplicateSet = new HashSet<>(); //用于检查code重复
//
// for (MapDestinationCodeDefinitionVO vo : destinationCodeDefinitionList) {
// //构建目的地码定义需要的所有参数
// String code = null;
// DestinationCodeDefinition.Type type = null;
// String description = null;
// Section startSection = null;
// Section section = null;
// Boolean right = vo.getRight();
// List<Section> necessarySections = new ArrayList<>();
// Station leftStation = null;
// Station rightStation = null;
// Boolean leftFrontTurnBack = null;
// Boolean rightFrontTurnBack = null;
// List<Route> necessaryRoutes = null;
// List<Section> runPath = null;
// List<Route> routes = null;
//
// code = vo.getCode();
// if (!checkCodeDuplicateSet.add(code)) {
// errMsgList.add(String.format("目的地码[%s]重复", code));
// }
// type = vo.getType();
// if (type == null) {
// errMsgList.add(String.format("目的地码[%s]没有类型", code));
// continue;
// }
// if (vo.getStartSectionCode() != null) {
// startSection = (Section) elementMap.get(vo.getStartSectionCode());
// }
// if (vo.getSectionCode() != null) {
// section = (Section) elementMap.get(vo.getSectionCode());
// }
// if (!CollectionUtils.isEmpty(vo.getRunPath())) {
// necessarySections = vo.getRunPath().stream().map(pathSectionCode -> (Section) elementMap.get(pathSectionCode))
// .collect(Collectors.toList());
// }
// switch (type) {
// case NORMAL_OPERATION: {
// description = vo.getDescription();
// if (!StringUtils.hasText(description)) {
// errMsgList.add(String.format("目的地码[%s]没有描述", code));
// }
// if (!StringUtils.hasText(vo.getStationACode())) {
// errMsgList.add(String.format("环路类目的地码[%s]没有车站A", code));
// continue;
// }
// if (!StringUtils.hasText(vo.getStationBCode())) {
// errMsgList.add(String.format("环路类目的地码[%s]没有车站B", code));
// continue;
// }
// Station stationA = (Station) elementMap.get(vo.getStationACode());
// Station stationB = (Station) elementMap.get(vo.getStationBCode());
// boolean stationAFrontTurnBack = vo.getStationAFrontTurnBack() != null ? vo.getStationAFrontTurnBack() : false;
// boolean stationBFrontTurnBack = vo.getStationBFrontTurnBack() != null ? vo.getStationBFrontTurnBack() : false;
// if (stationA.getSn() > stationB.getSn()) {
// leftStation = stationB;
// leftFrontTurnBack = stationBFrontTurnBack;
// rightStation = stationA;
// rightFrontTurnBack = stationAFrontTurnBack;
// } else {
// leftStation = stationA;
// leftFrontTurnBack = stationAFrontTurnBack;
// rightStation = stationB;
// rightFrontTurnBack = stationBFrontTurnBack;
// }
// //从左边车站右行站台站台轨开始构建运行路径--- 不标准的目的地码定义数据会导致运行路径构建错误
// Set<Section> necessarySectionSet = new HashSet<>(necessarySections); //必经区段副本
// Section startSection4RoutePath = null; //查询路径的起始区段
// Section endSection4RoutePath = null; //查询路径的终点区段
// runPath = new ArrayList<>();
// routes = new ArrayList<>();
// //从左端车站开始选择路径
// startSection4RoutePath = selectSection4DestinationCode(leftStation, leftFrontTurnBack, necessarySectionSet, true);
// runPath.add(startSection4RoutePath);
// endSection4RoutePath = selectSection4DestinationCode(rightStation, rightFrontTurnBack, necessarySectionSet, false);
// //查询并添加路径
// RoutePath optimalPath = CalculateService.queryLeastSwitchRoutePath(startSection4RoutePath, endSection4RoutePath, necessarySectionSet, true);
// BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(optimalPath,
// String.format("从%s到%s的路径未找到", startSection4RoutePath.debugStr(), endSection4RoutePath.debugStr()));
// runPath.addAll(optimalPath.getSectionList());
// //寻找反向的路径
// Section t = startSection4RoutePath;
// startSection4RoutePath = endSection4RoutePath;
// endSection4RoutePath = t;
// runPath.add(startSection4RoutePath);
// RoutePath optimalPath2 = CalculateService.queryLeastSwitchRoutePath(startSection4RoutePath, endSection4RoutePath, necessarySectionSet, false);
// BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(optimalPath2,
// String.format("从%s到%s的路径未找到", startSection4RoutePath.debugStr(), endSection4RoutePath.debugStr()));
// runPath.addAll(optimalPath2.getSectionList());
// //添加进路
// routes.addAll(CalculateService.selectUniqueRoutes(optimalPath, true));
// routes.addAll(CalculateService.selectUniqueRoutes(optimalPath2, true));
// break;
// }
// case LAST_OPERATION:
// case NON_OPERATION:
// case LAST_NON_OPERATION: {
// description = vo.getDescription();
// if (!StringUtils.hasText(description)) {
// errMsgList.add(String.format("目的地码[%s]没有描述", code));
// }
// if (section == null) {
// errMsgList.add(String.format("单向目的地码[%s]没有目标区段", code));
// continue;
// }
// if (startSection != null) {
// List<Section> sectionPath = new ArrayList<>();
// sectionPath.add(startSection);
// sectionPath.addAll(necessarySections);
// sectionPath.add(section);
// runPath = new ArrayList<>();
// routes = new ArrayList<>();
// for (int i = 0; i < sectionPath.size() - 1; i++) {
// Section start = sectionPath.get(i);
// Section end = sectionPath.get(i + 1);
// RoutePath routePath;
// if (right == null) {
// routePath = CalculateService.queryLeastSwitchRoutePath(start, end, null, true);
// if (routePath == null) {
// routePath = CalculateService.queryLeastSwitchRoutePath(start, end, null, false);
// }
// } else {
// routePath = CalculateService.queryLeastSwitchRoutePath(start, end, null, right);
// }
// BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(routePath,
// String.format("从%s到%s的路径未找到", startSection.debugStr(), section.debugStr()));
// runPath.add(start);
// runPath.addAll(routePath.getSectionList());
// routes.addAll(routePath.getRouteList());
// }
// runPath.add(section);
// }
// }
// case OTHER:
// if (section == null) {
// errMsgList.add(String.format("单向目的地码[%s]没有目标区段", code));
// continue;
// }
// break;
// }
// DestinationCodeDefinition destinationCodeDefinition = new DestinationCodeDefinition(code, type, description, startSection, section,
// right, necessarySections, leftStation, leftFrontTurnBack, rightStation, rightFrontTurnBack, necessaryRoutes, runPath, routes);
// destinationMap.put(code, destinationCodeDefinition);
// }
} }
/** /**

View File

@ -285,4 +285,13 @@ public class UserVO implements Serializable {
this.projectCodes = Arrays.asList(org.getProjectCode().split(",")); this.projectCodes = Arrays.asList(org.getProjectCode().split(","));
} }
} }
public void copyOrgInfo(UserVO userVO) {
if (userVO != null) {
this.companyId = userVO.getCompanyId();
this.companyName = userVO.getCompanyName();
this.companyAdmin = userVO.getCompanyAdmin();
this.projectCodes = userVO.getProjectCodes();
}
}
} }