package lingtao.net.util;

import com.aspose.pdf.Document;
import com.aspose.pdf.optimization.OptimizationOptions;
import lingtao.net.bean.Product;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

/**
 * A级铜版纸不干胶价格
 */
public class AStickersPrice {

    int bigCountArr[] = {500, 1000, 2000, 3000, 5000, 10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000,
            100000};

    double AreaArr[] = {0.004, 0.006, 0.008, 0.01, 0.012, 0.015, 0.017, 0.018, 0.02, 0.03, 0.04, 0.06, 0.1, 0.2, 0.3};

    // 9*5.4cm(一个名片位)以内价格
    public List<Product> oneCradPrice(int count, String role) {
        List<Product> list = new ArrayList<Product>();
        Product pro = new Product();
        int bigCountArr[] = {500, 1000, 2000, 3000, 5000, 10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000};
        int[] priceArr;
        priceArr = new int[]{60, 70, 95, 125, 175, 270, 510, 800, 1000, 1200, 1400, 1600, 1800, 2000, 2200};

        for (int i = 0; i < bigCountArr.length; i++) {
            if (bigCountArr[i] < count || list.size() > 5) {
                continue;
            }
            pro = new Product();
            pro.setCount(bigCountArr[i]);
            pro.setPrice(Math.ceil(priceArr[i]));
            list.add(pro);
        }
        return list;
    }

    // 20*1以内
    public List<Product> getPriceLess20(int count) {
        List<Product> list = new ArrayList<Product>();
        Product pro = new Product();
        int bigCountArr[] = {500, 1000, 2000, 3000, 5000, 10000, 20000, 30000, 40000};
        int priceArr[] = {80, 90, 150, 180, 200, 240, 400, 580, 720};
        if (count <= 40000) {
            for (int i = 0; i < bigCountArr.length; i++) {
                if (bigCountArr[i] < count) {
                    continue;
                }
                pro = new Product();
                pro.setCount(bigCountArr[i]);
                pro.setPrice(Math.ceil(priceArr[i]));
                list.add(pro);
            }
        } else {
            pro = new Product();
            pro.setCount(count);
            pro.setPrice(Math.ceil((Math.ceil(count / 10000.0) - 4) * 150 + 720));
            list.add(pro);
        }
        return list;
    }

    // 48*1以内
    public List<Product> getPriceLess48(int count) {
        List<Product> list = new ArrayList<Product>();
        Product pro = new Product();
        int bigCountArr[] = {500, 1000, 2000, 3000, 5000, 10000, 20000, 30000, 40000};
        int priceArr[] = {90, 100, 160, 190, 230, 420, 760, 1100, 1400};
        if (count <= 40000) {
            for (int i = 0; i < bigCountArr.length; i++) {
                if (bigCountArr[i] < count) {
                    continue;
                }
                pro = new Product();
                pro.setCount(bigCountArr[i]);
                pro.setPrice(Math.ceil(priceArr[i]));
                list.add(pro);
            }
        } else {
            pro = new Product();
            pro.setCount(count);
            pro.setPrice(Math.ceil((Math.ceil(count / 10000.0) - 4) * 300 + 1400));
            list.add(pro);
        }
        return list;
    }

    // 60*1以内
    public List<Product> getPriceLess60(int count) {
        List<Product> list = new ArrayList<Product>();
        Product pro = new Product();
        int bigCountArr[] = {500, 1000, 2000, 3000, 5000, 10000, 20000, 30000, 40000};
        int priceArr[] = {100, 120, 180, 230, 300, 550, 960, 1300, 1600};
        if (count <= 40000) {
            for (int i = 0; i < bigCountArr.length; i++) {
                if (bigCountArr[i] < count) {
                    continue;
                }
                pro = new Product();
                pro.setCount(bigCountArr[i]);
                pro.setPrice(Math.ceil(priceArr[i]));
                list.add(pro);
            }
        } else {
            pro = new Product();
            pro.setCount(count);
            pro.setPrice(Math.ceil((Math.ceil(count / 10000.0) - 4) * 400 + 1600));
            list.add(pro);
        }
        return list;
    }

