package com.gkhy.labRiskManage.application.account.converter; import cn.hutool.core.util.ObjectUtil; import com.gkhy.labRiskManage.api.controller.account.dto.resp.UserIdentityBindApiDTO; import com.gkhy.labRiskManage.application.account.dto.respDto.UserIdentityBindAppRespDTO; import com.gkhy.labRiskManage.application.account.dto.respDto.UserInfoAppRespDTO; import com.gkhy.labRiskManage.application.account.dto.respDto.UserRoleBindAppRespDTO; import com.gkhy.labRiskManage.application.attachment.service.dto.resp.AttachmentAppRespDTO; import com.gkhy.labRiskManage.commons.utils.BeanCopyUtils; import com.gkhy.labRiskManage.domain.account.model.dto.SysUserRoleBindDomainDTO; import com.gkhy.labRiskManage.domain.account.model.dto.UserInfoDomainDTO; import com.gkhy.labRiskManage.domain.attachment.dto.resp.AttachmentDomainDTO; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; @Service public class UserInfoAppConverter { public List toAppDtoList(List domainDtoList){ if(domainDtoList == null || domainDtoList.isEmpty()) return null; List appRespDTOList = new ArrayList<>(); domainDtoList.forEach(d -> { appRespDTOList.add(toAppDto(d)); }); return appRespDTOList; } public UserInfoAppRespDTO toAppDto(UserInfoDomainDTO domainDto){ if(domainDto == null) return null; UserInfoAppRespDTO appDto = new UserInfoAppRespDTO(); BeanUtils.copyProperties(domainDto,appDto); List userRoleBindAppRespDTOS = new ArrayList<>(); if(ObjectUtil.isNotEmpty(domainDto.getRoles())){ domainDto.getRoles().forEach(role -> { userRoleBindAppRespDTOS.add(toUserRoleAppRestDTO(role)); }); } appDto.setRoles(userRoleBindAppRespDTOS); //身份 List userIdentityBindAppDTOS = new ArrayList<>(); if(domainDto.getUserIdentities() != null){ userIdentityBindAppDTOS = BeanCopyUtils.copyBeanList(domainDto.getUserIdentities(), UserIdentityBindAppRespDTO.class); } //资质附件 if(domainDto.getQualificationAttDomainDTO() != null){ AttachmentAppRespDTO attachmentAppRespDTO = new AttachmentAppRespDTO(); BeanUtils.copyProperties(domainDto.getQualificationAttDomainDTO(),attachmentAppRespDTO); appDto.setQualificationAttaAppRespDTO(attachmentAppRespDTO); } appDto.setUserIdentities(userIdentityBindAppDTOS); return appDto; } private UserRoleBindAppRespDTO toUserRoleAppRestDTO(SysUserRoleBindDomainDTO role) { if(role == null){ return null; } UserRoleBindAppRespDTO userRoleBindAppRespDTO = new UserRoleBindAppRespDTO(); BeanUtils.copyProperties(role,userRoleBindAppRespDTO); return userRoleBindAppRespDTO; } }