高章伟
2022-02-24 2aa8da8af66aa8ae00f25831aed6bb0364176e7b
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
@isTest
private class MaintenanceContractSetColunmWSTest {
    static testMethod void testMethod1() {
 
        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        insert hospital;
 
        // 戦略科室を得る
        List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
 
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id;
        dep.Name = 'test dep';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;
 
        // 维修合同を作成する
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Name = 'tect contract';
        contract.Hospital__c = hospital.Id;
        contract.Department_Class__c = strategicDep[0].Id;
        contract.Department__c = dep.Id;
        contract.Contract_Start_Date__c = Date.today();
        contract.RecordTypeId = [Select Id FROM RecordType WHERE Name = '维修合同'].Id;
        contract.Contract_End_Date__c = Date.today();
        insert contract;
 
        // 维修合同を作成する
        Maintenance_Contract__c contract1 = new Maintenance_Contract__c();
        contract1.Name = 'tect contract';
        contract1.Hospital__c = hospital.Id;
        contract1.Department_Class__c = strategicDep[0].Id;
        contract1.Department__c = dep.Id;
        contract1.Maintenance_Contract_No__c = 'contact1';
        contract1.Contract_Start_Date__c = Date.today();
        contract1.Contract_Conclusion_Date__c = Date.today();
        contract1.RecordTypeId = [Select Id FROM RecordType WHERE Name = '服务合同'].Id;
        contract1.Contract_End_Date__c = Date.today();
        insert contract1;
 
 
        // 维修合同を作成する
        Maintenance_Contract__c contract2 = new Maintenance_Contract__c();
        contract2.Name = 'tect contract';
        contract2.Hospital__c = hospital.Id;
        contract2.Department_Class__c = strategicDep[0].Id;
        contract2.Department__c = dep.Id;
        contract2.Contract_Start_Date__c = Date.today();
        contract2.RecordTypeId = [Select Id FROM RecordType WHERE Name = '维修合同'].Id;
        contract2.Contract_End_Date__c = Date.today();
        insert contract2;
 
        // 维修合同を作成する
        Maintenance_Contract__c contract3 = new Maintenance_Contract__c();
        contract3.Name = 'tect contract';
        contract3.Hospital__c = hospital.Id;
        contract3.Department_Class__c = strategicDep[0].Id;
        contract3.Department__c = dep.Id;
        contract3.Contract_Start_Date__c = Date.today();
        contract3.Maintenance_Contract_No__c = 'contact1';
        contract3.Contract_Conclusion_Date__c = Date.today();
        contract3.RecordTypeId = [Select Id FROM RecordType WHERE Name = '服务合同'].Id;
        contract3.Contract_End_Date__c = Date.today();
        insert contract3;
 
 
        // 保有设备C (只有附属品 个体管理)
           Asset assetC1 = new Asset(Asset_Owner__c = 'Olympus');
        assetC1.RecordTypeId = System.Label.Asset_RecordType;
        assetC1.SerialNumber = 'assetC1';
        assetC1.Name = '测试';
        assetC1.AccountId = dep.Id;
   
        assetC1.Out_of_wh__c = 0;
        // 保有设备
        Asset asset = new Asset(Asset_Owner__c = 'Olympus');
        asset.RecordTypeId = System.Label.Asset_RecordType;
        asset.SerialNumber = 'asset';
        Asset.AccountId = dep.Id;
        asset.Freeze_sign__c = false;
        asset.Out_of_wh__c = 0;
        asset.Name = '测试';
        insert new Asset[] {assetC1, asset};
 
        //创建维修合同下的保有设备
        Maintenance_Contract_Asset__c mc1 = new Maintenance_Contract_Asset__c();
        mc1.Maintenance_Contract__c = contract2.Id;
        mc1.LastMContract__c = contract3.Id;
        mc1.Asset__c = assetC1.Id;
        insert mc1;
 
        //创建维修合同下的保有设备
        Maintenance_Contract_Asset__c mc2 = new Maintenance_Contract_Asset__c();
        mc2.Maintenance_Contract__c = contract1.Id;
        mc2.LastMContract__c = contract.Id;
        mc2.Asset__c = asset.Id;
        insert mc2;
 
        System.debug('上一期维修合同空白期:mc1 --- '+mc1.LastMContract_Gap__c);
        System.debug('上一期维修合同空白期:mc2 --- '+mc2.LastMContract_Gap__c);
 
        MaintenanceContractSetColunmWebService.updateColunm(contract.Id);
        MaintenanceContractSetColunmWebService.updateColunm(contract2.Id);
        
        MaintenanceContractSetColunmWebService.updateColunm(contract1.Id);
        MaintenanceContractSetColunmWebService.updateColunm(contract3.Id);
 
    }
}