package com.ruoyi.ibs.list.service.impl;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.ibs.custmap.domain.entity.CustInfoRadar;
import com.ruoyi.ibs.custmap.mapper.CustMapMapper;
import com.ruoyi.ibs.grid.domain.vo.AnchorDetail;
import com.ruoyi.ibs.grid.mapper.AnchorMapper;
import com.ruoyi.ibs.grid.service.AnchorService;
import com.ruoyi.ibs.grid.util.CustExcelUtil;
import com.ruoyi.ibs.list.domain.*;
import com.ruoyi.ibs.list.mapper.CorporateShareholderMapper;
import com.ruoyi.ibs.list.mapper.CustInfoMerchantMapper;
import com.ruoyi.ibs.list.mapper.CustInfoRetailMapper;
import com.ruoyi.ibs.list.mapper.SignedProductsMapper;
import com.ruoyi.ibs.list.service.ICustInfoMerchantService;
import com.ruoyi.system.mapper.SysIndustryMapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static com.ruoyi.common.utils.SecurityUtils.*;
import static com.ruoyi.ibs.enumertion.CustTypeEnum.MERCHANT;
import static com.ruoyi.ibs.list.domain.Constans.*;


/**
 * 商户客户基本信息Service业务层处理
 *
 * @author ruoyi
 * @date 2024-10-28
 */
@Service
public class CustInfoMerchantServiceImpl implements ICustInfoMerchantService {
    @Autowired
    private CustInfoMerchantMapper custInfoMerchantMapper;
    @Autowired
    private CorporateShareholderMapper corporateShareholderMapper;
    @Autowired
    private SignedProductsMapper signedProductsMapper;
    @Autowired
    private CustInfoRetailServiceImpl custInfoRetailService;
    @Autowired
    private CustInfoRetailMapper custInfoRetailMapper;
    @Autowired
    private SysIndustryMapper sysIndustryMapper;
    @Autowired
    private AnchorService anchorService;
    @Autowired
    private AnchorMapper anchorMapper;


    @Autowired
    private CustMapMapper custMapMapper;

    /**
     * 查询商户客户基本信息
     *
     * @param id 商户客户基本信息主键
     * @return 商户客户基本信息
     */
    @Override
    public CustInfoMerchant selectCustInfoMerchantById(Long id) {
        return custInfoMerchantMapper.selectCustInfoMerchantById(id);
    }

    @Override
    public CustInfoMerchantVo selectCustInfoMerchantVoByCustId(String  custId) {
        CustInfoMerchant custInfoMerchant = selectCustInfoMerchantByCustId(custId);
        CustInfoMerchantVo custInfoMerchantVo = new CustInfoMerchantVo();
        if (custInfoMerchant==null){
//            LambdaQueryWrapper<CustInfoRadar> queryWrapper = new LambdaQueryWrapper<>();
//            queryWrapper.eq(CustInfoRadar::getCustId,custId);
//            CustInfoRadar custInfoRadars = custMapMapper.selectOne(queryWrapper);
            String dept = SecurityUtils.getHeadId();
            CustInfoRadar custInfoRadars = custMapMapper.selectByCustId(custId, dept);
            if(custInfoRadars == null) {
                throw new IllegalArgumentException("非我行客户");
            }
            radarsVoConvert(custInfoMerchantVo,custInfoRadars);
            return custInfoMerchantVo;
        }

        custInfoMerchantVo.setCustInfoMerchant(custInfoMerchant);
        custInfoMerchantVo = custInfoMerchantVoSetGrid(custInfoMerchantVo);
//        custInfoMerchantVo.setGridUserName(custInfoRetailService.getNickNames(custInfoMerchant.getCustId()));
//        custInfoMerchantVo.setGridName(custInfoRetailService.getGridNames(custInfoMerchant.getCustId()));
        custInfoMerchantVo.setCmpmUserName(custInfoRetailService.getCmpmNickNames(custInfoMerchant.getCustId()));
        custInfoMerchantVo.setCmpmUserLists(custInfoRetailService.getCmpmUserList(custInfoMerchant.getCustId()));
        SignedProducts signedProducts = signedProductsMapper.selectSignedProductsByCurrdeposFlag(custInfoMerchant.getCustId());
        if (signedProducts != null) {
            custInfoMerchantVo.setSignedProducts(Constans.convertSignedProducts(signedProducts));
        }
        if (custInfoMerchant.getSocialCreditCode() != null && !custInfoMerchant.getSocialCreditCode().equals("")) {
            CorporateShareholder corporateShareholder = new CorporateShareholder();
            corporateShareholder.setSocialCreditCode(custInfoMerchant.getSocialCreditCode());
            corporateShareholder.setCustType(MERCHANT.getCode());
            corporateShareholder.setCustomerType("1");
            List<CorporateShareholder> corporateShareholders = corporateShareholderMapper.selectCorporateShareholderList(corporateShareholder);
            custInfoMerchantVo.setCorporateShareholders(corporateShareholders);
        }
        custInfoMerchantVo.setCommunity(custInfoRetailMapper.selectCommunityBycustId(custInfoMerchant.getCustId()));
        if (custInfoMerchant.getSocialCreditCode()!=null){
            custInfoMerchantVo.setAddressDetails(anchorMapper.selectCustAddressList(custInfoMerchant.getSocialCreditCode()));
        }

        return custInfoMerchantVo;
    }

