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 0000000000000000000000000000000000000000..b9e590eb486009924221a7703ed5d5f0edbce8a9 --- /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 0000000000000000000000000000000000000000..7758b8e76a380e7000c185b8213d738655795f27 --- /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 0000000000000000000000000000000000000000..708ff3e809dd5bbc37669591cda658afb7855193 --- /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 0000000000000000000000000000000000000000..f0b3add3a44a1f8eed3122e18378b8f079268d6f --- /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 0000000000000000000000000000000000000000..88e5a9b85dbd32485a73d89cb09f836c74a17da8 --- /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 0000000000000000000000000000000000000000..b8fb77fc9b3b7218548ef6d295c16a058ae23615 --- /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 82b26c30842899c2b0f174dc7ee602a12003b95e..f31cd5788861696625897607a5fa1985b3ee2798 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 af0dc5f4d8c106bdc13e70c48626a167deb6b2d8..cc518242fb20948db580c7df877bd61ae0347b80 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 7b2c3bcdb83680b8a35586255ab0f0296c7775fb..d877673b3dd274a87148dcf9d2aea2524881d560 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 99eafbab1aac86a6852b9929243743d8c8e15622..1e694d5cd86e9b72414ac643d7d9b60d576df7d8 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());