package com.sundot.airport.web.controller.system;

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

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.sundot.airport.common.annotation.Log;
import com.sundot.airport.common.core.controller.BaseController;
import com.sundot.airport.common.core.domain.AjaxResult;
import com.sundot.airport.common.enums.BusinessType;
import com.sundot.airport.system.domain.SysWorkingDocument;
import com.sundot.airport.system.service.ISysWorkingDocumentService;
import com.sundot.airport.common.utils.poi.ExcelUtil;
import com.sundot.airport.common.core.page.TableDataInfo;

/**
 * 工作文档Controller
 *
 * @author ruoyi
 * @date 2025-11-18
 */
@RestController
@RequestMapping("/system/workingDocument")
public class SysWorkingDocumentController extends BaseController {
    @Autowired
    private ISysWorkingDocumentService sysWorkingDocumentService;

    /**
     * 查询工作文档列表
     */
    @PreAuthorize("@ss.hasPermi('system:workingDocument:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysWorkingDocument sysWorkingDocument) {
        startPage();
        List<SysWorkingDocument> list = sysWorkingDocumentService.selectSysWorkingDocumentList(sysWorkingDocument);
        return getDataTable(list);
    }

    /**
     * 导出工作文档列表
     */
    @PreAuthorize("@ss.hasPermi('system:workingDocument:export')")
    @Log(title = "工作文档", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysWorkingDocument sysWorkingDocument) {
        List<SysWorkingDocument> list = sysWorkingDocumentService.selectSysWorkingDocumentList(sysWorkingDocument);
        ExcelUtil<SysWorkingDocument> util = new ExcelUtil<SysWorkingDocument>(SysWorkingDocument.class);
        util.exportExcel(response, list, "工作文档数据");
    }

    /**
     * 获取工作文档详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:workingDocument:query')")
    @GetMapping(value = "/{documentId}")
    public AjaxResult getInfo(@PathVariable("documentId") Long documentId) {
        return success(sysWorkingDocumentService.selectSysWorkingDocumentByDocumentId(documentId));
    }

    /**
     * 新增工作文档
     */
    @PreAuthorize("@ss.hasPermi('system:workingDocument:add')")
    @Log(title = "工作文档", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysWorkingDocument sysWorkingDocument) {
        sysWorkingDocument.setCreateByUserId(getUserId());
        sysWorkingDocument.setCreateBy(getLoginUser().getUser().getNickName());
        return toAjax(sysWorkingDocumentService.insertSysWorkingDocument(sysWorkingDocument));
    }

    /**
     * 修改工作文档
     */
    @PreAuthorize("@ss.hasPermi('system:workingDocument:edit')")
    @Log(title = "工作文档", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysWorkingDocument sysWorkingDocument) {
        sysWorkingDocument.setUpdateByUserId(getUserId());
        sysWorkingDocument.setUpdateBy(getLoginUser().getUser().getNickName());
        return toAjax(sysWorkingDocumentService.updateSysWorkingDocument(sysWorkingDocument));
    }

    /**
     * 删除工作文档
     */
    @PreAuthorize("@ss.hasPermi('system:workingDocument:remove')")
    @Log(title = "工作文档", businessType = BusinessType.DELETE)
    @DeleteMapping("/{documentIds}")
    public AjaxResult remove(@PathVariable Long[] documentIds) {
        return toAjax(sysWorkingDocumentService.deleteSysWorkingDocumentByDocumentIds(documentIds));
    }
}
