| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.baomidou.mybatisplus.extension.api.R; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.RoleMapper; |
| | | import com.whyc.pojo.Role; |
| | | import com.whyc.pojo.UserRole; |
| | | import com.whyc.mapper.UserMapper; |
| | | import com.whyc.mapper.UserRoleMapper; |
| | | import com.whyc.pojo.*; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | |
| | | |
| | | @Resource |
| | | private RoleMapper mapper; |
| | | @Resource |
| | | private UserRoleMapper userRoleMapper; |
| | | |
| | | |
| | | public List<Role> getAll() { |
| | | return mapper.selectList(null); |
| | | QueryWrapper<Role> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.ne("name","superuser"); |
| | | return mapper.selectList(queryWrapper); |
| | | } |
| | | |
| | | |
| | | public Response<IPage<Role>> getRoleByCondition(int pageNum,int pageSize,Role role){ |
| | | public Response<PageInfo<Role>> getRoleByCondition(int pageNum,int pageSize,Role role){ |
| | | QueryWrapper<Role> queryWrapper = new QueryWrapper<>(role); |
| | | queryWrapper.or().like(StringUtils.isNotEmpty(role.getSearch()) ,"label",role.getSearch()); |
| | | queryWrapper.or().like(StringUtils.isNotEmpty(role.getSearch()) ,"description",role.getSearch()); |
| | | IPage<Role> roleIPage = mapper.selectPage(new Page<>(pageNum, pageSize), queryWrapper); |
| | | return new Response<IPage<Role>>().set(1,roleIPage); |
| | | queryWrapper.ne("name","superuser"); |
| | | List<Role> list = mapper.selectList(queryWrapper); |
| | | for (Role role1: list) { |
| | | QueryWrapper<UserRole> userRoleQueryWrapper = new QueryWrapper<>(); |
| | | userRoleQueryWrapper.eq("role_id",role1.getId()); |
| | | int count = userRoleMapper.selectCount(userRoleQueryWrapper); |
| | | role1.setUserCount(count); |
| | | } |
| | | //IPage<Role> roleIPage = mapper.selectPage(new Page<>(pageNum, pageSize), queryWrapper); |
| | | PageInfo<Role> rolePageInfo = new PageInfo<>(list); |
| | | return new Response<PageInfo<Role>>().set(1,rolePageInfo); |
| | | } |
| | | |
| | | public Response add(Role role) { |
| | |
| | | return new Response().setMsg(0,"已有此权限组数据"); |
| | | } |
| | | |
| | | role.setState(1); |
| | | role.setState(0); |
| | | role.setUpdateTime(new Date()); |
| | | mapper.insert(role); |
| | | return new Response().set(1,role,"添加成功"); |
| | | } |
| | | public Response updateRole(Role role){ |
| | | if(mapper.updateById(role)>0){ |
| | | return new Response().setMsg(1,"更新成功"); |
| | | }else { |
| | | return new Response().setMsg(0,"更新失败"); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | public boolean addBatch(List<Role> roles) { |
| | | return mapper.insertBatchSomeColumn(roles)==roles.size(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | public Response updateRoleState(int roleId,int state){ |
| | | Role role = mapper.selectById(roleId); |
| | | if ("superuser".equals(role.getName())){ |
| | | return new Response().setMsg(0,"更新失败"); |
| | | } |
| | | role.setState(state); |
| | | if(mapper.updateById(role)>0){ |
| | | if (state==0){ |
| | | return new Response().setMsg(1,"启用成功"); |
| | | }else{ |
| | | return new Response().setMsg(1,"冻结成功"); |
| | | } |
| | | }else { |
| | | return new Response().setMsg(0,"更新失败"); |
| | | } |
| | | } |
| | | |
| | | public Response deleteRole(int roleId){ |
| | | Role role = mapper.selectById(roleId); |
| | | if ("superuser".equals(role.getName())){ |
| | | return new Response().setMsg(0,"删除失败"); |
| | | } |
| | | if(mapper.deleteById(roleId)>0){ |
| | | return new Response().setMsg(1, "删除成功"); |
| | | }else{ |
| | | return new Response().setMsg(0, "删除失败"); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |