package com.friday.custody.service.AmbersService.Impl;

import com.alibaba.dubbo.common.utils.CollectionUtils;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.friday.base.common.response.DubboResult;
import com.friday.custody.dao.*;
import com.friday.custody.dto.InterProviderResponseDto;
import com.friday.custody.entity.ChanpinquanjingEntity;
import com.friday.custody.entity.FileInfoEntity;
import com.friday.custody.service.AmbersService.Commom.Commons;
import com.friday.mystery.forwardapi.dto.DistributorGetDatePostResponseDto;
import com.friday.mystery.forwardapi.service.IHttpRequestService;
import com.google.common.collect.Lists;
import com.friday.custody.service.AmbersService.AmService;
import com.friday.custody.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import javax.annotation.Resource;
import java.io.*;
import java.util.*;

@Service("amServiceImpl")
@Slf4j
public class AmServiceImpl implements AmService {
    private static HashMap<Integer,String> fundStatusMap = new HashMap<>();
    private static HashMap<Integer,String> isSueModeMap = new HashMap<>();
    private ObjectMapper objectMapper = new ObjectMapper();
    @Autowired
    private ChanpinquanjingDao chanpinquanjingDao;
    @Autowired
    private AccpuntInfoDao accpuntInfoDao;
    @Autowired
    private ShareInfoDao shareInfoDao;
    @Autowired
    private AdvisorInfoDao advisorInfoDao;
    @Autowired
    private IInvestorInfoDao iInvestorInfoDao;
    @Autowired
    private IjsxiRobotMqDao ijsxiRobotMqDao;
    @Autowired
    private OneInvestorInfoDao oneInvestorInfoDao;
    @Autowired
    private OutsourcingInfoDao outsourcingInfoDao;
    @Autowired
    private FileInfoDao fileInfoDao;
    @Resource
    private IHttpRequestService httpRequestService;
    @Value("${custody.ambers.url}")
    private String url;
    private String cdsResourceKey = "f0c3dade20e84c8bae52d60a17560f19";

    static {
        fundStatusMap.put(0,"正在运作");
        fundStatusMap.put(1,"正常清算");
        fundStatusMap.put(2,"提前清算");
        fundStatusMap.put(3,"延期清算");
        fundStatusMap.put(4,"投顾协议已终止");
        fundStatusMap.put(5,"非正常清算");


        isSueModeMap.put(101,"101");
        isSueModeMap.put(102,"101");
        isSueModeMap.put(103,"101");
        isSueModeMap.put(106,"101");
        isSueModeMap.put(108,"101");
        isSueModeMap.put(109,"101");
    }


