|  |  |  | 
|---|
|  |  |  | package com.moral.api.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.moral.api.config.Interceptor.UserHelper; | 
|---|
|  |  |  | import com.moral.api.entity.SecondCruiserSort; | 
|---|
|  |  |  | import com.moral.api.entity.SysDictData; | 
|---|
|  |  |  | import com.moral.api.exception.BusinessException; | 
|---|
|  |  |  | import com.moral.api.mapper.*; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private DustldMapper dustldMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SecondCruiserSortMapper secondCruiserSortMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 保存日报信息 | 
|---|
|  |  |  | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<DustForm> sort(String mac, String startTime, String endTime) { | 
|---|
|  |  |  | public List<SecondCruiserSort> sort(String mac, String startTime, String endTime) { | 
|---|
|  |  |  | SysDictData list = sysDictTypeService.listOne(SysDictTypeEnum.SYS_SECOND_CRUISER.getValue(),"dustld"); | 
|---|
|  |  |  | Map<String, Object> userInfo = (Map<String, Object>) TokenUtils.getUserInfo(); | 
|---|
|  |  |  | Map<String, Object> orgInfo = (Map<String, Object>) userInfo.get("organization"); | 
|---|
|  |  |  | Integer orgId = (Integer) orgInfo.get("id"); | 
|---|
|  |  |  | List<SecondCruiserSort> secondCruiserSorts = secondCruiserSortMapper.getSort(mac, startTime, endTime); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Integer> orgList = organizationMapper.orgIdSpecialDevList(orgId,mac); | 
|---|
|  |  |  | if(CollectionUtils.isEmpty(orgList)){ | 
|---|
|  |  |  | throw new BusinessException("该设备没有路段组织信息!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | HashMap<String, Object> params = new HashMap<>(); | 
|---|
|  |  |  | params.put("mac",mac); | 
|---|
|  |  |  | params.put("startTime",startTime); | 
|---|
|  |  |  | params.put("endTime",endTime); | 
|---|
|  |  |  | List<Map<String, Object>> dusts = historySecondCruiserMapper.getDusts(params); | 
|---|
|  |  |  | Map<String, List<DustldDTO>> collect = manageCoordinateMapper.CompareTo(orgList.get(0)).stream().collect(Collectors.groupingBy(o -> o.getName())); | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(dusts) || ObjectUtils.isEmpty(collect)){ | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Set<String> strings = collect.keySet(); | 
|---|
|  |  |  | ArrayList<DustForm> list1 = new ArrayList<>(); | 
|---|
|  |  |  | for (String string : strings) { | 
|---|
|  |  |  | DustForm dustForm = new DustForm(); | 
|---|
|  |  |  | ArrayList<Double> doubleArrayList = new ArrayList<>(); | 
|---|
|  |  |  | List<DustldDTO> dustldDTOS = collect.get(string); | 
|---|
|  |  |  | for (DustldDTO dustldDTO : dustldDTOS) { | 
|---|
|  |  |  | String flyLat = dustldDTO.getFlyLat(); | 
|---|
|  |  |  | String flyLon = dustldDTO.getFlyLon(); | 
|---|
|  |  |  | if (flyLon==null && flyLat==null){ | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | double latDouble1 = Double.parseDouble(flyLat); | 
|---|
|  |  |  | double lonDouble1 = Double.parseDouble(flyLon); | 
|---|
|  |  |  | for (Map<String, Object> dust : dusts) { | 
|---|
|  |  |  | String flyLat1 = Objects.nonNull(dust.get("flyLat")) ? dust.get("flyLat").toString() :"0"; | 
|---|
|  |  |  | String flyLon1 = Objects.nonNull(dust.get("flyLon")) ? dust.get("flyLon").toString() :"0"; | 
|---|
|  |  |  | double latDouble = Double.parseDouble(flyLat1); | 
|---|
|  |  |  | double lonDouble = Double.parseDouble(flyLon1); | 
|---|
|  |  |  | //                    String flyLon1 = dust.get("flyLon").toString(); | 
|---|
|  |  |  | if (latDouble1==latDouble && lonDouble1==lonDouble){ | 
|---|
|  |  |  | Double dustld = Objects.nonNull(dust.get("dustld"))?Double.parseDouble(dust.get("dustld").toString()):0d; | 
|---|
|  |  |  | if(list.getDataValue().contains(",")){ | 
|---|
|  |  |  | List<String> resultStr = Arrays.asList(list.getDataValue().split(",")); | 
|---|
|  |  |  | if(resultStr.size() % 2 ==0){ | 
|---|
|  |  |  | dustld = numAvg(resultStr,BigDecimal.valueOf(dustld)).doubleValue(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | BigDecimal dataValue = Objects.nonNull(list.getDataValue())?BigDecimal.valueOf(Double.parseDouble(list.getDataValue())):BigDecimal.ZERO; | 
|---|
|  |  |  | dustld = BigDecimal.valueOf(dustld).add(dataValue).doubleValue(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | doubleArrayList.add(dustld); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | //校准尘负荷 | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(secondCruiserSorts)){ | 
|---|
|  |  |  | for (SecondCruiserSort secondCruiserSort : secondCruiserSorts) { | 
|---|
|  |  |  | if(list.getDataValue().contains(",")){ | 
|---|
|  |  |  | List<String> resultStr = Arrays.asList(list.getDataValue().split(",")); | 
|---|
|  |  |  | if(resultStr.size() % 2 ==0){ | 
|---|
|  |  |  | //                        secondCruiserSort.setAvg(numAvg(resultStr,BigDecimal.valueOf(secondCruiserSort.getAvg())).doubleValue()); | 
|---|
|  |  |  | secondCruiserSort.setAvg((double) Math.round(numAvg(resultStr, BigDecimal.valueOf(secondCruiserSort.getAvg())).doubleValue())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | BigDecimal dataValue = Objects.nonNull(list.getDataValue())?BigDecimal.valueOf(Double.parseDouble(list.getDataValue())):BigDecimal.ZERO; | 
|---|
|  |  |  | //                    secondCruiserSort.setAvg(BigDecimal.valueOf(secondCruiserSort.getAvg()).add(dataValue).doubleValue()); | 
|---|
|  |  |  | secondCruiserSort.setAvg((double) Math.round(BigDecimal.valueOf(secondCruiserSort.getAvg()).add(dataValue).doubleValue())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(doubleArrayList)){ | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Double ListAva = doubleArrayList.stream() .collect(Collectors.averagingDouble(Double::doubleValue)); | 
|---|
|  |  |  | double rsAvg = new BigDecimal(ListAva/1000).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue(); | 
|---|
|  |  |  | dustForm.setRoad(string); | 
|---|
|  |  |  | dustForm.setValue(rsAvg); | 
|---|
|  |  |  | list1.add(dustForm); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //排序 | 
|---|
|  |  |  | list1.sort(Comparator.comparing(DustForm::getValue).reversed()); | 
|---|
|  |  |  | return list1; | 
|---|
|  |  |  | return secondCruiserSorts; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|