binxie
2024-01-16 1b08402678deb31bba4a347bfd388eba8360cbc1
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
public with sharing class QLMAttachmentPreviewController {
    // //附件的parentId
    public String parentId { get; private set; }
//    //附件的Id
    public String attachId { get; private set; }
    //所有附件
    public list<ContentVersion> attachMentList { get; private set; }
 
    public List<ContentVersionResponse> contentVerResList { get; private set; } // 阿里云迁移 by DTT-亚楠 20240107
 
    //所有超过12Murl
    public list<Over12MInfo> Over12MInfoList { get; set; }
 
 
    //构造bean类
    public AttachmentInfo attachmentInfo  {get; set;}
 
    public String gethtmlvalue() {
        this.parentId = ApexPages.currentPage().getParameters().get('parentId');
        this.attachId = ApexPages.currentPage().getParameters().get('Id');
        System.debug('123456--=--=--=-=--=' + attachId);
        try {
            // return [SELECT Id, Body, ParentId FROM Attachment
            //        where Id = :parentId ].body.tostring();
            // String Att = [SELECT Id, Body, ParentId FROM Attachment
            //               where Id = :attachId ].body.tostring();
            // lwc改造
            String Att = [SELECT Id,Title,VersionData, ContentDocumentId
                                         FROM ContentVersion
                                         WHERE id = :attachId].VersionData.toString();
            System.debug('------123456----' + Att);
            return Att;
        } catch (exception e) {
            return '';
        }
    }
 
    public void init() {
        //获取页面参数
        this.parentId = ApexPages.currentPage().getParameters().get('parentId');
        this.attachId = ApexPages.currentPage().getParameters().get('Id');
        System.debug('this.parentId' + this.parentId);
        System.debug('this.attachId' + this.attachId);
        Over12MInfoList = new List<Over12MInfo>();
        this.contentVerResList = new List<ContentVersionResponse>(); // 阿里云迁移 by DTT-亚楠 20240107
        try {
            //判断url是否有id
            if (String.isNotBlank(this.parentId)) {
                // this.attachMentList = [SELECT id, parentId, Name, Body, ContentType
                //                        from Attachment where parentId = :parentId];
                // lwc 修改
                // 查询 ContentDocumentLink 对象
                List<ContentDocumentLink> cdlList = [SELECT ContentDocumentId
                                                     FROM ContentDocumentLink
                                                     WHERE LinkedEntityId = :parentId];
 
                // 阿里云迁移 by DTT-亚楠 20240107 start
                // 遍历 ContentDocumentLink 对象列表
                // for (ContentDocumentLink cdl : cdlList) {
                //     // 查询 ContentVersion 对象
                //     this.attachMentList = [SELECT Id,Title,VersionData, ContentDocumentId
                //                          FROM ContentVersion
                //                          WHERE ContentDocumentId = :cdl.ContentDocumentId];
                // }
 
                List<String> cdIdList = new List<String>();
                for (ContentDocumentLink cdl : cdlList) {
                    cdIdList.add(cdl.ContentDocumentId);
                }
                this.attachMentList = [SELECT Id,Title,VersionData, ContentDocumentId, Description
                                        FROM ContentVersion
                                        WHERE ContentDocumentId IN :cdIdList];
 
                // attachmentInfo = new AttachmentInfo(this.attachMentList);
                for (ContentVersion contentVersion : this.attachMentList) {
                    ContentVersionResponse contentVerRes = new ContentVersionResponse();
                    contentVerRes.Id = contentVersion.Id;
                    contentVerRes.Title = String.escapeSingleQuotes(contentVersion.Title);
                    List<String> descriptionList = contentVersion.Description.split(';');
                    if (descriptionList.size() > 0 && contentVersion.Description.contains(';')) {
                        contentVerRes.infoId = descriptionList[0];
                        contentVerRes.infoType = descriptionList[1];
                        contentVerRes.subInfoType = descriptionList[2];
                        contentVerRes.updateDate = String.isNotBlank(descriptionList[3]) ? Date.valueOf(descriptionList[3]) : null;
                    }
                    this.contentVerResList.add(contentVerRes);
                }
                attachmentInfo = new AttachmentInfo(this.attachMentList, this.contentVerResList);
                // 阿里云迁移 by DTT-亚楠 20240107 end
 
                List<Tender_information__c> QLMattachMentList = [SELECT id, ProjectId__c, InfoType__c,
                                            Overstep_12M_infofile__c,
                                            File_Surpass_12M__c from Tender_information__c
                                            where Id = :parentId];
                if (QLMattachMentList.size() > 0) {
                    System.debug('QLMattachMentList:' + QLMattachMentList);
                    Integer i = 1;
                    // for (Tender_information__c Over12M : QLMattachMentList) {
                    for (String urlStr : QLMattachMentList[0].Overstep_12M_infofile__c.split(',')) {
                        // this.url = Over12M.Overstep_12M_infofile__c;
                        System.debug('urlStr:' + urlStr);
                        urlStr = urlStr.replaceAll('http://', 'https://');
                        over12MInfo over12MFile = new Over12MInfo('文件' + i, urlStr);
                        Over12MInfoList.add(over12MFile);
                        System.debug('12345678Over12MInfoList:' + Over12MInfoList);
                        i++;
                    }
                }
            }
        } catch (Exception ex) {
            ApexPages.addMessages(ex);
        }
    }
 
    public class ContentVersionResponse {
        // 阿里云迁移 by DTT-亚楠 20240107 start 
        public String Id {get; set;}
        public String Title {get; set;}
        public String infoId {get; set;}
        public String infoType {get; set;}
        public String subInfoType {get; set;}
        public Date updateDate {get; set;}
        public ContentVersionResponse(String Id, String Title, String infoId, String infoType, String subInfoType, Date updateDate) {
            this.Id = Id;
            this.title = Title;
            this.infoId = infoId;
            this.infoType = infoType;
            this.subInfoType = subInfoType;
            this.updateDate = updateDate;
        }
 
        public ContentVersionResponse(){}
        // 阿里云迁移 by DTT-亚楠 20240107 end 
    }
 
    public class AttachmentInfo {
        // lighting 附件改造 start
        public list<ContentVersion> attachMentList { get; set; }
        public List<ContentVersionResponse> contentVerResList { get; set; } // 阿里云迁移 by DTT-亚楠 20240107
 
        public AttachmentInfo(list<ContentVersion> attachMentList) {
            this.attachMentList = attachMentList;
            for (ContentVersion tempatt : attachMentList) {
               tempatt.Title =  String.escapeSingleQuotes(tempatt.Title);
            }
        }
        // lighting 附件改造 end
 
        // 阿里云迁移 by DTT-亚楠 20240107 start
        public AttachmentInfo(list<ContentVersion> attachMentList, List<ContentVersionResponse> contentVerResList) {
            this.attachMentList = attachMentList;
            this.contentVerResList = contentVerResList;
        }
        // 阿里云迁移 by DTT-亚楠 20240107 end
    }
    public class Over12MInfo {
        public string name { get; set; }
        public string url { get; set; }
        public Over12MInfo(string name, string url) {
            this.name = name;
            this.url = url;
        }
    }
}