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.CrmCustomerAssign;
import com.fs.crm.service.ICrmCustomerAssignService;
import com.fs.crm.vo.CrmCustomerAssignListVO;
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-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();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        crmCustomerAssign.setCompanyId(loginUser.getCompany().getCompanyId());
        List<CrmCustomerAssignListVO> list = crmCustomerAssignService.selectCompanyCrmCustomerAssignList(crmCustomerAssign);
        return getDataTable(list);
    }



    @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);
    }


}
