| | |
| | | private List<Rental_Apply__c> oldList; |
| | | private static Date td = Date.today(); |
| | | private static Map<Id, Rental_Apply__c> oldRaMap = new Map<Id, Rental_Apply__c>(); |
| | | public static Boolean isFirst = true; |
| | | |
| | | //update wangweipeng 2021/11/25 start |
| | | private static Map<String, String> approver_of_Service_DepartmentMap = new Map<String, String>(); |
| | |
| | | } |
| | | protected override void afterInsert() { |
| | | // Check本部是否可以选择 |
| | | checkbenbu(); |
| | | checkbenbu();// 20220909 ljh 恢复代码 |
| | | // 共享设定 |
| | | setShare(); |
| | | |
| | | decryptInsert(newList); |
| | | } |
| | | protected override void beforeUpdate() { |
| | | setManager(); |
| | |
| | | |
| | | protected override void afterUpdate() { |
| | | // Check本部是否可以选择 |
| | | checkbenbu(); |
| | | checkbenbu();// 20220909 ljh 恢复代码 |
| | | cancelRa(); |
| | | // before では数式項目がnullの場合があります |
| | | formulaToTextCheck(); |
| | |
| | | // 取消申请单的审批 |
| | | removedProcessRequest(); |
| | | |
| | | System.debug('---------------newList--------------' + newList); |
| | | |
| | | // add by lc 2022/11/15 DB202211029119 start |
| | | if (isFirst) { |
| | | // 主从申请单,只延主单的情况,走单独的处理逻辑,并且只执行一次 |
| | | synchRentalApplyDataMaster(); |
| | | } |
| | | // add by lc 2022/11/15 DB202211029119 end |
| | | |
| | | synchRentalApplyData2(); |
| | | // 延期审批后需要更新一览 |
| | | setAppExtensionRaes(); |
| | |
| | | setShare(); |
| | | // 办事处分单的装机确认 |
| | | setAgencyHPReceived(); |
| | | |
| | | //批量审批时,需要把主单和从单的延期字段信息同步 |
| | | synchRentalApplyData(); |
| | | } |
| | | |
| | | // add by lc 2022/11/15 DB202211029119 start |
| | | // 主从申请单,只延主单的情况,走单独的处理逻辑 |
| | | private void synchRentalApplyDataMaster() { |
| | | List<Rental_Apply_Equipment_Set__c> raesList = new List<Rental_Apply_Equipment_Set__c>(); |
| | | // 批准只能一条一条的批准 |
| | | for (Rental_Apply__c nObj : newList) { |
| | | Rental_Apply__c oObj = oldMap.get(nObj.Id); |
| | | |
| | | if (oObj.ExtensionApprovalTime_Initial__c != nObj.ExtensionApprovalTime_Initial__c |
| | | && nObj.ExtensionApprovalTime_Initial__c != null && oObj.ExtensionApprovalTime_Initial__c == null |
| | | && String.isNotBlank(nObj.Extension_Type__c) && nObj.Extension_Type__c == '批量延期' |
| | | && (nObj.demo_purpose2__c == '试用(无询价)' || nObj.demo_purpose2__c == '试用(有询价)') |
| | | && String.isBlank(oObj.Extension_Much_ID__c) |
| | | && String.isBlank(oObj.Root_Rental_Apply__c)) { |
| | | isFirst = false; |
| | | List<Rental_Apply__c> checkRentalApply = new List<Rental_Apply__c>(); |
| | | checkRentalApply.add(oObj); |
| | | try { |
| | | System.debug('========================checkRentalApply=========================' + checkRentalApply); |
| | | for (Rental_Apply_Equipment_Set__c raes : getCan_Extend_RequestList(checkRentalApply)) { |
| | | System.debug('raes.Id=========================' + raes.Id); |
| | | //判断是此申请单是否存在 ok并且回寄时间不为空的一览, |
| | | if ((raes.Received_Confirm__c == 'OK' || raes.Received_Confirm__c == '默认签收-OK') && raes.Asset_return_time__c != null) { |
| | | |
| | | }else{ |
| | | raes.RcUnexpectExpiryDelay__c = raes.Rental_Apply__r.RcUnexpectExpiryDelay__c; |
| | | raesList.add(raes); |
| | | } |
| | | } |
| | | } |
| | | catch (Exception e) { |
| | | nObj.addError(e.getMessage() + ',请操作驳回。'); |
| | | } |
| | | } |
| | | } |
| | | if (0 < raesList.size()) { |
| | | update raesList; |
| | | } |
| | | } |
| | | // add by lc 2022/11/15 DB202211029119 end |
| | | |
| | | private void setAgencyHPReceived() { |
| | | Set<Id> raIdSet = new Set<Id>(); |
| | |
| | | //如果为批量延期,那么这个集合里面会存放 原单+原单下所有的从单 |
| | | //如果为从单,并且目的2为询价,那么会存放 当前从单的原单+从单原单下所有的从单(包括当前从单) |
| | | List<Rental_Apply__c> checkRentalApply = new List<Rental_Apply__c>(); |
| | | // 只有产品试用会存在批量延期 |
| | | if(String.isNotBlank(nObj.Extension_Type__c) && nObj.Extension_Type__c == '批量延期'){ |
| | | System.debug('========================1========================='); |
| | | if(String.isNotBlank(nObj.Extension_Much_ID__c)){ |
| | | System.debug('========================2========================='); |
| | | String parentId = nObj.Id; |
| | | parentId = parentId.substring(0,15); |
| | | String likeParentId = parentId+'%'; |
| | |
| | | order by CreatedDate asc]; |
| | | } |
| | | }else{ |
| | | System.debug('========================3========================='); |
| | | //如果延期的是从单,那么需要特殊处理 |
| | | if(String.isNotBlank(nObj.Root_Rental_Apply__c) && (nObj.demo_purpose2__c == '试用(无询价)' || nObj.demo_purpose2__c == '试用(有询价)')){ |
| | | String likeParentId = nObj.Root_Rental_Apply__c+'%'; |
| | |
| | | } |
| | | checkRentalApply.add(oObj); |
| | | } |
| | | |
| | | System.debug('========================checkRentalApply=========================' + checkRentalApply); |
| | | for (Rental_Apply_Equipment_Set__c raes : getCan_Extend_RequestList(checkRentalApply)) { |
| | | //延期批准时间(最初)或延期批准时间(最终) 值都有变动,那么证明此次延期已经批准了,那么需要给申请单的一览赋值 |
| | | if (oObj.ExtensionApprovalTime_Initial__c != nObj.ExtensionApprovalTime_Initial__c |
| | |
| | | update raesList; |
| | | } |
| | | } |
| | | |
| | | // 20220909 ljh 恢复代码 |
| | | private void checkbenbu() { |
| | | for (Rental_Apply__c nObj : newList) { |
| | | if (nObj.DataMigration_Flag__c == false) { |
| | |
| | | RentalApplyTriggerHandler.doUnlockByFuture(raIdList); |
| | | } |
| | | } |
| | | |
| | | public static void decryptInsert(List<Rental_Apply__c> newList){ |
| | | if(!system.isFuture()){ |
| | | List<Rental_Apply__c> fendanList = new List<Rental_Apply__c>(); |
| | | for(Rental_Apply__c ra : newList){ |
| | | if(ra.Old_Rental_Apply__c != null){ |
| | | fendanList.add(ra); |
| | | } |
| | | } |
| | | |
| | | if(fendanList.size() == 0){ |
| | | system.debug('no need split'); |
| | | return; |
| | | } |
| | | |
| | | decryptInsertFuture(JSON.serialize(fendanList)); |
| | | } |
| | | } |
| | | |
| | | @future(callout=true) |
| | | public static void decryptInsertFuture(string json_list){ |
| | | decryptInsertCore(json_list); |
| | | } |
| | | |
| | | // List<Rental_Apply__c> temps = [select id,AWS_Data_Id__c,name, direct_shippment_address__c, Direct_Shippment_Address_Encrypt__c, Phone_number__c, Phone_Number_Encrypt__c,CreatedDate from Rental_Apply__c where AWS_Data_Id__c != null order by CreatedDate desc limit 2]; |
| | | public static void decryptInsertCore(string json_list){ |
| | | system.debug('enter decryptInsertCore'); |
| | | //调用滨璜接口更新 |
| | | PIHelper.PIIntegration staticResource = PIHelper.getPIIntegrationInfo('Rental_Apply__c'); |
| | | system.debug('staticResource.token='+staticResource.token); |
| | | if(String.isBlank(staticResource.token)){ |
| | | System.debug('获取aws token 失败'); |
| | | return; |
| | | } |
| | | List<Rental_Apply__c> newList = (List<Rental_Apply__c>)Json.deserialize(json_list, List<Rental_Apply__c>.class); |
| | | Map<Id,Rental_Apply__c> newMap = new Map<Id,Rental_Apply__c>(newList); |
| | | List<Map<string,object>> lmso = new List<Map<string,object>>(); |
| | | for(Rental_Apply__c ra : newList){ |
| | | Map<string,object> mso = new Map<string,object>(); |
| | | |
| | | /*if(!string.isBlank(ra.AWS_Data_Id__c)){ |
| | | continue; |
| | | }*/ |
| | | for(PI_Field_Policy_Detail__c detail : staticResource.PIDetails){ |
| | | if(ra.isSet(detail.SF_Field_API_Name__c)){ |
| | | mso.put(detail.AWS_Field_API__c,ra.get(detail.SF_Field_API_Name__c)); |
| | | mso.put(detail.AWS_Encrypted_Field_API__c,ra.get(detail.SF_Field_Encrypted_API__c)); |
| | | } |
| | | } |
| | | mso.put('sfRecordId',ra.Id); |
| | | lmso.add(mso); |
| | | } |
| | | |
| | | if(lmso.size()==0){ |
| | | system.debug('lmso.size()='+lmso.size()); |
| | | return; |
| | | } |
| | | string payload = Json.serialize(lmso); |
| | | system.debug('payload='+payload); |
| | | String awsApi = staticResource.viewUnifiedContactUrl; |
| | | NFMUtil.response response = NFMUtil.sendToPiAWS(payload, awsApi,staticResource.token); |
| | | system.debug(response); |
| | | Map<string,object> res_obj = (Map<string,object>)Json.deserializeUntyped(response.responseBody); |
| | | if(res_obj == null || !res_obj.containsKey('object') ){ |
| | | System.debug('res_obj == null || !res_obj.containsKey(\'object\')'); |
| | | return; |
| | | } |
| | | |
| | | List<object> objList = (List<object>)res_obj.get('object'); |
| | | if(objList == null){ |
| | | System.debug('objList == null'); |
| | | return; |
| | | } |
| | | |
| | | List<Rental_Apply__c> updateList = new List<Rental_Apply__c>(); |
| | | for(object obj : objList){ |
| | | Map<string,object> obj_map = (Map<string,object>)obj; |
| | | string sfRecordId = null; |
| | | string dataId = null; |
| | | if(obj_map.containsKey('sfRecordId')){ |
| | | sfRecordId = string.valueOf(obj_map.get('sfRecordId')); |
| | | }else{ |
| | | system.debug('obj_map.containsKey(\'sfRecordId\')='+obj_map.containsKey('sfRecordId')); |
| | | continue; |
| | | } |
| | | |
| | | if(obj_map.containsKey('dataId')){ |
| | | dataId = string.valueOf(obj_map.get('dataId')); |
| | | }else{ |
| | | system.debug('obj_map.containsKey(\'dataId\')='+obj_map.containsKey('dataId')); |
| | | continue; |
| | | } |
| | | |
| | | |
| | | if(newMap.containsKey(sfRecordId)){ |
| | | Rental_Apply__c ra = newMap.get(sfRecordId); |
| | | ra.AWS_Data_Id__c = dataId; |
| | | updateList.add(ra); |
| | | }else{ |
| | | system.debug('newMap.containsKey('+sfRecordId+')='+newMap.containsKey(sfRecordId)); |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | system.debug('updateList.size='+updateList.size()); |
| | | if(updateList.size()>0){ |
| | | update updateList; |
| | | } |
| | | |
| | | } |
| | | |
| | | @future |
| | | public static void doUnlockByFuture(List<ID> idList) { |
| | |
| | | } |
| | | } |
| | | } |
| | | System.debug('raes==============' + raes); |
| | | System.debug('raes1==============' + checkCan_Extend_Request(raes, false)); |
| | | if (checkCan_Extend_Request(raes, false)) { |
| | | raesList.add(raes); |
| | | } |