    // 70*1以内
    public List<Product> getPriceLess70(int count) {
        List<Product> list = new ArrayList<Product>();
        Product pro = new Product();
        int bigCountArr[] = {500, 1000, 2000, 3000, 5000, 10000, 20000, 30000, 40000};
        int priceArr[] = {110, 130, 200, 270, 330, 580, 1100, 1500, 1900};
        if (count <= 40000) {
            for (int i = 0; i < bigCountArr.length; i++) {
                if (bigCountArr[i] < count) {
                    continue;
                }
                pro = new Product();
                pro.setCount(bigCountArr[i]);
                pro.setPrice(Math.ceil(priceArr[i]));
                list.add(pro);
            }
        } else {
            pro = new Product();
            pro.setCount(count);
            pro.setPrice(Math.ceil((Math.ceil(count / 10000.0) - 4) * 400 + 1900));
            list.add(pro);
        }
        return list;
    }

    // 80*1以内
    public List<Product> getPriceLess80(int count) {
        List<Product> list = new ArrayList<Product>();
        Product pro = new Product();
        int bigCountArr[] = {500, 1000, 2000, 3000, 5000, 10000, 20000, 30000, 40000};
        int priceArr[] = {130, 150, 240, 300, 380, 650, 1200, 1650, 2100};
        if (count <= 40000) {
            for (int i = 0; i < bigCountArr.length; i++) {
                if (bigCountArr[i] < count) {
                    continue;
                }
                pro = new Product();
                pro.setCount(bigCountArr[i]);
                pro.setPrice(Math.ceil(priceArr[i]));
                list.add(pro);
            }
        } else {
            pro = new Product();
            pro.setCount(count);
            pro.setPrice(Math.ceil((Math.ceil(count / 10000.0) - 4) * 450 + 2100));
            list.add(pro);
        }
        return list;
    }

    // 90*1以内
    public List<Product> getPriceLess90(int count) {
        List<Product> list = new ArrayList<Product>();
        Product pro = new Product();
        int bigCountArr[] = {500, 1000, 2000, 3000, 5000, 10000, 20000, 30000, 40000};
        int priceArr[] = {150, 170, 245, 320, 420, 750, 1300, 1750, 2200};
        if (count <= 40000) {
            for (int i = 0; i < bigCountArr.length; i++) {
                if (bigCountArr[i] < count) {
                    continue;
                }
                pro = new Product();
                pro.setCount(bigCountArr[i]);
                pro.setPrice(Math.ceil(priceArr[i]));
                list.add(pro);
            }
        } else {
            pro = new Product();
            pro.setCount(count);
            pro.setPrice(Math.ceil((Math.ceil(count / 10000.0) - 4) * 450 + 2200));
            list.add(pro);
        }
        return list;
    }

    // 100*1以内
    public List<Product> getPriceLess100(int count) {
        List<Product> list = new ArrayList<Product>();
        Product pro = new Product();
        int bigCountArr[] = {500, 1000, 2000, 3000, 5000, 10000, 20000, 30000, 40000};
        int priceArr[] = {170, 200, 260, 350, 480, 860, 1400, 2000, 2600};
        if (count <= 40000) {
            for (int i = 0; i < bigCountArr.length; i++) {
                if (bigCountArr[i] < count) {
                    continue;
                }
                pro = new Product();
                pro.setCount(bigCountArr[i]);
                pro.setPrice(Math.ceil(priceArr[i]));
                list.add(pro);
            }
        } else {
            pro = new Product();
            pro.setCount(count);
            pro.setPrice(Math.ceil((Math.ceil(count / 10000.0) - 4) * 600 + 2600));
            list.add(pro);
        }
        return list;
    }

    // 面积在0.003内
    public List<Product> getPrice(int count) {
        List<Product> list = new ArrayList<Product>();
        Product pro = new Product();
        int bigCountArr[] = {500, 1000, 2000, 3000, 5000, 10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000};
        int priceArr[] = {65, 75, 100, 130, 180, 275, 515, 805, 1005, 1205, 1405, 1605, 1805, 2005, 2205};
        if (count <= 40000) {
            for (int i = 0; i < bigCountArr.length; i++) {
                if (bigCountArr[i] < count || list.size() > 5) {
                    continue;
                }
                pro = new Product();
                pro.setCount(bigCountArr[i]);
                pro.setPrice(Math.ceil(priceArr[i]));
                list.add(pro);
            }
        } else {
            pro = new Product();
            pro.setCount(count);
            pro.setPrice(Math.ceil((Math.ceil(count / 10000.0) - 4) * 200 + 850));
            list.add(pro);
        }
        return list;
    }

