package com.sifang.modules.youkua.service;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.sifang.modules.customer.Service.CustomerEntryMsgService;
import com.sifang.modules.customer.constant.CustomerEntryConstants;
import com.sifang.modules.customer.constant.PartnerConstants;
import com.sifang.modules.customer.dao.*;
import com.sifang.modules.customer.entity.*;
import com.sifang.modules.customer.form.AddEntryReq;
import com.sifang.modules.customer.form.AddReportReq;
import com.sifang.modules.customer.form.AddReportSecondReq;
import com.sifang.modules.customer.utils.CustomerEntryUtil;
import com.sifang.modules.customer.utils.GaodeUtil;
import com.sifang.modules.monitor.vo.OverviewStaticDataVo;
import com.sifang.modules.monitor.vo.ThreeDaysPowerVo;
import com.sifang.modules.platform.utils.PlantformUtils;
import com.sifang.modules.sunshine.SystemSetting.dao.PlanMaterialEntryDao;
import com.sifang.modules.sunshine.SystemSetting.dao.ProjectCompanyDao;
import com.sifang.modules.sunshine.SystemSetting.entity.ProjectCompanySettings;
import com.sifang.modules.sunshine.SystemSetting.service.PlanService;
import com.sifang.modules.sunshine.SystemSetting.utils.BusinessException;
import com.sifang.modules.sunshine.SystemSetting.utils.RandomUtil;
import com.sifang.modules.sunshine.SystemSetting.utils.Result;
import com.sifang.modules.sunshine.partnerManagement.dao.PartnerBrandUtils;
import com.sifang.modules.sys.common.UserUtils;
import com.sifang.modules.sys.common.service.BaseService;
import com.sifang.modules.sys.common.utils.DateUtils;
import com.sifang.modules.sys.common.utils.StringUtil;
import com.sifang.modules.sys.dao.SysCapitalDictDao;
import com.sifang.modules.sys.entity.Operator;
import com.sifang.modules.sys.util.CrmUtils;
import com.sifang.modules.sys.util.SqlBuilder;
import com.sifang.modules.task.NHTask;
import com.sifang.modules.youkua.constants.YWConstants;
import com.sifang.modules.youkua.constants.ZfConstants;
import com.sifang.modules.youkua.entity.NhDevice;
import com.sifang.modules.youkua.entity.NhPowerStation;
import com.sifang.modules.youkua.utils.YWUtils;
import com.sifang.modules.youkua.vo.EnergyDataVo;
import com.sifang.modules.youkua.vo.PowerStationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.*;

@Service
public class NhPowerStationService extends BaseService {

    private final static String NHFileUrl ="https://pv.nhet.cloud/oss/";

    private final static String commonStaticImgPath ="https://nhet.oss-cn-shanghai.aliyuncs.com/";

    @Autowired
    CustomerEntryDao customerDao;
    @Autowired
    private CrmCustomerEntrySurveyRecordStockDao surveyRecordStockDao;
    @Autowired
    private CrmArchiveSurveyStockDao archiveSurveyStockDao;
    @Autowired
    private CrmCustomerEntryStockDao entryStockDao;
    @Autowired
    private CrmAcceptingReportStockDao reportStockDao;
    @Autowired
    private CrmCustomerIncomingApplicationDao incomingApplicationDao;
    @Autowired
    private ContractManagementDao contractManagementDao;
    @Autowired
    private ProjectCompanyDao projectCompanySettingsDao;
    @Autowired
    private CustomerEntrySurveyRecordDao surveyRecordDao;
    @Autowired
    private SysCapitalDictDao sysCapitalDictDao;
    @Autowired
    private CustomerEntryComponentDao customerEntryComponentDao;
    @Autowired
    private PlanMaterialEntryDao planMaterialEntryDao;
    @Autowired
    private CrmCustomerIncomingApplicationInsuranceDao insuranceDao;
    @Autowired
    private CrmAcceptingReportDao reportDao;
    @Autowired
    private CrmYxIncomingLogDao yxIncomingLogDao;
    @Autowired
    private PlanService planService;
    @Autowired
    private CustomerEntryMsgService msgService;

    /**
     * 生成同步日志
     * status 状态 0 成功 1失败
     * type 类型 0 友夸数据  1 能辉数据
     * addType 0.添加电站 1.添加设备 2.同步已并网验收通过 3.物料信息变更 4同步回款时间
     */
    public static int saveSysRecord(String stationId, String url, String requestParam,
                                    String responseParam, String status,String type,String addType){
        int result = Db.update("  INSERT INTO nh_yw_interface_process(id,station_id,url,create_time,request_param, response_param, status ,type,add_type ) " +
                "  VALUES (MD5(UUID()),?,?,NOW(),?,?,?,?,?)",stationId,url,requestParam,responseParam,status,type,addType);
        return result;
    }

    public static void backSysRecord(String stationId) {
        Db.update("update nh_yw_interface_process a set a.`status` = '1' where a.station_id = ? and a.`status` = '0'",
                stationId);
    }

    /**
     * 添加电站
     * @param nhPowerStation
     */
    public String  addPowerStation(NhPowerStation nhPowerStation,String applyStatus, String type){
        Map<String,Object> body=new HashMap<>();
        body.put("innerStationId",nhPowerStation.getInnerStationId());
        body.put("applyStatus",applyStatus);
        body.put("outStationId",nhPowerStation.getOutStationId());
        body.put("stationCode",nhPowerStation.getStationCode());
        body.put("stationName",nhPowerStation.getStationName());
        body.put("images",nhPowerStation.getImages());
        body.put("capitalCode",nhPowerStation.getCapitalCode());
        body.put("capitalName",nhPowerStation.getCapitalName());
        body.put("projectId",nhPowerStation.getProjectId());
        body.put("projectCode",nhPowerStation.getProjectCode());
        body.put("projectName",nhPowerStation.getProjectName());
        body.put("projectCompanyId",nhPowerStation.getProjectCompanyId());
        body.put("projectCompanyName",nhPowerStation.getProjectCompanyName()==null?"上海能辉科技股份有限公司":nhPowerStation.getProjectCompanyName());
        body.put("installType",nhPowerStation.getInstallType());
        body.put("agentId",nhPowerStation.getAgentId());
        body.put("agentName",nhPowerStation.getAgentName());
        body.put("agentPhone",nhPowerStation.getAgentPhone());
        body.put("ownerId",nhPowerStation.getOwnerId());
        body.put("ownerName",nhPowerStation.getOwnerName());
        body.put("ownerPhone",nhPowerStation.getOwnerPhone());
        body.put("sn",nhPowerStation.getSn());
        body.put("province",nhPowerStation.getProvince());
        body.put("city",nhPowerStation.getCity());
        body.put("district",nhPowerStation.getDistrict());
        body.put("address",nhPowerStation.getAddress());
        String longitude = nhPowerStation.getLongitude();
        String latitude = nhPowerStation.getLatitude();
        if (StringUtil.isBlank(longitude) || StringUtil.isBlank(latitude)){
            String address = nhPowerStation.getProvince() + nhPowerStation.getCity() + nhPowerStation.getDistrict() + nhPowerStation.getAddress();
            String lonLat = GaodeUtil.getLonLat(address);
            String[] split = lonLat.split(",");
            longitude = split[0];
            latitude = split[1];
        }
        body.put("longitude", longitude);
        body.put("latitude", latitude);
        String actualCapacity = "";
        if(nhPowerStation.getActualCapacity() != null){
            actualCapacity = nhPowerStation.getActualCapacity().stripTrailingZeros().toPlainString();
        }
        body.put("actualCapacity",actualCapacity);
        String installAcceptTime = "";
        if (nhPowerStation.getInstallAcceptTime() != null){
            installAcceptTime = DateUtils.formatDate(nhPowerStation.getInstallAcceptTime(), "yyyy-MM-dd HH:mm:ss");
        }
        body.put("installAcceptTime",installAcceptTime);
        String startGenDate = "";
        if (nhPowerStation.getStartGenDate() != null){
            startGenDate = DateUtils.formatDate(nhPowerStation.getStartGenDate(), "yyyy-MM-dd HH:mm:ss");
        }
        body.put("startGenDate",startGenDate);
        body.put("applyNo",nhPowerStation.getApplyNo());
        body.put("isFollow",nhPowerStation.getIsFollow());
        body.put("status","1");
        body.put("omProviderId",nhPowerStation.getOmProviderId());
        body.put("omProviderName",nhPowerStation.getOmProviderName());
        body.put("filingType",nhPowerStation.getFilingType());
        String mergeTime = "";
        if (nhPowerStation.getMergeTime() != null){
            mergeTime = DateUtils.formatDate(nhPowerStation.getMergeTime(), "yyyy-MM-dd HH:mm:ss");
        }
        body.put("mergeTime",mergeTime);
        body.put("customerType",nhPowerStation.getCustomerType());
        String url = YWConstants.url+YWConstants.addPowerStationUrl;
        String result = YWUtils.request(url, body);
        String status = "1";
        Map parse=(Map) JSONObject.parse(result);
        String code = "";
        if(parse.containsKey("code") && parse.containsKey("data")){
            code = String.valueOf(parse.get("code"));
            if("200".equals(code)){
                status = "0";
            }
            // 501 电站内部id重复，该电站已同步
            if("501".equals(code)){
                status = "0";
            }
        }
        saveSysRecord(nhPowerStation.getOutStationId(), url, new Gson().toJson(body), result, status, type,"0");
        return  code;
    }
    /**
     * 批量更新电站信息
     * @param
     */
    public Object pushEntryTime(List<Map<String,Object>> list){
        String url = YWConstants.url+YWConstants.batchUpdateInverterStatUrl;
        String result = YWUtils.request2(url, list);
        Map parse=(Map) JSONObject.parse(result);
       return parse.get("code");
    }
    /**
     * 同步电站已并网验收通过
     * 因为友夸系统的电站 都是已完成的 所以不需要调用此方法
     * @param nhPowerStation
     */
    public String sysYbwPowerStation(NhPowerStation nhPowerStation){
        Map<String,Object> body=new HashMap<>();
        body.put("innerStationId",nhPowerStation.getInnerStationId());
        body.put("outStationId",nhPowerStation.getOutStationId());
        body.put("applyStatus","1");
        String mergeTime = "";
        if (nhPowerStation.getMergeTime() != null){
            mergeTime = DateUtils.formatDate(nhPowerStation.getMergeTime(), "yyyy-MM-dd HH:mm:ss");
        }
        body.put("mergeTime",mergeTime);
        String startGenDate = "";
        if (nhPowerStation.getStartGenDate() != null){
            startGenDate = DateUtils.formatDate(nhPowerStation.getStartGenDate(), "yyyy-MM-dd HH:mm:ss");
        }
        body.put("startGenDate",startGenDate);
        String url = YWConstants.url+YWConstants.sysYbwPowerStation;
        String result = YWUtils.request(url, body);
        String status = "1";
        Map parse=(Map) JSONObject.parse(result);
        String code = "";
        if(parse.containsKey("code") && parse.containsKey("data")){
            code = String.valueOf(parse.get("code"));
            if("200".equals(code)){
                status = "0";
            }
            // 501 电站内部id重复，该电站已同步
            if("501".equals(code)){
                status = "0";
            }
        }
        saveSysRecord(nhPowerStation.getOutStationId(), url, new Gson().toJson(body), result, status, "1","2");
        return  code;
    }

    /**
     * 批量添加设备
     * @param nhDeviceList
     */
    public void batchAddInverterSta(List<NhDevice> nhDeviceList,String outStationId,String type){
        List<Map<String,Object>> list=new ArrayList<>();
        for (NhDevice device : nhDeviceList) {
            Map<String,Object> body=new HashMap<>();
            body.put("innerStationId",device.getInnerStationId());
            body.put("innerDeviceId",device.getInnerDeviceId());
            body.put("outStationId",device.getOutStationId());
            body.put("outDeviceId",device.getOutDeviceId());
            body.put("brand",device.getBrand());
            body.put("type",device.getType());
            body.put("name",device.getName());
            body.put("mods",device.getMods());
            body.put("sn",device.getSn());
            body.put("barCode",device.getBarCode());
            body.put("warrantyFlag",device.getWarrantyFlag());
            body.put("warrantyExpires",device.getWarrantyExpires());
            body.put("staus",device.getStatus());
            list.add(body);
        }
        String url = YWConstants.url+YWConstants.batchAddInverterStatUrl;
        String result = YWUtils.request2(url, list);
        String status = "1";
        Map parse=(Map) JSONObject.parse(result);
        if(parse.containsKey("code") && parse.containsKey("data")){
            if("200".equals(String.valueOf(parse.get("code")))){
                status = "0";
            }
        }
        if (list.size()==0){
            status = "1";
        }
        saveSysRecord(outStationId, url, new Gson().toJson(list), result, status, type,"1");
    }

    //物料信息变更，同步监控系统
    public void materialChangeCauseDeviceChange(String outStationId){
        logger.info(">>>materialChangeCauseDeviceChange outStationId:{} ",outStationId);
        List<Record> recordList = Db.find(" SELECT  m.entry_id as innerStationId , m.entry_id as outStationId,m.id as innerDeviceId ,m.id as outDeviceId ,s.material_brand as brand , " +
                " m.`name` as name,m.spec as mods,m.sn as sn  ,m.nbq_sn as nbqSn,m.barcode as barCode,m.`status` as status " +
                " from  crm_plan_material_entry m " +
                " LEFT JOIN crm_customer_entry e on e.id = m.entry_id " +
                " LEFT JOIN crm_supply_material s on s.id = m.material_id " +
                " where m.entry_id = ? and  m.type = '逆变器' ", outStationId);
        List<NhDevice> nhDeviceList = new ArrayList<>();
        for (Record record1 : recordList) {
            //采集器
            NhDevice nhDevice = NHTask.initNhDevice(record1);
            nhDevice.setType(2);
            nhDevice.setName("通讯棒");
            nhDeviceList.add(nhDevice);
            //逆变器
            NhDevice nhDevice2 = NHTask.initNhDevice(record1);
            nhDevice2.setType(1);
            String nbqSn = record1.getStr("nbqSn");
            String sn = record1.getStr("sn");
            String deviceId = nbqSn+sn;
            if (deviceId.length() > 32){
                deviceId = deviceId.substring(0,32);
            }
            nhDevice2.setInnerDeviceId(deviceId);
            nhDevice2.setOutDeviceId(deviceId);
            nhDevice2.setSn(nbqSn);
            nhDeviceList.add(nhDevice2);
        }
        //更新设备
        List<Map<String,Object>> list=new ArrayList<>();
        for (NhDevice device : nhDeviceList) {
            Map<String,Object> body=new HashMap<>();
            body.put("innerStationId",device.getInnerStationId());
            body.put("innerDeviceId",device.getInnerDeviceId());
            body.put("outStationId",device.getOutStationId());
            body.put("outDeviceId",device.getOutDeviceId());
            body.put("brand",device.getBrand());
            body.put("type",device.getType());
            body.put("name",device.getName());
            body.put("mods",device.getMods());
            body.put("sn",device.getSn());
            body.put("barCode",device.getBarCode());
            body.put("warrantyFlag",device.getWarrantyFlag());
            body.put("warrantyExpires",device.getWarrantyExpires());
            body.put("staus",device.getStatus());
            list.add(body);
        }
        String url = YWConstants.url+YWConstants.materialChangeUrl;
        String result = YWUtils.request2(url, list);
        String status = "1";
        Map parse=(Map) JSONObject.parse(result);
        if(parse.containsKey("code") && parse.containsKey("data")){
            if("200".equals(String.valueOf(parse.get("code")))){
                status = "0";
            }
        }
        if (list.size()==0){
            status = "1";
        }
        saveSysRecord(outStationId, url, new Gson().toJson(list), result, status, "1","3");
    }


    /**
     * 获取近三天发电量
     * @param id
     * @return
     */
    public ThreeDaysPowerVo getThreeDaysPower(String id){
        ThreeDaysPowerVo vo =new ThreeDaysPowerVo();
        Map<String,String> map = new HashMap<>();
        map.put("innerStationId",id);
        map.put("days","3");
        String host = YWConstants.url;
        String path = YWConstants.stationLastDaysEnergyUrl;
        String result = YWUtils.requestForGet(host,path,map);
        if (com.sifang.modules.sunshine.SystemSetting.utils.StringUtil.isNotBlank(result)){
            Map parse=(Map) com.alibaba.fastjson.JSONObject.parse(result);
            if(parse.containsKey("code") && parse.containsKey("data")){
                if("200".equals(String.valueOf(parse.get("code")))  && !"{}".equals(parse.get("data").toString())){
                    List<EnergyDataVo> list = JSONArray.parseArray(parse.get("data").toString(), EnergyDataVo.class);
                    vo.setFirstDay(list.get(0).getDay());
                    vo.setFirstDayElectric(list.get(0).getEnergy());
                    vo.setSecondDay(list.get(1).getDay());
                    vo.setSecondDayElectric(list.get(1).getEnergy());
                    vo.setThirdlyDay(list.get(2).getDay());
                    vo.setThirdlyDayElectric(list.get(2).getEnergy());
                }
            }
        }
        return vo;
    }

