Browse Source

新增行政区划模块

test
smallchill 5 years ago
parent
commit
71383171ba
  1. 63
      blade-service-api/blade-system-api/src/main/java/org/springblade/system/cache/RegionCache.java
  2. 128
      blade-service-api/blade-system-api/src/main/java/org/springblade/system/entity/Region.java
  3. 10
      blade-service-api/blade-system-api/src/main/java/org/springblade/system/feign/ISysClient.java
  4. 7
      blade-service-api/blade-system-api/src/main/java/org/springblade/system/feign/ISysClientFallback.java
  5. 89
      blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/RegionVO.java
  6. 4
      blade-service/blade-system/pom.xml
  7. 200
      blade-service/blade-system/src/main/java/org/springblade/system/controller/RegionController.java
  8. 90
      blade-service/blade-system/src/main/java/org/springblade/system/excel/RegionExcel.java
  9. 40
      blade-service/blade-system/src/main/java/org/springblade/system/excel/RegionImporter.java
  10. 9
      blade-service/blade-system/src/main/java/org/springblade/system/feign/SysClient.java
  11. 62
      blade-service/blade-system/src/main/java/org/springblade/system/mapper/RegionMapper.java
  12. 104
      blade-service/blade-system/src/main/java/org/springblade/system/mapper/RegionMapper.xml
  13. 86
      blade-service/blade-system/src/main/java/org/springblade/system/service/IRegionService.java
  14. 120
      blade-service/blade-system/src/main/java/org/springblade/system/service/impl/RegionServiceImpl.java
  15. 52
      blade-service/blade-system/src/main/java/org/springblade/system/wrapper/RegionWrapper.java
  16. 2
      blade-service/blade-user/src/main/java/org/springblade/system/user/excel/UserExcel.java
  17. 3
      blade-service/blade-user/src/main/java/org/springblade/system/user/service/IUserService.java
  18. 2
      pom.xml

63
blade-service-api/blade-system-api/src/main/java/org/springblade/system/cache/RegionCache.java vendored

@ -0,0 +1,63 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.system.cache;
import org.springblade.core.cache.utils.CacheUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.system.entity.Region;
import org.springblade.system.feign.ISysClient;
import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE;
/**
* 行政区划缓存工具类
*
* @author Chill
*/
public class RegionCache {
public static final int PROVINCE_LEVEL = 1;
public static final int CITY_LEVEL = 2;
public static final int DISTRICT_LEVEL = 3;
public static final int TOWN_LEVEL = 4;
public static final int VILLAGE_LEVEL = 5;
private static final String REGION_CODE = "region:code:";
private static ISysClient sysClient;
private static ISysClient getSysClient() {
if (sysClient == null) {
sysClient = SpringUtil.getBean(ISysClient.class);
}
return sysClient;
}
/**
* 获取行政区划实体
*
* @param code 区划编号
* @return Param
*/
public static Region getByCode(String code) {
return CacheUtil.get(SYS_CACHE, REGION_CODE, code, () -> {
R<Region> result = getSysClient().getRegion(code);
return result.getData();
});
}
}

128
blade-service-api/blade-system-api/src/main/java/org/springblade/system/entity/Region.java

