RiskAssessmentService.java 22.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
package cn.com.glsx.admin.modules.service;

import cn.com.glsx.admin.common.constants.Constants;
import cn.com.glsx.admin.common.enums.StuAlarmTypeEnum;
import cn.com.glsx.admin.common.enums.TypeConverseEnum;
import cn.com.glsx.admin.common.exception.AdminException;
import cn.com.glsx.admin.modules.converter.RiskAssessmentConvert;
import cn.com.glsx.admin.modules.entity.*;
import cn.com.glsx.admin.modules.mapper.*;
import cn.com.glsx.admin.modules.model.dto.BasicDeviceDTO;
import cn.com.glsx.admin.modules.model.dto.BasicInformationDTO;
import cn.com.glsx.admin.modules.model.dto.UserBehaviorDayDTO;
import cn.com.glsx.admin.modules.model.dto.UserBehaviorWeekDTO;
import cn.com.glsx.admin.modules.model.export.OfflineExport;
import cn.com.glsx.admin.modules.model.vo.*;
import cn.com.glsx.admin.modules.remote.*;
import cn.com.glsx.admin.modules.utils.DateUtil;
import cn.com.glsx.alarm.services.model.StuJudgeAlarmDto;
import cn.com.glsx.auth.utils.ShieldContextHolder;
import cn.com.glsx.devicemonitor.api.dto.LngLatDTO;
import cn.com.glsx.devicemonitor.api.dto.request.ResidentRequest;
import cn.com.glsx.devicemonitor.api.dto.request.StayPointRequest;
import cn.com.glsx.devicemonitor.api.dto.response.*;
import cn.com.glsx.devicemonitor.api.enums.DeviceStatusEnum;
import cn.hutool.json.JSONUtil;
import com.glsx.plat.common.utils.StringUtils;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 风险评估 service
 */
@Slf4j
@Service
public class RiskAssessmentService {

    @Autowired
    private WorkOrderMapper workOrderMapper;
    @Autowired
    private VehicleMapper vehicleMapper;
    @Autowired
    private DeviceMapper deviceMapper;
    @Autowired
    private VehicleDeviceMapper vehicleDeviceMapper;
    @Autowired
    private RemoteFeignDeviceService remoteFeignDeviceService;
    @Autowired
    private RemoteGpsBsService remoteGpsBsService;
    @Autowired
    private RemoteFeignStayPointService remoteFeignStayPointService;
    @Autowired
    private RemoteFeignResidentService remoteFeignResidentService;
    @Autowired
    private RemoteAlarmService remoteAlarmService;
    @Autowired
    private AlarmWarnAnalyseMapper alarmWarnAnalyseMapper;
    @Autowired
    private DeviceJourneyMapper deviceJourneyMapper;
    @Autowired
    private RemoteStuJudgeAlarmService remoteStuJudgeAlarmService;
    @Autowired
    private FakeOfflineVinMapper fakeOfflineVinMapper;
    @Autowired
    private FakeOfflineChangeFrequentlyMapper fakeOfflineChangeFrequentlyMapper;
    @Autowired
    private OrganizationApiService organizationApiService;
    @Autowired
    private WhitelistSnMapper whitelistSnMapper;
    @Autowired
    private DeviceStayOftenMapper deviceStayOftenMapper;

