审查视图

src/main/java/com/sy/service/impl/WeightCheckHandleServiceImpl.java 8.9 KB
朱兆平 authored
1 2 3 4 5
package com.sy.service.impl;

import com.sy.logic.LiftBar;
import com.sy.service.WeightCheckHandleService;
import com.sy.utils.FileTool;
6 7
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
朱兆平 authored
8 9 10 11 12 13 14 15
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;

@Service
public class WeightCheckHandleServiceImpl implements WeightCheckHandleService {
16
    private static final Logger logger = LoggerFactory.getLogger(LiftBar.class);
朱兆平 authored
17 18 19 20

    //从配置文件中读取货物重差可控范围
    private static String checkWt = FileTool.readProperties("grossWt");
朱兆平 authored
21
朱兆平 authored
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
    /**
     * 校验载重和称重是否在合理的范围
     *
     * @param grossWt   地磅称重,也称出场过磅重量
     * @param wt        车辆自重
     * @param goodsWt   货物总重
     * @param inWt      进场过磅重量
     * @return 获取运单重量
     */
    /**
     * 进场卸货误差判定
     * 出场重量 = 进场重量 - 货物重量
     * 首先计算 进出场差值数 ABS(进场重量-货物重量-出场重量)/出场重量, 计算出出场误差百分比
     *  (出场重量 - 车辆备案重量) /出场重量   空车离场
     *  (出场重量 - (车辆备案重量+货物重量)/出场重量   进场提货(涉及业务,普货提货,调拨,分拨,转关提货)
     *  (出场重量 - (进场重量+货物重量)/出场重量
     */
    @Override
    public boolean checkResult(double grossWt, double wt, double goodsWt, double inWt) {
        DecimalFormat df = new DecimalFormat("0.00");
        boolean flag = false;
        double result= 0.0,result2= 0.0,result3= 0.0,result4= 0.0;
        if(grossWt>0){
            result = Double.parseDouble(df.format(Math.abs((inWt - goodsWt - grossWt)) / grossWt));
            result2 = Double.parseDouble(df.format(Math.abs((grossWt-wt)) / grossWt));
            result3 = Double.parseDouble(df.format(Math.abs((grossWt-wt-goodsWt)) / grossWt));
            result4 = Double.parseDouble(df.format(Math.abs((inWt + goodsWt)) / grossWt));
        }
        if (result <= valueDob() ||result2 <= valueDob() || result3 <= valueDob() || result4 <= valueDob()) {
            flag = true;
        }
        return flag;
    }

    /**
     * 出口普货送货业务重量校验,可支持 带货送货,不支持送货提货
     * 进场重量-载货重量 = 出场重量 (此逻辑已包含空车离场判定)
     * @param grossWt   地磅称重,也称出场过磅重量
     * @param wt        车辆自重
     * @param goodsWt   货物总重
     * @param inWt      进场过磅重量
     * 误差计算方式 (应该出场重量 - 出场重量) / 出场重量 与 误差比对,超过误差则不放行
     * @return 返回校验结果 true 通过,false 不通过
     */
    @Override
    public boolean checkExportDownLoading(double grossWt, double wt, double goodsWt, double inWt){
        DecimalFormat df = new DecimalFormat("0.00");
        boolean flag = false;
        //卸货判定
        double result= 0.0;
        //以防万一 空车离场判定
        double result2= 0.0;
74
        if(Double.doubleToLongBits(grossWt)>Double.doubleToLongBits(0)){
朱兆平 authored
75
            result = Double.parseDouble(df.format(Math.abs((inWt - goodsWt - grossWt)) / grossWt));
76
朱兆平 authored
77
            result2 = Double.parseDouble(df.format(Math.abs((grossWt-wt)) / grossWt));
78 79

            logger.info("[WEIGHT-CHECK]-进出场比对差值:{},空车出场差值:{},进出场比对重量差:{},空车比对重量差:{}",result,result2,Math.abs(inWt - goodsWt - grossWt),Math.abs(grossWt-wt));
朱兆平 authored
80
        }
朱兆平 authored
81 82
        double range = valueDob();
        if (result <= range ||  result2 <= range) {
朱兆平 authored
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
            flag = true;
        }
        return flag;
    }