    public List<Product> f_getPrice(int priceArr[], int count, String craftMo) {
        List<Product> list = new ArrayList<Product>();
        Product p = new Product();
        int countArr[] = {500, 1000, 2000, 3000, 5000, 10000, 20000, 30000, 40000, 50000};
        for (int i = 0; i < countArr.length; i++) {
            if (countArr[i] < count || list.size() > 3) {
                continue;
            }
            p = new Product();
            p.setCount(countArr[i]);
            if ("覆哑膜".equals(craftMo)) {
                p.setPrice(Math.ceil(Double.valueOf(priceArr[i]) * 1.2));
            } else {
                p.setPrice(Double.valueOf(priceArr[i]));
            }

            list.add(p);
        }

        return list;
    }

    // 根据面积计算价格
    private List<Product> bigSizeAcountPrice(int count, Double area, List<Product> list, double[] priceArr) {
        Product pro = new Product();
        if (count > bigCountArr[bigCountArr.length - 1]) {
            pro.setCount(count);
            pro.setPrice(Math.ceil(area * count * priceArr[bigCountArr.length - 1]));
            list.add(pro);
        }
        for (int i = 0; i < bigCountArr.length; i++) {
            if (bigCountArr[i] < count || list.size() > 3) {
                continue;
            }

            double[] arrPrice = new double[16];
            if (bigCountArr[i] == 500) {
                arrPrice = new double[]{37, 33, 30, 26, 25, 21, 19, 18, 17, 19, 17, 12.8, 12.5, 12, 11.5, 11};
            } else if (bigCountArr[i] == 1000) {
                arrPrice = new double[]{21, 19, 17, 17, 15, 14, 14, 12, 12, 12.5, 13, 9, 9, 8, 8, 7.8};
            } else if (bigCountArr[i] == 2000) {
                arrPrice = new double[]{14, 13, 13, 12, 11, 11, 10, 10, 9, 10, 11, 7.8, 7.5, 7.5, 7.2, 7};
            } else if (bigCountArr[i] == 3000) {
                arrPrice = new double[]{12, 11, 11, 10, 9, 9.5, 9, 8, 8, 9, 10, 6.8, 6.5, 6.5, 6, 6.5};
            } else if (bigCountArr[i] == 5000) {
                arrPrice = new double[]{10, 9.5, 8, 7.8, 8.5, 9, 8.3, 7, 8, 6.5, 8, 6, 6, 6, 5.5, 5};
            } else if (bigCountArr[i] == 10000) {
                arrPrice = new double[]{8, 7.5, 6.5, 6.5, 7.6, 8, 7.3, 6, 7.5, 6, 6, 6, 6, 6, 5, 5};
            } else if (bigCountArr[i] == 20000) {
                arrPrice = new double[]{7.6, 6.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5, 4.5};
            } else if (bigCountArr[i] == 30000) {
                arrPrice = new double[]{7.6, 6.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5, 4.5};
            } else if (bigCountArr[i] == 40000) {
                arrPrice = new double[]{7.6, 6.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5, 4.5};
            } else if (bigCountArr[i] == 50000) {
                arrPrice = new double[]{7.5, 6.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5, 4.5};
            } else if (bigCountArr[i] == 60000) {
                arrPrice = new double[]{7.5, 6.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5, 4.5};
            } else if (bigCountArr[i] == 70000) {
                arrPrice = new double[]{7.5, 6.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5, 4.5};
            } else if (bigCountArr[i] == 80000) {
                arrPrice = new double[]{7.5, 6.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5, 4.5};
            } else if (bigCountArr[i] == 90000) {
                arrPrice = new double[]{7.5, 6.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5, 4.5};
            } else if (bigCountArr[i] == 100000) {
                arrPrice = new double[]{7.5, 6.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5, 4.5};
            }

            double pirce = getPrcieInArea(bigCountArr[i], area, arrPrice);
            pro = new Product();
            pro.setCount(bigCountArr[i]);
            pro.setPrice(Math.ceil(pirce));

            list.add(pro);
        }
        return list;
    }

