package cn.ezhizao.project.business.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import cn.ezhizao.common.utils.poi.ExcelUtil;
import cn.ezhizao.framework.aspectj.lang.annotation.Log;
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.framework.web.page.TableDataInfo;
import cn.ezhizao.project.business.domain.BizProcessInspectionRelation;
import cn.ezhizao.project.business.service.IBizProcessInspectionRelationService;
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;


/**
 * 外协检查关联Controller
 *
 * @author ezhizao
 * @date 2024-11-26
 */
@RestController
@RequestMapping("/business/relation")
public class BizProcessInspectionRelationController extends BaseController
{
    @Resource
    private IBizProcessInspectionRelationService bizProcessInspectionRelationService;

    /**
     * 查询外协检查关联列表
     */
    @PreAuthorize("@ss.hasPermi('business:relation:list')")
    @GetMapping("/list")
    @Log(title = "查询外协检查关联列表", businessType = BusinessType.SELECT)
    public TableDataInfo list(BizProcessInspectionRelation bizProcessInspectionRelation) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizProcessInspectionRelation);
        startPage();
        List<BizProcessInspectionRelation> list = bizProcessInspectionRelationService.getList(bizProcessInspectionRelation);
        return getDataTable(list);
    }

    /**
     * 导出外协检查关联列表
     */
    @PreAuthorize("@ss.hasPermi('business:relation:export')")
    @Log(title = "导出外协检查关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizProcessInspectionRelation bizProcessInspectionRelation) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizProcessInspectionRelation);
        List<BizProcessInspectionRelation> list = bizProcessInspectionRelationService.getList(bizProcessInspectionRelation);
        ExcelUtil<BizProcessInspectionRelation> util = new ExcelUtil<BizProcessInspectionRelation>(BizProcessInspectionRelation.class);
        util.exportExcel(response, list, "外协检查关联数据");
    }

    /**
     * 获取外协检查关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:relation:query')")
    @GetMapping(value = "/{id}")
    @Log(title = "获取外协检查关联详细信息", businessType = BusinessType.SELECT)
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizProcessInspectionRelationService.getById(id));
    }

    /**
     * 新增外协检查关联
     */
    @PreAuthorize("@ss.hasPermi('business:relation:add')")
    @Log(title = "新增外协检查关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizProcessInspectionRelation bizProcessInspectionRelation) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizProcessInspectionRelation);
        return toAjax(bizProcessInspectionRelationService.save(bizProcessInspectionRelation));
    }

    /**
     * 修改外协检查关联
     */
    @PreAuthorize("@ss.hasPermi('business:relation:edit')")
    @Log(title = "修改外协检查关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizProcessInspectionRelation bizProcessInspectionRelation) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizProcessInspectionRelation);
        return toAjax(bizProcessInspectionRelationService.updateById(bizProcessInspectionRelation));
    }

    /**
     * 删除外协检查关联
     */
    @PreAuthorize("@ss.hasPermi('business:relation:remove')")
    @Log(title = "删除外协检查关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizProcessInspectionRelationService.removeBatchByIds(ids));
    }
}