    /**
     * 获取电站实时数据
     */
    public PowerStationVo getStationRealTimeInfo(String id){
        Map<String,String> body=new HashMap<>();
        body.put("innerStationId",id);
        String host = YWConstants.url;
        String path = YWConstants.stationRealTimeInfoUrl;
        String result = YWUtils.requestForGet(host,path, body);
        PowerStationVo vo = new PowerStationVo();
        if (StringUtil.isNotBlank(result)){
            Map parse=(Map) JSONObject.parse(result);
            if(parse.containsKey("code") && parse.containsKey("data")){
                if("200".equals(String.valueOf(parse.get("code"))) &&   parse.get("data") != null ){
                    Map map = (Map)JSONObject.parseObject(String.valueOf(parse.get("data")));
                    vo.setInnerStationId(String.valueOf(map.get("innerStationId")));
                    vo.setOutStationId(String.valueOf(map.get("outStationId")));
                    vo.setStationName(String.valueOf(map.get("stationName")));
                    vo.setCapacity(String.valueOf(map.get("capacity")));
                    vo.setPower(String.valueOf(map.get("power")));
                    vo.setPac(String.valueOf(map.get("pac")));
                    vo.setType(String.valueOf(map.get("type")));
                    vo.setEtd(String.valueOf(map.get("etd")));
                    vo.setEtm(String.valueOf(map.get("etm")));
                    vo.setEty(String.valueOf(map.get("ety")));
                    vo.setEta(String.valueOf(map.get("eta")));
                    vo.setFullHour(String.valueOf(map.get("fullHour")));
                    vo.setState(String.valueOf(map.get("state")));
                    vo.setSyncTime(String.valueOf(map.get("syncTime")));
                    vo.setFisGenerateTime(String.valueOf(map.get("fisGenerateTime")));
                    OverviewStaticDataVo overviewVo = JSONObject.parseObject(String.valueOf(map.get("overviewVo")), OverviewStaticDataVo.class);
                    vo.setOverviewStaticData(overviewVo);
                }
            }
        }
        return vo;
    }

    /**
     * 发电趋势图数据
     * @param innerStationId 内部电站id
     * @param type 类型 day按日 week 最近七天 month按月 year按年
     * @param time 时间 day:2024-06-22 week 不用 month 2024-06 year 2024
     */
    public Map<String, Object>  getPowerGenerationTrends(String innerStationId,String type ,String time){
        Map<String,String> body=new HashMap<>();
        body.put("innerStationId",innerStationId);
        body.put("type",type);
        body.put("time",time);
        String host = YWConstants.url;
        String path = YWConstants.stationEnergyTrendUrl;
        String result = YWUtils.requestForGet(host,path, body);
        Map<String, Object> map = new HashMap<>();
        if (StringUtil.isNotBlank(result)){
            Map parse=(Map) com.alibaba.fastjson.JSONObject.parse(result);
            if(parse.containsKey("code") && parse.containsKey("data")){
                if("200".equals(String.valueOf(parse.get("code"))) && parse.get("data")!=null){
                    Object data = parse.get("data");
                    Map parse1=(Map) com.alibaba.fastjson.JSONObject.parse(data.toString());
                    List<String> XStr = JSONObject.parseArray(parse1.get("XStr").toString(), String.class);
                    List<Object> fdlY = JSONObject.parseArray(parse1.get("fdlY").toString(), Object.class);
                    map.put("XStr", XStr);
                    map.put("fdlY", fdlY);
                }
            }
        }
        return map;
    }

    //新系统广发存量电站客户信息推送
    @Transactional(rollbackFor = Exception.class)
    public Result customerEntryPush(String id,Operator operator){
        CustomerEntry entry = customerDao.get(id);
        CrmCustomerIncomingApplication application = incomingApplicationDao.getIncomingApplication(entry);
        String numberQZ = CustomerEntryUtil.getJJPrefix(entry.getPartnerId());
        application.setPartnersContractNumber(numberQZ + DateUtils.getNowDate().getTime() + RandomUtil.getPositiveRandomWithRang(2));
        if("20".equals(application.getTenantStatus() ) || "30".equals(application.getTenantStatus()) || "60".equals(application.getTenantStatus())){
            throw new IllegalArgumentException("当前电站状态不可推送电站客户信息");
        }
        //推送客户信息
        Map map = inputCustomerEntry(entry);
        if (map == null){
            throw  new IllegalArgumentException("推送失败");
        }
        entry.setApplyStatus("25");
        application.setTenantStatus("20");//客户信息推送状态
        application.setStatus("25");//整个进件状态
        application.setInputPieceId(map.get("inputPieceId").toString());
        application.setApplyTime(new Date());
        application.setPartnerId(entry.getPartnerId());
        incomingApplicationDao.save(application);
        customerDao.save(entry);
        msgService.saveCustomerEntryMsg(operator, entry.getId(), CustomerEntryConstants.GDF_HISTORY_ENTRY,"推送电站客户信息","");
        return Result.ok();
    }
    //新系统广发存量电站客户信息推送接口
    public Map inputCustomerEntry(CustomerEntry entry){
        Map<String,Object> maps= Maps.newHashMap();
        //进件信息
        Map<String,String> project = Maps.newHashMap();
        project.put("epcTenantCode","2006300");
        project.put("projectOrgCode",entry.getManagementType());//项目公司编码
        project.put("stationNo",entry.getPowerStationCode());
        maps.put("projectModule",project);
        //业主信息
        Map<String,Object> customerModule = Maps.newHashMap();
        Map<String,Object> info = Maps.newHashMap();
        info.put("customerType",entry.getTenantType());
        info.put("customerName",entry.getTenantName());
        info.put("idType","ID_CARD");
        info.put("customerIdCard",entry.getIdCode());
        info.put("customerPhone",entry.getMobile());
        info.put("address",entry.getProvince()+entry.getCity()+entry.getArea()+entry.getAddress());
        customerModule.put("customerBaseInfo",info);
        maps.put("customerModule",customerModule);
        //附件信息
        List<Map<String,String>> list = Lists.newArrayList();
        Map<String,String> file = Maps.newHashMap();
        file.put("code","BS_0_20");
        file.put("url",commonStaticImgPath+entry.getIdCardFront());
        list.add(file);
        Map<String,String> file2 = Maps.newHashMap();
        file2.put("code","BS_0_10");
        file2.put("url",commonStaticImgPath+entry.getIdCardBack());
        list.add(file2);
        Map<String,String> file3 = Maps.newHashMap();
        file3.put("code","BS_0_620");
        file3.put("url",commonStaticImgPath+entry.getBankCard());
        list.add(file3);
        maps.put("fileModule",list);//附件信息
        maps.put("partner","nenghui");
        maps.put("capital","03");
        logger.info("inputCustomerEntry 请求参数:{}",new Gson().toJson(maps));
        String url = ZfConstants.url+ZfConstants.stockEntryPushUrl;
        String result = YWUtils.request(url, maps);
        Map parse=(Map) JSONObject.parse(result);
        logger.info("inputCustomerEntry result ====  :{}",parse);
        if(parse.containsKey("code") && parse.containsKey("data")){
            if("200".equals(String.valueOf(parse.get("code")))){
                Object data =  parse.get("data");
                Map damap = (Map) JSONObject.parse(String.valueOf(data));
                CrmYxIncomingProcessDao.addIncomingProcess(entry.getId(),"1","20","0","0","推送");
                return damap;
            }else {
                CrmYxIncomingProcessDao.addIncomingProcess(entry.getId(),"1",null,"1",null,null);
                throw new IllegalArgumentException("推送失败:"+ parse.get("msg"));
            }
        }
        return null;
    }

