package com.ruoyi.web.controller.ems;

import com.huashe.common.domain.AjaxResult;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ems.domain.AdmOpInspectionReport;
import com.ruoyi.ems.service.IAdmOpInspectionReportService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * 巡检报告Controller
 *
 * @author ruoyi
 * @date 2024-08-29
 */
@RestController
@RequestMapping("/ems/inspectionReport")
@Api(value = "AdmOpInspectionReportController", description = "巡检报告")
public class AdmOpInspectionReportController extends BaseController {
    @Autowired
    private IAdmOpInspectionReportService inspectionReportService;

    /**
     * 查询巡检报告列表
     */
    @PreAuthorize("@ss.hasPermi('ems:inspection-report:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdmOpInspectionReport inspectionReport) {
        startPage();
        List<AdmOpInspectionReport> list = inspectionReportService.selectAdmOpInspectionReportList(inspectionReport);
        return getDataTable(list);
    }

    /**
     * 导出巡检报告列表
     */
    @PreAuthorize("@ss.hasPermi('ems:inspection-report:export')")
    @Log(title = "巡检报告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdmOpInspectionReport inspectionReport) {
        List<AdmOpInspectionReport> list = inspectionReportService.selectAdmOpInspectionReportList(inspectionReport);
        ExcelUtil<AdmOpInspectionReport> util = new ExcelUtil<AdmOpInspectionReport>(AdmOpInspectionReport.class);
        util.exportExcel(response, list, "巡检报告数据");
    }

    /**
     * 获取巡检报告详细信息
     */
    @PreAuthorize("@ss.hasPermi('ems:inspection-report:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(inspectionReportService.selectAdmOpInspectionReportById(id));
    }

    /**
     * 新增巡检报告
     */
    @PreAuthorize("@ss.hasPermi('ems:inspection-report:add')")
    @Log(title = "巡检报告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdmOpInspectionReport inspectionReport) {
        return toAjax(inspectionReportService.insertAdmOpInspectionReport(inspectionReport));
    }

    /**
     * 修改巡检报告
     */
    @PreAuthorize("@ss.hasPermi('ems:inspection-report:edit')")
    @Log(title = "巡检报告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdmOpInspectionReport inspectionReport) {
        return toAjax(inspectionReportService.updateAdmOpInspectionReport(inspectionReport));
    }

    /**
     * 删除巡检报告
     */
    @PreAuthorize("@ss.hasPermi('ems:inspection-report:remove')")
    @Log(title = "巡检报告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(inspectionReportService.deleteAdmOpInspectionReportByIds(ids));
    }
}
