✨ Introducing new features. 行政区划管理功能
This commit is contained in:
1 parent
48fcea9978
commit
bd762afa2d
6 files changed
+400
No files matched your search
+128
@@ -0,0 +1,128 @@
|
||||
package com.pig4cloud.pigx.admin.api.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.FieldNameConstants;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 行政区划表
|
||||
*
|
||||
* @author lbw
|
||||
* @date 2024-02-16 21:59:02
|
||||
*/
|
||||
@Data
|
||||
@FieldNameConstants
|
||||
@TableName("sys_area")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Schema(description = "行政区划表")
|
||||
public class SysAreaEntity extends Model<SysAreaEntity> {
|
||||
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@Schema(description = "主键ID")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 父ID
|
||||
*/
|
||||
@Schema(description = "父ID")
|
||||
private Long pid;
|
||||
|
||||
/**
|
||||
* 地区名称
|
||||
*/
|
||||
@Schema(description = "地区名称")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 地区字母
|
||||
*/
|
||||
@Schema(description = "地区字母")
|
||||
private String letter;
|
||||
|
||||
/**
|
||||
* 高德地区code
|
||||
*/
|
||||
@Schema(description = "地区code")
|
||||
private Long adcode;
|
||||
|
||||
/**
|
||||
* 经纬度
|
||||
*/
|
||||
@Schema(description = "经纬度")
|
||||
private String location;
|
||||
|
||||
/**
|
||||
* 排序值
|
||||
*/
|
||||
@Schema(description = "排序值")
|
||||
private Long areaSort;
|
||||
|
||||
/**
|
||||
* 0:未生效,1:生效
|
||||
*/
|
||||
@Schema(description = "0:未生效,1:生效")
|
||||
private String areaStatus;
|
||||
|
||||
/**
|
||||
* 0:国家,1:省,2:城市,3:区县
|
||||
*/
|
||||
@Schema(description = "0:国家,1:省,2:城市,3:区县")
|
||||
private String areaType;
|
||||
|
||||
/**
|
||||
* 0:非热门,1:热门
|
||||
*/
|
||||
@Schema(description = "0:非热门,1:热门")
|
||||
private String hot;
|
||||
|
||||
/**
|
||||
* 城市编码
|
||||
*/
|
||||
@Schema(description = "城市编码")
|
||||
private String cityCode;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "创建人")
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
@Schema(description = "更新时间")
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 删除标记
|
||||
*/
|
||||
@TableLogic
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "删除标记")
|
||||
private String delFlag;
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
package com.pig4cloud.pigx.admin.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysAreaEntity;
|
||||
import com.pig4cloud.pigx.admin.service.SysAreaService;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.excel.annotation.ResponseExcel;
|
||||
import com.pig4cloud.pigx.common.log.annotation.SysLog;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springdoc.core.annotations.ParameterObject;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 行政区划
|
||||
*
|
||||
* @author lbw
|
||||
* @date 2024-02-16 22:40:06
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/sysArea")
|
||||
@Tag(description = "sysArea", name = "行政区划管理")
|
||||
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
|
||||
public class SysAreaController {
|
||||
|
||||
private final SysAreaService sysAreaService;
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param sysArea 行政区划
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "分页查询", description = "分页查询")
|
||||
@GetMapping("/page")
|
||||
@PreAuthorize("@pms.hasPermission('sys_sysArea_view')")
|
||||
public R getSysAreaPage(@ParameterObject Page page, @ParameterObject SysAreaEntity sysArea) {
|
||||
return R.ok(sysAreaService.selectPage(page, sysArea));
|
||||
}
|
||||
|
||||
/**
|
||||
* 前端联动组件需要数据
|
||||
*
|
||||
* @param sysArea 查询条件
|
||||
* @return tree
|
||||
*/
|
||||
@Operation(summary = "分页查询", description = "分页查询")
|
||||
@GetMapping("/tree")
|
||||
@PreAuthorize("@pms.hasPermission('sys_sysArea_view')")
|
||||
public R getSysAreaTree(@ParameterObject SysAreaEntity sysArea) {
|
||||
return R.ok(sysAreaService.selectTree(sysArea));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过id查询行政区划
|
||||
*
|
||||
* @param sysArea 查询条件
|
||||
* @return R
|
||||
*/
|
||||
@Operation(summary = "通过id查询", description = "通过id查询")
|
||||
@GetMapping("/details")
|
||||
@PreAuthorize("@pms.hasPermission('sys_sysArea_view')")
|
||||
public R getDetails(@ParameterObject SysAreaEntity sysArea) {
|
||||
return R.ok(sysAreaService.getOne(Wrappers.query(sysArea)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增行政区划
|
||||
*
|
||||
* @param sysArea 行政区划
|
||||
* @return R
|
||||
*/
|
||||
@Operation(summary = "新增行政区划", description = "新增行政区划")
|
||||
@SysLog("新增行政区划")
|
||||
@PostMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys_sysArea_add')")
|
||||
public R save(@RequestBody SysAreaEntity sysArea) {
|
||||
return R.ok(sysAreaService.save(sysArea));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改行政区划
|
||||
*
|
||||
* @param sysArea 行政区划
|
||||
* @return R
|
||||
*/
|
||||
@Operation(summary = "修改行政区划", description = "修改行政区划")
|
||||
@SysLog("修改行政区划")
|
||||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys_sysArea_edit')")
|
||||
public R updateById(@RequestBody SysAreaEntity sysArea) {
|
||||
return R.ok(sysAreaService.updateById(sysArea));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除行政区划
|
||||
*
|
||||
* @param ids id列表
|
||||
* @return R
|
||||
*/
|
||||
@Operation(summary = "通过id删除行政区划", description = "通过id删除行政区划")
|
||||
@SysLog("通过id删除行政区划")
|
||||
@DeleteMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys_sysArea_del')")
|
||||
public R removeById(@RequestBody Long[] ids) {
|
||||
return R.ok(sysAreaService.removeBatchByIds(CollUtil.toList(ids)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出excel 表格
|
||||
*
|
||||
* @param sysArea 查询条件
|
||||
* @param ids 导出指定ID
|
||||
* @return excel 文件流
|
||||
*/
|
||||
@ResponseExcel
|
||||
@GetMapping("/export")
|
||||
@PreAuthorize("@pms.hasPermission('sys_sysArea_export')")
|
||||
public List<SysAreaEntity> export(SysAreaEntity sysArea, Long[] ids) {
|
||||
return sysAreaService.list(Wrappers.lambdaQuery(sysArea).in(ArrayUtil.isNotEmpty(ids), SysAreaEntity::getId, ids));
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package com.pig4cloud.pigx.admin.mapper;
|
||||
|
||||
import com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysAreaEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface SysAreaMapper extends PigxBaseMapper<SysAreaEntity> {
|
||||
|
||||
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.pig4cloud.pigx.admin.service;
|
||||
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysAreaEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SysAreaService extends IService<SysAreaEntity> {
|
||||
|
||||
/**
|
||||
* 查询行政区划树
|
||||
*
|
||||
* @param sysArea 查询条件
|
||||
* @return 树
|
||||
*/
|
||||
List<Tree<Long>> selectTree(SysAreaEntity sysArea);
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param sysArea 行政区划
|
||||
* @return Page
|
||||
*/
|
||||
Page selectPage(Page page, SysAreaEntity sysArea);
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package com.pig4cloud.pigx.admin.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.lang.tree.TreeNode;
|
||||
import cn.hutool.core.lang.tree.TreeUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysAreaEntity;
|
||||
import com.pig4cloud.pigx.admin.mapper.SysAreaMapper;
|
||||
import com.pig4cloud.pigx.admin.service.SysAreaService;
|
||||
import com.pig4cloud.pigx.common.core.constant.enums.YesNoEnum;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 行政区划
|
||||
*
|
||||
* @author lbw
|
||||
* @date 2024-02-16 22:40:06
|
||||
*/
|
||||
@Service
|
||||
public class SysAreaServiceImpl extends ServiceImpl<SysAreaMapper, SysAreaEntity> implements SysAreaService {
|
||||
/**
|
||||
* 查询行政区划树
|
||||
*
|
||||
* @param sysArea 查询条件
|
||||
* @return 树
|
||||
*/
|
||||
@Override
|
||||
public List<Tree<Long>> selectTree(SysAreaEntity sysArea) {
|
||||
List<SysAreaEntity> entityList = baseMapper.selectList(Wrappers.lambdaQuery(sysArea)
|
||||
.eq(SysAreaEntity::getAreaStatus, YesNoEnum.YES.getCode())
|
||||
.orderByDesc(SysAreaEntity::getAreaSort));
|
||||
|
||||
List<TreeNode<Long>> nodeList = CollUtil.newArrayList();
|
||||
for (SysAreaEntity sysAreaEntity : entityList) {
|
||||
TreeNode<Long> treeNode = new TreeNode<>(sysAreaEntity.getAdcode(), sysAreaEntity.getPid()
|
||||
, sysAreaEntity.getName(), -Optional.ofNullable(sysAreaEntity.getAreaSort()).orElse(0L));
|
||||
|
||||
HashMap<String, Object> extraMap = MapUtil.of(SysAreaEntity.Fields.adcode, sysAreaEntity.getAdcode());
|
||||
extraMap.put(SysAreaEntity.Fields.hot, sysAreaEntity.getHot());
|
||||
treeNode.setExtra(extraMap);
|
||||
nodeList.add(treeNode);
|
||||
}
|
||||
|
||||
return TreeUtil.build(nodeList, Optional.ofNullable(sysArea.getPid()).orElse(1L));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param sysArea 行政区划
|
||||
* @return Page
|
||||
*/
|
||||
@Override
|
||||
public Page selectPage(Page page, SysAreaEntity sysArea) {
|
||||
LambdaQueryWrapper<SysAreaEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.like(StrUtil.isNotBlank(sysArea.getName()), SysAreaEntity::getName, sysArea.getName());
|
||||
wrapper.eq(Objects.nonNull(sysArea.getAdcode()), SysAreaEntity::getPid, sysArea.getAdcode());
|
||||
wrapper.orderByAsc(SysAreaEntity::getAreaType);
|
||||
wrapper.orderByDesc(SysAreaEntity::getAreaSort);
|
||||
return baseMapper.selectPage(page, wrapper);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?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.pig4cloud.pigx.admin.mapper.SysAreaMapper">
|
||||
|
||||
<resultMap id="sysAreaMap" type="com.pig4cloud.pigx.admin.api.entity.SysAreaEntity">
|
||||
<id property="id" column="id"/>
|
||||
<result property="pid" column="pid"/>
|
||||
<result property="name" column="name"/>
|
||||
<result property="letter" column="letter"/>
|
||||
<result property="adcode" column="adcode"/>
|
||||
<result property="location" column="location"/>
|
||||
<result property="areaSort" column="area_sort"/>
|
||||
<result property="areaStatus" column="area_status"/>
|
||||
<result property="areaType" column="area_type"/>
|
||||
<result property="hot" column="hot"/>
|
||||
<result property="cityCode" column="city_code"/>
|
||||
<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="delFlag" column="del_flag"/>
|
||||
</resultMap>
|
||||
</mapper>
|
||||
Reference in new issue
Block a user