WeightCheckEmpty.groovy 3.5 KB
package com.sy.groovy

import com.sy.model.GatherInfo
import com.sy.model.LAND_BUSINEESTYPE_LIST_INFO
import com.sy.model.LandBusinessTypeList
import com.sy.service.WeightCheckHandleService
import com.sy.service.impl.GatherInfoHandle
import org.basis.enhance.groovy.entity.ExecuteParams
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.context.ApplicationContext

import java.text.DecimalFormat

/**
 * 重量验放
 * 空车验放
 */
class WeightCheckEmpty extends Script implements ChannelCheckScript {

    private final Logger logger = LoggerFactory.getLogger(getClass());
    private final String GROWSSEXCETION =      "禁止通行,重量不在可控范围";

    /**x21指令判定
    * 传入gatherInfo,三大属性验证,二维码/车牌/过卡重量
     * 车辆备案实体
     * 从redis读取的申请表体实体
     * 适用于进口转关,进口提货业务类型
    */
    Boolean check(ExecuteParams executeParams) {
        try{
            GatherInfo gatherInfo = (GatherInfo) executeParams.get("GatherInfo");
            LandBusinessTypeList landBusinessTypeList = (LandBusinessTypeList) executeParams.get("ChanelFormInfo");
            Double selfWt = (Double) executeParams.get("selfWt");
            List<LAND_BUSINEESTYPE_LIST_INFO> listinfos = (List<LAND_BUSINEESTYPE_LIST_INFO>) executeParams.get("ChanelFormBillLists");

            //3.车辆备案验证
            // 调用方法
            ApplicationContext context = getContext();
            // 获取容器中的bean
            GatherInfoHandle gatherInfoHandle = context.getBean(GatherInfoHandle.class);
            //重量校验算法
            if (checkEmpty(gatherInfo.getGrosswt(), selfWt)){
                return true;
            }else {
                logger.error("[空车业务]-出场重量未通过校验:"+GROWSSEXCETION);
                gatherInfoHandle.sendBw(gatherInfo,false,GROWSSEXCETION,landBusinessTypeList,listinfos);
                return false;
            }
        }catch (Exception e){
            e.printStackTrace();
            logger.error("[WEIGHT-CHECK-EMPTY-ERROR]:",e);
            return false;
        }
    }

    @Override
    Object run() {
        return null
    }

    // 获取spring容器
    ApplicationContext getContext() {
        // 获取spring IOC容器
        ApplicationContext context = applicationContext;
        return context;
    }

    /**
     * 空车入区重量验放判定
     * @param grossWt 车辆过卡总重量
     * @param wt 车辆备案重量
     * @param goodsWt 流转申请单货物总重量
     * @param inWt 车辆出区时的入区重量
     * @return
     */
    boolean checkEmpty(double grossWt, double wt){

        // 调用方法
        ApplicationContext context = getContext();

        //重量校验算法
        WeightCheckHandleService weightCheckHandleService = context.getBean(WeightCheckHandleService.class);

        double emptyIN= 0.00;
        DecimalFormat df = new DecimalFormat("0.00");
        if(Double.doubleToLongBits(grossWt)>Double.doubleToLongBits(0)){
            //空车入场判定,入场重量-车辆备案重量
            emptyIN = Double.parseDouble(df.format(Math.abs((wt  - grossWt)) / wt));

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

                return true;
            }
        }

        return false;
    }
}