高章伟
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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
public with sharing class ISO_NewDemandOAD_PDFController {
    // si询价需求表id
    public String ISodcIdStr {get;set;}
    // PDF文件名称
    public String fileName {get;set;} 
    public String NowDate{get;set;}
    public IS_Opportunity_Demand__c ISOppDemandList{ get; set; }
    public List<IS_Opportunity_Demand__c> ISOpptunityDemandList{ get; set; }
 
    // si询价手术间
    public List<IS_Opportunity_Demand_Operating__c> ISOppDemandOperList{ get; set; }
    public IS_Opportunity_Demand_Operating__c ISOppDemandOper1{ get; set; }
    public IS_Opportunity_Demand_Operating__c ISOppDemandOper2{ get; set; }
    public IS_Opportunity_Demand_Operating__c ISOppDemandOper3{ get; set; }
    public IS_Opportunity_Demand_Operating__c ISOppDemandOperMore{ get; set; }
    // si询价示教点
    public List<IS_Opportunity_Demand_Demonstration__c> ISOppDemandDemonList{ get; set; }
    public IS_Opportunity_Demand_Demonstration__c ISOppDemandDemon1{ get; set; }
    public IS_Opportunity_Demand_Demonstration__c ISOppDemandDemon2{ get; set; }
    public IS_Opportunity_Demand_Demonstration__c ISOppDemandDemonMore{ get; set; }
    // si询价术间对应的配置单
    public List<IS_Opportunity_Demand_Configuration__c> ISOppDemandConfiguateList{ get; set; }
    public List<IS_Opportunity_Demand_Configuration__c> ISOppDemandConfiguate1{get; set; }
    public List<IS_Opportunity_Demand_Configuration__c> ISOppDemandConfiguateMatch1{get; set; }
    public List<IS_Opportunity_Demand_Configuration__c> ISOppDemandConfiguate2{get; set; }
    public List<IS_Opportunity_Demand_Configuration__c> ISOppDemandConfiguateMatch2{get; set; }
    public List<IS_Opportunity_Demand_Configuration__c> ISOppDemandConfiguate3{get; set; }
    public List<IS_Opportunity_Demand_Configuration__c> ISOppDemandConfiguateMatch3{get; set; }
 
    // 控制术间的显示
    public Boolean showISOdo1{ get; set; }
    public Boolean showISOdo2{ get; set; }
    public Boolean showISOdo3{ get; set; }
    public Boolean showISOdoMore{ get; set; }
    // 控制示教点的显示
    public Boolean showISOdd1{ get; set; }
    public Boolean showISOdd2{ get; set; }
    public Boolean showISOddMore{ get; set; }
 
    public ISO_NewDemandOAD_PDFController() {
        ISodcIdStr = ApexPages.currentPage().getParameters().get('id');
        fileName = ApexPages.currentPage().getParameters().get('fileName');
        ApexPages.currentPage().getHeaders().put('content-disposition','inline;filename='+fileName+'.pdf');    
    }
 
    public void init(){
        showISOdo1 = false;
        showISOdo2 = false;
        showISOdo3 = false;
        showISOdoMore = false;
        showISOdd1 = false;
        showISOdd2 = false;
        showISOddMore = false;
        ISOppDemandConfiguate1 = new List<IS_Opportunity_Demand_Configuration__c>();
        ISOppDemandConfiguateMatch1 = new List<IS_Opportunity_Demand_Configuration__c>();
        ISOppDemandConfiguate2 = new List<IS_Opportunity_Demand_Configuration__c>();
        ISOppDemandConfiguateMatch2 = new List<IS_Opportunity_Demand_Configuration__c>();
        ISOppDemandConfiguate3 = new List<IS_Opportunity_Demand_Configuration__c>();
        ISOppDemandConfiguateMatch3 = new List<IS_Opportunity_Demand_Configuration__c>();
        NowDate = System.now().format('yyyy-MM-dd');
        // 查询si询价需求表的信息
        ISOpptunityDemandList = [select id,Opportunity_ID__r.State__c,Opportunity_ID__r.Opportunity_No__c,Demonstration_Number__c,Opportunity_ID__c,Transmission_Mode__c,Operating_Room_Count__c,Demand_DemonstrationType__c,OperatingRoomName__c,Operating_Room_Position_Area__c,Operating_Room_Position_Building__c,Operating_Room_Position_Stage__c from IS_Opportunity_Demand__c where id = :ISodcIdStr];
        if(ISOpptunityDemandList.size() > 0){
            ISOppDemandList = ISOpptunityDemandList[0];
        }
        // 查询si询价手术间
        ISOppDemandOperList = [select id,Project_Information__c,Name,Name__c,IS_Opportunity_Demand__c,Operating_Room_Area__c,Remarks_Text__c,Operating_Room_Type__c,Olympus_LightSource_Host__c,Olympus_CD_Writer__c,Olympus_Ultrasound_Knife__c,Olympus_Insufflator__c,Olympus_Camera_Host__c,Olympus_Electric_Knife__c,ThirdParty_OperatingTable__c,ThirdParty_OperationLamp__c,ThirdParty_Camera__c from IS_Opportunity_Demand_Operating__c where IS_Opportunity_Demand__c = :ISodcIdStr];
        // 查询si询价示教点
        ISOppDemandDemonList = [select id,Name,IS_Opportunity_Demand__c,Teaching_Needs__c,Other_Require_Text__c,Demonstration_Type__c,Other_Relative_Position__c,Name__c from IS_Opportunity_Demand_Demonstration__c where IS_Opportunity_Demand__c = :ISodcIdStr];
        // 查询si询价配置单
        ISOppDemandConfiguateList = [select id,name,Configuration_Type__c,Selection__c,Matching__c,SerialNumber__c,Number__c,Standard_Configuration__c,IS_Opportunity_Demand_Operating__c,Brand__c,Company__c,IS_Opportunity_Demand_Operating__r.Name__c from IS_Opportunity_Demand_Configuration__c where IS_Opportunity_Demand_Operating__c = :ISOppDemandOperList order by SerialNumber__c];
        // 拆分si询价手术间
        for(IS_Opportunity_Demand_Operating__c isOdo :ISOppDemandOperList){
            if(isOdo.Name__c == '手术间1'){
                ISOppDemandOper1 = isOdo;
                ISOppDemandOper1.Remarks_Text__c = reStringAll(isOdo.Remarks_Text__c);
                // System.debug(isOdo.Remarks_Text__c+'======');
                // String str = isOdo.Remarks_Text__c;
                // System.debug(str+'======');
                // String[] strlist =  str.split('\n');
                // System.debug(strlist+'======strlist');
                if(ISOppDemandOper1 != null){
                    System.debug('======是否显示');
                    showISOdo1 = true;
                    showISOdo2 = false;
                    showISOdo3 = false;
                    showISOdoMore = false;
                }
            }
            if(isOdo.Name__c == '手术间2'){
                ISOppDemandOper2 = isOdo;
                ISOppDemandOper2.Remarks_Text__c = reStringAll(isOdo.Remarks_Text__c);
                if(ISOppDemandOper2 != null){
                    showISOdo2 = true;
                    showISOdo1 = true;
                    showISOdo3 = false;
                    showISOdoMore = false;
                }
            }
            if(isOdo.Name__c == '手术间3'){
                ISOppDemandOper3 = isOdo;
                ISOppDemandOper3.Remarks_Text__c = reStringAll(isOdo.Remarks_Text__c);
                if(ISOppDemandOper3 != null){
                    showISOdo3 = true;
                    showISOdo2 = true;
                    showISOdo1 = true;
                    showISOdoMore = false;
                }
            }
            if(isOdo.Name__c == '术间数量>3间'){
                ISOppDemandOperMore = isOdo;
                ISOppDemandOperMore.Project_Information__c = reStringAll(isOdo.Project_Information__c);
                if(ISOppDemandOperMore != null){
                    showISOdoMore = true;
                    showISOdo2 = false;
                    showISOdo1 = false;
                    showISOdo3 = false;
                }
            }
        }
        // 控制术间和示教点的显示
        if(ISOppDemandList.Operating_Room_Count__c == '1'){
            showISOdo1 = true;
            showISOdo2 = false;
            showISOdo3 = false;
            showISOdoMore = false;
        }
        if(ISOppDemandList.Operating_Room_Count__c == '2'){
            showISOdo1 = true;
            showISOdo2 = true;
            showISOdo3 = false;
            showISOdoMore = false;
        }
        if(ISOppDemandList.Operating_Room_Count__c == '3'){
            showISOdo1 = true;
            showISOdo2 = true;
            showISOdo3 = true;
            showISOdoMore = false;
        }
        if(ISOppDemandList.Operating_Room_Count__c == '>3'){
            showISOdo1 = false;
            showISOdo2 = false;
            showISOdo3 = false;
            showISOdoMore = true;
        }
        if(ISOppDemandList.Demonstration_Number__c == '1'){
            showISOdd1 = true;
            showISOdd2 = false;
            showISOddMore = false;
        }
        if(ISOppDemandList.Demonstration_Number__c == '2'){
            showISOdd1 = true;
            showISOdd2 = true;
            showISOddMore = false;
        }
        if(ISOppDemandList.Demonstration_Number__c == '>2'){
            showISOdd1 = false;
            showISOdd2 = false;
            showISOddMore = true;
        }
        // 拆分si询价示教点
        for(IS_Opportunity_Demand_Demonstration__c isOdd : ISOppDemandDemonList){
            if(isOdd.Name__c == '示教点1'){
                ISOppDemandDemon1 = isOdd;
                ISOppDemandDemon1.Other_Require_Text__c = reStringAll(isOdd.Other_Require_Text__c);
                if(ISOppDemandDemon1 != null){
                    showISOdd1 = true;
                    showISOdd2 = false;
                    showISOddMore = false;
                }
            }
            if(isOdd.Name__c == '示教点2'){
                ISOppDemandDemon2 = isOdd;
                ISOppDemandDemon2.Other_Require_Text__c = reStringAll(isOdd.Other_Require_Text__c);
                if(ISOppDemandDemon2 != null){
                    showISOdd2 = true;
                    showISOdd1 = true;
                    showISOddMore = false;
                }
            }
            if(isOdd.Name__c == '示教点数量>2'){
                ISOppDemandDemonMore = isOdd;
                ISOppDemandDemonMore.Teaching_Needs__c = reStringAll(isOdd.Teaching_Needs__c);
                if(ISOppDemandDemonMore != null){
                    showISOddMore = true;
                    showISOdd2 = false;
                    showISOdd1 = false;
                }
            }
        }
        // 拆分si询价手术间的配置单
        for(IS_Opportunity_Demand_Configuration__c isOdc : ISOppDemandConfiguateList){
            String conType = isOdc.Configuration_Type__c;
            System.debug(isOdc.IS_Opportunity_Demand_Operating__r.Name__c +'配置单对应类型:'+conType.substring(5,conType.length()-3)+'术间对应类型:'+ISOppDemandOper1.Operating_Room_Type__c);
            if(isOdc.IS_Opportunity_Demand_Operating__r.Name__c == '手术间1' && conType.substring(5,conType.length()-3) == ISOppDemandOper1.Operating_Room_Type__c){
                if(!isOdc.Matching__c){
                    ISOppDemandConfiguate1.add(isOdc);
                }
                if(isOdc.Matching__c){
                    ISOppDemandConfiguateMatch1.add(isOdc);
                }
                
            }
            if(isOdc.IS_Opportunity_Demand_Operating__r.Name__c == '手术间2' && conType.substring(5,conType.length()-3) == ISOppDemandOper2.Operating_Room_Type__c){
                // ISOppDemandConfiguate2.add(isOdc);
                if(!isOdc.Matching__c){
                    ISOppDemandConfiguate2.add(isOdc);
                }
                if(isOdc.Matching__c){
                    ISOppDemandConfiguateMatch2.add(isOdc);
                }
            }
            if(isOdc.IS_Opportunity_Demand_Operating__r.Name__c == '手术间3' && conType.substring(5,conType.length()-3) == ISOppDemandOper3.Operating_Room_Type__c){
                // ISOppDemandConfiguate3.add(isOdc);
                if(!isOdc.Matching__c){
                    ISOppDemandConfiguate3.add(isOdc);
                }
                if(isOdc.Matching__c){
                    ISOppDemandConfiguateMatch3.add(isOdc);
                }
            }
        }
        System.debug(ISOppDemandConfiguate1+'======');
    }
 
    // 为长文本格式化打印
    public String reStringAll(String str){
        if(str != '' && str != null){
            String[] strList = str.split('\n');
            Integer lineL = 40;
            String reStrAll = '';
            for(Integer i = 0 ; i < strList.size() ; i++){
                String reStr = strList[i];
                String reStrM = '';
                for(Integer j = 0 ; j <= reStr.length()/lineL ; j++ ){
                    if(reStr.length() > (lineL*(j+1))){
                        reStrM += reStr.substring(j*lineL,(j+1)*lineL);
                        reStrM += '\n';
                    }else{
                        reStrM += reStr.substring(j*lineL,reStr.length());
                        reStrM += '\n';
                    }
                }
                reStrAll += reStrM;
            }
            return reStrAll;
        }
        return null;
    }
}