From 552238172036acf08ccf36134282a06b5e21b936 Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期五, 22 五月 2026 18:07:49 +0800
Subject: [PATCH] 代码生成

---
 server/services/src/main/java/com/doumee/service/business/impl/AreasServiceImpl.java |   87 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 87 insertions(+), 0 deletions(-)

diff --git a/server/services/src/main/java/com/doumee/service/business/impl/AreasServiceImpl.java b/server/services/src/main/java/com/doumee/service/business/impl/AreasServiceImpl.java
index 8408aca..8fe7aff 100644
--- a/server/services/src/main/java/com/doumee/service/business/impl/AreasServiceImpl.java
+++ b/server/services/src/main/java/com/doumee/service/business/impl/AreasServiceImpl.java
@@ -12,6 +12,7 @@
 import com.doumee.core.model.PageData;
 import com.doumee.core.model.PageWrap;
 import com.doumee.core.utils.PinYinUtil;
+import com.doumee.core.utils.geocode.MapUtil;
 import com.doumee.core.utils.Utils;
 import com.doumee.dao.business.AreasMapper;
 import com.doumee.dao.business.PricingRuleMapper;
@@ -19,7 +20,9 @@
 import com.doumee.dao.business.model.PricingRule;
 import com.doumee.service.business.AreasService;
 import com.github.yulichang.wrapper.MPJLambdaWrapper;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
+import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -35,6 +38,7 @@
  * @author 姹熻箘韫�
  * @date 2023/02/15 08:55
  */
+@Slf4j
 @Service
 public class AreasServiceImpl implements AreasService {
     public static   List<Areas> ALL_AREA_LIST;
@@ -71,6 +75,10 @@
         areas.setCreateDate(new Date());
         areasMapper.insert(areas);
         areas.setCode(areas.getId().toString());
+        // 鍩庡競绾у尯鍒掕嚜鍔ㄥ~鍏呯粡绾害
+        if (Constants.equalsInteger(areas.getType(), Constants.ONE)) {
+            areas.setInfo(geocodeCity(areas));
+        }
         areasMapper.updateById(areas);
         //鍒锋柊缂撳瓨鏁版嵁
         cacheData();
@@ -115,6 +123,14 @@
         Areas update = new Areas();
         update.setName(areas.getName());
         update.setSortnum(areas.getSortnum());
+        // 鍩庡競绾у尯鍒掕嚜鍔ㄦ洿鏂扮粡绾害
+        Areas existing = areasMapper.selectById(areas.getId());
+        if (existing != null && Constants.equalsInteger(existing.getType(), Constants.ONE)) {
+            String location = MapUtil.geocode(getParentName(existing.getParentId()) + areas.getName());
+            if (location != null) {
+                update.setInfo(location);
+            }
+        }
         areasMapper.update(update,wrapper);
         //鍒锋柊缂撳瓨鏁版嵁
         cacheData();
@@ -130,6 +146,11 @@
         }
         //鍒锋柊缂撳瓨鏁版嵁
         cacheData();
+    }
+
+    @Override
+    public Areas getById(Integer id) {
+       return areasMapper.selectById(id);
     }
 
     @Override
@@ -548,6 +569,7 @@
         return list;
     }
 
+
     @Override
     public Areas getOpenedCityByName(String cityName) {
         if (StringUtils.isBlank(cityName)) {
@@ -563,6 +585,24 @@
         return areasMapper.selectOne(qw);
     }
 
+
+    @Override
+    public Areas getOpenedCityByCode(String code) {
+        if (StringUtils.isBlank(code)) {
+            return null;
+        }
+        Areas areas = areasMapper.selectById(code);
+        if(Objects.isNull(areas)||Objects.isNull(areas.getParentId())){
+            return null;
+        }
+        Areas city = areasMapper.selectById(areas.getParentId());
+        if(Objects.isNull(city)||Constants.equalsInteger(city.getIsdeleted(),Constants.ONE)||
+            Constants.equalsInteger(city.getStatus(),Constants.ZERO)){
+            return null;
+        }
+        return city;
+    }
+
     @Override
     public void updateStatus(Areas areas) {
         if (areas == null || areas.getId() == null) {
@@ -574,4 +614,51 @@
         areasMapper.updateById(update);
     }
 
+    @Override
+    public String fillCityLocation() {
+        Areas query = new Areas();
+        query.setType(1);
+        List<Areas> cities = areasMapper.selectList(new QueryWrapper<Areas>().lambda()
+                .eq(Areas::getType, 1));
+        int success = 0, fail = 0;
+        for (Areas city : cities) {
+            if (StringUtils.isNotBlank(city.getInfo())) {
+                continue;
+            }
+            String parentName = "";
+            if (city.getParentId() != null) {
+                Areas parent = getById(city.getParentId());
+                if (parent != null) {
+                    parentName = parent.getName();
+                }
+            }
+            String address = parentName + city.getName();
+            String location = MapUtil.geocode(address);
+            if (location != null) {
+                city.setInfo(location);
+                areasMapper.updateById(city);
+                success++;
+                log.info("鍩庡競缁忕含搴﹀~鍏呮垚鍔�: {} => {}", address, location);
+            } else {
+                fail++;
+                log.warn("鍩庡競缁忕含搴﹀~鍏呭け璐�: {}", address);
+            }
+            try { Thread.sleep(200); } catch (InterruptedException ignored) {}
+        }
+        return "澶勭悊瀹屾垚锛屾垚鍔�: " + success + "锛屽け璐�: " + fail + "锛屾�昏: " + cities.size();
+    }
+
+    private String getParentName(Integer parentId) {
+        if (parentId == null) {
+            return "";
+        }
+        Areas parent = getById(parentId);
+        return parent != null ? parent.getName() : "";
+    }
+
+    private String geocodeCity(Areas city) {
+        String address = getParentName(city.getParentId()) + city.getName();
+        return MapUtil.geocode(address);
+    }
+
 }

--
Gitblit v1.9.3