审查视图

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

import com.sy.service.WeightCheckHandleService;
import com.sy.utils.FileTool;
5
import lombok.extern.slf4j.Slf4j;
朱兆平 authored
6 7 8 9 10 11
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
12
@Slf4j
朱兆平 authored
13 14 15 16 17 18
@Service
public class WeightCheckHandleServiceImpl implements WeightCheckHandleService {

    //从配置文件中读取货物重差可控范围
    private static String checkWt = FileTool.readProperties("grossWt");
朱兆平 authored
19
朱兆平 authored
20 21 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
    /**
     * 校验载重和称重是否在合理的范围
     *
     * @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      进场过磅重量
61 62
     * 误差计算方式 (应该出场重量 - 出场重量) / 出场重量 与 误差比对,超过误差则不放行(规则取消)
     * 误差计算方式 (应该出场重量 - 出场重量) / 货物重量 与 误差比对,超过误差则不放行(新规)
朱兆平 authored
63 64 65 66
     * @return 返回校验结果 true 通过,false 不通过
     */
    @Override
    public boolean checkExportDownLoading(double grossWt, double wt, double goodsWt, double inWt){
67 68 69 70 71 72 73 74 75 76 77

        /**
         *  异常情况判定
         *  送货业务的入场重量必须大于离场重量
         *  比如申请单申请的时候本来是进口提货 申请成出口送货
         */
        if (inWt<grossWt){
            log.info("出区重量比入区重量大,信息异常");
            return false;
        }
朱兆平 authored
78 79 80 81 82 83
        DecimalFormat df = new DecimalFormat("0.00");
        boolean flag = false;
        //卸货判定
        double result= 0.0;
        //以防万一 空车离场判定
        double result2= 0.0;
84
        if(Double.doubleToLongBits(grossWt)>Double.doubleToLongBits(0)){
朱兆平 authored
85
            result = Double.parseDouble(df.format(Math.abs((inWt - goodsWt - grossWt)) / grossWt));
86
87
            result2 = Double.parseDouble(df.format(Math.abs((grossWt-wt)) / wt));
88
89
            log.info("[WEIGHT-CHECK]-进出场比对差值:{},空车出场差值:{},进出场比对重量差:{},空车比对重量差:{}",result,result2,Math.abs(inWt - goodsWt - grossWt),Math.abs(grossWt-wt));
朱兆平 authored
90
        }
朱兆平 authored
91
        double range = valueDob();
92 93 94

        //车辆离场重量与车辆备案重量验放,只允许空车离场
        if (result2 <= range) {
朱兆平 authored
95 96
            flag = true;
        }
97 98 99 100
//
//        if (result <= range ||  result2 <= range) {
//            flag = true;
//        }
朱兆平 authored
101 102 103
        return flag;
    }
104 105 106 107 108 109 110

