BaseX21GatherInfoCheck.groovy 2.4 KB
package com.sy.groovy

import com.sy.model.GatherInfo
import com.sy.service.impl.GatherInfoHandle
import org.apache.commons.lang3.StringUtils
import org.basis.enhance.groovy.entity.ExecuteParams
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.context.ApplicationContext

//基本信息验放
class BaseX21GatherInfoCheck extends Script {

    private final Logger logger = LoggerFactory.getLogger(getClass());
    private final String X21_WEIGHT_ERR =            "车辆过卡重量异常";

    /**x21指令判定
    * 传入gatherInfo,三大属性验证,二维码/车牌/过卡重量
    */
    Boolean check(ExecuteParams executeParams) {
        try{
            GatherInfo gatherInfo = (GatherInfo) executeParams.get("gatherInfo");

            // 获取容器中的bean
            // 调用方法
            ApplicationContext context = getContext();
            GatherInfoHandle gatherInfoHandle = context.getBean(GatherInfoHandle.class);

            if (gatherInfo == null){
                logger.error("[ENGIN-BASE-CHECK-ERR]-过卡信息未获取到");
                return false;
            }
            //基本验放信息
            //2.车牌号验证,从过卡信息读取
            if(StringUtils.isEmpty(gatherInfo.getVename())){
                logger.error("[ENGIN-BASE-CHECK-ERR]-车牌信息未获取到");
                return false;
            }
            if(StringUtils.isEmpty(gatherInfo.getBarcode())){
                logger.error("[ENGIN-BASE-CHECK-ERR]-二维码信息未获取到");
                return false;
            }

            //4.车辆过卡重量验证,重量大于0 就正常
            if (!(gatherInfo.grosswt>0)){
                logger.error(X21_WEIGHT_ERR+gatherInfo.getVename());
                gatherInfoHandle.sendBw(gatherInfo,false,X21_WEIGHT_ERR,null,null);
                return false;
            }

            logger.info("[BASE-CHECK-SUCCESS]:{}过卡基本信息验证通过",gatherInfo.getVename());
            return true;
        }catch (Exception e){
            e.printStackTrace();
            logger.error("[BASE-CHECK-ERROR]:",e);
            return false;
        }
    }

    @Override
    Object run() {
        return null
    }

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


}