From 3b43925ca3211c861a2818a089907d34b5480aa5 Mon Sep 17 00:00:00 2001
From: 张宇恒 <bxyun0@163.com>
Date: 星期五, 06 五月 2022 10:41:15 +0800
Subject: [PATCH] 批量数据拆分处理
---
force-app/main/default/classes/InquiryFormHandler.cls | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 164 insertions(+), 2 deletions(-)
diff --git a/force-app/main/default/classes/InquiryFormHandler.cls b/force-app/main/default/classes/InquiryFormHandler.cls
index d0507c0..aa44703 100644
--- a/force-app/main/default/classes/InquiryFormHandler.cls
+++ b/force-app/main/default/classes/InquiryFormHandler.cls
@@ -27,11 +27,12 @@
}
protected override void afterInsert() {
- //shareToOSCM();
+ //FSE涓绘媴褰撳叡浜�
+ shareToFSEMain();
}
protected override void afterUpdate() {
- //shareToOSCM();
+ shareToFSEMain();
}
//Before鍑︾悊
private void beforeExecute() {
@@ -54,7 +55,9 @@
nnObj.HospitalName__c = null; //鍖婚櫌鍚�
nnObj.Hospital__c = null; //鍖婚櫌
}
+
}
+
if (depIDList.size()>0) {
accList = [Select Id,OwnerId,
Hospital__c,Hospital__r.Name,
@@ -75,6 +78,8 @@
nObj.HospitalName__c = accMap.get(nObj.Hospital_Name__c).Hospital__r.Name; //鍖婚櫌鍚�
nObj.Hospital__c = accMap.get(nObj.Hospital_Name__c).Hospital__c; //鍖婚櫌
}
+
+
//浜у搧淇℃伅鐨勬嫾鎺�
if (String.isNotBlank(nObj.Product1__c) && String.isNotBlank(nObj.Product1_Manual__c)){
@@ -99,8 +104,121 @@
}
nObj.Product1_Manual__c = '';
+ //20220419 you SWAG-CBUB2W start
+ //鍏紡鑰冩枃鏈� 缁橣SE鎷呭綋璧嬪��
+ System.debug(nObj.FSE_Owner_id__c+'==123=='+nObj.FSE_Owner__c);
+ if(nObj.FSE_Owner_id__c != nObj.FSE_Owner__c){
+ nObj.FSE_Owner__c = nObj.FSE_Owner_id__c;
+ }
+ if(Trigger.isInsert && (nObj.Request1__c.indexOf('鏈嶅姟瀵瑰簲') !=-1 || nObj.ServiceCorrespond__c ==true)){
+ nObj.Service_Status__c ='01.鏈窡杩�';
+ }
+ if(Trigger.isUpdate){
+
+ if((nObj.Request1__c != oldMap.get(nObj.Id).Request1__c && nObj.Request1__c.indexOf('鏈嶅姟瀵瑰簲') !=-1) || (nObj.ServiceCorrespond__c != oldMap.get(nObj.Id).ServiceCorrespond__c && nObj.ServiceCorrespond__c ==true)){
+ if(String.isBlank(nObj.Service_Status__c)){
+ nObj.Service_Status__c ='01.鏈窡杩�';
+ }else{
+
+ }
+ }else if( nObj.Request1__c.indexOf('鏈嶅姟瀵瑰簲') ==-1 && nObj.ServiceCorrespond__c ==false){
+ nObj.Service_Status__c ='';
+ }
+ }
+
+ //20220419 you SWAG-CBUB2W end
}
}
+ //20220419 you SWAG-CBUB2W start
+ private void shareToFSEMain() {
+ //瀛樻斁鐢ㄤ簬鏂板鐨勫叡浜暟鎹�
+ List<Inquiry_form__Share> insertList = new List<Inquiry_form__Share>();
+ //瀛樻斁(浜у搧鍜ㄨ鍗昳d,鍏变韩瀵硅薄)
+ Map<Id,Inquiry_form__Share> insertMap = new Map<Id,Inquiry_form__Share>();
+ //瀛樻斁鏈�鍚庨渶瑕佹柊澧炵殑鍏变韩鏁版嵁
+ List<Inquiry_form__Share> lastInsertList = new List<Inquiry_form__Share>();
+ //瀛樻斁宸叉湁鐨勭浉鍚岀殑鍏变韩鍘熷洜鐨勬暟鎹�
+ List<Id> deleteTargetAOIdList = new List<Id>();
+ //瀛樻斁鐢ㄤ簬鐨刬d
+ List<Id> userIdList = new List<Id>();
+ // String rowCause = 'Manual';
+ //鏂板涓�涓叡浜師鍥�
+ String rowCause = Schema.Inquiry_form__Share.RowCause.FSE_Owner_c_User__c;
+ System.debug('rowCause:'+rowCause);
+ String ownerCause = 'Owner';
+ //Apex鍏辨湁銇悊鐢卞悕OCSM_Owner_c_User
+ for(Inquiry_form__c nObj : newList) {
+ Inquiry_form__c oObj = null;
+ if (oldMap != null && oldMap.containsKey(nObj.Id)) {
+ oObj = oldMap.get(nObj.Id);
+ }
+
+ if ( nObj.FSE_Owner__c != null && (oObj == null || oObj.FSE_Owner__c != nObj.FSE_Owner__c)) {
+ Inquiry_form__Share aos = new Inquiry_form__Share(
+ RowCause = rowCause,
+ ParentId = nObj.Id,
+ UserOrGroupId = nObj.FSE_Owner__c,
+ AccessLevel = 'Edit');
+ //瀛樻斁瑕佹柊澧炵殑鍏变韩鏁版嵁
+ insertList.add(aos);
+ System.debug('key:'+nObj.Id);
+ //瀛樻斁锛堜骇鍝佸挩璇㈠崟id,鍏变韩瀵硅薄锛�;
+ insertMap.put(nObj.Id,aos);
+ //瀛樻斁鐢ㄦ埛id 鐢ㄤ綔妫�绱㈡潯浠�
+ userIdList.add(nObj.FSE_Owner__c);
+ }
+ if(oObj != null && oObj.FSE_Owner__c != nObj.FSE_Owner__c){
+ deleteTargetAOIdList.add(nObj.Id);
+ }
+ }
+ System.debug('insertList:'+insertList);
+ System.debug('insertMap1:'+insertMap);
+ System.debug('IDlIST:'+deleteTargetAOIdList);
+ // 鍏� Delete 鍚� Insert
+ if (deleteTargetAOIdList.size() > 0) {
+ List<Inquiry_form__Share> deleteList = [SELECT Id
+ FROM Inquiry_form__Share
+ WHERE RowCause = :rowCause
+ AND ParentId IN :deleteTargetAOIdList
+ ];
+ delete deleteList;
+ }
+ //鍒ゆ柇闇�瑕佸叡浜殑浜� 鏄笉鏄垱寤轰汉 濡傛灉鏄垯璇存槑鏈変竴鏉¤繖涓汉鐨刼wner鏁版嵁 鍒欎笉鏂板
+ if (insertMap!= null) {
+ List<Inquiry_form__Share> ownerList = [SELECT Id,ParentId,UserOrGroupId
+ FROM Inquiry_form__Share
+ WHERE RowCause = :ownerCause
+ AND ParentId IN :insertMap.keySet()
+ AND UserOrGroupId IN :userIdList
+ ];
+ System.debug('ownerList:'+ownerList);
+ if(ownerList.size() > 0){
+ for( Inquiry_form__Share inq:ownerList){
+ String id = String.valueOf(inq.ParentId);
+ System.debug('id:'+id);
+ if(insertMap.containsKey(id)){
+ insertMap.remove(inq.ParentId);
+ }
+ }
+ }
+
+ }
+ System.debug('insertMap2:'+insertMap);
+
+ if(insertMap != null){
+ for(Inquiry_form__Share inquiry : insertMap.values()){
+ lastInsertList.add(inquiry);
+ }
+ }
+
+
+ System.debug('鍏变韩鍐呭:' +lastInsertList);
+ if(lastInsertList.size() > 0){
+ insert lastInsertList;
+ }
+
+ }
+ //20220419 you SWAG-CBUB2W end
//瀹㈡埛浜哄憳褰曞叆鍚�,銆愮數璇濄�戙�愰偖绠便�戣嚜鍔ㄥ綍鍏� thh 20220321 start
// private void getContactInformation(){
@@ -222,4 +340,48 @@
// }
// }
+
+ @TestVisible private static void test() {
+ Integer i = 0;
+
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;//鍙互澶氬啓鐐�
+ }
}
\ No newline at end of file
--
Gitblit v1.9.1