X21FormReleaseCheck.groovy 7.1 KB
package com.sy.groovy

import com.sy.crossDomain.BuildBarCode
import com.sy.mapper.LandListDao
import com.sy.model.GatherInfo
import com.sy.model.LandBusinessTypeList
import com.sy.service.CommandLogService
import com.sy.service.LandBusListService
import com.sy.service.RedisService
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.util.stream.Collectors

/**
 * 流转申请-核销
 * 1. 所有申请单中的场站出通道出了,可以核销
 * 2. 根据申请单中的通道类型及通道信息判定没有未走完的通道类型,可以核销.比如 申请单证的通道只有进通道,车可以走进一,进二,进二入场,走完进一,即可核销.(一线进)
 */
class X21FormReleaseCheck extends Script {

    private final Logger logger = LoggerFactory.getLogger(getClass());


    /**x21指令判定
    * 传入gatherInfo
     *
     * 传入从redis读取的申请表体实体,验证
     * 进行通道比对
    */
    void check(ExecuteParams executeParams) {
        try{
            // 获取product对象
            GatherInfo gatherInfo = (GatherInfo) executeParams.get("GatherInfo");
            List<LandBusinessTypeList> formList = (List<LandBusinessTypeList>) executeParams.get("FormList");

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

            List<LandBusinessTypeList> temp =  new ArrayList<>(formList);
            //二维码已出区的记录
            List<LandBusinessTypeList> havenCrossList = gatherInfoHandle.listService.selectByBarcodeWithE(gatherInfo.getBarcode());

            if (formList == null && formList.isEmpty() ){
                logger.error("[FORM-RELEASE-CHECK]-车辆进出场对应申请缓存数据为空:{}",gatherInfo.getBarcode());
                return;
            }

            if (havenCrossList.isEmpty()){
                logger.error("[FORM-RELEASE-CHECK]{}:车辆无离场数据,不核销",gatherInfo.getVename());
                return;
            }
            logger.info("[FORM-RELEASE-CHECK]:已过卡数量:[{}]",havenCrossList.size())
            //申请核销判定,已出区的记录与流转申请数据核碰.如果流转申请列表核碰完,还剩下的需要出区的场站则不核销.
            for (LandBusinessTypeList businessTypeList : havenCrossList) {
                List<LandBusinessTypeList> r =  formList.stream().filter({item ->
                    //判断还有没有没有出区的场站,还有没有出区的场站就不核销
                    logger.debug("[releaseFormCheck-Stream-loop]-缓存与已出核碰,缓存元素场站:[{}],已出记录场站:[{}]",item.getEndstation(),businessTypeList.getEndstation());
                    //解决缓存那里存储有不一样的把人错的的有问题的点,二维码不一致也把缓存删除
                    if (!item.getBarcode().equals(businessTypeList.getBarcode())){
                        return true;
                    }
                    if(item.getEndstation().equals(businessTypeList.getEndstation())) {
                        logger.info("[releaseFormCheck-Stream-loop]-缓存元素场站:[{}],已出记录场站:[{}]-核销判定对碰成功",item.getEndstation(),businessTypeList.getEndstation());
                        return true;
                    }else {
                        return false;
                    }
                }).collect(Collectors.toList());
                temp.removeAll(r);
            }
            logger.info("[FORM-RELEASE-CHECK]-核销判定结果:{}",temp.size());
            if (temp.isEmpty()){
                //todo:流转申请状态核销
                logger.info("[进出场申请]-流转申请开始核销:"+gatherInfo.getVename());
                //二维码核销
                releaseBarCode(gatherInfo,executeParams);
                logger.info("[进出场申请]-流转申请已核销:"+gatherInfo.getVename());
            }
        }catch (Exception e){
            e.printStackTrace();
            logger.error("[FORM-RELEASE-ERROR]:",e);
        }
    }

    @Override
    Object run() {
        return false;
    }

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

    void releaseBarCode(GatherInfo info,ExecuteParams executeParams){
        ApplicationContext context = getContext();
        // 获取容器中的bean
        LandBusListService listService = context.getBean(LandBusListService.class);
        LandListDao landListDao = context.getBean(LandListDao.class);
        Boolean devdebug = (Boolean)context.getBean("devdebug");

        //是否有未驶离的流转记录二维码判定
        int count=listService.selectlaststation(info.getVename(),info.getBarcode());
        //二维码失效通知,已进入场站的与缓存比较.
        if(count==0){
            //todo:测试注释掉,二维码释放
            if (!devdebug){
                BuildBarCode.cancleBarCode(info.getVename());
                logger.info("[流转申请]-二维码已释放:"+info.getVename());
            }

            int rc = landListDao.releaseBarcode(info.getBarcode());
            if (rc>0) {
                logger.info("[进出场核销]-{}流转已核销:{}",info.getVename(),info.getBarcode());
            }else{
                logger.error("[进出场核销-ERROR]-{}流转未核销成功:{}",info.getVename(),info.getBarcode());
            }
            //车辆流转申请缓存删除
            releaseCache(info,executeParams);
        }else{
            logger.error("[进出场核销-ERROR]-{}二维码应该核销,但是不符合核销条件:{}",info.getVename(),info.getBarcode());
        }
    }

    void releaseCache(GatherInfo info,ExecuteParams executeParams){

        ApplicationContext context = getContext();
        // 获取容器中的bean
        RedisService redisService = context.getBean(RedisService.class);

        //车辆流转申请缓存删除
        redisService.del(info.getVename());
        //流转申请时生成的临时核碰场站代码列表
        redisService.del(info.getVename()+"_endstationList");
        //车辆过卡信息缓存删除-X22金二判定时候生成的这个缓存
        redisService.del(info.getSeqno());
        logger.info("[流转缓存]-{}缓存已核销",info.getVename());
        //核销记录
        releaseRecord(info,executeParams);
    }

    /**
     * 核销记录
     */
    void releaseRecord(GatherInfo info,ExecuteParams executeParams){
        LandBusinessTypeList chanelFormInfo = (LandBusinessTypeList) executeParams.get("ChanelFormInfo");
        ApplicationContext context = getContext();
        CommandLogService commandLogService = context.getBean(CommandLogService.class);
        commandLogService.commandlog(info,true,"流转核销",chanelFormInfo,null,0.0,0.0,0.0,0.0);
    }

}