|
@@ -0,0 +1,103 @@
|
|
|
+package com.sky.ioc.service.user.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
+import com.sky.ioc.entity.domain.system.Role;
|
|
|
+import com.sky.ioc.mapper.user.RoleMapper;
|
|
|
+import com.sky.ioc.mapper.user.UserMapper;
|
|
|
+import com.sky.ioc.service.user.RoleService;
|
|
|
+import com.sky.ioc.tool.ReturnMsg;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class RoleServiceImpl implements RoleService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RoleMapper roleMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserMapper userMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ReturnMsg getRoleList(String page, String pageSize) {
|
|
|
+ long total = 0;
|
|
|
+ List<Role> roles = new ArrayList<>();
|
|
|
+ if (StringUtils.isNoneBlank(page, pageSize)) {
|
|
|
+ PageHelper.startPage(Integer.parseInt(page), Integer.parseInt(pageSize));
|
|
|
+ roles = roleMapper.selectList(new LambdaQueryWrapper<>());
|
|
|
+ total = PageInfo.of(roles).getTotal();
|
|
|
+ } else {
|
|
|
+ roles = roleMapper.selectList(new LambdaQueryWrapper<>());
|
|
|
+ total = roles.size();
|
|
|
+ }
|
|
|
+ ReturnMsg<List<Role>> ok = ReturnMsg.ok(roles);
|
|
|
+ ok.setTotal(total);
|
|
|
+ return ok;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ReturnMsg getRoleById(String roleId) {
|
|
|
+ return ReturnMsg.ok(roleMapper.selectById(roleId));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ReturnMsg addRole(Role role) {
|
|
|
+ LambdaQueryWrapper<Role> queryWrapper = new LambdaQueryWrapper<Role>().eq(Role::getRole_name, role.getRole_name());
|
|
|
+ Role role1 = roleMapper.selectOne(queryWrapper);
|
|
|
+ if (role1 != null) {
|
|
|
+ throw new RuntimeException("角色名已存在");
|
|
|
+ }
|
|
|
+ roleMapper.insert(role);
|
|
|
+ return ReturnMsg.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ReturnMsg updateRole(Role role) {
|
|
|
+ Role role1 = roleMapper.selectById(role.getId());
|
|
|
+ if (!role1.getRole_name().equals(role.getRole_name())) {
|
|
|
+ LambdaQueryWrapper<Role> queryWrapper = new LambdaQueryWrapper<Role>().eq(Role::getRole_name, role.getRole_name());
|
|
|
+ Role role2 = roleMapper.selectOne(queryWrapper);
|
|
|
+ if (role2 != null) {
|
|
|
+ throw new RuntimeException("角色名已存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ roleMapper.updateById(role);
|
|
|
+ return ReturnMsg.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ReturnMsg deleteRole(String roleId) {
|
|
|
+ int num = roleMapper.deleteById(roleId);
|
|
|
+ if (num<1) {
|
|
|
+ return ReturnMsg.fail();
|
|
|
+ }
|
|
|
+ return ReturnMsg.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ReturnMsg batchDelRole(String roleIds) {
|
|
|
+ String[] roleIdArr = StringUtils.split(roleIds, ",");
|
|
|
+ roleMapper.deleteBatchIds(Arrays.asList(roleIdArr));
|
|
|
+ return ReturnMsg.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ReturnMsg removeMember(String userId, String roleId) {
|
|
|
+ int num = userMapper.batchModifyUserRole(new String[]{userId}, "");
|
|
|
+ return ReturnMsg.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ReturnMsg batchRemoveMember(String usersId, String roleId) {
|
|
|
+ String[] usersIdArr = StringUtils.split(usersId, ",");
|
|
|
+ int num = userMapper.batchModifyUserRole(usersIdArr, "");
|
|
|
+ return ReturnMsg.ok();
|
|
|
+ }
|
|
|
+}
|