package com.fastbee.data.controller.xunjian;

import com.fastbee.common.annotation.Log;
import com.fastbee.common.core.controller.BaseController;
import com.fastbee.common.core.domain.AjaxResult;
import com.fastbee.common.core.page.TableDataInfo;
import com.fastbee.common.enums.BusinessType;
import com.fastbee.common.utils.poi.ExcelUtil;
import com.fastbee.xunjian.domain.XjInspectionNote;
import com.fastbee.xunjian.service.IXjInspectionNoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 巡检注意事项Controller
 *
 * @author kenlixunjian
 * @date 2023-08-23
 */
@RestController
@RequestMapping("/inspection/note")
public class XjInspectionNoteController extends BaseController {
    @Autowired
    private IXjInspectionNoteService klxjInspectionNoteService;

    /**
     * 查询巡检注意事项列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:note:list')")
    @GetMapping("/list")
    public TableDataInfo list(XjInspectionNote klxjInspectionNote) {
        startPage();
        List<XjInspectionNote> list = klxjInspectionNoteService.selectXjInspectionNoteList(klxjInspectionNote);
        return getDataTable(list);
    }

    /**
     * 导出巡检注意事项列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:note:export')")
    @Log(title = "巡检注意事项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XjInspectionNote klxjInspectionNote) {
        List<XjInspectionNote> list = klxjInspectionNoteService.selectXjInspectionNoteList(klxjInspectionNote);
        ExcelUtil<XjInspectionNote> util = new ExcelUtil<XjInspectionNote>(XjInspectionNote.class);
        util.exportExcel(response, list, "巡检注意事项数据");
    }

    /**
     * 获取巡检注意事项详细信息
     */
    @PreAuthorize("@ss.hasPermi('inspection:note:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(klxjInspectionNoteService.selectXjInspectionNoteById(id));
    }

    /**
     * 新增巡检注意事项
     */
    @PreAuthorize("@ss.hasPermi('inspection:note:add')")
    @Log(title = "巡检注意事项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XjInspectionNote klxjInspectionNote) {
        return toAjax(klxjInspectionNoteService.insertXjInspectionNote(klxjInspectionNote));
    }

    /**
     * 修改巡检注意事项
     */
    @PreAuthorize("@ss.hasPermi('inspection:note:edit')")
    @Log(title = "巡检注意事项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XjInspectionNote klxjInspectionNote) {
        return toAjax(klxjInspectionNoteService.updateXjInspectionNote(klxjInspectionNote));
    }

    /**
     * 删除巡检注意事项
     */
    @PreAuthorize("@ss.hasPermi('inspection:note:remove')")
    @Log(title = "巡检注意事项", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(klxjInspectionNoteService.deleteXjInspectionNoteByIds(ids));
    }
}
