|
@@ -1,41 +1,5 @@
|
|
package cn.com.qmth.examcloud.core.basic.api.controller;
|
|
package cn.com.qmth.examcloud.core.basic.api.controller;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Date;
|
|
|
|
-import java.util.Iterator;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
-import java.util.stream.Stream;
|
|
|
|
-
|
|
|
|
-import javax.persistence.criteria.Predicate;
|
|
|
|
-import javax.persistence.criteria.Root;
|
|
|
|
-import javax.persistence.criteria.Subquery;
|
|
|
|
-
|
|
|
|
-import org.apache.commons.collections.CollectionUtils;
|
|
|
|
-import org.apache.commons.lang.StringEscapeUtils;
|
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
-import org.springframework.data.domain.Page;
|
|
|
|
-import org.springframework.data.domain.PageRequest;
|
|
|
|
-import org.springframework.data.domain.Pageable;
|
|
|
|
-import org.springframework.data.domain.Sort;
|
|
|
|
-import org.springframework.data.domain.Sort.Direction;
|
|
|
|
-import org.springframework.data.jpa.domain.Specification;
|
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
-import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.PutMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
|
-
|
|
|
|
-import com.google.common.collect.Lists;
|
|
|
|
-import com.google.common.collect.Maps;
|
|
|
|
-
|
|
|
|
import cn.com.qmth.examcloud.api.commons.exchange.PageInfo;
|
|
import cn.com.qmth.examcloud.api.commons.exchange.PageInfo;
|
|
import cn.com.qmth.examcloud.api.commons.security.bean.User;
|
|
import cn.com.qmth.examcloud.api.commons.security.bean.User;
|
|
import cn.com.qmth.examcloud.api.commons.security.enums.RoleMeta;
|
|
import cn.com.qmth.examcloud.api.commons.security.enums.RoleMeta;
|
|
@@ -54,658 +18,684 @@ import cn.com.qmth.examcloud.core.basic.dao.entity.UserRoleRelationEntity;
|
|
import cn.com.qmth.examcloud.core.basic.service.UserService;
|
|
import cn.com.qmth.examcloud.core.basic.service.UserService;
|
|
import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
|
+import com.google.common.collect.Maps;
|
|
|
|
+import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
|
+import org.apache.commons.lang.StringEscapeUtils;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
|
+import org.springframework.data.domain.Sort.Direction;
|
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
+
|
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
|
+import javax.persistence.criteria.Root;
|
|
|
|
+import javax.persistence.criteria.Subquery;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 用户服务API Created by songyue on 17/1/13.
|
|
* 用户服务API Created by songyue on 17/1/13.
|
|
*/
|
|
*/
|
|
@RestController
|
|
@RestController
|
|
|
|
+@Api(tags = "用户相关接口")
|
|
@RequestMapping("${$rmp.ctr.basic}/user")
|
|
@RequestMapping("${$rmp.ctr.basic}/user")
|
|
public class UserController extends ControllerSupport {
|
|
public class UserController extends ControllerSupport {
|
|
|
|
|
|
- @Autowired
|
|
|
|
- UserService userService;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- UserRepo userRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- OrgRepo orgRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- RoleRepo roleRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- UserRoleRelationRepo userRoleRelationRepo;
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 方法注释
|
|
|
|
- *
|
|
|
|
- * @author WANGWEI
|
|
|
|
- * @param curPage
|
|
|
|
- * @param pageSize
|
|
|
|
- * @param rootOrgId
|
|
|
|
- * @param loginName
|
|
|
|
- * @param name
|
|
|
|
- * @param enable
|
|
|
|
- * @param roleId
|
|
|
|
- * @param roleCode
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- @ApiOperation(value = "查询所有用户", notes = "")
|
|
|
|
- @GetMapping("all/{curPage}/{pageSize}")
|
|
|
|
- public PageInfo<UserDomain> getUserPage(@PathVariable Integer curPage,
|
|
|
|
- @PathVariable Integer pageSize, @RequestParam(required = false) Long rootOrgId,
|
|
|
|
- @RequestParam String loginName, @RequestParam String name,
|
|
|
|
- @RequestParam(required = false) Boolean enable,
|
|
|
|
- @RequestParam(required = false) Long roleId, @RequestParam(required = false) Long orgId,
|
|
|
|
- @RequestParam(required = false) String roleCode) {
|
|
|
|
-
|
|
|
|
- User accessUser = getAccessUser();
|
|
|
|
-
|
|
|
|
- if (null == rootOrgId) {
|
|
|
|
- rootOrgId = accessUser.getRootOrgId();
|
|
|
|
- } else {
|
|
|
|
- validateRootOrgIsolation(rootOrgId);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- final Long finalRootOrgId = rootOrgId;
|
|
|
|
-
|
|
|
|
- OrgEntity rootOrg = GlobalHelper.getEntity(orgRepo, rootOrgId, OrgEntity.class);
|
|
|
|
- if (null == rootOrg) {
|
|
|
|
- throw new StatusException("150003", "机构不存在");
|
|
|
|
- }
|
|
|
|
- if (null != rootOrg.getParentId()) {
|
|
|
|
- throw new StatusException("150004", "机构错误");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (null != roleId) {
|
|
|
|
- RoleEntity roleEntity = GlobalHelper.getEntity(roleRepo, roleId, RoleEntity.class);
|
|
|
|
- if (null == roleEntity) {
|
|
|
|
- throw new StatusException("150002", "角色不存在");
|
|
|
|
- }
|
|
|
|
- } else if (StringUtils.isNotBlank(roleCode)) {
|
|
|
|
- RoleEntity roleEntity = roleRepo.findByCodeAndRootOrgIdIsNull(roleCode.trim());
|
|
|
|
- if (null == roleEntity) {
|
|
|
|
- roleEntity = roleRepo.findByCodeAndRootOrgId(roleCode.trim(),
|
|
|
|
- accessUser.getRootOrgId());
|
|
|
|
- }
|
|
|
|
- if (null == roleEntity) {
|
|
|
|
- throw new StatusException("150002", "角色不存在");
|
|
|
|
- }
|
|
|
|
- roleId = roleEntity.getId();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- final Long finalRoleId = roleId;
|
|
|
|
-
|
|
|
|
- Specification<UserEntity> specification = (root, query, cb) -> {
|
|
|
|
- List<Predicate> predicates = new ArrayList<>();
|
|
|
|
- predicates.add(cb.equal(root.get("rootOrgId"), finalRootOrgId));
|
|
|
|
-
|
|
|
|
- if (StringUtils.isNotBlank(loginName)) {
|
|
|
|
- predicates.add(cb.like(root.get("loginName"), toSqlSearchPattern(loginName)));
|
|
|
|
- }
|
|
|
|
- if (StringUtils.isNotBlank(name)) {
|
|
|
|
- predicates.add(cb.like(root.get("name"), toSqlSearchPattern(name)));
|
|
|
|
- }
|
|
|
|
- if (null != orgId) {
|
|
|
|
- predicates.add(cb.equal(root.get("orgId"), orgId));
|
|
|
|
- }
|
|
|
|
- if (null != enable) {
|
|
|
|
- predicates.add(cb.equal(root.get("enable"), enable));
|
|
|
|
- }
|
|
|
|
- if (null != finalRoleId) {
|
|
|
|
- Subquery<UserRoleRelationEntity> subquery = query
|
|
|
|
- .subquery(UserRoleRelationEntity.class);
|
|
|
|
- Root<UserRoleRelationEntity> subRoot = subquery.from(UserRoleRelationEntity.class);
|
|
|
|
- subquery.select(subRoot.get("userId"));
|
|
|
|
- Predicate p1 = cb.equal(subRoot.get("roleId"), finalRoleId);
|
|
|
|
- Predicate p2 = cb.equal(subRoot.get("userId"), root.get("id"));
|
|
|
|
- subquery.where(cb.and(p1, p2));
|
|
|
|
- predicates.add(cb.exists(subquery));
|
|
|
|
- }
|
|
|
|
- return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
|
- };
|
|
|
|
- Pageable pageable = PageRequest.of(curPage - 1, pageSize, Sort.Direction.DESC, "updateTime",
|
|
|
|
- "id");
|
|
|
|
-
|
|
|
|
- Page<UserEntity> userList = userRepo.findAll(specification, pageable);
|
|
|
|
-
|
|
|
|
- Iterator<UserEntity> iterator = userList.iterator();
|
|
|
|
-
|
|
|
|
- List<UserDomain> fullUserInfoList = Lists.newArrayList();
|
|
|
|
- while (iterator.hasNext()) {
|
|
|
|
- UserEntity next = iterator.next();
|
|
|
|
- UserDomain bean = new UserDomain();
|
|
|
|
- bean.setId(next.getId());
|
|
|
|
- bean.setLoginName(next.getLoginName());
|
|
|
|
- bean.setName(next.getName());
|
|
|
|
- bean.setRootOrgId(next.getRootOrgId());
|
|
|
|
- bean.setUpdateTime(next.getUpdateTime());
|
|
|
|
- bean.setCreationTime(next.getCreationTime());
|
|
|
|
- bean.setOrgId(next.getOrgId());
|
|
|
|
- bean.setPhoneNumber(next.getPhoneNumber());
|
|
|
|
- if (null != bean.getOrgId()) {
|
|
|
|
- OrgEntity org = GlobalHelper.getEntity(orgRepo, Long.valueOf(bean.getOrgId()),
|
|
|
|
- OrgEntity.class);
|
|
|
|
- if (null != org) {
|
|
|
|
- bean.setOrgName(org.getName());
|
|
|
|
- bean.setOrgCode(org.getCode());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- bean.setRootOrgName(rootOrg.getName());
|
|
|
|
- bean.setEnable(next.getEnable());
|
|
|
|
-
|
|
|
|
- List<UserRoleRelationEntity> relationList = userRoleRelationRepo
|
|
|
|
- .findAllByUserId(next.getId());
|
|
|
|
- List<String> roleNameList = Lists.newArrayList();
|
|
|
|
- List<Long> roleIdList = Lists.newArrayList();
|
|
|
|
- List<String> roleCodeList = Lists.newArrayList();
|
|
|
|
- for (UserRoleRelationEntity cur : relationList) {
|
|
|
|
- RoleEntity curRoleEntity = GlobalHelper.getEntity(roleRepo, cur.getRoleId(),
|
|
|
|
- RoleEntity.class);
|
|
|
|
- if (null == curRoleEntity) {
|
|
|
|
- throw new StatusException("150002", "角色错误");
|
|
|
|
- }
|
|
|
|
- roleNameList.add(curRoleEntity.getName());
|
|
|
|
- roleIdList.add(curRoleEntity.getId());
|
|
|
|
- roleCodeList.add(curRoleEntity.getCode());
|
|
|
|
- }
|
|
|
|
- bean.setRoleNamesStr(StringUtils.join(roleNameList, ","));
|
|
|
|
- bean.setRoleIds(roleIdList);
|
|
|
|
- bean.setRoleCodes(roleCodeList);
|
|
|
|
-
|
|
|
|
- fullUserInfoList.add(bean);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- PageInfo<UserDomain> ret = new PageInfo<UserDomain>();
|
|
|
|
- ret.setList(fullUserInfoList);
|
|
|
|
- ret.setTotal(userList.getTotalElements());
|
|
|
|
- return ret;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @ApiOperation(value = "模糊查询用户", notes = "")
|
|
|
|
- @GetMapping("query")
|
|
|
|
- public List<UserDomain> query(@RequestParam(required = false) Long rootOrgId,
|
|
|
|
- @RequestParam(required = false) String rootOrgCode,
|
|
|
|
- @RequestParam(required = false) String loginName,
|
|
|
|
- @RequestParam(required = false) String name,
|
|
|
|
- @RequestParam(required = false) Boolean enable,
|
|
|
|
- @RequestParam(required = false) Long roleId, @RequestParam(required = false) Long orgId,
|
|
|
|
- @RequestParam(required = false) String roleCode) {
|
|
|
|
-
|
|
|
|
- OrgEntity rootOrg = null;
|
|
|
|
-
|
|
|
|
- if (null != rootOrgId) {
|
|
|
|
- rootOrg = GlobalHelper.getEntity(orgRepo, rootOrgId, OrgEntity.class);
|
|
|
|
- if (null == rootOrg) {
|
|
|
|
- throw new StatusException("150003", "机构不存在");
|
|
|
|
- }
|
|
|
|
- } else if (StringUtils.isNotBlank(rootOrgCode)) {
|
|
|
|
- rootOrg = orgRepo.findByParentIdIsNullAndCode(rootOrgCode);
|
|
|
|
- if (null == rootOrg) {
|
|
|
|
- throw new StatusException("150003", "机构不存在");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (null != rootOrg) {
|
|
|
|
- if (null != rootOrg.getParentId()) {
|
|
|
|
- throw new StatusException("150004", "机构错误");
|
|
|
|
- }
|
|
|
|
- rootOrgId = rootOrg.getId();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- final Long finalRootOrgId = rootOrgId;
|
|
|
|
-
|
|
|
|
- if (null != roleId) {
|
|
|
|
- RoleEntity roleEntity = GlobalHelper.getEntity(roleRepo, roleId, RoleEntity.class);
|
|
|
|
- if (null == roleEntity) {
|
|
|
|
- throw new StatusException("150002", "角色不存在");
|
|
|
|
- }
|
|
|
|
- } else if (StringUtils.isNotBlank(roleCode)) {
|
|
|
|
- RoleEntity roleEntity = roleRepo.findByCodeAndRootOrgIdIsNull(roleCode.trim());
|
|
|
|
- if (null == roleEntity) {
|
|
|
|
- roleEntity = roleRepo.findByCodeAndRootOrgId(roleCode.trim(), rootOrgId);
|
|
|
|
- }
|
|
|
|
- if (null == roleEntity) {
|
|
|
|
- throw new StatusException("150002", "角色不存在");
|
|
|
|
- }
|
|
|
|
- roleId = roleEntity.getId();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- final Long finalRoleId = roleId;
|
|
|
|
-
|
|
|
|
- Specification<UserEntity> specification = (root, query, cb) -> {
|
|
|
|
- List<Predicate> predicates = new ArrayList<>();
|
|
|
|
-
|
|
|
|
- if (null != finalRootOrgId) {
|
|
|
|
- predicates.add(cb.equal(root.get("rootOrgId"), finalRootOrgId));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (StringUtils.isNotBlank(loginName)) {
|
|
|
|
- predicates.add(cb.like(root.get("loginName"), toSqlSearchPattern(loginName)));
|
|
|
|
- }
|
|
|
|
- if (StringUtils.isNotBlank(name)) {
|
|
|
|
- predicates.add(cb.like(root.get("name"), toSqlSearchPattern(name)));
|
|
|
|
- }
|
|
|
|
- if (null != orgId) {
|
|
|
|
- predicates.add(cb.equal(root.get("orgId"), orgId));
|
|
|
|
- }
|
|
|
|
- if (null != enable) {
|
|
|
|
- predicates.add(cb.equal(root.get("enable"), enable));
|
|
|
|
- }
|
|
|
|
- if (null != finalRoleId) {
|
|
|
|
- Subquery<UserRoleRelationEntity> subquery = query
|
|
|
|
- .subquery(UserRoleRelationEntity.class);
|
|
|
|
- Root<UserRoleRelationEntity> subRoot = subquery.from(UserRoleRelationEntity.class);
|
|
|
|
- subquery.select(subRoot.get("userId"));
|
|
|
|
- Predicate p1 = cb.equal(subRoot.get("roleId"), finalRoleId);
|
|
|
|
- Predicate p2 = cb.equal(subRoot.get("userId"), root.get("id"));
|
|
|
|
- subquery.where(cb.and(p1, p2));
|
|
|
|
- predicates.add(cb.exists(subquery));
|
|
|
|
- }
|
|
|
|
- return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- PageRequest pageRequest = PageRequest.of(0, 50, new Sort(Direction.DESC, "updateTime"));
|
|
|
|
-
|
|
|
|
- Page<UserEntity> userList = userRepo.findAll(specification, pageRequest);
|
|
|
|
-
|
|
|
|
- Iterator<UserEntity> iterator = userList.iterator();
|
|
|
|
-
|
|
|
|
- List<UserDomain> fullUserInfoList = Lists.newArrayList();
|
|
|
|
- while (iterator.hasNext()) {
|
|
|
|
- UserEntity next = iterator.next();
|
|
|
|
- UserDomain bean = new UserDomain();
|
|
|
|
- bean.setId(next.getId());
|
|
|
|
- bean.setLoginName(next.getLoginName());
|
|
|
|
- bean.setName(next.getName());
|
|
|
|
- bean.setRootOrgId(next.getRootOrgId());
|
|
|
|
- bean.setUpdateTime(next.getUpdateTime());
|
|
|
|
- bean.setCreationTime(next.getCreationTime());
|
|
|
|
- bean.setOrgId(next.getOrgId());
|
|
|
|
- if (null != bean.getOrgId()) {
|
|
|
|
- OrgEntity org = GlobalHelper.getEntity(orgRepo, Long.valueOf(bean.getOrgId()),
|
|
|
|
- OrgEntity.class);
|
|
|
|
- if (null != org) {
|
|
|
|
- bean.setOrgName(org.getName());
|
|
|
|
- bean.setOrgCode(org.getCode());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- bean.setRootOrgName(rootOrg.getName());
|
|
|
|
- bean.setEnable(next.getEnable());
|
|
|
|
-
|
|
|
|
- List<UserRoleRelationEntity> relationList = userRoleRelationRepo
|
|
|
|
- .findAllByUserId(next.getId());
|
|
|
|
- List<String> roleNameList = Lists.newArrayList();
|
|
|
|
- List<Long> roleIdList = Lists.newArrayList();
|
|
|
|
- List<String> roleCodeList = Lists.newArrayList();
|
|
|
|
- for (UserRoleRelationEntity cur : relationList) {
|
|
|
|
- RoleEntity curRoleEntity = GlobalHelper.getEntity(roleRepo, cur.getRoleId(),
|
|
|
|
- RoleEntity.class);
|
|
|
|
- if (null == curRoleEntity) {
|
|
|
|
- throw new StatusException("150002", "角色错误");
|
|
|
|
- }
|
|
|
|
- roleNameList.add(curRoleEntity.getName());
|
|
|
|
- roleIdList.add(curRoleEntity.getId());
|
|
|
|
- roleCodeList.add(curRoleEntity.getCode());
|
|
|
|
- }
|
|
|
|
- bean.setRoleNamesStr(StringUtils.join(roleNameList, ","));
|
|
|
|
- bean.setRoleIds(roleIdList);
|
|
|
|
- bean.setRoleCodes(roleCodeList);
|
|
|
|
-
|
|
|
|
- fullUserInfoList.add(bean);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return fullUserInfoList;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 方法注释
|
|
|
|
- *
|
|
|
|
- * @author WANGWEI
|
|
|
|
- * @param id
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- @ApiOperation(value = "查询登陆用户", notes = "")
|
|
|
|
- @GetMapping("getUserBySession")
|
|
|
|
- public UserDomain getUserBySession() {
|
|
|
|
- User accessUser = getAccessUser();
|
|
|
|
- UserEntity userEntity = GlobalHelper.getEntity(userRepo, accessUser.getUserId(),
|
|
|
|
- UserEntity.class);
|
|
|
|
-
|
|
|
|
- UserDomain bean = new UserDomain();
|
|
|
|
- bean.setId(userEntity.getId());
|
|
|
|
- bean.setLoginName(userEntity.getLoginName());
|
|
|
|
- bean.setName(userEntity.getName());
|
|
|
|
- bean.setRootOrgId(userEntity.getRootOrgId());
|
|
|
|
- bean.setUpdateTime(userEntity.getUpdateTime());
|
|
|
|
- bean.setCreationTime(userEntity.getCreationTime());
|
|
|
|
- bean.setOrgId(userEntity.getOrgId());
|
|
|
|
- if (null != bean.getOrgId()) {
|
|
|
|
- OrgEntity org = GlobalHelper.getEntity(orgRepo, Long.valueOf(bean.getOrgId()),
|
|
|
|
- OrgEntity.class);
|
|
|
|
- if (null != org) {
|
|
|
|
- bean.setOrgName(org.getName());
|
|
|
|
- bean.setOrgCode(org.getCode());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- bean.setEnable(userEntity.getEnable());
|
|
|
|
- return bean;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 方法注释
|
|
|
|
- *
|
|
|
|
- * @author WANGWEI
|
|
|
|
- * @param id
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- @ApiOperation(value = "按id查询用户", notes = "id查询")
|
|
|
|
- @GetMapping("/{id}")
|
|
|
|
- public UserDomain getUserById(@PathVariable long id) {
|
|
|
|
- UserEntity userEntity = GlobalHelper.getEntity(userRepo, id, UserEntity.class);
|
|
|
|
-
|
|
|
|
- UserDomain bean = new UserDomain();
|
|
|
|
- bean.setId(userEntity.getId());
|
|
|
|
- bean.setLoginName(userEntity.getLoginName());
|
|
|
|
- bean.setName(userEntity.getName());
|
|
|
|
- bean.setRootOrgId(userEntity.getRootOrgId());
|
|
|
|
- bean.setUpdateTime(userEntity.getUpdateTime());
|
|
|
|
- bean.setCreationTime(userEntity.getCreationTime());
|
|
|
|
- bean.setOrgId(userEntity.getOrgId());
|
|
|
|
- if (null != bean.getOrgId()) {
|
|
|
|
- OrgEntity org = GlobalHelper.getEntity(orgRepo, Long.valueOf(bean.getOrgId()),
|
|
|
|
- OrgEntity.class);
|
|
|
|
- if (null != org) {
|
|
|
|
- bean.setOrgName(org.getName());
|
|
|
|
- bean.setOrgCode(org.getCode());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- bean.setEnable(userEntity.getEnable());
|
|
|
|
- return bean;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 方法注释
|
|
|
|
- *
|
|
|
|
- * @author WANGWEI
|
|
|
|
- * @param orgId
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- @ApiOperation(value = "按orgId查询用户", notes = "机构id查询机构用户")
|
|
|
|
- @GetMapping("/org/{orgId}")
|
|
|
|
- public List<UserEntity> getUserByOrgId(@PathVariable long orgId) {
|
|
|
|
- List<UserEntity> userList = userRepo.findByOrgId(orgId);
|
|
|
|
- return userList;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 方法注释
|
|
|
|
- *
|
|
|
|
- * @author WANGWEI
|
|
|
|
- * @param rootOrgId
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- @ApiOperation(value = "按rootOrgId查询用户", notes = "根机构id查询机构用户")
|
|
|
|
- @GetMapping("/rootOrg/{rootOrgId}")
|
|
|
|
- public List<UserEntity> getUserByRootOrgId(@PathVariable long rootOrgId) {
|
|
|
|
- List<UserEntity> userList = userRepo.findByRootOrgId(rootOrgId);
|
|
|
|
- return userList;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 重构 2018年6月26日
|
|
|
|
- *
|
|
|
|
- * @author WANGWEI
|
|
|
|
- * @param userForm
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- @ApiOperation(value = "新增用户", notes = "新增")
|
|
|
|
- @PostMapping
|
|
|
|
- @Transactional
|
|
|
|
- public Map<String, Object> addUser(@RequestBody UserFormDomain userForm) {
|
|
|
|
- trim(userForm, true);
|
|
|
|
- userForm.setId(null);
|
|
|
|
- return saveUser(userForm);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 重构 2018年6月26日
|
|
|
|
- *
|
|
|
|
- * @author WANGWEI
|
|
|
|
- * @param userForm
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- @ApiOperation(value = "更新用户", notes = "更新")
|
|
|
|
- @PutMapping
|
|
|
|
- @Transactional
|
|
|
|
- public Map<String, Object> updateUser(@RequestBody UserFormDomain userForm) {
|
|
|
|
- trim(userForm, true);
|
|
|
|
- if (null == userForm.getId()) {
|
|
|
|
- throw new StatusException("150009", "user ID is null");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- UserEntity userEntity = GlobalHelper.getEntity(userRepo, userForm.getId(),
|
|
|
|
- UserEntity.class);
|
|
|
|
- if (null == userEntity) {
|
|
|
|
- throw new StatusException("150010", "用户不存在");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (!userEntity.getRootOrgId().equals(userForm.getRootOrgId())) {
|
|
|
|
- throw new StatusException("150010", "顶级机构错误");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- userForm.setPassword(userEntity.getPassword());
|
|
|
|
-
|
|
|
|
- return saveUser(userForm);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 新增或更新用户
|
|
|
|
- *
|
|
|
|
- * @author WANGWEI
|
|
|
|
- * @param userForm
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- private Map<String, Object> saveUser(UserFormDomain userForm) {
|
|
|
|
-
|
|
|
|
- Long rootOrgId = userForm.getRootOrgId();
|
|
|
|
- Long orgId = userForm.getOrgId();
|
|
|
|
-
|
|
|
|
- if (StringUtils.isBlank(userForm.getName())) {
|
|
|
|
- throw new StatusException("130001", "用户名不能为空");
|
|
|
|
- }
|
|
|
|
- if (StringUtils.isBlank(userForm.getLoginName())) {
|
|
|
|
- throw new StatusException("130002", "登陆名不能为空");
|
|
|
|
- }
|
|
|
|
- if (StringUtils.isBlank(userForm.getPassword())) {
|
|
|
|
- throw new StatusException("130003", "密码不能为空");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (null == rootOrgId) {
|
|
|
|
- throw new StatusException("150002", "rootOrgId is null");
|
|
|
|
- }
|
|
|
|
- OrgEntity rootOrg = GlobalHelper.getEntity(orgRepo, rootOrgId, OrgEntity.class);
|
|
|
|
- if (null == rootOrg) {
|
|
|
|
- throw new StatusException("150003", "机构不存在");
|
|
|
|
- }
|
|
|
|
- if (null != rootOrg.getParentId()) {
|
|
|
|
- throw new StatusException("150004", "机构错误");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- validateRootOrgIsolation(rootOrgId);
|
|
|
|
-
|
|
|
|
- if (null != orgId) {
|
|
|
|
- OrgEntity org = GlobalHelper.getEntity(orgRepo, orgId, OrgEntity.class);
|
|
|
|
- if (null == org) {
|
|
|
|
- throw new StatusException("150101", "子机构不存在");
|
|
|
|
- }
|
|
|
|
- if (null == org.getParentId()) {
|
|
|
|
- throw new StatusException("150102", "子机构错误");
|
|
|
|
- }
|
|
|
|
- if (!org.getRootId().equals(rootOrgId)) {
|
|
|
|
- throw new StatusException("150103", "子机构错误");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- UserEntity userEntity = new UserEntity();
|
|
|
|
- userEntity.setId(userForm.getId());
|
|
|
|
- userEntity.setEnable(userForm.getEnable());
|
|
|
|
- userEntity.setLoginName(userForm.getLoginName());
|
|
|
|
- userEntity.setPhoneNumber(userForm.getPhoneNumber());
|
|
|
|
- userEntity.setName(userForm.getName());
|
|
|
|
- userEntity.setOrgId(orgId);
|
|
|
|
- userEntity.setRootOrgId(rootOrgId);
|
|
|
|
- userEntity.setPassword(userForm.getPassword());
|
|
|
|
- userEntity.setUpdateTime(new Date());
|
|
|
|
-
|
|
|
|
- UserEntity saved = userService.save(userEntity);
|
|
|
|
-
|
|
|
|
- List<UserRoleRelationEntity> userRoles = Lists.newArrayList();
|
|
|
|
- List<Long> roleIds = userForm.getRoleIds();
|
|
|
|
- for (Long cur : roleIds) {
|
|
|
|
- RoleEntity curRoleEntity = GlobalHelper.getEntity(roleRepo, cur, RoleEntity.class);
|
|
|
|
- if (null == curRoleEntity) {
|
|
|
|
- throw new StatusException("150005", "角色错误");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Long roleRootOrgId = curRoleEntity.getRootOrgId();
|
|
|
|
- if (null != roleRootOrgId && (!roleRootOrgId.equals(rootOrgId))) {
|
|
|
|
- throw new StatusException("150006", "角色错误");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (curRoleEntity.getCode().equals(RoleMeta.SUPER_ADMIN.name())) {
|
|
|
|
- throw new StatusException("150007", "不允许新增或修改超级管理员");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (curRoleEntity.getCode().equals(RoleMeta.LC_USER.name())) {
|
|
|
|
- if (null == saved.getOrgId()) {
|
|
|
|
- throw new StatusException("150008", "学习中心角色必须指定学习中心");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- UserRoleRelationEntity relation = new UserRoleRelationEntity(saved.getId(),
|
|
|
|
- curRoleEntity.getId());
|
|
|
|
- userRoles.add(relation);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- userRoleRelationRepo.deleteByUserId(saved.getId());
|
|
|
|
- List<UserRoleRelationEntity> savedRelationList = userRoleRelationRepo.saveAll(userRoles);
|
|
|
|
-
|
|
|
|
- Map<String, Object> ret = Maps.newHashMap();
|
|
|
|
- ret.put("userId", saved.getId());
|
|
|
|
- ret.put("loginName", saved.getLoginName());
|
|
|
|
- ret.put("roleList", savedRelationList);
|
|
|
|
- return ret;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 判断是否是超级管理员
|
|
|
|
- *
|
|
|
|
- * @author WANGWEI
|
|
|
|
- * @param userId
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- private boolean isSuperAdmin(Long userId) {
|
|
|
|
- List<UserRoleRelationEntity> relationList = userRoleRelationRepo.findAllByUserId(userId);
|
|
|
|
- if (CollectionUtils.isNotEmpty(relationList)) {
|
|
|
|
- for (UserRoleRelationEntity cur : relationList) {
|
|
|
|
- Long roleId = cur.getRoleId();
|
|
|
|
- RoleEntity roleEntity = GlobalHelper.getEntity(roleRepo, roleId, RoleEntity.class);
|
|
|
|
- if (roleEntity.getCode().equals(RoleMeta.SUPER_ADMIN.name())) {
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @ApiOperation(value = "重置用户密码", notes = "重置密码")
|
|
|
|
- @PutMapping("/resetPass/{id}")
|
|
|
|
- @Transactional
|
|
|
|
- public void resetPass(@PathVariable String id) {
|
|
|
|
- List<Long> ids = Stream.of(id.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
-
|
|
|
|
- for (Long userId : ids) {
|
|
|
|
- if (isSuperAdmin(userId)) {
|
|
|
|
- throw new StatusException("150410", "超级管理员账号不允许修改");
|
|
|
|
- }
|
|
|
|
- UserEntity user = GlobalHelper.getEntity(userRepo, userId, UserEntity.class);
|
|
|
|
- user.setPassword(BasicConsts.DEFAULT_PASSWORD);
|
|
|
|
- userRepo.save(user);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @ApiOperation(value = "启用用户", notes = "启用用户")
|
|
|
|
- @PutMapping("/enable/{ids}")
|
|
|
|
- @Transactional
|
|
|
|
- public List<String> enableUser(@PathVariable String ids) {
|
|
|
|
- List<Long> userIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- List<String> ret = Lists.newArrayList();
|
|
|
|
- for (Long userId : userIds) {
|
|
|
|
- if (isSuperAdmin(userId)) {
|
|
|
|
- throw new StatusException("150410", "超级管理员账号不允许修改");
|
|
|
|
- }
|
|
|
|
- UserEntity user = GlobalHelper.getEntity(userRepo, userId, UserEntity.class);
|
|
|
|
- user.setEnable(true);
|
|
|
|
- userRepo.save(user);
|
|
|
|
- ret.add(user.getId() + ":" + user.getName());
|
|
|
|
- }
|
|
|
|
- return ret;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @ApiOperation(value = "禁用用户", notes = "禁用用户")
|
|
|
|
- @PutMapping("/disable/{ids}")
|
|
|
|
- @Transactional
|
|
|
|
- public List<String> disableUser(@PathVariable String ids) {
|
|
|
|
- List<Long> userIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- List<String> ret = Lists.newArrayList();
|
|
|
|
- for (Long userId : userIds) {
|
|
|
|
- if (isSuperAdmin(userId)) {
|
|
|
|
- throw new StatusException("150410", "超级管理员账号不允许修改");
|
|
|
|
- }
|
|
|
|
- UserEntity user = GlobalHelper.getEntity(userRepo, userId, UserEntity.class);
|
|
|
|
- user.setEnable(false);
|
|
|
|
- userRepo.save(user);
|
|
|
|
- ret.add(user.getId() + ":" + user.getName());
|
|
|
|
- }
|
|
|
|
- return ret;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 方法注释
|
|
|
|
- *
|
|
|
|
- * @author WANGWEI
|
|
|
|
- * @param userId
|
|
|
|
- * @param password
|
|
|
|
- */
|
|
|
|
- @ApiOperation(value = "修改用户密码", notes = "修改密码")
|
|
|
|
- @PutMapping("/password")
|
|
|
|
- @Transactional
|
|
|
|
- public void updatePass(@RequestParam long userId, @RequestParam String password) {
|
|
|
|
- String realPassword = StringEscapeUtils.unescapeJavaScript(password);
|
|
|
|
- userRepo.updatePasswordById(userId, realPassword);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 方法注释
|
|
|
|
- *
|
|
|
|
- * @author WANGWEI
|
|
|
|
- * @param ids
|
|
|
|
- */
|
|
|
|
- @ApiOperation(value = "按id删除用户", notes = "删除")
|
|
|
|
- @DeleteMapping("/{ids}")
|
|
|
|
- public void deleteUser(@PathVariable String ids) {
|
|
|
|
- List<Long> userIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- for (Long userId : userIds) {
|
|
|
|
- userRepo.deleteById(userId);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ UserService userService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ UserRepo userRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ OrgRepo orgRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ RoleRepo roleRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ UserRoleRelationRepo userRoleRelationRepo;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 方法注释
|
|
|
|
+ *
|
|
|
|
+ * @param curPage
|
|
|
|
+ * @param pageSize
|
|
|
|
+ * @param rootOrgId
|
|
|
|
+ * @param loginName
|
|
|
|
+ * @param name
|
|
|
|
+ * @param enable
|
|
|
|
+ * @param roleId
|
|
|
|
+ * @param roleCode
|
|
|
|
+ * @return
|
|
|
|
+ * @author WANGWEI
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "查询所有用户", notes = "")
|
|
|
|
+ @GetMapping("all/{curPage}/{pageSize}")
|
|
|
|
+ public PageInfo<UserDomain> getUserPage(@PathVariable Integer curPage,
|
|
|
|
+ @PathVariable Integer pageSize,
|
|
|
|
+ @RequestParam(required = false) Long rootOrgId,
|
|
|
|
+ @RequestParam String loginName, @RequestParam String name,
|
|
|
|
+ @RequestParam(required = false) Boolean enable,
|
|
|
|
+ @RequestParam(required = false) Long roleId, @RequestParam(required =
|
|
|
|
+ false) Long orgId,
|
|
|
|
+ @RequestParam(required = false) String roleCode) {
|
|
|
|
+
|
|
|
|
+ User accessUser = getAccessUser();
|
|
|
|
+
|
|
|
|
+ if (null == rootOrgId) {
|
|
|
|
+ rootOrgId = accessUser.getRootOrgId();
|
|
|
|
+ } else {
|
|
|
|
+ validateRootOrgIsolation(rootOrgId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ final Long finalRootOrgId = rootOrgId;
|
|
|
|
+
|
|
|
|
+ OrgEntity rootOrg = GlobalHelper.getEntity(orgRepo, rootOrgId, OrgEntity.class);
|
|
|
|
+ if (null == rootOrg) {
|
|
|
|
+ throw new StatusException("150003", "机构不存在");
|
|
|
|
+ }
|
|
|
|
+ if (null != rootOrg.getParentId()) {
|
|
|
|
+ throw new StatusException("150004", "机构错误");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (null != roleId) {
|
|
|
|
+ RoleEntity roleEntity = GlobalHelper.getEntity(roleRepo, roleId, RoleEntity.class);
|
|
|
|
+ if (null == roleEntity) {
|
|
|
|
+ throw new StatusException("150002", "角色不存在");
|
|
|
|
+ }
|
|
|
|
+ } else if (StringUtils.isNotBlank(roleCode)) {
|
|
|
|
+ RoleEntity roleEntity = roleRepo.findByCodeAndRootOrgIdIsNull(roleCode.trim());
|
|
|
|
+ if (null == roleEntity) {
|
|
|
|
+ roleEntity = roleRepo.findByCodeAndRootOrgId(roleCode.trim(),
|
|
|
|
+ accessUser.getRootOrgId());
|
|
|
|
+ }
|
|
|
|
+ if (null == roleEntity) {
|
|
|
|
+ throw new StatusException("150002", "角色不存在");
|
|
|
|
+ }
|
|
|
|
+ roleId = roleEntity.getId();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ final Long finalRoleId = roleId;
|
|
|
|
+
|
|
|
|
+ Specification<UserEntity> specification = (root, query, cb) -> {
|
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
|
+ predicates.add(cb.equal(root.get("rootOrgId"), finalRootOrgId));
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isNotBlank(loginName)) {
|
|
|
|
+ predicates.add(cb.like(root.get("loginName"), toSqlSearchPattern(loginName)));
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(name)) {
|
|
|
|
+ predicates.add(cb.like(root.get("name"), toSqlSearchPattern(name)));
|
|
|
|
+ }
|
|
|
|
+ if (null != orgId) {
|
|
|
|
+ predicates.add(cb.equal(root.get("orgId"), orgId));
|
|
|
|
+ }
|
|
|
|
+ if (null != enable) {
|
|
|
|
+ predicates.add(cb.equal(root.get("enable"), enable));
|
|
|
|
+ }
|
|
|
|
+ if (null != finalRoleId) {
|
|
|
|
+ Subquery<UserRoleRelationEntity> subquery = query
|
|
|
|
+ .subquery(UserRoleRelationEntity.class);
|
|
|
|
+ Root<UserRoleRelationEntity> subRoot = subquery.from(UserRoleRelationEntity.class);
|
|
|
|
+ subquery.select(subRoot.get("userId"));
|
|
|
|
+ Predicate p1 = cb.equal(subRoot.get("roleId"), finalRoleId);
|
|
|
|
+ Predicate p2 = cb.equal(subRoot.get("userId"), root.get("id"));
|
|
|
|
+ subquery.where(cb.and(p1, p2));
|
|
|
|
+ predicates.add(cb.exists(subquery));
|
|
|
|
+ }
|
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
|
+ };
|
|
|
|
+ Pageable pageable = PageRequest.of(curPage - 1, pageSize, Sort.Direction.DESC, "updateTime",
|
|
|
|
+ "id");
|
|
|
|
+
|
|
|
|
+ Page<UserEntity> userList = userRepo.findAll(specification, pageable);
|
|
|
|
+
|
|
|
|
+ Iterator<UserEntity> iterator = userList.iterator();
|
|
|
|
+
|
|
|
|
+ List<UserDomain> fullUserInfoList = Lists.newArrayList();
|
|
|
|
+ while (iterator.hasNext()) {
|
|
|
|
+ UserEntity next = iterator.next();
|
|
|
|
+ UserDomain bean = new UserDomain();
|
|
|
|
+ bean.setId(next.getId());
|
|
|
|
+ bean.setLoginName(next.getLoginName());
|
|
|
|
+ bean.setName(next.getName());
|
|
|
|
+ bean.setRootOrgId(next.getRootOrgId());
|
|
|
|
+ bean.setUpdateTime(next.getUpdateTime());
|
|
|
|
+ bean.setCreationTime(next.getCreationTime());
|
|
|
|
+ bean.setOrgId(next.getOrgId());
|
|
|
|
+ bean.setPhoneNumber(next.getPhoneNumber());
|
|
|
|
+ if (null != bean.getOrgId()) {
|
|
|
|
+ OrgEntity org = GlobalHelper.getEntity(orgRepo, Long.valueOf(bean.getOrgId()),
|
|
|
|
+ OrgEntity.class);
|
|
|
|
+ if (null != org) {
|
|
|
|
+ bean.setOrgName(org.getName());
|
|
|
|
+ bean.setOrgCode(org.getCode());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ bean.setRootOrgName(rootOrg.getName());
|
|
|
|
+ bean.setEnable(next.getEnable());
|
|
|
|
+
|
|
|
|
+ List<UserRoleRelationEntity> relationList = userRoleRelationRepo
|
|
|
|
+ .findAllByUserId(next.getId());
|
|
|
|
+ List<String> roleNameList = Lists.newArrayList();
|
|
|
|
+ List<Long> roleIdList = Lists.newArrayList();
|
|
|
|
+ List<String> roleCodeList = Lists.newArrayList();
|
|
|
|
+ for (UserRoleRelationEntity cur : relationList) {
|
|
|
|
+ RoleEntity curRoleEntity = GlobalHelper.getEntity(roleRepo, cur.getRoleId(),
|
|
|
|
+ RoleEntity.class);
|
|
|
|
+ if (null == curRoleEntity) {
|
|
|
|
+ throw new StatusException("150002", "角色错误");
|
|
|
|
+ }
|
|
|
|
+ roleNameList.add(curRoleEntity.getName());
|
|
|
|
+ roleIdList.add(curRoleEntity.getId());
|
|
|
|
+ roleCodeList.add(curRoleEntity.getCode());
|
|
|
|
+ }
|
|
|
|
+ bean.setRoleNamesStr(StringUtils.join(roleNameList, ","));
|
|
|
|
+ bean.setRoleIds(roleIdList);
|
|
|
|
+ bean.setRoleCodes(roleCodeList);
|
|
|
|
+
|
|
|
|
+ fullUserInfoList.add(bean);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ PageInfo<UserDomain> ret = new PageInfo<UserDomain>();
|
|
|
|
+ ret.setList(fullUserInfoList);
|
|
|
|
+ ret.setTotal(userList.getTotalElements());
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "模糊查询用户", notes = "")
|
|
|
|
+ @GetMapping("query")
|
|
|
|
+ public List<UserDomain> query(@RequestParam(required = false) Long rootOrgId,
|
|
|
|
+ @RequestParam(required = false) String rootOrgCode,
|
|
|
|
+ @RequestParam(required = false) String loginName,
|
|
|
|
+ @RequestParam(required = false) String name,
|
|
|
|
+ @RequestParam(required = false) Boolean enable,
|
|
|
|
+ @RequestParam(required = false) Long roleId,
|
|
|
|
+ @RequestParam(required = false) Long orgId,
|
|
|
|
+ @RequestParam(required = false) String roleCode) {
|
|
|
|
+
|
|
|
|
+ OrgEntity rootOrg = null;
|
|
|
|
+
|
|
|
|
+ if (null != rootOrgId) {
|
|
|
|
+ rootOrg = GlobalHelper.getEntity(orgRepo, rootOrgId, OrgEntity.class);
|
|
|
|
+ if (null == rootOrg) {
|
|
|
|
+ throw new StatusException("150003", "机构不存在");
|
|
|
|
+ }
|
|
|
|
+ } else if (StringUtils.isNotBlank(rootOrgCode)) {
|
|
|
|
+ rootOrg = orgRepo.findByParentIdIsNullAndCode(rootOrgCode);
|
|
|
|
+ if (null == rootOrg) {
|
|
|
|
+ throw new StatusException("150003", "机构不存在");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (null != rootOrg) {
|
|
|
|
+ if (null != rootOrg.getParentId()) {
|
|
|
|
+ throw new StatusException("150004", "机构错误");
|
|
|
|
+ }
|
|
|
|
+ rootOrgId = rootOrg.getId();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ final Long finalRootOrgId = rootOrgId;
|
|
|
|
+
|
|
|
|
+ if (null != roleId) {
|
|
|
|
+ RoleEntity roleEntity = GlobalHelper.getEntity(roleRepo, roleId, RoleEntity.class);
|
|
|
|
+ if (null == roleEntity) {
|
|
|
|
+ throw new StatusException("150002", "角色不存在");
|
|
|
|
+ }
|
|
|
|
+ } else if (StringUtils.isNotBlank(roleCode)) {
|
|
|
|
+ RoleEntity roleEntity = roleRepo.findByCodeAndRootOrgIdIsNull(roleCode.trim());
|
|
|
|
+ if (null == roleEntity) {
|
|
|
|
+ roleEntity = roleRepo.findByCodeAndRootOrgId(roleCode.trim(), rootOrgId);
|
|
|
|
+ }
|
|
|
|
+ if (null == roleEntity) {
|
|
|
|
+ throw new StatusException("150002", "角色不存在");
|
|
|
|
+ }
|
|
|
|
+ roleId = roleEntity.getId();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ final Long finalRoleId = roleId;
|
|
|
|
+
|
|
|
|
+ Specification<UserEntity> specification = (root, query, cb) -> {
|
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ if (null != finalRootOrgId) {
|
|
|
|
+ predicates.add(cb.equal(root.get("rootOrgId"), finalRootOrgId));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isNotBlank(loginName)) {
|
|
|
|
+ predicates.add(cb.like(root.get("loginName"), toSqlSearchPattern(loginName)));
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(name)) {
|
|
|
|
+ predicates.add(cb.like(root.get("name"), toSqlSearchPattern(name)));
|
|
|
|
+ }
|
|
|
|
+ if (null != orgId) {
|
|
|
|
+ predicates.add(cb.equal(root.get("orgId"), orgId));
|
|
|
|
+ }
|
|
|
|
+ if (null != enable) {
|
|
|
|
+ predicates.add(cb.equal(root.get("enable"), enable));
|
|
|
|
+ }
|
|
|
|
+ if (null != finalRoleId) {
|
|
|
|
+ Subquery<UserRoleRelationEntity> subquery = query
|
|
|
|
+ .subquery(UserRoleRelationEntity.class);
|
|
|
|
+ Root<UserRoleRelationEntity> subRoot = subquery.from(UserRoleRelationEntity.class);
|
|
|
|
+ subquery.select(subRoot.get("userId"));
|
|
|
|
+ Predicate p1 = cb.equal(subRoot.get("roleId"), finalRoleId);
|
|
|
|
+ Predicate p2 = cb.equal(subRoot.get("userId"), root.get("id"));
|
|
|
|
+ subquery.where(cb.and(p1, p2));
|
|
|
|
+ predicates.add(cb.exists(subquery));
|
|
|
|
+ }
|
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ PageRequest pageRequest = PageRequest.of(0, 50, new Sort(Direction.DESC, "updateTime"));
|
|
|
|
+
|
|
|
|
+ Page<UserEntity> userList = userRepo.findAll(specification, pageRequest);
|
|
|
|
+
|
|
|
|
+ Iterator<UserEntity> iterator = userList.iterator();
|
|
|
|
+
|
|
|
|
+ List<UserDomain> fullUserInfoList = Lists.newArrayList();
|
|
|
|
+ while (iterator.hasNext()) {
|
|
|
|
+ UserEntity next = iterator.next();
|
|
|
|
+ UserDomain bean = new UserDomain();
|
|
|
|
+ bean.setId(next.getId());
|
|
|
|
+ bean.setLoginName(next.getLoginName());
|
|
|
|
+ bean.setName(next.getName());
|
|
|
|
+ bean.setRootOrgId(next.getRootOrgId());
|
|
|
|
+ bean.setUpdateTime(next.getUpdateTime());
|
|
|
|
+ bean.setCreationTime(next.getCreationTime());
|
|
|
|
+ bean.setOrgId(next.getOrgId());
|
|
|
|
+ if (null != bean.getOrgId()) {
|
|
|
|
+ OrgEntity org = GlobalHelper.getEntity(orgRepo, Long.valueOf(bean.getOrgId()),
|
|
|
|
+ OrgEntity.class);
|
|
|
|
+ if (null != org) {
|
|
|
|
+ bean.setOrgName(org.getName());
|
|
|
|
+ bean.setOrgCode(org.getCode());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ bean.setRootOrgName(rootOrg.getName());
|
|
|
|
+ bean.setEnable(next.getEnable());
|
|
|
|
+
|
|
|
|
+ List<UserRoleRelationEntity> relationList = userRoleRelationRepo
|
|
|
|
+ .findAllByUserId(next.getId());
|
|
|
|
+ List<String> roleNameList = Lists.newArrayList();
|
|
|
|
+ List<Long> roleIdList = Lists.newArrayList();
|
|
|
|
+ List<String> roleCodeList = Lists.newArrayList();
|
|
|
|
+ for (UserRoleRelationEntity cur : relationList) {
|
|
|
|
+ RoleEntity curRoleEntity = GlobalHelper.getEntity(roleRepo, cur.getRoleId(),
|
|
|
|
+ RoleEntity.class);
|
|
|
|
+ if (null == curRoleEntity) {
|
|
|
|
+ throw new StatusException("150002", "角色错误");
|
|
|
|
+ }
|
|
|
|
+ roleNameList.add(curRoleEntity.getName());
|
|
|
|
+ roleIdList.add(curRoleEntity.getId());
|
|
|
|
+ roleCodeList.add(curRoleEntity.getCode());
|
|
|
|
+ }
|
|
|
|
+ bean.setRoleNamesStr(StringUtils.join(roleNameList, ","));
|
|
|
|
+ bean.setRoleIds(roleIdList);
|
|
|
|
+ bean.setRoleCodes(roleCodeList);
|
|
|
|
+
|
|
|
|
+ fullUserInfoList.add(bean);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return fullUserInfoList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 方法注释
|
|
|
|
+ *
|
|
|
|
+ * @param id
|
|
|
|
+ * @return
|
|
|
|
+ * @author WANGWEI
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "查询登陆用户", notes = "")
|
|
|
|
+ @GetMapping("getUserBySession")
|
|
|
|
+ public UserDomain getUserBySession() {
|
|
|
|
+ User accessUser = getAccessUser();
|
|
|
|
+ UserEntity userEntity = GlobalHelper.getEntity(userRepo, accessUser.getUserId(),
|
|
|
|
+ UserEntity.class);
|
|
|
|
+
|
|
|
|
+ UserDomain bean = new UserDomain();
|
|
|
|
+ bean.setId(userEntity.getId());
|
|
|
|
+ bean.setLoginName(userEntity.getLoginName());
|
|
|
|
+ bean.setName(userEntity.getName());
|
|
|
|
+ bean.setRootOrgId(userEntity.getRootOrgId());
|
|
|
|
+ bean.setUpdateTime(userEntity.getUpdateTime());
|
|
|
|
+ bean.setCreationTime(userEntity.getCreationTime());
|
|
|
|
+ bean.setOrgId(userEntity.getOrgId());
|
|
|
|
+ if (null != bean.getOrgId()) {
|
|
|
|
+ OrgEntity org = GlobalHelper.getEntity(orgRepo, Long.valueOf(bean.getOrgId()),
|
|
|
|
+ OrgEntity.class);
|
|
|
|
+ if (null != org) {
|
|
|
|
+ bean.setOrgName(org.getName());
|
|
|
|
+ bean.setOrgCode(org.getCode());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ bean.setEnable(userEntity.getEnable());
|
|
|
|
+ return bean;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 方法注释
|
|
|
|
+ *
|
|
|
|
+ * @param id
|
|
|
|
+ * @return
|
|
|
|
+ * @author WANGWEI
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "按id查询用户", notes = "id查询")
|
|
|
|
+ @GetMapping("/{id}")
|
|
|
|
+ public UserDomain getUserById(@PathVariable long id) {
|
|
|
|
+ UserEntity userEntity = GlobalHelper.getEntity(userRepo, id, UserEntity.class);
|
|
|
|
+
|
|
|
|
+ UserDomain bean = new UserDomain();
|
|
|
|
+ bean.setId(userEntity.getId());
|
|
|
|
+ bean.setLoginName(userEntity.getLoginName());
|
|
|
|
+ bean.setName(userEntity.getName());
|
|
|
|
+ bean.setRootOrgId(userEntity.getRootOrgId());
|
|
|
|
+ bean.setUpdateTime(userEntity.getUpdateTime());
|
|
|
|
+ bean.setCreationTime(userEntity.getCreationTime());
|
|
|
|
+ bean.setOrgId(userEntity.getOrgId());
|
|
|
|
+ if (null != bean.getOrgId()) {
|
|
|
|
+ OrgEntity org = GlobalHelper.getEntity(orgRepo, Long.valueOf(bean.getOrgId()),
|
|
|
|
+ OrgEntity.class);
|
|
|
|
+ if (null != org) {
|
|
|
|
+ bean.setOrgName(org.getName());
|
|
|
|
+ bean.setOrgCode(org.getCode());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ bean.setEnable(userEntity.getEnable());
|
|
|
|
+ return bean;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 方法注释
|
|
|
|
+ *
|
|
|
|
+ * @param orgId
|
|
|
|
+ * @return
|
|
|
|
+ * @author WANGWEI
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "按orgId查询用户", notes = "机构id查询机构用户")
|
|
|
|
+ @GetMapping("/org/{orgId}")
|
|
|
|
+ public List<UserEntity> getUserByOrgId(@PathVariable long orgId) {
|
|
|
|
+ List<UserEntity> userList = userRepo.findByOrgId(orgId);
|
|
|
|
+ return userList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 方法注释
|
|
|
|
+ *
|
|
|
|
+ * @param rootOrgId
|
|
|
|
+ * @return
|
|
|
|
+ * @author WANGWEI
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "按rootOrgId查询用户", notes = "根机构id查询机构用户")
|
|
|
|
+ @GetMapping("/rootOrg/{rootOrgId}")
|
|
|
|
+ public List<UserEntity> getUserByRootOrgId(@PathVariable long rootOrgId) {
|
|
|
|
+ List<UserEntity> userList = userRepo.findByRootOrgId(rootOrgId);
|
|
|
|
+ return userList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 重构 2018年6月26日
|
|
|
|
+ *
|
|
|
|
+ * @param userForm
|
|
|
|
+ * @return
|
|
|
|
+ * @author WANGWEI
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "新增用户", notes = "新增")
|
|
|
|
+ @PostMapping
|
|
|
|
+ @Transactional
|
|
|
|
+ public Map<String, Object> addUser(@RequestBody UserFormDomain userForm) {
|
|
|
|
+ trim(userForm, true);
|
|
|
|
+ userForm.setId(null);
|
|
|
|
+ return saveUser(userForm);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 重构 2018年6月26日
|
|
|
|
+ *
|
|
|
|
+ * @param userForm
|
|
|
|
+ * @return
|
|
|
|
+ * @author WANGWEI
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "更新用户", notes = "更新")
|
|
|
|
+ @PutMapping
|
|
|
|
+ @Transactional
|
|
|
|
+ public Map<String, Object> updateUser(@RequestBody UserFormDomain userForm) {
|
|
|
|
+ trim(userForm, true);
|
|
|
|
+ if (null == userForm.getId()) {
|
|
|
|
+ throw new StatusException("150009", "user ID is null");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ UserEntity userEntity = GlobalHelper.getEntity(userRepo, userForm.getId(),
|
|
|
|
+ UserEntity.class);
|
|
|
|
+ if (null == userEntity) {
|
|
|
|
+ throw new StatusException("150010", "用户不存在");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!userEntity.getRootOrgId().equals(userForm.getRootOrgId())) {
|
|
|
|
+ throw new StatusException("150010", "顶级机构错误");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ userForm.setPassword(userEntity.getPassword());
|
|
|
|
+
|
|
|
|
+ return saveUser(userForm);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 新增或更新用户
|
|
|
|
+ *
|
|
|
|
+ * @param userForm
|
|
|
|
+ * @return
|
|
|
|
+ * @author WANGWEI
|
|
|
|
+ */
|
|
|
|
+ private Map<String, Object> saveUser(UserFormDomain userForm) {
|
|
|
|
+
|
|
|
|
+ Long rootOrgId = userForm.getRootOrgId();
|
|
|
|
+ Long orgId = userForm.getOrgId();
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isBlank(userForm.getName())) {
|
|
|
|
+ throw new StatusException("130001", "用户名不能为空");
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isBlank(userForm.getLoginName())) {
|
|
|
|
+ throw new StatusException("130002", "登陆名不能为空");
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isBlank(userForm.getPassword())) {
|
|
|
|
+ throw new StatusException("130003", "密码不能为空");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (null == rootOrgId) {
|
|
|
|
+ throw new StatusException("150002", "rootOrgId is null");
|
|
|
|
+ }
|
|
|
|
+ OrgEntity rootOrg = GlobalHelper.getEntity(orgRepo, rootOrgId, OrgEntity.class);
|
|
|
|
+ if (null == rootOrg) {
|
|
|
|
+ throw new StatusException("150003", "机构不存在");
|
|
|
|
+ }
|
|
|
|
+ if (null != rootOrg.getParentId()) {
|
|
|
|
+ throw new StatusException("150004", "机构错误");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ validateRootOrgIsolation(rootOrgId);
|
|
|
|
+
|
|
|
|
+ if (null != orgId) {
|
|
|
|
+ OrgEntity org = GlobalHelper.getEntity(orgRepo, orgId, OrgEntity.class);
|
|
|
|
+ if (null == org) {
|
|
|
|
+ throw new StatusException("150101", "子机构不存在");
|
|
|
|
+ }
|
|
|
|
+ if (null == org.getParentId()) {
|
|
|
|
+ throw new StatusException("150102", "子机构错误");
|
|
|
|
+ }
|
|
|
|
+ if (!org.getRootId().equals(rootOrgId)) {
|
|
|
|
+ throw new StatusException("150103", "子机构错误");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ UserEntity userEntity = new UserEntity();
|
|
|
|
+ userEntity.setId(userForm.getId());
|
|
|
|
+ userEntity.setEnable(userForm.getEnable());
|
|
|
|
+ userEntity.setLoginName(userForm.getLoginName());
|
|
|
|
+ userEntity.setPhoneNumber(userForm.getPhoneNumber());
|
|
|
|
+ userEntity.setName(userForm.getName());
|
|
|
|
+ userEntity.setOrgId(orgId);
|
|
|
|
+ userEntity.setRootOrgId(rootOrgId);
|
|
|
|
+ userEntity.setPassword(userForm.getPassword());
|
|
|
|
+ userEntity.setUpdateTime(new Date());
|
|
|
|
+
|
|
|
|
+ UserEntity saved = userService.save(userEntity);
|
|
|
|
+
|
|
|
|
+ List<UserRoleRelationEntity> userRoles = Lists.newArrayList();
|
|
|
|
+ List<Long> roleIds = userForm.getRoleIds();
|
|
|
|
+ for (Long cur : roleIds) {
|
|
|
|
+ RoleEntity curRoleEntity = GlobalHelper.getEntity(roleRepo, cur, RoleEntity.class);
|
|
|
|
+ if (null == curRoleEntity) {
|
|
|
|
+ throw new StatusException("150005", "角色错误");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Long roleRootOrgId = curRoleEntity.getRootOrgId();
|
|
|
|
+ if (null != roleRootOrgId && (!roleRootOrgId.equals(rootOrgId))) {
|
|
|
|
+ throw new StatusException("150006", "角色错误");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (curRoleEntity.getCode().equals(RoleMeta.SUPER_ADMIN.name())) {
|
|
|
|
+ throw new StatusException("150007", "不允许新增或修改超级管理员");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (curRoleEntity.getCode().equals(RoleMeta.LC_USER.name())) {
|
|
|
|
+ if (null == saved.getOrgId()) {
|
|
|
|
+ throw new StatusException("150008", "学习中心角色必须指定学习中心");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ UserRoleRelationEntity relation = new UserRoleRelationEntity(saved.getId(),
|
|
|
|
+ curRoleEntity.getId());
|
|
|
|
+ userRoles.add(relation);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ userRoleRelationRepo.deleteByUserId(saved.getId());
|
|
|
|
+ List<UserRoleRelationEntity> savedRelationList = userRoleRelationRepo.saveAll(userRoles);
|
|
|
|
+
|
|
|
|
+ Map<String, Object> ret = Maps.newHashMap();
|
|
|
|
+ ret.put("userId", saved.getId());
|
|
|
|
+ ret.put("loginName", saved.getLoginName());
|
|
|
|
+ ret.put("roleList", savedRelationList);
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 判断是否是超级管理员
|
|
|
|
+ *
|
|
|
|
+ * @param userId
|
|
|
|
+ * @return
|
|
|
|
+ * @author WANGWEI
|
|
|
|
+ */
|
|
|
|
+ private boolean isSuperAdmin(Long userId) {
|
|
|
|
+ List<UserRoleRelationEntity> relationList = userRoleRelationRepo.findAllByUserId(userId);
|
|
|
|
+ if (CollectionUtils.isNotEmpty(relationList)) {
|
|
|
|
+ for (UserRoleRelationEntity cur : relationList) {
|
|
|
|
+ Long roleId = cur.getRoleId();
|
|
|
|
+ RoleEntity roleEntity = GlobalHelper.getEntity(roleRepo, roleId, RoleEntity.class);
|
|
|
|
+ if (roleEntity.getCode().equals(RoleMeta.SUPER_ADMIN.name())) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "重置用户密码", notes = "重置密码")
|
|
|
|
+ @PutMapping("/resetPass/{id}")
|
|
|
|
+ @Transactional
|
|
|
|
+ public void resetPass(@PathVariable String id) {
|
|
|
|
+ List<Long> ids = Stream.of(id.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ for (Long userId : ids) {
|
|
|
|
+ if (isSuperAdmin(userId)) {
|
|
|
|
+ throw new StatusException("150410", "超级管理员账号不允许修改");
|
|
|
|
+ }
|
|
|
|
+ UserEntity user = GlobalHelper.getEntity(userRepo, userId, UserEntity.class);
|
|
|
|
+ user.setPassword(BasicConsts.DEFAULT_PASSWORD);
|
|
|
|
+ userRepo.save(user);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "启用用户", notes = "启用用户")
|
|
|
|
+ @PutMapping("/enable/{ids}")
|
|
|
|
+ @Transactional
|
|
|
|
+ public List<String> enableUser(@PathVariable String ids) {
|
|
|
|
+ List<Long> userIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ List<String> ret = Lists.newArrayList();
|
|
|
|
+ for (Long userId : userIds) {
|
|
|
|
+ if (isSuperAdmin(userId)) {
|
|
|
|
+ throw new StatusException("150410", "超级管理员账号不允许修改");
|
|
|
|
+ }
|
|
|
|
+ UserEntity user = GlobalHelper.getEntity(userRepo, userId, UserEntity.class);
|
|
|
|
+ user.setEnable(true);
|
|
|
|
+ userRepo.save(user);
|
|
|
|
+ ret.add(user.getId() + ":" + user.getName());
|
|
|
|
+ }
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "禁用用户", notes = "禁用用户")
|
|
|
|
+ @PutMapping("/disable/{ids}")
|
|
|
|
+ @Transactional
|
|
|
|
+ public List<String> disableUser(@PathVariable String ids) {
|
|
|
|
+ List<Long> userIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ List<String> ret = Lists.newArrayList();
|
|
|
|
+ for (Long userId : userIds) {
|
|
|
|
+ if (isSuperAdmin(userId)) {
|
|
|
|
+ throw new StatusException("150410", "超级管理员账号不允许修改");
|
|
|
|
+ }
|
|
|
|
+ UserEntity user = GlobalHelper.getEntity(userRepo, userId, UserEntity.class);
|
|
|
|
+ user.setEnable(false);
|
|
|
|
+ userRepo.save(user);
|
|
|
|
+ ret.add(user.getId() + ":" + user.getName());
|
|
|
|
+ }
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 方法注释
|
|
|
|
+ *
|
|
|
|
+ * @param userId
|
|
|
|
+ * @param password
|
|
|
|
+ * @author WANGWEI
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "修改用户密码", notes = "修改密码")
|
|
|
|
+ @PutMapping("/password")
|
|
|
|
+ @Transactional
|
|
|
|
+ public void updatePass(@RequestParam long userId, @RequestParam String password) {
|
|
|
|
+ String realPassword = StringEscapeUtils.unescapeJavaScript(password);
|
|
|
|
+ userRepo.updatePasswordById(userId, realPassword);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 方法注释
|
|
|
|
+ *
|
|
|
|
+ * @param ids
|
|
|
|
+ * @author WANGWEI
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "按id删除用户", notes = "删除")
|
|
|
|
+ @DeleteMapping("/{ids}")
|
|
|
|
+ public void deleteUser(@PathVariable String ids) {
|
|
|
|
+ List<Long> userIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ for (Long userId : userIds) {
|
|
|
|
+ userRepo.deleteById(userId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|