package com.ruixuan.salesLeads.controller;


import com.alibaba.fastjson.JSONObject;
import com.ruixuan.common.annotation.RateLimiter;
import com.ruixuan.common.core.controller.BaseController;
import com.ruixuan.common.core.domain.ResultResponse;
import com.ruixuan.common.core.domain.entity.SysRole;
import com.ruixuan.common.utils.DateUtils;
import com.ruixuan.common.utils.StringUtils;
import com.ruixuan.common.utils.file.FileTypeUtils;
import com.ruixuan.salesLeads.pojo.*;
import com.ruixuan.salesLeads.pojo.vo.PolicyApprovalVo;
import com.ruixuan.salesLeads.pojo.vo.SaleFinancePolicyInfoVo;
import com.ruixuan.salesLeads.pojo.vo.SaleTaskInfoVo;
import com.ruixuan.salesLeads.service.ISaleClueCallRecordService;
import com.ruixuan.salesLeads.service.ISaleClueInfoService;
import com.ruixuan.salesLeads.service.ISaleFinacePolicyService;
import com.ruixuan.salesLeads.service.impl.TelephoneRobotServiceImpl;
import com.ruixuan.system.service.ISysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.*;
import java.util.stream.Collectors;

/**
 * ***************************************************
 *
 * @Auther: zianY
 * @Descipion: 政策
 * @CreateDate: 2022-05-19
 * ****************************************************
 */


@Slf4j
@Api(tags = "政策结算",description = "saleFinacePolicyController")
@RestController
@RequestMapping("sale/saleFinacePolicyController")
public class SaleFinacePolicyController extends BaseController {


    @Autowired
    private ISaleClueInfoService saleClueInfoServiceImpl;


    @Autowired
    private TelephoneRobotServiceImpl telephoneRobotService;

    @Autowired
    private ISaleFinacePolicyService saleFinacePolicyService;


    @Autowired
    private ISysRoleService sysRoleService;






    @ApiOperation(value = "政策列表查询",notes = "政策列表查询")
    @GetMapping(value = "/selectPolicyList")
    public ResultResponse<List<SaleFinancePolicyInfoPojo>> selectPolicyList(SaleFinancePolicyInfoVo saleFinancePolicyInfoVo){
        //查询用户角色
        String roleList = sysRoleService.selectRoleByUserId(Long.valueOf(saleFinancePolicyInfoVo.getCreateUserId()));
        if (roleList.equals("admin")){
            saleFinancePolicyInfoVo.setCreateUserId(null);
        }
        return saleFinacePolicyService.selectPolicyList(saleFinancePolicyInfoVo);

    }


    @ApiOperation(value = "查看政策详情",notes = "根据政策id查看政策详情")
    @GetMapping(value = "/selectPolicyInfoById")
    public ResultResponse<SaleFinancePolicyInfoPojo> selectPolicyInfoById(@ApiParam("政策id") @RequestParam(value = "policyId")String policyId){

        return saleFinacePolicyService.selectPolicyInfoById(policyId);

    }


    @ApiOperation(value = "新增政策",notes = "新增政策")
    @PostMapping(value = "/addSaleFinancePolicyInfo")
    public ResultResponse addSaleFinancePolicyInfo(@RequestBody SaleFinancePolicyInfoPojo policyInfoPojo){

        return saleFinacePolicyService.addSaleFinancePolicyInfo(policyInfoPojo);

    }


    @ApiOperation(value = "政策返点比例查询",notes = "政策返点比例查询")
    @PostMapping(value = "/selectFinacePolicyRebateInfo")
    public ResultResponse<SaleFinancePolicyRebateInfoPojo> selectFinacePolicyRebateInfo(){
        return saleFinacePolicyService.selectFinacePolicyRebateInfo();
    }


    @ApiOperation(value = "新增政策的返点比例",notes = "新增政策的返点比例")
    @PostMapping(value = "/addSaleFinancePolicyRebateInfo")
    public ResultResponse addSaleFinancePolicyRebateInfo(@RequestBody SaleFinancePolicyRebateInfoPojo policyRebateInfoPojo){
        return saleFinacePolicyService.addSaleFinancePolicyRebateInfo(policyRebateInfoPojo);
    }



    @ApiOperation(value = "政策审核",notes = "政策审核")
    @PostMapping(value = "/policyApproval")
    public ResultResponse policyApproval(@RequestBody PolicyApprovalVo policyApprovalVo){
        return saleFinacePolicyService.policyApproval(policyApprovalVo);
    }




    @ApiOperation(value = "政策手动转审",notes = "政策审核")
    @PostMapping(value = "/policyApprovalManual")
    public ResultResponse policyApprovalManual(@RequestBody PolicyApprovalVo policyApprovalVo){
        return saleFinacePolicyService.policyApproval(policyApprovalVo);
    }



    @ApiOperation(value = "查询账户以及公司广告主列表",notes = "查询账户以及公司广告主列表")
    @GetMapping(value = "/selectPolicyCustomerList")
    public ResultResponse selectPolicyCustomerList(){
        return saleFinacePolicyService.selectPolicyCustomerList();
    }


    @ApiOperation(value = "查询公司主体列表",notes = "查询公司主体列表")
    @GetMapping(value = "/selectCompanySubjectInfoList")
    public ResultResponse<SaleFinanceCompanySubjectInfoPojo> selectCompanySubjectInfoList(){
        return saleFinacePolicyService.selectCompanySubjectInfoList();
    }




}
