package com.goldenwater.web.controller.pms;

import com.goldenwater.slgc.entity.pms.PmsChange;
import com.goldenwater.slgc.service.pms.IPmsChangeService;
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/change")
public class PmsChangeController extends BaseController {
    @Autowired
    private IPmsChangeService pmsChangeService;

    /**
     * 查询变更列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PmsChange change) {
        startPage();
        List<PmsChange> list = pmsChangeService.selectList(change);
        return getDataTable(list);
    }

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

    /**
     * 新增变更
     */
    @Log(title = "变更管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmsChange change) {
        return toAjax(pmsChangeService.insert(change));
    }

    /**
     * 修改变更
     */
    @Log(title = "变更管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsChange change) {
        return toAjax(pmsChangeService.update(change));
    }

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