    /**
     * 获取停留点列表
     *
     * @param vehicleId 车辆ID
     * @return
     */
    public List<StayPointListVO> getStayPointList(Long vehicleId) {
        if (Objects.isNull(vehicleId)) {
            log.warn("该车辆ID不存在");
            throw new AdminException("该车辆ID不存在");
        }
        // 通过车辆ID获取设备主有线设备
        List<BasicDeviceDTO> basicDeviceDTOList = vehicleDeviceMapper.selectBindDeviceByVehicleIdOrderByCreatedDate(vehicleId);
        Optional<BasicDeviceDTO> basicDeviceDTO = basicDeviceDTOList.stream().filter(dto -> TypeConverseEnum.SourceEnum.HAS_SOURCE.getSourceType().equals(dto.getSource())).findFirst();
        basicDeviceDTO.orElseGet(() -> {
            log.warn("该车辆绑定的主设备不存在");
            throw new AdminException("该车辆绑定的主设备不存在");
        });

        // 通过设备号获取最后定位点
        // 通过设备号获取设备类型
        String sn = basicDeviceDTO.get().getSn();
        Device device = deviceMapper.selectBySn(sn);
        if (Objects.isNull(device)) {
            log.warn("该设备不存在");
            throw new AdminException("该设备不存在");
        }
        GpsBsData gpsBsData = remoteGpsBsService.getLastGpsBsBySn(device.getSn(), TypeConverseEnum.DeviceTypeEnum.getMiniStrByDeviceType(device.getDeviceType()));
        if (Objects.isNull(gpsBsData)) {
            log.warn(sn + "暂无定位数据");
            throw new AdminException(sn + "暂无定位数据");
        }
        GpsLocation gpsLocation = gpsBsData.getGpsLocation();
        if (Objects.isNull(gpsLocation)) {
            log.warn(sn + "暂无GPS定位数据");
            throw new AdminException(sn + "暂无GPS定位数据");
        }
        StayPointRequest request = new StayPointRequest();
        request.setSn(sn);
        // 查询时间段 全天
        request.setPeriodType(0);
        request.setBeginTime(DateUtil.parseDateYmd(gpsLocation.getDateTime()));
        request.setEndTime(DateUtil.getOffsetDayDate(DateUtil.parseDateYmd(gpsLocation.getDateTime()), -30));
        request.setMax(null);
        request.setMin(null);
        List<StayPointRecordDTO> stayPointRecordList = remoteFeignStayPointService.getStayPointRecord(request);
        if (CollectionUtils.isEmpty(stayPointRecordList)) {
            log.warn(sn + "暂设备暂无历史停留点");
            throw new AdminException(sn + "暂设备暂无历史停留点");
        }
        // 组装停留点轨迹数据
        // 通过设备号查询车辆信息
        List<Vehicle> vehicleInfoList = vehicleMapper.findVehicleInfoBySn(sn);
        if (CollectionUtils.isNotEmpty(vehicleInfoList)) {
            log.warn(sn + "暂设备绑定车辆数据不存在");
            throw new AdminException(sn + "暂设备绑定车辆数据不存在");
        }
        Vehicle vehicle = vehicleInfoList.get(0);
        //获取地址信息
        List<LngLatDTO> lngLats = stayPointRecordList.stream().filter(e -> Objects.nonNull(e.getStayGps())).map(e -> new LngLatDTO(e.getStayGps().getElng(), e.getStayGps().getElat())).collect(Collectors.toList());
        LngLatAddressDTO addressDTO = remoteGpsBsService.getAddressMap(lngLats);
        Map<String, String> addressMap = Optional.ofNullable(addressDTO).map(LngLatAddressDTO::getAddress).orElse(Maps.newHashMap());
        return stayPointRecordList.stream().map(stayPoint -> RiskAssessmentConvert.buildStayPointListVO(stayPoint, vehicle, sn, Optional.ofNullable(stayPoint.getStayGps()).map(e -> e.getElat() + e.getElng()).map(addressMap::get).orElse(Constants.EMPTY_CONTENT_EXCEL))).collect(Collectors.toList());
    }

