高德API
parent
390eebd176
commit
e03191633d
|
@ -136,6 +136,11 @@
|
|||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
package com.muyu.common.system.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.muyu.common.core.annotation.Excel;
|
||||
import com.muyu.common.core.web.domain.TreeEntity;
|
||||
import com.muyu.common.system.domain.req.SysDistrictEditReq;
|
||||
import com.muyu.common.system.domain.req.SysDistrictQueryReq;
|
||||
import com.muyu.common.system.domain.req.SysDistrictSaveReq;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* 地域地区对象 sys_district
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @date 2024-04-11
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("sys_district")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel(value = "SysDistrict", description = "地域地区")
|
||||
public class SysDistrict extends TreeEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** ID */
|
||||
@TableId(value = "id",type = IdType.AUTO)
|
||||
@ApiModelProperty(name = "ID", value = "ID")
|
||||
private Long id;
|
||||
|
||||
/** 名称 */
|
||||
@Excel(name = "名称")
|
||||
@ApiModelProperty(name = "名称", value = "名称")
|
||||
private String name;
|
||||
|
||||
/** 编码 */
|
||||
@Excel(name = "编码")
|
||||
@ApiModelProperty(name = "编码", value = "编码")
|
||||
private String code;
|
||||
|
||||
/** 级别 */
|
||||
@Excel(name = "级别")
|
||||
@ApiModelProperty(name = "级别", value = "级别")
|
||||
private String level;
|
||||
|
||||
/** 级别编码 */
|
||||
@ApiModelProperty(name = "级别编码", value = "级别编码")
|
||||
private String codeLevel;
|
||||
|
||||
/** 区域编码 */
|
||||
@Excel(name = "区域编码")
|
||||
@ApiModelProperty(name = "区域编码", value = "区域编码")
|
||||
private String areaCode;
|
||||
|
||||
/** 中心经纬度 */
|
||||
@Excel(name = "中心经纬度")
|
||||
@ApiModelProperty(name = "中心经纬度", value = "中心经纬度")
|
||||
private String center;
|
||||
|
||||
/**
|
||||
* 查询构造器
|
||||
*/
|
||||
public static SysDistrict queryBuild( SysDistrictQueryReq sysDistrictQueryReq){
|
||||
return SysDistrict.builder()
|
||||
.parentId(sysDistrictQueryReq.getParentId())
|
||||
.name(sysDistrictQueryReq.getName())
|
||||
.code(sysDistrictQueryReq.getCode())
|
||||
.level(sysDistrictQueryReq.getLevel())
|
||||
.areaCode(sysDistrictQueryReq.getAreaCode())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加构造器
|
||||
*/
|
||||
public static SysDistrict saveBuild(SysDistrictSaveReq sysDistrictSaveReq){
|
||||
return SysDistrict.builder()
|
||||
.parentId(sysDistrictSaveReq.getParentId())
|
||||
.name(sysDistrictSaveReq.getName())
|
||||
.code(sysDistrictSaveReq.getCode())
|
||||
.level(sysDistrictSaveReq.getLevel())
|
||||
.codeLevel(sysDistrictSaveReq.getCodeLevel())
|
||||
.areaCode(sysDistrictSaveReq.getAreaCode())
|
||||
.center(sysDistrictSaveReq.getCenter())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改构造器
|
||||
*/
|
||||
public static SysDistrict editBuild(Long id, SysDistrictEditReq sysDistrictEditReq){
|
||||
return SysDistrict.builder()
|
||||
.id(id)
|
||||
.parentId(sysDistrictEditReq.getParentId())
|
||||
.name(sysDistrictEditReq.getName())
|
||||
.code(sysDistrictEditReq.getCode())
|
||||
.level(sysDistrictEditReq.getLevel())
|
||||
.codeLevel(sysDistrictEditReq.getCodeLevel())
|
||||
.areaCode(sysDistrictEditReq.getAreaCode())
|
||||
.center(sysDistrictEditReq.getCenter())
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package com.muyu.common.system.domain.req;
|
||||
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* 地域地区对象 sys_district
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @date 2024-04-11
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@ApiModel(value = "SysDistrictEditReq", description = "地域地区")
|
||||
public class SysDistrictEditReq extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 父级 */
|
||||
@ApiModelProperty(name = "父级", value = "父级")
|
||||
private Long parentId;
|
||||
|
||||
/** 名称 */
|
||||
@ApiModelProperty(name = "名称", value = "名称")
|
||||
private String name;
|
||||
|
||||
/** 编码 */
|
||||
@ApiModelProperty(name = "编码", value = "编码")
|
||||
private String code;
|
||||
|
||||
/** 级别 */
|
||||
@ApiModelProperty(name = "级别", value = "级别")
|
||||
private String level;
|
||||
|
||||
/** 级别编码 */
|
||||
@ApiModelProperty(name = "级别编码", value = "级别编码")
|
||||
private String codeLevel;
|
||||
|
||||
/** 区域编码 */
|
||||
@ApiModelProperty(name = "区域编码", value = "区域编码")
|
||||
private String areaCode;
|
||||
|
||||
/** 中心经纬度 */
|
||||
@ApiModelProperty(name = "中心经纬度", value = "中心经纬度")
|
||||
private String center;
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.muyu.common.system.domain.req;
|
||||
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* 地域地区对象 sys_district
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @date 2024-04-11
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@ApiModel(value = "SysDistrictQueryReq", description = "地域地区")
|
||||
public class SysDistrictQueryReq extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 父级 */
|
||||
@ApiModelProperty(name = "父级", value = "父级")
|
||||
private Long parentId;
|
||||
|
||||
/** 名称 */
|
||||
@ApiModelProperty(name = "名称", value = "名称")
|
||||
private String name;
|
||||
|
||||
/** 编码 */
|
||||
@ApiModelProperty(name = "编码", value = "编码")
|
||||
private String code;
|
||||
|
||||
/** 级别 */
|
||||
@ApiModelProperty(name = "级别", value = "级别")
|
||||
private String level;
|
||||
|
||||
/** 区域编码 */
|
||||
@ApiModelProperty(name = "区域编码", value = "区域编码")
|
||||
private String areaCode;
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package com.muyu.common.system.domain.req;
|
||||
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* 地域地区对象 sys_district
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @date 2024-04-11
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@ApiModel(value = "SysDistrictSaveReq", description = "地域地区")
|
||||
public class SysDistrictSaveReq extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** ID */
|
||||
|
||||
@ApiModelProperty(name = "ID", value = "ID")
|
||||
private Long id;
|
||||
|
||||
/** 父级 */
|
||||
|
||||
@ApiModelProperty(name = "父级", value = "父级")
|
||||
private Long parentId;
|
||||
|
||||
/** 名称 */
|
||||
|
||||
@ApiModelProperty(name = "名称", value = "名称")
|
||||
private String name;
|
||||
|
||||
/** 编码 */
|
||||
|
||||
@ApiModelProperty(name = "编码", value = "编码")
|
||||
private String code;
|
||||
|
||||
/** 级别 */
|
||||
|
||||
@ApiModelProperty(name = "级别", value = "级别")
|
||||
private String level;
|
||||
|
||||
/** 级别编码 */
|
||||
|
||||
@ApiModelProperty(name = "级别编码", value = "级别编码")
|
||||
private String codeLevel;
|
||||
|
||||
/** 区域编码 */
|
||||
|
||||
@ApiModelProperty(name = "区域编码", value = "区域编码")
|
||||
private String areaCode;
|
||||
|
||||
/** 中心经纬度 */
|
||||
|
||||
@ApiModelProperty(name = "中心经纬度", value = "中心经纬度")
|
||||
private String center;
|
||||
|
||||
}
|
|
@ -78,6 +78,12 @@
|
|||
<artifactId>muyu-common-swagger</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.dtflys.forest</groupId>
|
||||
<artifactId>forest-spring-boot-starter</artifactId>
|
||||
<version>1.5.36</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
package com.muyu.system.controller;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.poi.ExcelUtil;
|
||||
import com.muyu.common.core.web.controller.BaseController;
|
||||
import com.muyu.common.core.web.page.TableDataInfo;
|
||||
import com.muyu.common.log.annotation.Log;
|
||||
import com.muyu.common.log.enums.BusinessType;
|
||||
import com.muyu.common.security.annotation.RequiresPermissions;
|
||||
import com.muyu.common.system.domain.SysDistrict;
|
||||
import com.muyu.common.system.domain.req.SysDistrictEditReq;
|
||||
import com.muyu.common.system.domain.req.SysDistrictQueryReq;
|
||||
import com.muyu.common.system.domain.req.SysDistrictSaveReq;
|
||||
import com.muyu.system.service.SysDistrictService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 地域地区Controller
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @date 2024-04-11
|
||||
*/
|
||||
@Api(tags = "地域地区")
|
||||
@RestController
|
||||
@RequestMapping("/district")
|
||||
public class SysDistrictController extends BaseController {
|
||||
@Autowired
|
||||
private SysDistrictService sysDistrictService;
|
||||
|
||||
/**
|
||||
* 查询地域地区列表
|
||||
*/
|
||||
@ApiOperation("获取地域地区列表")
|
||||
@RequiresPermissions("system:district:list")
|
||||
@GetMapping("/list")
|
||||
public Result<TableDataInfo<SysDistrict>> list(SysDistrictQueryReq sysDistrictQueryReq) {
|
||||
List<SysDistrict> list = sysDistrictService.list(SysDistrict.queryBuild(sysDistrictQueryReq));
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出地域地区列表
|
||||
*/
|
||||
@ApiOperation("导出地域地区列表")
|
||||
@RequiresPermissions("system:district:export")
|
||||
@Log(title = "地域地区", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, SysDistrict sysDistrict) {
|
||||
List<SysDistrict> list = sysDistrictService.list(sysDistrict);
|
||||
ExcelUtil<SysDistrict> util = new ExcelUtil<SysDistrict>(SysDistrict.class);
|
||||
util.exportExcel(response, list, "地域地区数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取地域地区详细信息
|
||||
*/
|
||||
@ApiOperation("获取地域地区详细信息")
|
||||
@RequiresPermissions("system:district:query")
|
||||
@GetMapping(value = "/{id}")
|
||||
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
|
||||
public Result<SysDistrict> getInfo(@PathVariable("id") Long id) {
|
||||
return Result.success(sysDistrictService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增地域地区
|
||||
*/
|
||||
@RequiresPermissions("system:district:add")
|
||||
@Log(title = "地域地区", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
@ApiOperation("新增地域地区")
|
||||
public Result<String> add(@RequestBody SysDistrictSaveReq sysDistrictSaveReq) {
|
||||
return toAjax(sysDistrictService.save(SysDistrict.saveBuild(sysDistrictSaveReq)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改地域地区
|
||||
*/
|
||||
@RequiresPermissions("system:district:edit")
|
||||
@Log(title = "地域地区", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/{id}")
|
||||
@ApiOperation("修改地域地区")
|
||||
public Result<String> edit(@PathVariable Long id, @RequestBody SysDistrictEditReq sysDistrictEditReq) {
|
||||
return toAjax(sysDistrictService.updateById(SysDistrict.editBuild(id,sysDistrictEditReq)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除地域地区
|
||||
*/
|
||||
@RequiresPermissions("system:district:remove")
|
||||
@Log(title = "地域地区", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
@ApiOperation("删除地域地区")
|
||||
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = String.class, example = "1,2,3,4")
|
||||
public Result<String> remove(@PathVariable List<Long> ids) {
|
||||
return toAjax(sysDistrictService.removeBatchByIds(ids));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.muyu.system.forest.gaode.api;
|
||||
|
||||
import com.dtflys.forest.annotation.BaseRequest;
|
||||
import com.dtflys.forest.annotation.Get;
|
||||
import com.dtflys.forest.annotation.Var;
|
||||
import com.muyu.system.forest.gaode.api.resp.DistrictResult;
|
||||
import com.muyu.system.forest.gaode.interceptor.GaoDeInterceptor;
|
||||
|
||||
/**
|
||||
* 高德地图接口
|
||||
*
|
||||
* @author CHX
|
||||
* on 2024/4/11 星期四
|
||||
*/
|
||||
@BaseRequest(
|
||||
baseURL = "https://restapi.amap.com",
|
||||
interceptor = GaoDeInterceptor.class,
|
||||
timeout = 5000,
|
||||
connectTimeout = 5000,
|
||||
readTimeout = 5000
|
||||
)
|
||||
public interface GaoDeBaseApi {
|
||||
@Get("/v3/config/district?keywords={keywords}&subdistrict={subDistrict}")
|
||||
DistrictResult district(@Var("keywords") String keywords, @Var("subDistrict") String subDistrict);
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.muyu.system.forest.gaode.api.resp;
|
||||
|
||||
import lombok.Data;
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 响应实体类
|
||||
*
|
||||
* @author CHX
|
||||
* on 2024/4/11 星期四
|
||||
*/
|
||||
@Data
|
||||
public class District {
|
||||
|
||||
/** 名称 */
|
||||
private String name;
|
||||
|
||||
/** 编码 */
|
||||
@JSONField(name = "citycode")
|
||||
private String code;
|
||||
|
||||
/** 级别 */
|
||||
private String level;
|
||||
|
||||
/** 区域编码 */
|
||||
@JSONField(name = "adcode")
|
||||
private String areaCode;
|
||||
|
||||
/** 中心经纬度 */
|
||||
private String center;
|
||||
|
||||
/**
|
||||
* 子
|
||||
*/
|
||||
private List<District> districts;
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.muyu.system.forest.gaode.api.resp;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 接口返回结果集
|
||||
*
|
||||
* @author CHX
|
||||
* on 2024/4/11 星期四
|
||||
*/
|
||||
@Data
|
||||
public class DistrictResult {
|
||||
/**
|
||||
* 返回结果状态值
|
||||
* 值为0或1,0表示失败;1表示成功
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 返回状态说明
|
||||
* 返回状态说明,status为0时,info返回错误原因,否则返回“OK”。
|
||||
*/
|
||||
private String info;
|
||||
|
||||
/**
|
||||
* 状态码
|
||||
* 返回状态说明,10000代表正确,详情参阅info状态表
|
||||
*/
|
||||
@JSONField(name = "infocode")
|
||||
private String infoCode;
|
||||
|
||||
/**
|
||||
* 行政区列表
|
||||
*/
|
||||
private List<District> districts;
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.muyu.system.forest.gaode.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 高德配置
|
||||
*
|
||||
* @author CHX
|
||||
* on 2024/4/11 星期四
|
||||
*/
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "gaode")
|
||||
public class GaoDeConfig {
|
||||
/**
|
||||
* 高德key
|
||||
*/
|
||||
private String key;
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
package com.muyu.system.forest.gaode.interceptor;
|
||||
|
||||
import com.dtflys.forest.converter.ForestEncoder;
|
||||
import com.dtflys.forest.exceptions.ForestRuntimeException;
|
||||
import com.dtflys.forest.http.ForestRequest;
|
||||
import com.dtflys.forest.http.ForestResponse;
|
||||
import com.dtflys.forest.interceptor.Interceptor;
|
||||
import com.dtflys.forest.reflection.ForestMethod;
|
||||
import com.muyu.system.forest.gaode.config.GaoDeConfig;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
/**
|
||||
* 拦截器
|
||||
*
|
||||
* @author CHX
|
||||
* on 2024/4/11 星期四
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
public class GaoDeInterceptor implements Interceptor<String> {
|
||||
|
||||
@Autowired
|
||||
private GaoDeConfig gaoDeConfig;
|
||||
/**
|
||||
* 该方法在被调用时,并在beforeExecute前被调用
|
||||
* @Param request Forest请求对象
|
||||
* @Param args 方法被调用时传入的参数数组
|
||||
*/
|
||||
@Override
|
||||
public void onInvokeMethod(ForestRequest req, ForestMethod method, Object[] args) {
|
||||
log.info("on invoke method");
|
||||
}
|
||||
|
||||
/**
|
||||
* 在请求体数据序列化后,发送请求数据前调用该方法
|
||||
* 默认为什么都不做
|
||||
* 注: multlipart/data类型的文件上传格式的 Body 数据不会调用该回调函数
|
||||
*
|
||||
* @param request Forest请求对象
|
||||
* @param encoder Forest转换器
|
||||
* @param encodedData 序列化后的请求体数据
|
||||
*/
|
||||
public byte[] onBodyEncode(ForestRequest request, ForestEncoder encoder, byte[] encodedData) {
|
||||
// request: Forest请求对象
|
||||
// encoder: 此次转换请求数据的序列化器
|
||||
// encodedData: 序列化后的请求体字节数组
|
||||
// 返回的字节数组将替换原有的序列化结果
|
||||
// 默认不做任何处理,直接返回参数 encodedData
|
||||
return encodedData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 该方法在请求发送之前被调用, 若返回false则不会继续发送请求
|
||||
* @Param request Forest请求对象
|
||||
*/
|
||||
@Override
|
||||
public boolean beforeExecute(ForestRequest req) {
|
||||
log.info("invoke Simple beforeExecute");
|
||||
// 执行在发送请求之前处理的代码 // 添加Header
|
||||
req.addQuery("key", gaoDeConfig.getKey()); // 添加URL的Query参数
|
||||
return true; // 继续执行请求返回true
|
||||
}
|
||||
|
||||
/**
|
||||
* 该方法在请求发送失败时被调用
|
||||
*/
|
||||
@Override
|
||||
public void onError(ForestRuntimeException ex, ForestRequest req, ForestResponse res) {
|
||||
log.info("invoke Simple onError");
|
||||
}
|
||||
|
||||
/**
|
||||
* 该方法在请求发送之后被调用
|
||||
*/
|
||||
@Override
|
||||
public void afterExecute(ForestRequest req, ForestResponse res) {
|
||||
log.info("invoke Simple afterExecute");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.muyu.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.common.system.domain.SysDistrict;
|
||||
|
||||
/**
|
||||
* 地域地区Mapper接口
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @date 2024-04-11
|
||||
*/
|
||||
public interface SysDistrictMapper extends BaseMapper<SysDistrict> {
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.muyu.system.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.common.system.domain.SysDistrict;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 地域地区Service接口
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @date 2024-04-11
|
||||
*/
|
||||
public interface SysDistrictService extends IService<SysDistrict> {
|
||||
/**
|
||||
* 查询地域地区列表
|
||||
*
|
||||
* @param sysDistrict 地域地区
|
||||
* @return 地域地区集合
|
||||
*/
|
||||
public List<SysDistrict> list(SysDistrict sysDistrict);
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package com.muyu.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.common.core.utils.ObjUtils;
|
||||
import com.muyu.common.system.domain.SysDistrict;
|
||||
import com.muyu.system.mapper.SysDistrictMapper;
|
||||
import com.muyu.system.service.SysDistrictService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 地域地区Service业务层处理
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @date 2024-04-11
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SysDistrictServiceImpl extends ServiceImpl<SysDistrictMapper, SysDistrict> implements SysDistrictService {
|
||||
|
||||
/**
|
||||
* 查询地域地区列表
|
||||
*
|
||||
* @param sysDistrict 地域地区
|
||||
* @return 地域地区
|
||||
*/
|
||||
@Override
|
||||
public List<SysDistrict> list(SysDistrict sysDistrict) {
|
||||
LambdaQueryWrapper<SysDistrict> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
|
||||
if (ObjUtils.notNull(sysDistrict.getParentId())){
|
||||
queryWrapper.eq(SysDistrict::getParentId, sysDistrict.getParentId());
|
||||
}
|
||||
|
||||
if (ObjUtils.notNull(sysDistrict.getName())){
|
||||
queryWrapper.like(SysDistrict::getName, sysDistrict.getName());
|
||||
}
|
||||
|
||||
if (ObjUtils.notNull(sysDistrict.getCode())){
|
||||
queryWrapper.eq(SysDistrict::getCode, sysDistrict.getCode());
|
||||
}
|
||||
|
||||
if (ObjUtils.notNull(sysDistrict.getLevel())){
|
||||
queryWrapper.eq(SysDistrict::getLevel, sysDistrict.getLevel());
|
||||
}
|
||||
|
||||
|
||||
if (ObjUtils.notNull(sysDistrict.getAreaCode())){
|
||||
queryWrapper.eq(SysDistrict::getAreaCode, sysDistrict.getAreaCode());
|
||||
}
|
||||
|
||||
return list(queryWrapper);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.muyu.system.mapper.SysDistrictMapper">
|
||||
|
||||
<resultMap type="com.muyu.common.system.domain.SysDistrict" id="SysDistrictResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="parentId" column="parent_id" />
|
||||
<result property="name" column="name" />
|
||||
<result property="code" column="code" />
|
||||
<result property="level" column="level" />
|
||||
<result property="codeLevel" column="code_level" />
|
||||
<result property="areaCode" column="area_code" />
|
||||
<result property="center" column="center" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="remark" column="remark" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectSysDistrictVo">
|
||||
select id, parent_id, name, code, level, code_level, area_code, center, create_by, create_time, update_by, update_time, remark from sys_district
|
||||
</sql>
|
||||
</mapper>
|
|
@ -0,0 +1,89 @@
|
|||
package com.forest;
|
||||
|
||||
import com.alibaba.nacos.shaded.com.google.common.collect.Lists;
|
||||
import com.muyu.common.system.domain.SysDistrict;
|
||||
import com.muyu.system.MuYuSystemApplication;
|
||||
import com.muyu.system.forest.gaode.api.GaoDeBaseApi;
|
||||
import com.muyu.system.forest.gaode.api.resp.District;
|
||||
import com.muyu.system.forest.gaode.api.resp.DistrictResult;
|
||||
import com.muyu.system.service.SysDistrictService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 测试
|
||||
*
|
||||
* @author CHX
|
||||
* on 2024/4/11 星期四
|
||||
*/
|
||||
@SpringBootTest(classes = MuYuSystemApplication.class)
|
||||
public class FoRestTest {
|
||||
|
||||
@Resource
|
||||
private GaoDeBaseApi gaoDeBaseApi;
|
||||
|
||||
@Autowired
|
||||
private SysDistrictService sysDistrictService;
|
||||
|
||||
@Test
|
||||
public void testApiGaoDe() {
|
||||
DistrictResult districtResult = gaoDeBaseApi.district("广东省", "3");
|
||||
List<District> districtList = districtResult.getDistricts();
|
||||
if (districtList.size() == 1 && "中华人民共和国".equals(districtList.get(0).getName())) {
|
||||
districtList = districtList.get(0).getDistricts();
|
||||
}
|
||||
|
||||
// 使用线程池并发处理数据
|
||||
int NUM_THREADS = 10; // 根据实际情况调整线程数量
|
||||
int SUB_LIST_SIZE = (int) Math.ceil((double) districtList.size() / NUM_THREADS);
|
||||
ExecutorService executor = Executors.newFixedThreadPool(NUM_THREADS);
|
||||
|
||||
for (List<District> subList : Lists.partition(districtList, SUB_LIST_SIZE)) {
|
||||
executor.submit(() -> {
|
||||
conversion(0L, null, subList);
|
||||
});
|
||||
}
|
||||
|
||||
executor.shutdown();
|
||||
try {
|
||||
executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void conversion(Long parentId, String codeLevel, List<District> districtList) {
|
||||
if (districtList == null || districtList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (codeLevel == null || codeLevel.length() == 0) {
|
||||
codeLevel = parentId + "";
|
||||
} else {
|
||||
codeLevel = codeLevel + "-" + parentId;
|
||||
}
|
||||
|
||||
for (District district : districtList) {
|
||||
SysDistrict sysDistrict = SysDistrict.builder()
|
||||
.parentId(parentId)
|
||||
.level(district.getLevel())
|
||||
.code("[]".equals(district.getCode()) ? "-" : district.getCode())
|
||||
.codeLevel(codeLevel)
|
||||
.name(district.getName())
|
||||
.center(district.getCenter())
|
||||
.areaCode(district.getAreaCode())
|
||||
.build();
|
||||
sysDistrictService.save(sysDistrict);
|
||||
|
||||
conversion(sysDistrict.getId(), sysDistrict.getCodeLevel(), district.getDistricts());
|
||||
}
|
||||
}
|
||||
}
|
9
pom.xml
9
pom.xml
|
@ -30,11 +30,12 @@
|
|||
<dynamic-ds.version>3.5.2</dynamic-ds.version>
|
||||
<commons.io.version>2.13.0</commons.io.version>
|
||||
<velocity.version>2.3</velocity.version>
|
||||
<fastjson.version>2.0.41</fastjson.version>
|
||||
<fastjson.version>2.0.46</fastjson.version>
|
||||
<jjwt.version>0.9.1</jjwt.version>
|
||||
<minio.version>8.2.2</minio.version>
|
||||
<poi.version>4.1.2</poi.version>
|
||||
<transmittable-thread-local.version>2.14.3</transmittable-thread-local.version>
|
||||
<forest.version>1.5.36</forest.version>
|
||||
</properties>
|
||||
|
||||
<!-- 依赖声明 -->
|
||||
|
@ -94,6 +95,12 @@
|
|||
<version>${kaptcha.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.dtflys.forest</groupId>
|
||||
<artifactId>forest-spring-boot-starter</artifactId>
|
||||
<version>${forest.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- pagehelper 分页插件 -->
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
|
|
Loading…
Reference in New Issue