高章伟
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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/**
 * wangweipeng        2021/11/22
 * 备品:批量延期申请
 *
 * 只有批量延期的时候,才会进这个类
 */
public without sharing class RentalApplyMultiPostponeController {
 
    /***************url传来的备品申请单id********************/
    public String parentId{get;set;}
 
    /***************表格数据*********************/
    public List<getTableData> tableData { get; set; }
 
    public RentalApplyMultiPostponeController() {
        parentId = System.currentPageReference().getParameters().get('parentId');
        //parentId = 'a0t1000000T3KpAAAV';
        tableData = new List<getTableData>();
    }
 
    /**
     * 开始方法
     */
    public PageReference init(){
        if(String.isNotBlank(parentId)){
            getCanPostponeData(parentId);
        }
        return null;
    }
 
    /**
     * [getCanPostponeData description]
     * @param parentId [description]
     * 获取所有的申请单并处理数据
     */
    public void getCanPostponeData(String parentId){
        if(String.isNotBlank(parentId)){
            //获取所有的备品申请单
            List<Rental_Apply__c> rentalApplyList = getAllRentalApply(parentId);
            if(rentalApplyList != null && rentalApplyList.size() > 0){
                Map<ID,Rental_Apply_Equipment_Set__c> raescMap = new Map<ID,Rental_Apply_Equipment_Set__c>();
                Map<ID,Rental_Apply_Equipment_Set__c> raescMapTrue = new Map<ID,Rental_Apply_Equipment_Set__c>();
                List<Rental_Apply_Equipment_Set__c> raesc = getExtend_Request(parentId);
                //申请单任一个一览收货OK已回寄的,此单不满足延期条件
                if(raesc != null && raesc.size() > 0){
                    for(Rental_Apply_Equipment_Set__c raes : raesc){
                        //申请单任一个一览收货OK已回寄的,此单不满足延期条件
                        if ((raes.Received_Confirm__c == 'OK' || raes.Received_Confirm__c == '默认签收-OK') && raes.Asset_return_time__c != null) {
                            raescMap.put(raes.Rental_Apply__c, raes);
                        }
                        if(RentalApplyTriggerHandler.checkCan_Extend_Request(raes,false)){
                            raescMapTrue.put(raes.Rental_Apply__c,raes);
                        }
                    }
                }
                for(Rental_Apply__c rac : rentalApplyList){
                    //如果申请单为取消和删除状态,那么就不可以勾选
                    //延期申请时间(最初)  不为空,证明他已经延期过一回了,不需要再次延期(产品试用只能延期一回)
                    if(rac.RA_Status__c == '取消' || rac.RA_Status__c == '删除' || rac.ExtensionApplicationTime_Initial__c != null){
                        //tableData.add(new getTableData(rac,false));
                    }else{
                        //③可延期的申请单应满足:已出库的--已回收(不含)之间状态,且最新预定归还日≥ 今天
                        //没有满足上面的条件,页面置灰,并且也不可以选中
                        //当前日期
                        Date today = Date.today();
                        //预定归还日不能为空
                        if(rac.Return_dadeline_final__c != null){
                            //最新预定归还日≥ 今天。
                            if(rac.Return_dadeline_final__c >= today){
                                //多条数据,证明他需要批量延期,所有特殊处理
                                //可延期的申请单应满足:已出库的--已回收(不含)之间状态,且最新预定归还日≥ 今天。
                                if(rac.RA_Status__c == '申请者已收货' || rac.RA_Status__c == '医院已装机确认' || rac.RA_Status__c == '已出库')
                                {
                                    //申请单任一个一览收货OK已回寄的,此单不满足延期条件
                                    if(raescMap.containsKey(rac.Id)){
                                        //tableData.add(new getTableData(rac,false));
                                    }else{
                                        if(raescMapTrue.containsKey(rac.Id)){
                                            tableData.add(new getTableData(rac,true));
                                        }
                                    }
 
                                }
                                /*else{
                                    tableData.add(new getTableData(rac,false));
                                }*/
                            }
                            /*else{
                                tableData.add(new getTableData(rac,false));
                            }*/
                        }
                        /*else{
                            tableData.add(new getTableData(rac,false));
                        }*/
                    }
                }
            }
        }
    }
    //返回按钮
    public PageReference senBackPage(){
        PageReference ref = new Pagereference('/' + parentId);
        ref.setRedirect(true);
        return ref;
    }
    /**
     * 根据传过来的备品id获取所有的从单和原单
     * @param  parentId 备品id
     * @param  rentalApplyType 如果为办事处,那么只查 试用有询价和无询价的单子  0 备品中心,1 办事处
     * @return               返回所有的原单和从单
     * 参数有可能是原单id或从单id
     * 因为我们新增了一这样的逻辑,
     *     如果是原单,并且没有分割单,那么他只判断自己本身是否满足条件,
     *     如果为原单,并且有分割单,那么他也需要判断他下面的分割单是否满足条件
     *     如果为分割单,那么他需要找到他的原单,并且查询此原单下的所有分割单是否满足条件
     */
    public static List<Rental_Apply__c> getAllRentalApply(String parentId){
        String likeParentId = parentId+'%';
        List<Rental_Apply__c> allRentalApply = [SELECT id,
                                                        Name,
                                                        RA_Status__c,
                                                        Request_return_day__c,
                                                        demo_purpose1__c,
                                                        demo_purpose2__c,
                                                        ExtensionApprovalTime_Final__c,
                                                        RC_Ordered_Date__c,
                                                        Bollow_Date_Add_10_WD__c,
                                                        Loaner_received_ng_num__c,
                                                        ExtensionApprovalTime_Initial__c,
                                                        next_action__c,
                                                        NewRepair__c,
                                                        NewRepair__r.Agreed_Date__c,
                                                        NewRepair__r.Status__c,
                                                        NewRepair__r.ReRepairObject_F__c,
                                                        NewRepair__r.Repair_Shipped_Date__c,
                                                        AgreementBorrowingExtensionDate__c,
                                                        Return_dadeline_final__c,
                                                        loaner_Status__c,
                                                        Account__r.Department_Name__c,
                                                        Account__r.Name,
                                                        Account__c,
                                                        Split_Apply_Reason__c,
                                                        ExtensionApplicationTime_Initial__c,
                                                        Root_Rental_Apply__c
                                                    FROM Rental_Apply__c WHERE id = :parentId OR Root_Rental_Apply__c like :likeParentId 
                                                        order by Name asc];
        return allRentalApply;
    }
 
    public static List<Rental_Apply_Equipment_Set__c> getExtend_Request(String parentId){
        String likeParentId = parentId+'%';
        List<Rental_Apply_Equipment_Set__c> raes = [SELECT Id,Name
                                                    , Rental_Apply__c
                                                    , Rental_Apply__r.Repair__r.Agreed_Date__c
                                                    , Rental_Apply__r.Repair__r.Repair_Estimated_date_formula__c
                                                    , Rental_Apply__r.NewRepair__c
                                                    , Rental_Apply__r.NewRepair__r.Agreed_Date__c
                                                    , Rental_Apply__r.NewRepair__r.Status__c
                                                    , Rental_Apply__r.NewRepair__r.ReRepairObject_F__c
                                                    , Rental_Apply__r.NewRepair__r.Repair_Shipped_Date__c
                                                    , Rental_Apply__r.QISRepair__r.Repair_Shipped_Date__c
                                                    , Rental_Apply__r.RC_return_to_office__c
                                                    , Rental_Apply__r.AgreementBorrowingExtensionDate__c
                                                    , Rental_Apply__r.ExtensionApprovalTime_Initial__c
                                                    , Rental_Apply__r.ExtensionApplicationTime_Final__c
                                                    , Rental_Apply__r.RcUnexpectExpiryDelay__c
                                                    , Final_reply_day__c
                                                    , Asset_return_time__c
                                                    , Bollow_Date__c
                                                    , demo_purpose2__c
                                                    , demo_purpose1__c
                                                    , Request_demo_time__c
                                                    , Loaner_received_time__c
                                                    , Received_Confirm__c
                                                    , Loaner_received_day2__c
                                                    , RcUnexpectExpiryDelay__c
                                                 FROM Rental_Apply_Equipment_Set__c
                                                WHERE (Rental_Apply__c = :parentId OR Root_Rental_Apply__c like :likeParentId)
                                                  AND Cancel_Reason__c = null];
        return raes;
    }
    /**
     * 为了方便前段table获取值
     */
    class getTableData {
        //数据
        public Rental_Apply__c rentalApplyTable { get; set; }
        //是否可以勾选
        public Boolean canCheck { get; private set; }
        
        public getTableData(Rental_Apply__c rat,Boolean checkFlag) {
            this.canCheck = checkFlag; 
            this.rentalApplyTable = rat;
        }
    }
}