package cn.iocoder.yudao.module.inspection.controller;

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

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.inspection.entity.InspectionInfo;
import cn.iocoder.yudao.module.inspection.service.IInspectionInfoService;
import cn.iocoder.yudao.util.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.iocoder.yudao.module.core.controller.BaseController;
import cn.iocoder.yudao.module.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 *
 * @author ruoyi
 * @date 2023-08-13
 */
@RestController
@RequestMapping("/admin-api/system/info")
public class InspectionInfoController extends BaseController
{
    @Autowired
    private IInspectionInfoService inspectionInfoService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(InspectionInfo inspectionInfo)
    {
        startPage();
        List<InspectionInfo> list = inspectionInfoService.selectInspectionInfoList(inspectionInfo);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, InspectionInfo inspectionInfo)
    {
        List<InspectionInfo> list = inspectionInfoService.selectInspectionInfoList(inspectionInfo);
        ExcelUtil<InspectionInfo> util = new ExcelUtil<InspectionInfo>(InspectionInfo.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{id}")
    public CommonResult getInfo(@PathVariable("id") Long id)
    {
        return success(inspectionInfoService.selectInspectionInfoById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PostMapping("/add")
    public CommonResult add(@RequestBody InspectionInfo inspectionInfo) throws Exception {

        return toAjax(inspectionInfoService.insertInspectionInfo(inspectionInfo));
    }

    /**
     * 清账
     */
    @PostMapping("/settleAccounts")
    public CommonResult settleAccounts(Long InspectionId){
        inspectionInfoService.settleAccounts(InspectionId);
        return success();
    }


    @PostMapping("/update")
    public CommonResult edit(@RequestBody InspectionInfo inspectionInfo) throws Exception {
        return toAjax(inspectionInfoService.updateInspectionInfo(inspectionInfo));
    }


    @PostMapping("/del")
    public CommonResult remove(@RequestParam("id") Long id)
    {
        return toAjax(inspectionInfoService.deleteInspectionInfoByIds(id));
    }
}
