瀏覽代碼

地图单位撒点街镇获取

jichaobo 2 年之前
父節點
當前提交
f1284687ec

+ 15 - 3
service-fire/service-fire-biz/src/main/java/com/usky/fire/controller/web/BaseCompanyAttach1Controller.java

@@ -1,9 +1,12 @@
 package com.usky.fire.controller.web;
 
 
+import com.usky.common.core.bean.ApiResult;
+import com.usky.fire.service.BaseCompanyAttach1Service;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
-
-import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RestController;
 
 /**
  * <p>
@@ -13,9 +16,18 @@ import org.springframework.stereotype.Controller;
  * @author JCB
  * @since 2022-09-20
  */
-@Controller
+@RestController
 @RequestMapping("/baseCompanyAttach1")
 public class BaseCompanyAttach1Controller {
 
+    @Autowired
+    private BaseCompanyAttach1Service baseCompanyAttach1Service;
+
+    @GetMapping("streetTownList")
+    public ApiResult<Void> streetTownList() {
+        baseCompanyAttach1Service.streetTownList();
+        return ApiResult.success();
+    }
+
 }
 

+ 3 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/BaseCompanyAttach1Service.java

@@ -3,6 +3,8 @@ package com.usky.fire.service;
 import com.usky.fire.domain.BaseCompanyAttach1;
 import com.usky.common.mybatis.core.CrudService;
 
+import java.util.List;
+
 /**
  * <p>
  * 联网单位信息附表1 服务类
@@ -13,4 +15,5 @@ import com.usky.common.mybatis.core.CrudService;
  */
 public interface BaseCompanyAttach1Service extends CrudService<BaseCompanyAttach1> {
 
+    void streetTownList();
 }

+ 71 - 1
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/impl/BaseCompanyAttach1ServiceImpl.java

@@ -1,11 +1,22 @@
 package com.usky.fire.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.usky.common.mybatis.core.AbstractCrudService;
+import com.usky.fire.domain.BaseCompany;
 import com.usky.fire.domain.BaseCompanyAttach1;
 import com.usky.fire.mapper.BaseCompanyAttach1Mapper;
+import com.usky.fire.mapper.BaseCompanyMapper;
 import com.usky.fire.service.BaseCompanyAttach1Service;
-import com.usky.common.mybatis.core.AbstractCrudService;
+import com.usky.fire.service.util.OnlineMethod;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * <p>
  * 联网单位信息附表1 服务实现类
