|
@@ -1,285 +1,285 @@
|
|
|
-package cn.com.qmth.examcloud.service.core.api;
|
|
|
-
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-import java.util.stream.Stream;
|
|
|
-
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-
|
|
|
-import org.apache.commons.lang.StringEscapeUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.data.domain.PageImpl;
|
|
|
-import org.springframework.data.domain.PageRequest;
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
-import org.springframework.util.StringUtils;
|
|
|
-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;
|
|
|
-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 cn.com.qmth.examcloud.common.uac.annotation.Uac;
|
|
|
-import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
|
|
|
-import cn.com.qmth.examcloud.common.uac.enums.RoleMeta;
|
|
|
-import cn.com.qmth.examcloud.common.uac.enums.UacPolicy;
|
|
|
-import cn.com.qmth.examcloud.common.util.ErrorMsg;
|
|
|
-import cn.com.qmth.examcloud.service.core.dto.UserInfo;
|
|
|
-import cn.com.qmth.examcloud.service.core.entity.User;
|
|
|
-import cn.com.qmth.examcloud.service.core.enums.UserType;
|
|
|
-import cn.com.qmth.examcloud.service.core.repo.UserRepo;
|
|
|
-import cn.com.qmth.examcloud.service.core.service.UserService;
|
|
|
-
|
|
|
-/**
|
|
|
- * 用户服务API
|
|
|
- * Created by songyue on 17/1/13.
|
|
|
- */
|
|
|
-@RestController
|
|
|
-@RequestMapping("${app.api.root}/user")
|
|
|
-public class UserApi {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- UserService userService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- UserRepo userRepo;
|
|
|
-
|
|
|
-
|
|
|
- @ApiOperation(value = "查询所有用户", notes = "分页带查询")
|
|
|
- @GetMapping("/all/{curPage}/{pageSize}")
|
|
|
- public ResponseEntity getAllUser(@ModelAttribute User userCriteria,
|
|
|
- @PathVariable Integer curPage,
|
|
|
- @PathVariable Integer pageSize,
|
|
|
- HttpServletRequest request) {
|
|
|
- AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
- if (accessUser != null) {
|
|
|
- if (accessUser.getRootOrgId() == 0) {
|
|
|
- return new ResponseEntity(userService.findOrgUser(userCriteria,
|
|
|
- new PageRequest(curPage - 1, pageSize)), HttpStatus.OK);
|
|
|
- } else {
|
|
|
- userCriteria.setRootOrgId(accessUser.getRootOrgId());
|
|
|
- }
|
|
|
- } else {
|
|
|
- return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
|
- }
|
|
|
- return new ResponseEntity(userService.findAll(userCriteria,
|
|
|
- new PageRequest(curPage - 1, pageSize)), HttpStatus.OK);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "按id查询用户", notes = "id查询")
|
|
|
- @GetMapping("/{id}")
|
|
|
- public ResponseEntity getUserById(@PathVariable long id) {
|
|
|
- return new ResponseEntity(userRepo.findOne(id), HttpStatus.OK);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "按orgId查询用户", notes = "机构id查询机构用户")
|
|
|
- @GetMapping("/org/{orgId}")
|
|
|
- public ResponseEntity getUserByOrgId(@PathVariable long orgId) {
|
|
|
- List<User> userList = userRepo.findByOrgIdAndType(orgId, UserType.NOT_STUDENT.name());
|
|
|
- return new ResponseEntity(userList, HttpStatus.OK);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "按rootOrgId查询用户", notes = "根机构id查询机构用户")
|
|
|
- @GetMapping("/rootOrg/{rootOrgId}")
|
|
|
- public ResponseEntity getUserByRootOrgId(@PathVariable long rootOrgId) {
|
|
|
- List<User> userList = userRepo.findByRootOrgIdAndType(rootOrgId, UserType.NOT_STUDENT.name());
|
|
|
- return new ResponseEntity(userList, HttpStatus.OK);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "新增用户", notes = "新增")
|
|
|
- @PostMapping
|
|
|
- public ResponseEntity addUser(@RequestBody User user, HttpServletRequest request) {
|
|
|
- AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
- if (accessUser != null) {
|
|
|
- if (accessUser.getRootOrgId() != 0) {
|
|
|
- user.setRootOrgId(accessUser.getRootOrgId());
|
|
|
- } else {
|
|
|
- user.setRootOrgId(user.getOrgId());
|
|
|
- }
|
|
|
- } else {
|
|
|
- return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
|
- }
|
|
|
- try {
|
|
|
- return new ResponseEntity(userService.save(user), HttpStatus.CREATED);
|
|
|
- } catch (Exception e) {
|
|
|
- return new ResponseEntity(new ErrorMsg(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "更新用户", notes = "更新")
|
|
|
- @PutMapping
|
|
|
- public ResponseEntity updateUser(@RequestBody User user, HttpServletRequest request) {
|
|
|
- AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
- if (accessUser != null) {
|
|
|
- if (accessUser.getRootOrgId() != 0) {
|
|
|
- user.setRootOrgId(accessUser.getRootOrgId());
|
|
|
- } else {
|
|
|
- user.setRootOrgId(user.getOrgId());
|
|
|
- }
|
|
|
- } else {
|
|
|
- return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
|
- }
|
|
|
- try {
|
|
|
- return new ResponseEntity(userService.update(user.getId(), user), HttpStatus.OK);
|
|
|
- } catch (Exception e) {
|
|
|
- return new ResponseEntity(new ErrorMsg(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "重置用户密码", notes = "重置密码")
|
|
|
- @PutMapping("/resetPass/{id}")
|
|
|
- public ResponseEntity resetPass(@PathVariable String id) {
|
|
|
- List<Long> ids = Stream.of(id.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
- .collect(Collectors.toList());
|
|
|
- for (Long userId : ids) {
|
|
|
- userService.initPassword(userId);
|
|
|
- }
|
|
|
- return new ResponseEntity(HttpStatus.OK);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "启用用户", notes = "启用用户")
|
|
|
- @PutMapping("/enable/{ids}")
|
|
|
- public ResponseEntity enableUser(@PathVariable String ids) {
|
|
|
- List<Long> userIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
- .collect(Collectors.toList());
|
|
|
- for (Long userId : userIds) {
|
|
|
- User user = userRepo.findOne(userId);
|
|
|
- user.setEnable(true);
|
|
|
- user.setUpdateTime(new Date());
|
|
|
- userRepo.save(user);
|
|
|
- }
|
|
|
- return new ResponseEntity(HttpStatus.OK);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "禁用用户", notes = "禁用用户")
|
|
|
- @PutMapping("/disable/{ids}")
|
|
|
- public ResponseEntity disableUser(@PathVariable String ids) {
|
|
|
- List<Long> userIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
- .collect(Collectors.toList());
|
|
|
- for (Long userId : userIds) {
|
|
|
- User user = userRepo.findOne(userId);
|
|
|
- user.setEnable(false);
|
|
|
- user.setUpdateTime(new Date());
|
|
|
- userRepo.save(user);
|
|
|
- }
|
|
|
- return new ResponseEntity(HttpStatus.OK);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "修改用户密码", notes = "修改密码")
|
|
|
- @PutMapping("/password")
|
|
|
- public ResponseEntity updatePass(@RequestParam long userId, @RequestParam String password) {
|
|
|
- String realPassword = StringEscapeUtils.unescapeJavaScript(password);
|
|
|
- userRepo.updatePasswordById(userId, realPassword);
|
|
|
- return new ResponseEntity(HttpStatus.OK);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "修改用户密码", notes = "修改密码")
|
|
|
- @PutMapping("/stu-password")
|
|
|
- @Uac(roles = {RoleMeta.STUDENT}, policy = UacPolicy.IN)
|
|
|
- public ResponseEntity stuPassword(@RequestParam("oldPassword") String oldPassword,
|
|
|
- @RequestParam("newPassword") String newPassword,
|
|
|
- HttpServletRequest request) {
|
|
|
- AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
- if (StringUtils.isEmpty(oldPassword) || StringUtils.isEmpty(newPassword)) {
|
|
|
- return new ResponseEntity(new ErrorMsg("原密码不正确"), HttpStatus.BAD_REQUEST);
|
|
|
- } else {
|
|
|
- Long userId = accessUser.getUserId();
|
|
|
- User user = userRepo.findOne(userId);
|
|
|
- if (!oldPassword.equals(user.getPassword())) {
|
|
|
- return new ResponseEntity(new ErrorMsg("原密码不正确"), HttpStatus.BAD_REQUEST);
|
|
|
- }
|
|
|
- userRepo.updatePasswordById(userId, newPassword);
|
|
|
- return new ResponseEntity(HttpStatus.OK);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "按id删除用户", notes = "删除")
|
|
|
- @DeleteMapping("/{ids}")
|
|
|
- @Uac(roles = {RoleMeta.SUPER_ADMIN}, policy = UacPolicy.IN)
|
|
|
- public ResponseEntity 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")
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "二级登录", notes = "二级登录")
|
|
|
- @PostMapping("/login/{orgId}")
|
|
|
- public ResponseEntity login(@PathVariable long orgId,
|
|
|
- @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);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "登出", notes = "登出")
|
|
|
- @PostMapping("/logout")
|
|
|
- public ResponseEntity logout(HttpServletRequest request) {
|
|
|
- AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
- userService.logout(accessUser);
|
|
|
- return new ResponseEntity(HttpStatus.OK);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "查询评卷员", notes = "查询")
|
|
|
- @GetMapping("/marker")
|
|
|
- public ResponseEntity getMarker(HttpServletRequest request) {
|
|
|
- AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
- return new ResponseEntity(userService.getMarker(accessUser.getRootOrgId()), HttpStatus.OK);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "新增评卷员", notes = "新增")
|
|
|
- @PostMapping("/marker")
|
|
|
- public ResponseEntity saveMarker(@RequestParam String loginName,@RequestParam String name,HttpServletRequest request) {
|
|
|
- AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
- return new ResponseEntity(userService.saveMarker(accessUser.getRootOrgId(),loginName,name), HttpStatus.OK);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value="查询评卷员带分页",notes="查询评卷员带分页")
|
|
|
- @GetMapping("/all/marker/{curPage}/{pageSize}")
|
|
|
- public ResponseEntity getAllMark(@ModelAttribute User user,
|
|
|
- @PathVariable Integer curPage,
|
|
|
- @PathVariable Integer pageSize,
|
|
|
- HttpServletRequest request){
|
|
|
- AccessUser accessUser = (AccessUser)request.getAttribute("accessUser");
|
|
|
- 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<User>(new ArrayList<User>()),HttpStatus.OK);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value="查询印刷项目经理",notes="查询印刷项目经理")
|
|
|
- @GetMapping("/allPrintPm")
|
|
|
- public ResponseEntity getAllPrintPm(){
|
|
|
- return new ResponseEntity(userRepo.findPrintPm(),HttpStatus.OK);
|
|
|
- }
|
|
|
-}
|
|
|
+package cn.com.qmth.examcloud.service.core.api;
|
|
|
+
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+
|
|
|
+import org.apache.commons.lang.StringEscapeUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.PageImpl;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+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;
|
|
|
+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 cn.com.qmth.examcloud.common.uac.annotation.Uac;
|
|
|
+import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
|
|
|
+import cn.com.qmth.examcloud.common.uac.enums.RoleMeta;
|
|
|
+import cn.com.qmth.examcloud.common.uac.enums.UacPolicy;
|
|
|
+import cn.com.qmth.examcloud.common.util.ErrorMsg;
|
|
|
+import cn.com.qmth.examcloud.service.core.dto.UserInfo;
|
|
|
+import cn.com.qmth.examcloud.service.core.entity.User;
|
|
|
+import cn.com.qmth.examcloud.service.core.enums.UserType;
|
|
|
+import cn.com.qmth.examcloud.service.core.repo.UserRepo;
|
|
|
+import cn.com.qmth.examcloud.service.core.service.UserService;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 用户服务API
|
|
|
+ * Created by songyue on 17/1/13.
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("${app.api.root}/user")
|
|
|
+public class UserApi {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ UserService userService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ UserRepo userRepo;
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询所有用户", notes = "分页带查询")
|
|
|
+ @GetMapping("/all/{curPage}/{pageSize}")
|
|
|
+ public ResponseEntity getAllUser(@ModelAttribute User userCriteria,
|
|
|
+ @PathVariable Integer curPage,
|
|
|
+ @PathVariable Integer pageSize,
|
|
|
+ HttpServletRequest request) {
|
|
|
+ AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
+ if (accessUser != null) {
|
|
|
+ if (accessUser.getRootOrgId() == 0) {
|
|
|
+ return new ResponseEntity(userService.findOrgUser(userCriteria,
|
|
|
+ new PageRequest(curPage - 1, pageSize)), HttpStatus.OK);
|
|
|
+ } else {
|
|
|
+ userCriteria.setRootOrgId(accessUser.getRootOrgId());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
|
+ }
|
|
|
+ return new ResponseEntity(userService.findAll(userCriteria,
|
|
|
+ new PageRequest(curPage - 1, pageSize)), HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "按id查询用户", notes = "id查询")
|
|
|
+ @GetMapping("/{id}")
|
|
|
+ public ResponseEntity getUserById(@PathVariable long id) {
|
|
|
+ return new ResponseEntity(userRepo.findOne(id), HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "按orgId查询用户", notes = "机构id查询机构用户")
|
|
|
+ @GetMapping("/org/{orgId}")
|
|
|
+ public ResponseEntity getUserByOrgId(@PathVariable long orgId) {
|
|
|
+ List<User> userList = userRepo.findByOrgIdAndType(orgId, UserType.NOT_STUDENT.name());
|
|
|
+ return new ResponseEntity(userList, HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "按rootOrgId查询用户", notes = "根机构id查询机构用户")
|
|
|
+ @GetMapping("/rootOrg/{rootOrgId}")
|
|
|
+ public ResponseEntity getUserByRootOrgId(@PathVariable long rootOrgId) {
|
|
|
+ List<User> userList = userRepo.findByRootOrgIdAndType(rootOrgId, UserType.NOT_STUDENT.name());
|
|
|
+ return new ResponseEntity(userList, HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "新增用户", notes = "新增")
|
|
|
+ @PostMapping
|
|
|
+ public ResponseEntity addUser(@RequestBody User user, HttpServletRequest request) {
|
|
|
+ AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
+ if (accessUser != null) {
|
|
|
+ if (accessUser.getRootOrgId() != 0) {
|
|
|
+ user.setRootOrgId(accessUser.getRootOrgId());
|
|
|
+ } else {
|
|
|
+ user.setRootOrgId(user.getOrgId());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return new ResponseEntity(userService.save(user), HttpStatus.CREATED);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return new ResponseEntity(new ErrorMsg(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "更新用户", notes = "更新")
|
|
|
+ @PutMapping
|
|
|
+ public ResponseEntity updateUser(@RequestBody User user, HttpServletRequest request) {
|
|
|
+ AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
+ if (accessUser != null) {
|
|
|
+ if (accessUser.getRootOrgId() != 0) {
|
|
|
+ user.setRootOrgId(accessUser.getRootOrgId());
|
|
|
+ } else {
|
|
|
+ user.setRootOrgId(user.getOrgId());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return new ResponseEntity(userService.update(user.getId(), user), HttpStatus.OK);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return new ResponseEntity(new ErrorMsg(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "重置用户密码", notes = "重置密码")
|
|
|
+ @PutMapping("/resetPass/{id}")
|
|
|
+ public ResponseEntity resetPass(@PathVariable String id) {
|
|
|
+ List<Long> ids = Stream.of(id.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ for (Long userId : ids) {
|
|
|
+ userService.initPassword(userId);
|
|
|
+ }
|
|
|
+ return new ResponseEntity(HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "启用用户", notes = "启用用户")
|
|
|
+ @PutMapping("/enable/{ids}")
|
|
|
+ public ResponseEntity enableUser(@PathVariable String ids) {
|
|
|
+ List<Long> userIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ for (Long userId : userIds) {
|
|
|
+ User user = userRepo.findOne(userId);
|
|
|
+ user.setEnable(true);
|
|
|
+ user.setUpdateTime(new Date());
|
|
|
+ userRepo.save(user);
|
|
|
+ }
|
|
|
+ return new ResponseEntity(HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "禁用用户", notes = "禁用用户")
|
|
|
+ @PutMapping("/disable/{ids}")
|
|
|
+ public ResponseEntity disableUser(@PathVariable String ids) {
|
|
|
+ List<Long> userIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ for (Long userId : userIds) {
|
|
|
+ User user = userRepo.findOne(userId);
|
|
|
+ user.setEnable(false);
|
|
|
+ user.setUpdateTime(new Date());
|
|
|
+ userRepo.save(user);
|
|
|
+ }
|
|
|
+ return new ResponseEntity(HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "修改用户密码", notes = "修改密码")
|
|
|
+ @PutMapping("/password")
|
|
|
+ public ResponseEntity updatePass(@RequestParam long userId, @RequestParam String password) {
|
|
|
+ String realPassword = StringEscapeUtils.unescapeJavaScript(password);
|
|
|
+ userRepo.updatePasswordById(userId, realPassword);
|
|
|
+ return new ResponseEntity(HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "修改用户密码", notes = "修改密码")
|
|
|
+ @PutMapping("/stu-password")
|
|
|
+ @Uac(roles = {RoleMeta.STUDENT}, policy = UacPolicy.IN)
|
|
|
+ public ResponseEntity stuPassword(@RequestParam("oldPassword") String oldPassword,
|
|
|
+ @RequestParam("newPassword") String newPassword,
|
|
|
+ HttpServletRequest request) {
|
|
|
+ AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
+ if (StringUtils.isEmpty(oldPassword) || StringUtils.isEmpty(newPassword)) {
|
|
|
+ return new ResponseEntity(new ErrorMsg("原密码不正确"), HttpStatus.BAD_REQUEST);
|
|
|
+ } else {
|
|
|
+ Long userId = accessUser.getUserId();
|
|
|
+ User user = userRepo.findOne(userId);
|
|
|
+ if (!oldPassword.equals(user.getPassword())) {
|
|
|
+ return new ResponseEntity(new ErrorMsg("原密码不正确"), HttpStatus.BAD_REQUEST);
|
|
|
+ }
|
|
|
+ userRepo.updatePasswordById(userId, newPassword);
|
|
|
+ return new ResponseEntity(HttpStatus.OK);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "按id删除用户", notes = "删除")
|
|
|
+ @DeleteMapping("/{ids}")
|
|
|
+ @Uac(roles = {RoleMeta.SUPER_ADMIN}, policy = UacPolicy.IN)
|
|
|
+ public ResponseEntity 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")
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "二级登录", notes = "二级登录")
|
|
|
+ @PostMapping("/login/{orgId}")
|
|
|
+ public ResponseEntity login(@PathVariable long orgId,
|
|
|
+ @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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "登出", notes = "登出")
|
|
|
+ @PostMapping("/logout")
|
|
|
+ public ResponseEntity logout(HttpServletRequest request) {
|
|
|
+ AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
+ userService.logout(accessUser);
|
|
|
+ return new ResponseEntity(HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询评卷员", notes = "查询")
|
|
|
+ @GetMapping("/marker")
|
|
|
+ public ResponseEntity getMarker(HttpServletRequest request) {
|
|
|
+ AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
+ return new ResponseEntity(userService.getMarker(accessUser.getRootOrgId()), HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "新增评卷员", notes = "新增")
|
|
|
+ @PostMapping("/marker")
|
|
|
+ public ResponseEntity saveMarker(@RequestParam String loginName,@RequestParam String name,HttpServletRequest request) {
|
|
|
+ AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
+ return new ResponseEntity(userService.saveMarker(accessUser.getRootOrgId(),loginName,name), HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="查询评卷员带分页",notes="查询评卷员带分页")
|
|
|
+ @GetMapping("/all/marker/{curPage}/{pageSize}")
|
|
|
+ public ResponseEntity getAllMark(@ModelAttribute User user,
|
|
|
+ @PathVariable Integer curPage,
|
|
|
+ @PathVariable Integer pageSize,
|
|
|
+ HttpServletRequest request){
|
|
|
+ AccessUser accessUser = (AccessUser)request.getAttribute("accessUser");
|
|
|
+ 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<User>(new ArrayList<User>()),HttpStatus.OK);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="查询印刷项目经理",notes="查询印刷项目经理")
|
|
|
+ @GetMapping("/allPrintPm")
|
|
|
+ public ResponseEntity getAllPrintPm(){
|
|
|
+ return new ResponseEntity(userRepo.findPrintPm(),HttpStatus.OK);
|
|
|
+ }
|
|
|
+}
|