package com.ruoyi.ibs.list.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
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.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ibs.list.domain.*;
import com.ruoyi.ibs.list.service.ISysCampaignGroupCustomerService;
import com.ruoyi.ibs.list.service.ISysGroupBusinessService;
import com.ruoyi.ibs.list.service.ISysGroupCustomerService;
import com.ruoyi.ibs.list.service.ISysGroupService;
import com.ruoyi.ibs.tabs.domain.dto.ListTabDTO;
import com.ruoyi.ibs.tabs.domain.vo.CustTabIdDetailVO;
import com.ruoyi.ibs.tabs.domain.vo.CustTabListVo;
import com.ruoyi.ibs.tabs.service.ICustTabListInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.rmi.ServerException;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 客群圈选分群Controller
 *
 * @author ruoyi
 * @date 2024-09-11
 */
@RestController
@RequestMapping("/system/group")
@Api("标签管理-客群圈选")
public class SysGroupController extends BaseController
{
    @Autowired
    private ISysGroupService sysGroupService;
    @Autowired
    private ISysCampaignGroupCustomerService sysCampaignGroupCustomerService;

    @Autowired
    private ISysGroupCustomerService sysGroupCustomerService;
    @Autowired
    private ISysGroupBusinessService groupBusinessService;
    @Autowired
    private ICustTabListInfoService custTabListInfoService;


    /**
     * 查询客群圈选分群列表
     */
//    @PreAuthorize("@ss.hasPermi('system:group:list')")
    @GetMapping("/groupList")
    @ApiOperation("获取分群列表")
    @Log(title = "走访-客群圈选")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupName", value = "分群名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "groupType", value = "1我创建的，0推荐给我的", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "createBy", value = "创建者姓名", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "customerNumSort", value = "0正序,1逆序", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "updateTimeSort", value = "0正序,1逆序", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "type", value = "0对公，1对私,不传type查全部"),
    })
    public TableDataInfo list(String groupName,String groupType,String createBy,SysGroupSortVo groupSortVo,String type)
    {
        startPage();
        List<SysGroupVo> list = sysGroupService.selectSysGroupList(groupName,groupType,createBy,groupSortVo,type);
        return getDataTable(list);
    }

    @GetMapping("/groupListNoPage")
    @ApiOperation("获取未分页分群列表")
    @Log(title = "走访-客群圈选")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupName", value = "分群名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "groupType", value = "1我创建的，0推荐给我的", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "createBy", value = "创建者姓名", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "customerNumSort", value = "0正序,1逆序", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "updateTimeSort", value = "0正序,1逆序", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "type", value = "0对公，1对私,不传type查全部"),
    })
    public List<SysGroupVo> listNoPage(String groupName,String groupType,String createBy,SysGroupSortVo groupSortVo,String type)
    {

        return sysGroupService.selectSysGroupList(groupName,groupType,createBy,groupSortVo,type);
    }

    @GetMapping("/getGroupList")
    @ApiOperation("获取当前账号下分群列表")
    @Log(title = "走访-客群圈选")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "custTypes", value = "客户类型,0个人,1商户,2企业,以逗号隔开"),
    })
    public TableDataInfo list(@RequestParam(value = "custTypes") List<String> custTypes)
    {
        //startPage();
        List<SysGroup> list = sysGroupService.selectSysGroupListBydeptId();
        List<SysGroup> newList = new ArrayList<>();
        list = list.stream().filter(l->l.getCustType()!=null).collect(Collectors.toList());
        Map<String,List<SysGroup>> custsList= list.stream().collect(Collectors.groupingBy(SysGroup::getCustType));
        if (custTypes!=null){
            for (int i = 0; i <custTypes.size() ; i++) {
                if (custsList.get(custTypes.get(i))!=null&&custsList.get(custTypes.get(i)).size()>0){
                    newList.addAll(custsList.get(custTypes.get(i)));
                }
            }
        }
        return getDataTable(newList);
    }


    //    @PreAuthorize("@ss.hasPermi('system:grid:list')")
    @GetMapping("/CustomerList")
    @Log(title = "走访-客群圈选")
    @ApiOperation("获取客户列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "分群id", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "custId", value = "客户号", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "custName", value = "客户名", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "pushStatus", value = "推送状态(0代表未推送，1代表推送成功，2代表推送失败)", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "groupType", value = "0推荐给我的，1我创建的(暂时只有支行管理员需要传该参数)", dataType = "String", dataTypeClass = String.class),
    })
    public TableDataInfo CustomerList(String groupId,CustomerList customerList,String groupType)
    {
        startPage();
        List<CustomerList> list = sysGroupService.selectCustomerList(groupId,customerList,groupType);
        return getDataTable(list);
    }


    @GetMapping("/CustomerListDetail")
    @Log(title = "走访-客群圈选")
    @ApiOperation("查看客群详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "分群id", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "custId", value = "客户号", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "custName", value = "客户名", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "pushStatus", value = "推送状态(0代表未推送，1代表推送成功，2代表推送失败)", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "groupType", value = "0推荐给我的，1我创建的(暂时只有支行管理员需要传该参数)", dataType = "String", dataTypeClass = String.class),
    })
    public TableDataInfo CustomerListDetail(String groupId,CustomerList customerList,String groupType)
    {
        startPage();
        List<CustomerList> list = sysGroupService.selectCustomerListDetail(groupId,customerList,groupType);
        return getDataTable(list);
    }


    @Log(title = "走访-客群圈选，导出客群详情客户", businessType = BusinessType.IMPORT)
