package cn.ezhizao.project.business.entrust.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.ezhizao.framework.aspectj.lang.annotation.Log;
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
import cn.ezhizao.project.business.entrust.domain.BizEntrustPermission;
import cn.ezhizao.project.business.entrust.service.IBizEntrustPermissionService;
import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.common.utils.poi.ExcelUtil;
import cn.ezhizao.framework.web.page.TableDataInfo;

/**
 * 委托权限Controller
 *
 * @author ruoyi
 * @date 2023-10-16
 */
@RestController
@RequestMapping("/business/entrustPermission")
public class BizEntrustPermissionController extends BaseController
{
    @Resource
    private IBizEntrustPermissionService bizEntrustPermissionService;

    /**
     * 查询委托权限列表
     */
    @PreAuthorize("@ss.hasPermi('business:entrust:permission:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizEntrustPermission bizEntrustPermission) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizEntrustPermission);
        startPage();
        List<BizEntrustPermission> list = bizEntrustPermissionService.getList(bizEntrustPermission);
        return getDataTable(list);
    }

    /**
     * 导出委托权限列表
     */
    @PreAuthorize("@ss.hasPermi('business:entrust:permission:export')")
    @Log(title = "委托权限", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizEntrustPermission bizEntrustPermission) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizEntrustPermission);
        List<BizEntrustPermission> list = bizEntrustPermissionService.getList(bizEntrustPermission);
        ExcelUtil<BizEntrustPermission> util = new ExcelUtil<BizEntrustPermission>(BizEntrustPermission.class);
        util.exportExcel(response, list, "委托权限数据");
    }

    /**
     * 获取委托权限详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:entrust:permission:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizEntrustPermissionService.getById(id));
    }

    /**
     * 新增委托权限
     */
    @PreAuthorize("@ss.hasPermi('business:entrust:permission:add')")
    @Log(title = "委托权限", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizEntrustPermission bizEntrustPermission) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizEntrustPermission);
        return toAjax(bizEntrustPermissionService.save(bizEntrustPermission));
    }

    /**
     * 修改委托权限
     */
    @PreAuthorize("@ss.hasPermi('business:entrust:permission:edit')")
    @Log(title = "委托权限", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizEntrustPermission bizEntrustPermission) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizEntrustPermission);
        return toAjax(bizEntrustPermissionService.updateById(bizEntrustPermission));
    }

    /**
     * 删除委托权限
     */
    @PreAuthorize("@ss.hasPermi('business:entrust:permission:remove')")
    @Log(title = "委托权限", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizEntrustPermissionService.removeBatchByIds(ids));
    }
}
