package com.goldenwater.web.controller.pms;

import com.goldenwater.slgc.entity.pms.PmsProject;
import com.goldenwater.slgc.service.pms.IPmsProjectService;
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/project")
public class PmsProjectController extends BaseController {
    @Autowired
    private IPmsProjectService pmsProjectService;

    /**
     * 查询项目列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PmsProject project) {
        startPage();
        List<PmsProject> list = pmsProjectService.selectList(project);
        return getDataTable(list);
    }

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

    /**
     * 新增项目
     */
    @Log(title = "项目管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmsProject project) {
        return toAjax(pmsProjectService.insert(project));
    }

    /**
     * 修改项目
     */
    @Log(title = "项目管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsProject project) {
        return toAjax(pmsProjectService.update(project));
    }

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