    /**
     * 进口普货提货业务重量校验,可支持 带货提货,不支持卸货提货
     * 进口转关业务重量校验
     * 进场重量+载货重量 = 出场重量
     * @param grossWt   地磅称重,也称出场过磅重量
     * @param wt        车辆自重
     * @param goodsWt   货物总重
     * @param inWt      进场过磅重量
     * 误差计算方式 (应该出场重量 - 出场重量) / 出场重量 与 误差比对,超过误差则不放行
     * @return 返回校验结果 true 通过,false 不通过
     */
    @Override
    public boolean checkImportDlv(double grossWt, double wt, double goodsWt,double inWt){
        DecimalFormat df = new DecimalFormat("0.00");
        boolean flag = false;
103 104
        double result= 0.00;
        double result1= 0.00;
105 106
        double result2= 0.00;
        double emptyOut= 0.00;
107
        double goodCheckResult= 0.00;
108
        if(Double.doubleToLongBits(grossWt)>Double.doubleToLongBits(0)){
朱兆平 authored
109
            //进场过磅重量+带货重量 = 出场过磅重量
朱兆平 authored
110
            result = Double.parseDouble(df.format(Math.abs((inWt + goodsWt - grossWt)) / grossWt));
朱兆平 authored
111 112

            //todo:这里没有加空车离场判定,暂时不加,进口提货业务空车离场走空车验放判定系统.
113 114 115 116
            result2 = Double.parseDouble(df.format(Math.abs((inWt  - grossWt)) / grossWt));

            //个别原因不提货了,空车离场
            emptyOut = Double.parseDouble(df.format(Math.abs((wt  - grossWt)) / grossWt));
朱兆平 authored
117 118 119

            //车辆备案重量+货物重量 = 出场过磅重量,测试用,生产关闭
            result1 = Double.parseDouble(df.format(Math.abs((wt + goodsWt - grossWt)) / grossWt));
120 121 122

            //货重误差
            goodCheckResult = Double.parseDouble(df.format(Math.abs((grossWt-inWt-goodsWt)) / goodsWt));
朱兆平 authored
123
        }
朱兆平 authored
124
        double range = valueDob();
125
        logger.info("[WEIGHT-CHECK]-实际离场拉货重量:{},申请离场拉货重量:{},货重差值:{},货重误差:{}",grossWt-inWt,goodsWt,grossWt-inWt-goodsWt,goodCheckResult);
126 127
        logger.info("[WEIGHT-CHECK]-进出场比对差值:{},提货离场差值:{},进出场比对重量差:{}",result,result1,Math.abs(inWt  - grossWt));
朱兆平 authored
128
129
        if (result <= range || goodCheckResult<=range) {
朱兆平 authored
130
朱兆平 authored
131 132
            flag = true;
        }
朱兆平 authored
133
134 135 136 137 138
        //车辆备案重量+货物重量 = 出场过磅重量,测试用,生产关闭
        if (result1 <= range || result2 <= range || emptyOut <= range) {

            return true;
        }
朱兆平 authored
139
朱兆平 authored
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
        return flag;
    }

    /**
     * 分拨/调拨业务重量校验
     * 进场重量+载货重量 = 出场重量 (装载场站装货离场)
     * 或者 空车出场 (最后卸货离场)
     * 或者 进场重量-载货重量 = 出场重量 (目的场站卸货离场)
     * @param grossWt   地磅称重,也称出场过磅重量
     * @param wt        车辆自重
     * @param goodsWt   货物总重
     * @param inWt      进场过磅重量
     * 误差计算方式 (应该出场重量 - 出场重量) / 出场重量 与 误差比对,超过误差则不放行
     * @return 返回校验结果 true 通过,false 不通过
     */
    @Override
    public boolean checkAllocateOrDispatch(double grossWt, double wt, double goodsWt,double inWt){
157
        //todo:调拨分拨中的第二.三...场站的如卡口判断 都应该以带货入场进行判定.离场都应该以空车进行判定.
朱兆平 authored
158 159 160
        DecimalFormat df = new DecimalFormat("0.00");
        boolean flag = false;
        //载货离场判定
161
        double result= 0.00;
朱兆平 authored
162
        //空车离场判定
163
        double result2= 0.00;
朱兆平 authored
164 165

        //卸货离场判定
166
        double result3= 0.00;
朱兆平 authored
167
168
        if(Double.doubleToLongBits(grossWt)>Double.doubleToLongBits(0)){
朱兆平 authored
169 170 171
            result = Double.parseDouble(df.format(Math.abs((inWt + goodsWt - grossWt)) / grossWt));
            result2 = Double.parseDouble(df.format(Math.abs((grossWt-wt)) / grossWt));
            result3 = Double.parseDouble(df.format(Math.abs((inWt - goodsWt - grossWt)) / grossWt));
朱兆平 authored
172 173 174
            System.out.println("进场提货离场差值:"+result);
            System.out.println("空车离场差值:"+result2);
            System.out.println("进场卸货离场差值:"+result3);
朱兆平 authored
175
        }
朱兆平 authored
176 177
        double range = valueDob();
        if (result <= range ||  result2 <= range ||  result3 <= range ) {
朱兆平 authored
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
            flag = true;
        }
        return flag;
    }

    /**
     * 判断备案车重与运单重量和地磅称重是否在合理范围
     *
     * @param grossWt
     * @param wt
     * @return
     */
    public boolean checkFlag(double grossWt, double wt) {
        DecimalFormat df = new DecimalFormat("0.00");
        boolean flag = false;
        double reult = Double.parseDouble(df.format(Math.abs((grossWt - wt)) / grossWt));
        if (reult <= valueDob()) {
            flag = true;
        }
        return flag;
    }

    //将获取的checkWt进行小数转化
    private double valueDob() {
        NumberFormat nf = NumberFormat.getPercentInstance();
        Number m = null;
        try {
            m = nf.parse(checkWt);//将百分数转换成Number类型
        } catch (ParseException e) {
            logger.info("重量校验消息异常---"+e.toString());
            logger.info(e.getMessage());
        }
        return m.doubleValue();
    }
}