GainGrossWt.java 1.7 KB
package com.sy.logic;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import org.springframework.stereotype.Component;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Map;

@Component
public class GainGrossWt {

    /**
     * @Param waybill 主单号
     * @Param imp 进出港标识
     * @Result 获取运单重量
     * */

    //根据主单号和进出标志获取运单重量
    public static double getGrossWt(String waybill, String imp) {

        String url = "http://tjfx.15miaoo.com:8003/tj/orig/orig?waybill=" + waybill + "&imp=" + imp;
        StringBuilder json = new StringBuilder();
        Map map = null;
        double bg = 0;
        try {
            URL oracle = new URL(url);
            URLConnection yc = oracle.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
            String inputLine = null;
            while ((inputLine = in.readLine()) != null) {
                json.append(inputLine);
            }
            JSONArray array = JSONArray.parseArray(json.toString());
            for (int i = 0; i < array.size(); i++) {
                map = JSON.parseObject(array.getString(i));
                if (map.get("receiptinformation").toString().startsWith("41301")) {
                    bg = Double.parseDouble((String) map.get("totalweight"));
                    return bg;
                }
            }
            in.close();
        } catch (MalformedURLException e) {
            e.getMessage();
        } catch (IOException e) {
            e.getMessage();
        }
        return bg;
    }
}