//    @PreAuthorize("@ss.hasPermi('system:user:export')")
    @PostMapping("/exportDataDetail")
    @ApiOperation("客群圈选，导出客群详情客户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "客群id", dataType = "String", dataTypeClass = String.class),
    })
    public void exportDataDetail(HttpServletResponse response, String groupId) throws Exception
    {
        if (groupId!=null){
            sysGroupCustomerService.selectSysGroupCustomerListDetailExport(response,groupId);
        }


    }


    //@PreAuthorize("@ss.hasPermi('system:grid:list')")
    @GetMapping("/isHead")
    @Log(title = "走访-客群圈选")
    @ApiOperation("判断当前登录账号属于总行管理员还是支行管理员或是客户经理")
    public HashMap isHead()
    {
        String operName = getUsername();
       return sysGroupService.isHead(operName);

    }

//    /**
//     * 导出客群圈选分群列表
//     */
//    @PreAuthorize("@ss.hasPermi('system:group:export')")
//    @Log(title = "走访-客群圈选分群", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, SysGroup sysGroup)
//    {
//        List<SysGroup> list = sysGroupService.selectSysGroupList(sysGroup);
//        ExcelUtil<SysGroup> util = new ExcelUtil<SysGroup>(SysGroup.class);
//        util.exportExcel(response, list, "客群圈选分群数据");
//    }

    /**
     * 获取客群圈选分群详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:group:query')")
    @GetMapping(value = "/getGroupInfoByGroupId")
    @Log(title = "走访-客群圈选")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "分群id", dataType = "String", dataTypeClass = String.class),
    })
    @ApiOperation("根据客群id获取客群详情")
    public AjaxResult getInfo(String groupId)
    {
        return success(sysGroupService.selectSysGroupByGroupId(groupId));
    }

//    /**
//     * 新增客群圈选分群
//     */
//    @PreAuthorize("@ss.hasPermi('system:group:add')")
//    @Log(title = "走访-客群圈选分群", businessType = BusinessType.INSERT)
//    @PostMapping("/add")
//    @ApiOperation("新增客群")
//    public AjaxResult add(SysGroup sysGroup)
//    {
//        return toAjax(sysGroupService.insertSysGroup(sysGroup));
//    }

    /**
     * 修改客群圈选分群
     */
    @PreAuthorize("@ss.hasPermi('system:group:edit')")
    @Log(title = "走访-客群圈选分群", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysGroup sysGroup)
    {
        return toAjax(sysGroupService.updateSysGroup(sysGroup));
    }

    /**
     * 删除客群圈选分群
     */
    @PreAuthorize("@ss.hasPermi('system:group:remove')")
    @Log(title = "走访-客群圈选分群", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysGroupService.deleteSysGroupByIds(ids));
    }

    /**
     * 修改分群客户关联关系,导入的客群用户存放在这里
     */
    //@PreAuthorize("@ss.hasPermi('system:customer:edit')")
    @Log(title = "走访-手动指定推送客户对应的客户经理", businessType = BusinessType.UPDATE)
    @PutMapping("/appoint")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "分群id", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "campaignId", value = "活动id", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "createRole", value = "指定创建角色，0总行管理员，1支行管理员", dataType = "String", dataTypeClass = String.class),

    })
    @RepeatSubmit
    @ApiOperation("手动指定推送客户对应的客户经理")
    public R<String> appoint(@RequestParam(value = "groupId" ,required = true)List<String> groupId,String campaignId,@RequestParam(value = "custIds") List<String> custIds,@RequestParam(value = "userIds" ,required = false) List<Long> userIds,@RequestParam(value = "deptIds",required = false)List<Long> deptIds,String createRole)
    {
        groupId.forEach(e->{
            sysCampaignGroupCustomerService.appoint(e,campaignId,custIds,userIds,deptIds,createRole);}
        );
        return R.ok("分配成功")   ;
    }



    @Log(title = "走访-客群圈选分群", businessType = BusinessType.UPDATE)
    @ApiOperation("客群圈选,判断客群名称是否重复")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupName", value = "客群名称,若重复，返回false,不重复,返回true", dataType = "String", dataTypeClass = String.class),
    })
    @GetMapping("/isGroupNameRepeat")
    public Boolean selectGroupName(String groupName)
    {
        int count = sysGroupService.selectByGroupName(groupName);
        Boolean flag = true;
        if (count>0){
            flag = false;
        }
        return flag;
    }
    @Log(title = "走访-客群圈选，导入客户", businessType = BusinessType.IMPORT)
