package com.goldenwater.web.controller.pms;

import com.goldenwater.slgc.entity.pms.PmsCompany;
import com.goldenwater.slgc.service.pms.IPmsCompanyService;
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/company")
public class PmsCompanyController extends BaseController {
    @Autowired
    private IPmsCompanyService pmsCompanyService;

    /**
     * 查询单位列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PmsCompany company) {
        startPage();
        List<PmsCompany> list = pmsCompanyService.selectList(company);
        return getDataTable(list);
    }

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

    /**
     * 新增单位
     */
    @Log(title = "单位管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmsCompany company) {
        return toAjax(pmsCompanyService.insert(company));
    }

    /**
     * 修改单位
     */
    @Log(title = "单位管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsCompany company) {
        return toAjax(pmsCompanyService.update(company));
    }

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