vince
2023-07-05 169e829234045a236419fdf354e1f5acaf13c6df
igds-inout/src/main/java/com/ld/igds/inout/manager/InoutEventControlManager.java
@@ -6,10 +6,12 @@
import com.ld.igds.camera.data.ApiCameraResp;
import com.ld.igds.camera.data.ApiSnapReq;
import com.ld.igds.constant.BizType;
import com.ld.igds.constant.DeviceType;
import com.ld.igds.data.SnapImgDto;
import com.ld.igds.file.CoreFileService;
import com.ld.igds.inout.ApiInoutManager;
import com.ld.igds.inout.ApiInoutService;
import com.ld.igds.inout.InoutApiConstant;
import com.ld.igds.inout.InoutConstant;
import com.ld.igds.inout.dto.*;
import com.ld.igds.inout.service.InoutService;
@@ -68,20 +70,16 @@
        //如果使用的是地磅插件获取,则需要调整设备为地磅插件信息
        if (ProtocolEnum.TCP_FZZY_WEIGHT.getCode().equals(param.getProtocol())) {
            InoutConf conf = this.getInoutConf(param.getCompanyId(), param.getDeptId(), param.getSort(), InoutConstant.CONF_TYPE_70);
            if (null == conf) {
                param.setErrorMsg("没有获取到当前协议插件配置配置信息,获取失败");
                return param;
            }
            param.setIp(conf.getIp());
            param.setPort(conf.getPort());
            param.setProtocol(conf.getProtocol());
            return apiInoutManager.getApiService(param.getProtocol()).getPlateNum(param);
        }
        return apiInoutManager.getApiService(param.getProtocol()).getPlateNum(param);
@@ -95,6 +93,20 @@
     * @return
     */
    public ApiInoutData getIcCardNum(ApiInoutData param) {
        //如果使用的是地磅插件获取,则需要调整设备为地磅插件信息
        if (ProtocolEnum.TCP_FZZY_WEIGHT.getCode().equals(param.getProtocol())) {
            InoutConf conf = this.getInoutConf(param.getCompanyId(), param.getDeptId(), param.getSort(), InoutConstant.CONF_TYPE_70);
            if (null == conf) {
                param.setErrorMsg("没有获取到当前协议插件配置配置信息,获取失败");
                return param;
            }
            param.setIp(conf.getIp());
            param.setPort(conf.getPort());
            param.setProtocol(conf.getProtocol());
            return apiInoutManager.getApiService(param.getProtocol()).getIcCardNum(param);
        }
        return apiInoutManager.getApiService(param.getProtocol()).getIcCardNum(param);
    }
@@ -120,23 +132,23 @@
     * @param param
     * @return
     */
    public String noticeWeightDone(ApiInoutData param) {
        //获取称重主控器配置
        InoutConf conf = getWeightGateway(param.getCompanyId(), param.getDeptId(), param.getSort());
        if (null == conf) {
            return "称重主控未配置,支持失败";
        }
        ApiInoutData apiData = new ApiInoutData(conf);
        apiData.setPlateNum(param.getPlateNum());
        apiData.setTime(new Date());
        ApiInoutService inoutApiService = apiInoutManager.getApiService(conf.getProtocol());
        // return inoutApiService.noticeWeightDone(apiData); TODO
        return null;
    }
