From e4c42ca119803fee2b0109cadd97c699784630af Mon Sep 17 00:00:00 2001 From: Parker Date: Tue, 8 Dec 2020 15:41:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=BB=84=E7=BB=87=E6=9C=BA?= =?UTF-8?q?=E6=9E=84=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/web/system/org/SysOrgRestApi.java | 134 ++++++ .../opsli/api/web/system/user/UserApi.java | 26 +- .../api/web/system/user/UserOrgRefApi.java | 53 +++ .../api/wrapper/system/org/SysOrgModel.java | 94 ++++ .../wrapper/system/user/UserAndOrgModel.java | 150 ++++++ .../wrapper/system/user/UserOrgRefModel.java | 75 +++ .../org/opsli/modulars/system/SystemMsg.java | 12 +- .../system/area/mapper/SysAreaMapper.java | 2 +- .../system/area/mapper/xml/SysAreaMapper.xml | 2 +- .../system/area/service/ISysAreaService.java | 2 +- .../area/service/impl/SysAreaServiceImpl.java | 2 +- .../area/web/SysAreaRestController.java | 2 +- .../system/login/web/LoginRestController.java | 1 - .../opsli/modulars/system/org/api/README.md | 1 + .../modulars/system/org/entity/SysOrg.java | 64 +++ .../system/org/mapper/SysOrgMapper.java | 56 +++ .../system/org/mapper/xml/SysOrgMapper.xml | 48 ++ .../system/org/service/ISysOrgService.java | 43 ++ .../org/service/impl/SysOrgServiceImpl.java | 209 +++++++++ .../system/org/web/SysOrgRestController.java | 437 ++++++++++++++++++ .../system/user/entity/SysUserAndOrg.java | 92 ++++ .../system/user/entity/SysUserOrgRef.java | 49 ++ .../system/user/mapper/UserMapper.java | 10 + .../system/user/mapper/UserOrgRefMapper.java | 34 ++ .../system/user/mapper/xml/UserMapper.xml | 25 +- .../user/mapper/xml/UserOrgRefMapper.xml | 6 + .../user/service/IUserOrgRefService.java | 39 ++ .../system/user/service/IUserService.java | 12 + .../service/impl/UserOrgRefServiceImpl.java | 110 +++++ .../user/service/impl/UserServiceImpl.java | 30 ++ .../user/web/UserOrgRefRestController.java | 84 ++++ .../system/user/web/UserRestController.java | 150 +++++- 32 files changed, 2028 insertions(+), 26 deletions(-) create mode 100755 opsli-api/src/main/java/org/opsli/api/web/system/org/SysOrgRestApi.java create mode 100644 opsli-api/src/main/java/org/opsli/api/web/system/user/UserOrgRefApi.java create mode 100755 opsli-api/src/main/java/org/opsli/api/wrapper/system/org/SysOrgModel.java create mode 100644 opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserAndOrgModel.java create mode 100644 opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserOrgRefModel.java create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/api/README.md create mode 100755 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/entity/SysOrg.java create mode 100755 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/mapper/SysOrgMapper.java create mode 100755 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/mapper/xml/SysOrgMapper.xml create mode 100755 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/service/ISysOrgService.java create mode 100755 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/service/impl/SysOrgServiceImpl.java create mode 100755 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/web/SysOrgRestController.java create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/entity/SysUserAndOrg.java create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/entity/SysUserOrgRef.java create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/UserOrgRefMapper.java create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/xml/UserOrgRefMapper.xml create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/IUserOrgRefService.java create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserOrgRefServiceImpl.java create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserOrgRefRestController.java diff --git a/opsli-api/src/main/java/org/opsli/api/web/system/org/SysOrgRestApi.java b/opsli-api/src/main/java/org/opsli/api/web/system/org/SysOrgRestApi.java new file mode 100755 index 0000000..7c4ea5c --- /dev/null +++ b/opsli-api/src/main/java/org/opsli/api/web/system/org/SysOrgRestApi.java @@ -0,0 +1,134 @@ +/** + * 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.org; + +import org.opsli.api.base.result.ResultVo; +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.bind.annotation.RequestParam; +import org.springframework.web.multipart.MultipartHttpServletRequest; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.opsli.api.wrapper.system.org.SysOrgModel; + + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.api.web.system.org + * @Author: Parker + * @CreateTime: 2020-11-28 18:59:59 + * @Description: 组织机构表 + * + * 对外 API 直接 暴露 @GetMapping 或者 @PostMapping + * 对内也推荐 单机版 不需要设置 Mapping 但是调用方法得从Controller写起 + * + * 这样写法虽然比较绕,但是当单体项目想要改造微服务架构时 时非常容易的 + * + * + */ +public interface SysOrgRestApi { + + /** 标题 */ + String TITLE = "组织机构"; + + + @GetMapping("/findTreeLazyByUser") + ResultVo findTreeLazyByUser(String parentId); + + @GetMapping("/findTreeLazy") + ResultVo findTreeLazy(String parentId); + + @GetMapping("/findGridTree") + ResultVo findGridTree(String parentId); + + // ================ + + /** + * 组织机构表 查一条 + * @param model 模型 + * @return ResultVo + */ + @GetMapping("/get") + ResultVo get(SysOrgModel model); + + /** + * 组织树 + * @param request request + * @return ResultVo + */ + @GetMapping("/findTree") + ResultVo findTree( HttpServletRequest request ); + + /** + * 组织机构表 新增 + * @param model 模型 + * @return ResultVo + */ + @PostMapping("/insert") + ResultVo insert(@RequestBody SysOrgModel model); + + /** + * 组织机构表 修改 + * @param model 模型 + * @return ResultVo + */ + @PostMapping("/update") + ResultVo update(@RequestBody SysOrgModel 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/web/system/user/UserApi.java b/opsli-api/src/main/java/org/opsli/api/web/system/user/UserApi.java index b51a4ee..3203233 100644 --- a/opsli-api/src/main/java/org/opsli/api/web/system/user/UserApi.java +++ b/opsli-api/src/main/java/org/opsli/api/web/system/user/UserApi.java @@ -17,15 +17,14 @@ package org.opsli.api.web.system.user; import org.opsli.api.base.result.ResultVo; import org.opsli.api.wrapper.system.menu.MenuModel; -import org.opsli.api.wrapper.system.role.RoleModel; import org.opsli.api.wrapper.system.user.UserInfo; import org.opsli.api.wrapper.system.user.UserModel; +import org.opsli.api.wrapper.system.user.UserOrgRefModel; import org.opsli.api.wrapper.system.user.UserPassword; 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.bind.annotation.RequestParam; -import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import javax.servlet.http.HttpServletRequest; @@ -66,6 +65,20 @@ public interface UserApi { @GetMapping("/getInfoById") ResultVo getInfoById(@RequestParam(name = "userId") String userId); + /** + * 当前登陆用户信息 + * @return ResultVo + */ + @GetMapping("/getOrg") + ResultVo getOrg(); + + /** + * 当前登陆用户信息 + * @return ResultVo + */ + @GetMapping("/getOrgByUserId") + ResultVo getOrgByUserId(@RequestParam(name = "userId") String userId); + /** * 根据 userId 获得用户角色Id集合 * @param userId 用户Id @@ -118,6 +131,7 @@ public interface UserApi { ResultVo findPage( @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, + UserOrgRefModel org, HttpServletRequest request ); @@ -212,4 +226,12 @@ public interface UserApi { //@GetMapping("/queryAllPerms") ResultVo> getMenuListByUserId(String userId); + + /** + * 当前登陆用户信息 + * @return ResultVo + */ + ResultVo getOrgInfoByUserId(String userId); + + } diff --git a/opsli-api/src/main/java/org/opsli/api/web/system/user/UserOrgRefApi.java b/opsli-api/src/main/java/org/opsli/api/web/system/user/UserOrgRefApi.java new file mode 100644 index 0000000..847da00 --- /dev/null +++ b/opsli-api/src/main/java/org/opsli/api/web/system/user/UserOrgRefApi.java @@ -0,0 +1,53 @@ +/** + * 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.user; + +import org.opsli.api.base.result.ResultVo; +import org.opsli.api.wrapper.system.user.UserOrgRefModel; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.web + * @Author: Parker + * @CreateTime: 2020-09-13 17:40 + * @Description: 用户组织 API + * + * 对外 API 直接 暴露 @GetMapping 或者 @PostMapping + * 对内也推荐 单机版 不需要设置 Mapping 但是调用方法得从Controller写起 + * + * 这样写法虽然比较绕,但是当单体项目想要改造微服务架构时 时非常容易的 + * + * + */ +public interface UserOrgRefApi { + + /** 标题 */ + String TITLE = "组织机构"; + + + /** + * 设置角色 + * @param model userId 用户Id + * @param model roleIds 角色Id 数组 + * @return ResultVo + */ + @PostMapping("/setOrg") + ResultVo setOrg(@RequestBody UserOrgRefModel model); + +} diff --git a/opsli-api/src/main/java/org/opsli/api/wrapper/system/org/SysOrgModel.java b/opsli-api/src/main/java/org/opsli/api/wrapper/system/org/SysOrgModel.java new file mode 100755 index 0000000..80bd612 --- /dev/null +++ b/opsli-api/src/main/java/org/opsli/api/wrapper/system/org/SysOrgModel.java @@ -0,0 +1,94 @@ +/** + * 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.org; + +import java.util.Date; + +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; +import com.fasterxml.jackson.annotation.JsonFormat; +import org.springframework.format.annotation.DateTimeFormat; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.api.wrapper.system.org + * @Author: Parker + * @CreateTime: 2020-11-28 18:59:59 + * @Description: 组织机构表 + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class SysOrgModel 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_GENERAL}) + @ValidationArgsLenMax(120) + private String orgCode; + + /** 组织机构名称 */ + @ApiModelProperty(value = "组织机构名称") + @ExcelProperty(value = "组织机构名称", order = 3) + @ExcelInfo + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_GENERAL_WITH_CHINESE}) + @ValidationArgsLenMax(120) + private String orgName; + + /** 组织机构类型 1-公司 2-部门 3-岗位*/ + @ApiModelProperty(value = "组织机构类型") + @ExcelProperty(value = "组织机构类型", order = 4) + @ExcelInfo( dictType = "org_type") + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL}) + @ValidationArgsLenMax(3) + private String orgType; + + /** 排序 */ + @ApiModelProperty(value = "排序") + @ExcelProperty(value = "排序", order = 5) + @ExcelInfo + // 验证器 + @ValidationArgsLenMax(10) + private Integer sortNo; + + /** 多租户字段 */ + @ApiModelProperty(value = "多租户ID") + @ExcelIgnore + // 验证器 + @ValidationArgsLenMax(20) + private String tenantId; + +} diff --git a/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserAndOrgModel.java b/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserAndOrgModel.java new file mode 100644 index 0000000..1f226f6 --- /dev/null +++ b/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserAndOrgModel.java @@ -0,0 +1,150 @@ +/** + * 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.user; + +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.modulars.test.entity + * @Author: Parker + * @CreateTime: 2020-09-16 17:33 + * @Description: 用户信息表 + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class UserAndOrgModel extends ApiWrapper { + + + /** 登录账户 */ + @ApiModelProperty(value = "登录账户") + @ExcelIgnore + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL,ValiArgsType.IS_GENERAL}) + @ValidationArgsLenMax(32) + private String username; + + /** 登录密码 */ + @ApiModelProperty(value = "登录密码") + @ExcelIgnore + // 验证器 + @ValidationArgsLenMax(50) + private String password; + + /** 盐值,密码秘钥 */ + @ApiModelProperty(value = "盐值,密码秘钥") + @ExcelIgnore + // 验证器 + @ValidationArgsLenMax(50) + private String secretkey; + + /** 是否锁定 */ + @ApiModelProperty(value = "是否锁定") + @ExcelIgnore + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL}) + @ValidationArgsLenMax(1) + private Character locked; + + /** 真实姓名 */ + @ApiModelProperty(value = "真实姓名") + @ExcelProperty(value = "真实姓名", order = 1) + @ExcelInfo + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL,ValiArgsType.IS_GENERAL_WITH_CHINESE}) + @ValidationArgsLenMax(50) + private String realName; + + /** 手机 */ + @ApiModelProperty(value = "手机") + @ExcelProperty(value = "手机", order = 2) + @ExcelInfo + // 验证器 + @ValidationArgs({ValiArgsType.IS_MOBILE}) + private String mobile; + + /** 邮箱 */ + @ApiModelProperty(value = "邮箱") + @ExcelProperty(value = "邮箱", order = 3) + @ExcelInfo + // 验证器 + @ValidationArgs({ValiArgsType.IS_EMAIL}) + @ValidationArgsLenMax(100) + private String email; + + /** 工号 */ + @ApiModelProperty(value = "工号") + @ExcelProperty(value = "工号", order = 4) + @ExcelInfo + // 验证器 + @ValidationArgs({ValiArgsType.IS_GENERAL}) + @ValidationArgsLenMax(32) + private String no; + + /** 头像 */ + @ApiModelProperty(value = "头像") + @ExcelIgnore + // 验证器 + @ValidationArgsLenMax(255) + private String avatar; + + /** 最后登陆IP */ + @ApiModelProperty(value = "最后登陆IP") + @ExcelIgnore + // 验证器 + @ValidationArgs(ValiArgsType.IS_IPV4) + private String loginIp; + + /** 备注 */ + @ApiModelProperty(value = "备注") + @ExcelProperty(value = "备注", order = 5) + @ExcelInfo + // 验证器 + @ValidationArgsLenMax(255) + private String remark; + + /** 签名 */ + @ApiModelProperty(value = "签名") + @ExcelProperty(value = "签名", order = 5) + @ExcelInfo + // 验证器 + @ValidationArgsLenMax(255) + private String sign; + + + /** 多租户字段 */ + @ApiModelProperty(value = "多租户ID") + @ExcelIgnore + // 验证器 + @ValidationArgsLenMax(20) + private String tenantId; + + /** 组织机构 */ + @ApiModelProperty(value = "组织机构") + @ExcelIgnore + private UserOrgRefModel org; + + +} diff --git a/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserOrgRefModel.java b/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserOrgRefModel.java new file mode 100644 index 0000000..0613c84 --- /dev/null +++ b/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserOrgRefModel.java @@ -0,0 +1,75 @@ +/** + * 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.user; + +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.common.annotation.validation.ValidationArgs; +import org.opsli.common.annotation.validation.ValidationArgsLenMax; +import org.opsli.common.enums.ValiArgsType; + +import java.io.Serializable; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.entity + * @Author: Parker + * @CreateTime: 2020-09-16 17:33 + * @Description: 角色表 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@ExcelIgnoreUnannotated +public class UserOrgRefModel implements Serializable { + + /** 用户ID */ + @ApiModelProperty(value = "用户ID") + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL}) + @ValidationArgsLenMax(50) + private String userId; + + @ApiModelProperty(value = "公司") + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL}) + @ValidationArgsLenMax(19) + private String companyId; + + @ApiModelProperty(value = "公司名称") + // 验证器 + private String companyName; + + @ApiModelProperty(value = "部门ID") + // 验证器 + @ValidationArgsLenMax(19) + private String departmentId; + + @ApiModelProperty(value = "部门名称") + // 验证器 + private String departmentName; + + @ApiModelProperty(value = "岗位ID") + // 验证器 + @ValidationArgsLenMax(19) + private String postId; + + @ApiModelProperty(value = "岗位名称") + // 验证器 + private String postName; + +} 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 f6b888d..ac8dd10 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 @@ -41,7 +41,7 @@ public enum SystemMsg implements BaseMsg { /** * 角色 */ - EXCEPTION_ROLE_UNIQUE(20200,"角色编号重复,该角色已存在!"), + EXCEPTION_ROLE_UNIQUE(20200,"角色编号重复,该角色已存在"), EXCEPTION_ROLE_ID_NOT_NULL(20201,"角色Id不可为空"), EXCEPTION_ROLE_PERMS_ERROR(20202,"角色权限设置失败"), @@ -55,22 +55,26 @@ public enum SystemMsg implements BaseMsg { EXCEPTION_USER_ROLES_ERROR(20303,"用户角色设置失败"), EXCEPTION_USER_MENU_NOT_NULL(20304,"用户暂无角色菜单,请设置后登录"), EXCEPTION_USER_NO_UNIQUE(20305,"该工号已存在"), + EXCEPTION_ORG_NOT_NULL(20306,"组织不可为空"), + EXCEPTION_USER_ORG_ERROR(20307,"用户组织设置失败"), + /** * 租户 */ - EXCEPTION_TENANT_UNIQUE(20400,"租户名称重复,该租户已存在!"), + EXCEPTION_TENANT_UNIQUE(20400,"租户名称重复,该租户已存在"), /** * 组织机构 */ - EXCEPTION_ORG_UNIQUE(20500,"组织机构编号重复,已存在!"), + EXCEPTION_ORG_UNIQUE(20500,"组织机构编号重复,已存在"), + EXCEPTION_ORG_USE(20501,"组织机构已被引用,不能删除"), /** * 地域 */ - EXCEPTION_AREA_UNIQUE(20600,"地域编号重复,已存在!"), + EXCEPTION_AREA_UNIQUE(20600,"地域编号重复,已存在"), ; 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 index 61807a9..ffdc947 100755 --- 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 @@ -19,7 +19,7 @@ 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.core.base.entity.HasChildren; import org.opsli.modulars.system.area.entity.SysArea; import java.util.List; 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 index 1d859c3..2c924d6 100755 --- 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 @@ -12,7 +12,7 @@ - select parent_id as parentId, count(0) as `count` 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 index 291ca4b..c77f608 100755 --- 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 @@ -16,8 +16,8 @@ package org.opsli.modulars.system.area.service; import org.opsli.api.wrapper.system.area.SysAreaModel; +import org.opsli.core.base.entity.HasChildren; 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; 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 index b53d0a7..93dd4a6 100755 --- 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 @@ -23,11 +23,11 @@ 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.entity.HasChildren; 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; 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 index 62e1f50..9c67d02 100755 --- 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 @@ -35,10 +35,10 @@ 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.base.entity.HasChildren; 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; diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/login/web/LoginRestController.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/login/web/LoginRestController.java index 678e2b2..9fb8c99 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/login/web/LoginRestController.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/login/web/LoginRestController.java @@ -15,7 +15,6 @@ */ package org.opsli.modulars.system.login.web; -import cn.hutool.core.convert.Convert; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.google.common.collect.Maps; import io.swagger.annotations.ApiOperation; diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/api/README.md b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/api/README.md new file mode 100644 index 0000000..f2f9594 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/api/README.md @@ -0,0 +1 @@ +## 改造微服务时 将Feign 接口写在这里 \ No newline at end of file diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/entity/SysOrg.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/entity/SysOrg.java new file mode 100755 index 0000000..38a3478 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/entity/SysOrg.java @@ -0,0 +1,64 @@ +/** + * 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.org.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.org.entity + * @Author: Parker + * @CreateTime: 2020-11-28 18:59:59 + * @Description: 组织机构表 + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class SysOrg extends BaseEntity { + + + /** 父级主键 */ + private String parentId; + + /** 组织机构编号 */ + private String orgCode; + + /** 组织机构名称 */ + private String orgName; + + /** 组织机构类型: 1-公司 2-部门 3-岗位 */ + private String orgType; + + /** 排序 */ + private Integer sortNo; + + + // ======================================== + + + /** 逻辑删除字段 */ + @TableLogic + private Integer deleted; + + /** 多租户字段 */ + private String tenantId; + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/mapper/SysOrgMapper.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/mapper/SysOrgMapper.java new file mode 100755 index 0000000..bf80635 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/mapper/SysOrgMapper.java @@ -0,0 +1,56 @@ +/** +* 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.org.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.core.base.entity.HasChildren; +import org.opsli.modulars.system.org.entity.SysOrg; + +import java.util.List; + +/** +* @BelongsProject: opsli-boot +* @BelongsPackage: org.opsli.modulars.system.org.mapper +* @Author: Parker +* @CreateTime: 2020-11-28 18:59:59 +* @Description: 组织机构表 Mapper +*/ +@Mapper +public interface SysOrgMapper extends BaseMapper { + + /** + * 唯一验证 + * @return + */ + Integer uniqueVerificationByCode(@Param("ew") Wrapper wrapper); + + /** + * 是否有下级 + * @return + */ + List hasChildren(@Param("ew") Wrapper wrapper); + + + /** + * 是否被引用 + * @return + */ + Integer hasUse(@Param("ew") Wrapper wrapper); + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/mapper/xml/SysOrgMapper.xml b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/mapper/xml/SysOrgMapper.xml new file mode 100755 index 0000000..f71d396 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/mapper/xml/SysOrgMapper.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/service/ISysOrgService.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/service/ISysOrgService.java new file mode 100755 index 0000000..1d9a87b --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/service/ISysOrgService.java @@ -0,0 +1,43 @@ +/** +* 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.org.service; + +import org.opsli.core.base.entity.HasChildren; +import org.opsli.core.base.service.interfaces.CrudServiceInterface; + + +import org.opsli.modulars.system.org.entity.SysOrg; +import org.opsli.api.wrapper.system.org.SysOrgModel; + +import java.util.List; +import java.util.Set; + +/** +* @BelongsProject: opsli-boot +* @BelongsPackage: org.opsli.modulars.system.org.service +* @Author: Parker +* @CreateTime: 2020-11-28 18:59:59 +* @Description: 组织机构表 Service +*/ +public interface ISysOrgService extends CrudServiceInterface { + + /** + * 是否有下级 + * @return + */ + List hasChildren(Set parentIds); + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/service/impl/SysOrgServiceImpl.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/service/impl/SysOrgServiceImpl.java new file mode 100755 index 0000000..ebbf22c --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/service/impl/SysOrgServiceImpl.java @@ -0,0 +1,209 @@ +/** +* 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.org.service.impl; + + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.convert.Convert; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.StringUtils; +import org.opsli.api.wrapper.system.org.SysOrgModel; +import org.opsli.common.constants.MyBatisConstants; +import org.opsli.common.exception.ServiceException; +import org.opsli.common.utils.HumpUtil; +import org.opsli.core.base.entity.HasChildren; +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.core.persistence.querybuilder.chain.TenantHandler; +import org.opsli.modulars.system.SystemMsg; +import org.opsli.modulars.system.org.entity.SysOrg; +import org.opsli.modulars.system.org.mapper.SysOrgMapper; +import org.opsli.modulars.system.org.service.ISysOrgService; +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.org.service.impl +* @Author: Parker +* @CreateTime: 2020-11-28 18:59:59 +* @Description: 组织机构表 Service Impl +*/ +@Service +public class SysOrgServiceImpl extends CrudServiceImpl + implements ISysOrgService { + + @Autowired(required = false) + private SysOrgMapper mapper; + + + @Override + @Transactional(rollbackFor = Exception.class) + public SysOrgModel insert(SysOrgModel model) { + if(model == null) return null; + + SysOrg entity = super.transformM2T(model); + // 唯一验证 + Integer count = this.uniqueVerificationByCode(entity); + if(count != null && count > 0){ + // 重复 + throw new ServiceException(SystemMsg.EXCEPTION_ORG_UNIQUE); + } + + // 如果上级ID 为空 则默认为 0 + if(StringUtils.isEmpty(model.getParentId())){ + model.setParentId("0"); + } + + return super.insert(model); + } + + @Transactional(rollbackFor = Exception.class) + @Override + public SysOrgModel update(SysOrgModel model) { + if(model == null) return null; + + SysOrg entity = super.transformM2T(model); + // 唯一验证 + Integer count = this.uniqueVerificationByCode(entity); + if(count != null && count > 0){ + // 重复 + throw new ServiceException(SystemMsg.EXCEPTION_ORG_UNIQUE); + } + + return super.update(model); + } + + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean delete(String id) { + boolean ret; + if(StringUtils.isEmpty(id)){ + return false; + } + + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("org_id", id); + Integer count = mapper.hasUse(queryWrapper); + if(count > 0){ + // 组织机构已被引用,不能删除 + throw new ServiceException(SystemMsg.EXCEPTION_ORG_USE); + } + + ret = super.delete(id); + // 删除子数据 + this.deleteByParentId(id); + return ret; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean deleteAll(String[] ids) { + boolean ret; + if(ArrayUtils.isEmpty(ids)){ + return false; + } + + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.in("org_id", Convert.toList(String.class, ids)); + Integer count = mapper.hasUse(queryWrapper); + if(count > 0){ + // 组织机构已被引用,不能删除 + throw new ServiceException(SystemMsg.EXCEPTION_ORG_USE); + } + + 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 menuList = super.findList(queryWrapper); + for (SysOrg sysOrg : menuList) { + super.delete(sysOrg.getId()); + // 逐级删除子数据 + ret = this.deleteByParentId(sysOrg.getId()); + } + return ret; + } + + /** + * 唯一验证 + * @param entity + * @return + */ + @Transactional(readOnly = true) + public Integer uniqueVerificationByCode(SysOrg entity){ + QueryWrapper wrapper = new QueryWrapper<>(); + + // code 唯一 + wrapper.eq("org_code", entity.getOrgCode()) + .eq(MyBatisConstants.FIELD_DELETE_LOGIC, "0"); + + // 如果为修改 则跳过当前数据 + if(StringUtils.isNotBlank(entity.getId())){ + wrapper.notIn(MyBatisConstants.FIELD_ID, entity.getId()); + } + + // 租户检测 + wrapper = new TenantHandler().handler(super.entityClazz, wrapper); + + 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/org/web/SysOrgRestController.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/web/SysOrgRestController.java new file mode 100755 index 0000000..24d3382 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/org/web/SysOrgRestController.java @@ -0,0 +1,437 @@ +/** +* 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.org.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.Maps; +import com.google.common.collect.Sets; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.opsli.api.base.result.ResultVo; +import org.opsli.api.web.system.org.SysOrgRestApi; +import org.opsli.api.wrapper.system.org.SysOrgModel; +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.common.utils.WrapperUtil; +import org.opsli.core.base.concroller.BaseRestController; +import org.opsli.core.base.entity.HasChildren; +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.org.entity.SysOrg; +import org.opsli.modulars.system.org.service.ISysOrgService; +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.org.web +* @Author: Parker +* @CreateTime: 2020-11-28 18:59:59 +* @Description: 组织机构表 Controller +*/ +@Slf4j +@ApiRestController("/sys/org") +public class SysOrgRestController extends BaseRestController + implements SysOrgRestApi { + + /** 显示全部 */ + public static final String ORG_ALL = "all"; + /** 未分组 */ + public static final String ORG_NULL = "org_null"; + + /** + * 获得组织树 懒加载 + * @return ResultVo + */ + @ApiOperation(value = "获得组织树 懒加载", notes = "获得组织树 懒加载") + @Override + public ResultVo findTreeLazyByUser(String parentId) { + + QueryBuilder queryBuilder = new GenQueryBuilder<>(); + QueryWrapper wrapper = queryBuilder.build(); + wrapper.eq(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId); + + // 获得用户 对应菜单 + List dataList = IService.findList(wrapper); + List orgModelList = WrapperUtil.transformInstance(dataList, SysOrgModel.class); + // 0 为初始值 + if("0".equals(parentId)){ + // 显示全部 + SysOrgModel orgAll = new SysOrgModel(); + orgAll.setId(ORG_ALL); + orgAll.setOrgCode("-2"); + orgAll.setOrgName("全部"); + orgAll.setOrgType("-2"); + orgAll.setParentId("0"); + orgAll.setSortNo(-2); + orgModelList.add(orgAll); + + // 未分组 + SysOrgModel orgNull = new SysOrgModel(); + orgNull.setId(ORG_NULL); + orgNull.setOrgCode("-1"); + orgNull.setOrgName("未分组"); + orgNull.setOrgType("-1"); + orgNull.setParentId("0"); + orgNull.setSortNo(-1); + orgModelList.add(orgNull); + } + + //配置 + TreeNodeConfig treeNodeConfig = new TreeNodeConfig(); + // 自定义属性名 都要默认值的 + treeNodeConfig.setWeightKey("sortNo"); + treeNodeConfig.setNameKey("orgName"); + // 最大递归深度 最多支持4层菜单 + treeNodeConfig.setDeep(3); + + //转换器 + List> treeNodes = TreeUtil.build(orgModelList, parentId, treeNodeConfig, + (treeNode, tree) -> { + tree.setId(treeNode.getId()); + tree.setParentId(treeNode.getParentId()); + tree.setWeight(treeNode.getSortNo()); + tree.setName(treeNode.getOrgName()); + // 扩展属性 ... + // 不是外链 则处理组件 + tree.putExtra("orgCode", treeNode.getOrgCode()); + tree.putExtra("orgType", treeNode.getOrgType()); + tree.putExtra("version", treeNode.getVersion()); + tree.putExtra("tenantId", treeNode.getTenantId()); + }); + + 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); + } + + + /** + * 获得组织树 懒加载 + * @return ResultVo + */ + @ApiOperation(value = "获得组织树 懒加载", notes = "获得组织树 懒加载") + @Override + public ResultVo findTreeLazy(String parentId) { + + QueryBuilder queryBuilder = new GenQueryBuilder<>(); + QueryWrapper wrapper = queryBuilder.build(); + wrapper.eq(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId); + + // 获得用户 对应菜单 + List dataList = IService.findList(wrapper); + List orgModelList = WrapperUtil.transformInstance(dataList, SysOrgModel.class); + + + //配置 + TreeNodeConfig treeNodeConfig = new TreeNodeConfig(); + // 自定义属性名 都要默认值的 + treeNodeConfig.setWeightKey("sortNo"); + treeNodeConfig.setNameKey("orgName"); + // 最大递归深度 最多支持4层菜单 + treeNodeConfig.setDeep(3); + + //转换器 + List> treeNodes = TreeUtil.build(orgModelList, parentId, treeNodeConfig, + (treeNode, tree) -> { + tree.setId(treeNode.getId()); + tree.setParentId(treeNode.getParentId()); + tree.setWeight(treeNode.getSortNo()); + tree.setName(treeNode.getOrgName()); + // 扩展属性 ... + // 不是外链 则处理组件 + tree.putExtra("orgCode", treeNode.getOrgCode()); + tree.putExtra("orgType", treeNode.getOrgType()); + tree.putExtra("version", treeNode.getVersion()); + tree.putExtra("tenantId", treeNode.getTenantId()); + }); + + 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); + } + + /** + * 获得组织树树 + * @return ResultVo + */ + @ApiOperation(value = "获得组织树", notes = "获得组织树") + @Override + public ResultVo findGridTree(String parentId) { + + QueryBuilder queryBuilder = new GenQueryBuilder<>(); + QueryWrapper wrapper = queryBuilder.build(); + wrapper.eq(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId); + + // 获得用户 对应菜单 + List dataList = IService.findList(wrapper); + List orgModelList = WrapperUtil.transformInstance(dataList, SysOrgModel.class); + + + //配置 + TreeNodeConfig treeNodeConfig = new TreeNodeConfig(); + // 自定义属性名 都要默认值的 + treeNodeConfig.setWeightKey("sortNo"); + treeNodeConfig.setNameKey("orgName"); + // 最大递归深度 最多支持4层菜单 + treeNodeConfig.setDeep(3); + + //转换器 + List> treeNodes = TreeUtil.build(orgModelList, parentId, treeNodeConfig, + (treeNode, tree) -> { + tree.setId(treeNode.getId()); + tree.setParentId(treeNode.getParentId()); + tree.setWeight(treeNode.getSortNo()); + tree.setName(treeNode.getOrgName()); + // 扩展属性 ... + // 不是外链 则处理组件 + tree.putExtra("orgCode", treeNode.getOrgCode()); + tree.putExtra("orgType", treeNode.getOrgType()); + tree.putExtra("version", treeNode.getVersion()); + tree.putExtra("tenantId", treeNode.getTenantId()); + }); + + return ResultVo.success(treeNodes); + } + + // ============== + + /** + * 组织机构 查一条 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "获得单条组织机构", notes = "获得单条组织机构 - ID") + @RequiresPermissions("system_org_select") + @Override + public ResultVo get(SysOrgModel model) { + // 如果系统内部调用 则直接查数据库 + if(model != null && model.getIzApi() != null && model.getIzApi()){ + model = IService.get(model); + } + return ResultVo.success(model); + } + + /** + * 获得组织树树 + * @return ResultVo + */ + @ApiOperation(value = "获得菜单树", notes = "获得菜单树") + @RequiresPermissions("system_org_select") + @Override + public ResultVo findTree(HttpServletRequest request) { + + QueryBuilder queryBuilder = new WebQueryBuilder<>(SysOrg.class, + request.getParameterMap()); + + + // 获得用户 对应菜单 + List dataList = IService.findList(queryBuilder.build()); + + //配置 + TreeNodeConfig treeNodeConfig = new TreeNodeConfig(); + // 自定义属性名 都要默认值的 + treeNodeConfig.setWeightKey("sortNo"); + treeNodeConfig.setNameKey("orgName"); + // 最大递归深度 最多支持4层菜单 + treeNodeConfig.setDeep(3); + + //转换器 + List> treeNodes = TreeUtil.build(dataList, "0", treeNodeConfig, + (treeNode, tree) -> { + tree.setId(treeNode.getId()); + tree.setParentId(treeNode.getParentId()); + tree.setWeight(treeNode.getSortNo()); + tree.setName(treeNode.getOrgName()); + // 扩展属性 ... + // 不是外链 则处理组件 + tree.putExtra("orgCode", treeNode.getOrgCode()); + tree.putExtra("orgType", treeNode.getOrgType()); + tree.putExtra("version", treeNode.getVersion()); + tree.putExtra("tenantId", treeNode.getTenantId()); + }); + + return ResultVo.success(treeNodes); + } + + /** + * 组织机构 新增 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "新增组织机构数据", notes = "新增组织机构数据") + @RequiresPermissions("system_org_insert") + @EnableLog + @Override + public ResultVo insert(SysOrgModel model) { + // 演示模式 不允许操作 + //super.demoError(); + + // 调用新增方法 + IService.insert(model); + return ResultVo.success("新增组织机构成功"); + } + + /** + * 组织机构 修改 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "修改组织机构数据", notes = "修改组织机构数据") + @RequiresPermissions("system_org_update") + @EnableLog + @Override + public ResultVo update(SysOrgModel model) { + // 演示模式 不允许操作 + super.demoError(); + + // 调用修改方法 + IService.update(model); + return ResultVo.success("修改组织机构成功"); + } + + + /** + * 组织机构 删除 + * @param id ID + * @return ResultVo + */ + @ApiOperation(value = "删除组织机构数据", notes = "删除组织机构数据") + @RequiresPermissions("system_org_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_org_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_org_export") + @EnableLog + @Override + public ResultVo exportExcel(HttpServletRequest request, HttpServletResponse response) { + QueryBuilder queryBuilder = new WebQueryBuilder<>(SysOrg.class, request.getParameterMap()); + return super.excelExport(SysOrgRestApi.TITLE, queryBuilder.build(), response); + } + + /** + * 组织机构 Excel 导入 + * @param request 文件流 request + * @return ResultVo + */ + @ApiOperation(value = "导入Excel", notes = "导入Excel") + @RequiresPermissions("system_org_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_org_import") + @Override + public ResultVo importTemplate(HttpServletResponse response) { + return super.importTemplate(SysOrgRestApi.TITLE, response); + } + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/entity/SysUserAndOrg.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/entity/SysUserAndOrg.java new file mode 100644 index 0000000..1413864 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/entity/SysUserAndOrg.java @@ -0,0 +1,92 @@ +/** + * 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.user.entity; + +import com.baomidou.mybatisplus.annotation.FieldStrategy; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableLogic; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.opsli.api.wrapper.system.user.UserOrgRefModel; +import org.opsli.core.base.entity.BaseEntity; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.entity + * @Author: Parker + * @CreateTime: 2020-09-16 17:33 + * @Description: 用户信息表 + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class SysUserAndOrg extends BaseEntity { + + + /** 登录账户 */ + private String username; + + /** 登录密码 */ + private String password; + + /** 盐值,密码秘钥 */ + private String secretKey; + + /** 是否锁定 */ + private String locked; + + /** 真实姓名 */ + private String realName; + + /** 手机 */ + @TableField(updateStrategy = FieldStrategy.IGNORED) + private String mobile; + + /** 邮箱 */ + @TableField(updateStrategy = FieldStrategy.IGNORED) + private String email; + + /** 工号 */ + private String no; + + /** 头像 */ + private String avatar; + + /** 最后登陆IP */ + private String loginIp; + + /** 备注 */ + @TableField(updateStrategy = FieldStrategy.IGNORED) + private String remark; + + /** 签名 */ + @TableField(updateStrategy = FieldStrategy.IGNORED) + private String sign; + + /** 组织机构 */ + private UserOrgRefModel org; + + // ======================================== + + /** 逻辑删除字段 */ + @TableLogic + private Integer deleted; + + /** 多租户字段 */ + private String tenantId; + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/entity/SysUserOrgRef.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/entity/SysUserOrgRef.java new file mode 100644 index 0000000..7740fc6 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/entity/SysUserOrgRef.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.user.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.entity + * @Author: Parker + * @CreateTime: 2020-09-16 17:33 + * @Description: 用户表 - 组织表 + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class SysUserOrgRef implements Serializable { + + /** ID */ + @TableId + private String id; + + /** 用户ID */ + private String userId; + + /** 组织ID */ + private String orgId; + + /** 组织类型 */ + private String orgType; + + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/UserMapper.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/UserMapper.java index ddb6b56..abdfd15 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/UserMapper.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/UserMapper.java @@ -15,12 +15,15 @@ */ package org.opsli.modulars.system.user.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.api.wrapper.system.user.UserPassword; import org.opsli.modulars.system.menu.entity.SysMenu; +import org.opsli.modulars.system.org.entity.SysOrg; import org.opsli.modulars.system.user.entity.SysUser; +import org.opsli.modulars.system.user.entity.SysUserAndOrg; import java.util.List; @@ -97,4 +100,11 @@ public interface UserMapper extends BaseMapper { * @return */ boolean updateAvatar(SysUser entity); + + + /** + * 查询集合 + * @return + */ + List findList(@Param("ew") Wrapper wrapper); } diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/UserOrgRefMapper.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/UserOrgRefMapper.java new file mode 100644 index 0000000..babadd2 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/UserOrgRefMapper.java @@ -0,0 +1,34 @@ +/** + * 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.user.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.opsli.modulars.system.user.entity.SysUserOrgRef; + + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.mapper + * @Author: Parker + * @CreateTime: 2020-09-17 13:01 + * @Description: 用户组织 Mapper + */ +@Mapper +public interface UserOrgRefMapper extends BaseMapper { + + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/xml/UserMapper.xml b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/xml/UserMapper.xml index 5018250..ebcca98 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/xml/UserMapper.xml +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/xml/UserMapper.xml @@ -3,7 +3,7 @@ - + a.id as id, a.username as username, @@ -27,9 +27,30 @@ a.deleted as deleted - + + ,b.org_id as 'org.companyId', + c.org_id as 'org.departmentId', + d.org_id as 'org.postId' + + left join sys_user_org_ref b on b.user_id = a.id and b.org_type = '1' + left join sys_user_org_ref c on c.user_id = a.id and c.org_type = '2' + left join sys_user_org_ref d on d.user_id = a.id and d.org_type = '3' + + + +