高章伟
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
@isTest
private class updateQISPDAddFourTest {
    static Maintenance_Contract__c createMaintenanceContract( Account hospital, Account strategicDep, Account dep) {
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Name = 'tect contract';
        contract.status__c ='契約';
        contract.Maintenance_Contract_No__c = 'Kami_Contract_No';
        contract.Contract_Conclusion_Date__c = Date.today();
        contract.Hospital__c = hospital.Id;
        contract.Department_Class__c = strategicDep.Id;
        contract.Department__c = dep.Id;
        contract.Contract_Start_Date__c = Date.today().addDays( -10);   // 10日前
        contract.Contract_End_Date__c = Date.today().addDays( 5);       // 5日後
        contract.SalesOfficeCode_selection__c = '北京RC';
        insert contract;
        return contract;
    }
    
    static Maintenance_Contract_Asset__c createMiddleTable( Asset asset, Maintenance_Contract__c contract) {
        // 中間テーブルを設ける
        Maintenance_Contract_Asset__c middleTable = new Maintenance_Contract_Asset__c();
        middleTable.Asset__c = asset.Id;
        middleTable.Maintenance_Contract__c = contract.id;
        insert middleTable;
        return middleTable;
    }
    static testMethod void testMethod1() {
       // List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
       //  if (rectCo.size() == 0) {
       //      return;
       //  }
       //  List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
       //  if (rectSct.size() == 0) {
       //      return;
       //  }
       //  List<RecordType> rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN ('診療科 消化科', '診療科 呼吸科') order by Name desc];
       //  if (rectDpt.size() == 0) {
       //      return;
       //  }
       //   List<RecordType> rectAs = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '备品'];
       //  if (rectAs.size() == 0) {
       //      return;
       //  }
 
       //  Account company1 = new Account();
       //  company1.RecordTypeId = rectCo[0].Id;
       //  company1.Name = '病院テスト1';
       //  List<Account> hps = new Account[]{company1};
       //  insert hps;
          
       //  List<Account> dc1s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company1.Id order by Department_Class_Label__c];
        
       //  Account depart1 = new Account();
       //  depart1.RecordTypeId = rectDpt[0].Id;
       //  depart1.Name         = '*';
       //  depart1.Department_Name__c  = '診療科1';
       //  depart1.ParentId            = dc1s[0].Id;
       //  depart1.Department_Class__c = dc1s[0].Id;
       //  depart1.Hospital__c         = company1.Id;
       //  insert depart1;
 
       //  Product2 prd1 = new Product2();
       //  prd1.ProductCode_Ext__c     = 'HistoryPrd1';
       //  prd1.ProductCode            = 'HistoryPrd1';
       //  prd1.Repair_Product_Code__c = 'HistoryPrd1_RP';
       //  prd1.Name                   = 'HistoryPrd1';
       //  prd1.Manual_Entry__c        = false;
       //  prd1.Extend_new_product_gurantee__c = true;
       //  prd1.Extend_Gurantee_Start__c = Date.today().addDays(-60);
       //  prd1.Extend_Gurantee_End__c = Date.today().addDays(60);
       //  prd1.ENG_New__c = 'ENG2';
       //  insert prd1;
 
       //  // Oly_TriggerHandler.bypass('AssetHandler');
 
       //  Asset ast = new Asset();
       //  ast.RecordTypeId = rectAs[0].Id;
       //  ast.SerialNumber = 'abcdefg';
       //  ast.Name = '测试资产1';
       //  ast.AccountId              = depart1.Id;
       //  ast.Department_Class__c    = dc1s[0].Id;
       //  ast.Hospital__c            = company1.Id;
       //  ast.Product2Id             = prd1.Id;
       //  ast.Guarantee_period_for_products__c = Date.today();
       //  ast.InstallDate                      = Date.today();
       //  ast.Manage_type__c = '个体管理';
       //  ast.FirstApproveDate_old__c = Date.today().addDays(-30);
       //  insert ast;
 
       //  Maintenance_Contract__c mContract = createMaintenanceContract(company1, dc1s[0], depart1);
       //  Maintenance_Contract_Asset__c mca = createMiddleTable( ast, mContract);
 
       //  Repair__c repair = new Repair__c();
       //  repair.Account__c = depart1.Id;
       //  repair.Department_Class__c = dc1s[0].Id;
       //  repair.Hospital__c = company1.Id;
       //  repair.Delivered_Product__c = ast.Id;
       //  insert repair;
 
        
        String  action = '送回';
         OlympusCalendar__c oc = new OlympusCalendar__c(
            Date__c = System.today(),
            Before_5_WorkDay__c = System.today().addDays(-5),
            Before_4_WorkDay__c = System.today().addDays(-4)
 
        );
        insert oc;
 
         QIS_Report__c qr = new QIS_Report__c(
            RC__c = UserInfo.getUserId(),
            Photo_1__c = '<img src="http://www.google.co.jp/img1" />',
            Photo_2__c = '<img src="http://www.google.co.jp/img2" />',
            Photo_3__c = '<img src="http://www.google.co.jp/img3" />',
            Photo_4__c = '<img src="http://www.google.co.jp/img4" />',
            Damage_For_Doc_Or_Pat__c = '有',
            Relation_With_The_Problem__c = '有可能',
            Report_For_Goz__c = '不知道',
            Name = 'QIS012345',
            QIS_Submit_day__c = Date.Today(),
            SC_Judge_Date__c = Date.Today().addDays(-30),
            // nonyushohin__c  = ast.Id,
            // QIS_SC_Place__c =eng,
            next_action__c = action
        );
 
         insert qr;
 
        Test.startTest();
        Id execBTId = Database.executeBatch(new updateQISPDAddFour(),1);
        Test.stopTest();
    }
 
    static testMethod void testMethod2() {
          String  action = '送回';
         OlympusCalendar__c oc = new OlympusCalendar__c(
            Date__c = System.today(),
            Before_5_WorkDay__c = System.today().addDays(-5),
            Before_4_WorkDay__c = System.today().addDays(-4)
 
        );
        insert oc;
 
         QIS_Report__c qr = new QIS_Report__c(
            RC__c = UserInfo.getUserId(),
            Photo_1__c = '<img src="http://www.google.co.jp/img1" />',
            Photo_2__c = '<img src="http://www.google.co.jp/img2" />',
            Photo_3__c = '<img src="http://www.google.co.jp/img3" />',
            Photo_4__c = '<img src="http://www.google.co.jp/img4" />',
            Damage_For_Doc_Or_Pat__c = '有',
            Relation_With_The_Problem__c = '有可能',
            Report_For_Goz__c = '不知道',
            Name = 'QIS012345',
            QIS_Submit_day__c = Date.Today(),
            SC_Judge_Date__c = Date.Today().addDays(-30),
            // nonyushohin__c  = ast.Id,
            // QIS_SC_Place__c =eng,
            next_action__c = action
        );
 
         insert qr;
 
        Test.startTest();
        Id execBTId = Database.executeBatch(new updateQISPDAddFour(qr.id),1);
        Test.stopTest();
    }
}