package com.goldenwater.web.controller.pms;

import com.goldenwater.slgc.entity.pms.PmsContact;
import com.goldenwater.slgc.service.pms.IPmsContactService;
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/contact")
public class PmsContactController extends BaseController {
    @Autowired
    private IPmsContactService pmsContactService;

    /**
     * 查询联系人列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PmsContact contact) {
        startPage();
        List<PmsContact> list = pmsContactService.selectList(contact);
        return getDataTable(list);
    }

    /**
     * 获取联系人详细信息
     */
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(pmsContactService.selectById(id));
    }

    /**
     * 新增联系人
     */
    @Log(title = "联系人管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmsContact contact) {
        return toAjax(pmsContactService.insert(contact));
    }

    /**
     * 修改联系人
     */
    @Log(title = "联系人管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsContact contact) {
        return toAjax(pmsContactService.update(contact));
    }

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