LockNoticeCheck.groovy 5.1 KB
package com.sy.groovy

import com.sy.mapper.LandListDao
import com.sy.model.GatherInfo
import com.sy.model.LandBusinessTypeList
import com.sy.model.LandList
import com.sy.model.LockFeignResponse
import com.sy.model.NoticeLock
import com.sy.service.CommandLogService
import com.sy.service.CustomsLockService
import com.sy.service.feigin.LockFeignService
import com.sy.socket.CommandClient
import org.apache.commons.lang.StringUtils
import org.basis.enhance.groovy.entity.ExecuteParams
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.context.ApplicationContext

/**
 * 关锁验放
 * 关锁通知验放规则
 */
class LockNoticeCheck extends Script implements ChannelCheckScript {
    private final Logger log = LoggerFactory.getLogger(getClass());
    @Override
    Object run() {
        return null
    }

    @Override
    Boolean check(ExecuteParams executeParams) {
        try{
            /**
             * 入场标识
             */
            String IN_TYPE="I";
            /**
             * 离场标识
             */
            String OUT_TYPE="E";
            GatherInfo info = (GatherInfo) executeParams.get("gatherInfo");
            // 获取容器中的bean
            // 调用方法
            ApplicationContext context = getContext();
            CustomsLockService customsLockService = context.getBean(CustomsLockService.class);
            LandListDao landListDao = context.getBean(LandListDao.class);
            LockFeignService lockFeignService = context.getBean(LockFeignService.class);

            //需要关锁业务通知
            if (customsLockService.lockNoticeCheck(info)){
                /**
                 * 关锁号申请检查
                 * 根据二维码查申请是否有关锁信息,没有查到实体返回null
                 */
                LandList landList = landListDao.selectLockInfoByBarcode(info.getBarcode());
                if (landList!=null && StringUtils.isNotEmpty(landList.getLockNum())) {
                    log.info("[LOCK-CHECK]-流转申请携带关锁,二维码:{}",info.getBarcode());

                    NoticeLock noticeLock = new NoticeLock();
                    noticeLock.barcode = info.getBarcode();
                    noticeLock.areaId = info.getAreaid();
                    noticeLock.chnlNo = info.getChnlno();
                    noticeLock.vehicleNo = info.getVename();

                    //1. 判定是上锁通知还是解锁通知
                    if (OUT_TYPE.equals(info.getIetype()) && customsLockService.lockCheck(info)) {
                        //写入缓存
                        customsLockService.cacheWrite(info);
                        //接口通知
                        noticeLock.lockNo =landList.getLockNum();
                        noticeLock.type = "1";
                        LockFeignResponse lockFeignResponse = lockFeignService.noticeLock(noticeLock);
                        log.info("[LOCK-API-RSP]-关锁通知接口返回,code:{},message:{},success:{}",lockFeignResponse.code,lockFeignResponse.message,lockFeignResponse.success);
                        record(info,false,"关锁施封通知中,等待下一步指令",null);
                        return true;
                    }else {
                        if (IN_TYPE.equals(info.getIetype()) && customsLockService.unLockCheck(info)) {
                            customsLockService.cacheWrite(info);

                            //接口通知
                            noticeLock.lockNo =landList.getLockNum();
                            noticeLock.type = "2";
                            LockFeignResponse lockFeignResponse = lockFeignService.noticeLock(noticeLock);
                            log.info("[LOCK-API-RSP]-关锁通知接口返回,code:{},message:{},success:{}",lockFeignResponse.code,lockFeignResponse.message,lockFeignResponse.success);
                            record(info,false,"关锁解封通知中,等待下一步指令",null);
                            return true;
                        }
                    }
                }else {
                    CommandClient.Client(info,"流转业务-未申请关锁号");
                    record(info,false,"业务异常:流转业务-未申请关锁号",null);
                    //这里需要返回true,是关锁业务,但是中断,不抬杆不放行,给予关锁业务异常通知
                    return true;
                }
            }
            return false;
        }catch (Exception e){
            e.printStackTrace();
            log.error("[LockNoticeCheck-ERR]:",e);
            return false;
        }
    }

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

    void record(GatherInfo info, boolean result, String reason, LandBusinessTypeList landBusinessTypeList){
        ApplicationContext context = getContext();
        CommandLogService commandLogService = context.getBean(CommandLogService.class);
        commandLogService.commandlog(info,result,reason,landBusinessTypeList,null,0.0,0.0,0.0,0.0);
    }
}