Merge remote-tracking branch 'origin/test' into test

This commit is contained in:
walker-sheng 2021-04-02 11:18:03 +08:00
commit d90288429d
24 changed files with 560 additions and 414 deletions

View File

@ -0,0 +1,4 @@
alter table sys_user
add org_id bigint null comment '所属组织id' after account;
ALTER TABLE `org` DROP COLUMN `code`;

View File

@ -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<Object> adminQueryOrgTree(@PathVariable Long orgId, @RequestAttribute UserVO user) {
return iOrgService.adminQueryOrgTree(orgId);
}
@Transactional
@ApiOperation("数据处理接口,用后即删")
@PutMapping("/data/data")
public void data() {
OrgUserExample orgUserExample = new OrgUserExample();
orgUserExample.createCriteria().andRoleEqualTo(BusinessConsts.OrgRole.Student.name());
List<OrgUser> ous = orgUserDAO.selectByExample(orgUserExample);
Set<Long> orgIdSet = new HashSet<>();
Map<Long, Set<Long>> userId_orgIdSet_map = new HashMap<>();
ous.forEach(ou -> {
orgIdSet.add(ou.getOrgId());
Set<Long> userOrgIdSet = userId_orgIdSet_map.computeIfAbsent(ou.getUserId(), k -> new HashSet<>());
userOrgIdSet.add(ou.getOrgId());
});
List<Org> orgList = iOrgService.findEntities(new ArrayList<>(orgIdSet), null);
Map<Long, Long> orgId_rootId_map = orgList.stream().collect(Collectors.toMap(Org::getId, Org::getRootId));
Map<Long, Org> topOrgMap = iOrgService.findEntities(new ArrayList<>(orgId_rootId_map.values()), null)
.stream().collect(Collectors.toMap(Org::getId, Function.identity()));
List<SysUser> users = iSysUserService.findEntities(new ArrayList<>(userId_orgIdSet_map.keySet()), null);
Set<Long> nonRootOrgIds = new HashSet<>();
users.forEach(user -> {
Set<Long> 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());
}
}

View File

