zoukankan      html  css  js  c++  java
  • HTTPClient实现跨服务器传递数据

    摘要:(实现步骤很简单,内容之所以很长,主要是我粘贴的原代码需要处理的数据的有点多(关联的表数据太多了),哈哈哈哈~)

    本文参考自:https://blog.csdn.net/weixin_33755557/article/details/89621201

    首先:
    引入工具类: 可以自行添加/修改

    package com.shd.biz.bureauDetect.uploadData.util;//工具包路径
    
    public class Constants {
        
        public static final String TEST = "http://192.168.4.143:8089/sms";
        public static final String PRODUCT_MANAGEMENT_HOST = "http://192.168.4.143:8085/sms";
        
    }

    引入HttpClient支持:

    @Autowired
    private RestTemplate restTemplate;

    1.查询数据 :getForEntity(url,Object.class)

    参数一(URL): 需要调用服务的地址(可以携带数据)

    参数二(Object.class):String.class表示我希望返回的body类型是String

    返回值类型: ResponseEntity*<*T*>*

    @GetMapping("/findProductByPage")
        public ResponseEntity<String> findProductByPage(Integer page, Integer rows,Product product){
            HttpStatus statusCode = null;
            try {
                String url = Constants.PRODUCT_MANAGEMENT_HOST+ "/product/findProductByPage?page="+page+"&rows="+rows+"&product="+product;
                ResponseEntity<String> entity = restTemplate.getForEntity(url, String.class);//跨服务器访问
                statusCode = entity.getStatusCode();//获取状态码
                String body = entity.getBody(); //获取返回数据
                return new ResponseEntity<>(body,statusCode);
            } catch (Exception e) {
                e.printStackTrace();
                return new ResponseEntity<>(statusCode);
            }
    }

    2.若需要修改访问端服务器的数据(保存数据): postForEntity(url,pojo,Object.class)
    参数一:需要调用服务的地址(可以携带数据)
    参数二:传递的数据
    参数三:Object.class表示我希望返回的body类型,例如String.class是希望返回的body类型String类型
    *注意:该方法传递给跨服务器是 方法参数上需要加上@RequestBody 否则无法接受到数据

    @PostMapping("/saveProduct")
       public ResponseEntity<String> saveProduct(Product product){
           HttpStatus statusCode =null;
           try {
               JSONObject proJson = JSONObject.fromObject(product);
               String prodct = proJson.toString();
               String url = Constants.PRODUCT_MANAGEMENT_HOST+"/product/saveProduct";
               ResponseEntity<String> entity = restTemplate.postForEntity(url, prodct, String.class);
               String body = entity.getBody();
               statusCode = entity.getStatusCode();
               return new ResponseEntity<>(HttpStatus.CREATED);
           } catch (Exception e) {
               e.printStackTrace();
               return new ResponseEntity<>(statusCode);
           }
    }

    下面是我使用的完整例子,或许有所差异,谨供参考:

    第一步:添加工具类(设置对方服务器的访问地址,提供于实现层方法里的url参数)

    第二步:uploadDateService定义接口:

    /**
         * @function 发送端.
         * @author Liangjw  
         * @date 2019年10月10日 上午11:06:17
         * @param testId 局放检测任务id
         * @return
         */
        public String uploadData(String testId);

    注:我这里是前端传数据的id,然后后台接收id,查询获取相关表的数据,然后将数据封装到JSONObject中,传递的时候转换成json字符串再传递数据,这样的好处是在服务端无需建立参数模型,直接接收String,便于后期维护。

    第三步:uploadDateserviceImp实现层实现发送数据接口:

    注:我获取的数据很多,你自需要理解步骤思路就可以了
    1.获取自己需要上传的数据,封装到一个JSONObject对象中,然后把它转成Json字符串传递过去。
    例如:StringEntity entity = new StringEntity(params.toJSONString(), "UTF-8");
    2.然后获取httpClient,并创建请求方式(get只能获取数据,post可修改数据);
    3.post请求是将参数放在请求体里面传过去的;

    4.创建响应模型(获取请求的响应结果response);

    /**
         * 
         * @function 上传数据发送端.
         * @author Liangjw
         * @date 2019-10-18 上午10:10:30  
         * @param testId 局放检测任务id
         */
        @Override
        public String uploadData(String testId) {      
            if(testId != null && !"".equals(testId)){
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("TEST_ID", testId);
                //电缆局放检测任务
                DataRecord pdTestDr = this.getDao().queryForDataRecord(PATH + "getPDTestByTestId", map);  //查询车载系统库中的检测任务表
                //监测点
                List<DataRecord> test_pointList = this.getDao().queryForDataSet(PATH + "getTestPointByTestId", map).getResults();  //查询车载系统库中的监测点表
                //电缆线路(位置)
                Map<String, Object> placeIdMap = new HashMap<String, Object>();
                placeIdMap.put("PLACE_ID", pdTestDr.getLong("PLACE_ID"));
                DataRecord placeCableDr = this.getDao().queryForDataRecord(PATH + "getPlaceCableByPlaceId", placeIdMap);  //查询车载系统库中的电缆线路(位置)表
                //检测电缆(检测任务与电缆设备的中间表)
                List<DataRecord> test_cableList = this.getDao().queryForDataSet(PATH + "getTestCableByPlaceId", map).getResults();  //查询车载系统库中的检测电缆表
                //电缆局放检测分析结果
                List<DataRecord> test_analysis_resultList = this.getDao().queryForDataSet(PATH + "getTestAnalysisResultByTestId", map).getResults();  //查询车载系统库中的电缆局放检测分析结果
                //电缆(设备)
                Map<String, Object> deviceIdsMap = new HashMap<String, Object>();
                String ids = "";
                if(test_analysis_resultList.size() > 0){
                    for(DataRecord arDr : test_analysis_resultList){
                        String tempId = arDr.getLong("DEV_ID").toString()+",";
                        ids += tempId;                    
                    }
                }
                ids=(ids.substring(0,ids.length()-1)).trim();    
                deviceIdsMap.put("ids", ids);
                List<DataRecord> device_cableList = this.getDao().queryForDataSet(PATH + "getDeviceCableByDeviceId", deviceIdsMap).getResults();  //查询车载系统库中的电缆设备
                //局放检测装置
                Map<String, Object> equipmentIdsMap = new HashMap<String, Object>();
                String equipmentIds = "";
                if(test_pointList != null && test_pointList.size() > 0){
                    for(DataRecord test_PointDr : test_pointList){
                        String tempId2 = test_PointDr.getLong("EQUIPMENT_ID").toString()+",";
                        equipmentIds += tempId2;                    
                    }
                }
                equipmentIds=(equipmentIds.substring(0,equipmentIds.length()-1)).trim();    
                equipmentIdsMap.put("equipmentIds", equipmentIds);
                List<DataRecord> detection_deviceList = this.getDao().queryForDataSet(PATH + "getDetectionDeviceByEquipmentIds", equipmentIdsMap).getResults();  //查询车载系统库中的局放检测装置
                
                JSONObject params = new JSONObject();
                
                List<DataRecord> QPhiList = new ArrayList<DataRecord>();
                List<DataRecord> PRPDList = new ArrayList<DataRecord>();
                List<DataRecord> PRPSList = new ArrayList<DataRecord>();
                DataRecord sysLogQPhi = new DataRecord(), sysLogPRPD = new DataRecord(), sysLogTimeField = new DataRecord();
                
                //获取三个表上一次分别上传的截止时间
                String jsonMap = isExitUploadTime();
                if (jsonMap.startsWith("{")) {
                    jsonMap = jsonMap.substring(1, jsonMap.length());
                }
                if (jsonMap.endsWith("}")) {
                    jsonMap = jsonMap.substring(0, jsonMap.length() - 1);
                }
                Map<String, Object> paramMap = new HashMap<String, Object>();
                String[] out = jsonMap.split(",");
                for (String anOut : out) {
                    String[] inn = anOut.split("=");
                    paramMap.put(inn[0].trim(), inn[1].trim());
                }
                JSONObject jsonObject = new JSONObject(paramMap);
                String isExitQPhiDate = jsonObject.getString("isExitQPhiDate");
                String idQPhi = null;
                if(jsonObject.containsKey("idQPhi") == true){
                    idQPhi = jsonObject.getString("idQPhi");
                }
                String isExitPRPDDate = jsonObject.getString("isExitPRPDDate");
                String idPRPD = null;
                if(jsonObject.containsKey("idPRPD") == true){
                    idPRPD = jsonObject.getString("idPRPD");
                }
                String isExitTimeFieldDate = jsonObject.getString("isExitTimeFieldDate");
                String idTimeField = null;
                if(jsonObject.containsKey("idTimeField") == true){
                    idTimeField = jsonObject.getString("idTimeField");
                }
                
                Map<String, Object> typeNameMap = new HashMap<String, Object>();
                typeNameMap.put("TYPE_NAME", "检测车");
                //查询检测车
                DataRecord mechanicsType = this.getDao().queryForDataRecord(PATH + "getMechanicsTypeByTypeName", typeNameMap);  //查询车载系统库中的机具类型表
                Map<String, Object> typeIdMap = new HashMap<String, Object>();
                typeIdMap.put("TYPE_ID", mechanicsType.getString("TYPE_ID"));
                List<DataRecord> mechanics = this.getDao().queryForDataSet(PATH + "getMechanicsByTypeId", typeIdMap).getResults();  //查询车载系统库中的机具表
                String DATA_TYPE_KEY_QPhi = null, DATA_TYPE_KEY_PRPD = null, DATA_TYPE_KEY_TimeField = null;
                if(mechanics != null && mechanics.size() > 0){
                    DATA_TYPE_KEY_QPhi = mechanics.get(0).getString("MECHANICS_ID")+"tb_QPhiData";
                    DATA_TYPE_KEY_PRPD = mechanics.get(0).getString("MECHANICS_ID")+"tb_PRPDData";
                    DATA_TYPE_KEY_TimeField = mechanics.get(0).getString("MECHANICS_ID")+"tb_TimeFieldData";
                }
                
                //获取PRPD图谱图片
                String file_original_name =  testId;
                String PRPDImages_folderPath = SbpConfig.getProperty("sbp.phase.PRPD.images") + File.separator +file_original_name;
                String  uploadImagesResult = uploadImages(file_original_name, PRPDImages_folderPath);        
                System.out.println("PRPD图谱图片上传状态:"+uploadImagesResult);
                
                //获取QPhi、PRPD、TimeField数据
                if(test_pointList != null && test_pointList.size() > 0){
                    String sqlQPhi = null, sqlPRPD = null, sqlTimeField = null;
                    String beginTimeQPhi = null, beginTimePRPDD = null, beginTimeTimeField = null;
                    //QPhi
                    if(isExitQPhiDate.equals("是")){
                        beginTimeQPhi = jsonObject.getString("newQPhiUploadTime");
                        sqlQPhi = "select GUID, DeviceID, ReceiveTime, TimeStamp, PhaseDataA, PDDataA, PhaseDataB, PDDataB, PhaseDataC, PDDataC, PhaseFreq " +
                        "from tb_QPhiData where ReceiveTime > ? order by ReceiveTime";
                    }else{
                        sqlQPhi = "select GUID, DeviceID, ReceiveTime, TimeStamp, PhaseDataA, PDDataA, PhaseDataB, PDDataB, PhaseDataC, PDDataC, PhaseFreq " +
                        "from tb_QPhiData order by ReceiveTime";
                    }
                    
                    //PRPD
                    if(isExitPRPDDate.equals("是")){
                        beginTimePRPDD = jsonObject.getString("newPRPDUploadTime");
                        sqlPRPD = "select GUID, DeviceID, ReceiveTime, TimeStamp, PhaseDataA, PRPDDataA, PhaseDataB, PRPDDataB, PhaseDataC, PRPDDataC " +
                        "from tb_PRPDData where ReceiveTime > ? order by ReceiveTime";
                    }else{
                        sqlPRPD = "select GUID, DeviceID, ReceiveTime, TimeStamp, PhaseDataA, PRPDDataA, PhaseDataB, PRPDDataB, PhaseDataC, PRPDDataC " +
                        "from tb_PRPDData order by ReceiveTime";
                    }
                    
                    //TimeField
                    if(isExitTimeFieldDate.equals("是")){
                        beginTimeTimeField = jsonObject.getString("newTimeFieldUploadTime");
                        sqlTimeField = "select GUID, DeviceID, ReceiveTime, TimeStamp, TimeFieldDataA, TimeFieldDataB, TimeFieldDataC, GUID_QPhi " +
                        "from tb_TimeFieldData where ReceiveTime > ? order by ReceiveTime";
                    }else{
                        sqlTimeField = "select GUID, DeviceID, ReceiveTime, TimeStamp, TimeFieldDataA, TimeFieldDataB, TimeFieldDataC, GUID_QPhi " +
                        "from tb_TimeFieldData order by ReceiveTime";
                    }
                                
                    Connection con = DBConnectUtil.getConnection();
                    PreparedStatement pstmt = null;
                    ResultSet resultSet = null;
                    
                    try {
                        //QPhi
                        pstmt = con.prepareStatement(sqlQPhi);
                        if(isExitQPhiDate.equals("是")){
                            pstmt.setString(1, beginTimeQPhi);
                        }
                        resultSet = pstmt.executeQuery();
                        
                        while(resultSet.next()){
                            //如果该监测点存在QPhi数据                            
                            DataRecord QPhiDr = new DataRecord();
                            QPhiDr.put("GUID", resultSet.getString(1));
                            QPhiDr.put("DeviceID", resultSet.getString(2));
                            QPhiDr.put("ReceiveTime", resultSet.getString(3));
                            QPhiDr.put("TimeStamp", resultSet.getString(4));
                            QPhiDr.put("PhaseDataA", resultSet.getBytes(5));
                            QPhiDr.put("PDDataA", resultSet.getBytes(6));
                            QPhiDr.put("PhaseDataB", resultSet.getBytes(7));
                            QPhiDr.put("PDDataB", resultSet.getBytes(8));
                            QPhiDr.put("PhaseDataC", resultSet.getBytes(9));
                            QPhiDr.put("PDDataC", resultSet.getBytes(10));
                            QPhiDr.put("PhaseFreq", resultSet.getString(11));
                            QPhiList.add(QPhiDr);        
                        }
                        
                        //若QPhiList集合存在值,则(添加/修改同步记录进度--上传最大截止时间)发送数据同步记录到接收端                
                        if(QPhiList != null && QPhiList.size() > 0){
                            sysLogQPhi.put("isExitQPhiDate", isExitQPhiDate);
                            if(idQPhi != null ){
                                sysLogQPhi.put("ID", idQPhi);
                            }
                            sysLogQPhi.put("DATA_TYPE_KEY", DATA_TYPE_KEY_QPhi);
                            sysLogQPhi.put("SYN_PROGRESS", (QPhiList.get(QPhiList.size()-1)).getString("ReceiveTime"));                        
                        }    
                        
                        //PRPD
                        pstmt = con.prepareStatement(sqlPRPD);
                        
                        if(isExitPRPDDate.equals("是")){
                            pstmt.setString(1, beginTimePRPDD);
                        }
                        resultSet = pstmt.executeQuery();
                        
                        while(resultSet.next()){
                            //如果该监测点存在PRPD数据                            
                            DataRecord PRPDListDr = new DataRecord();
                            PRPDListDr.put("GUID", resultSet.getString(1));
                            PRPDListDr.put("DeviceID", resultSet.getString(2));
                            PRPDListDr.put("ReceiveTime", resultSet.getString(3));
                            PRPDListDr.put("TimeStamp", resultSet.getString(4));
                            PRPDListDr.put("PhaseDataA", resultSet.getBytes(5));
                            PRPDListDr.put("PRPDDataA", resultSet.getBytes(6));
                            PRPDListDr.put("PhaseDataB", resultSet.getBytes(7));
                            PRPDListDr.put("PRPDDataB", resultSet.getBytes(8));
                            PRPDListDr.put("PhaseDataC", resultSet.getBytes(9));
                            PRPDListDr.put("PRPDDataC", resultSet.getBytes(10));
                            PRPDList.add(PRPDListDr);        
                        }
                        
                        if(PRPDList != null && PRPDList.size() > 0){
                            sysLogPRPD.put("isExitPRPDDate", isExitPRPDDate);
                            if(idPRPD != null ){
                                sysLogPRPD.put("ID", idPRPD);
                            }
                            sysLogPRPD.put("DATA_TYPE_KEY", DATA_TYPE_KEY_PRPD);
                            sysLogPRPD.put("SYN_PROGRESS", (PRPDList.get(PRPDList.size()-1)).getString("ReceiveTime"));
                        }                
                        
                        //TimeField
                        pstmt = con.prepareStatement(sqlTimeField);
                        
                        if(isExitTimeFieldDate.equals("是")){
                            pstmt.setString(1, beginTimeTimeField);
                        }
                        resultSet = pstmt.executeQuery();
                        
                        while(resultSet.next()){
                            //如果该监测点存在PRPS数据                            
                            DataRecord PRPSListDr = new DataRecord();
                            PRPSListDr.put("GUID", resultSet.getString(1));
                            PRPSListDr.put("DeviceID", resultSet.getString(2));
                            PRPSListDr.put("ReceiveTime", resultSet.getString(3));
                            PRPSListDr.put("TimeStamp", resultSet.getString(4));
                            PRPSListDr.put("TimeFieldDataA", resultSet.getBytes(5));
                            PRPSListDr.put("TimeFieldDataB", resultSet.getBytes(6));
                            PRPSListDr.put("TimeFieldDataC", resultSet.getBytes(7));
                            PRPSListDr.put("GUID_QPhi", resultSet.getString(8));
                            PRPSList.add(PRPSListDr);        
                        }
                        
                        if(PRPSList != null && PRPSList.size() > 0){
                            sysLogTimeField.put("isExitTimeFieldDate", isExitTimeFieldDate);
                            if(idTimeField != null ){
                                sysLogTimeField.put("ID", idTimeField);
                            }
                            sysLogTimeField.put("DATA_TYPE_KEY", DATA_TYPE_KEY_TimeField);
                            sysLogTimeField.put("SYN_PROGRESS", (PRPSList.get(PRPSList.size()-1)).getString("ReceiveTime"));
                        }
                                    
                    } catch (SQLException e) {
                        e.printStackTrace();
                    } finally {
                        try {
                            if(resultSet != null){
                                resultSet.close();
                            }
                            if(pstmt != null){
                                pstmt.close();
                            }
                            if(con != null){
                                con.close();
                            }
                        } catch (SQLException e) {
                            e.printStackTrace();
                        }
                    }
                    
                }
                
                // 获得Http客户端(可以理解为:你得先有一个浏览器;注意:实际上HttpClient与浏览器是不一样的)
                CloseableHttpClient httpClient = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
                
                // 创建Post请求
                /*HttpPost httpPost = new HttpPost(Constants.TEST+"/biz/bureauDetect/uploadData.do?action=doPostReceiveData");    */           
                String port = SbpConfig.getProperty("sbp.jiangmen.visualWarningSystem.url");
                HttpPost httpPost = new HttpPost(port+"/biz/bureauDetect/uploadData.do?action=doPostReceiveData");    
                
                params.put("testId", testId);
                if(pdTestDr != null){
                    params.put("pdTestDr", pdTestDr);
                }
                if(test_pointList.size() > 0){
                    params.put("test_pointList", test_pointList);
                }
                if(placeCableDr != null){
                     params.put("placeCableDr", placeCableDr);
                }     
                if(test_cableList.size() > 0){
                    params.put("test_cableList", test_cableList);
                }
                if(test_analysis_resultList.size() > 0){
                    params.put("test_analysis_resultList", test_analysis_resultList);
                }
                if(device_cableList.size() > 0){
                    params.put("device_cableList", device_cableList);
                }
                if(detection_deviceList.size() > 0){
                    params.put("detection_deviceList", detection_deviceList);
                }
               
                if(QPhiList != null && QPhiList.size() > 0){
                    params.put("QPhiList", QPhiList);
                }
                if(PRPDList != null && PRPDList.size() > 0){
                    params.put("PRPDList", PRPDList);
                }
                if(PRPSList != null && PRPSList.size() > 0){
                    params.put("PRPSList", PRPSList);
                }
                if(sysLogQPhi != null){
                    params.put("sysLogQPhi", sysLogQPhi);
                }
                if(sysLogPRPD != null){
                    params.put("sysLogPRPD", sysLogPRPD);
                }
                if(sysLogTimeField != null){
                    params.put("sysLogTimeField", sysLogTimeField);
                }
    
                // 传值时传递的是json字符串,c
                StringEntity entity = new StringEntity(params.toJSONString(), "UTF-8");
               // post请求是将参数放在请求体里面传过去的;这里将entity放入post请求体中
                httpPost.setEntity(entity);              
                httpPost.setHeader("Content-Type", "application/json;charset=utf8");
                 
                // 响应模型
                CloseableHttpResponse response = null;
                try {
                    // 由客户端执行(发送)Post请求
                    response = httpClient.execute(httpPost);
                    // 从响应模型中获取响应实体
                    HttpEntity responseEntity = response.getEntity();         
                    
                    System.out.println("响应状态为:" + response.getStatusLine());
    
                    if (responseEntity != null) {
                        System.out.println("响应内容长度为:" + responseEntity.getContentLength());
                        /*InputStream in =  responseEntity.getContent();
                        BufferedReader br = new BufferedReader(new InputStreamReader(in,"UTF-8"));
                        String line = null;
                        StringBuilder sb = new StringBuilder();
                        while((line = br.readLine())!=null){
                            sb.append(line);
                        }       */
                        //将资料解码
    //                    System.out.println("响应内容为:" + EntityUtils.toString(responseEntity));
                        return EntityUtils.toString(responseEntity);
                    }
               
                } catch (ClientProtocolException e) {
                    e.printStackTrace();
                } catch (ParseException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    try {
                        // 释放资源
                        if (httpClient != null) {
                            httpClient.close();
                        }
                        if (response != null) {
                            response.close();
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }                
        }
            return null;    
    }

    第四步:数据发送到对方服务器,对方服务器的controller:

        /**
         * 
         * @function 数据接收.
         * @author Liangjw  
         * @date 2019-10-11 上午11:01:13
         * @param request
         * @param response
         * @return
         * @throws Exception 
         */
        public void doPostReceiveData(HttpServletRequest request, HttpServletResponse response) throws Exception{
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/html;charset=UTF-8");        
            //创建一个键值对,返回前台:存放上传后返回的结果
            HashMap<String, Object> map = new HashMap<String, Object>();
            
            System.out.println("数据发送过来了!");
            //读取请求内容................获取POST请求:将请求的数据转换成数据流
            //从request域里面读取数据流,InputStreamReader把数据流用指定的字符集读取字节,并解码为字符;
            //通过BufferedReader 流的形式进行流缓存,之后通过readLine方法获取到缓存的内容。    
            BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream(),"UTF-8"));
            String line = null;
            StringBuilder sb = new StringBuilder();
            while((line = br.readLine())!=null){
                sb.append(line);
            }       
            //将资料解码
            String reqData = sb.toString();
            String result = null;
            if(reqData != null && !"".equals(reqData)) {
                JSONObject jsonObject = JSON.parseObject(reqData);            
                if(!jsonObject.isEmpty()) {
                    result = service.receiveData(jsonObject);
                }     
            }
            if(result != null && !"".equals(result)) {            
                PrintWriter writer = response.getWriter();
                writer.write(result);
            }
        }

    第五步:对方服务器中接收发送过来的数据,进行插入/更新等业务逻辑的操作,然后返回数据。

    /**
         * 
         * @function 上传数据接收端.
         * @author Liangjw
         * @date 2019-10-20 上午10:01:01  
         * @param json 上传数据的json格式
         * @return 返回上传结果:“上传成功”或“上传失败”
         */
        @Override
        public String receiveData(JSONObject json) {
            if(json != null) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("TEST_ID", json.getString("testId"));    
                
                //.....插入电缆线路(位置)
                JSONObject pcDr = json.getJSONObject("placeCableDr");
                if(pcDr != null){
                    DataRecord placeCableDr = new DataRecord();
                    if(pcDr.getString("PLACE_ID") != null && !pcDr.getString("PLACE_ID").equals("")){
                        placeCableDr.put("PLACE_ID", pcDr.getString("PLACE_ID"));
                    }
                    if(pcDr.getString("PLACE_NAME") != null && !pcDr.getString("PLACE_NAME").equals("")){
                        placeCableDr.put("PLACE_NAME", pcDr.getString("PLACE_NAME"));
                    }
                    if(pcDr.getString("LAYING_START") != null && !pcDr.getString("LAYING_START").equals("")){
                        placeCableDr.put("LAYING_START", pcDr.getString("LAYING_START"));
                    }
                    if(pcDr.getString("LAYING_FINISH") != null && !pcDr.getString("LAYING_FINISH").equals("")){
                        placeCableDr.put("LAYING_FINISH", pcDr.getString("LAYING_FINISH"));
                    }
                    
                    Map<String, Object> placeIdMap = new HashMap<String, Object>();
                    placeIdMap.put("PLACE_ID", pcDr.getString("PLACE_ID"));
                    DataRecord placeCable2Dr = this.getDao().queryForDataRecord(PATH + "getPlaceCableByPlaceId", placeIdMap);  //查询可视化系统库的电缆线路(位置)表
                    if(placeCable2Dr != null){   //第一步:插入或修改电缆线路数据
                        this.getDao().update("DVC_PLACE_CABLE", placeCableDr, placeIdMap);                     
                    }else{
                        this.getDao().insert("DVC_PLACE_CABLE", placeCableDr);              
                    }        
                }
                
                //.....插入电缆局放检测任务
                JSONObject testDr = json.getJSONObject("pdTestDr");
                if(testDr != null){
                    DataRecord pdTestDr = new DataRecord();
                    if(testDr.getString("TEST_ID") != null && !testDr.getString("TEST_ID").equals("")){
                        pdTestDr.put("TEST_ID", testDr.getString("TEST_ID"));
                    }
                    if(testDr.getString("PLACE_ID") != null && !testDr.getString("PLACE_ID").equals("")){
                        pdTestDr.put("PLACE_ID", testDr.getString("PLACE_ID"));
                    }
                    if(testDr.getString("PLACE_NAME") != null && !testDr.getString("PLACE_NAME").equals("")){
                        pdTestDr.put("PLACE_NAME", testDr.getString("PLACE_NAME"));
                    }
                    if(testDr.getString("WEATHER") != null && !testDr.getString("WEATHER").equals("")){
                        pdTestDr.put("WEATHER", testDr.getString("WEATHER"));
                    }
                    if(testDr.getString("TEMPERATURE") != null && !testDr.getString("TEMPERATURE").equals("")){
                        pdTestDr.put("TEMPERATURE", testDr.getString("TEMPERATURE"));
                    }
                    if(testDr.getString("HUMIDITY") != null && !testDr.getString("HUMIDITY").equals("")){
                        pdTestDr.put("HUMIDITY", testDr.getString("HUMIDITY"));
                    }
                    if(testDr.getString("CABLE_LENGTH") != null && !testDr.getString("CABLE_LENGTH").equals("")){
                        pdTestDr.put("CABLE_LENGTH", testDr.getString("CABLE_LENGTH"));
                    }
                    if(testDr.getDate("BEGIN_TIME") != null && !testDr.getDate("BEGIN_TIME").equals("")){
                        pdTestDr.put("BEGIN_TIME", testDr.getDate("BEGIN_TIME"));
                    }
                    if(testDr.getDate("END_TIME") != null && !testDr.getDate("END_TIME").equals("")){
                        pdTestDr.put("END_TIME", testDr.getDate("END_TIME"));
                    }
                    if(testDr.getString("CAR_NUMBER") != null && !testDr.getString("CAR_NUMBER").equals("")){
                        pdTestDr.put("CAR_NUMBER", testDr.getString("CAR_NUMBER"));
                    }
                    if(testDr.getString("LONGITUDE") != null && !testDr.getString("LONGITUDE").equals("")){
                        pdTestDr.put("LONGITUDE", testDr.getString("LONGITUDE"));
                    }
                    if(testDr.getString("LATITUDE") != null && !testDr.getString("LATITUDE").equals("")){
                        pdTestDr.put("LATITUDE", testDr.getString("LATITUDE"));
                    }
                    if(testDr.getString("TESTERS") != null && !testDr.getString("TESTERS").equals("")){
                        pdTestDr.put("TESTERS", testDr.getString("TESTERS"));
                    }
                    if(testDr.getString("TEST_STATE") != null && !testDr.getString("TEST_STATE").equals("")){
                        pdTestDr.put("TEST_STATE", testDr.getString("TEST_STATE"));
                    }
                    if(testDr.getString("UPLOAD_STATE") != null && !testDr.getString("UPLOAD_STATE").equals("")){
                        pdTestDr.put("UPLOAD_STATE", testDr.getString("UPLOAD_STATE"));
                    }
                    if(testDr.getString("DISCHARGE") != null && !testDr.getString("DISCHARGE").equals("")){
                        pdTestDr.put("DISCHARGE", testDr.getString("DISCHARGE"));
                    }
                                                    
                    DataRecord pdTest2Dr = this.getDao().queryForDataRecord(PATH + "getPDTestByTestId", map);  //查询可视化系统库的检测任务表
                    if(pdTest2Dr != null){                        
                        this.getDao().update("PD_TEST", pdTestDr, map);  //修改检测任务数据,第一个人参数:表名,第二个参数:修改的DataRecord类型的数据,第三个参数:表的主键id    
                    }else{
                        this.getDao().insert("PD_TEST", pdTestDr);  //插入新的检测任务数据,第一个人参数:表名,第二个参数:插入表的DataRecord类型的数据        
                    }
                }
                
                //局放检测装置map
                Map<String, Object> equipmentIdsMap = new HashMap<String, Object>();
                String equipmentIds = "";
                
                //.....插入监测点
                List<JSONObject> test_pointList = json.getJSONArray("test_pointList").toJavaList(JSONObject.class);
                if(test_pointList != null && test_pointList.size() > 0){
                    List<DataRecord> test_pointList2 = new ArrayList<DataRecord>();
                    List<DataRecord> test_point2List = this.getDao().queryForDataSet(PATH + "getTestPointByTestId", map).getResults();  //查询可视化系统库的监测点表
                    for(JSONObject testPointDr2 : test_pointList){
                        DataRecord testPointDr = new DataRecord();
                        if(testPointDr2.getString("TEST_POING_ID") != null && !testPointDr2.getString("TEST_POING_ID").equals("")){
                            testPointDr.put("TEST_POING_ID", testPointDr2.getString("TEST_POING_ID"));
                        }
                        if(testPointDr2.getString("TEST_ID") != null && !testPointDr2.getString("TEST_ID").equals("")){
                            testPointDr.put("TEST_ID", testPointDr2.getString("TEST_ID"));
                        }
                        if(testPointDr2.getString("EQUIPMENT_ID") != null && !testPointDr2.getString("EQUIPMENT_ID").equals("")){
                            testPointDr.put("EQUIPMENT_ID", testPointDr2.getString("EQUIPMENT_ID"));
                        }
                        if(testPointDr2.getString("EQUIPMENT_NAME") != null && !testPointDr2.getString("EQUIPMENT_NAME").equals("")){
                            testPointDr.put("EQUIPMENT_NAME", testPointDr2.getString("EQUIPMENT_NAME"));
                        }
                        if(testPointDr2.getString("CMD_ID") != null && !testPointDr2.getString("CMD_ID").equals("")){
                            testPointDr.put("CMD_ID", testPointDr2.getString("CMD_ID"));
                        }
                        if(testPointDr2.getString("PLACE_ID") != null && !testPointDr2.getString("PLACE_ID").equals("")){
                            testPointDr.put("PLACE_ID", testPointDr2.getString("PLACE_ID"));
                        }
                        if(testPointDr2.getString("PLACE_NAME") != null && !testPointDr2.getString("PLACE_NAME").equals("")){
                            testPointDr.put("PLACE_NAME", testPointDr2.getString("PLACE_NAME"));
                        }
                        if(testPointDr2.getString("TEST_LOCATION") != null && !testPointDr2.getString("TEST_LOCATION").equals("")){
                            testPointDr.put("TEST_LOCATION", testPointDr2.getString("TEST_LOCATION"));
                        }
                        if(testPointDr2.getString("ORDER_NUMBER") != null && !testPointDr2.getString("ORDER_NUMBER").equals("")){
                            testPointDr.put("ORDER_NUMBER", testPointDr2.getString("ORDER_NUMBER"));
                        }
                        
                        test_pointList2.add(testPointDr);
                    }
                    
                    if(test_pointList2.size() > 0){
                        for(DataRecord test_PointDr : test_pointList2){
                            String tempId2 = test_PointDr.getLong("EQUIPMENT_ID").toString()+",";
                            equipmentIds += tempId2;                    
                        }
                    }
                    equipmentIds=(equipmentIds.substring(0,equipmentIds.length()-1)).trim();    
                    equipmentIdsMap.put("equipmentIds", equipmentIds);
                    
                    if(test_point2List != null && test_point2List.size() > 0){
                        for(DataRecord testPointDr : test_pointList2){
                            Map<String, Object> testPointMap = new HashMap<String, Object>();
                            testPointMap.put("TEST_POING_ID", testPointDr.getLong("TEST_POING_ID"));
                            this.getDao().update("PD_TEST_POINT", testPointDr, testPointMap);  //修改监测点数据,第一个人参数:表名,第二个参数:修改的DataRecord类型的数据,第三个参数:表的主键id
                        }        
                    }else{
                        this.getDao().insertBatch(test_pointList2, "PD_TEST_POINT");//插入新的监测点数据,第一个人参数:插入表的List<DataRecord>类型的数据,第二个参数:表名                
                    }
                }
                
                //.....插入检测电缆数据
                List<JSONObject> test_cableList = json.getJSONArray("test_cableList").toJavaList(JSONObject.class);
                if(test_cableList != null && test_cableList.size() > 0){
                    List<DataRecord> test_cable2List = this.getDao().queryForDataSet(PATH + "getTestCableByPlaceId", map).getResults();  //查询可视化系统库的检测电缆表
                    if(test_cable2List != null && test_cable2List.size() > 0){
                        for(JSONObject testCableDr2 : test_cableList){
                            DataRecord testCableDr = new DataRecord();
                            if(testCableDr2.getString("TEST_CABLE_ID") != null && !testCableDr2.getString("TEST_CABLE_ID").equals("")){
                                testCableDr.put("TEST_CABLE_ID", testCableDr2.getString("TEST_CABLE_ID"));
                            }
                            if(testCableDr2.getString("TEST_ID") != null && !testCableDr2.getString("TEST_ID").equals("")){
                                testCableDr.put("TEST_ID", testCableDr2.getString("TEST_ID"));
                            }
                            if(testCableDr2.getString("DEV_ID") != null && !testCableDr2.getString("DEV_ID").equals("")){
                                testCableDr.put("DEV_ID", testCableDr2.getString("DEV_ID"));
                            }
                            
                            Map<String, Object> testCableMap = new HashMap<String, Object>();
                            testCableMap.put("TEST_CABLE_ID", testCableDr2.getString("TEST_CABLE_ID"));
                            this.getDao().update("PD_TEST_CABLE", testCableDr, testCableMap);  //修改检测电缆数据,第一个人参数:表名,第二个参数:修改的DataRecord类型的数据,第三个参数:表的主键id
                        }        
                    }else{
                        List<DataRecord> test_cableList2 = new ArrayList<DataRecord>();
                        for(JSONObject testCableDr2 : test_cableList){
                            DataRecord testCableDr = new DataRecord();
                            if(testCableDr2.getString("TEST_CABLE_ID") != null && !testCableDr2.getString("TEST_CABLE_ID").equals("")){
                                testCableDr.put("TEST_CABLE_ID", testCableDr2.getString("TEST_CABLE_ID"));
                            }
                            if(testCableDr2.getString("TEST_ID") != null && !testCableDr2.getString("TEST_ID").equals("")){
                                testCableDr.put("TEST_ID", testCableDr2.getString("TEST_ID"));
                            }
                            if(testCableDr2.getString("DEV_ID") != null && !testCableDr2.getString("DEV_ID").equals("")){
                                testCableDr.put("DEV_ID", testCableDr2.getString("DEV_ID"));
                            }
                            /*testCableDr.put("TEST_CABLE_ID", testCableDr2.getString("TEST_CABLE_ID"));
                            testCableDr.put("TEST_ID", testCableDr2.getString("TEST_ID"));
                            testCableDr.put("DEV_ID", testCableDr2.getString("DEV_ID"));*/
                            
                            test_cableList2.add(testCableDr);
                        }
                        this.getDao().insertBatch(test_cableList2, "PD_TEST_CABLE");//插入新的监测点数据,第一个人参数:插入表的List<DataRecord>类型的数据,第二个参数:表名                
                    }
                }
                
                //....电缆设备id集map
                Map<String, Object> deviceIdsMap = new HashMap<String, Object>();
                String ids = "";
                
                //.....插入电缆局放检测分析结果
                List<JSONObject> test_analysis_resultList = json.getJSONArray("test_analysis_resultList").toJavaList(JSONObject.class);
                if(test_analysis_resultList != null && test_analysis_resultList.size() > 0){
                    List<DataRecord> test_analysis_result2List = this.getDao().queryForDataSet(PATH + "getTestAnalysisResultByTestId", map).getResults();  //查询可视化系统库的电缆局放检测分析结果
                    List<DataRecord> test_resultList2 = new ArrayList<DataRecord>();
                    for(JSONObject testResultDr2 : test_analysis_resultList){
                        DataRecord testResultDr = new DataRecord();
                        if(testResultDr2.getString("ID") != null && !testResultDr2.getString("ID").equals("")){
                            testResultDr.put("ID", testResultDr2.getString("ID"));
                        }
                        if(testResultDr2.getString("TEST_ID") != null && !testResultDr2.getString("TEST_ID").equals("")){
                            testResultDr.put("TEST_ID", testResultDr2.getString("TEST_ID"));
                        }
                        if(testResultDr2.getString("DEV_ID") != null && !testResultDr2.getString("DEV_ID").equals("")){
                            testResultDr.put("DEV_ID", testResultDr2.getString("DEV_ID"));
                        }
                        if(testResultDr2.getString("DEV_NAME") != null && !testResultDr2.getString("DEV_NAME").equals("")){
                            testResultDr.put("DEV_NAME", testResultDr2.getString("DEV_NAME"));
                        }
                        if(testResultDr2.getString("PHASE") != null && !testResultDr2.getString("PHASE").equals("")){
                            testResultDr.put("PHASE", testResultDr2.getString("PHASE"));
                        }
                        if(testResultDr2.getString("PLACE_ID") != null && !testResultDr2.getString("PLACE_ID").equals("")){
                            testResultDr.put("PLACE_ID", testResultDr2.getString("PLACE_ID"));
                        }
                        if(testResultDr2.getString("PLACE_NAME") != null && !testResultDr2.getString("PLACE_NAME").equals("")){
                            testResultDr.put("PLACE_NAME", testResultDr2.getString("PLACE_NAME"));
                        }
                        if(testResultDr2.getString("DISCHARGE") != null && !testResultDr2.getString("DISCHARGE").equals("")){
                            testResultDr.put("DISCHARGE", testResultDr2.getString("DISCHARGE"));
                        }
                        if(testResultDr2.getString("MAX_PD") != null && !testResultDr2.getString("MAX_PD").equals("")){
                            testResultDr.put("MAX_PD", testResultDr2.getString("MAX_PD"));
                        }
                        if(testResultDr2.getString("DISCHARGE_LOCATION") != null && !testResultDr2.getString("DISCHARGE_LOCATION").equals("")){
                            testResultDr.put("DISCHARGE_LOCATION", testResultDr2.getString("DISCHARGE_LOCATION"));
                        }
                        if(testResultDr2.getString("REASON") != null && !testResultDr2.getString("REASON").equals("")){
                            testResultDr.put("REASON", testResultDr2.getString("REASON"));
                        }
                        if(testResultDr2.getString("POSITION") != null && !testResultDr2.getString("POSITION").equals("")){
                            testResultDr.put("POSITION", testResultDr2.getString("POSITION"));
                        }
                        if(testResultDr2.getDate("TEST_TIME") != null && !testResultDr2.getDate("TEST_TIME").equals("")){
                            testResultDr.put("TEST_TIME", testResultDr2.getDate("TEST_TIME"));
                        }
                        if(testResultDr2.getString("PD_STATE") != null && !testResultDr2.getString("PD_STATE").equals("")){
                            testResultDr.put("PD_STATE", testResultDr2.getString("PD_STATE"));
                        }
                        
                        test_resultList2.add(testResultDr);
                        
                    }
                    
                    if(test_resultList2.size() > 0){
                        for(DataRecord arDr : test_resultList2){
                            String tempId = arDr.getLong("DEV_ID").toString()+",";
                            ids += tempId;                    
                        }
                    }
                    ids=(ids.substring(0,ids.length()-1)).trim();    
                    deviceIdsMap.put("ids", ids);
                    
                    if(test_analysis_result2List != null && test_analysis_result2List.size() > 0){  //可视化已存在数据:修改
                        for(DataRecord testResultDr : test_resultList2){
                            Map<String, Object> testResultMap = new HashMap<String, Object>();
                            testResultMap.put("ID", testResultDr.getString("ID"));
                            this.getDao().update("PD_TEST_ANALYSIS_RESULT", testResultDr, testResultMap);  
                        }        
                    }else{   //可视化不存在数据:新增
                        for(DataRecord testResultDr : test_resultList2){
                            this.getDao().insert("PD_TEST_ANALYSIS_RESULT", testResultDr);
                        }
                        
                    /*    this.getDao().insertBatch(test_resultList2, "PD_TEST_ANALYSIS_RESULT2");        */
                    }
                }
                
                //插入电缆设备
                List<JSONObject> device_cableList = json.getJSONArray("device_cableList").toJavaList(JSONObject.class);
                if(device_cableList != null && device_cableList.size() > 0){
                    List<DataRecord> dev_cableList2 = new ArrayList<DataRecord>();
                    for(JSONObject dev_cable : device_cableList){
                        DataRecord dev_cableDr = new DataRecord();
                        if(dev_cable.getString("DEV_ID") != null && !dev_cable.getString("DEV_ID").equals("")){
                            dev_cableDr.put("DEV_ID", dev_cable.getString("DEV_ID"));
                        }
                        if(dev_cable.getString("DEV_NAME") != null && !dev_cable.getString("DEV_NAME").equals("")){
                            dev_cableDr.put("DEV_NAME", dev_cable.getString("DEV_NAME"));
                        }
                        if(dev_cable.getString("PHASE") != null && !dev_cable.getString("PHASE").equals("")){
                            dev_cableDr.put("PHASE", dev_cable.getString("PHASE"));
                        }
                        if(dev_cable.getString("NOMINAL_AREA") != null && !dev_cable.getString("NOMINAL_AREA").equals("")){
                            dev_cableDr.put("NOMINAL_AREA", dev_cable.getString("NOMINAL_AREA"));
                        }
                        if(dev_cable.getString("POWER_LEVEL") != null && !dev_cable.getString("POWER_LEVEL").equals("")){
                            dev_cableDr.put("POWER_LEVEL", dev_cable.getString("POWER_LEVEL"));
                        }
                        if(dev_cable.getString("STRUCTURE_TYPE") != null && !dev_cable.getString("STRUCTURE_TYPE").equals("")){
                            dev_cableDr.put("STRUCTURE_TYPE", dev_cable.getString("STRUCTURE_TYPE"));
                        }
                        if(dev_cable.getString("INSULATION") != null && !dev_cable.getString("INSULATION").equals("")){
                            dev_cableDr.put("INSULATION", dev_cable.getString("INSULATION"));
                        }
                        if(dev_cable.getString("WIRE_CORE_NUM") != null && !dev_cable.getString("WIRE_CORE_NUM").equals("")){
                            dev_cableDr.put("WIRE_CORE_NUM", dev_cable.getString("WIRE_CORE_NUM"));
                        }
                        if(dev_cable.getString("LAYING_ENVIRONMENT") != null && !dev_cable.getString("LAYING_ENVIRONMENT").equals("")){
                            dev_cableDr.put("LAYING_ENVIRONMENT", dev_cable.getString("LAYING_ENVIRONMENT"));
                        }
                        if(dev_cable.getString("LENGTH") != null && !dev_cable.getString("LENGTH").equals("")){
                            dev_cableDr.put("LENGTH", dev_cable.getString("LENGTH"));
                        }
                        if(dev_cable.getString("PLACE_ID") != null && !dev_cable.getString("PLACE_ID").equals("")){
                            dev_cableDr.put("PLACE_ID", dev_cable.getString("PLACE_ID"));
                        }
                        
                        dev_cableList2.add(dev_cableDr);
                    }
                    List<DataRecord> device_cable2List = this.getDao().queryForDataSet(PATH + "getDeviceCableByDeviceId", deviceIdsMap).getResults();  //查询可视化系统库的电缆设备
                    if(device_cable2List != null && device_cable2List.size() > 0){
                        for(DataRecord deviceCableDr : dev_cableList2){
                            Map<String, Object> deviceIdMap = new HashMap<String, Object>();
                            deviceIdMap.put("DEV_ID", deviceCableDr.getLong("DEV_ID"));
                            this.getDao().update("DVC_DEVICE_CABLE", deviceCableDr, deviceIdMap);  
                        }    
                    }else{
                        this.getDao().insertBatch(dev_cableList2, "DVC_DEVICE_CABLE");
                    }
                }
                
                //插入局放检测装置
                List<JSONObject> detection_deviceList = json.getJSONArray("detection_deviceList").toJavaList(JSONObject.class);
                if(detection_deviceList != null && detection_deviceList.size() > 0){
                    List<DataRecord> detection_deviceList2 = new ArrayList<DataRecord>();
                    for(JSONObject detection_device : detection_deviceList){
                        DataRecord detection_deviceDr = new DataRecord();
                        if(detection_device.getString("EQUIPMENT_ID") != null && !detection_device.getString("EQUIPMENT_ID").equals("")){
                            detection_deviceDr.put("EQUIPMENT_ID", detection_device.getString("EQUIPMENT_ID"));
                        }
                        if(detection_device.getString("EQUIPMENT_NAME") != null && !detection_device.getString("EQUIPMENT_NAME").equals("")){
                            detection_deviceDr.put("EQUIPMENT_NAME", detection_device.getString("EQUIPMENT_NAME"));
                        }
                        if(detection_device.getString("CMD_ID") != null && !detection_device.getString("CMD_ID").equals("")){
                            detection_deviceDr.put("CMD_ID", detection_device.getString("CMD_ID"));
                        }
                        if(detection_device.getString("USE_STATE") != null && !detection_device.getString("USE_STATE").equals("")){
                            detection_deviceDr.put("USE_STATE", detection_device.getString("USE_STATE"));
                        }
                        if(detection_device.getString("CONNECT_STATE") != null && !detection_device.getString("CONNECT_STATE").equals("")){
                            detection_deviceDr.put("CONNECT_STATE", detection_device.getString("CONNECT_STATE"));
                        }
                        
                        detection_deviceList2.add(detection_deviceDr);
                    }
                    List<DataRecord> detection_device2List = this.getDao().queryForDataSet(PATH + "getDetectionDeviceByEquipmentIds", equipmentIdsMap).getResults();  //查询可视化系统库的局放检测装置
                    if(detection_device2List.size() > 0){
                        for(DataRecord detectionDeviceDr : detection_deviceList2){
                            Map<String, Object> detectionDeviceIdMap = new HashMap<String, Object>();
                            detectionDeviceIdMap.put("EQUIPMENT_ID", detectionDeviceDr.getLong("EQUIPMENT_ID"));
                            this.getDao().update("PD_DETECTION_DEVICE", detectionDeviceDr, detectionDeviceIdMap);  
                        }    
                    }else{
                        this.getDao().insertBatch(detection_deviceList2, "PD_DETECTION_DEVICE");
                    }
                }
                
                //接收QPhi集
                List<JSONObject> QPhiList = new ArrayList<JSONObject>();
                if(json.containsKey("QPhiList") == true){
                    QPhiList = json.getJSONArray("QPhiList").toJavaList(JSONObject.class);
                }
                
                //接收PRPD集
                List<JSONObject> PRPDList = new ArrayList<JSONObject>();
                if(json.containsKey("PRPDList") == true){
                    PRPDList = json.getJSONArray("PRPDList").toJavaList(JSONObject.class);
                }
                
                //接收TimeField集
                List<JSONObject> PRPSList = new ArrayList<JSONObject>();
                if(json.containsKey("PRPSList") == true){
                    PRPSList = json.getJSONArray("PRPSList").toJavaList(JSONObject.class);
                }            
                
                Connection con = DBConnectUtil.getConnection();
                PreparedStatement pstmt = null;
                ResultSet resultSet = null;
                
                JSONObject sysLogQPhi = json.getJSONObject("sysLogQPhi");
                Boolean flagQPhi = false;
                if(sysLogQPhi != null){
                    if("是".equals(sysLogQPhi.getString("ISEXITQPHIDATE"))){
                        flagQPhi = true;
                    }
                }
                DataRecord systemLogQPhi = new DataRecord();
                Map<String, Object> mapQPhi = new HashMap<String, Object>();
                
                JSONObject sysLogPRPD = json.getJSONObject("sysLogPRPD");
                Boolean flagPRPD = false;
                if(sysLogPRPD != null){
                    if("是".equals(sysLogPRPD.getString("ISEXITPRPDDATE"))){
                        flagPRPD = true;
                    }
                }
                DataRecord systemLogPRPD = new DataRecord();
                Map<String, Object> mapPRPD = new HashMap<String, Object>();
                
                
                JSONObject sysLogTimeField = json.getJSONObject("sysLogTimeField");
                Boolean flagTimeField = false;
                if(sysLogTimeField != null){
                    if("是".equals(sysLogTimeField.getString("ISEXITTIMEFIELDDATE"))){
                        flagTimeField = true;
                    }
                }
                DataRecord systemLogTimeField = new DataRecord();
                Map<String, Object> mapTimeField = new HashMap<String, Object>();
                
                try {
                    //QPhi
                    if(QPhiList != null && QPhiList.size() > 0){
                        String insertSqlQPhi = "insert into tb_QPhiData(GUID, DeviceID, ReceiveTime, TimeStamp, PhaseDataA, PDDataA, PhaseDataB, PDDataB, PhaseDataC, PDDataC, PhaseFreq) values(?, ?, ? , ? , ? , ? , ? , ? , ? , ?, ?)";
                        pstmt = con.prepareStatement(insertSqlQPhi);
                        con.setAutoCommit(false);
                        for(JSONObject QPhi : QPhiList){
                            pstmt.setString(1, QPhi.getString("GUID"));
                            pstmt.setString(2, QPhi.getString("DEVICEID"));
                            pstmt.setString(3, QPhi.getString("RECEIVETIME"));
                            pstmt.setString(4, QPhi.getString("TIMESTAMP"));
                            pstmt.setBytes(5, QPhi.getBytes("PHASEDATAA"));
                            pstmt.setBytes(6, QPhi.getBytes("PDDATAA"));
                            pstmt.setBytes(7, QPhi.getBytes("PHASEDATAB"));
                            pstmt.setBytes(8, QPhi.getBytes("PDDATAB"));
                            pstmt.setBytes(9, QPhi.getBytes("PHASEDATAC"));
                            pstmt.setBytes(10, QPhi.getBytes("PDDATAC"));
                            pstmt.setString(11, QPhi.getString("PHASEFREQ"));
                            /*pstmt.executeUpdate();    */  //一条一条的插入
                            pstmt.addBatch();                      //批量插入
                        }
                        pstmt.executeBatch();
                        con.commit();
                        if(flagQPhi){
                            mapQPhi.put("ID", sysLogQPhi.getString("ID"));
                            mapQPhi.put("DATA_TYPE_KEY", sysLogQPhi.getString("DATA_TYPE_KEY"));
                            mapQPhi.put("SYN_PROGRESS", sysLogQPhi.getString("SYN_PROGRESS"));
                            this.getDao().updateByStatement(PATH + "editSysSynLOG", mapQPhi);
                        }else{
                            systemLogQPhi.put("ID", this.getDao().generateId());
                            systemLogQPhi.put("DATA_TYPE_KEY", sysLogQPhi.getString("DATA_TYPE_KEY"));
                            systemLogQPhi.put("SYN_PROGRESS", sysLogQPhi.getString("SYN_PROGRESS"));
                            this.getDao().insert("SYS_SYN_LOG", systemLogQPhi);
                        }
                    }
                    
                    //PRPD
                    if(PRPDList != null && PRPDList.size() > 0){
                        String insertSqldeleteSqlPRPD = "insert into tb_PRPDData(GUID, DeviceID, ReceiveTime, TimeStamp, PhaseDataA, PRPDDataA, PhaseDataB, PRPDDataB, PhaseDataC, PRPDDataC) values(?, ?, ? , ? , ? , ? , ? , ? , ? , ?)";
                        pstmt = con.prepareStatement(insertSqldeleteSqlPRPD);
                        con.setAutoCommit(false);
                        for(JSONObject prpd : PRPDList){
                            pstmt.setString(1, prpd.getString("GUID"));
                            pstmt.setString(2, prpd.getString("DEVICEID"));
                            pstmt.setString(3, prpd.getString("RECEIVETIME"));
                            pstmt.setString(4, prpd.getString("TIMESTAMP"));
                            pstmt.setBytes(5, prpd.getBytes("PHASEDATAA"));
                            pstmt.setBytes(6, prpd.getBytes("PRPDDATAA"));
                            pstmt.setBytes(7, prpd.getBytes("PHASEDATAB"));
                            pstmt.setBytes(8, prpd.getBytes("PRPDDATAB"));
                            pstmt.setBytes(9, prpd.getBytes("PHASEDATAC"));
                            pstmt.setBytes(10, prpd.getBytes("PRPDDATAC"));
                            /*pstmt.executeUpdate();    */
                            pstmt.addBatch();        
                        }
                        pstmt.executeBatch();
                        con.commit();
                        if(flagPRPD){
                            mapPRPD.put("ID", sysLogPRPD.getString("ID"));
                            mapPRPD.put("DATA_TYPE_KEY", sysLogPRPD.getString("DATA_TYPE_KEY"));
                            mapPRPD.put("SYN_PROGRESS", sysLogPRPD.getString("SYN_PROGRESS"));
                            this.getDao().updateByStatement(PATH + "editSysSynLOG", mapPRPD);
                        }else{
                            systemLogPRPD.put("ID", this.getDao().generateId());
                            systemLogPRPD.put("DATA_TYPE_KEY", sysLogPRPD.getString("DATA_TYPE_KEY"));
                            systemLogPRPD.put("SYN_PROGRESS", sysLogPRPD.getString("SYN_PROGRESS"));
                            this.getDao().insert("SYS_SYN_LOG", systemLogPRPD);
                        }
                    }
                    
                    //TimeField
                    if(PRPSList != null && PRPSList.size() > 0){
                        String insertSqldeleteSqlPRPS = "insert into tb_TimeFieldData(GUID, DeviceID, ReceiveTime, TimeStamp, TimeFieldDataA, TimeFieldDataB, TimeFieldDataC, GUID_QPhi) values(?, ?, ? , ? , ? , ? , ? , ? )";
                        pstmt = con.prepareStatement(insertSqldeleteSqlPRPS);
                        con.setAutoCommit(false);
                        for(JSONObject prprs : PRPSList){
                            pstmt.setString(1, prprs.getString("GUID"));
                            pstmt.setString(2, prprs.getString("DEVICEID"));
                            pstmt.setString(3, prprs.getString("RECEIVETIME"));
                            pstmt.setString(4, prprs.getString("TIMESTAMP"));
                            pstmt.setBytes(5, prprs.getBytes("TIMEFIELDDATAA"));
                            pstmt.setBytes(6, prprs.getBytes("TIMEFIELDDATAB"));
                            pstmt.setBytes(7, prprs.getBytes("TIMEFIELDDATAC"));
                            pstmt.setString(8, prprs.getString("GUID_QPHI"));
                            /*pstmt.executeUpdate();        */
                            pstmt.addBatch();        
                        }
                        pstmt.executeBatch();
                        con.commit();
                        if(flagTimeField){
                            mapTimeField.put("ID", sysLogTimeField.getString("ID"));
                            mapTimeField.put("DATA_TYPE_KEY", sysLogTimeField.getString("DATA_TYPE_KEY"));
                            mapTimeField.put("SYN_PROGRESS", sysLogTimeField.getString("SYN_PROGRESS"));
                            this.getDao().updateByStatement(PATH + "editSysSynLOG", mapTimeField);
                        }else{
                            systemLogTimeField.put("ID", this.getDao().generateId());
                            systemLogTimeField.put("DATA_TYPE_KEY", sysLogTimeField.getString("DATA_TYPE_KEY"));
                            systemLogTimeField.put("SYN_PROGRESS", sysLogTimeField.getString("SYN_PROGRESS"));
                            this.getDao().insert("SYS_SYN_LOG", systemLogTimeField);
                        }
                    }
                    
                } catch (SQLException e) {
                    e.printStackTrace();
                } finally {
                    try {
                        if(resultSet != null){
                            resultSet.close();
                        }
                        if(pstmt != null){
                            pstmt.close();
                        }
                        if(con != null){
                            con.close();
                        }
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                }
                
                return "上传成功";
            }
            return "上传失败";
        }

    第六步:还需要你在双方后台配置文件配置不拦截对方的请求路径(可以只配置这个包下的这个接口的请求路径不拦截!)

    注:双方都要配置不设防该请求的拦截。

    前端调用代码:

    <a href="javascript: uploadData();" class="xs-btn btn_a" style="margin-left: 10px; ">上传数据</a>
    //JavaScirpt部分:
         //
    上传数据 function uploadData(){ var testId = $("#TEST_ID").val(); $.ajax({ type: "post", dataType: 'text', url: "<c:url value='/ajax'/>", data: { service: 'com.shd.biz.bureauDetect.uploadData.service.uploadDataService', method: 'uploadData', params: [testId] }, beforeSend: function(){ // 请求后的等待界面 $("#ajaxProgressDiv").css("display", "block"); }, success: function(data){ $("#ajaxProgressDiv").css("display", "none"); alert(data.substring(16,20)); } , error: function(XMLHttpRequest, textStatus, errorThrown){ //查看错误信息 alert(XMLHttpRequest.status); alert(XMLHttpRequest.readyState); alert(textStatus); } }) }

    好了,完事,其实实现步骤不难,理解后就发现挺简单的。(上面的内容之所以很长,主要是我的原代码需要处理的数据的有点多(关联的表数据太多了),哈哈哈哈~)

  • 相关阅读:
    连接数据库的几种方式
    c#拖拽文件
    设置webbrowser浏览器内核
    C#控件置于底层或顶层
    C#中读取xml文件指定节点
    关于selenium python Message: unknown error: Element is not clickable at point错误
    Linux的命令操作
    MySQL数据库的知识
    没有添加main方法
    eclipse导入已建工程
  • 原文地址:https://www.cnblogs.com/4AMLJW/p/httpclient20200413110000.html
Copyright © 2011-2022 走看看