//    public String noticeWeightDone(ApiInoutData param) {
//        //获取称重主控器配置
//        InoutConf conf = getWeightGateway(param.getCompanyId(), param.getDeptId(), param.getSort());
//
//        if (null == conf) {
//            return "称重主控未配置,支持失败";
//        }
//
//        ApiInoutData apiData = new ApiInoutData(conf);
//        apiData.setPlateNum(param.getPlateNum());
//        apiData.setTime(new Date());
//
//        ApiInoutService inoutApiService = apiInoutManager.getApiService(conf.getProtocol());
//
//        // return inoutApiService.noticeWeightDone(apiData); TODO
//        return null;
//    }
    /**
     * 出入库抓拍
@@ -174,73 +186,73 @@
     *
     * @param snapImgDto
     */
    private void noticeGatewayWeightInfo(SnapImgDto snapImgDto) {
        log.debug("-------------用户确认称重----通知称重网关----{}", snapImgDto.getWeight());
        InoutConf conf = this.getWeightGateway(snapImgDto.getCompanyId(), snapImgDto.getDeptId(), snapImgDto.getSort());
        if (null == conf) {
            log.info("-------------用户确认称重----通知称重网关---未配置网关----");
            return;
        }
        ApiInoutData apiData = new ApiInoutData(conf);
        apiData.setTime(new Date());
        apiData.setRepeat(2);
        apiData.setWeight(snapImgDto.getWeight());
        apiData.setPlateNum(snapImgDto.getPlateNum());
        //称重信息暂时取消播放
//        apiData.setMsg("当前称重:" + apiData.getWeight() + "千克");
        apiData.setMsg("称重已完成");
//        apiInoutManager.getApiService(apiData.getProtocol()).noticeWeightDone(apiData);
      //  apiInoutManager.getApiService(apiData.getProtocol()).noticeRadio(apiData);
    }
//    private void noticeGatewayWeightInfo(SnapImgDto snapImgDto) {
//
//        log.debug("-------------用户确认称重----通知称重网关----{}", snapImgDto.getWeight());
//        InoutConf conf = this.getWeightGateway(snapImgDto.getCompanyId(), snapImgDto.getDeptId(), snapImgDto.getSort());
//
//        if (null == conf) {
//            log.info("-------------用户确认称重----通知称重网关---未配置网关----");
//            return;
//        }
//
//        ApiInoutData apiData = new ApiInoutData(conf);
//        apiData.setTime(new Date());
//        apiData.setRepeat(2);
//        apiData.setWeight(snapImgDto.getWeight());
//        apiData.setPlateNum(snapImgDto.getPlateNum());
//        //称重信息暂时取消播放
////        apiData.setMsg("当前称重:" + apiData.getWeight() + "千克");
//        apiData.setMsg("称重已完成");
//
////        apiInoutManager.getApiService(apiData.getProtocol()).noticeWeightDone(apiData);
//        //  apiInoutManager.getApiService(apiData.getProtocol()).noticeRadio(apiData);
//    }
    /**
     * 新增白名单给住控制器,需要注意的是,登记时候不确认使用哪个地磅系统,如果系统配置多个主控器,需要同步全部推送
     *
     * @param imgDto
     */
    private void noticeGatewayAddWhitePlate(SnapImgDto imgDto) {
//    private void noticeGatewayAddWhitePlate(SnapImgDto imgDto) {
//
//        List<InoutConf> list = this.getWeightGateway(imgDto.getCompanyId(), imgDto.getDeptId());
//
//        if (null == list || list.isEmpty()) {
//            log.info("-------------称重网关增加白名单----没有获取到网关配置-----取消执行---");
//            return;
//        }
//
//        log.debug("-------------登记完成,增加车牌白名单-----------{}", imgDto.getPlateNum());
//
//        ApiInoutService inoutApiService = apiInoutManager.getApiService(list.get(0).getProtocol());
//
//        ApiInoutData apiData;
//        for (InoutConf conf : list) {
//            apiData = new ApiInoutData(conf);
//            apiData.setPlateNum(imgDto.getPlateNum());
//            // inoutApiService.addWhitePlate(apiData);
//        }
//    }
        List<InoutConf> list = this.getWeightGateway(imgDto.getCompanyId(), imgDto.getDeptId());
        if (null == list || list.isEmpty()) {
            log.info("-------------称重网关增加白名单----没有获取到网关配置-----取消执行---");
            return;
        }
        log.debug("-------------登记完成,增加车牌白名单-----------{}", imgDto.getPlateNum());
        ApiInoutService inoutApiService = apiInoutManager.getApiService(list.get(0).getProtocol());
        ApiInoutData apiData;
        for (InoutConf conf : list) {
            apiData = new ApiInoutData(conf);
            apiData.setPlateNum(imgDto.getPlateNum());
            // inoutApiService.addWhitePlate(apiData);
        }
    }
    public void noticeProgressComplete(InoutData data) {
        log.debug("-----------------通知称重主控--------流程结束删除白名单");
        List<InoutConf> list = this.getWeightGateway(data.getCompanyId(), data.getDeptId());
        if (null == list || list.isEmpty()) {
            return;
        }
        ApiInoutService inoutApiService = apiInoutManager.getApiService(list.get(0).getProtocol());
        ApiInoutData apiData;
        for (InoutConf conf : list) {
            apiData = new ApiInoutData(conf);
            apiData.setPlateNum(data.getPlateNum());
            // inoutApiService.delWhitePlate(apiData); TODO
        }
    }
