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.BizEntrust;
import cn.ezhizao.project.business.entrust.service.IBizEntrustService;
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/entrust")
public class BizEntrustController extends BaseController
{
    @Resource
    private IBizEntrustService bizEntrustService;

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

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

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

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

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

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