    private void radarsVoConvert(CustInfoMerchantVo custInfoMerchantVo, CustInfoRadar custInfoRadars) {
        CustInfoMerchant custInfoMerchant = new CustInfoMerchant();
        BeanUtils.copyProperties(custInfoRadars,custInfoMerchant);
        custInfoMerchant.setBusinessScope(custInfoRadars.getScope());
        custInfoMerchant.setCustCapital(custInfoRadars.getRegistCapiValue().toString());
        custInfoMerchant.setCustLocation(custInfoRadars.getAddressDetail());
        custInfoMerchantVo.setCustInfoMerchant(custInfoMerchant);
        custInfoMerchantVo.setRadarCustFlag("1");
    }

    public CustInfoMerchantVo custInfoMerchantVoSetGrid(CustInfoMerchantVo custInfoMerchantVo){
        String custId = custInfoMerchantVo.getCustInfoMerchant().getCustId();
        String roleName = userRole();
        List<String> LsNames = new ArrayList<>();
        if (custId==null||custId.equals("")){
            return custInfoMerchantVo;
        }
        List<GridInfo> gridInfos = new ArrayList<>();
        if (ROLE_HEAD.equals(roleName)||ROLE_HeadPrivate.equals(roleName)||ROLE_HeadOps.equals(roleName)||ROLE_HeadPublic.equals(roleName)) {
            gridInfos = custInfoRetailMapper.selectGridInfo(custId, null,null);
        }else if ("branch".equals(roleName)){
            gridInfos = custInfoRetailMapper.selectGridInfo(custId,getDeptId(),null);
        }else {
            gridInfos = custInfoRetailMapper.selectGridInfo(custId,getDeptId(),getUsername());
        }
        //零售部行政网格信息
        String XzLsGridUserName = "";
        String XzLsGridName= "";
        //公司部行政网格信息
        String XzGsGridUserName= "";
        String XZGsGridName= "";
        //运管部行政网格信息
        String XzYgGridUserName= "";
        String XZYgGridName= "";
        Set<String> gridSetLs = new HashSet<>();
        Set<String> gridSetGs = new HashSet<>();
        Set<String> gridSetYg = new HashSet<>();
        for (int i = 0; i < gridInfos.size(); i++) {
            if ("0".equals(gridInfos.get(i).getOpsDept())){
                if (!gridInfos.get(i).getUserName().equals("")){
                    XzLsGridUserName = XzLsGridUserName+gridInfos.get(i).getUserName()+",";
                }
                if (StringUtils.isNotBlank(gridInfos.get(i).getGridName())&&StringUtils.isNotBlank(gridInfos.get(i).getGridName2())){
                    gridSetLs.add(gridInfos.get(i).getGridName()+"-"+gridInfos.get(i).getGridName2());
                }
                if (StringUtils.isNotBlank(gridInfos.get(i).getGridName())&&StringUtils.isBlank(gridInfos.get(i).getGridName2())){
                    gridSetLs.add(gridInfos.get(i).getGridName());
                }
            }
            if ("1".equals(gridInfos.get(i).getOpsDept())){
                if (!gridInfos.get(i).getUserName().equals("")){
                    XzGsGridUserName = XzGsGridUserName+gridInfos.get(i).getUserName()+",";
                }
                if (StringUtils.isNotBlank(gridInfos.get(i).getGridName())&&StringUtils.isNotBlank(gridInfos.get(i).getGridName2())){
                    gridSetGs.add(gridInfos.get(i).getGridName()+"-"+gridInfos.get(i).getGridName2());
                }
                if (StringUtils.isNotBlank(gridInfos.get(i).getGridName())&&StringUtils.isBlank(gridInfos.get(i).getGridName2())){
                    gridSetGs.add(gridInfos.get(i).getGridName());
                }
            }
            if ("2".equals(gridInfos.get(i).getOpsDept())){
                if (!gridInfos.get(i).getUserName().equals("")){
                    XzYgGridUserName = XzYgGridUserName+gridInfos.get(i).getUserName()+",";
                }
                if (StringUtils.isNotBlank(gridInfos.get(i).getGridName())&&StringUtils.isNotBlank(gridInfos.get(i).getGridName2())){
                    gridSetYg.add(gridInfos.get(i).getGridName()+"-"+gridInfos.get(i).getGridName2());
                }
                if (StringUtils.isNotBlank(gridInfos.get(i).getGridName())&&StringUtils.isBlank(gridInfos.get(i).getGridName2())){
                    gridSetYg.add(gridInfos.get(i).getGridName());
                }
            }

        }
        custInfoMerchantVo.setXzLsGridUserName(strReplace(XzLsGridUserName));
        custInfoMerchantVo.setXzGsGridUserName(strReplace(XzGsGridUserName));
        custInfoMerchantVo.setXzYgGridUserName(strReplace(XzYgGridUserName));
        for (String gridName : gridSetLs){
            XzLsGridName = XzLsGridName+gridName+",";
        }
        for(String gridName : gridSetGs){
            XZGsGridName = XZGsGridName+gridName+",";
        }
        for(String gridName : gridSetYg){
            XZYgGridName = XZYgGridName+gridName+",";
        }
        custInfoMerchantVo.setXzLsGridName(strReplace(XzLsGridName));
        custInfoMerchantVo.setXzGsGridName(strReplace(XZGsGridName));
        custInfoMerchantVo.setXzYgGridName(strReplace(XZYgGridName));
        return custInfoMerchantVo;
    }

