jiangping
2024-10-12 532d94b41c1b1cc76fc1ccb46cef174a26391ee3
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncPushServiceImpl.java
@@ -17,6 +17,7 @@
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.DESUtil;
import com.doumee.core.utils.DateUtil;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.*;
import com.doumee.dao.business.join.VisitsJoinMapper;
import com.doumee.dao.business.model.*;
@@ -43,6 +44,8 @@
@Slf4j
public class HkSyncPushServiceImpl extends HkSyncBaseServiceImpl {
    @Autowired
    private InoutDayCountMapper inoutDayCountMapper;
    @Autowired
    private InterfaceLogMapper interfaceLogMapper;
    @Autowired
@@ -102,13 +105,14 @@
            List<DeviceEvent> list = new ArrayList<>();
            List<Integer> delRetentionLis = new ArrayList<>();
            List<Retention> retentionList = new ArrayList<>();
            InoutDayCount inoutDayCount = new InoutDayCount();
            for(EventAcsInfoRequest request : events){
                EventDeviceDataRequest model = request.getData();
                if(model ==null){
                    continue;
                }
                //根据推送人员编码,处理在场、离场人员数据记录
                dealMemberDataByRequest(request,delRetentionLis,retentionList);
                dealMemberDataByRequest(request,delRetentionLis,retentionList,inoutDayCount);
                //封装门禁事件信息表对象
                list.add(getDeviceEventModelByRequest(request));
            }
@@ -126,6 +130,7 @@
                //再插入最新的在厂人员
                retentionMapper.insert(retentionList);
            }
            dealInoutDayCountBiz(inoutDayCount);
            log.info("【海康门禁事件推送】========成功=======");
        }catch (Exception e) {
            log.error("【海康门禁事件推送】========失败=======:\n" + e.getMessage());
@@ -134,6 +139,37 @@
        }
        return  null;
    }
    private void dealInoutDayCountBiz(InoutDayCount param) {
        param.setTimeInfo(Utils.Date.getStart(new Date()));
        InoutDayCount model = inoutDayCountMapper.selectOne(new QueryWrapper<InoutDayCount>().lambda()
                .eq(InoutDayCount::getTimeInfo,param.getTimeInfo())
                .eq(InoutDayCount::getIsdeleted,Constants.ZERO)
                .last("limit 1"));
        if(model == null){
            param.setIsdeleted(Constants.ZERO);
            param.setCreateDate(new Date());
            param.setEditDate(new Date());
            inoutDayCountMapper.insert(param);
        }else{
            inoutDayCountMapper.update(null,new UpdateWrapper<InoutDayCount>().lambda()
                    .eq(InoutDayCount::getId,model.getId() )
                    .set(InoutDayCount::getEditDate,new Date() )
                    .setSql(param.getInCarNum()!=null,"IN_CAR_NUM = ifnull(IN_CAR_NUM)"+param.getInCarNum() )
                    .setSql(param.getOutCarNum()!=null,"OUT_CAR_NUM = ifnull(OUT_CAR_NUM)"+param.getOutCarNum() )
                    .setSql(param.getInMemberNum()!=null,"IN_MEMBER_NUM = ifnull(IN_MEMBER_NUM)"+param.getInMemberNum() )
                    .setSql(param.getOutMemberNum()!=null,"OUT_MEMBER_NUM = ifnull(OUT_MEMBER_NUM)"+param.getOutMemberNum() )
                    .setSql(param.getInVisitorNum()!=null,"IN_VISITOR_NUM = ifnull(IN_VISITOR_NUM)"+param.getInVisitorNum() )
                    .setSql(param.getOutVisitorNum()!=null,"OUT_VISITOR_NUM = ifnull(OUT_VISITOR_NUM)"+param.getOutVisitorNum() )
                    .setSql(param.getSigninVisitorNum()!=null,"SIGNIN_VISITOR_NUM = ifnull(SIGNIN_VISITOR_NUM)"+param.getSigninVisitorNum() )
                    .setSql(param.getLeaveVisitorNum()!=null,"LEAVE_VISITOR_NUM = ifnull(LEAVE_VISITOR_NUM)"+param.getLeaveVisitorNum() )
                    .setSql(param.getInOtherMemberNum()!=null,"IN_OTHER_MEMBER_NUM = ifnull(IN_OTHER_MEMBER_NUM)"+param.getInOtherMemberNum() )
                    .setSql(param.getOutOtherMemberNum()!=null,"OUT_OTHER_MEMBER_NUM = ifnull(OUT_OTHER_MEMBER_NUM)"+param.getOutOtherMemberNum() )
                    .setSql(param.getInSelfMemberNum()!=null,"IN_SELF_MEMBER_NUM = ifnull(IN_SELF_MEMBER_NUM)"+param.getInSelfMemberNum() )
                    .setSql(param.getOutSelfMemberNum()!=null,"OUT_SELF_MEMBER_NUM = ifnull(OUT_SELF_MEMBER_NUM)"+param.getOutSelfMemberNum() )
            );
        }
    }
    /**
@@ -394,8 +430,6 @@
        queryWrapper.last("limit 1");
        Visits visits = visitsMapper.selectJoinOne(Visits.class,queryWrapper);
        if(visits !=null){
            //如果人员信息存在,则删除之前的所有进场数据(无论此次推送是进厂还是出场推送事件)
            delRetentionLis.add(visits.getMemberId());
            if(dataSyncConfig.getOrgUserDataOrigin() == DataSyncConfig.origin.hk){
                //如果是伊利大屏项目,不做处理
                return;
@@ -404,7 +438,7 @@
            updateVistis.setId(visits.getId());
            if (Constants.formatIntegerNum(request.getEventType()) == HKConstants.EventTypes.VISIT_SIGN_ICCM_IN.getKey()) {
                //如果是访客登记,录入人员的在场数据记录
                retentionList.add(getRetentionModelByVisitRequest(visits, request.getHappenTime(),request.getSrcType()));
//                retentionList.add(getRetentionModelByVisitRequest(visits, request.getHappenTime(),request.getSrcType()));
                //来访时间
                updateVistis.setStatus(Constants.VisitStatus.signin);
                updateVistis.setInDate(DateUtil.getISO8601DateByStr(data.getBeginTime()));
@@ -414,7 +448,7 @@
                member.setLastVisitDate(updateVistis.getInDate());
                member.setId(visits.getMemberId());
                memberMapper.updateById(member);
            }else  if (Constants.formatIntegerNum(request.getEventType()) == HKConstants.EventTypes.VISIT_SIGN_ICCM_OUT.getKey())  {
            }else if (Constants.formatIntegerNum(request.getEventType()) == HKConstants.EventTypes.VISIT_SIGN_ICCM_OUT.getKey())  {
                //如果是访客签离事件
                updateVistis.setStatus(Constants.VisitStatus.signout);
                updateVistis.setInDate(DateUtil.getISO8601DateByStr(data.getBeginTime()));
@@ -422,12 +456,23 @@
                updateVistis.setOutType(Constants.ZERO);
                updateVistis.setOutInfo("访客正常签离");
            }else{
                //如果人员信息存在,切是访客通行,则删除之前的所有进场数据(无论此次推送是进厂还是出场推送事件)
                delRetentionLis.add(visits.getMemberId());
                //如果是访客通行
                if(request.getData()!=null&&request.getData().getParamValues()!=null &&
                        StringUtils.equals(request.getData().getParamValues().getInOrOut(),"1")){
                    //如果是访客登记,录入人员的在场数据记录
                    Retention r = getRetentionModelByVisitRequest(visits, request.getHappenTime(),request.getSrcType());
                    r.setCarNo(request.getData().getParamValues().getPlateNos());
                    r.setAccessType(request.getData().getParamValues().getAccessType());
                    r.setDeviceName(request.getData().getParamValues().getSrcName());
                    r.setDeviceIndex(request.getData().getParamValues().getSrcIndex());
                    retentionList.add(r);
                }
            }
            updateVistis.setEditDate(new Date());
            //更新访客来访或者签离时间信息
            visitsMapper.updateById(updateVistis) ;
        }
    }
    private Retention getRetentionModelByVisitRequest(Visits visits, String happentTime,String srcType) {
@@ -867,8 +912,9 @@
                }
                //各车道车辆状态
                EventPlatformCarsStatusInfoRequest status = data.getHPVehicleStatus();
                eventList.add(initPlatformEventModel(request,data,status));//封装事件(已月台通道为维度)
                PlatformEvent event = initPlatformEventModel(request,data,status);
                if(StringUtils.isBlank(status.getPlateNo())){
                    eventList.add(event);//封装事件(已月台通道为维度)
                    continue;//如果车辆信息为空,不处理直接跳过
                }
                PlatformDevice model = platformDeviceMapper.selectOne(new QueryWrapper<PlatformDevice>().lambda()
@@ -876,24 +922,32 @@
                        .eq(PlatformDevice::getIsdeleted,Constants.ZERO)
                        .last("limit 1"));
                if(model ==null){
                    eventList.add(event);//封装事件(已月台通道为维度)
                    continue;//监控点未同步,跳过处理
                }
                //截掉第一个颜色汉字
                status.setPlateNo(status.getPlateNo().substring(1,status.getPlateNo().length()));
                event.setPlatformId(model.getPlatformId());//月台编码
                eventList.add(event);//封装事件(已月台通道为维度)
                //截掉第一个颜色汉字,去掉“挂”字
                status.setPlateNo(status.getPlateNo().substring(1,status.getPlateNo().length()).replace("挂",""));
                PlatformJob job = platformJobMapper.selectJoinOne(PlatformJob.class, new MPJLambdaWrapper<PlatformJob>()
                        .selectAll(PlatformJob.class)
                        .selectAs(Platform::getName,PlatformJob::getPlatformName)
                        .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() )//后车牌号
//                        .eq(StringUtils.equals(status.getStockStatus(),"front"),PlatformJob::getCarCodeFront,status.getPlateNo() )//前车牌号
//                        .eq(!StringUtils.equals(status.getStockStatus(),"front"),PlatformJob::getCarCodeBack,status.getPlateNo() )//后车牌号
                        .eq(PlatformJob::getIsdeleted,Constants.ZERO )
                        .eq(PlatformJob::getPlatformId,model.getPlatformId() )
                        .orderByDesc(PlatformJob::getCallDate)
                        .last("limit 1 "));
                if(job == null){
                    continue;//如果作业为空,跳过处理
                }
                PlatformJob update = new PlatformJob();
                update.setId(job.getId());
                update.setEditDate(new Date());
                if(StringUtils.equals(status.getMotionStatus(),"leave")){
                    //如果是车辆离开,不做相关自动完成作业业务处理
                 /*   if(job ==null && !Constants.equalsInteger(job.getStatus(),Constants.PlatformJobStatus.WORKING.getKey())){
                   /* if(job ==null && !Constants.equalsInteger(job.getStatus(),Constants.PlatformJobStatus.WORKING.getKey())){
                        continue;//如果没查到对应的作业或者作业并非作业中,不做业务处理
                    }
                    if(Constants.equalsInteger(job.getType(), Constants.THREE) || Constants.equalsInteger(job.getType(), Constants.TWO)){
@@ -908,16 +962,36 @@
                    //如果是正在作业的状态,标记作业已完成
                    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.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);
                        }
                    }
                }else  if(StringUtils.equals(status.getMotionStatus(),"enter")){
                    //如果是车辆进入
                    if(job ==null || !Constants.equalsInteger(job.getStatus(),Constants.PlatformJobStatus.CALLED.getKey())){
                        //说明车辆进错月台 或者还未叫号状态,发起警告
                        dealCarsInErrorPlatformBiz(job,status);
                    if(Constants.equalsInteger(job.getStatus(),Constants.PlatformJobStatus.CALLED.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);
                        }else{
                            //车辆已经进入
                            update.setInOut(Constants.ONE);//车辆已经进入
                            platformJobMapper.updateById(update);
                        }
                    }
                    if(job.getStartDate() == null){
                    /*if(job.getStartDate() == null){
                        update.setStartDate(update.getEditDate());
                    }
                    update.setStatus(Constants.PlatformJobStatus.WORKING.getKey());//开始作业
                    */
                }else{
                    continue;//其他状态不处理,跳过
                }
