You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
135 lines
4.2 KiB
135 lines
4.2 KiB
package com.example.demo.controller.coin;
|
|
|
|
import com.example.demo.Util.JWTUtil;
|
|
import com.example.demo.config.interfac.Log;
|
|
import com.example.demo.domain.entity.Admin;
|
|
import com.example.demo.domain.vo.coin.Page;
|
|
import com.example.demo.domain.vo.coin.Result;
|
|
import com.example.demo.domain.vo.coin.RoleVo;
|
|
import com.example.demo.service.coin.RoleService;
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.util.ObjectUtils;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* @program: gold-java
|
|
* @ClassName RoleController
|
|
* @description:
|
|
* @author: Double
|
|
* @create: 2025−07-15 11:23
|
|
* @Version 1.0
|
|
**/
|
|
|
|
@RestController
|
|
@RequestMapping("/role")
|
|
@RequiredArgsConstructor
|
|
@Slf4j
|
|
@CrossOrigin
|
|
public class RoleController {
|
|
|
|
@Autowired
|
|
private RoleService roleService;
|
|
|
|
//新增角色
|
|
@Log("新增角色")
|
|
@PostMapping("/add")
|
|
public Result addRole(@RequestBody RoleVo roleVo) {
|
|
|
|
return roleService.addRole(roleVo);
|
|
}
|
|
//新增角色二期替补
|
|
@Log("新增角色二期替补")
|
|
@PostMapping("/add2")
|
|
public Result addRole2(@RequestBody RoleVo roleVo) {
|
|
|
|
return roleService.addRole2(roleVo);
|
|
}
|
|
//删除角色
|
|
@Log("删除角色")
|
|
@PostMapping("/delete")
|
|
public Result deleteRole(@RequestBody RoleVo roleVo) {
|
|
|
|
return roleService.deleteRole(roleVo);
|
|
}
|
|
|
|
//查找全部角色
|
|
@Log("查询全部角色")
|
|
@PostMapping("/selectAll")
|
|
public Result selectRole() {
|
|
return roleService.selectAllRole();
|
|
}
|
|
//获取上级角色的下属角色列表
|
|
@Log("获取当前角色的下属角色列表")
|
|
@PostMapping("/selectSub")
|
|
public Result selectSub(@RequestBody RoleVo roleVo) {
|
|
Integer id = roleVo.getId();
|
|
List<RoleVo> list=roleService.selectSubRole(id);
|
|
return Result.success(list);
|
|
}
|
|
//获取当前角色的上级角色
|
|
// @Log("获取当前角色的上级角色")
|
|
@PostMapping("/selectFather")
|
|
public Result selectFather(@RequestBody RoleVo roleVo) {
|
|
Integer id = roleVo.getId();
|
|
RoleVo role = roleService.selectFather(id);
|
|
return Result.success(role);
|
|
}
|
|
|
|
//角色明细筛选
|
|
@Log("角色明细筛选")
|
|
@PostMapping("/selectBy")
|
|
public Result selectBy(@RequestBody Page page) {
|
|
try {
|
|
//页码校验
|
|
if (ObjectUtils.isEmpty(page.getPageNum())) {
|
|
return Result.error("页码数为空!");
|
|
}
|
|
//页面大小校验
|
|
if (ObjectUtils.isEmpty(page.getPageSize())) {
|
|
return Result.error("页大小为空!");
|
|
} else {
|
|
//解token权限
|
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
String token = request.getHeader("token");
|
|
Admin admin = (Admin) JWTUtil.getUserDetailsList(String.valueOf(token), Admin.class);
|
|
if (admin != null) {
|
|
List<String> list = Arrays.asList(admin.getMarkets().split(","));
|
|
page.getRoleVo().setMarkets(list);
|
|
}
|
|
else{
|
|
return Result.error("角色为空");
|
|
}
|
|
return Result.success(roleService.selectBy(page.getPageNum(), page.getPageSize(), page.getRoleVo()));
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
return Result.error("请检查筛选数据的格式");
|
|
}
|
|
|
|
}
|
|
|
|
//查询所有直播渠道
|
|
@PostMapping("/getChannel")
|
|
public Result getChannel(){
|
|
return Result.success(roleService.getChannel());
|
|
}
|
|
|
|
|
|
@Log("获取频道列表")
|
|
@PostMapping("/selectChannel")
|
|
public Result selectChannel(@RequestBody RoleVo roleVo) {
|
|
Integer id = roleVo.getId();
|
|
List<RoleVo> list=roleService.selectSubRole(id);
|
|
return Result.success(list);
|
|
}
|
|
|
|
|
|
}
|