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 | 379 +++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 288 insertions(+), 91 deletions(-) diff --git a/force-app/main/default/classes/InquiryFormHandler.cls b/force-app/main/default/classes/InquiryFormHandler.cls index 735a187..0f96d2d 100644 --- a/force-app/main/default/classes/InquiryFormHandler.cls +++ b/force-app/main/default/classes/InquiryFormHandler.cls @@ -15,118 +15,315 @@ 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() { - Map<Id,Inquiry_form__c> accMap = new Map<Id,Inquiry_form__c>(); + Map<Id,Account> accMap = new Map<Id,Account>(); + Inquiry_form__c oObj = null; + List<String> depIDList = new List<String>(); + List<Account> accList = new List<Account>(); + + for(Inquiry_form__c nnObj : newList) { + if (oldMap != null && oldMap.containsKey(nnObj.Id)) { + oObj = oldMap.get(nnObj.Id); + } + if (String.isNotBlank(nnObj.Hospital_Name__c) && (Trigger.isInsert || oObj.Hospital_Name__c != nnObj.Hospital_Name__c || System.Label.Inquiry_form_flag == 'True')) { + depIDList.add(nnObj.Hospital_Name__c); + } + if (Trigger.isUpdate && String.isBlank(nnObj.Hospital_Name__c)){ + nnObj.Depart_Owner__c = null; //鎴樼暐绉戝鎵�鏈変汉 + nnObj.OwnerId = nnObj.CreatedById; //鎵�鏈変汉 + nnObj.Department_Class__c = null; //鎴樼暐绉戝 + 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, + Department_Class__c + from Account where Id =: depIDList]; + if (accList.size()>0) { + for(Account acc : accList){ + accMap.put(acc.Id, acc); + } + } + } + for(Inquiry_form__c nObj : newList) { - List<Account> accList = [Select Id,OwnerId from Account where Id =: nObj.Department_ID__c]; - for(Account acc : accList){ - nObj.Depart_Owner__c = acc.OwnerId; - } + if (accMap.containsKey(nObj.Hospital_Name__c)){ + nObj.Depart_Owner__c = accMap.get(nObj.Hospital_Name__c).OwnerId; //鎴樼暐绉戝鎵�鏈変汉 + nObj.OwnerId = accMap.get(nObj.Hospital_Name__c).OwnerId; //鎵�鏈変汉 + nObj.Department_Class__c = accMap.get(nObj.Hospital_Name__c).Department_Class__c; //鎴樼暐绉戝 + 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)){ + nObj.Product1__c = nObj.Product1__c +';'+nObj.Product1_Manual__c; + }else if (String.isBlank(nObj.Product1__c) && String.isNotBlank(nObj.Product1_Manual__c)){ + nObj.Product1__c = nObj.Product1_Manual__c; + }else if (String.isNotBlank(nObj.Product1__c) && String.isBlank(nObj.Product1_Manual__c)) { + nObj.Product1__c = nObj.Product1__c; + }else { + nObj.Product1__c = ''; + } + + //浜у搧鍜ㄨ鍗曞悕绉� + if (String.isNotBlank(nObj.Product1__c)&& String.isNotBlank(nObj.HospitalName__c)){ + nObj.Name = nObj.HospitalName__c+'-'+nObj.Product1__c; + }else if (String.isBlank(nObj.HospitalName__c)&& String.isNotBlank(nObj.Product1__c)) { + nObj.Name = nObj.Product1__c; + }else if (String.isNotBlank(nObj.HospitalName__c)&& String.isBlank(nObj.Product1__c)){ + nObj.Name = nObj.HospitalName__c; + }else{ + nObj.Name = '*'; + } + + 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() { - //瀛樻斁鐢ㄤ簬鏂板鐨勫叡浜暟鎹� - 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.OCSM_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('鎴樼暐绉戝鎷呭綋锛�'+nObj.Depart_Owner__c); - if (oldMap != null && oldMap.containsKey(nObj.Id)) { - oObj = oldMap.get(nObj.Id); - } + // private void shareToOSCM() { + // //瀛樻斁鐢ㄤ簬鏂板鐨勫叡浜暟鎹� + // 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.OCSM_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('鎴樼暐绉戝鎷呭綋锛�'+nObj.Depart_Owner__c); + // if (oldMap != null && oldMap.containsKey(nObj.Id)) { + // oObj = oldMap.get(nObj.Id); + // } - if ( nObj.Depart_Owner__c != null && (oObj == null || oObj.Depart_Owner__c != nObj.Depart_Owner__c)) { - Inquiry_form__Share aos = new Inquiry_form__Share( - RowCause = rowCause, - ParentId = nObj.Id, - UserOrGroupId = nObj.Depart_Owner__c, - AccessLevel = 'Edit'); - //瀛樻斁瑕佹柊澧炵殑鍏变韩鏁版嵁 - insertList.add(aos); - System.debug('key:'+nObj.Id); - //瀛樻斁锛堜細璁闂崟id,鍏变韩瀵硅薄锛�; - insertMap.put(nObj.Id,aos); - //瀛樻斁鐢ㄦ埛id 鐢ㄤ綔妫�绱㈡潯浠� - userIdList.add(nObj.Depart_Owner__c); - if (oObj != null && oObj.Depart_Owner__c != nObj.Depart_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); - } - } - } + // if ( nObj.Depart_Owner__c != null && (oObj == null || oObj.Depart_Owner__c != nObj.Depart_Owner__c)) { + // Inquiry_form__Share aos = new Inquiry_form__Share( + // RowCause = rowCause, + // ParentId = nObj.Id, + // UserOrGroupId = nObj.Depart_Owner__c, + // AccessLevel = 'Edit'); + // //瀛樻斁瑕佹柊澧炵殑鍏变韩鏁版嵁 + // insertList.add(aos); + // System.debug('key:'+nObj.Id); + // //瀛樻斁锛堜細璁闂崟id,鍏变韩瀵硅薄锛�; + // insertMap.put(nObj.Id,aos); + // //瀛樻斁鐢ㄦ埛id 鐢ㄤ綔妫�绱㈡潯浠� + // userIdList.add(nObj.Depart_Owner__c); + // if (oObj != null && oObj.Depart_Owner__c != nObj.Depart_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); + // } + // System.debug('insertMap2:'+insertMap); - if(insertMap != null){ - for(Inquiry_form__Share inquiry : insertMap.values()){ - lastInsertList.add(inquiry); - } - } + // if(insertMap != null){ + // for(Inquiry_form__Share inquiry : insertMap.values()){ + // lastInsertList.add(inquiry); + // } + // } - System.debug('鍏变韩鍐呭:' +lastInsertList); - if(lastInsertList.size() > 0){ - insert lastInsertList; - } + // System.debug('鍏变韩鍐呭:' +lastInsertList); + // if(lastInsertList.size() > 0){ + // insert lastInsertList; + // } - } + // } } \ No newline at end of file -- Gitblit v1.9.1