修改因组织和项目改为一对多关系导致的bug

This commit is contained in:
joylink_zhangsai 2021-04-02 10:51:49 +08:00
parent 707d23e2cc
commit 47d5ad0bb0
5 changed files with 48 additions and 33 deletions

View File

@ -133,10 +133,7 @@ public class SysUserService implements ISysUserService {
}
}
if (flag) {
userVO.setCompanyId(topOrg.getId());
userVO.setCompanyName(topOrg.getName());
userVO.setCompanyAdmin(iOrgUserService.isTheRoleInThisOrg(userVO.getId(), topOrg.getId(), BusinessConsts.OrgRole.Admin));
userVO.setProjectCodes(Arrays.asList(topOrg.getProjectCode().split(",")));
userVO.setOrgInfo(topOrg, iOrgUserService.isTheRoleInThisOrg(userVO.getId(), topOrg.getId(), BusinessConsts.OrgRole.Admin));
}
}
return userVO;
@ -275,9 +272,7 @@ public class SysUserService implements ISysUserService {
if (orgId != null) {
Org org = orgMap.get(orgId);
if (org != null) {
vo.setCompanyId(org.getId());
vo.setCompanyName(org.getName());
vo.setCompanyAdmin(true);
vo.setOrgInfo(org, true);
}
}
});
@ -290,8 +285,7 @@ public class SysUserService implements ISysUserService {
if (!user.getRoles().equals(userVO.getRolesStr())) {
user.setRoles(userVO.getRolesStr());
this.sysUserDAO.updateByPrimaryKey(user);
UserVO newUserVO = sysUserDAO.queryUserWithCompany(id);
newUserVO.setRolesByString();
UserVO newUserVO = queryUserInfoWithOrgInfo(id);
this.loginSessionManager.updateLoginUser(newUserVO);
}
}
@ -385,7 +379,7 @@ public class SysUserService implements ISysUserService {
@Override
public UserVO getUserBaseInfoById(Long id) {
UserVO userVO = this.sysUserDAO.queryUserWithCompany(id);
UserVO userVO = this.queryUserInfoWithOrgInfo(id);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(userVO, "不存在的用户");
userVO.setRolesByString();
userVO.setWmOpenId(null);
@ -448,7 +442,7 @@ public class SysUserService implements ISysUserService {
if (CollectionUtils.isEmpty(list)) {
return null;
}
UserVO userVO = sysUserDAO.queryUserWithCompany(list.get(0).getId());
UserVO userVO = this.queryUserInfoWithOrgInfo(list.get(0).getId());
userVO.setRolesByString();
return userVO;
}
@ -460,7 +454,7 @@ public class SysUserService implements ISysUserService {
example.createCriteria().andWmOpenIdEqualTo(wmOpenId);
List<SysUser> userList = this.sysUserDAO.selectByExample(example);
if (!CollectionUtils.isEmpty(userList)) {
UserVO userVO = sysUserDAO.queryUserWithCompany(userList.get(0).getId());
UserVO userVO = queryUserInfoWithOrgInfo(userList.get(0).getId());
userVO.setRolesByString();
return userVO;
}
@ -590,8 +584,7 @@ public class SysUserService implements ISysUserService {
user.setName(name);
user.setUpdateTime(LocalDateTime.now());
this.sysUserDAO.updateByPrimaryKey(user);
UserVO userVO = sysUserDAO.queryUserWithCompany(id);
userVO.setRolesByString();
UserVO userVO = this.queryUserInfoWithOrgInfo(id);
this.loginSessionManager.updateLoginUser(userVO);
}
}
@ -605,8 +598,7 @@ public class SysUserService implements ISysUserService {
user.setNickname(nickname);
user.setUpdateTime(LocalDateTime.now());
this.sysUserDAO.updateByPrimaryKey(user);
UserVO userVO = sysUserDAO.queryUserWithCompany(id);
userVO.setRolesByString();
UserVO userVO = this.queryUserInfoWithOrgInfo(id);
this.loginSessionManager.updateLoginUser(userVO);
}
}
@ -618,8 +610,7 @@ public class SysUserService implements ISysUserService {
user.setAvatarPath(avatarPath);
user.setUpdateTime(LocalDateTime.now());
this.sysUserDAO.updateByPrimaryKey(user);
UserVO userVO = sysUserDAO.queryUserWithCompany(id);
userVO.setRolesByString();
UserVO userVO = queryUserInfoWithOrgInfo(id);
this.loginSessionManager.updateLoginUser(userVO);
}
}
@ -637,8 +628,7 @@ public class SysUserService implements ISysUserService {
user.setMobile(updateMobileVO.getMobile());
user.setUpdateTime(LocalDateTime.now());
this.sysUserDAO.updateByPrimaryKey(user);
UserVO userVO = sysUserDAO.queryUserWithCompany(id);
userVO.setRolesByString();
UserVO userVO = this.queryUserInfoWithOrgInfo(id);
this.loginSessionManager.updateLoginUser(userVO);
}
}
@ -655,8 +645,7 @@ public class SysUserService implements ISysUserService {
user.setEmail(updateEmailVO.getEmail());
user.setUpdateTime(LocalDateTime.now());
this.sysUserDAO.updateByPrimaryKey(user);
UserVO userVO = sysUserDAO.queryUserWithCompany(id);
userVO.setRolesByString();
UserVO userVO = this.queryUserInfoWithOrgInfo(id);
this.loginSessionManager.updateLoginUser(userVO);
}
}
@ -793,8 +782,7 @@ public class SysUserService implements ISysUserService {
user.setRoles(updateUserVO.getRolesStr());
user.setUpdateTime(LocalDateTime.now());
this.sysUserDAO.updateByPrimaryKey(user);
UserVO newUserVO = sysUserDAO.queryUserWithCompany(userId);
newUserVO.setRolesByString();
UserVO newUserVO = this.queryUserInfoWithOrgInfo(userId);
this.loginSessionManager.updateLoginUser(newUserVO);
}
// //更新所属公司
@ -840,4 +828,18 @@ public class SysUserService implements ISysUserService {
.andEmailEqualTo(email);
return sysUserDAO.countByExample(example) > 0;
}
/**
* 查询包含组织信息的用户信息
*/
private UserVO queryUserInfoWithOrgInfo(long userId) {
SysUser sysUser = getEntity(userId);
UserVO userVO = new UserVO(sysUser);
List<OrgUser> adminOrgUser = iOrgUserService.findEntitiesByUserId(userId, BusinessConsts.OrgRole.Admin);
if (!CollectionUtils.isEmpty(adminOrgUser)) {
Org org = iOrgService.findEntity(adminOrgUser.get(0).getOrgId());
userVO.setOrgInfo(org, true);
}
return userVO;
}
}