    //新系统广发存量电站电站档案推送
    @Transactional(rollbackFor = Exception.class)
    public Result inputCustomerEntryInfo(String id,Operator operator){
        CustomerEntry entry = customerDao.get(id);
        CrmCustomerIncomingApplication application = incomingApplicationDao.getByEntryId(id);
        if (application == null){
            throw new IllegalArgumentException("进件信息不存在");
        }
        if (!"30".equals(application.getTenantStatus())){
            throw new IllegalArgumentException("客户信息未审核通过");
        }
        if("20".equals(application.getProjectStatus() ) || "30".equals(application.getProjectStatus()) || "60".equals(application.getProjectStatus())){
            throw new IllegalArgumentException("当前电站状态不可推送电站档案信息");
        }
        //推送电站信息
        try {
            customerEntryInputPiece(id);
        }catch (Exception e){
            e.printStackTrace();
            throw new IllegalArgumentException("推送失败："+e.getMessage());
        }
        entry.setApplyStatus("28");
        application.setProjectStatus("20");//电站档案状态
        application.setStatus("28");//整个进件状态
        application.setUpdateTime(new Date());
        customerDao.save(entry);
        incomingApplicationDao.save(application);
        msgService.saveCustomerEntryMsg(operator, entry.getId(), CustomerEntryConstants.GDF_HISTORY_ENTRY_INFO,"推送电站档案信息","");
        return Result.ok();
    }
    //新系统广发存量电站电站信息推送接口
    public  void customerEntryInputPiece(String id){
        CustomerEntry entry = customerDao.get(id);
        CrmCustomerIncomingApplication application = incomingApplicationDao.getByEntryId(id);
        if (application == null){
            throw new IllegalArgumentException("进件信息不存在");
        }
        ProjectCompanySettings companySettings = projectCompanySettingsDao.get(entry.getProjectCompanyId());
        CustomerEntrySurveyRecord surveyRecord = surveyRecordDao.findOneByEntryId(entry.getId());
        CrmAcceptingReport acceptingReport = reportDao.get(entry.getReceivingReportId());
        Map<String,Object> maps= Maps.newHashMap();
        //进件信息
        Map<String,String> project = Maps.newHashMap();
        project.put("inputPieceId",application.getInputPieceId());
        project.put("stationType","1");
        project.put("businessType","10");
        project.put("feecollectType","3");
        project.put("filingType","2");
        project.put("productCode",entry.getProjectCode());//产品编号
        maps.put("projectModule",project);
        //合同信息
        Map<String,Object> contractModule = Maps.newHashMap();
        contractModule.put("firstParty",entry.getTenantName());
        contractModule.put("secondPartyCode",entry.getManagementType());//项目公司编码
        //签署时间按上传合同时间来
        contractModule.put("createTime",acceptingReport.getSignDate());//创建时间
        contractModule.put("signDate",acceptingReport.getSignDate());//签署时间
        contractModule.put("signState","20");
        contractModule.put("contractState","10");
        contractModule.put("accountName",entry.getBankName());
        contractModule.put("accountNum",entry.getBankCode());
        contractModule.put("openBank",entry.getTssBankNumName());
        //签约方信息
        List<Map<String,Object>> signatoryInfoList = Lists.newArrayList();
        Map<String,Object> signatoryInfo = Maps.newHashMap();
        signatoryInfo.put("signatoryType","FIRST_PARTY");
        signatoryInfo.put("signatoryName",entry.getTenantName());
        signatoryInfo.put("certificateType","ID_CARD");
        signatoryInfo.put("certificateNo",entry.getIdCode());
        signatoryInfo.put("phone",entry.getMobile());
        signatoryInfo.put("address",entry.getProvince()+entry.getCity()+entry.getArea()+entry.getAddress());
        signatoryInfoList.add(signatoryInfo);
        Map<String,Object> jia = Maps.newHashMap();
        jia.put("signatoryType","SECOND_PARTY");
        jia.put("certificateType","BUSINESS_LICENSE");
        jia.put("signatoryName",entry.getProjectCompanyName());
        jia.put("certificateNo",entry.getManagementType());
        jia.put("phone",companySettings.getTelephone());
        jia.put("address",companySettings.getProvince()+companySettings.getCity()+companySettings.getArea()+companySettings.getAddress());
        signatoryInfoList.add(jia);
        contractModule.put("signatoryInfo",signatoryInfoList);
        //租金分享规则
        List<Map<String,Object>> shareRuleInfoList = Lists.newArrayList();
        Map<String,Object> shareRuleInfo = Maps.newHashMap();
        shareRuleInfo.put("beginYear",1);
        shareRuleInfo.put("endYear",25);
        shareRuleInfo.put("unitPrice","20");
        shareRuleInfoList.add(shareRuleInfo);
        contractModule.put("shareRuleInfo",shareRuleInfoList);
        maps.put("contractModule",contractModule);
        //动态勘察模块
        Map<String,Object> dyncProspectModule2 = Maps.newHashMap();
        //1.基本信息
//        List<Map<String,Object>> baseInfo = new ArrayList<>();
        Map<String,Object> baseInfo = Maps.newHashMap();
        String longitude = "";
        String latitude = "";
        if(entry.getLongitude() == null || entry.getLatitude() == null){
            String address = entry.getProvince()+entry.getCity()+entry.getArea()+entry.getAddress();
            String lonLat = GaodeUtil.getLonLat(address);
            if(StringUtil.isNotBlank(lonLat)){
                String[] split = lonLat.split(",");
                longitude = split[0];
                latitude = split[1];
            }
        }else {
            longitude = entry.getLongitude().stripTrailingZeros().toPlainString();
            latitude = entry.getLatitude().stripTrailingZeros().toPlainString();
        }
        //东经
        baseInfo.put("longitude",longitude);
        //北纬
        baseInfo.put("latitude",latitude);
        //屋顶类型
        baseInfo.put("roofType","flat_roof");
        //周边遮挡物
        baseInfo.put("perimeterBarrier","无");
        //房屋整体情况
        baseInfo.put("buildingWhole","普通农民房");
        //房屋建造年限(年)
        baseInfo.put("buildingLife",surveyRecord.getCompletionYear());
        //距离并网接入点的距离(m)
        baseInfo.put("distanceGridAccessPoint",surveyRecord.getDistance());
        dyncProspectModule2.put("baseInfo",baseInfo);
        //2.屋顶信息
        Map<String,Object> roofTypeInfo = Maps.newHashMap();
        List<Map<String,Object>> listMap = Lists.newArrayList();
        //屋顶层数

        //屋顶高度
        Map<String,Object> roofTypeInfo2 = Maps.newHashMap();
        roofTypeInfo2.put("flatRoofHeight",surveyRecord.getBuildingHeight());
        //房屋偏向 houseDeviation
        String building_head = sysCapitalDictDao.getDictValue("03", "angle_azimuth", surveyRecord.getAzimuth());
        String buildingHeadValue = "";
        if("正西".equals(building_head)){
            buildingHeadValue="west";
        }else if("东偏南".equals(building_head)){
            buildingHeadValue="east_by_south";
        }else if("南偏西".equals(building_head)){
            buildingHeadValue="south_by_west";
        }else if("北偏西".equals(building_head)){
            buildingHeadValue="north_by_west";
        }else if("西偏南".equals(building_head)){
            buildingHeadValue="west_by_south";
        }else if("东偏北".equals(building_head)){
            buildingHeadValue="east_by_north";
        }else if("北偏东".equals(building_head)){
            buildingHeadValue="north_by_east";
        }else if("西偏北".equals(building_head)){
            buildingHeadValue="west_by_north";
        }else if("南偏东".equals(building_head)){
            buildingHeadValue="south_by_east";
        }else if("正南".equals(building_head)){
            buildingHeadValue="south";
        }else if("正北".equals(building_head)){
            buildingHeadValue="north";
        }else if("正东".equals(building_head)){
            buildingHeadValue="east";
        }else{
            buildingHeadValue="south_by_west";
        }
        roofTypeInfo2.put("houseDeviation",buildingHeadValue);
        //方位角 flatAzimuthAngle
        String angle = surveyRecord.getAngle();
        if (StringUtil.isNotBlank(angle)){
            roofTypeInfo2.put("flatAzimuthAngle", angle);
        }else {
            roofTypeInfo2.put("flatAzimuthAngle", "90");
        }
        //东西长
        roofTypeInfo2.put("flatEwLength",surveyRecord.getEwLength());
        //南北宽
        roofTypeInfo2.put("flatNsWide",surveyRecord.getNsWide());
        //屋面防水层
        roofTypeInfo2.put("flatRoofWaterproofer","刚性防水");
        //屋面板类型 flatRoofFaceType
        roofTypeInfo2.put("flatRoofFaceType","现浇板");
        //屋面板厚度(mm)

        //保温层
        roofTypeInfo2.put("flatInsulatingLayer","混凝土");
        //保温层厚度

        //底座固定形式
        roofTypeInfo2.put("flatBaseFixedForm","膨胀螺旋栓");
        listMap.add(roofTypeInfo2);
        roofTypeInfo.put("flat_roof",listMap);
        dyncProspectModule2.put("roofTypeInfo",roofTypeInfo);
        maps.put("dyncProspectModule2",dyncProspectModule2);

        //设计信息
        Map<String,Object> designModule = Maps.newHashMap();
        List<Map<String,Object>> designBaseInfo = Lists.newArrayList();
        List<Record> components =  customerEntryComponentDao.findByEntryId2(entry.getId());
        Integer moduleCount = 0;
        String modulePower = "";
        String moduleModel = "";
        for (Record component : components) {
            moduleCount = component.getInt("num");
            modulePower = component.getStr("model");
            moduleModel = component.getStr("material_model");
        }
        Map<String,Object> design = Maps.newHashMap();
        //设计方案信息
        Record plan = planService.getPlanById(entry.getSchemeId());
        String designType = "";
        if(plan!=null){
            designType = plan.getStr("plan_type");
        }else{
            designType = entry.getSchemeTypeName();
        }
        if ("单坡阳光棚".equals(designType)){
            designType = "single_sun_shed";
        } else if ("人字坡阵列式".equals(designType)) {
            designType = "herringbone_array";
        } else if ("单坡阵列式".equals(designType)) {
            designType = "single_array_type";
        } else if ("人字坡阳光棚".equals(designType)) {
            designType = "herringbone_sun_shed";
        } else if ("双坡阳光栅".equals(designType)) {
            designType = "double_slope_sun_grating";
        } else if ("阳光棚".equals(designType)) {
            designType = "sun_shed";
        }else if ("庭院".equals(designType)) {
            designType = "courtyard";
        }else {
            designType = "sun_shed";
        }
        design.put("designType",designType);
        design.put("moduleCount",moduleCount);//组件数量
        design.put("designVolume",entry.getDesignCapacity());//设计容量
        designBaseInfo.add(design);
        designModule.put("designBaseInfo",designBaseInfo);

        List<Map<String,Object>> moduleInfo = Lists.newArrayList();
        Map<String,Object> moinfo = Maps.newHashMap();
        moinfo.put("moduleGlassType","double_wave");//single_wave:单坡  double_wave:双坡
        moinfo.put("batteryParam","n_type");//p_type \n_type
        moinfo.put("modulePower",modulePower);
        moinfo.put("moduleModel",moduleModel);
        moinfo.put("moduleCount",moduleCount);
        moduleInfo.add(moinfo);
        designModule.put("moduleInfo",moduleInfo);
        maps.put("designModule",designModule);
        //电站收益卡
        Map<String,Object> accountModule = Maps.newHashMap();
        accountModule.put("openBank",entry.getTssBankNumName());
        accountModule.put("accountName",entry.getBankName());
        accountModule.put("accountNum",entry.getBankCode());
        maps.put("accountModule",accountModule);
        //建设信息模块
        Map<String,Object> buildModule = Maps.newHashMap();
        buildModule.put("completeDate",DateUtils.formatDate(entry.getInstallTime(),"yyyyMMdd"));//完工日期
        buildModule.put("installCapacity",entry.getActualCapacity());//装机容量（W）
        maps.put("buildModule",buildModule);
        //7、完工设备模块
        Map<String,Object> deviceModule = Maps.newHashMap();
        List<Map<String,Object>> inverterInfo = Lists.newArrayList();
        //获取逆变器信息
        List<Record> rds = planMaterialEntryDao.findInverterByEntryId(entry.getId());
        for(Record nb :rds){
            Map<String,Object> info = Maps.newHashMap();
            String brand = nb.getStr("brand");
            if ("爱士惟".equals(brand)){
                brand="asw";
            }else if ("固德威".equals(brand)){
                brand="gdw";
            }else if ("锦浪".equals(brand)){
                brand="ginlong";
            }else if ("华为".equals(brand)){
                brand="huawei";
            }else if ("上能".equals(brand)){
                brand="sineng";
            }else if ("科华".equals(brand)){
                brand="kehua";
            }
            info.put("inverterBrand", brand);
            info.put("inverterSpec",nb.getStr("material_model"));//逆变器型号
            String spec = nb.getStr("spec");
            if (spec.contains("KW")){
                spec = spec.substring(0,spec.indexOf("KW"));
            }
            int inverterPower = Integer.parseInt(spec) * 1000;
            info.put("inverterPower", String.valueOf(inverterPower));
            List<Map<String,Object>> inverterSerialNumberInfo = Lists.newArrayList();
            Map<String,Object> numinfo = Maps.newHashMap();
            numinfo.put("inverterSerialNumber",nb.getStr("nbq_sn"));//逆变器序列号
            numinfo.put("collectorSerialNumber",nb.getStr("sn"));//采集器序列号
            inverterSerialNumberInfo.add(numinfo);
            info.put("inverterSerialNumberInfo",inverterSerialNumberInfo);
            inverterInfo.add(info);
        }
        deviceModule.put("inverterInfo",inverterInfo);
        List<Map<String,Object>> moduleInfo1 = Lists.newArrayList();
        List<Record> zjrds = planMaterialEntryDao.findModuleByEntryId(entry.getId());
        // 组件品牌
        Map<String, String> componentMap = PartnerBrandUtils.getBrandList("3", PartnerConstants.PARTNER_ID_GF);
        if(zjrds.size()>0){
            Record zjq = zjrds.get(0);
            Map<String,Object> info1 = Maps.newHashMap();
            info1.put("completeVolume",entry.getActualCapacity());//完工容量(W)
            String zjbrand = "";
            if (componentMap.containsKey(zjq.getStr("brand"))) {
                // 获取广发的品牌名称
                zjbrand = componentMap.get(zjq.getStr("brand"));
            }
            if("正泰".equals(zjbrand)){
                zjbrand="chnt";
            }else if("晶澳太阳能".equals(zjbrand)){
                zjbrand="ja";
            }else if("天合光能".equals(zjbrand)){
                zjbrand="tianh";
            }else if("英利能源".equals(zjbrand)){
                zjbrand="yl";
            }else if("晶科".equals(zjbrand)){
                zjbrand="jk";
            }else if("环晟".equals(zjbrand)){
                zjbrand="huansheng";
            }else if("一道".equals(zjbrand)){
                zjbrand="dasolar";
            }else if("东方日升".equals(zjbrand)){
                zjbrand="risen";
            }
            info1.put("moduleBrand",  zjbrand);//组件品牌

            info1.put("moduleGlassType","double_wave");//组件玻型
            info1.put("batteryParam","n_type");//电池参数
            info1.put("modulePower",zjq.getStr("spec"));//组件功率
            info1.put("moduleModel",zjq.getStr("model"));//组件型号
            List<Map<String,Object>> listinfo = Lists.newArrayList();
            for(Record zja:zjrds){
                Map<String,Object> zj = Maps.newHashMap();
                zj.put("serialNumber",zja.getStr("barcode"));
                listinfo.add(zj);
            }
            info1.put("moduleSerialNumberInfo",listinfo);//组件序列号信息
            moduleInfo1.add(info1);
        }
        deviceModule.put("moduleInfo",moduleInfo1);
        maps.put("deviceModule",deviceModule);
        //并网模块
        Map<String,Object> mergeGirdModule = Maps.newHashMap();
        mergeGirdModule.put("stationName",CrmUtils.getStationName(entry));//平台方进件名称
        mergeGirdModule.put("voltageLevel",surveyRecord.getVoltageClasses());//电压等级
        mergeGirdModule.put("mergeType","20");//并网类型
        mergeGirdModule.put("feecollectType","3");//电费归集方式
        mergeGirdModule.put("accountNum",entry.getGeneratorNo());//发电户号
        mergeGirdModule.put("effectiveFirstDate",entry.getFirstGenerationTime());//首日发电日期
        mergeGirdModule.put("checkTime",entry.getCheckAcceptTime());//并网审核日期
        mergeGirdModule.put("mergeCapacity",entry.getActualCapacity());//并网容量
        mergeGirdModule.put("countryCode","46");//国家
        Record province = customerDao.getProvinceCode(entry.getProvince());
        mergeGirdModule.put("provinceCode",province.getLong("regionalism_code")+"000000");
        Record city = customerDao.getCityCode(entry.getCity(),province.getLong("ProvinceID"));
        mergeGirdModule.put("cityCode",city.getLong("regionalism_code")+"000000");
        mergeGirdModule.put("areaCode",customerDao.getDistrictCode(entry.getArea(),city.getLong("CityID"))+"000000");
        mergeGirdModule.put("townCode","0");
        mergeGirdModule.put("detailAddress",entry.getAddress());//详细地址
        mergeGirdModule.put("longitude",entry.getLongitude()==null?longitude:entry.getLongitude());//经度
        mergeGirdModule.put("latitude",entry.getLatitude()==null?latitude:entry.getLatitude());//纬度
        maps.put("mergeGirdModule",mergeGirdModule);
        //9、并网方案
        List<Map<String,Object>> mergeDesignModule = Lists.newArrayList();
        Map<String,Object> merge = Maps.newHashMap();
        merge.put("designType",designType);
        merge.put("moduleCount",moduleCount);//并网组件数量
        merge.put("mergeVolume",entry.getActualCapacity());//并网容量(W)
        mergeDesignModule.add(merge);
        maps.put("mergeDesignModule",mergeDesignModule);
        //10、保险信息
        List<CrmCustomerIncomingApplicationInsurance> insurancesList = insuranceDao.getByEntryIds(entry.getId());
        List<Map<String,Object>> insuranceModule = Lists.newArrayList();
        for (CrmCustomerIncomingApplicationInsurance insurance : insurancesList) {
            Map<String,Object> insu = Maps.newHashMap();
            String insuranceNumber = insurance.getInsuranceNumber();
            insu.put("insuranceNumber",insuranceNumber);//保险单号
//            insu.put("insuranceType",insurance.getInsuranceType());
            if ("1".equals(insurance.getInsuranceType())){
                insu.put("insuranceType","1");//险种类型
            }else {
                insu.put("insuranceType","2");
            }
            insuranceModule.add(insu);
        }
        maps.put("insuranceModule",insuranceModule);
        //11、节点时间
        Map<String,Object> nodeTimeModule = Maps.newHashMap();
        nodeTimeModule.put("businessStartTime",application.getApplyTime().getTime());//商机完成时间
        nodeTimeModule.put("businessEndTime",application.getApplyTime().getTime());//商机审核完成时间
        nodeTimeModule.put("firstStartTime",entry.getExamineTime().getTime());//合规完成时间--首次进件时间
        nodeTimeModule.put("firstEndTime",entry.getExamineTime().getTime());//合规审核完成时间
        nodeTimeModule.put("completeStartTime",entry.getInstallTime().getTime());//过程完成时间
        nodeTimeModule.put("completeEndTime",entry.getInstallAcceptTime().getTime());//过程审核完成时间
        nodeTimeModule.put("mergeStartTime",entry.getMergeTime().getTime());//并网完成时间
        nodeTimeModule.put("mergeEndTime",entry.getCheckAcceptTime().getTime());//并网审核完成时间
        maps.put("nodeTimeModule",nodeTimeModule);
        //附件信息
        List<Map<String,Object>> list = Lists.newArrayList();
        String roof_photo_one = surveyRecord.getRoofPhotoOne();
        if(StringUtil.isNotBlank(roof_photo_one)) {
            for (String one : roof_photo_one.split(",")) {
                if (StringUtil.isNotBlank(one)) {
                    Map<String, Object> file = Maps.newHashMap();//房屋屋顶照片
                    file.put("code", "FR_200020_100");
                    file.put("url", commonStaticImgPath+one);
                    list.add(file);
                }
            }
        }
        String roof_photo_two = surveyRecord.getRoofPhotoTwo();
        if(StringUtil.isNotBlank(roof_photo_two)){
            for(String two :roof_photo_two.split(",")) {
                Map<String,Object> fileq = Maps.newHashMap();//房屋屋顶东侧图片
                fileq.put("code","GZFZFR_200020_1130");
                fileq.put("url",commonStaticImgPath+two);
                list.add(fileq);
            }
        }
        String roof_photo_four = surveyRecord.getRoofPhotoFour();
        if(StringUtil.isNotBlank(roof_photo_four)) {
            for (String four : roof_photo_four.split(",")) {
                Map<String, Object> fileq = Maps.newHashMap();//房屋屋顶南侧图片
                fileq.put("code", "GZFZFR_200020_111");
                fileq.put("url", commonStaticImgPath+four);
                list.add(fileq);
            }
        }
        String roof_photo_three = surveyRecord.getRoofPhotoThree();
        if(StringUtil.isNotBlank(roof_photo_three)) {
            for (String three : roof_photo_three.split(",")) {
                Map<String, Object> fileq = Maps.newHashMap();//房屋屋顶西侧图片
                fileq.put("code", "GZFZFR_200020_112");
                fileq.put("url", commonStaticImgPath+three);
                list.add(fileq);
            }
        }
        String cturls = surveyRecord.getSurveyFiles();
        if(StringUtil.isNotBlank(cturls)){
            for(String cturl :cturls.split(",")){
                Map<String,Object> file4 = Maps.newHashMap();//户用勘察记录表（附平面草图）
                file4.put("code","GZFZFR_200020_1140");
                file4.put("url",commonStaticImgPath+cturl);
                list.add(file4);
            }
        }
        String house_ownership = surveyRecord.getHouseOwnership();
        if(StringUtil.isNotBlank(house_ownership)) {
            for (String three : house_ownership.split(",")) {
                Map<String, Object> file5 = Maps.newHashMap();//房产证（或房产证明文件）
                file5.put("code", "BS_0_30");
                file5.put("url", commonStaticImgPath+three);
                list.add(file5);
            }
        }
        String design_drawings = entry.getDesignDrawings();
        if(StringUtil.isNotBlank(design_drawings)){
            for(String dra : design_drawings.split(",")){
                Map<String,Object> file6 = Maps.newHashMap();//附件：设计CAD文件
                file6.put("code","GZFZFR_200020_1170");
                file6.put("url",commonStaticImgPath+dra);
                list.add(file6);
            }
        }
        String insuranceFiles = "";//工程安装一切险
        String zj_report = "";//并网调试报告
        for (CrmCustomerIncomingApplicationInsurance insurance : insurancesList) {
            if("工程安装一切险".equals(insurance.getInsuranceName())){
                insuranceFiles = insurance.getInsurancePolicy();
                zj_report = insurance.getBwtsFile();
            }
        }
        if (StringUtil.isNotBlank(insuranceFiles)) {
            for (String ins : insuranceFiles.split(",")) {
                Map<String, Object> file7 = Maps.newHashMap();//工程安装一切险
                file7.put("code", "GZFZCP_200020_170");
                file7.put("url", commonStaticImgPath+ins);
                list.add(file7);
            }
        }
        String zjmp = acceptingReport.getZjPlateImg();
        if(StringUtil.isNotBlank(zjmp)){
            for(String zj :zjmp.split(",")){
                Map<String,Object> file8 = Maps.newHashMap();//组件铭牌照片
                file8.put("code","GZFZCP_200020_3790");
                file8.put("url",commonStaticImgPath+zj);
                list.add(file8);
            }
        }
        String zjfs = acceptingReport.getComponentImg3();
        if(StringUtil.isNotBlank(zjfs)) {
            for (String zjf : zjfs.split(",")) {
                Map<String, Object> file9 = Maps.newHashMap();//组件俯视图
                file9.put("code", "GZFZCP_200020_3815");
                file9.put("url", commonStaticImgPath+zjf);
                list.add(file9);
            }
        }
        String bnqaz = acceptingReport.getDcImgs();
        if(StringUtil.isNotBlank(bnqaz)) {
            for (String zjf : bnqaz.split(",")) {
                Map<String, Object> file11 = Maps.newHashMap();//逆变器安装图-整体外观及走线及采集器（离地高度）
                file11.put("code", "GZFZCP_200020_3820");
                file11.put("url", commonStaticImgPath+zjf);
                list.add(file11);
            }
        }
        String nbamp = acceptingReport.getNbqPlateImg();
        if(StringUtil.isNotBlank(nbamp)){
            for(String nbq :nbamp.split(",")) {
                Map<String, Object> file12 = Maps.newHashMap();//逆变器安装图-铭牌
                file12.put("code", "GZFZCP_200020_3830");
                file12.put("url", commonStaticImgPath+nbq);
                list.add(file12);
            }
        }

        String nbqzt = acceptingReport.getNbqZbImg();
        if(StringUtil.isNotBlank(nbqzt)) {
            for (String nbq : nbqzt.split(",")) {
                Map<String, Object> file16 = Maps.newHashMap();//并网箱安装图-外观及走线（离地高度）
                file16.put("code", "GZFZCP_200020_3880");
                file16.put("url", commonStaticImgPath+nbq);
                list.add(file16);
            }
        }
        String bwxn = acceptingReport.getBwInnerImg();
        if(StringUtil.isNotBlank(bwxn)) {
            for (String bwx : bwxn.split(",")) {
                Map<String, Object> file17 = Maps.newHashMap();//并网箱安装图-并网箱内部全景
                file17.put("code", "GZFZCP_200020_3890");
                file17.put("url", commonStaticImgPath+bwx);
                list.add(file17);
            }
        }
        String bwJdImg = acceptingReport.getBwJdImg();
        if(StringUtil.isNotBlank(bwJdImg)) {
            for (String bwjd : bwJdImg.split(",")) {
                Map<String, Object> file18 = Maps.newHashMap();//并网箱安装图-接地情况
                file18.put("code", "GZFZCP_200020_3920");
                file18.put("url", commonStaticImgPath+bwjd);
                list.add(file18);
            }
        }
        String zjzt = acceptingReport.getZjImg8();
        if(StringUtil.isNotBlank(zjzt)) {
            for (String zj : zjzt.split(",")) {
                Map<String, Object> file17 = Maps.newHashMap();//支架结构图-支架方阵（东向西完工照）
                file17.put("code", "GZFZCP_200020_3980");
                file17.put("url", commonStaticImgPath+zj);
                list.add(file17);
            }
        }
        String zjImg9 = acceptingReport.getZjImg9();
        if(StringUtil.isNotBlank(zjImg9)) {
            for (String zj : zjImg9.split(",")) {
                Map<String, Object> file17 = Maps.newHashMap();//支架结构图-支架方阵（北向南完工照)
                file17.put("code", "GZFZCP_200020_3990");
                file17.put("url", commonStaticImgPath+zj);
                list.add(file17);
            }
        }
        String zjImg4 = acceptingReport.getZjImg4();
        if(StringUtil.isNotBlank(zjImg4)) {
            for (String zj : zjImg4.split(",")) {
                Map<String, Object> file17 = Maps.newHashMap();//支架结构图-立柱东西间距、南北间距（带尺寸）
                file17.put("code", "GZFZCP_200020_4000");
                file17.put("url", commonStaticImgPath+zj);
                list.add(file17);
            }
        }
        String zjImg11 = acceptingReport.getZjImg11();
        if(StringUtil.isNotBlank(zjImg11)) {
            for (String zj : zjImg11.split(",")) {
                Map<String, Object> file17 = Maps.newHashMap();//支架结构图-柱脚防水完工图
                file17.put("code", "GZFZCP_200020_4020");
                file17.put("url", commonStaticImgPath+zj);
                list.add(file17);
            }
        }
        String zjImg12 = acceptingReport.getZjImg12();
        if(StringUtil.isNotBlank(zjImg12)) {
            for (String zj : zjImg12.split(",")) {
                Map<String, Object> file17 = Maps.newHashMap();//支架结构图-斜梁悬挑（南）
                file17.put("code", "GZFZCP_200020_4030");
                file17.put("url", commonStaticImgPath+zj);
                list.add(file17);
            }
        }

        String zjImg13 = acceptingReport.getZjImg13();
        if(StringUtil.isNotBlank(zjImg13)) {
            for (String zj : zjImg13.split(",")) {
                Map<String, Object> file17 = Maps.newHashMap();//支架结构图-斜梁悬挑（北）
                file17.put("code", "GZFZCP_200020_4040");
                file17.put("url", commonStaticImgPath+zj);
                list.add(file17);
            }
        }
        String zjImg14 = acceptingReport.getZjImg14();
        if(StringUtil.isNotBlank(zjImg14)) {
            for (String zj : zjImg14.split(",")) {
                Map<String, Object> file17 = Maps.newHashMap();//支架结构图-斜梁悬挑（东）
                file17.put("code", "GZFZCP_200020_4050");
                file17.put("url", commonStaticImgPath+zj);
                list.add(file17);
            }
        }
        String zjImg15 = acceptingReport.getZjImg15();
        if(StringUtil.isNotBlank(zjImg15)) {
            for (String zj : zjImg15.split(",")) {
                Map<String, Object> file17 = Maps.newHashMap();//支架结构图-斜梁悬挑（西）
                file17.put("code", "GZFZCP_200020_4060");
                file17.put("url", commonStaticImgPath+zj);
                list.add(file17);
            }
        }
        String jdImg4 = acceptingReport.getJdImg4();
        if(StringUtil.isNotBlank(jdImg4)) {
            for (String zj : jdImg4.split(",")) {
                Map<String, Object> file17 = Maps.newHashMap();//支架接地图-支架接地
                file17.put("code", "GZFZCP_200020_4090");
                file17.put("url", commonStaticImgPath+zj);
                list.add(file17);
            }
        }
        String bkImg1 = acceptingReport.getBkImg1();
        if(StringUtil.isNotBlank(bkImg1)) {
            for (String zj : bkImg1.split(",")) {
                Map<String, Object> file17 = Maps.newHashMap();//边框接地图-边框与边框接地
                file17.put("code", "GZFZCP_200020_4100");
                file17.put("url", commonStaticImgPath+zj);
                list.add(file17);
            }
        }
        String componentImg1 = acceptingReport.getComponentImg1();
        if(StringUtil.isNotBlank(componentImg1)) {
            for (String zj : componentImg1.split(",")) {
                Map<String, Object> file17 = Maps.newHashMap();//边框接地图-组件安装倾角
                file17.put("code", "GZFZCP_200020_4110");
                file17.put("url", commonStaticImgPath+zj);
                list.add(file17);
            }
        }

        String bkImg2 = acceptingReport.getBkImg2();
        if(StringUtil.isNotBlank(bkImg2)) {
            for (String zj : bkImg2.split(",")) {
                Map<String, Object> file17 = Maps.newHashMap();//边框接地图-边框与支架接地
                file17.put("code", "GZFZCP_200020_4120");
                file17.put("url", commonStaticImgPath+zj);
                list.add(file17);
            }
        }
        String ykImg1 = acceptingReport.getYkImg1();
        if(StringUtil.isNotBlank(ykImg1)) {
            for (String zj : ykImg1.split(",")) {
                Map<String, Object> file17 = Maps.newHashMap();//压块或背压板照片
                file17.put("code", "GZFZCP_200020_4150");
                file17.put("url", commonStaticImgPath+zj);
                list.add(file17);
            }
        }
        String xlzx = acceptingReport.getFixOtherImg();
        if(StringUtil.isNotBlank(xlzx)) {
            for (String xl : xlzx.split(",")) {
                Map<String, Object> file17 = Maps.newHashMap();//线缆走向（屋顶、下墙）、线缆保护管（或桥架）敷设及固定照片
                file17.put("code", "GZFZCP_200020_4160");
                file17.put("url", commonStaticImgPath+xl);
                list.add(file17);
            }
        }

        String zjjdj = acceptingReport.getJdImg8();
        if(StringUtil.isNotBlank(zjjdj)) {
            for (String xl : zjjdj.split(",")) {
                Map<String, Object> file2a = Maps.newHashMap();//接地极图-并网箱、逆变器安装接地极
                file2a.put("code", "GZFZCP_200020_4200");
                file2a.put("url", commonStaticImgPath+xl);
                list.add(file2a);
            }
        }

        String jdImg5 = acceptingReport.getJdImg5();
        if(StringUtil.isNotBlank(jdImg5)) {
            for (String xl : jdImg5.split(",")) {
                Map<String, Object> file2s = Maps.newHashMap();//接地极图-支架接地电阻阻值
                file2s.put("code", "GZFZCP_200020_4210");
                file2s.put("url", commonStaticImgPath+xl);
                list.add(file2s);
            }
        }

        String jdImg9 = acceptingReport.getJdImg9();
        if(StringUtil.isNotBlank(jdImg9)) {
            for (String xl : jdImg9.split(",")) {
                Map<String, Object> file2d = Maps.newHashMap();//接地极图-并网箱、逆变器安装接地电阻阻值
                file2d.put("code", "GZFZCP_200020_4220");
                file2d.put("url", commonStaticImgPath+xl);
                list.add(file2d);
            }
        }

        String jdImg12 = acceptingReport.getJdImg12();
        if(StringUtil.isNotBlank(jdImg12)) {
            for (String xl : jdImg12.split(",")) {
                Map<String, Object> file2d = Maps.newHashMap();//接地极图-并网箱、逆变器安装接地电阻测量照片
                file2d.put("code", "GZFZCP_200020_4250");
                file2d.put("url", commonStaticImgPath+xl);
                list.add(file2d);
            }
        }

        String fsImg1 = acceptingReport.getFsImg1();
        if(StringUtil.isNotBlank(fsImg1)) {
            for (String xl : fsImg1.split(",")) {
                Map<String, Object> file2d = Maps.newHashMap();//防水措施图-横竖向水槽
                file2d.put("code", "GZFZCP_200020_4260");
                file2d.put("url", commonStaticImgPath + xl);
                list.add(file2d);
            }
        }
        String fsImg2 = acceptingReport.getFsImg2();
        if(StringUtil.isNotBlank(fsImg2)) {
            for (String xl : fsImg2.split(",")) {
                Map<String, Object> file2d = Maps.newHashMap();//防水措施图-落水管走向及其固定
                file2d.put("code", "GZFZCP_200020_4290");
                file2d.put("url", commonStaticImgPath + xl);
                list.add(file2d);
            }
        }
        String fsImg3 = acceptingReport.getFsImg3();
        if(StringUtil.isNotBlank(fsImg3)) {
            for (String xl : fsImg3.split(",")) {
                Map<String, Object> file2d = Maps.newHashMap();//防水措施图-其他图片
                file2d.put("code", "GZFZCP_200020_4300");
                file2d.put("url", commonStaticImgPath + xl);
                list.add(file2d);
            }
        }

        String filingDocumentPhoto = surveyRecord.getFilingDocumentPhoto();
        if(StringUtil.isNotBlank(filingDocumentPhoto)) {
            for (String xl : filingDocumentPhoto.split(",")) {
                Map<String, Object> file26 = Maps.newHashMap();//项目公司备案证
                file26.put("code", "MG_200020_600");
                file26.put("url", commonStaticImgPath + xl);
                list.add(file26);
            }
        }
        String power_capacity_url = acceptingReport.getPowerCapacityUrl();
        if(StringUtil.isNotBlank(power_capacity_url)){
            for(String xl :power_capacity_url.split(",")) {
                Map<String, Object> file27 = Maps.newHashMap();//三天连续发电量监控系统截图
                file27.put("code", "MG_200020_310");
                file27.put("url", commonStaticImgPath+xl);
                list.add(file27);
            }
        }
        if(StringUtil.isNotBlank(zj_report)) {
            for (String xl : zj_report.split(",")) {
                Map<String, Object> file28 = Maps.newHashMap();//验收报告
                file28.put("code", "MG_200020_330");
                file28.put("url", commonStaticImgPath + xl);
                list.add(file28);
            }
        }

        String fix_conclusion = entry.getContract();
        if(StringUtil.isNotBlank(fix_conclusion)) {
            for (String xl : fix_conclusion.split(",")) {
                Map<String, Object> file29 = Maps.newHashMap();//购售电合同
                file29.put("code", "MG_200020_320");
                file29.put("url", commonStaticImgPath + xl);
                list.add(file29);
            }
        }
        String dbxImgs = acceptingReport.getDbxImgs();
        if(StringUtil.isNotBlank(dbxImgs)) {
            for (String xl : dbxImgs.split(",")) {
                Map<String, Object> file30 = Maps.newHashMap();//电表箱图片
                file30.put("code", "MG_200020_340");
                file30.put("url", commonStaticImgPath+xl);
                list.add(file30);
            }
        }
        String db_imgs = acceptingReport.getDbImgs();
        if(StringUtil.isNotBlank(db_imgs)) {
            for (String xl : db_imgs.split(",")) {
                Map<String, Object> file31 = Maps.newHashMap();//电表照片
                file31.put("code", "GZFZMG_200020_312");
                file31.put("url", commonStaticImgPath+xl);
                list.add(file31);
            }
        }
        String contractUrl = acceptingReport.getContractUrl();
        if(StringUtil.isNotBlank(contractUrl)) {
            for (String xl : contractUrl.split(",")) {
                Map<String, Object> file32 = Maps.newHashMap();//纸质合同
                file32.put("code", "2290");
                file32.put("url", commonStaticImgPath+xl);
                list.add(file32);
            }
        }

//        String supplement_url = filerd.getStr("supplement_url");
//        if(StringUtil.isNotBlank(supplement_url)){
//            for(String xl :supplement_url.split(",")) {
//                Map<String, Object> file32 = Maps.newHashMap();//补充证明材料20240807：荷载报告、接入方案，并网意见单等
//                file32.put("code", "2207");
//                file32.put("url", xl);
//                list.add(file32);
//            }
//        }
        maps.put("fileModule",list);//附件信息
        maps.put("partner","nenghui");
        maps.put("capital","03");
        String url = ZfConstants.url+ZfConstants.stockEntryUrl;
        logger.info("customerEntryInputPiece  请求参数：{}  url:{}",new Gson().toJson(maps),url);
        String result = YWUtils.request(url, maps);
        Map parse=(Map) JSONObject.parse(result);
        logger.info("customerEntryInputPiece 返回结果：{}",result);
        if("200".equals(String.valueOf(parse.get("code")))){
            CrmYxIncomingProcessDao.addIncomingProcess(entry.getId(),"2","20","0","0","推送");
        }else {
            CrmYxIncomingProcessDao.addIncomingProcess(entry.getId(),"2",null,"1",null,null);
            throw new IllegalArgumentException("推送失败："+parse.get("msg").toString());
        }
    }

