package com.doumee.service.business.impl.thrid; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.doumee.core.constants.ResponseStatus; import com.doumee.core.exception.BusinessException; import com.doumee.core.haikang.model.HKConstants; import com.doumee.core.haikang.model.param.BaseListPageResponse; import com.doumee.core.haikang.model.param.BaseResponse; import com.doumee.core.haikang.model.param.BaseListPageRequest; import com.doumee.core.haikang.model.param.request.SensorStatusListRequest; import com.doumee.core.haikang.model.param.respose.PageCameraInfoResponse; import com.doumee.core.haikang.model.param.respose.PageFireChannelInfoResponse; import com.doumee.core.haikang.model.param.respose.PageRegionInfoResponse; import com.doumee.core.haikang.model.param.respose.PageSensorStatusResponse; import com.doumee.core.haikang.service.HKService; import com.doumee.core.model.ApiResponse; import com.doumee.core.utils.Constants; import com.doumee.core.utils.DateUtil; import com.doumee.core.utils.Utils; import com.doumee.dao.business.*; import com.doumee.dao.business.model.*; import com.doumee.dao.web.reqeust.SavePlatformWarnEventDTO; import com.doumee.dao.web.response.platformReport.*; import com.doumee.service.business.impl.PlatformJobServiceImpl; import com.doumee.service.business.third.BoardService; import com.github.yulichang.wrapper.MPJLambdaWrapper; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.*; import java.util.stream.Collectors; /** * TMS平台对接Service实现 * @author 江蹄蹄 * @date 2023/11/30 15:33 */ @Service @Slf4j public class BoardServiceImpl implements BoardService { @Autowired private PlatformLogMapper platformLogMapper; @Autowired private PlatformWarnEventMapper platformWarnEventMapper; @Autowired private PlatformJobMapper platformJobMapper; @Autowired private PlatformWmsDetailMapper platformWmsDetailMapper; @Autowired private PlatformMapper platformMapper; /** * 获取区域树形结构数据 * @return */ @Override public List getRegionTree(CarmeraListVO req){ List allList = new ArrayList<>(); boolean hasNext = true; int curTotal = 0; int curPage = 1; while (hasNext){ //分页遍历循环查询所有门禁设备数据 BaseListPageRequest param = new BaseListPageRequest(); param.setUserId("admin"); param.setPageSize(100); param.setPageNo(curPage); BaseResponse> response = HKService.pageRegions(param); if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){ throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~"); } BaseListPageResponse r = response.getData(); curTotal += 100; if(curTotal >= r.getTotal()){ hasNext = false; } if(r.getList() == null || r.getList().size()==0){ hasNext =false; }else{ allList.addAll(r.getList()); } curPage++; } if(Constants.equalsInteger(req.getWithCameras(),Constants.ONE)){ initReginCameralList(allList,req.getName());//获取全部监控点数据 } List data = new RegionTreeVO(allList).buildTree(); return data; } private void initReginCameralList(List allList,String name) { List carmeraListVOList = cameraList(null); if(carmeraListVOList!=null && carmeraListVOList.size()>0){ for(PageRegionInfoResponse p : allList){ for(CarmeraListVO c : carmeraListVOList){ if(StringUtils.equals(p.getRegionIndexCode(),c.getReginCode()) && (StringUtils.contains(c.getName(),name) ||StringUtils.isBlank(name))){ if(p.getCarmeraList()==null){ p.setCarmeraList(new ArrayList<>()); } p.getCarmeraList().add(c); } } } } } /** * 获取区域树形结构数据 * @return */ @Override public List regionList(CarmeraListVO req){ List allList = new ArrayList<>(); boolean hasNext = true; int curTotal = 0; int curPage = 1; while (hasNext){ //分页遍历循环查询所有门禁设备数据 BaseListPageRequest param = new BaseListPageRequest(); param.setUserId("admin"); param.setPageSize(100); param.setPageNo(curPage); BaseResponse> response = HKService.pageRegions(param); if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){ throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~"); } BaseListPageResponse r = response.getData(); curTotal += 100; if(curTotal >= r.getTotal()){ hasNext = false; } if(r.getList() == null || r.getList().size()==0){ hasNext =false; }else{ allList.addAll(r.getList()); } curPage++; } if(Constants.equalsInteger(req.getWithCameras(),Constants.ONE)){ initReginCameralList(allList,req.getName());//获取全部监控点数据 } return allList; } @Override public List cameraList(CarmeraListVO req){ List allList = new ArrayList<>(); boolean hasNext = true; int curTotal = 0; int curPage = 1; while (hasNext){ //分页遍历循环查询所有门禁设备数据 BaseListPageRequest param = new BaseListPageRequest(); param.setUserId("admin"); param.setPageSize(100); param.setPageNo(curPage); BaseResponse> response = HKService.pageCameras(param); if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){ throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~"); } BaseListPageResponse r = response.getData(); curTotal += 100; if(curTotal >= r.getTotal()){ hasNext = false; } if(r.getList() == null || r.getList().size()==0){ hasNext =false; }else{ allList.addAll(r.getList()); } curPage++; } List data = new ArrayList<>(); for(PageCameraInfoResponse p : allList){ CarmeraListVO t = new CarmeraListVO(); t.setIndexCode(p.getCameraIndexCode()); t.setReginCode(p.getRegionIndexCode()); t.setName(p.getCameraName()); t.setStatus(p.getStatus()); t.setStatusName(p.getStatusName()); data.add(t); } return data; } @Override public List fireChannelList(){ List allList = new ArrayList<>(); boolean hasNext = true; int curTotal = 0; int curPage = 1; while (hasNext){ //分页遍历循环查询所有门禁设备数据 BaseListPageRequest param = new BaseListPageRequest(); param.setUserId("admin"); param.setPageSize(100); param.setPageNo(curPage); BaseResponse> response = HKService.pageFireChannel(param); if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){ throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~"); } BaseListPageResponse r = response.getData(); curTotal += 100; if(curTotal >= r.getTotal()){ hasNext = false; } if(r.getList() == null || r.getList().size()==0){ hasNext =false; }else{ allList.addAll(r.getList()); } curPage++; } return allList; } @Override public List sensorStatusList(){ List allList = new ArrayList<>(); boolean hasNext = true; int curTotal = 0; int curPage = 1; while (hasNext){ //分页遍历循环查询所有门禁设备数据 SensorStatusListRequest param = new SensorStatusListRequest(); param.setPageSize(100); param.setPageNo(curPage); BaseResponse> response = HKService.pageSensorStatus(param); if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){ throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~"); } BaseListPageResponse r = response.getData(); curTotal += 100; if(curTotal >= r.getTotal()){ hasNext = false; } if(r.getList() == null || r.getList().size()==0){ hasNext =false; }else{ allList.addAll(r.getList()); } curPage++; } return allList; } @Override public List platformGroupFinish(){ List data = new ArrayList<>(); List jobList = platformWmsDetailMapper.selectJoinList(PlatformWmsDetail.class, new MPJLambdaWrapper() .selectSum( PlatformWmsDetail::getIoQty) .selectAs(PlatformGroup::getName, PlatformWmsDetail::getGroupName) .leftJoin(PlatformJob.class,PlatformJob::getId,PlatformWmsDetail::getJobId) .rightJoin(PlatformGroup.class,PlatformGroup::getId,PlatformJob::getPlatformGroupId) .eq(PlatformWmsDetail::getIsdeleted, Constants.ZERO) .eq(PlatformJob::getIsdeleted, Constants.ZERO) .in(PlatformJob::getStatus, Constants.PlatformJobStatus.DONE.getKey() , Constants.PlatformJobStatus.AUTHED_LEAVE.getKey() , Constants.PlatformJobStatus.LEAVED.getKey()) .apply("to_days(t1.create_date) = to_days(now())") .groupBy(PlatformGroup::getId) ); if(jobList!=null){ for(PlatformWmsDetail d : jobList){ PlatformGroupFinishVO t = new PlatformGroupFinishVO(); t.setFinishData(Constants.formatBigdecimal(d.getIoQty()).intValue()); t.setPlatformGroupName(d.getGroupName()); } } return data; } @Override public CarWorkSituationVO carWorkSituation(int limit){ CarWorkSituationVO carWorkSituationVO = new CarWorkSituationVO(); List platformLogList = platformLogMapper.selectList(new QueryWrapper().lambda() .orderByDesc(PlatformLog::getCreateDate) .last(" limit "+limit) ); carWorkSituationVO.setPlatformLogList(platformLogList); return carWorkSituationVO; } @Override public List platformWorkData(){ List platformWorkDataVOList = new ArrayList<>(); List platformList = platformMapper.selectJoinList(Platform.class, new MPJLambdaWrapper() .selectAll( Platform.class) .eq(Platform::getIsdeleted, Constants.ZERO) .orderByAsc(Platform::getSortnum) ); /** * WAIT_CONFIRM(0, "待确认","待确认" ), * WART_SIGN_IN(1, "待签到","待签到" ), * WAIT_CALL(2, "已签到","已签到"), * IN_WAIT(3, "入园等待","入园等待" ), * CALLED(4, "已叫号","已叫号" ), * WORKING(5, "作业中","作业中" ), * DONE(6, "作业完成 ","作业完成" ), * TRANSFERING(7, "转移中","转移中" ), * EXCEPTION(8, "异常挂起","异常挂起" ), * AUTHED_LEAVE(9, "已授权离园","已授权离园" ), * LEAVED(10, "已离园 ","已离园 " ), * OVER_NUMBER(11, "已过号","已过号" ), * CANCEL(12, "已取消","已取消" ), */ if(platformList!=null && platformList.size()>0){ List jobList = platformJobMapper.selectJoinList(PlatformJob.class, new MPJLambdaWrapper() .selectAll( PlatformJob.class) .select("( select pl.CREATE_DATE from platform_log pl where t.id = pl.obj_id and pl.OBJ_TYPE = "+Constants.PlatformJobLogType.WORKING.getKey()+" order by pl.CREATE_DATE desc limit 1 ) as newStartDate") .select(" (select sum(ifnull(pl.IO_QTY , 0 )) from platform_wms_detail pl where pl.job_id = t.id and pl.isdeleted=0 )",PlatformJob::getWorkNum) .apply("to_days(t.create_date) = to_days(now())") .eq(Platform::getIsdeleted, Constants.ZERO) .in(PlatformJob ::getStatus,new Integer[]{Constants.PlatformJobStatus.WORKING.getKey(),Constants.PlatformJobStatus.CALLED.getKey() }) .orderByDesc(PlatformJob::getStatus )); //月台状态:0=作业中;1=空闲中;2=作业超时;3=叫号 for(Platform model : platformList){ PlatformWorkDataVO platformDurationVO = new PlatformWorkDataVO(); platformDurationVO.setPlatformName(model.getName()); platformDurationVO.setPlatformId(model.getId()); platformDurationVO.setPlatformSort(model.getSortnum()); PlatformJob job = getJobFromListById(model.getId(),jobList); if(job != null){ if(Constants.equalsInteger(job.getType(),Constants.ONE) || Constants.equalsInteger(job.getType(),Constants.THREE)){ platformDurationVO.setWorkType(Constants.ONE);//如果是装货 }else{ platformDurationVO.setWorkType(Constants.ZERO);//如果是卸货 } Integer workMinute = job.getWorkNum().multiply(new BigDecimal(60)).divide(model.getWorkRate(),0,BigDecimal.ROUND_HALF_UP).intValue(); Date overDate = DateUtil.getXMinuteAfterDate(job.getNewStartDate(),workMinute + model.getWorkTimeoutAlarmTime());//预计完成时间 platformDurationVO.setFinishTimeStr(DateUtil.DateToStr(overDate,"HH:mm")); platformDurationVO.setWorkNum(Constants.formatBigdecimal(job.getWorkNum()).intValue()); platformDurationVO.setCarNo(job.getCarCodeFront());//车牌号 if(Constants.equalsInteger(job.getStatus(),Constants.PlatformJobStatus.CALLED.getKey() )){ platformDurationVO.setStatus(Constants.THREE); //叫号中 }else{ platformDurationVO.setStatus(Constants.ZERO); //作业中 platformDurationVO.setWorkTime(PlatformJobServiceImpl.getWorkTime(job,platformLogMapper));//已工作时间 if(overDate.getTime() < System.currentTimeMillis() ){ model.setStatus(Constants.TWO); //作业已超时 } } }else{ platformDurationVO.setStatus(Constants.ONE);//空闲中 } platformWorkDataVOList.add(platformDurationVO); } } return platformWorkDataVOList; } private PlatformJob getJobFromListById(Integer id, List jobList) { if(jobList!=null){ for(PlatformJob job :jobList){ if(Constants.equalsInteger(job.getPlatformId(),id)){ return job; } } } return null; } /** * * @param type 查询类型:0=入库;1=出库 * @return */ @Override public List workEfficiency(Integer type){ //作业类型 0自有车卸货 1自有车装货 2外协车卸货 3外协车装货 4市公司外协车卸货 List workEfficiencyVOList = new ArrayList<>(); List jobList = platformWmsDetailMapper.selectJoinList(PlatformWmsDetail.class, new MPJLambdaWrapper() .selectAll( PlatformWmsDetail.class) .selectAs( PlatformJob::getDoneDate,PlatformWmsDetail::getDoneDate) .leftJoin(PlatformJob.class,PlatformJob::getId,PlatformWmsDetail::getJobId) .eq(PlatformWmsDetail::getIsdeleted, Constants.ZERO) .eq(PlatformJob::getIsdeleted, Constants.ZERO) .in(Constants.equalsInteger(type,Constants.ZERO),PlatformJob::getType,new Integer[]{0,2,4}) .in(Constants.equalsInteger(type,Constants.ONE),PlatformJob::getType,new Integer[]{1,3}) .in(PlatformJob::getStatus, Constants.PlatformJobStatus.DONE.getKey() , Constants.PlatformJobStatus.AUTHED_LEAVE.getKey() , Constants.PlatformJobStatus.LEAVED.getKey()) .apply("to_days(t1.create_date) = to_days(now())") ); int curtotalNum = 0; Date today = Utils.Date.getStart(new Date()); long curTime=0, lastTime=0; for (int i = 0; i < 8; i++) { lastTime = curTime;//上次的时间 int curHour = 8+(i*2); long time = curHour*60*60*1000 + today.getTime(); WorkEfficiencyVO workEfficiencyVO = new WorkEfficiencyVO(); workEfficiencyVO.setWorkTime(curHour+":00"); if(jobList!=null && jobList.size()>0){ for(PlatformWmsDetail detail : jobList){ if(detail.getDoneDate()!=null && detail.getDoneDate().getTime()<= time){ //当前量 if(detail.getDoneDate()!=null && detail.getDoneDate().getTime() > lastTime){ //区间值 取实近2小时内的累计值 workEfficiencyVO.setWorkNum(Constants.formatIntegerNum(workEfficiencyVO.getWorkNum())+Constants.formatBigdecimal(detail.getIoQty()).intValue()); } //累积量 curtotalNum += Constants.formatBigdecimal(detail.getIoQty()).intValue(); } } } workEfficiencyVO.setTotalWorkNum(curtotalNum);//累计值 workEfficiencyVOList.add(workEfficiencyVO); } return workEfficiencyVOList; } @Override public List platformDuration(){ List platformDurationList = new ArrayList<>(); List jobList = platformMapper.selectJoinList(Platform.class, new MPJLambdaWrapper() .selectAll( Platform.class) .select(" ( select ROUND( ifnull(SUM(pl.PARAM3),0)/60 , 2 ) from platform_log pl where pl.remark = t.id and to_days(pl.CREATE_DATE) =to_days now())",Platform::getWorkCountTime) .eq(Platform::getIsdeleted, Constants.ZERO) ); if(jobList!=null){ //按工作时长累计倒序排序 Collections.sort(jobList, new Comparator() { @Override public int compare(Platform o1, Platform o2) { return Constants.formatBigdecimal(o2.getWorkCountTime()).intValue() - Constants.formatBigdecimal(o1.getWorkCountTime()).intValue(); } }); for(Platform model : jobList){ PlatformDurationVO data = new PlatformDurationVO(); data.setPlatformId(model.getId()); data.setPlatformName(model.getName()); data.setWorkTotalTime(Constants.formatBigdecimal(model.getWorkCountTime()).intValue()); platformDurationList.add(data); } } return platformDurationList; } @Override public List warningList(int limit){ List platformLogList = platformWarnEventMapper.selectList(new QueryWrapper().lambda() .eq(PlatformWarnEvent::getIsdeleted,Constants.ZERO) .orderByDesc(PlatformWarnEvent::getCreateDate) .last(" limit "+limit) ); return platformLogList; } @Override public OnSitDispatchBoardVO getCnddCenterData(){ OnSitDispatchBoardVO data = new OnSitDispatchBoardVO(); //月台总数 List list = platformMapper.selectJoinList(Platform.class,new MPJLambdaWrapper() .selectAll(Platform.class) .select(" ( select count(1) from platform_job pj where t.id = pj.PLATFORM_ID and pj.STATUS = "+Constants.PlatformJobStatus.WORKING.getKey()+" ) as workStatus ") .eq(Platform::getIsdeleted,Constants.ZERO) ); data.setPlatformTotal(list==null?0:list.size()); //空闲月台数量 data.setFreePlatform( list.stream().filter(i->Constants.formatIntegerNum(i.getWorkStatus())<=Constants.ZERO).collect(Collectors.toList()).size() ); //查询今日月台个状态作业数量 List jobList = platformJobMapper.selectJoinList(PlatformJob.class,new MPJLambdaWrapper() .selectAll(PlatformJob.class) .select("count(id)" ,PlatformJob::getCountum) .eq(PlatformJob::getIsdeleted,Constants.ZERO) .apply("to_days(create_date) = to_days(now())" ) .groupBy(PlatformJob::getStatus ) ); if(jobList!=null){ //-------------TODO----------【看板】爱确认需求-------------- // * 0待确认 1待签到 2等待叫号 3入园等待 4已叫号 5作业中 6作业完成 7转移中 8异常挂起 9已授权离园 10已离园 11 已过号 12已取消 for(PlatformJob model : jobList){ //待确认 (预约车) if( Constants.equalsInteger(model.getStatus(),Constants.PlatformJobStatus.WAIT_CONFIRM.getKey())){ data.setReservationCar(data.getReservationCar()+Constants.formatIntegerNum(model.getCountum())); } //待签到(预约车) if( Constants.equalsInteger(model.getStatus(),Constants.PlatformJobStatus.WART_SIGN_IN.getKey())){ data.setReservationCar(data.getReservationCar()+Constants.formatIntegerNum(model.getCountum())); } //等待叫号(预约车、签到数、排队车) if(Constants.equalsInteger(model.getStatus(),Constants.PlatformJobStatus.WAIT_CALL.getKey())){ data.setSignedNum(data.getSignedNum()+Constants.formatIntegerNum(model.getCountum())); data.setReservationCar(data.getReservationCar()+Constants.formatIntegerNum(model.getCountum())); data.setLineUpCar(data.getLineUpCar()+Constants.formatIntegerNum(model.getCountum())); } //入园等待(预约车、签到数) if( Constants.equalsInteger(model.getStatus(),Constants.PlatformJobStatus.IN_WAIT.getKey())){ data.setSignedNum(data.getSignedNum()+Constants.formatIntegerNum(model.getCountum())); data.setReservationCar(data.getReservationCar()+Constants.formatIntegerNum(model.getCountum())); } //已叫号(预约车、签到数、已叫号) if(Constants.equalsInteger(model.getStatus(),Constants.PlatformJobStatus.CALLED.getKey()) ){ data.setSignedNum(data.getSignedNum()+Constants.formatIntegerNum(model.getCountum())); data.setReservationCar(data.getReservationCar()+Constants.formatIntegerNum(model.getCountum())); data.setCalledNum(data.getCalledNum()+Constants.formatIntegerNum(model.getCountum())); } // 作业车辆(预约车、签到数、已叫号、作业车) if(Constants.equalsInteger(model.getStatus(),Constants.PlatformJobStatus.WORKING.getKey())){ data.setSignedNum(data.getSignedNum()+Constants.formatIntegerNum(model.getCountum())); data.setReservationCar(data.getReservationCar()+Constants.formatIntegerNum(model.getCountum())); data.setCalledNum(data.getCalledNum()+Constants.formatIntegerNum(model.getCountum())); data.setWorkedNum(data.getWorkedNum()+Constants.formatIntegerNum(model.getCountum())); } // 作业完成(预约车、签到数、已叫号、作业车、已完成) if(Constants.equalsInteger(model.getStatus(),Constants.PlatformJobStatus.DONE.getKey())){ data.setSignedNum(data.getSignedNum()+Constants.formatIntegerNum(model.getCountum())); data.setReservationCar(data.getReservationCar()+Constants.formatIntegerNum(model.getCountum())); data.setCalledNum(data.getCalledNum()+Constants.formatIntegerNum(model.getCountum())); data.setWorkedNum(data.getWorkedNum()+Constants.formatIntegerNum(model.getCountum())); data.setDoneNum(data.getDoneNum()+Constants.formatIntegerNum(model.getCountum())); } // 转移中(预约车、签到数、排队车) if(Constants.equalsInteger(model.getStatus(),Constants.PlatformJobStatus.TRANSFERING.getKey())){ data.setSignedNum(data.getSignedNum()+Constants.formatIntegerNum(model.getCountum())); data.setReservationCar(data.getReservationCar()+Constants.formatIntegerNum(model.getCountum())); data.setLineUpCar(data.getLineUpCar()+Constants.formatIntegerNum(model.getCountum())); } // 已授权离园(预约车、签到数、已叫号、作业车、已完成) if(Constants.equalsInteger(model.getStatus(),Constants.PlatformJobStatus.AUTHED_LEAVE.getKey())){ data.setSignedNum(data.getSignedNum()+Constants.formatIntegerNum(model.getCountum())); data.setReservationCar(data.getReservationCar()+Constants.formatIntegerNum(model.getCountum())); data.setCalledNum(data.getCalledNum()+Constants.formatIntegerNum(model.getCountum())); data.setWorkedNum(data.getWorkedNum()+Constants.formatIntegerNum(model.getCountum())); data.setDoneNum(data.getDoneNum()+Constants.formatIntegerNum(model.getCountum())); } // 已离园 if(Constants.equalsInteger(model.getStatus(),Constants.PlatformJobStatus.LEAVED.getKey())){ data.setWorkingCar(data.getWorkingCar()+Constants.formatIntegerNum(model.getCountum())); } // 已过号(预约车、签到数、排队车) if(Constants.equalsInteger(model.getStatus(),Constants.PlatformJobStatus.OVER_NUMBER.getKey())){ data.setSignedNum(data.getSignedNum()+Constants.formatIntegerNum(model.getCountum())); data.setReservationCar(data.getReservationCar()+Constants.formatIntegerNum(model.getCountum())); data.setLineUpCar(data.getLineUpCar()+Constants.formatIntegerNum(model.getCountum())); } // 已取消(预约车) if(Constants.equalsInteger(model.getStatus(),Constants.PlatformJobStatus.CANCEL.getKey())){ data.setReservationCar(data.getReservationCar()+Constants.formatIntegerNum(model.getCountum())); } } } return data; } }