package com.gkhy.labRiskManage.api.controller.account.converter; import com.gkhy.labRiskManage.api.controller.account.dto.resp.UserIdentityBindApiDTO; import com.gkhy.labRiskManage.api.controller.account.dto.resp.UserInfoApiDTO; import com.gkhy.labRiskManage.api.controller.account.dto.resp.UserRoleBindApiDTO; import com.gkhy.labRiskManage.api.controller.attachment.dto.resp.AttachmentApiRespDTO; import com.gkhy.labRiskManage.application.account.dto.respDto.UserInfoAppRespDTO; import com.gkhy.labRiskManage.application.attachment.service.dto.resp.AttachmentAppRespDTO; import com.gkhy.labRiskManage.commons.utils.BeanCopyUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; @Service public class UserInfoApiConverter { public UserInfoApiDTO toApiDto(UserInfoAppRespDTO appDto){ if(appDto == null) return null; UserInfoApiDTO apiDTO = new UserInfoApiDTO(); BeanUtils.copyProperties(appDto,apiDTO); //角色 List userRoleBindApiDTOS = new ArrayList<>(); if(appDto.getRoles() != null){ userRoleBindApiDTOS = BeanCopyUtils.copyBeanList(appDto.getRoles(), UserRoleBindApiDTO.class); } apiDTO.setRoles(userRoleBindApiDTOS); //身份 List userIdentityBindApiDTOS = new ArrayList<>(); if(appDto.getUserIdentities() != null){ userIdentityBindApiDTOS = BeanCopyUtils.copyBeanList(appDto.getUserIdentities(), UserIdentityBindApiDTO.class); } //资质附件 if(appDto.getQualificationAttaAppRespDTO() != null){ AttachmentApiRespDTO attachmentApiRespDTO = new AttachmentApiRespDTO(); BeanUtils.copyProperties(appDto.getQualificationAttaAppRespDTO(),attachmentApiRespDTO); apiDTO.setQualificationAttApiRespDTO(attachmentApiRespDTO); } apiDTO.setUserIdentities(userIdentityBindApiDTOS); return apiDTO; } public List toApiDtoList(List appDtoList){ if(appDtoList == null || appDtoList.isEmpty()) return null; List apiDtoList = new ArrayList<>(); appDtoList.forEach(appDto -> { apiDtoList.add(toApiDto(appDto)); }); return apiDtoList; } }