package com.xinda.itsm.controller;

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

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
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;
import com.xinda.common.annotation.Log;
import com.xinda.common.core.controller.BaseController;
import com.xinda.common.core.domain.AjaxResult;
import com.xinda.common.enums.BusinessType;
import com.xinda.itsm.domain.InspectionPlan;
import com.xinda.itsm.service.IInspectionPlanService;
import com.xinda.common.utils.poi.ExcelUtil;
import com.xinda.common.core.page.TableDataInfo;

/**
 * 巡检计划Controller
 *
 * @author kerwincui
 * @date 2025-04-23
 */
@RestController
@RequestMapping("/itsm/plan")
@Api(tags = "巡检计划")
public class InspectionPlanController extends BaseController
{
    @Autowired
    private IInspectionPlanService inspectionPlanService;

/**
 * 查询巡检计划列表
 */
@PreAuthorize("@ss.hasPermi('itsm:plan:list')")
@GetMapping("/list")
@ApiOperation("查询巡检计划列表")
    public TableDataInfo list(InspectionPlan inspectionPlan)
    {
        startPage();
        List<InspectionPlan> list = inspectionPlanService.selectInspectionPlanList(inspectionPlan);
        return getDataTable(list);
    }

    /**
     * 导出巡检计划列表
     */
    @ApiOperation("导出巡检计划列表")
    @PreAuthorize("@ss.hasPermi('itsm:plan:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, InspectionPlan inspectionPlan)
    {
        List<InspectionPlan> list = inspectionPlanService.selectInspectionPlanList(inspectionPlan);
        ExcelUtil<InspectionPlan> util = new ExcelUtil<InspectionPlan>(InspectionPlan.class);
        util.exportExcel(response, list, "巡检计划数据");
    }

    /**
     * 获取巡检计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('itsm:plan:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取巡检计划详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(inspectionPlanService.selectInspectionPlanById(id));
    }

    /**
     * 新增巡检计划
     */
    @PreAuthorize("@ss.hasPermi('itsm:plan:add')")
    @PostMapping
    @ApiOperation("新增巡检计划")
    public AjaxResult add(@RequestBody InspectionPlan inspectionPlan)
    {
        return toAjax(inspectionPlanService.insertInspectionPlan(inspectionPlan));
    }

    /**
     * 修改巡检计划
     */
    @PreAuthorize("@ss.hasPermi('itsm:plan:edit')")
    @PutMapping
    @ApiOperation("修改巡检计划")
    public AjaxResult edit(@RequestBody InspectionPlan inspectionPlan)
    {
        return toAjax(inspectionPlanService.updateInspectionPlan(inspectionPlan));
    }

    /**
     * 删除巡检计划
     */
    @PreAuthorize("@ss.hasPermi('itsm:plan:remove')")
    @DeleteMapping("/{ids}")
    @ApiOperation("删除巡检计划")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(inspectionPlanService.deleteInspectionPlanByIds(ids));
    }
}
