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.Arrays; 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.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; /** * Description //todo * * @author swb * @ClassName HistorySecondCruiserServiceImpl * @date 2024.06.25 14:41 */ @Service @Slf4j public class HistorySecondCruiserServiceImpl extends ServiceImpl 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.getDateStringOfDay(-1, DateUtils.yyyy_MM_dd_HH_mm_ss_EN); //获取当前时间 endTime = DateUtils.getCurDate(DateUtils.yyyy_MM_dd_HH_mm_ss_EN); } List result = historySecondCruiserMapper.getResult(startTime, endTime); // ArrayList list1 = new ArrayList<>(); if (!ObjectUtils.isEmpty(result)){ for (HistorySecondCruiser historySecondCruiser : result) { String mac = historySecondCruiser.getMac(); Integer organizationId = historySecondCruiser.getOrganizationId(); List orgList = organizationMapper.orgIdSpecialDevList(organizationId, mac); if(CollectionUtils.isEmpty(orgList)){ return; } HashMap params = new HashMap<>(); params.put("mac",mac); params.put("startTime",startTime); params.put("endTime",endTime); List> dusts = historySecondCruiserMapper.getDusts(params); Map> collect = manageCoordinateDetailMapper.CompareTo(orgList.get(0)).stream().collect(Collectors.groupingBy(o -> o.getName())); if (ObjectUtils.isEmpty(dusts) || ObjectUtils.isEmpty(collect)){ return; } Set strings = collect.keySet(); for (String string : strings) { SecondCruiserSort secondCruiserSort = new SecondCruiserSort(); ArrayList doubleArrayList = new ArrayList<>(); List 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 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); list1.add(secondCruiserSort); } } } if (!ObjectUtils.isEmpty(list1)){ // log.info(list1.size()+""); secondCruiserSortMapper.insertAll(list1); } } }