From 687bc7597fd6735509355e4cc4eeda167aacc1ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=9C=E6=98=B1=E6=81=92?= Date: Fri, 25 Aug 2023 13:28:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86department=E3=80=81email=E3=80=81gener?= =?UTF-8?q?ic=E3=80=81log=E9=87=8D=E6=9E=84=E4=B8=BAMapStruct?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sherly/convertor/DepartmentConvertor.java | 22 +++++++++++++++++++ .../convertor/EmailConfigConvertor.java | 16 ++++++++++++++ .../oswh/sherly/convertor/MenuConvertor.java | 13 +++++++++++ .../convertor/OperationLogConvertor.java | 18 +++++++++++++++ .../oswh/sherly/convertor/RoleConvertor.java | 13 +++++++++++ .../oswh/sherly/convertor/UserConvertor.java | 13 +++++++++++ .../sherly/manager/email/EmailManager.java | 8 +++---- .../manager/log/OperationLogManagerImpl.java | 9 +++----- .../service/department/DepartmentService.java | 17 ++++---------- .../service/generic/GenericService.java | 19 ++++++---------- 10 files changed, 112 insertions(+), 36 deletions(-) create mode 100644 sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/convertor/DepartmentConvertor.java create mode 100644 sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/convertor/EmailConfigConvertor.java create mode 100644 sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/convertor/MenuConvertor.java create mode 100644 sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/convertor/OperationLogConvertor.java create mode 100644 sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/convertor/RoleConvertor.java create mode 100644 sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/convertor/UserConvertor.java diff --git a/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/convertor/DepartmentConvertor.java b/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/convertor/DepartmentConvertor.java new file mode 100644 index 0000000..b9e590e --- /dev/null +++ b/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/convertor/DepartmentConvertor.java @@ -0,0 +1,22 @@ +package org.oswh.sherly.convertor; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; +import org.oswh.sherly.controller.department.dto.DepartmentInsertReqDTO; +import org.oswh.sherly.controller.department.dto.DepartmentRespDTO; +import org.oswh.sherly.controller.department.dto.DepartmentUpdateReqDTO; +import org.oswh.sherly.model.DepartmentDO; + +import java.util.List; + +@Mapper +public interface DepartmentConvertor { + DepartmentConvertor INSTANCE = Mappers.getMapper(DepartmentConvertor.class); + + List convertToRespDTO(List departments); + + DepartmentDO convertToDO(DepartmentInsertReqDTO department); + + DepartmentDO convertToDO(DepartmentUpdateReqDTO department); + +} diff --git a/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/convertor/EmailConfigConvertor.java b/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/convertor/EmailConfigConvertor.java new file mode 100644 index 0000000..7758b8e --- /dev/null +++ b/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/convertor/EmailConfigConvertor.java @@ -0,0 +1,16 @@ +package org.oswh.sherly.convertor; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; +import org.oswh.sherly.controller.email.dto.EmailConfigReqDTO; +import org.oswh.sherly.controller.email.dto.EmailConfigRespDTO; +import org.oswh.sherly.model.EmailConfigDO; + +@Mapper +public interface EmailConfigConvertor { + EmailConfigConvertor INSTANCE = Mappers.getMapper(EmailConfigConvertor.class); + + EmailConfigRespDTO convertToRespDTO(EmailConfigDO emailConfig); + + EmailConfigDO convertToDO(EmailConfigReqDTO emailConfig); +} diff --git a/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/convertor/MenuConvertor.java b/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/convertor/MenuConvertor.java new file mode 100644 index 0000000..708ff3e --- /dev/null +++ b/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/convertor/MenuConvertor.java @@ -0,0 +1,13 @@ +package org.oswh.sherly.convertor; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; +import org.oswh.sherly.controller.generic.dto.BasicMenuInfoRespDTO; +import org.oswh.sherly.model.MenuDO; + +@Mapper +public interface MenuConvertor { + MenuConvertor INSTANCE = Mappers.getMapper(MenuConvertor.class); + + BasicMenuInfoRespDTO convertToInfoRespDTO(MenuDO menu); +} diff --git a/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/convertor/OperationLogConvertor.java b/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/convertor/OperationLogConvertor.java new file mode 100644 index 0000000..f0b3add --- /dev/null +++ b/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/convertor/OperationLogConvertor.java @@ -0,0 +1,18 @@ +package org.oswh.sherly.convertor; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; +import org.oswh.sherly.controller.log.dto.OperationLogPageRespDTO; +import org.oswh.sherly.controller.log.dto.OperationLogRespDTO; +import org.oswh.sherly.model.OperationLogDO; + +@Mapper +public interface OperationLogConvertor { + OperationLogConvertor INSTANCE = Mappers.getMapper(OperationLogConvertor.class); + + OperationLogPageRespDTO convertToPageRespDTO(OperationLogDO operationLog); + + OperationLogRespDTO convertToRespDTO(OperationLogDO operationLog); + + +} diff --git a/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/convertor/RoleConvertor.java b/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/convertor/RoleConvertor.java new file mode 100644 index 0000000..88e5a9b --- /dev/null +++ b/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/convertor/RoleConvertor.java @@ -0,0 +1,13 @@ +package org.oswh.sherly.convertor; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; +import org.oswh.sherly.controller.generic.dto.BasicRoleInfoRespDTO; +import org.oswh.sherly.model.RoleDO; + +@Mapper +public interface RoleConvertor { + RoleConvertor INSTANCE = Mappers.getMapper(RoleConvertor.class); + + BasicRoleInfoRespDTO convertToInfoRespDTO(RoleDO role); +} diff --git a/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/convertor/UserConvertor.java b/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/convertor/UserConvertor.java new file mode 100644 index 0000000..b8fb77f --- /dev/null +++ b/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/convertor/UserConvertor.java @@ -0,0 +1,13 @@ +package org.oswh.sherly.convertor; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; +import org.oswh.sherly.controller.generic.dto.BasicUserInfoRespDTO; +import org.oswh.sherly.model.UserDO; + +@Mapper +public interface UserConvertor { + UserConvertor INSTANCE = Mappers.getMapper(UserConvertor.class); + + BasicUserInfoRespDTO convertToInfoRespDTO(UserDO user); +} diff --git a/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/manager/email/EmailManager.java b/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/manager/email/EmailManager.java index 82b26c3..f31cd57 100644 --- a/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/manager/email/EmailManager.java +++ b/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/manager/email/EmailManager.java @@ -6,9 +6,9 @@ import org.oswh.sherly.common.modules.exception.BizException; import org.oswh.sherly.controller.email.dto.EmailConfigReqDTO; import org.oswh.sherly.controller.email.dto.EmailConfigRespDTO; import org.oswh.sherly.controller.email.dto.EmailSendReqDTO; +import org.oswh.sherly.convertor.EmailConfigConvertor; import org.oswh.sherly.mapper.email.EmailConfigMapper; import org.oswh.sherly.model.EmailConfigDO; -import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -36,8 +36,7 @@ public class EmailManager { if (emailConfigDO == null) { return emailConfigRespDTO; } - BeanUtils.copyProperties(emailConfigDO, emailConfigRespDTO); - return emailConfigRespDTO; + return EmailConfigConvertor.INSTANCE.convertToRespDTO(emailConfigDO); } /** @@ -45,8 +44,7 @@ public class EmailManager { * @param dto */ public void saveOrUpdate(EmailConfigReqDTO dto) { - EmailConfigDO emailConfigDO = new EmailConfigDO(); - BeanUtils.copyProperties(dto, emailConfigDO); + EmailConfigDO emailConfigDO = EmailConfigConvertor.INSTANCE.convertToDO(dto); if (emailConfigDO.getId() == null) { emailConfigMapper.insert(emailConfigDO); } else { diff --git a/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/manager/log/OperationLogManagerImpl.java b/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/manager/log/OperationLogManagerImpl.java index af0dc5f..cc51824 100644 --- a/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/manager/log/OperationLogManagerImpl.java +++ b/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/manager/log/OperationLogManagerImpl.java @@ -9,12 +9,12 @@ import org.oswh.sherly.controller.log.dto.OperationLogPageRespDTO; import org.oswh.sherly.controller.log.dto.OperationLogRespDTO; import org.oswh.sherly.controller.user.dto.UserSelectReqDTO; import org.oswh.sherly.controller.user.dto.UserSelectRespDTO; +import org.oswh.sherly.convertor.OperationLogConvertor; import org.oswh.sherly.mapper.log.OperationLogMapper; import org.oswh.sherly.mapper.user.UserMapper; import org.oswh.sherly.model.OperationLogDO; import org.oswh.sherly.model.UserDO; import org.oswh.sherly.other.log.service.OperationLogManager; -import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -54,8 +54,7 @@ public class OperationLogManagerImpl implements OperationLogManager { List userIds = page.getRecords().stream().map(OperationLogDO::getCreateUserId).collect(Collectors.toList()); Map userMap = userMapper.selectBatchIds(userIds).stream().collect(Collectors.toMap(UserDO::getUserId, UserDO::getRealName)); List result = page.getRecords().stream().map(e -> { - OperationLogPageRespDTO vo = new OperationLogPageRespDTO(); - BeanUtils.copyProperties(e, vo); + OperationLogPageRespDTO vo = OperationLogConvertor.INSTANCE.convertToPageRespDTO(e); vo.setOperateUser(userMap.get(e.getCreateUserId())); return vo; }).collect(Collectors.toList()); @@ -66,9 +65,7 @@ public class OperationLogManagerImpl implements OperationLogManager { @Override public OperationLogRespDTO getOne(Long logId) { OperationLogDO log = operationLogMapper.selectById(logId); - OperationLogRespDTO vo = new OperationLogRespDTO(); - BeanUtils.copyProperties(log, vo); - return vo; + return OperationLogConvertor.INSTANCE.convertToRespDTO(log); } @Override diff --git a/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/service/department/DepartmentService.java b/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/service/department/DepartmentService.java index 7b2c3bc..d877673 100644 --- a/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/service/department/DepartmentService.java +++ b/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/service/department/DepartmentService.java @@ -5,15 +5,14 @@ import org.oswh.sherly.common.modules.exception.BizException; import org.oswh.sherly.controller.department.dto.DepartmentInsertReqDTO; import org.oswh.sherly.controller.department.dto.DepartmentRespDTO; import org.oswh.sherly.controller.department.dto.DepartmentUpdateReqDTO; +import org.oswh.sherly.convertor.DepartmentConvertor; import org.oswh.sherly.mapper.department.DepartmentMapper; import org.oswh.sherly.mapper.user.UserMapper; import org.oswh.sherly.model.DepartmentDO; -import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.util.Comparator; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -42,13 +41,7 @@ public class DepartmentService { List list = departmentMapper.selectList(); // 对象转换成vo类型 - List all = list.stream() - .sorted(Comparator.comparing(DepartmentDO::getSort)) - .map(e -> { - DepartmentRespDTO vo = new DepartmentRespDTO(); - BeanUtils.copyProperties(e, vo); - return vo; - }).collect(Collectors.toList()); + List all = DepartmentConvertor.INSTANCE.convertToRespDTO(list); // 拼装子结点并返回 return all.stream() @@ -81,8 +74,7 @@ public class DepartmentService { throw new BizException(DEPARTMENT_REPEAT); } - DepartmentDO departmentDO = new DepartmentDO(); - BeanUtils.copyProperties(dto, departmentDO); + DepartmentDO departmentDO = DepartmentConvertor.INSTANCE.convertToDO(dto); departmentMapper.insert(departmentDO); } @@ -103,8 +95,7 @@ public class DepartmentService { throw new BizException(DEPARTMENT_REPEAT); } - DepartmentDO departmentDO = new DepartmentDO(); - BeanUtils.copyProperties(dto, departmentDO); + DepartmentDO departmentDO = DepartmentConvertor.INSTANCE.convertToDO(dto); departmentMapper.updateById(departmentDO); } diff --git a/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/service/generic/GenericService.java b/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/service/generic/GenericService.java index 99eafba..1e694d5 100644 --- a/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/service/generic/GenericService.java +++ b/sherly-boot-services/sherly-boot-system/sherly-boot-system-biz/src/main/java/org/oswh/sherly/service/generic/GenericService.java @@ -5,6 +5,9 @@ import org.oswh.sherly.controller.generic.dto.BasicInfoRespDTO; import org.oswh.sherly.controller.generic.dto.BasicMenuInfoRespDTO; import org.oswh.sherly.controller.generic.dto.BasicRoleInfoRespDTO; import org.oswh.sherly.controller.generic.dto.BasicUserInfoRespDTO; +import org.oswh.sherly.convertor.MenuConvertor; +import org.oswh.sherly.convertor.RoleConvertor; +import org.oswh.sherly.convertor.UserConvertor; import org.oswh.sherly.manager.oss.OssManager; import org.oswh.sherly.mapper.menu.MenuMapper; import org.oswh.sherly.mapper.role.RoleMapper; @@ -13,7 +16,6 @@ import org.oswh.sherly.mapper.tenant.TenantMapper; import org.oswh.sherly.mapper.user.UserMapper; import org.oswh.sherly.mapper.user.UserRoleMapper; import org.oswh.sherly.model.*; -import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; @@ -66,8 +68,7 @@ public class GenericService { // 用户信息收集 UserDO userDO = userMapper.selectById(userId); - BasicUserInfoRespDTO userRespDTO = new BasicUserInfoRespDTO(); - BeanUtils.copyProperties(userDO, userRespDTO); + BasicUserInfoRespDTO userRespDTO = UserConvertor.INSTANCE.convertToInfoRespDTO(userDO); userRespDTO.setAvatar(ossManager.accessUrl(userRespDTO.getAvatar())); userRespDTO.setTenantCode(tenantDO.getTenantCode()); userRespDTO.setTenantName(tenantDO.getTenantName()); @@ -76,11 +77,7 @@ public class GenericService { List userRoleDOs = UserRoleMapper.listByUserId(userId); List roleIds = userRoleDOs.stream().map(UserRoleDO::getRoleId).collect(Collectors.toList()); List roleDOs = roleMapper.selectBatchIds(roleIds); - List roleRespDTOList = roleDOs.stream().map(e -> { - BasicRoleInfoRespDTO basicRoleInfoRespDTO = new BasicRoleInfoRespDTO(); - BeanUtils.copyProperties(e, basicRoleInfoRespDTO); - return basicRoleInfoRespDTO; - }).collect(Collectors.toList()); + List roleRespDTOList = roleDOs.stream().map(RoleConvertor.INSTANCE::convertToInfoRespDTO).collect(Collectors.toList()); // 菜单信息收集 List roleMenuDOs = roleMenuMapper.listByRoleIds(roleIds); @@ -103,8 +100,7 @@ public class GenericService { // 跳转相关数据转换成树 List menuRespDTOList = jumps.stream().filter(e -> Objects.equals(e.getParentId(), ROOT_PARENT_ID)).map(e -> { - BasicMenuInfoRespDTO basicMenuInfoRespDTO = new BasicMenuInfoRespDTO(); - BeanUtils.copyProperties(e, basicMenuInfoRespDTO); + BasicMenuInfoRespDTO basicMenuInfoRespDTO = MenuConvertor.INSTANCE.convertToInfoRespDTO(e); basicMenuInfoRespDTO.setChildren(getChildren(e, jumps)); return basicMenuInfoRespDTO; }).collect(Collectors.toList()); @@ -131,8 +127,7 @@ public class GenericService { return all.stream() .filter(e -> Objects.equals(e.getParentId(), parent.getMenuId())) .map(e -> { - BasicMenuInfoRespDTO basicMenuInfoRespDTO = new BasicMenuInfoRespDTO(); - BeanUtils.copyProperties(e, basicMenuInfoRespDTO); + BasicMenuInfoRespDTO basicMenuInfoRespDTO = MenuConvertor.INSTANCE.convertToInfoRespDTO(e); basicMenuInfoRespDTO.setChildren(getChildren(e, all)); return basicMenuInfoRespDTO; }).collect(Collectors.toList()); -- Gitee