| | |
| | | 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; |
| | |
| | | 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; |
| | | |
| | |
| | | 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); |
| | |
| | | } |
| | | 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(); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | 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(); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public String checkLoginNameUnique(String loginName) { |
| | | int count = userMapper.checkLoginNameUnique(loginName); |
| | |
| | | } |
| | | return UserConstants.USER_NAME_UNIQUE; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public String checkPhoneUnique(User user) { |
| | | Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId(); |
| | |
| | | } |
| | | return UserConstants.USER_PHONE_UNIQUE; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public String checkEmailUnique(User user) { |
| | | Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId(); |
| | |
| | | } |
| | | return UserConstants.USER_EMAIL_UNIQUE; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public String selectUserRoleGroup(Long userId) { |
| | | List<Role> list = roleMapper.selectRolesByUserId(userId); |
| | |
| | | } |
| | | return idsStr.toString(); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public String selectUserPostGroup(Long userId) { |
| | | List<Post> list = postMapper.selectPostsByUserId(userId); |
| | |
| | | } |
| | | return idsStr.toString(); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public String importUser(List<User> userList, Boolean isUpdateSupport) { |
| | | if (StringUtils.isNull(userList) || userList.size() == 0) { |
| | |
| | | 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); |
| | |
| | | } |
| | | return successMsg.toString(); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public int changeStatus(User user) { |
| | | if (User.isAdmin(user.getUserId())) { |
| | |
| | | } |
| | | 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; |
| | | } |
| | | } |