Commit ba73f159 by 罗志长

fix: 区域固化数据兼容

parent 1f1fbb58
......@@ -10,6 +10,7 @@ import com.makeit.entity.platform.space.PlatRegionSettingFix;
import com.makeit.mapper.platform.space.PlatRegionSettingFixMapper;
import com.makeit.service.platform.device.PlatDeviceService;
import com.makeit.service.platform.space.PlatRegionSettingFixService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -18,9 +19,7 @@ import org.springframework.stereotype.Service;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
......@@ -50,9 +49,18 @@ public class PlatRegionSettingFixServiceImpl extends ServiceImpl<PlatRegionSetti
} else {
queryWrapper.eq(PlatRegionSettingFix::getHappenDate, dateTimeFormatter.format(dto.getEndTime()));
}
queryWrapper.orderByDesc(PlatRegionSettingFix::getCreateDate);
List<PlatRegionSettingFix> list = this.list(queryWrapper);
list = list.stream().filter(distinctByKey(PlatRegionSettingFix::getDeviceId)).collect(Collectors.toList());
// 兼容部分没有关联长者的数据
if (CollectionUtils.isEmpty(list)) {
LambdaQueryWrapper<PlatRegionSettingFix> queryWrapper1 = new LambdaQueryWrapper<>();
queryWrapper1.eq(PlatRegionSettingFix::getRoomId, dto.getRoomId());
if ("0".equals(dto.getReportType())) {
queryWrapper1.eq(PlatRegionSettingFix::getHappenDate, dateTimeFormatter.format(dto.getNow()));
} else {
queryWrapper1.eq(PlatRegionSettingFix::getHappenDate, dateTimeFormatter.format(dto.getEndTime()));
}
list = this.list(queryWrapper1);
}
List<String> deviceIds = list.stream().map(PlatRegionSettingFix::getDeviceId).collect(Collectors.toList());
Map<String, PlatDevice> deviceMap = platDeviceService.listByIds(deviceIds).stream().collect(Collectors.toMap(PlatDevice::getId, Function.identity()));
return list.stream().map(p -> {
......@@ -66,9 +74,4 @@ public class PlatRegionSettingFixServiceImpl extends ServiceImpl<PlatRegionSetti
}).collect(Collectors.toList());
}
private static <T> Predicate<T> distinctByKey(Function<? super T, Object> keyExtractor) {
Map<Object, Boolean> seen = new ConcurrentHashMap<>();
return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment