“djh”
2024-12-05 eee41a5fb58e6547a43929430f4b72908119db6e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.gkhy.testFourierSpecialGasMonitor.application.account.converter;
 
 
import cn.hutool.core.util.ObjectUtil;
import com.gkhy.testFourierSpecialGasMonitor.application.account.dto.respDto.UserIdentityBindAppRespDTO;
import com.gkhy.testFourierSpecialGasMonitor.application.account.dto.respDto.UserInfoAppRespDTO;
import com.gkhy.testFourierSpecialGasMonitor.application.account.dto.respDto.UserRoleBindAppRespDTO;
import com.gkhy.testFourierSpecialGasMonitor.application.attachment.service.dto.resp.AttachmentAppRespDTO;
import com.gkhy.testFourierSpecialGasMonitor.commons.utils.BeanCopyUtils;
import com.gkhy.testFourierSpecialGasMonitor.domain.account.model.dto.SysUserRoleBindDomainDTO;
import com.gkhy.testFourierSpecialGasMonitor.domain.account.model.dto.UserInfoDomainDTO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
 
@Service
public class UserInfoAppConverter {
 
    public List<UserInfoAppRespDTO> toAppDtoList(List<UserInfoDomainDTO> domainDtoList){
        if(domainDtoList == null || domainDtoList.isEmpty())
            return null;
        List<UserInfoAppRespDTO> 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<UserRoleBindAppRespDTO> userRoleBindAppRespDTOS = new ArrayList<>();
        if(ObjectUtil.isNotEmpty(domainDto.getRoles())){
            domainDto.getRoles().forEach(role -> {
                userRoleBindAppRespDTOS.add(toUserRoleAppRestDTO(role));
            });
        }
        appDto.setRoles(userRoleBindAppRespDTOS);
        //身份
        List<UserIdentityBindAppRespDTO> 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;
    }
 
}