@ -0,0 +1,128 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.system.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 行政区划表实体类
*
* @author Chill
*/
@Data
@TableName("blade_region")
@ApiModel(value = "Region对象", description = "行政区划表")
public class Region implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 区划编号
*/
@TableId(value = "code", type = IdType.INPUT)
@ApiModelProperty(value = "区划编号")
private String code;
/**
* 父区划编号
*/
@ApiModelProperty(value = "父区划编号")
private String parentCode;
/**
* 祖区划编号
*/
@ApiModelProperty(value = "祖区划编号")
private String ancestors;
/**
* 区划名称
*/
@ApiModelProperty(value = "区划名称")
private String name;
/**
* 省级区划编号
*/
@ApiModelProperty(value = "省级区划编号")
private String provinceCode;
/**
* 省级名称
*/
@ApiModelProperty(value = "省级名称")
private String provinceName;
/**
* 市级区划编号
*/
@ApiModelProperty(value = "市级区划编号")
private String cityCode;
/**
* 市级名称
*/
@ApiModelProperty(value = "市级名称")
private String cityName;
/**
* 区级区划编号
*/
@ApiModelProperty(value = "区级区划编号")
private String districtCode;
/**
* 区级名称
*/
@ApiModelProperty(value = "区级名称")
private String districtName;
/**
* 镇级区划编号
*/
@ApiModelProperty(value = "镇级区划编号")
private String townCode;
/**
* 镇级名称
*/
@ApiModelProperty(value = "镇级名称")
private String townName;
/**
* 村级区划编号
*/
@ApiModelProperty(value = "村级区划编号")
private String villageCode;
/**
* 村级名称
*/
@ApiModelProperty(value = "村级名称")
private String villageName;
/**
* 层级
*/
@ApiModelProperty(value = "层级")
private Integer level;
/**
* 排序
*/
@ApiModelProperty(value = "排序")
private Integer sort;
/**
* 备注
*/
@ApiModelProperty(value = "备注")
private String remark;
}

10
blade-service-api/blade-system-api/src/main/java/org/springblade/system/feign/ISysClient.java

@ -57,6 +57,7 @@ public interface ISysClient {
String TENANT_ID = API_PREFIX + "/tenant-id";
String PARAM = API_PREFIX + "/param";
String PARAM_VALUE = API_PREFIX + "/param-value";
String REGION = API_PREFIX + "/region";
/**
* 获取菜单
@ -241,4 +242,13 @@ public interface ISysClient {
@GetMapping(PARAM_VALUE)
R<String> getParamValue(@RequestParam("paramKey") String paramKey);
/**
* 获取行政区划
*
* @param code 主键
* @return Region
*/
@GetMapping(REGION)
R<Region> getRegion(@RequestParam("code") String code);
}

7
blade-service-api/blade-system-api/src/main/java/org/springblade/system/feign/ISysClientFallback.java

@ -129,4 +129,11 @@ public class ISysClientFallback implements ISysClient {
public R<String> getParamValue(String paramKey) {
return R.fail("获取数据失败");
}
@Override
public R<Region> getRegion(String code) {
return R.fail("获取数据失败");
}
}

89
blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/RegionVO.java

@ -0,0 +1,89 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.system.vo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.core.tool.node.INode;
import org.springblade.core.tool.utils.Func;
import org.springblade.system.entity.Region;
import java.util.ArrayList;
import java.util.List;
/**
* 行政区划表视图实体类
*
* @author Chill
*/
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "RegionVO对象", description = "行政区划表")
public class RegionVO extends Region implements INode<RegionVO> {
private static final long serialVersionUID = 1L;
/**
* 主键ID
*/
@JsonSerialize(using = ToStringSerializer.class)
private Long id;
/**
* 父节点ID
*/
@JsonSerialize(using = ToStringSerializer.class)
private Long parentId;
/**
* 父节点名称
*/
private String parentName;
/**
* 是否有子孙节点
*/
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private Boolean hasChildren;
/**
* 子孙节点
*/
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<RegionVO> children;
@Override
public Long getId() {
return Func.toLong(this.getCode());
}
@Override
public Long getParentId() {
return Func.toLong(this.getParentCode());
}
@Override
public List<RegionVO> getChildren() {
if (this.children == null) {
this.children = new ArrayList<>();
}
return this.children;
}
}

4
blade-service/blade-system/pom.xml

@ -19,6 +19,10 @@
<groupId>org.springblade</groupId>
<artifactId>blade-core-boot</artifactId>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-starter-excel</artifactId>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-starter-swagger</artifactId>

200
blade-service/blade-system/src/main/java/org/springblade/system/controller/RegionController.java

