package com.fs.crm.controller;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.domain.R;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.ServletUtils;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.core.security.LoginUser;
import com.fs.core.web.service.TokenService;
import com.fs.crm.domain.CrmCustomerExt;
import com.fs.crm.service.ICrmCustomerExtService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客户字段扩展Controller
 * 
 * @author fs
 * @date 2023-03-14
 */
@RestController
@RequestMapping("/crm/customerExt")
public class CrmCustomerExtController extends BaseController
{
    @Autowired
    private ICrmCustomerExtService crmCustomerExtService;
    @Autowired
    private TokenService tokenService;
    /**
     * 查询客户字段扩展列表
     */
    @GetMapping("/list")
    public R list(CrmCustomerExt crmCustomerExt)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        crmCustomerExt.setCompanyId(loginUser.getCompany().getCompanyId());
        List<CrmCustomerExt> list = crmCustomerExtService.selectCrmCustomerExtList(crmCustomerExt);
        return R.ok().put("data",list);
    }

    /**
     * 获取客户字段扩展详细信息
     */
    @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)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        crmCustomerExt.setCompanyId(loginUser.getCompany().getCompanyId());
        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));
    }
}
