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
@isTest
public with sharing class RepairAndQISToPDFControllerTest {
    public RepairAndQISToPDFControllerTest() {
        
    }
 
    @testSetup
    static void makeTestRepair() {
        StaticParameter.EscapeNFM001AgencyContractTrigger = false;
 
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            throw new ControllerUtil.myException('not found 病院 recodetype');
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 消化科'];
        if (rectSct.size() == 0) {
            throw new ControllerUtil.myException('not found 戦略科室分類 呼吸科 recodetype');
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            throw new ControllerUtil.myException('not found 診療科 消化科 recodetype');
        }
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name         = 'NFM105TestCompany';
        upsert company;
        Account section = [Select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where ParentId = :company.Id and RecordTypeId = :rectSct[0].Id];
 
        Account depart = new Account();
        depart.RecordTypeId        = rectDpt[0].Id;
        depart.Name                = '*';
        depart.Department_Name__c  = 'NFM105TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
 
        // 再取得
        List<Account> accList = new List<Account>();
        company = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :company.Id];
        accList.add(company);
        accList.add(section);
        depart = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :depart.Id];
        accList.add(depart);
 
        List<Product2> prdList = new List<Product2>();
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'NFM105Prd1';
        prd1.ProductCode            = 'NFM105Prd1';
        prd1.Repair_Product_Code__c = 'NFM105Prd1_RP';
        prd1.Name                   = 'NFM105Prd1';
        prd1.Manual_Entry__c        = false;
        prdList.add(prd1);
        Product2 prd2 = new Product2();
        prd2.ProductCode_Ext__c     = 'NFM105Prd2';
        prd2.ProductCode            = 'NFM105Prd2';
        prd2.Repair_Product_Code__c = 'NFM105Prd2_RP';
        prd2.Name                   = 'NFM105Prd2';
        prd2.Manual_Entry__c        = false;
        prdList.add(prd2);
        insert prdList;
 
        Asset ast = new Asset();
        ast.Name                   = 'NFM105Ast1';
        ast.AccountId              = depart.Id;
        ast.Department_Class__c    = section.Id;
        ast.Hospital__c            = company.Id;
        ast.Product2Id             = prd1.Id;
        ast.SerialNumber           = 'NFM105SerialNumber';
        ast.Guarantee_period_for_products__c = Date.today();
        ast.InstallDate                      = Date.today();
        insert ast;
        ast = [select Id, Name, Product_Serial_No__c, AccountId, Department_Class__c, Department_Class__r.Management_Code_Auto__c, Hospital__c, Product2Id, Product2.ProductCode, Product2.Repair_Product_Code__c, SerialNumber
               from Asset
               where Id = :ast.Id];
 
 
        // User testUser = new User();
        // testUser.Job_Category__c = '销售服务';
 
        Repair__c rpr = new Repair__c();
        //kk  20231124 add 避开验证规则 start
        rpr.AWS_Data_Id__c = '12123xx';
        // kk 20231124 add 避开验证规则  end
        rpr.SAPRepairNo__c   = 'NFM105Rpr1';
        rpr.Account__c             = depart.Id;
        rpr.Department_Class__c    = section.Id;
        rpr.Hospital__c            = company.Id;
        rpr.Delivered_Product__c   = ast.Id;
        rpr.Status__c              = '1.受理完毕';
        rpr.Incharge_Staff__c = Userinfo.getUserId();
        rpr.Repair_Detail__c = 'test';
        //update by rentx 2020-10-21
        rpr.ProblemDescription__c = '<img alt="用户添加的图片" src="http://www.google.co.jp/img1" style="height: 666px; width: 500px;"/>';
        rpr.GeneratedPDFField__c = null;
        insert rpr;
 
 
        QIS_Report__c qr = new QIS_Report__c(
            RC__c = UserInfo.getUserId(),
            Photo_1__c = '<img alt="用户添加的图片" src="http://www.google.co.jp/img1" style="height: 666px; width: 500px;"/>',
            Photo_2__c = '<img alt="用户添加的图片" src="http://www.google.co.jp/img2" style="height: 1000px; width: 500px;"/>',
            Photo_3__c = '<img alt="用户添加的图片" src="http://www.google.co.jp/img3" style="height: 800px; width: 500px;"/>',
            Photo_4__c = '<img alt="用户添加的图片" src="http://www.google.co.jp/img4" style="height: 900px; width: 500px;"/>',
            Damage_For_Doc_Or_Pat__c = '有',
            Relation_With_The_Problem__c = '有可能',
            Report_For_Goz__c = '不知道',
            Name = 'QIS012345',
            GeneratedPDFField__c = null,
            QIS_Submit_day__c = Date.Today()
        );
        insert qr;
    }
 
    @IsTest
    static void repairToPDFTest(){
        StaticParameter.EscapeNFM001AgencyContractTrigger = false;
        List<Repair__c> res = [select id,name,GeneratedPDFField__c,ProblemDescription__c from Repair__c];
        
        Test.startTest();
            PageReference pref = Page.RepairAndQISToPDF;
            pref.getParameters().put('id', res.get(0).Id);
            pref.getParameters().put('api', 'repair');
            pref.getParameters().put('field', 'ProblemDescription__c');
            Test.setCurrentPage(pref);
            RepairAndQISToPDFController.generateAttachment(res);
            new RepairAndQISToPDFController();
        Test.stopTest();
    }
 
    @IsTest
    static void QISToPDFTest(){
        
        List<QIS_Report__c> qis =  [select id,name,GeneratedPDFField__c,problem_detail_photo__c,Photo_1__c,Photo_2__c,Photo_3__c,
                Photo_4__c,
                //kk  DB202310177575 增加照片5——8  start
                Photo_5__c,
                Photo_6__c,
                Photo_7__c,
                Photo_8__c,
                //kk  DB202310177575 增加照片5——8  end
                Photo_OSH_1__c,Photo_OSH_2__c,Photo_OSH_3__c,Photo_OSH_4__c 
                //zzm 20231213 DB202310077820 start
                ,Photo_OSH_5__c,Photo_OSH_6__c,Photo_OSH_7__c,Photo_OSH_8__c
                //zzm 20231213 DB202310077820 end
                from QIS_Report__c];
        
        Test.startTest();
            PageReference pref = Page.RepairAndQISToPDF;
            pref.getParameters().put('id', qis.get(0).Id);
            pref.getParameters().put('api', 'qis');
            pref.getParameters().put('field', 'Photo_1__c');
            Test.setCurrentPage(pref);
            StaticParameter.ContentDocumentLink = false;
            RepairAndQISToPDFController.generateAttachment(qis);
            new RepairAndQISToPDFController();
        Test.stopTest();
    }
 
}