增加行政区划树接口
This commit is contained in:
@@ -1,26 +1,31 @@
|
||||
package org.dromara.property.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.constraints.*;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.dromara.common.idempotent.annotation.RepeatSubmit;
|
||||
import org.dromara.common.log.annotation.Log;
|
||||
import org.dromara.common.web.core.BaseController;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.common.core.validate.AddGroup;
|
||||
import org.dromara.common.core.validate.EditGroup;
|
||||
import org.dromara.common.log.enums.BusinessType;
|
||||
import org.dromara.common.excel.utils.ExcelUtil;
|
||||
import org.dromara.property.domain.vo.TbCityAreaVo;
|
||||
import org.dromara.property.domain.bo.TbCityAreaBo;
|
||||
import org.dromara.property.service.ITbCityAreaService;
|
||||
import org.dromara.common.idempotent.annotation.RepeatSubmit;
|
||||
import org.dromara.common.log.annotation.Log;
|
||||
import org.dromara.common.log.enums.BusinessType;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.common.web.core.BaseController;
|
||||
import org.dromara.property.domain.bo.SysCityAreaBo;
|
||||
import org.dromara.property.domain.vo.CityAreaTreeVo;
|
||||
import org.dromara.property.domain.vo.SysCityAreaVo;
|
||||
import org.dromara.property.service.ISysCityAreaService;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 行政区划
|
||||
@@ -34,9 +39,9 @@ import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/cityArea")
|
||||
public class TbCityAreaController extends BaseController {
|
||||
public class SysCityAreaController extends BaseController implements ApplicationRunner {
|
||||
|
||||
private final ITbCityAreaService tbCityAreaService;
|
||||
private final ISysCityAreaService SysCityAreaService;
|
||||
|
||||
/**
|
||||
* 查询行政区划
|
||||
@@ -44,8 +49,8 @@ public class TbCityAreaController extends BaseController {
|
||||
*/
|
||||
@SaCheckPermission("property:cityArea:list")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo<TbCityAreaVo> list(TbCityAreaBo bo, PageQuery pageQuery) {
|
||||
return tbCityAreaService.queryPageList(bo, pageQuery);
|
||||
public TableDataInfo<SysCityAreaVo> list(SysCityAreaBo bo, PageQuery pageQuery) {
|
||||
return SysCityAreaService.queryPageList(bo, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,22 +60,20 @@ public class TbCityAreaController extends BaseController {
|
||||
@SaCheckPermission("property:cityArea:export")
|
||||
@Log(title = "行政区划", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(TbCityAreaBo bo, HttpServletResponse response) {
|
||||
List<TbCityAreaVo> list = tbCityAreaService.queryList(bo);
|
||||
ExcelUtil.exportExcel(list, "行政区划", TbCityAreaVo.class, response);
|
||||
public void export(SysCityAreaBo bo, HttpServletResponse response) {
|
||||
List<SysCityAreaVo> list = SysCityAreaService.queryList(bo);
|
||||
ExcelUtil.exportExcel(list, "行政区划", SysCityAreaVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取行政区划
|
||||
详细信息
|
||||
*
|
||||
* 获取行政区划详细信息
|
||||
* @param areaCode 主键
|
||||
*/
|
||||
@SaCheckPermission("property:cityArea:query")
|
||||
@GetMapping("/{areaCode}")
|
||||
public R<TbCityAreaVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
public R<SysCityAreaVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable("areaCode") String areaCode) {
|
||||
return R.ok(tbCityAreaService.queryById(areaCode));
|
||||
return R.ok(SysCityAreaService.queryById(areaCode));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,8 +84,8 @@ public class TbCityAreaController extends BaseController {
|
||||
@Log(title = "行政区划", businessType = BusinessType.INSERT)
|
||||
@RepeatSubmit()
|
||||
@PostMapping()
|
||||
public R<Void> add(@Validated(AddGroup.class) @RequestBody TbCityAreaBo bo) {
|
||||
return toAjax(tbCityAreaService.insertByBo(bo));
|
||||
public R<Void> add(@Validated(AddGroup.class) @RequestBody SysCityAreaBo bo) {
|
||||
return toAjax(SysCityAreaService.insertByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,8 +96,8 @@ public class TbCityAreaController extends BaseController {
|
||||
@Log(title = "行政区划", businessType = BusinessType.UPDATE)
|
||||
@RepeatSubmit()
|
||||
@PutMapping()
|
||||
public R<Void> edit(@Validated(EditGroup.class) @RequestBody TbCityAreaBo bo) {
|
||||
return toAjax(tbCityAreaService.updateByBo(bo));
|
||||
public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysCityAreaBo bo) {
|
||||
return toAjax(SysCityAreaService.updateByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,6 +111,25 @@ public class TbCityAreaController extends BaseController {
|
||||
@DeleteMapping("/{areaCodes}")
|
||||
public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
||||
@PathVariable("areaCodes") String[] areaCodes) {
|
||||
return toAjax(tbCityAreaService.deleteWithValidByIds(List.of(areaCodes), true));
|
||||
return toAjax(SysCityAreaService.deleteWithValidByIds(List.of(areaCodes), true));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询行政区划树结构
|
||||
*
|
||||
* @return 返回行政区划树结构
|
||||
*/
|
||||
@GetMapping("/treeList")
|
||||
public R<List<CityAreaTreeVo>> queryTreeList() {
|
||||
List<CityAreaTreeVo> list = SysCityAreaService.queryTreeList();
|
||||
return R.ok(list);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
R<List<CityAreaTreeVo>> listR = queryTreeList();
|
||||
System.out.println(JSONObject.toJSONString(listR));
|
||||
}
|
||||
}
|
@@ -1,9 +1,8 @@
|
||||
package org.dromara.property.domain;
|
||||
|
||||
import org.dromara.common.tenant.core.TenantEntity;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
@@ -15,9 +14,8 @@ import java.io.Serial;
|
||||
* @date 2025-06-18
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("tb_city_area")
|
||||
public class TbCityArea extends TenantEntity {
|
||||
@TableName("sys_city_area")
|
||||
public class SysCityArea {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -68,10 +66,4 @@ public class TbCityArea extends TenantEntity {
|
||||
*/
|
||||
private Long dataState;
|
||||
|
||||
/**
|
||||
* 搜索值
|
||||
*/
|
||||
private String searchValue;
|
||||
|
||||
|
||||
}
|
@@ -1,13 +1,14 @@
|
||||
package org.dromara.property.domain.bo;
|
||||
|
||||
import org.dromara.property.domain.TbCityArea;
|
||||
import org.dromara.common.mybatis.core.domain.BaseEntity;
|
||||
import org.dromara.common.core.validate.AddGroup;
|
||||
import org.dromara.common.core.validate.EditGroup;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import jakarta.validation.constraints.*;
|
||||
import org.dromara.common.core.validate.AddGroup;
|
||||
import org.dromara.common.core.validate.EditGroup;
|
||||
import org.dromara.common.mybatis.core.domain.BaseEntity;
|
||||
import org.dromara.property.domain.SysCityArea;
|
||||
|
||||
/**
|
||||
* 行政区划
|
||||
@@ -18,8 +19,8 @@ import jakarta.validation.constraints.*;
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@AutoMapper(target = TbCityArea.class, reverseConvertGenerate = false)
|
||||
public class TbCityAreaBo extends BaseEntity {
|
||||
@AutoMapper(target = SysCityArea.class, reverseConvertGenerate = false)
|
||||
public class SysCityAreaBo extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 主键ID
|
@@ -0,0 +1,24 @@
|
||||
package org.dromara.property.domain.convert;
|
||||
|
||||
import org.dromara.property.domain.SysCityArea;
|
||||
import org.dromara.property.domain.vo.CityAreaTreeVo;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.MappingConstants;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 客户端数据转换器
|
||||
*
|
||||
* @author Michelle.Chung
|
||||
*/
|
||||
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface SysCityAreaCovert {
|
||||
|
||||
SysCityAreaCovert INSTANCE = Mappers.getMapper(SysCityAreaCovert.class);
|
||||
|
||||
List<CityAreaTreeVo> entity2Vo(List<SysCityArea> cityAreas);
|
||||
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
package org.dromara.property.domain.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import org.dromara.common.core.domain.TreeEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class CityAreaTreeVo implements TreeEntity<CityAreaTreeVo, String> {
|
||||
|
||||
/**
|
||||
* 城市编码
|
||||
*/
|
||||
private String areaCode;
|
||||
|
||||
/**
|
||||
* 城市名称
|
||||
*/
|
||||
private String areaName;
|
||||
|
||||
/**
|
||||
* 101 省级 202 市州 303 区县
|
||||
*/
|
||||
private String areaLevel;
|
||||
|
||||
/**
|
||||
* 父级城市编码
|
||||
*/
|
||||
private String parentAreaCode;
|
||||
|
||||
/**
|
||||
* 父级城市名称
|
||||
*/
|
||||
private String parentAreaName;
|
||||
|
||||
/**
|
||||
* 经度
|
||||
*/
|
||||
private String lon;
|
||||
|
||||
/**
|
||||
* 维度
|
||||
*/
|
||||
private String lat;
|
||||
|
||||
private List<CityAreaTreeVo> children;
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return getAreaCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParentId() {
|
||||
return getParentAreaCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChildren(List<CityAreaTreeVo> children) {
|
||||
this.children = children;
|
||||
}
|
||||
}
|
@@ -1,16 +1,15 @@
|
||||
package org.dromara.property.domain.vo;
|
||||
|
||||
import org.dromara.property.domain.TbCityArea;
|
||||
import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import org.dromara.common.excel.annotation.ExcelDictFormat;
|
||||
import org.dromara.common.excel.convert.ExcelDictConvert;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import lombok.Data;
|
||||
import org.dromara.common.excel.annotation.ExcelDictFormat;
|
||||
import org.dromara.common.excel.convert.ExcelDictConvert;
|
||||
import org.dromara.property.domain.SysCityArea;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
|
||||
@@ -23,8 +22,8 @@ import java.util.Date;
|
||||
*/
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
@AutoMapper(target = TbCityArea.class)
|
||||
public class TbCityAreaVo implements Serializable {
|
||||
@AutoMapper(target = SysCityArea.class)
|
||||
public class SysCityAreaVo implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
@@ -0,0 +1,16 @@
|
||||
package org.dromara.property.mapper;
|
||||
|
||||
import org.dromara.property.domain.SysCityArea;
|
||||
import org.dromara.property.domain.vo.SysCityAreaVo;
|
||||
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
|
||||
/**
|
||||
* 行政区划
|
||||
Mapper接口
|
||||
*
|
||||
* @author mocheng
|
||||
* @date 2025-06-18
|
||||
*/
|
||||
public interface SysCityAreaMapper extends BaseMapperPlus<SysCityArea, SysCityAreaVo> {
|
||||
|
||||
}
|
@@ -1,16 +0,0 @@
|
||||
package org.dromara.property.mapper;
|
||||
|
||||
import org.dromara.property.domain.TbCityArea;
|
||||
import org.dromara.property.domain.vo.TbCityAreaVo;
|
||||
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
|
||||
/**
|
||||
* 行政区划
|
||||
Mapper接口
|
||||
*
|
||||
* @author mocheng
|
||||
* @date 2025-06-18
|
||||
*/
|
||||
public interface TbCityAreaMapper extends BaseMapperPlus<TbCityArea, TbCityAreaVo> {
|
||||
|
||||
}
|
@@ -1,10 +1,10 @@
|
||||
package org.dromara.property.service;
|
||||
|
||||
import org.dromara.property.domain.TbCityArea;
|
||||
import org.dromara.property.domain.vo.TbCityAreaVo;
|
||||
import org.dromara.property.domain.bo.TbCityAreaBo;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.property.domain.bo.SysCityAreaBo;
|
||||
import org.dromara.property.domain.vo.CityAreaTreeVo;
|
||||
import org.dromara.property.domain.vo.SysCityAreaVo;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -16,7 +16,7 @@ Service接口
|
||||
* @author mocheng
|
||||
* @date 2025-06-18
|
||||
*/
|
||||
public interface ITbCityAreaService {
|
||||
public interface ISysCityAreaService {
|
||||
|
||||
/**
|
||||
* 查询行政区划
|
||||
@@ -26,7 +26,7 @@ public interface ITbCityAreaService {
|
||||
* @return 行政区划
|
||||
|
||||
*/
|
||||
TbCityAreaVo queryById(String areaCode);
|
||||
SysCityAreaVo queryById(String areaCode);
|
||||
|
||||
/**
|
||||
* 分页查询行政区划
|
||||
@@ -37,7 +37,7 @@ public interface ITbCityAreaService {
|
||||
* @return 行政区划
|
||||
分页列表
|
||||
*/
|
||||
TableDataInfo<TbCityAreaVo> queryPageList(TbCityAreaBo bo, PageQuery pageQuery);
|
||||
TableDataInfo<SysCityAreaVo> queryPageList(SysCityAreaBo bo, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查询符合条件的行政区划
|
||||
@@ -47,7 +47,7 @@ public interface ITbCityAreaService {
|
||||
* @return 行政区划
|
||||
列表
|
||||
*/
|
||||
List<TbCityAreaVo> queryList(TbCityAreaBo bo);
|
||||
List<SysCityAreaVo> queryList(SysCityAreaBo bo);
|
||||
|
||||
/**
|
||||
* 新增行政区划
|
||||
@@ -57,7 +57,7 @@ public interface ITbCityAreaService {
|
||||
|
||||
* @return 是否新增成功
|
||||
*/
|
||||
Boolean insertByBo(TbCityAreaBo bo);
|
||||
Boolean insertByBo(SysCityAreaBo bo);
|
||||
|
||||
/**
|
||||
* 修改行政区划
|
||||
@@ -67,7 +67,7 @@ public interface ITbCityAreaService {
|
||||
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
Boolean updateByBo(TbCityAreaBo bo);
|
||||
Boolean updateByBo(SysCityAreaBo bo);
|
||||
|
||||
/**
|
||||
* 校验并批量删除行政区划
|
||||
@@ -78,4 +78,11 @@ public interface ITbCityAreaService {
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<String> ids, Boolean isValid);
|
||||
|
||||
/**
|
||||
* 生成行政区划树结构
|
||||
*
|
||||
* @return 返回行政区划树结构
|
||||
*/
|
||||
List<CityAreaTreeVo> queryTreeList();
|
||||
}
|
@@ -0,0 +1,161 @@
|
||||
package org.dromara.property.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.core.utils.TreeUtils;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.property.domain.SysCityArea;
|
||||
import org.dromara.property.domain.bo.SysCityAreaBo;
|
||||
import org.dromara.property.domain.convert.SysCityAreaCovert;
|
||||
import org.dromara.property.domain.vo.CityAreaTreeVo;
|
||||
import org.dromara.property.domain.vo.SysCityAreaVo;
|
||||
import org.dromara.property.mapper.SysCityAreaMapper;
|
||||
import org.dromara.property.service.ISysCityAreaService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 行政区划
|
||||
* Service业务层处理
|
||||
*
|
||||
* @author mocheng
|
||||
* @date 2025-06-18
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class SysCityAreaServiceImpl implements ISysCityAreaService {
|
||||
|
||||
private final SysCityAreaMapper baseMapper;
|
||||
|
||||
/**
|
||||
* 查询行政区划
|
||||
*
|
||||
* @param areaCode 主键
|
||||
* @return 行政区划
|
||||
*/
|
||||
@Override
|
||||
public SysCityAreaVo queryById(String areaCode) {
|
||||
return baseMapper.selectVoById(areaCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询行政区划
|
||||
* 列表
|
||||
*
|
||||
* @param bo 查询条件
|
||||
* @param pageQuery 分页参数
|
||||
* @return 行政区划
|
||||
* 分页列表
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<SysCityAreaVo> queryPageList(SysCityAreaBo bo, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<SysCityArea> lqw = buildQueryWrapper(bo);
|
||||
Page<SysCityAreaVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询符合条件的行政区划
|
||||
* 列表
|
||||
*
|
||||
* @param bo 查询条件
|
||||
* @return 行政区划
|
||||
* 列表
|
||||
*/
|
||||
@Override
|
||||
public List<SysCityAreaVo> queryList(SysCityAreaBo bo) {
|
||||
LambdaQueryWrapper<SysCityArea> lqw = buildQueryWrapper(bo);
|
||||
return baseMapper.selectVoList(lqw);
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<SysCityArea> buildQueryWrapper(SysCityAreaBo bo) {
|
||||
Map<String, Object> params = bo.getParams();
|
||||
LambdaQueryWrapper<SysCityArea> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getAreaCode()), SysCityArea::getAreaCode, bo.getAreaCode());
|
||||
lqw.orderByAsc(SysCityArea::getAreaCode);
|
||||
lqw.like(StringUtils.isNotBlank(bo.getAreaName()), SysCityArea::getAreaName, bo.getAreaName());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getAreaLevel()), SysCityArea::getAreaLevel, bo.getAreaLevel());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getParentAreaCode()), SysCityArea::getParentAreaCode, bo.getParentAreaCode());
|
||||
lqw.like(StringUtils.isNotBlank(bo.getParentAreaName()), SysCityArea::getParentAreaName, bo.getParentAreaName());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getLon()), SysCityArea::getLon, bo.getLon());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getLat()), SysCityArea::getLat, bo.getLat());
|
||||
lqw.eq(bo.getDataState() != null, SysCityArea::getDataState, bo.getDataState());
|
||||
return lqw;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增行政区划
|
||||
*
|
||||
* @param bo 行政区划
|
||||
* @return 是否新增成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean insertByBo(SysCityAreaBo bo) {
|
||||
SysCityArea add = MapstructUtils.convert(bo, SysCityArea.class);
|
||||
validEntityBeforeSave(add);
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
if (flag) {
|
||||
bo.setAreaCode(add.getAreaCode());
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改行政区划
|
||||
*
|
||||
* @param bo 行政区划
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateByBo(SysCityAreaBo bo) {
|
||||
SysCityArea update = MapstructUtils.convert(bo, SysCityArea.class);
|
||||
validEntityBeforeSave(update);
|
||||
return baseMapper.updateById(update) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(SysCityArea entity) {
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验并批量删除行政区划
|
||||
* 信息
|
||||
*
|
||||
* @param ids 待删除的主键集合
|
||||
* @param isValid 是否进行有效性校验
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<String> ids, Boolean isValid) {
|
||||
if (isValid) {
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
return baseMapper.deleteByIds(ids) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CityAreaTreeVo> queryTreeList() {
|
||||
// 查询所有的行政区划数据
|
||||
List<SysCityArea> cityAreas = baseMapper.selectList(null);
|
||||
if (CollectionUtil.isEmpty(cityAreas)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<CityAreaTreeVo> vo = SysCityAreaCovert.INSTANCE.entity2Vo(cityAreas);
|
||||
return TreeUtils.getTreeList(vo, "0");
|
||||
}
|
||||
}
|
@@ -1,151 +0,0 @@
|
||||
package org.dromara.property.service.impl;
|
||||
|
||||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.dromara.property.domain.bo.TbCityAreaBo;
|
||||
import org.dromara.property.domain.vo.TbCityAreaVo;
|
||||
import org.dromara.property.domain.TbCityArea;
|
||||
import org.dromara.property.mapper.TbCityAreaMapper;
|
||||
import org.dromara.property.service.ITbCityAreaService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 行政区划
|
||||
Service业务层处理
|
||||
*
|
||||
* @author mocheng
|
||||
* @date 2025-06-18
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class TbCityAreaServiceImpl implements ITbCityAreaService {
|
||||
|
||||
private final TbCityAreaMapper baseMapper;
|
||||
|
||||
/**
|
||||
* 查询行政区划
|
||||
|
||||
*
|
||||
* @param areaCode 主键
|
||||
* @return 行政区划
|
||||
|
||||
*/
|
||||
@Override
|
||||
public TbCityAreaVo queryById(String areaCode){
|
||||
return baseMapper.selectVoById(areaCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询行政区划
|
||||
列表
|
||||
*
|
||||
* @param bo 查询条件
|
||||
* @param pageQuery 分页参数
|
||||
* @return 行政区划
|
||||
分页列表
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<TbCityAreaVo> queryPageList(TbCityAreaBo bo, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<TbCityArea> lqw = buildQueryWrapper(bo);
|
||||
Page<TbCityAreaVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询符合条件的行政区划
|
||||
列表
|
||||
*
|
||||
* @param bo 查询条件
|
||||
* @return 行政区划
|
||||
列表
|
||||
*/
|
||||
@Override
|
||||
public List<TbCityAreaVo> queryList(TbCityAreaBo bo) {
|
||||
LambdaQueryWrapper<TbCityArea> lqw = buildQueryWrapper(bo);
|
||||
return baseMapper.selectVoList(lqw);
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<TbCityArea> buildQueryWrapper(TbCityAreaBo bo) {
|
||||
Map<String, Object> params = bo.getParams();
|
||||
LambdaQueryWrapper<TbCityArea> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getAreaCode()), TbCityArea::getAreaCode, bo.getAreaCode());
|
||||
lqw.orderByAsc(TbCityArea::getAreaCode);
|
||||
lqw.like(StringUtils.isNotBlank(bo.getAreaName()), TbCityArea::getAreaName, bo.getAreaName());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getAreaLevel()), TbCityArea::getAreaLevel, bo.getAreaLevel());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getParentAreaCode()), TbCityArea::getParentAreaCode, bo.getParentAreaCode());
|
||||
lqw.like(StringUtils.isNotBlank(bo.getParentAreaName()), TbCityArea::getParentAreaName, bo.getParentAreaName());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getLon()), TbCityArea::getLon, bo.getLon());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getLat()), TbCityArea::getLat, bo.getLat());
|
||||
lqw.eq(bo.getDataState() != null, TbCityArea::getDataState, bo.getDataState());
|
||||
return lqw;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增行政区划
|
||||
|
||||
*
|
||||
* @param bo 行政区划
|
||||
|
||||
* @return 是否新增成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean insertByBo(TbCityAreaBo bo) {
|
||||
TbCityArea add = MapstructUtils.convert(bo, TbCityArea.class);
|
||||
validEntityBeforeSave(add);
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
if (flag) {
|
||||
bo.setAreaCode(add.getAreaCode());
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改行政区划
|
||||
|
||||
*
|
||||
* @param bo 行政区划
|
||||
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateByBo(TbCityAreaBo bo) {
|
||||
TbCityArea update = MapstructUtils.convert(bo, TbCityArea.class);
|
||||
validEntityBeforeSave(update);
|
||||
return baseMapper.updateById(update) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(TbCityArea entity){
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验并批量删除行政区划
|
||||
信息
|
||||
*
|
||||
* @param ids 待删除的主键集合
|
||||
* @param isValid 是否进行有效性校验
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<String> ids, Boolean isValid) {
|
||||
if(isValid){
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
return baseMapper.deleteByIds(ids) > 0;
|
||||
}
|
||||
}
|
@@ -2,6 +2,6 @@
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.dromara.property.mapper.TbCityAreaMapper">
|
||||
<mapper namespace="org.dromara.property.mapper.SysCityAreaMapper">
|
||||
|
||||
</mapper>
|
Reference in New Issue
Block a user