From da255fa7e0ce6a103e5f5f0f83c59694dc916c8a Mon Sep 17 00:00:00 2001 From: Odboy Date: Sat, 17 Jan 2026 10:01:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(system):=20=E6=96=B0=E5=A2=9E=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E7=BB=84=E4=BB=B6=E6=9C=8D=E5=8A=A1=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E9=83=A8=E9=97=A8=E5=92=8C=E7=94=A8=E6=88=B7=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 CuteDeptTreeVo 模型类用于部门树形结构 - 重命名并迁移 SystemProductLineTreeVo 到 CuteProductLineSelectProVo - 重命名并迁移 SystemProductLineVo 到 CuteProductLineSelectVo - 新增 CuteUserSelectVo 模型类用于用户选择组件 - 新增 CuteBaseService 提供基础部门查询服务 - 新增 CuteDeptTreeService 处理部门树形数据逻辑 - 新增 CuteFileUploadService 管理文件上传功能 - 新增 CuteProductLineSelectProService 和 CuteProductLineSelectService - 新增 CuteUserSelectService 提供用户选择数据源 - 新增多个 API 控制器包括 CuteDeptTreeApi、CuteFileUploadApi 等 - 更新缓存键常量 USER_INFO 替代 ONLINE_USER - 移除旧的 SystemComponentController 和相关方法 - 调整 SystemUserInfoDAO 使用新的缓存键名 - 修改 SystemUserVo 中的部门字段类型为 SystemDeptTb --- .../system/application/CuteDeptTreeApi.java | 31 +++ .../system/application/CuteFileUploadApi.java | 44 ++++ .../application/CuteProductLineSelectApi.java | 27 +++ .../CuteProductLineSelectProApi.java | 27 +++ .../system/application/CuteUserSelectApi.java | 41 ++++ .../application/model/CuteDeptTreeVo.java | 48 ++++ .../model/CuteProductLineSelectProVo.java} | 13 +- .../model/CuteProductLineSelectVo.java} | 6 +- .../application/model/CuteUserSelectVo.java | 31 +++ .../application/service/CuteBaseService.java | 24 ++ .../service/CuteDeptTreeService.java | 65 +++++ .../service/CuteFileUploadService.java | 67 ++++++ .../CuteProductLineSelectProService.java | 69 ++++++ .../service/CuteProductLineSelectService.java | 70 ++++++ .../service/CuteUserSelectService.java | 68 ++++++ .../odboy/system/constant/SystemCacheKey.java | 4 + .../controller/SystemAuthController.java | 2 +- .../controller/SystemComponentController.java | 49 ---- .../controller/SystemUserController.java | 9 - .../system/dal/dataobject/SystemDeptTb.java | 4 +- .../dal/model/response/SystemUserVo.java | 3 +- .../system/dal/redis/SystemUserInfoDAO.java | 6 +- .../system/service/SystemDeptService.java | 222 +++--------------- .../system/service/SystemUserService.java | 40 +--- 24 files changed, 678 insertions(+), 292 deletions(-) create mode 100644 cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteDeptTreeApi.java create mode 100644 cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteFileUploadApi.java create mode 100644 cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteProductLineSelectApi.java create mode 100644 cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteProductLineSelectProApi.java create mode 100644 cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteUserSelectApi.java create mode 100644 cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteDeptTreeVo.java rename cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/{dal/model/response/SystemProductLineTreeVo.java => application/model/CuteProductLineSelectProVo.java} (73%) rename cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/{dal/model/response/SystemProductLineVo.java => application/model/CuteProductLineSelectVo.java} (87%) create mode 100644 cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteUserSelectVo.java create mode 100644 cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteBaseService.java create mode 100644 cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteDeptTreeService.java create mode 100644 cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteFileUploadService.java create mode 100644 cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteProductLineSelectProService.java create mode 100644 cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteProductLineSelectService.java create mode 100644 cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteUserSelectService.java delete mode 100644 cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemComponentController.java diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteDeptTreeApi.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteDeptTreeApi.java new file mode 100644 index 00000000..48b141d1 --- /dev/null +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteDeptTreeApi.java @@ -0,0 +1,31 @@ +package cn.odboy.system.application; + +import cn.odboy.system.application.model.CuteDeptTreeVo; +import cn.odboy.system.application.service.CuteDeptTreeService; +import cn.odboy.system.dal.model.request.SystemQueryDeptArgs; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import java.util.List; + +@RestController +@Api(tags = "系统组件:CuteDeptTree") +@RequestMapping("/api/component/CuteDeptTree") +public class CuteDeptTreeApi { + + @Autowired + private CuteDeptTreeService cuteDeptTreeService; + + @ApiOperation("查询部门") + @PostMapping(value = "/listMetadata") + public ResponseEntity> listMetadata(@Validated @RequestBody SystemQueryDeptArgs args) throws Exception { + List depts = cuteDeptTreeService.listMetadata(args); + return ResponseEntity.ok(depts); + } +} diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteFileUploadApi.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteFileUploadApi.java new file mode 100644 index 00000000..e2f184e5 --- /dev/null +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteFileUploadApi.java @@ -0,0 +1,44 @@ +package cn.odboy.system.application; + +import cn.odboy.system.application.service.CuteFileUploadService; +import cn.odboy.system.framework.operalog.OperationLog; +import cn.odboy.system.service.SystemOssStorageService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +@RestController +@Api(tags = "系统组件:CuteFileUpload") +@RequestMapping("/api/component/CuteFileUpload") +public class CuteFileUploadApi { + + @Autowired + private CuteFileUploadService cuteFileUploadService; + @Autowired + private SystemOssStorageService systemOssStorageService; + + @OperationLog + @ApiOperation("上传文件到服务器本地") + @PostMapping(value = "/uploadLocal") + @PreAuthorize("@el.check()") + public ResponseEntity uploadLocal(@RequestParam("file") MultipartFile file) { + String fileUrl = cuteFileUploadService.uploadLocal(file); + return ResponseEntity.ok(fileUrl); + } + + @OperationLog + @ApiOperation("上传文件到OSS") + @PostMapping(value = "/uploadOSS") + @PreAuthorize("@el.check()") + public ResponseEntity uploadOSS(@RequestParam("file") MultipartFile file) { + String fileUrl = systemOssStorageService.uploadFile(file); + return ResponseEntity.ok(fileUrl); + } +} diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteProductLineSelectApi.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteProductLineSelectApi.java new file mode 100644 index 00000000..7037874e --- /dev/null +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteProductLineSelectApi.java @@ -0,0 +1,27 @@ +package cn.odboy.system.application; + +import cn.odboy.system.application.service.CuteProductLineSelectService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@Api(tags = "系统组件:CuteProductLineSelect") +@RequestMapping("/api/component/CuteProductLineSelect") +public class CuteProductLineSelectApi { + + @Autowired + private CuteProductLineSelectService cuteProductLineSelectService; + + @ApiOperation("查询部门下拉选择数据源") + @PostMapping(value = "/listMetadata") + @PreAuthorize("@el.check()") + public ResponseEntity listMetadata() { + return ResponseEntity.ok(cuteProductLineSelectService.listMetadata()); + } +} diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteProductLineSelectProApi.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteProductLineSelectProApi.java new file mode 100644 index 00000000..f671fa7c --- /dev/null +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteProductLineSelectProApi.java @@ -0,0 +1,27 @@ +package cn.odboy.system.application; + +import cn.odboy.system.application.service.CuteProductLineSelectProService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@Api(tags = "系统组件:CuteProductLineSelectPro") +@RequestMapping("/api/component/CuteProductLineSelectPro") +public class CuteProductLineSelectProApi { + + @Autowired + private CuteProductLineSelectProService cuteProductLineSelectProService; + + @ApiOperation("查询部门下拉选择Pro数据源") + @PostMapping(value = "/listMetadata") + @PreAuthorize("@el.check()") + public ResponseEntity listMetadata() { + return ResponseEntity.ok(cuteProductLineSelectProService.listMetadata()); + } +} diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteUserSelectApi.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteUserSelectApi.java new file mode 100644 index 00000000..21c5978e --- /dev/null +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteUserSelectApi.java @@ -0,0 +1,41 @@ +package cn.odboy.system.application; + +import cn.odboy.system.application.model.CuteUserSelectVo; +import cn.odboy.system.application.service.CuteUserSelectService; +import cn.odboy.system.dal.model.request.SystemQueryUserArgs; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import java.util.List; + +@RestController +@Api(tags = "系统组件:CuteUserSelect") +@RequestMapping("/api/component/CuteUserSelect") +public class CuteUserSelectApi { + + @Autowired + private CuteUserSelectService cuteUserSelectService; + + @ApiOperation("查询用户基础数据") + @PostMapping(value = "/listMetadata") + @PreAuthorize("@el.check()") + public ResponseEntity> listMetadata(@Validated @RequestBody SystemQueryUserArgs args) { + List collect = cuteUserSelectService.listMetadata(args); + return ResponseEntity.ok(collect); + } + + @ApiOperation("根据用户名称集合查询用户基础数据") + @PostMapping(value = "/listMetadataByUsernames") + @PreAuthorize("@el.check()") + public ResponseEntity> listMetadataByUsernames(@RequestBody List usernameList) { + List collect = cuteUserSelectService.listMetadataByUsernames(usernameList); + return ResponseEntity.ok(collect); + } +} diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteDeptTreeVo.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteDeptTreeVo.java new file mode 100644 index 00000000..db474eb8 --- /dev/null +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteDeptTreeVo.java @@ -0,0 +1,48 @@ +package cn.odboy.system.application.model; + +import cn.odboy.base.KitObject; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class CuteDeptTreeVo extends KitObject { + + /** + * 部门ID + */ + private String id; + /** + * 部门名称 + */ + private String name; + /** + * 上级部门ID + */ + private String pid; + /** + * 子节点数目 + */ + private Integer subCount = 0; + + /** + * 是否有子节点 + */ + public Boolean getHasChildren() { + return subCount > 0; + } + + /** + * 是否为叶子 + */ + public Boolean getLeaf() { + return subCount <= 0; + } + + /** + * 标签名称 + */ + public String getLabel() { + return name; + } +} diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/response/SystemProductLineTreeVo.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteProductLineSelectProVo.java similarity index 73% rename from cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/response/SystemProductLineTreeVo.java rename to cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteProductLineSelectProVo.java index 891ee082..8577fb1e 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/response/SystemProductLineTreeVo.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteProductLineSelectProVo.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package cn.odboy.system.dal.model.response; +package cn.odboy.system.application.model; import cn.odboy.base.KitObject; import lombok.Getter; @@ -22,9 +22,14 @@ import java.util.List; @Getter @Setter -public class SystemProductLineTreeVo extends KitObject { - +public class CuteProductLineSelectProVo extends KitObject { + /** + * 部门ID(select的value) + */ private String value; + /** + * 产品线,如"研发部/华南分部/devops组" + */ private String label; - private List children; + private List children; } diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/response/SystemProductLineVo.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteProductLineSelectVo.java similarity index 87% rename from cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/response/SystemProductLineVo.java rename to cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteProductLineSelectVo.java index 6b0291c2..eae8f15a 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/response/SystemProductLineVo.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteProductLineSelectVo.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package cn.odboy.system.dal.model.response; +package cn.odboy.system.application.model; import cn.odboy.base.KitObject; import lombok.Getter; @@ -21,12 +21,12 @@ import lombok.Setter; @Getter @Setter -public class SystemProductLineVo extends KitObject { +public class CuteProductLineSelectVo extends KitObject { /** * 部门ID(select的value) */ - private Long value; + private String value; /** * 产品线,如"研发部/华南分部/devops组" */ diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteUserSelectVo.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteUserSelectVo.java new file mode 100644 index 00000000..a03945c8 --- /dev/null +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteUserSelectVo.java @@ -0,0 +1,31 @@ +package cn.odboy.system.application.model; + +import cn.odboy.base.KitObject; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class CuteUserSelectVo extends KitObject { + + /** + * username + */ + private String value; + /** + * nickname + */ + private String label; + /** + * 部门ID + */ + private String deptId; + /** + * 邮箱 + */ + private String email; + /** + * 手机号 + */ + private String phone; +} diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteBaseService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteBaseService.java new file mode 100644 index 00000000..565cc64d --- /dev/null +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteBaseService.java @@ -0,0 +1,24 @@ +package cn.odboy.system.application.service; + +import cn.odboy.system.dal.dataobject.SystemDeptTb; +import cn.odboy.system.dal.mysql.SystemDeptMapper; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import org.springframework.beans.factory.annotation.Autowired; +import java.util.List; + +public class CuteBaseService { + + @Autowired + private SystemDeptMapper systemDeptMapper; + + /** + * 查询启用的所有部门集合 + * + * @return / + */ + public List listEnabledDept() { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(SystemDeptTb::getEnabled, 1); + return systemDeptMapper.selectList(wrapper); + } +} diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteDeptTreeService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteDeptTreeService.java new file mode 100644 index 00000000..96ab9509 --- /dev/null +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteDeptTreeService.java @@ -0,0 +1,65 @@ +package cn.odboy.system.application.service; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.odboy.system.application.model.CuteDeptTreeVo; +import cn.odboy.system.constant.SystemDataScopeEnum; +import cn.odboy.system.dal.dataobject.SystemDeptTb; +import cn.odboy.system.dal.model.request.SystemQueryDeptArgs; +import cn.odboy.system.framework.permission.core.KitSecurityHelper; +import cn.odboy.system.service.SystemDeptService; +import cn.odboy.util.KitClassUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +@Service +public class CuteDeptTreeService { + + @Autowired + private SystemDeptService systemDeptService; + + public List listMetadata(SystemQueryDeptArgs args) throws Exception { + String dataScopeType = KitSecurityHelper.getDataScopeType(); + if (dataScopeType.equals(SystemDataScopeEnum.ALL.getValue())) { + args.setPidIsNull(true); + } + List fields = KitClassUtil.getAllFields(args.getClass(), new ArrayList<>()); + List fieldNames = new ArrayList<>() {{ + add("pidIsNull"); + add("enabled"); + }}; + for (Field field : fields) { + // 设置对象的访问权限, 保证对private的属性的访问 + field.setAccessible(true); + Object val = field.get(args); + if (fieldNames.contains(field.getName())) { + continue; + } + if (ObjectUtil.isNotNull(val)) { + args.setPidIsNull(null); + break; + } + } + // 数据权限 + args.setIds(KitSecurityHelper.getCurrentUserDataScope()); + List list = systemDeptService.queryDeptByArgs(args); + // 如果为空, 就代表为自定义权限或者本级权限, 就需要去重, 不理解可以注释掉,看查询结果 + if (StrUtil.isBlank(dataScopeType)) { + return systemDeptService.filterRootDeptList(list).stream().map(this::convertToVo).collect(Collectors.toList()); + } + return list.stream().map(this::convertToVo).collect(Collectors.toList()); + } + + private CuteDeptTreeVo convertToVo(SystemDeptTb record) { + CuteDeptTreeVo treeVo = new CuteDeptTreeVo(); + treeVo.setId(Long.toString(record.getId())); + treeVo.setName(record.getName()); + treeVo.setPid(record.getPid() == null ? null : Long.toString(record.getPid())); + treeVo.setSubCount(record.getSubCount()); + return treeVo; + } +} diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteFileUploadService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteFileUploadService.java new file mode 100644 index 00000000..cdf347dc --- /dev/null +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteFileUploadService.java @@ -0,0 +1,67 @@ +package cn.odboy.system.application.service; + +import cn.hutool.core.date.DatePattern; +import cn.hutool.core.date.DateUtil; +import cn.odboy.framework.context.KitRequestHolder; +import cn.odboy.framework.exception.BadRequestException; +import cn.odboy.framework.properties.AppProperties; +import cn.odboy.framework.server.core.KitFileLocalUploadHelper; +import cn.odboy.system.dal.dataobject.SystemLocalStorageTb; +import cn.odboy.system.dal.mysql.SystemLocalStorageMapper; +import cn.odboy.util.KitFileUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; +import jakarta.servlet.http.HttpServletRequest; +import java.io.File; +import java.util.Date; + +@Slf4j +@Service +public class CuteFileUploadService { + + @Autowired + private SystemLocalStorageMapper systemLocalStorageMapper; + @Autowired + private KitFileLocalUploadHelper fileUploadPathHelper; + @Autowired + private AppProperties properties; + + @Transactional(rollbackFor = Exception.class) + public String uploadLocal(MultipartFile multipartFile) { + long size = multipartFile.getSize(); + KitFileUtil.checkSize(properties.getOss().getMaxSize(), size); + String suffix = KitFileUtil.getSuffix(multipartFile.getOriginalFilename()); + String type = KitFileUtil.getFileType(suffix); + String uploadDateStr = DateUtil.format(new Date(), DatePattern.PURE_DATE_FORMAT); + File file = KitFileUtil.upload(multipartFile, fileUploadPathHelper.getPath() + uploadDateStr + File.separator); + if (file == null) { + throw new BadRequestException("上传失败"); + } + try { + String formatSize = KitFileUtil.getSize(size); + String prefixName = KitFileUtil.getPrefix(multipartFile.getOriginalFilename(), null); + SystemLocalStorageTb localStorage = new SystemLocalStorageTb(); + localStorage.setRealName(file.getName()); + localStorage.setName(prefixName); + localStorage.setSuffix(suffix); + localStorage.setPath(file.getPath()); + localStorage.setType(type); + localStorage.setSize(formatSize); + localStorage.setDateGroup(uploadDateStr); + systemLocalStorageMapper.insert(localStorage); + // 构建上传路径 /file/20260117/odboycn-20260117055246428.png + HttpServletRequest httpServletRequest = KitRequestHolder.getHttpServletRequest(); + StringBuffer requestURL = httpServletRequest.getRequestURL(); + String[] splits = requestURL.toString().split("/api/component/CuteFileUpload"); + String requestAddress = splits[0]; + return String.format("%s/file/%s/%s", requestAddress, uploadDateStr, localStorage.getRealName()); + } catch (Exception e) { + log.error("上传文件失败", e); + KitFileUtil.del(file); + throw e; + } + } +} diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteProductLineSelectProService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteProductLineSelectProService.java new file mode 100644 index 00000000..27f1f587 --- /dev/null +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteProductLineSelectProService.java @@ -0,0 +1,69 @@ +package cn.odboy.system.application.service; + +import cn.odboy.system.application.model.CuteProductLineSelectProVo; +import cn.odboy.system.dal.dataobject.SystemDeptTb; +import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + +@Service +public class CuteProductLineSelectProService extends CuteBaseService { + + /** + * 产品线选择组件Pro版 数据源 + * + * @return / + */ + public List listMetadata() { + List depts = this.listEnabledDept(); + // 查询所有部门并按父子关系组织 + Map deptMap = + depts.stream().collect(Collectors.toMap(SystemDeptTb::getId, Function.identity())); + List options = new ArrayList<>(); + // 构建树形结构 + for (SystemDeptTb dept : depts) { + // 只处理顶级部门(pid为null或0的部门) + if (dept.getPid() == null || dept.getPid() == 0) { + CuteProductLineSelectProVo vo = this.buildDeptTreePro(dept, deptMap); + options.add(vo); + } + } + // 按排序字段排序 + options.sort(Comparator.comparingInt(o -> { + Long id = Long.valueOf(o.getValue()); + return deptMap.get(id) != null ? deptMap.get(id).getDeptSort() : 0; + })); + return options; + } + + /** + * 递归构建部门树 + * + * @param dept 当前部门 + * @param deptMap 部门映射 + * @return CuteProductLineSelectProVo 树节点 + */ + private CuteProductLineSelectProVo buildDeptTreePro(SystemDeptTb dept, Map deptMap) { + CuteProductLineSelectProVo vo = new CuteProductLineSelectProVo(); + vo.setValue(String.valueOf(dept.getId())); + vo.setLabel(dept.getName()); + // 查找子部门 + List children = new ArrayList<>(); + for (SystemDeptTb childDept : deptMap.values()) { + if (dept.getId().equals(childDept.getPid())) { + children.add(this.buildDeptTreePro(childDept, deptMap)); + } + } + // 子部门按排序字段排序 + children.sort(Comparator.comparingInt(o -> { + Long id = Long.valueOf(o.getValue()); + return deptMap.get(id) != null ? deptMap.get(id).getDeptSort() : 0; + })); + vo.setChildren(children); + return vo; + } +} diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteProductLineSelectService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteProductLineSelectService.java new file mode 100644 index 00000000..94d6ce19 --- /dev/null +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteProductLineSelectService.java @@ -0,0 +1,70 @@ +package cn.odboy.system.application.service; + +import cn.odboy.system.application.model.CuteProductLineSelectVo; +import cn.odboy.system.dal.dataobject.SystemDeptTb; +import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + +@Service +public class CuteProductLineSelectService extends CuteBaseService { + + /** + * 产品线选择组件 数据源 + * + * @return / + */ + public List listMetadata() { + List depts = this.listEnabledDept(); + return this.buildDeptMetadata(depts); + } + + private List buildDeptMetadata(List depts) { + // 查询所有部门并按父子关系组织 + Map deptMap = + depts.stream().collect(Collectors.toMap(SystemDeptTb::getId, Function.identity())); + List options = new ArrayList<>(); + for (SystemDeptTb dept : depts) { + // 构建部门ID路径 + List pathIds = new ArrayList<>(); + this.buildDeptIdPath(dept, deptMap, pathIds); + // 反转路径,从顶级部门到当前部门 + Collections.reverse(pathIds); + CuteProductLineSelectVo dto = new CuteProductLineSelectVo(); + dto.setValue(Long.toString(dept.getId())); + dto.setIdPath(pathIds.stream().map(String::valueOf).collect(Collectors.joining("-"))); + // 保留名称路径用于显示 + dto.setLabel(this.buildNamePath(dept, deptMap)); + options.add(dto); + } + // 按部门名称路径排序 + options.sort(Comparator.comparing(CuteProductLineSelectVo::getLabel)); + return options; + } + + private void buildDeptIdPath(SystemDeptTb dept, Map deptMap, List pathIds) { + pathIds.add(dept.getId()); + if (dept.getPid() != null && dept.getPid() != 0 && deptMap.containsKey(dept.getPid())) { + this.buildDeptIdPath(deptMap.get(dept.getPid()), deptMap, pathIds); + } + } + + private String buildNamePath(SystemDeptTb dept, Map deptMap) { + List pathNames = new ArrayList<>(); + this.buildDeptNamePath(dept, deptMap, pathNames); + Collections.reverse(pathNames); + return String.join(" / ", pathNames); + } + + private void buildDeptNamePath(SystemDeptTb dept, Map deptMap, List pathNames) { + pathNames.add(dept.getName()); + if (dept.getPid() != null && dept.getPid() != 0 && deptMap.containsKey(dept.getPid())) { + this.buildDeptNamePath(deptMap.get(dept.getPid()), deptMap, pathNames); + } + } +} diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteUserSelectService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteUserSelectService.java new file mode 100644 index 00000000..34d67f81 --- /dev/null +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteUserSelectService.java @@ -0,0 +1,68 @@ +package cn.odboy.system.application.service; + +import cn.hutool.core.collection.CollUtil; +import cn.odboy.system.application.model.CuteUserSelectVo; +import cn.odboy.system.dal.dataobject.SystemUserTb; +import cn.odboy.system.dal.model.request.SystemQueryUserArgs; +import cn.odboy.system.dal.mysql.SystemUserMapper; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +@Service +public class CuteUserSelectService { + + @Autowired + private SystemUserMapper systemUserMapper; + + /** + * 模糊查询用户基础信息,限制返回的条数 + * + * @param args 查询参数 + * @return / + */ + public List listMetadata(SystemQueryUserArgs args) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.select(SystemUserTb::getUsername, SystemUserTb::getNickName, SystemUserTb::getDeptId, SystemUserTb::getEmail, SystemUserTb::getPhone); + wrapper.and(c -> { + c.eq(SystemUserTb::getPhone, args.getBlurry()); + c.or(); + c.eq(SystemUserTb::getEmail, args.getBlurry()); + c.or(); + c.like(SystemUserTb::getUsername, args.getBlurry()); + c.or(); + c.like(SystemUserTb::getNickName, args.getBlurry()); + }); + return systemUserMapper.selectPage(new Page<>(1, 50), wrapper).convert(m -> { + CuteUserSelectVo selectVo = new CuteUserSelectVo(); + selectVo.setValue(m.getUsername()); + selectVo.setLabel(m.getNickName()); + selectVo.setDeptId(Long.toString(m.getDeptId())); + selectVo.setEmail(m.getEmail()); + selectVo.setPhone(m.getPhone()); + return selectVo; + }).getRecords(); + } + + public List listMetadataByUsernames(List usernameList) { + if (CollUtil.isEmpty(usernameList)) { + return new ArrayList<>(); + } + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.select(SystemUserTb::getUsername, SystemUserTb::getNickName, SystemUserTb::getDeptId, SystemUserTb::getEmail, SystemUserTb::getPhone); + wrapper.in(SystemUserTb::getUsername, usernameList); + return systemUserMapper.selectList(wrapper).stream().map(m -> { + CuteUserSelectVo selectVo = new CuteUserSelectVo(); + selectVo.setValue(m.getUsername()); + selectVo.setLabel(m.getNickName()); + selectVo.setDeptId(Long.toString(m.getDeptId())); + selectVo.setEmail(m.getEmail()); + selectVo.setPhone(m.getPhone()); + return selectVo; + }).collect(Collectors.toList()); + } +} diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/constant/SystemCacheKey.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/constant/SystemCacheKey.java index 554844af..fb51017b 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/constant/SystemCacheKey.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/constant/SystemCacheKey.java @@ -28,4 +28,8 @@ public interface SystemCacheKey { * 登录验证码 */ String CAPTCHA_LOGIN = "captcha::login:"; + /** + * 用户信息 + */ + String USER_INFO = "user::info:"; } diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemAuthController.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemAuthController.java index 0ae7a5c9..7ae1c964 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemAuthController.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemAuthController.java @@ -21,7 +21,6 @@ import cn.odboy.system.dal.model.response.SystemAuthVo; import cn.odboy.system.service.SystemAuthService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; @@ -29,6 +28,7 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import jakarta.servlet.http.HttpServletRequest; /** * 授权、根据token获取用户详细信息 diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemComponentController.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemComponentController.java deleted file mode 100644 index 3a7520e6..00000000 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemComponentController.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2021-2026 Odboy - * - * 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 cn.odboy.system.controller; - -import cn.odboy.system.service.SystemDeptService; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.ResponseEntity; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@Api(tags = "系统:组件数据源") -@RequestMapping("/api/component") -public class SystemComponentController { - - @Autowired - private SystemDeptService systemDeptService; - - @ApiOperation("查询部门下拉选择数据源") - @PostMapping(value = "/listDeptSelectDataSource") - @PreAuthorize("@el.check()") - public ResponseEntity listDeptSelectDataSource() { - return ResponseEntity.ok(systemDeptService.listDeptSelectDataSource()); - } - - @ApiOperation("查询部门下拉选择Pro数据源") - @PostMapping(value = "/listDeptSelectProDataSource") - @PreAuthorize("@el.check()") - public ResponseEntity listDeptSelectProDataSource() { - return ResponseEntity.ok(systemDeptService.listDeptSelectProDataSource()); - } -} diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemUserController.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemUserController.java index ce25a15b..a33fc5c4 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemUserController.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemUserController.java @@ -17,7 +17,6 @@ package cn.odboy.system.controller; import cn.odboy.base.KitPageArgs; import cn.odboy.base.KitPageResult; -import cn.odboy.base.KitSelectOptionVo; import cn.odboy.system.dal.dataobject.SystemUserTb; import cn.odboy.system.dal.model.request.SystemQueryUserArgs; import cn.odboy.system.dal.model.request.SystemUpdateUserPasswordArgs; @@ -43,7 +42,6 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import jakarta.servlet.http.HttpServletResponse; -import java.util.List; import java.util.Set; @Api(tags = "系统:用户管理") @@ -141,13 +139,6 @@ public class SystemUserController { return ResponseEntity.ok(null); } - @ApiOperation("查询用户基础数据") - @PostMapping(value = "/queryUserMetadataOptions") - @PreAuthorize("@el.check('user:list')") - public ResponseEntity> queryUserMetadataOptions(@Validated @RequestBody KitPageArgs args) { - List collect = systemUserService.queryUserMetadataOptions(args); - return ResponseEntity.ok(collect); - } @ApiOperation("获取用户信息") @PostMapping(value = "/getCurrentUserInfo") diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemDeptTb.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemDeptTb.java index 88d0658a..6098ddfc 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemDeptTb.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemDeptTb.java @@ -20,10 +20,10 @@ import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModelProperty; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; import lombok.Getter; import lombok.Setter; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import java.util.Objects; @Getter diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/response/SystemUserVo.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/response/SystemUserVo.java index 15c889ec..cb947f10 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/response/SystemUserVo.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/response/SystemUserVo.java @@ -16,6 +16,7 @@ package cn.odboy.system.dal.model.response; import cn.odboy.base.KitBaseUserTimeTb; +import cn.odboy.system.dal.dataobject.SystemDeptTb; import cn.odboy.system.dal.dataobject.SystemJobTb; import cn.odboy.system.dal.dataobject.SystemRoleTb; import io.swagger.annotations.ApiModelProperty; @@ -60,7 +61,7 @@ public class SystemUserVo extends KitBaseUserTimeTb { * 扩展字段 */ @ApiModelProperty(value = "用户部门") - private SystemDeptVo dept; + private SystemDeptTb dept; @ApiModelProperty(value = "用户角色") private Set roles; @ApiModelProperty(value = "用户岗位") diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/redis/SystemUserInfoDAO.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/redis/SystemUserInfoDAO.java index 767151cb..f5ec2465 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/redis/SystemUserInfoDAO.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/redis/SystemUserInfoDAO.java @@ -43,7 +43,7 @@ public class SystemUserInfoDAO { if (StrUtil.isNotEmpty(userName)) { // 添加数据, 避免数据同时过期(2小时左右) long time = 7200 + RandomUtil.randomInt(900, 1800); - redisHelper.set(SystemCacheKey.ONLINE_USER + userName, user, time); + redisHelper.set(SystemCacheKey.USER_INFO + userName, user, time); } } @@ -56,7 +56,7 @@ public class SystemUserInfoDAO { public void deleteUserLoginInfoByUserName(String userName) { if (StrUtil.isNotEmpty(userName)) { // 清除数据 - redisHelper.del(SystemCacheKey.ONLINE_USER + userName); + redisHelper.del(SystemCacheKey.USER_INFO + userName); } } @@ -69,7 +69,7 @@ public class SystemUserInfoDAO { public SystemUserJwtVo getUserLoginInfoByUserName(String username) { if (StrUtil.isNotEmpty(username)) { // 获取数据 - return redisHelper.get(SystemCacheKey.ONLINE_USER + username, SystemUserJwtVo.class); + return redisHelper.get(SystemCacheKey.USER_INFO + username, SystemUserJwtVo.class); } return null; } diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDeptService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDeptService.java index 9b6ec1a2..cc5d6b75 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDeptService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDeptService.java @@ -27,8 +27,6 @@ import cn.odboy.system.dal.model.export.SystemDeptExportRowVo; import cn.odboy.system.dal.model.request.SystemCreateDeptArgs; import cn.odboy.system.dal.model.request.SystemQueryDeptArgs; import cn.odboy.system.dal.model.response.SystemDeptVo; -import cn.odboy.system.dal.model.response.SystemProductLineTreeVo; -import cn.odboy.system.dal.model.response.SystemProductLineVo; import cn.odboy.system.dal.mysql.SystemDeptMapper; import cn.odboy.system.framework.permission.core.KitSecurityHelper; import cn.odboy.util.KitBeanUtil; @@ -42,14 +40,11 @@ import org.springframework.transaction.annotation.Transactional; import jakarta.servlet.http.HttpServletResponse; import java.lang.reflect.Field; import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.function.Function; import java.util.stream.Collectors; @Service @@ -107,10 +102,10 @@ public class SystemDeptService { @Transactional(rollbackFor = Exception.class) public void deleteDeptByIds(Set ids) { // 查询部门, 和其所有子部门 - Set depts = this.traverseDeptByIdWithPids(ids); + Set depts = this.traverseDeptByIdWithPids(ids); // 验证是否被角色或用户关联 this.verifyBindRelationByIds(depts); - for (SystemDeptVo dept : depts) { + for (SystemDeptTb dept : depts) { systemDeptMapper.deleteById(dept.getId()); this.updateDeptSubCnt(dept.getPid()); } @@ -171,16 +166,6 @@ public class SystemDeptService { return list; } - /** - * 根据ID查询 - * - * @param id / - * @return / - */ - public SystemDeptVo getDeptVoById(Long id) { - return KitBeanUtil.copyToClass(systemDeptMapper.selectById(id), SystemDeptVo.class); - } - /** * 根据部门id遍历所有部门和子部门id集合 * @@ -207,14 +192,15 @@ public class SystemDeptService { * @return / */ public KitPageResult searchDeptTree(List ids, Boolean exclude) { - Set deptSet1 = new LinkedHashSet<>(); + Map allDeptMap = this.getAllDeptMap(); + Set deptSet1 = new LinkedHashSet<>(); for (Long id : ids) { // 同级数据 - SystemDeptVo dept = this.getDeptVoById(id); + SystemDeptTb dept = allDeptMap.get(id); // 上级数据 - List depts = this.querySuperiorDeptByPid(dept, new ArrayList<>()); + List depts = this.querySuperiorDeptByPid(dept, new ArrayList<>(), allDeptMap); if (exclude) { - for (SystemDeptVo data : depts) { + for (SystemDeptTb data : depts) { if (data.getId().equals(dept.getPid())) { data.setSubCount(data.getSubCount() - 1); } @@ -224,18 +210,20 @@ public class SystemDeptService { } deptSet1.addAll(depts); } - List deptList = new ArrayList<>(deptSet1); + List deptList = new ArrayList<>(deptSet1); // 构建部门树 Set trees = new LinkedHashSet<>(); Set deptSet = new LinkedHashSet<>(); - List deptNames = deptList.stream().map(SystemDeptVo::getName).collect(Collectors.toList()); + List deptNames = deptList.stream().map(SystemDeptTb::getName).collect(Collectors.toList()); + boolean isChild; - for (SystemDeptVo dept : deptList) { + List systemDeptVos = KitBeanUtil.copyToList(deptList, SystemDeptVo.class); + for (SystemDeptVo dept : systemDeptVos) { isChild = false; if (dept.getPid() == null) { trees.add(dept); } - for (SystemDeptVo it : deptList) { + for (SystemDeptVo it : systemDeptVos) { if (it.getPid() != null && dept.getId().equals(it.getPid())) { isChild = true; if (dept.getChildren() == null) { @@ -246,7 +234,7 @@ public class SystemDeptService { } if (isChild) { deptSet.add(dept); - } else if (dept.getPid() != null && !deptNames.contains(this.getDeptVoById(dept.getPid()).getName())) { + } else if (dept.getPid() != null && !deptNames.contains(allDeptMap.get(dept.getPid()).getName())) { deptSet.add(dept); } } @@ -259,13 +247,18 @@ public class SystemDeptService { return baseResult; } + private Map getAllDeptMap() { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + return systemDeptMapper.selectList(wrapper).stream().collect(Collectors.toMap(SystemDeptTb::getId, i -> i, (m, n) -> m)); + } + /** * 验证是否被角色或用户关联 * * @param deptSet / */ - public void verifyBindRelationByIds(Set deptSet) { - Set deptIds = deptSet.stream().map(SystemDeptVo::getId).collect(Collectors.toSet()); + public void verifyBindRelationByIds(Set deptSet) { + Set deptIds = deptSet.stream().map(SystemDeptTb::getId).collect(Collectors.toSet()); if (systemUserDeptService.countUserByDeptIds(deptIds) > 0) { throw new BadRequestException("所选部门存在用户关联,请解除后再试!"); } @@ -279,13 +272,13 @@ public class SystemDeptService { * * @param ids 部门id集合 */ - public Set traverseDeptByIdWithPids(Set ids) { - Set depts = new HashSet<>(); + public Set traverseDeptByIdWithPids(Set ids) { + Set depts = new HashSet<>(); for (Long id : ids) { // 根部门 - depts.add(this.getDeptVoById(id)); + depts.add(systemDeptMapper.selectById(id)); // 子部门 - List deptList = this.listDeptVoByPid(id); + List deptList = this.listDeptByPid(id); if (CollUtil.isNotEmpty(deptList)) { this.queryRelationDeptByArgs(deptList, depts); } @@ -293,43 +286,6 @@ public class SystemDeptService { return depts; } - /** - * 产品线选择组件 数据源 - * - * @return / - */ - public List listDeptSelectDataSource() { - List depts = this.listEnabledDepts(); - return this.buildDeptSelectOptions(depts); - } - - /** - * 产品线选择组件Pro版 数据源 - * - * @return / - */ - public List listDeptSelectProDataSource() { - List depts = this.listEnabledDepts(); - // 查询所有部门并按父子关系组织 - Map deptMap = - depts.stream().collect(Collectors.toMap(SystemDeptTb::getId, Function.identity())); - List options = new ArrayList<>(); - // 构建树形结构 - for (SystemDeptTb dept : depts) { - // 只处理顶级部门(pid为null或0的部门) - if (dept.getPid() == null || dept.getPid() == 0) { - SystemProductLineTreeVo vo = this.buildDeptTreePro(dept, deptMap); - options.add(vo); - } - } - // 按排序字段排序 - options.sort(Comparator.comparingInt(o -> { - Long id = Long.valueOf(o.getValue()); - return deptMap.get(id) != null ? deptMap.get(id).getDeptSort() : 0; - })); - return options; - } - /** * 根据父部门id查询部门集合 * @@ -373,137 +329,37 @@ public class SystemDeptService { return systemDeptMapper.selectList(wrapper); } - /** - * 递归构建部门树 - * - * @param dept 当前部门 - * @param deptMap 部门映射 - * @return SystemProductLineTreeVo 树节点 - */ - private SystemProductLineTreeVo buildDeptTreePro(SystemDeptTb dept, Map deptMap) { - SystemProductLineTreeVo vo = new SystemProductLineTreeVo(); - vo.setValue(String.valueOf(dept.getId())); - vo.setLabel(dept.getName()); - // 查找子部门 - List children = new ArrayList<>(); - for (SystemDeptTb childDept : deptMap.values()) { - if (dept.getId().equals(childDept.getPid())) { - children.add(this.buildDeptTreePro(childDept, deptMap)); - } - } - // 子部门按排序字段排序 - children.sort(Comparator.comparingInt(o -> { - Long id = Long.valueOf(o.getValue()); - return deptMap.get(id) != null ? deptMap.get(id).getDeptSort() : 0; - })); - vo.setChildren(children); - return vo; - } - - /** - * 产品线选择组件使用 - * - * @param depts 部门集合 - * @return / - */ - private List buildDeptSelectOptions(List depts) { - // 查询所有部门并按父子关系组织 - Map deptMap = - depts.stream().collect(Collectors.toMap(SystemDeptTb::getId, Function.identity())); - List options = new ArrayList<>(); - for (SystemDeptTb dept : depts) { - // 构建部门ID路径 - List pathIds = new ArrayList<>(); - this.buildDeptIdPath(dept, deptMap, pathIds); - // 反转路径,从顶级部门到当前部门 - Collections.reverse(pathIds); - SystemProductLineVo dto = new SystemProductLineVo(); - dto.setValue(dept.getId()); - dto.setIdPath(pathIds.stream().map(String::valueOf).collect(Collectors.joining("-"))); - // 保留名称路径用于显示 - dto.setLabel(this.buildNamePath(dept, deptMap)); - options.add(dto); - } - // 按部门名称路径排序 - options.sort(Comparator.comparing(SystemProductLineVo::getLabel)); - return options; - } - - /** - * 产品线选择组件使用 - */ - private void buildDeptIdPath(SystemDeptTb dept, Map deptMap, List pathIds) { - pathIds.add(dept.getId()); - if (dept.getPid() != null && dept.getPid() != 0 && deptMap.containsKey(dept.getPid())) { - this.buildDeptIdPath(deptMap.get(dept.getPid()), deptMap, pathIds); - } - } - - /** - * 产品线选择组件使用 - */ - private String buildNamePath(SystemDeptTb dept, Map deptMap) { - List pathNames = new ArrayList<>(); - this.buildDeptNamePath(dept, deptMap, pathNames); - Collections.reverse(pathNames); - return String.join(" / ", pathNames); - } - - /** - * 产品线选择组件使用 - */ - private void buildDeptNamePath(SystemDeptTb dept, Map deptMap, List pathNames) { - pathNames.add(dept.getName()); - if (dept.getPid() != null && dept.getPid() != 0 && deptMap.containsKey(dept.getPid())) { - this.buildDeptNamePath(deptMap.get(dept.getPid()), deptMap, pathNames); - } - } - - /** - * 查询启用的所有部门集合 - * - * @return / - */ - private List listEnabledDepts() { - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(SystemDeptTb::getEnabled, 1); - return systemDeptMapper.selectList(wrapper); - } - /** * 查询部门下所有关联的部门 * * @param deptTbList / * @param depts / */ - private void queryRelationDeptByArgs(List deptTbList, Set depts) { - for (SystemDeptVo dept : deptTbList) { + private void queryRelationDeptByArgs(List deptTbList, Set depts) { + for (SystemDeptTb dept : deptTbList) { depts.add(dept); - List deptList = this.listDeptVoByPid(dept.getId()); + List deptList = this.listDeptByPid(dept.getId()); if (CollUtil.isNotEmpty(deptList)) { this.queryRelationDeptByArgs(deptList, depts); } } } - private List listDeptVoByPid(Long pid) { - return KitBeanUtil.copyToList(this.listDeptByPid(pid), SystemDeptVo.class); - } - /** * 根据ID查询同级与上级数据 * - * @param dept / - * @param deptList / + * @param dept / + * @param deptList / + * @param allDeptMap * @return / */ - private List querySuperiorDeptByPid(SystemDeptVo dept, List deptList) { + private List querySuperiorDeptByPid(SystemDeptTb dept, List deptList, Map allDeptMap) { if (dept.getPid() == null) { deptList.addAll(this.listRootDept()); return deptList; } - deptList.addAll(this.listDeptVoByPid(dept.getPid())); - return querySuperiorDeptByPid(this.getDeptVoById(dept.getPid()), deptList); + deptList.addAll(this.listDeptByPid(dept.getPid())); + return querySuperiorDeptByPid(allDeptMap.get(dept.getPid()), deptList, allDeptMap); } /** @@ -511,10 +367,10 @@ public class SystemDeptService { * * @return / */ - private List listRootDept() { + private List listRootDept() { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.isNull(SystemDeptTb::getPid); - return KitBeanUtil.copyToList(systemDeptMapper.selectList(wrapper), SystemDeptVo.class); + return systemDeptMapper.selectList(wrapper); } /** @@ -523,7 +379,7 @@ public class SystemDeptService { * @param id 部门id * @return / */ - private SystemDeptTb getDeptById(Long id) { + public SystemDeptTb getDeptById(Long id) { return systemDeptMapper.selectById(id); } @@ -542,7 +398,7 @@ public class SystemDeptService { /** * 筛选出 list 中没有父部门(即 pid 不在其他部门 id 列表中的部门)的部门列表 */ - private List filterRootDeptList(List list) { + public List filterRootDeptList(List list) { List deptList = new ArrayList<>(); // 使用 Set 存储所有部门的 id Set idSet = list.stream().map(SystemDeptTb::getId).collect(Collectors.toSet()); @@ -561,7 +417,7 @@ public class SystemDeptService { * @param args / * @return / */ - private List queryDeptByArgs(SystemQueryDeptArgs args) { + public List queryDeptByArgs(SystemQueryDeptArgs args) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); if (args != null) { wrapper.in(CollUtil.isNotEmpty(args.getIds()), SystemDeptTb::getId, args.getIds()); diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserService.java index 1a6d9259..35438ea0 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserService.java @@ -17,9 +17,7 @@ package cn.odboy.system.service; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; -import cn.odboy.base.KitPageArgs; import cn.odboy.base.KitPageResult; -import cn.odboy.base.KitSelectOptionVo; import cn.odboy.framework.exception.BadRequestException; import cn.odboy.framework.properties.AppProperties; import cn.odboy.framework.server.core.KitFileLocalUploadHelper; @@ -333,36 +331,6 @@ public class SystemUserService { return systemUserMapper.selectCount(wrapper); } - /** - * 模糊查询用户基础信息,限制返回的条数 - * - * @param pageArgs 分页参数 - * @return / - */ - public List queryUserMetadataOptions(KitPageArgs pageArgs) { - SystemQueryUserArgs args = pageArgs.getArgs(); - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.select( - SystemUserTb::getId, SystemUserTb::getUsername, SystemUserTb::getNickName, SystemUserTb::getDeptId, SystemUserTb::getEmail, SystemUserTb::getPhone); - wrapper.and(c -> { - c.eq(SystemUserTb::getPhone, args.getBlurry()); - c.or(); - c.eq(SystemUserTb::getEmail, args.getBlurry()); - c.or(); - c.like(SystemUserTb::getUsername, args.getBlurry()); - c.or(); - c.like(SystemUserTb::getNickName, args.getBlurry()); - }); - return systemUserMapper.selectPage(new Page<>(pageArgs.getPage(), 50), wrapper).getRecords().stream().map(m -> { - Map ext = new HashMap<>(1); - ext.put("id", m.getId()); - ext.put("deptId", m.getDeptId()); - ext.put("email", m.getEmail()); - ext.put("phone", m.getPhone()); - return KitSelectOptionVo.builder().label(m.getNickName()).value(String.valueOf(m.getId())).ext(ext).build(); - }).collect(Collectors.toList()); - } - /** * 根据用户名查询启用的用户信息 * @@ -399,10 +367,7 @@ public class SystemUserService { /** * 聚合查询 -> TestPassed */ - public KitPageResult aggregationSearchUserByArgs( - Page page, SystemQueryUserArgs args, - String currentUsername - ) { + public KitPageResult aggregationSearchUserByArgs(Page page, SystemQueryUserArgs args, String currentUsername) { if (!ObjectUtils.isEmpty(args.getDeptId())) { args.getDeptIds().add(args.getDeptId()); // 先查找是否存在子节点 @@ -584,7 +549,7 @@ public class SystemUserService { SystemUserVo userVo = KitBeanUtil.copyToClass(user, SystemUserVo.class); // 查询关联的部门信息 if (user.getDeptId() != null) { - userVo.setDept(systemDeptService.getDeptVoById(user.getDeptId())); + userVo.setDept(systemDeptService.getDeptById(user.getDeptId())); } // 查询关联的岗位信息 userVo.setJobs(systemUserJobService.listUserJobByUserId(user.getId())); @@ -592,4 +557,5 @@ public class SystemUserService { userVo.setRoles(systemUserRoleService.listUserRoleByUserId(user.getId())); return userVo; } + }