@ -0,0 +1,200 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.system.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.excel.util.ExcelUtil;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.system.entity.Region;
import org.springblade.system.excel.RegionExcel;
import org.springblade.system.excel.RegionImporter;
import org.springblade.system.service.IRegionService;
import org.springblade.system.vo.RegionVO;
import org.springblade.system.wrapper.RegionWrapper;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 行政区划表 控制器
*
* @author Chill
*/
@RestController
@AllArgsConstructor
@RequestMapping("/region")
@Api(value = "行政区划表", tags = "行政区划表接口")
public class RegionController extends BladeController {
private final IRegionService regionService;
/**
* 详情
*/
@GetMapping("/detail")
@ApiOperationSupport(order = 1)
@ApiOperation(value = "详情", notes = "传入region")
public R<RegionVO> detail(Region region) {
Region detail = regionService.getOne(Condition.getQueryWrapper(region));
return R.data(RegionWrapper.build().entityVO(detail));
}
/**
* 分页 行政区划表
*/
@GetMapping("/list")
@ApiOperationSupport(order = 2)
@ApiOperation(value = "分页", notes = "传入region")
public R<IPage<Region>> list(Region region, Query query) {
IPage<Region> pages = regionService.page(Condition.getPage(query), Condition.getQueryWrapper(region));
return R.data(pages);
}
/**
* 懒加载列表
*/
@GetMapping("/lazy-list")
@ApiImplicitParams({
@ApiImplicitParam(name = "code", value = "区划编号", paramType = "query", dataType = "string"),
@ApiImplicitParam(name = "name", value = "区划名称", paramType = "query", dataType = "string")
})
@ApiOperationSupport(order = 3)
@ApiOperation(value = "懒加载列表", notes = "传入menu")
public R<List<RegionVO>> lazyList(String parentCode, @ApiIgnore @RequestParam Map<String, Object> menu) {
List<RegionVO> list = regionService.lazyList(parentCode, menu);
return R.data(RegionWrapper.build().listNodeLazyVO(list));
}
/**
* 懒加载列表
*/
@GetMapping("/lazy-tree")
@ApiImplicitParams({
@ApiImplicitParam(name = "code", value = "区划编号", paramType = "query", dataType = "string"),
@ApiImplicitParam(name = "name", value = "区划名称", paramType = "query", dataType = "string")
})
@ApiOperationSupport(order = 4)
@ApiOperation(value = "懒加载列表", notes = "传入menu")
public R<List<RegionVO>> lazyTree(String parentCode, @ApiIgnore @RequestParam Map<String, Object> menu) {
List<RegionVO> list = regionService.lazyTree(parentCode, menu);
return R.data(RegionWrapper.build().listNodeLazyVO(list));
}
/**
* 新增 行政区划表
*/
@PostMapping("/save")
@ApiOperationSupport(order = 5)
@ApiOperation(value = "新增", notes = "传入region")
public R save(@Valid @RequestBody Region region) {
return R.status(regionService.save(region));
}
/**
* 修改 行政区划表
*/
@PostMapping("/update")
@ApiOperationSupport(order = 6)
@ApiOperation(value = "修改", notes = "传入region")
public R update(@Valid @RequestBody Region region) {
return R.status(regionService.updateById(region));
}
/**
* 新增或修改 行政区划表
*/
@PostMapping("/submit")
@ApiOperationSupport(order = 7)
@ApiOperation(value = "新增或修改", notes = "传入region")
public R submit(@Valid @RequestBody Region region) {
return R.status(regionService.submit(region));
}
/**
* 删除 行政区划表
*/
@PostMapping("/remove")
@ApiOperationSupport(order = 8)
@ApiOperation(value = "删除", notes = "传入主键")
public R remove(@ApiParam(value = "主键", required = true) @RequestParam String id) {
return R.status(regionService.removeRegion(id));
}
/**
* 行政区划下拉数据源
*/
@GetMapping("/select")
@ApiOperationSupport(order = 9)
@ApiOperation(value = "下拉数据源", notes = "传入tenant")
public R<List<Region>> select(@RequestParam(required = false, defaultValue = "00") String code) {
List<Region> list = regionService.list(Wrappers.<Region>query().lambda().eq(Region::getParentCode, code));
return R.data(list);
}
/**
* 导入行政区划数据
*/
@PostMapping("import-region")
@ApiOperationSupport(order = 10)
@ApiOperation(value = "导入行政区划", notes = "传入excel")
public R importRegion(MultipartFile file, Integer isCovered) {
RegionImporter regionImporter = new RegionImporter(regionService, isCovered == 1);
ExcelUtil.save(file, regionImporter, RegionExcel.class);
return R.success("操作成功");
}
/**
* 导出行政区划数据
*/
@GetMapping("export-region")
@ApiOperationSupport(order = 11)
@ApiOperation(value = "导出行政区划", notes = "传入user")
public void exportRegion(@ApiIgnore @RequestParam Map<String, Object> region, HttpServletResponse response) {
QueryWrapper<Region> queryWrapper = Condition.getQueryWrapper(region, Region.class);
List<RegionExcel> list = regionService.exportRegion(queryWrapper);
ExcelUtil.export(response, "行政区划数据" + DateUtil.time(), "行政区划数据表", list, RegionExcel.class);
}
/**
* 导出模板
*/
@GetMapping("export-template")
@ApiOperationSupport(order = 12)
@ApiOperation(value = "导出模板")
public void exportUser(HttpServletResponse response) {
List<RegionExcel> list = new ArrayList<>();
ExcelUtil.export(response, "行政区划模板", "行政区划表", list, RegionExcel.class);
}
}

