|
@@ -7,6 +7,7 @@ import com.platform.common.util.ListUtils;
|
|
|
import com.platform.common.util.MapUtils;
|
|
import com.platform.common.util.MapUtils;
|
|
|
import com.platform.common.util.StringUtils;
|
|
import com.platform.common.util.StringUtils;
|
|
|
import com.platform.dao.bean.MyVOPage;
|
|
import com.platform.dao.bean.MyVOPage;
|
|
|
|
|
+import com.platform.dao.dto.sb.SbInitPointRequest;
|
|
|
import com.platform.dao.dto.sb.SbPositionDTO;
|
|
import com.platform.dao.dto.sb.SbPositionDTO;
|
|
|
import com.platform.dao.dto.sqarepartmanage.SparePartUsedDTO;
|
|
import com.platform.dao.dto.sqarepartmanage.SparePartUsedDTO;
|
|
|
import com.platform.dao.entity.part.PartInfo;
|
|
import com.platform.dao.entity.part.PartInfo;
|
|
@@ -26,13 +27,18 @@ import com.platform.service.base.impl.BaseServiceImpl;
|
|
|
import com.platform.service.sb.SbPositionService;
|
|
import com.platform.service.sb.SbPositionService;
|
|
|
import com.platform.service.util.ExecuteSql;
|
|
import com.platform.service.util.ExecuteSql;
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import tk.mybatis.mapper.weekend.Weekend;
|
|
import tk.mybatis.mapper.weekend.Weekend;
|
|
|
import tk.mybatis.mapper.weekend.WeekendCriteria;
|
|
import tk.mybatis.mapper.weekend.WeekendCriteria;
|
|
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
|
|
+import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @Description 设备位置 service 实现类
|
|
* @Description 设备位置 service 实现类
|
|
@@ -41,6 +47,7 @@ import java.util.Map;
|
|
|
* @Version Copyright (c) 2019,北京乾元坤和科技有限公司 All rights reserved.
|
|
* @Version Copyright (c) 2019,北京乾元坤和科技有限公司 All rights reserved.
|
|
|
*/
|
|
*/
|
|
|
@AllArgsConstructor
|
|
@AllArgsConstructor
|
|
|
|
|
+@Slf4j
|
|
|
@Service("sbPositionService")
|
|
@Service("sbPositionService")
|
|
|
public class SbPositionServiceImpl extends BaseServiceImpl<SbPositionMapper, SbPosition, SbPositionDTO> implements SbPositionService {
|
|
public class SbPositionServiceImpl extends BaseServiceImpl<SbPositionMapper, SbPosition, SbPositionDTO> implements SbPositionService {
|
|
|
|
|
|
|
@@ -183,7 +190,7 @@ public class SbPositionServiceImpl extends BaseServiceImpl<SbPositionMapper, SbP
|
|
|
sbPartTreeMap.put(vo.getId(), vo);
|
|
sbPartTreeMap.put(vo.getId(), vo);
|
|
|
});
|
|
});
|
|
|
partInfoList.forEach(item -> {
|
|
partInfoList.forEach(item -> {
|
|
|
- MyCommonTree sbInfoTreeVO = sbInfoTreeMap.get(item.getSbId());
|
|
|
|
|
|
|
+ MyCommonTree sbInfoTreeVO = sbPartTreeMap.get(item.getSbId());
|
|
|
if (sbInfoTreeVO != null) {
|
|
if (sbInfoTreeVO != null) {
|
|
|
sbInfoTreeVO.add(sbPartTreeMap.get(item.getId()));
|
|
sbInfoTreeVO.add(sbPartTreeMap.get(item.getId()));
|
|
|
}
|
|
}
|
|
@@ -228,5 +235,94 @@ public class SbPositionServiceImpl extends BaseServiceImpl<SbPositionMapper, SbP
|
|
|
return mapper.getById(id);
|
|
return mapper.getById(id);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void initPoints(SbInitPointRequest request) {
|
|
|
|
|
+ List<SbInitPointRequest.Point> points = request.getPoints();
|
|
|
|
|
+ List<String> positionIds = request.getPositionIds();
|
|
|
|
|
+ String mapName = request.getMapName();
|
|
|
|
|
+ Integer isShow = request.getIsShow();
|
|
|
|
|
+ if (points == null || points.size() != 4) {
|
|
|
|
|
+ throw new BusinessException("请提供矩形的四个角点坐标");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (positionIds == null || positionIds.isEmpty()) {
|
|
|
|
|
+ throw new BusinessException("请选择至少一个设备位置");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (mapName == null || mapName.isEmpty()) {
|
|
|
|
|
+ throw new BusinessException("请选择底图");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isShow == null) {
|
|
|
|
|
+ throw new BusinessException("请设置是否显示");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 从四个角点中提取矩形边界
|
|
|
|
|
+ double lngMin = points.stream().mapToDouble(p -> p.getLongitude().doubleValue()).min().orElse(0);
|
|
|
|
|
+ double lngMax = points.stream().mapToDouble(p -> p.getLongitude().doubleValue()).max().orElse(0);
|
|
|
|
|
+ double latMin = points.stream().mapToDouble(p -> p.getLatitude().doubleValue()).min().orElse(0);
|
|
|
|
|
+ double latMax = points.stream().mapToDouble(p -> p.getLatitude().doubleValue()).max().orElse(0);
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 查询这些位置下的所有设备
|
|
|
|
|
+ Weekend<SbInfo> weekend = new Weekend<>(SbInfo.class);
|
|
|
|
|
+ WeekendCriteria<SbInfo, Object> criteria = weekend.weekendCriteria();
|
|
|
|
|
+ criteria.andIn(SbInfo::getPositionId, positionIds);
|
|
|
|
|
+ List<SbInfo> allDevices = sbInfoMapper.selectByExample(weekend);
|
|
|
|
|
+ if (allDevices.isEmpty()) {
|
|
|
|
|
+ throw new BusinessException("所选位置下没有设备");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 按 positionId 分组,保持插入顺序
|
|
|
|
|
+ Map<String, List<SbInfo>> positionDeviceMap = new LinkedHashMap<>();
|
|
|
|
|
+ for (String positionId : positionIds) {
|
|
|
|
|
+ List<SbInfo> devices = allDevices.stream()
|
|
|
|
|
+ .filter(d -> positionId.equals(d.getPositionId()))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ if (!devices.isEmpty()) {
|
|
|
|
|
+ positionDeviceMap.put(positionId, devices);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ int positionCount = positionDeviceMap.size();
|
|
|
|
|
+ double bandHeight = (latMax - latMin) / positionCount;
|
|
|
|
|
+ log.info("初始化打点:矩形边界 lng[{}, {}] lat[{}, {}],位置数{},设备总数{}",
|
|
|
|
|
+ lngMin, lngMax, latMin, latMax, positionCount, allDevices.size());
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 每个位置分配一个条带,条带内网格分布
|
|
|
|
|
+ int bandIndex = 0;
|
|
|
|
|
+ int totalUpdated = 0;
|
|
|
|
|
+ for (Map.Entry<String, List<SbInfo>> entry : positionDeviceMap.entrySet()) {
|
|
|
|
|
+ List<SbInfo> devices = entry.getValue();
|
|
|
|
|
+ int n = devices.size();
|
|
|
|
|
+
|
|
|
|
|
+ double bandTop = latMax - bandIndex * bandHeight;
|
|
|
|
|
+ double bandBottom = bandTop - bandHeight;
|
|
|
|
|
+
|
|
|
|
|
+ // 计算条带内网格
|
|
|
|
|
+ int cols = (int) Math.ceil(Math.sqrt(n));
|
|
|
|
|
+ int rows = (int) Math.ceil((double) n / cols);
|
|
|
|
|
+ double lngStep = cols > 1 ? (lngMax - lngMin) / (cols - 1) : 0;
|
|
|
|
|
+ double latStep = rows > 1 ? (bandTop - bandBottom) / (rows - 1) : 0;
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = 0; i < n; i++) {
|
|
|
|
|
+ int row = i / cols;
|
|
|
|
|
+ int col = i % cols;
|
|
|
|
|
+ double lng = lngMin + col * lngStep;
|
|
|
|
|
+ double lat = bandTop - row * latStep;
|
|
|
|
|
+
|
|
|
|
|
+ SbInfo update = new SbInfo();
|
|
|
|
|
+ update.setId(devices.get(i).getId());
|
|
|
|
|
+ update.setZjm(BigDecimal.valueOf(lng).setScale(6, RoundingMode.HALF_UP).toPlainString());
|
|
|
|
|
+ update.setJbdh(BigDecimal.valueOf(lat).setScale(6, RoundingMode.HALF_UP).toPlainString());
|
|
|
|
|
+ update.setMapName(mapName);
|
|
|
|
|
+ update.setIsShow(isShow);
|
|
|
|
|
+ sbInfoMapper.updateByPrimaryKeySelective(update);
|
|
|
|
|
+ totalUpdated++;
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("位置[{}] 设备数{},网格 {}x{},条带 lat[{}, {}]",
|
|
|
|
|
+ entry.getKey(), n, cols, rows,
|
|
|
|
|
+ BigDecimal.valueOf(bandBottom).setScale(6, RoundingMode.HALF_UP),
|
|
|
|
|
+ BigDecimal.valueOf(bandTop).setScale(6, RoundingMode.HALF_UP));
|
|
|
|
|
+ bandIndex++;
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("初始化打点完成,共更新{}台设备坐标", totalUpdated);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|