package com.muyu.server.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.domain.FirmPermission;
import com.muyu.domain.req.FirmPermissionAddReq;
import com.muyu.domain.req.FirmPermissionUpdReq;
import com.muyu.domain.req.FirmUpdPermissionReq;
import com.muyu.server.service.FirmPermissionService;
import io.swagger.v3.oas.annotations.Operation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 企业权限分配控制层
 * @Author：weiran
 * @Package：com.muyu.server.controller
 * @Project：cloud-server-8
 * @name：FirmPermission
 * @Date：2024/10/7 21:29
 */
@RestController
@RequestMapping("/permission")
public class FirmPermissionController {
    @Autowired
    private FirmPermissionService firmPermissionService;

    /**
     * 修改企业权限分配
     * @param firmUpdPermissionReq
     * @return
     */
    @PostMapping("/permissionupd")
    @Operation(summary = "修改权限分配",description = "修改权限分配")
    public Result updpermission(@RequestBody FirmUpdPermissionReq firmUpdPermissionReq){
        firmPermissionService.updpermission(firmUpdPermissionReq);
        return Result.success(null,"权限更改成功");
    }


    /**
     * 权限等级列表
     * @return
     */
    @PostMapping("/permissionlist")
    @Operation(summary = "权限等级列表",description = "权限等级列表")
    public Result permissionlist(){
        return Result.success(firmPermissionService.permissionlist());
    }


    /**
     * 企业权限新增
     * @param firmPermissionAddReq
     * @return
     */
    @PostMapping("/addpermission")
    @Operation(summary = "企业权限新增",description = "企业权限新增")
    public Result addpermission(@RequestBody FirmPermissionAddReq firmPermissionAddReq){
        firmPermissionService.save(FirmPermission.addfirmpermission(firmPermissionAddReq));
        return Result.success();
    }


    /**
     * 企业权限修改
     * @param firmPermissionUpdReq
     * @return
     */
    @PostMapping("/updpermission")
    @Operation(summary = "企业权限修改",description = "企业权限修改")
    public Result updpermission(@RequestBody FirmPermissionUpdReq firmPermissionUpdReq){
        firmPermissionService.updateById(FirmPermission.updfirmpermission(firmPermissionUpdReq));
        return Result.success();
    }
}
