package com.fs.crm.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.crm.domain.CrmCustomerContacts;
import com.fs.crm.service.ICrmCustomerContactsService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 客户联系人Controller
 * 
 * @author fs
 * @date 2023-03-14
 */
@RestController
@RequestMapping("/crm/customerContacts")
public class CrmCustomerContactsController extends BaseController
{
    @Autowired
    private ICrmCustomerContactsService crmCustomerContactsService;

    /**
     * 查询客户联系人列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CrmCustomerContacts crmCustomerContacts)
    {
        startPage();
        List<CrmCustomerContacts> list = crmCustomerContactsService.selectCrmCustomerContactsList(crmCustomerContacts);
        return getDataTable(list);
    }

    /**
     * 导出客户联系人列表
     */
    @PreAuthorize("@ss.hasPermi('crm:customerContacts:export')")
    @Log(title = "客户联系人", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CrmCustomerContacts crmCustomerContacts)
    {
        List<CrmCustomerContacts> list = crmCustomerContactsService.selectCrmCustomerContactsList(crmCustomerContacts);
        ExcelUtil<CrmCustomerContacts> util = new ExcelUtil<CrmCustomerContacts>(CrmCustomerContacts.class);
        return util.exportExcel(list, "customerContacts");
    }

    /**
     * 获取客户联系人详细信息
     */
    @GetMapping(value = "/{contactsId}")
    public AjaxResult getInfo(@PathVariable("contactsId") Long contactsId)
    {
        return AjaxResult.success(crmCustomerContactsService.selectCrmCustomerContactsById(contactsId));
    }

    /**
     * 新增客户联系人
     */
    @Log(title = "客户联系人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmCustomerContacts crmCustomerContacts)
    {
        return toAjax(crmCustomerContactsService.insertCrmCustomerContacts(crmCustomerContacts));
    }

    /**
     * 修改客户联系人
     */
    @Log(title = "客户联系人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmCustomerContacts crmCustomerContacts)
    {
        return toAjax(crmCustomerContactsService.updateCrmCustomerContacts(crmCustomerContacts));
    }

    /**
     * 删除客户联系人
     */
    @Log(title = "客户联系人", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contactsIds}")
    public AjaxResult remove(@PathVariable Long[] contactsIds)
    {
        return toAjax(crmCustomerContactsService.deleteCrmCustomerContactsByIds(contactsIds));
    }
}
