From 2c774e628a58f32004c9743aba8db8c10c236ec8 Mon Sep 17 00:00:00 2001 From: Parker Date: Sun, 6 Dec 2020 15:34:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=9C=B0=E5=9F=9F=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/web/system/area/SysAreaRestApi.java | 121 ++++++++ .../api/wrapper/system/area/SysAreaModel.java | 66 +++++ .../org/opsli/modulars/system/SystemMsg.java | 12 +- .../system/{depart => area}/api/README.md | 0 .../system/area/entity/HasChildren.java | 42 +++ .../modulars/system/area/entity/SysArea.java | 55 ++++ .../system/area/mapper/SysAreaMapper.java | 49 ++++ .../system/area/mapper/xml/SysAreaMapper.xml | 27 ++ .../system/area/service/ISysAreaService.java | 42 +++ .../area/service/impl/SysAreaServiceImpl.java | 178 ++++++++++++ .../area/web/SysAreaRestController.java | 264 ++++++++++++++++++ 11 files changed, 855 insertions(+), 1 deletion(-) create mode 100755 opsli-api/src/main/java/org/opsli/api/web/system/area/SysAreaRestApi.java create mode 100755 opsli-api/src/main/java/org/opsli/api/wrapper/system/area/SysAreaModel.java rename opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/{depart => area}/api/README.md (100%) create mode 100755 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/entity/HasChildren.java create mode 100755 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/entity/SysArea.java create mode 100755 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/mapper/SysAreaMapper.java create mode 100755 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/mapper/xml/SysAreaMapper.xml create mode 100755 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/service/ISysAreaService.java create mode 100755 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/service/impl/SysAreaServiceImpl.java create mode 100755 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/web/SysAreaRestController.java diff --git a/opsli-api/src/main/java/org/opsli/api/web/system/area/SysAreaRestApi.java b/opsli-api/src/main/java/org/opsli/api/web/system/area/SysAreaRestApi.java new file mode 100755 index 00000000..fe3eea42 --- /dev/null +++ b/opsli-api/src/main/java/org/opsli/api/web/system/area/SysAreaRestApi.java @@ -0,0 +1,121 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.api.web.system.area; + +import org.opsli.api.base.result.ResultVo; +import org.opsli.api.wrapper.system.area.SysAreaModel; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.multipart.MultipartHttpServletRequest; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.api.web.system.area + * @Author: Parker + * @CreateTime: 2020-11-28 18:59:59 + * @Description: 组织机构表 + * + * 对外 API 直接 暴露 @GetMapping 或者 @PostMapping + * 对内也推荐 单机版 不需要设置 Mapping 但是调用方法得从Controller写起 + * + * 这样写法虽然比较绕,但是当单体项目想要改造微服务架构时 时非常容易的 + * + * + */ +public interface SysAreaRestApi { + + /** 标题 */ + String TITLE = "地域"; + + /** + * 组织机构表 查一条 + * @param model 模型 + * @return ResultVo + */ + @GetMapping("/get") + ResultVo get(SysAreaModel model); + + /** + * 组织树 + * @param parentId + * @return ResultVo + */ + @GetMapping("/findTree") + ResultVo findTree( String parentId ); + + /** + * 组织机构表 新增 + * @param model 模型 + * @return ResultVo + */ + @PostMapping("/insert") + ResultVo insert(@RequestBody SysAreaModel model); + + /** + * 组织机构表 修改 + * @param model 模型 + * @return ResultVo + */ + @PostMapping("/update") + ResultVo update(@RequestBody SysAreaModel model); + + /** + * 组织机构表 删除 + * @param id ID + * @return ResultVo + */ + @PostMapping("/del") + ResultVo del(String id); + + /** + * 组织机构表 批量删除 + * @param ids ID 数组 + * @return ResultVo + */ + @PostMapping("/delAll") + ResultVo delAll(String[] ids); + + /** + * 组织机构表 Excel 导出 + * @param request request + * @param response response + * @return ResultVo + */ + @GetMapping("/exportExcel") + ResultVo exportExcel(HttpServletRequest request, HttpServletResponse response); + + /** + * 组织机构表 Excel 导入 + * @param request 文件流 request + * @return ResultVo + */ + @GetMapping("/exportImport") + ResultVo excelImport(MultipartHttpServletRequest request); + + /** + * 组织机构表 Excel 下载导入模版 + * @param response response + * @return ResultVo + */ + @GetMapping("/exportImport/template") + ResultVo importTemplate(HttpServletResponse response); + +} diff --git a/opsli-api/src/main/java/org/opsli/api/wrapper/system/area/SysAreaModel.java b/opsli-api/src/main/java/org/opsli/api/wrapper/system/area/SysAreaModel.java new file mode 100755 index 00000000..b1408d84 --- /dev/null +++ b/opsli-api/src/main/java/org/opsli/api/wrapper/system/area/SysAreaModel.java @@ -0,0 +1,66 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.api.wrapper.system.area; + +import com.alibaba.excel.annotation.ExcelIgnore; +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.api.base.warpper.ApiWrapper; +import org.opsli.common.annotation.validation.ValidationArgs; +import org.opsli.common.annotation.validation.ValidationArgsLenMax; +import org.opsli.common.enums.ValiArgsType; +import org.opsli.plugins.excel.annotation.ExcelInfo; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.api.wrapper.system.area + * @Author: Parker + * @CreateTime: 2020-11-28 18:59:59 + * @Description: 地域表 + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class SysAreaModel extends ApiWrapper { + + /** 父级主键 */ + @ApiModelProperty(value = "父级主键") + @ExcelProperty(value = "父级主键", order = 1) + @ExcelInfo + // 验证器 + @ValidationArgsLenMax(19) + private String parentId; + + /** 地域编号 */ + @ApiModelProperty(value = "地域编号") + @ExcelProperty(value = "地域编号", order = 2) + @ExcelInfo + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_NUMBER}) + @ValidationArgsLenMax(40) + private String areaCode; + + /** 地域名称 */ + @ApiModelProperty(value = "地域名称") + @ExcelProperty(value = "地域名称", order = 3) + @ExcelInfo + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_GENERAL_WITH_CHINESE}) + @ValidationArgsLenMax(40) + private String areaName; + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/SystemMsg.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/SystemMsg.java index 4769eaf1..f6b888da 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/SystemMsg.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/SystemMsg.java @@ -60,7 +60,17 @@ public enum SystemMsg implements BaseMsg { /** * 租户 */ - EXCEPTION_TENANT_UNIQUE(20200,"租户名称重复,该租户已存在!"), + EXCEPTION_TENANT_UNIQUE(20400,"租户名称重复,该租户已存在!"), + + /** + * 组织机构 + */ + EXCEPTION_ORG_UNIQUE(20500,"组织机构编号重复,已存在!"), + + /** + * 地域 + */ + EXCEPTION_AREA_UNIQUE(20600,"地域编号重复,已存在!"), ; diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/depart/api/README.md b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/api/README.md similarity index 100% rename from opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/depart/api/README.md rename to opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/api/README.md diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/entity/HasChildren.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/entity/HasChildren.java new file mode 100755 index 00000000..dfe2b445 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/entity/HasChildren.java @@ -0,0 +1,42 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.system.area.entity; + +import com.baomidou.mybatisplus.annotation.TableLogic; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.core.base.entity.BaseEntity; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.system.area.entity + * @Author: Parker + * @CreateTime: 2020-11-28 18:59:59 + * @Description: 地域表 + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class HasChildren{ + + + /** 父级主键 */ + private String parentId; + + /** 地域名称 */ + private Integer count; + + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/entity/SysArea.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/entity/SysArea.java new file mode 100755 index 00000000..fe0afa1f --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/entity/SysArea.java @@ -0,0 +1,55 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.system.area.entity; + +import java.util.Date; +import com.baomidou.mybatisplus.annotation.FieldStrategy; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableLogic; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.core.base.entity.BaseEntity; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.system.area.entity + * @Author: Parker + * @CreateTime: 2020-11-28 18:59:59 + * @Description: 地域表 + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class SysArea extends BaseEntity { + + + /** 父级主键 */ + private String parentId; + + /** 地域编号 */ + private String areaCode; + + /** 地域名称 */ + private String areaName; + + + // ======================================== + + + /** 逻辑删除字段 */ + @TableLogic + private Integer deleted; + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/mapper/SysAreaMapper.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/mapper/SysAreaMapper.java new file mode 100755 index 00000000..61807a96 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/mapper/SysAreaMapper.java @@ -0,0 +1,49 @@ +/** +* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com +*

+* Licensed under the Apache License, Version 2.0 (the "License"); you may not +* use this file except in compliance with the License. You may obtain a copy of +* the License at +*

+* http://www.apache.org/licenses/LICENSE-2.0 +*

+* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +* License for the specific language governing permissions and limitations under +* the License. +*/ +package org.opsli.modulars.system.area.mapper; + +import com.baomidou.mybatisplus.core.conditions.Wrapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.opsli.modulars.system.area.entity.HasChildren; +import org.opsli.modulars.system.area.entity.SysArea; + +import java.util.List; + +/** +* @BelongsProject: opsli-boot +* @BelongsPackage: org.opsli.modulars.system.area.mapper +* @Author: Parker +* @CreateTime: 2020-11-28 18:59:59 +* @Description: 地域表 Mapper +*/ +@Mapper +public interface SysAreaMapper extends BaseMapper { + + /** + * 唯一验证 + * @return + */ + Integer uniqueVerificationByCode(@Param("ew") Wrapper wrapper); + + /** + * 是否有下级 + * @return + */ + List hasChildren(@Param("ew") Wrapper wrapper); + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/mapper/xml/SysAreaMapper.xml b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/mapper/xml/SysAreaMapper.xml new file mode 100755 index 00000000..1d859c33 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/mapper/xml/SysAreaMapper.xml @@ -0,0 +1,27 @@ + + + + + + + + + + diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/service/ISysAreaService.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/service/ISysAreaService.java new file mode 100755 index 00000000..291ca4b7 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/service/ISysAreaService.java @@ -0,0 +1,42 @@ +/** +* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com +*

+* Licensed under the Apache License, Version 2.0 (the "License"); you may not +* use this file except in compliance with the License. You may obtain a copy of +* the License at +*

+* http://www.apache.org/licenses/LICENSE-2.0 +*

+* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +* License for the specific language governing permissions and limitations under +* the License. +*/ +package org.opsli.modulars.system.area.service; + +import org.opsli.api.wrapper.system.area.SysAreaModel; +import org.opsli.core.base.service.interfaces.CrudServiceInterface; +import org.opsli.modulars.system.area.entity.HasChildren; +import org.opsli.modulars.system.area.entity.SysArea; + +import java.util.List; +import java.util.Set; + +/** +* @BelongsProject: opsli-boot +* @BelongsPackage: org.opsli.modulars.system.area.service +* @Author: Parker +* @CreateTime: 2020-11-28 18:59:59 +* @Description: 地域表 Service +*/ +public interface ISysAreaService extends CrudServiceInterface { + + + /** + * 是否有下级 + * @return + */ + List hasChildren(Set parentIds); + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/service/impl/SysAreaServiceImpl.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/service/impl/SysAreaServiceImpl.java new file mode 100755 index 00000000..b53d0a7e --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/service/impl/SysAreaServiceImpl.java @@ -0,0 +1,178 @@ +/** +* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com +*

+* Licensed under the Apache License, Version 2.0 (the "License"); you may not +* use this file except in compliance with the License. You may obtain a copy of +* the License at +*

+* http://www.apache.org/licenses/LICENSE-2.0 +*

+* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +* License for the specific language governing permissions and limitations under +* the License. +*/ +package org.opsli.modulars.system.area.service.impl; + + +import cn.hutool.core.collection.CollUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import org.apache.commons.lang3.StringUtils; +import org.opsli.api.wrapper.system.area.SysAreaModel; +import org.opsli.common.constants.MyBatisConstants; +import org.opsli.common.exception.ServiceException; +import org.opsli.common.utils.HumpUtil; +import org.opsli.core.base.service.impl.CrudServiceImpl; +import org.opsli.core.persistence.querybuilder.GenQueryBuilder; +import org.opsli.core.persistence.querybuilder.QueryBuilder; +import org.opsli.modulars.system.SystemMsg; +import org.opsli.modulars.system.area.entity.HasChildren; +import org.opsli.modulars.system.area.entity.SysArea; +import org.opsli.modulars.system.area.mapper.SysAreaMapper; +import org.opsli.modulars.system.area.service.ISysAreaService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Set; + + +/** +* @BelongsProject: opsli-boot +* @BelongsPackage: org.opsli.modulars.system.area.service.impl +* @Author: Parker +* @CreateTime: 2020-11-28 18:59:59 +* @Description: 地域表 Service Impl +*/ +@Service +public class SysAreaServiceImpl extends CrudServiceImpl + implements ISysAreaService { + + @Autowired(required = false) + private SysAreaMapper mapper; + + + @Override + @Transactional(rollbackFor = Exception.class) + public SysAreaModel insert(SysAreaModel model) { + if(model == null) return null; + + SysArea entity = super.transformM2T(model); + // 唯一验证 + Integer count = this.uniqueVerificationByCode(entity); + if(count != null && count > 0){ + // 重复 + throw new ServiceException(SystemMsg.EXCEPTION_AREA_UNIQUE); + } + + // 如果上级ID 为空 则默认为 0 + if(StringUtils.isEmpty(model.getParentId())){ + model.setParentId("0"); + } + + return super.insert(model); + } + + @Transactional(rollbackFor = Exception.class) + @Override + public SysAreaModel update(SysAreaModel model) { + if(model == null) return null; + + SysArea entity = super.transformM2T(model); + // 唯一验证 + Integer count = this.uniqueVerificationByCode(entity); + if(count != null && count > 0){ + // 重复 + throw new ServiceException(SystemMsg.EXCEPTION_AREA_UNIQUE); + } + + return super.update(model); + } + + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean delete(String id) { + boolean ret = super.delete(id); + // 删除子数据 + this.deleteByParentId(id); + + return ret; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean deleteAll(String[] ids) { + boolean ret = super.deleteAll(ids); + // 删除子数据 + for (String id : ids) { + this.deleteByParentId(id); + } + + return ret; + } + + /** + * 逐级删除子数据 + * @param parentId + * @return + */ + @Transactional(rollbackFor = Exception.class) + public boolean deleteByParentId(String parentId) { + boolean ret = false; + QueryBuilder queryBuilder = new GenQueryBuilder<>(); + QueryWrapper queryWrapper = queryBuilder.build(); + queryWrapper.eq(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId); + List childList = super.findList(queryWrapper); + for (SysArea child : childList) { + super.delete(child.getId()); + // 逐级删除子数据 + ret = this.deleteByParentId(child.getId()); + } + return ret; + } + + /** + * 唯一验证 + * @param entity + * @return + */ + @Transactional(readOnly = true) + public Integer uniqueVerificationByCode(SysArea entity){ + QueryWrapper wrapper = new QueryWrapper<>(); + + // code 唯一 + wrapper.eq("area_code", entity.getAreaCode()) + .eq(MyBatisConstants.FIELD_DELETE_LOGIC, "0"); + + // 如果为修改 则跳过当前数据 + if(StringUtils.isNotBlank(entity.getId())){ + wrapper.notIn(MyBatisConstants.FIELD_ID, entity.getId()); + } + + return mapper.uniqueVerificationByCode(wrapper); + } + + + /** + * 是否有下级 + * @param parentIds + * @return + */ + @Override + @Transactional(readOnly = true) + public List hasChildren(Set parentIds){ + if(CollUtil.isEmpty(parentIds)){ + return null; + } + QueryWrapper wrapper = new QueryWrapper<>(); + + wrapper.in(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentIds) + .eq(MyBatisConstants.FIELD_DELETE_LOGIC, "0") + .groupBy(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID)); + + return mapper.hasChildren(wrapper); + } +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/web/SysAreaRestController.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/web/SysAreaRestController.java new file mode 100755 index 00000000..62e1f50a --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/area/web/SysAreaRestController.java @@ -0,0 +1,264 @@ +/** +* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com +*

+* Licensed under the Apache License, Version 2.0 (the "License"); you may not +* use this file except in compliance with the License. You may obtain a copy of +* the License at +*

+* http://www.apache.org/licenses/LICENSE-2.0 +*

+* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +* License for the specific language governing permissions and limitations under +* the License. +*/ +package org.opsli.modulars.system.area.web; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.lang.tree.Tree; +import cn.hutool.core.lang.tree.TreeNodeConfig; +import cn.hutool.core.lang.tree.TreeUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.opsli.api.base.result.ResultVo; +import org.opsli.api.web.system.area.SysAreaRestApi; +import org.opsli.api.wrapper.system.area.SysAreaModel; +import org.opsli.common.annotation.ApiRestController; +import org.opsli.common.annotation.EnableLog; +import org.opsli.common.constants.MyBatisConstants; +import org.opsli.common.utils.HumpUtil; +import org.opsli.core.base.concroller.BaseRestController; +import org.opsli.core.persistence.querybuilder.GenQueryBuilder; +import org.opsli.core.persistence.querybuilder.QueryBuilder; +import org.opsli.core.persistence.querybuilder.WebQueryBuilder; +import org.opsli.modulars.system.area.entity.HasChildren; +import org.opsli.modulars.system.area.entity.SysArea; +import org.opsli.modulars.system.area.service.ISysAreaService; +import org.springframework.web.multipart.MultipartHttpServletRequest; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** +* @BelongsProject: opsli-boot +* @BelongsPackage: org.opsli.modulars.system.area.web +* @Author: Parker +* @CreateTime: 2020-11-28 18:59:59 +* @Description: 地域表 Controller +*/ +@Slf4j +@ApiRestController("/sys/area") +public class SysAreaRestController extends BaseRestController + implements SysAreaRestApi { + + + /** + * 地域 查一条 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "获得单条地域", notes = "获得单条地域 - ID") + @RequiresPermissions("system_area_select") + @Override + public ResultVo get(SysAreaModel model) { + // 如果系统内部调用 则直接查数据库 + if(model != null && model.getIzApi() != null && model.getIzApi()){ + model = IService.get(model); + } + return ResultVo.success(model); + } + + /** + * 获得组织树树 + * @return ResultVo + */ + @ApiOperation(value = "获得菜单树", notes = "获得菜单树") + @RequiresPermissions("system_area_select") + @Override + public ResultVo findTree(String parentId) { + + QueryBuilder queryBuilder = new GenQueryBuilder<>(); + QueryWrapper wrapper = queryBuilder.build(); + wrapper.eq(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId); + + // 获得用户 对应菜单 + List dataList = IService.findList(wrapper); + + //配置 + TreeNodeConfig treeNodeConfig = new TreeNodeConfig(); + // 自定义属性名 都要默认值的 + treeNodeConfig.setWeightKey("sortNo"); + treeNodeConfig.setNameKey("areaName"); + // 最大递归深度 最多支持4层菜单 + treeNodeConfig.setDeep(1); + + List> treeNodes = TreeUtil.build(dataList, parentId, treeNodeConfig, + (treeNode, tree) -> { + + String areaCode = treeNode.getAreaCode(); + int sort = 0; + if(StringUtils.isNotEmpty(areaCode)){ + try { + sort = Integer.parseInt(areaCode); + }catch (Exception ignored){} + } + + tree.setId(treeNode.getId()); + tree.setParentId(treeNode.getParentId()); + tree.setWeight(sort); + tree.setName(treeNode.getAreaName()); + // 扩展属性 ... + // 不是外链 则处理组件 + tree.putExtra("areaCode", areaCode); + tree.putExtra("version", treeNode.getVersion()); + }); + + Set parentIds = Sets.newHashSet(); + for (Tree treeNode : treeNodes) { + parentIds.add(treeNode.getId()); + } + + // 数据排查是否存在下级 + List hasChildrenList = IService.hasChildren(parentIds); + if(CollUtil.isNotEmpty(hasChildrenList)){ + Map tmp = Maps.newHashMap(); + for (HasChildren hasChildren : hasChildrenList) { + if(hasChildren.getCount() != null && hasChildren.getCount() > 0){ + tmp.put(hasChildren.getParentId(), true); + } + } + + for (Tree treeNode : treeNodes) { + Boolean tmpFlag = tmp.get(treeNode.getId()); + if(tmpFlag != null && tmpFlag){ + treeNode.putExtra("hasChildren", true); + } + } + } + + return ResultVo.success(treeNodes); + } + + /** + * 地域 新增 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "新增地域数据", notes = "新增地域数据") + @RequiresPermissions("system_area_insert") + @EnableLog + @Override + public ResultVo insert(SysAreaModel model) { + // 演示模式 不允许操作 + super.demoError(); + + // 调用新增方法 + IService.insert(model); + return ResultVo.success("新增地域成功"); + } + + /** + * 地域 修改 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "修改地域数据", notes = "修改地域数据") + @RequiresPermissions("system_area_update") + @EnableLog + @Override + public ResultVo update(SysAreaModel model) { + // 演示模式 不允许操作 + super.demoError(); + + // 调用修改方法 + IService.update(model); + return ResultVo.success("修改地域成功"); + } + + + /** + * 地域 删除 + * @param id ID + * @return ResultVo + */ + @ApiOperation(value = "删除地域数据", notes = "删除地域数据") + @RequiresPermissions("system_area_update") + @EnableLog + @Override + public ResultVo del(String id){ + // 演示模式 不允许操作 + super.demoError(); + + IService.delete(id); + return ResultVo.success("删除地域成功"); + } + + /** + * 地域 批量删除 + * @param ids ID 数组 + * @return ResultVo + */ + @ApiOperation(value = "批量删除地域数据", notes = "批量删除地域数据") + @RequiresPermissions("system_area_update") + @EnableLog + @Override + public ResultVo delAll(String[] ids){ + // 演示模式 不允许操作 + super.demoError(); + + IService.deleteAll(ids); + return ResultVo.success("批量删除地域成功"); + } + + + /** + * 地域 Excel 导出 + * @param request request + * @param response response + * @return ResultVo + */ + @ApiOperation(value = "导出Excel", notes = "导出Excel") + @RequiresPermissions("system_area_export") + @EnableLog + @Override + public ResultVo exportExcel(HttpServletRequest request, HttpServletResponse response) { + QueryBuilder queryBuilder = new WebQueryBuilder<>(SysArea.class, request.getParameterMap()); + return super.excelExport(SysAreaRestApi.TITLE, queryBuilder.build(), response); + } + + /** + * 地域 Excel 导入 + * @param request 文件流 request + * @return ResultVo + */ + @ApiOperation(value = "导入Excel", notes = "导入Excel") + @RequiresPermissions("system_area_import") + @EnableLog + @Override + public ResultVo excelImport(MultipartHttpServletRequest request) { + return super.excelImport(request); + } + + /** + * 地域 Excel 下载导入模版 + * @param response response + * @return ResultVo + */ + @ApiOperation(value = "导出Excel模版", notes = "导出Excel模版") + @RequiresPermissions("system_area_import") + @Override + public ResultVo importTemplate(HttpServletResponse response) { + return super.importTemplate(SysAreaRestApi.TITLE, response); + } + +}