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.BizEntrustDetail;
import cn.ezhizao.project.business.entrust.service.IBizEntrustDetailService;
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/entrustDetail")
public class BizEntrustDetailController extends BaseController
{
    @Resource
    private IBizEntrustDetailService bizEntrustDetailService;

    /**
     * 查询委托流程列表
     */
    @PreAuthorize("@ss.hasPermi('business:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizEntrustDetail bizEntrustDetail) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizEntrustDetail);
        startPage();
        List<BizEntrustDetail> list = bizEntrustDetailService.getList(bizEntrustDetail);
        return getDataTable(list);
    }

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

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

    /**
     * 新增委托流程
     */
    @PreAuthorize("@ss.hasPermi('business:detail:add')")
    @Log(title = "委托流程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizEntrustDetail bizEntrustDetail) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizEntrustDetail);
        return toAjax(bizEntrustDetailService.save(bizEntrustDetail));
    }

    /**
     * 修改委托流程
     */
    @PreAuthorize("@ss.hasPermi('business:detail:edit')")
    @Log(title = "委托流程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizEntrustDetail bizEntrustDetail) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizEntrustDetail);
        return toAjax(bizEntrustDetailService.updateById(bizEntrustDetail));
    }

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