package com.ruoyi.manage.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
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.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manage.domain.RecordInspection;
import com.ruoyi.manage.service.IRecordInspectionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 巡检记录Controller
 * 
 * @author wangh
 * @date 2024-02-18
 */
@Controller
@RequestMapping("/manage/record_inspection")
public class RecordInspectionController extends BaseController
{
    private String prefix = "manage/record_inspection";

    @Autowired
    private IRecordInspectionService recordInspectionService;

    @RequiresPermissions("manage:record_inspection:view")
    @GetMapping()
    public String record_inspection()
    {
        return prefix + "/record_inspection";
    }

    /**
     * 查询巡检记录列表
     */
    @RequiresPermissions("manage:record_inspection:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RecordInspection recordInspection)
    {
        startPage();
        List<RecordInspection> list = recordInspectionService.selectRecordInspectionList(recordInspection);
        return getDataTable(list);
    }

    /**
     * 导出巡检记录列表
     */
    @RequiresPermissions("manage:record_inspection:export")
    @Log(title = "巡检记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RecordInspection recordInspection)
    {
        List<RecordInspection> list = recordInspectionService.selectRecordInspectionList(recordInspection);
        ExcelUtil<RecordInspection> util = new ExcelUtil<RecordInspection>(RecordInspection.class);
        return util.exportExcel(list, "巡检记录数据");
    }

    /**
     * 新增巡检记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存巡检记录
     */
    @RequiresPermissions("manage:record_inspection:add")
    @Log(title = "巡检记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RecordInspection recordInspection)
    {
        return toAjax(recordInspectionService.insertRecordInspection(recordInspection));
    }

    /**
     * 修改巡检记录
     */
    @RequiresPermissions("manage:record_inspection:edit")
    @GetMapping("/edit/{inspectionId}")
    public String edit(@PathVariable("inspectionId") Long inspectionId, ModelMap mmap)
    {
        RecordInspection recordInspection = recordInspectionService.selectRecordInspectionByInspectionId(inspectionId);
        mmap.put("recordInspection", recordInspection);
        return prefix + "/edit";
    }

    /**
     * 修改保存巡检记录
     */
    @RequiresPermissions("manage:record_inspection:edit")
    @Log(title = "巡检记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RecordInspection recordInspection)
    {
        return toAjax(recordInspectionService.updateRecordInspection(recordInspection));
    }

    /**
     * 删除巡检记录
     */
    @RequiresPermissions("manage:record_inspection:remove")
    @Log(title = "巡检记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(recordInspectionService.deleteRecordInspectionByInspectionIds(ids));
    }
}