//    @PreAuthorize("@ss.hasPermi('system:user:import')")
    @PostMapping("/importData")
    @ApiOperation("客群圈选，导入创建客群")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "客群创建模板", dataType = "MultipartFile", dataTypeClass = MultipartFile.class),
            @ApiImplicitParam(name = "groupName", value = "客群名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "custType", value = "客户类型 '0'个人，'1'商户，'2'企业", dataType = "String", dataTypeClass = String.class),
    })
    public AjaxResult importData(MultipartFile file, String groupName,String custType, String groupId, String importType) throws Exception
    {
        return success(sysGroupService.insertSysGroupAndCustomer(file,groupName,custType, groupId, importType));
    }

    /**
     * 异步导入
     */
    @Log(title = "走访-客群圈选，导入客户", businessType = BusinessType.IMPORT)
    @PostMapping("/importDataAsync")
    @ApiOperation("客群圈选，导入创建客群")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "客群创建模板", dataType = "MultipartFile", dataTypeClass = MultipartFile.class),
            @ApiImplicitParam(name = "groupName", value = "客群名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "custType", value = "客户类型 '0'个人，'1'商户，'2'企业", dataType = "String", dataTypeClass = String.class),
    })
    public AjaxResult importDataAsync(MultipartFile file, String groupName,String custType, String groupId, String importType) throws Exception
    {
        if(StringUtils.isBlank(groupId)){
            groupId = UUID.randomUUID().toString();
        }
        sysGroupService.insertSysGroupAndCustomerAsync(file,groupName,custType, groupId, importType);
        Map<String, String> result = new HashMap<>();
        result.put("groupId", groupId);
        result.put("message", "导入任务已提交，后台正在处理...");
        return success(result);
    }


    @PostMapping("/createGroupByRule")
    @Log(title = "走访-客群圈选")
    @ApiOperation("客群圈选，规则创建客群")
    @ApiImplicitParams({

            @ApiImplicitParam(name = "groupName", value = "客群名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "custType", value = "客户类型 '0'个人，'1'商户，'2'企业", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "labelIds", value = "规则建群标签id列表", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "description", value = "分群描述", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "updateType", value = "更新方式，0自动更新，1手动更新", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "updateTypeRelateTime", value = "自动更新方式更新时间，传0-23之间的数字即可", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "relateGroupId", value = "关联客群id，只有使用规则创建已有客群时才需要", dataType = "String", dataTypeClass = String.class),
    })
    public AjaxResult createGroupByRule(@RequestBody SysGroup sysGroup) throws Exception
    {
        String sql = custTabListInfoService.getIndexRelaitonSql(sysGroup.getTabPotAddDTO());
        sysGroup.setLabelSql(sql);
        return toAjax(sysGroupService.insertSysGroup(sysGroup));
    }


    @Log(title = "走访-客群圈选，导出客群客户", businessType = BusinessType.IMPORT)
//    @PreAuthorize("@ss.hasPermi('system:user:export')")
    @PostMapping("/exportData")
    @ApiOperation("客群圈选，导出客群客户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "客群id", dataType = "String", dataTypeClass = String.class),
    })
    public void exportData(HttpServletResponse response, String groupId) throws Exception
    {
        if (groupId!=null){
             sysGroupCustomerService.selectSysGroupCustomerListExport(response,groupId, null);
        }


    }

    @Log(title = "走访-客群圈选，导出指定客群客户列表", businessType = BusinessType.IMPORT)
