| @@ -24,10 +24,20 @@ open class SkillService( | |||||
| return skill | return skill | ||||
| } | } | ||||
| open fun updateSkill(req: NewSkillRequest, skill: Skill): Skill { | |||||
| skill.apply { | |||||
| name = req.name | |||||
| code = req.code | |||||
| description = req.description | |||||
| } | |||||
| skillRepository.save(skill) | |||||
| return skill | |||||
| } | |||||
| open fun saveOrUpdate(req: NewSkillRequest): Skill { | open fun saveOrUpdate(req: NewSkillRequest): Skill { | ||||
| val skill = if(req.id != null) find(req.id).get() else Skill() | val skill = if(req.id != null) find(req.id).get() else Skill() | ||||
| if (req.id != null) { | if (req.id != null) { | ||||
| // updateSkill(req, skill) | |||||
| updateSkill(req, skill) | |||||
| } else { | } else { | ||||
| saveSkill(req) | saveSkill(req) | ||||
| } | } | ||||
| @@ -175,7 +175,7 @@ public class GroupService extends AbstractBaseEntityService<Group, Long, GroupRe | |||||
| @Transactional(rollbackFor = Exception.class) | @Transactional(rollbackFor = Exception.class) | ||||
| public List<Map<String, Object>> listGroupAuth(Map<String, Object> args) { | |||||
| public List<Map<String, Object>> listAuth(Map<String, Object> args) { | |||||
| StringBuilder sql = new StringBuilder("SELECT" | StringBuilder sql = new StringBuilder("SELECT" | ||||
| + " a.id, " | + " a.id, " | ||||
| @@ -183,8 +183,12 @@ public class GroupService extends AbstractBaseEntityService<Group, Long, GroupRe | |||||
| + " a.authority," | + " a.authority," | ||||
| + " a.name," | + " a.name," | ||||
| + " a.description, "); | + " a.description, "); | ||||
| if (args.containsKey("groupId")) | |||||
| if (args.containsKey("groupId")) { | |||||
| sql.append(" EXISTS(SELECT 1 FROM group_authority ga WHERE a.id = ga.authId AND groupId = :groupId) AS v"); | sql.append(" EXISTS(SELECT 1 FROM group_authority ga WHERE a.id = ga.authId AND groupId = :groupId) AS v"); | ||||
| } | |||||
| else if (args.containsKey("userId")) { | |||||
| sql.append(" EXISTS(SELECT 1 FROM user_authority ua WHERE a.id = ua.authId AND userId = :userId) AS v"); | |||||
| } | |||||
| else | else | ||||
| sql.append(" 0 AS v"); | sql.append(" 0 AS v"); | ||||
| sql.append(" FROM authority a" | sql.append(" FROM authority a" | ||||
| @@ -7,6 +7,7 @@ import java.util.Map; | |||||
| import java.util.Optional; | import java.util.Optional; | ||||
| import java.util.Set; | import java.util.Set; | ||||
| import java.util.Date; | import java.util.Date; | ||||
| import java.util.stream.Collectors; | |||||
| import com.ffii.tsms.modules.common.service.AuditLogService; | import com.ffii.tsms.modules.common.service.AuditLogService; | ||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| @@ -184,6 +185,25 @@ public class UserService extends AbstractBaseEntityService<User, Long, UserRepos | |||||
| Map.of(Params.ID, id)); | Map.of(Params.ID, id)); | ||||
| } | } | ||||
| @Transactional(rollbackFor = Exception.class) | |||||
| public List<Map<String, Object>> listUserAuth(Map<String, Object> args) { | |||||
| StringBuilder sql = new StringBuilder("SELECT" | |||||
| + " a.id, " | |||||
| + " a.module," | |||||
| + " a.authority," | |||||
| + " a.name," | |||||
| + " a.description, "); | |||||
| if (args.containsKey("userId")) | |||||
| sql.append(" EXISTS(SELECT 1 FROM user_authority ua WHERE a.id = ua.authId AND userId = :userId) AS v"); | |||||
| else | |||||
| sql.append(" 0 AS v"); | |||||
| sql.append(" FROM authority a" | |||||
| + " ORDER BY a.module, a.name"); | |||||
| return jdbcDao.queryForList(sql.toString(), args); | |||||
| } | |||||
| public List<Integer> listUserGroupId(long id) { | public List<Integer> listUserGroupId(long id) { | ||||
| return jdbcDao.queryForInts( | return jdbcDao.queryForInts( | ||||
| "SELECT" | "SELECT" | ||||
| @@ -201,47 +221,28 @@ public class UserService extends AbstractBaseEntityService<User, Long, UserRepos | |||||
| } | } | ||||
| BeanUtils.copyProperties(req,instance); | BeanUtils.copyProperties(req,instance); | ||||
| instance = save(instance); | instance = save(instance); | ||||
| // long id = instance.getId(); | |||||
| // List<Map<String, Integer>> groupBatchInsertValues = req.getAddGroupIds().stream() | |||||
| // .map(groupId -> Map.of("userId", (int) id, "groupId", groupId)) | |||||
| // .collect(Collectors.toList()); | |||||
| // List<Map<String, Integer>> groupBatchDeleteValues = req.getRemoveGroupIds().stream() | |||||
| // .map(groupId -> Map.of("userId", (int) id, "groupId", groupId)) | |||||
| // .collect(Collectors.toList()); | |||||
| // if (!groupBatchInsertValues.isEmpty()) { | |||||
| // jdbcDao.batchUpdate( | |||||
| // "INSERT IGNORE INTO user_group (groupId,userId)" | |||||
| // + " VALUES (:groupId, :userId)", | |||||
| // groupBatchInsertValues); | |||||
| // } | |||||
| // if (!groupBatchDeleteValues.isEmpty()) { | |||||
| // jdbcDao.batchUpdate( | |||||
| // "DELETE FROM user_group" | |||||
| // + " WHERE groupId = :groupId AND userId = :userId", | |||||
| // groupBatchDeleteValues); | |||||
| // } | |||||
| // List<Map<String, Integer>> authBatchInsertValues = req.getAddAuthIds().stream() | |||||
| // .map(authId -> Map.of("userId", (int)id, "authId", authId)) | |||||
| // .collect(Collectors.toList()); | |||||
| // List<Map<String, Integer>> authBatchDeleteValues = req.getRemoveAuthIds().stream() | |||||
| // .map(authId -> Map.of("userId", (int)id, "authId", authId)) | |||||
| // .collect(Collectors.toList()); | |||||
| // if (!authBatchInsertValues.isEmpty()) { | |||||
| // jdbcDao.batchUpdate( | |||||
| // "INSERT IGNORE INTO user_authority (userId, authId)" | |||||
| // + " VALUES (:userId, :authId)", | |||||
| // authBatchInsertValues); | |||||
| // } | |||||
| // if (!authBatchDeleteValues.isEmpty()) { | |||||
| // jdbcDao.batchUpdate( | |||||
| // "DELETE FROM user_authority" | |||||
| // + " WHERE userId = :userId AND authId = :authId", | |||||
| // authBatchDeleteValues); | |||||
| // } | |||||
| long id = instance.getId(); | |||||
| List<Map<String, Integer>> authBatchInsertValues = req.getAddAuthIds().stream() | |||||
| .map(authId -> Map.of("userId", (int)id, "authId", authId)) | |||||
| .collect(Collectors.toList()); | |||||
| List<Map<String, Integer>> authBatchDeleteValues = req.getRemoveAuthIds().stream() | |||||
| .map(authId -> Map.of("userId", (int)id, "authId", authId)) | |||||
| .collect(Collectors.toList()); | |||||
| if (!authBatchInsertValues.isEmpty()) { | |||||
| jdbcDao.batchUpdate( | |||||
| "INSERT IGNORE INTO user_authority (userId, authId)" | |||||
| + " VALUES (:userId, :authId)", | |||||
| authBatchInsertValues); | |||||
| } | |||||
| if (!authBatchDeleteValues.isEmpty()) { | |||||
| jdbcDao.batchUpdate( | |||||
| "DELETE FROM user_authority" | |||||
| + " WHERE userId = :userId ", | |||||
| // + "AND authId = :authId", | |||||
| authBatchDeleteValues); | |||||
| } | |||||
| return instance; | return instance; | ||||
| } | } | ||||
| @@ -1,6 +1,7 @@ | |||||
| package com.ffii.tsms.modules.user.service.res; | package com.ffii.tsms.modules.user.service.res; | ||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Map; | |||||
| import com.ffii.tsms.modules.user.entity.User; | import com.ffii.tsms.modules.user.entity.User; | ||||
| @@ -16,6 +17,7 @@ public class LoadUserRes { | |||||
| this.data = data; | this.data = data; | ||||
| this.authIds = authIds; | this.authIds = authIds; | ||||
| this.groupIds = groupIds; | this.groupIds = groupIds; | ||||
| // this.auths = auths; | |||||
| } | } | ||||
| public User getData() { | public User getData() { | ||||
| @@ -42,4 +44,5 @@ public class LoadUserRes { | |||||
| this.groupIds = groupIds; | this.groupIds = groupIds; | ||||
| } | } | ||||
| } | } | ||||
| @@ -78,14 +78,20 @@ public class GroupController{ | |||||
| .build())); | .build())); | ||||
| } | } | ||||
| @GetMapping("/auth/combo/{id}") | |||||
| public RecordsRes<Map<String, Object>> authComboJson(HttpServletRequest request, @PathVariable("id") int id) throws ServletRequestBindingException { | |||||
| @GetMapping("/auth/{target}/{id}") | |||||
| public RecordsRes<Map<String, Object>> authComboJson(HttpServletRequest request, @PathVariable("id") int id, @PathVariable("target") String target) throws ServletRequestBindingException { | |||||
| System.out.println(request); | 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")){ | |||||
| args.put("groupId", id); | args.put("groupId", id); | ||||
| } else { | |||||
| args.put("userId", id); | |||||
| return new RecordsRes<>(groupService.listGroupAuth(args)); | |||||
| } | |||||
| } | |||||
| return new RecordsRes<>(groupService.listAuth(args)); | |||||
| } | } | ||||
| } | } | ||||
| @@ -1,6 +1,7 @@ | |||||
| package com.ffii.tsms.modules.user.web; | package com.ffii.tsms.modules.user.web; | ||||
| import java.io.UnsupportedEncodingException; | import java.io.UnsupportedEncodingException; | ||||
| import java.util.Map; | |||||
| import org.apache.commons.logging.Log; | import org.apache.commons.logging.Log; | ||||
| import org.apache.commons.logging.LogFactory; | import org.apache.commons.logging.LogFactory; | ||||
| @@ -73,11 +74,13 @@ public class UserController{ | |||||
| @PreAuthorize("hasAuthority('VIEW_USER')") | @PreAuthorize("hasAuthority('VIEW_USER')") | ||||
| public LoadUserRes load(@PathVariable long id) { | public LoadUserRes load(@PathVariable long id) { | ||||
| LoadUserRes test = new LoadUserRes( | LoadUserRes test = new LoadUserRes( | ||||
| userService.find(id).orElseThrow(NotFoundException::new), | |||||
| userService.listUserAuthId(id), | |||||
| userService.listUserGroupId(id)); | |||||
| logger.info("Test List user2"); | |||||
| logger.info(test); | |||||
| userService.find(id).orElseThrow(NotFoundException::new), | |||||
| userService.listUserAuthId(id), | |||||
| userService.listUserGroupId(id) | |||||
| // userService.listUserAuth(Map.of("userId", id)) | |||||
| ); | |||||
| logger.info("printing test LoadUserRes"); | |||||
| logger.info(test); | |||||
| return test; | return test; | ||||
| } | } | ||||