| @@ -16,8 +16,6 @@ public class JwtResponse implements Serializable { | |||
| private final String refreshToken; | |||
| private final String role; | |||
| //private final Set<AbilityModel> abilities; | |||
| private final Long subDivisionId; | |||
| private final Boolean lotusNotesUser; | |||
| private final List<String> abilities; | |||
| public JwtResponse(String accessToken, String refreshToken, String role, User user, /*Set<AbilityModel>*/List<String> abilities) { | |||
| @@ -27,8 +25,6 @@ public class JwtResponse implements Serializable { | |||
| this.id = user.getId(); | |||
| this.name = user.getName(); | |||
| this.email = user.getEmail(); | |||
| this.subDivisionId = user.getSubDivisionId(); | |||
| this.lotusNotesUser = user.getLotusNotesUser(); | |||
| this.abilities = abilities; | |||
| } | |||
| @@ -60,16 +56,4 @@ public class JwtResponse implements Serializable { | |||
| return abilities; | |||
| } | |||
| public Long getSubDivisionId() { | |||
| return this.subDivisionId; | |||
| } | |||
| public Boolean isLotusNotesUser() { | |||
| return this.lotusNotesUser; | |||
| } | |||
| public Boolean getLotusNotesUser() { | |||
| return this.lotusNotesUser; | |||
| } | |||
| } | |||
| @@ -75,17 +75,6 @@ public class User extends BaseEntity<Long> implements UserDetails { | |||
| @Column | |||
| private String remarks; | |||
| @Column | |||
| private boolean lotusNotesUser = false; | |||
| @Column | |||
| private String post; | |||
| @Column | |||
| private Long subDivisionId; | |||
| @Column | |||
| private boolean reminderFlag; | |||
| public boolean isLocked() { | |||
| return this.locked == null ? false : this.locked; | |||
| @@ -248,44 +237,4 @@ public class User extends BaseEntity<Long> implements UserDetails { | |||
| this.department = department; | |||
| } | |||
| public boolean isLotusNotesUser() { | |||
| return this.lotusNotesUser; | |||
| } | |||
| public boolean getLotusNotesUser() { | |||
| return this.lotusNotesUser; | |||
| } | |||
| public void setLotusNotesUser(boolean lotusNotesUser) { | |||
| this.lotusNotesUser = lotusNotesUser; | |||
| } | |||
| public String getPost() { | |||
| return this.post; | |||
| } | |||
| public void setPost(String post) { | |||
| this.post = post; | |||
| } | |||
| public Long getSubDivisionId() { | |||
| return this.subDivisionId; | |||
| } | |||
| public void setSubDivisionId(Long subDivisionId) { | |||
| this.subDivisionId = subDivisionId; | |||
| } | |||
| public boolean isReminderFlag() { | |||
| return this.reminderFlag; | |||
| } | |||
| public boolean getReminderFlag() { | |||
| return this.reminderFlag; | |||
| } | |||
| public void setReminderFlag(boolean reminderFlag) { | |||
| this.reminderFlag = reminderFlag; | |||
| } | |||
| } | |||
| @@ -36,12 +36,10 @@ public class NewLionerUserReq { | |||
| private String phone2; | |||
| private String post; | |||
| @NotBlank | |||
| private Long subDivisionId; | |||
| private Long userGroupId; | |||
| private LocalDate expiryDate; | |||
| private String locale; | |||
| private String remarks; | |||
| private Boolean lotusNotesUser; | |||
| private Boolean reminderFlag; | |||
| @NotBlank | |||
| @@ -56,30 +54,6 @@ public class NewLionerUserReq { | |||
| private List<Long> addAuthIds; | |||
| // @NotNull | |||
| private List<Long> removeAuthIds; | |||
| public Boolean isLotusNotesUser() { | |||
| return this.lotusNotesUser; | |||
| } | |||
| public Boolean getLotusNotesUser() { | |||
| return this.lotusNotesUser; | |||
| } | |||
| public Boolean isReminderFlag() { | |||
| return this.reminderFlag; | |||
| } | |||
| public Boolean getReminderFlag() { | |||
| return this.reminderFlag; | |||
| } | |||
| public void setReminderFlag(Boolean reminderFlag) { | |||
| this.reminderFlag = reminderFlag; | |||
| } | |||
| public void setLotusNotesUser(Boolean lotusNotesUser) { | |||
| this.lotusNotesUser = lotusNotesUser; | |||
| } | |||
| public Long getId() { | |||
| return this.id; | |||
| @@ -234,12 +208,12 @@ public class NewLionerUserReq { | |||
| this.post = post; | |||
| } | |||
| public Long getSubDivisionId() { | |||
| return this.subDivisionId; | |||
| public Long getUserGroupId() { | |||
| return this.userGroupId; | |||
| } | |||
| public void setSubDivisionId(Long subDivisionId) { | |||
| this.subDivisionId = subDivisionId; | |||
| public void setUserGroupId(Long userGroupId) { | |||
| this.userGroupId = userGroupId; | |||
| } | |||
| public String getUsername() { | |||
| @@ -15,7 +15,6 @@ public class SearchUserReq { | |||
| private Integer subDivisionId; | |||
| private String email; | |||
| private String phone; | |||
| private Boolean isLotusNotesUser; | |||
| public Integer getId() { | |||
| return id; | |||
| @@ -117,16 +116,4 @@ public class SearchUserReq { | |||
| this.phone = phone; | |||
| } | |||
| public Boolean isIsLotusNotesUser() { | |||
| return this.isLotusNotesUser; | |||
| } | |||
| public Boolean getIsLotusNotesUser() { | |||
| return this.isLotusNotesUser; | |||
| } | |||
| public void setIsLotusNotesUser(Boolean isLotusNotesUser) { | |||
| this.isLotusNotesUser = isLotusNotesUser; | |||
| } | |||
| } | |||
| @@ -29,7 +29,8 @@ public class UpdateUserReq { | |||
| private String email; | |||
| @NotBlank | |||
| private String department; | |||
| private Integer userGroupId; | |||
| // @NotNull | |||
| private List<Integer> addGroupIds; | |||
| // @NotNull | |||
| @@ -92,6 +93,14 @@ public class UpdateUserReq { | |||
| this.firstname = firstname; | |||
| } | |||
| public Integer getUserGroupId() { | |||
| return userGroupId; | |||
| } | |||
| public void setUserGroupId(Integer userGroupId) { | |||
| this.userGroupId = userGroupId; | |||
| } | |||
| public List<Integer> getAddGroupIds() { | |||
| return addGroupIds; | |||
| } | |||
| @@ -13,6 +13,7 @@ import java.util.Optional; | |||
| import java.util.Set; | |||
| import java.util.stream.Collectors; | |||
| import org.apache.commons.collections4.Put; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import com.ffii.core.utils.BeanUtils; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| @@ -134,15 +135,10 @@ public class UserService extends AbstractBaseEntityService<User, Long, UserRepos | |||
| + " u.name , " | |||
| + " u.fullname, " | |||
| + " u.email, " | |||
| + " u.phone1, " | |||
| + " u.lotusNotesUser, " | |||
| + " u.reminderFlag, " | |||
| + " u.post, " | |||
| + " sd.name " | |||
| + " u.phone1 " | |||
| + " FROM `user` u " | |||
| + " LEFT JOIN `user` u1 ON u1.id = u.createdBy " | |||
| + " LEFT JOIN `user` u2 ON u2.id = u.modifiedBy " | |||
| + " LEFT JOIN sub_division sd ON sd.id = u.subDivisionId " | |||
| + " WHERE u.id = :id " | |||
| ); | |||
| @@ -214,19 +210,21 @@ public class UserService extends AbstractBaseEntityService<User, Long, UserRepos | |||
| + " u.remarks, " | |||
| + " u.fullname, " | |||
| + " u.post, " | |||
| + " u.lotusNotesUser, " | |||
| + " sd.name as subDivision" | |||
| + " ug.groupId " | |||
| // + " sd.name as subDivision" | |||
| + " FROM `user` u" | |||
| + " left join user_group ug on u.id = ug.userId" | |||
| + " left join sub_division sd on u.subDivisionId = sd.id " | |||
| // + " left join sub_division sd on u.subDivisionId = sd.id " | |||
| + " where u.deleted = false"); | |||
| if (req != null) { | |||
| if (req.getId() != null) | |||
| sql.append(" AND u.id = :id"); | |||
| if (req.getGroupId() != null) | |||
| if (req.getGroupId() != null) { | |||
| sql.append(" AND ug.groupId = :groupId"); | |||
| } | |||
| if (StringUtils.isNotBlank(req.getUsername())) { | |||
| req.setUsername("%" + req.getUsername() + "%"); | |||
| sql.append(" AND u.username LIKE :username"); | |||
| @@ -260,10 +258,6 @@ public class UserService extends AbstractBaseEntityService<User, Long, UserRepos | |||
| sql.append(" AND u.locked = :locked"); | |||
| } | |||
| if (req.getIsLotusNotesUser() != null) { | |||
| sql.append(" AND u.lotusNotesUser = :isLotusNotesUser"); | |||
| } | |||
| } | |||
| sql.append(" ORDER BY u.username asc"); | |||
| @@ -275,6 +269,16 @@ public class UserService extends AbstractBaseEntityService<User, Long, UserRepos | |||
| return jdbcDao.queryForList(sql.toString(), req, UserRecord.class); | |||
| } | |||
| public Integer getUserGroupId(long id) { | |||
| return jdbcDao.queryForInt( | |||
| "SELECT" | |||
| + " MAX(ug.groupId) AS groupId" | |||
| + " FROM user_group ug" | |||
| + " WHERE ug.userId = :id" | |||
| + " GROUP BY ug.userId", | |||
| Map.of(Params.ID, id)); | |||
| } | |||
| public List<Integer> listUserAuthId(long id) { | |||
| return jdbcDao.queryForInts( | |||
| "SELECT" | |||
| @@ -388,8 +392,8 @@ public class UserService extends AbstractBaseEntityService<User, Long, UserRepos | |||
| throw new UnprocessableEntityException(ErrorCodes.USERNAME_NOT_AVAILABLE); | |||
| } | |||
| String submitedPassword = req.getPassword(); | |||
| String pwdHash = passwordEncoder.encode(submitedPassword); | |||
| String submittedPassword = req.getPassword(); | |||
| String pwdHash = passwordEncoder.encode(submittedPassword); | |||
| req.setPassword(pwdHash); | |||
| User instance = new User(); | |||
| @@ -412,7 +416,7 @@ public class UserService extends AbstractBaseEntityService<User, Long, UserRepos | |||
| } | |||
| if (req.getPassword() != null && req.getPassword() != "" && req.getPassword().length() > 1) { | |||
| String submitedPassword = req.getPassword(); | |||
| String submittedPassword = req.getPassword(); | |||
| PasswordRule rule = new PasswordRule(settingsService); | |||
| if (!PasswordUtils.checkPwd(req.getPassword(), rule, req.getUsername())) { | |||
| @@ -427,7 +431,7 @@ public class UserService extends AbstractBaseEntityService<User, Long, UserRepos | |||
| }); | |||
| } | |||
| String pwdHash = passwordEncoder.encode(submitedPassword); | |||
| String pwdHash = passwordEncoder.encode(submittedPassword); | |||
| req.setPassword(pwdHash); | |||
| } else { | |||
| @@ -467,45 +471,62 @@ public class UserService extends AbstractBaseEntityService<User, Long, UserRepos | |||
| record = userPasswordHistoryService.save(record); | |||
| } | |||
| List<Map<String, Long>> authBatchInsertValues = req.getAddAuthIds().stream() | |||
| .map(authId -> Map.of("userId", id, "authId", authId)) | |||
| .collect(Collectors.toList()); | |||
| List<Map<String, Long>> authBatchDeleteValues = req.getRemoveAuthIds().stream() | |||
| .map(authId -> Map.of("userId", 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); | |||
| Map<String, Long> userGroupMap = new HashMap<>(); | |||
| userGroupMap.put("userId", instance.getId()); | |||
| userGroupMap.put("groupId", req.getUserGroupId()); | |||
| if (req.getUserGroupId() > 0) { // The group id is updated | |||
| jdbcDao.executeUpdate( | |||
| "DELETE FROM user_group" | |||
| + " WHERE userId = :userId;", | |||
| userGroupMap | |||
| ); | |||
| jdbcDao.executeUpdate( | |||
| "INSERT IGNORE INTO user_group (groupId,userId)" | |||
| + " VALUES (:groupId, :userId);", | |||
| userGroupMap | |||
| ); | |||
| } | |||
| List<Map<String, Long>> userBatchInsertValues = req.getAddGroupIds().stream() | |||
| .map(groupId -> Map.of("userId", id, "groupId", groupId)) | |||
| .collect(Collectors.toList()); | |||
| List<Map<String, Long>> userBatchDeleteValues = req.getRemoveGroupIds().stream() | |||
| .map(groupId -> Map.of("userId", id, "groupId", groupId)) | |||
| .collect(Collectors.toList()); | |||
| if (!userBatchInsertValues.isEmpty()) { | |||
| jdbcDao.batchUpdate( | |||
| "INSERT IGNORE INTO user_group (groupId,userId)" | |||
| + " VALUES (:groupId, :userId)", | |||
| userBatchInsertValues); | |||
| } | |||
| if (!userBatchDeleteValues.isEmpty()) { | |||
| jdbcDao.batchUpdate( | |||
| "DELETE FROM user_group" | |||
| + " WHERE groupId = :groupId AND userId = :userId", | |||
| userBatchDeleteValues); | |||
| } | |||
| // List<Map<String, Long>> authBatchInsertValues = req.getAddAuthIds().stream() | |||
| // .map(authId -> Map.of("userId", id, "authId", authId)) | |||
| // .collect(Collectors.toList()); | |||
| // List<Map<String, Long>> authBatchDeleteValues = req.getRemoveAuthIds().stream() | |||
| // .map(authId -> Map.of("userId", 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); | |||
| // } | |||
| // List<Map<String, Long>> userBatchInsertValues = req.getAddGroupIds().stream() | |||
| // .map(groupId -> Map.of("userId", id, "groupId", groupId)) | |||
| // .collect(Collectors.toList()); | |||
| // List<Map<String, Long>> userBatchDeleteValues = req.getRemoveGroupIds().stream() | |||
| // .map(groupId -> Map.of("userId", id, "groupId", groupId)) | |||
| // .collect(Collectors.toList()); | |||
| // if (!userBatchInsertValues.isEmpty()) { | |||
| // jdbcDao.batchUpdate( | |||
| // "INSERT IGNORE INTO user_group (groupId,userId)" | |||
| // + " VALUES (:groupId, :userId)", | |||
| // userBatchInsertValues); | |||
| // } | |||
| // if (!userBatchDeleteValues.isEmpty()) { | |||
| // jdbcDao.batchUpdate( | |||
| // "DELETE FROM user_group" | |||
| // + " WHERE groupId = :groupId AND userId = :userId", | |||
| // userBatchDeleteValues); | |||
| // } | |||
| // =====GET NEW AUDIT LOG=====// | |||
| if (instance != null && instance.getId() != null && instance.getId() > 0) { | |||
| @@ -13,6 +13,7 @@ public class UserRecord { | |||
| private String name; | |||
| private Integer companyId; | |||
| private Integer customerId; | |||
| private Integer groupId; | |||
| private String locale; | |||
| private String fullname; | |||
| private String firstname; | |||
| @@ -24,9 +25,7 @@ public class UserRecord { | |||
| private String phone1; | |||
| private String phone2; | |||
| private String remarks; | |||
| private Boolean lotusNotesUser; | |||
| private String post; | |||
| private String subDivision; | |||
| public Boolean isLocked() { | |||
| return this.locked; | |||
| @@ -35,10 +34,6 @@ public class UserRecord { | |||
| this.remarks = remarks; | |||
| } | |||
| public Boolean isLotusNotesUser() { | |||
| return this.lotusNotesUser; | |||
| } | |||
| public String getPost() { | |||
| return this.post; | |||
| } | |||
| @@ -107,6 +102,12 @@ public class UserRecord { | |||
| public void setCustomerId(Integer customerId) { | |||
| this.customerId = customerId; | |||
| } | |||
| public Integer getGroupId() { | |||
| return groupId; | |||
| } | |||
| public void setGroupId(Integer groupId) { | |||
| this.groupId = groupId; | |||
| } | |||
| public String getLocale() { | |||
| return locale; | |||
| } | |||
| @@ -170,19 +171,5 @@ public class UserRecord { | |||
| public String getRemarks() { | |||
| return remarks; | |||
| } | |||
| public void setLotusNotesUser(Boolean lotusNotesUser) { | |||
| this.lotusNotesUser = lotusNotesUser; | |||
| } | |||
| public Boolean getLotusNotesUser() { | |||
| return lotusNotesUser; | |||
| } | |||
| public String getSubDivision() { | |||
| return this.subDivision; | |||
| } | |||
| public void setSubDivision(String subDivision) { | |||
| this.subDivision = subDivision; | |||
| } | |||
| } | |||
| @@ -6,14 +6,16 @@ import com.ffii.lioner.modules.user.entity.User; | |||
| public class LoadUserRes { | |||
| private User data; | |||
| private Integer groupId; | |||
| private List<Integer> authIds; | |||
| private List<Integer> groupIds; | |||
| public LoadUserRes() { | |||
| } | |||
| public LoadUserRes(User data, List<Integer> authIds, List<Integer> groupIds) { | |||
| public LoadUserRes(User data, Integer groupId, List<Integer> authIds, List<Integer> groupIds) { | |||
| this.data = data; | |||
| this.groupId = groupId; | |||
| this.authIds = authIds; | |||
| this.groupIds = groupIds; | |||
| } | |||
| @@ -42,4 +44,12 @@ public class LoadUserRes { | |||
| this.groupIds = groupIds; | |||
| } | |||
| public Integer getGroupId() { | |||
| return groupId; | |||
| } | |||
| public void setGroupId(Integer groupId) { | |||
| this.groupId = groupId; | |||
| } | |||
| } | |||
| @@ -103,11 +103,12 @@ public class UserController { | |||
| @GetMapping("/{id}") | |||
| @PreAuthorize("hasAuthority('MAINTAIN_USER')") | |||
| public LoadUserRes load(@PathVariable long id) { | |||
| LoadUserRes test = new LoadUserRes( | |||
| LoadUserRes userRes = new LoadUserRes( | |||
| userService.find(id).orElseThrow(NotFoundException::new), | |||
| userService.getUserGroupId(id), | |||
| userService.listUserAuthId(id), | |||
| userService.listUserGroupId(id)); | |||
| return test; | |||
| return userRes; | |||
| } | |||
| // @Operation(summary = "delete user", responses = { @ApiResponse(responseCode = | |||
| @@ -288,22 +289,6 @@ public class UserController { | |||
| return new RecordsRes<>(temp); | |||
| } | |||
| @GetMapping("/lotusCombo") | |||
| public ResponseEntity<?> lotusCombo(@RequestParam(defaultValue = "") String username) throws Exception { | |||
| AtomicInteger tempId = new AtomicInteger(0); | |||
| List<Map<String, Object>> searchUser = ldapTemplate.search("", "(&(objectClass=*)(cn=*" + username + "*))", | |||
| (AttributesMapper<Map<String, Object>>) (attrs -> { | |||
| Map<String, Object> user = new HashMap<>(); | |||
| user.put("id", tempId.getAndIncrement()); | |||
| user.put("label", attrs.get("cn").get().toString()); | |||
| user.put("key", attrs.get("cn").get().toString()); | |||
| user.put("mail", attrs.get("mail").get().toString()); | |||
| return user; | |||
| })); | |||
| return ResponseEntity.ok(Map.of("records",searchUser)); | |||
| } | |||
| @GetMapping("/checkDuplicate") | |||
| public Map<String, Boolean> checkDuplicate(@RequestParam String name, Long id) { | |||
| boolean isNameTaken = userService.isNameTaken(name, id); | |||
| @@ -311,20 +296,6 @@ public class UserController { | |||
| "isTaken", isNameTaken); | |||
| } | |||
| @GetMapping("/getReminderFlag/{id}") | |||
| public Map<String, Object> getReminderFlag(@PathVariable Long id) { | |||
| User user = userService.find(id).get(); | |||
| return Map.of("isReminder", user.getReminderFlag()); | |||
| } | |||
| @PostMapping("/setReminderFlag/{id}/{flag}") | |||
| @ResponseStatus(HttpStatus.NO_CONTENT) | |||
| public void setReminderFlag(@PathVariable Long id, @PathVariable Boolean flag) { | |||
| User user = userService.find(id).get(); | |||
| user.setReminderFlag(flag); | |||
| userService.save(user); | |||
| } | |||
| @GetMapping("/isPasswordExpired") | |||
| public Map<String, Boolean> getIsPasswordExpired(@RequestParam Long id) { | |||
| Integer maximumDay = settingsService.getInt(SettingNames.SYS_PASSWORD_RULE_DURATION); | |||