    /**
     * 查询商户客户基本信息列表
     *
     * @param custInfoMerchant 商户客户基本信息
     * @return 商户客户基本信息
     */
    @Override
    public List<CustInfoMerchant> selectCustInfoMerchantList(CustInfoMerchant custInfoMerchant) {
        return custInfoMerchantMapper.selectCustInfoMerchantList(custInfoMerchant);
    }

    @Override
    public List<CustInfoMerchant> selectCustInfoMerchantListBykeyword(String keyword) {
        String roleName = userRole();
        List<CustInfoMerchant> custInfoMerchants = new ArrayList<>();
        if (ROLE_HEAD.equals(roleName)||ROLE_HeadPrivate.equals(roleName)||ROLE_HeadOps.equals(roleName)) {
            custInfoMerchants = custInfoMerchantMapper.selectCustInfoMerchantListByKeyword(keyword);
        }
        else if (ROLE_BRANCH.equals(roleName)) {
            custInfoMerchants = custInfoMerchantMapper.selectCustInfoMerchantListByKeywordBranchAndManager(keyword, getDeptId(), null,null,null);
        }else if (ROLE_Outlet.equals(roleName)) {
            custInfoMerchants = custInfoMerchantMapper.selectCustInfoMerchantListByKeywordBranchAndManager(keyword, null, getDeptId(),null,null);
        } else {
            custInfoMerchants = custInfoMerchantMapper.selectCustInfoMerchantListByKeywordBranchAndManager(keyword, null, null,getUserId(),null);
        }
        return custInfoMerchants;
    }

    /**
     * 新增商户客户基本信息
     *
     * @param custInfoMerchant 商户客户基本信息
     * @return 结果
     */
    @Override
    public int insertCustInfoMerchant(CustInfoMerchant custInfoMerchant) {
        custInfoMerchant.setCreateTime(DateUtils.getNowDate());
        return custInfoMerchantMapper.insertCustInfoMerchant(custInfoMerchant);
    }