    /**
     * 获取设备基础信息
     *
     * @param vehicleId 车辆ID
     * @return 设备基础信息
     */
    public BasicInformationVO getBasicInformation(Long vehicleId) {
        if (Objects.isNull(vehicleId)) {
            log.warn("该车辆ID为空");
            throw new AdminException("该车辆ID为空");
        }
        BasicInformationVO basicInformationVO = new BasicInformationVO();
        // 1 通过设备号获取门店以及车辆信息
        BasicInformationDTO basicInformationDTO = vehicleMapper.getBasicInformationByVehicleId(vehicleId);
        if (Objects.isNull(basicInformationDTO)) {
            log.warn("该车辆信息为空");
            throw new AdminException(vehicleId + "该车辆信息为空");
        }
        basicInformationVO.setLesseeName(basicInformationDTO.getLesseeName());
        basicInformationVO.setShopName(basicInformationDTO.getShopName());
        basicInformationVO.setUserName(ShieldContextHolder.getUsername());
        basicInformationVO.setWorkOrderNo(basicInformationDTO.getWorkOrderNo());
        basicInformationVO.setVin(basicInformationDTO.getVin());
        basicInformationVO.setCreateTime(basicInformationDTO.getCreateTime());
        // 通过设备号获取设备组合信息
        String sns = basicInformationDTO.getSns();
        String sources = basicInformationDTO.getSources();
        String deviceTypes = basicInformationDTO.getDeviceTypes();
        Map<String, Integer> snsMap = Maps.newHashMap();
        List<String> snsList = Arrays.stream(sns.split(",")).collect(Collectors.toList());
        List<Integer> sourceList = Arrays.stream(sources.split(",")).map(Integer::parseInt).collect(Collectors.toList());
        List<Integer> deviceTypeList = Arrays.stream(deviceTypes.split(",")).map(Integer::parseInt).collect(Collectors.toList());
        snsList.forEach(s -> snsMap.put(s, deviceTypeList.get(snsList.indexOf(s))));
        // 获取设备号对应的设备状态
        Map<String, DeviceStatusModel> deviceStatusMap = remoteFeignDeviceService.getDeviceStatusBySns(snsMap);
        // 获取设备号对应的定位信息
        Map<String, GpsBsData> lastGpsBsBySnsMap = remoteGpsBsService.getLastGpsBsBySnsMap(snsMap);
        List<DeviceInformationVO> deviceInformationVOList = Lists.newArrayList();
        snsList.forEach(sn -> {
            DeviceInformationVO deviceInformationVO = new DeviceInformationVO();
            deviceInformationVO.setSn(sn);
            deviceInformationVO.setSource(sourceList.get(snsList.indexOf(sn)));
            deviceInformationVO.setSourceStr(TypeConverseEnum.SourceEnum.getStrBySourceType(sourceList.get(snsList.indexOf(sn))));

            //设置设备状态
            DeviceStatusModel statusModel = deviceStatusMap.get(sn);
            if (statusModel != null) {
                deviceInformationVO.setDeviceState(statusModel.getStatus());
                String deviceStateStr = DeviceStatusEnum.getNameByCode(statusModel.getStatus());
                if (StringUtils.isNotEmpty(statusModel.getStatusTime())) {
                    deviceStateStr = deviceStateStr.concat("(" + statusModel.getStatusTime() + ")");
                }
                deviceInformationVO.setDeviceStateStr(deviceStateStr);
            } else {
                deviceInformationVO.setDeviceState(DeviceStatusEnum.OFFLINE.getCode());
                deviceInformationVO.setDeviceStateStr(DeviceStatusEnum.OFFLINE.getName());
            }
            deviceInformationVOList.add(deviceInformationVO);

            GpsBsData gpsBsData = lastGpsBsBySnsMap.get(sn);
            if (Objects.nonNull(gpsBsData)) {
                GpsLocation gpsLocation = gpsBsData.getGpsLocation();
                GpsLocation bsLocation = gpsBsData.getBsLocation();
                if (Objects.nonNull(gpsLocation) && Objects.nonNull(bsLocation) && DateUtil.compareDate(gpsLocation.getDateTime(), bsLocation.getDateTime())) {
                    deviceInformationVO.setLng(gpsBsData.getGpsLocation().getLng());
                    deviceInformationVO.setLat(gpsBsData.getGpsLocation().getLat());
                    deviceInformationVO.setAddress(remoteGpsBsService.getAddressByLngAndLat(gpsBsData.getGpsLocation().getLng(), gpsBsData.getGpsLocation().getLat()));
                } else if (Objects.nonNull(gpsLocation)) {
                    deviceInformationVO.setLng(gpsBsData.getGpsLocation().getLng());
                    deviceInformationVO.setLat(gpsBsData.getGpsLocation().getLat());
                    deviceInformationVO.setAddress(remoteGpsBsService.getAddressByLngAndLat(gpsBsData.getGpsLocation().getLng(), gpsBsData.getGpsLocation().getLat()));
                } else if (Objects.nonNull(bsLocation)) {
                    deviceInformationVO.setLng(gpsBsData.getBsLocation().getLng());
                    deviceInformationVO.setLat(gpsBsData.getBsLocation().getLat());
                    deviceInformationVO.setAddress(remoteGpsBsService.getAddressByLngAndLat(gpsBsData.getBsLocation().getLng(), gpsBsData.getBsLocation().getLat()));
                }
            }
        });
        basicInformationVO.setDeviceInformationVOList(deviceInformationVOList);
        return basicInformationVO;
    }

