|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.api.entity.Dustld; | 
|---|
|  |  |  | import com.moral.api.entity.ManageCoordinate; | 
|---|
|  |  |  | import com.moral.api.entity.MaxRoad; | 
|---|
|  |  |  | import com.moral.api.mapper.DustldMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.HistorySecondCruiserMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.ManageCoordinateMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.MaxRoadMapper; | 
|---|
|  |  |  | import com.moral.api.pojo.dto.historySecondCruiser.DustldDTO; | 
|---|
|  |  |  | import com.moral.api.pojo.dust.DustForm; | 
|---|
|  |  |  | import com.moral.api.pojo.dust.TimeForm; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ManageCoordinateMapper manageCoordinateMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private MaxRoadMapper maxRoadMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Map<String, Object> dailyDustlds(List<MultipartFile> file,Map<String, Object> params) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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"); | 
|---|
|  |  |  | String time1 = params.get("time1").toString(); | 
|---|
|  |  |  | String substring1 = time1.substring(5, 14); | 
|---|
|  |  |  | String dateString1 = DateUtils.stringToDateString(time1, DateUtils.yyyy_MM_dd_HH_mm_ss_EN, DateUtils.yyyy_MM_dd_HH_mm_CN); | 
|---|
|  |  |  | String rsTime1 = dateString1.substring(5, 14); | 
|---|
|  |  |  | String time2 = params.get("time2").toString(); | 
|---|
|  |  |  | String substring2 = time2.substring(5, 14); | 
|---|
|  |  |  | String dateString2 = DateUtils.stringToDateString(time2, DateUtils.yyyy_MM_dd_HH_mm_ss_EN, DateUtils.yyyy_MM_dd_HH_mm_CN); | 
|---|
|  |  |  | String rsTime2 = dateString2.substring(5, 14); | 
|---|
|  |  |  | HashMap<String, Object> rsMap = new HashMap<>(); | 
|---|
|  |  |  | List<Map<String, Object>> dusts = historySecondCruiserMapper.getDusts(params); | 
|---|
|  |  |  | Map<String, List<DustldDTO>> collect = manageCoordinateMapper.CompareTo(orgId).stream().collect(Collectors.groupingBy(o -> o.getName())); | 
|---|
|  |  |  | 
|---|
|  |  |  | StringBuilder builder = new StringBuilder(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int i = 1; | 
|---|
|  |  |  | long timestamp = System.currentTimeMillis(); | 
|---|
|  |  |  | for (String string : strings) { | 
|---|
|  |  |  | DustForm dustForm = new DustForm(); | 
|---|
|  |  |  | ArrayList<Double> doubleArrayList = new ArrayList<>(); | 
|---|
|  |  |  | 
|---|
|  |  |  | for (DustldDTO dustldDTO : dustldDTOS) { | 
|---|
|  |  |  | String flyLat = dustldDTO.getFlyLat(); | 
|---|
|  |  |  | String flyLon = dustldDTO.getFlyLon(); | 
|---|
|  |  |  | //                if (flyLon==null && flyLat==null){ | 
|---|
|  |  |  | //                    continue; | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | 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"; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | if (rsAvg>=0.3){ | 
|---|
|  |  |  | builder.append("("+i+")"+string); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | list1.add(dustForm); | 
|---|
|  |  |  | //添加高值路段 | 
|---|
|  |  |  | QueryWrapper<MaxRoad> wrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | wrapper.eq("name",string); | 
|---|
|  |  |  | wrapper.eq("time",DateUtils.getDate(time1,DateUtils.yyyy_MM_dd_EN)); | 
|---|
|  |  |  | Integer integer = maxRoadMapper.selectCount(wrapper); | 
|---|
|  |  |  | if (integer==0){ | 
|---|
|  |  |  | MaxRoad maxRoad = new MaxRoad(); | 
|---|
|  |  |  | maxRoad.setData(rsAvg); | 
|---|
|  |  |  | maxRoad.setName(string); | 
|---|
|  |  |  | maxRoad.setTime(DateUtils.getDate(time1,DateUtils.yyyy_MM_dd_EN)); | 
|---|
|  |  |  | maxRoadMapper.insert(maxRoad); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | list2.add(dustForm); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | long timestamp2 = System.currentTimeMillis(); | 
|---|
|  |  |  | log.info(timestamp2-timestamp+""); | 
|---|
|  |  |  | //排序 | 
|---|
|  |  |  | list1.sort(Comparator.comparing(DustForm::getValue).reversed()); | 
|---|
|  |  |  | list2.sort(Comparator.comparing(DustForm::getValue).reversed()); | 
|---|
|  |  |  | rsMap.put("list1",list1); | 
|---|
|  |  |  | rsMap.put("list2",list2); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取上一次的高值路段 | 
|---|
|  |  |  | ArrayList<Map<String, Object>> list3 = new ArrayList<>(); | 
|---|
|  |  |  | QueryWrapper<MaxRoad> wrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | wrapper.lt("time",DateUtils.getDate(time1,DateUtils.yyyy_MM_dd_EN)); | 
|---|
|  |  |  | wrapper.orderByDesc("time"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MaxRoad maxRoad = maxRoadMapper.selectOne(wrapper); | 
|---|
|  |  |  | String dateString3 = DateUtils.dateToDateString(maxRoad.getTime(), DateUtils.yyyy_MM_dd_CN); | 
|---|
|  |  |  | QueryWrapper<MaxRoad> wrapper2 = new QueryWrapper<>(); | 
|---|
|  |  |  | wrapper2.eq("time",maxRoad.getTime()); | 
|---|
|  |  |  | List<MaxRoad> maxRoads = maxRoadMapper.selectList(wrapper2); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //合并数据 | 
|---|
|  |  |  | ArrayList<DustForm> dustForms = new ArrayList<>(); | 
|---|
|  |  |  | dustForms.addAll(list1); | 
|---|
|  |  |  | dustForms.addAll(list2); | 
|---|
|  |  |  | for (MaxRoad road : maxRoads) { | 
|---|
|  |  |  | for (DustForm dustForm : dustForms) { | 
|---|
|  |  |  | if (road.getName().equals(dustForm.getRoad())){ | 
|---|
|  |  |  | HashMap<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  | map.put("road",road.getName()); | 
|---|
|  |  |  | map.put("value1",road.getData()); | 
|---|
|  |  |  | map.put("value2",dustForm.getValue()); | 
|---|
|  |  |  | map.put("value3",road.getData()-dustForm.getValue()); | 
|---|
|  |  |  | list3.add(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | rsMap.put("data",builder); | 
|---|
|  |  |  | rsMap.put("list3",""); | 
|---|
|  |  |  | rsMap.put("time",substring1+"-"+substring2); | 
|---|
|  |  |  | rsMap.put("list3",list3); | 
|---|
|  |  |  | rsMap.put("time",rsTime1+"-"+rsTime2); | 
|---|
|  |  |  | rsMap.put("date1",dateString3.substring(5,10)); | 
|---|
|  |  |  | rsMap.put("date2",dateString1.substring(5,10)); | 
|---|
|  |  |  | return rsMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|