高章伟
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
public with sharing class CreateDataCommon {
    //调用共通类的方法,可以创建医院、战略科室、科室、经销商、契约
    //医院
    public Account CreateHp(){
        Account hospital = new Account();
        Id hpRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
        //hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.recordtypeId = hpRecordTypeId;
        hospital.Name = '20220110testHospital';
        hospital.Is_Active__c = '有効';
        hospital.Attribute_Type__c = '卫生部';
        hospital.Speciality_Type__c = '综合医院';
        hospital.Grade__c = '一级';
        hospital.OCM_Category__c = 'SLTV';
        hospital.Is_Medical__c = '医疗机构';
        hospital.Assume_Change__c = true;
        insert hospital;
        return hospital;
    }
 
    //战略科室
    public Account CreateStrategicDep(Account hospital){
        //Department_Class_OTH  戦略科室分類 その他
        // Account sdep = new Account();
        // Id sdepRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_Class_OTH').getRecordTypeId();
        // sdep.recordtypeId = sdepRecordTypeId;
        // sdep.Name = '20220113Test 其他';
        // sdep.Department_Class_Label__c = '其他';
        // sdep.parentId = hospital.Id;
        // insert sdep;
        // return sdep;
        Account sdep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_OTH'];
        return sdep;
        
    }
 
    //科室(医院 -- 战略科室 -- 科室)
    public Account CreateDepartment(Account hospital,Account sdep){
        //Department_OTH  診療科 その他
        Account dep = new Account();
        dep.parentId = sdep.Id;
        Id depRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_OTH').getRecordTypeId();
        dep.recordtypeId = depRecordTypeId;
        dep.Name = '其他';
        dep.Department_Class__c = sdep.Id;
        dep.Department_Name__c = '20220113Test 其他 其他';
        dep.Hospital__c = hospital.Id;
        insert dep;
        return dep;
    }
 
    //经销商  
    public Account CreateDealer(){
        Account acc = new Account();
        Id accRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Agency').getRecordTypeId();
        acc.recordtypeId = accRecordTypeId;
        //acc.Dealer_discount__c =20;
        acc.name='20220113TestAcc';
        insert acc;
        return acc;
 
    }
 
    //契约(经销商合同)
    public Account CreateContract(Account acc){
        Account con = new Account();
        Id conRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('AgencyContract').getRecordTypeId();
        con.name='20220113TestCon';
        con.RecordTypeId = conRecordTypeId;
        con.Contract_Decide_Start_Date__c = Date.today().addDays(-1);
        con.Contract_Decide_End_Date__c =Date.today().addDays(1);
        con.Agent_Ref__c = acc.Id;
        con.ParentId = acc.Id;
        //con.ET_SP_Dealer__c = true;
        insert con;
        return con;
    }
 
}