package com.aucma.base.controller;

import com.aucma.base.domain.ProcessDocument;
import com.aucma.base.service.IProcessDocumentService;
import com.aucma.common.annotation.Log;
import com.aucma.common.core.controller.BaseController;
import com.aucma.common.core.domain.AjaxResult;
import com.aucma.common.core.page.TableDataInfo;
import com.aucma.common.enums.BusinessType;
import com.aucma.common.utils.DateUtils;
import com.aucma.common.utils.poi.ExcelUtil;
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 Yinq
 * @date 2025-12-30
 */
@RestController
@RequestMapping("/base/processDocument")
public class ProcessDocumentController extends BaseController {
    @Autowired
    private IProcessDocumentService processDocumentService;

    @PreAuthorize("@ss.hasPermi('base:processDocument:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProcessDocument processDocument) {
        startPage();
        List<ProcessDocument> list = processDocumentService.selectProcessDocumentList(processDocument);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('base:processDocument:export')")
    @Log(title = "工艺文档", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProcessDocument processDocument) {
        List<ProcessDocument> list = processDocumentService.selectProcessDocumentList(processDocument);
        ExcelUtil<ProcessDocument> util = new ExcelUtil<ProcessDocument>(ProcessDocument.class);
        util.exportExcel(response, list, "工艺文档数据");
    }

    @PreAuthorize("@ss.hasPermi('base:processDocument:query')")
    @GetMapping(value = "/{docId}")
    public AjaxResult getInfo(@PathVariable("docId") Long docId) {
        return success(processDocumentService.selectProcessDocumentByDocId(docId));
    }

    @PreAuthorize("@ss.hasPermi('base:processDocument:add')")
    @Log(title = "工艺文档", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProcessDocument processDocument) {
        processDocument.setCreateBy(getUsername());
        return toAjax(processDocumentService.insertProcessDocument(processDocument));
    }

    @PreAuthorize("@ss.hasPermi('base:processDocument:edit')")
    @Log(title = "工艺文档", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProcessDocument processDocument) {
        processDocument.setUpdateBy(getUsername());
        return toAjax(processDocumentService.updateProcessDocument(processDocument));
    }

    @PreAuthorize("@ss.hasPermi('base:processDocument:remove')")
    @Log(title = "工艺文档", businessType = BusinessType.DELETE)
    @DeleteMapping("/{docIds}")
    public AjaxResult remove(@PathVariable Long[] docIds) {
        return toAjax(processDocumentService.deleteProcessDocumentByDocIds(docIds));
    }

    @PreAuthorize("@ss.hasPermi('base:processDocument:list')")
    @GetMapping("/getProcessDocumentList")
    public AjaxResult getProcessDocumentList(ProcessDocument processDocument) {
        List<ProcessDocument> list = processDocumentService.selectProcessDocumentList(processDocument);
        return success(list);
    }
}