    public ResidentInformationVO getResidentInformation(Long vehicleId) {
        if (Objects.isNull(vehicleId)) {
            log.warn("该车辆ID不存在");
            throw new AdminException("该车辆ID不存在");
        }
        // 通过车辆ID获取设备主有线设备
        List<BasicDeviceDTO> basicDeviceDTOList = vehicleDeviceMapper.selectBindDeviceByVehicleIdOrderByCreatedDate(vehicleId);
        Optional<BasicDeviceDTO> basicDeviceDTO = basicDeviceDTOList.stream().filter(dto -> TypeConverseEnum.SourceEnum.HAS_SOURCE.getSourceType().equals(dto.getSource())).findFirst();
        log.info("basicDeviceDTO===" + JSONUtil.toJsonStr(basicDeviceDTO));
        basicDeviceDTO.orElseGet(() -> {
            log.warn("该车辆绑定的主设备不存在");
            throw new AdminException("该车辆绑定的主设备不存在");
        });
        ResidentInformationVO residentInformationVO = new ResidentInformationVO();
        // 设置常住地
        List<ResidentDTO> residentList = remoteFeignResidentService.getResidentList(buildResidentRequest(basicDeviceDTO.get().getSn()));
        // 常驻地,是“截止目前”的条件,选驻留次数最多的那个
        residentList.stream().min((o1, o2) -> o2.getTotalTimes() - o1.getTotalTimes()).ifPresent(residentDTO -> {
            String addressByLngAndLat = remoteGpsBsService.getAddressByLngAndLat(residentDTO.getElng(), residentDTO.getElat());
            residentInformationVO.setResidence(addressByLngAndLat);
        });

        // 添加预测家庭地址和预测工作地址
        DeviceStayOften deviceStayOften = deviceStayOftenMapper.selectOneBySn(basicDeviceDTO.get().getSn());
        if (Objects.nonNull(deviceStayOften)) {
            residentInformationVO.setHomeAddress(deviceStayOften.getHomeAddress());
            residentInformationVO.setWorkAddress(deviceStayOften.getWorkAddress());
        }
        return residentInformationVO;
    }

    /**
     * 构建 request
     */
    private ResidentRequest buildResidentRequest(String sn) {
        //2为无源设备查询基站;1为有源设备查询GPS
        Device device = deviceMapper.selectBySn(sn);
        VehicleDevice vehicleDevice = vehicleDeviceMapper.selectBindDeviceBySn(sn);
        boolean isGps = Objects.isNull(device) || Objects.equals(device.getSource(), 1);
        int lacType = isGps ? 1 : 2;
        Date deviceActivateTime = Optional.ofNullable(vehicleDevice).map(VehicleDevice::getCreatedDate).orElse(new Date());
        //ICE接口查询常驻地列表
        return RiskAssessmentConvert.buildResidentRequest(sn, DateUtil.formatDate(deviceActivateTime), DateUtil.getNowDateTimeFormat(), lacType);
    }

