|
@ -0,0 +1,75 @@ |
|
|
|
|
|
package com.qyft.gd.system.controller; |
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
|
import com.qyft.gd.system.common.base.BasePageQuery; |
|
|
|
|
|
import com.qyft.gd.system.common.result.PageResult; |
|
|
|
|
|
import com.qyft.gd.system.common.result.Result; |
|
|
|
|
|
import com.qyft.gd.system.common.result.ResultCode; |
|
|
|
|
|
import com.qyft.gd.system.model.entity.Role; |
|
|
|
|
|
import com.qyft.gd.system.service.RoleService; |
|
|
|
|
|
import io.swagger.v3.oas.annotations.Operation; |
|
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag; |
|
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
|
|
|
@Tag(name = "角色接口") |
|
|
|
|
|
@RestController |
|
|
|
|
|
@RequestMapping("/api/role") |
|
|
|
|
|
@RequiredArgsConstructor |
|
|
|
|
|
@Slf4j |
|
|
|
|
|
public class RoleController { |
|
|
|
|
|
|
|
|
|
|
|
private final RoleService roleService; |
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "角色列表") |
|
|
|
|
|
@GetMapping("/list") |
|
|
|
|
|
public PageResult<Role> getAllRole(BasePageQuery pageQuery) { |
|
|
|
|
|
IPage<Role> result = roleService.page(new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize()), null); |
|
|
|
|
|
return PageResult.success(result); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "添加新角色") |
|
|
|
|
|
@PostMapping("/") |
|
|
|
|
|
public Result<String> addRole(@RequestBody Role role) { |
|
|
|
|
|
Role existingRole = roleService.findByCode(role.getCode()); |
|
|
|
|
|
if(existingRole == null) { |
|
|
|
|
|
boolean isSuccess = roleService.addRole(role); |
|
|
|
|
|
if (isSuccess) { |
|
|
|
|
|
return Result.success(); |
|
|
|
|
|
} |
|
|
|
|
|
}else{ |
|
|
|
|
|
return Result.failed(ResultCode.DATA_ALREADY_EXISTS); |
|
|
|
|
|
} |
|
|
|
|
|
return Result.failed(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "更新角色") |
|
|
|
|
|
@PutMapping("/{id}") |
|
|
|
|
|
public Result<String> updateRole(@PathVariable Long id, @RequestBody Role role) { |
|
|
|
|
|
role.setId(id); |
|
|
|
|
|
Role existingRole = roleService.findByCode(role.getCode()); |
|
|
|
|
|
if(existingRole == null) { |
|
|
|
|
|
boolean isSuccess = roleService.updateRole(role); |
|
|
|
|
|
if (isSuccess) { |
|
|
|
|
|
return Result.success(); |
|
|
|
|
|
} |
|
|
|
|
|
}else{ |
|
|
|
|
|
return Result.failed(ResultCode.DATA_ALREADY_EXISTS); |
|
|
|
|
|
} |
|
|
|
|
|
return Result.failed(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "删除角色") |
|
|
|
|
|
@DeleteMapping("/{id}") |
|
|
|
|
|
public Result<String> deleteRole(@PathVariable Long id) { |
|
|
|
|
|
boolean isSuccess = roleService.deleteRole(id); |
|
|
|
|
|
if (isSuccess) { |
|
|
|
|
|
return Result.success(); |
|
|
|
|
|
} |
|
|
|
|
|
return Result.failed(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |