package com.fs.crm.controller;

import java.util.List;

import com.fs.common.core.domain.R;
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.CrmCustomerExt;
import com.fs.crm.service.ICrmCustomerExtService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 客户字段扩展Controller
 * 
 * @author fs
 * @date 2023-03-14
 */
@RestController
@RequestMapping("/crm/customerExt")
public class CrmCustomerExtController extends BaseController
{
    @Autowired
    private ICrmCustomerExtService crmCustomerExtService;

    /**
     * 查询客户字段扩展列表
     */
    @GetMapping("/list")
    public R list(CrmCustomerExt crmCustomerExt)
    {
        List<CrmCustomerExt> list = crmCustomerExtService.selectCrmCustomerExtList(crmCustomerExt);
        return R.ok().put("data",list);
    }

    /**
     * 导出客户字段扩展列表
     */
    @Log(title = "客户字段扩展", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CrmCustomerExt crmCustomerExt)
    {
        List<CrmCustomerExt> list = crmCustomerExtService.selectCrmCustomerExtList(crmCustomerExt);
        ExcelUtil<CrmCustomerExt> util = new ExcelUtil<CrmCustomerExt>(CrmCustomerExt.class);
        return util.exportExcel(list, "customerExt");
    }

    /**
     * 获取客户字段扩展详细信息
     */
    @GetMapping(value = "/{extId}")
    public AjaxResult getInfo(@PathVariable("extId") Long extId)
    {
        return AjaxResult.success(crmCustomerExtService.selectCrmCustomerExtById(extId));
    }

    /**
     * 新增客户字段扩展
     */
    @Log(title = "客户字段扩展", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmCustomerExt crmCustomerExt)
    {
        return toAjax(crmCustomerExtService.insertCrmCustomerExt(crmCustomerExt));
    }

    /**
     * 修改客户字段扩展
     */
    @Log(title = "客户字段扩展", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmCustomerExt crmCustomerExt)
    {
        return toAjax(crmCustomerExtService.updateCrmCustomerExt(crmCustomerExt));
    }

    /**
     * 删除客户字段扩展
     */
    @Log(title = "客户字段扩展", businessType = BusinessType.DELETE)
	@DeleteMapping("/{extIds}")
    public AjaxResult remove(@PathVariable Long[] extIds)
    {
        return toAjax(crmCustomerExtService.deleteCrmCustomerExtByIds(extIds));
    }
}
