package com.fs.crm.controller;

import java.util.List;

import com.fs.common.utils.ServletUtils;
import com.fs.core.security.LoginUser;
import com.fs.core.web.service.TokenService;
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.CrmCustomerThird;
import com.fs.crm.service.ICrmCustomerThirdService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 客户线索三方平台Controller
 *
 * @author fs
 * @date 2023-07-11
 */
@RestController
@RequestMapping("/crm/third")
public class CrmCustomerThirdController extends BaseController
{
    @Autowired
    private ICrmCustomerThirdService crmCustomerThirdService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询客户线索三方平台列表
     */
    @PreAuthorize("@ss.hasPermi('crm:third:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmCustomerThird crmCustomerThird)
    {
        startPage();
        List<CrmCustomerThird> list = crmCustomerThirdService.selectCrmCustomerThirdList(crmCustomerThird);
        return getDataTable(list);
    }

    /**
     * 导出客户线索三方平台列表
     */
    @PreAuthorize("@ss.hasPermi('crm:third:export')")
    @Log(title = "客户线索三方平台", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CrmCustomerThird crmCustomerThird)
    {
        List<CrmCustomerThird> list = crmCustomerThirdService.selectCrmCustomerThirdList(crmCustomerThird);
        ExcelUtil<CrmCustomerThird> util = new ExcelUtil<CrmCustomerThird>(CrmCustomerThird.class);
        return util.exportExcel(list, "third");
    }

    /**
     * 获取客户线索三方平台详细信息
     */
    @PreAuthorize("@ss.hasPermi('crm:third:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(crmCustomerThirdService.selectCrmCustomerThirdById(id));
    }

    /**
     * 新增客户线索三方平台
     */
    @PreAuthorize("@ss.hasPermi('crm:third:add')")
    @Log(title = "客户线索三方平台", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmCustomerThird crmCustomerThird)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        crmCustomerThird.setCreateUserId(loginUser.getUser().getUserId());
        return toAjax(crmCustomerThirdService.insertCrmCustomerThird(crmCustomerThird));
    }

    /**
     * 修改客户线索三方平台
     */
    @PreAuthorize("@ss.hasPermi('crm:third:edit')")
    @Log(title = "客户线索三方平台", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmCustomerThird crmCustomerThird)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        crmCustomerThird.setUpdateUserId(loginUser.getUser().getUserId());
        return toAjax(crmCustomerThirdService.updateCrmCustomerThird(crmCustomerThird));
    }

    /**
     * 删除客户线索三方平台
     */
    @PreAuthorize("@ss.hasPermi('crm:third:delete')")
    @Log(title = "客户线索三方平台", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(crmCustomerThirdService.deleteCrmCustomerThirdByIds(ids));
    }
}
