package com.huashe.park.application.web.controller.park;

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

import com.huashe.park.core.service.IParkInspectTaskService;
import com.huashe.park.domain.entity.ParkInspectTask;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.huashe.common.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 巡检任务Controller
 *
 * @author ruoyi
 * @date 2025-01-07
 */
@RestController
@RequestMapping("/park/inspectTask")
public class ParkInspectTaskController extends BaseController {
    @Autowired
    private IParkInspectTaskService parkInspectTaskService;

    /**
     * 查询巡检任务列表
     */
    @PreAuthorize("@ss.hasPermi('park:inspectTask:list')")
    @GetMapping("/list")
    public TableDataInfo list(ParkInspectTask parkInspectTask) {
        startPage();
        List<ParkInspectTask> list = parkInspectTaskService.selectParkInspectTaskList(parkInspectTask);
        return getDataTable(list);
    }

    /**
     * 导出巡检任务列表
     */
    @PreAuthorize("@ss.hasPermi('park:inspectTask:export')")
    @Log(title = "巡检任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParkInspectTask parkInspectTask) {
        List<ParkInspectTask> list = parkInspectTaskService.selectParkInspectTaskList(parkInspectTask);
        ExcelUtil<ParkInspectTask> util = new ExcelUtil<ParkInspectTask>(ParkInspectTask.class);
        util.exportExcel(response, list, "巡检任务数据");
    }

    /**
     * 获取巡检任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('park:inspectTask:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(parkInspectTaskService.selectParkInspectTaskById(id));
    }

    /**
     * 新增巡检任务
     */
    @PreAuthorize("@ss.hasPermi('park:inspectTask:add')")
    @Log(title = "巡检任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParkInspectTask parkInspectTask) {
        return toAjax(parkInspectTaskService.insertParkInspectTask(parkInspectTask));
    }

    /**
     * 修改巡检任务
     */
    @PreAuthorize("@ss.hasPermi('park:inspectTask:edit')")
    @Log(title = "巡检任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParkInspectTask parkInspectTask) {
        return toAjax(parkInspectTaskService.updateParkInspectTask(parkInspectTask));
    }

    /**
     * 删除巡检任务
     */
    @PreAuthorize("@ss.hasPermi('park:inspectTask:remove')")
    @Log(title = "巡检任务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(parkInspectTaskService.deleteParkInspectTaskByIds(ids));
    }
}