@@ -1046,29 +1120,29 @@
            return;
        }
        String content =Constants.PlatformLedContent.WRONG_IN.getInfo();
        content = content.replace("${param}",model.getPlatformName());
        content = content.replace("${param2}",model.getCarCodeFront());
        content = content.replace("${param2}",model.getPlatformName());
        content = content.replace("${param}",status.getPlateNo());
        List<String> broadcastList = new ArrayList<>();
        List<String> ledList = new ArrayList<>();
        String bNames = "";
        List<PlatformBroadcastLog> logList = new ArrayList<>();
        for(PlatformDevice device : deviceList){
            if(StringUtils.isNotBlank(device.getHkId())){
            if(StringUtils.isBlank(device.getHkId())){
                continue;
            }
            if(Constants.equalsInteger(device.getType(),Constants.ZERO)){
                //如果是LED
                PlatformBroadcastLog log = dealLedContentBiz(device.getHkNo(),device.getName(),content,speed,1);
                PlatformBroadcastLog log = dealLedContentBiz(model.getId(),device.getHkNo(),device.getName(),content,speed,1);
                logList.add(log);
                ledList.add(device.getHkId());
            }else  if(Constants.equalsInteger(device.getType(),Constants.ZERO)){
            }else  if(Constants.equalsInteger(device.getType(),Constants.TWO)){
                //如果是广播点
                bNames += device.getName()+";";
                broadcastList.add(device.getHkId());
            }
        }
        if(broadcastList.size()>0){
            PlatformBroadcastLog log = dealBroadcastBiz(model,broadcastList,bNames);
            PlatformBroadcastLog log = dealBroadcastBiz(model,broadcastList,bNames,Constants.PlatformBroadcastContent.WRONG_IN.getInfo().replace("${param}",status.getPlateNo()));
            logList.add(log);
        }
        if(logList.size()>0){
@@ -1076,11 +1150,18 @@
        }
    }
    private PlatformBroadcastLog dealBroadcastBiz(PlatformJob model, List<String> broadcastList,String bNames) {
    /**
     * 广播通知
     * @param model
     * @param broadcastList
     * @param bNames
     * @param content1
     * @return
     */
    public static PlatformBroadcastLog dealBroadcastBiz(PlatformJob model, List<String> broadcastList,String bNames , String content1) {
        PlatformBroadcastLog log = new PlatformBroadcastLog();
        String content1 =Constants.PlatformBroadcastContent.WRONG_IN.getInfo();
        content1 = content1.replace("${param}",model.getCarCodeFront());
        log.setObjId(model.getId().toString());
        log.setCreateDate(new Date());
        log.setBizType(Constants.ONE);
        log.setHkDate(new Date());
@@ -1104,12 +1185,12 @@
            log.setHkInfo("请求成功");
            log.setHkStatus(Constants.TWO);
        }
        log.setDeviceType(Constants.ONE);
        log.setDeviceType(Constants.ZERO);
        log.setName("发送广播播报内容");
        return  log;
    }
    public static PlatformBroadcastLog dealLedContentBiz(String hkNo,String hkName, String content,int speed,int color) {
    public static PlatformBroadcastLog dealLedContentBiz(Integer platformId,String hkNo,String hkName, String content,int speed,int color) {
        PlatformBroadcastLog log = new PlatformBroadcastLog();
        log.setCreateDate(new Date());
        log.setBizType(Constants.ONE);
@@ -1119,6 +1200,7 @@
        log.setRemark(hkName);
        log.setInfo(content);
        log.setNum(Constants.ONE);
        log.setObjId(platformId.toString());
        TransparentChannelBodyRequest body = new TransparentChannelBodyRequest();
        TransparentChannelHeadRequest head = new TransparentChannelHeadRequest();