@ -20,7 +20,7 @@ public interface SysUserDAO extends MyBatisBaseDao<SysUser, Long, SysUserExample
@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
@Insert(value = "<script>" +
" insert into sys_user (account, `name`, nickname, \n" +
" insert into sys_user (account, org_id, `name`, nickname, \n" +
" avatar_path, `password`, mobile, \n" +
" nationcode, email, wx_id, \n" +
" wx_union_id, wm_open_id, `status`, \n" +
@ -28,7 +28,7 @@ public interface SysUserDAO extends MyBatisBaseDao<SysUser, Long, SysUserExample
" update_user_id, update_time)\n" +
" values " +
" <foreach collection=\"list\" item=\"entity\" separator=\",\"> " +
" (#{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" +

View File

@ -30,9 +30,6 @@ public class Org implements Serializable {
*/
private String projectCode;
/**
* 顶级组织code(唯一)
*/
private String code;
/**

View File

@ -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);

View File

@ -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<Long> values) {
addCriterion("org_id in", values, "orgId");
return (Criteria) this;
}
public Criteria andOrgIdNotIn(List<Long> 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;

View File

@ -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);
/**
* 查询所有的销售人员
*/

View File

@ -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,82 @@ 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<SysUser> 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<Org> 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<OrgUser> orgUsers = iOrgUserService.findEntitiesByUserId(userVO.getId(), null);
if (orgUsers.stream().anyMatch(ou -> Objects.equals(ou.getOrgId(), topOrg.getId()))) {
flag = true;
} else {
Set<Long> 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.setOrgInfo(topOrg, iOrgUserService.isTheRoleInThisOrg(userVO.getId(), topOrg.getId(), BusinessConsts.OrgRole.Admin));
}
}
return userVO;
}
@Override
public SysUser findEntity(@NonNull String account, long orgId) {
SysUserExample example = new SysUserExample();
example.createCriteria().andAccountEqualTo(account).andOrgIdEqualTo(orgId);
List<SysUser> 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<UserVO> queryUserByNameOrMobile(String query) {
String format = String.format("%%%s%%", query);
@ -127,7 +174,7 @@ public class SysUserService implements ISysUserService {
SysUserExample example = new SysUserExample();
example.createCriteria().andAccountEqualTo(account);
List<SysUser> 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 +208,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 +222,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<SysUser> mUser = this.sysUserDAO.selectByExample(example);
@ -193,43 +240,52 @@ public class SysUserService implements ISysUserService {
@Override
public PageVO<UserVO> queryPagedUser(UserQueryVO queryVO) {
PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize());
Page<UserVO> page = (Page<UserVO>) 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<SysUser> page = (Page<SysUser>) this.sysUserDAO.selectByExample(example);
// List<UserVO> userVOS = UserVO.convertFromDB(page.getResult());
// List<UserCompanyRel> ucrList = iCompanyService.findUserCompanyRelEntity(userVOS.stream().map(UserVO::getId).collect(Collectors.toList()));
// Map<Long, UserCompanyRel> userIdUcrMap = ucrList.stream().collect(Collectors.toMap(UserCompanyRel::getUserId, Function.identity()));
//
// if (Objects.nonNull(queryVO.getCompanyId())) { //todo这里有问题
//
// }
// return PageVO.convert(page, userVOS);
// Page<UserVO> page = (Page<UserVO>) 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<SysUser> page = (Page<SysUser>) this.sysUserDAO.selectByExample(example);
List<UserVO> userVOS = UserVO.convertFromDB(page.getResult());
List<Long> userIds = userVOS.stream().map(UserVO::getId).collect(Collectors.toList());
Map<Long, Long> userOrgMap = iOrgUserService.findEntitiesByUserIds(userIds, BusinessConsts.OrgRole.Admin)
.stream().collect(Collectors.toMap(OrgUser::getUserId, OrgUser::getOrgId));
Map<Long, Org> 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.setOrgInfo(org, 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);
newUserVO.setRolesByString();
UserVO newUserVO = queryUserInfoWithOrgInfo(id);
this.loginSessionManager.updateLoginUser(newUserVO);
}
}
@ -261,10 +317,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,14 +372,14 @@ 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);
}
@Override
public UserVO getUserBaseInfoById(Long id) {
UserVO userVO = this.sysUserDAO.queryUserWithCompany(id);
UserVO userVO = this.queryUserInfoWithOrgInfo(id);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(userVO, "不存在的用户");
userVO.setRolesByString();
userVO.setWmOpenId(null);
@ -386,10 +439,10 @@ public class SysUserService implements ISysUserService {
SysUserExample example = new SysUserExample();
example.createCriteria().andWxUnionIdEqualTo(unionId);
List<SysUser> list = this.sysUserDAO.selectByExample(example);
if(CollectionUtils.isEmpty(list)) {
if (CollectionUtils.isEmpty(list)) {
return null;
}
UserVO userVO = sysUserDAO.queryUserWithCompany(list.get(0).getId());
UserVO userVO = this.queryUserInfoWithOrgInfo(list.get(0).getId());
userVO.setRolesByString();
return userVO;
}
@ -400,8 +453,8 @@ public class SysUserService implements ISysUserService {
SysUserExample example = new SysUserExample();
example.createCriteria().andWmOpenIdEqualTo(wmOpenId);
List<SysUser> userList = this.sysUserDAO.selectByExample(example);
if(!CollectionUtils.isEmpty(userList)) {
UserVO userVO = sysUserDAO.queryUserWithCompany(userList.get(0).getId());
if (!CollectionUtils.isEmpty(userList)) {
UserVO userVO = queryUserInfoWithOrgInfo(userList.get(0).getId());
userVO.setRolesByString();
return userVO;
}
@ -456,24 +509,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<UserVO> changeUserList) {
if(!CollectionUtils.isEmpty(changeUserList)) {
if (!CollectionUtils.isEmpty(changeUserList)) {
List<SysUser> sysUsers = UserVO.convert2UnionIdInfoVOs(changeUserList);
sysUsers.forEach(sysUser -> this.sysUserDAO.updateByPrimaryKeySelective(sysUser));
}
@ -510,14 +563,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,12 +580,11 @@ 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);
UserVO userVO = sysUserDAO.queryUserWithCompany(id);
userVO.setRolesByString();
UserVO userVO = this.queryUserInfoWithOrgInfo(id);
this.loginSessionManager.updateLoginUser(userVO);
}
}
@ -542,12 +594,11 @@ 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);
UserVO userVO = sysUserDAO.queryUserWithCompany(id);
userVO.setRolesByString();
UserVO userVO = this.queryUserInfoWithOrgInfo(id);
this.loginSessionManager.updateLoginUser(userVO);
}
}
@ -555,12 +606,11 @@ 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);
UserVO userVO = sysUserDAO.queryUserWithCompany(id);
userVO.setRolesByString();
UserVO userVO = queryUserInfoWithOrgInfo(id);
this.loginSessionManager.updateLoginUser(userVO);
}
}
@ -573,13 +623,12 @@ 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());
this.sysUserDAO.updateByPrimaryKey(user);
UserVO userVO = sysUserDAO.queryUserWithCompany(id);
userVO.setRolesByString();
UserVO userVO = this.queryUserInfoWithOrgInfo(id);
this.loginSessionManager.updateLoginUser(userVO);
}
}
@ -592,12 +641,11 @@ 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);
UserVO userVO = sysUserDAO.queryUserWithCompany(id);
userVO.setRolesByString();
UserVO userVO = this.queryUserInfoWithOrgInfo(id);
this.loginSessionManager.updateLoginUser(userVO);
}
}
@ -619,9 +667,9 @@ public class SysUserService implements ISysUserService {
long ts = System.currentTimeMillis();
List<String> 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 +681,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 +697,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 +728,7 @@ public class SysUserService implements ISysUserService {
}
@Override
public List<UserVO> getUsersWithEmail(){
public List<UserVO> getUsersWithEmail() {
SysUserExample example = new SysUserExample();
example.createCriteria().andMobileIsNotNull().andNationcodeIsNotNull().andStatusEqualTo(BusinessConsts.STATUS_USE);
List<SysUser> sysUsers = sysUserDAO.selectByExample(example);
@ -689,7 +737,7 @@ public class SysUserService implements ISysUserService {
}
@Override
public List<UserVO> getUsersWithMobile(){
public List<UserVO> getUsersWithMobile() {
SysUserExample example = new SysUserExample();
example.createCriteria().andEmailIsNotNull().andStatusEqualTo(BusinessConsts.STATUS_USE);
List<SysUser> sysUsers = sysUserDAO.selectByExample(example);
@ -698,7 +746,7 @@ public class SysUserService implements ISysUserService {
}
@Override
public List<UserVO> getPlatformUsers(){
public List<UserVO> getPlatformUsers() {
SysUserExample example = new SysUserExample();
example.createCriteria().andStatusEqualTo(BusinessConsts.STATUS_USE).andOfflineEqualTo(false);
List<SysUser> sysUsers = sysUserDAO.selectByExample(example);
@ -730,12 +778,11 @@ 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);
UserVO newUserVO = sysUserDAO.queryUserWithCompany(userId);
newUserVO.setRolesByString();
UserVO newUserVO = this.queryUserInfoWithOrgInfo(userId);
this.loginSessionManager.updateLoginUser(newUserVO);
}
// //更新所属公司
@ -745,49 +792,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<OrgUser> companyMangers = orgUserDAO.getCompanyManger(userVO.getId());
OrgUserExample oe = new OrgUserExample();
oe.createCriteria().andUserIdEqualTo(userVO.getId());
if (CollectionUtils.isEmpty(companyMangers)) {
List<OrgUser> 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<UserVO> querySellers() {
SysUserExample example = new SysUserExample();
@ -805,7 +809,7 @@ public class SysUserService implements ISysUserService {
@Override
public void deleteById(Long id) {
sysUserDAO.deleteByPrimaryKey(id);
sysUserDAO.deleteByPrimaryKey(id);
}
@Override
@ -824,4 +828,18 @@ public class SysUserService implements ISysUserService {
.andEmailEqualTo(email);
return sysUserDAO.countByExample(example) > 0;
}
/**
* 查询包含组织信息的用户信息
*/
private UserVO queryUserInfoWithOrgInfo(long userId) {
SysUser sysUser = getEntity(userId);
UserVO userVO = new UserVO(sysUser);
List<OrgUser> adminOrgUser = iOrgUserService.findEntitiesByUserId(userId, BusinessConsts.OrgRole.Admin);
if (!CollectionUtils.isEmpty(adminOrgUser)) {
Org org = iOrgService.findEntity(adminOrgUser.get(0).getOrgId());
userVO.setOrgInfo(org, true);
}
return userVO;
}
}

View File

@ -311,7 +311,6 @@ public class UserExamService implements IUserExamService {
List<UserExam> userExams = userExamMapper.selectByExample(example);
Map<Long, Optional<UserExam>> user_exam_map = userExams.stream().collect(Collectors.groupingBy(UserExam::getUserId, Collectors.maxBy(Comparator.comparingDouble(UserExam::getScore))));
List<SysUser> users = iSysUserService.findEntities(studentIds, "account");
Org topOrg = iOrgService.getTopOrgEntity(orgId, null);
List<UserExamVO> vos = users.stream().map(user -> {
UserExamVO vo;
Optional<UserExam> 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());

View File

@ -27,7 +27,9 @@ public interface IOrgService {
void createCls(NonTopOrgCreateVO createVO, LoginUserInfoVO loginInfo);
Org getEntity(Long orgId);
Org getEntity(long orgId);
Org findEntity(long orgId);
Org getEntity(Project project, String status);
@ -71,4 +73,8 @@ public interface IOrgService {
* 查询这些考试关联的班级
*/
List<ExamDefinitionVO> queryByExamIds(List<Long> examIds, String status);
void confirmIsTopOrg(long id);
void confirmIsNonTopOrg(Long id);
}

View File

@ -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<OrgUser> findEntitiesByOrgId(Long orgId, BusinessConsts.OrgRole role);
List<OrgUser> findEntitiesByOrgId(long orgId, BusinessConsts.OrgRole role);
List<OrgUser> findEntities(List<Long> orgIds, BusinessConsts.OrgRole role);
List<OrgUser> findEntitiesByOrgIds(List<Long> orgIds, BusinessConsts.OrgRole role);
List<OrgUser> findEntities(Long userId, BusinessConsts.OrgRole role);
List<OrgUser> findEntitiesByUserIds(List<Long> userIds, BusinessConsts.OrgRole role);
List<OrgUser> findEntitiesByUserId(long userId, BusinessConsts.OrgRole role);
void userBindCompanyManager(UserVO userVO, Long topOrgId);
}

View File

@ -293,17 +293,14 @@ public class OrgScoringRuleService implements IOrgScoringRuleService {
// TODO: 2021/3/24 评价结果保存确认流程
List<OrgUser> 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<Long> userIds = students.stream().map(OrgUser::getUserId).collect(Collectors.toList());
List<SysUser> users = iSysUserService.findEntities(userIds, "id");
Org topOrg = iOrgService.getTopOrgEntity(orgScoringRuleVO.getOrgIds().get(0), BusinessConsts.Org.Status.VALID);
List<OrgScoringResultVO> 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<OrgScoringResultVO> results = users.stream().map(OrgScoringResultVO::new).collect(Collectors.toList());
List<String> projects = List.of(topOrg.getProjectCode().split(","));
this.score(results, orgScoringRuleVO.getScoringRules(), projects);
return results;

View File

@ -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,16 +101,21 @@ 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
public Org getEntity(Long orgId) {
public Org getEntity(long orgId) {
Org org = orgDAO.selectByPrimaryKey(orgId);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(org, String.format("id为[%s]的组织不存在", orgId));
return org;
}
@Override
public Org findEntity(long orgId) {
return orgDAO.selectByPrimaryKey(orgId);
}
@Override
public Org getEntity(Project project, String status) {
Org org = findEntity(project, status);
@ -132,7 +126,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 +142,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 +251,6 @@ public class OrgService implements IOrgService {
Org org = getEntity(orgId);
Map<Long, List<Org>> groupByParentIdOrg = findEntitiesByRootId(org.getRootId(), null, BusinessConsts.Org.Status.VALID)
.stream().filter(o -> o.getParentId() != null).collect(Collectors.groupingBy(Org::getParentId));
List<Long> orgIds = new ArrayList<>(); //要展示的组织
orgIds.add(orgId);
Node<Object> root = new Node<>(new DepartmentVO(org), Node.Type.ORG);
Map<Long, Node<Object>> all_orgId_node_map = new HashMap<>(); //所有的组织和对应的节点
Map<Long, Node<Object>> orgId_node_map = new HashMap<>();
@ -270,7 +262,6 @@ public class OrgService implements IOrgService {
List<Org> childOrgList = groupByParentIdOrg.get(k);
if (!CollectionUtils.isEmpty(childOrgList)) {
List<Node<Object>> children = childOrgList.stream().map(o -> {
orgIds.add(o.getId());
Node<Object> node = new Node<>(new DepartmentVO(o), Node.Type.ORG);
newMap.put(o.getId(), node);
return node;
@ -281,21 +272,23 @@ public class OrgService implements IOrgService {
orgId_node_map = newMap;
}
/* 再查询用户 */
List<OrgUser> orgUsers = iOrgUserService.findEntities(orgIds, null);
List<OrgUser> orgUsers = iOrgUserService.findEntitiesByOrgIds(new ArrayList<>(all_orgId_node_map.keySet()), null);
Map<Long, List<OrgUser>> groupByOrgIdOrgUsers = orgUsers.stream().collect(Collectors.groupingBy(OrgUser::getOrgId));
List<Long> userIds = orgUsers.stream().map(OrgUser::getUserId).collect(Collectors.toList());
Map<Long, SysUser> userMap = iSysUserService.findEntities(userIds, null)
.stream().collect(Collectors.toMap(SysUser::getId, Function.identity()));
all_orgId_node_map.forEach((k,v)->{
List<OrgUser> ous = groupByOrgIdOrgUsers.get(k);
List<Node<Object>> children = ous.stream().map(ou -> {
OrgUserVO vo = new OrgUserVO(ou, userMap.get(ou.getUserId()));
return new Node<Object>(vo, Node.Type.USER);
}).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(v.getChildren())) {
children.addAll(v.getChildren());
if (!CollectionUtils.isEmpty(ous)) {
List<Node<Object>> children = ous.stream().map(ou -> {
OrgUserVO vo = new OrgUserVO(ou, userMap.get(ou.getUserId()));
return new Node<Object>(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 +307,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 +350,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<Org> findEntitiesByRootId(Long rootId, String orderBy, String status) {
OrgExample example = new OrgExample();
if (StringUtils.hasText(orderBy)) {
@ -379,16 +373,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<Org> orgs = orgDAO.selectByExample(e);
if (CollectionUtils.isEmpty(orgs)) {
return companyCodePrefix + "001";
/**
* 确认这些项目没有被关联到其它的组织
*/
private void confirmProjectCodesNotRepeat(Long orgId, List<String> 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,
"部分所选项目已与其它组织关联");
}
}

View File

@ -24,10 +24,7 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
@Service
@ -220,10 +217,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 +253,6 @@ public class OrgUserService implements IOrgUserService {
confirmIsTheRoleInThisOrg(user.getId(), clsId, BusinessConsts.OrgRole.Teacher);
Set<Long> 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<Org> 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<Org> 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<SysUser> 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<OrgUser> orgUsers = orgUserDAO.selectByExample(e);
// BusinessExceptionAssertEnum.INVALID_OPERATION.assertCollectionNotEmpty(orgUsers, sysUser.getAccount() + "账号重复");
// OrgExample oe = new OrgExample();
// oe.createCriteria().andRootIdEqualTo(companyId);
// List<Integer> 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<Long> 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<OrgUser> orgUsers = orgUserDAO.selectByExample(e);
// BusinessExceptionAssertEnum.INVALID_OPERATION.assertCollectionNotEmpty(orgUsers, sysUser.getAccount() + "账号已存在且不属于任何组织");
// Set<Integer> 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 +283,6 @@ public class OrgUserService implements IOrgUserService {
confirmIsTheRoleInThisOrg(user.getId(), clsId, BusinessConsts.OrgRole.Teacher);
Org topOrg = iOrgService.getEntity(cls.getRootId());
Set<Long> 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 +299,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 +321,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 +332,7 @@ public class OrgUserService implements IOrgUserService {
}
@Override
public List<OrgUser> findEntitiesByOrgId(Long orgId, BusinessConsts.OrgRole role) {
public List<OrgUser> findEntitiesByOrgId(long orgId, BusinessConsts.OrgRole role) {
OrgUserExample example = new OrgUserExample();
OrgUserExample.Criteria criteria = example.createCriteria().andOrgIdEqualTo(orgId);
if (role != null) {
@ -450,7 +342,7 @@ public class OrgUserService implements IOrgUserService {
}
@Override
public List<OrgUser> findEntities(List<Long> orgIds, BusinessConsts.OrgRole role) {
public List<OrgUser> findEntitiesByOrgIds(List<Long> orgIds, BusinessConsts.OrgRole role) {
if (CollectionUtils.isEmpty(orgIds)) {
return new ArrayList<>();
} else {
@ -464,7 +356,21 @@ public class OrgUserService implements IOrgUserService {
}
@Override
public List<OrgUser> findEntities(@NonNull Long userId, BusinessConsts.OrgRole role) {
public List<OrgUser> findEntitiesByUserIds(List<Long> 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<OrgUser> findEntitiesByUserId(long userId, BusinessConsts.OrgRole role) {
OrgUserExample example = new OrgUserExample();
OrgUserExample.Criteria criteria = example.createCriteria().andUserIdEqualTo(userId);
if (role != null) {
@ -473,4 +379,47 @@ 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<OrgUser> orgUsers = findEntitiesByUserId(userVO.getId(), BusinessConsts.OrgRole.Admin);
List<Long> 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.setOrgInfo(topOrg, true);
}
/**
* 导入组织用户
*
* @param topOrg 导入的组织所属的顶级组织
* @param orgId 要导入的组织
* @param orgUserIdSet 导入的组织当前已有的成员
*/
private void importOrgUser(Org topOrg, Long orgId, Set<Long> 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);
}
}
}
}

View File

@ -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<UserPermissionVO> ups = iUserPermissionService.getSimulationUserPermission(userVO, mapId, prdType);
if (!CollectionUtils.isEmpty(ups)) {

View File

@ -21,6 +21,8 @@ public class UserQueryVO extends PageQueryVO {
@ApiModelProperty(value = "真实姓名")
private String name;
private String email;
/**
* 昵称
*/

View File

@ -1,6 +1,7 @@
package club.joylink.rtss.vo;
import club.joylink.rtss.constants.BusinessConsts;
import club.joylink.rtss.entity.Org;
import club.joylink.rtss.entity.SysUser;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
@ -17,6 +18,7 @@ import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@ -34,6 +36,11 @@ public class UserVO implements Serializable {
*/
private String account;
/**
* 用户所属的顶级组织
*/
private Long orgId;
/**
* 真实姓名
*/
@ -114,7 +121,7 @@ public class UserVO implements Serializable {
/**
* 用户所属组织关联的项目
*/
private String projectCode;
private List<String> projectCodes;
public UserVO() {}
@ -122,6 +129,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();
@ -268,4 +276,13 @@ public class UserVO implements Serializable {
this.roles = List.of(dbRoles.split(","));
}
}
public void setOrgInfo(Org org, Boolean companyAdmin) {
this.companyId = org.getId();
this.companyName = org.getName();
this.companyAdmin = companyAdmin;
if (StringUtils.hasText(org.getProjectCode())) {
this.projectCodes = Arrays.asList(org.getProjectCode().split(","));
}
}
}

View File

@ -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<String> 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<CompanyVO> convert2VOList(List<Org> 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;
}
}
}

View File

@ -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<String> 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;
}

View File

@ -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();
}
}

View File

@ -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;
}
}

View File

@ -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) {

View File

@ -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;
}
}

View File

@ -4,6 +4,7 @@
<resultMap id="BaseResultMap" type="club.joylink.rtss.entity.SysUser">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="account" jdbcType="VARCHAR" property="account" />
<result column="org_id" jdbcType="BIGINT" property="orgId" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="nickname" jdbcType="VARCHAR" property="nickname" />
<result column="avatar_path" jdbcType="VARCHAR" property="avatarPath" />
@ -16,7 +17,7 @@
<result column="wm_open_id" jdbcType="VARCHAR" property="wmOpenId" />
<result column="status" jdbcType="VARCHAR" property="status" />
<result column="roles" jdbcType="VARCHAR" property="roles" />
<result column="offline" jdbcType="BIT" property="offline" />
<result column="offline" jdbcType="TINYINT" property="offline" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_user_id" jdbcType="BIGINT" property="updateUserId" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
@ -80,8 +81,8 @@
</where>
</sql>
<sql id="Base_Column_List">
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
</sql>
<select id="selectByExample" parameterType="club.joylink.rtss.entity.SysUserExample" resultMap="BaseResultMap">
@ -123,18 +124,20 @@
</if>
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="club.joylink.rtss.entity.SysUser" useGeneratedKeys="true">
insert into sys_user (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, update_time)
values (#{account,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{nickname,jdbcType=VARCHAR},
#{avatarPath,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{mobile,jdbcType=VARCHAR},
#{nationcode,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{wxId,jdbcType=VARCHAR},
#{wxUnionId,jdbcType=VARCHAR}, #{wmOpenId,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR},
#{roles,jdbcType=VARCHAR}, #{offline,jdbcType=BIT}, #{createTime,jdbcType=TIMESTAMP},
#{updateUserId,jdbcType=BIGINT}, #{updateTime,jdbcType=TIMESTAMP})
insert into sys_user (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
)
values (#{account,jdbcType=VARCHAR}, #{orgId,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR},
#{nickname,jdbcType=VARCHAR}, #{avatarPath,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},
#{mobile,jdbcType=VARCHAR}, #{nationcode,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR},
#{wxId,jdbcType=VARCHAR}, #{wxUnionId,jdbcType=VARCHAR}, #{wmOpenId,jdbcType=VARCHAR},
#{status,jdbcType=VARCHAR}, #{roles,jdbcType=VARCHAR}, #{offline,jdbcType=TINYINT},
#{createTime,jdbcType=TIMESTAMP}, #{updateUserId,jdbcType=BIGINT}, #{updateTime,jdbcType=TIMESTAMP}
)
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="club.joylink.rtss.entity.SysUser" useGeneratedKeys="true">
insert into sys_user
@ -142,6 +145,9 @@
<if test="account != null">
account,
</if>
<if test="orgId != null">
org_id,
</if>
<if test="name != null">
`name`,
</if>
@ -195,6 +201,9 @@
<if test="account != null">
#{account,jdbcType=VARCHAR},
</if>
<if test="orgId != null">
#{orgId,jdbcType=BIGINT},
</if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
@ -232,7 +241,7 @@
#{roles,jdbcType=VARCHAR},
</if>
<if test="offline != null">
#{offline,jdbcType=BIT},
#{offline,jdbcType=TINYINT},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
@ -260,6 +269,9 @@
<if test="record.account != null">
account = #{record.account,jdbcType=VARCHAR},
</if>
<if test="record.orgId != null">
org_id = #{record.orgId,jdbcType=BIGINT},
</if>
<if test="record.name != null">
`name` = #{record.name,jdbcType=VARCHAR},
</if>
@ -297,7 +309,7 @@
roles = #{record.roles,jdbcType=VARCHAR},
</if>
<if test="record.offline != null">
`offline` = #{record.offline,jdbcType=BIT},
`offline` = #{record.offline,jdbcType=TINYINT},
</if>
<if test="record.createTime != null">
create_time = #{record.createTime,jdbcType=TIMESTAMP},
@ -317,6 +329,7 @@
update sys_user
set id = #{record.id,jdbcType=BIGINT},
account = #{record.account,jdbcType=VARCHAR},
org_id = #{record.orgId,jdbcType=BIGINT},
`name` = #{record.name,jdbcType=VARCHAR},
nickname = #{record.nickname,jdbcType=VARCHAR},
avatar_path = #{record.avatarPath,jdbcType=VARCHAR},
@ -329,7 +342,7 @@
wm_open_id = #{record.wmOpenId,jdbcType=VARCHAR},
`status` = #{record.status,jdbcType=VARCHAR},
roles = #{record.roles,jdbcType=VARCHAR},
`offline` = #{record.offline,jdbcType=BIT},
`offline` = #{record.offline,jdbcType=TINYINT},
create_time = #{record.createTime,jdbcType=TIMESTAMP},
update_user_id = #{record.updateUserId,jdbcType=BIGINT},
update_time = #{record.updateTime,jdbcType=TIMESTAMP}
@ -343,6 +356,9 @@
<if test="account != null">
account = #{account,jdbcType=VARCHAR},
</if>
<if test="orgId != null">
org_id = #{orgId,jdbcType=BIGINT},
</if>
<if test="name != null">
`name` = #{name,jdbcType=VARCHAR},
</if>
@ -380,7 +396,7 @@
roles = #{roles,jdbcType=VARCHAR},
</if>
<if test="offline != null">
`offline` = #{offline,jdbcType=BIT},
`offline` = #{offline,jdbcType=TINYINT},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
@ -397,6 +413,7 @@
<update id="updateByPrimaryKey" parameterType="club.joylink.rtss.entity.SysUser">
update sys_user
set account = #{account,jdbcType=VARCHAR},
org_id = #{orgId,jdbcType=BIGINT},
`name` = #{name,jdbcType=VARCHAR},
nickname = #{nickname,jdbcType=VARCHAR},
avatar_path = #{avatarPath,jdbcType=VARCHAR},
@ -409,7 +426,7 @@
wm_open_id = #{wmOpenId,jdbcType=VARCHAR},
`status` = #{status,jdbcType=VARCHAR},
roles = #{roles,jdbcType=VARCHAR},
`offline` = #{offline,jdbcType=BIT},
`offline` = #{offline,jdbcType=TINYINT},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_user_id = #{updateUserId,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=TIMESTAMP}