90
blade-service/blade-system/src/main/java/org/springblade/system/excel/RegionExcel.java

@ -0,0 +1,90 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.system.excel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import lombok.Data;
import java.io.Serializable;
/**
* RegionExcel
*
* @author Chill
*/
@Data
@ColumnWidth(16)
@HeadRowHeight(20)
@ContentRowHeight(18)
public class RegionExcel implements Serializable {
private static final long serialVersionUID = 1L;
@ExcelProperty("区划编号")
private String code;
@ExcelProperty("父区划编号")
private String parentCode;
@ExcelProperty("祖区划编号")
private String ancestors;
@ExcelProperty("区划名称")
private String name;
@ExcelProperty("省级区划编号")
private String provinceCode;
@ExcelProperty("省级名称")
private String provinceName;
@ExcelProperty("市级区划编号")
private String cityCode;
@ExcelProperty("市级名称")
private String cityName;
@ExcelProperty("区级区划编号")
private String districtCode;
@ExcelProperty("区级名称")
private String districtName;
@ExcelProperty("镇级区划编号")
private String townCode;
@ExcelProperty("镇级名称")
private String townName;
@ExcelProperty("村级区划编号")
private String villageCode;
@ExcelProperty("村级名称")
private String villageName;
@ExcelProperty("层级")
private Integer level;
@ExcelProperty("排序")
private Integer sort;
@ExcelProperty("备注")
private String remark;
}

40
blade-service/blade-system/src/main/java/org/springblade/system/excel/RegionImporter.java

@ -0,0 +1,40 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.system.excel;
import lombok.RequiredArgsConstructor;
import org.springblade.core.excel.support.ExcelImporter;
import org.springblade.system.service.IRegionService;
import java.util.List;
/**
* 行政区划数据导入类
*
* @author Chill
*/
@RequiredArgsConstructor
public class RegionImporter implements ExcelImporter<RegionExcel> {
private final IRegionService service;
private final Boolean isCovered;
@Override
public void save(List<RegionExcel> data) {
service.importRegion(data, isCovered);
}
}

9
blade-service/blade-system/src/main/java/org/springblade/system/feign/SysClient.java

