liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
public with sharing class ConsumApplyApprovalProcessController {
 
    @AuraEnabled
    public static InitDate initSubmitApprovalProcessController(String recordId) {
        InitDate res = new InitDate();
 
        
        Consum_Apply__c apply = [SELECT Id,
                            Request_Shipping_7days_Before__c,
                            Request_shipping_day__c,
                            Campaign__c,
                            QIS_number__c,
                            QIS_ID_Line__c,
                            Status__c,
                            Min_Consum_Can_Request_approval_Date__c,
                            applyUser__c,
                            JingliApprovalManager__c,
                            SalesManager__c,
                            BuchangApprovalManager__c,
                            BuchangApprovalManagerSales__c,
                            ZongjianApprovalManager__c, 
                            AccDealerBlacklist__c,
                            direct_send__c,
                            Medical_Institution_Address__c, // 20240103 fy  DB202312530994 add
                            Medical_Institution_Address_sup__c, // 20240103 fy  DB202312530994 add
                            CreatedDate,// 20240103 fy  DB202312530994 add
                            Hospital__r.TradeComplianceStatus__c, //20240121 kk 贸易合规2 add
                            Hospital__r.Name,//20240121 kk 贸易合规2 add
                            OwnerId FROM Consum_Apply__c WHERE Id = :recordId LIMIT 1];
        res.id = apply.Id;
        res.shippingDays = apply.Request_Shipping_7days_Before__c;
        res.shippingDay = apply.Request_shipping_day__c;
        res.campaign = apply.Campaign__c;
        res.qISNumber = apply.QIS_number__c;
        res.qISIDLine = apply.QIS_ID_Line__c;
        res.status = apply.Status__c;
        res.minApprovalDate = apply.Min_Consum_Can_Request_approval_Date__c;
        res.applyUser = apply.applyUser__c;
        res.jingliManager = apply.JingliApprovalManager__c;
        res.salesManager = apply.SalesManager__c;
        res.buchangManager = apply.BuchangApprovalManager__c;
        res.buchangManagerSale = apply.BuchangApprovalManagerSales__c;
        res.zongjianManager = apply.ZongjianApprovalManager__c;
        res.accDealerBlacklistc = apply.AccDealerBlacklist__c;
        res.tradeComplianceStatusFlagBP = System.Label.TradeComplianceStatusFlagBP;
        res.iFTradeComplianceAlertBP = System.Label.IFTradeComplianceAlertBP;
        res.owner = apply.OwnerId;
        res.directSend = apply.direct_send__c;
        // 20240103 fy  DB202312530994 start
        res.medicalInstitutionAddress = apply.Medical_Institution_Address__c;
        res.medicalInstitutionAddresssup = apply.Medical_Institution_Address_sup__c;
        res.createdDate = apply.CreatedDate;
        // 20240103 fy  DB202312530994 end
        //kk 贸易合规2期  20240121 start 
        res.accountTradeStatus = apply.Hospital__r.TradeComplianceStatus__c;
        res.accountName = apply.Hospital__r.Name;
        List<String> caesdStringList = new List<String>();
        List<Consum_Apply_Equipment_Set_Detail__c> caesdList = [select id,name,Asset__c,Asset__r.Product2.ProTradeComplianceStatus__c,
                                                                    Asset__r.Account.TradeComplianceStatus__c  
                                                                    from Consum_Apply_Equipment_Set_Detail__c where Consum_Apply__c = :recordId and Asset__c  != null];
        if (caesdList.size()>0) {
            for (Consum_Apply_Equipment_Set_Detail__c caesd : caesdList) {
                if (apply.Hospital__r.TradeComplianceStatus__c == '警示名单' && caesd.Asset__r.Product2.ProTradeComplianceStatus__c == '0') {
                    res.hgerqi = 'true';
                    caesdStringList.add(caesd.Id);
                }
            }
 
            //20240204 sx 发送邮件 start
            if(caesdStringList.size()>0){
                SendEmailUtil.tradeConsumTempleSend(recordId, '提交待审批', null, caesdStringList);
            }
            //20240204 sx 发送邮件 end
        }
        //kk 贸易合规2期  20240121 end
        
        return res;
 
    }
 
    public class InitDate{
 
        @AuraEnabled
        public String id;
    
        @AuraEnabled
        public Date shippingDays;//希望到货日前7个工作日
    
        @AuraEnabled
        public Date shippingDay;//希望到货日
    
        @AuraEnabled
        public String campaign ;//学会
    
        @AuraEnabled
        public String qISNumber;//QIS
    
        @AuraEnabled
        public String qISIDLine;//QIS的ID值
    
        @AuraEnabled
        public String status;//    状态
    
        @AuraEnabled
        public Date minApprovalDate;//最小可以提交申请日期
    
        @AuraEnabled
        public String applyUser;//操作者
    
        @AuraEnabled
        public String jingliManager;//CL6 经理级(服务)
    
        @AuraEnabled
        public String salesManager;//CL6 经理级
    
        @AuraEnabled
        public String buchangManager;//CL5 总监级(服务)
    
        @AuraEnabled
        public String buchangManagerSale;//CL5 总监级
    
        @AuraEnabled
        public String zongjianManager;//CL4 高级总监
 
        @AuraEnabled
        public String accDealerBlacklistc;//客户是否为黑名单
 
        @AuraEnabled
        public String tradeComplianceStatusFlagBP;//贸易合规开关
 
        @AuraEnabled
        public String iFTradeComplianceAlertBP;//贸易合规提醒
 
        //kk 贸易合规2期  20240121 start 
        @AuraEnabled
        public String accountTradeStatus;//医院贸易合规状态
 
        @AuraEnabled
        public String hgerqi;//是否有不合规的保有设备
 
        @AuraEnabled
        public String accountName; //医院名字
        //kk 贸易合规2期  20240121 end
 
    
        @AuraEnabled
        public String owner;//所有人
 
        @AuraEnabled
        public String directSend;//发送方
 
        // 20240103 fy  DB202312530994 start
        @AuraEnabled
        public String medicalInstitutionAddress;//医疗机构地址
 
        @AuraEnabled
        public String medicalInstitutionAddresssup;//医疗机构地址补充
 
        @AuraEnabled
        public Datetime createdDate;//创建日期
        // 20240103 fy  DB202312530994 end
      
    }
 
    @AuraEnabled
    public static List<Campaign> selectCampaignById(String recordId){
        
        List<Campaign> campaign=[SELECT Status, Rental_Apply_Flag__c FROM Campaign WHERE id  =:recordId]; 
        
        return campaign;
    }
    
    @AuraEnabled
    public static List<QIS_report__c> selectReportById(String recordId){
        
        List<QIS_report__c> report=[SELECT id,next_action__c FROM QIS_report__c WHERE id  =:recordId]; 
        return report;
    }
    
    @AuraEnabled
    public static List<Consum_Apply_Equipment_Set__c> selectEquipmentById(String recordId){
        
        List<Consum_Apply_Equipment_Set__c> equipment=[SELECT Id FROM Consum_Apply_Equipment_Set__c 
                                                            WHERE RetalFSetDetail_Cnt__c = 0 AND Consum_Apply__c  =:recordId]; 
    
        return equipment;
    }
 
    @AuraEnabled
    public static String approvalCheck(String recordId){
        
        String res = ConsumApplyWebService.approvalCheck(recordId);
        return res;
    }
 
    @AuraEnabled
    public static String setSObjectShare(String applyUser,String parentId,List<String> userAccess, String ownerId){
        
        String res = ControllerUtil.setSObjectShare('Consum_Apply__Share','ApplyUserShare__c',parentId,userAccess,ownerId);
        System.debug('controller---res'+res);
        return res;
    }
 
    @AuraEnabled
    public static String updateConsumApply(String recordId){
        try{
            Consum_Apply__c apply = [SELECT Id,
            Request_Shipping_7days_Before__c,
            Request_shipping_day__c,
            Campaign__c,
            QIS_number__c,
            QIS_ID_Line__c,
            Status__c,
            Min_Consum_Can_Request_approval_Date__c,
            applyUser__c,
            JingliApprovalManager__c,
            SalesManager__c,
            BuchangApprovalManager__c,
            BuchangApprovalManagerSales__c,
            ZongjianApprovalManager__c, 
            OwnerId FROM Consum_Apply__c WHERE Id = :recordId LIMIT 1];
            apply.Status__c = '填写完毕';
            update apply;
            return '1';
        }catch(Exception e){
            if (e.getMessage().contains(':')) {
                String eMessage = e.getMessage();
                Integer left  = e.getMessage().indexOf(',')+1;
                Integer right = e.getMessage().lastIndexOf('。')+1;
                return eMessage.substring(left,right);
            }else{
                return e.getMessage();
            }
        }
        
        
        
    }
 
    
}