|  |  |  | 
|---|
|  |  |  | import com.doumee.dao.business.model.Member; | 
|---|
|  |  |  | import com.doumee.dao.web.reqeust.SavePlatformWarnEventDTO; | 
|---|
|  |  |  | import com.doumee.service.business.impl.PlatformWarnEventServiceImpl; | 
|---|
|  |  |  | import com.doumee.service.business.third.TmsService; | 
|---|
|  |  |  | import com.doumee.service.business.third.model.request.TmsOrderInfoRequest; | 
|---|
|  |  |  | import com.doumee.service.business.third.model.response.TmsOrderInfoResponse; | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | 
|---|
|  |  |  | private PlatformBroadcastLogMapper platformBroadcastLogMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private PlatformJobMapper platformJobMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TmsService tmsService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private PlatformWmsDetailMapper platformWmsDetailMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | 
|---|
|  |  |  | *  根据访客推送访客记录编码,处理访客记录、在场人员等信息 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void dealVisitDataByRequstIccm(EventVisitIccmInfoRequest request, List<Integer> delRetentionLis, List<Retention> retentionList,  InoutDayCount inoutDayCount) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | EventVisitIccmDataRequest model = request.getData(); | 
|---|
|  |  |  | EventVisitIccmInvoiceParamRequest data =  request.getData().getVisitorInvoices(); | 
|---|
|  |  |  | MPJLambdaWrapper<Visits> queryWrapper = new MPJLambdaWrapper<>(); | 
|---|
|  |  |  | 
|---|
|  |  |  | 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())); | 
|---|
|  |  |  | //来访时间 | 
|---|
|  |  |  | if(Constants.equalsInteger(visits.getStatus(),Constants.VisitStatus.xfSuccess)){ | 
|---|
|  |  |  | inoutDayCount.setSigninVisitorNum(Constants.formatIntegerNum(inoutDayCount.getSigninVisitorNum())+1); | 
|---|
|  |  |  | 
|---|
|  |  |  | updateVistis.setOutType(Constants.ZERO); | 
|---|
|  |  |  | updateVistis.setOutInfo("访客正常签离"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | delRetentionLis.add(visits.getMemberId()); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | //如果人员信息存在,切是访客通行,则删除之前的所有进场数据(无论此次推送是进厂还是出场推送事件) | 
|---|
|  |  |  | delRetentionLis.add(visits.getMemberId()); | 
|---|
|  |  |  | 
|---|
|  |  |  | event.setCreateDate(DateUtil.getISO8601DateByStr2(request.getHappenTime())); | 
|---|
|  |  |  | if(event.getCreateDate() == null){ | 
|---|
|  |  |  | event.setCreateDate(new Date()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (Constants.formatIntegerNum(request.getEventType()) == HKConstants.EventTypes.VISIT_SIGN_ICCM_PASS.getKey())  { | 
|---|
|  |  |  | //如果是访客通行事件,进入进出事件 | 
|---|
|  |  |  | if(request.getData()!=null&&request.getData().getParamValues()!=null && | 
|---|
|  |  |  | StringUtils.equals(request.getData().getParamValues().getInOrOut(),"0")){ | 
|---|
|  |  |  | event.setInOrOut("0");//进 | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | event.setInOrOut("1");//出 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | event.setVisitorWorkUint(detail.getUnit()); | 
|---|
|  |  |  | event.setVisitorId(detail.getVisitorId()); | 
|---|
|  |  |  | 
|---|
|  |  |  | event.setEventCmd(request.getData().getEventCmd()); | 
|---|
|  |  |  | event.setCardNo(request.getData().getCardNo()); | 
|---|
|  |  |  | event.setCarAttributeName(request.getData().getCarAttributeName()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | event.setCarType(Constants.RetentionCarType.unknown);//默认未登记车辆 | 
|---|
|  |  |  | if(request.getData().getInResult()!=null && request.getData().getInResult().getRlsResult() !=null ){ | 
|---|
|  |  |  | //放行方式 | 
|---|
|  |  |  | event.setReleaseWay(request.getData().getInResult().getRlsResult().getReleaseWay()); | 
|---|
|  |  |  | 
|---|
|  |  |  | Constants.PlatformJobStatus.TRANSFERING.getKey(), | 
|---|
|  |  |  | Constants.PlatformJobStatus.EXCEPTION.getKey() | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | )==Constants.ZERO){ | 
|---|
|  |  |  | )==Constants.ZERO){//如果没进行中任务 | 
|---|
|  |  |  | PlatformJob platformJob = platformJobMapper.selectOne(new QueryWrapper<PlatformJob>().lambda() | 
|---|
|  |  |  | .eq(PlatformJob::getCarCodeFront,event.getPlateNos()) | 
|---|
|  |  |  | .eq(PlatformJob::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | 
|---|
|  |  |  | .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); | 
|---|
|  |  |  | if(Constants.equalsInteger(platformJob.getType(),Constants.ONE)){ | 
|---|
|  |  |  | //如果是自有车装货自动签到 | 
|---|
|  |  |  | jobAutoSignBiz(platformJob); | 
|---|
|  |  |  | }else  if(Constants.equalsInteger(platformJob.getType(),Constants.ZERO)){ | 
|---|
|  |  |  | //如果是自有车卸货 查询TMS合同状态,决定是否自动签到 | 
|---|
|  |  |  | checkTmsContractStatusBiz(platformJob); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | platformJobMapper.updateById(platformJob); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return event; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * ;如果是卸货任务,需要通过TMS提供的“2.2合同列表接口”接口查询车辆对应的合同状态是否为在途状态(对应orderStatus值为3/4/5/6), | 
|---|
|  |  |  | * 如果是自动签到,否则不自动签到;如果一个车辆对应多个合同号,则取运单下任一合同查询对应在途信息 | 
|---|
|  |  |  | * @param platformJob | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void checkTmsContractStatusBiz(PlatformJob platformJob) { | 
|---|
|  |  |  | PlatformWmsDetail detail = platformWmsDetailMapper.selectOne(new QueryWrapper<PlatformWmsDetail>().lambda() | 
|---|
|  |  |  | .eq(PlatformWmsDetail::getIsdeleted, Constants.ZERO) | 
|---|
|  |  |  | .eq(PlatformWmsDetail::getJobId, platformJob.getId()) | 
|---|
|  |  |  | .isNotNull(PlatformWmsDetail::getContractNum) | 
|---|
|  |  |  | .last("limit 1") | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(detail!=null && StringUtils.isNotBlank(detail.getContractNum())){ | 
|---|
|  |  |  | TmsOrderInfoRequest param = new TmsOrderInfoRequest(); | 
|---|
|  |  |  | param.setContractNumber(detail.getContractNum()); | 
|---|
|  |  |  | TmsOrderInfoResponse response = tmsService.orderInfo(param); | 
|---|
|  |  |  | if(response!=null &&( StringUtils.equals(response.getOrderStatus(),"3")  ) | 
|---|
|  |  |  | ||StringUtils.equals(response.getOrderStatus(),"4") | 
|---|
|  |  |  | ||StringUtils.equals(response.getOrderStatus(),"5") | 
|---|
|  |  |  | ||StringUtils.equals(response.getOrderStatus(),"6")){ | 
|---|
|  |  |  | //如果合同在途,则自动签到 | 
|---|
|  |  |  | jobAutoSignBiz(platformJob); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void jobAutoSignBiz(PlatformJob 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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private Retention getRetentionModelByParkRequest(EventParkInfoRequest request,CarEvent event) { | 
|---|
|  |  |  | 
|---|
|  |  |  | .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() )//后车牌号 | 
|---|
|  |  |  | //                        .eq(StringUtils.equals(status.getStockStatus(),"front"),PlatformJob::getCarCodeFront,status.getPlateNo() )//前车牌号 | 
|---|
|  |  |  | .eq(PlatformJob::getIsdeleted,Constants.ZERO ) | 
|---|
|  |  |  | .eq(PlatformJob::getPlatformId,model.getPlatformId() ) | 
|---|
|  |  |  | .orderByDesc(PlatformJob::getCallDate) | 
|---|
|  |  |  | .last("limit 1 ")); | 
|---|
|  |  |  | if(job == null){ | 
|---|
|  |  |  | if(StringUtils.equals(status.getMotionStatus(),"enter")){ | 
|---|
|  |  |  | //如果月台当前没作业,直接提示车辆停错 | 
|---|
|  |  |  | Platform platform = platformMapper.selectJoinOne(Platform.class, new MPJLambdaWrapper<Platform>() | 
|---|
|  |  |  | .selectAll(Platform.class) | 
|---|
|  |  |  | .eq(Platform::getIsdeleted,Constants.ZERO ) | 
|---|
|  |  |  | .eq(PlatformJob::getId,model.getPlatformId() ) | 
|---|
|  |  |  | .last("limit 1 ")); | 
|---|
|  |  |  | if(platform!=null){ | 
|---|
|  |  |  | dealCarsAndPlatformErrorBiz(platform,status); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | continue;//如果作业为空,跳过处理 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | PlatformJob update = new PlatformJob(); | 
|---|
|  |  |  | 
|---|
|  |  |  | platformBroadcastLogMapper.insert(logList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | private void dealCarsAndPlatformErrorBiz( Platform model, EventPlatformCarsStatusInfoRequest status) { | 
|---|
|  |  |  | //处理车辆进入错误月台业务逻辑 | 
|---|
|  |  |  | SavePlatformWarnEventDTO savePlatformWarnEventDTO = new SavePlatformWarnEventDTO(); | 
|---|
|  |  |  | savePlatformWarnEventDTO.setPlatformJobId(model.getId()); | 
|---|
|  |  |  | savePlatformWarnEventDTO.setPlatformId(model.getId()); | 
|---|
|  |  |  | savePlatformWarnEventDTO.setCarCode(status.getPlateNo()); | 
|---|
|  |  |  | savePlatformWarnEventDTO.setEventType(Constants.PlatformWarnEvent.STOP_ERROR.getKey()); | 
|---|
|  |  |  | platformWarnEventService.savePlatformWarnEvent(savePlatformWarnEventDTO); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int speed = 13; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | speed = Integer.parseInt(systemDictDataBiz.queryByCode(Constants.HK_PARAM,Constants.LED_CONTENT_SPEED).getCode()); | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<PlatformDevice> deviceList = platformDeviceMapper.selectList(new QueryWrapper<PlatformDevice>().lambda() | 
|---|
|  |  |  | .eq(PlatformDevice::getPlatformId,model.getId()) | 
|---|
|  |  |  | .eq(PlatformDevice::getIsdeleted,Constants.ZERO)); | 
|---|
|  |  |  | if(deviceList ==null || deviceList.size() == 0){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String content =Constants.PlatformLedContent.WRONG_IN.getInfo(); | 
|---|
|  |  |  | content = content.replace("${param2}",model.getName()); | 
|---|
|  |  |  | 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.isBlank(device.getHkId())){ | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(Constants.equalsInteger(device.getType(),Constants.TWO)){ | 
|---|
|  |  |  | //如果是广播点 | 
|---|
|  |  |  | bNames += device.getName()+";"; | 
|---|
|  |  |  | broadcastList.add(device.getHkId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(broadcastList.size()>0){ | 
|---|
|  |  |  | PlatformJob job = new PlatformJob(); | 
|---|
|  |  |  | job.setId(-1); | 
|---|
|  |  |  | job.setCarCodeFront(status.getPlateNo()); | 
|---|
|  |  |  | job.setPlatformId(model.getId()); | 
|---|
|  |  |  | PlatformBroadcastLog log = dealBroadcastBiz(job,broadcastList,bNames,Constants.PlatformBroadcastContent.WRONG_IN.getInfo().replace("${param}",status.getPlateNo())); | 
|---|
|  |  |  | logList.add(log); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(logList.size()>0){ | 
|---|
|  |  |  | platformBroadcastLogMapper.insert(logList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 广播通知 | 
|---|