package org.ta.pddserver.utils;

import java.util.HashMap;
import java.util.Map;

public class PddOverseaPriceTool {

    //首重重量
    private static int initialWeight = 1000;
    //上限重量
    private static int maxWeight = 20000;

    // 普货首重价格
    private static int gInitalPrice = 1850;

    //特货首重价格
    private static int sInitalPrice = 2800;

    //超重计费标准
    private static int excessWeight = 500;

    //超重价格
    private static int excessPrice = 175;

    //标椎三边长度
    private static int standard = 100;

    //标准三边之和
    private static int maxStandard = 160;


    /*
     * 根据类型、重量（g） 计算运费
     * */
    public static Map FreightCostCalculation(String type, int length, int width, int height, int weight, int exchange) {
        Map map = new HashMap();

        int price = 0;
        boolean key = true;
        int excess = 0;
        int max = length + width + height;

        //判断边长是否符合标准
        if (length > standard || width > standard || height > standard || max > maxStandard) {
            //三边各超100或者和超160
            key = false;
        } else {

            // 判断重量是否超重
            if (weight > maxWeight) {
                //超重无法计算
                key = false;
            } else {
                //分析重量
                if (weight > initialWeight) {
                    //计算超出重量
                    weight = weight - initialWeight;
                    excess = excessPrice * ((int) Math.ceil(weight / excessWeight));
                }
            }

            if (key) {
                //计算价格
                if (type.equals("NORMAL")) {
                    //普货
                    price = gInitalPrice + excess;

                } else {
                    price = sInitalPrice + excess;
                }
            }
        }
        map.put("price", price);
        map.put("key", key);
        return map;
    }
}