    /**
     * 存量数据-客户信息推送
    */
    public void stockEntryPush(String id ){
        SqlBuilder sql = new SqlBuilder();
        sql.line("select id,power_station_code,tenant_name,mobile,id_code,id_card_front,id_card_back,bank_card, concat(province, city, area, address) as customeraddress " +
                "from crm_customer_entry_stock where id = ?",id);
        List<Record> lists = Db.find(sql.build(),sql.params());
        for(Record rd:lists){
            //获取所有未推送的电站客户信息
            Map<String,Object> maps= Maps.newHashMap();
            Map<String,String> project = Maps.newHashMap();
            project.put("epcTenantCode","2006300");//生产
            project.put("projectOrgCode","ORG202407240001");
           // project.put("epcTenantCode","ORG202405230001");
           // project.put("projectOrgCode","ORG202405230002");
            project.put("stationNo",rd.getStr("power_station_code"));
            maps.put("projectModule",project);//进件信息

            Map<String,Object> customerModule = Maps.newHashMap();
            Map<String,Object> info = Maps.newHashMap();
            info.put("customerType","1");
            info.put("customerName",rd.getStr("tenant_name"));
            info.put("idType","ID_CARD");
            info.put("customerIdCard",rd.getStr("id_code"));
            info.put("customerPhone",rd.getStr("mobile"));
            info.put("address",rd.getStr("customeraddress"));

            customerModule.put("customerBaseInfo",info);

            maps.put("customerModule",customerModule);//业主信息
            List<Map<String,String>> list = Lists.newArrayList();
            Map<String,String> file = Maps.newHashMap();
            file.put("code","BS_0_20");
            file.put("url",rd.getStr("id_card_front"));
            list.add(file);
            Map<String,String> file2 = Maps.newHashMap();
            file2.put("code","BS_0_10");
            file2.put("url",rd.getStr("id_card_back"));
            list.add(file2);
            Map<String,String> file3 = Maps.newHashMap();
            file3.put("code","BS_0_620");
            file3.put("url",rd.getStr("bank_card"));
            list.add(file3);
            maps.put("fileModule",list);//附件信息
            maps.put("partner","nenghui");
            maps.put("capital","03");
            System.out.println("stockEntryPush----"+new Gson().toJson(maps));
            String url = ZfConstants.url+ZfConstants.stockEntryPushUrl;
            String result = YWUtils.request(url, maps);
            Map parse=(Map) JSONObject.parse(result);
            logger.info("parse====  :{}",parse);
            //{"code":200,"success":true,"data":{"inputPieceId":"ORG202405230001202407240001","stationNo":"D2404260011943"},"msg":"操作成功"}
            if(parse.containsKey("code") && parse.containsKey("data")){
                if("200".equals(String.valueOf(parse.get("code")))){
                  Object data =  parse.get("data");
                  Map damap = (Map) JSONObject.parse(String.valueOf(data));
                  Db.update("DELETE from crm_gf_stock_entry where entry_id=?",rd.getStr("id"));
                    String addsql = "INSERT INTO crm_gf_stock_entry(entry_id,input_piece_id,customer_state,station_state) VALUES(?,?,?,?)";
                    Db.update(addsql,rd.getStr("id"),damap.get("inputPieceId"),"20","10");

                }else {
                    throw new IllegalArgumentException("推送失败:"+ parse.get("msg"));
                }
            }
        }
    }
    public static void main(String[] args) {
        String dssd ="https://pv.nhet.cloud/oss/nen";

        System.out.println(dssd.lastIndexOf("."));

/*
        Map<String,Object> maps= Maps.newHashMap();

        Map<String,String> project = Maps.newHashMap();
        project.put("inputPieceId","ORG202405230001202407260001");
        project.put("stationType","1");
        project.put("businessType","10");
        project.put("feecollectType","3");
        project.put("filingType","2");
        project.put("productCode","PROD202405230001");
        maps.put("projectModule",project);//进件信息

        List<Map<String,Object>> listMap = Lists.newArrayList();
        Map<String,Object> dync = Maps.newHashMap();
        dync.put("code","buildingWhole");
        dync.put("value","普通农民房");
        listMap.add(dync);
        Map<String,Object> dync1 = Maps.newHashMap();
        dync1.put("code","buildingFloors");
        dync1.put("value","1");
        listMap.add(dync1);
        Map<String,Object> dync2 = Maps.newHashMap();
        dync2.put("code","roofHeight");
        dync2.put("value","4");
        listMap.add(dync2);
        Map<String,Object> dync3 = Maps.newHashMap();
        dync3.put("code","houseDeviation");
        dync3.put("value","south_by_west");
        listMap.add(dync3);
        Map<String,Object> dync4 = Maps.newHashMap();
        dync4.put("code","buildingLife");
        dync4.put("value","2024");
        listMap.add(dync4);
        Map<String,Object> dync5 = Maps.newHashMap();
        dync5.put("code","latitude");//北纬
        dync5.put("value","24.958797");
        listMap.add(dync5);
        Map<String,Object> dync6 = Maps.newHashMap();
        dync6.put("code","longitude");//经度
        dync6.put("value","113.417043");
        listMap.add(dync6);
        Map<String,Object> dync7 = Maps.newHashMap();
        dync7.put("code","roofFaceBarrier");//经度
        dync7.put("value","无");
        listMap.add(dync7);
        Map<String,Object> dync8 = Maps.newHashMap();
        dync8.put("code","houseLeadInLength");//经度
        dync8.put("value","80");
        listMap.add(dync8);
        Map<String,Object> dync9 = Maps.newHashMap();
        dync9.put("code","roofWaterproofer");//
        dync9.put("value","刚性防水");
        listMap.add(dync9);
        Map<String,Object> dynca = Maps.newHashMap();
        dynca.put("code","roofFaceType");//
        dynca.put("value","现浇板");
        listMap.add(dynca);
        Map<String,Object> dyncq = Maps.newHashMap();
        dyncq.put("code","insulatingLayerType");//
        dyncq.put("value","混凝土面层");
        listMap.add(dyncq);
        Map<String,Object> dyncc = Maps.newHashMap();
        dyncc.put("code","baseFixedForm");//
        dyncc.put("value","膨胀螺栓");
        listMap.add(dyncc);

        maps.put("dyncProspectModule",listMap);

        //设计信息
        Map<String,Object> designModule = Maps.newHashMap();
        List<Map<String,Object>> designBaseInfo = Lists.newArrayList();
        Map<String,Object> design = Maps.newHashMap();
        design.put("designType","single_sun_shed");
        design.put("moduleCount",60);
        design.put("designVolume",33000);
        designBaseInfo.add(design);
        designModule.put("designBaseInfo",designBaseInfo);
        List<Map<String,Object>> moduleInfo = Lists.newArrayList();
        Map<String,Object> moinfo = Maps.newHashMap();
        moinfo.put("moduleGlassType","single_wave");
        moinfo.put("batteryParam","n_type");
        moinfo.put("modulePower","550");
        moinfo.put("moduleModel","60");
        moinfo.put("moduleCount","60");
        moduleInfo.add(moinfo);
        designModule.put("moduleInfo",moduleInfo);
        maps.put("designModule",designModule);

        //电站收益卡
        Map<String,Object> accountModule = Maps.newHashMap();
        accountModule.put("openBank","广东农村信用社韶关市乳源县桂头营业所");
        accountModule.put("accountName","施桂芬");
        accountModule.put("accountNum","6217281884000496431");
        maps.put("accountModule",accountModule);

        //建设信息模块
        Map<String,Object> buildModule = Maps.newHashMap();
        buildModule.put("completeDate","20240415");//完工日期
        buildModule.put("installCapacity","33000");//装机容量（W）
        maps.put("buildModule",buildModule);
        //7、完工设备模块
        Map<String,Object> deviceModule = Maps.newHashMap();
        List<Map<String,Object>> inverterInfo = Lists.newArrayList();
        Map<String,Object> info = Maps.newHashMap();
        info.put("inverterBrand","asw");
        info.put("inverterSpec","80KW");//逆变器型号
        info.put("inverterPower","80");
        List<Map<String,Object>> inverterSerialNumberInfo = Lists.newArrayList();
        Map<String,Object> numinfo = Maps.newHashMap();
        numinfo.put("inverterSerialNumber","4025KDTX244G0307");//逆变器序列号
        numinfo.put("collectorSerialNumber","A980908342C86006156");//采集器序列号
        inverterSerialNumberInfo.add(numinfo);
        info.put("inverterSerialNumberInfo",inverterSerialNumberInfo);
        inverterInfo.add(info);
        deviceModule.put("inverterInfo",inverterInfo);

        List<Map<String,Object>> moduleInfo1 = Lists.newArrayList();
        Map<String,Object> info1 = Maps.newHashMap();
        info1.put("completeVolume","33000");//完工容量(W)
        info1.put("moduleBrand","ats");//组件品牌
        info1.put("moduleGlassType","single_wave");//组件玻型
        info1.put("batteryParam","n_type");//电池参数
        info1.put("modulePower","550");//组件功率
        info1.put("moduleModel","60");//组件型号
        List<Map<String,Object>> listinfo = Lists.newArrayList();
        for(int i=0;i<60;i++){
            Map<String,Object> zj = Maps.newHashMap();
            zj.put("serialNumber","A980908342C8600100"+i);
            listinfo.add(zj);
        }
        info1.put("moduleSerialNumberInfo",listinfo);//组件序列号信息
        moduleInfo1.add(info1);

        deviceModule.put("moduleInfo",moduleInfo1);
        maps.put("deviceModule",deviceModule);

        //并网模块
        Map<String,Object> mergeGirdModule = Maps.newHashMap();
        mergeGirdModule.put("stationName","施桂芬的光伏电站");//平台方进件名称
        mergeGirdModule.put("voltageLevel","380");//电压等级
        mergeGirdModule.put("mergeType","20");//并网类型
        mergeGirdModule.put("feecollectType","3");//电费归集方式
        mergeGirdModule.put("accountNum","03591DY0000000231457423");//发电户号
        mergeGirdModule.put("effectiveFirstDate","1718380800000");//首日发电日期
        mergeGirdModule.put("checkTime","1718380800000");//并网审核日期
        mergeGirdModule.put("mergeCapacity","33000");//并网容量
        mergeGirdModule.put("countryCode","46");//国家
        mergeGirdModule.put("provinceCode","440000");//省
        mergeGirdModule.put("cityCode","440200000000");//市
        mergeGirdModule.put("areaCode","440232000000");//区
        mergeGirdModule.put("townCode","0");
        mergeGirdModule.put("detailAddress","桂头镇大坝村151号");//详细地址
        mergeGirdModule.put("longitude","113.417043");//经度
        mergeGirdModule.put("latitude","24.958797");//纬度
        maps.put("mergeGirdModule",mergeGirdModule);

        //9、并网方案
        List<Map<String,Object>> mergeDesignModule = Lists.newArrayList();
        Map<String,Object> merge = Maps.newHashMap();
        merge.put("designType","single_sun_shed");//设计方案
        merge.put("mergeVolume","33000");//并网容量(W)
        mergeDesignModule.add(merge);
        maps.put("mergeDesignModule",mergeDesignModule);

        //11、节点时间
        Map<String,Object> nodeTimeModule = Maps.newHashMap();
        nodeTimeModule.put("businessStartTime","1714093230000");//商机完成时间
        nodeTimeModule.put("businessEndTime","1714104030000");//商机审核完成时间
        nodeTimeModule.put("firstStartTime","1714190430000");//合规完成时间--首次进件时间
        nodeTimeModule.put("firstEndTime","1714197810000");//合规审核完成时间
        nodeTimeModule.put("completeStartTime","1714205010000");//过程完成时间
        nodeTimeModule.put("completeEndTime","1714291410000");//过程审核完成时间
        nodeTimeModule.put("mergeStartTime","1714291410000");//并网完成时间
        nodeTimeModule.put("mergeEndTime","1714291410000");//并网审核完成时间

        maps.put("nodeTimeModule",nodeTimeModule);

        //获取附件信息
    *//*    Record filerd = Db.findFirst("select * from crm_accepting_report_stock id=?");
        if(filerd== null){
            throw  new IllegalArgumentException("附件为空");
        }*//*

        List<Map<String,Object>> list = Lists.newArrayList();
        Map<String,Object> file = Maps.newHashMap();//房屋屋顶照片
        file.put("code","FR_200020_100");
        file.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663664265759.jpg");
        list.add(file);

        Map<String,Object> file2 = Maps.newHashMap();//房屋屋顶东侧图片
        file2.put("code","GZFZFR_200020_1130");
        file2.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file2);
        Map<String,Object> file1 = Maps.newHashMap();//房屋屋顶南侧图片
        file1.put("code","GZFZFR_200020_111");
        file1.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file1);
        Map<String,Object> file3 = Maps.newHashMap();//房屋屋顶西侧图片
        file3.put("code","GZFZFR_200020_112");
        file3.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file3);
        Map<String,Object> fileq = Maps.newHashMap();//房屋周边照片（4张，4个方位角）
        fileq.put("code","FR_200020_90");
        fileq.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(fileq);
        Map<String,Object> file4 = Maps.newHashMap();//户用勘察记录表（附平面草图）
        file4.put("code","GZFZFR_200020_1140");
        file4.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file4);
        Map<String,Object> file5 = Maps.newHashMap();//房产证（或房产证明文件）
        file5.put("code","BS_0_30");
        file5.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file5);

        Map<String,Object> file6 = Maps.newHashMap();//附件：设计CAD文件
        file6.put("code","GZFZFR_200020_1170");
        file6.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file6);


        Map<String,Object> file7 = Maps.newHashMap();//工程安装一切险
        file7.put("code","GZFZCP_200020_170");
        file7.put("url","https://nhet.oss-cn-shanghai.aliyuncs.com/energy_img/pdf/20240726/14cbb9aca5ec419ea6b1c61d0233c265/177df18b8bfe85163b2483bc40485cbe_97a0e79076e2ce526958c582c58c0bbe_8_85c1e.pdf");
        list.add(file7);
        Map<String,Object> file7a = Maps.newHashMap();//工程安装一切险
        file7a.put("code","GZFZCP_200020_170");
        file7a.put("url","https://nhet.oss-cn-shanghai.aliyuncs.com/energy_img/pdf/20240726/add979ed57654400ac6a114b20ff27db/8b829231e8ad999346d442791c856e52_da8bea8825bc6ef850aa578b36aa91d4_8_cbd5e.pdf");
        list.add(file7a);

        Map<String,Object> file81 = Maps.newHashMap();//支架类
        file81.put("code","GZFZCP_200020_3980");
        file81.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file81);
        Map<String,Object> file8w = Maps.newHashMap();//支架类
        file8w.put("code","GZFZCP_200020_4090");
        file8w.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file8w);

        Map<String,Object> file8 = Maps.newHashMap();//组件铭牌照片
        file8.put("code","GZFZCP_200020_3790");
        file8.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file8);
        Map<String,Object> file9 = Maps.newHashMap();//组件俯视图

        file9.put("code","GZFZCP_200020_3815");
        file9.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file9);


        Map<String,Object> file11 = Maps.newHashMap();//逆变器安装图-整体外观及走线及采集器（离地高度）
        file11.put("code","GZFZCP_200020_3820");
        file11.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file11);
        Map<String,Object> file12 = Maps.newHashMap();//逆变器安装图-铭牌

        file12.put("code","GZFZCP_200020_3830");
        file12.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file12);
        Map<String,Object> file13 = Maps.newHashMap();//逆变器安装图-接地情况

        file13.put("code","GZFZCP_200020_3840");
        file13.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file13);
        Map<String,Object> file14 = Maps.newHashMap();//逆变器安装图-逆变器直流侧

        file14.put("code","GZFZCP_200020_3850");
        file14.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file14);
        Map<String,Object> file15 = Maps.newHashMap();//逆变器安装图-组串开路电压照片
        file15.put("code","GZFZCP_200020_3860");
        file15.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file15);
        Map<String,Object> file16 = Maps.newHashMap();//并网箱安装图-外观及走线（离地高度）
        file16.put("code","GZFZCP_200020_3880");
        file16.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file16);
        Map<String,Object> file17 = Maps.newHashMap();//并网箱安装图-并网箱内部全景
        file17.put("code","GZFZCP_200020_3890");
        file17.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file17);

        Map<String,Object> file18 = Maps.newHashMap();//并网箱安装图-接地情况
        file18.put("code","GZFZCP_200020_3920");
        file18.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file18);

        Map<String,Object> file19 = Maps.newHashMap();//线缆走向（屋顶、下墙）、线缆保护管（或桥架）敷设及固定照片
        file19.put("code","GZFZCP_200020_4160");
        file19.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file19);




        Map<String,Object> file2a = Maps.newHashMap();//接地极图
        file2a.put("code","GZFZCP_200020_4200");
        file2a.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file2a);
        Map<String,Object> file2s = Maps.newHashMap();//接地极图
        file2s.put("code","GZFZCP_200020_4210");
        file2s.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file2s);
        Map<String,Object> file2d = Maps.newHashMap();//接地极图
        file2d.put("code","GZFZCP_200020_4220");
        file2d.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file2d);
        Map<String,Object> file2f = Maps.newHashMap();//接地极图
        file2f.put("code","GZFZCP_200020_4230");
        file2f.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file2f);
        Map<String,Object> file2g = Maps.newHashMap();//接地极图
        file2g.put("code","GZFZCP_200020_4240");
        file2g.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file2g);
        Map<String,Object> file2h = Maps.newHashMap();//接地极图
        file2h.put("code","GZFZCP_200020_4250");
        file2h.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file2h);



        Map<String,Object> file23 = Maps.newHashMap();//防水措施图-横向水槽

        file23.put("code","GZFZCP_200020_4260");
        file23.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file23);

        Map<String,Object> file24 = Maps.newHashMap();//防水措施图-竖向水槽

        file24.put("code","GZFZCP_200020_4270");
        file24.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file24);

        Map<String,Object> file25 = Maps.newHashMap();//防水措施图-落水管走向及其固定

        file25.put("code","GZFZCP_200020_4290");
        file25.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file25);

        Map<String,Object> file26 = Maps.newHashMap();//项目公司备案证

        file26.put("code","MG_200020_600");
        file26.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file26);
        Map<String,Object> file27 = Maps.newHashMap();//三天连续发电量监控系统截图

        file27.put("code","MG_200020_310");
        file27.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file27);
        Map<String,Object> file28 = Maps.newHashMap();//验收报告

        file28.put("code","MG_200020_330");
        file28.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file28);
        Map<String,Object> file29 = Maps.newHashMap();//购售电合同

        file29.put("code","MG_200020_320");
        file29.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file29);
        Map<String,Object> file30 = Maps.newHashMap();//电表箱图片

        file30.put("code","MG_200020_340");
        file30.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file30);
        Map<String,Object> file31 = Maps.newHashMap();//电表照片

        file31.put("code","GZFZMG_200020_312");
        file31.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file31);
        Map<String,Object> file32 = Maps.newHashMap();//纸质合同
        file32.put("code","2290");
        file32.put("url","https://pv.nhet.cloud/oss/nenghui/wx/fileupload/1663742621669.jpg");
        list.add(file32);

        maps.put("fileModule",list);//附件信息
        maps.put("partner","nenghui");
        maps.put("capital","03");
        String url = ZfConstants.url+ZfConstants.stockEntryUrl;
        String result = YWUtils.request(url, maps);
        Map parse=(Map) JSONObject.parse(result);
        System.out.println(parse);*/
    }
    public  void stockEntryStationInputPiece(String id){
        SqlBuilder sql = new SqlBuilder();
        sql.line("select s.*,g.input_piece_id from crm_customer_entry_stock s ");
        sql.line("left join crm_gf_stock_entry g on g.entry_id =s.id");
        sql.line("where  g.customer_state in('20','30','50','60')");
        if(StringUtil.isNotBlank(id)){
            sql.line("and s.id=?",id);
        }
        List<Record> listEntry = Db.find(sql.build(),sql.params());
        for(Record rd :listEntry){
            try {


        Map<String,Object> maps= Maps.newHashMap();

        Map<String,String> project = Maps.newHashMap();
        project.put("inputPieceId",rd.getStr("input_piece_id"));
        project.put("stationType","1");
        project.put("businessType","10");
        project.put("feecollectType","3");
        project.put("filingType","2");
        project.put("productCode",rd.getStr("project_id"));
       // project.put("productCode","PROD202405230001");//测试
        maps.put("projectModule",project);//进件信息
        Record sur = Db.findFirst("select * from crm_archive_survey_stock where archive_id=?",rd.getStr("id"));
        if(sur== null){
            throw  new IllegalArgumentException("勘测记录为空");
        }
            Map<String,Object> contractModule = Maps.newHashMap();
            contractModule.put("firstParty",rd.getStr("tenant_name"));
            contractModule.put("secondPartyCode",rd.getStr("management_type"));//项目公司编码
          //  contractModule.put("secondPartyCode","ORG202405230002"); //测试

            contractModule.put("createTime",rd.getDate("examine_time").getTime());
            contractModule.put("signDate",rd.getDate("examine_time").getTime());
            contractModule.put("signState","20");
            contractModule.put("contractState","10");
            contractModule.put("accountName",rd.getStr("tenant_name"));
            contractModule.put("accountNum",rd.getStr("bank_code"));
            contractModule.put("openBank",rd.getStr("bank_name"));
            List<Map<String,Object>> signatoryInfoList = Lists.newArrayList();
            Map<String,Object> signatoryInfo = Maps.newHashMap();
            signatoryInfo.put("signatoryType","FIRST_PARTY");
            signatoryInfo.put("signatoryName",rd.getStr("tenant_name"));
            signatoryInfo.put("certificateType","ID_CARD");
            signatoryInfo.put("certificateNo",rd.getStr("id_code"));
            signatoryInfo.put("phone",rd.getStr("mobile"));
            signatoryInfo.put("address",rd.getStr("province")+rd.getStr("city")+rd.getStr("area")+rd.getStr("address"));
            signatoryInfoList.add(signatoryInfo);

            Map<String,Object> jia = Maps.newHashMap();
            if("a3e11338c7fd4144af23b127c90ab97e".equals(rd.getStr("distributor_id"))){
                jia.put("signatoryType","SECOND_PARTY");
                jia.put("signatoryName","广州穗发能辉新能源有限公司");
                jia.put("certificateType","BUSINESS_LICENSE");
                jia.put("certificateNo","91440106MABT5BPU59");
                jia.put("phone","13432441160");
                jia.put("address","广东省广州市荔湾区东城街道新江东江街55号自编201号");
            }else if("9bc68444f3d44397a5c320d1be3c27cd".equals(rd.getStr("distributor_id"))){
                jia.put("signatoryType","SECOND_PARTY");
                jia.put("certificateType","BUSINESS_LICENSE");
                jia.put("signatoryName","罗山县穗发能辉新能源发展有限公司");
                jia.put("certificateNo","91411521MA9LLE4U6R");
                jia.put("phone","18538321816");
                jia.put("address","河南省信阳市罗山县楠杆镇消防站东侧门面1-2号");
            }else if("5ecd37a882cd4c12adfb605edc0c521e".equals(rd.getStr("distributor_id")) || "f2b0e54f34014d5796ce8370243736cb".equals(rd.getStr("distributor_id"))){
                jia.put("signatoryType","SECOND_PARTY");
                jia.put("certificateType","BUSINESS_LICENSE");
                jia.put("signatoryName","乐昌穗发新能源有限公司");
                jia.put("certificateNo","91440281MA55EHNT77");
                jia.put("phone","020-37850000");
                jia.put("address","广东省韶关市乐昌市乐昌产业转移工业园管委会后座1086号");
            }else if("069097259150497db48222b5a8773a3e".equals(rd.getStr("distributor_id"))){
                jia.put("signatoryType","SECOND_PARTY");
                jia.put("certificateType","BUSINESS_LICENSE");
                jia.put("signatoryName","新丰穗发丰光新能源有限公司");
                jia.put("certificateNo","91440233MABY8M0Q4J");
                jia.put("phone","13432441160");
                jia.put("address","广东省韶关市新丰县丰城街道群英路新城二街25号A栋3楼301号");
            }else if("115ba06f574f4b79b7cac27440b1bffe".equals(rd.getStr("distributor_id"))){
                jia.put("signatoryType","SECOND_PARTY");
                jia.put("certificateType","BUSINESS_LICENSE");
                jia.put("signatoryName","乳源穗发新能源有限公司");
                jia.put("certificateNo","91440232MACDMFE6X2");
                jia.put("phone","13432441160");
                jia.put("address","广东省韶关市乳源瑶族自治县乳城镇北环路13号广科乳源产业创新园众创空间大楼3楼302室");
            }
//            else if("9bc68444f3d44397a5c320d1be3c27cd".equals(rd.getStr("distributor_id"))){
//                jia.put("signatoryType","SECOND_PARTY");
//                jia.put("certificateType","BUSINESS_LICENSE");
//                jia.put("signatoryName","韶关广发光伏发电有限公司");
//                jia.put("certificateNo","91440203MA4X0UPA71");
//                jia.put("phone","13432441160");
//                jia.put("address","广东省广州市荔湾区东城街道新江东江街55号自编201号");
//            }

            signatoryInfoList.add(jia);

            contractModule.put("signatoryInfo",signatoryInfoList);
            List<Map<String,Object>> shareRuleInfoList = Lists.newArrayList();
            Map<String,Object> shareRuleInfo = Maps.newHashMap();
            if (rd.getDate("merge_time") == null){
                throw new IllegalArgumentException("并网日期为空!");
            }
            shareRuleInfo.put("beginYear",1);
            shareRuleInfo.put("endYear",25);
            shareRuleInfo.put("unitPrice","20");
            shareRuleInfoList.add(shareRuleInfo);
            contractModule.put("shareRuleInfo",shareRuleInfoList);

            maps.put("contractModule",contractModule);//

        Map<String,Object> dyncProspectModule2 = Maps.newHashMap();
        //1.基本信息
        Map<String,Object> baseInfo = Maps.newHashMap();
        String longitude = sur.getStr("longitude");
        String latitude = sur.getStr("latitude");
        if(StringUtil.isBlank(latitude) ||StringUtil.isBlank(longitude)){
            String address = rd.getStr("province")+rd.getStr("city")+rd.getStr("area")+rd.getStr("address");
            String lonLat = GaodeUtil.getLonLat(address);
            if(StringUtil.isNotBlank(lonLat)){
                String[] split = lonLat.split(",");
                longitude = split[0];
                latitude = split[1];
            }
        }
        //东经
        baseInfo.put("longitude",longitude);
        //北纬
        baseInfo.put("latitude",latitude);
        //屋顶类型
        baseInfo.put("roofType","flat_roof");
        //周边遮挡物
        baseInfo.put("perimeterBarrier","无");
        //房屋整体情况
        baseInfo.put("buildingWhole","普通农民房");
        //房屋建造年限(年)
        baseInfo.put("buildingLife",sur.getStr("house_build_year"));
        //距离并网接入点的距离(m)
        baseInfo.put("distanceGridAccessPoint",sur.getStr("power_box_distance"));
        dyncProspectModule2.put("baseInfo",baseInfo);
        //2.屋顶信息
        Map<String,Object> roofTypeInfo = Maps.newHashMap();
        List<Map<String,Object>> listMap = Lists.newArrayList();
        Map<String,Object> roofTypeInfo2 = Maps.newHashMap();
        //屋顶层数

        //屋顶高度
        roofTypeInfo2.put("flatRoofHeight",sur.getStr("build_high"));
        //房屋偏向 houseDeviation
        String building_head = sur.getStr("building_head");
        String buildingHeadValue = "";
        if("东偏南".equals(building_head)){
            buildingHeadValue="east_by_south";
        }else if("南偏西".equals(building_head)){
            buildingHeadValue="south_by_west";
        }else if("南偏东".equals(building_head)){
            buildingHeadValue="south_by_east";
        }else if("正南".equals(building_head)){
            buildingHeadValue="south";
        }else{
            buildingHeadValue="south_by_west";
        }
        roofTypeInfo2.put("houseDeviation",buildingHeadValue);
        //方位角 flatAzimuthAngle
        String angle = sur.getStr("zj_direc_degree");
        if (StringUtil.isNotBlank(angle)){
            roofTypeInfo2.put("flatAzimuthAngle", angle);
        }else {
            roofTypeInfo2.put("flatAzimuthAngle", "90");
        }
        //东西长

        //南北宽

        //屋面防水层
        String roof_waterproof_layer = sur.getStr("roof_waterproof_layer");
        if("0".equals(roof_waterproof_layer)){
            roof_waterproof_layer = "混凝土";
        }else if("1".equals(roof_waterproof_layer)){
            roof_waterproof_layer = "土层混凝土";
        }else if("2".equals(roof_waterproof_layer)){
            roof_waterproof_layer = "焦渣层混凝土";
        }else{
            roof_waterproof_layer = "其他";
        }
        roofTypeInfo2.put("flatRoofWaterproofer",roof_waterproof_layer);
        //屋面板类型 flatRoofFaceType
        roofTypeInfo2.put("flatRoofFaceType","现浇板");
        //屋面板厚度(mm)

        //保温层
        if (StringUtil.isNotBlank(sur.getStr("insulation_layer"))){
            roofTypeInfo2.put("flatInsulatingLayer",sur.getStr("insulation_layer"));
        }else {
            roofTypeInfo2.put("flatInsulatingLayer","混凝土");
        }
        //保温层厚度

        //底座固定形式
        if (StringUtil.isNotBlank(sur.getStr("advice_install_way"))){
            roofTypeInfo2.put("flatBaseFixedForm",sur.getStr("advice_install_way"));
        }else {
            roofTypeInfo2.put("flatBaseFixedForm","膨胀螺旋栓");
        }
        listMap.add(roofTypeInfo2);
        roofTypeInfo.put("flat_roof",listMap);
        dyncProspectModule2.put("roofTypeInfo",roofTypeInfo);
        maps.put("dyncProspectModule2",dyncProspectModule2);

        //获取附件信息
        Record filerd = Db.findFirst("select * from crm_accepting_report_stock where id=?",rd.getStr("id"));
        if(filerd== null){
           // continue;
             throw  new IllegalArgumentException("附件为空");
        }

        //设计信息
        Map<String,Object> designModule = Maps.newHashMap();
        List<Map<String,Object>> designBaseInfo = Lists.newArrayList();
        Map<String,Object> design = Maps.newHashMap();
        design.put("designType","single_sun_shed");
        design.put("moduleCount",filerd.getInt("component_num"));
        design.put("designVolume",rd.getBigDecimal("actual_capacity").multiply(new BigDecimal(1000)));
        designBaseInfo.add(design);
        designModule.put("designBaseInfo",designBaseInfo);
        List<Map<String,Object>> moduleInfo = Lists.newArrayList();
        Map<String,Object> moinfo = Maps.newHashMap();
        moinfo.put("moduleGlassType","single_wave");//single_wave:单坡  double_wave:双坡
        moinfo.put("batteryParam","p_type");//p_type \n_type
        moinfo.put("modulePower",filerd.getStr("component_spec"));
        moinfo.put("moduleModel",filerd.getStr("component_spec"));
        moinfo.put("moduleCount",filerd.getInt("component_num"));
        moduleInfo.add(moinfo);
        designModule.put("moduleInfo",moduleInfo);
        maps.put("designModule",designModule);

        //电站收益卡
        Map<String,Object> accountModule = Maps.newHashMap();
        accountModule.put("openBank",rd.getStr("bank_name"));
        accountModule.put("accountName",rd.getStr("tenant_name"));
        accountModule.put("accountNum",rd.getStr("bank_code"));
        maps.put("accountModule",accountModule);

        //建设信息模块
        Map<String,Object> buildModule = Maps.newHashMap();
        buildModule.put("completeDate",DateUtils.formatDate(rd.getDate("install_time"),"yyyyMMdd"));//完工日期
        buildModule.put("installCapacity",rd.getBigDecimal("actual_capacity").multiply(new BigDecimal(1000)));//装机容量（W）
        maps.put("buildModule",buildModule);
        //7、完工设备模块
        Map<String,Object> deviceModule = Maps.newHashMap();
        List<Map<String,Object>> inverterInfo = Lists.newArrayList();
        //获取逆变器信息
            List<Record> rds = Db.find("select * from crm_plan_material_entry_stock where type='逆变器' and status='0' and entry_id=?",rd.getStr("id"));
        for(Record nb :rds){
            Map<String,Object> info = Maps.newHashMap();
            info.put("inverterBrand",nb.getStr("brand"));
            info.put("inverterSpec",nb.getStr("name"));//逆变器型号
            info.put("inverterPower",nb.getStr("spec"));
            List<Map<String,Object>> inverterSerialNumberInfo = Lists.newArrayList();
            Map<String,Object> numinfo = Maps.newHashMap();
            numinfo.put("inverterSerialNumber",nb.getStr("nbq_sn"));//逆变器序列号
            numinfo.put("collectorSerialNumber",nb.getStr("sn"));//采集器序列号
            inverterSerialNumberInfo.add(numinfo);
            info.put("inverterSerialNumberInfo",inverterSerialNumberInfo);
            inverterInfo.add(info);
        }
            deviceModule.put("inverterInfo",inverterInfo);

        List<Map<String,Object>> moduleInfo1 = Lists.newArrayList();
        List<Record> zjrds = Db.find("select * from crm_plan_material_entry_stock where type='组件' and status='0' and entry_id=?",rd.getStr("id"));
        if(zjrds.size()>0){
            Record zjq = zjrds.get(0);
            Map<String,Object> info1 = Maps.newHashMap();
            info1.put("completeVolume",rd.getBigDecimal("actual_capacity").multiply(new BigDecimal(1000)));//完工容量(W)
            String zjbrand = zjq.getStr("brand");
            if("正泰".equals(zjbrand)){
                zjbrand="chnt";
            }else if("环晟".equals(zjbrand)){
                zjbrand="huansheng";
            }else if("英利".equals(zjbrand)){
                zjbrand="yl";
            }else if("东方日升".equals(zjbrand)){
                zjbrand="risen";
            }else if("一道".equals(zjbrand)){
                zjbrand="dasolar";
            }else if("晶科".equals(zjbrand)){
                zjbrand="jk";
            }else if("晶澳".equals(zjbrand)){
                zjbrand="ja";
            }else if("天合".equals(zjbrand)){
                zjbrand="tianh";
            }
            info1.put("moduleBrand",  zjbrand);//组件品牌

            info1.put("moduleGlassType","single_wave");//组件玻型
            info1.put("batteryParam","p_type");//电池参数
            info1.put("modulePower",zjq.getStr("spec"));//组件功率
            info1.put("moduleModel",zjq.getStr("spec"));//组件型号
            List<Map<String,Object>> listinfo = Lists.newArrayList();
            for(Record zja:zjrds){
                Map<String,Object> zj = Maps.newHashMap();
                zj.put("serialNumber",zja.getStr("barcode"));
                listinfo.add(zj);
            }
            info1.put("moduleSerialNumberInfo",listinfo);//组件序列号信息
            moduleInfo1.add(info1);
        }

        deviceModule.put("moduleInfo",moduleInfo1);

        maps.put("deviceModule",deviceModule);

        //并网模块
        Map<String,Object> mergeGirdModule = Maps.newHashMap();
        mergeGirdModule.put("stationName",rd.getStr("tenant_name")+"的光伏电站");//平台方进件名称
        mergeGirdModule.put("voltageLevel","380");//电压等级
        mergeGirdModule.put("mergeType","20");//并网类型
        mergeGirdModule.put("feecollectType","3");//电费归集方式
        mergeGirdModule.put("accountNum",rd.getStr("generator_no"));//发电户号
        if (rd.getDate("first_generation_time") == null){
            throw new RuntimeException("首日发电日期为空");
        }
        mergeGirdModule.put("effectiveFirstDate",rd.getDate("first_generation_time").getTime());//首日发电日期fggf
                if (rd.getDate("check_accept_time") == null){
                    throw new RuntimeException("并网审核日期为空");
                }
        mergeGirdModule.put("checkTime",rd.getDate("check_accept_time").getTime());//并网审核日期

        mergeGirdModule.put("mergeCapacity",rd.getBigDecimal("actual_capacity").multiply(new BigDecimal(1000)));//并网容量
        mergeGirdModule.put("countryCode","46");//国家
            Record province = customerDao.getProvinceCode(rd.getStr("province"));
            mergeGirdModule.put("provinceCode",province.getLong("regionalism_code")+"000000");
            Record city = customerDao.getCityCode(rd.getStr("city"),province.getLong("ProvinceID"));
            mergeGirdModule.put("cityCode",city.getLong("regionalism_code")+"000000");
            mergeGirdModule.put("areaCode",customerDao.getDistrictCode(rd.getStr("area"),city.getLong("CityID"))+"000000");

        mergeGirdModule.put("townCode","0");
        mergeGirdModule.put("detailAddress",rd.getStr("address"));//详细地址
        mergeGirdModule.put("longitude",rd.getBigDecimal("longitude")==null?longitude:rd.getBigDecimal("longitude"));//经度
        mergeGirdModule.put("latitude",rd.getBigDecimal("latitude")==null?latitude:rd.getBigDecimal("latitude"));//纬度
        maps.put("mergeGirdModule",mergeGirdModule);

        //9、并网方案
        List<Map<String,Object>> mergeDesignModule = Lists.newArrayList();
        Map<String,Object> merge = Maps.newHashMap();
        merge.put("designType","single_sun_shed");//设计方案
        merge.put("moduleCount",filerd.getInt("component_num"));//并网组件数量
        merge.put("mergeVolume",rd.getBigDecimal("actual_capacity").multiply(new BigDecimal(1000)));//并网容量(W)
        mergeDesignModule.add(merge);
        maps.put("mergeDesignModule",mergeDesignModule);

            //10、保险信息
        List<Map<String,Object>> insuranceModule = Lists.newArrayList();
        Map<String,Object> insu = Maps.newHashMap();
                String insuranceNumber = rd.getStr("insurance_number");
                if (StringUtil.isNotBlank(insuranceNumber)){
                    insu.put("insuranceNumber",insuranceNumber);//保险单号
                }else {
                    insu.put("insuranceNumber","10484003902051065570");//保险单号
                }
            insu.put("insuranceType","1");//险种类型
            insuranceModule.add(insu);
        maps.put("insuranceModule",insuranceModule);


            //11、节点时间
        Map<String,Object> nodeTimeModule = Maps.newHashMap();
        nodeTimeModule.put("businessStartTime",rd.getDate("pre_audit_time").getTime());//商机完成时间
        nodeTimeModule.put("businessEndTime",rd.getDate("pre_audit_time").getTime());//商机审核完成时间
        nodeTimeModule.put("firstStartTime",rd.getDate("examine_time").getTime());//合规完成时间--首次进件时间
        nodeTimeModule.put("firstEndTime",rd.getDate("examine_time").getTime());//合规审核完成时间
        nodeTimeModule.put("completeStartTime",rd.getDate("install_time").getTime());//过程完成时间
        nodeTimeModule.put("completeEndTime",rd.getDate("install_accept_time").getTime());//过程审核完成时间
        nodeTimeModule.put("mergeStartTime",rd.getDate("merge_time").getTime());//并网完成时间
        nodeTimeModule.put("mergeEndTime",rd.getDate("check_accept_time").getTime());//并网审核完成时间
        maps.put("nodeTimeModule",nodeTimeModule);


        Record kcrd = Db.findFirst("select * from crm_customer_entry_survey_record_stock where entry_id=?",rd.getStr("id"));
            if(kcrd== null){
                throw  new IllegalArgumentException("踏勘数据为空");
               // continue;
            }
            List<Map<String,Object>> list = Lists.newArrayList();
            String roof_photo_one = kcrd.getStr("roof_photo_one");
            for(String one :roof_photo_one.split(",")){
                if(StringUtil.isNotBlank(one) && one.lastIndexOf(".")>20 ){
                    Map<String,Object> file = Maps.newHashMap();//房屋屋顶照片
                    file.put("code","FR_200020_100");
                    file.put("url",one);
                    list.add(file);
                }
         /*       Map<String,Object> fileq = Maps.newHashMap();//房屋周边照片（4张，4个方位角）
                fileq.put("code","FR_200020_90");
                fileq.put("url",one);
                list.add(fileq);*/
            }
            String roof_photo_two = kcrd.getStr("roof_photo_two");
            if(StringUtil.isNotBlank(roof_photo_two)){
                for(String two :roof_photo_two.split(",")) {
                    Map<String,Object> fileq = Maps.newHashMap();//房屋周边照片（4张，4个方位角）
                    fileq.put("code","FR_200020_90");
                    fileq.put("url",two);
                    list.add(fileq);
                }
            }
            String roof_photo_four = kcrd.getStr("roof_photo_four");
            if(StringUtil.isNotBlank(roof_photo_four)) {
                for (String three : roof_photo_four.split(",")) {
           /*     Map<String, Object> file1 = Maps.newHashMap();//房屋屋顶南侧图片
                file1.put("code", "GZFZFR_200020_111");
                file1.put("url", three);
                list.add(file1);*/
                    Map<String, Object> fileq = Maps.newHashMap();//房屋周边照片（4张，4个方位角）
                    fileq.put("code", "FR_200020_90");
                    fileq.put("url", three);
                    list.add(fileq);
                }
            }
            String roof_photo_three = kcrd.getStr("roof_photo_three");
            if(StringUtil.isNotBlank(roof_photo_three)) {
                for (String three : roof_photo_three.split(",")) {
         /*       Map<String, Object> file3 = Maps.newHashMap();//房屋屋顶西侧图片
                file3.put("code", "GZFZFR_200020_112");
                file3.put("url", three);
                list.add(file3);*/
                    Map<String, Object> fileq = Maps.newHashMap();//房屋周边照片（4张，4个方位角）
                    fileq.put("code", "FR_200020_90");
                    fileq.put("url", three);
                    list.add(fileq);
                }
            }


      /*  Map<String,Object> file4 = Maps.newHashMap();//户用勘察记录表（附平面草图） url
        file4.put("code","GZFZFR_200020_1140");
        file4.put("url","https://pv.nhet.cloud/oss/nenghui/web/fileupload/1660794267372.jpg");
        list.add(file4);*/

            String cturls = sur.getStr("url");
            if(StringUtil.isNotBlank(cturls)){
                for(String cturl :cturls.split(",")){
                    Map<String,Object> file4 = Maps.newHashMap();//户用勘察记录表（附平面草图） url
                    file4.put("code","GZFZFR_200020_1140");
                    file4.put("url",cturl);
                    list.add(file4);
                }

            }


            String house_ownership = kcrd.getStr("house_ownership");
            for(String three :house_ownership.split(",")) {
                Map<String, Object> file5 = Maps.newHashMap();//房产证（或房产证明文件）
                file5.put("code", "BS_0_30");
                file5.put("url", three);
                list.add(file5);
            }

        String design_drawings = rd.getStr("dz_imgs");
            String safety_disclose_doc_img = filerd.getStr("safety_disclose_doc_img");
        if(StringUtil.isNotBlank(design_drawings)){
            for(String dra : design_drawings.split(",")){
                Map<String,Object> file6 = Maps.newHashMap();//附件：设计CAD文件
                file6.put("code","GZFZFR_200020_1170");
                file6.put("url",dra);
                list.add(file6);
            }
        }else {
            for(String xl :safety_disclose_doc_img.split(",")) {
                Map<String, Object> file31 = Maps.newHashMap();//电表照片
                file31.put("code", "GZFZFR_200020_1170");
                file31.put("url", xl);
                list.add(file31);
            }
        }
        String insuranceFiles = rd.getStr("insurance_files");
        if (StringUtil.isNotBlank(insuranceFiles)) {
            for (String ins : insuranceFiles.split(",")) {
                Map<String, Object> file7 = Maps.newHashMap();//工程安装一切险
                file7.put("code", "GZFZCP_200020_170");
                file7.put("url", ins);
                list.add(file7);
            }
        }else {
            Map<String,Object> file7 = Maps.newHashMap();//工程安装一切险
            file7.put("code","GZFZCP_200020_170");
            file7.put("url","https://nhet.oss-cn-shanghai.aliyuncs.com/energy_img/pdf/20240726/14cbb9aca5ec419ea6b1c61d0233c265/177df18b8bfe85163b2483bc40485cbe_97a0e79076e2ce526958c582c58c0bbe_8_85c1e.pdf");
            list.add(file7);
            Map<String,Object> file7a = Maps.newHashMap();//工程安装一切险
            file7a.put("code","GZFZCP_200020_170");
            file7a.put("url","https://nhet.oss-cn-shanghai.aliyuncs.com/energy_img/pdf/20240726/add979ed57654400ac6a114b20ff27db/8b829231e8ad999346d442791c856e52_da8bea8825bc6ef850aa578b36aa91d4_8_cbd5e.pdf");
            list.add(file7a);
        }

        String zjmp = filerd.getStr("zj_plate_img");
        if(StringUtil.isNotBlank(zjmp)){
            for(String zj :zjmp.split(",")){
                Map<String,Object> file8 = Maps.newHashMap();//组件铭牌照片
                file8.put("code","GZFZCP_200020_3790");
                file8.put("url",zj);
                list.add(file8);
            }
        }

            String zjfs = filerd.getStr("zj_img5");
            if(StringUtil.isBlank(zjfs)){
                throw new IllegalArgumentException("组件俯视图为空");
            }
            for(String zjf :zjfs.split(",")) {
                Map<String, Object> file9 = Maps.newHashMap();//组件俯视图
                file9.put("code", "GZFZCP_200020_3815");
                file9.put("url", zjf);
                list.add(file9);
            }

            String bnqaz = filerd.getStr("dc_imgs");
            if(StringUtil.isBlank(bnqaz)){
                throw new IllegalArgumentException("逆变器安装图为空");
            }
            for(String zjf :bnqaz.split(",")) {
                Map<String, Object> file11 = Maps.newHashMap();//逆变器安装图-整体外观及走线及采集器（离地高度）
                file11.put("code", "GZFZCP_200020_3820");
                file11.put("url",zjf);
                list.add(file11);
             /*   Map<String,Object> file13 = Maps.newHashMap();//逆变器安装图-接地情况
                file13.put("code","GZFZCP_200020_3840");
                file13.put("url",zjf);
                list.add(file13);
                Map<String,Object> file15 = Maps.newHashMap();//逆变器安装图-组串开路电压照片
                file15.put("code","GZFZCP_200020_3860");
                file15.put("url",zjf);
                list.add(file15);*/
            }
            String nbamp = filerd.getStr("nbq_plate_img");
            if(StringUtil.isBlank(nbamp)){
                throw new IllegalArgumentException("逆变器安装图-铭牌为空");
            }
            for(String nbq :nbamp.split(",")) {
                Map<String, Object> file12 = Maps.newHashMap();//逆变器安装图-铭牌
                file12.put("code", "GZFZCP_200020_3830");
                file12.put("url", nbq);
                list.add(file12);
           /*     Map<String,Object> file14 = Maps.newHashMap();//逆变器安装图-逆变器直流侧
                file14.put("code","GZFZCP_200020_3850");
                file14.put("url",nbq);
                list.add(file14);*/
                Map<String,Object> file18 = Maps.newHashMap();//并网箱安装图-接地情况
                file18.put("code","GZFZCP_200020_3920");
                file18.put("url",nbq);
                list.add(file18);
            }
            String nbqzt = filerd.getStr("nbq_zb_img");
            for(String nbq :nbqzt.split(",")) {
                Map<String,Object> file16 = Maps.newHashMap();//并网箱安装图-外观及走线（离地高度）
                file16.put("code","GZFZCP_200020_3880");
                file16.put("url",nbq);
                list.add(file16);
            }

            String bwxn = filerd.getStr("bw_inner_img");
            for(String bwx :bwxn.split(",")) {
                Map<String,Object> file17 = Maps.newHashMap();//并网箱安装图-并网箱内部全景
                file17.put("code","GZFZCP_200020_3890");
                file17.put("url",bwx);
                list.add(file17);
            }

            String zjzt = filerd.getStr("zj_img1");
            for(String zj :zjzt.split(",")) {
                if(StringUtil.isNotBlank(zj) && zj.lastIndexOf(".")>0){
                    Map<String,Object> file17 = Maps.newHashMap();//支架类
                    file17.put("code","GZFZCP_200020_3980");
                    file17.put("url",NHFileUrl+zj);
                    list.add(file17);
                }
            }
            String xlzx = filerd.getStr("size_measure_imgs");
            for(String xl :xlzx.split(",")) {
                if(StringUtil.isNotBlank(xl) && xl.lastIndexOf(".")>20) {
                    Map<String, Object> file17 = Maps.newHashMap();//线缆走向（屋顶、下墙）、线缆保护管（或桥架）敷设及固定照片
                    file17.put("code", "GZFZCP_200020_4160");
                    file17.put("url", xl);
                    list.add(file17);
                }

            }
      /*      String xlxq = filerd.getStr("fix_other_img");
            if(StringUtil.isNotBlank(xlxq)){
                for(String xl :xlxq.split(",")) {
                    Map<String,Object> file17 = Maps.newHashMap();//线缆走向（屋顶、下墙）、线缆保护管（或桥架）敷设及固定照片
                    file17.put("code","GZFZCP_200020_4160");
                    file17.put("url",xl);
                    list.add(file17);
                }
            }*/
            String zjjdj = filerd.getStr("component_img3");
            for(String xl :zjjdj.split(",")) {
                Map<String, Object> file2a = Maps.newHashMap();//接地极图
                file2a.put("code", "GZFZCP_200020_4200");
                file2a.put("url", xl);
                list.add(file2a);
            }

            String jd_img6 = filerd.getStr("jd_img6");
            for(String xl :jd_img6.split(",")) {
                Map<String, Object> file2s = Maps.newHashMap();//接地极图
                file2s.put("code", "GZFZCP_200020_4210");
                file2s.put("url", xl);
                list.add(file2s);
                Map<String,Object> file2d = Maps.newHashMap();//接地极图
                file2d.put("code","GZFZCP_200020_4220");
                file2d.put("url",xl);
                list.add(file2d);
               /* Map<String,Object> file2f = Maps.newHashMap();//接地极图
                file2f.put("code","GZFZCP_200020_4230");
                file2f.put("url",xl);
                list.add(file2f);*/
        /*        Map<String,Object> file2g = Maps.newHashMap();//接地极图
                file2g.put("code","GZFZCP_200020_4240");
                file2g.put("url",xl);
                list.add(file2g);*/
          /*      Map<String,Object> file2h = Maps.newHashMap();//接地极图
                    file2h.put("code","GZFZCP_200020_4250");
                file2h.put("url",xl);
                list.add(file2h);*/
            }


            String zj_img2 = filerd.getStr("zj_img2");
            for(String xl :zj_img2.split(",")) {
               /* Map<String,Object> file23 = Maps.newHashMap();//防水措施图-横向水槽
                file23.put("code","GZFZCP_200020_4260");
                file23.put("url",xl);
                list.add(file23);
                Map<String,Object> file24 = Maps.newHashMap();//防水措施图-竖向水槽
                file24.put("code","GZFZCP_200020_4270");
                file24.put("url",xl);
                list.add(file24);*/
                if(StringUtil.isNotBlank(xl) && xl.lastIndexOf(".")>20) {
                Map<String,Object> file25 = Maps.newHashMap();//防水措施图-其他图片
                file25.put("code","GZFZCP_200020_4300");
                file25.put("url",xl);
                list.add(file25);
                }
            }


            String other_files = filerd.getStr("other_files");
            for(String xl :other_files.split(",")) {
                Map<String, Object> file26 = Maps.newHashMap();//项目公司备案证
                file26.put("code", "MG_200020_600");
                file26.put("url", xl);
                list.add(file26);
            }

            String power_capacity_url = filerd.getStr("power_capacity_url");
            if(StringUtil.isNotBlank(power_capacity_url)){
                for(String xl :power_capacity_url.split(",")) {
                    Map<String, Object> file27 = Maps.newHashMap();//三天连续发电量监控系统截图
                    file27.put("code", "MG_200020_310");
                    file27.put("url", xl);
                    list.add(file27);
                }
            }else{
                    Map<String, Object> file27 = Maps.newHashMap();//三天连续发电量监控系统截图
                    file27.put("code", "MG_200020_310");
                    file27.put("url", "https://pv.nhet.cloud/oss/nenghui/web/fileupload/1695354296163.jpg");
                    list.add(file27);

            }


            String zj_report = filerd.getStr("zj_report");
            for(String xl :zj_report.split(",")) {
                Map<String, Object> file28 = Maps.newHashMap();//验收报告
                file28.put("code", "MG_200020_330");
                file28.put("url", xl);
                list.add(file28);
            }

            String fix_conclusion = filerd.getStr("fix_conclusion");
            if(fix_conclusion == null){
                throw new IllegalArgumentException("购售电合同为空");
            }
            for(String xl :fix_conclusion.split(",")) {
                Map<String, Object> file29 = Maps.newHashMap();//购售电合同
                file29.put("code", "MG_200020_320");
                file29.put("url", xl);
                list.add(file29);
            }
            String safety_warning_img = filerd.getStr("safety_warning_img");
            if(safety_warning_img == null){
                throw new IllegalArgumentException("电表箱图片为空");
            }
            for(String xl :safety_warning_img.split(",")) {
                Map<String, Object> file30 = Maps.newHashMap();//电表箱图片
                file30.put("code", "MG_200020_340");
                file30.put("url", xl);
                list.add(file30);
            }
            String db_imgs = filerd.getStr("db_imgs");
            if(db_imgs == null){
                throw new IllegalArgumentException("电表照片为空");
            }
            for(String xl :db_imgs.split(",")) {
                Map<String, Object> file31 = Maps.newHashMap();//电表照片
                file31.put("code", "GZFZMG_200020_312");
                file31.put("url", xl);
                list.add(file31);
            }


            String disclose_doc_img = filerd.getStr("disclose_doc_img");
            for(String xl :disclose_doc_img.split(",")) {
                Map<String, Object> file32 = Maps.newHashMap();//纸质合同
                file32.put("code", "2290");
                file32.put("url", xl);
                list.add(file32);
            }
            String supplement_url = filerd.getStr("supplement_url");
            if(StringUtil.isNotBlank(supplement_url)){
                for(String xl :supplement_url.split(",")) {
                    Map<String, Object> file32 = Maps.newHashMap();//补充证明材料20240807：荷载报告、接入方案，并网意见单等
                    file32.put("code", "2207");
                    file32.put("url", xl);
                    list.add(file32);
                }
            }



            maps.put("fileModule",list);//附件信息
        maps.put("partner","nenghui");
        maps.put("capital","03");
        String url = ZfConstants.url+ZfConstants.stockEntryUrl;
        System.out.println("stockEntryStationInputPiece  请求参数："+new Gson().toJson(maps));

        String result = YWUtils.request(url, maps);
        Map parse=(Map) JSONObject.parse(result);
        System.out.println("stockEntryStationInputPiece 返回结果："+parse);
        //{"code":200,"success":true,"data":null,"msg":"暂无承载数据"}
        if("200".equals(String.valueOf(parse.get("code")))){
            String addsql = "update crm_gf_stock_entry set station_state='20',station_msg=? where entry_id=? ";
            Db.update(addsql,parse.get("msg"),rd.getStr("id"));
        }else if("400".equals(String.valueOf(parse.get("code")))){
                    String addsql = "update crm_gf_stock_entry set station_msg=? where entry_id=? ";
                    Db.update(addsql,parse.get("msg"),rd.getStr("id"));
                }
            }catch (Exception e){
                logger.error("Exception :{}",e);
                System.out.println(e.getMessage());
                throw new IllegalArgumentException("推送失败:"+e.getMessage());
            }
        }
    }