    /**
     * 查询设备号警情风控登记数据
     *
     * @param vehicleId 车辆ID
     * @return 风控登记数据
     */
    public Set<AlarmInformationVO> getAlarmInformation(Long vehicleId) {
        // 校验车架号
        if (Objects.isNull(vehicleId)) {
            log.warn("该车辆ID不存在");
            throw new AdminException("该车辆ID不存在");
        }
        // 通过车辆ID获取设备主有线设备
        List<BasicDeviceDTO> basicDeviceDTOList = vehicleDeviceMapper.selectBindDeviceByVehicleIdOrderByCreatedDate(vehicleId);
        Optional<BasicDeviceDTO> basicDeviceDTO = basicDeviceDTOList.stream().filter(dto -> TypeConverseEnum.SourceEnum.HAS_SOURCE.getSourceType().equals(dto.getSource())).findFirst();
        basicDeviceDTO.orElseGet(() -> {
            log.warn("该车辆绑定的主设备不存在");
            throw new AdminException("该车辆绑定的主设备不存在");
        });
        Set<AlarmInformationVO> basicAlarmDTOSet = Sets.newHashSet();
        // 防拆报警 需要统计所有设备 只有有一个设备有报警 则报风险等级
        List<String> snList = basicDeviceDTOList.stream().map(BasicDeviceDTO::getSn).collect(Collectors.toList());
        Integer tearDownAlarmNum = remoteAlarmService.countAlarmRec(snList, Constants.TEAR_DOWN_ALARM_TYPE);
        if (tearDownAlarmNum > 0) {
            basicAlarmDTOSet.add(new AlarmInformationVO("防拆报警", 1, "建议电呼或者家访"));
        }
        Integer powerOffAlarmNum = remoteAlarmService.countAlarmRec(snList, Constants.POWER_OFF_ALARM_TYPE);
        if (powerOffAlarmNum > 0) {
            basicAlarmDTOSet.add(new AlarmInformationVO("防拆报警", 1, "建议电呼或者家访"));
        }
        // 高危区域内长停 警情中心警情
        List<AlarmWarnAnalyse> alarmWarnAnalyseList = alarmWarnAnalyseMapper.selectByVehicleId(vehicleId);
        alarmWarnAnalyseList.forEach(alarmWarnAnalyse -> basicAlarmDTOSet.add(new AlarmInformationVO(alarmWarnAnalyse.getAlarmExplain(), alarmWarnAnalyse.getAlarmLevel(), alarmWarnAnalyse.getAlarmSuggest())));

        // 聚集报警
        List<StuJudgeAlarmDto> aggregationAlarmDataList = remoteStuJudgeAlarmService.getStuJudgeAlarmDataList(snList, StuAlarmTypeEnum.ABNORMAL_AGGREGATION.getCode());
        if (CollectionUtils.isNotEmpty(aggregationAlarmDataList)) {
            basicAlarmDTOSet.add(new AlarmInformationVO("聚集报警", 1, "建议核实用车情况"));
        }

        // 黑区报警
        List<StuJudgeAlarmDto> blackAreaAlarmDatalist = remoteStuJudgeAlarmService.getStuJudgeAlarmDataList(snList, StuAlarmTypeEnum.BLACK_AREA.getCode());
        if (CollectionUtils.isNotEmpty(blackAreaAlarmDatalist)) {
            basicAlarmDTOSet.add(new AlarmInformationVO("黑区报警", 1, "建议核实用车情况"));
        }

        // 计算真离线
        calculateTrueOffline(vehicleId, snList, basicAlarmDTOSet);
        return basicAlarmDTOSet.stream().sorted(Comparator.comparingInt(AlarmInformationVO::getAlarmLevel)).collect(Collectors.toCollection(LinkedHashSet::new));
    }

