package com.fs.company.controller.crm;

import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.R;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.utils.ServletUtils;
import com.fs.crm.domain.CrmCustomerAssign;
import com.fs.crm.service.ICrmCustomerAssignService;
import com.fs.crm.vo.CrmCustomerAssignListVO;
import com.fs.framework.security.LoginUser;
import com.fs.framework.security.SecurityUtils;
import com.fs.framework.service.TokenService;
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 = SecurityUtils.getLoginUser();
        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);
    }


}