    @Override
    public boolean checkImportAtCheckIN(double grossWt, double wt, double goodsWt, double inWt){
        double emptyIN= 0.00;
        DecimalFormat df = new DecimalFormat("0.00");
        if(Double.doubleToLongBits(grossWt)>Double.doubleToLongBits(0)){
            //空车入场判定,入场重量-车辆备案重量
111
            emptyIN = Double.parseDouble(df.format(Math.abs((wt  - grossWt)) / wt));
112 113 114 115 116 117 118 119 120 121 122

            double range = valueDob();

            if (emptyIN <= range) {
                log.info("[WEIGHT-CHECK]-进口提货入口重量验放:入场重量{},车辆备案重量:{},差值:{}",grossWt,wt,emptyIN);
                return true;
            }
        }

        return false;
    }
朱兆平 authored
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
    /**
     * 进口普货提货业务重量校验,可支持 带货提货,不支持卸货提货
     * 进口转关业务重量校验
     * 进场重量+载货重量 = 出场重量
     * @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;
138 139
        double result= 0.00;
        double result1= 0.00;
140 141
        double result2= 0.00;
        double emptyOut= 0.00;
142
        double goodCheckResult= 0.00;
143
        if(Double.doubleToLongBits(grossWt)>Double.doubleToLongBits(0)){
朱兆平 authored
144
            //进场过磅重量+带货重量 = 出场过磅重量
145 146
//            result = Double.parseDouble(df.format(Math.abs((inWt + goodsWt - grossWt)) / grossWt));
            result = Double.parseDouble(df.format(Math.abs((grossWt-wt-goodsWt)) / goodsWt));
朱兆平 authored
147
148
            //带货提货,不提货判定,非空车离场
149 150 151 152
            result2 = Double.parseDouble(df.format(Math.abs((inWt  - grossWt)) / grossWt));

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

            //车辆备案重量+货物重量 = 出场过磅重量,测试用,生产关闭
            result1 = Double.parseDouble(df.format(Math.abs((wt + goodsWt - grossWt)) / grossWt));
156
157
            //带货提货,货重误差
158
            goodCheckResult = Double.parseDouble(df.format(Math.abs((grossWt-inWt-goodsWt)) / goodsWt));
159
160 161 162
            double range = valueDob();
            log.info("[WEIGHT-CHECK]-实际离场拉货重量:{},申请离场拉货重量:{},货重差值:{},货重误差:{}",grossWt-inWt,goodsWt,grossWt-inWt-goodsWt,goodCheckResult);
            log.info("[WEIGHT-CHECK]-进出场比对差值:{},提货离场差值:{},进出场比对重量差:{}",result,result1,Math.abs(inWt  - grossWt));
朱兆平 authored
163
朱兆平 authored
164 165
            if (goodCheckResult<=range
//                    || result <= range
166
            ) {
朱兆平 authored
167
168 169
                flag = true;
            }
朱兆平 authored
170
171 172 173 174 175
//            //车辆备案重量+货物重量 = 出场过磅重量,测试用,生产关闭
//            if (result1 <= range || result2 <= range || emptyOut <= range) {
//
//                return true;
//            }
176
朱兆平 authored
177
178
        }
朱兆平 authored
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
        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){
196
        //todo:调拨分拨中的第二.三...场站的如卡口判断 都应该以带货入场进行判定.离场都应该以空车进行判定.
朱兆平 authored
197 198 199
        DecimalFormat df = new DecimalFormat("0.00");
        boolean flag = false;
        //载货离场判定
200
        double result= 0.00;
朱兆平 authored
201
        //空车离场判定
202
        double result2= 0.00;
朱兆平 authored
203 204

        //卸货离场判定
205
        double result3= 0.00;
206
        double result4= 0.00;
朱兆平 authored
207
208
        if(Double.doubleToLongBits(grossWt)>Double.doubleToLongBits(0)){
209
            //带货出,入场重量+带货重量 = 离场重量
朱兆平 authored
210
            result = Double.parseDouble(df.format(Math.abs((grossWt-inWt-goodsWt)) / goodsWt));
211
            //带货出,用车辆备案重量对碰,车辆备案重量+带货重量 = 离场重量
212 213
//            result4 = Double.parseDouble(df.format(Math.abs((wt + goodsWt - grossWt)) / grossWt));
            result4 = Double.parseDouble(df.format(Math.abs((grossWt-wt-goodsWt)) / goodsWt));
214
            //空车出,过磅重量 = 车辆备案重量
215
            result2 = Double.parseDouble(df.format(Math.abs((grossWt-wt)) / wt));
216
            //卸货出,入场重量-卸货重量 = 离场重量
朱兆平 authored
217 218
            result3 = Double.parseDouble(df.format(Math.abs((inWt - goodsWt - grossWt)) / goodsWt));
朱兆平 authored
219 220 221
            System.out.println("进场提货离场差值:"+result);
            System.out.println("空车离场差值:"+result2);
            System.out.println("进场卸货离场差值:"+result3);
222
            System.out.println("备案重量进场装载货物离场差值:"+result4);
朱兆平 authored
223
        }
朱兆平 authored
224
        double range = valueDob();
225
        if (result2 <= range
朱兆平 authored
226 227
                ||  result <= range
                ||  result3 <= range
228 229
                ||  result4 <= range
        ) {
朱兆平 authored
230 231 232 233
            flag = true;
        }
        return flag;
    }
234 235 236 237 238 239 240 241 242 243 244
    /**
     * 判断备案车重与地磅称重是否在合理范围
     *
     * @param grossWt
     * @param wt
     * @return
     */
    @Override
    public boolean checkEmpty(double grossWt, double wt) {
        DecimalFormat df = new DecimalFormat("0.00");
        boolean flag=false;
245
        double reult = Double.parseDouble(df.format(Math.abs((grossWt - wt)) / wt));
246 247 248 249 250
        if (reult <= valueDob()) {
            flag = true;
        }
        return flag;
    }
朱兆平 authored
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275

    /**
     * 判断备案车重与运单重量和地磅称重是否在合理范围
     *
     * @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) {
276 277
            log.info("重量校验消息异常---"+e.toString());
            log.info(e.getMessage());
朱兆平 authored
278 279 280 281
        }
        return m.doubleValue();
    }
}