解除对Org.projectCode的使用

This commit is contained in:
joylink_zhangsai 2022-12-09 18:04:38 +08:00
parent 7ef02b4ce4
commit e81fa4548d
23 changed files with 315 additions and 374 deletions

View File

@ -44,7 +44,7 @@ public class CompanyController {
* 创建顶级组织 * 创建顶级组织
*/ */
@PostMapping @PostMapping
public CompanyVO create(@RequestBody @Validated CompanyVO company, @RequestAttribute(AuthenticateInterceptor.LOGIN_USER_KEY) AccountVO user) { public OrgVO create(@RequestBody @Validated OrgVO company, @RequestAttribute(AuthenticateInterceptor.LOGIN_USER_KEY) AccountVO user) {
return iOrgService.createTopOrg(company, user); return iOrgService.createTopOrg(company, user);
} }
@ -52,7 +52,7 @@ public class CompanyController {
* 获取公司列表 * 获取公司列表
*/ */
@GetMapping @GetMapping
public List<CompanyVO> queryAll() { public List<OrgVO> queryAll() {
return iOrgService.queryAllTopOrg(); return iOrgService.queryAllTopOrg();
} }
@ -60,7 +60,7 @@ public class CompanyController {
* 分页获取公司列表 * 分页获取公司列表
*/ */
@GetMapping("paging") @GetMapping("paging")
public PageVO<CompanyVO> pagingQueryAll(OrgQueryVO queryVO) { public PageVO<OrgVO> pagingQueryAll(OrgQueryVO queryVO) {
return iOrgService.pagedQueryAllTopOrg(queryVO); return iOrgService.pagedQueryAllTopOrg(queryVO);
} }
@ -68,7 +68,7 @@ public class CompanyController {
* 查询公司信息 * 查询公司信息
*/ */
@GetMapping("{id}") @GetMapping("{id}")
public CompanyVO get(@PathVariable Long id) { public OrgVO get(@PathVariable Long id) {
return iOrgService.get(id); return iOrgService.get(id);
} }
@ -76,7 +76,7 @@ public class CompanyController {
* 更新公司信息 * 更新公司信息
*/ */
@PutMapping("{id}") @PutMapping("{id}")
public CompanyVO updateCompany(@PathVariable Long id, @RequestBody @Validated CompanyVO company, @RequestAttribute AccountVO user) { public OrgVO updateCompany(@PathVariable Long id, @RequestBody @Validated OrgVO company, @RequestAttribute AccountVO user) {
return iOrgService.updateOrg(id, company, user); return iOrgService.updateOrg(id, company, user);
} }
@ -84,7 +84,7 @@ public class CompanyController {
* 微信小程用户绑定为单位管理员 * 微信小程用户绑定为单位管理员
*/ */
@PutMapping(path = "/bind/company") @PutMapping(path = "/bind/company")
public CompanyVO userScanCodeBindCompany(Long userId, Long companyId) { public OrgVO userScanCodeBindCompany(Long userId, Long companyId) {
return iOrgUserService.userScanCodeBindCompanyManager(userId, companyId); return iOrgUserService.userScanCodeBindCompanyManager(userId, companyId);
} }
@ -92,15 +92,15 @@ public class CompanyController {
* 添加部门信息 * 添加部门信息
*/ */
@PostMapping(path = "/dept") @PostMapping(path = "/dept")
public DepartmentVO createDepart(@RequestBody @Validated DepartmentVO departmentVO) { public OrgVO createDepart(@RequestBody @Validated OrgVO orgVO) {
return iOrgUserService.createDepart(departmentVO); return iOrgUserService.createDepart(orgVO);
} }
/** /**
* 获取单位所有部门 * 获取单位所有部门
*/ */
@GetMapping(path = "{companyId}/dept") @GetMapping(path = "{companyId}/dept")
public List<DepartmentVO> queryCompanyDepart(@PathVariable Long companyId) { public List<OrgVO> queryCompanyDepart(@PathVariable Long companyId) {
return iOrgUserService.getCompanyAllDepart(companyId); return iOrgUserService.getCompanyAllDepart(companyId);
} }
@ -108,7 +108,7 @@ public class CompanyController {
* 获取部门及其子树 * 获取部门及其子树
*/ */
@GetMapping(path = "{companyId}/dept/{deptId}/tree") @GetMapping(path = "{companyId}/dept/{deptId}/tree")
public DepartmentVO queryDepartTree(@PathVariable Long deptId, @PathVariable Long companyId) { public OrgVO queryDepartTree(@PathVariable Long deptId, @PathVariable Long companyId) {
return iOrgUserService.getDepartTree(companyId, deptId); return iOrgUserService.getDepartTree(companyId, deptId);
} }
@ -116,7 +116,7 @@ public class CompanyController {
* 获取部门及其子部门 * 获取部门及其子部门
*/ */
@GetMapping(path = "{companyId}/dept/{deptId}") @GetMapping(path = "{companyId}/dept/{deptId}")
public List<DepartmentVO> queryDepart(@PathVariable Long deptId, @PathVariable Long companyId) { public List<OrgVO> queryDepart(@PathVariable Long deptId, @PathVariable Long companyId) {
return iOrgUserService.getDepartAndChild(companyId, deptId); return iOrgUserService.getDepartAndChild(companyId, deptId);
} }
@ -132,16 +132,16 @@ public class CompanyController {
* 查询部门信息 * 查询部门信息
*/ */
@GetMapping("/dept/{deptId}") @GetMapping("/dept/{deptId}")
public DepartmentVO getDepart(@PathVariable Long deptId) { public OrgVO queryDepart(@PathVariable Long deptId) {
return iOrgUserService.getDepartById(deptId); return iOrgUserService.queryDepartById(deptId);
} }
/** /**
* 更新部门信息 * 更新部门信息
*/ */
@PutMapping("/dept/{id}") @PutMapping("/dept/{id}")
public void updateDepartInfo(@PathVariable Long id, @RequestBody @Validated DepartmentVO departmentVO) { public void updateDepartInfo(@PathVariable Long id, @RequestBody @Validated OrgVO orgVO) {
iOrgUserService.updateDepartInfo(id, departmentVO); iOrgUserService.updateDepartInfo(id, orgVO);
} }
/** /**
@ -228,7 +228,7 @@ public class CompanyController {
* 分页查询当前登录用户所属组织下的班级 * 分页查询当前登录用户所属组织下的班级
*/ */
@GetMapping("/paged/cls") @GetMapping("/paged/cls")
public PageVO<DepartmentVO> pagedQuerySelfCls(OrgQueryVO queryVO, @RequestAttribute LoginUserInfoVO loginInfo) { public PageVO<OrgVO> pagedQuerySelfCls(OrgQueryVO queryVO, @RequestAttribute LoginUserInfoVO loginInfo) {
return iOrgService.pagedQueryCls(queryVO, loginInfo); return iOrgService.pagedQueryCls(queryVO, loginInfo);
} }
@ -236,7 +236,7 @@ public class CompanyController {
* 查询当前登录项目所属组织下的班级 * 查询当前登录项目所属组织下的班级
*/ */
@GetMapping("/list/cls") @GetMapping("/list/cls")
public List<DepartmentVO> queryCls(OrgQueryVO queryVO, @RequestAttribute LoginUserInfoVO loginInfo) { public List<OrgVO> queryCls(OrgQueryVO queryVO, @RequestAttribute LoginUserInfoVO loginInfo) {
return iOrgService.queryCls(queryVO, loginInfo); return iOrgService.queryCls(queryVO, loginInfo);
} }
@ -302,7 +302,7 @@ public class CompanyController {
* 查询规则能够应用到的组织 * 查询规则能够应用到的组织
*/ */
@GetMapping("/orgScoringRule/{ruleId}/canApplyTo") @GetMapping("/orgScoringRule/{ruleId}/canApplyTo")
public List<DepartmentVO> queryRuleCanApplyTo(@PathVariable Long ruleId, @RequestAttribute AccountVO user) { public List<OrgVO> queryRuleCanApplyTo(@PathVariable Long ruleId, @RequestAttribute AccountVO user) {
return iOrgScoringRuleService.queryRuleCanApplyTo(ruleId, user); return iOrgScoringRuleService.queryRuleCanApplyTo(ruleId, user);
} }

View File

@ -1,7 +1,7 @@
package club.joylink.rtss.controller.org; package club.joylink.rtss.controller.org;
import club.joylink.rtss.services.org.IOrgService; import club.joylink.rtss.services.org.IOrgService;
import club.joylink.rtss.vo.client.org.DepartmentVO; import club.joylink.rtss.vo.client.org.OrgVO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
@ -23,7 +23,7 @@ public class OrgController {
* 列表查询该组织下的所有班级 * 列表查询该组织下的所有班级
*/ */
@GetMapping("/{topOrgId}/cls/list") @GetMapping("/{topOrgId}/cls/list")
public List<DepartmentVO> listQueryCls(@PathVariable long topOrgId) { public List<OrgVO> listQueryCls(@PathVariable long topOrgId) {
return iOrgService.listQueryCls(topOrgId); return iOrgService.listQueryCls(topOrgId);
} }
} }

View File

@ -5,8 +5,8 @@ import club.joylink.rtss.entity.org.OrgProject;
import club.joylink.rtss.services.org.IOrgProjectService; import club.joylink.rtss.services.org.IOrgProjectService;
import club.joylink.rtss.services.org.OrgService; import club.joylink.rtss.services.org.OrgService;
import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.org.CompanyVO;
import club.joylink.rtss.vo.client.org.OrgProjectVO; import club.joylink.rtss.vo.client.org.OrgProjectVO;
import club.joylink.rtss.vo.client.org.OrgVO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -57,8 +57,8 @@ public class OrgProjectController {
OrgProject orgProject = new OrgProject(); OrgProject orgProject = new OrgProject();
orgProject.setCreateTime(LocalDateTime.now()); orgProject.setCreateTime(LocalDateTime.now());
orgProject.setCreatorId(1L); orgProject.setCreatorId(1L);
List<CompanyVO> orgs = orgService.queryAllTopOrg(); List<OrgVO> orgs = orgService.queryAllTopOrg();
for (CompanyVO org : orgs) { for (OrgVO org : orgs) {
List<String> projectCodes = org.getProjectCodes(); List<String> projectCodes = org.getProjectCodes();
if (!CollectionUtils.isEmpty(projectCodes)) { if (!CollectionUtils.isEmpty(projectCodes)) {
for (String projectCode : projectCodes) { for (String projectCode : projectCodes) {

View File

@ -6,7 +6,7 @@ import club.joylink.rtss.entity.project.ProjectView;
import club.joylink.rtss.services.project.ProjectService; import club.joylink.rtss.services.project.ProjectService;
import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.org.CompanyVO; import club.joylink.rtss.vo.client.org.OrgVO;
import club.joylink.rtss.vo.project.*; import club.joylink.rtss.vo.project.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -69,14 +69,14 @@ public class ProjectInfoController {
} }
@GetMapping("/{id}/orgList") @GetMapping("/{id}/orgList")
public List<CompanyVO> orgList(@PathVariable Long id) { public List<OrgVO> orgList(@PathVariable Long id) {
return projectService.projectOrgList(id); return projectService.projectOrgList(id);
} }
@PostMapping("/{id}/createDefaultOrg") @PostMapping("/{id}/createDefaultOrg")
public ProjectInfoVO quickCreateDefaultOrg(@PathVariable Long id, @RequestBody CompanyVO companyVO public ProjectInfoVO quickCreateDefaultOrg(@PathVariable Long id, @RequestBody OrgVO orgVO
, @RequestAttribute(AuthenticateInterceptor.LOGIN_USER_KEY) AccountVO user) { , @RequestAttribute(AuthenticateInterceptor.LOGIN_USER_KEY) AccountVO user) {
return projectService.quickCreateDefaultOrg(id, companyVO, user); return projectService.quickCreateDefaultOrg(id, orgVO, user);
} }
@GetMapping("/viewSetting/page") @GetMapping("/viewSetting/page")

View File

@ -4,7 +4,7 @@ import java.io.Serializable;
import java.time.LocalDateTime; import java.time.LocalDateTime;
/** /**
* @author * @author
* 组织树 * 组织树
*/ */
public class Org implements Serializable { public class Org implements Serializable {
@ -28,6 +28,7 @@ public class Org implements Serializable {
/** /**
* 关联项目code * 关联项目code
*/ */
@Deprecated(forRemoval = true)
private String projectCode; private String projectCode;
private String code; private String code;
@ -211,4 +212,4 @@ public class Org implements Serializable {
sb.append("]"); sb.append("]");
return sb.toString(); return sb.toString();
} }
} }

View File

@ -1,12 +1,11 @@
package club.joylink.rtss.services; package club.joylink.rtss.services;
import club.joylink.rtss.entity.Org;
import club.joylink.rtss.entity.SysAccount; import club.joylink.rtss.entity.SysAccount;
import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.UserQueryVO; import club.joylink.rtss.vo.UserQueryVO;
import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.org.CompanyVO; import club.joylink.rtss.vo.client.org.OrgVO;
import club.joylink.rtss.vo.client.user.*; import club.joylink.rtss.vo.client.user.*;
import club.joylink.rtss.vo.user.AccountCreateVO; import club.joylink.rtss.vo.user.AccountCreateVO;
import club.joylink.rtss.vo.wx.WmUserSession; import club.joylink.rtss.vo.wx.WmUserSession;
@ -33,16 +32,6 @@ public interface ISysUserService {
*/ */
AccountVO findUserById(Long id); AccountVO findUserById(Long id);
/**
* 设置用户的与项目{project}关联的组织信息
*/
void setOrgInfoOfOrgRelWithTheProject(String project, AccountVO accountVO);
/**
* 设置用户与该组织的关联信息
*/
void setOrgInfoOfThisOrg(Org topOrg, AccountVO accountVO);
SysAccount findEntity(@NonNull String account, long orgId); SysAccount findEntity(@NonNull String account, long orgId);
boolean isExist(@NonNull String account, long orgId); boolean isExist(@NonNull String account, long orgId);
@ -308,7 +297,7 @@ public interface ISysUserService {
*/ */
void userBindWm(String code, Long userId); void userBindWm(String code, Long userId);
CompanyVO userScanCodeBindCompanyManager(Long userId, Long companyId); OrgVO userScanCodeBindCompanyManager(Long userId, Long companyId);
AccountVO getUserBaseInfoById(Long id); AccountVO getUserBaseInfoById(Long id);

View File

@ -1,6 +1,5 @@
package club.joylink.rtss.services; package club.joylink.rtss.services;
import club.joylink.rtss.configuration.configProp.WeChatConfig;
import club.joylink.rtss.constants.BusinessConsts; import club.joylink.rtss.constants.BusinessConsts;
import club.joylink.rtss.constants.EmailSubject; import club.joylink.rtss.constants.EmailSubject;
import club.joylink.rtss.constants.StatusEnum; import club.joylink.rtss.constants.StatusEnum;
@ -10,13 +9,14 @@ import club.joylink.rtss.dao.UserSubscribeMapper;
import club.joylink.rtss.entity.*; import club.joylink.rtss.entity.*;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.cache.ICacheService; import club.joylink.rtss.services.cache.ICacheService;
import club.joylink.rtss.services.org.IOrgProjectService;
import club.joylink.rtss.services.org.IOrgService; 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.*; import club.joylink.rtss.vo.*;
import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.org.CompanyVO; import club.joylink.rtss.vo.client.org.OrgVO;
import club.joylink.rtss.vo.client.user.*; import club.joylink.rtss.vo.client.user.*;
import club.joylink.rtss.vo.map.MapVO; import club.joylink.rtss.vo.map.MapVO;
import club.joylink.rtss.vo.user.AccountCreateVO; import club.joylink.rtss.vo.user.AccountCreateVO;
@ -64,9 +64,6 @@ public class SysUserService implements ISysUserService {
@Autowired @Autowired
private UserSubscribeMapper userSubscribeMapper; private UserSubscribeMapper userSubscribeMapper;
@Autowired
private WeChatConfig weChatConfig;
@Autowired @Autowired
private IWxApiService iWxApiService; private IWxApiService iWxApiService;
@ -84,6 +81,8 @@ public class SysUserService implements ISysUserService {
@Autowired @Autowired
private QRCodeManager qrCodeManager; private QRCodeManager qrCodeManager;
@Autowired
private IOrgProjectService iOrgProjectService;
/** /**
* @update 20221019 删除账号查询逻辑去除绑定组织操作 * @update 20221019 删除账号查询逻辑去除绑定组织操作
@ -112,47 +111,6 @@ public class SysUserService implements ISysUserService {
return accountVO; return accountVO;
} }
@Override
public void setOrgInfoOfOrgRelWithTheProject(String project, AccountVO accountVO) {
if (project != null) {
Org topOrg = iOrgService.findTopOrgOfUser(accountVO.getId());
if (topOrg != null && topOrg.getProjectCode().contains(project)) {
setOrgInfoOfThisOrg(topOrg, accountVO);
}
}
}
@Override
public void setOrgInfoOfThisOrg(Org topOrg, AccountVO accountVO) {
if (topOrg != null && accountVO != null && topOrg.getId() != null && accountVO.getId() != null) {
boolean flag = false;
if (Objects.equals(topOrg.getId(), accountVO.getOrgId())) {
flag = true;
} else {
List<OrgUser> orgUsers = iOrgUserService.findEntitiesByUserId(accountVO.getId(), null);
if (CollectionUtils.isEmpty(orgUsers))
return;
if (orgUsers.stream().anyMatch(ou -> Objects.equals(ou.getOrgId(), topOrg.getId()))) {
flag = true;
} else {
List<Long> orgIds = orgUsers.stream().map(OrgUser::getOrgId).collect(Collectors.toList());
if (CollectionUtils.isEmpty(orgIds))
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())) {
flag = true;
}
}
}
if (flag) {
accountVO.setOrgInfo(topOrg, iOrgUserService.isTheRoleInThisOrg(accountVO.getId(), topOrg.getId(), BusinessConsts.OrgRole.Admin));
}
}
}
@Override @Override
public SysAccount findEntity(@NonNull String account, long orgId) { public SysAccount findEntity(@NonNull String account, long orgId) {
SysAccountExample example = new SysAccountExample(); SysAccountExample example = new SysAccountExample();
@ -301,20 +259,32 @@ public class SysUserService implements ISysUserService {
PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize());
Page<SysAccount> page = (Page<SysAccount>) this.sysAccountDAO.selectByExample(example); Page<SysAccount> page = (Page<SysAccount>) this.sysAccountDAO.selectByExample(example);
List<AccountVO> accountVOS = AccountVO.convertFromDB(page.getResult()); List<AccountVO> accountVOS = AccountVO.convertFromDB(page.getResult());
List<Long> userIds = accountVOS.stream().map(AccountVO::getId).collect(Collectors.toList()); // List<Long> userIds = accountVOS.stream().map(AccountVO::getId).collect(Collectors.toList());
Map<Long, Long> userOrgMap = iOrgUserService.findEntitiesByUserIds(userIds, BusinessConsts.OrgRole.Admin) // Map<Long, Long> userOrgMap = iOrgUserService.findEntitiesByUserIds(userIds, BusinessConsts.OrgRole.Admin)
.stream().collect(Collectors.toMap(OrgUser::getUserId, OrgUser::getOrgId)); // .stream().collect(Collectors.toMap(OrgUser::getUserId, OrgUser::getOrgId));
Map<Long, Org> orgMap = iOrgService.findEntities(new ArrayList<>(userOrgMap.values()), BusinessConsts.Org.Status.VALID) // Map<Long, Org> orgMap = iOrgService.findEntities(new ArrayList<>(userOrgMap.values()), BusinessConsts.Org.Status.VALID)
.stream().collect(Collectors.toMap(Org::getId, Function.identity())); // .stream().collect(Collectors.toMap(Org::getId, Function.identity()));
accountVOS.forEach(vo -> { // Map<Long, List<String>> orgId_projects_map = iOrgProjectService.queryOrgProjectListByOrgIds(new ArrayList<>(orgMap.keySet())).stream()
Long orgId = userOrgMap.get(vo.getId()); // .collect(Collectors.groupingBy(OrgProject::getOrgId, Collectors.mapping(OrgProject::getProjectCode, Collectors.toList())));
if (orgId != null) { // accountVOS.forEach(vo -> {
Org org = orgMap.get(orgId); // Long orgId = userOrgMap.get(vo.getId());
if (org != null) { // if (orgId != null) {
vo.setOrgInfo(org, true); // Org org = orgMap.get(orgId);
} // if (org != null) {
// vo.setOrgInfo(org, true, orgId_projects_map.get(org.getId()));
// }
// }
// });
List<Long> orgIds = accountVOS.stream().map(AccountVO::getOrgId).collect(Collectors.toList());
Map<Long, Org> orgMap = iOrgService.findEntities(orgIds, null).stream()
.collect(Collectors.toMap(Org::getId, Function.identity()));
accountVOS.forEach(accountVO -> {
Org org = orgMap.get(accountVO.getOrgId());
if (org != null) {
accountVO.setOrgInfo(org, false, null);
} }
}); });
return PageVO.convert(page, accountVOS); return PageVO.convert(page, accountVOS);
} }
@ -405,15 +375,13 @@ public class SysUserService implements ISysUserService {
@Override @Override
@Transactional @Transactional
public CompanyVO userScanCodeBindCompanyManager(Long userId, Long companyId) { public OrgVO userScanCodeBindCompanyManager(Long userId, Long companyId) {
Org company = companyDAO.selectByPrimaryKey(companyId);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(company, String.format("id为[%s]的组织不存在", companyId));
SysAccount sysAccount = sysAccountDAO.selectByPrimaryKey(userId); SysAccount sysAccount = sysAccountDAO.selectByPrimaryKey(userId);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(sysAccount, String.format("id为[%s]的用户不存在", userId)); BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(sysAccount, String.format("id为[%s]的用户不存在", userId));
AccountVO accountVO = new AccountVO(sysAccount); AccountVO accountVO = new AccountVO(sysAccount);
iOrgUserService.userBindCompanyManager(accountVO, companyId); OrgVO orgVO = iOrgUserService.userBindCompanyManager(accountVO, companyId);
this.loginSessionManager.updateLoginUser(accountVO); this.loginSessionManager.updateLoginUser(accountVO);
return new CompanyVO(company); return orgVO;
} }
@Override @Override
@ -1056,11 +1024,16 @@ public class SysUserService implements ISysUserService {
private AccountVO queryUserInfoWithOrgInfo(long userId) { private AccountVO queryUserInfoWithOrgInfo(long userId) {
SysAccount sysAccount = getEntity(userId); SysAccount sysAccount = getEntity(userId);
AccountVO accountVO = new AccountVO(sysAccount); AccountVO accountVO = new AccountVO(sysAccount);
List<OrgUser> adminOrgUser = iOrgUserService.findEntitiesByUserId(userId, BusinessConsts.OrgRole.Admin); // 2022-12-09 17:27:30 账号组织关系变成一对多之后这里逻辑不清楚了经查只用到了account字段故删除以下
if (!CollectionUtils.isEmpty(adminOrgUser)) { // List<OrgUser> adminOrgUser = iOrgUserService.findEntitiesByUserId(userId, BusinessConsts.OrgRole.Admin);
Org org = iOrgService.findEntity(adminOrgUser.get(0).getOrgId()); // if (!CollectionUtils.isEmpty(adminOrgUser)) {
accountVO.setOrgInfo(org, true); // Org org = iOrgService.findEntity(adminOrgUser.get(0).getOrgId());
} // if (org != null) {
// List<String> projects = iOrgProjectService.queryOrgProjectListByOrgId(org.getId()).stream()
// .map(OrgProject::getProjectCode).collect(Collectors.toList());
// accountVO.setOrgInfo(org, true, projects);
// }
// }
return accountVO; return accountVO;
} }

View File

@ -37,4 +37,6 @@ public interface IOrgProjectService {
* 保存顶级信息时处理编辑信息 * 保存顶级信息时处理编辑信息
*/ */
void update(Long orgId, List<String> projectList, AccountVO user); void update(Long orgId, List<String> projectList, AccountVO user);
List<OrgProject> queryOrgProjectListByOrgIds(List<Long> orgIds);
} }

View File

@ -3,10 +3,10 @@ package club.joylink.rtss.services.org;
import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.org.DepartmentVO;
import club.joylink.rtss.vo.client.org.OrgScoringResultVO; import club.joylink.rtss.vo.client.org.OrgScoringResultVO;
import club.joylink.rtss.vo.client.org.OrgScoringRuleQueryVO; import club.joylink.rtss.vo.client.org.OrgScoringRuleQueryVO;
import club.joylink.rtss.vo.client.org.OrgScoringRuleVO; import club.joylink.rtss.vo.client.org.OrgScoringRuleVO;
import club.joylink.rtss.vo.client.org.OrgVO;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
@ -57,5 +57,5 @@ public interface IOrgScoringRuleService {
* 查询评价规则能应用到的组织 * 查询评价规则能应用到的组织
* @return * @return
*/ */
List<DepartmentVO> queryRuleCanApplyTo(Long ruleId, AccountVO user); List<OrgVO> queryRuleCanApplyTo(Long ruleId, AccountVO user);
} }

View File

@ -6,10 +6,9 @@ import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.ExamDefinitionVO; import club.joylink.rtss.vo.client.ExamDefinitionVO;
import club.joylink.rtss.vo.client.Node; import club.joylink.rtss.vo.client.Node;
import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.org.CompanyVO;
import club.joylink.rtss.vo.client.org.DepartmentVO;
import club.joylink.rtss.vo.client.org.NonTopOrgCreateVO; import club.joylink.rtss.vo.client.org.NonTopOrgCreateVO;
import club.joylink.rtss.vo.client.org.OrgQueryVO; import club.joylink.rtss.vo.client.org.OrgQueryVO;
import club.joylink.rtss.vo.client.org.OrgVO;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.Collection; import java.util.Collection;
@ -17,11 +16,11 @@ import java.util.List;
public interface IOrgService { public interface IOrgService {
@Transactional @Transactional
CompanyVO createTopOrg(CompanyVO companyVO, AccountVO user); OrgVO createTopOrg(OrgVO orgVO, AccountVO user);
List<CompanyVO> queryAllTopOrg(); List<OrgVO> queryAllTopOrg();
PageVO<CompanyVO> pagedQueryAllTopOrg(OrgQueryVO queryVO); PageVO<OrgVO> pagedQueryAllTopOrg(OrgQueryVO queryVO);
void confirmExist(Long orgId); void confirmExist(Long orgId);
@ -37,7 +36,7 @@ public interface IOrgService {
// TODO 20220922 将Project 修改为 String // TODO 20220922 将Project 修改为 String
Collection<Org> findEntities(String project, String status); Collection<Org> findEntities(String project, String status);
CompanyVO updateOrg(Long id, CompanyVO companyVO, AccountVO user); OrgVO updateOrg(Long id, OrgVO orgVO, AccountVO user);
/** /**
* 删除非顶级组织 * 删除非顶级组织
@ -51,12 +50,12 @@ public interface IOrgService {
/** /**
* 分页查询自己创建的班级 * 分页查询自己创建的班级
*/ */
PageVO<DepartmentVO> pagedQueryCls(OrgQueryVO queryVO, LoginUserInfoVO loginInfo); PageVO<OrgVO> pagedQueryCls(OrgQueryVO queryVO, LoginUserInfoVO loginInfo);
/** /**
* 查询自己创建的班级 * 查询自己创建的班级
*/ */
List<DepartmentVO> queryCls(OrgQueryVO queryVO, LoginUserInfoVO loginInfo); List<OrgVO> queryCls(OrgQueryVO queryVO, LoginUserInfoVO loginInfo);
/** /**
* 获取该组织所属的顶级组织 * 获取该组织所属的顶级组织
@ -70,7 +69,7 @@ public interface IOrgService {
*/ */
Node<Object> adminQueryOrgTree(Long orgId); Node<Object> adminQueryOrgTree(Long orgId);
CompanyVO get(Long id); OrgVO get(Long id);
/** /**
* 查询这些考试关联的班级 * 查询这些考试关联的班级
@ -96,5 +95,12 @@ public interface IOrgService {
* 查询该组织下的所有班级 * 查询该组织下的所有班级
* 目前组织结构仅有两级非顶级的就是班级 * 目前组织结构仅有两级非顶级的就是班级
*/ */
List<DepartmentVO> listQueryCls(long topOrgId); List<OrgVO> listQueryCls(long topOrgId);
/**
* 查询组织信息可能返回null
*/
OrgVO query(Long id);
OrgVO getTopOrg(long topOrgId);
} }

View File

@ -15,21 +15,21 @@ public interface IOrgUserService {
/** /**
* 用户绑定为单位管理员 * 用户绑定为单位管理员
*/ */
CompanyVO userScanCodeBindCompanyManager(Long userId, Long companyId); OrgVO userScanCodeBindCompanyManager(Long userId, Long companyId);
DepartmentVO createDepart(DepartmentVO departmentVO); OrgVO createDepart(OrgVO orgVO);
void updateDepartInfo(Long id, DepartmentVO departmentVO); void updateDepartInfo(Long id, OrgVO orgVO);
DepartmentVO getDepartById(Long deptId); OrgVO queryDepartById(Long deptId);
List<DepartmentVO> getCompanyDepartTree(Long companyId); List<OrgVO> getCompanyDepartTree(Long companyId);
List<DepartmentVO> getCompanyAllDepart(Long companyId); List<OrgVO> getCompanyAllDepart(Long companyId);
DepartmentVO getDepartTree(Long companyId, Long deptId); OrgVO getDepartTree(Long companyId, Long deptId);
List<DepartmentVO> getDepartAndChild(Long companyId, Long deptId); List<OrgVO> getDepartAndChild(Long companyId, Long deptId);
void addDepartUserInfo(AccountVO user, UserDepartRelVO userDepartRelVO); void addDepartUserInfo(AccountVO user, UserDepartRelVO userDepartRelVO);
@ -74,7 +74,7 @@ public interface IOrgUserService {
List<OrgUser> findEntitiesByUserId(long userId, BusinessConsts.OrgRole role); List<OrgUser> findEntitiesByUserId(long userId, BusinessConsts.OrgRole role);
void userBindCompanyManager(AccountVO accountVO, Long topOrgId); OrgVO userBindCompanyManager(AccountVO accountVO, Long topOrgId);
List<StudentsUsageStatisticsVO> statisticUsage(UsageQueryVO queryVO); List<StudentsUsageStatisticsVO> statisticUsage(UsageQueryVO queryVO);

View File

@ -15,6 +15,7 @@ import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType;
import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.org.OrgProjectVO; import club.joylink.rtss.vo.client.org.OrgProjectVO;
import club.joylink.rtss.vo.client.org.OrgVO;
import club.joylink.rtss.vo.project.ProjectVO; import club.joylink.rtss.vo.project.ProjectVO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -22,6 +23,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -38,6 +40,10 @@ public class OrgProjectService implements IOrgProjectService {
@Autowired @Autowired
private OrgDAO orgDAO; private OrgDAO orgDAO;
@Autowired
private IOrgService iOrgService;
@Autowired
private IOrgUserService iOrgUserService;
@Override @Override
public List<OrgProject> queryOrgProjectListByOrgId(Long orgId) { public List<OrgProject> queryOrgProjectListByOrgId(Long orgId) {
@ -78,24 +84,9 @@ public class OrgProjectService implements IOrgProjectService {
@Override @Override
public void signInOrg(Long orgId, LoginUserInfoVO loginInfo) { public void signInOrg(Long orgId, LoginUserInfoVO loginInfo) {
// TODO 验证权限 OrgVO orgVO = iOrgService.getTopOrg(orgId);
boolean orgAdmin = iOrgUserService.isTheRoleInThisOrg(loginInfo.getAccountVO().getId(), orgId, BusinessConsts.OrgRole.Admin);
Org topOrg = orgDAO.selectByPrimaryKey(orgId); loginInfo.setOrgProjectVO(orgVO, orgAdmin);
if (topOrg == null) {
throw new SimulationException(SimulationExceptionType.Illegal_Argument);
}
// 是否是顶级组织的管理员
OrgUserExample example = new OrgUserExample();
example.createCriteria().andUserIdEqualTo(loginInfo.getAccountVO().getId()).andOrgIdEqualTo(orgId);
List<OrgUser> orgUserList = orgUserDAO.selectByExample(example);
OrgProjectVO orgProjectVO = new OrgProjectVO(topOrg);
if (!CollectionUtils.isEmpty(orgUserList)) {
List<String> roleList = orgUserList.stream().map(OrgUser::getRole).collect(Collectors.toList());
orgProjectVO.setRole(roleList);
} else {
orgProjectVO.setRole(List.of());
}
loginInfo.setOrgProjectVO(orgProjectVO);
} }
@Override @Override
@ -139,6 +130,17 @@ public class OrgProjectService implements IOrgProjectService {
} }
} }
@Override
public List<OrgProject> queryOrgProjectListByOrgIds(List<Long> orgIds) {
if (CollectionUtils.isEmpty(orgIds)) {
return new ArrayList<>();
} else {
OrgProjectExample example = new OrgProjectExample();
example.createCriteria().andOrgIdIn(orgIds);
return orgProjectDao.selectByExample(example);
}
}
/** /**
* 判断数组是否发生变化 * 判断数组是否发生变化
*/ */

View File

@ -4,6 +4,7 @@ import club.joylink.rtss.constants.BusinessConsts;
import club.joylink.rtss.dao.OrgScoringRuleDAO; import club.joylink.rtss.dao.OrgScoringRuleDAO;
import club.joylink.rtss.dao.OrgScoringRuleRelDAO; import club.joylink.rtss.dao.OrgScoringRuleRelDAO;
import club.joylink.rtss.entity.*; import club.joylink.rtss.entity.*;
import club.joylink.rtss.entity.org.OrgProject;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.IExamService; import club.joylink.rtss.services.IExamService;
import club.joylink.rtss.services.ISysUserService; import club.joylink.rtss.services.ISysUserService;
@ -14,10 +15,10 @@ import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.UserRankStatsVO; import club.joylink.rtss.vo.client.UserRankStatsVO;
import club.joylink.rtss.vo.client.org.DepartmentVO;
import club.joylink.rtss.vo.client.org.OrgScoringResultVO; import club.joylink.rtss.vo.client.org.OrgScoringResultVO;
import club.joylink.rtss.vo.client.org.OrgScoringRuleQueryVO; import club.joylink.rtss.vo.client.org.OrgScoringRuleQueryVO;
import club.joylink.rtss.vo.client.org.OrgScoringRuleVO; import club.joylink.rtss.vo.client.org.OrgScoringRuleVO;
import club.joylink.rtss.vo.client.org.OrgVO;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import lombok.NonNull; import lombok.NonNull;
@ -68,6 +69,8 @@ public class OrgScoringRuleService implements IOrgScoringRuleService {
@Autowired @Autowired
private IOrgExamService iOrgExamService; private IOrgExamService iOrgExamService;
@Autowired
private IOrgProjectService iOrgProjectService;
@Override @Override
@ -233,7 +236,7 @@ public class OrgScoringRuleService implements IOrgScoringRuleService {
} }
@Override @Override
public List<DepartmentVO> queryRuleCanApplyTo(Long ruleId, AccountVO user) { public List<OrgVO> queryRuleCanApplyTo(Long ruleId, AccountVO user) {
OrgScoringRuleWithBLOBs rule = getRuleEntity(ruleId); OrgScoringRuleWithBLOBs rule = getRuleEntity(ruleId);
OrgScoringRuleVO vo = OrgScoringRuleVO.buildDetails(rule, null); OrgScoringRuleVO vo = OrgScoringRuleVO.buildDetails(rule, null);
List<Long> lessonIds = vo.getAllLessonIds(); List<Long> lessonIds = vo.getAllLessonIds();
@ -251,9 +254,9 @@ public class OrgScoringRuleService implements IOrgScoringRuleService {
clsIds.addAll(iOrgExamService.findEntities(examIds, user.getId()) clsIds.addAll(iOrgExamService.findEntities(examIds, user.getId())
.stream().map(OrgExam::getOrgId).collect(Collectors.toList())); .stream().map(OrgExam::getOrgId).collect(Collectors.toList()));
} else { } else {
return DepartmentVO.convert2VOList(iOrgService.findEntitiesByParentId(rule.getOrgId(), null, BusinessConsts.Org.Status.VALID)); return OrgVO.convert2VOList(iOrgService.findEntitiesByParentId(rule.getOrgId(), null, BusinessConsts.Org.Status.VALID));
} }
return DepartmentVO.convert2VOList(iOrgService.findEntities(clsIds, BusinessConsts.Org.Status.VALID)); return OrgVO.convert2VOList(iOrgService.findEntities(clsIds, BusinessConsts.Org.Status.VALID));
} }
private void check4Update(OrgScoringRuleVO orgScoringRuleVO) { private void check4Update(OrgScoringRuleVO orgScoringRuleVO) {
@ -306,8 +309,9 @@ public class OrgScoringRuleService implements IOrgScoringRuleService {
List<Long> userIds = students.stream().map(OrgUser::getUserId).collect(Collectors.toList()); List<Long> userIds = students.stream().map(OrgUser::getUserId).collect(Collectors.toList());
List<SysAccount> users = iSysUserService.findEntities(userIds, "id"); List<SysAccount> users = iSysUserService.findEntities(userIds, "id");
Org topOrg = iOrgService.getTopOrgEntity(orgScoringRuleVO.getOrgIds().get(0)); Org topOrg = iOrgService.getTopOrgEntity(orgScoringRuleVO.getOrgIds().get(0));
List<String> projects = iOrgProjectService.queryOrgProjectListByOrgId(topOrg.getId()).stream()
.map(OrgProject::getProjectCode).collect(Collectors.toList());
List<OrgScoringResultVO> results = users.stream().map(OrgScoringResultVO::new).collect(Collectors.toList()); List<OrgScoringResultVO> results = users.stream().map(OrgScoringResultVO::new).collect(Collectors.toList());
List<String> projects = List.of(topOrg.getProjectCode().split(","));
this.score(results, orgScoringRuleVO.getScoringRules(), projects); this.score(results, orgScoringRuleVO.getScoringRules(), projects);
return results; return results;
} }

View File

@ -6,6 +6,7 @@ import club.joylink.rtss.entity.Org;
import club.joylink.rtss.entity.OrgExample; import club.joylink.rtss.entity.OrgExample;
import club.joylink.rtss.entity.OrgUser; import club.joylink.rtss.entity.OrgUser;
import club.joylink.rtss.entity.SysAccount; import club.joylink.rtss.entity.SysAccount;
import club.joylink.rtss.entity.org.OrgProject;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.ISysUserService; import club.joylink.rtss.services.ISysUserService;
import club.joylink.rtss.services.QRCodeManager; import club.joylink.rtss.services.QRCodeManager;
@ -14,7 +15,10 @@ import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.ExamDefinitionVO; import club.joylink.rtss.vo.client.ExamDefinitionVO;
import club.joylink.rtss.vo.client.Node; import club.joylink.rtss.vo.client.Node;
import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.org.*; import club.joylink.rtss.vo.client.org.NonTopOrgCreateVO;
import club.joylink.rtss.vo.client.org.OrgQueryVO;
import club.joylink.rtss.vo.client.org.OrgUserVO;
import club.joylink.rtss.vo.client.org.OrgVO;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import lombok.NonNull; import lombok.NonNull;
@ -48,14 +52,14 @@ public class OrgService implements IOrgService {
@Transactional @Transactional
@Override @Override
public CompanyVO createTopOrg(CompanyVO companyVO, AccountVO user) { public OrgVO createTopOrg(OrgVO orgVO, AccountVO user) {
// /* 检查 */ // /* 检查 */
// if (!CollectionUtils.isEmpty(companyVO.getProjectCodes())) { // if (!CollectionUtils.isEmpty(orgVO.getProjectCodes())) {
// confirmProjectCodesNotRepeat(null, companyVO.getProjectCodes()); // confirmProjectCodesNotRepeat(null, orgVO.getProjectCodes());
// } // }
confirmNameUnique(null, companyVO.getName()); confirmNameUnique(null, orgVO.getName());
/* 处理 */ /* 处理 */
Org entity = companyVO.toDB(); Org entity = orgVO.toDB();
entity.setId(null); entity.setId(null);
entity.setCreatorId(user.getId()); entity.setCreatorId(user.getId());
entity.setCreateTime(LocalDateTime.now()); entity.setCreateTime(LocalDateTime.now());
@ -64,8 +68,8 @@ public class OrgService implements IOrgService {
entity.setRootId(entity.getId()); entity.setRootId(entity.getId());
orgDAO.updateByPrimaryKey(entity); orgDAO.updateByPrimaryKey(entity);
// 20220929 增加 // 20220929 增加
orgProjectService.save(entity.getId(), companyVO.getProjectCodes(), user); orgProjectService.save(entity.getId(), orgVO.getProjectCodes(), user);
return new CompanyVO(entity); return new OrgVO(entity, orgVO.getProjectCodes());
} }
/** /**
@ -83,15 +87,17 @@ public class OrgService implements IOrgService {
} }
@Override @Override
public List<CompanyVO> queryAllTopOrg() { public List<OrgVO> queryAllTopOrg() {
OrgExample example = new OrgExample(); OrgExample example = new OrgExample();
example.createCriteria().andParentIdIsNull(); example.createCriteria().andParentIdIsNull();
List<Org> list = this.orgDAO.selectByExample(example); List<Org> orgs = this.orgDAO.selectByExample(example);
return CompanyVO.convert2VOList(list); List<Long> orgIds = orgs.stream().map(Org::getId).collect(Collectors.toList());
List<OrgProject> orgProjects = orgProjectService.queryOrgProjectListByOrgIds(orgIds);
return OrgVO.convert2VOList(orgs, orgProjects);
} }
@Override @Override
public PageVO<CompanyVO> pagedQueryAllTopOrg(OrgQueryVO queryVO) { public PageVO<OrgVO> pagedQueryAllTopOrg(OrgQueryVO queryVO) {
PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize());
OrgExample example = new OrgExample(); OrgExample example = new OrgExample();
OrgExample.Criteria criteria = example.createCriteria(); OrgExample.Criteria criteria = example.createCriteria();
@ -100,7 +106,9 @@ public class OrgService implements IOrgService {
criteria.andNameLike(String.format("%%%s%%", queryVO.getName())); criteria.andNameLike(String.format("%%%s%%", queryVO.getName()));
} }
Page<Org> page = (Page<Org>) orgDAO.selectByExample(example); Page<Org> page = (Page<Org>) orgDAO.selectByExample(example);
List<CompanyVO> voList = CompanyVO.convert2VOList(page.getResult()); List<Long> orgIds = page.getResult().stream().map(Org::getId).collect(Collectors.toList());
List<OrgProject> orgProjects = orgProjectService.queryOrgProjectListByOrgIds(orgIds);
List<OrgVO> voList = OrgVO.convert2VOList(page.getResult(), orgProjects);
return PageVO.convert(page, voList); return PageVO.convert(page, voList);
} }
@ -152,23 +160,25 @@ public class OrgService implements IOrgService {
} }
@Override @Override
public CompanyVO updateOrg(Long id, CompanyVO companyVO, AccountVO user) { public OrgVO updateOrg(Long id, OrgVO orgVO, AccountVO user) {
//校验 //校验
Org org = getEntity(id); Org org = getEntity(id);
if (!CollectionUtils.isEmpty(companyVO.getProjectCodes())) { if (!CollectionUtils.isEmpty(orgVO.getProjectCodes())) {
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(isTopOrg(org), "非顶级组织不能修改关联项目"); BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(isTopOrg(org), "非顶级组织不能修改关联项目");
// confirmProjectCodesNotRepeat(org.getId(), companyVO.getProjectCodes()); // confirmProjectCodesNotRepeat(org.getId(), orgVO.getProjectCodes());
// 20220929 增加 // 20220929 增加
orgProjectService.update(id, companyVO.getProjectCodes(), user); orgProjectService.update(id, orgVO.getProjectCodes(), user);
} }
confirmNameUnique(id, companyVO.getName()); confirmNameUnique(id, orgVO.getName());
//更新 //更新
org.setName(companyVO.getName()); org.setName(orgVO.getName());
org.setProjectCode(companyVO.getDBProjectCode()); // org.setProjectCode(orgVO.getDBProjectCode());
org.setUpdateId(user.getId()); org.setUpdateId(user.getId());
org.setUpdateTime(LocalDateTime.now()); org.setUpdateTime(LocalDateTime.now());
this.orgDAO.updateByPrimaryKeySelective(org); this.orgDAO.updateByPrimaryKeySelective(org);
return new CompanyVO(org); List<String> projects = orgProjectService.queryOrgProjectListByOrgId(org.getId()).stream()
.map(OrgProject::getProjectCode).collect(Collectors.toList());
return new OrgVO(org, projects);
} }
@Override @Override
@ -194,21 +204,19 @@ public class OrgService implements IOrgService {
} }
@Override @Override
public PageVO<DepartmentVO> pagedQueryCls(OrgQueryVO queryVO, LoginUserInfoVO loginInfo) { public PageVO<OrgVO> pagedQueryCls(OrgQueryVO queryVO, LoginUserInfoVO loginInfo) {
OrgExample example = new OrgExample(); OrgExample example = new OrgExample();
OrgExample.Criteria criteria = example.createCriteria().andParentIdEqualTo(loginInfo.getTopOrgId()) OrgExample.Criteria criteria = example.createCriteria().andParentIdEqualTo(loginInfo.getTopOrgId())
.andStatusEqualTo(BusinessConsts.Org.Status.VALID); .andStatusEqualTo(BusinessConsts.Org.Status.VALID);
if (queryVO != null) { if (StringUtils.hasText(queryVO.getName())) {
if (StringUtils.hasText(queryVO.getName())) { criteria.andNameLike(String.format("%%%s%%", queryVO.getName()));
criteria.andNameLike(String.format("%%%s%%", queryVO.getName())); }
} if (StringUtils.hasText(queryVO.getCreatorName())) {
if (StringUtils.hasText(queryVO.getCreatorName())) { List<Long> creatorIds = iSysUserService.findUserByName(queryVO.getCreatorName()).stream().map(AccountVO::getId).collect(Collectors.toList());
List<Long> creatorIds = iSysUserService.findUserByName(queryVO.getCreatorName()).stream().map(AccountVO::getId).collect(Collectors.toList()); if (CollectionUtils.isEmpty(creatorIds)) {
if (CollectionUtils.isEmpty(creatorIds)) { return new PageVO<>(queryVO.getPageNum(), queryVO.getPageSize(), 0, new ArrayList<>());
return new PageVO<>(queryVO.getPageNum(), queryVO.getPageSize(), 0, new ArrayList<>()); } else {
} else { criteria.andCreatorIdIn(creatorIds);
criteria.andCreatorIdIn(creatorIds);
}
} }
} }
PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize());
@ -216,15 +224,15 @@ public class OrgService implements IOrgService {
List<Long> creatorIds = page.stream().map(Org::getCreatorId).collect(Collectors.toList()); List<Long> creatorIds = page.stream().map(Org::getCreatorId).collect(Collectors.toList());
Map<Long, SysAccount> creatorMap = iSysUserService.findEntities(creatorIds, null).stream() Map<Long, SysAccount> creatorMap = iSysUserService.findEntities(creatorIds, null).stream()
.collect(Collectors.toMap(SysAccount::getId, Function.identity())); .collect(Collectors.toMap(SysAccount::getId, Function.identity()));
List<DepartmentVO> list = page.getResult().stream().map(entity -> { List<OrgVO> list = page.getResult().stream().map(entity -> {
int numberOfPeople = iOrgUserService.getQuantities(entity.getId(), BusinessConsts.OrgRole.Student); int numberOfPeople = iOrgUserService.getQuantities(entity.getId(), BusinessConsts.OrgRole.Student);
return new DepartmentVO(entity, numberOfPeople, creatorMap.get(entity.getCreatorId())); return new OrgVO(entity, null, numberOfPeople, creatorMap.get(entity.getCreatorId()));
}).collect(Collectors.toList()); }).collect(Collectors.toList());
return PageVO.convert(page, list); return PageVO.convert(page, list);
} }
@Override @Override
public List<DepartmentVO> queryCls(OrgQueryVO queryVO, LoginUserInfoVO loginInfo) { public List<OrgVO> queryCls(OrgQueryVO queryVO, LoginUserInfoVO loginInfo) {
OrgExample example = new OrgExample(); OrgExample example = new OrgExample();
OrgExample.Criteria criteria = example.createCriteria() OrgExample.Criteria criteria = example.createCriteria()
.andParentIdEqualTo(loginInfo.getTopOrgId()) .andParentIdEqualTo(loginInfo.getTopOrgId())
@ -235,7 +243,7 @@ public class OrgService implements IOrgService {
} }
} }
List<Org> clsList = orgDAO.selectByExample(example); List<Org> clsList = orgDAO.selectByExample(example);
return clsList.stream().map(DepartmentVO::new).collect(Collectors.toList()); return clsList.stream().map(OrgVO::new).collect(Collectors.toList());
} }
@Override @Override
@ -263,13 +271,13 @@ public class OrgService implements IOrgService {
@Override @Override
public Node<Object> adminQueryOrgTree(Long orgId) { public Node<Object> adminQueryOrgTree(Long orgId) {
/* 先筛选组织 */ /* 先筛选组织 */
Org org = getEntity(orgId); OrgVO orgVO = get(orgId);
Map<Long, List<Org>> groupByParentIdOrg = findEntitiesByRootId(org.getRootId(), null, BusinessConsts.Org.Status.VALID) Map<Long, List<Org>> groupByParentIdOrg = findEntitiesByRootId(orgVO.getRootId(), null, BusinessConsts.Org.Status.VALID)
.stream().filter(o -> o.getParentId() != null).collect(Collectors.groupingBy(Org::getParentId)); .stream().filter(o -> !isTopOrg(o)).collect(Collectors.groupingBy(Org::getParentId));
Node<Object> root = new Node<>(new DepartmentVO(org), Node.Type.ORG); Node<Object> root = new Node<>(orgVO, Node.Type.ORG);
Map<Long, Node<Object>> all_orgId_node_map = new HashMap<>(); //所有的组织和对应的节点 Map<Long, Node<Object>> all_orgId_node_map = new HashMap<>(); //所有的组织和对应的节点
Map<Long, Node<Object>> orgId_node_map = new HashMap<>(); Map<Long, Node<Object>> orgId_node_map = new HashMap<>();
orgId_node_map.put(org.getId(), root); orgId_node_map.put(orgVO.getId(), root);
while (!orgId_node_map.isEmpty()) { while (!orgId_node_map.isEmpty()) {
all_orgId_node_map.putAll(orgId_node_map); all_orgId_node_map.putAll(orgId_node_map);
Map<Long, Node<Object>> newMap = new HashMap<>(); Map<Long, Node<Object>> newMap = new HashMap<>();
@ -277,7 +285,7 @@ public class OrgService implements IOrgService {
List<Org> childOrgList = groupByParentIdOrg.get(k); List<Org> childOrgList = groupByParentIdOrg.get(k);
if (!CollectionUtils.isEmpty(childOrgList)) { if (!CollectionUtils.isEmpty(childOrgList)) {
List<Node<Object>> children = childOrgList.stream().map(o -> { List<Node<Object>> children = childOrgList.stream().map(o -> {
Node<Object> node = new Node<>(new DepartmentVO(o), Node.Type.ORG); Node<Object> node = new Node<>(new OrgVO(o), Node.Type.ORG);
newMap.put(o.getId(), node); newMap.put(o.getId(), node);
return node; return node;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
@ -309,9 +317,10 @@ public class OrgService implements IOrgService {
} }
@Override @Override
public CompanyVO get(Long id) { public OrgVO get(Long id) {
Org entity = getEntity(id); OrgVO vo = query(id);
return new CompanyVO(entity); BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(vo, String.format("[id:%s]的组织不存在", id));
return vo;
} }
@Override @Override
@ -381,9 +390,35 @@ public class OrgService implements IOrgService {
} }
@Override @Override
public List<DepartmentVO> listQueryCls(long topOrgId) { public List<OrgVO> listQueryCls(long topOrgId) {
List<Org> clsList = findClsByTopOrgId(topOrgId); List<Org> clsList = findClsByTopOrgId(topOrgId);
return DepartmentVO.convert2VOList(clsList); return OrgVO.convert2VOList(clsList);
}
@Override
public OrgVO query(Long id) {
Org entity = findEntity(id);
if (entity == null) {
return null;
}
List<String> projects;
if (isTopOrg(entity)) {
projects = orgProjectService.queryOrgProjectListByOrgId(entity.getId()).stream()
.map(OrgProject::getProjectCode).collect(Collectors.toList());
} else {
projects = null;
}
return new OrgVO(entity, projects);
}
@Override
public OrgVO getTopOrg(long topOrgId) {
Org org = getEntity(topOrgId);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(isTopOrg(org),
String.format("[id:%s]的组织不是顶级组织", topOrgId));
List<String> projects = orgProjectService.queryOrgProjectListByOrgId(topOrgId)
.stream().map(OrgProject::getProjectCode).collect(Collectors.toList());
return new OrgVO(org, projects);
} }
/** /**
@ -420,7 +455,7 @@ public class OrgService implements IOrgService {
} }
private boolean isTopOrg(long orgId) { private boolean isTopOrg(long orgId) {
return getEntity(orgId).getParentId() == null; return isTopOrg(getEntity(orgId));
} }
private boolean isTopOrg(Org org) { private boolean isTopOrg(Org org) {

View File

@ -66,7 +66,7 @@ public class OrgUserService implements IOrgUserService {
@Override @Override
public CompanyVO userScanCodeBindCompanyManager(Long userId, Long companyId) { public OrgVO userScanCodeBindCompanyManager(Long userId, Long companyId) {
return iSysUserService.userScanCodeBindCompanyManager(userId, companyId); return iSysUserService.userScanCodeBindCompanyManager(userId, companyId);
} }
@ -76,23 +76,22 @@ public class OrgUserService implements IOrgUserService {
* 增加部门 * 增加部门
*/ */
@Override @Override
public DepartmentVO createDepart(DepartmentVO departmentVO) { public OrgVO createDepart(OrgVO orgVO) {
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(departmentIsExist(departmentVO), "同级部门信息重复"); BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(departmentIsExist(orgVO), "同级部门信息重复");
Org entity = departmentVO.toDB(); Org entity = orgVO.toDB();
orgDAO.insert(entity); orgDAO.insert(entity);
departmentVO.setId(entity.getId()); orgVO.setId(entity.getId());
return departmentVO; return orgVO;
} }
/** /**
* 修改部门 * 修改部门
*/ */
@Override @Override
public void updateDepartInfo(Long deptId, DepartmentVO departmentVO) { public void updateDepartInfo(Long deptId, OrgVO orgVO) {
Org entity = departmentVO.toDB(); Org entity = orgVO.toDB();
entity.setId(deptId); entity.setId(deptId);
entity.setRootId(null); entity.setRootId(null);
entity.setProjectCode(null);
orgDAO.updateByPrimaryKeySelective(entity); orgDAO.updateByPrimaryKeySelective(entity);
} }
@ -102,12 +101,8 @@ public class OrgUserService implements IOrgUserService {
* @param deptId * @param deptId
*/ */
@Override @Override
public DepartmentVO getDepartById(Long deptId) { public OrgVO queryDepartById(Long deptId) {
Org entity = orgDAO.selectByPrimaryKey(deptId); return iOrgService.query(deptId);
if (Objects.isNull(entity)) {
return null;
}
return new DepartmentVO(entity);
} }
/** /**
@ -116,54 +111,54 @@ public class OrgUserService implements IOrgUserService {
* @param companyId * @param companyId
*/ */
@Override @Override
public List<DepartmentVO> getCompanyDepartTree(Long companyId) { public List<OrgVO> getCompanyDepartTree(Long companyId) {
OrgExample example = new OrgExample(); OrgExample example = new OrgExample();
example.createCriteria().andRootIdEqualTo(companyId); example.createCriteria().andRootIdEqualTo(companyId);
List<Org> orgList = orgDAO.selectByExample(example); List<Org> orgList = orgDAO.selectByExample(example);
return DepartmentVO.buildDeptTree(DepartmentVO.convert2VOList(orgList)); return OrgVO.buildDeptTree(OrgVO.convert2VOList(orgList));
} }
@Override @Override
public List<DepartmentVO> getCompanyAllDepart(Long companyId) { public List<OrgVO> getCompanyAllDepart(Long companyId) {
OrgExample example = new OrgExample(); OrgExample example = new OrgExample();
example.createCriteria().andRootIdEqualTo(companyId).andParentIdIsNotNull(); example.createCriteria().andRootIdEqualTo(companyId).andParentIdIsNotNull();
List<Org> companyDepartments = orgDAO.selectByExample(example); List<Org> companyDepartments = orgDAO.selectByExample(example);
return DepartmentVO.convert2VOList(companyDepartments); return OrgVO.convert2VOList(companyDepartments);
} }
@Override @Override
public DepartmentVO getDepartTree(Long companyId, Long deptId) { public OrgVO getDepartTree(Long companyId, Long deptId) {
Org companyDepartment = orgDAO.selectByPrimaryKey(deptId); Org companyDepartment = orgDAO.selectByPrimaryKey(deptId);
OrgExample example = new OrgExample(); OrgExample example = new OrgExample();
example.createCriteria().andRootIdEqualTo(companyId).andParentIdIsNotNull(); example.createCriteria().andRootIdEqualTo(companyId).andParentIdIsNotNull();
List<Org> companyDepartments = orgDAO.selectByExample(example); List<Org> companyDepartments = orgDAO.selectByExample(example);
List<DepartmentVO> childDept = DepartmentVO.getChildDept(deptId, DepartmentVO.convert2VOList(companyDepartments)); List<OrgVO> childDept = OrgVO.getChildDept(deptId, OrgVO.convert2VOList(companyDepartments));
DepartmentVO departmentVO = new DepartmentVO(companyDepartment); OrgVO orgVO = new OrgVO(companyDepartment);
departmentVO.setChildDept(childDept); orgVO.setChildDept(childDept);
return departmentVO; return orgVO;
} }
@Override @Override
public List<DepartmentVO> getDepartAndChild(Long companyId, Long deptId) { public List<OrgVO> getDepartAndChild(Long companyId, Long deptId) {
var example = new OrgExample(); var example = new OrgExample();
example.createCriteria().andRootIdEqualTo(companyId).andParentIdIsNotNull(); example.createCriteria().andRootIdEqualTo(companyId).andParentIdIsNotNull();
var companyDepartments = orgDAO.selectByExample(example); var companyDepartments = orgDAO.selectByExample(example);
var childDept = DepartmentVO.getChildDeptList(deptId, DepartmentVO.convert2VOList(companyDepartments)); var childDept = OrgVO.getChildDeptList(deptId, OrgVO.convert2VOList(companyDepartments));
var companyDepartment = orgDAO.selectByPrimaryKey(deptId); var companyDepartment = orgDAO.selectByPrimaryKey(deptId);
childDept.add(new DepartmentVO(companyDepartment)); childDept.add(new OrgVO(companyDepartment));
return childDept; return childDept;
} }
private boolean departmentIsExist(DepartmentVO departmentVO) { private boolean departmentIsExist(OrgVO orgVO) {
var example = new OrgExample(); var example = new OrgExample();
OrgExample.Criteria criteria = example.createCriteria() OrgExample.Criteria criteria = example.createCriteria()
.andRootIdEqualTo(departmentVO.getRootId()) .andRootIdEqualTo(orgVO.getRootId())
.andNameEqualTo(departmentVO.getName()); .andNameEqualTo(orgVO.getName());
if (Objects.isNull(departmentVO.getParentId())) { if (Objects.isNull(orgVO.getParentId())) {
criteria.andParentIdIsNull(); criteria.andParentIdIsNull();
} else { } else {
criteria.andParentIdEqualTo(departmentVO.getParentId()); criteria.andParentIdEqualTo(orgVO.getParentId());
} }
return orgDAO.countByExample(example) != 0; return orgDAO.countByExample(example) != 0;
@ -373,9 +368,9 @@ public class OrgUserService implements IOrgUserService {
} }
@Override @Override
public void userBindCompanyManager(AccountVO accountVO, Long topOrgId) { public OrgVO userBindCompanyManager(AccountVO accountVO, Long topOrgId) {
Org topOrg = iOrgService.getEntity(topOrgId); OrgVO topOrgVO = iOrgService.get(topOrgId);
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNull(topOrg.getParentId(), "所选组织不是顶级组织"); BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNull(topOrgVO.getParentId(), "所选组织不是顶级组织");
BusinessExceptionAssertEnum.OPERATION_REPEAT.assertNotTrue(isTheRoleInThisOrg(accountVO.getId(), topOrgId, BusinessConsts.OrgRole.Admin), BusinessExceptionAssertEnum.OPERATION_REPEAT.assertNotTrue(isTheRoleInThisOrg(accountVO.getId(), topOrgId, BusinessConsts.OrgRole.Admin),
"已经是所选组织管理员"); "已经是所选组织管理员");
/* 如果是其它组织的管理员,删除关系 */ /* 如果是其它组织的管理员,删除关系 */
@ -388,7 +383,9 @@ public class OrgUserService implements IOrgUserService {
} }
/* 建立新关系 */ /* 建立新关系 */
create(topOrgId, accountVO.getId(), BusinessConsts.OrgRole.Admin); create(topOrgId, accountVO.getId(), BusinessConsts.OrgRole.Admin);
accountVO.setOrgInfo(topOrg, true); return topOrgVO;
// accountVO.setOrgInfo(topOrg, true); 现在登录信息里的组织信息应该是和登录的项目相关所以不需要这个逻辑
} }
@Override @Override

View File

@ -4,7 +4,7 @@ import club.joylink.rtss.entity.project.Project;
import club.joylink.rtss.entity.project.ProjectView; import club.joylink.rtss.entity.project.ProjectView;
import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.org.CompanyVO; import club.joylink.rtss.vo.client.org.OrgVO;
import club.joylink.rtss.vo.project.*; import club.joylink.rtss.vo.project.*;
import java.util.List; import java.util.List;
@ -62,12 +62,12 @@ public interface ProjectService {
/** /**
* 根据项目ID获取与项目关联的所有组织信息 * 根据项目ID获取与项目关联的所有组织信息
*/ */
List<CompanyVO> projectOrgList(Long id); List<OrgVO> projectOrgList(Long id);
/** /**
* 快速创建默认组织 * 快速创建默认组织
*/ */
ProjectInfoVO quickCreateDefaultOrg(Long id, CompanyVO companyVO, AccountVO user); ProjectInfoVO quickCreateDefaultOrg(Long id, OrgVO companyVO, AccountVO user);
/** /**
* 前端设置信息分页 * 前端设置信息分页

View File

@ -18,7 +18,7 @@ import club.joylink.rtss.simulation.cbtc.exception.SimulationException;
import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType;
import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.org.CompanyVO; import club.joylink.rtss.vo.client.org.OrgVO;
import club.joylink.rtss.vo.project.*; import club.joylink.rtss.vo.project.*;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
@ -166,7 +166,7 @@ public class ProjectServiceImpl implements ProjectService {
} }
@Override @Override
public List<CompanyVO> projectOrgList(Long id) { public List<OrgVO> projectOrgList(Long id) {
Project project = projectDAO.selectByPrimaryKey(id); Project project = projectDAO.selectByPrimaryKey(id);
if (project == null) { if (project == null) {
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "项目不存在"); throw new SimulationException(SimulationExceptionType.Illegal_Argument, "项目不存在");
@ -175,7 +175,7 @@ public class ProjectServiceImpl implements ProjectService {
if (!CollectionUtils.isEmpty(orgProjectList)) { if (!CollectionUtils.isEmpty(orgProjectList)) {
List<Long> orgIdList = orgProjectList.stream().map(OrgProject::getOrgId).distinct().collect(Collectors.toList()); List<Long> orgIdList = orgProjectList.stream().map(OrgProject::getOrgId).distinct().collect(Collectors.toList());
List<Org> orgList = getOrgList(orgIdList); List<Org> orgList = getOrgList(orgIdList);
return orgList.stream().map(CompanyVO::simpleInfoVO).collect(Collectors.toList()); return orgList.stream().map(OrgVO::simpleInfoVO).collect(Collectors.toList());
} }
return List.of(); return List.of();
} }
@ -183,7 +183,7 @@ public class ProjectServiceImpl implements ProjectService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@CacheEvict(cacheNames = "project", allEntries = true) @CacheEvict(cacheNames = "project", allEntries = true)
public ProjectInfoVO quickCreateDefaultOrg(Long id, CompanyVO companyVO, AccountVO user) { public ProjectInfoVO quickCreateDefaultOrg(Long id, OrgVO companyVO, AccountVO user) {
Project project = projectDAO.selectByPrimaryKey(id); Project project = projectDAO.selectByPrimaryKey(id);
if (project == null) { if (project == null) {
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "项目不存在"); throw new SimulationException(SimulationExceptionType.Illegal_Argument, "项目不存在");
@ -194,7 +194,7 @@ public class ProjectServiceImpl implements ProjectService {
} }
// 保存默认组织 // 保存默认组织
companyVO.setProjectCodes(List.of(project.getCode())); companyVO.setProjectCodes(List.of(project.getCode()));
CompanyVO resultCompany = orgService.createTopOrg(companyVO, user); OrgVO resultCompany = orgService.createTopOrg(companyVO, user);
// 修改项目信息 // 修改项目信息
setProjectDefaultOrg(id, resultCompany.getId()); setProjectDefaultOrg(id, resultCompany.getId());
ProjectInfoVO projectVO = new ProjectInfoVO(project); ProjectInfoVO projectVO = new ProjectInfoVO(project);
@ -395,4 +395,4 @@ public class ProjectServiceImpl implements ProjectService {
}).collect(Collectors.toList()); }).collect(Collectors.toList());
return projectVOList; return projectVOList;
} }
} }

View File

@ -3,7 +3,7 @@ package club.joylink.rtss.vo;
import club.joylink.rtss.constants.BusinessConsts; import club.joylink.rtss.constants.BusinessConsts;
import club.joylink.rtss.entity.Org; import club.joylink.rtss.entity.Org;
import club.joylink.rtss.entity.SysAccount; import club.joylink.rtss.entity.SysAccount;
import club.joylink.rtss.vo.client.org.OrgProjectVO; import club.joylink.rtss.vo.client.org.OrgVO;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
@ -17,7 +17,6 @@ import javax.validation.constraints.NotBlank;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -49,7 +48,7 @@ public class AccountVO implements Serializable {
public static final String Type_3 = "3"; // 第三方企业子账户 public static final String Type_3 = "3"; // 第三方企业子账户
/** /**
* 用户所属的顶级组织 * 账号所属的组织是账号表里的字段
*/ */
private Long orgId; private Long orgId;
@ -298,13 +297,11 @@ public class AccountVO implements Serializable {
} }
} }
public void setOrgInfo(Org org, Boolean companyAdmin) { public void setOrgInfo(Org org, Boolean companyAdmin, List<String> projectCodes) {
this.companyId = org.getId(); this.companyId = org.getId();
this.companyName = org.getName(); this.companyName = org.getName();
this.companyAdmin = companyAdmin; this.companyAdmin = companyAdmin;
if (StringUtils.hasText(org.getProjectCode())) { this.projectCodes = projectCodes;
this.projectCodes = Arrays.asList(org.getProjectCode().split(","));
}
} }
public void copyOrgInfo(AccountVO accountVO) { public void copyOrgInfo(AccountVO accountVO) {
@ -321,13 +318,12 @@ public class AccountVO implements Serializable {
return Type_3.equalsIgnoreCase(this.type) && StringUtils.hasText(this.parentAccount); return Type_3.equalsIgnoreCase(this.type) && StringUtils.hasText(this.parentAccount);
} }
public void setOrgProjectVO(OrgProjectVO orgProjectVO) { public void setOrgProjectVO(OrgVO orgVO, boolean orgAdmin) {
if (orgProjectVO != null) { if (orgVO != null) {
this.companyId = orgProjectVO.getOrgId(); this.companyId = orgVO.getId();
this.companyName = orgProjectVO.getName(); this.companyName = orgVO.getName();
this.companyAdmin = !CollectionUtils.isEmpty(orgProjectVO.getRole()) this.companyAdmin = orgAdmin;
&& orgProjectVO.getRole().contains(BusinessConsts.OrgRole.Admin.name()); this.projectCodes = orgVO.getProjectCodes();
this.projectCodes = Arrays.asList(orgProjectVO.getProjectCode().split(","));
} else { } else {
this.companyId = 0L; this.companyId = 0L;
this.companyName = null; this.companyName = null;

View File

@ -4,7 +4,7 @@ import club.joylink.rtss.constants.Client;
import club.joylink.rtss.entity.SysAccountLogin; import club.joylink.rtss.entity.SysAccountLogin;
import club.joylink.rtss.entity.project.Project; import club.joylink.rtss.entity.project.Project;
import club.joylink.rtss.util.EncryptUtil; import club.joylink.rtss.util.EncryptUtil;
import club.joylink.rtss.vo.client.org.OrgProjectVO; import club.joylink.rtss.vo.client.org.OrgVO;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO; import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.project.ProjectVO; import club.joylink.rtss.vo.project.ProjectVO;
import lombok.Getter; import lombok.Getter;
@ -50,9 +50,6 @@ public class LoginUserInfoVO {
private LocalDateTime preLogoutTime; private LocalDateTime preLogoutTime;
private LocalDateTime lastQueryTime; // 最后使用时间 private LocalDateTime lastQueryTime; // 最后使用时间
// 20220929 增加
private OrgProjectVO orgProjectVO;
public LoginUserInfoVO(AccountVO accountVO, Client client, String project, ProjectDeviceVO deviceVO) { public LoginUserInfoVO(AccountVO accountVO, Client client, String project, ProjectDeviceVO deviceVO) {
this.accountVO = accountVO; this.accountVO = accountVO;
this.client = client; this.client = client;
@ -148,14 +145,10 @@ public class LoginUserInfoVO {
* 获取顶级组织Id * 获取顶级组织Id
*/ */
public Long getTopOrgId() { public Long getTopOrgId() {
if (orgProjectVO == null) { return getAccountVO().getCompanyId();
return null;
}
return orgProjectVO.getTopOrgId();
} }
public void setOrgProjectVO(OrgProjectVO orgProjectVO) { public void setOrgProjectVO(OrgVO orgVO, boolean orgAdmin) {
this.orgProjectVO = orgProjectVO; this.accountVO.setOrgProjectVO(orgVO, orgAdmin);
this.accountVO.setOrgProjectVO(orgProjectVO);
} }
} }

View File

@ -2,7 +2,7 @@ package club.joylink.rtss.vo.client;
import club.joylink.rtss.entity.ExamDefinition; import club.joylink.rtss.entity.ExamDefinition;
import club.joylink.rtss.entity.SysAccount; import club.joylink.rtss.entity.SysAccount;
import club.joylink.rtss.vo.client.org.DepartmentVO; import club.joylink.rtss.vo.client.org.OrgVO;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
@ -135,7 +135,7 @@ public class ExamDefinitionVO {
private Boolean system; private Boolean system;
/**关联班级列表*/ /**关联班级列表*/
private List<DepartmentVO> classes; private List<OrgVO> classes;
private List<Long> clsIds; private List<Long> clsIds;

View File

@ -1,75 +0,0 @@
package club.joylink.rtss.vo.client.org;
import club.joylink.rtss.entity.Org;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.validation.constraints.NotBlank;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Getter
@Setter
@NoArgsConstructor
public class CompanyVO {
@JsonSerialize(using = ToStringSerializer.class)
private Long id;
private String code;
/**
* 公司名称
*/
@NotBlank(message = "公司名称不能为空")
private String name;
private List<String> projectCodes;
public CompanyVO(Org entity) {
this.id = entity.getId();
this.code = entity.getCode();
this.name = entity.getName();
if (StringUtils.hasText(entity.getProjectCode())) {
this.projectCodes = Arrays.asList(entity.getProjectCode().split(","));
}
}
public static CompanyVO simpleInfoVO(Org entity) {
CompanyVO companyVO = new CompanyVO();
companyVO.setId(entity.getId());
companyVO.setName(entity.getName());
return companyVO;
}
public static List<CompanyVO> convert2VOList(List<Org> dataList) {
List<CompanyVO> voList = new ArrayList<>();
for (Org entity : dataList) {
voList.add(new CompanyVO(entity));
}
return voList;
}
public Org toDB() {
Org entity = new Org();
entity.setId(this.id);
entity.setName(this.name);
entity.setProjectCode(getDBProjectCode());
return entity;
}
@JsonIgnore
public String getDBProjectCode() {
if (!CollectionUtils.isEmpty(projectCodes)) {
return String.join(",", projectCodes);
} else {
return null;
}
}
}

View File

@ -17,12 +17,9 @@ public class OrgProjectVO {
private List<String> role; private List<String> role;
private String projectCode;
public OrgProjectVO(Org org) { public OrgProjectVO(Org org) {
this.orgId = org.getId(); this.orgId = org.getId();
this.name = org.getName(); this.name = org.getName();
this.topOrgId = org.getRootId(); this.topOrgId = org.getRootId();
this.projectCode = org.getProjectCode();
} }
} }

View File

@ -2,6 +2,7 @@ package club.joylink.rtss.vo.client.org;
import club.joylink.rtss.entity.Org; import club.joylink.rtss.entity.Org;
import club.joylink.rtss.entity.SysAccount; import club.joylink.rtss.entity.SysAccount;
import club.joylink.rtss.entity.org.OrgProject;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
@ -9,20 +10,19 @@ import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Getter @Getter
@Setter @Setter
@NoArgsConstructor @NoArgsConstructor
public class DepartmentVO { public class OrgVO {
@JsonSerialize(using = ToStringSerializer.class) @JsonSerialize(using = ToStringSerializer.class)
private Long id; private Long id;
@ -49,7 +49,7 @@ public class DepartmentVO {
*/ */
private Integer numberOfPeople; private Integer numberOfPeople;
private List<DepartmentVO> childDept; private List<OrgVO> childDept;
private Long creatorId; private Long creatorId;
@ -57,26 +57,28 @@ public class DepartmentVO {
private String creatorNickName; private String creatorNickName;
public DepartmentVO(Org entity) { public OrgVO(Org entity) {
this.id = entity.getId(); this.id = entity.getId();
this.code = entity.getCode(); this.code = entity.getCode();
this.name = entity.getName(); this.name = entity.getName();
if (StringUtils.hasText(entity.getProjectCode())) {
this.projectCodes = Arrays.asList(entity.getProjectCode().split(","));
}
this.parentId = entity.getParentId(); this.parentId = entity.getParentId();
this.rootId = entity.getRootId(); this.rootId = entity.getRootId();
this.creatorId = entity.getCreatorId(); this.creatorId = entity.getCreatorId();
this.createTime = entity.getCreateTime(); this.createTime = entity.getCreateTime();
} }
public DepartmentVO(Org entity, Integer numberOfPeople) { public OrgVO(Org entity, List<String> projectCodes) {
this(entity); this(entity);
this.projectCodes = projectCodes;
}
public OrgVO(Org entity, List<String> projectCodes, Integer numberOfPeople) {
this(entity, projectCodes);
this.numberOfPeople = numberOfPeople; this.numberOfPeople = numberOfPeople;
} }
public DepartmentVO(Org entity, Integer numberOfPeople, SysAccount creator) { public OrgVO(Org entity, List<String> projectCodes, Integer numberOfPeople, SysAccount creator) {
this(entity, numberOfPeople); this(entity, projectCodes, numberOfPeople);
if (creator != null) { if (creator != null) {
this.creatorId = creator.getId(); this.creatorId = creator.getId();
this.creatorName = creator.getName(); this.creatorName = creator.getName();
@ -84,11 +86,24 @@ public class DepartmentVO {
} }
} }
public static List<DepartmentVO> convert2VOList(List<Org> dataList) { public static List<OrgVO> convert2VOList(List<Org> orgs) {
if (CollectionUtils.isEmpty(dataList)) { if (CollectionUtils.isEmpty(orgs)) {
return new ArrayList<>(); return new ArrayList<>();
} else { } else {
return dataList.stream().map(DepartmentVO::new).collect(Collectors.toList()); return orgs.stream().map(OrgVO::new).collect(Collectors.toList());
}
}
public static List<OrgVO> convert2VOList(List<Org> orgs, List<OrgProject> orgProjects) {
if (CollectionUtils.isEmpty(orgs)) {
return new ArrayList<>();
} else {
Map<Long, List<String>> orgId_projects_map = orgProjects.stream()
.collect(Collectors.groupingBy(OrgProject::getOrgId,
Collectors.mapping(OrgProject::getProjectCode, Collectors.toList())));
return orgs.stream()
.map(org -> new OrgVO(org, orgId_projects_map.get(org.getId())))
.collect(Collectors.toList());
} }
} }
@ -98,12 +113,11 @@ public class DepartmentVO {
entity.setName(this.name); entity.setName(this.name);
entity.setParentId(this.parentId); entity.setParentId(this.parentId);
entity.setRootId(this.rootId); entity.setRootId(this.rootId);
entity.setProjectCode(String.join(",", this.projectCodes));
return entity; return entity;
} }
public static List<DepartmentVO> buildDeptTree(List<DepartmentVO> voList) { public static List<OrgVO> buildDeptTree(List<OrgVO> voList) {
List<DepartmentVO> rootDeparts = new ArrayList<>(); List<OrgVO> rootDeparts = new ArrayList<>();
voList.forEach(d -> { voList.forEach(d -> {
if (Objects.isNull(d.getParentId())) { if (Objects.isNull(d.getParentId())) {
d.setChildDept(getChildDept(d.getId(), voList)); d.setChildDept(getChildDept(d.getId(), voList));
@ -113,8 +127,8 @@ public class DepartmentVO {
return rootDeparts; return rootDeparts;
} }
public static List<DepartmentVO> getChildDept(Long parentId, List<DepartmentVO> list) { public static List<OrgVO> getChildDept(Long parentId, List<OrgVO> list) {
List<DepartmentVO> child = new ArrayList<>(); List<OrgVO> child = new ArrayList<>();
list.forEach(c -> { list.forEach(c -> {
if (parentId == c.getParentId()) { if (parentId == c.getParentId()) {
child.add(c); child.add(c);
@ -129,8 +143,8 @@ public class DepartmentVO {
return child; return child;
} }
public static List<DepartmentVO> getChildDeptList(Long parentId, List<DepartmentVO> list) { public static List<OrgVO> getChildDeptList(Long parentId, List<OrgVO> list) {
List<DepartmentVO> child = new ArrayList<>(); List<OrgVO> child = new ArrayList<>();
list.forEach(c -> { list.forEach(c -> {
if (parentId == c.getParentId()) { if (parentId == c.getParentId()) {
child.add(c); child.add(c);
@ -143,4 +157,11 @@ public class DepartmentVO {
}); });
return child; return child;
} }
public static OrgVO simpleInfoVO(Org org) {
OrgVO orgVO = new OrgVO();
orgVO.setId(org.getId());
orgVO.setName(org.getName());
return orgVO;
}
} }