| @@ -1,6 +1,7 @@ | |||||
| package com.ffii.fpsms.modules.user.service; | package com.ffii.fpsms.modules.user.service; | ||||
| import java.util.Date; | import java.util.Date; | ||||
| import java.util.LinkedHashMap; | |||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Map; | import java.util.Map; | ||||
| import java.util.stream.Collectors; | import java.util.stream.Collectors; | ||||
| @@ -209,4 +210,13 @@ public class GroupService extends AbstractBaseEntityService<Group, Long, GroupRe | |||||
| return jdbcDao.queryForList(sql.toString(), args); | return jdbcDao.queryForList(sql.toString(), args); | ||||
| } | } | ||||
| @Transactional(rollbackFor = Exception.class) | |||||
| public Map<Integer, List<Map<String, Object>>> listAuthForUsers(List<Integer> userIds) { | |||||
| Map<Integer, List<Map<String, Object>>> result = new LinkedHashMap<>(); | |||||
| for (Integer userId : userIds) { | |||||
| result.put(userId, listAuth(Map.of("userId", userId))); | |||||
| } | |||||
| return result; | |||||
| } | |||||
| } | } | ||||
| @@ -185,8 +185,8 @@ public class UserService extends AbstractBaseEntityService<User, Long, UserRepos | |||||
| if (!authBatchDeleteValues.isEmpty()) { | if (!authBatchDeleteValues.isEmpty()) { | ||||
| jdbcDao.batchUpdate( | jdbcDao.batchUpdate( | ||||
| "DELETE FROM user_authority" | "DELETE FROM user_authority" | ||||
| + " WHERE userId = :userId ", | |||||
| // + "AND authId = :authId", | |||||
| + " WHERE userId = :userId " | |||||
| + " AND authId = :authId", | |||||
| authBatchDeleteValues); | authBatchDeleteValues); | ||||
| } | } | ||||
| if (!authBatchInsertValues.isEmpty()) { | if (!authBatchInsertValues.isEmpty()) { | ||||
| @@ -228,8 +228,8 @@ public class UserService extends AbstractBaseEntityService<User, Long, UserRepos | |||||
| if (!authBatchDeleteValues.isEmpty()) { | if (!authBatchDeleteValues.isEmpty()) { | ||||
| jdbcDao.batchUpdate( | jdbcDao.batchUpdate( | ||||
| "DELETE FROM user_authority" | "DELETE FROM user_authority" | ||||
| + " WHERE userId = :userId ", | |||||
| // + "AND authId = :authId", | |||||
| + " WHERE userId = :userId " | |||||
| + " AND authId = :authId", | |||||
| authBatchDeleteValues); | authBatchDeleteValues); | ||||
| } | } | ||||
| if (!authBatchInsertValues.isEmpty()) { | if (!authBatchInsertValues.isEmpty()) { | ||||
| @@ -1,6 +1,7 @@ | |||||
| package com.ffii.fpsms.modules.user.web; | package com.ffii.fpsms.modules.user.web; | ||||
| import java.util.HashMap; | import java.util.HashMap; | ||||
| import java.util.List; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| import org.apache.commons.logging.Log; | import org.apache.commons.logging.Log; | ||||
| @@ -11,6 +12,7 @@ import org.springframework.web.bind.annotation.DeleteMapping; | |||||
| import org.springframework.web.bind.annotation.GetMapping; | import org.springframework.web.bind.annotation.GetMapping; | ||||
| import org.springframework.web.bind.annotation.PathVariable; | import org.springframework.web.bind.annotation.PathVariable; | ||||
| import org.springframework.web.bind.annotation.PostMapping; | import org.springframework.web.bind.annotation.PostMapping; | ||||
| import org.springframework.web.bind.annotation.RequestParam; | |||||
| import org.springframework.web.bind.annotation.RequestBody; | import org.springframework.web.bind.annotation.RequestBody; | ||||
| import org.springframework.web.bind.annotation.RequestMapping; | import org.springframework.web.bind.annotation.RequestMapping; | ||||
| import org.springframework.web.bind.annotation.ResponseStatus; | import org.springframework.web.bind.annotation.ResponseStatus; | ||||
| @@ -80,7 +82,6 @@ public class GroupController{ | |||||
| @GetMapping("/auth/{target}/{id}") | @GetMapping("/auth/{target}/{id}") | ||||
| public RecordsRes<Map<String, Object>> authComboJson(HttpServletRequest request, @PathVariable("id") int id, @PathVariable("target") String target) throws ServletRequestBindingException { | public RecordsRes<Map<String, Object>> authComboJson(HttpServletRequest request, @PathVariable("id") int id, @PathVariable("target") String target) throws ServletRequestBindingException { | ||||
| System.out.println(request); | |||||
| Map<String, Object> args = new HashMap<>(); | Map<String, Object> args = new HashMap<>(); | ||||
| if (id != 0){ | if (id != 0){ | ||||
| if (target.equals("group")){ | if (target.equals("group")){ | ||||
| @@ -94,4 +95,11 @@ public class GroupController{ | |||||
| return new RecordsRes<>(groupService.listAuth(args)); | return new RecordsRes<>(groupService.listAuth(args)); | ||||
| } | } | ||||
| @GetMapping("/auth/user-batch") | |||||
| public Map<Integer, List<Map<String, Object>>> authBatchByUserIds( | |||||
| @RequestParam("userIds") List<Integer> userIds | |||||
| ) { | |||||
| return groupService.listAuthForUsers(userIds); | |||||
| } | |||||
| } | } | ||||
| @@ -78,7 +78,6 @@ public class UserController{ | |||||
| @GetMapping | @GetMapping | ||||
| // @PreAuthorize("hasAuthority('VIEW_USER')") | // @PreAuthorize("hasAuthority('VIEW_USER')") | ||||
| public ResponseEntity<List<UserRecord>> list(@ModelAttribute @Valid SearchUserReq req) { | public ResponseEntity<List<UserRecord>> list(@ModelAttribute @Valid SearchUserReq req) { | ||||
| logger.info("Test List user"); | |||||
| return ResponseEntity.ok(userService.search(req)); | return ResponseEntity.ok(userService.search(req)); | ||||
| } | } | ||||
| @@ -120,13 +119,10 @@ public class UserController{ | |||||
| @GetMapping("/{id}") | @GetMapping("/{id}") | ||||
| @PreAuthorize("hasAuthority('VIEW_USER')") | @PreAuthorize("hasAuthority('VIEW_USER')") | ||||
| public LoadUserRes load(@PathVariable long id) { | public LoadUserRes load(@PathVariable long id) { | ||||
| LoadUserRes test = new LoadUserRes( | |||||
| return new LoadUserRes( | |||||
| userService.find(id).orElseThrow(NotFoundException::new), | userService.find(id).orElseThrow(NotFoundException::new), | ||||
| userService.listUserAuthId(id), | userService.listUserAuthId(id), | ||||
| userService.listUserGroupId(id)); | userService.listUserGroupId(id)); | ||||
| logger.info("Test List user2"); | |||||
| logger.info(test); | |||||
| return test; | |||||
| } | } | ||||
| @GetMapping("/user-info/{id}") | @GetMapping("/user-info/{id}") | ||||
| // @PreAuthorize("hasAuthority('VIEW_USER')") | // @PreAuthorize("hasAuthority('VIEW_USER')") | ||||
| @@ -147,7 +143,6 @@ public class UserController{ | |||||
| // @ResponseStatus(HttpStatus.CREATED) | // @ResponseStatus(HttpStatus.CREATED) | ||||
| // @PreAuthorize("hasAuthority('MAINTAIN_USER')") | // @PreAuthorize("hasAuthority('MAINTAIN_USER')") | ||||
| public IdRes newRecord(@RequestBody @Valid NewUserReq req) throws UnsupportedEncodingException { | public IdRes newRecord(@RequestBody @Valid NewUserReq req) throws UnsupportedEncodingException { | ||||
| System.out.println(req.getUsername()); | |||||
| return new IdRes(userService.newRecord(req).getId()); | return new IdRes(userService.newRecord(req).getId()); | ||||
| } | } | ||||