View File

@ -27,7 +27,9 @@ public interface IOrgService {
void createCls(NonTopOrgCreateVO createVO, LoginUserInfoVO loginInfo);
Org getEntity(Long orgId);
Org getEntity(long orgId);
Org findEntity(long orgId);
Org getEntity(Project project, String status);

View File

@ -105,12 +105,17 @@ public class OrgService implements IOrgService {
}
@Override
public Org getEntity(Long orgId) {
public Org getEntity(long orgId) {
Org org = orgDAO.selectByPrimaryKey(orgId);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(org, String.format("id为[%s]的组织不存在", orgId));
return org;
}
@Override
public Org findEntity(long orgId) {
return orgDAO.selectByPrimaryKey(orgId);
}
@Override
public Org getEntity(Project project, String status) {
Org org = findEntity(project, status);

View File

@ -24,10 +24,7 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
@Service
@ -398,9 +395,7 @@ public class OrgUserService implements IOrgUserService {
}
/* 建立新关系 */
create(topOrgId, userVO.getId(), BusinessConsts.OrgRole.Admin);
userVO.setCompanyId(topOrgId);
userVO.setCompanyName(topOrg.getName());
userVO.setCompanyAdmin(true);
userVO.setOrgInfo(topOrg, true);
}

View File

@ -1,6 +1,7 @@
package club.joylink.rtss.vo;
import club.joylink.rtss.constants.BusinessConsts;
import club.joylink.rtss.entity.Org;
import club.joylink.rtss.entity.SysUser;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
@ -17,6 +18,7 @@ import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@ -274,4 +276,13 @@ public class UserVO implements Serializable {
this.roles = List.of(dbRoles.split(","));
}
}
public void setOrgInfo(Org org, Boolean companyAdmin) {
this.companyId = org.getId();
this.companyName = org.getName();
this.companyAdmin = companyAdmin;
if (StringUtils.hasText(org.getProjectCode())) {
this.projectCodes = Arrays.asList(org.getProjectCode().split(","));
}
}
}