jiangping
2024-10-21 291baf8ad5bd225c426b5cbfff38168ffda251cd
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncPushServiceImpl.java
@@ -27,6 +27,7 @@
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -87,8 +88,6 @@
    private PlatformLogMapper platformLogMapper;
    @Autowired
    private PlatformWarnEventServiceImpl platformWarnEventService;
    @Autowired
    private PlatformJobService platformJobService;
    /**
     * 海康门禁事件推送
     * @param param
@@ -825,75 +824,55 @@
                    .last("limit 1" ));
            if(cars!=null){
                event.setMemberId(cars.getMemberId());
                    if(Constants.formatIntegerNum(request.getEventType()) == HKConstants.EventTypes.PARK_PASS_IN.getKey()){
                        if(carsMapper.selectCount(new QueryWrapper<Cars>()
                                .lambda().eq(Cars::getCode,event.getPlateNos())
                                .eq(Cars::getType,Constants.ONE)
                                .eq(Cars::getIsdeleted,Constants.ZERO)
                        )>Constants.ZERO){
                            //自有车进场  查询当前是否有待签到的任务
                            //查询车辆当前是否存在进行中的任务
                            if(platformJobMapper.selectCount(new QueryWrapper<PlatformJob>().lambda()
                                    .eq(PlatformJob::getCarCodeFront,event.getPlateNos())
                                    .eq(PlatformJob::getIsdeleted,Constants.ZERO)
                                    .in(PlatformJob::getStatus,
                                            Constants.PlatformJobStatus.IN_WAIT.getKey(),
                                            Constants.PlatformJobStatus.CALLED.getKey(),
                                            Constants.PlatformJobStatus.WORKING.getKey(),
                                            Constants.PlatformJobStatus.DONE.getKey(),
                                            Constants.PlatformJobStatus.TRANSFERING.getKey(),
                                            Constants.PlatformJobStatus.EXCEPTION.getKey(),
                                            Constants.PlatformJobStatus.AUTHED_LEAVE.getKey()
                                    )
                            )==Constants.ZERO){
                                PlatformJob platformJob = platformJobMapper.selectOne(new QueryWrapper<PlatformJob>().lambda()
                                        .eq(PlatformJob::getCarCodeFront,event.getPlateNos())
                                        .eq(PlatformJob::getIsdeleted,Constants.ZERO)
                                        .in(PlatformJob::getStatus,
                                                Constants.PlatformJobStatus.WAIT_CONFIRM.getKey(),
                                                Constants.PlatformJobStatus.WART_SIGN_IN.getKey()
                                        )
                                        .orderByAsc(PlatformJob::getCreateDate)
                                        .last(" limit 1")
                                );
                                if(Objects.nonNull(platformJob)){
                                    platformJob.setStatus(Constants.PlatformJobStatus.WAIT_CALL.getKey());
                                    platformJob.setArriveDate(new Date());
                                    platformJob.setSingType(Constants.TWO);
                                    platformJob.setSignDate(new Date());
                                    List<PlatformJob> signList = platformJobMapper.selectList(new QueryWrapper<PlatformJob>().lambda().apply(" DATE(SIGN_DATE) = DATE(NOW()) and sign_date is not null  "));
                                    if(CollectionUtils.isEmpty(signList)){
                                        platformJob.setSignNum(Constants.ONE);
                                    } else{
                                        int maxNumber = Collections.max(signList.stream().map(i->i.getSignNum()).collect(Collectors.toList()));
                                        platformJob.setSignNum(maxNumber + Constants.ONE);
                                    }
                                    platformJobMapper.updateById(platformJob);
                                }
                            }
                        }
                    }else if(Constants.formatIntegerNum(request.getEventType()) == HKConstants.EventTypes.PARK_PASS_OUT.getKey()){
                        //离场判断是否存在未离场的订单数据 处理订单数据
                        List<PlatformJob> platformJobList = platformJobMapper.selectList(new QueryWrapper<PlatformJob>().lambda()
                //自有车  查询当前是否有待签到的任务
                if(carsMapper.selectCount(new QueryWrapper<Cars>()
                        .lambda().eq(Cars::getCode,event.getPlateNos())
                        .eq(Cars::getType,Constants.ONE)
                        .eq(Cars::getIsdeleted,Constants.ZERO)
                )>Constants.ZERO){
                    //查询车辆当前是否存在进行中的任务
                    if( platformJobMapper.selectCount(new QueryWrapper<PlatformJob>().lambda()
                            .eq(PlatformJob::getCarCodeFront,event.getPlateNos())
                            .eq(PlatformJob::getIsdeleted,Constants.ZERO)
                            .in(PlatformJob::getStatus,
                                    Constants.PlatformJobStatus.IN_WAIT.getKey(),
                                    Constants.PlatformJobStatus.CALLED.getKey(),
                                    Constants.PlatformJobStatus.WORKING.getKey(),
                                    Constants.PlatformJobStatus.DONE.getKey(),
                                    Constants.PlatformJobStatus.TRANSFERING.getKey(),
                                    Constants.PlatformJobStatus.EXCEPTION.getKey(),
                                    Constants.PlatformJobStatus.AUTHED_LEAVE.getKey()
                            )
                    )==Constants.ZERO){
                        PlatformJob platformJob = platformJobMapper.selectOne(new QueryWrapper<PlatformJob>().lambda()
                                .eq(PlatformJob::getCarCodeFront,event.getPlateNos())
                                .eq(PlatformJob::getIsdeleted,Constants.ZERO)
                                .in(PlatformJob::getStatus,
                                        Constants.PlatformJobStatus.DONE.getKey(),
                                        Constants.PlatformJobStatus.AUTHED_LEAVE.getKey()
                                ));
                        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(platformJobList)){
                            for (PlatformJob platformJob:platformJobList) {
                                platformJob.setStatus(Constants.PlatformJobStatus.LEAVED.getKey());
                                platformJob.setOutDate(new Date());
                                platformJob.setEditDate(new Date());
                                platformJob.setOutType(Constants.ZERO);
                                platformJobMapper.updateById(platformJob);
                                //清空授权
                                platformJobService.cancelInPark(platformJob);
                                        Constants.PlatformJobStatus.WAIT_CONFIRM.getKey(),
                                        Constants.PlatformJobStatus.WART_SIGN_IN.getKey()
                                )
                                .orderByAsc(PlatformJob::getCreateDate)
                                .last(" limit 1")
                        );
                        if(Objects.nonNull(platformJob)){
                            platformJob.setStatus(Constants.PlatformJobStatus.WAIT_CALL.getKey());
                            platformJob.setArriveDate(new Date());
                            platformJob.setSingType(Constants.TWO);
                            platformJob.setSignDate(new Date());
                            List<PlatformJob> signList = platformJobMapper.selectList(new QueryWrapper<PlatformJob>().lambda().apply(" DATE(SIGN_DATE) = DATE(NOW()) and sign_date is not null  "));
                            if(CollectionUtils.isEmpty(signList)){
                                platformJob.setSignNum(Constants.ONE);
                            } else{
                                int maxNumber = Collections.max(signList.stream().map(i->i.getSignNum()).collect(Collectors.toList()));
                                platformJob.setSignNum(maxNumber + Constants.ONE);
                            }
                            platformJobMapper.updateById(platformJob);
                        }
                    }
                };
            }else{
                Visits visits =  visitsMapper.selectOne(new QueryWrapper<Visits>().lambda()
                        .eq(Visits::getCarNos,event.getPlateNos())
@@ -1045,6 +1024,7 @@
                PlatformJob job = platformJobMapper.selectJoinOne(PlatformJob.class, new MPJLambdaWrapper<PlatformJob>()
                        .selectAll(PlatformJob.class)
                        .selectAs(Platform::getName,PlatformJob::getPlatformName)
                        .selectAs(Platform::getLedContent,PlatformJob::getLedContent)
                        .leftJoin(Platform.class,Platform::getId,PlatformJob::getPlatformId)
//                        .eq(StringUtils.equals(status.getStockStatus(),"front"),PlatformJob::getCarCodeFront,status.getPlateNo() )//前车牌号
//                        .eq(!StringUtils.equals(status.getStockStatus(),"front"),PlatformJob::getCarCodeBack,status.getPlateNo() )//后车牌号
@@ -1076,15 +1056,21 @@
                    update.setStatus(Constants.PlatformJobStatus.DONE.getKey());//作业已完成
                    update.setDoneDate(update.getEditDate());*/
                    if(Constants.equalsInteger(job.getStatus(),Constants.PlatformJobStatus.DONE.getKey()) ||
                            Constants.equalsInteger(job.getStatus(),Constants.PlatformJobStatus.TRANSFERING.getKey()) ||
                            Constants.equalsInteger(job.getStatus(),Constants.PlatformJobStatus.EXCEPTION.getKey()) ||
                            Constants.equalsInteger(job.getStatus(),Constants.PlatformJobStatus.AUTHED_LEAVE.getKey())){
                        if(((StringUtils.equals(status.getStockStatus(),"front") && StringUtils.equals(job.getCarCodeFront(),status.getPlateNo()))
                                ||(!StringUtils.equals(status.getStockStatus(),"front") && StringUtils.equals(job.getCarCodeBack(),status.getPlateNo()))
                        )){
                            //说明车辆进错月台 或者还未叫号状态,发起警告
//                          dealCarsInErrorPlatformBiz(job,status);
                            update.setInOut(Constants.ZERO);//车辆已经离开
                            platformJobMapper.updateById(update);
                        }
                            if(Constants.equalsInteger(job.getStatus(),Constants.PlatformJobStatus.DONE.getKey())  ||
                                    Constants.equalsInteger(job.getStatus(),Constants.PlatformJobStatus.AUTHED_LEAVE.getKey())){
                                update.setInOut(Constants.ZERO);//车辆已经离开
                                platformJobMapper.updateById(update);
                            }
                            dealPlatformContentForLeave(job);
                         }
                    }
                }else  if(StringUtils.equals(status.getMotionStatus(),"enter")){
                    //如果是车辆进入
@@ -1100,7 +1086,8 @@
                            platformJobMapper.updateById(update);
                        }
                    }
                    /*if(job.getStartDate() == null){
                    /*
                    if(job.getStartDate() == null){
                        update.setStartDate(update.getEditDate());
                    }
                    update.setStatus(Constants.PlatformJobStatus.WORKING.getKey());//开始作业
@@ -1126,6 +1113,37 @@
        return  null;
    }
    /**
     * 月台车辆离开 设置月台文案为“空闲中 文案”
     * @param model
     */
    private void dealPlatformContentForLeave(PlatformJob model) {
        List<PlatformDevice> deviceList = platformDeviceMapper.selectList(new QueryWrapper<PlatformDevice>().lambda()
                .eq(PlatformDevice::getType, Constants.ZERO)
                .eq(PlatformDevice::getPlatformId,model.getPlatformId())
                .eq(PlatformDevice::getIsdeleted,Constants.ZERO));
        if(deviceList ==null || deviceList.size() == 0){
            return;
        }
        int speed = 13;
        try {
            speed = Integer.parseInt(systemDictDataBiz.queryByCode(Constants.HK_PARAM,Constants.LED_CONTENT_SPEED).getCode());
        }catch (Exception e){
        }
        String content = StringUtils.defaultString(model.getLedContent(), Constants.PlatformLedContent.IDEL_CONTNET.getInfo());
        List<PlatformBroadcastLog> logList = new ArrayList<>();
        for(PlatformDevice device : deviceList){
            if(StringUtils.isBlank(device.getHkId())){
                continue;
            }
            PlatformBroadcastLog log = dealLedContentBiz(model.getId(),device.getHkNo(),device.getName(),content,speed,1);
            logList.add(log);
        }
        if(logList.size()>0){
            platformBroadcastLogMapper.insert(logList);
        }
    }
    private PlatformEvent initPlatformEventModel(EventPlatformCarsInfoRequest request, EventPlatformCarsDataRequest data, EventPlatformCarsStatusInfoRequest status) {
        PlatformEvent model = new PlatformEvent();
        model.setCreateDate(new Date());