package com.fs.crm.controller;

import java.util.List;

import com.fs.common.core.domain.R;
import com.fs.common.utils.ServletUtils;
import com.fs.core.security.LoginUser;

import com.fs.crm.vo.CrmCustomerAssignListVO;
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.core.web.service.TokenService;
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.CrmCustomerAssign;
import com.fs.crm.service.ICrmCustomerAssignService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 客户分配记录Controller
 *
 * @author fs
 * @date 2023-03-30
 */
@RestController
@RequestMapping("/crm/customerAssign")
public class CrmCustomerAssignController extends BaseController
{
    @Autowired
    private ICrmCustomerAssignService crmCustomerAssignService;
    @Autowired
    private TokenService tokenService;
    /**
     * 查询客户分配记录列表
     */
    @PreAuthorize("@ss.hasPermi('crm:customerAssign:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmCustomerAssign crmCustomerAssign)
    {
        startPage();
        List<CrmCustomerAssignListVO> list = crmCustomerAssignService.selectCrmCustomerAssignListVO(crmCustomerAssign);
        return getDataTable(list);
    }

    /**
     * 导出客户分配记录列表
     */
    @PreAuthorize("@ss.hasPermi('crm:customerAssign:export')")
    @Log(title = "客户分配记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CrmCustomerAssign crmCustomerAssign)
    {
        List<CrmCustomerAssign> list = crmCustomerAssignService.selectCrmCustomerAssignList(crmCustomerAssign);
        ExcelUtil<CrmCustomerAssign> util = new ExcelUtil<CrmCustomerAssign>(CrmCustomerAssign.class);
        return util.exportExcel(list, "customerAssign");
    }

    /**
     * 获取客户分配记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('crm:customerAssign:query')")
    @GetMapping(value = "/{assignId}")
    public AjaxResult getInfo(@PathVariable("assignId") Long assignId)
    {
        return AjaxResult.success(crmCustomerAssignService.selectCrmCustomerAssignById(assignId));
    }

    @PreAuthorize("@ss.hasPermi('crm:customerAssign:cancel')")
    @PostMapping("/cancel")
    public R cancel(@RequestBody CrmCustomerAssign crmCustomerAssign)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        String operName = loginUser.getUsername();
        return crmCustomerAssignService.cancel(crmCustomerAssign,operName);
    }


}