//    @PreAuthorize("@ss.hasPermi('system:user:export')")
    @PostMapping("/exportDataByCustIds")
    @ApiOperation("客群圈选，导出指定客群客户列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "客群id", dataType = "String", dataTypeClass = String.class),
    })
    public void exportDataByCustIds(HttpServletResponse response, String groupId,@RequestParam(value = "custIds") List<String> custIds,@RequestParam(value ="exportType") String exportType) throws Exception
    {
        if (groupId!=null&&custIds!=null&&custIds.size()>0){
            sysGroupCustomerService.selectSysGroupCustomerListExportByCustIds(response,groupId,custIds,exportType);
        }

    }

    @Log(title = "走访-客群圈选，模板样例下载", businessType = BusinessType.IMPORT)
//    @PreAuthorize("@ss.hasPermi('system:user:export')")
    @PostMapping("/download")
    @ApiOperation("客群圈选，模板样例下载")
    public void download(HttpServletResponse response) throws Exception
    {
        SysGroupCustomer sysGroupCustomer = new SysGroupCustomer();
//        sysGroupCustomer.setCustType("个人");
//        sysGroupCustomer.setCustName("test");
//        sysGroupCustomer.setCustId("123456");
//        sysGroupCustomer.setCustIsn("123456");
//        sysGroupCustomer.setCustIdc("41090x");
//        sysGroupCustomer.setUserName("张三");
//        sysGroupCustomer.setGridName("测试一级网格");
//        sysGroupCustomer.setDeptName("测试机构");
//        sysGroupCustomer.setGridName2("测试二级网格");
//        sysGroupCustomer.setTellerId("9650999");
//        sysGroupCustomer.setOutlets("测试网点1");
//        sysGroupCustomer.setCustPhone("13888888888");
//        sysGroupCustomer.setIdType("居民二代身份证");
            List<SysGroupCustomer> list = new ArrayList<>();
            list.add(sysGroupCustomer);
            ExcelUtil<SysGroupCustomer> util = new ExcelUtil<SysGroupCustomer>(SysGroupCustomer.class);
            String org = SecurityUtils.getUsername().substring(0,3);
                if(!(org.equals("931")
                    ||org.equals("932")
                    ||org.equals("933")
                    ||org.equals("935")
                    ||org.equals("936")
                    ||org.equals("937")
                    ||org.equals("938")
                    ||org.equals("939")
                    ||org.equals("951"))){
                util.hideColumn("detailAddress","industry","asset","credit");
            }
            util.exportExcel(response, list, "客群圈选，模板样例下载");
    }