    @Override
    public R queryFundIdAndName(String adminId) {
        // 查询字段(为空则查询全部字段)
        List<String> selectedFields = Lists.newArrayList("MANAGEFUNDID", "MANAGEFUNDNAME");
        Map<String, List<String>> paramMaps = new HashMap<>();
        paramMaps.put("REGCODE", Lists.newArrayList(adminId));  // 交易代码
        log.info("调用资讯中心接口入参：{}, {}", "ZX_FNDORGCY", JSON.toJSONString(paramMaps));
        DubboResult<DistributorGetDatePostResponseDto> resultData = httpRequestService.getInformationByDistributor("ZX_FNDORGCY", paramMaps, 0, 10000, "", selectedFields);
        InterProviderResponseDto responseDto = getInterProviderResponse(resultData);
        if (!responseDto.isSuccess()) {
            String errMsg = "调用资讯中心接口查询Resource= [ZX_FNDORGCY]的数据失败! resultData= " + JSON.toJSONString(resultData);
            log.error(errMsg);
            return R.error("调用资讯中心接口查询fundIdAndName失败");
        }
        List<Map<String, Object>> resultDataList = responseDto.getDataList();
        if (CollectionUtils.isEmpty(resultDataList)) {
            String errMsg = "调用资讯中心接口查询resource=[ZX_FNDORGCY]的数据为空! resultData= " + JSON.toJSONString(resultDataList);
            log.warn(errMsg);
            return R.ok("调用资讯中心接口查询fundIdAndName未查询到数据");
        }
        String fundId = String.valueOf(resultDataList.get(0).get("MANAGEFUNDID"));
        // 查询字段(为空则查询全部字段)
        selectedFields = Lists.newArrayList("REGCODE", "FUNDFULLNAME","ISLIQUIDATION","ISSUEMODE");
        // 查询条件
        paramMaps = new HashMap<>();
        String[] split = fundId.split(",");
        paramMaps.put("FUNDID", Lists.newArrayList(split)); // 交易代码
        // 执行查询操作
        log.info("调用资讯中心接口入参：{}, {}", "ZX_FNDBASICINFOCY", JSON.toJSONString(paramMaps));
        resultData = httpRequestService.getInformationByDistributor("ZX_FNDBASICINFOCY", paramMaps, 0, 10000, "FUNDID", selectedFields);
        responseDto = getInterProviderResponse(resultData);
        if (!responseDto.isSuccess()) {
            String errMsg = "调用资讯中心接口查询Resource= [ZX_FNDBASICINFOCY]的数据失败! resultData= " + JSON.toJSONString(resultData);
            log.error(errMsg);
            return R.error("调用资讯中心接口查询fundFullName失败");
        }
        List<Map<String, Object>> dataList = responseDto.getDataList();
        if (CollectionUtils.isEmpty(dataList)) {
            String errMsg = "调用资讯中心接口查询resource=[ZX_FNDBASICINFOCY]的数据为空! resultData= " + JSON.toJSONString(dataList);
            log.warn(errMsg);
            return R.ok("调用资讯中心接口查询fundFullName未查询到数据");
        }
        for (Map<String, Object> fundMap : dataList) {
            Double isliquidation = (Double) fundMap.get("ISLIQUIDATION");
            Double isSueMode = (Double) fundMap.get("ISSUEMODE");

            String id = String.valueOf(fundMap.get("REGCODE")) ;
            ChanpinquanjingEntity chanpinquanjing= chanpinquanjingDao.selectById(id);

            Boolean need = false;
            if (isSueModeMap.keySet().contains(isSueMode.intValue())){
                need = true;
            }
            if (null == chanpinquanjing && need) {
                if (StringUtils.isNotEmpty(id) && !"null".equals(id)){
                    ChanpinquanjingEntity chanpinquanjingEntity = ChanpinquanjingEntity.builder()
                            .id(id)
                            .prodFullName(String.valueOf(fundMap.get("FUNDFULLNAME")))
                            .prodCode(id)
                            .sequencestatus("COMPLETED")
                            .chanpingzhuangtai(fundStatusMap.get(isliquidation.intValue()))
                            .build();
                    chanpinquanjingDao.insert(chanpinquanjingEntity);
                }
            } else {
                if ("null".equals(id) || !need){
                    chanpinquanjingDao.deleteById(id);
                } else {
                    String fund_statusOld = chanpinquanjing.getChanpingzhuangtai();
                    if (StringUtils.isEmpty(fund_statusOld) || !fund_statusOld.equals(fundStatusMap.get(isliquidation.intValue()))){
                        ChanpinquanjingEntity entity = ChanpinquanjingEntity.builder()
                                .id(id)
                                .chanpingzhuangtai(fundStatusMap.get(isliquidation.intValue()))
                                .build();
                        chanpinquanjingDao.updateById(entity);
                    }
                }
            }

        }
        return R.ok("获取资讯数据成功！").put("data",dataList);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public R saveAmbersData(String data, String admin, String creater) {
        String id = null;
        try {

            Map<String,Object> dataMap = objectMapper.readValue(data,Map.class);

            // 基本信息
            //产品名称（全称）
            String proNameAll = (String) dataMap.get("proNameAll");
            //根据产品名称查询是否有数据，有则返回存在 无则新增

            //id = (String) dataMap.get("proCode");
            id = UUID.randomUUID().toString().replace("-","");
            String fundCode = (String) dataMap.get("proCode");

            ChanpinquanjingEntity entity = chanpinquanjingDao.selectInfo(fundCode,admin);
            Map<String,Object> productPanoramaMap = new HashMap<>();
            if (null!=entity){
                // 有数据先删除
                // 先同步产品状态
                productPanoramaMap.put("ChanPingZhuangTai",entity.getChanpingzhuangtai());
                Map<String , Object> map = new HashMap<>();
                map.put("prod_code",fundCode);
                map.put("admin",admin);
                chanpinquanjingDao.deleteByMap(map);
            }else{
                String status = ijsxiRobotMqDao.selectProStatus(admin,fundCode);
                if(StringUtils.isEmpty(status)){
                    status = "正在运作";
                }
                productPanoramaMap.put("ChanPingZhuangTai",status);
            }

            productPanoramaMap.put("creater",creater);
            productPanoramaMap.put("id",id);
            productPanoramaMap.put("sequenceStatus","COMPLETED");

            // 基本信息
            //产品名称（全称）
            productPanoramaMap.put("prod_full_name",proNameAll);
            // 产品简称
            productPanoramaMap.put("prod_short_name",dataMap.get("proNameAs"));
            // 产品编码
            productPanoramaMap.put("prod_code",dataMap.get("proCode"));

            //搜索
            //productPanoramaMap.put("search_key_saas",proNameAll+dataMap.get("proCode"));


            // 基金类型
            productPanoramaMap.put("fund_type_name",dataMap.get("fundType"));
            // 业务模式
            productPanoramaMap.put("biz_mode",dataMap.get("busModel"));
            // 是否量化/对冲基金
            productPanoramaMap.put("fund_type",dataMap.get("whetherChange"));
            // 产品类型
            productPanoramaMap.put("prod_type",dataMap.get("proType"));
            // 其他产品类型名称
            productPanoramaMap.put("other_type_name",dataMap.get("proElse"));
            // 投资策略（可多选）
            productPanoramaMap.put("invest_strategy", StringUtils.join(((List<String>)dataMap.get("investmentPolicy")),";"));
            // 其他投资策略名称
            productPanoramaMap.put("other_invest_strategy",dataMap.get("investmentPolicyElse"));
            // 量化主策略
            productPanoramaMap.put("policy_main_name",dataMap.get("masterStrategy"));
            // 其他量化主策略名称
            productPanoramaMap.put("other_policy_main_name",dataMap.get("mainStrElse"));
            // 量化辅策略（可多选）
            productPanoramaMap.put("policy_support_name",StringUtils.join(((List<String>)dataMap.get("auxiliaryStrategy")),";"));
            // 其他量化辅策略名称
            productPanoramaMap.put("other_policy_support_name",dataMap.get("auxiliaryStrategyElse"));
            // 基金成立日期
            productPanoramaMap.put("fund_setup_date",formatNumber(dataMap.get("beginDate")));
            // 基金到期日
            productPanoramaMap.put("fund_due_date",formatNumber(dataMap.get("endDate")));
            // 募集完成日
            productPanoramaMap.put("finished_date",formatNumber(dataMap.get("raisingDay")));
            // 组织形式
            productPanoramaMap.put("organize_type",dataMap.get("orgForm"));
            // 基金组织机构代码
            productPanoramaMap.put("fund_organ_code",dataMap.get("orgCode"));
            // 币种
            productPanoramaMap.put("currency",dataMap.get("currency"));
            // 是否涉及跨境投资
            productPanoramaMap.put("is_crossborder_investment",dataMap.get("cbInvestment"));
            //todo 目前只做契约型
            // 基金份额（万份）
            productPanoramaMap.put("fund_share",dataMap.get("fundShare"));
            // 是否存在保本情形
            productPanoramaMap.put("noLoss_flag",dataMap.get("breakEven"));
            // 是否存在保收益情形
            productPanoramaMap.put("gain_flag",dataMap.get("breakBenefits"));
            // 是否仅投资单一标的
            productPanoramaMap.put("only_target",dataMap.get("investmentSingle"));
            // 单一投资标的名称
            productPanoramaMap.put("invest_target_name",dataMap.get("name"));
            // 单一投资标的编码
            productPanoramaMap.put("invest_target_code",dataMap.get("investCode"));
            // 是否涉及关联交易
            productPanoramaMap.put("related_trade_flag",dataMap.get("relevance"));
            // 关联交易风险控制机制
            productPanoramaMap.put("related_trade_risk",dataMap.get("riskControl"));
            // 产品种类
            productPanoramaMap.put("fof",dataMap.get("fof"));
            // 标的资管计划全称
            productPanoramaMap.put("under_lying",dataMap.get("underlying"));
            // 是否通过SPV投资
            productPanoramaMap.put("SPV_flag",dataMap.get("spv"));
            // 主要投资方向
            productPanoramaMap.put("main_invest_target",dataMap.get("investmentDirection"));
            // 管理人其他问题说明
            productPanoramaMap.put("other_problems",dataMap.get("otherProblems"));
            // 备案主要联系人
            //姓名
            productPanoramaMap.put("contatct_name",((Map<String,Object>)dataMap.get("mainContact")).get("name"));
            //座机
            productPanoramaMap.put("contact_phone",((Map<String,Object>)dataMap.get("mainContact")).get("phone"));
            //手机
            productPanoramaMap.put("contatc_mobile",((Map<String,Object>)dataMap.get("mainContact")).get("mobile"));
            //邮箱
            productPanoramaMap.put("contact_email",((Map<String,Object>)dataMap.get("mainContact")).get("email"));
            // 备案主要联系人
            //姓名
            productPanoramaMap.put("spare_name",((Map<String,Object>)dataMap.get("alternateContact")).get("name"));
            //座机
            productPanoramaMap.put("spare_phone",((Map<String,Object>)dataMap.get("alternateContact")).get("phone"));
            //手机
            productPanoramaMap.put("spare_mobile",((Map<String,Object>)dataMap.get("alternateContact")).get("mobile"));
            //邮箱
            productPanoramaMap.put("mobile_email",((Map<String,Object>)dataMap.get("alternateContact")).get("email"));
            // 结构化信息&杠杆信息
            // 是否为结构化产品
            productPanoramaMap.put("is_constructed",((Map<String,Object>)dataMap.get("structuredInfo")).get("value"));
            // 杠杆比例
            productPanoramaMap.put("leverage_ratio",formatNumber(((Map<String,Object>)dataMap.get("structuredInfo")).get("managerValue")));
            // 份额类别信息
            Map<String,Object> shMap = new HashMap<>();
            shMap.put("sortKey",fundCode);
            shMap.put("admin",admin);
            shareInfoDao.deleteByMap(shMap);
            //List<Map<String,Object>> share_info = new ArrayList<>();
            List<Map<String,Object>> shareInfo = (List<Map<String, Object>>) ((Map<String,Object>)dataMap.get("structuredInfo")).get("shareInfo");
            for (Map<String, Object> shareMap : shareInfo) {
                Map<String,Object> share_Map = new HashMap<>();
                share_Map.put("id",UUID.randomUUID().toString().replace("-",""));
                share_Map.put("parentId",id);
                //share_Map.put("status","Add");
                // 份额名称
                share_Map.put("share_name",shareMap.get("shareName"));
                // 份额类别
                share_Map.put("share_type",shareMap.get("shareType"));
                // 其他份额类别说明
                //share_Map.put("shareElse",shareMap.get("shareElse"));
                // 收益安排（从低风险级
                share_Map.put("income_arrangement",shareMap.get("syType"));
                // 基准收益
                share_Map.put("basic_income_ratio",formatNumber(shareMap.get("basicIncome")));
                // 浮动收益
                share_Map.put("float_income",formatNumber(shareMap.get("floatIncome")));
                // 分配比例
                share_Map.put("allocate_ratio",formatNumber(shareMap.get("allocateRatio")));
                // 业绩比较基准收益类型
                share_Map.put("basic_income_type",shareMap.get("benchmark"));
                // 业绩比较基准收益说明
                share_Map.put("basic_income_note",shareMap.get("benchmarkContent"));
                // 创建时间
                share_Map.put("create_time",new Date());
                //修改时间
                share_Map.put("update_time",new Date());
                share_Map.put("sortKey",fundCode);
                //租户
                share_Map.put("admin",admin);
                //ShareInfoEntity shareInfoEntity = shareInfoDao.selectByParentIdAndAdmin(admin,fundCode);
                if(StringUtils.isNotEmpty((String)share_Map.get("share_name"))){
                    //share_info.add(share_Map);
                    shareInfoDao.insertByMap(Commons.shareInfo,share_Map);
                }
            }
            //productPanoramaMap.put("share_info"+admin,share_info);

            // 结构化安排的其他说明
            productPanoramaMap.put("constructed_note",((Map<String,Object>)dataMap.get("structuredInfo")).get("remark"));

            // 募集信息
            Map<String,Object> raisingInstitution = (Map<String, Object>) dataMap.get("raisingInstitution");
            // 募集方式
            productPanoramaMap.put("raise_method",StringUtils.join(((List<String>)raisingInstitution.get("raiseWay")),";"));
            // 自行募集机构名称
            productPanoramaMap.put("self_raise_agency_name",StringUtils.join(((List<String>)raisingInstitution.get("raiseName")),";"));
            // 委托募集机构名称
            productPanoramaMap.put("entrusted_raise_name",StringUtils.join(((List<String>)raisingInstitution.get("entrustName")),";"));

            Map<String,Object> raisingAccount = (Map<String, Object>) dataMap.get("raisingAccount");
            // 募集结算资金专用账户
            Map<String,Object> accMap = new HashMap<>();
            accMap.put("sortKey",fundCode);
            accMap.put("admin",admin);
            accpuntInfoDao.deleteByMap(accMap);
            //List<Map<String,Object>> accpunt_info = new ArrayList<>();
            List<Map<String,Object>> listInfo = (List<Map<String, Object>>) raisingAccount.get("listInfo");
            for (Map<String, Object> map : listInfo) {
                Map<String, Object> accpunt_map = new HashMap<>();
                accpunt_map.put("id",UUID.randomUUID().toString().replace("-",""));
                accpunt_map.put("parentId",id);
                //accpunt_map.put("status","Add");
                // 账户名称
                accpunt_map.put("account_name",map.get("accountName"));
                // 账号
                accpunt_map.put("account_number",map.get("account"));
                // 开户银行名称
                accpunt_map.put("bank_name",map.get("bankName"));
                // 创建时间
                accpunt_map.put("create_time",new Date());
                //修改时间
                accpunt_map.put("update_time",new Date());
                accpunt_map.put("sortKey",fundCode);
                //租户
                accpunt_map.put("admin",admin);
                //AccountInfoEntity accountInfoEntity = accpuntInfoDao.selectByParentIdAndAdmin(admin,fundCode);
                accpuntInfoDao.insertByMap(Commons.accpuntInfo,accpunt_map);
                //accpunt_info.add(accpunt_map);
            }
            //productPanoramaMap.put("accpunt_info"+admin,accpunt_info);
            // 监督机构名称
            productPanoramaMap.put("supervisory_name",StringUtils.join(((List<String>)raisingAccount.get("orgName")),";"));
            // 监督机构类型
            productPanoramaMap.put("supervisory_type",raisingAccount.get("orgType"));

            // 合同信息
            // 私募基金的募集
            // 按《管理办法》募集
            productPanoramaMap.put("to_manage_measures",((Map<String,Object>)dataMap.get("contractValue4")).get("contractValue4"));
            // 解释说明原因
            productPanoramaMap.put("explain_reason",((Map<String,Object>)dataMap.get("contractValue4")).get("contractValue4Exp"));
            // 募集期开始日期
            productPanoramaMap.put("raise_start_date",formatNumber(((Map<String,Object>)dataMap.get("contractRaisePeriod")).get("beginTime")));
            // 募集期结束日期
            productPanoramaMap.put("raise_end_date",formatNumber(((Map<String,Object>)dataMap.get("contractRaisePeriod")).get("endTime")));
            // 认购费率
            productPanoramaMap.put("subscribe_type",((Map<String,Object>)dataMap.get("contractSubscriptionRate")).get("rateName"));
            // 单一费率值
            productPanoramaMap.put("flat_rate_value",formatNumber(((Map<String,Object>)dataMap.get("contractSubscriptionRate")).get("rateValue")));
            // 差异化费率的划分标准
            productPanoramaMap.put("ratio_standard",StringUtils.join(((List<String>)((Map<String,Object>)dataMap.get("contractSubscriptionRate")).get("rateType")),";"));
            // 其他差异化费率的划分
            productPanoramaMap.put("other_subscribe_rate_note",((Map<String,Object>)dataMap.get("contractSubscriptionRate")).get("otherRate"));
            // 最高费率_%
            productPanoramaMap.put("rate_uplimit",formatNumber(((Map<String,Object>)dataMap.get("contractSubscriptionRate")).get("maxRate")));
            // 最低费率_%
            productPanoramaMap.put("rate_lowlimit",formatNumber(((Map<String,Object>)dataMap.get("contractSubscriptionRate")).get("minRate")));
            // 私募基金的成立与备案
            // 合同签署方式
            productPanoramaMap.put("contract_sign_type",StringUtils.join(((List<String>)dataMap.get("contractSigningMethod")),";"));
            // 私募基金的申购、赎回、转让
            // 申购费率
            productPanoramaMap.put("purchase_rate",((Map<String,Object>)dataMap.get("contractPurchaseRate")).get("rateName"));
            // 单一费率值
            productPanoramaMap.put("flat_rate_value_purchase",formatNumber(((Map<String,Object>)dataMap.get("contractPurchaseRate")).get("rateValue")));
            // 差异化费率的划分标准
            productPanoramaMap.put("purchase_rate_standard",StringUtils.join(((List<String>)((Map<String,Object>)dataMap.get("contractPurchaseRate")).get("rateType")),";"));
            // 其他差异化费率的划分
            productPanoramaMap.put("other_purchase_rate_note",((Map<String,Object>)dataMap.get("contractPurchaseRate")).get("otherRather"));
            // 最高费率_%
            productPanoramaMap.put("purchase_rate_uplimt",formatNumber(((Map<String,Object>)dataMap.get("contractPurchaseRate")).get("maxRate")));
            // 最低费率_%
            productPanoramaMap.put("purchase_rate_lowlimt",formatNumber(((Map<String,Object>)dataMap.get("contractPurchaseRate")).get("minRate")));

            // 赎回费率
            productPanoramaMap.put("redemption_rate",((Map<String,Object>)dataMap.get("contractRedemptionRate")).get("rateName"));


            // 单一费率值
            productPanoramaMap.put("flat_rate_value_redemption",formatNumber(((Map<String,Object>)dataMap.get("contractRedemptionRate")).get("rateValue")));
            // 赎回费归属
            productPanoramaMap.put("attribution_redemption_fee",StringUtils.join(((List<String>)((Map<String,Object>)dataMap.get("contractRedemptionRate")).get("redemption")),";"));
            // 其他归属
            productPanoramaMap.put("other_attribution",((Map<String,Object>)dataMap.get("contractRedemptionRate")).get("otherRather"));
            // 差异化费率的划分标准
            productPanoramaMap.put("redemption_rate_standard",StringUtils.join(((List<String>)((Map<String,Object>)dataMap.get("contractRedemptionRate")).get("dfRate")),";"));
            // 其他差异化费率的划分
            productPanoramaMap.put("other_redemption_rate_note",((Map<String,Object>)dataMap.get("contractRedemptionRate")).get("otherdfRather"));
            // 最高费率_%
            productPanoramaMap.put("redemption_rate_uplimt",formatNumber(((Map<String,Object>)dataMap.get("contractRedemptionRate")).get("maxRate")));
            // 最低费率_%
            productPanoramaMap.put("redemption_rate_lowlimt",formatNumber(((Map<String,Object>)dataMap.get("contractRedemptionRate")).get("minRate")));



            // 运作方式
            productPanoramaMap.put("operation_method",((Map<String,Object>)dataMap.get("contractOperationMode")).get("operateMode"));
            // 运作方式补充说明
            productPanoramaMap.put("operation_method_note",((Map<String,Object>)dataMap.get("contractOperationMode")).get("remark"));
            // 封闭期
            productPanoramaMap.put("close_period",((Map<String,Object>)dataMap.get("contractClosedPeriod")).get("closePeriod"));
            // 成立后月数
            productPanoramaMap.put("months_setup",formatNumber(((Map<String,Object>)dataMap.get("contractClosedPeriod")).get("setupMonth")));
            // (封闭期add)
            productPanoramaMap.put("close_period_add",((Map<String,Object>)dataMap.get("contractClosedPeriod")).get("closePeriodAdd"));
            // 封闭期补充说明
            productPanoramaMap.put("close_period_method_tips",((Map<String,Object>)dataMap.get("contractClosedPeriod")).get("notes"));
            // 开放期
            productPanoramaMap.put("open_period",((Map<String,Object>)dataMap.get("contractOpenPeriod")).get("openPeriod"));
            // 开放期补充说明
            productPanoramaMap.put("open_period_method_tips",((Map<String,Object>)dataMap.get("contractOpenPeriod")).get("remark"));
            // 其他赎回限制
            productPanoramaMap.put("other_redemption_limit",((Map<String,Object>)dataMap.get("contractOther")).get("redempLimit"));
            // 未满天数
            productPanoramaMap.put("less_days",formatNumber(((Map<String,Object>)dataMap.get("contractOther")).get("lessDays")));
            // 未满月数
            productPanoramaMap.put("less_months",formatNumber(((Map<String,Object>)dataMap.get("contractOther")).get("lessMonths")));
            // 其他赎回限制补充说明
            productPanoramaMap.put("other_r_l_tips",((Map<String,Object>)dataMap.get("contractOther")).get("notes"));
            // 本基金份额是否可转让
            productPanoramaMap.put("can_share_transfered",((Map<String,Object>)dataMap.get("contractValue6")).get("contractValue6"));
            // 基金份额转让补充说明
            productPanoramaMap.put("share_transfer_note",((Map<String,Object>)dataMap.get("contractValue6")).get("contractValue6Exp"));

            // 私募基金份额持有人大会及日常机构
            // 是否设立持有人大会
            productPanoramaMap.put("set_holder_meeting_flag",((Map<String,Object>)dataMap.get("contractValue10")).get("contractValue10"));
            //持有人大会议事内容
            productPanoramaMap.put("holder_meeting_contents",StringUtils.join(((List<String>)((Map<String,Object>)dataMap.get("contractValue10")).get("meetContList")),";"));
            // 解释说明原因
            productPanoramaMap.put("set_holder_reason_note",((Map<String,Object>)dataMap.get("contractValue10")).get("contractValue10Exp"));
            // 其他持有人大会议事内
            productPanoramaMap.put("other_holdier_meet_contents",((Map<String,Object>)dataMap.get("contractValue10")).get("notes"));
            // 是否设立日常机构
            productPanoramaMap.put("set_common_agency_flag",((Map<String,Object>)dataMap.get("contractValue11")).get("contractValue11"));
            // 日常机构议事内容
            productPanoramaMap.put("common_agency_contents",StringUtils.join(((List<String>)((Map<String,Object>)dataMap.get("contractValue11")).get("orgContList")),";"));
            // 其他日常机构议事内容
            productPanoramaMap.put("other_regular_contents",((Map<String,Object>)dataMap.get("contractValue11")).get("notes"));
            // 私募基金的份额登记
            // 本基金的份额登记机构
            productPanoramaMap.put("share_register_agency",dataMap.get("contractOrg"));
            // 私募基金的投资
            // 基金存续期限（月）
            productPanoramaMap.put("fund_duration_text",formatNumber(dataMap.get("contractFundDuration")));
            // 合同约定的投资范围
            productPanoramaMap.put("invest_types",StringUtils.join(((List<String>)((Map<String,Object>)dataMap.get("contractInvestment")).get("investTypes")),";"));
            // 证券类
            productPanoramaMap.put("security_types",StringUtils.join(((List<String>)(((Map<String,Object>)dataMap.get("contractInvestment")).get("secuTypes"))),";"));
            // 其他
            productPanoramaMap.put("other_security_types",((Map<String,Object>)dataMap.get("contractInvestment")).get("secuAdd"));
            // 非证券类
            productPanoramaMap.put("nosecurity_types",StringUtils.join(((List<String>)((Map<String,Object>)dataMap.get("contractInvestment")).get("nosecuTypes")),";"));
            // 其他
            productPanoramaMap.put("other_nosecurity_types",((Map<String,Object>)dataMap.get("contractInvestment")).get("nosecuAdd"));
            // FOF类
            productPanoramaMap.put("FOF_types",StringUtils.join(((List<String>)((Map<String,Object>)dataMap.get("contractInvestment")).get("fofTypes")),";"));
            // 其他
            productPanoramaMap.put("other_FOF_types",((Map<String,Object>)dataMap.get("contractInvestment")).get("fotAdd"));
            // 预警线
            productPanoramaMap.put("warning_line",((Map<String,Object>)dataMap.get("contractWarning")).get("warnType"));
            // 预警线的基金单位净值
            productPanoramaMap.put("warning_value",formatNumber(((Map<String,Object>)dataMap.get("contractWarning")).get("warnNum")));
            // 预警线具体情况
            productPanoramaMap.put("warning_content",((Map<String,Object>)dataMap.get("contractWarning")).get("remark"));
            // 止损线
            productPanoramaMap.put("stop_loss_line",((Map<String,Object>)dataMap.get("contractStoploss")).get("stopLossType"));
            // 止损线的基金单位净值
            productPanoramaMap.put("stop_loss_value",formatNumber(((Map<String,Object>)dataMap.get("contractStoploss")).get("stopLossNum")));
            // 止损线具体情况
            productPanoramaMap.put("stop_loss_content",((Map<String,Object>)dataMap.get("contractStoploss")).get("remark"));
            // 有无业绩比较基准
            productPanoramaMap.put("have_performance_basic",((Map<String,Object>)dataMap.get("contractValue13")).get("contractValue13"));
            // 业绩比较基准内容
            productPanoramaMap.put("performance_basic_content",((Map<String,Object>)dataMap.get("contractValue13")).get("contractValue13Exp"));

            // 私募基金的估值和会计核算
            // 基金的估值频率
            productPanoramaMap.put("valuation_frequency",((Map<String,Object>)dataMap.get("contractFrequency")).get("valueFreq"));
            // 其他基金的估值频率
            productPanoramaMap.put("other_valuation_frequency",((Map<String,Object>)dataMap.get("contractFrequency")).get("valueFreqAdd"));
            // 私募基金的费用与税收
            // 管理费
            productPanoramaMap.put("manage_fee",((Map<String,Object>)dataMap.get("contractManagementExpenses")).get("type"));
            // 固定比例管理费率%
            productPanoramaMap.put("fixed_manage_ratio",formatNumber(((Map<String,Object>)dataMap.get("contractManagementExpenses")).get("fixRatio")));
            // 固定金额管理费（万）
            productPanoramaMap.put("fixed_manage_fee",formatNumber(((Map<String,Object>)dataMap.get("contractManagementExpenses")).get("fixNum")));
            // 其他
            productPanoramaMap.put("other_manage_fee",((Map<String,Object>)dataMap.get("contractManagementExpenses")).get("other"));
            // 是否有保底管理费
            productPanoramaMap.put("have_manageLowlimit",(((Map<String,Object>)dataMap.get("contractManagementExpenses")).get("hasLimitFee")));
            // 保底管理费（万元/年
            productPanoramaMap.put("low_limit_manage_fee",formatNumber(((Map<String,Object>)dataMap.get("contractManagementExpenses")).get("LimitFee")));
            // 差异化费率的划分标准
            productPanoramaMap.put("standards_manage_fee",StringUtils.join(((List<String>)((Map<String,Object>)dataMap.get("contractManagementExpenses")).get("dfRateTypes")),";"));
            // 最高费率_%
            productPanoramaMap.put("highlimit_manage_ratio",formatNumber(((Map<String,Object>)dataMap.get("contractManagementExpenses")).get("maxRate")));
            // 最低费率_%
            productPanoramaMap.put("lowlimt_manage_ratio",formatNumber(((Map<String,Object>)dataMap.get("contractManagementExpenses")).get("minRate")));
            // 其他差异化费率的划分标准
            productPanoramaMap.put("other_standard_manage_ratio",(((Map<String,Object>)dataMap.get("contractManagementExpenses")).get("dfRateTypeAdd")));

            // 托管费/保管费
            productPanoramaMap.put("custody_fee",((Map<String,Object>)dataMap.get("contractCustodyExpenses")).get("type"));
            // 固定比例托/保管率%
            productPanoramaMap.put("fix_custody_rate",formatNumber(((Map<String,Object>)dataMap.get("contractCustodyExpenses")).get("fixRatio")));
            // 固定金额托/保管费（万元）
            productPanoramaMap.put("fix_custody_fee",formatNumber(((Map<String,Object>)dataMap.get("contractCustodyExpenses")).get("fixNum")));
            // 其他
            productPanoramaMap.put("other_custody_fee",((Map<String,Object>)dataMap.get("contractCustodyExpenses")).get("other"));
            // 是否有保底托管费保管
            productPanoramaMap.put("have_custody_lowlimit",(((Map<String,Object>)dataMap.get("contractCustodyExpenses")).get("hasLimitFee")));
            // 保底托管费保管费
            productPanoramaMap.put("low_limit_custody_fee",formatNumber(((Map<String,Object>)dataMap.get("contractCustodyExpenses")).get("LimitFee")));


            // 运营服务费外包服务费
            productPanoramaMap.put("operate_service_fee",((Map<String,Object>)dataMap.get("contractOperateExpenses")).get("type"));
            // 固定比例_%
            productPanoramaMap.put("fix_service_rate",formatNumber(((Map<String,Object>)dataMap.get("contractOperateExpenses")).get("fixRatio")));
            // 固定金额_(万元)
            productPanoramaMap.put("fix_service_fee",formatNumber(((Map<String,Object>)dataMap.get("contractOperateExpenses")).get("fixNum")));
            // 其他
            productPanoramaMap.put("other_operate_service_fee",((Map<String,Object>)dataMap.get("contractOperateExpenses")).get("other"));
            // 是否有保底运营服务费
            productPanoramaMap.put("have_lowlimit_service_fee",(((Map<String,Object>)dataMap.get("contractOperateExpenses")).get("hasLimitFee")));
            // 保底服务费（万元年)
            productPanoramaMap.put("lowlimit_service_fee",formatNumber(((Map<String,Object>)dataMap.get("contractOperateExpenses")).get("LimitFee")));

            // 销售服务费
            productPanoramaMap.put("sale_service_fee",((Map<String,Object>)dataMap.get("contractSaleExpenses")).get("type"));
            // 固定比例销售服务费率
            productPanoramaMap.put("fix_sale_ratio",formatNumber(((Map<String,Object>)dataMap.get("contractSaleExpenses")).get("fixRatio")));
            // 固定金额销售服务费
            productPanoramaMap.put("fix_sale_service",formatNumber(((Map<String,Object>)dataMap.get("contractSaleExpenses")).get("fixNum")));
            // 其他
            productPanoramaMap.put("other_sale_service_fee",((Map<String,Object>)dataMap.get("contractSaleExpenses")).get("other"));
            // 是否有保底销售服务费
            productPanoramaMap.put("have_lowlimit_sale_fee",(((Map<String,Object>)dataMap.get("contractSaleExpenses")).get("hasLimitFee")));
            // 保底销售服务费/万元
            productPanoramaMap.put("lowlimt_sale_fee",formatNumber(((Map<String,Object>)dataMap.get("contractSaleExpenses")).get("LimitFee")));

            // 其他费用
            productPanoramaMap.put("other_fee",dataMap.get("contractOtherExpenses"));

            // 计提时点
            productPanoramaMap.put("provision_time",StringUtils.join(((List<String>)((Map<String,Object>)dataMap.get("contractRemuneration")).get("timeTypes")),";"));
            // 其他计提方式
            productPanoramaMap.put("other_provision_way",(((Map<String,Object>)dataMap.get("contractRemuneration")).get("timeAdd")));
            // 计提基准
            productPanoramaMap.put("provision_benchmark",(((Map<String,Object>)dataMap.get("contractRemuneration")).get("standType")));
            // 设定业绩基准为/%
            productPanoramaMap.put("set_provision_benchmark",formatNumber(((Map<String,Object>)dataMap.get("contractRemuneration")).get("standVal")));
            // 其他
            productPanoramaMap.put("other_provision_benchmark",(((Map<String,Object>)dataMap.get("contractRemuneration")).get("standValAdd")));
            // 计提比例%
            productPanoramaMap.put("total_proportion",formatNumber(((Map<String,Object>)dataMap.get("contractRemuneration")).get("fixRatio")));
            // 业绩报酬其他解释说明
            productPanoramaMap.put("other_compensation_tips",((Map<String,Object>)dataMap.get("contractRemuneration")).get("notes"));

            // 私募基金的收益分配
            // 收益分配方式
            productPanoramaMap.put("options_profit_distribution",StringUtils.join(((List<String>)((Map<String,Object>)dataMap.get("contractDistributionInfo")).get("types")),";"));
            // 其他方式
            productPanoramaMap.put("other_profit_d_options",((Map<String,Object>)dataMap.get("contractDistributionInfo")).get("typeAdd"));
            // 收益分配次数 选项
            productPanoramaMap.put("times_profit_distribution",((Map<String,Object>)dataMap.get("contractDistributionInfo")).get("timesTypes"));
            // 分配次数/年
            productPanoramaMap.put("times_distribution_year",formatNumber(((Map<String,Object>)dataMap.get("contractDistributionInfo")).get("fixTimes")));
            // 不超过次数/年
            productPanoramaMap.put("less_times_year",formatNumber(((Map<String,Object>)dataMap.get("contractDistributionInfo")).get("limitTimes")));
            // 其他
            productPanoramaMap.put("other_times_distribution",((Map<String,Object>)dataMap.get("contractDistributionInfo")).get("timesAdd"));
            // 收益分配条件
            productPanoramaMap.put("conditions_profit_d",((Map<String,Object>)dataMap.get("contractDistributionInfo")).get("condition"));

            // 基金合同的效力、变更、解除与终止
            // 合同生效条件
            productPanoramaMap.put("contract_condition",((Map<String,Object>)dataMap.get("contractFileInfo")).get("effectType"));
            // 附加条件
            productPanoramaMap.put("add_condition",((Map<String,Object>)dataMap.get("contractFileInfo")).get("effectCondAdd"));
            // 合同变更的方式
            productPanoramaMap.put("contract_change_ways",StringUtils.join(((List<String>)((Map<String,Object>)dataMap.get("contractFileInfo")).get("changeTypes")),";"));
            // 其他方式
            productPanoramaMap.put("other_ways",((Map<String,Object>)dataMap.get("contractFileInfo")).get("changeTypeAdd"));
            // 合同解除的方式
            productPanoramaMap.put("contract_cancel_way",((Map<String,Object>)dataMap.get("contractFileInfo")).get("relieveNotes"));
            // 合同终止情形
            productPanoramaMap.put("contract_end_way",StringUtils.join(((List<String>)((Map<String,Object>)dataMap.get("contractFileInfo")).get("terminationTypes")),";"));
            // 附加情形
            productPanoramaMap.put("add_situation",((Map<String,Object>)dataMap.get("contractFileInfo")).get("terminationTypeAdd"));
            // 争议的处理
            // 调解方式
            productPanoramaMap.put("mediation_mode",StringUtils.join(((List<String>)((Map<String,Object>)dataMap.get("contractMediationMode")).get("types")),";"));
            // 其他方式
            productPanoramaMap.put("other_disagree_way",((Map<String,Object>)dataMap.get("contractMediationMode")).get("other"));
            // 其他
            productPanoramaMap.put("other_content",dataMap.get("contractContentAdd"));
            // 托管及外包服务机构信息
            // 托管相关信息
            // 是否托管
            productPanoramaMap.put("selectt_custody",((Map<String,Object>)dataMap.get("outerPackInfo")).get("exist"));
            // 托管人名称(全称)
            productPanoramaMap.put("name_custody",((Map<String,Object>)dataMap.get("outerPackInfo")).get("name"));
            // 其他类型
            productPanoramaMap.put("custody_other_type",((Map<String,Object>)dataMap.get("outerPackInfo")).get("otherType"));
            // 其他保障财产安全的制度措施和纠纷解决机制内容
            productPanoramaMap.put("custody_notes",((Map<String,Object>)dataMap.get("outerPackInfo")).get("notes"));

            // 基金财产托管账户
            // 账户名称
            productPanoramaMap.put("bank_account_custody",((Map<String,Object>)dataMap.get("fundBankInfo")).get("accountName"));
            // 账号
            productPanoramaMap.put("bank_ID_custody",((Map<String,Object>)dataMap.get("fundBankInfo")).get("account"));
            // 开户银行名称
            productPanoramaMap.put("bank_name_custody",((Map<String,Object>)dataMap.get("fundBankInfo")).get("bankName"));
            // 托管人主要联系人
            // 姓名
            productPanoramaMap.put("contact_name_custody",((Map<String,Object>)dataMap.get("outerManagerContact")).get("name"));
            // 座机
            productPanoramaMap.put("fix_tel_contact_custody",((Map<String,Object>)dataMap.get("outerManagerContact")).get("phone"));
            // 手机
            productPanoramaMap.put("phone_contact_person",((Map<String,Object>)dataMap.get("outerManagerContact")).get("mobile"));
            // 邮箱
            productPanoramaMap.put("emall_contact_custody",((Map<String,Object>)dataMap.get("outerManagerContact")).get("email"));
            // 外包机构信息
            // 是否有外包机构
            productPanoramaMap.put("have_outsourcing",((Map<String,Object>)dataMap.get("outerOrgInfo")).get("exist"));
            // 外包机构信息
            Map<String,Object> outMap = new HashMap<>();
            outMap.put("sortKey",fundCode);
            outMap.put("admin",admin);
            outsourcingInfoDao.deleteByMap(outMap);
            List<Map<String,Object>> outerOrgInfoItems = (List<Map<String, Object>>) ((Map<String,Object>)dataMap.get("outerOrgInfo")).get("orgList");
            //List<Map<String,Object>> outsourcing_info = new ArrayList<>();
            for (Map<String, Object> outerOrgInfoItem : outerOrgInfoItems) {
                Map<String,Object> outsourcing_map = new HashMap<>();
                outsourcing_map.put("id",UUID.randomUUID().toString().replace("-",""));
                outsourcing_map.put("parentId",id);
                //outsourcing_map.put("status","Add");
                // 是否已在协会登记
                outsourcing_map.put("had_registered",outerOrgInfoItem.get("registered"));
                // 基金服务(外包)机构
                outsourcing_map.put("outsourcing_name",outerOrgInfoItem.get("orgName"));
                // 组织机构代码
                outsourcing_map.put("outsourcing_code",outerOrgInfoItem.get("orgCode"));
                // 备案编号
                outsourcing_map.put("prod_code",outerOrgInfoItem.get("prodCode"));
                // 服务类型
                outsourcing_map.put("service_types",StringUtils.join(((List<String>)outerOrgInfoItem.get("serviceTypes")),";"));
                // 信息技术服务类型（补
                outsourcing_map.put("cs_service_types",StringUtils.join(((List<String>)outerOrgInfoItem.get("serviceTypesAdds")),";"));
                // 其他
                outsourcing_map.put("other_service_types",outerOrgInfoItem.get("serviceTypesOther"));
                // 创建时间
                outsourcing_map.put("create_time",new Date());
                //修改时间
                outsourcing_map.put("update_time",new Date());
                outsourcing_map.put("sortKey",fundCode);
                //租户
                outsourcing_map.put("admin",admin);
                //OutsourcingInfoEntity outsourcingInfoEntity = outsourcingInfoDao.selectByParentIdAndAdmin(admin,id);
                outsourcingInfoDao.insertByMap(Commons.outsourcingInfo,outsourcing_map);
                //outsourcing_info.add(outsourcing_map);
            }
            //productPanoramaMap.put("outsourcing_info"+admin,outsourcing_info);
            // 顾问信息
            // 是否有投资顾问
            productPanoramaMap.put("have_advisor",((Map<String,Object>)dataMap.get("consultantInfo")).get("exist"));
            // 外包机构信息
            Map<String,Object> adMap = new HashMap<>();
            adMap.put("sortKey",fundCode);
            adMap.put("admin",admin);
            advisorInfoDao.deleteByMap(adMap);
            List<Map<String,Object>> consultantList = (List<Map<String, Object>>) ((Map<String,Object>)dataMap.get("consultantInfo")).get("consultantList");
            //List<Map<String,Object>> advisor_info = new ArrayList<>();
            for (Map<String, Object> consultant : consultantList) {
                Map<String,Object> advisor_map = new HashMap<>();
                advisor_map.put("id",UUID.randomUUID().toString().replace("-",""));
                advisor_map.put("parentId",id);
                //advisor_map.put("status","Add");
                // 顾问方式
                advisor_map.put("consultant_mode",consultant.get("consultantMethod"));
                // 其他顾问方式
                advisor_map.put("other_consult_method",consultant.get("methodElse"));
                // 顾问类型
                advisor_map.put("consultant_type",consultant.get("consultantType"));
                // 其他顾问类型
                advisor_map.put("other_consult_type",consultant.get("typeElse"));
                // 是否已在协会登记
                advisor_map.put("is_advisor_regestered",consultant.get("registered"));
                // 登记编码
                advisor_map.put("register_code",consultant.get("registrationCode"));
                // 投资/财务顾问名称
                advisor_map.put("advisor_name",consultant.get("orgName"));
                // 投资顾问组织机构代码
                advisor_map.put("advisor_code",consultant.get("orgCode"));
                // 费用(%或描述）
                advisor_map.put("advisor_fee",consultant.get("feeNote"));
                // 权利及义务
                advisor_map.put("rights",consultant.get("obligation"));
                // 创建时间
                advisor_map.put("create_time",new Date());
                //修改时间
                advisor_map.put("update_time",new Date());
                advisor_map.put("sortKey",fundCode);
                //租户
                advisor_map.put("admin",admin);
                //AdvisorInfoEntity advisorInfoEntity = advisorInfoDao.selectByParentIdAndAdmin(admin,id);
                advisorInfoDao.insertByMap(Commons.advisorInfo,advisor_map);
                //advisor_info.add(advisor_map);
            }
            //productPanoramaMap.put("advisor_info"+admin,advisor_info);
            // 投资经理信息
            // 投资经理信息
            Map<String,Object> iiMap = new HashMap<>();
            iiMap.put("sortKey",fundCode);
            iiMap.put("admin",admin);
            iInvestorInfoDao.deleteByMap(iiMap);
            //List<Map<String,Object>> investor_info = new ArrayList<>();
            List<Map<String,Object>> investmentManagers = (List<Map<String, Object>>) dataMap.get("investmentManager");
            for (Map<String, Object> investmentManager : investmentManagers) {
                Map<String,Object> investor_map = new HashMap<>();
                investor_map.put("id",UUID.randomUUID().toString().replace("-",""));
                investor_map.put("parentId",id);
                //investor_map.put("status","Add");
                // 姓名
                investor_map.put("investor_name",investmentManager.get("name"));
                // 证件类型
                investor_map.put("idcard_type",investmentManager.get("cardType"));
                // 证件号码
                investor_map.put("id_code",investmentManager.get("cardCode"));
                // 担任本产品投资经理的起始时间
                investor_map.put("start_time",formatNumber(investmentManager.get("beginTime")));
                // 创建时间
                investor_map.put("create_time",new Date());
                //修改时间
                investor_map.put("update_time",new Date());
                investor_map.put("sortKey",fundCode);
                //租户
                investor_map.put("admin",admin);
                //IInvestorInfoEntity iInvestorInfoEntity = iInvestorInfoDao.selectByParentIdAndAdmin(admin,id);
                iInvestorInfoDao.insertByMap(Commons.investorInfo,investor_map);
                //investor_info.add(investor_map);
            }
            //productPanoramaMap.put("investor_info"+admin,investor_info);

            // 投资者信息
            // 投资者总数
            productPanoramaMap.put("investor_sum",((Map<String,Object>)dataMap.get("stat")).get("investorSum"));
            // 自然人数量
            productPanoramaMap.put("nature_amount",((Map<String,Object>)dataMap.get("stat")).get("personNum"));
            // 机构数量
            productPanoramaMap.put("institutions_num",((Map<String,Object>)dataMap.get("stat")).get("orgNum"));
            // 投资产品数量
            productPanoramaMap.put("invest_prod_num",((Map<String,Object>)dataMap.get("stat")).get("proNum"));
            // 认缴总额（万元）
            productPanoramaMap.put("subscribed_amount",((Map<String,Object>)dataMap.get("stat")).get("mountNum"));
            // 基金总份额（万份）
            productPanoramaMap.put("total_fund_share",((Map<String,Object>)dataMap.get("stat")).get("shareNum"));
            // 1级投资者信息
            Map<String,Object> oneMap = new HashMap<>();
            oneMap.put("sortKey",fundCode);
            oneMap.put("admin",admin);
            oneInvestorInfoDao.deleteByMap(oneMap);
           // List<Map<String,Object>> Sheet1641870268373 = new ArrayList<>();
            List<Map<String,Object>> investmentMembers = (List<Map<String, Object>>) dataMap.get("investmentMember");
            for (Map<String, Object> investmentMember : investmentMembers) {
                Map<String,Object> Sheet1641870268373_map = new HashMap<>();
                Sheet1641870268373_map.put("id",UUID.randomUUID().toString().replace("-",""));
                Sheet1641870268373_map.put("parentId",id);
                //Sheet1641870268373_map.put("status","Add");
                // 投资者类型
                Sheet1641870268373_map.put("investor_types",investmentMember.get("investmentType"));
                // 投资者名称
                Sheet1641870268373_map.put("investor_name",investmentMember.get("investmentName"));
                // 有效证件类型
                Sheet1641870268373_map.put("investor_id_type",investmentMember.get("cardType"));
                // 有效证件号码
                Sheet1641870268373_map.put("valid_id_card",investmentMember.get("cardCode"));
                // 合伙人类型
                Sheet1641870268373_map.put("partner_type",investmentMember.get("partnerType"));
                // 认缴金额（万元）
                Sheet1641870268373_map.put("subscribed_amount",investmentMember.get("subscriptionAmount"));
                // 份额名称
                Sheet1641870268373_map.put("share_name",investmentMember.get("shareName"));
                // 销售机构
                Sheet1641870268373_map.put("sales_agency",investmentMember.get("saleOrganization"));
                // 基金份额（万份）
                Sheet1641870268373_map.put("fund_share",formatNumber(investmentMember.get("fundAmount")));
                // 联系方式
                Sheet1641870268373_map.put("contact_num",investmentMember.get("linkPhone"));
                // 创建时间
                Sheet1641870268373_map.put("create_time",new Date());
                //修改时间
                Sheet1641870268373_map.put("update_time",new Date());
                Sheet1641870268373_map.put("sortKey",fundCode);
                //租户
                Sheet1641870268373_map.put("admin",admin);
                //OneInvestorInfoEntity oneInvestorInfoEntity = oneInvestorInfoDao.selectByParentIdAndAdmin(admin,id);
                oneInvestorInfoDao.insertByMap(Commons.oneInvestorInfo,Sheet1641870268373_map);
                //Sheet1641870268373.add(Sheet1641870268373_map);
            }
            //productPanoramaMap.put("Sheet1641870268373"+admin,Sheet1641870268373);
            productPanoramaMap.put("admin",admin);
            productPanoramaMap.put("createdTime",new Date());
            productPanoramaMap.put("modifiedTime",new Date());
            chanpinquanjingDao.insertByMap(Commons.chanpinquanjing,productPanoramaMap);

            // 同步 产品全景报表数据
            //operationTask.syncReportData(productPanoramaMap,"cpqj_report_date"+admin);

            return R.ok("成功");
        } catch (Exception e) {
            log.info(e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return R.error(e.getMessage().substring(0,200));
        }
    }

    @Override
    public R upLoadFile(String filePath, String fileName, String admin, String productId, String attmfield) {
        // 根据productId查询对应产品全景数据
        ChanpinquanjingEntity chanpinquanjingEntity = chanpinquanjingDao.selectById(productId);
        if(!Objects.isNull(chanpinquanjingEntity)){
            try {
                filePath = "\\" + filePath;
                log.info("filePath---"+filePath);
                filePath ="/nas_data"+ filePath.replace("\\","/");
                log.info("filePath:"+filePath);
                //下载从rpa获取到的文件
                byte[] bytes = downloadFile(filePath);
                log.info("byte数组长度:"+bytes.length);
                //todo
                String path =url+admin+"/"+productId+"/";
                File file = bytesToFile(bytes, path, fileName);
                //入库
                if(file !=null && file.exists()){
                    String absolutePath = file.getAbsolutePath();
                    log.info("文件绝对路径:"+absolutePath);
                    String name = file.getName();
                    String type = name.split("\\.")[1];
                    //String type = Files.probeContentType(file.toPath());
                    String fileSize = getFileSize(file.length());
                    log.info("文件大小:"+fileSize);
                    log.info("文件类型:"+type);
                    //判断数据库是否有该文件
                    FileInfoEntity entity = fileInfoDao.selectFile(admin,productId,absolutePath);
                    if(!Objects.isNull(entity)){
                        //不为空先删后入库
                        fileInfoDao.delFileInfo(admin,productId,absolutePath);
                    }
                    FileInfoEntity fileInfoEntity = FileInfoEntity.builder()
                            .fileUrl(absolutePath)
                            .fileName(name)
                            .fileSize(fileSize)
                            .fileType(type)
                            .admin(admin)
                            .fundCode(productId)
                            .createTime(new Date())
                            .updateTime(new Date())
                            .build();
                    fileInfoDao.insert(fileInfoEntity);
                }
            } catch (Exception e) {
                e.printStackTrace();
                return R.error("文件上传失败");
            }
        }
        return null;
    }

    public static String getFileSize(long length){
        if(1000L<= length&&length<1000000L){
            return length/1000.0F+"KB";
        }else if(1000000L <=length && length <1000000000L){
            return length/1000000.0F+"MB";
        }else if(1000000000L <= length && length<1000000000000L){
            return length/1000000000.0F+"GB";
        }else{
            return length+"B";
        }
    }

    public static File bytesToFile(byte[] bytes, String outPath, String fileName) {
        BufferedOutputStream bos = null;
        FileOutputStream fos = null;
        File file = null;
        try {
            File dir = new File(outPath);
            if (!dir.exists() || dir.isDirectory()) { //判断文件目录是否存在
                dir.mkdirs();
            }
            file = new File(outPath + File.separator + fileName);
            fos = new FileOutputStream(file);
            bos = new BufferedOutputStream(fos);
            bos.write(bytes);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (bos != null) {
                try {
                    bos.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }
        return file;
    }


    public byte[] downloadFile(String fileName) throws Exception {
        byte[] buffer = new byte[1024];
        try {
            FileInputStream is = new FileInputStream(fileName);
            ByteArrayOutputStream baos = cloneInputStream(is);
            buffer = baos.toByteArray();
        } catch (Exception var17) {
            log.error("下载失败:", var17);
            throw new RuntimeException("下载失败:", var17);
        }

        return buffer;
    }
    private static ByteArrayOutputStream cloneInputStream(InputStream input) {
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];

            int len;
            while((len = input.read(buffer)) > -1) {
                baos.write(buffer, 0, len);
            }

            baos.flush();
            return baos;
        } catch (IOException var4) {
            throw new RuntimeException(var4);
        }
    }

    private Object formatNumber(Object value){
        if (value instanceof String){
            if ("".equals(value)){
                return null;
            }
        }
        return value;
    }

    private InterProviderResponseDto getInterProviderResponse(DubboResult<DistributorGetDatePostResponseDto> resultData){
        if (resultData == null) {
            return InterProviderResponseDto.builder().success(false).failMsg("资讯接口调用失败，返回结果为空！").build();
        }
        if (resultData.success()) {
            DistributorGetDatePostResponseDto responseDto = resultData.getObject();
            if (responseDto.getRetCode() == 0) {
                String value = JSON.toJSONString(responseDto.getValue());
                if (org.apache.commons.lang.StringUtils.isNotEmpty(value)) {
                    return JSON.parseObject(value, InterProviderResponseDto.class);
                }
            } else {
                return InterProviderResponseDto.builder().success(false).failMsg(responseDto.getMessage()).build();
            }
        }
        return InterProviderResponseDto.builder().success(false).failMsg(resultData.getError() + resultData.getMessage()).build();
    }
}
