From 64b3629116e6f3f5eb3debf9b451d100f4010fa5 Mon Sep 17 00:00:00 2001 From: 游畅 <youchang@prec-tech.com> Date: 星期五, 22 四月 2022 13:50:56 +0800 Subject: [PATCH] 询问单相关修改 --- force-app/main/default/classes/InquiryFormHandler.cls | 145 +++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 142 insertions(+), 3 deletions(-) diff --git a/force-app/main/default/classes/InquiryFormHandler.cls b/force-app/main/default/classes/InquiryFormHandler.cls index ffe6238..0f96d2d 100644 --- a/force-app/main/default/classes/InquiryFormHandler.cls +++ b/force-app/main/default/classes/InquiryFormHandler.cls @@ -15,17 +15,24 @@ protected override void beforeInsert() { beforeExecute(); + //瀹㈡埛浜哄憳褰曞叆鍚�,銆愮數璇濄�戙�愰偖绠便�戣嚜鍔ㄥ綍鍏� thh 20220321 start + // getContactInformation(); + //瀹㈡埛浜哄憳褰曞叆鍚�,銆愮數璇濄�戙�愰偖绠便�戣嚜鍔ㄥ綍鍏� thh 20220321 end } protected override void beforeUpdate() { beforeExecute(); + //瀹㈡埛浜哄憳褰曞叆鍚�,銆愮數璇濄�戙�愰偖绠便�戣嚜鍔ㄥ綍鍏� thh 20220321 start + // getContactInformation(); + //瀹㈡埛浜哄憳褰曞叆鍚�,銆愮數璇濄�戙�愰偖绠便�戣嚜鍔ㄥ綍鍏� thh 20220321 end } protected override void afterInsert() { - //shareToOSCM(); + //FSE涓绘媴褰撳叡浜� + shareToFSEMain(); } protected override void afterUpdate() { - //shareToOSCM(); + shareToFSEMain(); } //Before鍑︾悊 private void beforeExecute() { @@ -48,7 +55,18 @@ nnObj.HospitalName__c = null; //鍖婚櫌鍚� nnObj.Hospital__c = null; //鍖婚櫌 } + //20220419 you SWAG-CBUB2W start + //鍏紡鑰冩枃鏈� 缁橣SE鎷呭綋璧嬪�� + System.debug(nnObj.FSE_Owner_id__c+'==123=='+nnObj.FSE_Owner__c); + if(nnObj.FSE_Owner_id__c != nnObj.FSE_Owner__c){ + nnObj.FSE_Owner__c = nnObj.FSE_Owner_id__c; + } + if(Trigger.isInsert && (nnObj.Request1__c.indexOf('鏈嶅姟瀵瑰簲') !=-1 || nnObj.ServiceCorrespond__c ==true)){ + nnObj.Service_Status__c ='01.鏈窡杩�'; + } + //20220419 you SWAG-CBUB2W end } + if (depIDList.size()>0) { accList = [Select Id,OwnerId, Hospital__c,Hospital__r.Name, @@ -95,7 +113,128 @@ nObj.Product1_Manual__c = ''; } } - + //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; + System.debug('FSE涓绘媴褰擄細'+nObj.FSE_Owner__c); + 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(){ + // List<String> ContactIdList = new List<String>(); + // List<Contact> ContactList = new List<Contact>(); + // Map<String, Contact> ContactMap = new Map<String, Contact>(); + // for(Inquiry_form__c nnObj : newList) { + // if(String.isNotBlank(nnObj.Contact_Name__c)){ + // ContactIdList.add(nnObj.Contact_Name__c); + // } + // } + // if(ContactIdList.size() > 0){ + // ContactList = [select id, Phone, Email from Contact where Id IN :ContactIdList]; + // for(Contact contact : ContactList){ + // ContactMap.put(contact.Id, contact); + // } + // } + // for(Inquiry_form__c nnObj : newList) { + // if(String.isNotBlank(nnObj.Contact_Name__c)){ + // if(String.isNotBlank(ContactMap.get(nnObj.Contact_Name__c).Phone)){ + // nnObj.Phone__c = ContactMap.get(nnObj.Contact_Name__c).Phone; + // } + // if(String.isNotBlank(ContactMap.get(nnObj.Contact_Name__c).Email)){ + // nnObj.Email__c = ContactMap.get(nnObj.Contact_Name__c).Email; + // } + // } + // } + // } + //瀹㈡埛浜哄憳褰曞叆鍚�,銆愮數璇濄�戙�愰偖绠便�戣嚜鍔ㄥ綍鍏� thh 20220321 end + // 鎴樼暐绉戝鐨勪富鎷呭綋 銈掑彇寰椼�両nquiry_form__Share銇ō瀹�(Read) // private void shareToOSCM() { // //瀛樻斁鐢ㄤ簬鏂板鐨勫叡浜暟鎹� -- Gitblit v1.9.1