From 4afe983ff5bd6be564043305c9e18ff502cfdd33 Mon Sep 17 00:00:00 2001 From: Carina Date: Sat, 12 Jun 2021 01:36:51 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E7=BB=84?= =?UTF-8?q?=E7=BB=87=E6=9E=B6=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db-file/opsli-boot.sql | 80 +++-- .../api/web/system/org/SysOrgRestApi.java | 31 +- .../opsli/api/web/system/user/UserApi.java | 13 +- .../api/web/system/user/UserOrgRefApi.java | 12 +- .../api/wrapper/system/org/SysOrgModel.java | 26 +- .../api/wrapper/system/user/UserModel.java | 7 + .../wrapper/system/user/UserOrgRefModel.java | 37 +- .../system/user/UserOrgRefWebModel.java | 53 +++ ...UserAndOrgModel.java => UserWebModel.java} | 8 +- .../common/constants/MyBatisConstants.java | 4 + .../opsli/common/constants/TreeConstants.java | 33 ++ .../base/controller/BaseRestController.java | 74 +++- .../opsli/core/base/entity/BaseEntity.java | 2 +- .../base/service/impl/CrudServiceImpl.java | 23 +- .../cache/pushsub/msgs/OrgMsgFactory.java | 5 +- .../cache/pushsub/msgs/TenantMsgFactory.java | 1 - .../querybuilder/WebQueryBuilder.java | 14 + .../querybuilder/chain/QueryOrgHandler.java | 71 ++++ ...ntHandler.java => QueryTenantHandler.java} | 16 +- .../java/org/opsli/core/utils/OrgUtil.java | 172 +++++++-- .../modulars/system/area/entity/SysArea.java | 2 +- .../area/web/SysAreaRestController.java | 42 +-- .../modulars/system/dict/entity/SysDict.java | 2 +- .../system/dict/entity/SysDictDetail.java | 2 +- .../modulars/system/menu/entity/SysMenu.java | 2 +- .../system/menu/web/MenuRestController.java | 126 ++----- .../modulars/system/org/entity/SysOrg.java | 12 +- .../org/service/impl/SysOrgServiceImpl.java | 111 ++++-- .../system/org/web/SysOrgRestController.java | 328 +++++++++--------- .../modulars/system/role/entity/SysRole.java | 2 +- .../role/service/impl/RoleServiceImpl.java | 23 +- .../system/tenant/entity/SysTenant.java | 2 +- .../modulars/system/user/entity/SysUser.java | 5 +- .../system/user/entity/SysUserOrgRef.java | 8 +- .../{SysUserAndOrg.java => SysUserWeb.java} | 10 +- .../system/user/mapper/UserMapper.java | 4 +- .../system/user/mapper/xml/UserMapper.xml | 9 +- .../user/service/IUserOrgRefService.java | 10 +- .../system/user/service/IUserService.java | 6 +- .../service/impl/UserOrgRefServiceImpl.java | 166 +++++++-- .../user/service/impl/UserServiceImpl.java | 51 ++- .../user/web/UserOrgRefRestController.java | 20 +- .../system/user/web/UserRestController.java | 148 ++++---- .../gentest/carinfo/entity/TestCar.java | 2 +- .../gentest/user/entity/TestUser.java | 2 +- .../modulars/test/entity/TestEntity.java | 2 +- 46 files changed, 1131 insertions(+), 648 deletions(-) create mode 100644 opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserOrgRefWebModel.java rename opsli-api/src/main/java/org/opsli/api/wrapper/system/user/{UserAndOrgModel.java => UserWebModel.java} (95%) create mode 100644 opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/TreeConstants.java create mode 100644 opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/chain/QueryOrgHandler.java rename opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/chain/{TenantHandler.java => QueryTenantHandler.java} (93%) rename opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/entity/{SysUserAndOrg.java => SysUserWeb.java} (89%) diff --git a/db-file/opsli-boot.sql b/db-file/opsli-boot.sql index eac8ff2..ff939a4 100644 --- a/db-file/opsli-boot.sql +++ b/db-file/opsli-boot.sql @@ -11,7 +11,7 @@ Target Server Version : 50733 File Encoding : 65001 - Date: 07/06/2021 11:01:05 + Date: 12/06/2021 01:33:50 */ SET NAMES utf8mb4; @@ -208,18 +208,18 @@ CREATE TABLE `gen_template_detail` ( -- ---------------------------- -- Records of gen_template_detail -- ---------------------------- -INSERT INTO `gen_template_detail` VALUES (1401734394151141378, 1398253704724828162, '0', '${packageName}/${moduleName}/${subModuleName}/entity', '${model.tableHumpName}Entity.java', '#if(data.subModuleName != null && data.subModuleName != \"\")\npackage #(data.packageName+\".\"+data.moduleName+\".\"+data.subModuleName).entity;\n#else\npackage #(data.packageName+\".\"+data.moduleName).entity;\n#end\n\n#for(pkg : data.model.entityPkgList)\nimport #(pkg);\n#end\nimport com.baomidou.mybatisplus.annotation.FieldStrategy;\nimport com.baomidou.mybatisplus.annotation.TableField;\nimport com.baomidou.mybatisplus.annotation.TableLogic;\nimport lombok.Data;\nimport lombok.EqualsAndHashCode;\nimport org.opsli.core.base.entity.BaseEntity;\n\n/**\n * #(data.codeTitle) Entity\n *\n * @author #(data.authorName)\n * @date #(currTime)\n */\n@Data\n@EqualsAndHashCode(callSuper = false)\npublic class #(data.model.tableHumpName) extends BaseEntity {\n\n\n #for(column : data.model.columnList)\n ### 不等于 删除字段 和 不等于 租户字段放入上边\n #if(column.fieldHumpName != \"deleted\" && column.fieldHumpName != \"tenantId\")\n /** #(column.fieldComments) */\n #if(!column.izNotNull)\n @TableField(updateStrategy = FieldStrategy.IGNORED)\n #end\n private #(column.javaType) #(column.fieldHumpName);\n\n #end\n #end\n\n // ========================================\n\n ### 专门处理 删除字段 和 租户字段\n #for(column : data.model.columnList)\n #if(column.fieldHumpName == \"deleted\")\n /** 逻辑删除字段 */\n @TableLogic\n private Integer deleted;\n #else if(column.fieldHumpName == \"tenantId\")\n /** 多租户字段 */\n private String tenantId;\n #end\n\n #end\n\n}', '1', 0, 1, '2021-06-07 10:54:57', 1, '2021-06-07 10:54:57'); -INSERT INTO `gen_template_detail` VALUES (1401734394184695810, 1398253704724828162, '0', '${packageName}/${moduleName}/${subModuleName}/mapper', '${model.tableHumpName}Mapper.java', '#if(data.subModuleName != null && data.subModuleName != \"\")\npackage #(data.packageName+\".\"+data.moduleName+\".\"+data.subModuleName).mapper;\n#else\npackage #(data.packageName+\".\"+data.moduleName).mapper;\n#end\n\nimport com.baomidou.mybatisplus.core.mapper.BaseMapper;\nimport org.apache.ibatis.annotations.Mapper;\nimport org.apache.ibatis.annotations.Param;\n#if(data.subModuleName != null && data.subModuleName != \"\")\nimport #(data.packageName+\".\"+data.moduleName+\".\"+data.subModuleName).entity.#(data.model.tableHumpName);\n#else\nimport #(data.packageName+\".\"+data.moduleName).entity.#(data.model.tableHumpName);\n#end\n\n/**\n * #(data.codeTitle) Mapper\n *\n * @author #(data.authorName)\n * @date #(currTime)\n */\n@Mapper\npublic interface #(data.model.tableHumpName)Mapper extends BaseMapper<#(data.model.tableHumpName)> {\n\n}', '0', 0, 1, '2021-06-07 10:54:57', 1, '2021-06-07 10:54:57'); -INSERT INTO `gen_template_detail` VALUES (1401734394222444546, 1398253704724828162, '0', '${packageName}/${moduleName}/${subModuleName}/mapper/xml', '${model.tableHumpName}Mapper.xml', '\n\n#if(data.subModuleName != null && data.subModuleName != \"\")\n\n#else\n\n#end\n\n\n', '0', 0, 1, '2021-06-07 10:54:57', 1, '2021-06-07 10:54:57'); -INSERT INTO `gen_template_detail` VALUES (1401734394318913537, 1398253704724828162, '0', 'org/opsli/api/wrapper/${moduleName}/${subModuleName}', '${model.tableHumpName}Model.java', '#if(data.subModuleName != null && data.subModuleName != \"\")\npackage #(apiPath).wrapper.#(data.moduleName+\".\"+data.subModuleName);\n#else\npackage #(apiPath).wrapper.#(data.moduleName);\n#end\n\n#for(pkg : data.model.entityPkgList)\nimport #(pkg);\n#end\nimport com.alibaba.excel.annotation.ExcelProperty;\nimport io.swagger.annotations.ApiModelProperty;\nimport lombok.Data;\nimport lombok.EqualsAndHashCode;\nimport #(apiPath).base.warpper.ApiWrapper;\nimport org.opsli.common.annotation.validator.Validator;\nimport org.opsli.common.annotation.validator.ValidatorLenMax;\nimport org.opsli.common.annotation.validator.ValidatorLenMin;\nimport org.opsli.common.enums.ValidatorType;\nimport org.opsli.plugins.excel.annotation.ExcelInfo;\nimport com.fasterxml.jackson.databind.ser.std.ToStringSerializer;\nimport com.fasterxml.jackson.databind.annotation.JsonSerialize;\nimport com.fasterxml.jackson.annotation.JsonFormat;\nimport org.springframework.format.annotation.DateTimeFormat;\n\n/**\n* #(data.codeTitle) Model\n*\n* @author #(data.authorName)\n* @date #(currTime)\n*/\n@Data\n@EqualsAndHashCode(callSuper = false)\npublic class #(data.model.tableHumpName)Model extends ApiWrapper {\n\n #for(column : data.model.columnList)\n ### 不等于 删除字段 和 不等于 租户字段放入上边\n #if(column.fieldHumpName != \"deleted\" && column.fieldHumpName != \"tenantId\")\n /** #(column.fieldComments) */\n @ApiModelProperty(value = \"#(column.fieldComments)\")\n @ExcelProperty(value = \"#(column.fieldComments)\", order = #(column.sort))\n #if(column.dictTypeCode != null && column.dictTypeCode != \"\")\n @ExcelInfo( dictType = \"#(column.dictTypeCode)\" )\n #else\n @ExcelInfo\n #end\n #if(column.validateTypeAndCommaList != null && column.validateTypeAndCommaList.size() > 0)\n @Validator({\n #for(typeAndComma : column.validateTypeAndCommaList)\n ValidatorType.#(typeAndComma)\n #end\n })\n #end\n #if(column.fieldLength != null && column.fieldLength > 0)\n #if(column.fieldPrecision != null && column.fieldPrecision > 0)\n @ValidatorLenMax(#(column.fieldLength+column.fieldPrecision))\n #else\n @ValidatorLenMax(#(column.fieldLength))\n #end\n #end\n ### 日期处理\n #if(column.javaType == \"Date\")\n #if(column.showType == \"4\")\n @JsonFormat(timezone = \"GMT+8\", pattern = \"yyyy-MM-dd\")\n @DateTimeFormat(pattern = \"yyyy-MM-dd\")\n #else\n @JsonFormat(timezone = \"GMT+8\", pattern = \"yyyy-MM-dd HH:mm:ss\")\n @DateTimeFormat(pattern = \"yyyy-MM-dd HH:mm:ss\")\n #end\n #else if(column.javaType == \"Long\" || column.javaType == \"long\")\n @JsonSerialize(using= ToStringSerializer.class)\n #end\n private #(column.javaType) #(column.fieldHumpName);\n\n #end\n #end\n\n\n}', '0', 0, 1, '2021-06-07 10:54:57', 1, '2021-06-07 10:54:57'); -INSERT INTO `gen_template_detail` VALUES (1401734394348273665, 1398253704724828162, '0', 'org/opsli/api/web/${moduleName}/${subModuleName}', '${model.tableHumpName}RestApi.java', '#if(data.subModuleName != null && data.subModuleName != \"\")\npackage #(apiPath).web.#(data.moduleName+\".\"+data.subModuleName);\n#else\npackage #(apiPath).web.#(data.moduleName);\n#end\n\nimport #(apiPath).base.result.ResultVo;\nimport org.springframework.web.bind.annotation.GetMapping;\nimport org.springframework.web.bind.annotation.PostMapping;\nimport org.springframework.web.bind.annotation.RequestBody;\nimport org.springframework.web.bind.annotation.RequestParam;\nimport org.springframework.web.multipart.MultipartHttpServletRequest;\nimport javax.servlet.http.HttpServletRequest;\nimport javax.servlet.http.HttpServletResponse;\n\n#if(data.subModuleName != null && data.subModuleName != \"\")\nimport #(apiPath).wrapper.#(data.moduleName+\".\"+data.subModuleName).#(data.model.tableHumpName)Model;\n#else\nimport #(apiPath).wrapper.#(data.moduleName).#(data.model.tableHumpName)Model;\n#end\n\n\n/**\n * #(data.codeTitle) Api\n *\n * 对外 API 直接 暴露 @GetMapping 或者 @PostMapping\n * 对内也推荐 单机版 不需要设置 Mapping 但是调用方法得从Controller写起\n *\n * 这样写法虽然比较绕,但是当单体项目想要改造微服务架构时 时非常容易的\n *\n * @author #(data.authorName)\n * @date #(currTime)\n */\npublic interface #(data.model.tableHumpName)RestApi {\n\n /** 标题 */\n String TITLE = \"#(data.codeTitle)\";\n /** 子标题 */\n String SUB_TITLE = \"#(data.codeTitleBrief)\";\n\n /**\n * #(data.codeTitle) 查一条\n * @param model 模型\n * @return ResultVo\n */\n @GetMapping(\"/get\")\n ResultVo<#(data.model.tableHumpName)Model> get(#(data.model.tableHumpName)Model model);\n\n /**\n * #(data.codeTitle) 查询分页\n * @param pageNo 当前页\n * @param pageSize 每页条数\n * @param request request\n * @return ResultVo\n */\n @GetMapping(\"/findPage\")\n ResultVo findPage(\n @RequestParam(name = \"pageNo\", defaultValue = \"1\") Integer pageNo,\n @RequestParam(name = \"pageSize\", defaultValue = \"10\") Integer pageSize,\n HttpServletRequest request\n );\n\n /**\n * #(data.codeTitle) 新增\n * @param model 模型\n * @return ResultVo\n */\n @PostMapping(\"/insert\")\n ResultVo insert(@RequestBody #(data.model.tableHumpName)Model model);\n\n /**\n * #(data.codeTitle) 修改\n * @param model 模型\n * @return ResultVo\n */\n @PostMapping(\"/update\")\n ResultVo update(@RequestBody #(data.model.tableHumpName)Model model);\n\n /**\n * #(data.codeTitle) 删除\n * @param id ID\n * @return ResultVo\n */\n @PostMapping(\"/del\")\n ResultVo del(String id);\n\n /**\n * #(data.codeTitle) 批量删除\n * @param ids ID 数组\n * @return ResultVo\n */\n @PostMapping(\"/delAll\")\n ResultVo delAll(String ids);\n\n /**\n * #(data.codeTitle) Excel 导出\n *\n * 导出时,Token认证和方法权限认证 全部都由自定义完成\n * 因为在 导出不成功时,需要推送错误信息,\n * 前端直接走下载流,当失败时无法获得失败信息,即使前后端换一种方式后端推送二进制文件前端再次解析也是最少2倍的耗时\n * ,且如果数据量过大,前端进行渲染时直接会把浏览器卡死\n * 而直接开启socket接口推送显然是太过浪费资源了,所以目前采用Java最原始的手段\n * response 推送 javascript代码 alert 提示报错信息\n *\n * @param request request\n * @param response response\n */\n @GetMapping(\"/exportExcel\")\n void exportExcel(HttpServletRequest request, HttpServletResponse response);\n\n /**\n * #(data.codeTitle) Excel 导入\n * @param request 文件流 request\n * @return ResultVo\n */\n @PostMapping(\"/importExcel\")\n ResultVo importExcel(MultipartHttpServletRequest request);\n\n /**\n * #(data.codeTitle) Excel 下载导入模版\n * @param response response\n */\n @GetMapping(\"/importExcel/template\")\n void importTemplate(HttpServletResponse response);\n\n}', '0', 0, 1, '2021-06-07 10:54:57', 1, '2021-06-07 10:54:57'); -INSERT INTO `gen_template_detail` VALUES (1401734394390216705, 1398253704724828162, '0', '${packageName}/${moduleName}/${subModuleName}/web', '${model.tableHumpName}RestController.java', '#if(data.subModuleName != null && data.subModuleName != \"\")\npackage #(data.packageName+\".\"+data.moduleName+\".\"+data.subModuleName).web;\n#else\npackage #(data.packageName+\".\"+data.moduleName).web;\n#end\n\nimport cn.hutool.core.util.ReflectUtil;\nimport cn.hutool.core.convert.Convert;\nimport io.swagger.annotations.Api;\nimport io.swagger.annotations.ApiOperation;\nimport lombok.extern.slf4j.Slf4j;\nimport org.opsli.common.annotation.RequiresPermissionsCus;\nimport org.apache.shiro.authz.annotation.RequiresPermissions;\nimport #(apiPath).base.result.ResultVo;\nimport org.opsli.common.annotation.ApiRestController;\nimport org.opsli.common.annotation.EnableLog;\nimport org.opsli.core.base.controller.BaseRestController;\nimport org.opsli.core.persistence.Page;\nimport org.opsli.core.persistence.querybuilder.QueryBuilder;\nimport org.opsli.core.persistence.querybuilder.WebQueryBuilder;\nimport org.springframework.web.multipart.MultipartHttpServletRequest;\nimport javax.servlet.http.HttpServletRequest;\nimport javax.servlet.http.HttpServletResponse;\nimport java.lang.reflect.Method;\n\n#if(data.subModuleName != null && data.subModuleName != \"\")\nimport #(data.packageName+\".\"+data.moduleName+\".\"+data.subModuleName).entity.#(data.model.tableHumpName);\nimport #(apiPath).wrapper.#(data.moduleName+\".\"+data.subModuleName).#(data.model.tableHumpName)Model;\nimport #(data.packageName+\".\"+data.moduleName+\".\"+data.subModuleName).service.I#(data.model.tableHumpName)Service;\nimport #(apiPath).web.#(data.moduleName+\".\"+data.subModuleName).#(data.model.tableHumpName)RestApi;\n#else\nimport #(data.packageName+\".\"+data.moduleName).entity.#(data.model.tableHumpName);\nimport #(apiPath).wrapper.#(data.moduleName).#(data.model.tableHumpName)Model;\nimport #(data.packageName+\".\"+data.moduleName).service.I#(data.model.tableHumpName)Service;\nimport #(apiPath).web.#(data.moduleName).#(data.model.tableHumpName)RestApi;\n#end\n\n/**\n * #(data.codeTitle) Controller\n *\n * @author #(data.authorName)\n * @date #(currTime)\n */\n@Api(tags = #(data.model.tableHumpName)RestApi.TITLE)\n@Slf4j\n#if(data.subModuleName != null && data.subModuleName != \"\")\n@ApiRestController(\"/#(data.moduleName)/#(data.subModuleName)\")\n#else\n@ApiRestController(\"/#(data.moduleName)\")\n#end\npublic class #(data.model.tableHumpName)RestController extends BaseRestController<#(data.model.tableHumpName), #(data.model.tableHumpName)Model, I#(data.model.tableHumpName)Service>\n implements #(data.model.tableHumpName)RestApi {\n\n\n /**\n * #(data.codeTitleBrief) 查一条\n * @param model 模型\n * @return ResultVo\n */\n @ApiOperation(value = \"获得单条#(data.codeTitleBrief)\", notes = \"获得单条#(data.codeTitleBrief) - ID\")\n #if(data.subModuleName != null && data.subModuleName != \"\")\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_select\")\n #else\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_select\")\n #end\n @Override\n public ResultVo<#(data.model.tableHumpName)Model> get(#(data.model.tableHumpName)Model model) {\n // 如果系统内部调用 则直接查数据库\n if(model != null && model.getIzApi() != null && model.getIzApi()){\n model = IService.get(model);\n }\n return ResultVo.success(model);\n }\n\n /**\n * #(data.codeTitleBrief) 查询分页\n * @param pageNo 当前页\n * @param pageSize 每页条数\n * @param request request\n * @return ResultVo\n */\n @ApiOperation(value = \"获得分页数据\", notes = \"获得分页数据 - 查询构造器\")\n #if(data.subModuleName != null && data.subModuleName != \"\")\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_select\")\n #else\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_select\")\n #end\n @Override\n public ResultVo findPage(Integer pageNo, Integer pageSize, HttpServletRequest request) {\n\n QueryBuilder<#(data.model.tableHumpName)> queryBuilder = new WebQueryBuilder<>(entityClazz, request.getParameterMap());\n Page<#(data.model.tableHumpName), #(data.model.tableHumpName)Model> page = new Page<>(pageNo, pageSize);\n page.setQueryWrapper(queryBuilder.build());\n page = IService.findPage(page);\n\n return ResultVo.success(page.getPageData());\n }\n\n /**\n * #(data.codeTitleBrief) 新增\n * @param model 模型\n * @return ResultVo\n */\n @ApiOperation(value = \"新增#(data.codeTitleBrief)数据\", notes = \"新增#(data.codeTitleBrief)数据\")\n #if(data.subModuleName != null && data.subModuleName != \"\")\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_insert\")\n #else\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_insert\")\n #end\n @EnableLog\n @Override\n public ResultVo insert(#(data.model.tableHumpName)Model model) {\n // 调用新增方法\n IService.insert(model);\n return ResultVo.success(\"新增#(data.codeTitleBrief)成功\");\n }\n\n /**\n * #(data.codeTitleBrief) 修改\n * @param model 模型\n * @return ResultVo\n */\n @ApiOperation(value = \"修改#(data.codeTitleBrief)数据\", notes = \"修改#(data.codeTitleBrief)数据\")\n #if(data.subModuleName != null && data.subModuleName != \"\")\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_update\")\n #else\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_update\")\n #end\n @EnableLog\n @Override\n public ResultVo update(#(data.model.tableHumpName)Model model) {\n // 调用修改方法\n IService.update(model);\n return ResultVo.success(\"修改#(data.codeTitleBrief)成功\");\n }\n\n\n /**\n * #(data.codeTitleBrief) 删除\n * @param id ID\n * @return ResultVo\n */\n @ApiOperation(value = \"删除#(data.codeTitleBrief)数据\", notes = \"删除#(data.codeTitleBrief)数据\")\n #if(data.subModuleName != null && data.subModuleName != \"\")\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_update\")\n #else\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_update\")\n #end\n @EnableLog\n @Override\n public ResultVo del(String id){\n IService.delete(id);\n return ResultVo.success(\"删除#(data.codeTitleBrief)成功\");\n }\n\n /**\n * #(data.codeTitleBrief) 批量删除\n * @param ids ID 数组\n * @return ResultVo\n */\n @ApiOperation(value = \"批量删除#(data.codeTitleBrief)数据\", notes = \"批量删除#(data.codeTitleBrief)数据\")\n #if(data.subModuleName != null && data.subModuleName != \"\")\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_update\")\n #else\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_update\")\n #end\n @EnableLog\n @Override\n public ResultVo delAll(String ids){\n String[] idArray = Convert.toStrArray(ids);\n IService.deleteAll(idArray);\n return ResultVo.success(\"批量删除#(data.codeTitleBrief)成功\");\n }\n\n\n /**\n * #(data.codeTitleBrief) Excel 导出\n * 注:这里 RequiresPermissionsCus 引入的是 自定义鉴权注解\n *\n * 导出时,Token认证和方法权限认证 全部都由自定义完成\n * 因为在 导出不成功时,需要推送错误信息,\n * 前端直接走下载流,当失败时无法获得失败信息,即使前后端换一种方式后端推送二进制文件前端再次解析也是最少2倍的耗时\n * ,且如果数据量过大,前端进行渲染时直接会把浏览器卡死\n * 而直接开启socket接口推送显然是太过浪费资源了,所以目前采用Java最原始的手段\n * response 推送 javascript代码 alert 提示报错信息\n *\n * @param request request\n * @param response response\n */\n @ApiOperation(value = \"导出Excel\", notes = \"导出Excel\")\n #if(data.subModuleName != null && data.subModuleName != \"\")\n @RequiresPermissionsCus(\"#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_export\")\n #else\n @RequiresPermissionsCus(\"#(data.moduleName.toLowerCase())_export\")\n #end\n @EnableLog\n @Override\n public void exportExcel(HttpServletRequest request, HttpServletResponse response) {\n // 当前方法\n Method method = ReflectUtil.getMethodByName(this.getClass(), \"exportExcel\");\n QueryBuilder<#(data.model.tableHumpName)> queryBuilder = new WebQueryBuilder<>(entityClazz, request.getParameterMap());\n super.excelExport(#(data.model.tableHumpName)RestApi.SUB_TITLE, queryBuilder.build(), response, method);\n }\n\n /**\n * #(data.codeTitleBrief) Excel 导入\n * 注:这里 RequiresPermissions 引入的是 Shiro原生鉴权注解\n * @param request 文件流 request\n * @return ResultVo\n */\n @ApiOperation(value = \"导入Excel\", notes = \"导入Excel\")\n #if(data.subModuleName != null && data.subModuleName != \"\")\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_import\")\n #else\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_import\")\n #end\n @EnableLog\n @Override\n public ResultVo importExcel(MultipartHttpServletRequest request) {\n return super.importExcel(request);\n }\n\n /**\n * #(data.codeTitleBrief) Excel 下载导入模版\n * 注:这里 RequiresPermissionsCus 引入的是 自定义鉴权注解\n * @param response response\n */\n @ApiOperation(value = \"导出Excel模版\", notes = \"导出Excel模版\")\n #if(data.subModuleName != null && data.subModuleName != \"\")\n @RequiresPermissionsCus(\"#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_import\")\n #else\n @RequiresPermissionsCus(\"#(data.moduleName.toLowerCase())_import\")\n #end\n @Override\n public void importTemplate(HttpServletResponse response) {\n // 当前方法\n Method method = ReflectUtil.getMethodByName(this.getClass(), \"importTemplate\");\n super.importTemplate(#(data.model.tableHumpName)RestApi.SUB_TITLE, response, method);\n }\n\n}', '0', 0, 1, '2021-06-07 10:54:57', 1, '2021-06-07 10:54:57'); -INSERT INTO `gen_template_detail` VALUES (1401734394432159745, 1398253704724828162, '0', '${packageName}/${moduleName}/${subModuleName}/service/impl', '${model.tableHumpName}ServiceImpl.java', '#if(data.subModuleName != null && data.subModuleName != \"\")\npackage #(data.packageName+\".\"+data.moduleName+\".\"+data.subModuleName).service.impl;\n#else\npackage #(data.packageName+\".\"+data.moduleName).service.impl;\n#end\n\n\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.stereotype.Service;\nimport org.springframework.transaction.annotation.Transactional;\nimport org.opsli.core.base.service.impl.CrudServiceImpl;\n\n#if(data.subModuleName != null && data.subModuleName != \"\")\nimport #(data.packageName+\".\"+data.moduleName+\".\"+data.subModuleName).entity.#(data.model.tableHumpName);\nimport #(apiPath).wrapper.#(data.moduleName+\".\"+data.subModuleName).#(data.model.tableHumpName)Model;\nimport #(data.packageName+\".\"+data.moduleName+\".\"+data.subModuleName).service.I#(data.model.tableHumpName)Service;\nimport #(data.packageName+\".\"+data.moduleName+\".\"+data.subModuleName).mapper.#(data.model.tableHumpName)Mapper;\n#else\nimport #(data.packageName+\".\"+data.moduleName).entity.#(data.model.tableHumpName);\nimport #(apiPath).wrapper.#(data.moduleName).#(data.model.tableHumpName)Model;\nimport #(data.packageName+\".\"+data.moduleName).service.I#(data.model.tableHumpName)Service;\nimport #(data.packageName+\".\"+data.moduleName).mapper.#(data.model.tableHumpName)Mapper;\n#end\n\n\n/**\n * #(data.codeTitle) Service Impl\n *\n * @author #(data.authorName)\n * @date #(currTime)\n */\n@Service\npublic class #(data.model.tableHumpName)ServiceImpl extends CrudServiceImpl<#(data.model.tableHumpName)Mapper, #(data.model.tableHumpName), #(data.model.tableHumpName)Model>\n implements I#(data.model.tableHumpName)Service {\n\n @Autowired(required = false)\n private #(data.model.tableHumpName)Mapper mapper;\n\n}', '0', 0, 1, '2021-06-07 10:54:57', 1, '2021-06-07 10:54:57'); -INSERT INTO `gen_template_detail` VALUES (1401734394478297089, 1398253704724828162, '0', '${packageName}/${moduleName}/${subModuleName}/service', 'I${model.tableHumpName}Service.java', '#if(data.subModuleName != null && data.subModuleName != \"\")\npackage #(data.packageName+\".\"+data.moduleName+\".\"+data.subModuleName).service;\n#else\npackage #(data.packageName+\".\"+data.moduleName).service;\n#end\n\nimport org.opsli.core.base.service.interfaces.CrudServiceInterface;\n\n\n#if(data.subModuleName != null && data.subModuleName != \"\")\nimport #(data.packageName+\".\"+data.moduleName+\".\"+data.subModuleName).entity.#(data.model.tableHumpName);\nimport #(apiPath).wrapper.#(data.moduleName+\".\"+data.subModuleName).#(data.model.tableHumpName)Model;\n#else\nimport #(data.packageName+\".\"+data.moduleName).entity.#(data.model.tableHumpName);\nimport #(apiPath).wrapper.#(data.moduleName).#(data.model.tableHumpName)Model;\n#end\n\n/**\n * #(data.codeTitle) Service\n *\n * @author #(data.authorName)\n * @date #(currTime)\n */\npublic interface I#(data.model.tableHumpName)Service extends CrudServiceInterface<#(data.model.tableHumpName), #(data.model.tableHumpName)Model> {\n\n}', '0', 0, 1, '2021-06-07 10:54:57', 1, '2021-06-07 10:54:57'); -INSERT INTO `gen_template_detail` VALUES (1401734394520240129, 1398253704724828162, '1', 'src/api/${moduleName}/${subModuleName}', '${model.tableHumpName}ManagementApi.js', 'import request from \"@/utils/request\";\nimport { downloadFileByData } from \"@/utils/download\";\n\nexport function getList(data) {\n return request({\n #if(data.subModuleName != null && data.subModuleName != \"\")\n url: \"/api/v1/#(data.moduleName)/#(data.subModuleName)/findPage\",\n #else\n url: \"/api/v1/#(data.moduleName)/findPage\",\n #end\n method: \"get\",\n params: data,\n });\n}\n\nexport function doInsert(data) {\n return request({\n #if(data.subModuleName != null && data.subModuleName != \"\")\n url: \"/api/v1/#(data.moduleName)/#(data.subModuleName)/insert\",\n #else\n url: \"/api/v1/#(data.moduleName)/insert\",\n #end\n method: \"post\",\n data,\n });\n}\n\nexport function doUpdate(data) {\n return request({\n #if(data.subModuleName != null && data.subModuleName != \"\")\n url: \"/api/v1/#(data.moduleName)/#(data.subModuleName)/update\",\n #else\n url: \"/api/v1/#(data.moduleName)/update\",\n #end\n method: \"post\",\n data,\n });\n}\n\nexport function doDelete(data) {\n return request({\n #if(data.subModuleName != null && data.subModuleName != \"\")\n url: \"/api/v1/#(data.moduleName)/#(data.subModuleName)/del\",\n #else\n url: \"/api/v1/#(data.moduleName)/del\",\n #end\n method: \"post\",\n params: data,\n });\n}\n\nexport function doDeleteAll(data) {\n return request({\n #if(data.subModuleName != null && data.subModuleName != \"\")\n url: \"/api/v1/#(data.moduleName)/#(data.subModuleName)/delAll\",\n #else\n url: \"/api/v1/#(data.moduleName)/delAll\",\n #end\n method: \"post\",\n params: data,\n });\n}\n\n/**\n * 导出Excel 目前只支持一层参数传递\n * @param data\n * @returns file\n */\nexport function doExportExcel(data) {\n #if(data.subModuleName != null && data.subModuleName != \"\")\n let requestURL = \"/api/v1/#(data.moduleName)/#(data.subModuleName)/exportExcel\";\n #else\n let requestURL = \"/api/v1/#(data.moduleName)/exportExcel\";\n #end\n // 下载文件\n downloadFileByData(requestURL, data);\n}\n\n/**\n * 下载模版\n * @returns file\n */\nexport function doDownloadTemplate() {\n let data = {};\n #if(data.subModuleName != null && data.subModuleName != \"\")\n let requestURL = \"/api/v1/#(data.moduleName)/#(data.subModuleName)/importExcel/template\";\n #else\n let requestURL = \"/api/v1/#(data.moduleName)/importExcel/template\";\n #end\n // 下载文件\n downloadFileByData(requestURL, data);\n}\n\n/**\n * 导入Excel\n * @returns file\n */\nexport function doImportExcel(data) {\n return request({\n #if(data.subModuleName != null && data.subModuleName != \"\")\n url: \"/api/v1/#(data.moduleName)/#(data.subModuleName)/importExcel\",\n #else\n url: \"/api/v1/#(data.moduleName)/importExcel\",\n #end\n method: \"post\",\n // 最长超时时间 3 分钟\n timeout: 180000,\n headers: {\n \"Content-Type\": \"multipart/form-data\"\n },\n data,\n });\n}', '0', 0, 1, '2021-06-07 10:54:57', 1, '2021-06-07 10:54:57'); -INSERT INTO `gen_template_detail` VALUES (1401734394595737601, 1398253704724828162, '1', 'src/views/modules/${moduleName}/${subModuleName}/components', '${model.tableHumpName}ManagementEdit.vue', '\n\n\n', '0', 0, 1, '2021-06-07 10:54:57', 1, '2021-06-07 10:54:57'); -INSERT INTO `gen_template_detail` VALUES (1401734394671235073, 1398253704724828162, '1', 'src/views/modules/${moduleName}/${subModuleName}/components', '${model.tableHumpName}ManagementImport.vue', '\n\n\n', '0', 0, 1, '2021-06-07 10:54:57', 1, '2021-06-07 10:54:57'); -INSERT INTO `gen_template_detail` VALUES (1401734394738343938, 1398253704724828162, '1', 'src/views/modules/${moduleName}/${subModuleName}', 'index.vue', '\n\n\n', '0', 0, 1, '2021-06-07 10:54:57', 1, '2021-06-07 10:54:57'); +INSERT INTO `gen_template_detail` VALUES (1403404813839888386, 1398253704724828162, '0', '${packageName}/${moduleName}/${subModuleName}/entity', '${model.tableHumpName}Entity.java', '#if(data.subModuleName != null && data.subModuleName != \"\")\npackage #(data.packageName+\".\"+data.moduleName+\".\"+data.subModuleName).entity;\n#else\npackage #(data.packageName+\".\"+data.moduleName).entity;\n#end\n\n#for(pkg : data.model.entityPkgList)\nimport #(pkg);\n#end\nimport com.baomidou.mybatisplus.annotation.FieldStrategy;\nimport com.baomidou.mybatisplus.annotation.TableField;\nimport com.baomidou.mybatisplus.annotation.TableLogic;\nimport lombok.Data;\nimport lombok.EqualsAndHashCode;\nimport org.opsli.core.base.entity.BaseEntity;\n\n/**\n * #(data.codeTitle) Entity\n *\n * @author #(data.authorName)\n * @date #(currTime)\n */\n@Data\n@EqualsAndHashCode(callSuper = false)\npublic class #(data.model.tableHumpName) extends BaseEntity {\n\n\n #for(column : data.model.columnList)\n ### 不等于 删除字段 和 不等于 租户字段放入上边\n #if(column.fieldHumpName != \"deleted\" && column.fieldHumpName != \"tenantId\")\n /** #(column.fieldComments) */\n #if(!column.izNotNull)\n @TableField(updateStrategy = FieldStrategy.IGNORED)\n #end\n private #(column.javaType) #(column.fieldHumpName);\n\n #end\n #end\n\n // ========================================\n\n ### 专门处理 删除字段 和 租户字段\n #for(column : data.model.columnList)\n #if(column.fieldHumpName == \"deleted\")\n /** 逻辑删除字段 */\n @TableLogic\n private Integer deleted;\n #else if(column.fieldHumpName == \"tenantId\")\n /** 多租户字段 */\n private String tenantId;\n #end\n\n #end\n\n}', '1', 0, 1, '2021-06-12 01:32:36', 1, '2021-06-12 01:32:36'); +INSERT INTO `gen_template_detail` VALUES (1403404813965717505, 1398253704724828162, '0', '${packageName}/${moduleName}/${subModuleName}/mapper', '${model.tableHumpName}Mapper.java', '#if(data.subModuleName != null && data.subModuleName != \"\")\npackage #(data.packageName+\".\"+data.moduleName+\".\"+data.subModuleName).mapper;\n#else\npackage #(data.packageName+\".\"+data.moduleName).mapper;\n#end\n\nimport com.baomidou.mybatisplus.core.mapper.BaseMapper;\nimport org.apache.ibatis.annotations.Mapper;\nimport org.apache.ibatis.annotations.Param;\n#if(data.subModuleName != null && data.subModuleName != \"\")\nimport #(data.packageName+\".\"+data.moduleName+\".\"+data.subModuleName).entity.#(data.model.tableHumpName);\n#else\nimport #(data.packageName+\".\"+data.moduleName).entity.#(data.model.tableHumpName);\n#end\n\n/**\n * #(data.codeTitle) Mapper\n *\n * @author #(data.authorName)\n * @date #(currTime)\n */\n@Mapper\npublic interface #(data.model.tableHumpName)Mapper extends BaseMapper<#(data.model.tableHumpName)> {\n\n}', '0', 0, 1, '2021-06-12 01:32:36', 1, '2021-06-12 01:32:36'); +INSERT INTO `gen_template_detail` VALUES (1403404814032826370, 1398253704724828162, '0', '${packageName}/${moduleName}/${subModuleName}/mapper/xml', '${model.tableHumpName}Mapper.xml', '\n\n#if(data.subModuleName != null && data.subModuleName != \"\")\n\n#else\n\n#end\n\n\n', '0', 0, 1, '2021-06-12 01:32:36', 1, '2021-06-12 01:32:36'); +INSERT INTO `gen_template_detail` VALUES (1403404814099935234, 1398253704724828162, '0', 'org/opsli/api/wrapper/${moduleName}/${subModuleName}', '${model.tableHumpName}Model.java', '#if(data.subModuleName != null && data.subModuleName != \"\")\npackage #(apiPath).wrapper.#(data.moduleName+\".\"+data.subModuleName);\n#else\npackage #(apiPath).wrapper.#(data.moduleName);\n#end\n\n#for(pkg : data.model.entityPkgList)\nimport #(pkg);\n#end\nimport com.alibaba.excel.annotation.ExcelProperty;\nimport io.swagger.annotations.ApiModelProperty;\nimport lombok.Data;\nimport lombok.EqualsAndHashCode;\nimport #(apiPath).base.warpper.ApiWrapper;\nimport org.opsli.common.annotation.validator.Validator;\nimport org.opsli.common.annotation.validator.ValidatorLenMax;\nimport org.opsli.common.annotation.validator.ValidatorLenMin;\nimport org.opsli.common.enums.ValidatorType;\nimport org.opsli.plugins.excel.annotation.ExcelInfo;\nimport com.fasterxml.jackson.annotation.JsonFormat;\nimport org.springframework.format.annotation.DateTimeFormat;\n\n/**\n* #(data.codeTitle) Model\n*\n* @author #(data.authorName)\n* @date #(currTime)\n*/\n@Data\n@EqualsAndHashCode(callSuper = false)\npublic class #(data.model.tableHumpName)Model extends ApiWrapper {\n\n #for(column : data.model.columnList)\n ### 不等于 删除字段 和 不等于 租户字段放入上边\n #if(column.fieldHumpName != \"deleted\" && column.fieldHumpName != \"tenantId\")\n /** #(column.fieldComments) */\n @ApiModelProperty(value = \"#(column.fieldComments)\")\n @ExcelProperty(value = \"#(column.fieldComments)\", order = #(column.sort))\n #if(column.dictTypeCode != null && column.dictTypeCode != \"\")\n @ExcelInfo( dictType = \"#(column.dictTypeCode)\" )\n #else\n @ExcelInfo\n #end\n #if(column.validateTypeAndCommaList != null && column.validateTypeAndCommaList.size() > 0)\n @Validator({\n #for(typeAndComma : column.validateTypeAndCommaList)\n ValidatorType.#(typeAndComma)\n #end\n })\n #end\n #if(column.fieldLength != null && column.fieldLength > 0)\n #if(column.fieldPrecision != null && column.fieldPrecision > 0)\n @ValidatorLenMax(#(column.fieldLength+column.fieldPrecision))\n #else\n @ValidatorLenMax(#(column.fieldLength))\n #end\n #end\n ### 日期处理\n #if(column.javaType == \"Date\")\n #if(column.showType == \"4\")\n @JsonFormat(timezone = \"GMT+8\", pattern = \"yyyy-MM-dd\")\n @DateTimeFormat(pattern = \"yyyy-MM-dd\")\n #else\n @JsonFormat(timezone = \"GMT+8\", pattern = \"yyyy-MM-dd HH:mm:ss\")\n @DateTimeFormat(pattern = \"yyyy-MM-dd HH:mm:ss\")\n #end\n #end\n private #(column.javaType) #(column.fieldHumpName);\n\n #end\n #end\n\n\n}', '0', 0, 1, '2021-06-12 01:32:36', 1, '2021-06-12 01:32:36'); +INSERT INTO `gen_template_detail` VALUES (1403404814171238402, 1398253704724828162, '0', 'org/opsli/api/web/${moduleName}/${subModuleName}', '${model.tableHumpName}RestApi.java', '#if(data.subModuleName != null && data.subModuleName != \"\")\npackage #(apiPath).web.#(data.moduleName+\".\"+data.subModuleName);\n#else\npackage #(apiPath).web.#(data.moduleName);\n#end\n\nimport #(apiPath).base.result.ResultVo;\nimport org.springframework.web.bind.annotation.GetMapping;\nimport org.springframework.web.bind.annotation.PostMapping;\nimport org.springframework.web.bind.annotation.RequestBody;\nimport org.springframework.web.bind.annotation.RequestParam;\nimport org.springframework.web.multipart.MultipartHttpServletRequest;\nimport javax.servlet.http.HttpServletRequest;\nimport javax.servlet.http.HttpServletResponse;\n\n#if(data.subModuleName != null && data.subModuleName != \"\")\nimport #(apiPath).wrapper.#(data.moduleName+\".\"+data.subModuleName).#(data.model.tableHumpName)Model;\n#else\nimport #(apiPath).wrapper.#(data.moduleName).#(data.model.tableHumpName)Model;\n#end\n\n\n/**\n * #(data.codeTitle) Api\n *\n * 对外 API 直接 暴露 @GetMapping 或者 @PostMapping\n * 对内也推荐 单机版 不需要设置 Mapping 但是调用方法得从Controller写起\n *\n * 这样写法虽然比较绕,但是当单体项目想要改造微服务架构时 时非常容易的\n *\n * @author #(data.authorName)\n * @date #(currTime)\n */\npublic interface #(data.model.tableHumpName)RestApi {\n\n /** 标题 */\n String TITLE = \"#(data.codeTitle)\";\n /** 子标题 */\n String SUB_TITLE = \"#(data.codeTitleBrief)\";\n\n /**\n * #(data.codeTitle) 查一条\n * @param model 模型\n * @return ResultVo\n */\n @GetMapping(\"/get\")\n ResultVo<#(data.model.tableHumpName)Model> get(#(data.model.tableHumpName)Model model);\n\n /**\n * #(data.codeTitle) 查询分页\n * @param pageNo 当前页\n * @param pageSize 每页条数\n * @param request request\n * @return ResultVo\n */\n @GetMapping(\"/findPage\")\n ResultVo findPage(\n @RequestParam(name = \"pageNo\", defaultValue = \"1\") Integer pageNo,\n @RequestParam(name = \"pageSize\", defaultValue = \"10\") Integer pageSize,\n HttpServletRequest request\n );\n\n /**\n * #(data.codeTitle) 新增\n * @param model 模型\n * @return ResultVo\n */\n @PostMapping(\"/insert\")\n ResultVo insert(@RequestBody #(data.model.tableHumpName)Model model);\n\n /**\n * #(data.codeTitle) 修改\n * @param model 模型\n * @return ResultVo\n */\n @PostMapping(\"/update\")\n ResultVo update(@RequestBody #(data.model.tableHumpName)Model model);\n\n /**\n * #(data.codeTitle) 删除\n * @param id ID\n * @return ResultVo\n */\n @PostMapping(\"/del\")\n ResultVo del(String id);\n\n /**\n * #(data.codeTitle) 批量删除\n * @param ids ID 数组\n * @return ResultVo\n */\n @PostMapping(\"/delAll\")\n ResultVo delAll(String ids);\n\n /**\n * #(data.codeTitle) Excel 导出\n *\n * 导出时,Token认证和方法权限认证 全部都由自定义完成\n * 因为在 导出不成功时,需要推送错误信息,\n * 前端直接走下载流,当失败时无法获得失败信息,即使前后端换一种方式后端推送二进制文件前端再次解析也是最少2倍的耗时\n * ,且如果数据量过大,前端进行渲染时直接会把浏览器卡死\n * 而直接开启socket接口推送显然是太过浪费资源了,所以目前采用Java最原始的手段\n * response 推送 javascript代码 alert 提示报错信息\n *\n * @param request request\n * @param response response\n */\n @GetMapping(\"/exportExcel\")\n void exportExcel(HttpServletRequest request, HttpServletResponse response);\n\n /**\n * #(data.codeTitle) Excel 导入\n * @param request 文件流 request\n * @return ResultVo\n */\n @PostMapping(\"/importExcel\")\n ResultVo importExcel(MultipartHttpServletRequest request);\n\n /**\n * #(data.codeTitle) Excel 下载导入模版\n * @param response response\n */\n @GetMapping(\"/importExcel/template\")\n void importTemplate(HttpServletResponse response);\n\n}', '0', 0, 1, '2021-06-12 01:32:36', 1, '2021-06-12 01:32:36'); +INSERT INTO `gen_template_detail` VALUES (1403404814225764353, 1398253704724828162, '0', '${packageName}/${moduleName}/${subModuleName}/web', '${model.tableHumpName}RestController.java', '#if(data.subModuleName != null && data.subModuleName != \"\")\npackage #(data.packageName+\".\"+data.moduleName+\".\"+data.subModuleName).web;\n#else\npackage #(data.packageName+\".\"+data.moduleName).web;\n#end\n\nimport cn.hutool.core.util.ReflectUtil;\nimport cn.hutool.core.convert.Convert;\nimport io.swagger.annotations.Api;\nimport io.swagger.annotations.ApiOperation;\nimport lombok.extern.slf4j.Slf4j;\nimport org.opsli.common.annotation.RequiresPermissionsCus;\nimport org.apache.shiro.authz.annotation.RequiresPermissions;\nimport #(apiPath).base.result.ResultVo;\nimport org.opsli.common.annotation.ApiRestController;\nimport org.opsli.common.annotation.EnableLog;\nimport org.opsli.core.base.controller.BaseRestController;\nimport org.opsli.core.persistence.Page;\nimport org.opsli.core.persistence.querybuilder.QueryBuilder;\nimport org.opsli.core.persistence.querybuilder.WebQueryBuilder;\nimport org.springframework.web.multipart.MultipartHttpServletRequest;\nimport javax.servlet.http.HttpServletRequest;\nimport javax.servlet.http.HttpServletResponse;\nimport java.lang.reflect.Method;\n\n#if(data.subModuleName != null && data.subModuleName != \"\")\nimport #(data.packageName+\".\"+data.moduleName+\".\"+data.subModuleName).entity.#(data.model.tableHumpName);\nimport #(apiPath).wrapper.#(data.moduleName+\".\"+data.subModuleName).#(data.model.tableHumpName)Model;\nimport #(data.packageName+\".\"+data.moduleName+\".\"+data.subModuleName).service.I#(data.model.tableHumpName)Service;\nimport #(apiPath).web.#(data.moduleName+\".\"+data.subModuleName).#(data.model.tableHumpName)RestApi;\n#else\nimport #(data.packageName+\".\"+data.moduleName).entity.#(data.model.tableHumpName);\nimport #(apiPath).wrapper.#(data.moduleName).#(data.model.tableHumpName)Model;\nimport #(data.packageName+\".\"+data.moduleName).service.I#(data.model.tableHumpName)Service;\nimport #(apiPath).web.#(data.moduleName).#(data.model.tableHumpName)RestApi;\n#end\n\n/**\n * #(data.codeTitle) Controller\n *\n * @author #(data.authorName)\n * @date #(currTime)\n */\n@Api(tags = #(data.model.tableHumpName)RestApi.TITLE)\n@Slf4j\n#if(data.subModuleName != null && data.subModuleName != \"\")\n@ApiRestController(\"/#(data.moduleName)/#(data.subModuleName)\")\n#else\n@ApiRestController(\"/#(data.moduleName)\")\n#end\npublic class #(data.model.tableHumpName)RestController extends BaseRestController<#(data.model.tableHumpName), #(data.model.tableHumpName)Model, I#(data.model.tableHumpName)Service>\n implements #(data.model.tableHumpName)RestApi {\n\n\n /**\n * #(data.codeTitleBrief) 查一条\n * @param model 模型\n * @return ResultVo\n */\n @ApiOperation(value = \"获得单条#(data.codeTitleBrief)\", notes = \"获得单条#(data.codeTitleBrief) - ID\")\n #if(data.subModuleName != null && data.subModuleName != \"\")\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_select\")\n #else\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_select\")\n #end\n @Override\n public ResultVo<#(data.model.tableHumpName)Model> get(#(data.model.tableHumpName)Model model) {\n // 如果系统内部调用 则直接查数据库\n if(model != null && model.getIzApi() != null && model.getIzApi()){\n model = IService.get(model);\n }\n return ResultVo.success(model);\n }\n\n /**\n * #(data.codeTitleBrief) 查询分页\n * @param pageNo 当前页\n * @param pageSize 每页条数\n * @param request request\n * @return ResultVo\n */\n @ApiOperation(value = \"获得分页数据\", notes = \"获得分页数据 - 查询构造器\")\n #if(data.subModuleName != null && data.subModuleName != \"\")\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_select\")\n #else\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_select\")\n #end\n @Override\n public ResultVo findPage(Integer pageNo, Integer pageSize, HttpServletRequest request) {\n\n QueryBuilder<#(data.model.tableHumpName)> queryBuilder = new WebQueryBuilder<>(entityClazz, request.getParameterMap());\n Page<#(data.model.tableHumpName), #(data.model.tableHumpName)Model> page = new Page<>(pageNo, pageSize);\n page.setQueryWrapper(queryBuilder.build());\n page = IService.findPage(page);\n\n return ResultVo.success(page.getPageData());\n }\n\n /**\n * #(data.codeTitleBrief) 新增\n * @param model 模型\n * @return ResultVo\n */\n @ApiOperation(value = \"新增#(data.codeTitleBrief)数据\", notes = \"新增#(data.codeTitleBrief)数据\")\n #if(data.subModuleName != null && data.subModuleName != \"\")\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_insert\")\n #else\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_insert\")\n #end\n @EnableLog\n @Override\n public ResultVo insert(#(data.model.tableHumpName)Model model) {\n // 调用新增方法\n IService.insert(model);\n return ResultVo.success(\"新增#(data.codeTitleBrief)成功\");\n }\n\n /**\n * #(data.codeTitleBrief) 修改\n * @param model 模型\n * @return ResultVo\n */\n @ApiOperation(value = \"修改#(data.codeTitleBrief)数据\", notes = \"修改#(data.codeTitleBrief)数据\")\n #if(data.subModuleName != null && data.subModuleName != \"\")\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_update\")\n #else\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_update\")\n #end\n @EnableLog\n @Override\n public ResultVo update(#(data.model.tableHumpName)Model model) {\n // 调用修改方法\n IService.update(model);\n return ResultVo.success(\"修改#(data.codeTitleBrief)成功\");\n }\n\n\n /**\n * #(data.codeTitleBrief) 删除\n * @param id ID\n * @return ResultVo\n */\n @ApiOperation(value = \"删除#(data.codeTitleBrief)数据\", notes = \"删除#(data.codeTitleBrief)数据\")\n #if(data.subModuleName != null && data.subModuleName != \"\")\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_update\")\n #else\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_update\")\n #end\n @EnableLog\n @Override\n public ResultVo del(String id){\n IService.delete(id);\n return ResultVo.success(\"删除#(data.codeTitleBrief)成功\");\n }\n\n /**\n * #(data.codeTitleBrief) 批量删除\n * @param ids ID 数组\n * @return ResultVo\n */\n @ApiOperation(value = \"批量删除#(data.codeTitleBrief)数据\", notes = \"批量删除#(data.codeTitleBrief)数据\")\n #if(data.subModuleName != null && data.subModuleName != \"\")\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_update\")\n #else\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_update\")\n #end\n @EnableLog\n @Override\n public ResultVo delAll(String ids){\n String[] idArray = Convert.toStrArray(ids);\n IService.deleteAll(idArray);\n return ResultVo.success(\"批量删除#(data.codeTitleBrief)成功\");\n }\n\n\n /**\n * #(data.codeTitleBrief) Excel 导出\n * 注:这里 RequiresPermissionsCus 引入的是 自定义鉴权注解\n *\n * 导出时,Token认证和方法权限认证 全部都由自定义完成\n * 因为在 导出不成功时,需要推送错误信息,\n * 前端直接走下载流,当失败时无法获得失败信息,即使前后端换一种方式后端推送二进制文件前端再次解析也是最少2倍的耗时\n * ,且如果数据量过大,前端进行渲染时直接会把浏览器卡死\n * 而直接开启socket接口推送显然是太过浪费资源了,所以目前采用Java最原始的手段\n * response 推送 javascript代码 alert 提示报错信息\n *\n * @param request request\n * @param response response\n */\n @ApiOperation(value = \"导出Excel\", notes = \"导出Excel\")\n #if(data.subModuleName != null && data.subModuleName != \"\")\n @RequiresPermissionsCus(\"#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_export\")\n #else\n @RequiresPermissionsCus(\"#(data.moduleName.toLowerCase())_export\")\n #end\n @EnableLog\n @Override\n public void exportExcel(HttpServletRequest request, HttpServletResponse response) {\n // 当前方法\n Method method = ReflectUtil.getMethodByName(this.getClass(), \"exportExcel\");\n QueryBuilder<#(data.model.tableHumpName)> queryBuilder = new WebQueryBuilder<>(entityClazz, request.getParameterMap());\n super.excelExport(#(data.model.tableHumpName)RestApi.SUB_TITLE, queryBuilder.build(), response, method);\n }\n\n /**\n * #(data.codeTitleBrief) Excel 导入\n * 注:这里 RequiresPermissions 引入的是 Shiro原生鉴权注解\n * @param request 文件流 request\n * @return ResultVo\n */\n @ApiOperation(value = \"导入Excel\", notes = \"导入Excel\")\n #if(data.subModuleName != null && data.subModuleName != \"\")\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_import\")\n #else\n @RequiresPermissions(\"#(data.moduleName.toLowerCase())_import\")\n #end\n @EnableLog\n @Override\n public ResultVo importExcel(MultipartHttpServletRequest request) {\n return super.importExcel(request);\n }\n\n /**\n * #(data.codeTitleBrief) Excel 下载导入模版\n * 注:这里 RequiresPermissionsCus 引入的是 自定义鉴权注解\n * @param response response\n */\n @ApiOperation(value = \"导出Excel模版\", notes = \"导出Excel模版\")\n #if(data.subModuleName != null && data.subModuleName != \"\")\n @RequiresPermissionsCus(\"#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_import\")\n #else\n @RequiresPermissionsCus(\"#(data.moduleName.toLowerCase())_import\")\n #end\n @Override\n public void importTemplate(HttpServletResponse response) {\n // 当前方法\n Method method = ReflectUtil.getMethodByName(this.getClass(), \"importTemplate\");\n super.importTemplate(#(data.model.tableHumpName)RestApi.SUB_TITLE, response, method);\n }\n\n}', '0', 0, 1, '2021-06-12 01:32:36', 1, '2021-06-12 01:32:36'); +INSERT INTO `gen_template_detail` VALUES (1403404814292873218, 1398253704724828162, '0', '${packageName}/${moduleName}/${subModuleName}/service/impl', '${model.tableHumpName}ServiceImpl.java', '#if(data.subModuleName != null && data.subModuleName != \"\")\npackage #(data.packageName+\".\"+data.moduleName+\".\"+data.subModuleName).service.impl;\n#else\npackage #(data.packageName+\".\"+data.moduleName).service.impl;\n#end\n\n\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.stereotype.Service;\nimport org.springframework.transaction.annotation.Transactional;\nimport org.opsli.core.base.service.impl.CrudServiceImpl;\n\n#if(data.subModuleName != null && data.subModuleName != \"\")\nimport #(data.packageName+\".\"+data.moduleName+\".\"+data.subModuleName).entity.#(data.model.tableHumpName);\nimport #(apiPath).wrapper.#(data.moduleName+\".\"+data.subModuleName).#(data.model.tableHumpName)Model;\nimport #(data.packageName+\".\"+data.moduleName+\".\"+data.subModuleName).service.I#(data.model.tableHumpName)Service;\nimport #(data.packageName+\".\"+data.moduleName+\".\"+data.subModuleName).mapper.#(data.model.tableHumpName)Mapper;\n#else\nimport #(data.packageName+\".\"+data.moduleName).entity.#(data.model.tableHumpName);\nimport #(apiPath).wrapper.#(data.moduleName).#(data.model.tableHumpName)Model;\nimport #(data.packageName+\".\"+data.moduleName).service.I#(data.model.tableHumpName)Service;\nimport #(data.packageName+\".\"+data.moduleName).mapper.#(data.model.tableHumpName)Mapper;\n#end\n\n\n/**\n * #(data.codeTitle) Service Impl\n *\n * @author #(data.authorName)\n * @date #(currTime)\n */\n@Service\npublic class #(data.model.tableHumpName)ServiceImpl extends CrudServiceImpl<#(data.model.tableHumpName)Mapper, #(data.model.tableHumpName), #(data.model.tableHumpName)Model>\n implements I#(data.model.tableHumpName)Service {\n\n @Autowired(required = false)\n private #(data.model.tableHumpName)Mapper mapper;\n\n}', '0', 0, 1, '2021-06-12 01:32:36', 1, '2021-06-12 01:32:36'); +INSERT INTO `gen_template_detail` VALUES (1403404814422896641, 1398253704724828162, '0', '${packageName}/${moduleName}/${subModuleName}/service', 'I${model.tableHumpName}Service.java', '#if(data.subModuleName != null && data.subModuleName != \"\")\npackage #(data.packageName+\".\"+data.moduleName+\".\"+data.subModuleName).service;\n#else\npackage #(data.packageName+\".\"+data.moduleName).service;\n#end\n\nimport org.opsli.core.base.service.interfaces.CrudServiceInterface;\n\n\n#if(data.subModuleName != null && data.subModuleName != \"\")\nimport #(data.packageName+\".\"+data.moduleName+\".\"+data.subModuleName).entity.#(data.model.tableHumpName);\nimport #(apiPath).wrapper.#(data.moduleName+\".\"+data.subModuleName).#(data.model.tableHumpName)Model;\n#else\nimport #(data.packageName+\".\"+data.moduleName).entity.#(data.model.tableHumpName);\nimport #(apiPath).wrapper.#(data.moduleName).#(data.model.tableHumpName)Model;\n#end\n\n/**\n * #(data.codeTitle) Service\n *\n * @author #(data.authorName)\n * @date #(currTime)\n */\npublic interface I#(data.model.tableHumpName)Service extends CrudServiceInterface<#(data.model.tableHumpName), #(data.model.tableHumpName)Model> {\n\n}', '0', 0, 1, '2021-06-12 01:32:36', 1, '2021-06-12 01:32:36'); +INSERT INTO `gen_template_detail` VALUES (1403404814485811202, 1398253704724828162, '1', 'src/api/${moduleName}/${subModuleName}', '${model.tableHumpName}ManagementApi.js', 'import request from \"@/utils/request\";\nimport { downloadFileByData } from \"@/utils/download\";\n\nexport function getList(data) {\n return request({\n #if(data.subModuleName != null && data.subModuleName != \"\")\n url: \"/api/v1/#(data.moduleName)/#(data.subModuleName)/findPage\",\n #else\n url: \"/api/v1/#(data.moduleName)/findPage\",\n #end\n method: \"get\",\n params: data,\n });\n}\n\nexport function doInsert(data) {\n return request({\n #if(data.subModuleName != null && data.subModuleName != \"\")\n url: \"/api/v1/#(data.moduleName)/#(data.subModuleName)/insert\",\n #else\n url: \"/api/v1/#(data.moduleName)/insert\",\n #end\n method: \"post\",\n data,\n });\n}\n\nexport function doUpdate(data) {\n return request({\n #if(data.subModuleName != null && data.subModuleName != \"\")\n url: \"/api/v1/#(data.moduleName)/#(data.subModuleName)/update\",\n #else\n url: \"/api/v1/#(data.moduleName)/update\",\n #end\n method: \"post\",\n data,\n });\n}\n\nexport function doDelete(data) {\n return request({\n #if(data.subModuleName != null && data.subModuleName != \"\")\n url: \"/api/v1/#(data.moduleName)/#(data.subModuleName)/del\",\n #else\n url: \"/api/v1/#(data.moduleName)/del\",\n #end\n method: \"post\",\n params: data,\n });\n}\n\nexport function doDeleteAll(data) {\n return request({\n #if(data.subModuleName != null && data.subModuleName != \"\")\n url: \"/api/v1/#(data.moduleName)/#(data.subModuleName)/delAll\",\n #else\n url: \"/api/v1/#(data.moduleName)/delAll\",\n #end\n method: \"post\",\n params: data,\n });\n}\n\n/**\n * 导出Excel 目前只支持一层参数传递\n * @param data\n * @returns file\n */\nexport function doExportExcel(data) {\n #if(data.subModuleName != null && data.subModuleName != \"\")\n let requestURL = \"/api/v1/#(data.moduleName)/#(data.subModuleName)/exportExcel\";\n #else\n let requestURL = \"/api/v1/#(data.moduleName)/exportExcel\";\n #end\n // 下载文件\n downloadFileByData(requestURL, data);\n}\n\n/**\n * 下载模版\n * @returns file\n */\nexport function doDownloadTemplate() {\n let data = {};\n #if(data.subModuleName != null && data.subModuleName != \"\")\n let requestURL = \"/api/v1/#(data.moduleName)/#(data.subModuleName)/importExcel/template\";\n #else\n let requestURL = \"/api/v1/#(data.moduleName)/importExcel/template\";\n #end\n // 下载文件\n downloadFileByData(requestURL, data);\n}\n\n/**\n * 导入Excel\n * @returns file\n */\nexport function doImportExcel(data) {\n return request({\n #if(data.subModuleName != null && data.subModuleName != \"\")\n url: \"/api/v1/#(data.moduleName)/#(data.subModuleName)/importExcel\",\n #else\n url: \"/api/v1/#(data.moduleName)/importExcel\",\n #end\n method: \"post\",\n // 最长超时时间 3 分钟\n timeout: 180000,\n headers: {\n \"Content-Type\": \"multipart/form-data\"\n },\n data,\n });\n}', '0', 0, 1, '2021-06-12 01:32:36', 1, '2021-06-12 01:32:36'); +INSERT INTO `gen_template_detail` VALUES (1403404814615834625, 1398253704724828162, '1', 'src/views/modules/${moduleName}/${subModuleName}/components', '${model.tableHumpName}ManagementEdit.vue', '\n\n\n', '0', 0, 1, '2021-06-12 01:32:36', 1, '2021-06-12 01:32:36'); +INSERT INTO `gen_template_detail` VALUES (1403404814674554882, 1398253704724828162, '1', 'src/views/modules/${moduleName}/${subModuleName}/components', '${model.tableHumpName}ManagementImport.vue', '\n\n\n', '0', 0, 1, '2021-06-12 01:32:36', 1, '2021-06-12 01:32:36'); +INSERT INTO `gen_template_detail` VALUES (1403404814800384002, 1398253704724828162, '1', 'src/views/modules/${moduleName}/${subModuleName}', 'index.vue', '\n\n\n', '0', 0, 1, '2021-06-12 01:32:37', 1, '2021-06-12 01:32:37'); -- ---------------------------- -- Table structure for sys_area @@ -6451,11 +6451,11 @@ DROP TABLE IF EXISTS `sys_org`; CREATE TABLE `sys_org` ( `id` bigint(19) NOT NULL COMMENT '字典主键', `parent_id` bigint(19) NOT NULL DEFAULT 0 COMMENT '父级主键', + `parent_ids` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '0' COMMENT '父级主键集合', `org_code` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '组织机构编号', `org_name` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '组织机构名称', - `org_type` int(3) NOT NULL COMMENT '组织机构类型', `sort_no` int(11) NOT NULL COMMENT '排序', - `iz_validate` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '1' COMMENT '开启数据校验:0否,1是 默认为是', + `remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '备注', `tenant_id` bigint(20) NULL DEFAULT NULL COMMENT '多租户ID', `deleted` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '0' COMMENT '删除标记:0未删除,1删除', `version` int(11) NOT NULL COMMENT '版本(乐观锁)', @@ -6466,22 +6466,24 @@ CREATE TABLE `sys_org` ( `ts` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '时间戳', PRIMARY KEY (`id`) USING BTREE, INDEX `org_index`(`org_code`, `org_name`) USING BTREE, - INDEX `pid`(`parent_id`) USING BTREE COMMENT '上级id' + INDEX `pid`(`parent_id`) USING BTREE COMMENT '上级id', + INDEX `pids`(`parent_ids`) USING BTREE COMMENT '上级id集合' ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '组织机构表' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of sys_org -- ---------------------------- -INSERT INTO `sys_org` VALUES (1332710973848449026, 0, '0011', 'A公司', 1, 1, '1', 1, '0', 10, 1313694379541635074, '2020-11-28 23:40:31', 1313694379541635074, '2021-02-25 13:31:20', '2021-04-08 23:51:16'); -INSERT INTO `sys_org` VALUES (1332720768622120961, 0, '0012', 'B公司', 1, 2, '1', 1, '1', 6, 1313694379541635074, '2020-11-29 00:19:27', 1313694379541635074, '2020-11-29 22:18:06', '2021-04-08 23:51:16'); -INSERT INTO `sys_org` VALUES (1332876488965476354, 0, '0011', 'C公司', 1, 3, '0', 1, '1', 0, 1313694379541635074, '2020-11-29 10:38:13', 1313694379541635074, '2020-11-29 10:38:13', '2021-04-08 23:51:16'); -INSERT INTO `sys_org` VALUES (1332877640071237634, 0, '0012', 'c', 1, 4, '0', 1, '1', 0, 1313694379541635074, '2020-11-29 10:42:48', 1313694379541635074, '2020-11-29 10:42:48', '2021-04-08 23:51:16'); -INSERT INTO `sys_org` VALUES (1332878633177477122, 0, '0013', 'C公司', 1, 3, '0', 1, '0', 3, 1313694379541635074, '2020-11-29 10:46:44', 1313694379541635074, '2020-11-29 22:26:35', '2021-04-08 23:51:16'); -INSERT INTO `sys_org` VALUES (1332879851278856193, 1332710973848449026, '0011_123', 'A公司B部门', 2, 1, '1', 1, '0', 6, 1313694379541635074, '2020-11-29 10:51:35', 1313694379541635074, '2021-02-25 13:31:17', '2021-04-08 23:51:16'); -INSERT INTO `sys_org` VALUES (1332880775317581826, 1332879851278856193, '0011_123_003', '测试岗', 3, 1, '1', 1, '0', 5, 1313694379541635074, '2020-11-29 10:55:15', 1313694379541635074, '2021-02-25 13:30:51', '2021-04-08 23:51:16'); -INSERT INTO `sys_org` VALUES (1336209704187879425, 0, '0012', 'B公司', 1, 2, '1', 1, '0', 3, 1313694379541635074, '2020-12-08 15:23:14', 1, '2021-01-11 19:19:51', '2021-04-08 23:51:16'); -INSERT INTO `sys_org` VALUES (1389268887044624385, 1336209704187879425, '0012_1111', '1111', 2, 1, '1', 1, '0', 0, 1, '2021-05-04 01:21:29', 1, '2021-05-04 01:21:29', '2021-05-04 01:21:28'); -INSERT INTO `sys_org` VALUES (1389268928454987778, 1389268887044624385, '0012_1111_2222', '11111', 3, 1, '1', 1, '0', 0, 1, '2021-05-04 01:21:39', 1, '2021-05-04 01:21:39', '2021-05-04 01:21:38'); +INSERT INTO `sys_org` VALUES (1332710973848449026, 0, '0', '0011', 'A公司', 1, NULL, 1, '0', 11, 1313694379541635074, '2020-11-28 23:40:31', 1, '2021-06-08 11:38:29', '2021-06-08 11:38:28'); +INSERT INTO `sys_org` VALUES (1332878633177477122, 0, '0', '0013', 'C公司', 3, NULL, 1, '0', 10, 1313694379541635074, '2020-11-29 10:46:44', 1, '2021-06-07 19:52:59', '2021-06-07 20:07:21'); +INSERT INTO `sys_org` VALUES (1332879851278856193, 1332710973848449026, '0,1332710973848449026', '0011_123', 'A公司B部门', 1, NULL, 1, '0', 6, 1313694379541635074, '2020-11-29 10:51:35', 1313694379541635074, '2021-02-25 13:31:17', '2021-06-07 19:23:35'); +INSERT INTO `sys_org` VALUES (1332880775317581826, 1332879851278856193, '0,1332710973848449026,1332879851278856193', '0011_123_003', '测试岗', 1, NULL, 1, '0', 5, 1313694379541635074, '2020-11-29 10:55:15', 1313694379541635074, '2021-02-25 13:30:51', '2021-06-07 19:23:48'); +INSERT INTO `sys_org` VALUES (1336209704187879425, 0, '0', '0012', 'B公司', 2, NULL, 1, '0', 3, 1313694379541635074, '2020-12-08 15:23:14', 1, '2021-01-11 19:19:51', '2021-04-08 23:51:16'); +INSERT INTO `sys_org` VALUES (1401861234604605441, 0, '0', '12334', 'D公司', 1, NULL, 1, '0', 0, 1, '2021-06-07 19:18:58', 1, '2021-06-07 19:18:58', '2021-06-11 18:06:56'); +INSERT INTO `sys_org` VALUES (1401861575953842177, 1401861234604605441, '0,1401861234604605441', '12334_111', 'D公司的XXX部门', 1, NULL, 1, '0', 0, 1, '2021-06-07 19:20:20', 1, '2021-06-07 19:20:20', '2021-06-11 18:06:56'); +INSERT INTO `sys_org` VALUES (1401861991370293250, 1401873907685687297, '0,1401873858511667201,1401873907685687297', '12334_111_111', '不知道哪儿个岗位', 1, NULL, 1, '0', 11, 1, '2021-06-07 19:21:59', 1, '2021-06-07 20:18:22', '2021-06-11 18:06:56'); +INSERT INTO `sys_org` VALUES (1401873858511667201, 0, '0', '123123', 'E公司', 1, NULL, 1, '0', 0, 1, '2021-06-07 20:09:08', 1, '2021-06-07 20:09:08', '2021-06-11 18:06:56'); +INSERT INTO `sys_org` VALUES (1401873907685687297, 1401873858511667201, '0,1401873858511667201', '123123_123', '123', 1, '123333', 1, '0', 0, 1, '2021-06-07 20:09:20', 1, '2021-06-07 20:09:20', '2021-06-11 18:06:56'); +INSERT INTO `sys_org` VALUES (1401874418988122114, 1401861991370293250, '0,1401873858511667201,1401873907685687297,1401861991370293250', '12334_111_111_123', '3333333', 1, NULL, 1, '0', 6, 1, '2021-06-07 20:11:22', 1, '2021-06-07 20:18:22', '2021-06-11 18:06:56'); -- ---------------------------- -- Table structure for sys_role @@ -6726,6 +6728,7 @@ CREATE TABLE `sys_user` ( `email` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '邮箱', `sign` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '签名', `remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '备注', + `iz_exist_org` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '0' COMMENT '是否存在组织', `tenant_id` bigint(19) NULL DEFAULT NULL COMMENT '多租户ID', `deleted` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '0' COMMENT '删除状态', `version` int(11) NOT NULL COMMENT '版本(乐观锁)', @@ -6742,12 +6745,12 @@ CREATE TABLE `sys_user` ( -- ---------------------------- -- Records of sys_user -- ---------------------------- -INSERT INTO `sys_user` VALUES (1, 'system', '10b80e7442518fee52191617e602527a', '2', 'gu4ix7czy8g2x4xf5td7', '1', '超级管理员', '15321010110', '112', 'http://upload.bedebug.com/20210603/162433012495676994QGGVX.jpg', '', 'meet.parker@foxmail.com', '没有自学能力的人没有未来', '', 1315203865179602945, '0', 95, 1, '2020-09-25 15:03:22', 1, '2021-05-04 01:59:11', '2021-06-03 19:48:02'); -INSERT INTO `sys_user` VALUES (1313694379541635074, 'demo', 'cc6875215ef04072164bc81b9e2ce496', '2', '489e0bs6p7du02t8ij8t', '1', '演示用户', '15321010110', 'test_001', 'http://127.0.0.1:8080/opsli-boot/static/files/20210503/162030164596296168YISD4.jpg', '', 'meet.parker@foxmail.com', '没有自学能力的人没有未来', NULL, 1, '0', 2, 1, '2020-10-06 23:15:22', 1, '2020-10-11 16:53:58', '2021-05-24 18:50:29'); -INSERT INTO `sys_user` VALUES (1315218541317750785, 'zhangsan', '386a1212b388a49d6cca827173824914', '1', 'g6880o4q5k98w6a6hplu', '1', '张三', NULL, '123123', NULL, '127.0.0.1', NULL, NULL, NULL, NULL, '0', 0, 1, '2020-10-11 17:11:50', 1, '2020-10-11 17:11:50', '2021-05-13 16:17:27'); -INSERT INTO `sys_user` VALUES (1315224529580072961, 'test', '248b77e86f3137b0381e78a0050c8eab', '1', 'x93jqlq94e7bmludjzxm', '0', '123', NULL, '123123123', NULL, NULL, NULL, NULL, NULL, NULL, '1', 0, 1, '2020-10-11 17:35:38', 1, '2020-10-11 17:35:38', '2021-05-13 16:17:27'); -INSERT INTO `sys_user` VALUES (1315224823500120066, 'lyf', 'e7f977aac0007f3ae2b36c46d5fdc5c9', '1', '0ep05v5hl5q86lv0uprg', '1', '刘亦菲', NULL, '0101001', NULL, '127.0.0.1', NULL, NULL, NULL, 1, '0', 0, 1313694379541635074, '2020-10-11 17:36:48', 1313694379541635074, '2020-10-11 17:36:48', '2021-05-13 16:17:27'); -INSERT INTO `sys_user` VALUES (1340328715309092866, 'tests', 'efb6175f6c12483b0e48d8dbb1da2f5c', '1', 'v6u9hu3kl0yowdpoxuel', '0', '测试', NULL, '123213123', NULL, '127.0.0.1', NULL, NULL, NULL, 1, '1', 7, 1313694379541635074, '2020-12-20 00:10:42', 1313694379541635074, '2021-03-13 00:09:49', '2021-05-13 16:17:27'); +INSERT INTO `sys_user` VALUES (1, 'system', '10b80e7442518fee52191617e602527a', '2', 'gu4ix7czy8g2x4xf5td7', '1', '超级管理员', '15321010110', '112', 'http://upload.bedebug.com/20210603/162433012495676994QGGVX.jpg', '', 'meet.parker@foxmail.com', '没有自学能力的人没有未来', '', '0', 1315203865179602945, '0', 95, 1, '2020-09-25 15:03:22', 1, '2021-05-04 01:59:11', '2021-06-03 19:48:02'); +INSERT INTO `sys_user` VALUES (1313694379541635074, 'demo', 'cc6875215ef04072164bc81b9e2ce496', '2', '489e0bs6p7du02t8ij8t', '1', '演示用户', '15321010110', 'test_001', 'https://upload.bedebug.com/20210603/162361618003399601E83NF.jpg', '', 'meet.parker@foxmail.com', '没有自学能力的人没有未来', NULL, '1', 1, '0', 2, 1, '2020-10-06 23:15:22', 1, '2020-10-11 16:53:58', '2021-06-12 01:07:38'); +INSERT INTO `sys_user` VALUES (1315218541317750785, 'zhangsan', '4beeb20b06086f97744aa5de7d9bd499', '2', 'b3ab5dhf2j72e0a9f25f', '1', '张三', NULL, '123123', NULL, '', NULL, NULL, NULL, '1', 1, '0', 3, 1, '2020-10-11 17:11:50', 1, '2021-06-11 17:44:11', '2021-06-12 01:24:48'); +INSERT INTO `sys_user` VALUES (1315224529580072961, 'test', '248b77e86f3137b0381e78a0050c8eab', '1', 'x93jqlq94e7bmludjzxm', '0', '123', NULL, '123123123', NULL, NULL, NULL, NULL, NULL, '0', NULL, '1', 0, 1, '2020-10-11 17:35:38', 1, '2020-10-11 17:35:38', '2021-05-13 16:17:27'); +INSERT INTO `sys_user` VALUES (1315224823500120066, 'lyf', 'e7f977aac0007f3ae2b36c46d5fdc5c9', '1', '0ep05v5hl5q86lv0uprg', '1', '刘亦菲', NULL, '0101001', NULL, '127.0.0.1', NULL, NULL, NULL, '0', 1, '0', 0, 1313694379541635074, '2020-10-11 17:36:48', 1313694379541635074, '2020-10-11 17:36:48', '2021-05-13 16:17:27'); +INSERT INTO `sys_user` VALUES (1340328715309092866, 'tests', 'efb6175f6c12483b0e48d8dbb1da2f5c', '1', 'v6u9hu3kl0yowdpoxuel', '0', '测试', NULL, '123213123', NULL, '127.0.0.1', NULL, NULL, NULL, '0', 1, '1', 7, 1313694379541635074, '2020-12-20 00:10:42', 1313694379541635074, '2021-03-13 00:09:49', '2021-05-13 16:17:27'); -- ---------------------------- -- Table structure for sys_user_org_ref @@ -6756,18 +6759,19 @@ DROP TABLE IF EXISTS `sys_user_org_ref`; CREATE TABLE `sys_user_org_ref` ( `id` bigint(19) NOT NULL COMMENT '用户角色关联', `user_id` bigint(19) NOT NULL COMMENT '用户主键', - `org_id` bigint(19) NOT NULL COMMENT '组织机构主键', - `org_type` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '组织机构类型', + `org_id` bigint(19) NOT NULL COMMENT '当前组织机构', + `org_ids` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '组织机构组', + `iz_def` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '是否默认', PRIMARY KEY (`id`) USING BTREE, - INDEX `sys_org_user`(`user_id`, `org_id`, `org_type`) USING BTREE + INDEX `sys_org_user`(`user_id`, `org_ids`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '组织机构用户关联表' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of sys_user_org_ref -- ---------------------------- -INSERT INTO `sys_user_org_ref` VALUES (1336194711962796034, 1313694379541635074, 1332710973848449026, '1'); -INSERT INTO `sys_user_org_ref` VALUES (1336194711996350466, 1313694379541635074, 1332879851278856193, '2'); -INSERT INTO `sys_user_org_ref` VALUES (1336204588500140033, 1315224823500120066, 1332878633177477122, '1'); +INSERT INTO `sys_user_org_ref` VALUES (1403297083045163010, 1313694379541635074, 1401861575953842177, '0,1401861234604605441,1401861575953842177', '1'); +INSERT INTO `sys_user_org_ref` VALUES (1403297083070328833, 1313694379541635074, 1401861991370293250, '0,1401873858511667201,1401873907685687297,1401861991370293250', '0'); +INSERT INTO `sys_user_org_ref` VALUES (1403403014114373634, 1315218541317750785, 1332879851278856193, '0,1332710973848449026,1332879851278856193', '1'); -- ---------------------------- -- Table structure for sys_user_role_ref 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 index 844817e..208f175 100644 --- 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 @@ -47,28 +47,29 @@ public interface SysOrgRestApi { /** - * 获得懒加载树 By 用户 + * 获得懒加载树 * @param parentId 父级ID + * @param id 忽略自身ID * @return ResultVo */ - @GetMapping("/findTreeLazyByUser") - ResultVo findTreeLazyByUser(String parentId); + @GetMapping("/findTreeLazy") + ResultVo findTreeLazy(String parentId, String id); /** - * 获得懒加载树 - * @param parentId 父级ID + * 获得全量树 包含默认节点 + * @param isGen 是否包含根节点 + * @param id 忽略自身ID * @return ResultVo */ - @GetMapping("/findTreeLazy") - ResultVo findTreeLazy(String parentId); + @GetMapping("/findTreeByDef") + ResultVo findTreeByDef(boolean isGen, String id); /** - * 获得控件树 - * @param parentId 父级ID + * 获得当前用户下 组织 * @return ResultVo */ - @GetMapping("/findGridTree") - ResultVo findGridTree(String parentId); + @GetMapping("/findTreeByDefWithUserToLike") + ResultVo findTreeByDefWithUserToLike(); // ================ @@ -80,14 +81,6 @@ public interface SysOrgRestApi { @GetMapping("/get") ResultVo get(SysOrgModel model); - /** - * 组织树 - * @param request request - * @return ResultVo - */ - @GetMapping("/findTree") - ResultVo findTree( HttpServletRequest request ); - /** * 组织机构表 新增 * @param model 模型 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 7a54331..cca47d8 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 @@ -19,7 +19,7 @@ import org.opsli.api.base.result.ResultVo; import org.opsli.api.wrapper.system.menu.MenuModel; 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.UserOrgRefWebModel; import org.opsli.api.wrapper.system.user.UserPassword; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -72,7 +72,7 @@ public interface UserApi { * @return ResultVo */ @GetMapping("/getOrg") - ResultVo getOrg(); + ResultVo getOrg(); /** * 当前登陆用户信息 @@ -81,7 +81,7 @@ public interface UserApi { * @return ResultVo */ @GetMapping("/getOrgByUserId") - ResultVo getOrgByUserId(String userId); + ResultVo getOrgByUserId(String userId); /** * 根据 userId 获得用户角色Id集合 @@ -94,6 +94,7 @@ public interface UserApi { /** * 修改密码 + * @param userPassword 账号密码 * @return ResultVo */ @PostMapping("/updatePassword") @@ -148,7 +149,7 @@ public interface UserApi { * 用户信息 查询分页 * @param pageNo 当前页 * @param pageSize 每页条数 - * @param org 组织 + * @param orgIdGroup 组织ID组 * @param request request * @return ResultVo */ @@ -156,7 +157,7 @@ public interface UserApi { ResultVo findPage( @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, - UserOrgRefModel org, + @RequestParam(name = "orgIdGroup") String orgIdGroup, HttpServletRequest request ); @@ -265,7 +266,7 @@ public interface UserApi { * @param userId 用户ID * @return ResultVo */ - ResultVo getOrgInfoByUserId(String userId); + 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 index eb3b7ba..1af292a 100644 --- 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 @@ -17,9 +17,12 @@ package org.opsli.api.web.system.user; import org.opsli.api.base.result.ResultVo; import org.opsli.api.wrapper.system.user.UserOrgRefModel; +import org.opsli.api.wrapper.system.user.UserOrgRefWebModel; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import java.util.List; + /** * 用户组织 API @@ -46,6 +49,13 @@ public interface UserOrgRefApi { * @return ResultVo */ @PostMapping("/setOrg") - ResultVo setOrg(@RequestBody UserOrgRefModel model); + ResultVo setOrg(@RequestBody UserOrgRefWebModel model); + + /** + * 根据用户ID 获得组织列表 + * @param userId 用户ID + * @return List + */ + ResultVo> findListByUserId(String userId); } 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 index 9e339d5..00d29bb 100644 --- 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 @@ -37,6 +37,7 @@ import org.opsli.plugins.excel.annotation.ExcelInfo; @EqualsAndHashCode(callSuper = false) public class SysOrgModel extends ApiWrapper { + /** 父级主键 */ @ApiModelProperty(value = "父级主键") @ExcelProperty(value = "父级主键", order = 1) @@ -44,9 +45,15 @@ public class SysOrgModel extends ApiWrapper { @ValidatorLenMax(19) private String parentId; + /** 父级主键集合 xxx,xxx */ + @ApiModelProperty(value = "父级主键集合") + @ExcelProperty(value = "父级主键集合", order = 2) + @ExcelInfo + private String parentIds; + /** 组织机构编号 */ @ApiModelProperty(value = "组织机构编号") - @ExcelProperty(value = "组织机构编号", order = 2) + @ExcelProperty(value = "组织机构编号", order = 3) @ExcelInfo @Validator({ValidatorType.IS_NOT_NULL, ValidatorType.IS_GENERAL}) @ValidatorLenMax(120) @@ -54,20 +61,12 @@ public class SysOrgModel extends ApiWrapper { /** 组织机构名称 */ @ApiModelProperty(value = "组织机构名称") - @ExcelProperty(value = "组织机构名称", order = 3) + @ExcelProperty(value = "组织机构名称", order = 4) @ExcelInfo @Validator({ValidatorType.IS_NOT_NULL, ValidatorType.IS_GENERAL_WITH_CHINESE}) @ValidatorLenMax(120) private String orgName; - /** 组织机构类型 1-公司 2-部门 3-岗位*/ - @ApiModelProperty(value = "组织机构类型") - @ExcelProperty(value = "组织机构类型", order = 4) - @ExcelInfo( dictType = "org_type") - @Validator({ValidatorType.IS_NOT_NULL}) - @ValidatorLenMax(3) - private String orgType; - /** 排序 */ @ApiModelProperty(value = "排序") @ExcelProperty(value = "排序", order = 5) @@ -75,6 +74,13 @@ public class SysOrgModel extends ApiWrapper { @ValidatorLenMax(10) private Integer sortNo; + /** 备注 */ + @ApiModelProperty(value = "备注") + @ExcelProperty(value = "备注", order = 6) + @ExcelInfo + @ValidatorLenMax(255) + private String remark; + /** 多租户字段 */ @ApiModelProperty(value = "多租户ID") @ExcelIgnore diff --git a/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserModel.java b/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserModel.java index b3112ba..9f61752 100644 --- a/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserModel.java +++ b/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserModel.java @@ -17,6 +17,7 @@ package org.opsli.api.wrapper.system.user; import com.alibaba.excel.annotation.ExcelIgnore; import com.alibaba.excel.annotation.ExcelProperty; +import com.fasterxml.jackson.annotation.JsonIgnore; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; @@ -135,5 +136,11 @@ public class UserModel extends ApiWrapper { @ValidatorLenMax(20) private String tenantId; + /** 是否存在组织 */ + @JsonIgnore + @ExcelIgnore + @ValidatorLenMax(1) + private String izExistOrg; + } 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 index b9c343e..9b22121 100644 --- 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 @@ -16,17 +16,20 @@ package org.opsli.api.wrapper.system.user; import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.baomidou.mybatisplus.annotation.TableId; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; +import org.opsli.api.wrapper.system.org.SysOrgModel; import org.opsli.common.annotation.validator.Validator; import org.opsli.common.annotation.validator.ValidatorLenMax; import org.opsli.common.enums.ValidatorType; import java.io.Serializable; +import java.util.List; /** - * 角色表 + * 用户组织关系表 * * @author Parker * @date 2020-09-16 17:33 @@ -36,32 +39,26 @@ import java.io.Serializable; @ExcelIgnoreUnannotated public class UserOrgRefModel implements Serializable { + /** ID */ + @ApiModelProperty(value = "ID") + private String id; + /** 用户ID */ @ApiModelProperty(value = "用户ID") @Validator({ValidatorType.IS_NOT_NULL}) @ValidatorLenMax(50) private String userId; - @ApiModelProperty(value = "公司") - @Validator({ValidatorType.IS_NOT_NULL}) - @ValidatorLenMax(19) - private String companyId; - - @ApiModelProperty(value = "公司名称") - private String companyName; - - @ApiModelProperty(value = "部门ID") - @ValidatorLenMax(19) - private String departmentId; - - @ApiModelProperty(value = "部门名称") - private String departmentName; + /** 当前组织 */ + @ApiModelProperty(value = "当前组织") + private String orgId; - @ApiModelProperty(value = "岗位ID") - @ValidatorLenMax(19) - private String postId; + /** 组织ID集合 xxx,xxx */ + @ApiModelProperty(value = "组织ID集合") + private String orgIds; - @ApiModelProperty(value = "岗位名称") - private String postName; + /** 是否默认 */ + @ApiModelProperty(value = "是否默认") + private String izDef; } diff --git a/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserOrgRefWebModel.java b/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserOrgRefWebModel.java new file mode 100644 index 0000000..bc8a6e2 --- /dev/null +++ b/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserOrgRefWebModel.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.wrapper.system.user; + +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.api.wrapper.system.org.SysOrgModel; +import org.opsli.common.annotation.validator.Validator; +import org.opsli.common.annotation.validator.ValidatorLenMax; +import org.opsli.common.enums.ValidatorType; + +import java.io.Serializable; +import java.util.List; + +/** + * 角色表 + * + * @author Parker + * @date 2020-09-16 17:33 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@ExcelIgnoreUnannotated +public class UserOrgRefWebModel implements Serializable { + + /** 用户ID */ + @ApiModelProperty(value = "用户ID") + @Validator({ValidatorType.IS_NOT_NULL}) + @ValidatorLenMax(50) + private String userId; + + @ApiModelProperty(value = "默认组织") + private SysOrgModel defModel; + + @ApiModelProperty(value = "组织机构") + private List orgModelList; + +} 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/UserWebModel.java similarity index 95% rename from opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserAndOrgModel.java rename to opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserWebModel.java index 362f93f..7d16fa4 100644 --- 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/UserWebModel.java @@ -35,7 +35,7 @@ import org.opsli.plugins.excel.annotation.ExcelInfo; */ @Data @EqualsAndHashCode(callSuper = false) -public class UserAndOrgModel extends ApiWrapper { +public class UserWebModel extends ApiWrapper { /** 登录账户 */ @@ -137,10 +137,4 @@ public class UserAndOrgModel extends ApiWrapper { @ValidatorLenMax(20) private String tenantId; - /** 组织机构 */ - @ApiModelProperty(value = "组织机构") - @ExcelIgnore - private UserOrgRefModel org; - - } diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/MyBatisConstants.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/MyBatisConstants.java index 7f935c3..6bf6eba 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/MyBatisConstants.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/MyBatisConstants.java @@ -36,6 +36,8 @@ public interface MyBatisConstants { String FIELD_ID = "id"; /** PID */ String FIELD_PARENT_ID = "parentId"; + /** PIDs */ + String FIELD_PARENT_IDS = "parentIds"; /** 创建人 */ String FIELD_CREATE_BY = "createBy"; /** 更新时间 */ @@ -50,4 +52,6 @@ public interface MyBatisConstants { String FIELD_OPTIMISTIC_LOCK = "version"; /** 多租户字段 */ String FIELD_TENANT = "tenantId"; + /** 组织字段 */ + String FIELD_ORG_GROUP = "org_group"; } diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/TreeConstants.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/TreeConstants.java new file mode 100644 index 0000000..ed7ec73 --- /dev/null +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/TreeConstants.java @@ -0,0 +1,33 @@ +/** + * 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.common.constants; + +/** + * 菜单常量 + * + * @author Parker + * @date 2021年3月10日15:50:16 + */ +public interface TreeConstants { + + /** 是否包含子集 */ + String HAS_CHILDREN = "hasChildren"; + + + /** 是否是叶子节点 */ + String IS_LEAF = "isLeaf"; + +} diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/controller/BaseRestController.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/controller/BaseRestController.java index 373b6da..e25d33a 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/controller/BaseRestController.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/controller/BaseRestController.java @@ -17,13 +17,19 @@ package org.opsli.core.base.controller; import cn.hutool.core.annotation.AnnotationUtil; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.ListUtil; +import cn.hutool.core.convert.Convert; import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.TimeInterval; +import cn.hutool.core.lang.tree.Tree; import cn.hutool.core.util.StrUtil; import com.alibaba.excel.support.ExcelTypeEnum; import com.alibaba.excel.util.CollectionUtils; 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 lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.opsli.api.base.result.ResultVo; @@ -32,6 +38,7 @@ import org.opsli.api.wrapper.system.user.UserModel; import org.opsli.common.annotation.RequiresPermissionsCus; import org.opsli.common.annotation.hotdata.EnableHotData; import org.opsli.common.constants.CacheConstants; +import org.opsli.common.constants.TreeConstants; import org.opsli.common.enums.ExcelOperate; import org.opsli.common.exception.ServiceException; import org.opsli.common.exception.TokenException; @@ -40,6 +47,7 @@ import org.opsli.common.utils.OutputStreamUtil; import org.opsli.common.utils.WrapperUtil; import org.opsli.core.autoconfigure.properties.GlobalProperties; import org.opsli.core.base.entity.BaseEntity; +import org.opsli.core.base.entity.HasChildren; import org.opsli.core.base.service.interfaces.CrudServiceInterface; import org.opsli.core.cache.local.CacheUtil; import org.opsli.core.msg.CoreMsg; @@ -60,9 +68,8 @@ import org.springframework.web.multipart.MultipartHttpServletRequest; import javax.annotation.PostConstruct; import javax.servlet.http.HttpServletResponse; import java.lang.reflect.Method; -import java.util.Date; -import java.util.Iterator; -import java.util.List; +import java.util.*; +import java.util.function.Function; /** * 默认 范型引用 子类的Service , 为简单的CRUD做足准备 @@ -353,6 +360,67 @@ public abstract class BaseRestController > handleTreeHasChildren(List> treeNodes, + Function, List> callback) { + if(CollUtil.isEmpty(treeNodes) || callback == null){ + return treeNodes; + } + + Set parentIds = Sets.newHashSet(); + for (Tree treeNode : treeNodes) { + parentIds.add(Convert.toStr(treeNode.getId())); + } + + // 数据排查是否存在下级 + List hasChildrenList = callback.apply(parentIds); + if(CollUtil.isEmpty(hasChildrenList)){ + hasChildrenList = ListUtil.empty(); + } + + // 字典 + Map hasChildrenDict = Maps.newHashMap(); + for (HasChildren hasChildren : hasChildrenList) { + if (hasChildren.getCount() != null && hasChildren.getCount() > 0) { + hasChildrenDict.put(hasChildren.getParentId(), true); + } + } + + // 处理节点 + this.handleTreeHasChildren(treeNodes, hasChildrenDict); + + return treeNodes; + } + + /** + * 处理 树节点是否 有子节点 + * @param treeNodes 树节点 + * @param hasChildrenDict 字典树 + */ + private void handleTreeHasChildren(List> treeNodes, + Map hasChildrenDict){ + + for (Tree treeNode : treeNodes) { + Boolean tmpFlag = hasChildrenDict.get(Convert.toStr(treeNode.getId())); + if (tmpFlag != null && tmpFlag) { + treeNode.putExtra(TreeConstants.IS_LEAF, false); + treeNode.putExtra(TreeConstants.HAS_CHILDREN, true); + }else { + treeNode.putExtra(TreeConstants.IS_LEAF, true); + treeNode.putExtra(TreeConstants.HAS_CHILDREN, false); + } + + // 如果不为空 则继续递归处理 + if(CollUtil.isNotEmpty(treeNode.getChildren())){ + handleTreeHasChildren(treeNode.getChildren(), hasChildrenDict); + } + } + } + // ================================================= @PostConstruct diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/entity/BaseEntity.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/entity/BaseEntity.java index 8262a03..5ad3612 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/entity/BaseEntity.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/entity/BaseEntity.java @@ -43,7 +43,7 @@ public abstract class BaseEntity extends ApiWrapper { /** @TableLogic - private Integer deleted; + private String deleted; **/ diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/service/impl/CrudServiceImpl.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/service/impl/CrudServiceImpl.java index e6dd1a3..3fa28ea 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/service/impl/CrudServiceImpl.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/service/impl/CrudServiceImpl.java @@ -32,7 +32,8 @@ import org.opsli.core.base.service.interfaces.CrudServiceInterface; import org.opsli.core.persistence.Page; 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.core.persistence.querybuilder.chain.QueryOrgHandler; +import org.opsli.core.persistence.querybuilder.chain.QueryTenantHandler; import org.springframework.transaction.annotation.Transactional; import javax.annotation.PostConstruct; @@ -210,17 +211,24 @@ public abstract class CrudServiceImpl, T extends BaseEnt @Override public List findList(QueryWrapper queryWrapper) { - // 多租户处理 - QueryWrapper qWrapper = new TenantHandler().handler(entityClazz, queryWrapper); - return super.list(qWrapper); + // 数据处理责任链 + queryWrapper = new QueryTenantHandler( + new QueryOrgHandler() + ).handler(entityClazz, queryWrapper); + + return super.list(queryWrapper); } @Override public List findAllList() { QueryBuilder queryBuilder = new GenQueryBuilder<>(); - // 多租户处理 - QueryWrapper qWrapper = new TenantHandler().handler(entityClazz, queryBuilder.build()); - return super.list(qWrapper); + QueryWrapper queryWrapper = queryBuilder.build(); + // 数据处理责任链 + queryWrapper = new QueryTenantHandler( + new QueryOrgHandler() + ).handler(entityClazz, queryWrapper); + + return super.list(queryWrapper); } @Override @@ -251,7 +259,6 @@ public abstract class CrudServiceImpl, T extends BaseEnt return page; } - // ======================== 对象转化 ======================== /** diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/msgs/OrgMsgFactory.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/msgs/OrgMsgFactory.java index fd838da..39a3225 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/msgs/OrgMsgFactory.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/msgs/OrgMsgFactory.java @@ -18,8 +18,7 @@ package org.opsli.core.cache.pushsub.msgs; import com.alibaba.fastjson.JSONObject; import lombok.Data; import lombok.experimental.Accessors; -import org.opsli.api.wrapper.system.menu.MenuModel; -import org.opsli.api.wrapper.system.user.UserOrgRefModel; +import org.opsli.api.wrapper.system.user.UserOrgRefWebModel; import org.opsli.core.cache.pushsub.enums.MsgArgsType; import org.opsli.core.cache.pushsub.enums.PushSubType; import org.opsli.core.cache.pushsub.receiver.RedisPushSubReceiver; @@ -45,7 +44,7 @@ public final class OrgMsgFactory extends BaseSubMessage{ * @param orgRefModel 用户组织模型 * @return 消息 */ - public static BaseSubMessage createOrgMsg(UserOrgRefModel orgRefModel){ + public static BaseSubMessage createOrgMsg(UserOrgRefWebModel orgRefModel){ BaseSubMessage baseSubMessage = new BaseSubMessage(); // 数据 JSONObject jsonObj = new JSONObject(); diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/msgs/TenantMsgFactory.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/msgs/TenantMsgFactory.java index ec82e5e..73124ef 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/msgs/TenantMsgFactory.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/msgs/TenantMsgFactory.java @@ -19,7 +19,6 @@ import com.alibaba.fastjson.JSONObject; import lombok.Data; import lombok.experimental.Accessors; import org.opsli.api.wrapper.system.tenant.TenantModel; -import org.opsli.api.wrapper.system.user.UserOrgRefModel; import org.opsli.core.cache.pushsub.enums.MsgArgsType; import org.opsli.core.cache.pushsub.enums.PushSubType; import org.opsli.core.cache.pushsub.receiver.RedisPushSubReceiver; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/WebQueryBuilder.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/WebQueryBuilder.java index 5da15a9..7a61ac1 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/WebQueryBuilder.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/WebQueryBuilder.java @@ -38,6 +38,10 @@ public class WebQueryBuilder implements QueryBuilder{ private static final String EQ = "EQ"; /** 模糊匹配 */ private static final String LIKE = "LIKE"; + /** 左模糊匹配 */ + private static final String LIKE_LEFT = "LIKEL"; + /** 右模糊匹配 */ + private static final String LIKE_RIGHT = "LIKER"; /** 日期匹配 */ private static final String BEGIN = "BEGIN"; private static final String END = "END"; @@ -217,6 +221,14 @@ public class WebQueryBuilder implements QueryBuilder{ // 模糊匹配 queryWrapper.like(key, value); break; + case LIKE_LEFT: + // 模糊匹配 左 + queryWrapper.likeLeft(key, value); + break; + case LIKE_RIGHT: + // 模糊匹配 右 + queryWrapper.likeRight(key, value); + break; case BEGIN: // 大于等于 queryWrapper.ge(key, value); @@ -282,6 +294,8 @@ public class WebQueryBuilder implements QueryBuilder{ case EQ: case END: case LIKE: + case LIKE_LEFT: + case LIKE_RIGHT: case BEGIN: return true; default: diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/chain/QueryOrgHandler.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/chain/QueryOrgHandler.java new file mode 100644 index 0000000..e782f9f --- /dev/null +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/chain/QueryOrgHandler.java @@ -0,0 +1,71 @@ +/** + * 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.core.persistence.querybuilder.chain; + +import cn.hutool.core.util.ReflectUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import org.apache.commons.lang3.StringUtils; +import org.opsli.api.wrapper.system.user.UserModel; +import org.opsli.common.constants.MyBatisConstants; +import org.opsli.common.utils.FieldUtil; +import org.opsli.core.base.entity.BaseEntity; +import org.opsli.core.utils.UserUtil; + +/** + * 组织赋值处理 + * + * @author Parker + * @date 2020-09-13 19:36 + */ +public class QueryOrgHandler implements QueryBuilderChain{ + + /** + * 子 责任链 + */ + private QueryBuilderChain queryBuilderChain; + + + public QueryOrgHandler(){} + + /** + * 构造函数 + * @param queryBuilderChain 责任链 + */ + public QueryOrgHandler(QueryBuilderChain queryBuilderChain){ + this.queryBuilderChain = queryBuilderChain; + } + + @Override + public QueryWrapper handler(Class entityClazz, QueryWrapper wrapper) { + // 执行 子 责任链 + if(queryBuilderChain != null){ + wrapper = queryBuilderChain.handler(entityClazz, wrapper); + } + + // 自身责任 -- 判断组织 + boolean flag = ReflectUtil.hasField(entityClazz, MyBatisConstants.FIELD_ORG_GROUP); + if(flag) { + // 1. 获得 用户 数据权限 + + // 2. 获得 角色 数据权限 + + } + + + return wrapper; + } + +} diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/chain/TenantHandler.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/chain/QueryTenantHandler.java similarity index 93% rename from opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/chain/TenantHandler.java rename to opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/chain/QueryTenantHandler.java index df81d40..786ad32 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/chain/TenantHandler.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/chain/QueryTenantHandler.java @@ -30,7 +30,7 @@ import org.opsli.core.utils.UserUtil; * @author Parker * @date 2020-09-13 19:36 */ -public class TenantHandler implements QueryBuilderChain{ +public class QueryTenantHandler implements QueryBuilderChain{ /** * 子 责任链 @@ -38,18 +38,23 @@ public class TenantHandler implements QueryBuilderChain{ private QueryBuilderChain queryBuilderChain; - public TenantHandler(){} + public QueryTenantHandler(){} /** * 构造函数 * @param queryBuilderChain 责任链 */ - public TenantHandler(QueryBuilderChain queryBuilderChain){ + public QueryTenantHandler(QueryBuilderChain queryBuilderChain){ this.queryBuilderChain = queryBuilderChain; } @Override public QueryWrapper handler(Class entityClazz, QueryWrapper wrapper) { + // 执行 子 责任链 + if(queryBuilderChain != null){ + wrapper = queryBuilderChain.handler(entityClazz, wrapper); + } + // 自身责任 -- 判断多租户 boolean tenantFlag = ReflectUtil.hasField(entityClazz, MyBatisConstants.FIELD_TENANT); if(tenantFlag) { @@ -62,11 +67,6 @@ public class TenantHandler implements QueryBuilderChain{ wrapper.eq(FieldUtil.humpToUnderline(MyBatisConstants.FIELD_TENANT), tenantId); } } - - // 执行 子 责任链 - if(queryBuilderChain != null){ - wrapper = queryBuilderChain.handler(entityClazz, wrapper); - } return wrapper; } diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/OrgUtil.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/OrgUtil.java index 8894c39..3e24599 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/OrgUtil.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/OrgUtil.java @@ -15,11 +15,24 @@ */ package org.opsli.core.utils; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.ListUtil; +import cn.hutool.core.convert.Convert; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.google.common.collect.Lists; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.opsli.api.base.result.ResultVo; import org.opsli.api.web.system.user.UserApi; +import org.opsli.api.web.system.user.UserOrgRefApi; +import org.opsli.api.wrapper.system.menu.MenuModel; +import org.opsli.api.wrapper.system.org.SysOrgModel; +import org.opsli.api.wrapper.system.user.UserModel; import org.opsli.api.wrapper.system.user.UserOrgRefModel; +import org.opsli.api.wrapper.system.user.UserOrgRefWebModel; +import org.opsli.common.enums.DictType; +import org.opsli.common.utils.FieldUtil; +import org.opsli.common.utils.ListDistinctUtil; import org.opsli.core.cache.local.CacheUtil; import org.opsli.core.msg.CoreMsg; import org.springframework.beans.factory.annotation.Autowired; @@ -27,6 +40,8 @@ import org.springframework.context.annotation.Lazy; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; +import java.util.List; + import static org.opsli.common.constants.OrderConstants.UTIL_ORDER; /** @@ -44,18 +59,25 @@ public class OrgUtil { /** 前缀 */ public static final String PREFIX_CODE = "org:userId:"; - /** 用户 Api */ - private static UserApi userApi; + /** 用户表 是否分配组织 状态标识 */ + public static final String USER_ORG_FIELD = "iz_exist_org"; + /** 显示全部 */ + public static final String ORG_ALL = "org_all"; + /** 未分组 */ + public static final String ORG_NULL = "org_null"; + + /** 用户组织 Api */ + private static UserOrgRefApi userOrgRefApi; /** 增加初始状态开关 防止异常使用 */ private static boolean IS_INIT; /** - * 根据 userId 获得用户组织 + * 根据 userId 获得用户菜单 * @param userId 用户ID - * @return model + * @return List */ - public static UserOrgRefModel getOrgByUserId(String userId){ + public static List getOrgListByUserId(String userId){ // 判断 工具类是否初始化完成 ThrowExceptionUtil.isThrowException(!IS_INIT, CoreMsg.OTHER_EXCEPTION_UTILS_INIT); @@ -63,56 +85,160 @@ public class OrgUtil { // 缓存Key String cacheKey = PREFIX_CODE + userId; + List orgList; + // 先从缓存里拿 - UserOrgRefModel orgRefModel = CacheUtil.getTimed(UserOrgRefModel.class, cacheKey); - if (orgRefModel != null){ - return orgRefModel; + Object obj = CacheUtil.getTimed(cacheKey); + orgList = Convert.toList(UserOrgRefModel.class, obj); + if(CollUtil.isNotEmpty(orgList)){ + return orgList; } // 拿不到 -------- // 防止缓存穿透判断 boolean hasNilFlag = CacheUtil.hasNilFlag(cacheKey); if(hasNilFlag){ - return null; + return ListUtil.empty(); } + try { // 分布式加锁 if(!DistributedLockUtil.lock(cacheKey)){ // 无法申领分布式锁 log.error(CoreMsg.REDIS_EXCEPTION_LOCK.getMessage()); - return null; + return ListUtil.empty(); } // 如果获得锁 则 再次检查缓存里有没有, 如果有则直接退出, 没有的话才发起数据库请求 - orgRefModel = CacheUtil.getTimed(UserOrgRefModel.class, cacheKey); - if (orgRefModel != null){ - return orgRefModel; + obj = CacheUtil.getTimed(cacheKey); + orgList = Convert.toList(UserOrgRefModel.class, obj); + if(CollUtil.isNotEmpty(orgList)){ + return orgList; } // 查询数据库 - ResultVo resultVo = userApi.getOrgInfoByUserId(userId); + ResultVo> resultVo = userOrgRefApi.findListByUserId(userId); if(resultVo.isSuccess()){ - orgRefModel = resultVo.getData(); + orgList = resultVo.getData(); // 存入缓存 - CacheUtil.put(cacheKey, orgRefModel); + CacheUtil.put(cacheKey, orgList); } }catch (Exception e){ - log.error(e.getMessage(),e); + log.error(e.getMessage(), e); }finally { // 释放锁 DistributedLockUtil.unlock(cacheKey); } - if(orgRefModel == null){ + if(CollUtil.isEmpty(orgList)){ // 设置空变量 用于防止穿透判断 CacheUtil.putNilFlag(cacheKey); - return null; + return ListUtil.empty(); } - return orgRefModel; + return orgList; } + /** + * 处理展示节点 + * @param parentId 父节点ID + * @param orgModelList 组织集合 + * @return List + */ + public static List createDefShowNodes(String parentId, List orgModelList) { + // 显示全部 + SysOrgModel orgAll = new SysOrgModel(); + orgAll.setId(ORG_ALL); + orgAll.setOrgName("全部"); + orgAll.setParentId(parentId); + orgAll.setSortNo(-2); + orgModelList.add(orgAll); + + // 未分组 + SysOrgModel orgNull = new SysOrgModel(); + orgNull.setId(ORG_NULL); + orgNull.setOrgName("未分组"); + orgNull.setParentId(parentId); + orgNull.setSortNo(-1); + orgModelList.add(orgNull); + + return orgModelList; + } + + /** + * 处理 组织ID 组条件 + * @param orgIdGroup 父节点ID + * @param queryWrapper 组织集合 + */ + public static void handleOrgIdGroupCondition(String orgIdGroup, QueryWrapper queryWrapper) { + String userRefOrgField = "b.org_ids"; + + queryWrapper.and(wra -> { + + if(!ORG_NULL.equals(orgIdGroup)){ + wra.and(wraConfine -> { + // 增加自身 组织限制 + UserModel currUser = UserUtil.getUser(); + List orgListByUserId = OrgUtil.getOrgListByUserId(currUser.getId()); + if(CollUtil.isEmpty(orgListByUserId)){ + // 如果为空 则默认 不查询 + wraConfine.eq("1", "2"); + }else { + List parentIdList = Lists.newArrayListWithCapacity(orgListByUserId.size()); + // 处理ParentId数据 + for (UserOrgRefModel userOrgRefModel : orgListByUserId) { + parentIdList.add(userOrgRefModel.getOrgIds()); + } + // 去重 + parentIdList = ListDistinctUtil.distinct(parentIdList); + + // 增加右模糊 查询条件 + for (int i = 0; i < parentIdList.size(); i++) { + // 右模糊匹配 + wraConfine.likeRight( + userRefOrgField, + parentIdList.get(i)); + + if(i < parentIdList.size() - 1){ + wraConfine.or(); + } + } + } + }); + } + + // 放在后面 前面会报错 + switch (orgIdGroup){ + case ORG_ALL: + wra.and(wraAll -> { + wraAll.eq(FieldUtil.humpToUnderline(USER_ORG_FIELD), + DictType.NO_YES_YES.getValue()); + }); + wra.or(wraAll -> { + wraAll.eq(FieldUtil.humpToUnderline(USER_ORG_FIELD), + DictType.NO_YES_NO.getValue()); + }); + break; + case ORG_NULL: + wra.and(wraNo -> { + wraNo.eq(FieldUtil.humpToUnderline(USER_ORG_FIELD), + DictType.NO_YES_NO.getValue()); + }); + break; + default: + // 右模糊匹配 + wra.likeRight( + userRefOrgField, orgIdGroup); + wra.and(wraYes -> { + wraYes.eq(FieldUtil.humpToUnderline(USER_ORG_FIELD), + DictType.NO_YES_YES.getValue()); + }); + break; + } + + }); + } // ============== 刷新缓存 ============== @@ -133,7 +259,7 @@ public class OrgUtil { // 计数器 int count = 0; - UserOrgRefModel orgRefModel = CacheUtil.getTimed(UserOrgRefModel.class, PREFIX_CODE + userId); + UserOrgRefWebModel orgRefModel = CacheUtil.getTimed(UserOrgRefWebModel.class, PREFIX_CODE + userId); boolean hasNilFlag = CacheUtil.hasNilFlag(PREFIX_CODE + userId); // 只要不为空 则执行刷新 @@ -164,8 +290,8 @@ public class OrgUtil { * 初始化 */ @Autowired - public void init(UserApi userApi) { - OrgUtil.userApi = userApi; + public void init(UserOrgRefApi userOrgRefApi) { + OrgUtil.userOrgRefApi = userOrgRefApi; IS_INIT = true; } 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 index 6d5e811..0d1ffb7 100644 --- 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 @@ -49,6 +49,6 @@ public class SysArea extends BaseEntity { /** 逻辑删除字段 */ @TableLogic - private Integer deleted; + private String deleted; } 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 4f683e3..00e9b27 100644 --- 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 @@ -42,6 +42,7 @@ import org.opsli.common.annotation.ApiRestController; import org.opsli.common.annotation.EnableLog; import org.opsli.common.annotation.RequiresPermissionsCus; import org.opsli.common.constants.MyBatisConstants; +import org.opsli.common.constants.TreeConstants; import org.opsli.common.utils.FieldUtil; import org.opsli.core.base.controller.BaseRestController; import org.opsli.core.base.entity.HasChildren; @@ -74,8 +75,6 @@ import java.util.Set; public class SysAreaRestController extends BaseRestController implements SysAreaRestApi { - /** 是否包含子集 */ - private static final String HAS_CHILDREN = "hasChildren"; /** 排序字段 */ private static final String SORT_FIELD = "sortNo"; @@ -122,7 +121,8 @@ public class SysAreaRestController extends BaseRestController> treeNodes = TreeBuildUtil.INSTANCE.build(beanMapList, parentId, treeNodeConfig); // 处理是否包含子集 - this.handleTreeHasChildren(treeNodes); + super.handleTreeHasChildren(treeNodes, + (parentIds)-> IService.hasChildren(parentIds)); return ResultVo.success(treeNodes); } @@ -156,7 +156,8 @@ public class SysAreaRestController extends BaseRestController> treeNodes = TreeBuildUtil.INSTANCE.build(beanMapList, treeNodeConfig); // 处理是否包含子集 - this.handleTreeHasChildren(treeNodes); + super.handleTreeHasChildren(treeNodes, + (parentIds)-> IService.hasChildren(parentIds)); return ResultVo.success(treeNodes); } @@ -309,39 +310,6 @@ public class SysAreaRestController extends BaseRestController> treeNodes) { - if(CollUtil.isEmpty(treeNodes)){ - return; - } - - Set parentIds = Sets.newHashSet(); - for (Tree treeNode : treeNodes) { - parentIds.add(Convert.toStr(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(Convert.toStr(treeNode.getId())); - if (tmpFlag != null && tmpFlag) { - treeNode.putExtra(HAS_CHILDREN, true); - } - } - } - } - /** * 导入数据 diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/entity/SysDict.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/entity/SysDict.java index d21f822..9115ef1 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/entity/SysDict.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/entity/SysDict.java @@ -52,6 +52,6 @@ public class SysDict extends BaseEntity { /** 逻辑删除字段 */ @TableLogic - private Integer deleted; + private String deleted; } diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/entity/SysDictDetail.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/entity/SysDictDetail.java index ac5a07f..a6eab95 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/entity/SysDictDetail.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/entity/SysDictDetail.java @@ -60,6 +60,6 @@ public class SysDictDetail extends BaseEntity { /** 逻辑删除字段 */ @TableLogic - private Integer deleted; + private String deleted; } diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/entity/SysMenu.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/entity/SysMenu.java index 53eb13f..dfe86bf 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/entity/SysMenu.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/entity/SysMenu.java @@ -74,6 +74,6 @@ public class SysMenu extends BaseEntity { /** 逻辑删除字段 */ @TableLogic - private Integer deleted; + private String deleted; } diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/web/MenuRestController.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/web/MenuRestController.java index b3eb587..2289d9d 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/web/MenuRestController.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/web/MenuRestController.java @@ -25,7 +25,6 @@ import cn.hutool.core.util.ReflectUtil; 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.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; @@ -41,10 +40,10 @@ import org.opsli.common.annotation.EnableLog; import org.opsli.common.annotation.RequiresPermissionsCus; import org.opsli.common.constants.MenuConstants; import org.opsli.common.constants.MyBatisConstants; +import org.opsli.common.enums.DictType; import org.opsli.common.utils.FieldUtil; import org.opsli.common.utils.WrapperUtil; import org.opsli.core.base.controller.BaseRestController; -import org.opsli.core.base.entity.HasChildren; import org.opsli.core.general.StartPrint; import org.opsli.core.persistence.Page; import org.opsli.core.persistence.querybuilder.GenQueryBuilder; @@ -63,7 +62,6 @@ import javax.servlet.http.HttpServletResponse; import java.lang.reflect.Method; import java.util.List; import java.util.Map; -import java.util.Set; /** @@ -83,10 +81,6 @@ public class MenuRestController extends BaseRestController MenuConstants.MENU.equals(menuModel.getType()) && + menuModelList.removeIf( + menuModel -> MenuConstants.MENU.equals(menuModel.getType()) && (StringUtils.isEmpty(menuModel.getComponent()) || StringUtils.isEmpty(menuModel.getUrl()) )); @@ -142,7 +137,8 @@ public class MenuRestController extends BaseRestController MenuConstants.MENU.equals(menuModel.getType()) && + menuModelList.removeIf( + menuModel -> MenuConstants.MENU.equals(menuModel.getType()) && (StringUtils.isEmpty(menuModel.getComponent()) || StringUtils.isEmpty(menuModel.getUrl()) )); @@ -167,14 +163,8 @@ public class MenuRestController extends BaseRestController menuModelList; if(StringUtils.isEmpty(parentId)){ menuModelList = Lists.newArrayList(); - parentId = VIRTUAL_TOTAL_NODE; - MenuModel model = new MenuModel(); - model.setId(MenuConstants.GEN_ID); - model.setMenuName("根节点"); - model.setHidden("0"); - model.setSortNo(-1); - model.setType("1"); - model.setParentId(parentId); + // 生成根节点菜单 + MenuModel model = getGenMenuModel(); menuModelList.add(model); }else{ // 只查菜单 @@ -182,7 +172,7 @@ public class MenuRestController extends BaseRestController queryWrapper = queryBuilder.build(); queryWrapper.eq( FieldUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId); - queryWrapper.eq("type", "1"); + queryWrapper.eq("type", MenuConstants.MENU); // 如果传入ID 则不包含自身 if(StringUtils.isNotEmpty(id)){ @@ -200,7 +190,8 @@ public class MenuRestController extends BaseRestController> treeNodes = getMenuTrees(menuModelList, parentId,1); // 处理是否包含子集 - this.handleTreeIsLeafByChoose(treeNodes); + super.handleTreeHasChildren(treeNodes, + (parentIds)-> IService.hasChildrenByChoose(parentIds)); return ResultVo.success(treeNodes); } @@ -216,14 +207,8 @@ public class MenuRestController extends BaseRestController menuModelList; if(StringUtils.isEmpty(parentId)){ menuModelList = Lists.newArrayList(); - parentId = VIRTUAL_TOTAL_NODE; - MenuModel model = new MenuModel(); - model.setId(MenuConstants.GEN_ID); - model.setMenuName("根节点"); - model.setHidden("0"); - model.setSortNo(-1); - model.setType("1"); - model.setParentId(parentId); + // 生成根节点菜单 + MenuModel model = getGenMenuModel(); menuModelList.add(model); }else{ QueryBuilder queryBuilder = new GenQueryBuilder<>(); @@ -238,7 +223,8 @@ public class MenuRestController extends BaseRestController> treeNodes = getMenuTrees(menuModelList, parentId,1); // 处理是否包含子集 - this.handleTreeHasChildren(treeNodes); + super.handleTreeHasChildren(treeNodes, + (parentIds)-> IService.hasChildren(parentIds)); return ResultVo.success(treeNodes); } @@ -251,11 +237,9 @@ public class MenuRestController extends BaseRestController findMenuTreePage(HttpServletRequest request) { - QueryBuilder queryBuilder = new WebQueryBuilder<>(entityClazz, request.getParameterMap()); - // 获得菜单 List menuList = IService.findList(queryBuilder.build()); List menuModelList = WrapperUtil.transformInstance(menuList, MenuModel.class); @@ -292,11 +276,8 @@ public class MenuRestController extends BaseRestController get(MenuModel model) { if(model != null){ if(StringUtils.equals(MenuConstants.GEN_ID, model.getId())){ - model.setMenuName("根节点"); - model.setHidden("0"); - model.setSortNo(-1); - model.setType("1"); - model.setParentId(VIRTUAL_TOTAL_NODE); + // 生成根节点菜单 + model = getGenMenuModel(); }else{ // 如果系统内部调用 则直接查数据库 if (model.getIzApi() != null && model.getIzApi()){ @@ -589,72 +570,19 @@ public class MenuRestController extends BaseRestController> treeNodes) { - if(CollUtil.isEmpty(treeNodes)){ - return; - } - - Set parentIds = Sets.newHashSet(); - for (Tree treeNode : treeNodes) { - parentIds.add(Convert.toStr(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(Convert.toStr(treeNode.getId())); - if (tmpFlag != null && tmpFlag) { - treeNode.putExtra(HAS_CHILDREN, true); - } - } - } - } - - - /** - * 处理是否包含子集 - * @param treeNodes 树节点 - */ - private void handleTreeIsLeafByChoose(List> treeNodes) { - if(CollUtil.isEmpty(treeNodes)){ - return; - } - - Set parentIds = Sets.newHashSet(); - for (Tree treeNode : treeNodes) { - parentIds.add(Convert.toStr(treeNode.getId())); - } - - // 数据排查是否存在下级 - List hasChildrenList = IService.hasChildrenByChoose(parentIds); - Map tmp = Maps.newHashMap(); - for (HasChildren hasChildren : hasChildrenList) { - if (hasChildren.getCount() != null && hasChildren.getCount() > 0) { - tmp.put(hasChildren.getParentId(), false); - } - } - - for (Tree treeNode : treeNodes) { - Boolean tmpFlag = tmp.get(Convert.toStr(treeNode.getId())); - if (tmpFlag == null || tmpFlag) { - treeNode.putExtra(IS_LEAF, true); - }else { - treeNode.putExtra(IS_LEAF, false); - } - } + private MenuModel getGenMenuModel() { + MenuModel model = new MenuModel(); + model.setId(MenuConstants.GEN_ID); + model.setMenuName("根菜单"); + model.setHidden(DictType.NO_YES_NO.getValue()); + model.setSortNo(-1); + model.setType(MenuConstants.MENU); + model.setParentId(VIRTUAL_TOTAL_NODE); + return model; } /** 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 index 4de9e57..ac7758e 100644 --- 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 @@ -33,29 +33,31 @@ import org.opsli.core.base.entity.BaseEntity; @EqualsAndHashCode(callSuper = false) public class SysOrg extends BaseEntity { - /** 父级主键 */ private String parentId; + /** 父级主键集合 xxx,xxx */ + private String parentIds; + /** 组织机构编号 */ private String orgCode; /** 组织机构名称 */ private String orgName; - /** 组织机构类型: 1-公司 2-部门 3-岗位 */ - private String orgType; - /** 排序 */ private Integer sortNo; + /** 备注 */ + @TableField(updateStrategy = FieldStrategy.IGNORED) + private String remark; // ======================================== /** 逻辑删除字段 */ @TableLogic - private Integer deleted; + private String deleted; /** 多租户字段 */ private String tenantId; 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 index 0908365..cadd01e 100644 --- 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 @@ -1,23 +1,24 @@ /** -* 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. -*/ + * 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 cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; @@ -30,7 +31,7 @@ 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.core.persistence.querybuilder.chain.QueryTenantHandler; import org.opsli.modulars.system.SystemMsg; import org.opsli.modulars.system.org.entity.SysOrg; import org.opsli.modulars.system.org.mapper.SysOrgMapper; @@ -52,10 +53,12 @@ import java.util.Set; */ @Service public class SysOrgServiceImpl extends CrudServiceImpl - implements ISysOrgService { + implements ISysOrgService { /** 顶级ID */ private static final String TOP_PARENT_ID = "0"; + /** 分割符 */ + private static final String DELIMITER = ","; @Autowired(required = false) private SysOrgMapper mapper; @@ -67,6 +70,8 @@ public class SysOrgServiceImpl extends CrudServiceImpl 0){ @@ -77,15 +82,23 @@ public class SysOrgServiceImpl extends CrudServiceImpl 0){ @@ -108,13 +123,22 @@ public class SysOrgServiceImpl extends CrudServiceImpl queryBuilder = new GenQueryBuilder<>(); QueryWrapper queryWrapper = queryBuilder.build(); - queryWrapper.eq(FieldUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId); + queryWrapper.eq( + FieldUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId); List entityList = super.findList(queryWrapper); for (SysOrg sysOrg : entityList) { sysOrg.setTenantId(tenantId); @@ -182,6 +217,32 @@ public class SysOrgServiceImpl extends CrudServiceImpl queryBuilder = new GenQueryBuilder<>(); + QueryWrapper queryWrapper = queryBuilder.build(); + queryWrapper.eq( + FieldUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId); + List entityList = super.findList(queryWrapper); + for (SysOrg sysOrg : entityList) { + SysOrgModel sysOrgModel = super.get(parentId); + + // 下级沿用上级ParentIds + sysOrg.setParentIds( + StrUtil.appendIfMissing( + sysOrgModel.getParentIds(), DELIMITER) + + sysOrgModel.getId()); + + super.updateById(sysOrg); + // 逐级删除子数据 + this.updateChildrenParentIdsByParentId(sysOrg.getId()); + } + } + /** * 逐级删除子数据 * @param parentId 父级ID @@ -190,7 +251,8 @@ public class SysOrgServiceImpl extends CrudServiceImpl queryBuilder = new GenQueryBuilder<>(); QueryWrapper queryWrapper = queryBuilder.build(); - queryWrapper.eq(FieldUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId); + queryWrapper.eq( + FieldUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId); List entityList = super.findList(queryWrapper); for (SysOrg sysOrg : entityList) { super.delete(sysOrg.getId()); @@ -219,7 +281,7 @@ public class SysOrgServiceImpl extends CrudServiceImpl wrapper = new QueryWrapper<>(); - wrapper.in(FieldUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentIds) .eq(MyBatisConstants.FIELD_DELETE_LOGIC, DictType.NO_YES_NO.getValue()) .groupBy(FieldUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID)); 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 index 0d6fc66..43504af 100644 --- 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 @@ -20,28 +20,34 @@ import cn.hutool.core.convert.Convert; import cn.hutool.core.lang.tree.Tree; import cn.hutool.core.lang.tree.TreeNodeConfig; import cn.hutool.core.util.ReflectUtil; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.google.common.collect.Maps; +import com.google.common.collect.Lists; import com.google.common.collect.Sets; import io.swagger.annotations.Api; 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.org.SysOrgRestApi; import org.opsli.api.wrapper.system.org.SysOrgModel; +import org.opsli.api.wrapper.system.user.UserModel; +import org.opsli.api.wrapper.system.user.UserOrgRefModel; import org.opsli.common.annotation.ApiRestController; import org.opsli.common.annotation.EnableLog; import org.opsli.common.annotation.RequiresPermissionsCus; import org.opsli.common.constants.MyBatisConstants; import org.opsli.common.utils.FieldUtil; +import org.opsli.common.utils.ListDistinctUtil; import org.opsli.common.utils.WrapperUtil; import org.opsli.core.base.controller.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.core.utils.OrgUtil; import org.opsli.core.utils.TreeBuildUtil; +import org.opsli.core.utils.UserUtil; import org.opsli.modulars.system.org.entity.SysOrg; import org.opsli.modulars.system.org.service.ISysOrgService; import org.springframework.web.multipart.MultipartHttpServletRequest; @@ -50,7 +56,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.lang.reflect.Method; import java.util.List; -import java.util.Map; import java.util.Set; /** @@ -65,117 +70,161 @@ import java.util.Set; public class SysOrgRestController extends BaseRestController implements SysOrgRestApi { + /** 虚拟总节点 ID */ + private static final String VIRTUAL_TOTAL_NODE = "-1"; /** 父节点ID */ private static final String PARENT_ID = "0"; - /** 显示全部 */ - public static final String ORG_ALL = "all"; - /** 未分组 */ - public static final String ORG_NULL = "org_null"; /** 排序字段 */ private static final String SORT_FIELD = "sortNo"; - /** 是否包含子集 */ - private static final String HAS_CHILDREN = "hasChildren"; + /** 分割符 */ + private static final String DELIMITER = ","; /** - * 获得组织树 懒加载 + * 获得当前用户下 组织 * @return ResultVo */ - @ApiOperation(value = "获得组织树 懒加载", notes = "获得组织树 懒加载") + @ApiOperation(value = "获得当前用户下 组织", notes = "获得当前用户下 组织") @Override - public ResultVo findTreeLazyByUser(String parentId) { + public ResultVo findTreeByDefWithUserToLike() { + // 生成 全部/未分组 + String parentId = PARENT_ID; + List orgModelList = OrgUtil.createDefShowNodes(parentId, Lists.newArrayList()); QueryBuilder queryBuilder = new GenQueryBuilder<>(); QueryWrapper wrapper = queryBuilder.build(); - wrapper.eq(FieldUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId); - - // 获得用户 对应菜单 - List dataList = IService.findList(wrapper); - List orgModelList = WrapperUtil.transformInstance(dataList, modelClazz); - - // 处理展示节点 - this.handleShowNodes(parentId, orgModelList); - - //配置 - TreeNodeConfig treeNodeConfig = new TreeNodeConfig(); - // 自定义属性名 都要默认值的 - treeNodeConfig.setWeightKey(SORT_FIELD); - // 最大递归深度 最多支持4层菜单 - treeNodeConfig.setDeep(3); - - //转换器 - List> treeNodes = TreeBuildUtil.INSTANCE.build(orgModelList, parentId, treeNodeConfig); + UserModel currUser = UserUtil.getUser(); + List orgListByUserId = OrgUtil.getOrgListByUserId(currUser.getId()); + if(!CollUtil.isEmpty(orgListByUserId)){ + List parentIdList = Lists.newArrayListWithCapacity(orgListByUserId.size()); + + // 处理ParentId数据 + for (UserOrgRefModel userOrgRefModel : orgListByUserId) { + String orgId = userOrgRefModel.getOrgId(); + String orgIds = userOrgRefModel.getOrgIds(); + // 减掉 结尾自身 orgId 得到 org表中 parentIds + String parentIds = + StrUtil.replace(orgIds, StrUtil.prependIfMissing(orgId, DELIMITER), ""); + parentIdList.add(parentIds); + } - // 处理是否包含子集 - this.handleTreeHasChildren(treeNodes); + // 去重 + parentIdList = ListDistinctUtil.distinct(parentIdList); + + List finalParentIdList = parentIdList; + wrapper.and(wra -> { + // 增加右模糊 查询条件 + for (int i = 0; i < finalParentIdList.size(); i++) { + // 右模糊匹配 + wra.likeRight( + FieldUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_IDS), + finalParentIdList.get(i)); + + if(i < finalParentIdList.size() - 1){ + wra.or(); + } + } + }); + + // 获得组织 + List dataList = IService.findList(wrapper); + if(CollUtil.isNotEmpty(dataList)){ + for (SysOrg sysOrg : dataList) { + // 如果父级ID 与 当前检索父级ID 一致 则默认初始化ID为主ID + if(!CollUtil.contains(parentIdList, sysOrg.getParentIds())){ + continue; + } + + sysOrg.setParentId(parentId); + } + orgModelList.addAll( + WrapperUtil.transformInstance(dataList, modelClazz) + ); + } + } - return ResultVo.success(treeNodes); + // 处理组织树 + return handleOrgTree(parentId, orgModelList, false); } - - - /** * 获得组织树 懒加载 * @return ResultVo */ @ApiOperation(value = "获得组织树 懒加载", notes = "获得组织树 懒加载") @Override - public ResultVo findTreeLazy(String parentId) { - - QueryBuilder queryBuilder = new GenQueryBuilder<>(); - QueryWrapper wrapper = queryBuilder.build(); - wrapper.eq(FieldUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId); - - // 获得用户 对应菜单 - List dataList = IService.findList(wrapper); - List orgModelList = WrapperUtil.transformInstance(dataList, modelClazz); - - - //配置 - TreeNodeConfig treeNodeConfig = new TreeNodeConfig(); - // 自定义属性名 都要默认值的 - treeNodeConfig.setWeightKey(SORT_FIELD); - // 最大递归深度 最多支持4层菜单 - treeNodeConfig.setDeep(3); + public ResultVo findTreeLazy(String parentId, String id) { + List orgModelList; + if(StringUtils.isEmpty(parentId)){ + orgModelList = Lists.newArrayList(); + parentId = VIRTUAL_TOTAL_NODE; + // 生成根节点组织 + SysOrgModel model = getGenOrgModel(); + orgModelList.add(model); + }else{ + QueryBuilder queryBuilder = new GenQueryBuilder<>(); + QueryWrapper wrapper = queryBuilder.build(); + wrapper.eq(FieldUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId); + + // 如果传入ID 则不包含自身 + if(StringUtils.isNotEmpty(id)){ + wrapper.notIn( + FieldUtil.humpToUnderline(MyBatisConstants.FIELD_ID), id); - //转换器 - List> treeNodes = TreeBuildUtil.INSTANCE.build(orgModelList, parentId, treeNodeConfig); + } - // 处理是否包含子集 - this.handleTreeHasChildren(treeNodes); + // 获得组织 + List dataList = IService.findList(wrapper); + orgModelList = WrapperUtil.transformInstance(dataList, modelClazz); + } - return ResultVo.success(treeNodes); + // 处理组织树 + return handleOrgTree(parentId, orgModelList, true); } /** - * 获得组织树树 + * 获得组织树 * @return ResultVo */ @ApiOperation(value = "获得组织树", notes = "获得组织树") + @RequiresPermissions("system_org_select") @Override - public ResultVo findGridTree(String parentId) { + public ResultVo findTreeByDef(boolean isGen, String id) { + List orgModelList = Lists.newArrayList(); + String parentId = PARENT_ID; + if(isGen){ + parentId = VIRTUAL_TOTAL_NODE; + // 生成根节点组织 + SysOrgModel model = getGenOrgModel(); + orgModelList.add(model); + } QueryBuilder queryBuilder = new GenQueryBuilder<>(); QueryWrapper wrapper = queryBuilder.build(); - wrapper.eq(FieldUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId); +// // 左模糊匹配 +// wrapper.likeLeft( +// FieldUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_IDS), parentId); + + // 如果传入ID 则不包含自身 + if(StringUtils.isNotEmpty(id)){ + wrapper.notIn( + FieldUtil.humpToUnderline(MyBatisConstants.FIELD_ID), id); + + } - // 获得用户 对应菜单 + // 获得组织 List dataList = IService.findList(wrapper); - List orgModelList = WrapperUtil.transformInstance(dataList, modelClazz); + if(CollUtil.isNotEmpty(dataList)){ + orgModelList.addAll( + WrapperUtil.transformInstance(dataList, modelClazz) + ); + } + // 处理组织树 + return handleOrgTree(parentId, orgModelList, false); + } - //配置 - TreeNodeConfig treeNodeConfig = new TreeNodeConfig(); - // 自定义属性名 都要默认值的 - treeNodeConfig.setWeightKey(SORT_FIELD); - // 最大递归深度 最多支持4层菜单 - treeNodeConfig.setDeep(3); - //转换器 - List> treeNodes = TreeBuildUtil.INSTANCE.build(orgModelList, parentId, treeNodeConfig); - return ResultVo.success(treeNodes); - } // ============== @@ -188,40 +237,19 @@ public class SysOrgRestController extends BaseRestController get(SysOrgModel model) { - // 如果系统内部调用 则直接查数据库 - if(model != null && model.getIzApi() != null && model.getIzApi()){ - model = IService.get(model); + if(model != null){ + if(StringUtils.equals(PARENT_ID, model.getId())){ + // 生成根节点组织 + model = getGenOrgModel(); + }else{ + // 如果系统内部调用 则直接查数据库 + if (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<>(entityClazz, - request.getParameterMap()); - - - // 获得用户 对应菜单 - List dataList = IService.findList(queryBuilder.build()); - //配置 - TreeNodeConfig treeNodeConfig = new TreeNodeConfig(); - // 自定义属性名 都要默认值的 - treeNodeConfig.setWeightKey(SORT_FIELD); - // 最大递归深度 最多支持4层菜单 - treeNodeConfig.setDeep(3); - - //转换器 - List> treeNodes = TreeBuildUtil.INSTANCE.build(dataList, treeNodeConfig); - - return ResultVo.success(treeNodes); + return ResultVo.success(model); } /** @@ -342,68 +370,56 @@ public class SysOrgRestController extends BaseRestController orgModelList) { - // 0 为初始值 - if(PARENT_ID.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); - } + private SysOrgModel getGenOrgModel() { + SysOrgModel model = new SysOrgModel(); + model.setId(PARENT_ID); + model.setOrgName("组织架构"); + model.setSortNo(-1); + model.setParentId(VIRTUAL_TOTAL_NODE); + return model; } + + /** - * 处理是否包含子集 - * @param treeNodes 树节点 + * 处理组织树 + * @param parentId 父级ID + * @param orgModelList 组织集合 + * @param izLazy 是否懒加载 + * @return ResultVo */ - private void handleTreeHasChildren(List> treeNodes) { - if(CollUtil.isEmpty(treeNodes)){ - return; - } + private ResultVo handleOrgTree(String parentId, List orgModelList, boolean izLazy) { + //配置 + TreeNodeConfig treeNodeConfig = new TreeNodeConfig(); + // 自定义属性名 都要默认值的 + treeNodeConfig.setWeightKey(SORT_FIELD); + // 最大递归深度 最多支持4层 + treeNodeConfig.setDeep(4); - Set parentIds = Sets.newHashSet(); - for (Tree treeNode : treeNodes) { - parentIds.add(Convert.toStr(treeNode.getId())); - } + //转换器 + List> treeNodes = TreeBuildUtil.INSTANCE.build(orgModelList, parentId, treeNodeConfig); - // 数据排查是否存在下级 - 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); - } + // 是否懒加载 + if(izLazy){ + // 处理是否包含子集 + super.handleTreeHasChildren(treeNodes, + (parentIds)-> IService.hasChildren(parentIds)); + }else{ + Set parentIdSet = Sets.newHashSet(); + for (SysOrgModel sysOrgModel : orgModelList) { + parentIdSet.add(sysOrgModel.getParentId()); } - for (Tree treeNode : treeNodes) { - Boolean tmpFlag = tmp.get(Convert.toStr(treeNode.getId())); - if (tmpFlag != null && tmpFlag) { - treeNode.putExtra(HAS_CHILDREN, true); - } - } + // 处理是否包含子集 + super.handleTreeHasChildren(treeNodes, + (parentIds)-> IService.hasChildren(parentIdSet)); } + + return ResultVo.success(treeNodes); } } diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/entity/SysRole.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/entity/SysRole.java index cdfc10c..0be5ca2 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/entity/SysRole.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/entity/SysRole.java @@ -51,7 +51,7 @@ public class SysRole extends BaseEntity { /** 逻辑删除字段 */ @TableLogic - private Integer deleted; + private String deleted; /** 多租户字段 */ private String tenantId; diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/service/impl/RoleServiceImpl.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/service/impl/RoleServiceImpl.java index b791df3..fc5fffd 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/service/impl/RoleServiceImpl.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/service/impl/RoleServiceImpl.java @@ -26,7 +26,8 @@ import org.opsli.common.exception.ServiceException; 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.core.persistence.querybuilder.chain.QueryOrgHandler; +import org.opsli.core.persistence.querybuilder.chain.QueryTenantHandler; import org.opsli.core.utils.UserUtil; import org.opsli.modulars.system.SystemMsg; import org.opsli.modulars.system.role.entity.SysRole; @@ -144,9 +145,10 @@ public class RoleServiceImpl extends CrudServiceImpl findList(QueryWrapper queryWrapper) { // 如果没有租户修改能力 则默认增加租户限制 if(!UserUtil.isHasUpdateTenantPerms(UserUtil.getUser())){ - // 多租户处理 - TenantHandler tenantHandler = new TenantHandler(); - tenantHandler.handler(entityClazz, queryWrapper); + // 数据处理责任链 + queryWrapper = new QueryTenantHandler( + new QueryOrgHandler() + ).handler(entityClazz, queryWrapper); } return super.list(queryWrapper); @@ -159,9 +161,10 @@ public class RoleServiceImpl extends CrudServiceImpl { * @param wrapper 条件查询器 * @return List */ - List findList(@Param(Constants.WRAPPER) Wrapper wrapper); + List findList(@Param(Constants.WRAPPER) Wrapper wrapper); } 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 0fdc42c..680ed3a 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 @@ -29,18 +29,13 @@ - ,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' + left join sys_user_org_ref b on b.user_id = a.id - select diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/IUserOrgRefService.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/IUserOrgRefService.java index cb5fc1b..fdd1123 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/IUserOrgRefService.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/IUserOrgRefService.java @@ -16,6 +16,7 @@ package org.opsli.modulars.system.user.service; import org.opsli.api.wrapper.system.user.UserOrgRefModel; +import org.opsli.api.wrapper.system.user.UserOrgRefWebModel; import java.util.List; @@ -33,6 +34,13 @@ public interface IUserOrgRefService { * @param model 模型 * @return boolean */ - boolean setOrg(UserOrgRefModel model); + boolean setOrg(UserOrgRefWebModel model); + + /** + * 根据用户ID 获得组织列表 + * @param userId 用户ID + * @return List + */ + List findListByUserId(String userId); } diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/IUserService.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/IUserService.java index d9a8986..08f9756 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/IUserService.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/IUserService.java @@ -16,13 +16,13 @@ package org.opsli.modulars.system.user.service; import org.opsli.api.wrapper.system.menu.MenuModel; -import org.opsli.api.wrapper.system.user.UserAndOrgModel; +import org.opsli.api.wrapper.system.user.UserWebModel; import org.opsli.api.wrapper.system.user.UserModel; import org.opsli.api.wrapper.system.user.UserPassword; import org.opsli.core.base.service.interfaces.CrudServiceInterface; import org.opsli.core.persistence.Page; import org.opsli.modulars.system.user.entity.SysUser; -import org.opsli.modulars.system.user.entity.SysUserAndOrg; +import org.opsli.modulars.system.user.entity.SysUserWeb; import java.util.List; @@ -122,5 +122,5 @@ public interface IUserService extends CrudServiceInterface { * @param page 分页 * @return Page */ - Page findPageByCus(Page page); + Page findPageByCus(Page page); } diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserOrgRefServiceImpl.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserOrgRefServiceImpl.java index c9cd359..febd8d8 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserOrgRefServiceImpl.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserOrgRefServiceImpl.java @@ -16,23 +16,44 @@ package org.opsli.modulars.system.user.service.impl; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.ListUtil; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.google.common.collect.Lists; import org.apache.commons.lang3.StringUtils; +import org.opsli.api.base.warpper.ApiWrapper; +import org.opsli.api.wrapper.system.org.SysOrgModel; +import org.opsli.api.wrapper.system.user.UserModel; import org.opsli.api.wrapper.system.user.UserOrgRefModel; +import org.opsli.api.wrapper.system.user.UserOrgRefWebModel; +import org.opsli.common.constants.MyBatisConstants; +import org.opsli.common.enums.DictType; import org.opsli.common.exception.ServiceException; +import org.opsli.common.utils.FieldUtil; +import org.opsli.common.utils.ListDistinctUtil; +import org.opsli.common.utils.WrapperUtil; import org.opsli.core.msg.CoreMsg; +import org.opsli.core.persistence.querybuilder.GenQueryBuilder; +import org.opsli.core.persistence.querybuilder.QueryBuilder; import org.opsli.core.utils.OrgUtil; +import org.opsli.core.utils.UserUtil; import org.opsli.modulars.system.SystemMsg; +import org.opsli.modulars.system.menu.entity.SysMenu; +import org.opsli.modulars.system.org.entity.SysOrg; +import org.opsli.modulars.system.org.service.ISysOrgService; +import org.opsli.modulars.system.user.entity.SysUser; import org.opsli.modulars.system.user.entity.SysUserOrgRef; import org.opsli.modulars.system.user.mapper.UserOrgRefMapper; import org.opsli.modulars.system.user.service.IUserOrgRefService; +import org.opsli.modulars.system.user.service.IUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.Collections; +import java.util.Comparator; import java.util.List; @@ -45,12 +66,62 @@ import java.util.List; @Service public class UserOrgRefServiceImpl extends ServiceImpl implements IUserOrgRefService { + /** 分割符 */ + private static final String DELIMITER = ","; + + /** 父节点ID */ + private static final String PARENT_ID = "0"; + @Autowired(required = false) private UserOrgRefMapper mapper; + @Autowired + private IUserService iUserService; + @Autowired + private ISysOrgService iSysOrgService; + + @Override + public List findListByUserId(String userId) { + if(StrUtil.isEmpty(userId)){ + return ListUtil.empty(); + } + + UserModel userModel = iUserService.get(userId); + if(userModel == null){ + return ListUtil.empty(); + } + + String userIdField = "user_id"; + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq(userIdField, userId); + + List orgRefList = super.list(wrapper); + + if(CollUtil.isEmpty(orgRefList)){ + + // 判断是否是超级管理员 如果是超级管理员 则默认享有全部权限 + if(StringUtils.equals(UserUtil.SUPER_ADMIN, userModel.getUsername())){ + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq( + FieldUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), PARENT_ID + ); + List orgList = iSysOrgService.findList(queryWrapper); + List sysOrgModels = WrapperUtil.transformInstance(orgList, SysOrgModel.class); + for (SysOrgModel orgModel : sysOrgModels) { + SysUserOrgRef orgRef = this.createOrgRef(userId, orgModel, DictType.NO_YES_NO.getValue()); + orgRefList.add(orgRef); + } + } + } + + return WrapperUtil.transformInstance( + orgRefList, UserOrgRefModel.class + ); + } + @Override @Transactional(rollbackFor = Exception.class) - public boolean setOrg(UserOrgRefModel model) { + public boolean setOrg(UserOrgRefWebModel model) { // 非法验证 组织不可为空 if(model == null){ throw new ServiceException(SystemMsg.EXCEPTION_ORG_NOT_NULL); @@ -60,41 +131,42 @@ public class UserOrgRefServiceImpl extends ServiceImpl wrapper = new QueryWrapper<>(); wrapper.eq(userIdField, model.getUserId()); - super.remove(wrapper); + boolean removeFlag = super.remove(wrapper); - List orgRefs = Lists.newArrayList(); + // 设置组织 + List orgRefList = Lists.newArrayList(); - // 设置公司 - if(StringUtils.isNotEmpty(model.getCompanyId())){ - SysUserOrgRef tmp = new SysUserOrgRef(); - tmp.setUserId(model.getUserId()); - tmp.setOrgId(model.getCompanyId()); - tmp.setOrgType("1"); - orgRefs.add(tmp); + SysOrgModel defModel = model.getDefModel(); + if(defModel != null){ + SysUserOrgRef orgRef = createOrgRef( + model.getUserId(), defModel, DictType.NO_YES_YES.getValue()); + orgRefList.add(orgRef); } - - // 设置部门 - if(StringUtils.isNotEmpty(model.getDepartmentId())){ - SysUserOrgRef tmp = new SysUserOrgRef(); - tmp.setUserId(model.getUserId()); - tmp.setOrgId(model.getDepartmentId()); - tmp.setOrgType("2"); - orgRefs.add(tmp); + List orgModelList = model.getOrgModelList(); + if(!CollUtil.isEmpty(orgModelList)){ + for (SysOrgModel orgModel : orgModelList) { + SysUserOrgRef orgRef = createOrgRef( + model.getUserId(), orgModel, DictType.NO_YES_NO.getValue()); + orgRefList.add(orgRef); + } } - // 设置岗位 - if(StringUtils.isNotEmpty(model.getPostId())){ - SysUserOrgRef tmp = new SysUserOrgRef(); - tmp.setUserId(model.getUserId()); - tmp.setOrgId(model.getPostId()); - tmp.setOrgType("3"); - orgRefs.add(tmp); + boolean izExistOrg = false; + + if(!CollUtil.isEmpty(orgRefList)){ + // 去重 + orgRefList = ListDistinctUtil.distinct( + orgRefList, Comparator.comparing(SysUserOrgRef::getId)); + + // 批量保存 + izExistOrg = super.saveBatch(orgRefList); } - boolean saveBatchFlag = super.saveBatch(orgRefs); + // 修改用户组织状态 + this.updateUserOrgFlag(model.getUserId(), izExistOrg); // 清空缓存 - if(saveBatchFlag){ + if(removeFlag){ // 刷新用户缓存 this.clearCache(Collections.singletonList(model.getUserId())); } @@ -102,6 +174,46 @@ public class UserOrgRefServiceImpl extends ServiceImpl updateUserWrapper = new UpdateWrapper<>(); + updateUserWrapper.set("iz_exist_org", flagVal); + updateUserWrapper.eq( + FieldUtil.humpToUnderline(MyBatisConstants.FIELD_ID), userId); + iUserService.update(updateUserWrapper); + } + + /** + * 生成Org关联对象 + * @param userId 用户ID + * @param orgModel 组织 + * @return ref + */ + private SysUserOrgRef createOrgRef(String userId, SysOrgModel orgModel, String izDef) { + String orgGroup = + StrUtil.appendIfMissing( + orgModel.getParentIds(), DELIMITER) + + orgModel.getId(); + + SysUserOrgRef orgRef = new SysUserOrgRef(); + orgRef.setUserId(userId); + orgRef.setOrgId(orgModel.getId()); + orgRef.setOrgIds(orgGroup); + orgRef.setIzDef(izDef); + return orgRef; + } + // ============ /** diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserServiceImpl.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserServiceImpl.java index cd93d43..2e4745a 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserServiceImpl.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserServiceImpl.java @@ -27,7 +27,7 @@ import org.apache.commons.lang3.StringUtils; import org.opsli.api.base.warpper.ApiWrapper; import org.opsli.api.wrapper.system.menu.MenuModel; import org.opsli.api.wrapper.system.options.OptionsModel; -import org.opsli.api.wrapper.system.user.UserAndOrgModel; +import org.opsli.api.wrapper.system.user.UserWebModel; import org.opsli.api.wrapper.system.user.UserModel; import org.opsli.api.wrapper.system.user.UserPassword; import org.opsli.common.constants.MyBatisConstants; @@ -42,7 +42,8 @@ import org.opsli.core.msg.CoreMsg; import org.opsli.core.persistence.Page; 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.core.persistence.querybuilder.chain.QueryOrgHandler; +import org.opsli.core.persistence.querybuilder.chain.QueryTenantHandler; import org.opsli.core.utils.OptionsUtil; import org.opsli.core.utils.UserUtil; import org.opsli.modulars.system.SystemMsg; @@ -51,7 +52,7 @@ import org.opsli.modulars.system.menu.service.IMenuService; import org.opsli.modulars.system.role.entity.SysRole; import org.opsli.modulars.system.role.service.IRoleService; import org.opsli.modulars.system.user.entity.SysUser; -import org.opsli.modulars.system.user.entity.SysUserAndOrg; +import org.opsli.modulars.system.user.entity.SysUserWeb; import org.opsli.modulars.system.user.mapper.UserMapper; import org.opsli.modulars.system.user.service.IUserRoleRefService; import org.opsli.modulars.system.user.service.IUserService; @@ -116,6 +117,8 @@ public class UserServiceImpl extends CrudServiceImpl findList(QueryWrapper queryWrapper) { // 如果没有租户修改能力 则默认增加租户限制 if(!UserUtil.isHasUpdateTenantPerms(UserUtil.getUser())){ - // 多租户处理 - TenantHandler tenantHandler = new TenantHandler(); - tenantHandler.handler(entityClazz, queryWrapper); + // 数据处理责任链 + queryWrapper = new QueryTenantHandler( + new QueryOrgHandler() + ).handler(entityClazz, queryWrapper); } return super.list(queryWrapper); @@ -559,9 +564,10 @@ public class UserServiceImpl extends CrudServiceImpl queryWrapper = queryBuilder.build(); // 如果没有租户修改能力 则默认增加租户限制 if(!UserUtil.isHasUpdateTenantPerms(UserUtil.getUser())){ - // 多租户处理 - TenantHandler tenantHandler = new TenantHandler(); - tenantHandler.handler(entityClazz, queryWrapper); + // 数据处理责任链 + queryWrapper = new QueryTenantHandler( + new QueryOrgHandler() + ).handler(entityClazz, queryWrapper); } return super.list(queryWrapper); } @@ -689,37 +695,44 @@ public class UserServiceImpl extends CrudServiceImpl findListByCus(QueryWrapper queryWrapper) { + private List findListByCus(QueryWrapper queryWrapper) { // 如果没有租户修改能力 则默认增加租户限制 if(!UserUtil.isHasUpdateTenantPerms(UserUtil.getUser())){ - // 多租户处理 - TenantHandler tenantHandler = new TenantHandler(); - tenantHandler.handler(SysUserAndOrg.class, queryWrapper); + // 数据处理责任链 + queryWrapper = new QueryTenantHandler( + new QueryOrgHandler() + ).handler(SysUserWeb.class, queryWrapper); } // 逻辑删除 查询未删除数据 queryWrapper.eq( FieldUtil.humpToUnderline(MyBatisConstants.FIELD_DELETE_LOGIC), DictType.NO_YES_NO.getValue()); - + // 按照ID 分组 + queryWrapper.groupBy("a.id","b.user_id"); return mapper.findList(queryWrapper); } @Override - public Page findPageByCus(Page page) { + public Page findPageByCus(Page page) { UserModel currUser = UserUtil.getUser(); + + QueryWrapper queryWrapper = page.getQueryWrapper(); + // 如果不是超级管理员则 无法看到超级管理员账户 if(!UserUtil.SUPER_ADMIN.equals(currUser.getUsername())){ - QueryWrapper queryWrapper = page.getQueryWrapper(); queryWrapper.notIn("username", UserUtil.SUPER_ADMIN); page.setQueryWrapper(queryWrapper); } + // 不能查看自身 + queryWrapper.notIn("username", currUser.getUsername()); + page.pageHelperBegin(); try{ - List list = this.findListByCus(page.getQueryWrapper()); - PageInfo pageInfo = new PageInfo<>(list); - List es = WrapperUtil.transformInstance(pageInfo.getList(), UserAndOrgModel.class); + List list = this.findListByCus(page.getQueryWrapper()); + PageInfo pageInfo = new PageInfo<>(list); + List es = WrapperUtil.transformInstance(pageInfo.getList(), UserWebModel.class); page.instance(pageInfo, es); } finally { page.pageHelperEnd(); diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserOrgRefRestController.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserOrgRefRestController.java index 94acb48..bc36668 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserOrgRefRestController.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserOrgRefRestController.java @@ -23,6 +23,7 @@ import org.opsli.api.base.result.ResultVo; import org.opsli.api.web.system.user.UserOrgRefApi; import org.opsli.api.wrapper.system.user.UserModel; import org.opsli.api.wrapper.system.user.UserOrgRefModel; +import org.opsli.api.wrapper.system.user.UserOrgRefWebModel; import org.opsli.common.annotation.ApiRestController; import org.opsli.common.exception.ServiceException; import org.opsli.core.autoconfigure.properties.GlobalProperties; @@ -32,6 +33,8 @@ import org.opsli.modulars.system.SystemMsg; import org.opsli.modulars.system.user.service.IUserOrgRefService; import org.springframework.beans.factory.annotation.Autowired; +import java.util.List; + /** * 用户-组织 Controller * @@ -50,6 +53,11 @@ public class UserOrgRefRestController implements UserOrgRefApi { @Autowired private IUserOrgRefService iUserOrgRefService; + @Override + public ResultVo> findListByUserId(String userId) { + List listByUserId = iUserOrgRefService.findListByUserId(userId); + return ResultVo.success(listByUserId); + } /** * 设置组织 @@ -58,18 +66,16 @@ public class UserOrgRefRestController implements UserOrgRefApi { */ @Override @RequiresPermissions("system_user_setOrg") - public ResultVo setOrg(UserOrgRefModel model) { + public ResultVo setOrg(UserOrgRefWebModel model) { // 演示模式 不允许操作 this.demoError(); boolean ret = iUserOrgRefService.setOrg(model); - if(ret){ - return ResultVo.success(); + if(!ret){ + // 权限设置失败 + throw new ServiceException(SystemMsg.EXCEPTION_USER_ORG_ERROR); } - // 权限设置失败 - return ResultVo.error(SystemMsg.EXCEPTION_USER_ORG_ERROR.getCode(), - SystemMsg.EXCEPTION_USER_ORG_ERROR.getMessage() - ); + return ResultVo.success(); } diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserRestController.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserRestController.java index 485be6f..a2bd9ec 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserRestController.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserRestController.java @@ -22,7 +22,6 @@ import cn.hutool.core.util.StrUtil; import com.alibaba.excel.util.CollectionUtils; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; @@ -37,9 +36,11 @@ import org.opsli.common.annotation.ApiRestController; import org.opsli.common.annotation.EnableLog; import org.opsli.common.annotation.RequiresPermissionsCus; import org.opsli.common.constants.MyBatisConstants; +import org.opsli.common.enums.DictType; import org.opsli.common.exception.ServiceException; import org.opsli.common.exception.TokenException; import org.opsli.common.utils.FieldUtil; +import org.opsli.common.utils.ListDistinctUtil; import org.opsli.common.utils.WrapperUtil; import org.opsli.core.base.controller.BaseRestController; import org.opsli.core.msg.TokenMsg; @@ -47,15 +48,14 @@ import org.opsli.core.persistence.Page; import org.opsli.core.persistence.querybuilder.GenQueryBuilder; import org.opsli.core.persistence.querybuilder.QueryBuilder; import org.opsli.core.persistence.querybuilder.WebQueryBuilder; +import org.opsli.core.persistence.querybuilder.conf.WebQueryConf; import org.opsli.core.utils.OptionsUtil; import org.opsli.core.utils.OrgUtil; import org.opsli.core.utils.UserUtil; import org.opsli.modulars.system.SystemMsg; -import org.opsli.modulars.system.org.entity.SysOrg; import org.opsli.modulars.system.org.service.ISysOrgService; -import org.opsli.modulars.system.org.web.SysOrgRestController; import org.opsli.modulars.system.user.entity.SysUser; -import org.opsli.modulars.system.user.entity.SysUserAndOrg; +import org.opsli.modulars.system.user.entity.SysUserWeb; import org.opsli.modulars.system.user.service.IUserService; import org.opsli.plugins.oss.OssStorageFactory; import org.opsli.plugins.oss.service.BaseOssStorageService; @@ -70,7 +70,6 @@ import java.io.IOException; import java.lang.reflect.Method; import java.util.Iterator; import java.util.List; -import java.util.Map; /** @@ -85,8 +84,6 @@ import java.util.Map; public class UserRestController extends BaseRestController implements UserApi { - @Autowired - private ISysOrgService iSysOrgService; /** * 当前登陆用户信息 @@ -133,7 +130,7 @@ public class UserRestController extends BaseRestController getOrg() { + public ResultVo getOrg() { UserModel user = UserUtil.getUser(); return this.getOrgByUserId(user.getId()); } @@ -145,9 +142,9 @@ public class UserRestController extends BaseRestController getOrgByUserId(String userId) { - UserOrgRefModel orgRef = OrgUtil.getOrgByUserId(userId); - return ResultVo.success(orgRef); + public ResultVo getOrgByUserId(String userId) { + List orgListByUserId = OrgUtil.getOrgListByUserId(userId); + return ResultVo.success(orgListByUserId); } /** @@ -313,44 +310,31 @@ public class UserRestController extends BaseRestController findPage(Integer pageNo, Integer pageSize, UserOrgRefModel org, HttpServletRequest request) { - QueryBuilder queryBuilder = new WebQueryBuilder<>(SysUserAndOrg.class, request.getParameterMap()); - Page page = new Page<>(pageNo, pageSize); - QueryWrapper queryWrapper = queryBuilder.build(); - if(org != null){ - // 公司ID - if(StringUtils.isNotBlank(org.getCompanyId())){ - // 未分组判断 - if(SysOrgRestController.ORG_NULL.equals(org.getCompanyId())){ - queryWrapper.isNull("b.org_id"); - - }else{ - queryWrapper.eq("b.org_id", org.getCompanyId()); - } - } + public ResultVo findPage(Integer pageNo, Integer pageSize, + String orgIdGroup, + HttpServletRequest request) { + QueryBuilder queryBuilder = new WebQueryBuilder<>( + SysUserWeb.class, request.getParameterMap()); + Page page = new Page<>(pageNo, pageSize); + QueryWrapper queryWrapper = queryBuilder.build(); - // 部门ID - if(StringUtils.isNotBlank(org.getDepartmentId())){ - queryWrapper.eq("c.org_id", org.getDepartmentId()); - } + // 处理组织权限 + OrgUtil.handleOrgIdGroupCondition(orgIdGroup, queryWrapper); - // 岗位ID - if(StringUtils.isNotBlank(org.getPostId())){ - queryWrapper.eq("d.org_id", org.getPostId()); - } - } page.setQueryWrapper(queryWrapper); page = IService.findPageByCus(page); // 密码防止分页泄露处理 - for (UserAndOrgModel userModel : page.getList()) { + for (UserWebModel userModel : page.getList()) { userModel.setSecretKey(null); userModel.setPassword(null); + userModel.setPasswordLevel(null); } return ResultVo.success(page.getPageData()); } @@ -547,60 +531,60 @@ public class UserRestController extends BaseRestController getOrgInfoByUserId(String userId) { - UserOrgRefModel org = null; + public ResultVo getOrgInfoByUserId(String userId) { + UserOrgRefWebModel org = null; // 不写SQL了 直接分页 第一页 取第一条 - QueryBuilder queryBuilder = new GenQueryBuilder<>(); - Page page = new Page<>(1, 1); - QueryWrapper queryWrapper = queryBuilder.build(); + QueryBuilder queryBuilder = new GenQueryBuilder<>(); + Page page = new Page<>(1, 1); + QueryWrapper queryWrapper = queryBuilder.build(); queryWrapper.eq( "a.id", userId ); page.setQueryWrapper(queryWrapper); page = IService.findPageByCus(page); - List list = page.getList(); + List list = page.getList(); if(CollUtil.isNotEmpty(list)){ - UserAndOrgModel userAndOrgModel = list.get(0); - if(userAndOrgModel != null){ - org = userAndOrgModel.getOrg(); - if(org != null){ - - org.setUserId(userId); - - List orgIds = Lists.newArrayListWithCapacity(3); - orgIds.add(org.getCompanyId()); - orgIds.add(org.getDepartmentId()); - orgIds.add(org.getPostId()); - QueryWrapper orgQueryWrapper = new QueryWrapper<>(); - orgQueryWrapper.in( - FieldUtil.humpToUnderline(MyBatisConstants.FIELD_ID), - orgIds); - List orgList = iSysOrgService.findList(orgQueryWrapper); - if(CollUtil.isNotEmpty(orgList)){ - Map tmp = Maps.newHashMap(); - for (SysOrg sysOrg : orgList) { - tmp.put(sysOrg.getId(), sysOrg); - } - - // 设置 名称 - SysOrg company = tmp.get(org.getCompanyId()); - if(company != null){ - org.setCompanyName(company.getOrgName()); - } - - SysOrg department = tmp.get(org.getDepartmentId()); - if(department != null){ - org.setDepartmentName(department.getOrgName()); - } - - SysOrg post = tmp.get(org.getPostId()); - if(post != null){ - org.setPostName(post.getOrgName()); - } - } - - } + UserWebModel userWebModel = list.get(0); + if(userWebModel != null){ +// org = userAndOrgModel.getOrg(); +// if(org != null){ +// +// org.setUserId(userId); + +// List orgIds = Lists.newArrayListWithCapacity(3); +// orgIds.add(org.getCompanyId()); +// orgIds.add(org.getDepartmentId()); +// orgIds.add(org.getPostId()); +// QueryWrapper orgQueryWrapper = new QueryWrapper<>(); +// orgQueryWrapper.in( +// FieldUtil.humpToUnderline(MyBatisConstants.FIELD_ID), +// orgIds); +// List orgList = iSysOrgService.findList(orgQueryWrapper); +// if(CollUtil.isNotEmpty(orgList)){ +// Map tmp = Maps.newHashMap(); +// for (SysOrg sysOrg : orgList) { +// tmp.put(sysOrg.getId(), sysOrg); +// } +// +// // 设置 名称 +// SysOrg company = tmp.get(org.getCompanyId()); +// if(company != null){ +// org.setCompanyName(company.getOrgName()); +// } +// +// SysOrg department = tmp.get(org.getDepartmentId()); +// if(department != null){ +// org.setDepartmentName(department.getOrgName()); +// } +// +// SysOrg post = tmp.get(org.getPostId()); +// if(post != null){ +// org.setPostName(post.getOrgName()); +// } +// } + +// } } } return ResultVo.success(org); diff --git a/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/gentest/carinfo/entity/TestCar.java b/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/gentest/carinfo/entity/TestCar.java index 0e88682..1bc1b4e 100644 --- a/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/gentest/carinfo/entity/TestCar.java +++ b/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/gentest/carinfo/entity/TestCar.java @@ -58,6 +58,6 @@ public class TestCar extends BaseEntity { /** 逻辑删除字段 */ @TableLogic - private Integer deleted; + private String deleted; } diff --git a/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/gentest/user/entity/TestUser.java b/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/gentest/user/entity/TestUser.java index b46a655..65cdd62 100644 --- a/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/gentest/user/entity/TestUser.java +++ b/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/gentest/user/entity/TestUser.java @@ -56,6 +56,6 @@ public class TestUser extends BaseEntity { private String tenantId; /** 逻辑删除字段 */ - private Integer deleted; + private String deleted; } diff --git a/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/test/entity/TestEntity.java b/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/test/entity/TestEntity.java index 39a9070..3fc781a 100644 --- a/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/test/entity/TestEntity.java +++ b/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/test/entity/TestEntity.java @@ -47,6 +47,6 @@ public class TestEntity extends BaseEntity { /** 逻辑删除字段 */ //@TableLogic - //private Integer deleted; + //private String deleted; }