package com.friday.custody.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.friday.custody.entity.*;
import com.friday.custody.service.basicService.DataDictionaryTypeCertificateCsdcService;
import com.friday.custody.service.basicService.DataDictionaryZxFndBasicInfoCyService;
import com.friday.custody.service.basicService.PullDataFailureLogService;
import com.friday.custody.service.basicService.impl.*;
import com.friday.custody.service.logicService.DataDictionaryBasicService;
import com.friday.custody.service.trustService.cmsc.dto.*;
import com.friday.custody.service.trustService.cmsc.service.OutsourceCmscServiceImpl;
import com.friday.custody.service.trustService.cmsc.utils.RandomStrUtil;
import com.friday.custody.service.trustService.haitong.service.OutsourceHaiTongServiceImpl;
import com.friday.custody.service.trustService.haitong.utils.HaiTongHttpUtil;
import com.friday.custody.service.trustService.htsc.utils.HTSCGetDataUtil;
import com.friday.custody.dto.TenantEscrowAuthorizationInfoDto;
import com.friday.custody.enums.DataDictionaryTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

@Component
@Slf4j
public class TranferUtils {
    @Autowired
    HTSCGetDataUtil hTSCGetDataUtil;

    @Autowired
    private HaiTongHttpUtil haiTongHttpUtil;

    private RestTemplate restTemplate = new RestTemplate();
    @Autowired
    private PullDataFailureLogService pullDataFailureLogService;
    @Autowired
    DataDictionaryTypeCertificateCsdcService certificateCsdcService;
    @Autowired
    private FundInfoServiceImpl fundInfoService;//a
    @Autowired
    private InvestorInfoServiceImpl investorInfoService;//b
    @Autowired
    private FundNetValueInfoServiceImpl fundNetValueInfoService;//c
    @Autowired
    private CustShareInfoServiceImpl custShareInfoService;//d
    @Autowired
    private TgAccountBalanceInfoServiceImpl tgAccountBalanceInfoService;//e
    @Autowired
    private TgAccountSeqInfoServiceImpl tgAccountSeqInfoService;//f
    @Autowired
    private MjAccountBalanceInfoServiceImpl mjAccountBalanceInfoService;//g
    @Autowired
    private MjAccountSeqInfoServiceImpl mjAccountSeqInfoService;//h
    @Autowired
    private FundTradeInfoServiceImpl fundTradeInfoService;//i
    @Autowired
    private FundValueTableDataInfoServiceImpl fundValueTableDataInfoService;//j
    @Autowired
    private AccountInfoServiceImpl accountInfoService;//11
    @Autowired
    private CustShareSeqInfoServiceImpl custShareSeqInfoService;//12
    @Autowired
    private InvestorBankInfoServiceImpl investorBankInfoService;//13
    @Autowired
    private FundProfitInfoServiceImpl fundProfitInfoService;//14
    @Autowired
    private CustShareDetailInfoServiceImpl custShareDetailInfoService;//15
    @Autowired
    private DataDictionarySellerServiceImpl sellerService;
    @Autowired
    private FundFeeDataInfoServiceImpl fundFeeDataInfoService;
    @Autowired
    private FundOpenInfoServiceImpl fundOpenInfoService;
    @Autowired
    private DataDictionaryOpenStateServiceImpl openStateService;

    @Autowired
    @Lazy
    OutsourceHaiTongServiceImpl outsourceHaiTongService;
    @Autowired
    OutsourceCmscServiceImpl outsourceCmscService;

    @Resource(name = "pullDataThreadPool")
    private ExecutorService pullDataThreadPool;
    @Autowired
    private MailNewUtils mailNewUtils;
    @Autowired
    private DataDictionaryBasicService dataDictionaryBasicService;
    @Autowired
    DataDictionaryZxFndBasicInfoCyService dataDictionaryZxFndBasicInfoCyService;
    //@Resource(name = "tenantEscrowAuthorizationInfoService")
    @Autowired
    private TenantEscrowAuthorizationInfoServiceImpl tenantEscrowAuthorizationInfoServiceimpl;
    @Value("${custody.remote.url.cmsc.cmscUrlPrefix}")
    private String cmscUrlPrefix;

