package com.sw.mes.yb.turnstore.statics;

import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Utlis {
    public  static String getOrderNoByType(String type, Integer sort){
        String orderNo = "";
        //RK-
        if(type.equals(EnumValues.InType.圆棒入库.getValue())){
            orderNo+="RK-";
        }
        //TL-
        else if(type.equals(EnumValues.InType.方棒退料.getValue())||type.equals(EnumValues.InType.综计退料.getValue())||type.equals(EnumValues.OutType.退料到圆棒.getValue())){
            orderNo+="TL-";
        }
        //CK-
        else if(type.equals(EnumValues.OutType.出库到方棒.getValue())||type.equals(EnumValues.OutType.出库到综计.getValue())){
            orderNo+="CK-";
        }
        else{
            return orderNo;
        }
        Date now=new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
        String nowDateStr=dateFormat.format(now);
        orderNo +=nowDateStr;
        String sortStr = String.format("%04d", sort);
        orderNo +=sortStr;
        return orderNo;
    }

    public static BigDecimal getInstoreLength(BigDecimal ybcd,BigDecimal xjc,BigDecimal bjx){
        BigDecimal result = new BigDecimal(0);
        if(ybcd==null||ybcd.compareTo(new BigDecimal(0))<=0){
            return result;
        }else{
            BigDecimal newXjc = new BigDecimal(0);
            BigDecimal newBjx = new BigDecimal(0);
            if(xjc!=null&&xjc.compareTo(new BigDecimal(0))>=0){
                newXjc = xjc;
            }
            if(bjx!=null&&bjx.compareTo(new BigDecimal(0))>=0){
                newBjx=bjx;
            }
            result = ybcd.subtract(newXjc).subtract(newBjx);
            if(result.compareTo(new BigDecimal(0))<=0){
                result = new BigDecimal(0);
            }
        }
        return result;

    }

    public static BigDecimal getInstoreWeight(String productTypeSecond,BigDecimal length){

        BigDecimal result = new BigDecimal(0);
        if(length.compareTo(new BigDecimal(0))<=0){
            return result;
        }
        if(StringUtils.isBlank(productTypeSecond)){
            return result;
        }
        if(productTypeSecond.indexOf("210.9")>0){
            result = length.divide(new BigDecimal(12.29),3, RoundingMode.DOWN);
        }else if(productTypeSecond.indexOf("210")>0){
            result = length.divide(new BigDecimal(12.39),3, RoundingMode.DOWN);
        }else if(productTypeSecond.indexOf("211")>0){
            result = length.divide(new BigDecimal(12.27),3, RoundingMode.DOWN);
        }else if(productTypeSecond.indexOf("219")>0){
            result = length.divide(new BigDecimal(11.39),3, RoundingMode.DOWN);
        }else if(productTypeSecond.indexOf("213")>0){
            result = length.divide(new BigDecimal(12.04),3, RoundingMode.DOWN);
        }else if(productTypeSecond.indexOf("220")>0){
            result = length.divide(new BigDecimal(11.29),3, RoundingMode.DOWN);
        }else if(productTypeSecond.indexOf("223")>0){
            result = length.divide(new BigDecimal(10.99),3, RoundingMode.DOWN);
        }else if(productTypeSecond.indexOf("295")>0){
            result = length.divide(new BigDecimal(6.28),3, RoundingMode.DOWN);
        }else if(productTypeSecond.indexOf("247")>0){
            result = length.divide(new BigDecimal(8.96),3, RoundingMode.DOWN);
        }else if(productTypeSecond.indexOf("216")>0){
            result = length.divide(new BigDecimal(11.71),3, RoundingMode.DOWN);
        }else if(productTypeSecond.indexOf("224")>0){
            result = length.divide(new BigDecimal(10.89),3, RoundingMode.DOWN);
        }else if(productTypeSecond.indexOf("226")>0){
            result = length.divide(new BigDecimal(10.7),3, RoundingMode.DOWN);
        }else if(productTypeSecond.indexOf("227")>0){
            result = length.divide(new BigDecimal(10.6),3, RoundingMode.DOWN);
        }else if(productTypeSecond.indexOf("200")>0){
            result = length.divide(new BigDecimal(13.66),3, RoundingMode.DOWN);
        }else if(productTypeSecond.indexOf("205")>0){
            result = length.divide(new BigDecimal(13),3, RoundingMode.DOWN);
        }else if(productTypeSecond.indexOf("208")>0){
            result = length.divide(new BigDecimal(12.63),3, RoundingMode.DOWN);
        }else if(productTypeSecond.indexOf("165")>0){
            result = length.divide(new BigDecimal(20.07),3, RoundingMode.DOWN);
        }else if(productTypeSecond.indexOf("166")>0){
            result = length.divide(new BigDecimal(19.83),3, RoundingMode.DOWN);
        }else if(productTypeSecond.indexOf("175")>0){
            result = length.divide(new BigDecimal(17.84),3, RoundingMode.DOWN);
        }else if(productTypeSecond.indexOf("155")>0){
            result = length.divide(new BigDecimal(22.75),3, RoundingMode.DOWN);
        }else if(productTypeSecond.indexOf("160")>0){
            result = length.divide(new BigDecimal(21.35),3, RoundingMode.DOWN);
        }else if(productTypeSecond.indexOf("281")>0){
            result = length.divide(new BigDecimal(6.92),3, RoundingMode.DOWN);
        }else if(productTypeSecond.indexOf("310")>0){
            result = length.divide(new BigDecimal(5.69),3, RoundingMode.DOWN);
        }
        return result;
    }


}