//    @PostMapping("/downloadtest")
//    @ApiOperation("客群圈选，模板样例下载10000条")
//    public void downloadtest(HttpServletResponse response,String type) throws Exception
//    {
//        SysGroupCustomer sysGroupCustomer = new SysGroupCustomer();
//        sysGroupCustomer.setCustName("test");
//        sysGroupCustomer.setCustId("123456");
//        sysGroupCustomer.setCustIsn("123456");
//        sysGroupCustomer.setCustIdc("41090x");
//        sysGroupCustomer.setUserName("张三");
//        sysGroupCustomer.setGridName("测试一级网格");
//        sysGroupCustomer.setDeptName("测试机构");
//        sysGroupCustomer.setGridName2("测试二级网格");
//        sysGroupCustomer.setTellerId("9650999");
//        sysGroupCustomer.setOutlets("测试网点1");
//        sysGroupCustomer.setCustPhone("13888888888");
//        sysGroupCustomer.setIdType("居民二代身份证");
//        if (type==null||"0".equals(type)) {
//            List<SysGroupCustomer> list = new ArrayList<>();
//            for (int i = 0; i < 10000; i++) {
//                list.add(sysGroupCustomer);
//            }
//
//            ExcelUtil<SysGroupCustomer> util = new ExcelUtil<SysGroupCustomer>(SysGroupCustomer.class);
//            util.exportExcel(response, list, "客群圈选，个人客户模板样例下载");
//        }
//
//
//    }

    @Log(title = "走访-支行管理员认领推荐营销清单", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping("/orgClaim")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "分群id", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "campaignId", value = "活动id", dataType = "String", dataTypeClass = String.class)

    })
    @ApiOperation("支行管理员认领推荐营销清单")
    public AjaxResult orgClaim(String groupId,String campaignId) throws ServerException {
        return toAjax(sysCampaignGroupCustomerService.orgClaim("",campaignId));
    }


    @Log(title = "走访-客户经理批量认领指定客户", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping("/custIdsClaim")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "分群id", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "campaignId", value = "活动id", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "custIds", value = "客户id列表", dataType = "String", dataTypeClass = String.class)

    })
    @ApiOperation("客户经理认领指定客户")
    public AjaxResult custClaim(String groupId,String campaignId,@RequestParam(value = "custIds") List<String> custIds) throws ServerException {
        return toAjax(sysCampaignGroupCustomerService.custClaim(groupId,campaignId,custIds));
    }

    @Log(title = "走访-客群圈选，导入客户", businessType = BusinessType.IMPORT)
//    @PreAuthorize("@ss.hasPermi('system:user:import')")
    @PostMapping(value = "/importDataBySelect")
    @ApiOperation("客群圈选，选择锚点客户创建客群")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "groupName", value = "客群名称", dataType = "String", dataTypeClass = String.class),
//            @ApiImplicitParam(name = "custType", value = "客户类型 '0'个人，'1'商户，'2'企业", dataType = "String", dataTypeClass = String.class),
//    })
    public AjaxResult importDataBySelect(@RequestBody CustomerSelects customerSelects)
    {

        return sysGroupService.insertSysGroupAndCustomerBySelect(customerSelects.getGroupName(),customerSelects.getCustType(),customerSelects.getCustomerSelects());
    }

    @GetMapping("/DeleteGroupByGroupId")
    @ApiOperation("根据客群id删除客群")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "分群id", dataType = "String", dataTypeClass = String.class),
    })
    public AjaxResult DeleteGroupByGroupId(String groupId)
    {
        SysGroup sysGroup = sysGroupService.selectSysGroupByGroupId(groupId);
        sysGroup.setDelFlag("2");
        return toAjax(sysGroupService.updateSysGroup(sysGroup));
    }



    @GetMapping("/listTab")
    @Log(title = "走访-客群圈选")
    @ApiOperation("查询指标列表")
    public R<List<CustTabListVo>> listTab(ListTabDTO listTabDTO)
    {
        startPage();
        return R.ok(  custTabListInfoService.listTab(listTabDTO));
    }

    @GetMapping("/tabDetail")
    @Log(title = "走访-客群圈选")
    @ApiOperation("根据id查询指标")
    public R<CustTabIdDetailVO> tabDetail(Long id)
    {
        return R.ok(custTabListInfoService.selectCustTabListInfoById(id));
    }

    @Log(title = "走访-客群圈选，导出客群客户", businessType = BusinessType.IMPORT)
//    @PreAuthorize("@ss.hasPermi('system:user:export')")
    @PostMapping("/exportDataError")
    @ApiOperation("客群圈选，导出导入失败客群客户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "客群id", dataType = "String", dataTypeClass = String.class),
    })
    public void exportDataError(HttpServletResponse response, String groupId) throws Exception
    {
        if (groupId!=null){
            sysGroupCustomerService.selectSysGroupCustomerListExport(response,groupId,"2");
        }
    }

    @Log(title = "走访-添加到已有任务", businessType = BusinessType.IMPORT)
    @PostMapping("/createTask")
    @ApiOperation("添加到已有任务")
    public R<Object> createTask(@RequestBody AddTask addTask) throws ServerException
    {
            for (String id : addTask.getGroupId()){
                sysCampaignGroupCustomerService.appointHisCamp(id,addTask.getCustIds(),addTask.getCampaignIds());
            }
            return R.ok();
    }

}