@@ -17,4 +28,63 @@ import org.springframework.stereotype.Service;
 @Service
 public class BaseCompanyAttach1ServiceImpl extends AbstractCrudService<BaseCompanyAttach1Mapper, BaseCompanyAttach1> implements BaseCompanyAttach1Service {
 
+    @Autowired
+    private BaseCompanyMapper baseCompanyMapper;
+
+    @Override
+    public void streetTownList() {
+        List<String> streetTownList = new ArrayList<>();
+        streetTownList.add("华漕镇");
+        streetTownList.add("新虹街道");
+        streetTownList.add("七宝镇");
+        streetTownList.add("虹桥镇");
+        streetTownList.add("古美路街道");
+        streetTownList.add("莘庄镇");
+        streetTownList.add("梅陇镇");
+        streetTownList.add("颛桥镇");
+        streetTownList.add("马桥镇");
+        streetTownList.add("江川路街道");
+        streetTownList.add("吴泾镇");
+        streetTownList.add("浦锦街道");
+        streetTownList.add("浦江镇");
+        LambdaQueryWrapper<BaseCompany> queryWrapper1 = Wrappers.lambdaQuery();
+        queryWrapper1.select(BaseCompany::getId, BaseCompany::getCompanyId)
+                .eq(BaseCompany::getEnable, 0)
+                .notIn(BaseCompany::getStreetTown,streetTownList);
+        List<BaseCompany> baseCompanies = baseCompanyMapper.selectList(queryWrapper1);
+        if (CollectionUtils.isNotEmpty(baseCompanies)){
+            List<String> companyIdList = new ArrayList<>();
+            for (int i = 0; i < baseCompanies.size(); i++) {
+                companyIdList.add(baseCompanies.get(i).getCompanyId());
+            }
+
+            LambdaQueryWrapper<BaseCompanyAttach1> queryWrapper = Wrappers.lambdaQuery();
+            queryWrapper.select(BaseCompanyAttach1::getId, BaseCompanyAttach1::getLatitude, BaseCompanyAttach1::getLongitude, BaseCompanyAttach1::getCompanyId)
+//                    .ne(BaseCompanyAttach1::getLatitude, "")
+//                    .ne(BaseCompanyAttach1::getLongitude, "")
+                    .in(BaseCompanyAttach1::getCompanyId,companyIdList);
+            List<BaseCompanyAttach1> list = this.list(queryWrapper);
+
+            if (CollectionUtils.isNotEmpty(list)) {
+                for (int i = 0; i < 11; i++) {
+                    if (StringUtils.isNotBlank(list.get(i).getLongitude()) && StringUtils.isNotBlank(list.get(i).getLatitude())) {
+                        String location = list.get(i).getLongitude() + "," + list.get(i).getLatitude();
+                        String streetTown = OnlineMethod.getStreetTown(location);
+                        System.out.println(streetTown);
+                        if (StringUtils.isNotBlank(streetTown)) {
+                            for (int j = 0; j < baseCompanies.size(); j++) {
+                                if (list.get(i).getCompanyId().equals(baseCompanies.get(j).getCompanyId())) {
+                                    BaseCompany baseCompany = new BaseCompany();
+                                    baseCompany.setId(baseCompanies.get(j).getId());
+                                    baseCompany.setStreetTown(streetTown);
+                                    baseCompanyMapper.updateById(baseCompany);
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
 }

+ 26 - 5
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/util/OnlineMethod.java

@@ -1,6 +1,7 @@
 package com.usky.fire.service.util;
 
 //import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+
 import com.alibaba.nacos.common.utils.StringUtils;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -32,30 +33,31 @@ public class OnlineMethod {
 
     /**
      * 1.地址转换为经纬度
+     *
      * @param address 地址
      * @return 经纬度
      */
-    private static final String GOULD_KEY="2761d6ab4784b2f1de57a787f18c0e46";
+    private static final String GOULD_KEY = "2761d6ab4784b2f1de57a787f18c0e46";
 
     public static List<LocateInfo> getLonLat(String address) {
         List<LocateInfo> locateInfos = new ArrayList<>();
         try {
             // 返回输入地址address的经纬度信息, 格式是 经度,纬度
             String encode = URLEncoder.encode(address, "UTF-8");
-            String queryUrl = "http://restapi.amap.com/v3/geocode/geo?"+"key="+GOULD_KEY+"&address=" + encode+"&batch=true";
+            String queryUrl = "http://restapi.amap.com/v3/geocode/geo?" + "key=" + GOULD_KEY + "&address=" + encode + "&batch=true";
             String queryResult = getResponse(queryUrl);
             JsonNode arrNode = new ObjectMapper().readTree(queryResult).get("geocodes");
             if (arrNode.isArray()) {
                 for (JsonNode objNode : arrNode) {
                     LocateInfo locateInfo = new LocateInfo();
                     String location = objNode.get("location").asText();
-                    if (StringUtils.isNotBlank(location) && !"[]".equals(location)){
+                    if (StringUtils.isNotBlank(location) && !"[]".equals(location)) {
                         String[] locations = StringUtils.split(objNode.get("location").asText(), ",");
                         locateInfo.setLongitude(Double.parseDouble(locations[0]));
                         locateInfo.setLatitude(Double.parseDouble(locations[1]));
                         locateInfo.setDistrict(objNode.get("district").asText());
                         locateInfo.setStreet(objNode.get("street").asText());
-                    }else {
+                    } else {
                         locateInfo.setLongitude(0.00);
                         locateInfo.setLatitude(0.00);
                         locateInfo.setDistrict("");
@@ -64,14 +66,33 @@ public class OnlineMethod {
                     locateInfos.add(locateInfo);
                 }
             }
-        }catch (Exception e){
+        } catch (Exception e) {
             log.error(e.getMessage());
         }
         return locateInfos;
     }
 
+
+    public static String getStreetTown(String location) {
+        String streetTown = null;
+        try {
+            // 返回输入地址address的经纬度信息, 格式是 经度,纬度
+            String encode = URLEncoder.encode(location, "UTF-8");
+            String queryUrl = "http://restapi.amap.com/v3/geocode/regeo?" + "key=" + GOULD_KEY + "&location=" + encode + "";
+            String queryResult = getResponse(queryUrl);
+            JsonNode arrNode = new ObjectMapper().readTree(queryResult).get("regeocode");
+            JsonNode addressComponent = arrNode.get("addressComponent");
+            streetTown = addressComponent.get("township").toString();
+            streetTown = streetTown.replace("\"","");
+        } catch (Exception e) {
+            log.error(e.getMessage());
+        }
+        return streetTown;
+    }
+
     /**
      * 3.发送请求
+     *
      * @param serverUrl 请求地址
      */
     private static String getResponse(String serverUrl) {