New file |
| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.api.entity.DustldDTO; |
| | | import com.moral.api.entity.HistorySecondCruiser; |
| | | import com.moral.api.entity.SecondCruiserSort; |
| | | 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.util.DateUtils; |
| | | |
| | | /** |
| | | * Description //todo |
| | | * |
| | | * @author swb |
| | | * @ClassName HistorySecondCruiserServiceImpl |
| | | * @date 2024.06.25 14:41 |
| | | */ |
| | | @Service |
| | | @Slf4j |
| | | public class HistorySecondCruiserServiceImpl extends ServiceImpl<HistorySecondCruiserMapper, HistorySecondCruiser> implements HistorySecondCruiserService { |
| | | |
| | | @Autowired |
| | | private HistorySecondCruiserMapper historySecondCruiserMapper; |
| | | @Autowired |
| | | private OrganizationMapper organizationMapper; |
| | | @Autowired |
| | | private ManageCoordinateDetailMapper manageCoordinateDetailMapper; |
| | | @Autowired |
| | | private SecondCruiserSortMapper secondCruiserSortMapper; |
| | | |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void sort(String startTime, String endTime) { |
| | | |
| | | if (ObjectUtils.isEmpty(startTime)&&ObjectUtils.isEmpty(endTime)){ |
| | | //当前时间的前一个小时 |
| | | startTime = DateUtils.getDateStringOfHour(-2, "yyyy-MM-dd HH:00:00"); |
| | | |
| | | //获取当前时间 |
| | | endTime = DateUtils.getCurDate("yyyy-MM-dd HH:00:00"); |
| | | } |
| | | 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; |
| | | } |
| | | |
| | | 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 = manageCoordinateDetailMapper.CompareTo(orgList.get(0)).stream().collect(Collectors.groupingBy(o -> o.getName())); |
| | | if (ObjectUtils.isEmpty(dusts) || ObjectUtils.isEmpty(collect)){ |
| | | return; |
| | | } |
| | | Set<String> strings = collect.keySet(); |
| | | for (String string : strings) { |
| | | SecondCruiserSort secondCruiserSort = new SecondCruiserSort(); |
| | | 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; |
| | | doubleArrayList.add(dustld); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | if (ObjectUtils.isEmpty(doubleArrayList)){ |
| | | continue; |
| | | } |
| | | Double ListAva = doubleArrayList.stream() .collect(Collectors.averagingDouble(Double::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(endTime); |
| | | list1.add(secondCruiserSort); |
| | | } |
| | | } |
| | | } |
| | | if (!ObjectUtils.isEmpty(list1)){ |
| | | // log.info(list1.size()+""); |
| | | secondCruiserSortMapper.insertAll(list1); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |