|
@@ -0,0 +1,120 @@
|
|
|
|
|
+package com.onemap.apply.service.impl.yzt;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.LinkedHashMap;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+import com.onemap.apply.mapper.yzt.UrbanMonitorMapper;
|
|
|
|
|
+import com.onemap.apply.domain.yzt.UrbanMonitorVO;
|
|
|
|
|
+import com.onemap.apply.domain.yzt.UrbanExpansionLayerVO;
|
|
|
|
|
+import com.onemap.apply.domain.yzt.UrbanExpansionConfigVO;
|
|
|
|
|
+import com.onemap.apply.service.yzt.IUrbanMonitorService;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 城市监测Service业务层处理
|
|
|
|
|
+ */
|
|
|
|
|
+@Service
|
|
|
|
|
+public class UrbanMonitorServiceImpl implements IUrbanMonitorService {
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private UrbanMonitorMapper urbanMonitorMapper;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询城市监测列表
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param type buildUp_area/building_area/building_count
|
|
|
|
|
+ * @param code 区域代码
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<UrbanMonitorVO> selectUrbanMonitorList(String type, String code) {
|
|
|
|
|
+ // 如果行政码是6位,且后两位为00,则查询全市(设为null不进行过滤)
|
|
|
|
|
+ if (code != null && code.length() == 6 && code.endsWith("00")) {
|
|
|
|
|
+ code = null;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<UrbanMonitorVO> list = urbanMonitorMapper.selectUrbanMonitorList(type, code);
|
|
|
|
|
+ return calculateChangeRate(list);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取城市扩张图层配置
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param dimType 维度类型: 2d/3d
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public UrbanExpansionConfigVO getUrbanExpansionConfig(String dimType) {
|
|
|
|
|
+ // 默认为 2d
|
|
|
|
|
+ if (dimType == null || dimType.isEmpty()) {
|
|
|
|
|
+ dimType = "2d";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<UrbanExpansionLayerVO> list = urbanMonitorMapper.selectUrbanExpansionList(dimType);
|
|
|
|
|
+
|
|
|
|
|
+ UrbanExpansionConfigVO config = new UrbanExpansionConfigVO();
|
|
|
|
|
+ List<Integer> years = new ArrayList<>();
|
|
|
|
|
+ Map<String, UrbanExpansionConfigVO.LayerInfo> boundaryLayers = new LinkedHashMap<>();
|
|
|
|
|
+ Map<String, UrbanExpansionConfigVO.LayerInfo> expandLayers = new LinkedHashMap<>();
|
|
|
|
|
+
|
|
|
|
|
+ if (list != null && !list.isEmpty()) {
|
|
|
|
|
+ config.setServiceId(list.get(0).getServiceId());
|
|
|
|
|
+ // 提取年份并去重排序
|
|
|
|
|
+ years = list.stream()
|
|
|
|
|
+ .map(UrbanExpansionLayerVO::getYear)
|
|
|
|
|
+ .distinct()
|
|
|
|
|
+ .sorted()
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ for (UrbanExpansionLayerVO item : list) {
|
|
|
|
|
+ UrbanExpansionConfigVO.LayerInfo info = new UrbanExpansionConfigVO.LayerInfo(item.getLayerName(),
|
|
|
|
|
+ item.getData());
|
|
|
|
|
+
|
|
|
|
|
+ if ("boundary".equals(item.getLayerType())) {
|
|
|
|
|
+ // key is year string
|
|
|
|
|
+ boundaryLayers.put(String.valueOf(item.getYear()), info);
|
|
|
|
|
+ } else if ("expand".equals(item.getLayerType())) {
|
|
|
|
|
+ // key is prevYear_year
|
|
|
|
|
+ if (item.getPrevYear() != null) {
|
|
|
|
|
+ String key = item.getPrevYear() + "_" + item.getYear();
|
|
|
|
|
+ expandLayers.put(key, info);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ config.setYears(years);
|
|
|
|
|
+ config.setBoundaryLayers(boundaryLayers);
|
|
|
|
|
+ config.setExpandLayers(expandLayers);
|
|
|
|
|
+
|
|
|
|
|
+ return config;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 计算变化率
|
|
|
|
|
+ */
|
|
|
|
|
+ private List<UrbanMonitorVO> calculateChangeRate(List<UrbanMonitorVO> list) {
|
|
|
|
|
+ if (list == null || list.isEmpty()) {
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
+ UrbanMonitorVO current = list.get(i);
|
|
|
|
|
+ if (i == 0) {
|
|
|
|
|
+ current.setChangeRate(0);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ UrbanMonitorVO prev = list.get(i - 1);
|
|
|
|
|
+ double prevData = prev.getData();
|
|
|
|
|
+
|
|
|
|
|
+ if (prevData == 0) {
|
|
|
|
|
+ current.setChangeRate(0);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ double rate = (current.getData() - prevData) / prevData * 100;
|
|
|
|
|
+ rate = Math.round(rate * 100.0) / 100.0;
|
|
|
|
|
+ current.setChangeRate(rate);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|