    //状态状态 新系统数据
    public Result tbStatus2(String id ){
        Operator operator = Operator.of(UserUtils.getUser());
        CustomerEntry entry = customerDao.get(id);
        CrmCustomerIncomingApplication application = incomingApplicationDao.getByEntryId(id);
        if (application == null){
            return Result.fail("当前电站无进件信息");
        }
        List<String> inputPieceIdList = Lists.newArrayList();
        inputPieceIdList.add(application.getInputPieceId());
        Map<String,Object> maps = Maps.newHashMap();
        maps.put("inputPieceIdList",inputPieceIdList);
        maps.put("partner","nenghui");
        maps.put("capital","03");
        logger.info("tbStatus2 params :{}",new Gson().toJson(maps));
        String url = ZfConstants.url+ZfConstants.entryStateUrl;
        String result = YWUtils.request(url, maps);
        logger.info("tbStatus2 result :{}",result);
        Map parse=(Map) JSONObject.parse(result);
        if("200".equals(parse.get("code").toString())){
            JSONArray fddf =  JSONObject.parseArray(parse.get("data").toString());
            for(int i=0;i< fddf.size();i++){
                JSONObject parsemap = fddf.getJSONObject(i);
                String itemStatus = "";
                String auditStatus = "";
                //客户信息状态
                String customerState = parsemap.get("customerState").toString();
                String customerMsg = parsemap.get("customerMsg").toString();
                //电站档案状态
                String stationState = parsemap.get("stationState").toString();
                String stationMsg = parsemap.get("stationMsg").toString();
                if (!"30".equals(application.getTenantStatus()) && !customerState.equals(application.getTenantStatus())){
                    application.setTenantStatus(customerState);
                    if("30".equals(customerState)){
                        application.setStatus("26");
                        entry.setApplyStatus("26");
                        itemStatus = "30";
                        auditStatus = "2";
                    }else if("40".equals(customerState) || "50".equals(customerState)){
                        application.setStatus("27");
                        entry.setApplyStatus("27");
                        itemStatus = "40";
                        auditStatus = "3";
                    }else if("20".equals(customerState) || "60".equals(customerState)){
                        itemStatus = "20";
                        auditStatus = "1";
                    }
                    yxIncomingLogDao.addCrmYxIncomingLog(id,application.getInputPieceId(),"1","查询客户信息状态,"+customerMsg, operator);
                    CrmYxIncomingProcessDao.addIncomingProcess(id,"1",itemStatus,"0",auditStatus,customerMsg);
                }else if(!"30".equals(application.getProjectStatus()) && !stationState.equals(application.getProjectStatus())){
                    application.setProjectStatus(stationState);
                    if("30".equals(stationState)){
                        application.setStatus("29");
                        entry.setApplyStatus("29");
                        itemStatus = "30";
                        auditStatus = "2";
                    }else if("40".equals(stationState) || "50".equals(stationState)){
                        application.setStatus("30");
                        entry.setApplyStatus("30");
                        itemStatus = "40";
                        auditStatus = "3";
                    }else if("20".equals(stationState) || "60".equals(stationState)){
                        itemStatus = "20";
                        auditStatus = "1";
                    }
                    yxIncomingLogDao.addCrmYxIncomingLog(id,application.getInputPieceId(),"2","查询电站档案状态,"+stationMsg, operator);
                    CrmYxIncomingProcessDao.addIncomingProcess(id,"2",itemStatus,"0",auditStatus,stationMsg);
                }
                incomingApplicationDao.save(application);
                customerDao.save(entry);
            }
        }else {
            return Result.fail("同步失败");
        }
        return Result.ok();
    }
    public Result tbStatus(List<String> ids){
//        Record record = Db.findFirst(" select * from crm_gf_stock_entry where entry_id = ?", id);
        SqlBuilder builder = new SqlBuilder();
        builder.inst(" select * from crm_gf_stock_entry where entry_id  in  ",ids);
        List<Record> records = Db.find(builder.build(), builder.params());
        List<String> inputPieceIdList = Lists.newArrayList();
        for (Record record : records) {
            if (record == null) {
                return Result.fail("当前电站无进件信息");
            }
            inputPieceIdList.add(record.getStr("input_piece_id"));
        }
        Map<String,Object> maps = Maps.newHashMap();
        maps.put("inputPieceIdList",inputPieceIdList);
        maps.put("partner","nenghui");
        maps.put("capital","03");
        String url = ZfConstants.url+ZfConstants.entryStateUrl;
        String result = YWUtils.request(url, maps);
        System.out.println("tbStatus----"+result);
        Map parse=(Map) JSONObject.parse(result);
        if("200".equals(parse.get("code").toString())){
            JSONArray fddf =  JSONObject.parseArray(parse.get("data").toString());
            for(int i=0;i< fddf.size();i++){
                JSONObject parsemap = fddf.getJSONObject(i);
                String sqlsta = "update crm_gf_stock_entry set customer_state=?,station_state=?,station_msg=?,customer_msg=? where input_piece_id=?";
                Db.update(sqlsta,parsemap.get("customerState").toString(),parsemap.get("stationState").toString(),parsemap.get("stationMsg"),parsemap.get("customerMsg"),parsemap.get("inputPieceId"));
            }
        }else {
            return Result.fail("同步失败");
        }
        return Result.ok();
    }

