SpRoleController.java 3.49 KB
package com.bs.web.controller.role;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bs.common.annotation.Log;
import com.bs.common.core.controller.BaseController;
import com.bs.common.core.domain.AjaxResult;
import com.bs.common.core.domain.entity.role.SpRole;
import com.bs.common.core.page.TableDataInfo;
import com.bs.common.enums.BusinessType;
import com.bs.common.enums.OperatorType;
import com.bs.web.service.role.ISpRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sp/role")
@Tag(name = "服务商角色")
public class SpRoleController extends BaseController {

    @Resource
    private ISpRoleService spRoleService;

    @PostMapping("/list")
    @Operation(summary = "列表")
    public AjaxResult<List<SpRole>> list(SpRole query) {
        List<SpRole> list = spRoleService.list(query);
        return AjaxResult.success(list);
    }

    @RequestMapping(value = "/page", method = {RequestMethod.GET, RequestMethod.POST})
    @Operation(summary = "分页列表")
    public TableDataInfo page(@RequestBody(required = false) SpRole query) {
        com.bs.common.core.page.PageDomain pageDomain = com.bs.common.core.page.TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();

        if (pageNum == null && query != null && query.getParams() != null && query.getParams().get("pageNum") != null) {
            pageNum = Integer.parseInt(query.getParams().get("pageNum").toString());
        }
        if (pageSize == null && query != null && query.getParams() != null && query.getParams().get("pageSize") != null) {
            pageSize = Integer.parseInt(query.getParams().get("pageSize").toString());
        }

        if (pageNum == null) pageNum = 1;
        if (pageSize == null) pageSize = 10;

        com.baomidou.mybatisplus.core.metadata.IPage<SpRole> pageResult = spRoleService.page(query, pageNum, pageSize);

        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(com.bs.common.constant.HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(pageResult.getRecords());
        rspData.setTotal(pageResult.getTotal());
        return rspData;
    }

    @PostMapping("/{id}")
    @Operation(summary = "详情")
    public AjaxResult<SpRole> get(@PathVariable("id") Long id) {
        return AjaxResult.success(spRoleService.get(id));
    }

    @Log(title = "服务商角色新增", businessType = BusinessType.INSERT,operatorType = OperatorType.MANAGE)
    @PostMapping("/add")
    @Operation(summary = "新增")
    public AjaxResult add(@RequestBody SpRole info) {
        spRoleService.add(info);
        return AjaxResult.success();
    }

    @Log(title = "服务商角色编辑", businessType = BusinessType.UPDATE,operatorType = OperatorType.MANAGE)
    @PostMapping("/edit")
    @Operation(summary = "编辑")
    public AjaxResult edit(@RequestBody SpRole info) {
        spRoleService.edit(info);
        return AjaxResult.success();
    }

    @Log(title = "服务商角色删除", businessType = BusinessType.DELETE,operatorType = OperatorType.MANAGE)
    @PostMapping("/delete/{id}")
    @Operation(summary = "删除")
    public AjaxResult remove(@PathVariable("id") Long id) {
        spRoleService.remove(id);
        return AjaxResult.success();
    }
}