package com.ruoyi.ibs.customerselect.controller;

import com.github.pagehelper.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataPageInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ibs.customerselect.domain.*;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.ibs.customerselect.service.IMyCustomerService;
import com.ruoyi.ibs.dashboard.domain.vo.CommonRespVO;
import com.ruoyi.ibs.dashboard.service.DashboardService;
import com.ruoyi.ibs.grid.domain.excel.NewPersonAnchor;
import com.ruoyi.ibs.list.domain.CustManualTagDTO;
import com.ruoyi.ibs.list.domain.CustTagVo;
import com.ruoyi.ibs.list.domain.TreeNode;
import com.ruoyi.ibs.list.service.ISysCampaignGroupCustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.rmi.ServerException;
import java.util.*;

/**
 * 我的客户 控制类
 *
 * @author ruoyi
 */
@Api(tags="客户基本信息管理")
@RestController
@RequestMapping("/system/custBaseInfo")
public class MyCustomerController extends BaseController {

    @Autowired
    private IMyCustomerService myCustomerService;

    @Autowired
    ISysCampaignGroupCustomerService iSysCampaignGroupCustomerService;

    @Autowired
    private DashboardService dashboardService;

    private static Logger logger= LoggerFactory.getLogger(MyCustomerController.class);
    /**
     * 获取我的客户信息列表
     */
//    @PreAuthorize("@ss.hasPermi('system:custBaseInfo:list')")
    @Log(title = "我的客户-获取客户信息列表")
    @PostMapping("/list")
    @ApiOperation("获取客户信息列表")
    public AjaxResult list(@RequestBody CustBaseInfo sysCustomerBasedata)
//    public TableDataPageInfo<CustBaseInfo> list(CustBaseInfo sysCustomerBasedata)
    {
//        Page<Object> page = startPage();
        List<CustBaseInfo> custBaseInfoList = myCustomerService.selectSysCustomerBasedataList(sysCustomerBasedata);
        logger.info(custBaseInfoList.toString());
//        return getDataTable(custBaseInfoList ,page);
        return AjaxResult.success(custBaseInfoList);
    }

    @Log(title = "我的客户-获取商户云相关信息")
    @GetMapping("/merchantMessage")
    @ApiOperation("获取商户云相关信息")
    public AjaxResult merchantMessage( String  custId)
//    public TableDataPageInfo<CustBaseInfo> list(CustBaseInfo sysCustomerBasedata)
    {
//        Page<Object> page = startPage();
        MerchantMcspInfo merchantMcspInfo = myCustomerService.selectmerchantMessage(custId);
//        logger.info(merchantMcspInfo.toString());
//        return getDataTable(custBaseInfoList ,page);
        return AjaxResult.success(merchantMcspInfo);
    }

    @GetMapping("/tagList")
    @ApiOperation("获取客户信息標簽列表")
    public AjaxResult list(@Valid @NotNull String custId,@Valid @NotNull String custType)
    {
        List<TreeNode> hashMaps = myCustomerService.selectCustEnumByCustId(custId,custType);
        return AjaxResult.success(hashMaps);
    }

    @GetMapping("/manualTagList")
    @ApiOperation("获取自定义客户标签列表")
    public AjaxResult manualList(@Valid @NotNull String custId,@Valid @NotNull String custType)
    {
        List<TreeNode> hashMaps = myCustomerService.selectmanualListByCustId(custId,custType);
        return AjaxResult.success(hashMaps);
    }


    @PostMapping(value = "/editCustTag")
    @ApiOperation("修改客户标签")
    public R<Objects> editCustTag(@RequestBody CustTagDTO custTagDTO)  {

        myCustomerService.editCustTag(custTagDTO);
        return R.ok();
    }

    @PostMapping(value = "/editManualTag")
    @ApiOperation("修改手动标签")
    public R<Objects> editManualTag(@RequestBody CustManualTagDTO custManualTagDTO)  {
        myCustomerService.editManualTag(custManualTagDTO);
        return R.ok();
    }

    @GetMapping("/specialTagList")
    @ApiOperation("获取青田特色商户标签列表")
    public AjaxResult specialTagList(String custId)
    {
        CommonRespVO tagList = dashboardService.getTagList(custId);
        return AjaxResult.success(tagList.getData());
    }

}