    /**
     * 获取状态
    */
    public void queryStockInputPieceState(String id ){
        String sql = "select * from crm_gf_stock_entry where station_state in('10') ";
        if(StringUtil.isNotBlank(id)){
            sql = sql +" and entry_id ='"+id+"'";
        }
        List<Record> list = Db.find(sql);
        List<String> inputPieceIdList = Lists.newArrayList();
        for(Record rd:list){
            inputPieceIdList.add(rd.getStr("input_piece_id"));
        }
        if(inputPieceIdList.size()>0){
            Map<String,Object> maps = Maps.newHashMap();
            maps.put("inputPieceIdList",inputPieceIdList);
            maps.put("partner","nenghui");
            maps.put("capital","03");
            String url = ZfConstants.url+ZfConstants.entryStateUrl;
            String result = YWUtils.request(url, maps);
            Map parse=(Map) JSONObject.parse(result);
            if("200".equals(parse.get("code").toString())){
              JSONArray fddf =  JSONObject.parseArray(parse.get("data").toString());
              for(int i=0;i< fddf.size();i++){
                  JSONObject parsemap = fddf.getJSONObject(i);
                  String sqlsta = "update crm_gf_stock_entry set customer_state=?,station_state=?,station_msg=? where input_piece_id=?";
                  Db.update(sqlsta,parsemap.get("customerState").toString(),parsemap.get("stationState").toString(),parsemap.get("stationMsg"),parsemap.get("inputPieceId"));

              }

            }
        }
    }


