• 通过IP获取省市区,批量更改


    XXXServicelmpl.java

    @Override
    public void getEquipmentLocation(Long currentPage, Long size){
    
            boolean loop = true;
            List<AppStatisticalSettingEquipmentAddressRespVO> equipmentList = new ArrayList<>();
            while (loop){
                Page<EquipmentDO> page = new Page<>(currentPage, size);
    
                QueryWrapper<EquipmentDO> queryWrapperX = new QueryWrapper<EquipmentDO>().select("id,lat,lng");
                IPage<EquipmentDO> iPage = equipmentMapper.selectPage(page, queryWrapperX);
    
                if(iPage.getRecords().size() > 0){
                    iPage.getRecords().forEach((item) -> {
                        if(item.getLat() > 0 && item.getLng() > 0)
                        {
                            AppStatisticalSettingEquipmentAddressRespVO equipmentAddressRespVO = new AppStatisticalSettingEquipmentAddressRespVO();
                            try {
                                URL url = new URL("https://api.map.baidu.com/reverse_geocoding/v3/?ak=RVbvVtpBxRgkvDGS6Wej2G3nb0ejOxGk&output=json&coordtype=wgs84ll&location=" + item.getLat() + "," + item.getLng());
                                HttpURLConnection ucon = (HttpURLConnection) url.openConnection();
                                ucon.connect();
    
                                InputStream in = ucon.getInputStream();
                                BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
                                String str = reader.readLine();
    
                                JSONObject jsonObj = JSON.parseObject(str);
                                JSONObject address = jsonObj.getJSONObject("result").getJSONObject("addressComponent");
    
                                if(address != null)
                                {
                                    equipmentAddressRespVO.setEquipmentId(item.getId());
                                    equipmentAddressRespVO.setProvince(address.getString("province"));
                                    equipmentAddressRespVO.setCity(address.getString("city"));
                                    equipmentAddressRespVO.setDistrict(address.getString("district"));
    
                                    equipmentList.add(equipmentAddressRespVO);
                                }
    
                            } catch (IOException e) {
                                throw new RuntimeException(e);
                            }
                        }
                    });
                    loop = false;
                    currentPage += 1;
                }else{
                    loop = false;
                }
            }
    
            // 生成批量数据
            equipmentMapper.updateBatchDifferentFields(equipmentList);
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53

    XXXMapper.java

     void updateBatchDifferentFields(@Param("list") List<AppStatisticalSettingEquipmentAddressRespVO> equipmentList);
    
    • 1

    XXXMapper.xml

    
        
            update nlm_equipment
            
                province=#{item.province},
                city=#{item.city},
                district=#{item.district}
            
            where id = ${item.equipmentId}
        
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
  • 相关阅读:
    【RocketMQ】消息的存储总结
    实时人脸五观检测:基于libfacedetection(CNN模型)
    身为网络工程师必考证书:华为HCIP认证!
    Dlang 与 C 语言交互(二)
    MyBatis Dynamic SQL基本使用
    基于语雀编辑器的在线文档编辑与查看
    神经网络最重要的是什么,什么神经网络最好用
    冠军方案!2023第二届广州·琶洲算法大赛
    什么是SpringMVC?简单好理解!
    Ps:裁剪工具 - 裁剪预设的应用
  • 原文地址:https://blog.csdn.net/qq_31315703/article/details/127743733