|
@@ -17,17 +17,13 @@ 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.PageImpl;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
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.ModelAttribute;
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.PutMapping;
|
|
@@ -40,16 +36,13 @@ import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
|
|
import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
-import cn.com.qmth.examcloud.commons.base.util.ErrorMsg;
|
|
|
import cn.com.qmth.examcloud.commons.web.helpers.page.PageInfo;
|
|
|
-import cn.com.qmth.examcloud.commons.web.security.annotation.Uac;
|
|
|
import cn.com.qmth.examcloud.commons.web.security.bean.User;
|
|
|
-import cn.com.qmth.examcloud.commons.web.security.entity.AccessUser;
|
|
|
import cn.com.qmth.examcloud.commons.web.security.enums.RoleMeta;
|
|
|
-import cn.com.qmth.examcloud.commons.web.security.enums.UacPolicy;
|
|
|
import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.controller.bean.FullUserInfo;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.controller.bean.UserForm;
|
|
|
+import cn.com.qmth.examcloud.core.basic.base.enums.AccountType;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.RoleRepo;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.UserRepo;
|
|
@@ -59,7 +52,8 @@ import cn.com.qmth.examcloud.core.basic.dao.entity.Org;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.RoleEntity;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.UserEntity;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.UserRoleRelationEntity;
|
|
|
-import cn.com.qmth.examcloud.core.basic.service.bean.UserInfo;
|
|
|
+import cn.com.qmth.examcloud.core.basic.service.AuthService;
|
|
|
+import cn.com.qmth.examcloud.core.basic.service.bean.LoginInfo;
|
|
|
import cn.com.qmth.examcloud.core.basic.service.impl.UserServiceImpl;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
@@ -83,6 +77,9 @@ public class UserController extends ControllerSupport {
|
|
|
@Autowired
|
|
|
RoleRepo roleRepo;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ AuthService authService;
|
|
|
+
|
|
|
@Autowired
|
|
|
UserRoleRelationRepo userRoleRelationRepo;
|
|
|
|
|
@@ -106,7 +103,8 @@ public class UserController extends ControllerSupport {
|
|
|
@PathVariable Integer pageSize, @RequestParam Long rootOrgId,
|
|
|
@RequestParam String loginName, @RequestParam String name,
|
|
|
@RequestParam(required = false) Boolean enable,
|
|
|
- @RequestParam(required = false) Long roleId) {
|
|
|
+ @RequestParam(required = false) Long roleId,
|
|
|
+ @RequestParam(required = false) String roleCode) {
|
|
|
|
|
|
User accessUser = getAccessUser();
|
|
|
if ((!isSuperAdmin()) && (!rootOrgId.equals(accessUser.getRootOrgId()))) {
|
|
@@ -126,8 +124,16 @@ public class UserController extends ControllerSupport {
|
|
|
if (null == roleEntity) {
|
|
|
throw new StatusException("B-150002", "角色不存在");
|
|
|
}
|
|
|
+ } else if (StringUtils.isNotBlank(roleCode)) {
|
|
|
+ RoleEntity roleEntity = roleRepo.findByCode(roleCode.trim());
|
|
|
+ if (null == roleEntity) {
|
|
|
+ throw new StatusException("B-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"), rootOrgId));
|
|
@@ -138,12 +144,12 @@ public class UserController extends ControllerSupport {
|
|
|
if (StringUtils.isNotBlank(name)) {
|
|
|
predicates.add(cb.like(root.get("name"), toSqlSearchPattern(name)));
|
|
|
}
|
|
|
- if (null != roleId) {
|
|
|
+ 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"), roleId);
|
|
|
+ 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));
|
|
@@ -204,12 +210,27 @@ public class UserController extends ControllerSupport {
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@ApiOperation(value = "按id查询用户", notes = "id查询")
|
|
|
@GetMapping("/{id}")
|
|
|
- public ResponseEntity getUserById(@PathVariable long id) {
|
|
|
- return new ResponseEntity(userRepo.findOne(id), HttpStatus.OK);
|
|
|
+ public UserEntity getUserById(@PathVariable long id) {
|
|
|
+ UserEntity user = userRepo.findOne(id);
|
|
|
+ return user;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param orgId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@ApiOperation(value = "按orgId查询用户", notes = "机构id查询机构用户")
|
|
|
@GetMapping("/org/{orgId}")
|
|
|
public List<UserEntity> getUserByOrgId(@PathVariable long orgId) {
|
|
@@ -217,6 +238,13 @@ public class UserController extends ControllerSupport {
|
|
|
return userList;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param rootOrgId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@ApiOperation(value = "按rootOrgId查询用户", notes = "根机构id查询机构用户")
|
|
|
@GetMapping("/rootOrg/{rootOrgId}")
|
|
|
public List<UserEntity> getUserByRootOrgId(@PathVariable long rootOrgId) {
|
|
@@ -370,99 +398,115 @@ public class UserController extends ControllerSupport {
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param userId
|
|
|
+ * @param password
|
|
|
+ */
|
|
|
@ApiOperation(value = "修改用户密码", notes = "修改密码")
|
|
|
@PutMapping("/password")
|
|
|
- public ResponseEntity updatePass(@RequestParam long userId, @RequestParam String password) {
|
|
|
+ public void updatePass(@RequestParam long userId, @RequestParam String password) {
|
|
|
String realPassword = StringEscapeUtils.unescapeJavaScript(password);
|
|
|
userRepo.updatePasswordById(userId, realPassword);
|
|
|
- return new ResponseEntity(HttpStatus.OK);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param ids
|
|
|
+ */
|
|
|
@ApiOperation(value = "按id删除用户", notes = "删除")
|
|
|
@DeleteMapping("/{ids}")
|
|
|
- @Uac(roles = {RoleMeta.SUPER_ADMIN}, policy = UacPolicy.IN)
|
|
|
- public ResponseEntity deleteUser(@PathVariable String 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.delete(userId);
|
|
|
}
|
|
|
- return new ResponseEntity(HttpStatus.OK);
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "一般登录", notes = "登录")
|
|
|
@PostMapping("/login")
|
|
|
- @Deprecated
|
|
|
- public ResponseEntity login(@RequestParam String loginName, @RequestParam String password) {
|
|
|
- try {
|
|
|
- UserInfo userInfo = userService.login(loginName, password);
|
|
|
- return new ResponseEntity(userInfo, HttpStatus.OK);
|
|
|
- } catch (Exception e) {
|
|
|
- return new ResponseEntity(new ErrorMsg(e.getMessage()),
|
|
|
- HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
+ public Map<String, Object> login(@RequestParam String loginName,
|
|
|
+ @RequestParam String password) {
|
|
|
+ UserEntity user = userRepo.findByLoginName(loginName);
|
|
|
+ if (user == null) {
|
|
|
+ throw new RuntimeException("该用户不存在");
|
|
|
+ } else if (!user.getEnable()) {
|
|
|
+ throw new RuntimeException("该用户被禁用");
|
|
|
}
|
|
|
+
|
|
|
+ LoginInfo loginInfo = new LoginInfo();
|
|
|
+ loginInfo.setAccountType(AccountType.COMMON_LOGIN_NAME.getCode());
|
|
|
+ loginInfo.setAccountValue(user.getLoginName());
|
|
|
+ loginInfo.setPassword(user.getPassword());
|
|
|
+ loginInfo.setRootOrgId(String.valueOf(user.getRootOrgId()));
|
|
|
+ User loginUser = authService.login(loginInfo);
|
|
|
+
|
|
|
+ Map<String, Object> ret = Maps.newHashMap();
|
|
|
+ ret.put("userId", loginUser.getUserId());
|
|
|
+ ret.put("token", loginUser.getUserToken());
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "二级登录", notes = "二级登录")
|
|
|
- @PostMapping("/login/{orgId}")
|
|
|
- @Deprecated
|
|
|
- public ResponseEntity login(@PathVariable long orgId, @RequestParam String loginName,
|
|
|
+ @PostMapping("/login/{rootOrgId}")
|
|
|
+ public Map<String, Object> login(@PathVariable long rootOrgId, @RequestParam String loginName,
|
|
|
@RequestParam String password) {
|
|
|
- try {
|
|
|
- UserInfo userInfo = userService.login(orgId, loginName, password);
|
|
|
- return new ResponseEntity(userInfo, HttpStatus.OK);
|
|
|
- } catch (Exception e) {
|
|
|
- return new ResponseEntity(new ErrorMsg(e.getMessage()),
|
|
|
- HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
+ UserEntity user = userRepo.findByRootOrgIdAndLoginName(rootOrgId, loginName);
|
|
|
+ if (user == null) {
|
|
|
+ throw new RuntimeException("该用户不存在");
|
|
|
+ } else if (!user.getEnable()) {
|
|
|
+ throw new RuntimeException("该用户被禁用");
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- @ApiOperation(value = "第三方机构接入", notes = "第三方机构接入")
|
|
|
- @PostMapping("/thirdPartyAccess/{orgId}")
|
|
|
- @Deprecated
|
|
|
- public ResponseEntity thirdPartyAccess(@PathVariable long orgId, @RequestParam String userid,
|
|
|
- @RequestParam String appid, @RequestParam String timestamp,
|
|
|
- @RequestParam String token) {
|
|
|
- try {
|
|
|
- UserInfo userInfo = userService.thirdPartyAccess(orgId, userid, appid, timestamp,
|
|
|
- token);
|
|
|
- return new ResponseEntity(userInfo, HttpStatus.OK);
|
|
|
- } catch (Exception e) {
|
|
|
- return new ResponseEntity(new ErrorMsg(e.getMessage()),
|
|
|
- HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
- }
|
|
|
- }
|
|
|
+ LoginInfo loginInfo = new LoginInfo();
|
|
|
+ loginInfo.setAccountType(AccountType.COMMON_LOGIN_NAME.getCode());
|
|
|
+ loginInfo.setAccountValue(user.getLoginName());
|
|
|
+ loginInfo.setPassword(user.getPassword());
|
|
|
+ loginInfo.setRootOrgId(String.valueOf(user.getRootOrgId()));
|
|
|
+ User loginUser = authService.login(loginInfo);
|
|
|
|
|
|
- @ApiOperation(value = "登出", notes = "登出")
|
|
|
- @PostMapping("/logout")
|
|
|
- @Deprecated
|
|
|
- public ResponseEntity logout(HttpServletRequest request) {
|
|
|
- AccessUser accessUser = null;
|
|
|
- userService.logout(accessUser);
|
|
|
- return new ResponseEntity(HttpStatus.OK);
|
|
|
+ Map<String, Object> ret = Maps.newHashMap();
|
|
|
+ ret.put("userId", loginUser.getUserId());
|
|
|
+ ret.put("token", loginUser.getUserToken());
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "查询评卷员", notes = "查询")
|
|
|
- @GetMapping("/marker")
|
|
|
- public ResponseEntity getMarker(HttpServletRequest request) {
|
|
|
- cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
|
|
|
- return new ResponseEntity(userService.getMarker(accessUser.getRootOrgId()), HttpStatus.OK);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "查询所有评卷员(不分页)", notes = "查询")
|
|
|
+ @GetMapping("/getMarkerListNoPageable")
|
|
|
+ public List<UserEntity> getMarkerListNoPageable(HttpServletRequest request) {
|
|
|
|
|
|
- @ApiOperation(value = "查询评卷员带分页", notes = "查询评卷员带分页")
|
|
|
- @GetMapping("/all/marker/{curPage}/{pageSize}")
|
|
|
- public ResponseEntity getAllMark(@ModelAttribute UserEntity user, @PathVariable Integer curPage,
|
|
|
- @PathVariable Integer pageSize, HttpServletRequest request) {
|
|
|
- cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
|
|
|
- if (accessUser != null) {
|
|
|
- user.setRootOrgId(accessUser.getRootOrgId());
|
|
|
- return new ResponseEntity(
|
|
|
- userService.getAllMaker(user, new PageRequest(curPage - 1, pageSize)),
|
|
|
- HttpStatus.OK);
|
|
|
- } else {
|
|
|
- return new ResponseEntity(new PageImpl<UserEntity>(new ArrayList<UserEntity>()),
|
|
|
- HttpStatus.OK);
|
|
|
- }
|
|
|
+ RoleEntity role = roleRepo.findByCode(RoleMeta.MARKER.name());
|
|
|
+
|
|
|
+ Specification<UserEntity> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ predicates.add(cb.equal(root.get("rootOrgId"), getRootOrgId()));
|
|
|
+
|
|
|
+ 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"), role.getId());
|
|
|
+ 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()]));
|
|
|
+ };
|
|
|
+
|
|
|
+ List<UserEntity> userList = userRepo.findAll(specification);
|
|
|
+ return userList;
|
|
|
}
|
|
|
|
|
|
}
|