    public void terminateProject(){
        String sql = "select * from crm_gf_stock_entry where station_msg like '合同模块的业主与预审的业主姓名不一致%' ";
        List<Record> list = Db.find(sql);
        for(Record rd:list){
            Map<String,Object> maps = Maps.newHashMap();
            maps.put("partner","nenghui");
            maps.put("capital","03");
            maps.put("inputPieceId",rd.getStr("input_piece_id"));
            maps.put("cancelReason","信息错误");
            String url = ZfConstants.url+"/open/link/terminateProject";
            String result = YWUtils.request(url, maps);
          System.out.println(result);

        }
    }
    @Transactional(rollbackFor = Exception.class)
    public void updateBWInfo(AddReportSecondReq req) {
        String entryId = req.getEntryId();
        CrmAcceptingReportStock reportStock = reportStockDao.get(entryId);
        if (reportStock == null){
            throw new BusinessException("订单不存在或状态异常");
        }
        CrmCustomerEntryStock customerEntryStock = entryStockDao.get(entryId);
        customerEntryStock.setGeneratorNo(req.getGeneratorNo());//发电户号
        customerEntryStock.setInsuranceNumber(req.getInsuranceNumber());//保险单号
        reportStock.setFixConclusion(req.getContractFile());//购售电合同
        reportStock.setPowerCapacityUrl(req.getPowerCapacityUrl());//三天发电量
        reportStock.setDbImgs(req.getDbImgs());//电表照片
        reportStock.setSafetyWarningImg(req.getDbxImgs());//电表箱照片
        reportStock.setSupplementUrl(req.getSupplementUrl());//其他附件
        reportStockDao.save(reportStock);
        entryStockDao.save(customerEntryStock);
    }
    @Transactional(rollbackFor = Exception.class)
    public void updateWGInfo(AddReportReq req) {
        String entryId = req.getEntryId();
        CrmAcceptingReportStock reportStock = reportStockDao.get(entryId);
        CrmCustomerEntryStock customerEntryStock = entryStockDao.get(entryId);
        customerEntryStock.setInsuranceFiles(req.getInsuranceFiles());//工程安装一切险
        if (reportStock == null){
            throw new BusinessException("订单不存在或状态异常");
        }
        reportStock.setOtherFiles(req.getFilingDocumentPhoto());//项目备案证
        reportStock.setDiscloseDocImg(req.getDiscloseDocImg());//纸质合同
        reportStock.setZjPlateImg(req.getZjPlateImg());//组件铭牌照片
        reportStock.setZjImg5(req.getZjImg5());//组件航拍俯视图
        reportStock.setDcImgs(req.getDcImgs());//逆变器安装图-整体外观及走线及采集器（离地高度）
        reportStock.setNbqPlateImg(req.getNbqPlateImg());//逆变器安装图-铭牌
        reportStock.setNbqZbImg(req.getNbqZbImg());//并网箱安装图-外观及走线（离地高度）
        reportStock.setBwInnerImg(req.getBwInnerImg());//并网箱安装图-并网箱内部全景
        reportStock.setZjImg1(req.getZjImg1());//支架类
        reportStock.setSizeMeasureImgs(req.getSizeMeasureImgs());//线缆走向（屋顶、下墙）、线缆保护管（或桥架）敷设及固定照片
        reportStock.setComponentImg3(req.getComponentImg3());//接地极图-并网箱、逆变器安装接地极
        reportStock.setJdImg6(req.getJdImg6());//接地极图-接地电阻阻值
        reportStock.setZjImg2(req.getZjImg2());//防水措施图-其他图片
        reportStockDao.save(reportStock);
        entryStockDao.save(customerEntryStock);
    }
    @Transactional(rollbackFor = Exception.class)
    public Result updateSurveyRecordInfo(AddEntryReq req){
        String entryId = req.getId();
        CrmCustomerEntryStock customerEntryStock = entryStockDao.get(entryId);
        customerEntryStock.setLongitude(req.getLongitude());//经度
        customerEntryStock.setLatitude(req.getLatitude());//纬度
        customerEntryStock.setAddress(req.getAddress());//地址
        CrmCustomerEntrySurveyRecordStock surveyRecordStock = surveyRecordStockDao.get(entryId);
        if (surveyRecordStock == null){
            surveyRecordStock = new CrmCustomerEntrySurveyRecordStock();
            surveyRecordStock.setEntryId(entryId);
        }
        surveyRecordStock.setSealRoof(req.getSealRoof());//是否封屋顶
        surveyRecordStock.setAzimuth(req.getAzimuth());//房屋朝向
        surveyRecordStock.setAngle(req.getAngle());//方位角
        surveyRecordStock.setCompletionYear(req.getCompletionYear());//建成年份
        surveyRecordStock.setBuildingHeight(req.getBuildingHeight());//建筑高度
        surveyRecordStock.setWaterproof(req.getWaterproof());//屋顶防水情况
        surveyRecordStock.setSourcePollution(req.getSourcePollution());//是否有污染源
        surveyRecordStock.setOpsCondition(req.getOpsCondition());//是否具备运维空间
        surveyRecordStock.setVoltageClasses(req.getVoltageClasses());//并网电压等级
        surveyRecordStock.setTransformerCapacity(req.getTransformerCapacity());//变压器容量
        surveyRecordStock.setRestrictFlag(req.getRestrictFlag());//是否符合变压器容量限制要求
        surveyRecordStock.setDistance(req.getDistance());//并网距离
        surveyRecordStock.setRoofPhotoOne(req.getRoofPhotoOne());//屋顶照片
        surveyRecordStock.setRoofPhotoTwo(req.getRoofPhotoTwo());//房屋周边照片
        surveyRecordStock.setHouseOwnership(req.getHouseOwnership());//房产证
        CrmArchiveSurveyStock archiveSurveyStock = archiveSurveyStockDao.findByEntryId(Integer.valueOf(entryId));
        if (archiveSurveyStock == null){
            archiveSurveyStock = new CrmArchiveSurveyStock();
            archiveSurveyStock.setArchiveId(Integer.parseInt(entryId));
        }
        String buildingHead = "正南";
        if ("1".equals(req.getAzimuth())){
            buildingHead = "南偏西";
        }else if ("2".equals(req.getAzimuth())){
            buildingHead = "南偏东";
        }
        archiveSurveyStock.setPowerBoxDistance(req.getDistance().stripTrailingZeros().toPlainString());
        archiveSurveyStock.setBuildingHead(buildingHead);
        archiveSurveyStock.setZjDirecDegree(req.getAngle());
        archiveSurveyStock.setHouseBuildYear(req.getCompletionYear());
        archiveSurveyStock.setBuildHigh(req.getBuildingHeight().stripTrailingZeros().toPlainString());
        archiveSurveyStock.setLatitude(req.getLatitude().stripTrailingZeros().toPlainString());
        archiveSurveyStock.setLongitude(req.getLongitude().stripTrailingZeros().toPlainString());
        archiveSurveyStock.setUrl(req.getSurveyFiles());//勘察记录表
        CrmAcceptingReportStock reportStock = reportStockDao.get(entryId);
        if (reportStock == null){
            reportStock = new CrmAcceptingReportStock();
            reportStock.setId(entryId);
        }
        reportStock.setSafetyDiscloseDocImg(req.getDesignDrawings());//设计图纸
        entryStockDao.save(customerEntryStock);
        surveyRecordStockDao.save(surveyRecordStock);
        archiveSurveyStockDao.save(archiveSurveyStock);
        reportStockDao.save(reportStock);
        return Result.ok();
    }

