src/main/java/com/ots/project/system/role/mapper/RoleMapper.java
@@ -1,5 +1,7 @@ package com.ots.project.system.role.mapper; import com.ots.project.system.role.domain.Role; import org.apache.ibatis.annotations.Param; import java.util.List; public interface RoleMapper { @@ -21,4 +23,6 @@ public Role checkRoleNameUnique(String roleName); public Role checkRoleKeyUnique(String roleKey); Role selectByRoleKey(@Param("roleKey")String roleKey); } src/main/java/com/ots/project/system/user/controller/UserController.java
@@ -1,4 +1,5 @@ package com.ots.project.system.user.controller; import com.ots.common.constant.UserConstants; import com.ots.common.enums.UserTypeEnum; import com.ots.common.utils.StringUtils; @@ -20,6 +21,7 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import java.util.List; @Controller @@ -32,25 +34,29 @@ private IRoleService roleService; @Autowired private IPostService postService; @RequiresPermissions("system:user:view") @GetMapping() public String user() { return prefix + "/user"; } @RequiresPermissions("system:user:manager:view") @GetMapping("/manager") public String manager() { return prefix + "/usermanager"; } @RequiresPermissions("system:user:list") @PostMapping("/list") @ResponseBody public TableDataInfo list(User user) { startPage(); user.setUserType(UserTypeEnum.SYS_USER.getUserType()); user.setUserType(UserTypeEnum.SYS_USER.getUserType()); List<User> list = userService.selectUserList(user); return getDataTable(list); } @Log(title = "用户管理", businessType = BusinessType.EXPORT) @RequiresPermissions("system:user:export") @PostMapping("/export") @@ -60,6 +66,7 @@ ExcelUtil<User> util = new ExcelUtil<User>(User.class); return util.exportExcel(list, "用户数据"); } @Log(title = "用户管理", businessType = BusinessType.IMPORT) @RequiresPermissions("system:user:import") @PostMapping("/importData") @@ -70,6 +77,7 @@ String message = userService.importUser(userList, updateSupport); return AjaxResult.success(message); } @RequiresPermissions("system:user:view") @GetMapping("/importTemplate") @ResponseBody @@ -77,14 +85,14 @@ ExcelUtil<User> util = new ExcelUtil<User>(User.class); return util.importTemplateExcel("用户数据"); } @GetMapping("/add") public String add(ModelMap mmap) { mmap.put("roles", roleService.selectRoleAll()); mmap.put("posts", postService.selectPostAll()); return prefix + "/add"; } @RequiresPermissions("system:user:add") @Log(title = "用户管理", businessType = BusinessType.INSERT) @PostMapping("/add") @@ -99,7 +107,7 @@ } return toAjax(userService.insertUser(user)); } @GetMapping("/edit/{userId}") public String edit(@PathVariable("userId") Long userId, ModelMap mmap) { mmap.put("user", userService.selectUserById(userId)); @@ -107,7 +115,7 @@ mmap.put("posts", postService.selectPostsByUserId(userId)); return prefix + "/edit"; } @RequiresPermissions("system:user:edit") @Log(title = "用户管理", businessType = BusinessType.UPDATE) @PostMapping("/edit") @@ -122,6 +130,7 @@ } return toAjax(userService.updateUser(user)); } @RequiresPermissions("system:user:resetPwd") @Log(title = "重置密码", businessType = BusinessType.UPDATE) @GetMapping("/resetPwd/{userId}") @@ -129,6 +138,7 @@ mmap.put("user", userService.selectUserById(userId)); return prefix + "/resetPwd"; } @RequiresPermissions("system:user:resetPwd") @Log(title = "重置密码", businessType = BusinessType.UPDATE) @PostMapping("/resetPwd") @@ -142,6 +152,7 @@ } return error(); } @RequiresPermissions("system:user:remove") @Log(title = "用户管理", businessType = BusinessType.DELETE) @PostMapping("/remove") @@ -153,25 +164,25 @@ return error(e.getMessage()); } } @PostMapping("/checkLoginNameUnique") @ResponseBody public String checkLoginNameUnique(User user) { return userService.checkLoginNameUnique(user.getLoginName()); } @PostMapping("/checkPhoneUnique") @ResponseBody public String checkPhoneUnique(User user) { return userService.checkPhoneUnique(user); } @PostMapping("/checkEmailUnique") @ResponseBody public String checkEmailUnique(User user) { return userService.checkEmailUnique(user); } @Log(title = "用户管理", businessType = BusinessType.UPDATE) @RequiresPermissions("system:user:edit") @PostMapping("/changeStatus") @@ -179,4 +190,13 @@ public AjaxResult changeStatus(User user) { return toAjax(userService.changeStatus(user)); } @Log(title = "事中提示语授权", businessType = BusinessType.UPDATE) @RequiresPermissions("system:user:hint:auth") @GetMapping("/changeHintStatus") @ResponseBody public AjaxResult changeHintStatus(String userId,Integer type) { //type 0取消授权 1授权 return toAjax(userService.changeHintStatus(userId,type)); } } src/main/java/com/ots/project/system/user/mapper/UserMapper.java
@@ -1,6 +1,8 @@ package com.ots.project.system.user.mapper; import com.ots.project.system.user.domain.User; import org.apache.ibatis.annotations.Options; import org.apache.ibatis.annotations.Param; import java.util.List; public interface UserMapper { @@ -33,4 +35,6 @@ User checkPhoneUnique(String phonenumber); User checkEmailUnique(String email); int updateHintState(@Param("userId")String userId,@Param("type") Integer type); } src/main/java/com/ots/project/system/user/mapper/UserRoleMapper.java
@@ -1,4 +1,5 @@ package com.ots.project.system.user.mapper; import com.ots.project.system.role.domain.Role; import com.ots.project.system.user.domain.UserRole; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -16,4 +17,5 @@ public int deleteUserRoleInfo(UserRole userRole); public int deleteUserRoleInfos(@Param("roleId") Long roleId, @Param("userIds") Long[] userIds); } src/main/java/com/ots/project/system/user/service/IUserService.java
@@ -44,4 +44,7 @@ String importUser(List<User> userList, Boolean isUpdateSupport); int changeStatus(User user); int changeHintStatus(String userId, Integer type); } src/main/java/com/ots/project/system/user/service/UserServiceImpl.java
@@ -1,4 +1,5 @@ package com.ots.project.system.user.service; import com.ots.common.constant.UserConstants; import com.ots.common.exception.BusinessException; import com.ots.common.utils.StringUtils; @@ -22,6 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; @@ -42,57 +44,58 @@ private IConfigService configService; @Autowired private PasswordService passwordService; @Override @DataScope(deptAlias = "d", userAlias = "u") public List<User> selectUserList(User user) { return userMapper.selectUserList(user); } public List<User> selectUserList2(User user) { return userMapper.selectUserList(user); } @DataScope(deptAlias = "d", userAlias = "u") public List<User> selectAllocatedList(User user) { return userMapper.selectAllocatedList(user); } @DataScope(deptAlias = "d", userAlias = "u") public List<User> selectUnallocatedList(User user) { return userMapper.selectUnallocatedList(user); } @Override public User selectUserByLoginName(String userName) { return userMapper.selectUserByLoginName(userName); } @Override public User selectUserByPhoneNumber(String phoneNumber) { return userMapper.selectUserByPhoneNumber(phoneNumber); } @Override public User selectUserByEmail(String email) { return userMapper.selectUserByEmail(email); } @Override public User selectUserById(Long userId) { return userMapper.selectUserById(userId); } @Override public int deleteUserById(Long userId) { userRoleMapper.deleteUserRoleByUserId(userId); userPostMapper.deleteUserPostByUserId(userId); return userMapper.deleteUserById(userId); } @Override public int deleteUserByIds(String ids) throws BusinessException { Long[] userIds = Convert.toLongArray(ids); @@ -103,54 +106,54 @@ } return userMapper.deleteUserByIds(userIds); } @Override @Transactional public int insertUser(User user) { user.randomSalt(); user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt())); user.setCreateBy(ShiroUtils.getLoginName()); int rows = userMapper.insertUser(user); insertUserPost(user); insertUserRole(user); return rows; } @Override @Transactional public int updateUser(User user) { Long userId = user.getUserId(); user.setUpdateBy(ShiroUtils.getLoginName()); userRoleMapper.deleteUserRoleByUserId(userId); insertUserRole(user); userPostMapper.deleteUserPostByUserId(userId); insertUserPost(user); return userMapper.updateUser(user); } @Override public int updateUserInfo(User user) { return userMapper.updateUser(user); } @Override public int resetUserPwd(User user) { user.randomSalt(); user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt())); return updateUserInfo(user); } public void insertUserRole(User user) { Long[] roles = user.getRoleIds(); if (StringUtils.isNotNull(roles)) { List<UserRole> list = new ArrayList<UserRole>(); for (Long roleId : user.getRoleIds()) { UserRole ur = new UserRole(); @@ -163,11 +166,11 @@ } } } public void insertUserPost(User user) { Long[] posts = user.getPostIds(); if (StringUtils.isNotNull(posts)) { List<UserPost> list = new ArrayList<UserPost>(); for (Long postId : user.getPostIds()) { UserPost up = new UserPost(); @@ -180,7 +183,7 @@ } } } @Override public String checkLoginNameUnique(String loginName) { int count = userMapper.checkLoginNameUnique(loginName); @@ -189,7 +192,7 @@ } return UserConstants.USER_NAME_UNIQUE; } @Override public String checkPhoneUnique(User user) { Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId(); @@ -199,7 +202,7 @@ } return UserConstants.USER_PHONE_UNIQUE; } @Override public String checkEmailUnique(User user) { Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId(); @@ -209,7 +212,7 @@ } return UserConstants.USER_EMAIL_UNIQUE; } @Override public String selectUserRoleGroup(Long userId) { List<Role> list = roleMapper.selectRolesByUserId(userId); @@ -222,7 +225,7 @@ } return idsStr.toString(); } @Override public String selectUserPostGroup(Long userId) { List<Post> list = postMapper.selectPostsByUserId(userId); @@ -235,7 +238,7 @@ } return idsStr.toString(); } @Override public String importUser(List<User> userList, Boolean isUpdateSupport) { if (StringUtils.isNull(userList) || userList.size() == 0) { @@ -249,7 +252,7 @@ String password = configService.selectConfigByKey("sys.user.initPassword"); for (User user : userList) { try { User u = userMapper.selectUserByLoginName(user.getLoginName()); if (StringUtils.isNull(u)) { user.setPassword(password); @@ -281,7 +284,7 @@ } return successMsg.toString(); } @Override public int changeStatus(User user) { if (User.isAdmin(user.getUserId())) { @@ -289,4 +292,37 @@ } return userMapper.updateUser(user); } @Override public int changeHintStatus(String userId, Integer type) { // type 0取消授权 1授权 if(type == 0){ //查询事中提示语管理员 Role role = roleMapper.selectByRoleKey("hint_common"); if(role != null && StringUtils.isNotEmpty(userId)){ //更新事中提示语状态 userMapper.updateHintState(userId,type); UserRole userRole = new UserRole(); userRole.setRoleId(role.getRoleId()); userRole.setUserId(Long.valueOf(userId)); return userRoleMapper.deleteUserRoleInfo(userRole); } }else if(type == 1){ //查询事中提示语管理员 Role role = roleMapper.selectByRoleKey("hint_common"); List<UserRole> list = new ArrayList<UserRole>(); if(role != null && StringUtils.isNotEmpty(userId)){ //更新事中提示语状态 userMapper.updateHintState(userId,type); UserRole ur = new UserRole(); ur.setUserId(Long.valueOf(userId)); ur.setRoleId(role.getRoleId()); list.add(ur); return userRoleMapper.batchUserRole(list); } } return 0; } }