高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
public with sharing class QLMAttachmentPreviewController {
    // //附件的parentId
    public String parentId { get; private set; }
//    //附件的Id
    public String attachId { get; private set; }
    //所有附件
    public list<Attachment> attachMentList { get; private set; }
 
    //所有超过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();
            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');
        Over12MInfoList = new List<Over12MInfo>();
        try {
            //判断url是否有id
            if (String.isNotBlank(this.parentId)) {
                this.attachMentList = [SELECT id, parentId, Name, Body, ContentType
                                       from Attachment where parentId = :parentId];
 
                attachmentInfo = new AttachmentInfo(attachMentList);
                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 AttachmentInfo {
        public list<Attachment> attachMentList { get; set; }
 
        public AttachmentInfo(list<Attachment> attachMentList) {
            this.attachMentList = attachMentList;
            for (Attachment tempatt : attachMentList) {
               tempatt.Name =  String.escapeSingleQuotes(tempatt.Name);
            }
        }
    }
    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;
        }
    }
}