@ -48,6 +48,8 @@ public class SysClient implements ISysClient {
private final IParamService paramService;
private final IRegionService regionService;
@Override
@GetMapping(MENU)
public R<Menu> getMenu(Long id) {
@ -162,4 +164,11 @@ public class SysClient implements ISysClient {
return R.data(paramService.getValue(paramKey));
}
@Override
@GetMapping(REGION)
public R<Region> getRegion(String code) {
return R.data(regionService.getById(code));
}
}

62
blade-service/blade-system/src/main/java/org/springblade/system/mapper/RegionMapper.java

@ -0,0 +1,62 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.system.mapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.springblade.system.entity.Region;
import org.springblade.system.excel.RegionExcel;
import org.springblade.system.vo.RegionVO;
import java.util.List;
import java.util.Map;
/**
* 行政区划表 Mapper 接口
*
* @author Chill
*/
public interface RegionMapper extends BaseMapper<Region> {
/**
* 懒加载列表
*
* @param parentCode
* @param param
* @return
*/
List<RegionVO> lazyList(String parentCode, Map<String, Object> param);
/**
* 懒加载列表
*
* @param parentCode
* @param param
* @return
*/
List<RegionVO> lazyTree(String parentCode, Map<String, Object> param);
/**
* 导出区划数据
*
* @param queryWrapper
* @return
*/
List<RegionExcel> exportRegion(@Param("ew") Wrapper<Region> queryWrapper);
}

104
blade-service/blade-system/src/main/java/org/springblade/system/mapper/RegionMapper.xml

@ -0,0 +1,104 @@
<?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="org.springblade.system.mapper.RegionMapper">
<!-- 通用查询映射结果 -->
<resultMap id="regionResultMap" type="org.springblade.system.entity.Region">
<id column="code" property="code"/>
<result column="parent_code" property="parentCode"/>
<result column="ancestors" property="ancestors"/>
<result column="name" property="name"/>
<result column="province_code" property="provinceCode"/>
<result column="province_name" property="provinceName"/>
<result column="city_code" property="cityCode"/>
<result column="city_name" property="cityName"/>
<result column="district_code" property="districtCode"/>
<result column="district_name" property="districtName"/>
<result column="town_code" property="townCode"/>
<result column="town_name" property="townName"/>
<result column="village_code" property="villageCode"/>
<result column="village_name" property="villageName"/>
<result column="level" property="level"/>
<result column="sort" property="sort"/>
<result column="remark" property="remark"/>
</resultMap>
<resultMap id="regionVOResultMap" type="org.springblade.system.vo.RegionVO">
<id column="code" property="code"/>
<result column="parent_code" property="parentCode"/>
<result column="ancestors" property="ancestors"/>
<result column="name" property="name"/>
<result column="province_code" property="provinceCode"/>
<result column="province_name" property="provinceName"/>
<result column="city_code" property="cityCode"/>
<result column="city_name" property="cityName"/>
<result column="district_code" property="districtCode"/>
<result column="district_name" property="districtName"/>
<result column="town_code" property="townCode"/>
<result column="town_name" property="townName"/>
<result column="village_code" property="villageCode"/>
<result column="village_name" property="villageName"/>
<result column="level" property="level"/>
<result column="sort" property="sort"/>
<result column="remark" property="remark"/>
<result column="id" property="id"/>
<result column="parent_id" property="parentId"/>
<result column="has_children" property="hasChildren"/>
</resultMap>
<resultMap id="treeNodeResultMap" type="org.springblade.core.tool.node.TreeNode">
<id column="id" property="id"/>
<result column="parent_id" property="parentId"/>
<result column="title" property="title"/>
<result column="value" property="value"/>
<result column="key" property="key"/>
<result column="has_children" property="hasChildren"/>
</resultMap>
<select id="lazyList" resultMap="regionVOResultMap">
SELECT
region.*,
( SELECT CASE WHEN count( 1 ) > 0 THEN 1 ELSE 0 END FROM blade_region WHERE parent_code = region.code ) AS "has_children"
FROM
blade_region region
<where>
<if test="param1!=null">
and region.parent_code = #{param1}
</if>
<if test="param2.code!=null and param2.code!=''">
and region.code like concat(concat('%', #{param2.code}),'%')
</if>
<if test="param2.name!=null and param2.name!=''">
and region.name like concat(concat('%', #{param2.name}),'%')
</if>
</where>
</select>
<select id="lazyTree" resultMap="treeNodeResultMap">
SELECT
region.code AS "id",
region.parent_code AS "parent_id",
region.name AS "title",
region.code AS "value",
region.code AS "key",
( SELECT CASE WHEN count( 1 ) > 0 THEN 1 ELSE 0 END FROM blade_region WHERE parent_code = region.code ) AS "has_children"
FROM
blade_region region
<where>
<if test="param1!=null">
and region.parent_code = #{param1}
</if>
<if test="param2.code!=null and param2.code!=''">
and region.code like concat(concat('%', #{param2.code}),'%')
</if>
<if test="param2.name!=null and param2.name!=''">
and region.name like concat(concat('%', #{param2.name}),'%')
</if>
</where>
</select>
<select id="exportRegion" resultType="org.springblade.system.excel.RegionExcel">
SELECT * FROM blade_region ${ew.customSqlSegment}
</select>
</mapper>

86
blade-service/blade-system/src/main/java/org/springblade/system/service/IRegionService.java

@ -0,0 +1,86 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.system.service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springblade.system.entity.Region;
import org.springblade.system.excel.RegionExcel;
import org.springblade.system.vo.RegionVO;
import java.util.List;
import java.util.Map;
/**
* 行政区划表 服务类
*
* @author Chill
*/
public interface IRegionService extends IService<Region> {
/**
* 提交
*
* @param region
* @return
*/
boolean submit(Region region);
/**
* 删除
*
* @param id
* @return
*/
boolean removeRegion(String id);
/**
* 懒加载列表
*
* @param parentCode
* @param param
* @return
*/
List<RegionVO> lazyList(String parentCode, Map<String, Object> param);
/**
* 懒加载列表
*
* @param parentCode
* @param param
* @return
*/
List<RegionVO> lazyTree(String parentCode, Map<String, Object> param);
/**
* 导入区划数据
*
* @param data
* @param isCovered
* @return
*/
void importRegion(List<RegionExcel> data, Boolean isCovered);
/**
* 导出区划数据
*
* @param queryWrapper
* @return
*/
List<RegionExcel> exportRegion(Wrapper<Region> queryWrapper);
}

120
blade-service/blade-system/src/main/java/org/springblade/system/service/impl/RegionServiceImpl.java

@ -0,0 +1,120 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.system.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringPool;
import org.springblade.system.entity.Region;
import org.springblade.system.excel.RegionExcel;
import org.springblade.system.mapper.RegionMapper;
import org.springblade.system.service.IRegionService;
import org.springblade.system.vo.RegionVO;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static org.springblade.system.cache.RegionCache.*;
/**
* 行政区划表 服务实现类
*
* @author Chill
*/
@Service
public class RegionServiceImpl extends ServiceImpl<RegionMapper, Region> implements IRegionService {
@Override
public boolean submit(Region region) {
Integer cnt = baseMapper.selectCount(Wrappers.<Region>query().lambda().eq(Region::getCode, region.getCode()));
if (cnt > 0) {
return this.updateById(region);
}
// 设置祖区划编号
Region parent = getByCode(region.getParentCode());
if (Func.isNotEmpty(parent) || Func.isNotEmpty(parent.getCode())) {
String ancestors = parent.getAncestors() + StringPool.COMMA + parent.getCode();
region.setAncestors(ancestors);
}
// 设置省、市、区、镇、村
Integer level = region.getLevel();
String code = region.getCode();
String name = region.getName();
if (level == PROVINCE_LEVEL) {
region.setProvinceCode(code);
region.setProvinceName(name);
} else if (level == CITY_LEVEL) {
region.setCityCode(code);
region.setCityName(name);
} else if (level == DISTRICT_LEVEL) {
region.setDistrictCode(code);
region.setDistrictName(name);
} else if (level == TOWN_LEVEL) {
region.setTownCode(code);
region.setTownName(name);
} else if (level == VILLAGE_LEVEL) {
region.setVillageCode(code);
region.setVillageName(name);
}
return this.save(region);
}
@Override
public boolean removeRegion(String id) {
Integer cnt = baseMapper.selectCount(Wrappers.<Region>query().lambda().eq(Region::getParentCode, id));
if (cnt > 0) {
throw new ServiceException("请先删除子节点!");
}
return removeById(id);
}
@Override
public List<RegionVO> lazyList(String parentCode, Map<String, Object> param) {
return baseMapper.lazyList(parentCode, param);
}
@Override
public List<RegionVO> lazyTree(String parentCode, Map<String, Object> param) {
return baseMapper.lazyTree(parentCode, param);
}
@Override
public void importRegion(List<RegionExcel> data, Boolean isCovered) {
List<Region> list = new ArrayList<>();
data.forEach(regionExcel -> {
Region region = BeanUtil.copy(regionExcel, Region.class);
list.add(region);
});
if (isCovered) {
this.saveOrUpdateBatch(list);
} else {
this.saveBatch(list);
}
}
@Override
public List<RegionExcel> exportRegion(Wrapper<Region> queryWrapper) {
return baseMapper.exportRegion(queryWrapper);
}
}

52
blade-service/blade-system/src/main/java/org/springblade/system/wrapper/RegionWrapper.java

@ -0,0 +1,52 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.system.wrapper;
import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.node.ForestNodeMerger;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.system.cache.RegionCache;
import org.springblade.system.entity.Region;
import org.springblade.system.vo.RegionVO;
import java.util.List;
import java.util.Objects;
/**
* 包装类,返回视图层所需的字段
*
* @author Chill
*/
public class RegionWrapper extends BaseEntityWrapper<Region, RegionVO> {
public static RegionWrapper build() {
return new RegionWrapper();
}
@Override
public RegionVO entityVO(Region region) {
RegionVO regionVO = Objects.requireNonNull(BeanUtil.copy(region, RegionVO.class));
Region parentRegion = RegionCache.getByCode(region.getParentCode());
regionVO.setParentName(parentRegion.getName());
return regionVO;
}
public List<RegionVO> listNodeLazyVO(List<RegionVO> list) {
return ForestNodeMerger.merge(list);
}
}

2
blade-service/blade-user/src/main/java/org/springblade/system/user/excel/UserExcel.java

@ -27,7 +27,7 @@ import java.io.Serializable;
import java.util.Date;
/**
* UserDTO
* UserExcel
*
* @author Chill
*/

3
blade-service/blade-user/src/main/java/org/springblade/system/user/service/IUserService.java

@ -135,12 +135,13 @@ public interface IUserService extends BaseService<User> {
* 导入用户数据
*
* @param data
* @param isCovered
* @return
*/
void importUser(List<UserExcel> data, Boolean isCovered);
/**
* 获取导出用户数据
* 导出用户数据
*
* @param queryWrapper
* @return

2
pom.xml

@ -18,7 +18,7 @@
<flowable.version>6.4.2</flowable.version>
<spring.boot.version>2.1.13.RELEASE</spring.boot.version>
<spring.boot.version>2.1.14.RELEASE</spring.boot.version>
<spring.cloud.version>Greenwich.SR5</spring.cloud.version>
<spring.platform.version>Cairo-SR8</spring.platform.version>

Loading…
Cancel
Save