    // 判断小尺寸是否大于大尺寸价格
    private double getPrcieInArea(int count, Double area, double[] priceArr) {
        double lastPrice = 0, price = 0;
        if (area > AreaArr[AreaArr.length - 1]) {
            price = area * count * priceArr[AreaArr.length - 1];
            lastPrice = area * count * priceArr[AreaArr.length - 2];
            if (lastPrice > price) {
                price = lastPrice;
            }
        }
        for (int i = 0; i < AreaArr.length; i++) {
            if (AreaArr[i] < area) {
                continue;
            }
            double lastArea = 0;
            if (i > 0) {
                lastArea = AreaArr[i - 1];
                lastPrice = lastArea * count * priceArr[i - 1];
            }
            price = area * count * priceArr[i];
            if (lastPrice > price) {
                price = lastPrice;
            }
            break;
        }

        return price;
    }

    public List<Product> getPrice(int count, Double area, String role) {
        List<Product> list = new ArrayList<Product>();
        double[] priceArrA = new double[16];


        if (area <= 0.004) {
            priceArrA = new double[]{37.0, 21.0, 14.0, 12.0, 10.0, 8.0, 7.6, 7.6, 7.6, 7.5, 7.5, 7.5, 7.5, 7.5, 7.5, 7.5};
        } else if (area <= 0.006) {
            priceArrA = new double[]{33.0, 19.0, 13.0, 11.0, 9.5, 7.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5};
        } else if (area <= 0.008) {
            priceArrA = new double[]{30.0, 17.0, 13.0, 11.0, 8, 6.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5};
        } else if (area <= 0.01) {
            priceArrA = new double[]{26.0, 17.0, 12.0, 10.0, 7.8, 6.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5};
        } else if (area <= 0.012) {
            priceArrA = new double[]{25.0, 15.0, 11.0, 9.0, 8.5, 7.6, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5};
        } else if (area <= 0.015) {
            priceArrA = new double[]{21.0, 14.0, 11.0, 9.5, 9, 8, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5};
        } else if (area <= 0.017) {
            priceArrA = new double[]{19.0, 14.0, 10, 9, 8.3, 7.3, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5};
        } else if (area <= 0.018) {
            priceArrA = new double[]{18.0, 12.0, 10.0, 8.0, 7.0, 6.0, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5};
        } else if (area <= 0.02) {
            priceArrA = new double[]{17.0, 12.0, 9.0, 8.0, 8.0, 7.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5};
        } else if (area <= 0.03) {
            priceArrA = new double[]{19.0, 12.5, 10.0, 9.0, 6.5, 6.0, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5};
        } else if (area <= 0.04) {
            priceArrA = new double[]{17.0, 13.0, 11.0, 10.0, 6.0, 6.0, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5};
        } else if (area <= 0.06) {
            priceArrA = new double[]{12.8, 9.0, 7.8, 6.8, 6.0, 6.0, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5};
        } else if (area <= 0.1) {
            priceArrA = new double[]{12.5, 9.0, 7.5, 6.5, 6.0, 6.0, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5};
        } else if (area <= 0.2) {
            priceArrA = new double[]{12.0, 8.0, 7.5, 6.5, 6.0, 6.0, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5};
        } else if (area <= 0.3) {
            priceArrA = new double[]{11.5, 8.0, 7.2, 6.0, 5.5, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0};
        } else if (area > 0.3) {
            priceArrA = new double[]{11.0, 7.8, 7.0, 6.5, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5};
        }

        list = bigSizeAcountPrice(count, area, list, priceArrA);
        return list;
    }

    public static void main(String[] args) {
        String source = "C:\\Users\\231010\\Downloads\\蓝朝旺.pdf";
        String target = "C:\\Users\\231010\\Downloads\\蓝朝旺1.pdf";
        optimize(source, target);
    }

    public static void optimize(String source, String target) {
        Document doc = new Document(source);
        //设置压缩属性
        OptimizationOptions opt = new OptimizationOptions();
        //删除PDF不必要的对象
        opt.setRemoveUnusedObjects(true);
        //链接重复流
        opt.setLinkDuplcateStreams(false);
        //删除未使用的流
        opt.setRemoveUnusedStreams(false);
        //删除不必要的字体
        opt.setUnembedFonts(true);
        //压缩PDF中的图片
        opt.getImageCompressionOptions().setCompressImages(true);
        //图片压缩比， 0 到100可选，越低压缩比越大
        opt.getImageCompressionOptions().setImageQuality(100);
        doc.optimizeResources(opt);
        //优化web的PDF文档
        doc.optimize();
        doc.save(target);
    }
}