    public Record findByEntryId(String entryId){
        SqlBuilder builder = new SqlBuilder();
        builder.line(" select e.id,e.tenant_type as tenantType ,e.tenant_name as tenantName ,e.age,e.mobile,e.id_code as idCode ,e.gender,e.province,e.city,e.area,e.address,")
                .line(" e.id_card_front as idCardFront,e.id_card_back as idCardBack, e.bank_card as bankCard  ,e.bank_code as bankCode ,e.bank_name as bankName ,e.residence_booklet as residenceBooklet, e.power_station_code  as powerStationCode  ")
                .line(" ,e.trader_name as traderName,e.status ,e.creator ,e.create_time as createTime,e.project_company_name as projectCompanyName,e.project_id as projectId ")
                .line(" from  crm_customer_entry_stock e ")
                .line(" where 1=1 and  e.id = ? ",entryId);

        return Db.findFirst(builder.build(),builder.params());
    }
    public Record findRecordByEntryId(String entryId){
        SqlBuilder builder = new SqlBuilder();
        builder.line(" select s.entry_id ,s.roof_type as roofType ,s.seal_roof as sealRoof ,s.completion_year as completionYear,s.azimuth,s.building_height as buildingHeight")
                .line(" ,s.distance,s.fly_imgs as flyImgs ,s.roof_photo_one as roofPhotoOne,s.roof_photo_two as roofPhotoTwo, s.house_ownership as houseOwnership ,s.voltage_classes as voltageClasses ")
                .line(" ,s.transformer_capacity  as transformerCapacity, s.restrict_flag as restrictFlag ,s.waterproof,s.source_pollution  as sourcePollution ,s.ops_condition as opsCondition ")
                .line(" ,s.roof_photo_three as roofPhotoThree,s.roof_photo_four as roofPhotoFour,s.roof_photo_five as roofPhotoFive ")
                .line(" from  crm_customer_entry_survey_record_stock s ")
                .line(" where 1=1 and  s.entry_id = ? ",entryId);

        return Db.findFirst(builder.build(),builder.params());
    }

    public Record findArchiveSurveyByEntryId(String entryId){
        Record sur = Db.findFirst("select * from crm_archive_survey_stock where archive_id=?",entryId);
        return sur;
    }
    public Record findAcceptingReportByEntryId(String entryId){
        Record report = Db.findFirst("select * from crm_accepting_report_stock where id=?",entryId);
        return report;
    }

    public  List<Record> findinverterList(String entryId){
        return Db.find("select * from crm_plan_material_entry_stock where  type='逆变器' and status='0' and entry_id=?",entryId);
    }

    public List<Record> findZjList(String entryId){
        return Db.find("select * from crm_plan_material_entry_stock where type='组件' and status='0' and entry_id=?",entryId);
    }

    //同步回款时间
    public void tbPaymentTime(String entryId,Date paymentTime){
        try{
            Map<String,Object> body=new HashMap<>();
            body.put("innerStationId",entryId);
            String paymentT=DateUtils.formatDate(paymentTime, "yyyy-MM-dd");
            body.put("paymentTime",paymentT);
            String url = YWConstants.url+YWConstants.tbPaymentTimeUrl;
            String result = YWUtils.request(url, body);
            String status = "1";
            Map parse=(Map) JSONObject.parse(result);
            if(parse.containsKey("code")){
                if("200".equals(String.valueOf(parse.get("code")))){
                    status = "0";
                }
            }
            saveSysRecord(entryId, url, new Gson().toJson(body), result, status, "1","4");
        }catch (Exception e){
            logger.error("tbPaymentTime  e:",e);
        }
    }
}
