| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | import com.moral.api.entity.DustldDTO; |
| | | import com.moral.api.entity.HistorySecondCruiser; |
| | | import com.moral.api.entity.SecondCruiserSort; |
| | | import com.moral.api.entity.SysDictData; |
| | | import com.moral.api.mapper.HistorySecondCruiserMapper; |
| | | import com.moral.api.mapper.ManageCoordinateDetailMapper; |
| | | import com.moral.api.mapper.OrganizationMapper; |
| | | import com.moral.api.mapper.SecondCruiserSortMapper; |
| | | import com.moral.api.service.HistorySecondCruiserService; |
| | | import com.moral.api.service.SysDictTypeService; |
| | | import com.moral.util.DateUtils; |
| | | |
| | | /** |
| | |
| | | @Service |
| | | @Slf4j |
| | | public class HistorySecondCruiserServiceImpl extends ServiceImpl<HistorySecondCruiserMapper, HistorySecondCruiser> implements HistorySecondCruiserService { |
| | | @Autowired |
| | | private SysDictTypeService sysDictTypeService; |
| | | |
| | | @Autowired |
| | | private HistorySecondCruiserMapper historySecondCruiserMapper; |
| | |
| | | //获取当前时间 |
| | | endTime = DateUtils.getCurDate(DateUtils.yyyy_MM_dd_HH_mm_ss_EN); |
| | | } |
| | | SysDictData list = sysDictTypeService.listOne("ZHC", "dustld"); |
| | | List<HistorySecondCruiser> result = historySecondCruiserMapper.getResult(startTime, endTime); |
| | | |
| | | // |
| | | ArrayList<SecondCruiserSort> list1 = new ArrayList<>(); |
| | | if (!ObjectUtils.isEmpty(result)){ |
| | | |
| | | for (HistorySecondCruiser historySecondCruiser : result) { |
| | | String mac = historySecondCruiser.getMac(); |
| | | Integer organizationId = historySecondCruiser.getOrganizationId(); |
| | | List<Integer> orgList = organizationMapper.orgIdSpecialDevList(organizationId, mac); |
| | | if(CollectionUtils.isEmpty(orgList)){ |
| | | return; |
| | | continue; |
| | | } |
| | | |
| | | 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); |
| | | if (ObjectUtils.isEmpty(dusts)){ |
| | | continue; |
| | | } |
| | | Map<String, List<DustldDTO>> collect = manageCoordinateDetailMapper.CompareTo(orgList.get(0)).stream().collect(Collectors.groupingBy(o -> o.getName())); |
| | | if (ObjectUtils.isEmpty(dusts) || ObjectUtils.isEmpty(collect)){ |
| | | return; |
| | | if (ObjectUtils.isEmpty(collect)){ |
| | | continue; |
| | | } |
| | | Set<String> strings = collect.keySet(); |
| | | int i = 1; |
| | | for (String string : strings) { |
| | | log.info("当前记录>>>>>>>>> "+i+"/"+strings.size()+" >>>>>>>> "+string+" >>>>>>"); |
| | | i++; |
| | | SecondCruiserSort secondCruiserSort = new SecondCruiserSort(); |
| | | ArrayList<Double> doubleArrayList = new ArrayList<>(); |
| | | List<DustldDTO> dustldDTOS = collect.get(string); |
| | |
| | | } |
| | | double latDouble1 = Double.parseDouble(flyLat); |
| | | double lonDouble1 = Double.parseDouble(flyLon); |
| | | for (Map<String, Object> dust : dusts) { |
| | | //for (Map<String, Object> dust : dusts) { |
| | | for( int ii=0;ii<dusts.size();ii++){ |
| | | Map<String, Object> dust = dusts.get(ii); |
| | | 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); |
| | |
| | | // 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; |
| | | // break; |
| | | dusts.remove(ii); |
| | | ii--; |
| | | } |
| | | } |
| | | } |
| | |
| | | continue; |
| | | } |
| | | Double ListAva = doubleArrayList.stream() .collect(Collectors.averagingDouble(Double::doubleValue)); |
| | | double rsAvg = new BigDecimal(ListAva/1000).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue(); |
| | | double rsAvg = new BigDecimal(ListAva).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); |
| | | secondCruiserSort.setRoad(string); |
| | | secondCruiserSort.setValue(rsAvg); |
| | | secondCruiserSort.setMac(mac); |
| | | secondCruiserSort.setOrganizationId(organizationId); |
| | | secondCruiserSort.setTime(startTime); |
| | | list1.add(secondCruiserSort); |
| | | } |
| | | } |
| | | } |
| | | secondCruiserSortMapper.insertAll(list1); |
| | | if (!ObjectUtils.isEmpty(list1)){ |
| | | secondCruiserSortMapper.insertAll(list1); |
| | | log.info("新增路段排名>>>>>>>> "+list1.size()+" >>>>>>>>>条"); |
| | | } |
| | | |
| | | } |
| | | |
| | | private BigDecimal numAvg(List<String> list , BigDecimal num){ |
| | | int nums = 1; |
| | | for (int i=0;i<list.size();i=i+2){ |
| | | if(num.compareTo(BigDecimal.valueOf(Double.parseDouble(list.get(i))))>= 0 ){ |
| | | return num.add(BigDecimal.valueOf(Double.parseDouble(list.get(i+1)))); |
| | | } |
| | | nums+=2; |
| | | } |
| | | return num; |
| | | } |
| | | } |