package com.ruoyi.ems.controller;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
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 com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.ems.domain.AdmOpInspectionReport;
import com.ruoyi.ems.service.IAdmOpInspectionReportService;

/**
 * 巡检报告Controller
 *
 * @author ruoyi
 * @date 2024-08-29
 */
@RestController
@RequestMapping("/inspectionReport")
public class AdmOpInspectionReportController extends BaseController {
    @Autowired
    private IAdmOpInspectionReportService admOpInspectionReportService;

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

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

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

    /**
     * 新增巡检报告
     */
    @RequiresPermissions("ems:inspection-report:add")
    @Log(title = "巡检报告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdmOpInspectionReport admOpInspectionReport) {
        admOpInspectionReport.setSubTime(DateUtils.getNowDate());
        admOpInspectionReport.setSubmitter(SecurityUtils.getUsername());
        return toAjax(admOpInspectionReportService.insertAdmOpInspectionReport(admOpInspectionReport));
    }

    /**
     * 修改巡检报告
     */
    @RequiresPermissions("ems:inspection-report:edit")
    @Log(title = "巡检报告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdmOpInspectionReport admOpInspectionReport) {
        admOpInspectionReport.setSubTime(DateUtils.getNowDate());
        admOpInspectionReport.setSubmitter(SecurityUtils.getUsername());
        return toAjax(admOpInspectionReportService.updateAdmOpInspectionReport(admOpInspectionReport));
    }

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