/** * @Author lijinhuan * @DateTime 2022-12-28T18:25:42+0800 * 测试类:FrameNumUploadControllerTest */ global class SetFrameNumManageWebService { // 2023-07-31 zhangchunxu add @AuraEnabled @AuraEnabled /** * @fuction [关联数据] * @Author lijinhuan * @DateTime 2023-01-10T11:06:10+0800 */ WebService static String updateFrameNumManag(String Id) { Id execBTId = Database.executeBatch(new SetFrameNumManageBatch(Id), 1); return '1'; } // 2023-07-31 zhangchunxu add @AuraEnabled @AuraEnabled /** * @fuction [批量删除] * @Author lijinhuan * @DateTime 2023-01-10T11:06:10+0800 */ WebService static String BatchDelete(List idList) { Savepoint sp = Database.setSavepoint(); try{ //sf删除 Database.delete(idList); return 'success'; }catch(Exception e){ Database.rollback(sp); System.debug('失败原因是 : ' + e.getMessage()); return '失败原因是 : ' + e.getMessage(); } } // 2023-07-31 zhangchunxu add @AuraEnabled @AuraEnabled /** * @fuction [生成机身号管理对象数据] * @Author lijinhuan0 * @DateTime 2023-02-07T11:06:1+0800 */ WebService static String insertFrameNumManag(String Id,String esId) { // 进口单证 kyb 20231122 DB202311302316 增加发货日设置 start Set dateset = new Set(); Map olycals = new Map(); // 进口单证 kyb 20231122 DB202311302316 增加发货日设置 end // return Id+';'+esId; // 20231017 ljh DB202308311963 update start // Map sandMap = new Map(); Map> sandMap = new Map>(); // 20231017 ljh DB202308311963 update end Map UpdateSandMap = new Map(); Map UpdateFIdMap = new Map(); try{ // 查询明细 在机身号管理中有没,没有生成,有更新 签收单、发货DN明细、保有设备 for(Statu_Achievements_DN_details__c dn:[SELECT Id,SerialNumber__c,asset__c, Statu_Achievements_DN__c,SerialNoorLotNo_Raw__c,TracingCodeRawSys__c, OTCode_Raw__c,asset__r.Name,QTY__c,Statu_Achievements_DN__r.Name // 进口单证 kyb 20231122 DB202311302316 增加发货日设置 start , Statu_Achievements_DN__r.DeliveryDate__c // 进口单证 kyb 20231122 DB202311302316 增加发货日设置 end FROM Statu_Achievements_DN_details__c WHERE Statu_Achievements_DN__c =:Id ]){ // 20230915 ljh DB202308311963 start // sandMap.put(dn.TracingCode_Raw__c,dn); List tempObjList; if(sandMap.containsKey(dn.TracingCodeRawSys__c)){ tempObjList = sandMap.get(dn.TracingCodeRawSys__c); }else{ tempObjList = new List(); } tempObjList.add(dn); sandMap.put(dn.TracingCodeRawSys__c,tempObjList); // 20230915 ljh DB202308311963 end // 取所有发货日 kyb 20231122 DB202311302316 start dateset.add(dn.Statu_Achievements_DN__r.DeliveryDate__c); // 取所有发货日 kyb 20231122 DB202311302316 end } for(FrameNumManage__c f:[SELECT Id,ManagementCode__c FROM FrameNumManage__c WHERE ManagementCode__c in :sandMap.keySet()]){ // 更新机身号管理 // 20231017 DB202308311963 start // UpdateSandMap.put(f.ManagementCode__c,sandMap.get(f.ManagementCode__c)); UpdateSandMap.put(f.ManagementCode__c,sandMap.get(f.ManagementCode__c)[0]); // 20231017 DB202308311963 end UpdateFIdMap.put(f.ManagementCode__c, f.Id); sandMap.remove(f.ManagementCode__c); } // 取发货日的奥林巴斯日历 kyb 20231122 DB202311302316 start for (OlympusCalendar__c oc : [select Id, Date__c from OlympusCalendar__c where Date__c in :dateset]) { olycals.put(oc.Date__c, oc.Id); } // 取发货日的奥林巴斯日历 kyb 20231122 DB202311302316 end if(sandMap.size() > 0 || UpdateSandMap.size() > 0){ List infnmList = new List(); // 20231017 ljh DB202308311963 start for (String skey:sandMap.keySet()) { Integer qty = sandMap.get(skey).size(); Statu_Achievements_DN_details__c s = sandMap.get(skey)[0]; // for (Statu_Achievements_DN_details__c s:sandMap.values()) { FrameNumManage__c temp = new FrameNumManage__c(); // 20230915 ljh DB202308311963 start // temp.Name = s.TracingCode_Raw__c; // temp.ManagementCode__c = s.TracingCode_Raw__c; // temp.SerialNumberS__c = s.SerialNoorLotNo_Raw__c+'('+s.TracingCode_Raw__c+')'; temp.Name = s.TracingCodeRawSys__c; temp.ManagementCode__c = s.TracingCodeRawSys__c; temp.SerialNumberS__c = s.SerialNoorLotNo_Raw__c+'('+s.TracingCodeRawSys__c+')'; // 20230915 ljh DB202308311963 end temp.SerialNumber__c = s.SerialNoorLotNo_Raw__c; // 20231017 ljh DB202308311963 start // temp.Num__c = s.QTY__c; temp.Num__c = qty; // 20231017 ljh DB202308311963 end temp.CheckOutNo__c = s.Statu_Achievements_DN__r.Name.subString(2);//发货DN 的name去掉前两位的 00 temp.Statu_Achievements_DN_details__c = s.Id; temp.Asset__c = s.asset__c; temp.signInForm__c = esId; // 设置发货日和奥林巴斯日历 kyb 20231122 DB202311302316 start temp.DeliveryDate__c = s.Statu_Achievements_DN__r.DeliveryDate__c; temp.DeliveryDate_select__c = temp.DeliveryDate__c != null && olycals.size() > 0 && String.isNotBlank(olycals.get(temp.DeliveryDate__c)) ? olycals.get(temp.DeliveryDate__c) : null; // 设置发货日和奥林巴斯日历 kyb 20231122 DB202311302316 send temp.Material__c = s.OTCode_Raw__c; temp.MaterialDepict__c = s.asset__r.Name; infnmList.add(temp); } if(infnmList.size() > 0){ insert infnmList; // Database.executeBatch(new SetFrameNumManageBatch(), 100); } if(UpdateSandMap.size() > 0){ List upfnmList = new List(); for (Statu_Achievements_DN_details__c s:UpdateSandMap.values()) { // 20230915 ljh DB202308311963 start // if(UpdateFIdMap.get(s.TracingCode_Raw__c) != null ){ if(UpdateFIdMap.get(s.TracingCodeRawSys__c) != null ){ // 20230915 ljh DB202308311963 end FrameNumManage__c temp = new FrameNumManage__c(); // 20230915 ljh DB202308311963 start // temp.id = UpdateFIdMap.get(s.TracingCode_Raw__c); temp.id = UpdateFIdMap.get(s.TracingCodeRawSys__c); // 20230915 ljh DB202308311963 end temp.Statu_Achievements_DN_details__c = s.Id; temp.Asset__c = s.asset__c; temp.signInForm__c = esId; upfnmList.add(temp); } } if(upfnmList.size() > 0 ){ update upfnmList; } } // return '1'; } return '1'; // else{ // return '数据已经关联,没有需要关联的数据'; // } }catch(Exception e){ // Database.rollback(sp); System.debug('失败原因是 : ' + e.getMessage()); return '失败原因是 : ' + e.getMessage(); } } }