    public R getEntityDataByMap(HashMap<String, Object> map) {

        String trustNo = (String) map.get("trustNo");
        List<JSONObject> objects1 = (List<JSONObject>) map.get("objects");
        ObjectMapper objectMapper = new ObjectMapper();
        List<CMInvestorInfoDto> objectsList = new ArrayList<>();
        objects1 = objectMapper.convertValue(objects1, new TypeReference<List<JSONObject>>() {});
        Map objectsMap = null;
        if (map.get("objectsMap") != null) {
            objectsMap = (Map<String, Object>) map.get("objectsMap");
        }
        String tenantName = (String) map.get("tenantName");
        String typeCode = (String) map.get("accoTypeCode");
//        TenantEscrowAuthorizationInfoDto tenant = tenantEscrowAuthorizationInfoServiceimpl.queryAuthorizationByTrustNoAndTenantName(tenantName, trustNo);
        TenantEscrowAuthorizationInfoDto tenant = JSON.parseObject(JSON.toJSONString(map.get("tenant")), TenantEscrowAuthorizationInfoDto.class);
        String today = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        String companyId = tenant.getCompanyId();
        List collect;
        //根据
        List entities = null;
        if ("21".equals(trustNo)) {
            switch (map.get("tableName").toString()) {
                case "investorInfo": // 投资者信息查询
                    entities = outsourceHaiTongService.getInvestorInfoData(tenant, objects1, trustNo);
                    investorInfoService.saveData(null, entities);
                    break;
                case "investorBankInfo":  // 投资者信息查询（银行）
                    entities = outsourceHaiTongService.getInvestorBankInfo(tenant, objects1, trustNo);
                    investorBankInfoService.saveData(null, entities);
                    break;
                case "fundOpenInfo": //开放日
                    entities = outsourceHaiTongService.getFundOpenInfo(tenant, objects1, trustNo);
                    fundOpenInfoService.saveData(null, entities);
                    break;
                case "fundInfo": //产品信息查询
                    entities = outsourceHaiTongService.getFundInfoData(tenant, objects1, trustNo);
                    fundInfoService.saveData(null, entities);
                    break;
                case "custShareInfo": // 份额持有人查询 cust_share_info
                    List<CustShareInfoEntity> entities1 = outsourceHaiTongService.getCustShareInfo(tenant, objects1, trustNo);
                    entities1 = entities1.stream().map(item -> {
                        item.setRemark("transfer");
                        return item;
                    }).collect(Collectors.toList());
                    custShareInfoService.saveData(null, entities1);
                    break;
                case "fundTradeInfo": //交易确认查询：fund_trade_info
                    //entities = getFundTradeInfo(tenantName, objects, trustNo);
                    entities = outsourceHaiTongService.getFundTradeInfo(tenant, objects1, trustNo);
                    fundTradeInfoService.saveData(null, entities);
                    break;
                case "fundProfitInfo": //业绩报酬数据查询：fund_profit_info
                    //entities = getFundProfitInfo(tenantName, objects, trustNo);
                    entities = outsourceHaiTongService.getFundProfitInfo(tenant, objects1, trustNo);
                    fundProfitInfoService.saveData(null, entities);
                    break;
                case "custShareDetailInfo": //份额明细查询：cust_share_detail_info
                    //entities = getCustShareDetailInfo(tenantName, objects, trustNo);
                    entities = outsourceHaiTongService.getCustShareDetailInfo(tenant, objects1, trustNo);
                    custShareDetailInfoService.saveData(null, entities);
                    break;
                case "mjAccountSeqInfo": //查询募集户银行流水：mjAccount_seq_info
                    //entities = getMJAccountSeqInfo(tenantName, objects, trustNo);
                    entities = outsourceHaiTongService.getMJAccountSeqInfo(tenant, objects1, trustNo);
                    mjAccountSeqInfoService.saveData(null, entities);
                    break;
                case "accountInfo": //查询募集户当日余额信息：account_info
                    //entities = getAccountInfoByT0214(tenantName, objects, trustNo, accoTypeCode);
                    entities = outsourceHaiTongService.getAccountInfoByT0214(tenant, objects1, trustNo);
                    //setRemarkInEntities(entities);
                    accountInfoService.saveData(null, entities);
                    break;
                case "MJAccountBalanceInfo": //查询募集户当日余额信息：account_info+MJAccount_balance_info
                    //entities = getMJAccountBalanceInfoByT0214(tenantName, objects, trustNo);
                    entities = outsourceHaiTongService.getMJAccountBalanceInfoByT0214(tenant, objects1, trustNo);
                    mjAccountBalanceInfoService.saveData(null, entities);
                    break;
                case "fundFeeDataInfo": //产品费用计提余额查询：fund_fee_data_info
                    //entities = getFundFeeDataInfo(tenantName, objects, trustNo);
                    entities = outsourceHaiTongService.getFundFeeDataInfo(tenant, objects1, trustNo);
                    fundFeeDataInfoService.saveData(null, entities);
                    break;
                case "TGAccountSeqInfo": //银行账户流水本地查询(T0215)(T0216):TGAccount_seq_info
                    //entities = getTgAccountSeqInfo(tenantName, objects, trustNo);
                    entities = outsourceHaiTongService.getTgAccountSeqInfo(tenant, objects1, trustNo);
                    tgAccountSeqInfoService.saveData(null, entities);
                    break;
                case "TGAccountBalanceInfo": //银行账户余额本地查询(T0217)：TGAccount_balance_info
                    //entities = getTgAccountBalanceInfo(tenantName, objects, trustNo);
                    entities = outsourceHaiTongService.getTgAccountBalanceInfo(tenant, objects1, trustNo);
                    tgAccountBalanceInfoService.saveData(null, entities);
                    break;
                case "fundNetValueInfo": //净值查询：fund_net_value_info
                    //entities = getFundNetValueInfo(tenantName, objects, trustNo);
                    entities = outsourceHaiTongService.getFundNetValueInfo(tenant, objects1, trustNo);
                    fundNetValueInfoService.saveData(null, entities);
                    break;
            }


        }
        if ("25".equals(trustNo)) {
            switch (map.get("tableName").toString()) {
                case "investorInfo": // 投资者信息查询
                    entities = (List) outsourceCmscService.getInvestorInfoData(tenant, trustNo, objectsMap).get("result");
                    investorInfoService.saveData(null, entities);
                    break;
                case "investorBankInfo":  // 投资者信息查询（银行）
                    Map<String, Object> mapInvestorBankInfo = outsourceCmscService.getInvestorInfoData(tenant, trustNo, objectsMap);
                    entities = (List) mapInvestorBankInfo.get("result1");
                    investorBankInfoService.saveData(null, entities);
                    break;
                case "fundOpenInfo": //开放日
                    entities = outsourceCmscService.getFundOpenInfo(tenant, trustNo, objectsMap);
                    fundOpenInfoService.saveData(null, entities);
                    break;
                case "fundInfo": //产品信息查询
                    entities = outsourceCmscService.getFundInfoData(tenant, trustNo, objectsMap, cmscUrlPrefix, today, companyId);
                    fundInfoService.saveData(null, entities);
                    break;
                case "custShareInfo": // 份额持有人查询 cust_share_info
                    List<CustShareInfoEntity> entities1 = outsourceCmscService.getCustShareInfoData(tenant, trustNo, objectsMap);
                    collect = entities1.stream().map(item -> {
                        item.setRemark("transfer");
                        return item;
                    }).collect(Collectors.toList());
                    custShareInfoService.saveData(null, collect);
                    break;
                case "fundTradeInfo": //交易确认查询：fund_trade_info
                    entities = outsourceCmscService.getFundTradeInfoData(tenant, trustNo, objectsMap);
                    fundTradeInfoService.saveData(null, entities);
                    break;
                /*case "fundProfitInfo": //业绩报酬数据查询：fund_profit_info
                    //entities = getFundProfitInfo(tenantName, objects, trustNo);
                    entities =outsourceCmscService.getFundProfitInfo(tenant,objects1,trustNo);
                    fundProfitInfoService.saveData(null, entities);
                    break;*/
                /*case "custShareDetailInfo": //份额明细查询：cust_share_detail_info
                    //entities = getCustShareDetailInfo(tenantName, objects, trustNo);
                    entities =outsourceCmscService.getCustShareDetailInfo(tenant,objects1,trustNo);
                    custShareDetailInfoService.saveData(null, entities);
                    break;*/
                case "mjAccountSeqInfo": //查询募集户银行流水：mjAccount_seq_info
                    entities = outsourceCmscService.getMJAccountSeqInfoData(tenant, trustNo, objectsMap);
                    mjAccountSeqInfoService.saveData(null, entities);
                    break;
                case "accountInfo": //查询募集户当日余额信息：account_info
                    if ("ZJ002".equals(typeCode)) {
                        entities = outsourceCmscService.getAccountInfoData(tenant, trustNo, objectsMap);
                    }
                    if ("ZJ001".equals(typeCode)) {
                        entities = outsourceCmscService.getAccountInfoData2(tenant, trustNo, objectsMap);
                    }
                    accountInfoService.saveData(null, entities);
                    break;
                case "MJAccountBalanceInfo": //查询募集户当日余额信息：account_info+MJAccount_balance_info
                    entities = outsourceCmscService.getMJAccountBalanceInfoData(tenant, trustNo, objectsMap);
                    mjAccountBalanceInfoService.saveData(null, entities);
                    break;
                case "fundFeeDataInfo": //产品费用计提余额查询：fund_fee_data_info
                    entities = outsourceCmscService.getFundFeeDataInfo(tenant, trustNo, objectsMap);
                    fundFeeDataInfoService.saveData(null, entities);
                    break;
                case "TGAccountSeqInfo": //银行账户流水本地查询(T0215)(T0216):TGAccount_seq_info
                    entities = outsourceCmscService.getTgAccountSeqInfoData(tenant, trustNo, objectsMap);
                    tgAccountSeqInfoService.saveData(null, entities);
                    break;
                case "TGAccountBalanceInfo": //银行账户余额本地查询(T0217)：TGAccount_balance_info
                    entities = outsourceCmscService.getTgAccountBalanceInfoData(tenant, trustNo, objectsMap);
                    tgAccountBalanceInfoService.saveData(null, entities);
                    break;
                case "fundNetValueInfo": //净值查询：fund_net_value_info
                    entities = outsourceCmscService.getFundNetValueInfoData(tenant, trustNo, objectsMap);
                    fundNetValueInfoService.saveData(null, entities);
                    break;
            }
        }
        return R.ok();
        //return entities;
    }

