public without sharing class ConsumApplyEquipmentSetDetailHandler extends Oly_TriggerHandler { private Map newMap; private Map oldMap; private List newList; private List oldList; //Consum_Apply_Equipment_Set_Detail__c 更新する時にAssetも更新する可能性がありますので,ここでstaticMapを作成しsiAssetを結集します private static Map assMap = new Map(); // new Only private static Map assUpdMap = new Map(); // new と old private static Set updatedSet = new Set(); // new と old private static Set executeed_refreshQueueNumber = new Set(); // 已经处理过排队顺 Consum_Apply_Equipment_Set_Detail__c.Id private static Map calendarMap = new Map(); // 已经处理过排队顺 Consum_Apply_Equipment_Set_Detail__c.Id public ConsumApplyEquipmentSetDetailHandler() { if (Trigger.isUpdate || Trigger.isUndelete || Trigger.isDelete) { this.newMap = new Map(); this.newList = new List(); this.oldMap = (Map) Trigger.oldMap; this.oldList = (List) Trigger.old; // 大前提 Fixture_Set__c ですが下記の属性が設定されています // 参照関係に含まれる参照レコードは削除できません。 if (Trigger.isUpdate || Trigger.isUndelete) { for (SObject nSObj : Trigger.new) { Consum_Apply_Equipment_Set_Detail__c nObj = (Consum_Apply_Equipment_Set_Detail__c) nSObj; Consum_Apply_Equipment_Set_Detail__c oObj = null; if (Trigger.isUpdate) { oObj = oldMap.get(nObj.Id); } if (Trigger.isUpdate && String.isNotBlank(nObj.DeliverySlip__c) && String.isNotBlank(oObj.DeliverySlip__c) && oObj.DeliverySlip__c != nObj.DeliverySlip__c) { nObj.addError('不能修改借出备品配套明细的运输单'); } else if (Trigger.isUpdate && String.isNotBlank(nObj.Return_DeliverySlip__c ) && String.isNotBlank(oObj.Return_DeliverySlip__c ) && oObj.Return_DeliverySlip__c != nObj.Return_DeliverySlip__c ) { nObj.addError('不能修改借出备品配套明细的回寄运输单'); } else { this.newList.add(nObj); this.newMap.put(nObj.Id, nObj); } } } } else { // insert this.newMap = (Map) Trigger.newMap; this.oldMap = (Map) Trigger.oldMap; this.newList = (List) Trigger.new; this.oldList = (List) Trigger.old; } } protected override void beforeInsert() { beforeSetValue(); } protected override void beforeUpdate() { setcalendarMap(); beforeSetValue(); } private void setcalendarMap() { Set dSet = new Set(); for (Consum_Apply_Equipment_Set_Detail__c nObj : newList) { Consum_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id); if (oObj.Consum_Start_Date__c != nObj.Consum_Start_Date__c && nObj.Consum_Start_Date__c != null && calendarMap.containsKey(nObj.Consum_Start_Date__c) == false) { dSet.add(nObj.Consum_Start_Date__c); } } if (dSet.size() > 0) { List cList = [SELECT Id , Date__c , IsWorkDay__c , After_1_WorkDay__c , After_2_WorkDay__c , After_3_WorkDay__c , After_4_WorkDay__c , After_5_WorkDay__c , After_6_WorkDay__c , After_7_WorkDay__c , After_8_WorkDay__c , After_9_WorkDay__c , After_10_WorkDay__c , After_11_WorkDay__c , After_12_WorkDay__c , After_13_WorkDay__c , After_14_WorkDay__c , After_15_WorkDay__c , After_16_WorkDay__c , After_17_WorkDay__c , After_18_WorkDay__c , After_19_WorkDay__c , After_20_WorkDay__c , After_21_WorkDay__c , After_22_WorkDay__c , After_23_WorkDay__c , After_24_WorkDay__c , After_25_WorkDay__c , After_26_WorkDay__c , After_27_WorkDay__c , After_28_WorkDay__c , After_29_WorkDay__c , After_30_WorkDay__c , Before_1_WorkDay__c , Before_2_WorkDay__c , Before_3_WorkDay__c , Before_4_WorkDay__c , Before_5_WorkDay__c , Before_6_WorkDay__c , Before_7_WorkDay__c , Before_8_WorkDay__c , Before_9_WorkDay__c , Before_10_WorkDay__c , Before_11_WorkDay__c , Before_12_WorkDay__c , Before_13_WorkDay__c , Before_14_WorkDay__c , Before_15_WorkDay__c , Before_16_WorkDay__c , Before_17_WorkDay__c , Before_18_WorkDay__c , Before_19_WorkDay__c , Before_20_WorkDay__c , Before_21_WorkDay__c , Before_22_WorkDay__c , Before_23_WorkDay__c , Before_24_WorkDay__c , Before_25_WorkDay__c , Before_26_WorkDay__c , Before_27_WorkDay__c , Before_28_WorkDay__c , Before_29_WorkDay__c , Before_30_WorkDay__c FROM OlympusCalendar__c WHERE Date__c = :dSet ]; System.debug(dSet); System.debug(cList); for (OlympusCalendar__c calender: cList) { calendarMap.put(calender.Date__c, calender); } } } protected override void afterInsert() { setassMap(); formulaToTextCheck(); //入力規則 新建数据不能分配がありますので,ここではLastとOut_of_wh__cの設定必要ありません Set raesdAssignSet = new Set(); for (Consum_Apply_Equipment_Set_Detail__c nObj : newList) { if (nObj.Select_Time__c != null) { if (String.isNotBlank(nObj.Consum_Apply__c)) { raesdAssignSet.add(nObj.Consum_Apply__c); } } } if (raesdAssignSet.size() > 0) { // 设置分配人 setAssginPerson(raesdAssignSet); } changeAssetCount(); if (!assUpdMap.isEmpty()) { System.debug(assUpdMap); update assUpdMap.values(); } } private void setassMap() { Set assIds = new Set(); List caesdList = new List(); if (Trigger.isDelete) { caesdList = oldList; } else { caesdList = newList; } for (Consum_Apply_Equipment_Set_Detail__c raesd : caesdList) { if (String.isNotBlank(raesd.Asset__c)) { assIds.add(raesd.Asset__c); } } if (!assIds.isEmpty()) { assMap = new Map([ Select Id, Quantity, Status, Manage_type__c, Out_of_wh__c, Rental_Count__c, Abandoned_Inventory__c, Abandoned_RealThing__c, Confirm_Lost_Count__c, Consumed_Count__c From Asset Where Id =: assIds FOR UPDATE]); } } protected override void afterDelete() { setassMap(); deleteReFirst(); //排队顺有变化的时候重新设置排队顺 reQueueNumber(); changeAssetCount(); if (!assUpdMap.isEmpty()) { update assUpdMap.values(); } } protected override void afterUpdate() { setassMap(); // 备品数量的加减 changeAsset(); // 排队再分配 借出分配数量的减 等, clear Last_Reserve_RAES_Detail__c, 設定First_RAESD__c // clearLastReserveRAESD(); //Asset变更的时候 更新Asset的 Last_Reserve_RAES_Detail__c // changeAssetLast(); // Asset.Out_of_wh__c+ - changeAssetCount(); // change Consumable_Guaranteen_end__c OLY_OCM-601 changeAssetConsumable_Guaranteen_end(); // 同じblock の 排队レコード Queue_Number__c をrefresh // refreshQueueNumberByBlock(); if (!assUpdMap.isEmpty()) { System.debug(assUpdMap); update assUpdMap.values(); } // 4-XX 的 一对一对应 // oneToOne4XX(); // キャンセルコピー, 一览单位取消后的拷贝在一览的Handler里面做 // cancelCopy(); // before では数式項目がnullの場合があります formulaToTextCheck(); //排队顺有变化的时候重新设置排队顺 // reQueueNumber(); //申请者收回NG后明细回寄时的邮件回寄单内容设置 receivedConfirmNGSetReturnDeliverySlipText(); Set raesdSet = new Set(); Set raesdAssignSet = new Set(); for (Consum_Apply_Equipment_Set_Detail__c nObj : newList) { Consum_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id); if (String.isBlank(oObj.Return_DeliverySlip__c) && String.isNotBlank(nObj.Return_DeliverySlip__c)) { raesdSet.add(nObj.Id); } if (nObj.Select_Time__c != null && oObj.Select_Time__c == null) { raesdAssignSet.add(nObj.Consum_Apply__c); } } System.debug(raesdSet); if (raesdSet.size() > 0) { // 设置回寄通知内容 ConsumApplyEquipmentSetDetailHandler.setRequestAsset_return_Text(raesdSet); } if (raesdAssignSet.size() > 0) { // 设置分配人 setAssginPerson(raesdAssignSet); } } private void beforeSetValue() { Set raesdSet = new Set(); for (Consum_Apply_Equipment_Set_Detail__c nObj : newList) { raesdSet.add(nObj.Consum_Apply_Equipment_Set__c); } Map raesdMap = new Map([Select Id, Model_No__c , Name , IndexFromUniqueKey__c From Consum_Apply_Equipment_Set__c Where Id =: raesdSet]); for (Consum_Apply_Equipment_Set_Detail__c nObj : newList) { //因为是Insert时候设值 情况1,申请新建会设值 情况2,NG拷贝出来的时候会设值 //因为UniqueKey__c判断了DataMigration_Flag__c所以这里也需要判断 检索的时候因为要假Insert所以不需要设置 // TODO bp3 DetailHandler里, 对FSD设值的地方 需要在Consum_Apply__c的Handler里, 变成批准時, 也要设值。 if (Trigger.isInsert && nObj.DataMigration_Flag__c == false) { //nObj.Is_Body__c = nObj.Is_Body_F__c; if (String.isNotBlank(nObj.Fixture_Set_Detail__c)) { nObj.FSD_Id__c = nObj.Fixture_Set_Detail__c; } if (nObj.Consum_Start_Date__c == null) { nObj.Consum_Start_Date__c = nObj.Consum_Start_Date_F__c; } if (nObj.Consum_Can_Request_approval_Date__c == null) { nObj.Consum_Can_Request_approval_Date__c = nObj.Consum_Can_Request_approval_Date_F__c; } if (nObj.Consum_Start_Date_After_15_Day__c == null) { nObj.Consum_Start_Date_After_15_Day__c = nObj.Consum_Start_Date_After_15_Day_F__c; } // 272チケット // Create_State__c为空并且申请书的标准批准时间不为空的时候设置为1 // 1 --- 追加附属品 // 0 --- Cancel拷贝 // null --- 普通新规 if (nObj.Create_State__c == null && nObj.Consum_Apply_Request_approval_time_F__c != null //&& nObj.Substitute_Select_Again__c == false) { // OLY_OCM-404 分配代替品 ) { nObj.Create_State__c = 1; } //nObj.FSD_Is_Optional__c = nObj.FSD_Is_Optional_F__c; //nObj.FSD_Is_OneToOne__c = nObj.FSD_Is_OneToOne_F__c; //nObj.FSD_OneToOneAccessory_Cnt__c = nObj.FSD_OneToOneAccessory_Cnt_F__c; nObj.FSD_Fixture_Model_No__c = nObj.Fixture_Model_No_F__c; if (nObj.DataMigration_Flag__c == false && (!Trigger.isUpdate || String.isNotBlank(nObj.Asset__c))) { nObj.Fixture_Model_No_text__c = nObj.Fixture_Model_No_F__c; nObj.FSD_Name_CHN__c = nObj.Fixture_Name_F__c; } nObj.CreatedBy_ProfileId__c = UserInfo.getProfileId(); // nObj.ApplyPersonAppended__c = nObj.ApplyPersonAppended_F__c; } if (nObj.DeliverySlip__c != null && nObj.DataMigration_Flag__c == false && (!Trigger.isUpdate || String.isNotBlank(nObj.Asset__c))) { if (nObj.Shippment_loaner_time__c == null) { nObj.Shippment_loaner_time__c = nObj.Shippment_loaner_time2__c; } } nObj.DeliverySlip_Text__c = nObj.DeliverySlip__c; nObj.Return_DeliverySlip_Text__c = nObj.Return_DeliverySlip__c; nObj.Received_Confirm_Text__c = nObj.Received_Confirm__c; Consum_Apply_Equipment_Set_Detail__c oObj = null; if (Trigger.isUpdate) { oObj = oldMap.get(nObj.Id); if(oObj.Received_Confirm__c != nObj.Received_Confirm__c){ if(String.isNotBlank(nObj.Received_Confirm__c)){ nObj.Loaner_received_time__c = System.Now(); } else{ nObj.Loaner_received_time__c = null; } } if (oObj.Asset_Center_Confirm__c != nObj.Asset_Center_Confirm__c && String.isNotBlank(nObj.Asset_Center_Confirm__c)) { nObj.Asset_Center_Confirm_Time__c = System.Now(); nObj.Asset_Center_Confirm_Staff__c = UserInfo.getUserId(); } if (oObj.Consum_Start_Date__c != nObj.Consum_Start_Date__c) { if (nObj.Consum_Start_Date__c == null) { nObj.Consum_Can_Request_approval_Date__c = null; nObj.Consum_Start_Date_After_15_Day__c = null; } else { Date d; Date d1; System.debug(calendarMap); System.debug(nObj.Consum_Start_Date__c); if (calendarMap.get(nObj.Consum_Start_Date__c).Before_22_WorkDay__c != null) { d = calendarMap.get(nObj.Consum_Start_Date__c).Before_22_WorkDay__c; } else { d = Consum_ApplyUtil.getWD_addday(nObj.Consum_Start_Date__c, -22); } if (calendarMap.get(nObj.Consum_Start_Date__c).After_15_WorkDay__c != null) { d1 = calendarMap.get(nObj.Consum_Start_Date__c).After_15_WorkDay__c; } else { d1 = Consum_ApplyUtil.getWD_addday(nObj.Consum_Start_Date__c, 15); } nObj.Consum_Start_Date_After_15_Day__c = d1; nObj.Consum_Can_Request_approval_Date__c = d; } } //出库前检查NGの場合キャンセルします //if(oObj.Inspection_result__c != 'NG' && nObj.Inspection_result__c == 'NG') { // nObj.Cancel_Select__c = true; // nObj.Cancel_Reason__c = '重新分配'; // nObj.Loaner_cancel_Remarks__c = '出库前检查NG'; //} // OLY_OCM-435対応 start String userid = UserInfo.getUserId(); DateTime now = System.now(); if (oObj.Inspection_result__c != nObj.Inspection_result__c && String.isNotBlank(nObj.Inspection_result__c)) { nObj.Pre_inspection_time__c = now; nObj.Inspection_staff__c = userid; } if (oObj.Check_lost_Item_Final__c != nObj.Check_lost_Item_Final__c && String.isNotBlank(nObj.Check_lost_Item_Final__c)) { nObj.Lost_item_check_time_Final__c = now; nObj.Lost_item_check_staff_Final__c = userid; } if (oObj.Check_lost_Item__c != nObj.Check_lost_Item__c && String.isNotBlank(nObj.Check_lost_Item__c)) { nObj.Lost_item_check_time__c = now; nObj.Lost_item_check_staff__c = userid; } //if (oObj.CDS_complete__c != nObj.CDS_complete__c && nObj.CDS_complete__c) { // nObj.CDS_complete_time__c = now; // nObj.CDS_staff__c = userid; //} if (oObj.Inspection_result_after_Final__c != nObj.Inspection_result_after_Final__c && String.isNotBlank(nObj.Inspection_result_after_Final__c)) { nObj.After_Inspection_time_Final__c = now; nObj.Inspection_staff_After_Final__c = userid; } if (oObj.Inspection_result_after__c != nObj.Inspection_result_after__c && String.isNotBlank(nObj.Inspection_result_after__c)) { nObj.After_Inspection_time__c = now; nObj.Inspection_staff_After__c = userid; } if (String.isNotBlank(nObj.Picture1__c) || String.isNotBlank(nObj.Picture2__c)) { nObj.Has_Picture__c = true; } else{ nObj.Has_Picture__c = false; } // OLY_OCM-435対応 end } Consum_Apply_Equipment_Set__c raes = raesdMap.get(nObj.Consum_Apply_Equipment_Set__c); //画面显示用clone出来的数据不需要设置Name //IndexFromUniqueKey__c.format()会报错 要判不是Null if (nObj.DataMigration_Flag__c == false && raes != null //&& raes.IndexFromUniqueKey__c != null && nObj.IndexFromUniqueKey__c != null //&& (!Trigger.isUpdate || String.isNotBlank(nObj.Fixture_Set_Id__c))) ) { String split_ApplyNum = nObj.RequestNoJoinStr2__c; if (nObj.Consum_Apply_r_Name__c.contains('_')) { // XXXX-YYYY_1 (ZZZZ_1) List split_ApplyNumList = nObj.Consum_Apply_r_Name__c.split('_'); String raName = split_ApplyNumList[split_ApplyNumList.size() - 2]; // XXXX-YYYY (ZZZZ) split_ApplyNum = split_ApplyNumList[split_ApplyNumList.size() - 1]; // 1 split_ApplyNumList = raName.split('-'); // [XXXX, YYYY] ([ZZZZ]) if (split_ApplyNumList.size() > 1) { // YYYY_1 split_ApplyNum = split_ApplyNumList[split_ApplyNumList.size() - 1] + '_' + split_ApplyNum; } else { // ZZZZ_1 split_ApplyNum = nObj.Consum_Apply_r_Name__c; } } // ToDo 确认以下命名规则是否可以 nObj.Name = split_ApplyNum + ':' + raes.Model_No__c + ':' + nObj.IndexFromUniqueKey__c.format().leftpad(3, '0'); // 如果是分配代替品名字加:Sub //if (nObj.Substitute_Select_Again__c) { // nObj.Name += ':Sub'; //} //一览时申请者收货NG的话名字添加NG if (nObj.Received_Confirm__c == 'NG') { nObj.Name += ':NG'; } //取消的时候名字加Canceled if (nObj.Cancel_Select__c) { nObj.Name += ':Canceled'; } } nObj.Loaner_accsessary__c = nObj.Loaner_accsessary_F__c; nObj.Loaner_centre_mail_address__c = nObj.Loaner_centre_mail_address_F__c; // 暂定分配或保有设备更新时, 设值 if (Trigger.isInsert || (oObj.Asset__c != nObj.Asset__c ) || (oObj.Select_Time__c != nObj.Select_Time__c)) { // 一对一保管主体(借出时) if (nObj.DataMigration_Flag__c == false && (!Trigger.isUpdate)) { // 备品配套明细型号(借出时) if (String.isBlank(nObj.Fixture_Model_No_F__c)) { nObj.addError('分配的Asset:'+ nObj.Asset__c + ', 没有设定 备品配套明细型号'); } else { nObj.Fixture_Model_No_text__c = nObj.Fixture_Model_No_F__c; } } if (nObj.Select_Time__c == null && (Trigger.isInsert || (oObj.Asset__c != nObj.Asset__c )) ) { if (nObj.Asset__c != null) { nObj.Provisional_Select_Time__c = Datetime.now(); } else { nObj.Provisional_Select_Time__c = null; } } // 机身编号(耗材时) nObj.SerialNumber_text__c = nObj.SerialNumber__c; // 所在地区(省) 耗材时 #OLY_OCM-654:因为是赋值所以不修改 nObj.SalesProvince_before__c = nObj.SalesProvince__c; // 所在地区(本部) 耗材时 #OLY_OCM-654:因为是赋值所以不修改 nObj.Salesdepartment_before__c = nObj.Salesdepartment__c; // 产品分类(GI/SP)(耗材时) #OLY_OCM-654:因为是赋值所以不修改 nObj.Product_category_text__c = nObj.Product_category_F__c; // 备品分类(耗材时) #OLY_OCM-654:因为是赋值所以不修改 nObj.Equipment_Type_text__c = nObj.Equipment_Type_F__c; // 备品成本(耗材时) nObj.Asset_cost_del_before__c = nObj.Asset_cost_del__c; // 备品存放地(耗材时) nObj.Internal_asset_location_before__c = nObj.Internal_asset_location__c; //备品名称(耗材时) nObj.Fixture_Name_text__c = nObj.Fixture_Name_F__c; // OLY_OCM-243 追加字段对应 备品管理编码(耗材时) nObj.EquipmentSet_Managment_Code_text__c = nObj.EquipmentSet_Managment_Code__c; //// OLY_OCM-452 追加字段对应 刀头(借出时) //if (String.isNotBlank(nObj.Fixture_Set_Detail__c)) { // nObj.Is_Special_Product_Text__c = nObj.Is_Special_Product__c; //} } // 排队时, 要注意 设值 移动到排队btn里 //else if (Trigger.isUpdate && String.isBlank(nObj.Asset__c) && oObj.Cancel_Select__c == false // // && oObj.Fixture_Model_No_text__c != nObj.Fixture_Model_No_text__c // && (oObj.Queue_Number__c == 0 || oObj.Queue_Number__c == null) && nObj.Queue_Number__c > 0 //) { // 排队时重新赋值Fixture_Model_No_text__c 为了排的不是旧Model_No //nObj.FSD_Fixture_Model_No__c = nObj.Fixture_Model_No_F__c; // 备品配套明细型号(借出时) // nObj.Fixture_Model_No_text__c = nObj.Fixture_Model_No_F__c; // 所在地区(省) 借出时 //nObj.SalesProvince_before__c = nObj.SalesProvince__c; // // 所在地区(本部) 借出时 // nObj.Salesdepartment_before__c = nObj.Salesdepartment__c; // // 产品分类(GI/SP)(借出时) // nObj.Product_category_text__c = nObj.Product_category_F__c; // // 备品分类(借出时) // nObj.Equipment_Type_text__c = nObj.Equipment_Type__c; // // 备品存放地(借出时) // nObj.Internal_asset_location_before__c = nObj.Internal_asset_location__c; //} // 其他时候(申请时), null设值 和 // 一对一已分配的附属品,主体重新排队时,一对一附属品需要重新按照申请的逻辑重新赋值 else if ((Trigger.isInsert && nObj.Cancel_Select__c == false) || (Trigger.isUpdate && String.isBlank(nObj.Asset__c) && oObj.Cancel_Select__c == false)) { // 备品配套明细型号(耗材时) if (String.isBlank(nObj.Fixture_Model_No_text__c) && nObj.DataMigration_Flag__c == false && (!Trigger.isUpdate || String.isNotBlank(nObj.Asset__c))) { nObj.Fixture_Model_No_text__c = nObj.Fixture_Model_No_F__c; } // 所在地区(省) 耗材时 #OLY_OCM-654:因为是赋值所以不修改 if (String.isBlank(nObj.SalesProvince_before__c)) { nObj.SalesProvince_before__c = nObj.SalesProvince__c; } // 所在地区(本部) 耗材时 #OLY_OCM-654:因为是赋值所以不修改 if (String.isBlank(nObj.Salesdepartment_before__c)) { nObj.Salesdepartment_before__c = nObj.Salesdepartment__c; } // 产品分类(GI/SP)(耗材时) #OLY_OCM-654:因为是赋值所以不修改 if (String.isBlank(nObj.Product_category_text__c)) { nObj.Product_category_text__c = nObj.Product_category_F__c; } // 备品分类(耗材时) #OLY_OCM-654:因为是赋值所以不修改 if (String.isBlank(nObj.Equipment_Type_text__c)) { nObj.Equipment_Type_text__c = nObj.Equipment_Type__c; } // 备品存放地(耗材时) if (String.isBlank(nObj.Internal_asset_location_before__c)) { nObj.Internal_asset_location_before__c = nObj.Internal_asset_location__c; } // 备品名称(耗材时) if (String.isBlank(nObj.Fixture_Name_text__c)) { nObj.Fixture_Name_text__c = nObj.Fixture_Name_F__c; } // OLY_OCM-243 追加字段对应 备品管理编码(耗材时) if (String.isBlank(nObj.EquipmentSet_Managment_Code_text__c)) { nObj.EquipmentSet_Managment_Code_text__c = nObj.EquipmentSet_Managment_Code__c; } //// OLY_OCM-452 追加字段对应 刀头(借出时) //if (String.isBlank(nObj.Is_Special_Product_Text__c)) { // nObj.Is_Special_Product_Text__c = nObj.Is_Special_Product__c; //} } else { // 取消的情况在下面有设值 } if (nObj.DataMigration_Flag__c == false && nObj.Cancel_Select__c == false && (!Trigger.isUpdate || String.isNotBlank(nObj.Asset__c))) { // if (String.isBlank(nObj.Fixture_Model_No_text__c)) { // nObj.addError(nObj.Id + ':备品配套明细型号不能为空, 备品配套明细=' + nObj.Fixture_Set_Detail__c); // } // #OLY_OCM-654 数量管理的话,所在地区(本部)&产品分类&备品分类的判断不需要 Start // if ('数量管理' == nObj.Manage_type_F__c ) { // || false == nObj.Loaner_accsessary__c TODO: 需确认 if (String.isBlank(nObj.Internal_asset_location_before__c)) { nObj.addError('备品存放地不能为空'); // } // } // else { // #OLY_OCM-654 数量管理的话,所在地区(本部)&产品分类&备品分类的判断不需要 end // if (String.isBlank(nObj.Salesdepartment_before__c)) { // nObj.addError('所在地区(本部)不能为空'); // } // if (String.isBlank(nObj.Internal_asset_location_before__c)) { // nObj.addError('备品存放地不能为空'); // } // if (String.isBlank(nObj.Product_category_text__c) && nObj.Is_Body__c) { // nObj.addError('产品分类(GI/SP)不能为空'); // } // if (String.isBlank(nObj.Equipment_Type_text__c) && nObj.Is_Body__c && nObj.Demo_purpose1__c != '其他') { // nObj.addError('备品分类不能为空'); // } // if (String.isBlank(nObj.SalesProvince_before__c) && nObj.Is_Body__c) { // nObj.addError('所在地区(省)不能为空'); // } } } if (nObj.DataMigration_Flag__c == false) { //出库指示更新明细的key nObj.UniqueKey__c = nObj.RequestNoJoinStr2__c + ':'+ nObj.Consum_Apply_Equipment_Set__c + ':' + nObj.Fixture_Model_No__c + ':' + nObj.Degree_Of_Importance__c; System.debug(nObj.Degree_Of_Importance__c); if (nObj.Cancel_Select__c) { nObj.UniqueKey__c += nObj.Id; // 下架后的取消加; if (nObj.StockDown__c) { nObj.UniqueKey__c += ';' + nObj.Id; } // nObj.Queue_Number__c = null; if (nObj.StockDown__c && //nObj.Inspection_result__c != 'NG' && String.isBlank(nObj.DeliverySlip__c)) { nObj.OnStock_By_Cancel__c = true; // nObj.Inspection_result_after_Flag_Text__c = 'true'; } } } System.debug(nObj.Degree_Of_Importance__c + 'key is' + nObj.UniqueKey__c); // 取消分配 //Action 18 によってキャンセルの場合 //借出备品Set一览明细.保有设备(Link) //借出备品Set一览明细.分配时间 //借出备品Set一览明细.已做出库指示 //借出备品Set一览明细.出库指示时间 if (Trigger.isInsert || oObj.Cancel_Select__c != nObj.Cancel_Select__c || (oObj.Asset__c != nObj.Asset__c && String.isBlank(nObj.Asset__c))) { if (nObj.Cancel_Select__c || String.isBlank(nObj.Asset__c)) { if(nObj.Cancel_Select__c && nObj.NG_Select_Again__C == false){ nObj.Cancel_Date__c = System.today(); nObj.Cancel_Time__c = MainFixtureSelectController.getCurrentTime(); nObj.Cancel_Mem__c = UserInfo.getUserId(); } if (nObj.StockDown__c == false) { nObj.Asset__c = null; nObj.Select_Time__c = null; nObj.Shipment_request_time2__c = null; nObj.Shipment_request__c = false; // 根据OLY_OCM-243记载,取消也需要清除接借出时相关的字段 if (nObj.DataMigration_Flag__c == false && (!Trigger.isUpdate || String.isNotBlank(nObj.Asset__c))) { // 备品配套明细型号(借出时) nObj.Fixture_Model_No_text__c = nObj.FSD_Fixture_Model_No__c; } // 机身编号(借出时) nObj.SerialNumber_text__c = null; // 所在地区(省) 借出时 #OLY_OCM-654:因为是赋值所以不修改 nObj.SalesProvince_before__c = null; // 所在地区(本部) 借出时 #OLY_OCM-654:因为是赋值所以不修改 nObj.Salesdepartment_before__c = null; // 产品分类(GI/SP)(借出时) #OLY_OCM-654:因为是赋值所以不修改 nObj.Product_category_text__c = null; // 备品分类(借出时) #OLY_OCM-654:因为是赋值所以不修改 nObj.Equipment_Type_text__c = null; // 备品成本(借出时) nObj.Asset_cost_del_before__c = null; // 备品存放地(借出时) nObj.Internal_asset_location_before__c = null; //备品名称(借出时) nObj.Fixture_Name_text__c = nObj.FSD_Name_CHN__c; // 备品管理编码(借出时) nObj.EquipmentSet_Managment_Code_text__c = null; } } else { nObj.Cancel_Date__c = null; nObj.Cancel_Time__c = null; nObj.Cancel_Mem__c = null; //nObj.Cancel_Reason__c = null; } } if (oObj != null && oObj.Select_Time__c != nObj.Select_Time__c) { if (nObj.Select_Time__c != null) { nObj.Consum_Assign_Person__c = UserInfo.getUserId(); } else { nObj.Consum_Assign_Person__c = null; } } // 归还后CDS //if (Trigger.isInsert || oObj.CDS_complete__c != nObj.CDS_complete__c) { // if (nObj.CDS_complete__c) { // nObj.CDS_complete_time__c = System.now(); // nObj.CDS_staff__c = UserInfo.getUserId(); // } else { // nObj.CDS_complete_time__c = null; // nObj.CDS_staff__c = null; // } //} System.debug(nObj.Return_Status_F__c); // 必ず最後で置く //効かないの場合がありますのでAfterでやります // nObj.Repair_Status_Text__c = nObj.Repair_Status_F__c; // nObj.Return_Status_Text__c = nObj.Return_Status_F__c; // nObj.Shipment_Status_Text__c = nObj.Shipment_Status_F__c; nObj.Canceled_Id__c = nObj.Canceled__c; //if (Trigger.isUpdate // && ((oObj.Inspection_result_after_Final__c != 'NG' // && nObj.Inspection_result_after_Final__c == 'NG' // && nObj.Inspection_result_after_NG_Final__c == '维修') // || (oObj.Inspection_result_after__c != 'NG' // && nObj.Inspection_result_after__c == 'NG' // && nObj.Inspection_result_after_NG__c == '维修') // ) //) { // nObj.Repair__c = null; //} // OLY_OCM-531 Start 搬工作流规则 // if (nObj.Check_lost_Item_F__c == '欠品' // && nObj.Loaner_Giveup_Time__c == null // && nObj.Lost_item_giveup__c == true) { // nObj.Loaner_Giveup_Time__c = Datetime.now(); // } //if (nObj.RAESD_Status__c == '排队中' // && nObj.Queue_Day_Text__c == null) { //nObj.Queue_Day_Text__c = nObj.Queue_Day__c; // nObj.Queue_Time_Text__c = nObj.Queue_Time__c; //} // OLY_OCM-531 End if (Trigger.isUpdate &&oObj.Confirm_Lost_Date__c != null && oObj.Check_lost_Item_F__c != nObj.Check_lost_Item_F__c && oObj.Check_lost_Item_F__c == '欠品') { nObj.Confirm_Lost_Date__c = null; } if (Trigger.isUpdate && (oObj.Received_NG_Content__c != nObj.Received_NG_Content__c || oObj.Received_Confirm__c != nObj.Received_Confirm__c || oObj.Picture1__c != nObj.Picture1__c || oObj.Picture2__c != nObj.Picture2__c) ) { nObj.Asset_Center_Confirm__c = null; } } } /* * Asset のQuantity更新 * changeAssetCount()方法でOut_of_wh__c、Consum_Count__c 减1 */ private void changeAsset() { if (Trigger.isUpdate && Trigger.isAfter) { if (assMap.isEmpty()) { return; } for (Consum_Apply_Equipment_Set_Detail__c nObj : newList) { if (!assMap.containsKey(nObj.Asset__c)) { continue; } Consum_Apply_Equipment_Set_Detail__c oObj = null; if (Trigger.isUpdate) { oObj = oldMap.get(nObj.Id); } Asset ass = assMap.get(nObj.Asset__c); // Abandoned_Inventory__c null -> 0 if (ass.Abandoned_Inventory__c == null) { ass.Abandoned_Inventory__c = 0; } // Abandoned_RealThing__c null -> 0 if (ass.Abandoned_RealThing__c == null) { ass.Abandoned_RealThing__c = 0; } if (ass.Confirm_Lost_Count__c == null) { ass.Confirm_Lost_Count__c = 0; } if (ass.Consumed_Count__c == null) { ass.Consumed_Count__c = 0; } if (String.isBlank(oObj.Check_lost_Item_F__c) && nObj.Check_lost_Item_F__c == 'OK') { //未入力から欠品に変更時何もしません } else if (String.isBlank(oObj.Check_lost_Item_F__c) && nObj.Check_lost_Item_F__c == '欠品' && nObj.Lost_item_giveup__c == false) { //未入力から欠品に変更時何もしません } else if (String.isBlank(oObj.Check_lost_Item_F__c) && nObj.Check_lost_Item_F__c == '欠品' && nObj.Lost_item_giveup__c == true) { //未入力から欠品放棄に変更時 放弃欠品回收(丢失)のとき 待废弃数(丢失/盘亏)加1 ass.Abandoned_Inventory__c += 1; if (oObj.Confirm_Lost_Date__c != null) { ass.Confirm_Lost_Count__c -= 1; } assUpdMap.put(ass.Id, ass); } else if (String.isBlank(oObj.Check_lost_Item_Final__c) && nObj.Check_lost_Item_Final__c == '消耗') { //未入力から消耗に変更時Quantityを-1 if(ass.Quantity != null && ass.Quantity > 0) { ass.Quantity -= 1; } if(ass.Consumed_Count__c == null){ ass.Consumed_Count__c = 0; } ass.Consumed_Count__c += 1; ass.ChangeQuantityReason__c = '消耗'; assUpdMap.put(ass.Id, ass); } else if (oObj.Check_lost_Item_F__c == 'OK' && String.isBlank(nObj.Check_lost_Item_F__c)) { //OKから空白に変更時何もしません } else if (oObj.Check_lost_Item_F__c == 'OK' && nObj.Check_lost_Item_F__c == '欠品' && nObj.Lost_item_giveup__c == false) { //OKから欠品に変更時何もしません } else if (oObj.Check_lost_Item_F__c == 'OK' && nObj.Check_lost_Item_F__c == '欠品' && nObj.Lost_item_giveup__c == true) { //OKから欠品放棄に変更時 放弃欠品回收(丢失)のとき 待废弃数(丢失/盘亏)加1 ass.Abandoned_Inventory__c += 1; if (oObj.Confirm_Lost_Date__c != null) { ass.Confirm_Lost_Count__c -= 1; } assUpdMap.put(ass.Id, ass); } else if (oObj.Check_lost_Item_F__c == 'OK' && nObj.Check_lost_Item_F__c == '消耗') { //OKから消耗に変更時Quantityを-1 ass.Quantity -= 1; ass.ChangeQuantityReason__c = '消耗'; assUpdMap.put(ass.Id, ass); } else if (oObj.Check_lost_Item_F__c == '欠品' && String.isBlank(nObj.Check_lost_Item_F__c) && oObj.Lost_item_giveup__c == false) { if (oObj.Confirm_Lost_Date__c != null) { ass.Confirm_Lost_Count__c -= 1; } assUpdMap.put(ass.Id, ass); } else if (oObj.Check_lost_Item_F__c == '欠品' && nObj.Check_lost_Item_F__c == 'OK' && oObj.Lost_item_giveup__c == false) { if (oObj.Confirm_Lost_Date__c != null) { ass.Confirm_Lost_Count__c -= 1; } assUpdMap.put(ass.Id, ass); } else if (oObj.Check_lost_Item_F__c == '欠品' && nObj.Check_lost_Item_F__c == '欠品' && oObj.Lost_item_giveup__c == false && nObj.Lost_item_giveup__c == true) { //欠品から欠品放棄に変更時 放弃欠品回收(丢失)のとき 待废弃数(丢失/盘亏)加1 ass.Abandoned_Inventory__c += 1; if (oObj.Confirm_Lost_Date__c != null) { ass.Confirm_Lost_Count__c -= 1; } assUpdMap.put(ass.Id, ass); } else if (oObj.Check_lost_Item_F__c == '欠品' && nObj.Check_lost_Item_F__c == '消耗' && oObj.Lost_item_giveup__c == false) { //欠品から消耗に変更時Quantityを-1 ass.Quantity -= 1; ass.ChangeQuantityReason__c = '消耗'; if (oObj.Confirm_Lost_Date__c != null) { ass.Confirm_Lost_Count__c -= 1; } assUpdMap.put(ass.Id, ass); } else if (oObj.Check_lost_Item_F__c == '欠品' && String.isBlank(nObj.Check_lost_Item_F__c) && oObj.Lost_item_giveup__c == true) { //欠品放棄から空白に変更時 待废弃数(丢失/盘亏)减1 ass.Abandoned_Inventory__c -= 1; ass.Out_of_wh__c += 1; ass.Rental_Count__c += 1; ass.ChangeQuantityReason__c = '欠品' + '->' + ''; assUpdMap.put(ass.Id, ass); } else if (oObj.Check_lost_Item_F__c == '欠品' && nObj.Check_lost_Item_F__c == 'OK' && oObj.Lost_item_giveup__c == true) { //欠品放棄からOKに変更時 待废弃数(丢失/盘亏)减1 ass.Abandoned_Inventory__c -= 1; ass.Out_of_wh__c += 1; ass.Rental_Count__c += 1; ass.ChangeQuantityReason__c = '欠品' + '->' + 'OK'; assUpdMap.put(ass.Id, ass); } else if (oObj.Check_lost_Item_F__c == '欠品' && nObj.Check_lost_Item_F__c == '欠品' && oObj.Lost_item_giveup__c == true && nObj.Lost_item_giveup__c == false) { //欠品放棄から欠品に変更時 待废弃数(丢失/盘亏)减1 ass.Abandoned_Inventory__c -= 1; ass.Out_of_wh__c += 1; ass.Rental_Count__c += 1; ass.ChangeQuantityReason__c = '欠品放弃 -> ' + '欠品'; assUpdMap.put(ass.Id, ass); } else if (oObj.Check_lost_Item_F__c == '欠品' && nObj.Check_lost_Item_F__c == '消耗' && oObj.Lost_item_giveup__c == true) { //欠品放棄から消耗に変更時 待废弃数(丢失/盘亏)减1 Quantityを-1 ass.Abandoned_Inventory__c -= 1; ass.Quantity -= 1; } else if (oObj.Check_lost_Item_F__c == '消耗' && String.isBlank(nObj.Check_lost_Item_F__c)) { //消耗から空白に変更時Quantityを+1 ass.Quantity += 1; ass.Out_of_wh__c += 1; ass.Rental_Count__c += 1; ass.ChangeQuantityReason__c = '消耗 -> ' + ''; assUpdMap.put(ass.Id, ass); } else if (oObj.Check_lost_Item_F__c == '消耗' && nObj.Check_lost_Item_F__c == 'OK') { //消耗から空白に変更時Quantityを+1 ass.Quantity += 1; ass.Out_of_wh__c += 1; ass.Rental_Count__c += 1; ass.ChangeQuantityReason__c = '消耗 -> ' + 'OK'; assUpdMap.put(ass.Id, ass); } else if (oObj.Check_lost_Item_F__c == '消耗' && nObj.Check_lost_Item_F__c == '欠品' && nObj.Lost_item_giveup__c == false) { //消耗から欠品に変更時Quantityを+1 ass.Quantity += 1; ass.Out_of_wh__c += 1; ass.Rental_Count__c += 1; ass.ChangeQuantityReason__c = '消耗 -> 欠品'; assUpdMap.put(ass.Id, ass); } else if (oObj.Check_lost_Item_F__c == '消耗' && nObj.Check_lost_Item_F__c == '欠品' && nObj.Lost_item_giveup__c == true) { //消耗から欠品放棄に変更時 待废弃数(丢失/盘亏)+1 Quantityを+1 ass.Abandoned_Inventory__c += 1; ass.Quantity += 1; } //废弃 if (oObj.Arrival_in_wh__c == false && nObj.Arrival_in_wh__c == true && (nObj.Inspection_result_after_NG_F__c == '废弃' //出库前检测废弃的时候也需要判断 || nObj.Inspection_result_NG__c == '废弃')) { ass.Abandoned_RealThing__c += 1; ass.ChangeQuantityReason__c = FixtureUtil.raesdStatusMap.get(FixtureUtil.HistoryStatus.Dai_Fei_Qi.ordinal()); assUpdMap.put(ass.Id, ass); } else if (oObj.Arrival_in_wh__c == true && nObj.Arrival_in_wh__c == false && (oObj.Inspection_result_after_NG_F__c == '废弃' //出库前检测废弃的时候也需要判断 || oObj.Inspection_result_NG__c == '废弃')) { ass.Abandoned_RealThing__c -= 1; ass.Out_of_wh__c += 1; ass.Rental_Count__c += 1; // ass.Freeze_sign__c = true; // OLY_OCM-689 删除冻结字段的更新 String rea = nObj.Inspection_result_after_NG_F__c == '废弃' ? '待移至报废区' : nObj.Inspection_result_after_NG_F__c; ass.ChangeQuantityReason__c = FixtureUtil.raesdStatusMap.get(FixtureUtil.HistoryStatus.Dai_Fei_Qi.ordinal()) + ' ->' + rea; assUpdMap.put(ass.Id, ass); } //待废弃 if (nObj.RAESD_Status__c == FixtureUtil.raesdStatusMap.get(FixtureUtil.HistoryStatus.Dai_Fei_Qi.ordinal()) && oObj.RAESD_Status__c != nObj.RAESD_Status__c && ass.Manage_type__c == '个体管理') { ass.Status = FixtureUtil.assetStatusMap.get(FixtureUtil.AssetStatus.Dai_Fei_Qi.ordinal()); // ass.Freeze_sign__c = true; assUpdMap.put(ass.Id, ass); } // //已消耗 // else if (nObj.Check_lost_Item_Final__c == '消耗' // && oObj.Check_lost_Item_Final__c != nObj.Check_lost_Item_Final__c // && ass.Manage_type__c == '个体管理') { // ass.Status = FixtureUtil.assetFixtureStatusMap.get(FixtureUtil.AssetFixtureStatus.Yi_Xiao_Hao.ordinal()); // assUpdMap.put(ass.Id, ass); // } //丢失 // else if (nObj.Lost_item_giveup__c == true // && oObj.Lost_item_giveup__c != nObj.Lost_item_giveup__c // && ass.Manage_type__c == '个体管理') { // ass.Status = FixtureUtil.assetFixtureStatusMap.get(FixtureUtil.AssetFixtureStatus.Diu_Shi.ordinal()); // assUpdMap.put(ass.Id, ass); // } // else if (ass.Manage_type__c == '数量管理' && assMap.containsKey(ass.Id)) { // if (ass.Quantity != null && ass.Quantity > 0) { // if (ass.Status != FixtureUtil.assetFixtureStatusMap.get(FixtureUtil.AssetFixtureStatus.Ke_Yi_Fen_Pei.ordinal())) { // ass.Status = FixtureUtil.assetFixtureStatusMap.get(FixtureUtil.AssetFixtureStatus.Ke_Yi_Fen_Pei.ordinal()); // assUpdMap.put(ass.Id, ass); // } // } // else { // if (ass.Status != FixtureUtil.assetFixtureStatusMap.get(FixtureUtil.AssetFixtureStatus.Mei_You_Ku_Cun.ordinal())) { // ass.Status = FixtureUtil.assetFixtureStatusMap.get(FixtureUtil.AssetFixtureStatus.Mei_You_Ku_Cun.ordinal()); // assUpdMap.put(ass.Id, ass); // } // } // } } } } /* * 回库确认 OFF -> ON: * 取消分配 OFF -> ON: * 放弃欠品 OFF -> ON * 已消耗 * * 清空Asset 最新备品申请借出明细 Last_Reserve_RAES_Detail__c * (nObj.Asset__c 変更しないため、changeAssetLast()でクリアできないため、ここでクリア) * * クラスの assUpdMap を更新するだけ */ // private void clearLastReserveRAESD() { // for (Consum_Apply_Equipment_Set_Detail__c nObj : newList) { // Consum_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id); // // 主体和附属品 // if (finishOrChangeAsset(Trigger.isDelete, oObj, nObj)) { // Asset ass = assMap.get(nObj.Asset__c); // if (assUpdMap.containsKey(nObj.Asset__c)) { // ass = assUpdMap.get(nObj.Asset__c); // } // // 这里 会出现 assUpdMap 有 但是 assMap 没有的情况 // if (ass == null // //分配备品有变化 (下架前) // && (oObj.Asset__c != null && oObj.Asset__c != nObj.Asset__c // && nObj.StockDown__c == false)) { // ass = new Asset(Id = oObj.Asset__c); // } // if (ass == null) { // continue; // } // // 暂时放在这里 // if (oObj.Manage_type_F__c == '个体管理') { // ass.Last_Reserve_RAES_Detail__c = null; // assUpdMap.put(ass.Id, ass); // } // } // } // } //nObj.Asset__cがある場合、変更した場合 // private void changeAssetLast() { // for (Consum_Apply_Equipment_Set_Detail__c nObj : newList) { // Consum_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id); // Asset nass = assMap.get(nObj.Asset__c); // if (assUpdMap.containsKey(nObj.Asset__c)) { // nass = assUpdMap.get(nObj.Asset__c); // } else if (String.isNotBlank(nObj.Asset__c)) { // nass = new Asset(Id = nObj.Asset__c); // } // Asset oass = assMap.get(oObj.Asset__c); // if (assUpdMap.containsKey(oObj.Asset__c)) { // oass = assUpdMap.get(oObj.Asset__c); // } else if (String.isNotBlank(oObj.Asset__c)) { // oass = new Asset(Id = oObj.Asset__c); // } // //nObj.Asset__cがある場合、変更した場合 // if (nObj.Asset__c != null && oObj.Asset__c != nObj.Asset__c // && (oObj.Manage_type_F__c == '个体管理' || nObj.Manage_type_F__c == '个体管理')) { // if (nObj.Manage_type_F__c == '个体管理') { // nass.Last_Reserve_RAES_Detail__c = nObj.Id; // assUpdMap.put(nass.Id, nass); // } // if (oObj.Manage_type_F__c == '个体管理') { // oass.Last_Reserve_RAES_Detail__c = null; // assUpdMap.put(oass.Id, oass); // } // } // } // } // 取消分配 的时候, 需要在 beforeSetValue() 里把 Asset__c 清除 //明細終了とAsset変更の時Out_of_wh__cを更新 //afterinsert, afterupdate, afterdelete から実行 private void changeAssetCount() { List nList = newList; if (Trigger.isDelete) { nList = oldList; } for (Consum_Apply_Equipment_Set_Detail__c nObj : nList) { Consum_Apply_Equipment_Set_Detail__c oObj; Asset nass = assMap.get(nObj.Asset__c); if (assUpdMap.containsKey(nObj.Asset__c)) { nass = assUpdMap.get(nObj.Asset__c); } else if (String.isNotBlank(nObj.Asset__c)) { nass = new Asset(Id = nObj.Asset__c); } if (nass != null && (nass.Out_of_wh__c == null || nass.Rental_Count__c == null || nass.Confirm_Lost_Count__c == null)) { nass.Out_of_wh__c = nObj.Out_of_wh__c; nass.Rental_Count__c = nObj.Consum_Count__c; nass.Confirm_Lost_Count__c = nObj.Confirm_Lost_Count__c; } if (Trigger.isInsert == false) { oObj = oldMap.get(nObj.Id); Asset oass = assMap.get(oObj.Asset__c); if (assUpdMap.containsKey(oObj.Asset__c)) { oass = assUpdMap.get(oObj.Asset__c); } else if (String.isNotBlank(oObj.Asset__c)) { oass = new Asset(Id = oObj.Asset__c); } //MapにAssetを新規push時値を設定 if (oass != null && (oass.Out_of_wh__c == null || oass.Rental_Count__c == null || oass.Confirm_Lost_Count__c == null)) { oass.Out_of_wh__c = oObj.Out_of_wh__c; oass.Rental_Count__c = oObj.Consum_Count__c; oass.Confirm_Lost_Count__c = oObj.Confirm_Lost_Count__c; } System.debug('111111111111111'); System.debug(Trigger.isDelete); // 最終状態及とAsset変更の場合 if (finishOrChangeAsset(Trigger.isDelete, oObj, nObj)) { System.debug('oass is ' + oass); if (oass != null) { if (oass.Out_of_wh__c != null && oass.Out_of_wh__c > 0) { oass.Out_of_wh__c = oass.Out_of_wh__c - 1; // assUpdMap.put(oass.Id, oass); System.debug('oass.Out_of_wh__c -1' + oass.Out_of_wh__c + ' Id = ' + nObj.Id); } if (nObj.DeliverySlip__c != null) { if (oass.Rental_Count__c != null && oass.Rental_Count__c > 0) { oass.Rental_Count__c = oass.Rental_Count__c - 1; } } assUpdMap.put(oass.Id, oass); } } else if (oass != null && oObj.DeliverySlip__c != null && nObj.DeliverySlip__c == null) { //发货运输单 删除的时候已借出数 -1 发货Asset__c原则不会变所以就直接用上面的oass // if (nObj.DeliverySlip__c != null) { if (oass.Rental_Count__c != null && oass.Rental_Count__c > 0) { oass.Rental_Count__c = oass.Rental_Count__c - 1; assUpdMap.put(oass.Id, oass); } // } } if (oObj.Confirm_Lost_Date__c == null && nObj.Confirm_Lost_Date__c != null) { nass.Confirm_Lost_Count__c = nass.Confirm_Lost_Count__c + 1; assUpdMap.put(nass.Id, nass); } else if (nObj.Confirm_Lost_Date__c == null && oObj.Confirm_Lost_Date__c != null && nass.Confirm_Lost_Count__c > 0) { nass.Confirm_Lost_Count__c = nass.Confirm_Lost_Count__c - 1; assUpdMap.put(nass.Id, nass); } //发货运输单设置的时候已解除数+1 if (oObj.DeliverySlip__c == null && nObj.DeliverySlip__c != null) { nass.Rental_Count__c = nass.Rental_Count__c + 1; assUpdMap.put(nass.Id, nass); } } //nObj.Asset__cがある場合、変更した場合 if (nObj.Asset__c != null && ((Trigger.isInsert && nObj.DataMigration_Flag__c == false) || (oObj != null && oObj.Asset__c != nObj.Asset__c) ) ) { if (Trigger.isInsert == false) { System.debug(oObj.Asset__c); } System.debug(nObj.Asset__c); System.debug(Trigger.isInsert); System.debug(Trigger.isBefore); if (nass.Out_of_wh__c == null) { nass.Out_of_wh__c = 0; } nass.Out_of_wh__c = nass.Out_of_wh__c + 1; System.debug('nass.Out_of_wh__c +1' + nass.Out_of_wh__c + ' Id = ' + nObj.Id); assUpdMap.put(nass.Id, nass); } } } // 同じblock の 排队レコード Queue_Number__c をrefresh // private void refreshQueueNumberByBlock() { // for (Consum_Apply_Equipment_Set_Detail__c nObj : newList) { // Consum_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id); // // 同じblock に 排队変更がある場合 // if (oObj.Cancel_Select__c == false // && String.isBlank(oObj.Fixture_Model_No_text__c) == false // && String.isBlank(oObj.Salesdepartment_before__c) == false // && String.isBlank(oObj.Product_category_text__c) == false // && String.isBlank(oObj.Equipment_Type_text__c) == false // && oObj.Queue_Number__c > 0 // // 変化を確認 // && (oObj.Cancel_Select__c != nObj.Cancel_Select__c // || oObj.Fixture_Model_No_text__c != nObj.Fixture_Model_No_text__c // || oObj.Salesdepartment_before__c != nObj.Salesdepartment_before__c // || oObj.Product_category_text__c != nObj.Product_category_text__c // || oObj.Equipment_Type_text__c != nObj.Equipment_Type_text__c // || (nObj.Queue_Number__c == 0 || nObj.Queue_Number__c == null)) // ) { // if (executeed_refreshQueueNumber.contains(nObj.Id) && executeed_refreshQueueNumber.contains(oObj.Id)) { // continue; // } // else if (executeed_refreshQueueNumber.contains(nObj.Id) == false) { // executeed_refreshQueueNumber.add(nObj.Id); // } else { // executeed_refreshQueueNumber.contains(oObj.Id) == false // executeed_refreshQueueNumber.add(oObj.Id); // } // // TODO 想定 画面からの1 record しかない // List updateList = new List(); // List refreshTargetList = [ // Select Id, Queue_Number__c // from Consum_Apply_Equipment_Set_Detail__c // where Cancel_Select__c = false // and Fixture_Model_No_text__c = :oObj.Fixture_Model_No_text__c // and Salesdepartment_before__c = :oObj.Salesdepartment_before__c // and Product_category_text__c = :oObj.Product_category_text__c // and Equipment_Type_text__c = :oObj.Equipment_Type_text__c // and Queue_Number__c > 0 // Order by Queue_Number__c]; // for (Integer i = 0; i < refreshTargetList.size(); i++) { // Consum_Apply_Equipment_Set_Detail__c refreshTarget = refreshTargetList[i]; // if (refreshTarget.Queue_Number__c != (i + 1)) { // refreshTarget.Queue_Number__c = i + 1; // executeed_refreshQueueNumber.add(refreshTarget.Id); // updateList.add(refreshTarget); // } // } // if (!updateList.isEmpty()) { update updateList; } // } // } // } // 4-XX 下架后, 出库前检测的Action一对一分配的话, 和主体一起 Cancel private void oneToOne4XX() { //主体CnacelSet Set raesdBodyCnacelSet = new Set(); Set raesdBodyNGSet = new Set(); //暂时只考虑主体NG或者取消的时候 Map raesdCancel_Remarks = new Map(); //检测NG或者本来就Cancel的不需要再更新 Set raesdIdSet = new Set(); //for (Consum_Apply_Equipment_Set_Detail__c nObj : newList) { // Consum_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id); //Set没有cancel的话都需要拷贝 //主体出库前检测NG 维修 //if (nObj.Is_Body__c == true // && nObj.Inspection_result__c == 'NG' // && oObj.Inspection_result__c != nObj.Inspection_result__c // && nObj.Inspection_result_NG__c == '维修') { // //需要重新分配一对一附属品的一览 // raesdBodyNGSet.add(nObj.Consum_Apply_Equipment_Set__c); // raesdCancel_Remarks.put(nObj.Consum_Apply_Equipment_Set__c, nObj.Loaner_cancel_Remarks__c); // raesdIdSet.add(nObj.Id); //} ////主体出库前检测NG 废弃 //else if (nObj.Is_Body__c == true // && nObj.Inspection_result__c == 'NG' // && oObj.Inspection_result__c != nObj.Inspection_result__c // && nObj.Inspection_result_NG__c == '废弃') { // //需要重新分配一对一附属品的一览 // raesdBodyNGSet.add(nObj.Consum_Apply_Equipment_Set__c); // raesdCancel_Remarks.put(nObj.Consum_Apply_Equipment_Set__c, nObj.Loaner_cancel_Remarks__c); // raesdIdSet.add(nObj.Id); //} ////附属品出库前检测NG 维修 并且是一对一分配 //else if (nObj.Is_Body__c == false // && nObj.Inspection_result__c == 'NG' // && oObj.Inspection_result__c != nObj.Inspection_result__c // && nObj.Inspection_result_NG__c == '维修' // //&& nObj.OneToOne_Flag__c == true //) { // raesdIdSet.add(nObj.Id); //} ////附属品出库前检测NG 废弃 并且是一对一分配 //else if (nObj.Is_Body__c == false // && nObj.Inspection_result__c == 'NG' // && oObj.Inspection_result__c != nObj.Inspection_result__c // && nObj.Inspection_result_NG__c == '废弃' // //&& nObj.OneToOne_Flag__c == true //) { // raesdIdSet.add(nObj.Id); //} ////OLY_OCM-152 下架后主体取消的话一对一附属品也要一起取消 //else if (String.isBlank(nObj.DeliverySlip__c) // && nObj.Is_Body__c == true // //&& nObj.StockDown__c == true // && oObj.Cancel_Select__c == false // && nObj.Cancel_Select__c == true) { // raesdIdSet.add(nObj.Id); // raesdBodyCnacelSet.add(nObj.Consum_Apply_Equipment_Set__c); // raesdCancel_Remarks.put(nObj.Consum_Apply_Equipment_Set__c, nObj.Loaner_cancel_Remarks__c); //} //} if (raesdBodyNGSet.isEmpty() && raesdBodyCnacelSet.isEmpty()) { return; } List raesds = [ Select Id , UniqueKey__c , Consum_Apply_Equipment_Set__c , Consum_Apply__c , Fixture_Set_Detail__c From Consum_Apply_Equipment_Set_Detail__c //主体出库前检测NG一览的所有一对一分配的明细 Where (Consum_Apply_Equipment_Set__c = :raesdBodyNGSet //下架后主体取消一对一附属品也要一起取消 OR Consum_Apply_Equipment_Set__c = :raesdBodyCnacelSet) //AND OneToOne_Flag__c = true //和主体一起检测NG的不再更新 AND Id !=: raesdIdSet]; List raesdList = new List(); for (Consum_Apply_Equipment_Set_Detail__c raesd : raesds) { raesd.OnStock_By_Cancel__c = true; raesd.Cancel_Select__c = true; // OLY_OCM-163#comment-20120592 通过取消日判断 -》 更新的时候before设置 //raesd.Cancel_Date__c = Date.today(); raesd.Cancel_Reason__c = '重新分配'; //主体出库前检查NG的话取消备注回自动设置为出库前检查NG raesd.Loaner_cancel_Remarks__c = raesdCancel_Remarks.get(raesd.Consum_Apply_Equipment_Set__c); // } raesdList.add(raesd); } System.debug('raesdList size' + raesdList.size()); if (!raesdList.isEmpty()) { update raesdList; } } //一览单位取消后的拷贝在一览的Handler里面做 // 因为cancel是主体的话First应开始拷贝出来的主体所以First的更新逻辑移动到cancelcopy private void cancelCopy() { List raesdList = new List(); List raesdListup = new List(); Map raesMap = new Map(); for (Consum_Apply_Equipment_Set_Detail__c nObj : newList) { Consum_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id); //Set没有cancel的话都需要拷贝 //Cancel_Select__c はfalseからtrueに変更なのでなのでtrigger二回はしても実行するのは1回だけ if (nObj.Set_Cancel_Select__c == false && (oObj.Cancel_Select__c == false && nObj.Cancel_Select__c == true) && nObj.StockDown__c == true && nObj.Cancel_Reason__c == '重新分配') { Consum_Apply_Equipment_Set_Detail__c craesd = new Consum_Apply_Equipment_Set_Detail__c(); craesd.Consum_Apply_Equipment_Set__c = nObj.Consum_Apply_Equipment_Set__c; craesd.Consum_Apply__c = nObj.Consum_Apply__c; craesd.Fixture_Set_Detail__c = nObj.Fixture_Set_Detail__c; craesd.Fixture_Model_No_text__c = nObj.FSD_Fixture_Model_No__c; craesd.Fixture_Name_text__c = nObj.FSD_Name_CHN__c; craesd.IndexFromUniqueKey_Text__c = nObj.IndexFromUniqueKey_Text__c; craesd.Canceled__c = nObj.Id; craesd.FSD_Id__c = nObj.FSD_Id__c; //craesd.FSD_Is_Optional__c = nObj.FSD_Is_Optional_F__c; //craesd.FSD_Is_OneToOne__c = nObj.FSD_Is_OneToOne_F__c; craesd.FSD_Name_CHN__c = nObj.FSD_Name_CHN__c; //craesd.FSD_OneToOneAccessory_Cnt__c = nObj.FSD_OneToOneAccessory_Cnt_F__c; craesd.FSD_Fixture_Model_No__c = nObj.FSD_Fixture_Model_No__c; if (nObj.DataMigration_Flag__c == false && (!Trigger.isUpdate || String.isNotBlank(nObj.Asset__c))) { craesd.Consum_Num__c = nObj.Consum_Num__c; craesd.IndexFromUniqueKey__c = nObj.IndexFromUniqueKey__c; craesd.Degree_Of_Importance__c = nObj.Degree_Of_Importance__c; } //cancel重新分配的不算追加附属品 272チケット craesd.Create_State__c = 0; raesdList.add(craesd); } // 如果是主体 cancel的话First应该是拷贝出来的主体 // if ((oObj.Cancel_Select__c == false && nObj.Cancel_Select__c == true) // && nObj.Is_First_RAESD_F__c == true && nObj.Set_Cancel_Select__c == false // && nObj.DataMigration_Flag__c == false && (!Trigger.isUpdate || String.isNotBlank(nObj.Fixture_Set_Id__c))) { // Consum_Apply_Equipment_Set__c raes = new Consum_Apply_Equipment_Set__c( // Id = nObj.Consum_Apply_Equipment_Set__c, // First_RAESD__c = null); // raesMap.put(nObj.Consum_Apply_Equipment_Set__c, raes); // } } //没下架的字段清空在before里面做 if (!raesdList.isEmpty()) { insert raesdList; } if (!raesMap.isEmpty()) { List raess = [Select Id, Consum_Apply_Equipment_Set__c From Consum_Apply_Equipment_Set_Detail__c Where Consum_Apply_Equipment_Set__c = :raesMap.keySet() and Cancel_Select__c = False order by Consum_Apply_Equipment_Set__c //, Fixture_Set_Detail__r.SortInt__c ASC nulls last]; System.debug(raess); Id raesId = null; // 一件目をFirst_RAESD__cに設定 for (Consum_Apply_Equipment_Set_Detail__c raes : raess) { if (raesId != raes.Consum_Apply_Equipment_Set__c) { raesMap.get(raes.Consum_Apply_Equipment_Set__c).First_RAESD__c = raes.Id; raesId = raes.Consum_Apply_Equipment_Set__c; } } } //一览First更新 if (!raesMap.isEmpty()) { update raesMap.values(); } } // afterdeleteのみ private void deleteReFirst() { Map raesMap = new Map(); for (Consum_Apply_Equipment_Set_Detail__c oObj : oldList) { if (oObj.Is_First_RAESD_F__c == true) { Consum_Apply_Equipment_Set__c raes = new Consum_Apply_Equipment_Set__c( Id = oObj.Consum_Apply_Equipment_Set__c, First_RAESD__c = null); raesMap.put(oObj.Consum_Apply_Equipment_Set__c, raes); } } //修改一览的FirstMap if (raesMap.isEmpty()) { return; } if (!raesMap.isEmpty()) { List raess = [Select Id, Consum_Apply_Equipment_Set__c From Consum_Apply_Equipment_Set_Detail__c Where Consum_Apply_Equipment_Set__c = :raesMap.keySet() and Cancel_Select__c = False //一覧も削除したら更新しません and IsDeleted = false // RAESD_SortInt_F__c -> IndexFromUniqueKey_Text__c(备品配套明细.SortInt__c) // 1应该是主体 order by Consum_Apply_Equipment_Set__c, IndexFromUniqueKey_Text__c ASC nulls last]; Id raesId = null; // 一件目をFirst_RAESD__cに設定 for (Consum_Apply_Equipment_Set_Detail__c raes : raess) { if (raesId != raes.Consum_Apply_Equipment_Set__c) { raesMap.get(raes.Consum_Apply_Equipment_Set__c).First_RAESD__c = raes.Id; raesId = raes.Consum_Apply_Equipment_Set__c; } } } //一览First更新 if (!raesMap.isEmpty()) { update raesMap.values(); } } // 最終状態及びAsset変更 private Boolean finishOrChangeAsset(Boolean isDelete, Consum_Apply_Equipment_Set_Detail__c oObj, Consum_Apply_Equipment_Set_Detail__c nObj) { Boolean rtn = false; if (isDelete && updatedSet.contains(oObj.Id) == false) { updatedSet.add(oObj.Id); // oObj を確認する、oldで もともと finishのもの、falseを返す、 rtn = !( //回库确认 (oObj.Arrival_in_wh__c) //取消分配, (下架后, 原则需要上架, 所以不能单纯的断开) || (oObj.Cancel_Select__c == true && oObj.StockDown__c == false ) //下架前, 分配备品有变化 (变成别的配套, or 变 null) || (oObj.Asset__c == null && oObj.StockDown__c == false ) //取消分配, (下架后, 原则需要上架, 所以不能单纯的断开) || (oObj.Cancel_Select__c == true && nObj.StockDown__c == false ) //放弃欠品 //|| (oObj.Lost_item_giveup__c == true) //已消耗 //|| (oObj.Check_lost_Item_F__c == '消耗') ); } else { rtn = ( //回库确认 (!oObj.Arrival_in_wh__c && nObj.Arrival_in_wh__c) //取消分配, (下架后, 原则需要上架, 所以不能单纯的断开) || (oObj.Cancel_Select__c == false && nObj.Cancel_Select__c == true && nObj.StockDown__c == false ) //下架前, 分配备品有变化 (变成别的配套, or 变 null) || (oObj.Asset__c != null && oObj.Asset__c != nObj.Asset__c && nObj.StockDown__c == false ) //取消分配, (下架后, 原则需要上架, 所以不能单纯的断开) || (oObj.Cancel_Select__c == false && nObj.Cancel_Select__c == true && nObj.StockDown__c == false ) //放弃欠品 || (oObj.Lost_item_giveup__c == false && nObj.Lost_item_giveup__c == true && oObj.Check_lost_Item_F__c != '消耗') //已消耗 || (oObj.Check_lost_Item_F__c != '消耗' && nObj.Check_lost_Item_F__c == '消耗' && oObj.Lost_item_giveup__c == false) ); } return rtn; } //before 数式の値がnullになる可能性がありますのでここでも一回チェックします private void formulaToTextCheck() { List raesds = new List(); for (Consum_Apply_Equipment_Set_Detail__c nObj : newList) { //明细状态没有修理完毕所以修理完毕的时候不拷贝状态到Text字段 if (//(nObj.Repair_Status_Text__c != nObj.Repair_Status_F__c // && nObj.Repair_Status_F__c != '修理完毕') || nObj.Return_Status_Text__c != nObj.Return_Status_F__c || nObj.Shipment_Status_Text__c != nObj.Shipment_Status_F__c //|| (nObj.ApplyPersonAppended__c != nObj.ApplyPersonAppended_F__c && Trigger.isInsert) ) { Consum_Apply_Equipment_Set_Detail__c raesd = new Consum_Apply_Equipment_Set_Detail__c(Id = nObj.Id); //明细状态没有修理完毕所以修理完毕的时候不拷贝状态到Text字段 //if (nObj.Repair_Status_F__c != '修理完毕') { // raesd.Repair_Status_Text__c = nObj.Repair_Status_F__c; //} raesd.Return_Status_Text__c = nObj.Return_Status_F__c; raesd.Shipment_Status_Text__c = nObj.Shipment_Status_F__c; //if (Trigger.isInsert) { // raesd.ApplyPersonAppended__c = nObj.ApplyPersonAppended_F__c; //} raesds.add(raesd); } } if (!raesds.isEmpty()) { update raesds; } } private void reQueueNumber() { Map> queueRaesdMap = new Map>(); String wher = ''; for (Consum_Apply_Equipment_Set_Detail__c oObj : oldList) { Consum_Apply_Equipment_Set_Detail__c nObj; if (Trigger.isUpdate) { nObj = newMap.get(oObj.Id); } //if ((Trigger.isUpdate && (oObj.Queue_Number__c != 0 && nObj.Queue_Number__c == 0 // || (!oObj.Cancel_Select__c && nObj.Cancel_Select__c ) // || (String.isBlank(oObj.Fixture_Model_No_text__c) == false // // #OLY_OCM-654 因为是排队的逻辑。所以不需要删除。因为只有主体才能排队 Start // && String.isBlank(oObj.Salesdepartment_before__c) == false // && String.isBlank(oObj.Product_category_text__c) == false // && String.isBlank(oObj.Equipment_Type_text__c) == false // // #OLY_OCM-654 因为是排队的逻辑。所以不需要删除。因为只有主体才能排队 End // && oObj.Queue_Number__c > 0 // // 変化を確認 // && (oObj.Fixture_Model_No_text__c != nObj.Fixture_Model_No_text__c // // #OLY_OCM-654 因为是排队的逻辑。所以不需要删除。因为只有主体才能排队 Start // || oObj.Salesdepartment_before__c != nObj.Salesdepartment_before__c // || oObj.Product_category_text__c != nObj.Product_category_text__c // || oObj.Equipment_Type_text__c != nObj.Equipment_Type_text__c)))) // // #OLY_OCM-654 因为是排队的逻辑。所以不需要删除。因为只有主体才能排队 End // || (Trigger.isDelete && oObj.Queue_Number__c != 0 && oObj.Queue_Number__c != null)) { // if (String.isBlank(oObj.Fixture_Model_No_text__c)) { // if (Trigger.isUpdate) { // //更新时用nObj // if (String.isNotBlank(nObj.Asset__c)) nObj.addError('备品配套型号不能为空'); // } else { // //因为上面的If文已经判断了只有更新和删除所以这里不再判断删除 // //删除时用oObj // oObj.addError(oObj.Id + '(排队):备品配套明细型号不能为空'); // } // // 不continue的话下面使用的时候会报NullOoint // continue; // } // String key = oObj.Fixture_Model_No_text__c; // // 式の左と右 ともに Fixture_Model_No_text__c なので、問題ないです。 // wher += ' ( Fixture_Model_No_text__c = \'' + String.escapeSingleQuotes(oObj.Fixture_Model_No_text__c) + '\''; // // if (String.isNotBlank(oObj.Internal_asset_location_before__c)) { // // wher += ' and Internal_asset_location_before__c =\'' + String.escapeSingleQuotes(oObj.Internal_asset_location_before__c) + '\''; // // } // // #OLY_OCM-654 这里是排队的逻辑。只有主体才能排队。所以是不删除的 Start // if (String.isNotBlank(oObj.Salesdepartment_before__c)) { // wher += ' and Salesdepartment_before__c =\'' + String.escapeSingleQuotes(oObj.Salesdepartment_before__c) + '\''; // } // if (String.isNotBlank(oObj.Product_category_text__c)) { // wher += ' and Product_category_text__c =\'' + String.escapeSingleQuotes(oObj.Product_category_text__c) + '\''; // } // if (String.isNotBlank(oObj.Equipment_Type_text__c)) { // wher += ' and Equipment_Type_text__c =\'' + String.escapeSingleQuotes(oObj.Equipment_Type_text__c) + '\''; // } // // #OLY_OCM-654 这里是排队的逻辑。只有主体才能排队。所以是不删除的 End // wher += ') OR'; //} } if (String.isBlank(wher)) { return; } wher = wher.removeEnd('OR'); wher = '(' + wher + ')'; //String soql = 'Select Id, Queue_Number__c, Fixture_Model_No_text__c, Internal_asset_location_before__c, Product_category_text__c,' // + ' Equipment_Type_text__c, Salesdepartment_before__c' // + ' From Consum_Apply_Equipment_Set_Detail__c ' // + ' Where Queue_Number__c > 0 AND Cancel_Select__c = false' // + ' AND Queue_Number__c != null AND ' // + wher // + ' order by Queue_Number__c ASC'; //System.debug(soql); //List queueRaesds = Database.query(soql); //System.debug(queueRaesds.size()); //for (Consum_Apply_Equipment_Set_Detail__c raesd : queueRaesds) { // String key = raesd.Fixture_Model_No_text__c; // // if (String.isNotBlank(raesd.Internal_asset_location_before__c)) { // // key += '_' + raesd.Internal_asset_location_before__c; // // } // // #OLY_OCM-654 这里是排队的逻辑。只有主体才能排队。所以是不删除的 Start // if (String.isNotBlank(raesd.Salesdepartment_before__c)) { // key += '_' + raesd.Salesdepartment_before__c; // } // if (String.isNotBlank(raesd.Product_category_text__c)) { // key += '_' + raesd.Product_category_text__c; // } // if (String.isNotBlank(raesd.Equipment_Type_text__c)) { // key += '_' + raesd.Equipment_Type_text__c; // } // // #OLY_OCM-654 这里是排队的逻辑。只有主体才能排队。所以是不删除的 End // if (!queueRaesdMap.containsKey(key)) { // queueRaesdMap.put(key, new List()); // } // queueRaesdMap.get(key).add(raesd); //} List raesdList = new List(); for (String key : queueRaesdMap.keySet()) { List raesds = queueRaesdMap.get(key); for (Integer i = 1; i <= raesds.size(); i++) { Consum_Apply_Equipment_Set_Detail__c raesd = raesds[i-1]; //if (raesd.Queue_Number__c != i) { // raesd.Queue_Number__c = i; // raesdList.add(raesd); //} } } if (!raesdList.isEmpty()) { update raesdList; } } //申请者收回NG后明细回寄时的邮件回寄单内容设置 //只在Afterupdate里面调用 private void receivedConfirmNGSetReturnDeliverySlipText() { //一览Id和对应的回寄发货单ID Map raesRDSMap = new Map(); Map raesDateMap = new Map(); for (Consum_Apply_Equipment_Set_Detail__c nObj : newList) { Consum_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id); //申请者收货NG的明细 if (nObj.Received_Confirm__c == 'NG') { //回寄运输单赋值 if (String.isBlank(oObj.Return_DeliverySlip__c) && String.isNotBlank(nObj.Return_DeliverySlip__c)) { //因为是以为一览为单位,所以只有一条回寄单 //申请者收货NG的明细拆成两个回寄单回寄的情况暂时不考虑(应该没有这种情况) if (!raesRDSMap.containsKey(nObj.Consum_Apply_Equipment_Set__c)) { raesRDSMap.put(nObj.Consum_Apply_Equipment_Set__c, nObj.Return_DeliverySlip__c); raesDateMap.put(nObj.Consum_Apply_Equipment_Set__c, nObj.Asset_return_time__c.format()); } } } } if (raesRDSMap.isEmpty()) { return; } //NG_Return_DeliverySlip__c为空的一览才做邮件发送 Map raessMap = new Map([Select Id From Consum_Apply_Equipment_Set__c WHERE Id =: raesRDSMap.keySet() AND NG_Return_DeliverySlip__c = null]); Map fdss = new Map([Select Id, Name, Combine_Pack__c, Wh_Staff__c, DeliveryCompany__c, Shippment_loaner_time__c, Distributor_method__c, DeliveryCompany_SlipNo__c, DeliveryType__c From FixtureDeliverySlip__c Where Id =: raesRDSMap.values()]); System.debug('fdss is ' + fdss); List raess = new List(); for (Id key: raesRDSMap.keySet()) { //当NG_Return_DeliverySlip__c不为空时不发邮件 if (!raessMap.containsKey(key)) { continue; } FixtureDeliverySlip__c fds = fdss.get(raesRDSMap.get(key)); String message = '发货-发货运输单号:' + fds.Name + '
' + '发货-物流公司:' + fds.DeliveryCompany__c + '
' + '发货-运输方式:' + fds.Distributor_method__c + '
' + '物流提货时间:' + raesDateMap.get(key) + '
'; raess.add(new Consum_Apply_Equipment_Set__c(Id = key, NG_Return_DeliverySlip_Information__c = message, NG_Return_DeliverySlip__c = fds.Id)); } if (!raess.isEmpty()) { update raess; } } //设置申请书的回寄通知文本 @future private static void setRequestAsset_return_Text(Set raesdIdSet) { List raesdList = [SELECT Id, Consum_Apply__c, Return_DeliverySlip__c, Consum_Apply_Equipment_Set__c, Fixture_Model_No_text__c, //Lost_Item_return__c, NoItemReturn__c, Consum_Apply__r.Name, Consum_Apply__r.Id, Return_DeliverySlip__r.Id, Return_DeliverySlip__r.Name, Return_DeliverySlip__r.DeliveryCompany__c, Return_DeliverySlip__r.Distributor_method__c, Return_DeliverySlip__r.Shippment_loaner_time__c FROM Consum_Apply_Equipment_Set_Detail__c WHERE Id = :raesdIdSet // 回寄通知只发送有链接回寄单的明细信息 AND Return_DeliverySlip__c != null ORDER BY Consum_Apply__c, Consum_Apply_Equipment_Set__c, Name]; // 收集回寄明细 {raesId -> raesdList} Map> raesdListMap = new Map>(); Map return_DeliverySlipIdMap = new Map(); Map return_DeliverySlipMap = new Map(); for (Consum_Apply_Equipment_Set_Detail__c raesd : raesdList) { if (!raesdListMap.containsKey(raesd.Consum_Apply_Equipment_Set__c)) { raesdListMap.put(raesd.Consum_Apply_Equipment_Set__c, new List()); } return_DeliverySlipIdMap.put(raesd.Return_DeliverySlip__c, raesd.Consum_Apply__r); raesdListMap.get(raesd.Consum_Apply_Equipment_Set__c).add(raesd); /* --------- 设置运输单Map Start --------- */ if (return_DeliverySlipMap.containsKey(raesd.Consum_Apply__c) == false) { FixtureDeliverySlip__c fds = raesd.Return_DeliverySlip__r; // 无实物回寄的回寄单不显示物流单信息 if (fds.Name == raesd.Consum_Apply__r.Name + '_Dummy') { continue; } return_DeliverySlipMap.put(raesd.Consum_Apply__c, fds); } /* --------- 设置运输单Map End --------- */ } if (raesdListMap.isEmpty()) { return; } // 检索回寄的一览 {raId -> raesList} Map> raesListMap = new Map>(); List raesList = [SELECT Id, //Loaner_code_F__c, Consum_Apply__c, //Asset_return_Status__c, Received_Confirm__c FROM Consum_Apply_Equipment_Set__c WHERE Id =: raesdListMap.keySet()]; for (Consum_Apply_Equipment_Set__c raes : raesList) { if (!raesListMap.containsKey(raes.Consum_Apply__c)) { raesListMap.put(raes.Consum_Apply__c, new List()); } raes.recalculateFormulas(); raesListMap.get(raes.Consum_Apply__c).add(raes); } List raList = new List(); List raList2 = new List(); String message = ''; Integer i = 0; // 申请书单位都是欠品回寄的明细 Boolean allLostItemReturnFlag = true; // 查看所有的申请书 for (Id raId : raesListMap.keySet()) { allLostItemReturnFlag = true; i = 0; // 查看申请书下面的所有一览 for (Consum_Apply_Equipment_Set__c raes : raesListMap.get(raId)) { i++; //message += '配套' + i + ':' + raes.Loaner_code_F__c; String message2 = '
'; Boolean haveLost_Item_return = false; // 查看一览下的所有明细 for (Consum_Apply_Equipment_Set_Detail__c nObj : raesdListMap.get(raes.Id)) { message2 += '    ' + nObj.Fixture_Model_No_text__c; //if (nObj.Lost_Item_return__c) { // message2 += ' (欠品归还)'; // haveLost_Item_return = true; //} //else { // // 如果有一条不是欠品回寄那么就不显示欠品回寄 // allLostItemReturnFlag = false; //} if (nObj.NoItemReturn__c == true) { message2 += ' (无实物归还)'; } // if (nObj.Received_Confirm__c == 'NG') { // message += '(NG归还)'; // } message2 += '
'; } if (haveLost_Item_return == false && raes.Received_Confirm__c == 'NG') { message += ' (NG归还)'; } message += message2; } message += '
'; FixtureDeliverySlip__c fds = new FixtureDeliverySlip__c(); if (return_DeliverySlipMap.containsKey(raId)) { fds = return_DeliverySlipMap.get(raId); } message += '回寄-发货运输单号:' + (String.isBlank(fds.Name)? '' : fds.Name) + '
'; message += '回寄-物流公司:' + (String.isBlank(fds.DeliveryCompany__c)? '' : fds.DeliveryCompany__c) + '
'; message += '回寄-运输方式:' + (String.isBlank(fds.Distributor_method__c)? '' : fds.Distributor_method__c) + '
'; String sdate = fds.Shippment_loaner_time__c == null ? '' : fds.Shippment_loaner_time__c.format(); message += '物流提货时间:' + sdate + '
'; if (String.isNotBlank(message)) { raList.add(new Consum_Apply__c(Id = raId, Asset_return_Text__c = message, Lost_item_Return_Flag__c = allLostItemReturnFlag)); raList2.add(new Consum_Apply__c(Id = raId, Asset_return_Text__c = null)); message = ''; } } if (raList.size() > 0) { FixtureUtil.withoutUpdate(raList2); FixtureUtil.withoutUpdate(raList); } } private void setAssginPerson(Set raId) { List raList = [select Id, Assign_Person__c from Consum_Apply__c where Id in :raId]; List updateList = new List(); for (Consum_Apply__c ra : raList) { if (ra.Assign_Person__c == null) { ra.Assign_Person__c = UserInfo.getUserId(); updateList.add(ra); } } if (updateList.size() > 0) update updateList; } private void changeAssetConsumable_Guaranteen_end() { for (Consum_Apply_Equipment_Set_Detail__c nObj : newList) { Consum_Apply_Equipment_Set_Detail__c oObj; if (trigger.isUpdate) { oObj = oldMap.get(nObj.Id); } if (oObj.Shippment_loaner_time__c == null && nObj.Shippment_loaner_time__c != null && nObj.NeedSet_Consumable_Guaranteen_end_F__c == true) { Asset nass = assMap.get(nObj.Asset__c); if (assUpdMap.containsKey(nObj.Asset__c)) { nass = assUpdMap.get(nObj.Asset__c); } else if (String.isNotBlank(nObj.Asset__c)) { nass = new Asset(Id = nObj.Asset__c); } Datetime dt = nObj.Shippment_loaner_time__c.addYears(1); nass.Consumable_Guaranteen_end__c = Date.newinstance(dT.year(), dT.month(), dT.day()); nass.HaveSet_Consumable_Guaranteen_end__c = true; } } } @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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; 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++; i++; i++; i++; } }