//    public void noticeProgressComplete(InoutData data) {
//        log.debug("-----------------通知称重主控--------流程结束删除白名单");
//        List<InoutConf> list = this.getWeightGateway(data.getCompanyId(), data.getDeptId());
//
//        if (null == list || list.isEmpty()) {
//            return;
//        }
//
//        ApiInoutService inoutApiService = apiInoutManager.getApiService(list.get(0).getProtocol());
//
//        ApiInoutData apiData;
//        for (InoutConf conf : list) {
//            apiData = new ApiInoutData(conf);
//            apiData.setPlateNum(data.getPlateNum());
//
//            // inoutApiService.delWhitePlate(apiData); TODO
//        }
//    }
    /**
     * 调用接口进行抓拍
@@ -399,6 +411,80 @@
        return null;
    }
    /**
     * 被动收到车牌识别结果,事件
     *
     * @param data
     */
    @Async
    public void onReceivePlateNum(ApiInoutData data) {
        InoutConf conf = this.getInoutConfBySn(data.getCompanyId(), data.getDeptId(), data.getSn());
        if (null == conf) {
            log.error("没有获取到出入库配置CONF:"+data.toString());
            return;
        }
        log.info(conf.toString());
        if (0 == conf.getInOrder()) return;
        data = new ApiInoutData(conf);
        log.info(data.toString());
        ApiInoutService inoutApiService = null;
        InoutConf gateconf = null;
        //获取车牌信息,开闸机
        if (InoutApiConstant.DEVICE_CODE_1002 == data.getDeviceCode()) {
            gateconf = this.getWeightGateway(data.getCompanyId(), data.getDeptId(), null);
            if (null == gateconf) {
                log.info("----------没有获取到称重控制器--------------");
            }
            data = new ApiInoutData(gateconf);
            //开入口处道闸
            inoutApiService = apiInoutManager.getApiService(gateconf.getProtocol());
            data.setDeviceCode(InoutApiConstant.DEVICE_CODE_2002);
            data.setActionCode(InoutApiConstant.ACTION_CODE_1);
            inoutApiService.gateControl(data);
        }
        if (InoutApiConstant.DEVICE_CODE_1003 == data.getDeviceCode()) {
            gateconf = this.getWeightGateway(data.getCompanyId(), data.getDeptId(), null);
            if (null == gateconf) {
                log.info("----------没有获取到称重控制器--------------");
            }
            //开入口处道闸
            data = new ApiInoutData(gateconf);
            inoutApiService = apiInoutManager.getApiService(gateconf.getProtocol());
            data.setDeviceCode(InoutApiConstant.DEVICE_CODE_2003);
            data.setActionCode(InoutApiConstant.ACTION_CODE_1);
            inoutApiService.gateControl(data);
        }
    }
    /**
     * 出入库称重页面初始化,如果有SDK车牌识别,需要进行初始化操作
     *
     * @param listInoutConf
     * @param sort
     */
    @Async
    public void initInoutWeight(List<InoutConf> listInoutConf, String sort) {
        //获取车牌配置信息
        if (null == listInoutConf) return;
        ApiInoutData apiInoutData;
        ApiInoutService inoutApiService;
        for (InoutConf conf : listInoutConf) {
            if (InoutConstant.PROGRESS_WEIGHT_TAG.equals(conf.getInoutProgress())&&InoutConstant.CONF_TYPE_10.equals(conf.getType()) && sort.equals(conf.getSort())) {
                apiInoutData = new ApiInoutData(conf);
                inoutApiService = apiInoutManager.getApiService(conf.getProtocol());
                inoutApiService.initLpr(apiInoutData);
            }
        }
    }
    /**
     * 出入库登记完成触发事件,默认为异步处理
     *
@@ -420,14 +506,66 @@
     */
    @Async
    public void onInoutWeight(InoutData data, String curProgress, String nextProgress) {
        //获取地磅控制器
        InoutConf conf = this.getWeightGateway(data.getCompanyId(), data.getDeptId(), null);
        if (null == conf) {
            log.info("----------称重完成事件,没有获取到称重控制器--------------");
        }
        //1、通知称重显示屏
        //1、通知称重显示屏,设备编号6001
        ApiInoutData apiData = new ApiInoutData(conf);
        apiData.setTime(new Date());
        apiData.setDeviceCode(InoutApiConstant.DEVICE_CODE_6001);
        ApiInoutService inoutApiService = apiInoutManager.getApiService(conf.getProtocol());
        inoutApiService.noticeLed(apiData, data);
        //2、语音通知
        apiData.setDeviceCode(InoutApiConstant.DEVICE_CODE_8001);
        inoutApiService.noticeRadio(apiData, data);
        //3、开闸机
        if (InoutConstant.TYPE_IN.equals(data.getType())) {
            //结算重量大于0表示二次称重
            if (data.getNetWeight() > 0) {
                apiData.setDeviceCode(InoutApiConstant.DEVICE_CODE_2002);
            } else {
                apiData.setDeviceCode(InoutApiConstant.DEVICE_CODE_2003);
            }
            apiData.setActionCode(InoutApiConstant.ACTION_CODE_1);
            inoutApiService.gateControl(apiData);
        } else {
            //结算重量大于0表示二次称重
            if (data.getNetWeight() > 0) {
                apiData.setDeviceCode(InoutApiConstant.DEVICE_CODE_2002);
            } else {
                apiData.setDeviceCode(InoutApiConstant.DEVICE_CODE_2003);
            }
            apiData.setActionCode(InoutApiConstant.ACTION_CODE_1);
            inoutApiService.gateControl(apiData);
        }
        //4、开红绿灯
        if (InoutConstant.TYPE_IN.equals(data.getType())) {
            //结算重量大于0表示二次称重
            if (data.getNetWeight() > 0) {
                apiData.setDeviceCode(InoutApiConstant.DEVICE_CODE_7001);
            } else {
                apiData.setDeviceCode(InoutApiConstant.DEVICE_CODE_7002);
            }
            apiData.setActionCode(InoutApiConstant.ACTION_CODE_1);
            inoutApiService.lightControl(apiData);
        } else {
            //结算重量大于0表示二次称重
            if (data.getNetWeight() > 0) {
                apiData.setDeviceCode(InoutApiConstant.DEVICE_CODE_7002);
            } else {
                apiData.setDeviceCode(InoutApiConstant.DEVICE_CODE_7001);
            }
            apiData.setActionCode(InoutApiConstant.ACTION_CODE_1);
            inoutApiService.lightControl(apiData);
        }
    }
@@ -618,5 +756,24 @@
        return result;
    }
    private InoutConf getInoutConfBySn(String companyId, String deptId, String sn) {
        if (null == sn) return null;
        // 获取出入库配置信息
        List<InoutConf> listInoutConf = inoutCommonService.getCacheInoutConf(companyId, deptId);
        if (null == listInoutConf) return null;
        for (InoutConf conf : listInoutConf) {
            if (null == conf.getSn()) continue;
            if (sn.equals(conf.getSn())) return conf;
        }
        return null;
    }
}