    //净值查询：fund_net_value_info
    private List<FundNetValueInfoEntity> getFundNetValueInfo(String tenantName, List<JSONObject> remoteDatas, String trustNo) {
        List<FundNetValueInfoEntity> result = new ArrayList<>();
        Map<String, String> remoteDataMap;
        Date now = new Date();
        if ("25".equals(trustNo)) {
            if (!remoteDatas.isEmpty()) {
                remoteDatas.forEach(entry -> {
                    CMFundNetValueInfoDto dto = JSON.toJavaObject(entry, CMFundNetValueInfoDto.class);
                    //CMFundNetValueInfoDto dto = (CMFundNetValueInfoDto) entry.getValue();

                    String fundCode = dto.getFundCode();
                    String fundName = dto.getFundName();
                    if (StringUtils.isBlank(fundName)) {
                        fundName = "null";
                    }

                    result.add(FundNetValueInfoEntity.builder()
                            .innerFundCode(dto.getFundCode())
                            //这里需要daas处理
                            .fundCode(dto.getFundCode())
                            .fundName(dto.getFundName())
                            .netValueDate(dto.getNavDate())
                            .shares(BigDecimalUtil.str2BigDecimalDefaultZero(dto.getAssetVol()))
                            .assetValue(BigDecimalUtil.str2BigDecimalDefaultZero(dto.getAssetNav()))
                            .totalAsset(BigDecimalUtil.str2BigDecimalDefaultZero(dto.getTotalAsset()))
                            .netValue(BigDecimalUtil.str2BigDecimal(dto.getNav(), 4))
                            .totalNetValue(BigDecimalUtil.str2BigDecimal(dto.getAccumulativeNav(), 4))
                            .admin(tenantName)
                            .trustNo(trustNo)
                            .createTime(new Date())
                            .updateTime(new Date())
                            .remark("transfer")
                            .build());
                });
            }
            return result;
        }
        if ("21".equals(trustNo)) {
            //2、封装数据
            for (JSONObject remoteData : remoteDatas) {
                remoteDataMap = JSONObject.toJavaObject(remoteData, Map.class);
                result.add(FundNetValueInfoEntity.builder()
                        .netValueDate(remoteDataMap.get("netDate"))
                        .fundCode(remoteDataMap.get("fundCode"))
                        .fundName(remoteDataMap.get("fundName"))
                        .shares(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("assetShares"), 2))
                        .assetValue(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("assetNet"), 2))
                        .netValue(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("netAssetVal"), 4))
                        .totalNetValue(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("totalAssetVal"), 4))
                        .ettFundIncome(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("ettFundIncome"), 2))
                        .sevenDayRate(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("sevenDayRate"), 4))
                        .fundLevel(remoteDataMap.get("fundLevel"))
                        .trustNo(trustNo)
                        .admin(tenantName)
                        .currency("156")
                        .createTime(now)
                        .updateTime(now)
                        .remark("transfer")
                        .build()
                );
            }
        }
        return result;
    }

    //银行账户余额本地查询：TGAccount_balance_info
    private List<TgAccountBalanceInfoEntity> getTgAccountBalanceInfo(String tenantName, List<JSONObject> remoteDatas, String trustNo) {
        log.info("getTgAccountBalanceInfo{}", JSON.toJSONString(remoteDatas));
        Map<String, String> currencyDir = dataDictionaryBasicService.queryWithDetail(DataDictionaryTypeEnum.CURRENCY_SERVICE, trustNo);
        Map<String, String> bankCodeDic = dataDictionaryBasicService.queryWithDetail(DataDictionaryTypeEnum.BANK_CODE_SERVICE, "海通TA");
        List<TgAccountBalanceInfoEntity> result = new ArrayList<>();
        Map<String, String> remoteDataMap;
        Date now = new Date();
        if ("25".equals(trustNo)) {
            for (JSONObject remoteData : remoteDatas) {
                remoteDataMap = JSONObject.toJavaObject(remoteData, Map.class);
                result.add(TgAccountBalanceInfoEntity.builder()
                        .bankAcco(remoteDataMap.get("curType"))
                        .accoBalance(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("balance")))
                        .updateDate(remoteDataMap.get("updateTime"))
                        .trustNo(trustNo)
                        .admin(tenantName)
                        .createTime(new Date())
                        .updateTime(new Date())
                        .remark("transfer")
                        .build());
            }

        }
        if ("21".equals(trustNo)) {
            try {
                //2、封装数据

                for (JSONObject remoteData : remoteDatas) {
                    String dateStr = (String) remoteData.get("retTime");
                    dateStr = dateStr.replace("/", "-");

                    remoteDataMap = JSONObject.toJavaObject(remoteData, Map.class);
                    result.add(TgAccountBalanceInfoEntity.builder()
                            .currency(remoteDataMap.get("curType"))
                            .bankAcco(remoteDataMap.get("bankAcco"))
                            .accoBalance(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("acctBal")))
                            .updateDate(dateStr)
                            .trustNo(trustNo)
                            .admin(tenantName)
                            .createTime(now)
                            .updateTime(now)
                            .remark("transfer")
                            .build());
                }
                return result;
            } catch (Exception e) {
                log.error("getTgAccountBalanceInfo异常{}", e);
            }
        }
        return result;
    }

    //银行账户流水本地查询(T0215):TGAccount_seq_info
    private List<TgAccountSeqInfoEntity> getTgAccountSeqInfo(String tenantName, List<JSONObject> remoteDatas, String trustNo) {
        //2、封装数据
        List<TgAccountSeqInfoEntity> result = new ArrayList<>();
        Map<String, String> remoteDataMap;
        Date now = new Date();
        log.info("getTgAccountSeqInfo{}", JSON.toJSONString(remoteDatas));
        if ("25".equals(trustNo)) {
            if (!remoteDatas.isEmpty()) {
                remoteDatas.forEach(entry -> {
                    CMTgAccountSeqInfoDto dto = JSON.toJavaObject(entry, CMTgAccountSeqInfoDto.class);
                    SimpleDateFormat rq = new SimpleDateFormat("yyyyMMdd");
                    SimpleDateFormat sj = new SimpleDateFormat("HH:mm:ss");
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String rqStr = null;
                    String sjStr = null;
                    try {
                        String tradeDate = dto.getTradeDate();
                        Date parse = simpleDateFormat.parse(tradeDate);
                        rqStr = rq.format(parse);
                        if (rqStr != null && rqStr.length() > 10) {
                            rqStr = rqStr.substring(0, 10);
                        }
                        sjStr = sj.format(parse);
                    } catch (Exception e) {
                        log.error(dto.getTradeDate() + "日期转换异常", e);
                    }
                    result.add(TgAccountSeqInfoEntity.builder()
                            .innerFundCode(dto.getFundCode())
                            .seqNo(RandomStrUtil.getRandomStr(32))
                            .fundName(dto.getFundName())
                            .fundCode(dto.getFundCode())
                            .account(dto.getOwnAccount())
                            .transferDate(rqStr)
                            .transferTime(sjStr)
//                                .transferInOut(MatchDataDictionaryKeyUtil.getKey(paymentDirectionDir, dto.getReceiptDirection()))
                            .transferInOut(dto.getReceiptDirection())
                            .amount(BigDecimalUtil.str2BigDecimal(dto.getTradingAmount()))
                            .opAccountName(dto.getCounterpartyName())
                            .opAccount(dto.getCounterpartyAccount())
                            .opBankName(dto.getCounterpartyOpenAccountBank())
                            .summary(dto.getBankAbstract())
                            .memo(dto.getPostScript())
                            .trustNo(trustNo)
                            .admin(tenantName)
                            .createTime(new Date())
                            .updateTime(new Date())
                            .remark("transfer")
                            .build());
                });
            }
            return result;
        }
        if ("21".equals(trustNo)) {
            for (JSONObject remoteData : remoteDatas) {
                remoteDataMap = JSONObject.toJavaObject(remoteData, Map.class);
                String occurTime = remoteDataMap.get("occurTime");

                String transferDate = occurTime.substring(0, 8);
                String transferTime = occurTime.substring(9);
                log.info("t0215 occurTime={},transferDate={},transferTime={}", occurTime, transferDate, transferTime);

                result.add(TgAccountSeqInfoEntity.builder()
                        .currency(remoteDataMap.get("curType"))
                        .fundCode(remoteDataMap.get("fundCode"))
                        .fundName(remoteDataMap.get("fundName"))
                        .transferInOut(remoteDataMap.get("directFlag"))
                        .account(remoteDataMap.get("bankAcco"))
                        .accountName(remoteDataMap.get("accName"))
                        .bankName(remoteDataMap.get("openBankName"))
                        .opAccount(remoteDataMap.get("othBankAcco"))
                        .opAccountName(remoteDataMap.get("othAccName"))
                        .opBankName(remoteDataMap.get("othOpenBankName"))
                        .amount(BigDecimalUtil.obj2BigDecimalTrunToZero(remoteDataMap.get("occurAmt")))
                        .transferDate(transferDate)
                        .transferTime(transferTime)
                        .summary(remoteDataMap.get("bankNote"))
                        .seqNo(RandomStrUtil.getRandomStr(32))
                        .trustNo(trustNo)
                        .admin(tenantName)
                        .createTime(now)
                        .updateTime(now)
                        .remark("transfer")
                        .build()
                );
            }
        }


        return result;
    }

    //产品费用计提余额查询：fund_fee_data_info
    private List<FundFeeDataInfoEntity> getFundFeeDataInfo(String tenantName, List<JSONObject> objects, String trustNo) {
        //封装数据
        List<FundFeeDataInfoEntity> entityList = new ArrayList<>();
        Map<String, String> remoteDataMap;

        if ("25".equals(trustNo)) {
            //2.封装数据
            if (!objects.isEmpty()) {
                objects.forEach(entry -> {
                    CMFundFeeDataInfoDto dto = JSON.toJavaObject(entry, CMFundFeeDataInfoDto.class);
                    //根据获取到的inner_fund_code查询fundCode
                    String fundCode = fundInfoService.getFundCodeByInnerFundCode(dto.getFundCode(), trustNo);
                    //托管费
                    entityList.add(FundFeeDataInfoEntity.builder()
                            .fundName(dto.getFundName())
                            .innerFundCode(dto.getFundCode())
                            .confirmDate(dto.getBusiDate())
                            .fareDebit(BigDecimalUtil.obj2BigDecimalTrunToZero(dto.getCustodianFeeJt()))
                            .fareCredit(BigDecimalUtil.obj2BigDecimalTrunToZero(dto.getCustodianFeeZf()))
                            .fareUnpaid(BigDecimalUtil.obj2BigDecimalTrunToZero(dto.getCustodianFeeYe()))
                            .subjectCode("TGF")
                            .subjectName("托管费")
                            .fundCode(fundCode)
                            .trustNo(trustNo)
                            .admin(tenantName)
                            .createTime(new Date())
                            .updateTime(new Date())
                            .remark("transfer")
                            .build());
                    //运营服务费
                    entityList.add(FundFeeDataInfoEntity.builder()
                            .fundName(dto.getFundName())
                            .innerFundCode(dto.getFundCode())
                            .confirmDate(dto.getBusiDate())
                            .fareDebit(BigDecimalUtil.obj2BigDecimalTrunToZero(dto.getOperationServiceFeeJt()))
                            .fareCredit(BigDecimalUtil.obj2BigDecimalTrunToZero(dto.getOperationServiceFeeZf()))
                            .fareUnpaid(BigDecimalUtil.obj2BigDecimalTrunToZero(dto.getOperationServiceFeeYe()))
                            .subjectCode("YYFWF")
                            .subjectName("运营服务费")
                            .fundCode(fundCode)
                            .trustNo(trustNo)
                            .admin(tenantName)
                            .createTime(new Date())
                            .updateTime(new Date())
                            .remark("transfer")
                            .build());
                    //管理费
                    entityList.add(FundFeeDataInfoEntity.builder()
                            .fundName(dto.getFundName())
                            .innerFundCode(dto.getFundCode())
                            .confirmDate(dto.getBusiDate())
                            .fareDebit(BigDecimalUtil.obj2BigDecimalTrunToZero(dto.getManagementFeeJt()))
                            .fareCredit(BigDecimalUtil.obj2BigDecimalTrunToZero(dto.getManagementFeeZf()))
                            .fareUnpaid(BigDecimalUtil.obj2BigDecimalTrunToZero(dto.getManagementFeeYe()))
                            .subjectCode("GLF")
                            .subjectName("管理费")
                            .fundCode(fundCode)
                            .trustNo(trustNo)
                            .admin(tenantName)
                            .createTime(new Date())
                            .updateTime(new Date())
                            .remark("transfer")
                            .build());
                    //业绩报酬
                    entityList.add(FundFeeDataInfoEntity.builder()
                            .fundName(dto.getFundName())
                            .innerFundCode(dto.getFundCode())
                            .confirmDate(dto.getBusiDate())
                            .fareDebit(BigDecimalUtil.obj2BigDecimalTrunToZero(dto.getPerformanceFeeJt()))
                            .fareCredit(BigDecimalUtil.obj2BigDecimalTrunToZero(dto.getPerformanceFeeZf()))
                            .fareUnpaid(BigDecimalUtil.obj2BigDecimalTrunToZero(dto.getPerformanceFeeYe()))
                            .subjectCode("YJBC")
                            .subjectName("业绩报酬")
                            .fundCode(fundCode)
                            .trustNo(trustNo)
                            .admin(tenantName)
                            .createTime(new Date())
                            .updateTime(new Date())
                            .remark("transfer")
                            .build());
                    //销售服务费
                    entityList.add(FundFeeDataInfoEntity.builder()
                            .fundName(dto.getFundName())
                            .innerFundCode(dto.getFundCode())
                            .confirmDate(dto.getBusiDate())
                            .fareDebit(BigDecimalUtil.obj2BigDecimalTrunToZero(dto.getSalesandServiceFeesJt()))
                            .fareCredit(BigDecimalUtil.obj2BigDecimalTrunToZero(dto.getSalesandServiceFeesZf()))
                            .fareUnpaid(BigDecimalUtil.obj2BigDecimalTrunToZero(dto.getSalesandServiceFeesYe()))
                            .subjectCode("XSF")
                            .subjectName("销售服务费")
                            .fundCode(fundCode)
                            .trustNo(trustNo)
                            .admin(tenantName)
                            .createTime(new Date())
                            .updateTime(new Date())
                            .remark("transfer")
                            .build());
                    //投顾费
                    entityList.add(FundFeeDataInfoEntity.builder()
                            .fundName(dto.getFundName())
                            .innerFundCode(dto.getFundCode())
                            .confirmDate(dto.getBusiDate())
                            .fareDebit(BigDecimalUtil.obj2BigDecimalTrunToZero(dto.getInvestmentConsultantFeeJt()))
                            .fareCredit(BigDecimalUtil.obj2BigDecimalTrunToZero(dto.getInvestmentConsultantFeeZf()))
                            .fareUnpaid(BigDecimalUtil.obj2BigDecimalTrunToZero(dto.getInvestmentConsultantFeeYe()))
                            .subjectCode("TGF2")
                            .subjectName("投顾费")
                            .fundCode(fundCode)
                            .trustNo(trustNo)
                            .admin(tenantName)
                            .createTime(new Date())
                            .updateTime(new Date())
                            .remark("transfer")
                            .build());
                    //外包服务费
                    entityList.add(FundFeeDataInfoEntity.builder()
                            .fundName(dto.getFundName())
                            .innerFundCode(dto.getFundCode())
                            .confirmDate(dto.getBusiDate())
                            .fareDebit(BigDecimalUtil.obj2BigDecimalTrunToZero(dto.getCustomerServiceFeeJt()))
                            .fareCredit(BigDecimalUtil.obj2BigDecimalTrunToZero(dto.getCustomerServiceFeeZf()))
                            .fareUnpaid(BigDecimalUtil.obj2BigDecimalTrunToZero(dto.getCustomerServiceFeeYe()))
                            .subjectCode("WBF")
                            .subjectName("外包服务费")
                            .fundCode(fundCode)
                            .trustNo(trustNo)
                            .admin(tenantName)
                            .createTime(new Date())
                            .updateTime(new Date())
                            .remark("transfer")
                            .build());
                });
            }
            return entityList;
        }
        if ("21".equals(trustNo)) {

            for (JSONObject remoteData : objects) {
                remoteDataMap = JSONObject.toJavaObject(remoteData, Map.class);
                //管理费
                entityList.add(FundFeeDataInfoEntity.builder()
                        .fundName(remoteDataMap.get("fundName"))
                        .fundCode(remoteDataMap.get("fundCode"))
                        .confirmDate(remoteDataMap.get("endDate"))
                        .fareDebit(BigDecimalUtil.obj2BigDecimalTrunToZero(remoteDataMap.get("managementFee")))
                        .fareUnpaid(BigDecimalUtil.obj2BigDecimalTrunToZero(remoteDataMap.get("managementFeeBal")))
                        .subjectCode("GLF")
                        .subjectName("管理费")
                        .trustNo(trustNo)
                        .admin(tenantName)
                        .createTime(new Date())
                        .updateTime(new Date())
                        .remark("transfer")
                        .build());
                //外包服务费
                entityList.add(FundFeeDataInfoEntity.builder()
                        .fundName(remoteDataMap.get("fundName"))
                        .fundCode(remoteDataMap.get("fundCode"))
                        .confirmDate(remoteDataMap.get("endDate"))
                        .fareDebit(BigDecimalUtil.obj2BigDecimalTrunToZero(remoteDataMap.get("outsourceFee")))
                        .fareUnpaid(BigDecimalUtil.obj2BigDecimalTrunToZero(remoteDataMap.get("outsourceFeeBal")))
                        .subjectCode("WBF")
                        .subjectName("外包服务费")
                        .trustNo(trustNo)
                        .admin(tenantName)
                        .createTime(new Date())
                        .updateTime(new Date())
                        .remark("transfer")
                        .build());
                //托管费
                entityList.add(FundFeeDataInfoEntity.builder()
                        .fundName(remoteDataMap.get("fundName"))
                        .fundCode(remoteDataMap.get("fundCode"))
                        .confirmDate(remoteDataMap.get("endDate"))
                        .fareDebit(BigDecimalUtil.obj2BigDecimalTrunToZero(remoteDataMap.get("custodianFee")))
                        .fareUnpaid(BigDecimalUtil.obj2BigDecimalTrunToZero(remoteDataMap.get("custodianFeeBal")))
                        .subjectCode("TGF")
                        .subjectName("托管费")
                        .trustNo(trustNo)
                        .admin(tenantName)
                        .createTime(new Date())
                        .updateTime(new Date())
                        .remark("transfer")
                        .build());
                //销售服务费
                entityList.add(FundFeeDataInfoEntity.builder()
                        .fundName(remoteDataMap.get("fundName"))
                        .fundCode(remoteDataMap.get("fundCode"))
                        .confirmDate(remoteDataMap.get("endDate"))
                        .fareDebit(BigDecimalUtil.obj2BigDecimalTrunToZero(remoteDataMap.get("salesFee")))
                        .fareUnpaid(BigDecimalUtil.obj2BigDecimalTrunToZero(remoteDataMap.get("salesFeeBal")))
                        .subjectCode("XSF")
                        .subjectName("销售服务费")
                        .trustNo(trustNo)
                        .admin(tenantName)
                        .createTime(new Date())
                        .updateTime(new Date())
                        .remark("transfer")
                        .build());
                //增值税
                entityList.add(FundFeeDataInfoEntity.builder()
                        .fundName(remoteDataMap.get("fundName"))
                        .fundCode(remoteDataMap.get("fundCode"))
                        .confirmDate(remoteDataMap.get("endDate"))
                        .fareDebit(BigDecimalUtil.obj2BigDecimalTrunToZero(remoteDataMap.get("payableValueAddedTax")))
                        .fareUnpaid(BigDecimalUtil.obj2BigDecimalTrunToZero(remoteDataMap.get("payableValueAddedTaxBal")))
                        .subjectCode("ZZS")
                        .subjectName("增值税")
                        .trustNo(trustNo)
                        .admin(tenantName)
                        .createTime(new Date())
                        .updateTime(new Date())
                        .remark("transfer")
                        .build());
                //附加税
                entityList.add(FundFeeDataInfoEntity.builder()
                        .fundName(remoteDataMap.get("fundName"))
                        .fundCode(remoteDataMap.get("fundCode"))
                        .confirmDate(remoteDataMap.get("endDate"))
                        .fareDebit(BigDecimalUtil.obj2BigDecimalTrunToZero(remoteDataMap.get("payableSurtax")))
                        .fareUnpaid(BigDecimalUtil.obj2BigDecimalTrunToZero(remoteDataMap.get("payableSurtaxBal")))
                        .subjectCode("FJS")
                        .subjectName("附加税")
                        .trustNo(trustNo)
                        .admin(tenantName)
                        .createTime(new Date())
                        .updateTime(new Date())
                        .remark("transfer")
                        .build());
            }
        }

        return entityList;
    }

    //查询募集户当日余额信息：MJAccount_balance_info
    private List<MjAccountBalanceInfoEntity> getMJAccountBalanceInfoByT0214(String tenantName, List<JSONObject> remoteDatas, String trustNo) {
        List<MjAccountBalanceInfoEntity> result = new ArrayList<>();
        log.info("getMJAccountBalanceInfoByT0214{}", JSON.toJSONString(remoteDatas));
        //2、封装数据
        Map<String, String> remoteDataMap;
        Date now = new Date();
        if ("25".equals(trustNo)) {
            //招商的加这里
        }
        if ("21".equals(trustNo)) {
            try {
                for (JSONObject remoteData : remoteDatas) {
                    String dateStr = (String) remoteData.get("date");
                    if (StringUtils.isNotBlank(dateStr) && dateStr.length() == 8) {
                        dateStr = dateStr.substring(0, 4) + "-" + dateStr.substring(4, 6) + "-" + dateStr.substring(6, 8);
                        dateStr = dateStr + " 00:00:00";
                    } else {
                        log.error("getMJAccountBalanceInfoByT0214时间为{}", dateStr);
                    }

                    remoteDataMap = JSONObject.toJavaObject(remoteData, Map.class);
                    result.add(MjAccountBalanceInfoEntity.builder()
                            .updateDate(dateStr)
                            .currency(remoteDataMap.get("curType"))
                            .bankAcco(remoteDataMap.get("fundBankAcc"))
                            .accoBalance(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("acctBal")))
                            .availableBalance(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("availableBal")))
                            .accoTypeCode("ZJ002")
                            .trustNo(trustNo)
                            .admin(tenantName)
                            .createTime(now)
                            .updateTime(now)
                            .remark("transfer")
                            .build());
                }
                return result;
            } catch (Exception e) {
                log.error("getMJAccountBalanceInfoByT0214异常{}", e);
            }
        }

        return result;
    }
    //查询募集户当日余额信息：account_info

    private List<AccountInfoEntity> getAccountInfoByT0214(String tenantName, List<JSONObject> remoteDatas, String trustNo, String accoTypeCode) {
        //2、封装数据
        Map<String, String> remoteDataMap;
        Date now = new Date();
        List<AccountInfoEntity> result = new ArrayList<>();
        if ("25".equals(trustNo)) {
            if ("ZJ002".equals(accoTypeCode)) {
                for (JSONObject remoteData : remoteDatas) {
                    remoteDataMap = JSONObject.toJavaObject(remoteData, Map.class);
                    result.add(AccountInfoEntity.builder()
                            .currency(remoteDataMap.get("bz"))
                            .innerFundCode(remoteDataMap.get("bz"))
                            .fundCode(remoteDataMap.get("cpdm"))
                            .fundName(remoteDataMap.get("cpmc"))
                            .branchBankName(remoteDataMap.get("khzh"))
                            .bankAcco(remoteDataMap.get("zhh"))
                            .nameInBank(remoteDataMap.get("zhmc"))
                            .accoTypeCode("ZJ002")
                            .trustNo(trustNo)
                            .admin(tenantName)
                            .createTime(new Date())
                            .updateTime(new Date())
                            .remark("transfer")
                            .build());
                }
            }
            if ("ZJ001".equals(accoTypeCode)) {
                for (JSONObject remoteData : remoteDatas) {
                    remoteDataMap = JSONObject.toJavaObject(remoteData, Map.class);
                    result.add(AccountInfoEntity.builder()
                            .fundName(remoteDataMap.get("fundName"))
                            .fundCode(remoteDataMap.get("fundCode"))
                            .bankAcco(remoteDataMap.get("accountNo"))
                            .nameInBank(remoteDataMap.get("accountName"))
                            .branchBankName(remoteDataMap.get("openAccountBank"))
                            .accoTypeCode("ZJ001")
                            .trustNo(trustNo)
                            .admin(tenantName)
                            .createTime(new Date())
                            .updateTime(new Date())
                            .remark("transfer")
                            .build());
                }
            }
        }
        if ("21".equals(trustNo)) {
            try {
                log.info("getAccountInfoByT0214{}", JSON.toJSONString(remoteDatas));
                Map<String, String> currencyDir = dataDictionaryBasicService.queryWithDetail(DataDictionaryTypeEnum.CURRENCY_SERVICE, trustNo);
                Map<String, String> bankCodeDic = dataDictionaryBasicService.queryWithDetail(DataDictionaryTypeEnum.BANK_CODE_SERVICE, "海通TA");
                for (JSONObject remoteData : remoteDatas) {
                    remoteDataMap = JSONObject.toJavaObject(remoteData, Map.class);
                    result.add(AccountInfoEntity.builder()
                            .fundCode(remoteDataMap.get("fundCode"))
                            .fundName(remoteDataMap.get("fundName"))
                            .bankCode(remoteDataMap.get("bankNo"))
                            .branchBankName(remoteDataMap.get("bankName"))
                            .currency(remoteDataMap.get("curType"))
                            .bankAcco(remoteDataMap.get("fundBankAcc"))
                            .nameInBank(remoteDataMap.get("bankAccName"))
                            .accoTypeCode("ZJ002")
                            .trustNo(trustNo)
                            .admin(tenantName)
                            .createTime(now)
                            .updateTime(now)
                            .remark("transfer")
                            .build());
                }
                return result;
            } catch (Exception e) {
                log.error("getAccountInfoByT0214异常{}", e);
            }

        }


        return result;
    }

    //查询募集户银行流水：mjAccount_seq_info
    private List<MjAccountSeqInfoEntity> getMJAccountSeqInfo(String tenantName, List<JSONObject> remoteDatas, String trustNo) {
        //2、封装数据
        List<MjAccountSeqInfoEntity> result = new ArrayList<>();
        Map<String, String> remoteDataMap;
        Date now = new Date();
        if ("25".equals(trustNo)) {
            if (!remoteDatas.isEmpty()) {
                remoteDatas.forEach(entry -> {
                    CMMJAccountSeqInfoDto dto = JSON.toJavaObject(entry, CMMJAccountSeqInfoDto.class);
                    log.info("cpdm" + JSON.toJSONString(dto));
                    String jyrq = dto.getJyrq();
                    if (jyrq != null && jyrq.length() > 10) {
                        jyrq = jyrq.substring(0, 10);
                    }
                    result.add(MjAccountSeqInfoEntity.builder()
                            .innerFundCode(dto.getCpdm())
                            .seqNo(dto.getLsh() == null ? RandomStrUtil.getRandomStr(32) : dto.getLsh().length() > 32 ? dto.getLsh().substring(0, 32) : dto.getLsh())
                            .account(dto.getBfzhh())
                            .accountName(dto.getBfzhmc())
                            .currency(dto.getBz())
                            .fundCode(dto.getCpdm())
                            .fundName(dto.getCpmc())
                            .opBankName(dto.getDsfkhhmc())
                            .opAccount(dto.getDsfzhh())
                            .opAccountName(dto.getDsfzhmc())
                            .amount(BigDecimalUtil.str2BigDecimal(dto.getJyje()))
                            .transferDate(jyrq)
                            .transferTime(dto.getJysj())
                            .bankName(dto.getMjhyh())
                            .transferInOut(dto.getSffx())
                            .summary(dto.getYhbz())
                            .admin(tenantName)
                            .trustNo(trustNo)
                            .createTime(new Date())
                            .updateTime(new Date())
                            .remark("transfer")
                            .build());
                });
            }
            return result;
        }
        if ("21".equals(trustNo)) {
            for (JSONObject remoteData : remoteDatas) {
                remoteDataMap = JSONObject.toJavaObject(remoteData, Map.class);
                //默认按照  directFlag 为 收 的情况去保存数据
                String opAccount = "";
                String opAccountName = "";
                String opBankName = "";
                String account = "";
                String accountName = "";
                String bankName = "";
                opAccount = remoteDataMap.get("outBankAcc");
                opAccountName = remoteDataMap.get("outAccName");
                opBankName = remoteDataMap.get("outOpenBank");
                account = remoteDataMap.get("inBankAcc");
                accountName = remoteDataMap.get("inAccName");
                bankName = remoteDataMap.get("inOpenBank");


                String bankJour = remoteDataMap.get("bankJour");
                if (StringUtils.isNotBlank(bankJour) && bankJour.length() > 32) {
                    bankJour = bankJour.substring(0, 32);
                }
                result.add(MjAccountSeqInfoEntity.builder()
                        .fundCode(remoteDataMap.get("fundCode"))
                        .fundName(remoteDataMap.get("fundName"))
                        .transferDate(remoteDataMap.get("occurDate"))
                        .transferTime(remoteDataMap.get("occurTime"))
                        .opAccount(opAccount)
                        .opAccountName(opAccountName)
                        .opBankName(opBankName)
                        .account(account)
                        .accountName(accountName)
                        .bankName(bankName)
                        .transferInOut(remoteDataMap.get("directFlag"))
                        .amount(BigDecimalUtil.obj2BigDecimal(remoteDataMap.get("occurAmt")))
                        .balance(BigDecimalUtil.obj2BigDecimal(remoteDataMap.get("acctBal")))
                        .summary(remoteDataMap.get("ftNote"))
                        .remark(remoteDataMap.get("bz"))
                        .remark(remoteDataMap.get("bz"))
                        .seqNo(bankJour)
                        .currency("156")
                        .trustNo(trustNo)
                        .admin(tenantName)
                        .createTime(now)
                        .updateTime(now)
                        .build());
            }
        }
        return result;
    }

    //份额明细查询：cust_share_detail_info
    private List<CustShareDetailInfoEntity> getCustShareDetailInfo(String tenantName, List<JSONObject> remoteDatas, String trustNo) {
        //2、封装数据
        List<CustShareDetailInfoEntity> result = new ArrayList<>();
        Map<String, String> remoteDataMap;
        Date now = new Date();
        if ("25".equals(trustNo)) {
            //招商的加这里
        }
        if ("21".equals(trustNo)) {

            for (JSONObject remoteData : remoteDatas) {
                remoteDataMap = JSONObject.toJavaObject(remoteData, Map.class);

                result.add(CustShareDetailInfoEntity.builder()
                        .fundCode(remoteDataMap.get("fundCode"))
                        .fundName(remoteDataMap.get("fundName"))
                        .fundAcco(remoteDataMap.get("fundAcco"))
                        .tradeAcco(remoteDataMap.get("tradeAcco"))
                        .tradeAcco(remoteDataMap.get("tradeAcco"))
                        .agencyNo(remoteDataMap.get("agencyNo"))
                        .agencyName(remoteDataMap.get("agencyNo"))
                        .remainShares(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("realShares")))
                        .confirmDate(remoteDataMap.get("confDate"))
                        .registDate(remoteDataMap.get("registDate"))
                        .sourceType(remoteDataMap.get("sourceType"))
                        .oriSource(remoteDataMap.get("oriSourceType"))
                        .oriNetValue(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("oriNetValue"), 4))
                        .oriShares(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("oriShares")))
                        .oriBalance(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("oriBalance")))
                        .lastDeductDate(remoteDataMap.get("lastDeductDate"))
                        .seqNo(RandomStrUtil.getRandomStr(32))
                        .agencyName(remoteDataMap.get("agencyNo"))
                        .trustNo(trustNo)
                        .admin(tenantName)
                        .createTime(now)
                        .updateTime(now)
                        .remark("transfer")
                        .build());
            }
        }

        return result;
    }

    //业绩报酬数据查询：fund_profit_info
    private List<FundProfitInfoEntity> getFundProfitInfo(String tenantName, List<JSONObject> remoteDatas, String trustNo) {
        //2、封装数据
        List<FundProfitInfoEntity> result = new ArrayList<>();
        Map<String, String> remoteDataMap;
        Date now = new Date();
        if ("25".equals(trustNo)) {
            //招商的加这里
        }
        if ("21".equals(trustNo)) {
            for (JSONObject remoteData : remoteDatas) {
                remoteDataMap = JSONObject.toJavaObject(remoteData, Map.class);
                result.add(FundProfitInfoEntity.builder()
                        .confirmDate(remoteDataMap.get("confDate"))
                        .fundCode(remoteDataMap.get("fundCode"))
                        .fundName(remoteDataMap.get("fundName"))
                        .agencyNo(remoteDataMap.get("agencyNo"))
                        .fundAcco(remoteDataMap.get("fundAcco"))
                        .tradeAcco(remoteDataMap.get("tradeAcco"))
                        .businessName(remoteDataMap.get("busiType"))
                        .sortFlag(remoteDataMap.get("sortFlag"))
                        .requestDate(remoteDataMap.get("dDate"))
                        .registDate(remoteDataMap.get("registDate"))
                        .oriDate(remoteDataMap.get("dBeginDate"))
                        .holdDay(remoteDataMap.get("hold"))
                        .shares(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("shares")))
                        .oriNav(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("oriNav"), 4))
                        .oriTotalNav(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("oriTotalNav"), 4))
                        .nav(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("nav"), 4))
                        .totalNav(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("totalNav"), 4))
                        .currRatio(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("currRatio"), 4))
                        .yearRatio(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("yearRatio"), 4))
                        .standardRatio(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("standardRatio"), 4))
                        .returnFare(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("returnFare")))
                        .oriBalance(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("oriBalance")))
                        .factBalance(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("factBalance")))
                        .factShares(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("factShares")))
                        .bonusBalance(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("bonusBalance")))
                        .income(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("income")))
                        .deductRatio(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("deductRatio"), 4))
                        .valueAddedFare(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("valueAddedFare")))
                        .costPrice(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("costPrice")))
                        .totalUnitBonus(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("totalUnitBonus")))
                        .oriCserialNo(remoteDataMap.get("oriCserialNo"))
                        .cserialNo(remoteDataMap.get("cserialNo"))
                        .agencyName(remoteDataMap.get("agencyNo"))
                        .trustNo(trustNo)
                        .admin(tenantName)
                        .createTime(now)
                        .updateTime(now)
                        .remark("transfer")
                        .build());
            }
        }


        return result;
    }

    //9 交易确认查询：fund_trade_info
    private List<FundTradeInfoEntity> getFundTradeInfo(String tenantName, List<JSONObject> remoteDatas, String trustNo) {
        //封装数据
        List<FundTradeInfoEntity> result = new ArrayList<>();
        Map<String, String> remoteDataMap;
        Date now = new Date();
        if ("25".equals(trustNo)) {
            Map<String, String> businessTypeDir = dataDictionaryBasicService.queryWithDetail(DataDictionaryTypeEnum.BUSINESS_NAME_SERVICE, trustNo);
            Map<String, String> confirmStatusDir = dataDictionaryBasicService.queryWithDetail(DataDictionaryTypeEnum.CONFIRM_STATUS_SERVICE, trustNo);
            Map<String, String> sellerDir = dataDictionaryBasicService.queryWithDetail(DataDictionaryTypeEnum.SELLER_SERVICE, "招商证券");
            if (!remoteDatas.isEmpty()) {
                remoteDatas.forEach(entry -> {
                    CMFundTradeInfoDto dto = JSON.toJavaObject(entry, CMFundTradeInfoDto.class);
                    //CMFundTradeInfoDto dto = (CMFundTradeInfoDto) entry.getValue();
                    String agency1 = MatchDataDictionaryKeyUtil.getKey(sellerDir, dto.getDistributorCode());
                    log.info("fund_trade_info agencyNo原值=" + dto.getDistributorCode() + "映射值=" + agency1);
                    log.info("fund_trade_info confirmStatus原值=" + dto.getRemark2() + "映射值=" + MatchDataDictionaryKeyUtil.getKey(confirmStatusDir, dto.getRemark2()));
                    log.info("fund_trade_info businessName原值=" + dto.getBusinessCode() + "映射值=" + MatchDataDictionaryKeyUtil.getKey(businessTypeDir, dto.getBusinessCode()));
                    result.add(FundTradeInfoEntity.builder()
                            .innerFundCode(dto.getFundCode())
                            .fundAcco(dto.getTaAccountId())
                            .tradeAcco(dto.getTransactionAccountId())
                            .fundName(dto.getFundName())
                            //需要daas处理
                            .fundCode(dto.getFundName())
//                                .businessName(MatchDataDictionaryKeyUtil.getKey(businessTypeDir,dto.getBusinessCode()))
                            .businessName(MatchDataDictionaryKeyUtil.getKey(businessTypeDir, dto.getBusinessCode()))
                            .applyBalance(dto.getApplicationAmount())
                            .applyShares(dto.getApplicationVol())
                            .requestDate(dto.getTransactionDate())
                            .netValue(dto.getNav())
                            .confirmDate(dto.getTransactionCfmDate())
                            .confirmShares(dto.getConfirmedVol())
                            .confirmBalance(dto.getConfirmedAmount())
                            .confirmNavVol(dto.getConfirmedNavVol())
                            .tradeFare(dto.getCharge())
                            .profitBalance(dto.getPerformance())
                            .agencyNo(agency1)
                            .agencyName(dto.getDistributorName())
                            .cserialNo(dto.getRemark1())
//                                .confirmStatus(MatchDataDictionaryKeyUtil.getKey(confirmStatusDir,dto.getRemark2()))
                            .confirmStatus(MatchDataDictionaryKeyUtil.getKey(confirmStatusDir, dto.getRemark2()))
                            .summary(dto.getNote())
                            .requestNo(dto.getOrigDefNo())
                            .admin(tenantName)
                            .trustNo(trustNo)
                            .createTime(new Date())
                            .updateTime(new Date())
                            .remark("transfer")
                            .build());
                });
            }
            return result;
        }
        if ("21".equals(trustNo)) {
            for (JSONObject remoteData : remoteDatas) {
                remoteDataMap = JSONObject.toJavaObject(remoteData, Map.class);

                result.add(FundTradeInfoEntity.builder()
                        .confirmDate(remoteDataMap.get("confDate"))
                        .requestDate(remoteDataMap.get("applyDate"))
                        .fundCode(remoteDataMap.get("fundCode"))
                        .fundName(remoteDataMap.get("fundName"))
                        .agencyNo(remoteDataMap.get("agencyNo"))
                        .agencyName(remoteDataMap.get("agencyName"))
                        .fundAcco(remoteDataMap.get("fundAcco"))
                        .tradeAcco(remoteDataMap.get("tradeAcco"))
                        .taFlag(remoteDataMap.get("taFlag"))
                        .confirmStatus(remoteDataMap.get("confStatus"))
                        .agio(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("agio"), 4))
                        .bonusMethod(remoteDataMap.get("bonusType"))
                        .applyBalance(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("balance"), 2))
                        .applyShares(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("shares"), 2))
                        .netValue(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("netValue"), 4))
                        .confirmBalance(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("confBalance"), 2))
                        .confirmShares(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("confShares"), 2))
                        .tradeFare(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("tradeFare"), 2))
                        .taFare(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("taFare"), 2))
                        .stampTax(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("stampTax")))
                        .backFare(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("backFare")))
                        .breachFare(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("breachFare")))
                        .breachFareAgt(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("breachFare4Agt")))
                        .breachFareFund(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("breachFare4Fund")))
                        .profitBalance(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("profitBalance")))
                        .profitBalanceAgt(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("profitBalance4Agt")))
                        .totalFare(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("totalFare")))
                        .agencyFare(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("agencyFare")))
                        .fundFare(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("fundFare")))
                        .registFare(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("registFare")))
                        .interest(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("interest")))
                        .interestTax(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("interestTax")))
                        .interestShare(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("interestShare")))
                        .frozenBalance(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("frozenBalance")))
                        .unfrozenBalance(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("unfrozenBalance")))
                        .unShares(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("unShares")))
                        .confirmNavVol(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("netConfBalance")))
                        .cserialNo(remoteDataMap.get("cserialNo"))
                        .businessName(remoteDataMap.get("busiFlag"))
                        .requestNo(remoteDataMap.get("originalNo"))
                        .trustNo(trustNo)
                        .admin(tenantName)
                        .createTime(now)
                        .updateTime(now)
                        .remark("transfer")
                        .build());
            }
        }


        return result;
    }

    // 份额持有人查询 cust_share_info
    private List<CustShareInfoEntity> getCustShareInfo(String tenantName, List<JSONObject> remoteDatas, String trustNo) {
        //2、封装数据
        List<CustShareInfoEntity> result = new ArrayList<>();
        Map<String, String> remoteDataMap;
        Date now = new Date();
        if ("25".equals(trustNo)) {
            if (!remoteDatas.isEmpty()) {
                remoteDatas.forEach(entry -> {
                    CMCustShareInfoDto dto = JSON.toJavaObject(entry, CMCustShareInfoDto.class);
                    //CMCustShareInfoDto dto = (CMCustShareInfoDto) entry.getValue();

                    String fundCode = dto.getFundCode();


                    log.info("cust_share_info的 dto.getFundVolDate()" + dto.getFundVolDate());
                    //处理updateDate
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
                    SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String updateDate = null;
                    if (!StringUtils.isEmpty(dto.getFundVolDate())) {
                        try {
                            Date parse = sdf.parse(dto.getFundVolDate());
                            updateDate = sdf1.format(parse);
                        } catch (ParseException e) {
                            e.printStackTrace();
                            log.error("时间转化失败！", e);
                        }
                    }
                    result.add(CustShareInfoEntity.builder()
                            .innerFundCode(dto.getFundCode())
                            .fundAcco(dto.getTaAccountId())
                            .tradeAcco(dto.getTransactionAccountId())
                            .fundName(dto.getFundName())
                            .fundCode(fundCode)
                            .updateDate(updateDate)
                            .lastHoldShares(dto.getTotalFundVol())
                            .enableShares(dto.getApplicationVol())
                            .frozenShares(dto.getFrozenVol())
                            .bonusMethod(dto.getDefdividendMethod())
                            .agencyNo(dto.getDistributorCode())
                            .agencyName(dto.getDistributorName())
                            //fixme 这个地方托管那边处理
                            .shareRatio(null)
                            .admin(tenantName)
                            .trustNo(trustNo)
                            .createTime(new Date())
                            .updateTime(new Date())
                            .remark("transfer")
                            .build());
                });
            }
            return result;
        }
        if ("21".equals(trustNo)) {
            for (JSONObject remoteData : remoteDatas) {
                remoteDataMap = JSONObject.toJavaObject(remoteData, Map.class);
                //修改shareRatio
                BigDecimal shareRatio = BigDecimalUtil.str2BigDecimal(remoteDataMap.get("shareRatio"), 6);
                BigDecimal shareRatioReal = null;
                if (shareRatio == null) {
                    log.error("海通getCustShareInfo为空");
                } else {
                    shareRatioReal = shareRatio.multiply(new BigDecimal("100")).setScale(4, RoundingMode.HALF_DOWN);
                }
                //处理updateDate
                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
                SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String updateDate = null;
                if (!StringUtils.isEmpty(remoteDataMap.get("lastModify"))) {
                    try {
                        Date parse = sdf.parse(remoteDataMap.get("lastModify"));
                        updateDate = sdf1.format(parse);
                    } catch (ParseException e) {
                        e.printStackTrace();
                        log.error("时间转化失败！", e);
                    }
                }
                result.add(CustShareInfoEntity.builder()
                        .fundCode(remoteDataMap.get("fundCode"))
                        .fundName(remoteDataMap.get("fundName"))
                        .fundAcco(remoteDataMap.get("fundAcco"))
                        .tradeAcco(remoteDataMap.get("tradeAcco"))
                        .agencyNo(remoteDataMap.get("agencyNo"))
                        .enableShares(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("enableShares")))
                        .lastHoldShares(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("realShares")))
                        .shareRatio(shareRatioReal)
                        .netValueDate(remoteDataMap.get("busiDate"))
                        .frozenShares(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("frozenShares")))
                        .bonusMethod(remoteDataMap.get("bonusType"))
                        .income(BigDecimalUtil.str2BigDecimal(remoteDataMap.get("income") == null ? "0" : remoteDataMap.get("income")).setScale(2, RoundingMode.HALF_UP))
                        .updateDate(updateDate)
                        .agencyName(remoteDataMap.get("agencyNo"))
                        .trustNo(trustNo)
                        .admin(tenantName)
                        .createTime(now)
                        .updateTime(now)
                        .remark("transfer")
                        .build());
            }
        }


        return result;
    }

    //产品信息查询
    private List<FundInfoEntity> getFundInfoData(String tenantName, List<JSONObject> remoteDatas, String trustNo) {
        List<FundInfoEntity> result = new ArrayList<>();
        Map<String, String> remoteDataMap;
        Date now = new Date();
        if ("25".equals(trustNo)) {
            //招商的加这里
        }
        if ("21".equals(trustNo)) {
            //2、封装数据
            for (JSONObject remoteData : remoteDatas) {
                remoteDataMap = JSONObject.toJavaObject(remoteData, Map.class);

                result.add(FundInfoEntity.builder()
                        .fundCode(remoteDataMap.get("fundCode"))
                        .fundName(remoteDataMap.get("fundName"))
                        .serviceMode(remoteDataMap.get("serviceMode"))
                        .fundType(remoteDataMap.get("fundType"))
                        .peType(remoteDataMap.get("fundType"))
                        .fundStatus(remoteDataMap.get("fundStatus"))
                        .createDate(remoteDataMap.get("establishDate"))
                        .confDays(remoteDataMap.get("confDays"))
                        .trustNo(trustNo)
                        .admin(tenantName)
                        .createTime(now)
                        .updateTime(now)
                        .remark("transfer")
                        .build());
            }
        }


        return result;
    }

    //投资者信息查询 investor_bank_info
    private List getInvestorBankInfo(String tenantName, List<JSONObject> remoteDatas, String trustNo) {
        //2、封装数据
        List<InvestorBankInfoEntity> result = new ArrayList<>();
        Map<String, String> remoteDataMap;
        Date now = new Date();
        if ("25".equals(trustNo)) {
            if (!remoteDatas.isEmpty()) {
                for (JSONObject entry : remoteDatas) {
                    CMInvestorInfoDto dto = JSON.toJavaObject(entry, CMInvestorInfoDto.class);
                    //招商的加这里
                    result.add(InvestorBankInfoEntity.builder()
                            .fundAcco(dto.getTaAccountId())
                            .tradeAcco(dto.getTransactionAccountId())
                            .nameInBank(dto.getAcctName())
                            .bankNo(dto.getAcctNo())
                            .branchBankName(dto.getClearingAgency())
                            .bankProvince(dto.getProvinces())
                            .bankCity(dto.getCity())
                            .bankNoType("银行账号")
                            .trustNo(trustNo)
                            .admin(tenantName)
                            .createTime(new Date())
                            .updateTime(new Date())
                            .remark("transfer")
                            .build());

                }
            }
        }
        if ("21".equals(trustNo)) {
            for (JSONObject remoteData : remoteDatas) {
                remoteDataMap = JSONObject.toJavaObject(remoteData, Map.class);
                result.add(InvestorBankInfoEntity.builder()
                        .fundAcco(remoteDataMap.get("fundAcco"))
                        .tradeAcco(remoteDataMap.get("tradeAcco"))
                        .bankCode(remoteDataMap.get("bankNo"))
                        .bankNo(remoteDataMap.get("bankAcco"))
                        .branchBankName(remoteDataMap.get("openBankName"))
                        .nameInBank(remoteDataMap.get("nameInBank"))
                        .bankNoType("银行账号")
                        .trustNo(trustNo)
                        .admin(tenantName)
                        .createTime(now)
                        .updateTime(now)
                        .remark("transfer")
                        .build());
            }
        }
        return result;
    }

    //投资者信息查询 investor_info
    public List<InvestorInfoEntity> getInvestorInfoDataByMap(HashMap<String, Object> map) {
        String trustNo = (String) map.get("trustNo");
        List<JSONObject> objects1 = (List<JSONObject>) map.get("objects");
        ObjectMapper objectMapper = new ObjectMapper();
        List<JSONObject> objects = objectMapper.convertValue(objects1, new TypeReference<List<JSONObject>>() {
        });
        String tenant = (String) map.get("tenantName");
        List<InvestorInfoEntity> entities = getInvestorInfoData(tenant, objects, trustNo);
        return entities;
    }

    //投资者信息查询 investor_info
    private List<InvestorInfoEntity> getInvestorInfoData(String tenantName, List<JSONObject> remoteDatas, String trustNo) {
        List<InvestorInfoEntity> result = new ArrayList<>();
        Map<String, String> remoteDataMap;
        Date now = new Date();
        if ("25".equals(trustNo)) {
            HashMap<String, Object> stringObjectHashMap = new HashMap<>();
            List<InvestorBankInfoEntity> result1 = new ArrayList<>();
            if (!remoteDatas.isEmpty()) {

                remoteDatas.forEach(entry -> {
                    CMInvestorInfoDto dto = JSON.toJavaObject(entry, CMInvestorInfoDto.class);
                    //CMInvestorInfoDto dto = (CMInvestorInfoDto) entry.getValue();

                    result.add(InvestorInfoEntity.builder()
                            .custName(dto.getCustName())
                            .custType(dto.getCustType())
                            .identityType(dto.getCertificateType())
                            .identityNo(dto.getCertificateNo())
                            .fundAcco(dto.getTaAccountId())
                            .accoOpenDate(dto.getOpenDate())
                            .individualOrInstitution("是".equals(dto.getIndividualOrInstitution()) ? 1 : 0)
                            .trustNo(trustNo)
                            .admin(tenantName)
                            .createTime(new Date())
                            .updateTime(new Date())
                            .remark("transfer")
                            .build());

                    /*result1.add(InvestorBankInfoEntity.builder()
                            .fundAcco(dto.getTaAccountId())
                            .tradeAcco(dto.getTransactionAccountId())
                            .nameInBank(dto.getAcctName())
                            .bankNo(dto.getAcctNo())
                            .branchBankName(dto.getClearingAgency())
                            .bankProvince(dto.getProvinces())
                            .bankCity(dto.getCity())
                            .bankNoType("银行账号")
                            .trustNo(trustNo)
                            .admin(tenantName)
                            .createTime(new Date())
                            .updateTime(new Date())
                            .remark("transfer")
                            .build());*/

                });
            }
            stringObjectHashMap.put("result", result);
            //stringObjectHashMap.put("result1", result1);
            List<InvestorInfoEntity> entities = (List<InvestorInfoEntity>) stringObjectHashMap.get("result");
            return entities;
        }
        if ("21".equals(trustNo)) {
            //2、封装数据
            for (JSONObject remoteData : remoteDatas) {
                remoteDataMap = JSONObject.toJavaObject(remoteData, Map.class);
                result.add(InvestorInfoEntity.builder()
                        .custName(remoteDataMap.get("custName"))
                        .fundAcco(remoteDataMap.get("fundAcco"))
                        .custType(remoteDataMap.get("custType"))
                        .identityType(remoteDataMap.get("certiType"))
                        .identityNo(remoteDataMap.get("certiNo"))
                        .address(remoteDataMap.get("address"))
                        .mobileNo(remoteDataMap.get("tel"))
                        .zipCode(remoteDataMap.get("zipCode"))
                        .trustNo(trustNo)
                        .admin(tenantName)
                        .createTime(now)
                        .updateTime(now)
                        .remark("transfer")
                        .build());
            }
        }


        return result;
    }

    //开放日 fund_open_info
    /*public List<FundOpenInfoEntity> getFundOpenInfoByMap(HashMap<String, Object> map) {
        String trustNo = (String) map.get("trustNo");
        List<JSONObject> objects1 = (List<JSONObject>) map.get("objects");
        ObjectMapper objectMapper = new ObjectMapper();
        List<JSONObject> objects = objectMapper.convertValue(objects1, new TypeReference<List<JSONObject>>() {
        });
        String tenant = (String) map.get("tenantName");
        List<FundOpenInfoEntity> entities = getFundOpenInfo(tenant, objects, trustNo);
        return entities;
    }*/
    public static final Pattern letterPattern = Pattern.compile("^[a-zA-Z]$");

    //开放日 fund_open_info
    //private List<FundOpenInfoEntity> getFundOpenInfo(String tenantName, List<JSONObject> objects, String trustNo,TenantEscrowAuthorizationInfoDto tenant) {
    private List<FundOpenInfoEntity> getFundOpenInfo(String tenantName, List<JSONObject> objects, String trustNo) {
        List<FundOpenInfoEntity> entityList = new ArrayList<>();
        Map<String, String> dataMap;
        if ("25".equals(trustNo)) {
            //获取数据字典
            //开放日类型字典
            Map<String, String> typeOfOpenDayDic = dataDictionaryBasicService.queryWithDetail(DataDictionaryTypeEnum.TYPE_OF_OPEN_DAY_SERVICE, trustNo);
            //发放状态字典
            Map<String, Map<String, String>> openStateDic = openStateService.queryOpenStateWithDetail(trustNo);
            //封装数据
            objects.forEach(entry -> {
                CMPrdInfoDto dto = JSON.toJavaObject(entry, CMPrdInfoDto.class);
                //开放类型转义
                String openType = MatchDataDictionaryKeyUtil.getKey(typeOfOpenDayDic, dto.getOpenType());
                //获取fundCode
                String fundCode = dto.getFundCode();
                String fundName = dto.getFundName();
                if (StringUtils.isBlank(fundName)) {
                    fundName = "null";
                }
                //设置fundCode
                log.info("getFundInfoData：上游拿到的fundCode={},fundName={}", fundCode, fundName);
                String fundInfoFundCode = "";
                if (StringUtils.isBlank(fundName)) {
                    log.error("当前1009接口上线数据为{},fundName为blank:{}", JSON.toJSONString(dto), fundName);
                } else {
                    //判断fundName是否以字母结尾
                    String substring = fundName.substring(fundName.length() - 1);
                    Matcher matcher = letterPattern.matcher(substring);
                    boolean lastCharIsLetter = matcher.find();
                    //如果以字母结尾
                    if (lastCharIsLetter) {
                        String fundNamePrefix = fundName.substring(0, fundName.length() - 1);
                        log.info("fundName为：{}末尾为字母，去掉字母后为{}去数据库查", fundName, fundNamePrefix);
                        fundInfoFundCode = getFundCodeByFundName(fundNamePrefix, trustNo, tenantName);
                        log.info("查询数据库、上游、字典表拿到的fundCode为{}", fundInfoFundCode);
                    } else {//如果不以字母结尾，fundCode和innerFundCode取值一样
                        fundInfoFundCode = fundCode;
                    }
                }
                log.info("getFundInfoData:入参fundCode{},入参fundName{},出参fundInfoFundCode{}", fundCode, fundName, fundInfoFundCode);
                entityList.add(FundOpenInfoEntity.builder()
                        .innerFundCode(dto.getFundCode())
                        .fundName(fundName)
                        .fundOpenDate(dto.getOpenDate())
                        .openType(openType)
                        .openStatus(MatchDataDictionaryKeyUtil.getKey(openType, openStateDic, dto.getIfTempOpen()))
                        .ifFixedTime(Integer.parseInt(dto.getIfFixedTime()))
                        .fundCode(fundCode)
                        .trustNo(trustNo)
                        .admin(tenantName)
                        .createTime(new Date())
                        .updateTime(new Date())
                        .build());
            });
            return entityList;
        }
        if ("21".equals(trustNo)) {
            for (JSONObject data : objects) {
                dataMap = JSONObject.toJavaObject(data, Map.class);
                String fundName = fundInfoService.getFundNameByFundCode(dataMap.get("fundCode"), trustNo, tenantName);
                entityList.add(FundOpenInfoEntity.builder()
                        .fundCode(dataMap.get("fundCode"))
                        .fundOpenDate(dataMap.get("openDate"))
                        .openType(dataMap.get("openSrc"))
                        .openStatus(dataMap.get("openType"))
                        .fundName(fundName)
                        .trustNo(trustNo)
                        .admin(tenantName)
                        .createTime(new Date())
                        .updateTime(new Date())
                        .remark("transfer")
                        .build());
            }
        }

        return entityList;
    }

    //private String getFundCodeByFundName(String fundName,TenantEscrowAuthorizationInfoDto tenant) {
    private String getFundCodeByFundName(String fundName, String trustNo, String tenantName) {
        //1先从数据库查，应该可能已经落过一些数据了
        String fundCode = fundInfoService.getFundCodeByFundName(fundName, trustNo, tenantName);
        if (StringUtils.isNotBlank(fundCode)) {
            return fundCode;
        }

        //查询字典表
        return dataDictionaryZxFndBasicInfoCyService.getFundCodeByFundname(fundName);
    }

    public List setRemarkInEntities(List entities) {
        for (Object entity : entities) {
            String s = entity.toString();
            s = s + "remark=“transfer”";
        }
        return null;
    }

}
