package com.goldenwater.web.controller.pms;

import com.goldenwater.slgc.entity.pms.PmsDocument;
import com.goldenwater.slgc.service.pms.IPmsDocumentService;
import com.goldenwater.common.core.controller.BaseController;
import com.goldenwater.common.core.domain.AjaxResult;
import com.goldenwater.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.goldenwater.common.annotation.Log;
import com.goldenwater.common.enums.BusinessType;
import org.springframework.validation.annotation.Validated;

import java.util.List;

@RestController
@Validated
@RequestMapping("/pms/document")
public class PmsDocumentController extends BaseController {
    @Autowired
    private IPmsDocumentService pmsDocumentService;

    /**
     * 查询文档列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PmsDocument document) {
        startPage();
        List<PmsDocument> list = pmsDocumentService.selectList(document);
        return getDataTable(list);
    }

    /**
     * 获取文档详细信息
     */
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(pmsDocumentService.selectById(id));
    }

    /**
     * 新增文档
     */
    @Log(title = "文档管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmsDocument document) {
        return toAjax(pmsDocumentService.insert(document));
    }

    /**
     * 修改文档
     */
    @Log(title = "文档管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsDocument document) {
        return toAjax(pmsDocumentService.update(document));
    }

    /**
     * 删除文档
     */
    @Log(title = "文档管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(pmsDocumentService.deleteByIds(ids));
    }
}
