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
@isTest
private class OPDSortManageControllerTest {
  public static User user = new User();
    static testMethod void testMethod1() { 
      
        // User user = [select id,Salesdepartment__c from User where Salesdepartment__c='1.华北' limit 1];
        //OPD计划
        OPDPlan__c oPDPlan1 = new OPDPlan__c();
        oPDPlan1.Name = 'oPDPlan1';
        oPDPlan1.Status__c = '计划中';
        oPDPlan1.OPDPlan_ImplementDate__c =  Date.today().addMonths(1);
        oPDPlan1.NoOpp_Reason__c = 'HCP对应';     //无询价理由
        oPDPlan1.OPDLendSortDraft__c = 1;       //备品借出优先度
        oPDPlan1.OPDType__c = '事件';
        // oPDPlan1.Owner = user.Id;
        insert oPDPlan1;
 
        OPDPlan__c oPDPlan2 = new OPDPlan__c();
        oPDPlan2.Name = 'oPDPlan2';
        oPDPlan2.Status__c = '计划中';
        oPDPlan2.OPDPlan_ImplementDate__c = Date.today().addMonths(1);
        oPDPlan2.NoOpp_Reason__c = 'HCP对应'; 
        oPDPlan2.OPDType__c = '事件';
        insert oPDPlan2;
 
 
        OPDPlan__c oPDPlan3 = new OPDPlan__c();
        oPDPlan3.Name = 'oPDPlan3';
        oPDPlan3.Status__c = '计划中';
        oPDPlan3.OPDPlan_ImplementDate__c = Date.today().addMonths(1);
        oPDPlan3.NoOpp_Reason__c = 'HCP对应'; 
        oPDPlan3.OPDLendSortDraft__c = 2;
        oPDPlan3.OPDType__c = '事件';
        insert oPDPlan3;
 
        OPDPlan__c oPDPlan4 = new OPDPlan__c();
        oPDPlan4.Name = 'oPDPlan4';
        oPDPlan4.Status__c = '计划中';
        oPDPlan4.OPDPlan_ImplementDate__c = Date.today().addMonths(1);
        oPDPlan4.NoOpp_Reason__c = 'HCP对应'; 
        oPDPlan4.OPDType__c = '事件';
        insert oPDPlan4;
 
 
        OPDPlan__c oPDPlan5 = new OPDPlan__c();   
        oPDPlan5.Name = 'oPDPlan5';  
        oPDPlan5.Status__c = '计划中';
        oPDPlan5.OPDPlan_ImplementDate__c = Date.today().addMonths(1);
        oPDPlan5.NoOpp_Reason__c = 'HCP对应'; 
        oPDPlan5.OPDType__c = '事件';
        oPDPlan5.IsJump__c = true;
        oPDPlan5.JumpCause__c = '想插队';
        oPDPlan5.OPDLendSortDraft__c = 15;
        insert oPDPlan5;
 
        OPDPlan__c oPDPlan6 = new OPDPlan__c();  
        oPDPlan6.Name = 'oPDPlan6';   
        oPDPlan6.Status__c = '计划中';
        oPDPlan6.OPDPlan_ImplementDate__c = Date.today().addMonths(1);
        oPDPlan6.NoOpp_Reason__c = 'HCP对应'; 
        oPDPlan6.OPDType__c = '事件';
        oPDPlan6.IsJump__c = true;
        oPDPlan6.JumpCause__c = '想插队';
        oPDPlan6.OPDLendSort__c = 0;
        insert oPDPlan6;
        
        OPDPlan__c oPDPlan7 = new OPDPlan__c();     
        oPDPlan7.Name = 'oPDPlan7';
        oPDPlan7.Status__c = '计划中';
        oPDPlan7.OPDPlan_ImplementDate__c = Date.today().addMonths(1);
        oPDPlan7.NoOpp_Reason__c = 'HCP对应'; 
        oPDPlan7.OPDType__c = '事件';
        oPDPlan7.IsJump__c = true;
        oPDPlan7.JumpCause__c = '想插队';
        insert oPDPlan7;
 
        OPDPlan__c oPDPlan8 = new OPDPlan__c();   
        oPDPlan8.Name = 'oPDPlan8';  
        oPDPlan8.Status__c = '计划中';
        oPDPlan8.OPDPlan_ImplementDate__c = Date.today().addMonths(1);
        oPDPlan8.NoOpp_Reason__c = 'HCP对应'; 
        oPDPlan8.OPDType__c = '事件';
        oPDPlan8.IsJump__c = false;
        oPDPlan8.JumpCause__c = '想插队';
        oPDPlan8.OPDLendSortDraft__c = 1;
        oPDPlan8.OPDLendSort__c = 1;
        insert oPDPlan8;
        
 
        user = getUser();
 
        List<OPDPlan__c> oplist = [select id,IsJump__c,JumpCause__c,OPDLendSortDraft__c,OPDLendSort__c,IsSaveOrSubmit__c from OPDPlan__c where Status__c='计划中'];
        System.assertEquals(8, oplist.size());
 
        PageReference ref = new PageReference('/apex/OPDSortManage');
        Test.setCurrentPage(ref);
        OPDSortManageController target = new OPDSortManageController();
        target.init();
        // System.assertEquals(2, target.unCheckedOPDPlan.size()); //未排序的
        // target.Salesdepartment = '1.华北';
        target.searchBtn();
        //System.assertEquals(2, target.unCheckedOPDPlan.size()); //未排序的
        //target.unCheckedOPDPlan[0].check = true;
        target.saveAdd();
        target.autoSort();
        target.opdDelId = oPDPlan5.id;
        target.del();
        //target.checkedOPDPlan[4].op.OPDLendSortDraft__c = 18;
        target.save();
        //2020-12-02  mzy add 点击项目自行排序功能
        target.sortTableFlagSort ='asc';
        target.sortKey ='Sort';
        target.sortTable();
        target.sortTableFlagNDetail ='asc';
        target.sortKey ='NDetail';
        target.sortTable();
        target.sortTableFlagNtime ='asc';
        target.sortKey ='Ntime';
        target.sortTable();
        //2020-12-02  mzy add 点击项目自行排序功能
        System.runAs(user) {  
            List<Group> glist = [select id from group WHERE DeveloperName in ('X00_LOHBbeijing')];
            GroupMember mb = new GroupMember();
            mb.groupid =  glist[0].id;
            mb.userOrGroupId = user.id;
            insert mb;
            target.submitBtn();
        }
    }
 
    private static User getUser() {
    // 20230119 ljh  start
    /*String timenow = Datetime.now().format('yyyyMMddHHmmss');
    User usr = new User(Test_staff__c = true, LastName = 'TestZY', FirstName = 'TestZY',
                            Alias = 'zy', CommunityNickname = 'TestMiao', Email = 'TestZY@test.com',
                            Username = 'Test' + timenow + '@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP',
                            TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = System.Label.ProfileId_SystemAdmin,
                            Province__c = '北京市',Work_Location__c = '北京');
    insert usr;*/
    String ProfileId = System.Label.ProfileId_SystemAdmin;
    User usr = [SELECT Id,name from User WHERE ProfileId =:ProfileId AND Test_staff__c = true AND IsActive = true AND Province__c = '北京市' AND Work_Location__c = '北京'limit 1];
    // 20230119 ljh  end
    return usr;
  }
 
}