    /**
     * 计算真离线
     */
    private void calculateTrueOffline(Long vehicleId, List<String> snList, Set<AlarmInformationVO> basicAlarmDTOSet) {
        // 离线时间计算
        String OfflineStartTime = DateUtil.formatDate(DateUtils.addHours(new Date(), -72));
        // 判断是否是离线
        List<OfflineExport> offlineExportList = vehicleMapper.findOfflineDataByVehicleId(vehicleId, OfflineStartTime);
        if (CollectionUtils.isEmpty(offlineExportList)) {
            // 为空表示没有离线数据
            return;
        }
        // 判断是否是假性离线
        List<String> vinList = offlineExportList.stream().map(OfflineExport::getVin).collect(Collectors.toList());
        // 假性离线的三种情况
        Boolean flag = Boolean.TRUE;
        // 一 获取设备都离线 最后定位点在家庭围栏或者工作地围栏 获取车架通过权限控制 当存在设备都离线的车辆时才进行计算
        if (offlineExportList.size() == snList.size()) {
            List<String> fakeOfflineVinList = fakeOfflineVinMapper.getFakeOfflineVinByFence(vinList);
            if (CollectionUtils.isNotEmpty(fakeOfflineVinList)) {
                flag = Boolean.FALSE;
            }
        }
        // 二 十日内状态反复变化 假性离线
        List<FakeOfflineChangeFrequently> changeFrequentlyList = fakeOfflineChangeFrequentlyMapper.listByVin(vinList);
        if (CollectionUtils.isNotEmpty(changeFrequentlyList)) {
            flag = Boolean.FALSE;
        }
        // 三 获取本部门以及下级部门的白名单
        Set<Long> deptIds = organizationApiService.getAllSubOrgIds();
        log.info("userId:" + ShieldContextHolder.getUserId() + ";deptIds:" + JSONUtil.toJsonStr(deptIds));
        // 从白名单列表获取白名单设备号及其车架号
        List<String> writeListVinList = whitelistSnMapper.getWriteListVin(deptIds);
        if (CollectionUtils.isNotEmpty(writeListVinList)) {
            flag = Boolean.FALSE;
        }
        // 判断是否是真离线
        if (flag) {
            basicAlarmDTOSet.add(new AlarmInformationVO("离线报警", 3, "建议核实用车情况"));
        }
    }

    /**
     * 进行用户行为数据查询
     *
     * @param vehicleId 车辆ID
     * @return
     */
    public UserBehaviorInformationVO getUserBehaviorInformation(Long vehicleId) {
        // 校验车架号
        if (Objects.isNull(vehicleId)) {
            log.warn("该车辆ID不存在");
            throw new AdminException("该车辆ID不存在");
        }
        // 通过车辆ID获取设备主有线设备
        List<BasicDeviceDTO> basicDeviceDTOList = vehicleDeviceMapper.selectBindDeviceByVehicleIdOrderByCreatedDate(vehicleId);
        Optional<BasicDeviceDTO> basicDeviceDTO = basicDeviceDTOList.stream().filter(dto -> TypeConverseEnum.SourceEnum.HAS_SOURCE.getSourceType().equals(dto.getSource())).findFirst();
        basicDeviceDTO.orElseGet(() -> {
            log.warn("该车辆绑定的主设备不存在");
            throw new AdminException("该车辆绑定的主设备不存在");
        });
        // 获取主设备
        String sn = basicDeviceDTO.get().getSn();
        UserBehaviorInformationVO userBehaviorInformationVO = new UserBehaviorInformationVO();
        List<UserBehaviorWeekDTO> userBehaviorWeekDTOList = deviceJourneyMapper.statisticsDeviceJourneyWithWeek(sn);
        // 获取最大的周数
        Integer maxWeekNum = userBehaviorWeekDTOList.stream().map(UserBehaviorWeekDTO::getWeekNum).max(Integer::compareTo).orElse(0);
        // 获取最小的周数
        Integer minWeekNum = userBehaviorWeekDTOList.stream().map(UserBehaviorWeekDTO::getWeekNum).min(Integer::compareTo).orElse(0);
        // 如果数据不满一周 则按照每日数量进行统计
        if (Objects.equals(maxWeekNum, minWeekNum)) {
            userBehaviorInformationVO.setStatisticsType(2);
            List<UserBehaviorDayDTO> userBehaviorDayDTOList = deviceJourneyMapper.statisticsDeviceJourneyWithDay(sn);
            userBehaviorInformationVO.setUserBehaviorDayDTOList(userBehaviorDayDTOList);
            return userBehaviorInformationVO;
        }

        // 如果最多的周数减去18周 和最小的周进行对比
        userBehaviorInformationVO.setStatisticsType(2);
        int num = maxWeekNum - 18;
        if (num < minWeekNum) {
            userBehaviorInformationVO.setUserBehaviorWeekDTOList(userBehaviorWeekDTOList);
        } else {
            userBehaviorInformationVO.setUserBehaviorWeekDTOList(userBehaviorWeekDTOList.stream().filter(vo -> vo.getWeekNum() >= num).collect(Collectors.toList()));
        }
        return userBehaviorInformationVO;
    }
}