|
@@ -1,81 +1,9 @@
|
|
package com.nokia.controller;
|
|
package com.nokia.controller;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
-import com.nokia.common.R;
|
|
|
|
-import com.nokia.dao.RoleDao;
|
|
|
|
-import com.nokia.pojo.Role;
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
@RequestMapping("rest/api/role")
|
|
@RequestMapping("rest/api/role")
|
|
@RestController
|
|
@RestController
|
|
public class RoleController {
|
|
public class RoleController {
|
|
-
|
|
|
|
- public final RoleDao roleDao;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- public RoleController(RoleDao roleDao){
|
|
|
|
- this.roleDao=roleDao;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @PostMapping("/list")
|
|
|
|
- public R list() {
|
|
|
|
- return R.ok().data(roleDao.selectList(null));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @PostMapping("/add")
|
|
|
|
- public R RoleAdd(@RequestBody Role roleEntity){
|
|
|
|
- if (roleEntity==null){
|
|
|
|
- return R.error().message("空");
|
|
|
|
- }
|
|
|
|
- QueryWrapper<Role> queryWrapper = new QueryWrapper<>();
|
|
|
|
- queryWrapper.eq("role_name",roleEntity.getRoleName());
|
|
|
|
- Role roleEntity1 = roleDao.selectOne(queryWrapper);
|
|
|
|
- if (roleEntity1!=null){
|
|
|
|
- return R.error().message("角色已经存在");
|
|
|
|
- }
|
|
|
|
- int insert = roleDao.insert(roleEntity);
|
|
|
|
- if (insert>0){
|
|
|
|
- return R.ok().message("添加成功");
|
|
|
|
- }else {
|
|
|
|
- return R.error().message("添加失败");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @PostMapping("/delete/id/{roleId}")
|
|
|
|
- public R RoleDelete(@PathVariable Integer roleId){
|
|
|
|
- if (roleId==null){
|
|
|
|
- return R.error().message("roleId 为空");
|
|
|
|
- }
|
|
|
|
- int ResurnRole = roleDao.deleteById(roleId);
|
|
|
|
- if (ResurnRole>0){
|
|
|
|
- return R.ok().message("删除成功");
|
|
|
|
- }else {
|
|
|
|
- return R.error().message("删除失败");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @PostMapping("/update/id/{roleId}")
|
|
|
|
- public R RoleUpdate(@PathVariable Integer roleId, @RequestBody Role roleEntity){
|
|
|
|
- if (roleEntity==null){
|
|
|
|
- return R.error().message("roleEntity 为空");
|
|
|
|
- }
|
|
|
|
- Role roleEntity1 = roleDao.selectById(roleId);
|
|
|
|
- roleEntity1.setRoleName(roleEntity.getRoleName());
|
|
|
|
- int i = roleDao.updateById(roleEntity1);
|
|
|
|
- if (i>0){
|
|
|
|
- return R.ok().message("修改成功");
|
|
|
|
- }else {
|
|
|
|
- return R.ok().message("修改失败");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @PostMapping("/select/id/{roleId}")
|
|
|
|
- public R RoleSelect(@PathVariable Integer roleId){
|
|
|
|
- if (roleId==null){
|
|
|
|
- return R.error().message("roleId 为空");
|
|
|
|
- }
|
|
|
|
- Role roleEntity = roleDao.selectById(roleId);
|
|
|
|
- return roleEntity==null ? R.error().message("role不存在") :R.ok().data(roleEntity);
|
|
|
|
- }
|
|
|
|
}
|
|
}
|