From 733c06b191b36e05a026bf6460dee11ff6354b63 Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Thu, 1 Apr 2021 16:30:01 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=A1=A8=E6=B7=BB=E5=8A=A0or?= =?UTF-8?q?g=5Fid=EF=BC=8C=E5=AF=BC=E5=85=A5=E7=9A=84=E5=AD=A6=E7=94=9F?= =?UTF-8?q?=E4=B8=8E=E7=BB=84=E7=BB=87=E6=B0=B8=E8=BF=9C=E5=85=B3=E8=81=94?= =?UTF-8?q?=EF=BC=9B=E7=BB=84=E7=BB=87=E5=92=8C=E9=A1=B9=E7=9B=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E4=B8=80=E5=AF=B9=E5=A4=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/20210401-zhangsai.sql | 4 + .../rtss/controller/OrgController.java | 78 +++++- .../club/joylink/rtss/dao/SysUserDAO.java | 4 +- .../java/club/joylink/rtss/entity/Org.java | 3 - .../club/joylink/rtss/entity/SysUser.java | 18 +- .../joylink/rtss/entity/SysUserExample.java | 60 ++++ .../rtss/services/ISysUserService.java | 10 +- .../joylink/rtss/services/SysUserService.java | 262 ++++++++++-------- .../rtss/services/UserExamService.java | 3 +- .../rtss/services/org/IOrgService.java | 4 + .../rtss/services/org/IOrgUserService.java | 14 +- .../services/org/OrgScoringRuleService.java | 7 +- .../joylink/rtss/services/org/OrgService.java | 116 ++++---- .../rtss/services/org/OrgUserService.java | 186 +++++-------- .../cbtc/GroupSimulationServiceImpl.java | 6 +- .../club/joylink/rtss/vo/UserQueryVO.java | 2 + .../java/club/joylink/rtss/vo/UserVO.java | 8 +- .../joylink/rtss/vo/client/org/CompanyVO.java | 23 +- .../rtss/vo/client/org/DepartmentVO.java | 10 +- .../vo/client/org/OrgScoringResultVO.java | 18 +- .../joylink/rtss/vo/client/org/OrgUserVO.java | 7 - .../rtss/vo/client/org/UserDepartRelVO.java | 5 + .../vo/client/student/ExportStudentInfo.java | 8 - .../resources/mybatis/mapper/SysUserDAO.xml | 57 ++-- 24 files changed, 522 insertions(+), 391 deletions(-) create mode 100644 sql/20210401-zhangsai.sql diff --git a/sql/20210401-zhangsai.sql b/sql/20210401-zhangsai.sql new file mode 100644 index 000000000..7bf1eeef9 --- /dev/null +++ b/sql/20210401-zhangsai.sql @@ -0,0 +1,4 @@ +alter table sys_user + add org_id bigint null comment '所属组织id' after account; + +ALTER TABLE `org` DROP COLUMN `code`; diff --git a/src/main/java/club/joylink/rtss/controller/OrgController.java b/src/main/java/club/joylink/rtss/controller/OrgController.java index cb28d2583..caff2b77b 100644 --- a/src/main/java/club/joylink/rtss/controller/OrgController.java +++ b/src/main/java/club/joylink/rtss/controller/OrgController.java @@ -1,8 +1,18 @@ package club.joylink.rtss.controller; +import club.joylink.rtss.constants.BusinessConsts; import club.joylink.rtss.constants.RoleEnum; import club.joylink.rtss.controller.advice.AuthenticateInterceptor; import club.joylink.rtss.controller.advice.Role; +import club.joylink.rtss.dao.OrgDAO; +import club.joylink.rtss.dao.OrgUserDAO; +import club.joylink.rtss.dao.SysUserDAO; +import club.joylink.rtss.entity.Org; +import club.joylink.rtss.entity.OrgUser; +import club.joylink.rtss.entity.OrgUserExample; +import club.joylink.rtss.entity.SysUser; +import club.joylink.rtss.exception.BusinessExceptionAssertEnum; +import club.joylink.rtss.services.ISysUserService; import club.joylink.rtss.services.org.*; import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.UserVO; @@ -13,12 +23,15 @@ import club.joylink.rtss.vo.client.org.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; import javax.validation.constraints.NotBlank; -import java.util.List; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; @Api(tags = {"组织成员管理接口"}) @RestController @@ -40,6 +53,18 @@ public class OrgController { @Autowired private IOrgExamService iOrgExamService; + @Autowired + private ISysUserService iSysUserService; + + @Autowired + private SysUserDAO sysUserDAO; + + @Autowired + private OrgUserDAO orgUserDAO; + + @Autowired + private OrgDAO orgDAO; + @ApiOperation(value = "创建顶级组织") @PostMapping public CompanyVO create(@RequestBody @Validated CompanyVO company, @RequestAttribute(AuthenticateInterceptor.LOGIN_USER_KEY) UserVO user) { @@ -72,7 +97,7 @@ public class OrgController { @ApiOperation(value = "微信小程用户绑定为单位管理员") @PutMapping(path = "/bind/company") - public CompanyVO userScanCodeBindCompany(Long userId, @NotBlank Long companyId) { + public CompanyVO userScanCodeBindCompany(Long userId, Long companyId) { return iOrgUserService.userScanCodeBindCompanyManager(userId, companyId); } @@ -132,7 +157,7 @@ public class OrgController { @ApiOperation(value = "取消单位的部门成员关系") @DeleteMapping("departUserInfo") - public void deleteCompanyUserInfo(@RequestAttribute @ApiIgnore UserVO user, @RequestBody UserDepartRelVO userDepartRelVO) { + public void deleteCompanyUserInfo(@RequestAttribute @ApiIgnore UserVO user, @RequestBody @Validated UserDepartRelVO userDepartRelVO) { iOrgUserService.deleteDepartUserInfo(user, userDepartRelVO); } @@ -259,10 +284,55 @@ public class OrgController { } @Role(RoleEnum.Admin) - @ApiOperation("管理员查看非顶级组织") + @ApiOperation("管理员查看组织树") @GetMapping("/orgTree/{orgId}") public Node adminQueryOrgTree(@PathVariable Long orgId, @RequestAttribute UserVO user) { return iOrgService.adminQueryOrgTree(orgId); } + @Transactional + @ApiOperation("数据处理接口,用后即删") + @PutMapping("/data") + public void data() { + OrgUserExample orgUserExample = new OrgUserExample(); + orgUserExample.createCriteria().andRoleEqualTo(BusinessConsts.OrgRole.Student.name()); + List ous = orgUserDAO.selectByExample(orgUserExample); + Set orgIdSet = new HashSet<>(); + Map> userId_orgIdSet_map = new HashMap<>(); + ous.forEach(ou -> { + orgIdSet.add(ou.getOrgId()); + Set userOrgIdSet = userId_orgIdSet_map.computeIfAbsent(ou.getUserId(), k -> new HashSet<>()); + userOrgIdSet.add(ou.getOrgId()); + }); + List orgList = iOrgService.findEntities(new ArrayList<>(orgIdSet), null); + Map orgId_rootId_map = orgList.stream().collect(Collectors.toMap(Org::getId, Org::getRootId)); + Map topOrgMap = iOrgService.findEntities(new ArrayList<>(orgId_rootId_map.values()), null) + .stream().collect(Collectors.toMap(Org::getId, Function.identity())); + List users = iSysUserService.findEntities(new ArrayList<>(userId_orgIdSet_map.keySet()), null); + Set nonRootOrgIds = new HashSet<>(); + users.forEach(user -> { + Set userOrgIdSet = userId_orgIdSet_map.get(user.getId()); + String orgCode = null; + Long rootId = null; + for (Long orgId : userOrgIdSet) { + rootId = orgId_rootId_map.get(orgId); + if (rootId == null) { + nonRootOrgIds.add(rootId); + } else { + Org org = topOrgMap.get(rootId); + if (orgCode == null) { + orgCode = org.getCode(); + } else { + BusinessExceptionAssertEnum.DATA_ERROR.assertEquals(orgCode, org.getCode(), userOrgIdSet.toString()); + } + } + } + BusinessExceptionAssertEnum.DATA_ERROR.assertNotNull(orgCode, user.getId() + "无所属顶级组织"); + user.setAccount(user.getAccount().substring(0, user.getAccount().indexOf(orgCode))); + user.setOrgId(rootId); + sysUserDAO.updateByPrimaryKey(user); + }); + System.out.println(nonRootOrgIds.toString()); + } + } diff --git a/src/main/java/club/joylink/rtss/dao/SysUserDAO.java b/src/main/java/club/joylink/rtss/dao/SysUserDAO.java index 5191d5c0b..d754da08b 100644 --- a/src/main/java/club/joylink/rtss/dao/SysUserDAO.java +++ b/src/main/java/club/joylink/rtss/dao/SysUserDAO.java @@ -20,7 +20,7 @@ public interface SysUserDAO extends MyBatisBaseDao " + - " (#{entity.account,jdbcType=VARCHAR}, #{entity.name,jdbcType=VARCHAR}, #{entity.nickname,jdbcType=VARCHAR}, \n" + + " (#{entity.account,jdbcType=VARCHAR}, #{entity.orgId, jdbcType=BIGINT}, #{entity.name,jdbcType=VARCHAR}, #{entity.nickname,jdbcType=VARCHAR}, \n" + " #{entity.avatarPath,jdbcType=VARCHAR}, #{entity.password,jdbcType=VARCHAR}, #{entity.mobile,jdbcType=VARCHAR}, \n" + " #{entity.nationcode,jdbcType=VARCHAR}, #{entity.email,jdbcType=VARCHAR}, #{entity.wxId,jdbcType=VARCHAR}, \n" + " #{entity.wxUnionId,jdbcType=VARCHAR}, #{entity.wmOpenId,jdbcType=VARCHAR}, #{entity.status,jdbcType=VARCHAR}, \n" + diff --git a/src/main/java/club/joylink/rtss/entity/Org.java b/src/main/java/club/joylink/rtss/entity/Org.java index 006a7fe0f..55931e44c 100644 --- a/src/main/java/club/joylink/rtss/entity/Org.java +++ b/src/main/java/club/joylink/rtss/entity/Org.java @@ -30,9 +30,6 @@ public class Org implements Serializable { */ private String projectCode; - /** - * 顶级组织code(唯一) - */ private String code; /** diff --git a/src/main/java/club/joylink/rtss/entity/SysUser.java b/src/main/java/club/joylink/rtss/entity/SysUser.java index a5a0d3eda..ff8dee47a 100644 --- a/src/main/java/club/joylink/rtss/entity/SysUser.java +++ b/src/main/java/club/joylink/rtss/entity/SysUser.java @@ -4,8 +4,8 @@ import java.io.Serializable; import java.time.LocalDateTime; /** - * sys_user * @author + * 用户 */ public class SysUser implements Serializable { private Long id; @@ -15,6 +15,11 @@ public class SysUser implements Serializable { */ private String account; + /** + * 所属组织id + */ + private Long orgId; + /** * 真实姓名 */ @@ -113,6 +118,14 @@ public class SysUser implements Serializable { this.account = account; } + public Long getOrgId() { + return orgId; + } + + public void setOrgId(Long orgId) { + this.orgId = orgId; + } + public String getName() { return name; } @@ -255,6 +268,7 @@ public class SysUser implements Serializable { SysUser other = (SysUser) that; return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) && (this.getAccount() == null ? other.getAccount() == null : this.getAccount().equals(other.getAccount())) + && (this.getOrgId() == null ? other.getOrgId() == null : this.getOrgId().equals(other.getOrgId())) && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName())) && (this.getNickname() == null ? other.getNickname() == null : this.getNickname().equals(other.getNickname())) && (this.getAvatarPath() == null ? other.getAvatarPath() == null : this.getAvatarPath().equals(other.getAvatarPath())) @@ -279,6 +293,7 @@ public class SysUser implements Serializable { int result = 1; result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); result = prime * result + ((getAccount() == null) ? 0 : getAccount().hashCode()); + result = prime * result + ((getOrgId() == null) ? 0 : getOrgId().hashCode()); result = prime * result + ((getName() == null) ? 0 : getName().hashCode()); result = prime * result + ((getNickname() == null) ? 0 : getNickname().hashCode()); result = prime * result + ((getAvatarPath() == null) ? 0 : getAvatarPath().hashCode()); @@ -306,6 +321,7 @@ public class SysUser implements Serializable { sb.append("Hash = ").append(hashCode()); sb.append(", id=").append(id); sb.append(", account=").append(account); + sb.append(", orgId=").append(orgId); sb.append(", name=").append(name); sb.append(", nickname=").append(nickname); sb.append(", avatarPath=").append(avatarPath); diff --git a/src/main/java/club/joylink/rtss/entity/SysUserExample.java b/src/main/java/club/joylink/rtss/entity/SysUserExample.java index cf8c4afbb..a5ab0d598 100644 --- a/src/main/java/club/joylink/rtss/entity/SysUserExample.java +++ b/src/main/java/club/joylink/rtss/entity/SysUserExample.java @@ -255,6 +255,66 @@ public class SysUserExample { return (Criteria) this; } + public Criteria andOrgIdIsNull() { + addCriterion("org_id is null"); + return (Criteria) this; + } + + public Criteria andOrgIdIsNotNull() { + addCriterion("org_id is not null"); + return (Criteria) this; + } + + public Criteria andOrgIdEqualTo(Long value) { + addCriterion("org_id =", value, "orgId"); + return (Criteria) this; + } + + public Criteria andOrgIdNotEqualTo(Long value) { + addCriterion("org_id <>", value, "orgId"); + return (Criteria) this; + } + + public Criteria andOrgIdGreaterThan(Long value) { + addCriterion("org_id >", value, "orgId"); + return (Criteria) this; + } + + public Criteria andOrgIdGreaterThanOrEqualTo(Long value) { + addCriterion("org_id >=", value, "orgId"); + return (Criteria) this; + } + + public Criteria andOrgIdLessThan(Long value) { + addCriterion("org_id <", value, "orgId"); + return (Criteria) this; + } + + public Criteria andOrgIdLessThanOrEqualTo(Long value) { + addCriterion("org_id <=", value, "orgId"); + return (Criteria) this; + } + + public Criteria andOrgIdIn(List values) { + addCriterion("org_id in", values, "orgId"); + return (Criteria) this; + } + + public Criteria andOrgIdNotIn(List values) { + addCriterion("org_id not in", values, "orgId"); + return (Criteria) this; + } + + public Criteria andOrgIdBetween(Long value1, Long value2) { + addCriterion("org_id between", value1, value2, "orgId"); + return (Criteria) this; + } + + public Criteria andOrgIdNotBetween(Long value1, Long value2) { + addCriterion("org_id not between", value1, value2, "orgId"); + return (Criteria) this; + } + public Criteria andNameIsNull() { addCriterion("`name` is null"); return (Criteria) this; diff --git a/src/main/java/club/joylink/rtss/services/ISysUserService.java b/src/main/java/club/joylink/rtss/services/ISysUserService.java index 9459cbb65..b84aeb676 100644 --- a/src/main/java/club/joylink/rtss/services/ISysUserService.java +++ b/src/main/java/club/joylink/rtss/services/ISysUserService.java @@ -9,6 +9,7 @@ import club.joylink.rtss.vo.client.org.CompanyVO; import club.joylink.rtss.vo.client.user.*; import club.joylink.rtss.vo.user.UserInfoVO; import club.joylink.rtss.vo.wx.WmUserSession; +import lombok.NonNull; import org.springframework.transaction.annotation.Transactional; import java.util.List; @@ -30,6 +31,10 @@ public interface ISysUserService { */ UserVO findUserById(Long id); + SysUser findEntity(@NonNull String account, long orgId); + + boolean isExist(@NonNull String account, long orgId); + /** * 通过用户姓名或手机号查询 * @param query @@ -46,9 +51,6 @@ public interface ISysUserService { /** * 修改用户信息 - * @param id - * @param userInfo - * @param vdcode */ void modify(Long id, UserVO userInfo, String vdcode); @@ -289,8 +291,6 @@ public interface ISysUserService { void superAdminUpdateUserInfo(UserVO updateUser, UserVO superAdmin); - void userBindCompanyManager(UserVO userVO, Long companyId); - /** * 查询所有的销售人员 */ diff --git a/src/main/java/club/joylink/rtss/services/SysUserService.java b/src/main/java/club/joylink/rtss/services/SysUserService.java index 53b2bb4d3..2c3874022 100644 --- a/src/main/java/club/joylink/rtss/services/SysUserService.java +++ b/src/main/java/club/joylink/rtss/services/SysUserService.java @@ -6,12 +6,13 @@ import club.joylink.rtss.constants.EmailSubject; import club.joylink.rtss.constants.Project; import club.joylink.rtss.constants.StatusEnum; import club.joylink.rtss.dao.OrgDAO; -import club.joylink.rtss.dao.OrgUserDAO; import club.joylink.rtss.dao.SysUserDAO; import club.joylink.rtss.dao.UserSubscribeMapper; import club.joylink.rtss.entity.*; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.services.cache.ICacheService; +import club.joylink.rtss.services.org.IOrgService; +import club.joylink.rtss.services.org.IOrgUserService; import club.joylink.rtss.util.EncryptUtil; import club.joylink.rtss.util.RandomGenerator; import club.joylink.rtss.vo.SmsResponse; @@ -27,6 +28,7 @@ import club.joylink.rtss.vo.wx.WmUserSession; import club.joylink.rtss.vo.wx.WxUserGet; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; +import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -39,6 +41,7 @@ import java.time.LocalDateTime; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; +import java.util.function.Function; import java.util.stream.Collectors; @Service @@ -79,38 +82,85 @@ public class SysUserService implements ISysUserService { private OrgDAO companyDAO; @Autowired - private OrgUserDAO orgUserDAO; + private IOrgUserService iOrgUserService; + + @Autowired + private IOrgService iOrgService; @Override public UserVO findUserByAccountAndPassword(String account, String password, Project project) { - SysUserExample example = new SysUserExample(); + /* 先按手机号和邮箱查询 */ + SysUserExample example = new SysUserExample(); example.createCriteria().andMobileEqualTo(account).andPasswordEqualTo(password); // 手机号 example.or().andEmailEqualTo(account).andPasswordEqualTo(password); // 邮箱 List users = this.sysUserDAO.selectByExample(example); + Org topOrg = iOrgService.findEntity(project, BusinessConsts.Org.Status.VALID); + UserVO userVO = null; if (!CollectionUtils.isEmpty(users)) { - UserVO userVO = sysUserDAO.queryUserWithCompany(users.get(0).getId()); - userVO.setRolesByString(); - return userVO; + userVO = new UserVO(users.get(0)); } - OrgExample e = new OrgExample(); - e.createCriteria().andProjectCodeEqualTo(project.name()).andParentIdIsNull(); - List orgs = companyDAO.selectByExample(e); - if(!CollectionUtils.isEmpty(orgs)) { - account += orgs.get(0).getCode(); + /* 再按账号结合所属组织id查询(目前这种是学生账号/测试账号) */ + if (userVO == null) { + if (topOrg == null) { + return null; + } else { + example.clear(); + SysUserExample.Criteria criteria = example.createCriteria().andAccountEqualTo(account).andPasswordEqualTo(password); + criteria.andOrgIdEqualTo(topOrg.getId()); + users = this.sysUserDAO.selectByExample(example); + if (CollectionUtils.isEmpty(users)) return null; + userVO = new UserVO(users.get(0)); + } } - example.clear(); - example.createCriteria().andAccountEqualTo(account).andPasswordEqualTo(password); // 账号 - users = this.sysUserDAO.selectByExample(example); - if (CollectionUtils.isEmpty(users)) return null; - UserVO userVO = sysUserDAO.queryUserWithCompany(users.get(0).getId()); + /* 如果用户属于该顶级组织,设置相关属性 */ userVO.setRolesByString(); - if (!Project.isDefault(project)) { - BusinessExceptionAssertEnum.INSUFFICIENT_PERMISSIONS.assertTrue(!StringUtils.hasText(userVO.getProjectCode()) || Objects.equals(project.name(),userVO.getProjectCode()),"没有项目权限"); + if (topOrg != null) { + boolean flag = false; + if (Objects.equals(topOrg.getId(), userVO.getOrgId())) { + flag = true; + } else { + List orgUsers = iOrgUserService.findEntitiesByUserId(userVO.getId(), null); + if (orgUsers.stream().anyMatch(ou -> Objects.equals(ou.getOrgId(), topOrg.getId()))) { + flag = true; + } else { + Set userRelTopOrgId = iOrgService.findEntities(orgUsers.stream().map(OrgUser::getOrgId) + .collect(Collectors.toList()), BusinessConsts.Org.Status.VALID) + .stream().map(Org::getRootId).collect(Collectors.toSet()); //用户直接或间接关联的所有顶级组织id + if (userRelTopOrgId.contains(topOrg.getId())) { + flag = true; + } + } + } + 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(","))); + } } return userVO; } + @Override + public SysUser findEntity(@NonNull String account, long orgId) { + SysUserExample example = new SysUserExample(); + example.createCriteria().andAccountEqualTo(account).andOrgIdEqualTo(orgId); + List users = sysUserDAO.selectByExample(example); + if (CollectionUtils.isEmpty(users)) { + return null; + } else { + return users.get(0); + } + } + + @Override + public boolean isExist(@NonNull String account, long orgId) { + SysUserExample example = new SysUserExample(); + example.createCriteria().andAccountEqualTo(account).andOrgIdEqualTo(orgId); + return sysUserDAO.countByExample(example) > 0; + } + @Override public List queryUserByNameOrMobile(String query) { String format = String.format("%%%s%%", query); @@ -127,7 +177,7 @@ public class SysUserService implements ISysUserService { SysUserExample example = new SysUserExample(); example.createCriteria().andAccountEqualTo(account); List sysUsers = this.sysUserDAO.selectByExample(example); - if(CollectionUtils.isEmpty(sysUsers))return null; + if (CollectionUtils.isEmpty(sysUsers)) return null; return new UserVO(sysUsers.get(0)); } @@ -161,12 +211,12 @@ public class SysUserService implements ISysUserService { BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(user); log.info("用户信息修改:" + userInfo.toString()); // 修改邮箱/手机 验证码校验 - if(StringUtils.hasText(userInfo.getMobile()) || StringUtils.hasText(userInfo.getEmail())) { + if (StringUtils.hasText(userInfo.getMobile()) || StringUtils.hasText(userInfo.getEmail())) { VdCode vdCode = null; - if(StringUtils.hasText(userInfo.getMobile())) { + if (StringUtils.hasText(userInfo.getMobile())) { vdCode = (VdCode) iCacheService.get(NATION_CODE + userInfo.getMobile()); } - if(Objects.isNull(vdCode) && StringUtils.hasText(userInfo.getEmail())) { + if (Objects.isNull(vdCode) && StringUtils.hasText(userInfo.getEmail())) { vdCode = (VdCode) iCacheService.get(userInfo.getEmail()); } BusinessExceptionAssertEnum.INCORRECT_VERIFICATION_CODE.assertNotNull( @@ -175,10 +225,10 @@ public class SysUserService implements ISysUserService { ); // 验证码校验正确 SysUserExample example = new SysUserExample(); - if(StringUtils.hasText(userInfo.getMobile())) { + if (StringUtils.hasText(userInfo.getMobile())) { example.createCriteria().andMobileEqualTo(userInfo.getMobile()); } - if(StringUtils.hasText(userInfo.getEmail())) { + if (StringUtils.hasText(userInfo.getEmail())) { example.createCriteria().andEmailEqualTo(userInfo.getEmail()); } List mUser = this.sysUserDAO.selectByExample(example); @@ -193,39 +243,51 @@ public class SysUserService implements ISysUserService { @Override public PageVO queryPagedUser(UserQueryVO queryVO) { PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); - Page page = (Page) sysUserDAO.queryUsersWithCompany(queryVO); - page.getResult().forEach(UserVO::forClient); - return PageVO.convert(page); -// SysUserExample example = new SysUserExample(); -// SysUserExample.Criteria criteria = example.createCriteria(); -// if (StringUtils.hasText(queryVO.getName())) { -// criteria.andNameLike(String.format("%%%s%%", queryVO.getName())); -// } -// if (StringUtils.hasText(queryVO.getNickname())) { -// criteria.andNicknameLike(String.format("%%%s%%", queryVO.getNickname())); -// } -// if (StringUtils.hasText(queryVO.getMobile())) { -// criteria.andMobileLike(String.format("%%%s%%", queryVO.getMobile())); -// } -// if (StringUtils.hasText(queryVO.getRolesStr())) { -// criteria.andRolesLike(String.format("%%%s%%", queryVO.getRolesStr())); -// } - -// Page page = (Page) this.sysUserDAO.selectByExample(example); -// List userVOS = UserVO.convertFromDB(page.getResult()); -// List ucrList = iCompanyService.findUserCompanyRelEntity(userVOS.stream().map(UserVO::getId).collect(Collectors.toList())); -// Map userIdUcrMap = ucrList.stream().collect(Collectors.toMap(UserCompanyRel::getUserId, Function.identity())); -// -// if (Objects.nonNull(queryVO.getCompanyId())) { //todo这里有问题 -// -// } -// return PageVO.convert(page, userVOS); +// Page page = (Page) sysUserDAO.queryUsersWithCompany(queryVO); +// page.getResult().forEach(UserVO::forClient); +// return PageVO.convert(page); + SysUserExample example = new SysUserExample(); + SysUserExample.Criteria criteria = example.createCriteria(); + if (StringUtils.hasText(queryVO.getName())) { + criteria.andNameLike(String.format("%%%s%%", queryVO.getName())); + } + if (StringUtils.hasText(queryVO.getEmail())) { + criteria.andEmailLike(String.format("%%%s%%", queryVO.getEmail())); + } + if (StringUtils.hasText(queryVO.getNickname())) { + criteria.andNicknameLike(String.format("%%%s%%", queryVO.getNickname())); + } + if (StringUtils.hasText(queryVO.getMobile())) { + criteria.andMobileLike(String.format("%%%s%%", queryVO.getMobile())); + } + if (StringUtils.hasText(queryVO.getRolesStr())) { + criteria.andRolesLike(String.format("%%%s%%", queryVO.getRolesStr())); + } + Page page = (Page) this.sysUserDAO.selectByExample(example); + List userVOS = UserVO.convertFromDB(page.getResult()); + List userIds = userVOS.stream().map(UserVO::getId).collect(Collectors.toList()); + Map userOrgMap = iOrgUserService.findEntitiesByUserIds(userIds, BusinessConsts.OrgRole.Admin) + .stream().collect(Collectors.toMap(OrgUser::getUserId, OrgUser::getOrgId)); + Map orgMap = iOrgService.findEntities(new ArrayList<>(userOrgMap.values()), BusinessConsts.Org.Status.VALID) + .stream().collect(Collectors.toMap(Org::getId, Function.identity())); + userVOS.forEach(vo -> { + Long orgId = userOrgMap.get(vo.getId()); + if (orgId != null) { + Org org = orgMap.get(orgId); + if (org != null) { + vo.setCompanyId(org.getId()); + vo.setCompanyName(org.getName()); + vo.setCompanyAdmin(true); + } + } + }); + return PageVO.convert(page, userVOS); } @Override public void updateUserRole(Long id, Long userId, UserVO userVO) { SysUser user = this.sysUserDAO.selectByPrimaryKey(id); - if(!user.getRoles().equals(userVO.getRolesStr())) { + if (!user.getRoles().equals(userVO.getRolesStr())) { user.setRoles(userVO.getRolesStr()); this.sysUserDAO.updateByPrimaryKey(user); UserVO newUserVO = sysUserDAO.queryUserWithCompany(id); @@ -261,10 +323,7 @@ public class SysUserService implements ISysUserService { @Override public boolean isExist(Long id) { SysUser user = sysUserDAO.selectByPrimaryKey(id); - if (user == null) { - return false; - } - return true; + return user != null; } @Override @@ -319,7 +378,7 @@ public class SysUserService implements ISysUserService { SysUser sysUser = sysUserDAO.selectByPrimaryKey(userId); BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(sysUser, String.format("id为[%s]的用户不存在", userId)); UserVO userVO = new UserVO(sysUser); - userBindCompanyManager(userVO, companyId); + iOrgUserService.userBindCompanyManager(userVO, companyId); this.loginSessionManager.updateLoginUser(userVO); return new CompanyVO(company); } @@ -386,7 +445,7 @@ public class SysUserService implements ISysUserService { SysUserExample example = new SysUserExample(); example.createCriteria().andWxUnionIdEqualTo(unionId); List list = this.sysUserDAO.selectByExample(example); - if(CollectionUtils.isEmpty(list)) { + if (CollectionUtils.isEmpty(list)) { return null; } UserVO userVO = sysUserDAO.queryUserWithCompany(list.get(0).getId()); @@ -400,7 +459,7 @@ public class SysUserService implements ISysUserService { SysUserExample example = new SysUserExample(); example.createCriteria().andWmOpenIdEqualTo(wmOpenId); List userList = this.sysUserDAO.selectByExample(example); - if(!CollectionUtils.isEmpty(userList)) { + if (!CollectionUtils.isEmpty(userList)) { UserVO userVO = sysUserDAO.queryUserWithCompany(userList.get(0).getId()); userVO.setRolesByString(); return userVO; @@ -456,24 +515,24 @@ public class SysUserService implements ISysUserService { public void updateUserWmOpenId(Long id, String wmOpenId) { Objects.requireNonNull(id); SysUser user = this.sysUserDAO.selectByPrimaryKey(id); - if(Objects.nonNull(user)) { + if (Objects.nonNull(user)) { user.setWmOpenId(wmOpenId); this.sysUserDAO.updateByPrimaryKey(user); } } @Override - public void updateUserWX(Long userId, WmUserSession wmUserSession){ + public void updateUserWX(Long userId, WmUserSession wmUserSession) { SysUser user = this.sysUserDAO.selectByPrimaryKey(userId); - user.setWmOpenId(Objects.isNull(wmUserSession)?null:wmUserSession.getOpenid()); - user.setWxUnionId(Objects.isNull(wmUserSession)?null:wmUserSession.getUnionid()); + user.setWmOpenId(Objects.isNull(wmUserSession) ? null : wmUserSession.getOpenid()); + user.setWxUnionId(Objects.isNull(wmUserSession) ? null : wmUserSession.getUnionid()); this.sysUserDAO.updateByPrimaryKey(user); } @Override @Transactional public void updateUserWxUnionId(List changeUserList) { - if(!CollectionUtils.isEmpty(changeUserList)) { + if (!CollectionUtils.isEmpty(changeUserList)) { List sysUsers = UserVO.convert2UnionIdInfoVOs(changeUserList); sysUsers.forEach(sysUser -> this.sysUserDAO.updateByPrimaryKeySelective(sysUser)); } @@ -510,14 +569,14 @@ public class SysUserService implements ISysUserService { // changeUserList.add(userVO); // } // }); - if(userVOPageVO.getList().size() < pageSize) { + if (userVOPageVO.getList().size() < pageSize) { break; } // 取下一批用户 pagination.setPageNum(++i); userVOPageVO = this.queryPagedUser(pagination); } - if(!CollectionUtils.isEmpty(changeUserList)) { // 转换成功的用户 + if (!CollectionUtils.isEmpty(changeUserList)) { // 转换成功的用户 this.updateUserWxUnionId(changeUserList); } } @@ -527,7 +586,7 @@ public class SysUserService implements ISysUserService { Objects.requireNonNull(id, "用户id不能为空"); Assert.hasText(name, "name 不能为空"); SysUser user = this.sysUserDAO.selectByPrimaryKey(id); - if(Objects.nonNull(user) && !Objects.equals(name, user.getName())) { + if (Objects.nonNull(user) && !Objects.equals(name, user.getName())) { user.setName(name); user.setUpdateTime(LocalDateTime.now()); this.sysUserDAO.updateByPrimaryKey(user); @@ -542,7 +601,7 @@ public class SysUserService implements ISysUserService { Objects.requireNonNull(id, "用户id不能为空"); Assert.hasText(nickname, "nickname不能为空"); SysUser user = this.sysUserDAO.selectByPrimaryKey(id); - if(Objects.nonNull(user) && !Objects.equals(nickname, user.getNickname())) { + if (Objects.nonNull(user) && !Objects.equals(nickname, user.getNickname())) { user.setNickname(nickname); user.setUpdateTime(LocalDateTime.now()); this.sysUserDAO.updateByPrimaryKey(user); @@ -555,7 +614,7 @@ public class SysUserService implements ISysUserService { @Override public void updateAvatar(Long id, String avatarPath) { SysUser user = this.sysUserDAO.selectByPrimaryKey(id); - if(Objects.nonNull(user)) { + if (Objects.nonNull(user)) { user.setAvatarPath(avatarPath); user.setUpdateTime(LocalDateTime.now()); this.sysUserDAO.updateByPrimaryKey(user); @@ -573,7 +632,7 @@ public class SysUserService implements ISysUserService { BusinessExceptionAssertEnum.INCORRECT_VERIFICATION_CODE.assertNotNull(vdCode); vdCode.isValidCode(updateMobileVO.getValidCode()); SysUser user = this.sysUserDAO.selectByPrimaryKey(id); - if(Objects.nonNull(user)) { + if (Objects.nonNull(user)) { user.setNationcode(updateMobileVO.getNationCode()); user.setMobile(updateMobileVO.getMobile()); user.setUpdateTime(LocalDateTime.now()); @@ -592,7 +651,7 @@ public class SysUserService implements ISysUserService { // 验证验证码 vdCode.isValidCode(updateEmailVO.getValidCode()); SysUser user = this.sysUserDAO.selectByPrimaryKey(id); - if(Objects.nonNull(user)) { + if (Objects.nonNull(user)) { user.setEmail(updateEmailVO.getEmail()); user.setUpdateTime(LocalDateTime.now()); this.sysUserDAO.updateByPrimaryKey(user); @@ -619,9 +678,9 @@ public class SysUserService implements ISysUserService { long ts = System.currentTimeMillis(); List params = new ArrayList<>(); params.add(code); - params.add(VdCode.CODE_TIMEOUT+""); + params.add(VdCode.CODE_TIMEOUT + ""); SmsResponse resp = this.iSmsService.sendValidateCode(mobileInfoVO.getMobile(), mobileInfoVO.getNationCode(), params, ts); - BusinessExceptionAssertEnum.THIRD_SERVICE_CALL_EXCEPTION.assertTrue(resp.getResult()==0, + BusinessExceptionAssertEnum.THIRD_SERVICE_CALL_EXCEPTION.assertTrue(resp.getResult() == 0, String.format("短信发送服务调用异常:[result: %s, errmsg: %s]", resp.getResult(), resp.getErrmsg())); iCacheService.putExpired(mobileInfoVO.buildUp(), new VdCode(code, ts), VdCode.CODE_TIMEOUT, TimeUnit.MINUTES); log.debug(String.format("短息发送手机%s验证码:[%s]", mobileInfoVO.buildUp(), code)); @@ -633,7 +692,7 @@ public class SysUserService implements ISysUserService { public void updatePassword(Long id, UpdatePasswordVO updatePasswordVO) { Objects.requireNonNull(id, "用户id不能为空"); SysUser user = this.sysUserDAO.selectByPrimaryKey(id); - if(Objects.nonNull(user)) { + if (Objects.nonNull(user)) { VdCode vdCode = (VdCode) this.iCacheService.get(user.getNationcode() + user.getMobile()); BusinessExceptionAssertEnum.INCORRECT_VERIFICATION_CODE.assertNotNull(vdCode); // 验证验证码 @@ -649,7 +708,7 @@ public class SysUserService implements ISysUserService { public void updateUserPassword(Long id, String password) { Objects.requireNonNull(id, "用户id不能为空"); SysUser user = this.sysUserDAO.selectByPrimaryKey(id); - if(Objects.nonNull(user)) { + if (Objects.nonNull(user)) { user.setPassword(password); user.setUpdateTime(LocalDateTime.now()); this.sysUserDAO.updateByPrimaryKey(user); @@ -680,7 +739,7 @@ public class SysUserService implements ISysUserService { } @Override - public List getUsersWithEmail(){ + public List getUsersWithEmail() { SysUserExample example = new SysUserExample(); example.createCriteria().andMobileIsNotNull().andNationcodeIsNotNull().andStatusEqualTo(BusinessConsts.STATUS_USE); List sysUsers = sysUserDAO.selectByExample(example); @@ -689,7 +748,7 @@ public class SysUserService implements ISysUserService { } @Override - public List getUsersWithMobile(){ + public List getUsersWithMobile() { SysUserExample example = new SysUserExample(); example.createCriteria().andEmailIsNotNull().andStatusEqualTo(BusinessConsts.STATUS_USE); List sysUsers = sysUserDAO.selectByExample(example); @@ -698,7 +757,7 @@ public class SysUserService implements ISysUserService { } @Override - public List getPlatformUsers(){ + public List getPlatformUsers() { SysUserExample example = new SysUserExample(); example.createCriteria().andStatusEqualTo(BusinessConsts.STATUS_USE).andOfflineEqualTo(false); List sysUsers = sysUserDAO.selectByExample(example); @@ -730,7 +789,7 @@ public class SysUserService implements ISysUserService { public void superAdminUpdateUserInfo(UserVO updateUserVO, UserVO superAdmin) { Long userId = updateUserVO.getId(); SysUser user = getEntity(userId); - if(!user.getRoles().equals(updateUserVO.getRolesStr())) { + if (!user.getRoles().equals(updateUserVO.getRolesStr())) { user.setRoles(updateUserVO.getRolesStr()); user.setUpdateTime(LocalDateTime.now()); this.sysUserDAO.updateByPrimaryKey(user); @@ -745,49 +804,6 @@ public class SysUserService implements ISysUserService { // this.loginSessionManager.updateLoginUser(userVO); } - @Override - @Transactional - public void userBindCompanyManager(UserVO userVO, Long companyId) { - OrgExample companyExample = new OrgExample(); - companyExample.createCriteria().andParentIdIsNull().andIdEqualTo(companyId); - BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(companyDAO.countByExample(companyExample) > 0, "不存在的单位"); - if (Objects.nonNull(companyId)) { - List companyMangers = orgUserDAO.getCompanyManger(userVO.getId()); - OrgUserExample oe = new OrgUserExample(); - oe.createCriteria().andUserIdEqualTo(userVO.getId()); - if (CollectionUtils.isEmpty(companyMangers)) { - List orgUsers = orgUserDAO.selectByExample(oe); - if (CollectionUtils.isEmpty(orgUsers)) { - OrgUser companyManager = new OrgUser(); - companyManager.setOrgId(companyId); - companyManager.setUserId(userVO.getId()); - companyManager.setRole(BusinessConsts.OrgRole.Admin.name()); - orgUserDAO.insertSelective(companyManager); - } else { - Long orgId = orgUsers.get(0).getOrgId(); - Org org = companyDAO.selectByPrimaryKey(orgId); - if (!Objects.equals(org.getRootId(), companyId)) { - orgUserDAO.deleteByExample(oe); - } - } - } else { - OrgUser companyManger = companyMangers.get(0); - if (!Objects.equals(companyManger.getOrgId(), companyId)) { - orgUserDAO.deleteByExample(oe); - companyManger.setOrgId(companyId); - companyManger.setId(null); - companyManger.setCreateTime(null); - companyManger.setUpdateTime(null); - orgUserDAO.insertSelective(companyManger); - } - } - String companyName = companyDAO.selectByPrimaryKey(companyId).getName(); - userVO.setCompanyName(companyName); - userVO.setCompanyId(companyId); - userVO.setCompanyAdmin(true); - } - } - @Override public List querySellers() { SysUserExample example = new SysUserExample(); @@ -805,7 +821,7 @@ public class SysUserService implements ISysUserService { @Override public void deleteById(Long id) { - sysUserDAO.deleteByPrimaryKey(id); + sysUserDAO.deleteByPrimaryKey(id); } @Override diff --git a/src/main/java/club/joylink/rtss/services/UserExamService.java b/src/main/java/club/joylink/rtss/services/UserExamService.java index dbef03510..a1feb68e8 100644 --- a/src/main/java/club/joylink/rtss/services/UserExamService.java +++ b/src/main/java/club/joylink/rtss/services/UserExamService.java @@ -311,7 +311,6 @@ public class UserExamService implements IUserExamService { List userExams = userExamMapper.selectByExample(example); Map> user_exam_map = userExams.stream().collect(Collectors.groupingBy(UserExam::getUserId, Collectors.maxBy(Comparator.comparingDouble(UserExam::getScore)))); List users = iSysUserService.findEntities(studentIds, "account"); - Org topOrg = iOrgService.getTopOrgEntity(orgId, null); List vos = users.stream().map(user -> { UserExamVO vo; Optional userExamOptional = user_exam_map.get(user.getId()); @@ -321,7 +320,7 @@ public class UserExamService implements IUserExamService { vo = new UserExamVO(); } vo.setUserId(user.getId().toString()); - vo.setAccount(user.getAccount().substring(0, user.getAccount().indexOf(topOrg.getCode()))); + vo.setAccount(user.getAccount()); vo.setUsername(user.getName()); return vo; }).collect(Collectors.toList()); diff --git a/src/main/java/club/joylink/rtss/services/org/IOrgService.java b/src/main/java/club/joylink/rtss/services/org/IOrgService.java index b9a0e3e41..54d54d284 100644 --- a/src/main/java/club/joylink/rtss/services/org/IOrgService.java +++ b/src/main/java/club/joylink/rtss/services/org/IOrgService.java @@ -71,4 +71,8 @@ public interface IOrgService { * 查询这些考试关联的班级 */ List queryByExamIds(List examIds, String status); + + void confirmIsTopOrg(long id); + + void confirmIsNonTopOrg(Long id); } diff --git a/src/main/java/club/joylink/rtss/services/org/IOrgUserService.java b/src/main/java/club/joylink/rtss/services/org/IOrgUserService.java index e93e856fb..435bdaf61 100644 --- a/src/main/java/club/joylink/rtss/services/org/IOrgUserService.java +++ b/src/main/java/club/joylink/rtss/services/org/IOrgUserService.java @@ -60,15 +60,19 @@ public interface IOrgUserService { */ int getQuantities(Long orgId, BusinessConsts.OrgRole role); - boolean isTheRoleInThisOrg(Long userId, Long orgId, BusinessConsts.OrgRole role); + boolean isTheRoleInThisOrg(long userId, long orgId, BusinessConsts.OrgRole role); void confirmIsTheRoleInThisOrg(Long userId, Long orgId, BusinessConsts.OrgRole role); - void createOrgUser(Long orgId, Long userId, BusinessConsts.OrgRole role); + void create(long orgId, long userId, BusinessConsts.OrgRole role); - List findEntitiesByOrgId(Long orgId, BusinessConsts.OrgRole role); + List findEntitiesByOrgId(long orgId, BusinessConsts.OrgRole role); - List findEntities(List orgIds, BusinessConsts.OrgRole role); + List findEntitiesByOrgIds(List orgIds, BusinessConsts.OrgRole role); - List findEntities(Long userId, BusinessConsts.OrgRole role); + List findEntitiesByUserIds(List userIds, BusinessConsts.OrgRole role); + + List findEntitiesByUserId(long userId, BusinessConsts.OrgRole role); + + void userBindCompanyManager(UserVO userVO, Long topOrgId); } diff --git a/src/main/java/club/joylink/rtss/services/org/OrgScoringRuleService.java b/src/main/java/club/joylink/rtss/services/org/OrgScoringRuleService.java index bde324625..b0c3202a8 100644 --- a/src/main/java/club/joylink/rtss/services/org/OrgScoringRuleService.java +++ b/src/main/java/club/joylink/rtss/services/org/OrgScoringRuleService.java @@ -293,17 +293,14 @@ public class OrgScoringRuleService implements IOrgScoringRuleService { // TODO: 2021/3/24 评价结果保存、确认流程 List students; if (clsId == null) { - students = iOrgUserService.findEntities(orgScoringRuleVO.getOrgIds(), BusinessConsts.OrgRole.Student); + students = iOrgUserService.findEntitiesByOrgIds(orgScoringRuleVO.getOrgIds(), BusinessConsts.OrgRole.Student); } else { students = iOrgUserService.findEntitiesByOrgId(clsId, BusinessConsts.OrgRole.Student); } List userIds = students.stream().map(OrgUser::getUserId).collect(Collectors.toList()); List users = iSysUserService.findEntities(userIds, "id"); Org topOrg = iOrgService.getTopOrgEntity(orgScoringRuleVO.getOrgIds().get(0), BusinessConsts.Org.Status.VALID); - List results = users.stream().map(sysUser -> { - String account = sysUser.getAccount().substring(0, sysUser.getAccount().indexOf(topOrg.getCode())); - return new OrgScoringResultVO(sysUser.getId(), account, sysUser.getName()); - }).collect(Collectors.toList()); + List results = users.stream().map(OrgScoringResultVO::new).collect(Collectors.toList()); List projects = List.of(topOrg.getProjectCode().split(",")); this.score(results, orgScoringRuleVO.getScoringRules(), projects); return results; diff --git a/src/main/java/club/joylink/rtss/services/org/OrgService.java b/src/main/java/club/joylink/rtss/services/org/OrgService.java index 4512751af..21484f01c 100644 --- a/src/main/java/club/joylink/rtss/services/org/OrgService.java +++ b/src/main/java/club/joylink/rtss/services/org/OrgService.java @@ -3,10 +3,7 @@ package club.joylink.rtss.services.org; import club.joylink.rtss.constants.BusinessConsts; import club.joylink.rtss.constants.Project; import club.joylink.rtss.dao.OrgDAO; -import club.joylink.rtss.entity.Org; -import club.joylink.rtss.entity.OrgExample; -import club.joylink.rtss.entity.OrgUser; -import club.joylink.rtss.entity.SysUser; +import club.joylink.rtss.entity.*; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.services.ISysUserService; import club.joylink.rtss.vo.LoginUserInfoVO; @@ -43,31 +40,23 @@ public class OrgService implements IOrgService { @Autowired private ISysUserService iSysUserService; - public final static String companyCodePrefix = "C"; - @Transactional @Override public CompanyVO createTopOrg(CompanyVO companyVO, UserVO user) { /* 检查 */ - if (StringUtils.hasText(companyVO.getProjectCode())) { - Org org = findEntity(Project.valueOf(companyVO.getProjectCode()), BusinessConsts.Org.Status.VALID); - BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNull(org, "项目已被绑定到其他单位!"); + if (!CollectionUtils.isEmpty(companyVO.getProjectCodes())) { + confirmProjectCodesNotRepeat(null, companyVO.getProjectCodes()); } //名称检查 OrgExample example = new OrgExample(); example.createCriteria().andNameEqualTo(companyVO.getName()); BusinessExceptionAssertEnum.DATA_UNIQUE_PROPERTY_REPEAT.assertTrue(orgDAO.countByExample(example) == 0, "名称重复"); -// //编号检查 -// example.clear(); -// example.createCriteria().andCodeEqualTo(companyVO.getCode()); -// BusinessExceptionAssertEnum.DATA_UNIQUE_PROPERTY_REPEAT.assertTrue(orgDAO.countByExample(example) == 0, -// "编号重复"); /* 处理 */ Org entity = companyVO.toDB(); + entity.setId(null); entity.setCreatorId(user.getId()); entity.setCreateTime(LocalDateTime.now()); - entity.setCode(nextCompanyCode()); entity.setStatus(BusinessConsts.Org.Status.VALID); this.orgDAO.insert(entity); entity.setRootId(entity.getId()); @@ -112,7 +101,7 @@ public class OrgService implements IOrgService { Long userId = loginInfo.getUserVO().getId(); iOrgUserService.confirmIsTheRoleInThisOrg(userId, topOrgId, BusinessConsts.OrgRole.Admin); Org cls = createNonTopOrg(createVO.getName(), topOrgId, topOrgId, userId); - iOrgUserService.createOrgUser(cls.getId(), userId, BusinessConsts.OrgRole.Teacher); + iOrgUserService.create(cls.getId(), userId, BusinessConsts.OrgRole.Teacher); } @Override @@ -132,7 +121,7 @@ public class OrgService implements IOrgService { @Override public Org findEntity(@NonNull Project project, String status) { OrgExample example = new OrgExample(); - OrgExample.Criteria criteria = example.createCriteria().andProjectCodeEqualTo(project.name()); + OrgExample.Criteria criteria = example.createCriteria().andProjectCodeLike(String.format("%%%s%%", project.name())); if (StringUtils.hasText(status)) { criteria.andStatusEqualTo(status); } @@ -148,13 +137,13 @@ public class OrgService implements IOrgService { public CompanyVO updateOrg(Long id, CompanyVO companyVO, UserVO user) { //校验 Org org = getEntity(id); - if (!isTopOrg(org)) { - BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(!StringUtils.hasText(companyVO.getProjectCode()), - "非顶级组织不能修改projectCode"); + if (!CollectionUtils.isEmpty(companyVO.getProjectCodes())) { + BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(isTopOrg(org), "非顶级组织不能修改关联项目"); + confirmProjectCodesNotRepeat(org.getId(), companyVO.getProjectCodes()); } //更新 org.setName(companyVO.getName()); - org.setProjectCode(companyVO.getProjectCode()); + org.setProjectCode(companyVO.getDBProjectCode()); org.setUpdateId(user.getId()); org.setUpdateTime(LocalDateTime.now()); this.orgDAO.updateByPrimaryKeySelective(org); @@ -257,8 +246,6 @@ public class OrgService implements IOrgService { Org org = getEntity(orgId); Map> groupByParentIdOrg = findEntitiesByRootId(org.getRootId(), null, BusinessConsts.Org.Status.VALID) .stream().filter(o -> o.getParentId() != null).collect(Collectors.groupingBy(Org::getParentId)); - List orgIds = new ArrayList<>(); //要展示的组织 - orgIds.add(orgId); Node root = new Node<>(new DepartmentVO(org), Node.Type.ORG); Map> all_orgId_node_map = new HashMap<>(); //所有的组织和对应的节点 Map> orgId_node_map = new HashMap<>(); @@ -270,7 +257,6 @@ public class OrgService implements IOrgService { List childOrgList = groupByParentIdOrg.get(k); if (!CollectionUtils.isEmpty(childOrgList)) { List> children = childOrgList.stream().map(o -> { - orgIds.add(o.getId()); Node node = new Node<>(new DepartmentVO(o), Node.Type.ORG); newMap.put(o.getId(), node); return node; @@ -281,21 +267,23 @@ public class OrgService implements IOrgService { orgId_node_map = newMap; } /* 再查询用户 */ - List orgUsers = iOrgUserService.findEntities(orgIds, null); + List orgUsers = iOrgUserService.findEntitiesByOrgIds(new ArrayList<>(all_orgId_node_map.keySet()), null); Map> groupByOrgIdOrgUsers = orgUsers.stream().collect(Collectors.groupingBy(OrgUser::getOrgId)); List userIds = orgUsers.stream().map(OrgUser::getUserId).collect(Collectors.toList()); Map userMap = iSysUserService.findEntities(userIds, null) .stream().collect(Collectors.toMap(SysUser::getId, Function.identity())); all_orgId_node_map.forEach((k,v)->{ List ous = groupByOrgIdOrgUsers.get(k); - List> children = ous.stream().map(ou -> { - OrgUserVO vo = new OrgUserVO(ou, userMap.get(ou.getUserId())); - return new Node(vo, Node.Type.USER); - }).collect(Collectors.toList()); - if (!CollectionUtils.isEmpty(v.getChildren())) { - children.addAll(v.getChildren()); + if (!CollectionUtils.isEmpty(ous)) { + List> children = ous.stream().map(ou -> { + OrgUserVO vo = new OrgUserVO(ou, userMap.get(ou.getUserId())); + return new Node(vo, Node.Type.USER); + }).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(v.getChildren())) { + children.addAll(v.getChildren()); + } + v.setChildren(children); } - v.setChildren(children); }); return root; } @@ -314,6 +302,25 @@ public class OrgService implements IOrgService { return orgDAO.queryByExamIds(examIds, status); } + /** + * 确认是顶级组织 + * @param id + */ + @Override + public void confirmIsTopOrg(long id) { + BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(isTopOrg(id), + String.format("组织[%s]不是顶级组织", id)); + } + + /** + * 确认是非顶级组织 + */ + @Override + public void confirmIsNonTopOrg(Long id) { + BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(!isTopOrg(id), + String.format("组织[%s]是顶级组织", id)); + } + /** * 创建非顶级组织 */ @@ -338,32 +345,14 @@ public class OrgService implements IOrgService { return org; } - /** - * 确认是顶级组织 - * - * @param id - */ - private void confirmIsTopOrg(@NonNull Long id) { - Org org = getEntity(id); - BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(isTopOrg(org), - String.format("组织[%s]不是顶级组织", id)); + private boolean isTopOrg(long orgId) { + return getEntity(orgId).getParentId() == null; } private boolean isTopOrg(Org org) { return org.getParentId() == null; } - /** - * 确认是顶级组织 - * - * @param id - */ - private void confirmIsNonTopOrg(Long id) { - Org org = getEntity(id); - BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(!isTopOrg(org), - String.format("组织[%s]是顶级组织", id)); - } - private List findEntitiesByRootId(Long rootId, String orderBy, String status) { OrgExample example = new OrgExample(); if (StringUtils.hasText(orderBy)) { @@ -379,16 +368,19 @@ public class OrgService implements IOrgService { return orgs; } - private String nextCompanyCode() { - OrgExample e = new OrgExample(); - e.setLimit(1); - e.setOrderByClause(" code DESC"); - e.createCriteria().andParentIdIsNull().andCodeIsNotNull(); - List orgs = orgDAO.selectByExample(e); - if (CollectionUtils.isEmpty(orgs)) { - return companyCodePrefix + "001"; + /** + * 确认这些项目没有被关联到其它的组织 + */ + private void confirmProjectCodesNotRepeat(Long orgId, List projectCodes) { + OrgExample example = new OrgExample(); + for (String projectCode : projectCodes) { + OrgExample.Criteria criteria = example.or(); + if (orgId != null) { + criteria.andIdNotEqualTo(orgId); + } + criteria.andProjectCodeLike(String.format("%%%s%%", projectCode)); } - int seq = Integer.parseInt(orgs.get(0).getCode().substring(1)); - return companyCodePrefix + (String.format("%03d", ++seq)); + BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(orgDAO.countByExample(example) == 0, + "部分所选项目已与其它组织关联"); } } diff --git a/src/main/java/club/joylink/rtss/services/org/OrgUserService.java b/src/main/java/club/joylink/rtss/services/org/OrgUserService.java index bb78e9fb6..e1934082e 100644 --- a/src/main/java/club/joylink/rtss/services/org/OrgUserService.java +++ b/src/main/java/club/joylink/rtss/services/org/OrgUserService.java @@ -220,10 +220,11 @@ public class OrgUserService implements IOrgUserService { */ @Override public void deleteDepartUserInfo(UserVO user, UserDepartRelVO userDepartRelVO) { - OrgUser userRel = getDepartUseRelEntity(user.getId(), userDepartRelVO.getDepartmentId()); - BusinessExceptionAssertEnum.INVALID_OPERATION.assertNotNull(userRel, "非本部门成员"); - BusinessExceptionAssertEnum.INVALID_OPERATION.assertTrue(StringUtils.hasText(userRel.getRole()) - && !Objects.equals(userRel.getRole(), BusinessConsts.OrgRole.Student.name()), "无权操作"); + if (!iSysUserService.isAdmin(user)) { + BusinessExceptionAssertEnum.INSUFFICIENT_PERMISSIONS.assertTrue( + isTheRoleInThisOrg(user.getId(), userDepartRelVO.getDepartmentId(), BusinessConsts.OrgRole.Teacher), "无权操作"); + BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertEquals(BusinessConsts.OrgRole.Student.name(), userDepartRelVO.getOrgRole(), "只能以学生为对象"); + } OrgUserExample example = new OrgUserExample(); example.createCriteria().andOrgIdEqualTo(userDepartRelVO.getDepartmentId()) .andUserIdEqualTo(userDepartRelVO.getUserId()).andRoleEqualTo(userDepartRelVO.getOrgRole()); @@ -255,107 +256,6 @@ public class OrgUserService implements IOrgUserService { confirmIsTheRoleInThisOrg(user.getId(), clsId, BusinessConsts.OrgRole.Teacher); Set studentIdSet = findEntitiesByOrgId(clsId, BusinessConsts.OrgRole.Student).stream().map(OrgUser::getUserId).collect(Collectors.toSet()); importOrgUsers.forEach(vo -> importOrgUser(topOrg, cls.getId(), studentIdSet, vo)); - -// //验证操作人员 -// Org company = getCompanyEntity(clsId); -// BusinessExceptionAssertEnum.INVALID_OPERATION.assertNotNull(company, "单位不存在"); -// BusinessExceptionAssertEnum.INVALID_OPERATION.assertEquals(user.getCompanyId(), clsId, "非同单位成员无法操作"); -// OrgUserExample oue = new OrgUserExample(); -// oue.createCriteria().andOrgIdEqualTo(clsId).andRoleEqualTo(BusinessConsts.OrgRole.Admin.name()); -// BusinessExceptionAssertEnum.INVALID_OPERATION.assertTrue(orgUserDAO.countByExample(oue) > 0, "非本单位管理员"); -// //验证是否存在并导入新的年级和班级 -// var departmentExample = new OrgExample(); -// departmentExample.createCriteria() -// .andParentIdIsNotNull() -// .andRootIdEqualTo(clsId) -// .andNameEqualTo(importOrgUsers.getParentDepart()); -// List importParentDepart = orgDAO.selectByExample(departmentExample); -// DepartmentVO parentDepart; -// DepartmentVO childDepart; -// if (CollectionUtils.isEmpty(importParentDepart)) { -// parentDepart = new DepartmentVO(importOrgUsers.getParentDepart(), clsId, clsId); -// createDepart(parentDepart); -// childDepart = new DepartmentVO(importOrgUsers.getDepart(), parentDepart.getId(), clsId); -// createDepart(childDepart); -// UserDepartRelVO userDepartRelVO = new UserDepartRelVO(user.getId(), childDepart.getId(), BusinessConsts.OrgRole.Teacher.name()); -// orgUserDAO.insertSelective(userDepartRelVO.toDB()); -// } else { -// parentDepart = new DepartmentVO(importParentDepart.get(0)); -// departmentExample.clear(); -// OrgExample.Criteria criteria = departmentExample.createCriteria() -// .andRootIdEqualTo(clsId) -// .andNameEqualTo(importOrgUsers.getDepart()); -// if (Objects.isNull(parentDepart.getParentId())) { -// criteria.andParentIdIsNull(); -// } else { -// criteria.andParentIdEqualTo(parentDepart.getParentId()); -// } -// List importChildDepart = orgDAO.selectByExample(departmentExample); -// BusinessExceptionAssertEnum.INVALID_OPERATION.assertCollectionEmpty(importChildDepart, "班级信息重复"); -// childDepart = new DepartmentVO(importOrgUsers.getDepart(), parentDepart.getId(), clsId); -// createDepart(childDepart); -// UserDepartRelVO userDepartRelVO = new UserDepartRelVO(user.getId(), childDepart.getId(), BusinessConsts.OrgRole.Teacher.name()); -// orgUserDAO.insertSelective(userDepartRelVO.toDB()); -// } -// -// importOrgUsers.getCompanyUsers().forEach(importOrgUser -> importOrgUser(company, childDepart, importOrgUser)); - -// List sysUsers = ImportOrgUserVO.convert2DBList(importCompanyUserVO.getCompanyUsers()); -// sysUsers.forEach(sysUser -> { -// sysUser.setAccount(sysUser.getAccount()+company.getCode()); -// UserVO userVO = iSysUserService.queryUserByAccount(sysUser.getAccount()); -// if (Objects.isNull(userVO)) { -// iSysUserService.createUser(sysUser); -// userVO = new UserVO(sysUser); -// UserDepartRelVO userDepartRelVO = new UserDepartRelVO(userVO.getId(), childDepart.getId(), BusinessConsts.OrgRole.Student.name()); -// orgUserDAO.insertSelective(userDepartRelVO.toDB()); -// } else { -// OrgUserExample e = new OrgUserExample(); -// e.createCriteria().andUserIdEqualTo(userVO.getId()); -// List orgUsers = orgUserDAO.selectByExample(e); -// BusinessExceptionAssertEnum.INVALID_OPERATION.assertCollectionNotEmpty(orgUsers, sysUser.getAccount() + "账号重复"); -// OrgExample oe = new OrgExample(); -// oe.createCriteria().andRootIdEqualTo(companyId); -// List orgIds = orgDAO.selectByExample(oe).stream().map(Org::getId).collect(Collectors.toList()); -// BusinessExceptionAssertEnum.INVALID_OPERATION.assertTrue(orgUsers.stream().allMatch(orgUser -> orgIds.contains(orgUser.getOrgId())), sysUser.getAccount() + "账号重复"); -// if (orgUsers.stream().anyMatch(orgUser -> Objects.equals(orgUser.getOrgId(), childDepart.getId()))) return; -// UserDepartRelVO userDepartRelVO = new UserDepartRelVO(userVO.getId(), childDepart.getId(), BusinessConsts.OrgRole.Student.name()); -// orgUserDAO.insertSelective(userDepartRelVO.toDB()); -// } -// }); - } - - /** - * 导入组织用户 - * - * @param topOrg 导入的组织所属的顶级组织 - * @param orgId - * @param orgUserIdSet 导入的组织当前已有的成员 - */ - private void importOrgUser(Org topOrg, Long orgId, Set orgUserIdSet, ImportOrgUserVO importOrgUser) { - SysUser sysUser = importOrgUser.convert2DB(); - sysUser.setAccount(sysUser.getAccount() + topOrg.getCode()); - UserVO userVO = iSysUserService.queryUserByAccount(sysUser.getAccount()); - if (Objects.isNull(userVO)) { - iSysUserService.createUser(sysUser); - userVO = new UserVO(sysUser); - UserDepartRelVO userDepartRelVO = new UserDepartRelVO(userVO.getId(), orgId, BusinessConsts.OrgRole.Student.name()); - orgUserDAO.insertSelective(userDepartRelVO.toDB()); - } else { -// OrgUserExample e = new OrgUserExample(); -// e.createCriteria().andUserIdEqualTo(userVO.getId()); -// List orgUsers = orgUserDAO.selectByExample(e); -// BusinessExceptionAssertEnum.INVALID_OPERATION.assertCollectionNotEmpty(orgUsers, sysUser.getAccount() + "账号已存在且不属于任何组织"); -// Set clsIdSet = iOrgService.findEntitiesByParentId(topOrg.getId(), null, BusinessConsts.Org.Status.VALID) -// .stream().map(Org::getId).collect(Collectors.toSet()); -// BusinessExceptionAssertEnum.INVALID_OPERATION.assertTrue(orgUsers.stream().allMatch(orgUser -> clsIdSet.contains(orgUser.getOrgId())), -// sysUser.getAccount() + "账号重复"); -// if (orgUsers.stream().anyMatch(orgUser -> Objects.equals(orgUser.getOrgId(), departmentId))) return; - if (!orgUserIdSet.contains(userVO.getId())) { - UserDepartRelVO userDepartRelVO = new UserDepartRelVO(userVO.getId(), orgId, BusinessConsts.OrgRole.Student.name()); - orgUserDAO.insertSelective(userDepartRelVO.toDB()); - } - } } //---------------------------课程 / 考试 / 部门----------------------------------------- @@ -386,11 +286,6 @@ public class OrgUserService implements IOrgUserService { confirmIsTheRoleInThisOrg(user.getId(), clsId, BusinessConsts.OrgRole.Teacher); Org topOrg = iOrgService.getEntity(cls.getRootId()); Set studentIdSet = findEntitiesByOrgId(clsId, BusinessConsts.OrgRole.Student).stream().map(OrgUser::getUserId).collect(Collectors.toSet()); - SysUser sysUser = importVO.convert2DB(); - sysUser.setAccount(sysUser.getAccount() + topOrg.getCode()); - UserVO userVO = iSysUserService.queryUserByAccount(sysUser.getAccount()); - BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(userVO == null || !studentIdSet.contains(userVO.getId()), - "该学生已在班级中"); this.importOrgUser(topOrg, cls.getId(), studentIdSet, importVO); } @@ -407,10 +302,10 @@ public class OrgUserService implements IOrgUserService { } /** - * 该用户在该组织中是否是这个角色 + * 该用户是否属于该组织并是这个角色 */ @Override - public boolean isTheRoleInThisOrg(@NonNull Long userId, @NonNull Long orgId, @NonNull BusinessConsts.OrgRole role) { + public boolean isTheRoleInThisOrg(long userId, long orgId, @NonNull BusinessConsts.OrgRole role) { OrgUserExample example = new OrgUserExample(); example.createCriteria() .andUserIdEqualTo(userId) @@ -429,7 +324,7 @@ public class OrgUserService implements IOrgUserService { } @Override - public void createOrgUser(Long orgId, Long userId, BusinessConsts.OrgRole role) { + public void create(long orgId, long userId, @NonNull BusinessConsts.OrgRole role) { OrgUser orgUser = new OrgUser(); orgUser.setOrgId(orgId); orgUser.setUserId(userId); @@ -440,7 +335,7 @@ public class OrgUserService implements IOrgUserService { } @Override - public List findEntitiesByOrgId(Long orgId, BusinessConsts.OrgRole role) { + public List findEntitiesByOrgId(long orgId, BusinessConsts.OrgRole role) { OrgUserExample example = new OrgUserExample(); OrgUserExample.Criteria criteria = example.createCriteria().andOrgIdEqualTo(orgId); if (role != null) { @@ -450,7 +345,7 @@ public class OrgUserService implements IOrgUserService { } @Override - public List findEntities(List orgIds, BusinessConsts.OrgRole role) { + public List findEntitiesByOrgIds(List orgIds, BusinessConsts.OrgRole role) { if (CollectionUtils.isEmpty(orgIds)) { return new ArrayList<>(); } else { @@ -464,7 +359,21 @@ public class OrgUserService implements IOrgUserService { } @Override - public List findEntities(@NonNull Long userId, BusinessConsts.OrgRole role) { + public List findEntitiesByUserIds(List userIds, BusinessConsts.OrgRole role) { + if (CollectionUtils.isEmpty(userIds)) { + return new ArrayList<>(); + } else { + OrgUserExample example = new OrgUserExample(); + OrgUserExample.Criteria criteria = example.createCriteria().andUserIdIn(userIds); + if (role != null) { + criteria.andRoleEqualTo(role.name()); + } + return orgUserDAO.selectByExample(example); + } + } + + @Override + public List findEntitiesByUserId(long userId, BusinessConsts.OrgRole role) { OrgUserExample example = new OrgUserExample(); OrgUserExample.Criteria criteria = example.createCriteria().andUserIdEqualTo(userId); if (role != null) { @@ -473,4 +382,49 @@ public class OrgUserService implements IOrgUserService { return orgUserDAO.selectByExample(example); } + @Override + public void userBindCompanyManager(UserVO userVO, Long topOrgId) { + Org topOrg = iOrgService.getEntity(topOrgId); + BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNull(topOrg.getParentId(), "所选组织不是顶级组织"); + BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNotTrue(isTheRoleInThisOrg(userVO.getId(), topOrgId, BusinessConsts.OrgRole.Admin), + "已经是所选组织管理员"); + /* 如果是其它组织的管理员,删除关系 */ + List orgUsers = findEntitiesByUserId(userVO.getId(), BusinessConsts.OrgRole.Admin); + List ouIds = orgUsers.stream().map(OrgUser::getId).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(ouIds)) { + OrgUserExample example = new OrgUserExample(); + example.createCriteria().andIdIn(ouIds); + orgUserDAO.deleteByExample(example); + } + /* 建立新关系 */ + create(topOrgId, userVO.getId(), BusinessConsts.OrgRole.Admin); + userVO.setCompanyId(topOrgId); + userVO.setCompanyName(topOrg.getName()); + userVO.setCompanyAdmin(true); + } + + + + + /** + * 导入组织用户 + * + * @param topOrg 导入的组织所属的顶级组织 + * @param orgId 要导入的组织 + * @param orgUserIdSet 导入的组织当前已有的成员 + */ + private void importOrgUser(Org topOrg, Long orgId, Set orgUserIdSet, ImportOrgUserVO importOrgUser) { + SysUser user = iSysUserService.findEntity(importOrgUser.getAccount(), topOrg.getId()); + if (user == null) { + SysUser sysUser = importOrgUser.convert2DB(); + sysUser.setOrgId(topOrg.getId()); + iSysUserService.createUser(sysUser); + create(orgId, sysUser.getId() , BusinessConsts.OrgRole.Student); + } else { + if (!orgUserIdSet.contains(user.getId())) { + create(orgId, user.getId() , BusinessConsts.OrgRole.Student); + } + } + } + } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/GroupSimulationServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/GroupSimulationServiceImpl.java index 4b37a2003..d60505d06 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/GroupSimulationServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/GroupSimulationServiceImpl.java @@ -976,12 +976,8 @@ public class GroupSimulationServiceImpl implements GroupSimulationService { return true; } if (userVO.getCompanyId() != null) { - Org org = iOrgService.getEntity(userVO.getCompanyId()); String mapProject = mapDetail.getProjectCode(); - String companyProject = org.getProjectCode(); - if (StringUtils.hasText(mapProject) && mapProject.equals(companyProject)) { - return true; - } + return userVO.getProjectCodes().stream().anyMatch(orgProject -> Objects.equals(mapProject, orgProject)); } List ups = iUserPermissionService.getSimulationUserPermission(userVO, mapId, prdType); if (!CollectionUtils.isEmpty(ups)) { diff --git a/src/main/java/club/joylink/rtss/vo/UserQueryVO.java b/src/main/java/club/joylink/rtss/vo/UserQueryVO.java index 58055efd4..dfb44a534 100644 --- a/src/main/java/club/joylink/rtss/vo/UserQueryVO.java +++ b/src/main/java/club/joylink/rtss/vo/UserQueryVO.java @@ -21,6 +21,8 @@ public class UserQueryVO extends PageQueryVO { @ApiModelProperty(value = "真实姓名") private String name; + private String email; + /** * 昵称 */ diff --git a/src/main/java/club/joylink/rtss/vo/UserVO.java b/src/main/java/club/joylink/rtss/vo/UserVO.java index 3eb0f6c82..388893c67 100644 --- a/src/main/java/club/joylink/rtss/vo/UserVO.java +++ b/src/main/java/club/joylink/rtss/vo/UserVO.java @@ -34,6 +34,11 @@ public class UserVO implements Serializable { */ private String account; + /** + * 用户所属的顶级组织 + */ + private Long orgId; + /** * 真实姓名 */ @@ -114,7 +119,7 @@ public class UserVO implements Serializable { /** * 用户所属组织关联的项目 */ - private String projectCode; + private List projectCodes; public UserVO() {} @@ -122,6 +127,7 @@ public class UserVO implements Serializable { public UserVO(SysUser sysUser) { this.id = sysUser.getId(); this.account = sysUser.getAccount(); + this.orgId = sysUser.getOrgId(); this.name = sysUser.getName(); this.nickname = sysUser.getNickname(); this.avatarPath = sysUser.getAvatarPath(); diff --git a/src/main/java/club/joylink/rtss/vo/client/org/CompanyVO.java b/src/main/java/club/joylink/rtss/vo/client/org/CompanyVO.java index a62f58a8b..c9f10d9a1 100644 --- a/src/main/java/club/joylink/rtss/vo/client/org/CompanyVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/org/CompanyVO.java @@ -1,14 +1,18 @@ 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 @@ -23,14 +27,14 @@ public class CompanyVO { @NotBlank(message = "公司名称不能为空") private String name; - private String projectCode; - - private String code; + private List projectCodes; public CompanyVO(Org entity) { this.id = entity.getId(); this.name = entity.getName(); - this.projectCode = entity.getProjectCode(); + if (StringUtils.hasText(entity.getProjectCode())) { + this.projectCodes = Arrays.asList(entity.getProjectCode().split(",")); + } } public static List convert2VOList(List dataList) { @@ -45,9 +49,16 @@ public class CompanyVO { Org entity = new Org(); entity.setId(this.id); entity.setName(this.name); - entity.setProjectCode(this.projectCode); + entity.setProjectCode(getDBProjectCode()); return entity; } - + @JsonIgnore + public String getDBProjectCode() { + if (!CollectionUtils.isEmpty(projectCodes)) { + return String.join(",", projectCodes); + } else { + return null; + } + } } diff --git a/src/main/java/club/joylink/rtss/vo/client/org/DepartmentVO.java b/src/main/java/club/joylink/rtss/vo/client/org/DepartmentVO.java index 919547790..ee5190fed 100644 --- a/src/main/java/club/joylink/rtss/vo/client/org/DepartmentVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/org/DepartmentVO.java @@ -9,10 +9,12 @@ 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.time.LocalDateTime; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -28,7 +30,7 @@ public class DepartmentVO { @NotBlank(message = "部门名称不能为空") private String name; - private String projectCode; + private List projectCodes; @JsonIgnore @@ -58,7 +60,9 @@ public class DepartmentVO { public DepartmentVO(Org entity) { this.id = entity.getId(); this.name = entity.getName(); - this.projectCode = entity.getProjectCode(); + if (StringUtils.hasText(entity.getProjectCode())) { + this.projectCodes = Arrays.asList(entity.getProjectCode().split(",")); + } this.parentId = entity.getParentId(); this.rootId = entity.getRootId(); this.creatorId = entity.getCreatorId(); @@ -93,7 +97,7 @@ public class DepartmentVO { entity.setName(this.name); entity.setParentId(this.parentId); entity.setRootId(this.rootId); - entity.setProjectCode(this.projectCode); + entity.setProjectCode(String.join(",", this.projectCodes)); return entity; } diff --git a/src/main/java/club/joylink/rtss/vo/client/org/OrgScoringResultVO.java b/src/main/java/club/joylink/rtss/vo/client/org/OrgScoringResultVO.java index 10d917df3..2381da09a 100644 --- a/src/main/java/club/joylink/rtss/vo/client/org/OrgScoringResultVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/org/OrgScoringResultVO.java @@ -1,5 +1,6 @@ package club.joylink.rtss.vo.client.org; +import club.joylink.rtss.entity.SysUser; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -23,18 +24,9 @@ public class OrgScoringResultVO { private Integer examScore; - public OrgScoringResultVO(Long userId, String account, String username, Integer attendanceScore, Integer learningTimeScore, Integer examScore) { - this.userId = userId; - this.account = account; - this.username = username; - this.attendanceScore = attendanceScore; - this.learningTimeScore = learningTimeScore; - this.examScore = examScore; - } - - public OrgScoringResultVO(Long userId, String account, String username) { - this.userId = userId; - this.account = account; - this.username = username; + public OrgScoringResultVO(SysUser user) { + this.userId = user.getId(); + this.account = user.getAccount(); + this.username = user.getName(); } } diff --git a/src/main/java/club/joylink/rtss/vo/client/org/OrgUserVO.java b/src/main/java/club/joylink/rtss/vo/client/org/OrgUserVO.java index 496d59f3b..c4fe91ab8 100644 --- a/src/main/java/club/joylink/rtss/vo/client/org/OrgUserVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/org/OrgUserVO.java @@ -48,11 +48,4 @@ public class OrgUserVO { this.orgRole = ou.getRole(); } } - - public String getAccount() { - if (Objects.nonNull(account)) { - return account.substring(0, account.indexOf(OrgService.companyCodePrefix)); - } - return null; - } } diff --git a/src/main/java/club/joylink/rtss/vo/client/org/UserDepartRelVO.java b/src/main/java/club/joylink/rtss/vo/client/org/UserDepartRelVO.java index c6424e859..3c56d6fa8 100644 --- a/src/main/java/club/joylink/rtss/vo/client/org/UserDepartRelVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/org/UserDepartRelVO.java @@ -6,6 +6,8 @@ import lombok.NoArgsConstructor; import lombok.Setter; import org.springframework.util.CollectionUtils; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -15,10 +17,13 @@ import java.util.stream.Collectors; @NoArgsConstructor public class UserDepartRelVO { + @NotNull(message = "用户id不能为null") private Long userId; + @NotNull(message = "组织id不能为null") private Long departmentId; + @NotBlank(message = "组织角色不能为空") private String orgRole; public UserDepartRelVO(Long userId, Long departmentId, String orgRole) { diff --git a/src/main/java/club/joylink/rtss/vo/client/student/ExportStudentInfo.java b/src/main/java/club/joylink/rtss/vo/client/student/ExportStudentInfo.java index 9c4b66fcf..6080539dc 100644 --- a/src/main/java/club/joylink/rtss/vo/client/student/ExportStudentInfo.java +++ b/src/main/java/club/joylink/rtss/vo/client/student/ExportStudentInfo.java @@ -29,12 +29,4 @@ public class ExportStudentInfo { public ExportStudentInfo() { this.scores = new ArrayList<>(); } - - public String getStudentID() { - if(Objects.nonNull(studentID)){ - return studentID.substring(0,studentID.indexOf(OrgService.companyCodePrefix)); - } - return null; - } - } diff --git a/src/main/resources/mybatis/mapper/SysUserDAO.xml b/src/main/resources/mybatis/mapper/SysUserDAO.xml index 2974457b3..a61a1f9e6 100644 --- a/src/main/resources/mybatis/mapper/SysUserDAO.xml +++ b/src/main/resources/mybatis/mapper/SysUserDAO.xml @@ -4,6 +4,7 @@ + @@ -16,7 +17,7 @@ - + @@ -80,8 +81,8 @@ - id, account, `name`, nickname, avatar_path, `password`, mobile, nationcode, email, - wx_id, wx_union_id, wm_open_id, `status`, roles, `offline`, create_time, update_user_id, + id, account, org_id, `name`, nickname, avatar_path, `password`, mobile, nationcode, + email, wx_id, wx_union_id, wm_open_id, `status`, roles, `offline`, create_time, update_user_id, update_time