|
@@ -179,11 +179,25 @@ public class EquipmentBaseServiceImpl extends ServiceImpl<EquipmentBaseMapper, E
|
|
|
String keyword, Integer rootTypeId,
|
|
String keyword, Integer rootTypeId,
|
|
|
Integer onlineStatus,
|
|
Integer onlineStatus,
|
|
|
Integer alarmStatus) {
|
|
Integer alarmStatus) {
|
|
|
|
|
+ return findMobileByPage(pageNum, pageSize, keyword, rootTypeId, onlineStatus, alarmStatus,
|
|
|
|
|
+ null, null, null, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Page<EquipmentBaseVO> findMobileByPage(long pageNum, long pageSize,
|
|
|
|
|
+ String keyword, Integer rootTypeId,
|
|
|
|
|
+ Integer onlineStatus, Integer alarmStatus,
|
|
|
|
|
+ Integer equipmentTypeId, Double latitude,
|
|
|
|
|
+ Double longitude, String distanceOrder) {
|
|
|
Set<Integer> companyRootTypeIds = assignScopeSupport.currentCompanyEquipmentRootTypeIds();
|
|
Set<Integer> companyRootTypeIds = assignScopeSupport.currentCompanyEquipmentRootTypeIds();
|
|
|
if (rootTypeId != null && !companyRootTypeIds.contains(rootTypeId)) {
|
|
if (rootTypeId != null && !companyRootTypeIds.contains(rootTypeId)) {
|
|
|
return new Page<>(pageNum, pageSize, 0);
|
|
return new Page<>(pageNum, pageSize, 0);
|
|
|
}
|
|
}
|
|
|
Set<Integer> allowedTypeIds = resolveMobileTypeIds(companyRootTypeIds, rootTypeId);
|
|
Set<Integer> allowedTypeIds = resolveMobileTypeIds(companyRootTypeIds, rootTypeId);
|
|
|
|
|
+ if (equipmentTypeId != null) {
|
|
|
|
|
+ if (!allowedTypeIds.contains(equipmentTypeId)) return new Page<>(pageNum, pageSize, 0);
|
|
|
|
|
+ allowedTypeIds = Collections.singleton(equipmentTypeId);
|
|
|
|
|
+ }
|
|
|
if (allowedTypeIds.isEmpty()) return new Page<>(pageNum, pageSize, 0);
|
|
if (allowedTypeIds.isEmpty()) return new Page<>(pageNum, pageSize, 0);
|
|
|
|
|
|
|
|
LambdaQueryWrapper<EquipmentBase> queryWrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<EquipmentBase> queryWrapper = new LambdaQueryWrapper<>();
|
|
@@ -212,7 +226,61 @@ public class EquipmentBaseServiceImpl extends ServiceImpl<EquipmentBaseMapper, E
|
|
|
queryWrapper.in(EquipmentBase::getEquipmentId, matchedIds);
|
|
queryWrapper.in(EquipmentBase::getEquipmentId, matchedIds);
|
|
|
}
|
|
}
|
|
|
queryWrapper.orderByDesc(EquipmentBase::getCreateTime);
|
|
queryWrapper.orderByDesc(EquipmentBase::getCreateTime);
|
|
|
- return toEquipmentBaseVOPage(this.page(new Page<>(pageNum, pageSize), queryWrapper), pageNum, pageSize);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ boolean sortByDistance = latitude != null && longitude != null
|
|
|
|
|
+ && StringUtils.isNotBlank(distanceOrder);
|
|
|
|
|
+ if (!sortByDistance) {
|
|
|
|
|
+ return toEquipmentBaseVOPage(this.page(new Page<>(pageNum, pageSize), queryWrapper), pageNum, pageSize);
|
|
|
|
|
+ }
|
|
|
|
|
+ Page<EquipmentBase> all = this.page(new Page<>(1, 100000), queryWrapper);
|
|
|
|
|
+ Page<EquipmentBaseVO> allVo = toEquipmentBaseVOPage(all, 1, 100000);
|
|
|
|
|
+ List<EquipmentBaseVO> records = new ArrayList<>(allVo.getRecords());
|
|
|
|
|
+ final double fromLat = latitude;
|
|
|
|
|
+ final double fromLng = longitude;
|
|
|
|
|
+ records.sort(Comparator.comparingDouble(vo -> {
|
|
|
|
|
+ Double distance = distanceMeters(vo.getLongitude(), vo.getLatitude(), fromLng, fromLat);
|
|
|
|
|
+ return distance == null ? Double.MAX_VALUE : distance;
|
|
|
|
|
+ }));
|
|
|
|
|
+ if ("desc".equalsIgnoreCase(distanceOrder)) {
|
|
|
|
|
+ Collections.reverse(records);
|
|
|
|
|
+ }
|
|
|
|
|
+ int fromIndex = (int) Math.min((pageNum - 1) * pageSize, records.size());
|
|
|
|
|
+ int toIndex = (int) Math.min(fromIndex + pageSize, records.size());
|
|
|
|
|
+ Page<EquipmentBaseVO> result = new Page<>(pageNum, pageSize, records.size());
|
|
|
|
|
+ result.setRecords(new ArrayList<>(records.subList(fromIndex, toIndex)));
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public EquipmentBase findByEquipmentCode(String equipmentCode) {
|
|
|
|
|
+ String code = StringUtils.trimToNull(equipmentCode);
|
|
|
|
|
+ if (code == null) return null;
|
|
|
|
|
+ return this.getOne(new LambdaQueryWrapper<EquipmentBase>()
|
|
|
|
|
+ .eq(EquipmentBase::getEquipmentCode, code).last("LIMIT 1"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<EquipmentType> listMobileEquipmentTypes() {
|
|
|
|
|
+ Set<Integer> allowedTypeIds = resolveMobileTypeIds(
|
|
|
|
|
+ assignScopeSupport.currentCompanyEquipmentRootTypeIds(), null);
|
|
|
|
|
+ if (allowedTypeIds.isEmpty()) return Collections.emptyList();
|
|
|
|
|
+ return equipmentTypeMapper.selectList(new LambdaQueryWrapper<EquipmentType>()
|
|
|
|
|
+ .in(EquipmentType::getId, allowedTypeIds)
|
|
|
|
|
+ .orderByAsc(EquipmentType::getOrderNum)
|
|
|
|
|
+ .orderByAsc(EquipmentType::getId));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Double distanceMeters(java.math.BigDecimal lng, java.math.BigDecimal lat,
|
|
|
|
|
+ double fromLng, double fromLat) {
|
|
|
|
|
+ if (lng == null || lat == null) return null;
|
|
|
|
|
+ double toLng = lng.doubleValue();
|
|
|
|
|
+ double toLat = lat.doubleValue();
|
|
|
|
|
+ if (Math.abs(toLng) < 0.000001 && Math.abs(toLat) < 0.000001) return null;
|
|
|
|
|
+ double rad = Math.PI / 180;
|
|
|
|
|
+ double dLat = (toLat - fromLat) * rad;
|
|
|
|
|
+ double dLng = (toLng - fromLng) * rad;
|
|
|
|
|
+ double a = Math.pow(Math.sin(dLat / 2), 2) + Math.cos(fromLat * rad) * Math.cos(toLat * rad) * Math.pow(Math.sin(dLng / 2), 2);
|
|
|
|
|
+ return 2 * 6371000 * Math.asin(Math.sqrt(a));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|