    @Override
    public AjaxResult insertCustInfoMerchantVo(CustInfoMerchant custInfoMerchant, String relatePerson) {
        if (custInfoMerchant.getSocialCreditCode() == null || "".equals(custInfoMerchant.getSocialCreditCode())
                || custInfoMerchant.getCustName() == null || "".equals(custInfoMerchant.getCustName())) {
            return AjaxResult.error("缺乏必要建档信息，无法建档成功");
        }
        CustInfoMerchant mer = new CustInfoMerchant();
        mer.setSocialCreditCode(custInfoMerchant.getSocialCreditCode());
        List<CustInfoMerchant> custInfoMerchants = custInfoMerchantMapper.selectCustInfoMerchantList(mer);
        if (custInfoMerchants != null && custInfoMerchants.size() > 0) {
            return AjaxResult.error("当前商户统信码已建档,无需重复建档");
        }
        //查看是否存在同名企业，且法人身份证号与当前法人身份证号相同的企业数据，但是没有统信码和客户号的数据，若存在即为个人插入的关联企业数据，此时无需插入新数据，只需更新补全该数据
        CustInfoMerchant merchant = custInfoMerchantMapper.selectCustInfoMerchatByCustNameAndCustIdc(custInfoMerchant.getCustName(), custInfoMerchant.getCustIdc());
        if (merchant != null) {
            Long id = merchant.getId();
            if (merchant.getSocialCreditCode() == null || "".equals(merchant.getSocialCreditCode())) {
                BeanUtils.copyProperties(custInfoMerchant, merchant);
                merchant.setCustId("202" + custInfoMerchant.getSocialCreditCode());
                merchant.setId(id);
                custInfoMerchantMapper.updateCustInfoMerchant(merchant);
                if (relatePerson != null && !relatePerson.isEmpty()) {
                    CorporateShareholder shareholder = new CorporateShareholder();
                    shareholder.setName(relatePerson);
                    shareholder.setCustomerType("1");
                    shareholder.setCustType(MERCHANT.getCode());
                    shareholder.setSocialCreditCode(custInfoMerchant.getSocialCreditCode());
                    corporateShareholderMapper.insertCorporateShareholder(shareholder);
                }
                return AjaxResult.success("当前法人下存在同名企业，但是缺乏统信码等必要信息，已自动补全");
            } else {
                return AjaxResult.error("当前法人下存在同名企业，无法重复为该企业建档");
            }

        }
        custInfoMerchant.setCustId("202" + custInfoMerchant.getSocialCreditCode());
        insertCustInfoMerchant(custInfoMerchant);
        if (relatePerson != null && !relatePerson.isEmpty()) {
            CorporateShareholder shareholder = new CorporateShareholder();
            shareholder.setName(relatePerson);
            shareholder.setCustomerType("1");
            shareholder.setCustType(MERCHANT.getCode());
            shareholder.setSocialCreditCode(custInfoMerchant.getSocialCreditCode());
            corporateShareholderMapper.insertCorporateShareholder(shareholder);
        }
        return AjaxResult.success("建档成功");
    }

    /**
     * 修改商户客户基本信息
     *
     * @param custInfoMerchant 商户客户基本信息
     * @return 结果
     */
    @Override
    @Transactional
    public AjaxResult updateCustInfoMerchant(CustInfoMerchant custInfoMerchant) {
        custInfoMerchant.setUpdateTime(DateUtils.getNowDate());
        if (custInfoMerchant.getLabel() != null && !custInfoMerchant.getLabel().isEmpty()) {
            if (Constans.labelDuplicate(custInfoMerchant.getLabel())) {
                return AjaxResult.error("客户标签不允许重复");
            }
        }
        if(StringUtils.isNotEmpty(custInfoMerchant.getLabel())){
            custInfoMerchantMapper.updateCustInfoMerchantLabel(custInfoMerchant);
        }else{
            custInfoMerchantMapper.updateCustInfoMerchant(custInfoMerchant);
        }

        AnchorDetail anchorDetail = new AnchorDetail();
        anchorDetail.setLegalId(custInfoMerchant.getSocialCreditCode());
        anchorDetail.setAnchorName(custInfoMerchant.getCustName());
        if (custInfoMerchant.getIndustry()!=null){
            anchorDetail.setBelongBusiness(sysIndustryMapper.selectIndustryNameByCode(custInfoMerchant.getIndustry()));
        }
        anchorService.update(anchorDetail);
        return AjaxResult.success("客户信息更新成功");
    }

    /**
     * 批量删除商户客户基本信息
     *
     * @param ids 需要删除的商户客户基本信息主键
     * @return 结果
     */
    @Override
    public int deleteCustInfoMerchantByIds(Long[] ids) {
        return custInfoMerchantMapper.deleteCustInfoMerchantByIds(ids);
    }

    /**
     * 删除商户客户基本信息信息
     *
     * @param id 商户客户基本信息主键
     * @return 结果
     */
    @Override
    public int deleteCustInfoMerchantById(Long id) {
        return custInfoMerchantMapper.deleteCustInfoMerchantById(id);
    }

    @Override
    public CustInfoMerchant selectCustInfoMerchantByCustId(String custId) {
        return custInfoMerchantMapper.selectCustInfoMerchantByCustId(custId);
    }

    @Override
    public void exportMerchantDetail(HttpServletResponse response, String custId) throws Exception {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        CustInfoMerchantVo merchant = selectCustInfoMerchantVoByCustId(custId);
        Workbook workbook = new XSSFWorkbook();
        Sheet sheet = workbook.createSheet("Merchant Information");
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setHeader("Content-Disposition", "attachment; filename=商户视图详情.xlsx");
        // 创建标题行
        Row headerRow = sheet.createRow(0);
        headerRow.createCell(0).setCellValue("模块名称");
        headerRow.createCell(1).setCellValue("字段");
        headerRow.createCell(2).setCellValue("字段内容");

        int rowNum = 1; // 从第二行开始填充数据
        int startRow = rowNum;

        // 填充基础信息
        CustExcelUtil.fillRow(sheet, rowNum++, "基础信息", "商户名称", merchant.getCustInfoMerchant().getCustName());
        CustExcelUtil.fillRow(sheet, rowNum++, "", "经营人姓名", merchant.getCustInfoMerchant().getLpName());
        CustExcelUtil.fillRow(sheet, rowNum++, "", "性别", merchant.getCustInfoMerchant().getCustGender());
        CustExcelUtil.fillRow(sheet, rowNum++, "", "年龄", merchant.getCustInfoMerchant().getCustAge());
        CustExcelUtil.fillRow(sheet, rowNum++, "", "身份证号", merchant.getCustInfoMerchant().getCustIdc());
        if (merchant.getCustInfoMerchant().getBirthday() != null) {
            CustExcelUtil.fillRow(sheet, rowNum++, "", "出生日期", sdf.format(merchant.getCustInfoMerchant().getBirthday()));
        } else {
            CustExcelUtil.fillRow(sheet, rowNum++, "", "出生日期", "");
        }
        CustExcelUtil.fillRow(sheet, rowNum++, "", "手机号", merchant.getCustInfoMerchant().getCustPhone());
        CustExcelUtil.fillRow(sheet, rowNum++, "", "行业名称", merchant.getCustInfoMerchant().getIndustry());
        CustExcelUtil.fillRow(sheet, rowNum++, "", "客户号", merchant.getCustInfoMerchant().getCustId());
        CustExcelUtil.fillRow(sheet, rowNum++, "", "客户内码", merchant.getCustInfoMerchant().getCustIsn());
        CustExcelUtil.fillRow(sheet, rowNum++, "", "统信码", merchant.getCustInfoMerchant().getSocialCreditCode());
        CustExcelUtil.fillRow(sheet, rowNum++, "", "注册地址", merchant.getCustInfoMerchant().getRegisterLocation());
        CustExcelUtil.fillRow(sheet, rowNum++, "", "经营地址", merchant.getCustInfoMerchant().getCustLocation());
        String status = "";
        if (merchant.getCustInfoMerchant().getStatus()==null||merchant.getCustInfoMerchant().getStatus().equals("")){

        }else{
            status = merchant.getCustInfoMerchant().getStatus();
        }
        String statusName="";
        switch (status) {
            case "1":
                statusName = "正常";
                break;
            case "2":
                statusName = "特殊";
                break;
            case "3":
                statusName = "其他";
                break;
            case "4":
                statusName = "黑名单客户";
                break;
            case "5":
                statusName = "灰名单";
                break;
            case "6":
                statusName = "未知";
                break;
            default:
                statusName="";
        }
        CustExcelUtil.fillRow(sheet, rowNum++, "", "经营状态", statusName);
        CustExcelUtil.fillRow(sheet, rowNum++, "", "经营范围", merchant.getCustInfoMerchant().getBusinessScope());
        CustExcelUtil.fillRow(sheet, rowNum++, "", "网格客户经理", merchant.getGridUserName());
        CustExcelUtil.fillRow(sheet, rowNum++, "", "绩效客户经理", merchant.getCmpmUserName());
        if (merchant.getCustInfoMerchant().getUpdateTime() != null) {
            CustExcelUtil.fillRow(sheet, rowNum++, "", "更新时间", sdf.format(merchant.getCustInfoMerchant().getUpdateTime()));
        }else {
            CustExcelUtil.fillRow(sheet, rowNum++, "", "更新时间", "");
        }
        CustExcelUtil.mergeCells(sheet, startRow, rowNum - 1, 0, "基础信息");
        startRow = rowNum;

        List<Products> list = Constans.convertProducts(signedProductsMapper.selectSignedProductsByCurrdeposFlag(merchant.getCustInfoMerchant().getCustId()));
        if (!list.isEmpty()) {
            CustExcelUtil.fillRow(sheet, rowNum++, "签约产品", list.get(0).getProductGroup(), list.get(0).getProductName());
            if (list.size() > 2) {
                for (int i = 1; i < list.size(); i++) {
                    CustExcelUtil.fillRow(sheet, rowNum++, "", list.get(i).getProductGroup(), list.get(i).getProductName());
                }
            }
        } else {
            CustExcelUtil.fillRow(sheet, rowNum++, "签约产品", "存款", "");
            CustExcelUtil.fillRow(sheet, rowNum++, "", "贷款", "");
            CustExcelUtil.fillRow(sheet, rowNum++, "", "理财", "");
            CustExcelUtil.fillRow(sheet, rowNum++, "", "中间业务", "");
        }
        //合并单元格
        CustExcelUtil.mergeCells(sheet, startRow, rowNum - 1, 0, "签约产品");
        startRow = rowNum;

        CustExcelUtil.fillRow(sheet, rowNum++, "走访记录", "走访内容", "");

        CustExcelUtil.fillRow(sheet, rowNum++, "登记信息", "客户标签", merchant.getCustInfoMerchant().getLabel());

        if (!merchant.getCorporateShareholders().isEmpty() && merchant.getCorporateShareholders() != null) {
            for (CorporateShareholder cpsh : merchant.getCorporateShareholders()
            ) {
                if (cpsh.getCustType().equals("1")) {
                    CustExcelUtil.fillRow(sheet, rowNum++, "关联商户", "商户关联人", cpsh.getName());
                }
                if (cpsh.getCustType().equals("2")) {
                    CustExcelUtil.fillRow(sheet, rowNum++, "关联企业", "企业关联人", cpsh.getName());
                }
            }
        } else {
            CustExcelUtil.fillRow(sheet, rowNum++, "关联商户", "商户关联人", "");
            CustExcelUtil.fillRow(sheet, rowNum++, "关联企业", "企业关联人", "");
        }

        for (int i = 0; i < 2; i++) {
            sheet.autoSizeColumn(i);
            sheet.setColumnWidth(i, sheet.getColumnWidth(i) * 17 / 10);
        }
        //第三列容易超出255.故单独设置
        if (sheet.getColumnWidth(2) * 17 / 10>255){
            sheet.autoSizeColumn(2);
            sheet.setColumnWidth(2, sheet.getColumnWidth(2) * 13 / 10);
        } else {
            sheet.autoSizeColumn(2);
            sheet.setColumnWidth(2, sheet.getColumnWidth(2) * 17 / 10);
        }
        try (OutputStream outputStream = response.getOutputStream()) {
            workbook.write(outputStream);
            workbook.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        workbook.close();
    }

    public int insertCustomersToMmerchantByScCode(List<SysGroupCustomer> sysGroupCustomers){
        return custInfoMerchantMapper.insertCustomersToMmerchantByScCode(sysGroupCustomers);
    }

    public List<String> selectCustInfoByScCodeList(List<String> idcConditionList,String custType){
        return custInfoMerchantMapper.selectCustInfoByScCodeList(idcConditionList, custType);
    }
}
