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.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.crm.domain.CrmCustomerUser;
import com.fs.crm.service.ICrmCustomerUserService;
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 2022-12-21
 */
@RestController
@RequestMapping("/crm/customerUser")
public class CrmCustomerUserController extends BaseController
{
    @Autowired
    private ICrmCustomerUserService crmCustomerUserService;

    /**
     * 查询客户员工认领列表
     */
    @PreAuthorize("@ss.hasPermi('crm:customerUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmCustomerUser crmCustomerUser)
    {
        startPage();
        List<CrmCustomerUser> list = crmCustomerUserService.selectCrmCustomerUserList(crmCustomerUser);
        return getDataTable(list);
    }

    /**
     * 导出客户员工认领列表
     */
    @PreAuthorize("@ss.hasPermi('crm:customerUser:export')")
    @Log(title = "客户员工认领", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CrmCustomerUser crmCustomerUser)
    {
        List<CrmCustomerUser> list = crmCustomerUserService.selectCrmCustomerUserList(crmCustomerUser);
        ExcelUtil<CrmCustomerUser> util = new ExcelUtil<CrmCustomerUser>(CrmCustomerUser.class);
        return util.exportExcel(list, "customerUser");
    }

    /**
     * 获取客户员工认领详细信息
     */
    @PreAuthorize("@ss.hasPermi('crm:customerUser:query')")
    @GetMapping(value = "/{customerUserId}")
    public AjaxResult getInfo(@PathVariable("customerUserId") Long customerUserId)
    {
        return AjaxResult.success(crmCustomerUserService.selectCrmCustomerUserById(customerUserId));
    }

    /**
     * 新增客户员工认领
     */
    @PreAuthorize("@ss.hasPermi('crm:customerUser:add')")
    @Log(title = "客户员工认领", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmCustomerUser crmCustomerUser)
    {
        return toAjax(crmCustomerUserService.insertCrmCustomerUser(crmCustomerUser));
    }

    /**
     * 修改客户员工认领
     */
    @PreAuthorize("@ss.hasPermi('crm:customerUser:edit')")
    @Log(title = "客户员工认领", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmCustomerUser crmCustomerUser)
    {
        return toAjax(crmCustomerUserService.updateCrmCustomerUser(crmCustomerUser));
    }

    /**
     * 删除客户员工认领
     */
    @PreAuthorize("@ss.hasPermi('crm:customerUser:remove')")
    @Log(title = "客户员工认领", businessType = BusinessType.DELETE)
	@DeleteMapping("/{customerUserIds}")
    public AjaxResult remove(@PathVariable Long[] customerUserIds)
    {
        return toAjax(crmCustomerUserService.deleteCrmCustomerUserByIds(customerUserIds));
    }
}
