增加获取附近停车场或超市地址任务
This commit is contained in:
parent
a6f08a7ad2
commit
c771fac8dc
|
|
@ -0,0 +1,116 @@
|
|||
package com.ruoyi.database.domain;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 停车场附近表(ParkingNearInfo)实体类
|
||||
*
|
||||
* @author makejava
|
||||
* @since 2025-11-18 13:45:09
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName(value = "parking_near_info")
|
||||
@ApiModel(value = "ParkingNearInfo", description = "停车场附近表")
|
||||
public class ParkingNearInfo {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@ApiModelProperty("主键")
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@ApiModelProperty("创建时间")
|
||||
@Excel(name = "创建时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
@ApiModelProperty("创建者")
|
||||
@Excel(name = "创建者")
|
||||
private Integer createBy;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@ApiModelProperty("更新时间")
|
||||
@Excel(name = "更新时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 更新者
|
||||
*/
|
||||
@ApiModelProperty("更新者")
|
||||
@Excel(name = "更新者")
|
||||
private Integer updateBy;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
@ApiModelProperty("名称")
|
||||
@Excel(name = "名称")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 地址
|
||||
*/
|
||||
@ApiModelProperty("地址")
|
||||
@Excel(name = "地址")
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 经度
|
||||
*/
|
||||
@ApiModelProperty("经度")
|
||||
@Excel(name = "经度")
|
||||
private Double lng;
|
||||
|
||||
/**
|
||||
* 纬度
|
||||
*/
|
||||
@ApiModelProperty("纬度")
|
||||
@Excel(name = "纬度")
|
||||
private Double lat;
|
||||
|
||||
/**
|
||||
* 类型 1.附近停车场 2.附近常客隆
|
||||
*/
|
||||
@ApiModelProperty("类型 1.附近停车场 2.附近常客隆")
|
||||
@Excel(name = "类型 1.附近停车场 2.附近常客隆")
|
||||
private Integer nearType;
|
||||
|
||||
/**
|
||||
* 距离
|
||||
*/
|
||||
@ApiModelProperty("距离")
|
||||
@Excel(name = "距离")
|
||||
private String distance;
|
||||
|
||||
/**
|
||||
* 中心停车场编码
|
||||
*/
|
||||
@ApiModelProperty("中心停车场编码")
|
||||
@Excel(name = "中心停车场编码")
|
||||
private String code;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.ruoyi.database.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.ruoyi.database.domain.ParkingNearInfo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 停车场附近表(ParkingNearInfo) Mapper 接口
|
||||
*
|
||||
* @author makejava
|
||||
* @since ${date}
|
||||
*/
|
||||
@Mapper
|
||||
public interface ParkingNearInfoMapper extends BaseMapper<ParkingNearInfo> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.ruoyi.database.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.ruoyi.database.domain.ParkingNearInfo;
|
||||
|
||||
/**
|
||||
* (停车场附近表)Service
|
||||
*
|
||||
* @author makejava
|
||||
* @since 2025-11-18 13:45:10
|
||||
*/
|
||||
public interface ParkingNearInfoService extends IService<ParkingNearInfo> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.ruoyi.database.service.impl;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ruoyi.database.domain.ParkingNearInfo;
|
||||
import com.ruoyi.database.mapper.ParkingNearInfoMapper;
|
||||
import com.ruoyi.database.service.ParkingNearInfoService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* (停车场附近表)ServiceImpl
|
||||
*
|
||||
* @author makejava
|
||||
* @since 2025-11-18 13:45:10
|
||||
*/
|
||||
@Service
|
||||
public class ParkingNearInfoServiceImpl extends ServiceImpl<ParkingNearInfoMapper, ParkingNearInfo> implements ParkingNearInfoService {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
package com.ruoyi.database.task;
|
||||
import java.util.List;
|
||||
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.ruoyi.business.util.StringKit;
|
||||
import com.ruoyi.database.domain.BaseParkingLotInfo;
|
||||
import com.ruoyi.database.domain.ParkingNearInfo;
|
||||
import com.ruoyi.database.service.BaseParkingLotInfoService;
|
||||
import com.ruoyi.database.service.ParkingNearInfoService;
|
||||
import com.ruoyi.database.util.AmapGeocoding;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ParkingNearInfoTask {
|
||||
|
||||
/**
|
||||
* 用于获取停车场经纬度
|
||||
* 以及停车场周边地址经纬度,名称。
|
||||
*/
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ParkingNearInfoTask.class);
|
||||
|
||||
private final BaseParkingLotInfoService baseParkingLotInfoService;
|
||||
private final ParkingNearInfoService parkingNearInfoService;
|
||||
|
||||
|
||||
// @Scheduled(initialDelay = 100, fixedRate = 3000000)
|
||||
@RequestMapping("/test")
|
||||
public void getPois() {
|
||||
try {
|
||||
List<BaseParkingLotInfo> list = baseParkingLotInfoService.list();
|
||||
list.forEach(baseParkingLotInfo -> {
|
||||
String location = AmapGeocoding.getLocation(baseParkingLotInfo.getAddress());
|
||||
JSONArray pois = AmapGeocoding.getPois(location,1000,"停车场");
|
||||
for (int i = 0; i < pois.size(); i++) {
|
||||
JSONObject poi = pois.getJSONObject(i);
|
||||
String name = poi.getStr("name");
|
||||
String address = poi.getStr("address");
|
||||
String location1 = poi.getStr("location"); // 格式: "经度,纬度"
|
||||
String[] lngLat = location1.split(",");
|
||||
String longitude = lngLat[0]; // 经度
|
||||
String latitude = lngLat[1]; // 纬度
|
||||
String distance = poi.getStr("distance", "未知"); // 距离中心点的距离
|
||||
ParkingNearInfo parkingNearInfo = new ParkingNearInfo();
|
||||
parkingNearInfo.setName(name);
|
||||
parkingNearInfo.setAddress(address);
|
||||
parkingNearInfo.setLng(Double.valueOf(longitude));
|
||||
parkingNearInfo.setLat(Double.valueOf(latitude));
|
||||
parkingNearInfo.setNearType(1);
|
||||
parkingNearInfo.setDistance(distance + "米");
|
||||
parkingNearInfo.setCode(baseParkingLotInfo.getCode());
|
||||
LambdaUpdateWrapper<ParkingNearInfo> queryWrapper = new LambdaUpdateWrapper<>();
|
||||
queryWrapper.eq(ParkingNearInfo::getCode, baseParkingLotInfo.getCode());
|
||||
queryWrapper.eq(ParkingNearInfo::getName, name);
|
||||
queryWrapper.eq(ParkingNearInfo::getAddress, address);
|
||||
parkingNearInfoService.saveOrUpdate(parkingNearInfo,queryWrapper);
|
||||
}
|
||||
|
||||
JSONArray pois1 = AmapGeocoding.getPois(location,1000,"常客隆超市");
|
||||
for (int i = 0; i < pois1.size(); i++) {
|
||||
JSONObject poi = pois1.getJSONObject(i);
|
||||
String name = poi.getStr("name");
|
||||
String address = poi.getStr("address");
|
||||
String location1 = poi.getStr("location"); // 格式: "经度,纬度"
|
||||
String[] lngLat = location1.split(",");
|
||||
String longitude = lngLat[0]; // 经度
|
||||
String latitude = lngLat[1]; // 纬度
|
||||
String distance = poi.getStr("distance", "未知"); // 距离中心点的距离
|
||||
ParkingNearInfo parkingNearInfo = new ParkingNearInfo();
|
||||
parkingNearInfo.setName(name);
|
||||
parkingNearInfo.setAddress(address);
|
||||
parkingNearInfo.setLng(Double.valueOf(longitude));
|
||||
parkingNearInfo.setLat(Double.valueOf(latitude));
|
||||
parkingNearInfo.setNearType(2);
|
||||
parkingNearInfo.setDistance(distance + "米");
|
||||
parkingNearInfo.setCode(baseParkingLotInfo.getCode());
|
||||
LambdaUpdateWrapper<ParkingNearInfo> queryWrapper = new LambdaUpdateWrapper<>();
|
||||
queryWrapper.eq(ParkingNearInfo::getCode, baseParkingLotInfo.getCode());
|
||||
queryWrapper.eq(ParkingNearInfo::getName, name);
|
||||
queryWrapper.eq(ParkingNearInfo::getAddress, address);
|
||||
parkingNearInfoService.saveOrUpdate(parkingNearInfo,queryWrapper);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.info(StringKit.getTrace(e));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -83,7 +83,7 @@ public class AmapGeocoding {
|
|||
* @param searchKeyword (关键词) 如:停车场
|
||||
* @return
|
||||
*/
|
||||
public static String getPois(String centerLocation,int searchRadius,String searchKeyword) {
|
||||
public static JSONArray getPois(String centerLocation,int searchRadius,String searchKeyword) {
|
||||
try {
|
||||
// 构建请求URL(注意:实际应用中需对keyword进行URL编码)
|
||||
String urlStr = String.format("https://restapi.amap.com/v3/place/around?key=%s&location=%s&radius=%d&keywords=%s&sortrule=distance",
|
||||
|
|
@ -119,6 +119,7 @@ public class AmapGeocoding {
|
|||
System.out.printf("名称: %s | 地址: %s | 经纬度: %s | 距离: %s米%n",
|
||||
name, address, location, distance);
|
||||
}
|
||||
return pois;
|
||||
} else {
|
||||
String errorInfo = jsonResponse.getStr("info");
|
||||
System.err.println("请求失败: " + errorInfo);
|
||||
|
|
@ -134,10 +135,10 @@ public class AmapGeocoding {
|
|||
|
||||
|
||||
public static void main(String[] args) {
|
||||
// String location = getLocation("常熟市海虞北路27号");
|
||||
// String location = getLocation("海虞北路27号");
|
||||
// System.out.println(location);
|
||||
// 120.754471,31.666573
|
||||
|
||||
getPois("120.754471,31.666573",1000,"常客隆超市");
|
||||
// getPois("120.754471,31.666573",1000,"常客隆超市");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.ruoyi;
|
|||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
* 场所管控 启动程序
|
||||
|
|
@ -10,6 +11,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
|||
* @author ruoyi
|
||||
*/
|
||||
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
|
||||
@EnableScheduling
|
||||
public class RuoYiApplication
|
||||
{
|
||||
public static void main(String[] args)
|
||||
|
|
|
|||
Loading…
Reference in New Issue