From af7b716a60d889acea95560abba0e46eee008b8f Mon Sep 17 00:00:00 2001
From: buli <137736985@qq.com>
Date: 星期三, 05 七月 2023 13:54:50 +0800
Subject: [PATCH] backup0705
---
force-app/main/default/classes/AssetHandler.cls | 2157 ++++++++++++++++++++++++++++++++++++++--------------------
1 files changed, 1,403 insertions(+), 754 deletions(-)
diff --git a/force-app/main/default/classes/AssetHandler.cls b/force-app/main/default/classes/AssetHandler.cls
index 7d9e01b..18a09ec 100644
--- a/force-app/main/default/classes/AssetHandler.cls
+++ b/force-app/main/default/classes/AssetHandler.cls
@@ -1,81 +1,577 @@
public without sharing class AssetHandler extends Oly_TriggerHandler {
+ public static Map<String, List<Rental_Apply_Equipment_Set_Detail__c>> queueRaesdMap;
+ private Map<Id, Asset> newMap;
+ private Map<Id, Asset> oldMap;
+ private List<Asset> newList;
+ private List<Asset> oldList;
+ private static final Map<String, Schema.RecordTypeInfo> DEVELOPERNAMEMAP = Schema.SObjectType.Asset.getRecordTypeInfosByDeveloperName(); // 20230306 ljh add
+ @TestVisible
+ private static Set<String> testTargetDepts;
+ @TestVisible
+ private static Id Account_Asset_Id;
+ public static Boolean disabled = false;
- public static Map<String , List<Rental_Apply_Equipment_Set_Detail__c>> queueRaesdMap;
- private Map<Id, Asset> newMap;
- private Map<Id, Asset> oldMap;
- private List<Asset> newList;
- private List<Asset> oldList;
- @TestVisible private static Set<String> testTargetDepts;
- @TestVisible private static Id Account_Asset_Id;
- public static Boolean disabled = false;
+ public AssetHandler() {
+ this.newMap = (Map<Id, Asset>) Trigger.newMap;
+ this.oldMap = (Map<Id, Asset>) Trigger.oldMap;
+ this.newList = (List<Asset>) Trigger.new;
+ this.oldList = (List<Asset>) Trigger.old;
- public AssetHandler() {
- this.newMap = (Map<Id, Asset>) Trigger.newMap;
- this.oldMap = (Map<Id, Asset>) Trigger.oldMap;
- this.newList = (List<Asset>) Trigger.new;
- this.oldList = (List<Asset>) Trigger.old;
+ Integer i = 0;
+ }
+
+ protected override void beforeInsert() {
+ beforeSetValue();
+ //鍔ㄦ�佹洿鏂� Asset鐨� AccountId鐨� Logic
+ beforeSetAccountId();
+
+ //绗竴娆′笉鍔犲彉鏇寸殑鏃跺�欎笉鐭ラ亾绗竴娆℃槸澶氬皯
+ updateChangeQuantityReason();
+
+ workflowCode();
+ }
+ protected override void beforeUpdate() {
+ if (!disabled) {
+ beforeSetValue();
+ //鍔ㄦ�佹洿鏂� Asset鐨� AccountId鐨� Logic
+ beforeSetAccountId();
+
+ updateChangeQuantityReason();
+
+ // 20230309 gzw 浼樺寲 娉ㄩ噴浠g爜
+
+ // 铏氭嫙缁翠慨淇濅慨鍚堝悓淇濅慨寮�濮嬬粨鏉熸棩鏈熸洿鏂�
+ // updateMaintenance_Contract_Asset();
+
+ // 20230309 gzw 浼樺寲 娉ㄩ噴浠g爜
+
+ updateRentalCount();
+
+ workflowCode();
}
+ }
- protected override void beforeInsert() {
- beforeSetValue();
- //鍔ㄦ�佹洿鏂� Asset鐨� AccountId鐨� Logic
- beforeSetAccountId();
+ protected override void afterInsert() {
+ //鏈夋柊鐨凙sset鐨勬椂鍊� 鏆傚畾鍒嗛厤
+ queueRedistribution();
+ }
- //绗竴娆′笉鍔犲彉鏇寸殑鏃跺�欎笉鐭ラ亾绗竴娆℃槸澶氬皯
- updateChangeQuantityReason();
+ protected override void afterUpdate() {
+ if (!disabled) {
+ mainAssetUpdateed_OneToOneRecord();
+ // 宸茬粡鏀硅繘 Must_Input_ChangeQuantityReason 鐨� valida before鍙互瀹屾垚 ChangeQuantityReason__c = ''
+ ////鍏ュ姏瑕忓墖銇倛銇c仸before銈儶銈€仹銇嶃伨銇涖倱,
+ cleanChangeQuantityReason();
+ // 娓呯悊瀛楁銆屽緟搴熷純鏁帮紙涓㈠け/鐩樹簭锛変慨鏀圭悊鐢便��
+ cleanGiveupReturnReason();
+ //褰撲富浣撳弬鐓х殑Asset鐨凩ast鏂紑鐨勬椂鍊欓噸鏂板鎵炬殏瀹氬垎閰�
+ queueRedistribution();
+ // before 銇с伅鏁板紡闋呯洰銇宯ull銇牬鍚堛亴銇傘倞銇俱仚
+ formulaToTextCheck();
+ // check涓�瀵逛竴link琛�
+ checkOneToOneLink();
+ // 铏氭嫙缁翠慨淇濅慨鍚堝悓淇濅慨寮�濮嬬粨鏉熸棩鏈熸洿鏂�
+ updateMaintenance_Contract_Asset();
}
- protected override void beforeUpdate() {
- if(!disabled){
- beforeSetValue();
- //鍔ㄦ�佹洿鏂� Asset鐨� AccountId鐨� Logic
- beforeSetAccountId();
+ }
- updateChangeQuantityReason();
-
- // 铏氭嫙缁翠慨淇濅慨鍚堝悓淇濅慨寮�濮嬬粨鏉熸棩鏈熸洿鏂�
- updateMaintenance_Contract_Asset();
-
- updateRentalCount();
+ //20230309 sx 淇濇湁璁惧workflow浠g爜鍖� start
+ private void workflowCode() {
+ /*List<Id> accIds = new List<Id>();
+ List<Id> productIds = new List<Id>();
+ List<Id> hospitalIds = new List<Id>();
+ for(Asset nObj : newList) {
+ accIds.add(nObj.Account.Id);
+ productIds.add(nObj.Product2.Id);
+ hospitalIds.add(nObj.Hospital__c);
}
- }
+ //鏌ユ壘瀹㈡埛List
+ Map<Id, Account> accMap = new Map<Id, Account>([SELECT Id, Name, Management_Code__c from Account where Id in :accIds]);
+ Map<Id, Product2> productMap = new Map<Id, Product2>([SELECT Id, Name, RecordTypeId, RecordType.Name, Serial_Lot_No__c ,ProductCode from Product2 where Id in :productIds]);
+ Map<Id, Account> hosMap = new Map<Id, Account>([SELECT Id, Name, RecordType.Name from Account where id in :hospitalIds]);
- protected override void afterInsert() {
- //鏈夋柊鐨凙sset鐨勬椂鍊� 鏆傚畾鍒嗛厤
- queueRedistribution();
- }
-
- protected override void afterUpdate() {
- if(!disabled){
- mainAssetUpdateed_OneToOneRecord();
- // 宸茬粡鏀硅繘 Must_Input_ChangeQuantityReason 鐨� valida before鍙互瀹屾垚 ChangeQuantityReason__c = ''
- ////鍏ュ姏瑕忓墖銇倛銇c仸before銈儶銈€仹銇嶃伨銇涖倱,
- cleanChangeQuantityReason();
- // 娓呯悊瀛楁銆屽緟搴熷純鏁帮紙涓㈠け/鐩樹簭锛変慨鏀圭悊鐢便��
- cleanGiveupReturnReason();
- //褰撲富浣撳弬鐓х殑Asset鐨凩ast鏂紑鐨勬椂鍊欓噸鏂板鎵炬殏瀹氬垎閰�
- queueRedistribution();
- // before 銇с伅鏁板紡闋呯洰銇宯ull銇牬鍚堛亴銇傘倞銇俱仚
- formulaToTextCheck();
- // check涓�瀵逛竴link琛�
- checkOneToOneLink();
- // 铏氭嫙缁翠慨淇濅慨鍚堝悓淇濅慨寮�濮嬬粨鏉熸棩鏈熸洿鏂�
- updateMaintenance_Contract_Asset();
- }
- }
- // 鍊熷嚭鏄庣粏鏇存柊鍊熷嚭_鍒嗛厤_鏁�(Sys)鍜屽凡鍊熷嚭鏁�(Sys)
- private void updateRentalCount() {
- Set<Id> idSet = new Set<Id>();
- for(Id assId : this.newMap.keySet()) {
- if(this.newMap.get(assId).AssetManageConfirm__c &&
- this.newMap.get(assId).Account_Management_Code__c != System.Label.Account_Asset_FJZ ) {
- idSet.add(assId);
- this.newMap.get(assId).Out_of_wh_Sys__c = 0;
- this.newMap.get(assId).Rental_Count_Sys__c = 0;
+ Map<Id, Account> acc_assMap = new Map<Id, Account>();
+ Map<Id, Product2> pro_proMap = new Map<Id, Product2>();
+ Map<Id, Account> hos_assMap = new Map<Id, Account>();
+ for(Asset nObj : newList){
+ if(accMap.containsKey(nObj.Account.Id)) {
+ acc_assMap.put(nObj.Id, accMap.get(nObj.Account.Id));
}
+ if(productMap.containsKey(nObj.Product2.Id)) {
+ pro_proMap.put(nObj.Id, productMap.get(nObj.Product2.Id));
+ }
+ if(hosMap.containsKey(nObj.Hospital__c)) {
+ hos_assMap.put(nObj.Id, hosMap.get(nObj.Id));
+ }
+ }*/
+ Date today = Date.today();
+
+ for (Asset nObj : newList) {
+ //淇濇湁璁惧HPID鏂囨湰鍖�
+ nObj.Asset_Year_Txt__c = nObj.Asset_Year__c;
+ nObj.HP_ID_Text__c = nObj.HP_Id__c;
+ nObj.Gurantee_End_day1__c = nObj.Gurantee_End_day__c;
+
+ //瑕嗙洊璁惧鐨勫彲閫夊璞℃枃鏈寲
+ if (
+ Trigger.isInsert ||
+ (Trigger.isUpdate &&
+ nObj.Posting_Date__c != oldMap.get(nObj.Id).Posting_Date__c)
+ ) {
+ if (
+ String.isBlank(nObj.IF_Coverage_Target_Asset__c) ||
+ '0'.equals(nObj.IF_Coverage_Target_Asset__c)
+ ) {
+ nObj.IF_Coverage_Target_Asset__c =
+ nObj.IF_Coverage_Target_Asset_FF__c + '';
}
- if(!idSet.isEmpty()) {
- for (Rental_Apply_Equipment_Set_Detail__c raesd : [
+
+ if (
+ nObj.IF_Coverage_Target_Asset_FF__c == 3 &&
+ nObj.FY23_Asset_Age__c == null
+ ) {
+ nObj.FY23_Asset_Age__c = 0;
+ }
+ }
+
+ //甯傚満瀵瑰簲褰曞叆鏃堕棿鑷姩褰曞叆
+ if (
+ (Trigger.isInsert && nObj.Market_Product_Category__c != null) ||
+ (Trigger.isUpdate &&
+ nObj.Market_Product_Category__c !=
+ oldMap.get(nObj.Id).Market_Product_Category__c &&
+ nObj.Market_Product_Category__c != null)
+ ) {
+ nObj.Marketing_Input_Date__c = today;
+ }
+
+ /*//寰呮姤搴熷彉鏇翠负浣跨敤涓�
+ if(nObj.RecordType.Name == '澶囧搧'
+ && nObj.Manage_type__c == '涓綋绠$悊'
+ && nObj.Quantity > 0 && nObj.Status == '寰呮姤搴�'
+ && ( (nObj.Abandoned_RealThing__c == null && nObj.Abandoned_Inventory__c == null) || (nObj.Abandoned_RealThing__c + nObj.Abandoned_Inventory__c) == 0)
+ && acc_assMap.get(nObj.Id).Management_Code__c != System.Label.Account_Asset_FJZ) {
+ nObj.Status = '浣跨敤涓�';
+ nObj.Tobe_Discarded_Date__c = null;
+ }*/
+
+ /*//AssetMarkUpdate
+ if(Trigger.isUpdate && nObj.IF_Information_From__c == false && nObj.AssetMark__c == null) {
+ if(pro_proMap.containsKey(nObj.Id)){
+ if(pro_proMap.get(nObj.Id).RecordType.Name == '绔炲搧-涓绘満' ) {
+ nObj.AssetMark__c = '绔炲搧涓绘満';
+ }else if(pro_proMap.get(nObj.Id).RecordType.Name == '绔炲搧-鑰楁潗') {
+ nObj.AssetMark__c = '绔炲搧鑰楁潗';
+ }else if(pro_proMap.get(nObj.Id).Serial_Lot_No__c == 'S/N tracing') {
+ nObj.AssetMark__c = '涓绘満';
+ }
+ }
+ else {
+ nObj.AssetMark__c = '鑰楁潗';
+ }
+ }*/
+
+ /*//AssetName=ProductName
+ if(nObj.Name.equals('*') || (nObj.Product2.Id != null && nObj.Product2 != oldMap.get(nObj.Id).Product2)) {
+ nObj.Name = pro_proMap.get(nObj.Id).Name;
+ }*/
+
+ //AssetTextCopy
+ if (
+ Trigger.isInsert ||
+ (Trigger.isUpdate && nObj.Product2 != oldMap.get(nObj.Id).Product2)
+ ) {
+ nObj.BSSCategory_Text__c = nObj.BSSCategory__c;
+ nObj.Brand_Name_Text__c = nObj.Brand_Name__c;
+ nObj.Category2_Text__c = nObj.Category2__c;
+ nObj.Category3_Text__c = nObj.Category3__c;
+ nObj.Category4_Text__c = nObj.Category4__c;
+ nObj.Category5_Text__c = nObj.Category5__c;
+ }
+
+ //CIC瀹夎鐘舵�佺‘璁ゆ棩
+ if (
+ nObj.CIC_call_back_check__c && nObj.CIC_call_back_confirm_day__c == null
+ ) {
+ nObj.CIC_call_back_confirm_day__c = today;
+ }
+
+ //Equipment_Last_confirmed_day
+ if (
+ (Trigger.isInsert &&
+ (nObj.Status != null ||
+ nObj.Installation_Site__c != null ||
+ nObj.Final_Examination_Date__c != null ||
+ nObj.Hospital_Manage_Number__c != null)) ||
+ (Trigger.isUpdate &&
+ (nObj.Status != oldMap.get(nObj.Id).Status ||
+ nObj.Installation_Site__c != oldMap.get(nObj.Id).Installation_Site__c ||
+ nObj.Final_Examination_Date__c !=
+ oldMap.get(nObj.Id).Final_Examination_Date__c ||
+ nObj.Hospital_Manage_Number__c !=
+ oldMap.get(nObj.Id).Hospital_Manage_Number__c))
+ ) {
+ nObj.Equipment_Last_checking_day__c = today;
+ }
+
+ /*//Product_Code+Serial_No
+ if(Trigger.isUpdate && nObj.IsCompetitorProduct == false && nObj.Manage_type__c != '鏁伴噺绠$悊' && nObj.AssetMark__c != '鑰楁潗' && nObj.Loaner_accsessary__c != true && nObj.unknow_serial_NO_product__c != false) {
+ if(nObj.Product2.Id == null) {
+ nObj.Product_Serial_No__c = nObj.Id;
+ }else {
+ nObj.Product_Serial_No__c = pro_proMap.get(nObj.Id).ProductCode + ' ' + nObj.SerialNumber;
+ if(nObj.Delete_Flag__c){
+ nObj.Product_Serial_No__c += ':' + acc_assMap.get(nObj.Id).Management_Code__c;
+ }
+ }
+ }*/
+
+ //Product_Code+Serial_No Clear
+ if (
+ (Trigger.isInsert && nObj.IsCompetitorProduct) ||
+ (Trigger.isUpdate &&
+ nObj.IsCompetitorProduct &&
+ !oldMap.get(nObj.Id).IsCompetitorProduct)
+ ) {
+ nObj.Product_Serial_No__c = '';
+ }
+
+ /*//Product_Code+Serial_No+Salesdepartment
+ if(Trigger.isUpdate && nObj.IsCompetitorProduct == false && nObj.Manage_type__c == '鏁伴噺绠$悊' && nObj.AssetMark__c == '鑰楁潗' && nObj.Loaner_accsessary__c == true && nObj.unknow_serial_NO_product__c == false) {
+ if(nObj.Product2.Id == null) {
+ nObj.Product_Serial_No__c = nObj.Id;
+ }else {
+ nObj.Product_Serial_No__c = pro_proMap.get(nObj.Id).ProductCode + ' ' + nObj.SerialNumber + ':' + nObj.Salesdepartment__c.subString(0,nObj.Salesdepartment__c.indexOf(':'));
+ if(nObj.Delete_Flag__c){
+ nObj.Product_Serial_No__c += ':' + acc_assMap.get(nObj.Id).Management_Code__c;
+ }
+ }
+ }*/
+
+ /*//Product_Code+Serial_No UnkownSerial
+ if(Trigger.isUpdate && nObj.unknow_serial_NO_product__c == true) {
+ nObj.SerialNumber = nObj.serial_past__c;
+ if(nObj.Product2.Id == null) {
+ nObj.Product_Serial_No__c = nObj.Id;
+ }else {
+ nObj.Product_Serial_No__c = pro_proMap.get(nObj.Id).ProductCode + ':' + nObj.serial_past__c;
+ if(nObj.Delete_Flag__c){
+ nObj.Product_Serial_No__c += ':' + acc_assMap.get(nObj.Id).Management_Code__c;
+ }
+ }
+ }*/
+
+ //鏇存柊澶囧搧璧勪骇绠$悊璐熻矗鏈儴閫夐」
+ if (
+ (Trigger.isInsert && nObj.Internal_demo_incharge_demo__c != null) ||
+ (Trigger.isUpdate &&
+ nObj.Internal_demo_incharge_demo__c !=
+ oldMap.get(nObj.Id).Internal_demo_incharge_demo__c)
+ ) {
+ nObj.Internal_demo_incharge_demo_text__c = nObj.Internal_demo_incharge_demo__c;
+ }
+
+ /*//鑷姩鏇存柊璧勪骇鎵�灞�(鍖婚櫌璧勪骇)
+ if(Trigger.isUpdate && nObj.RecordType.Name == '鍖婚櫌淇濇湁璁惧' && hos_assMap.containskey(nObj.Id) && hos_assMap.get(nObj.Id).RecordType.Name == '鐥呴櫌' && acc_assMap.get(nObj.Id).Id == '00110000015Bx0h' ) {
+ nObj.Asset_Owner__c = '鍖婚櫌璧勪骇';
+ }*/
+
+ /*//鑷姩鏇存柊璧勪骇鎵�灞�(濂ユ灄宸存柉)
+ if(nObj.RecordType.Name == '鍖婚櫌淇濇湁璁惧' || (acc_assMap.containskey(nObj.Id) && acc_assMap.get(nObj.Id).Id == '00110000015Bx0h')) {
+ nObj.Asset_Owner__c = '濂ユ灄宸存柉';
+ }*/
+
+ /*//鑷姩鏇存柊璧勪骇鎵�灞�(缁忛攢鍟嗚祫浜�)
+ if(nObj.RecordType.Name == '鍖婚櫌淇濇湁璁惧' && (acc_assMap.containskey(nObj.Id) && hos_assMap.get(nObj.Id).RecordType.Name == '璨╁2搴�')) {
+ nObj.Asset_Owner__c = '缁忛攢鍟嗚祫浜�';
+ }*/
+
+ //鎵嬪姩鍒涘缓鐨勮�楁潗淇℃伅淇敼
+ if (
+ nObj.RecordTypeId == '01210000000kOPM' &&
+ nObj.Information_From__c == '鎵嬪姩杈撳叆' &&
+ nObj.AssetMark__c == '鑰楁潗'
+ ) {
+ nObj.Guarantee_period_for_products__c = nObj.Posting_Date__c;
+ nObj.InstallDate = nObj.Posting_Date__c;
+ }
+
+ //鍑鸿揣鏃ヨ嚜鍔ㄨ祴鍊�
+ if (Trigger.isInsert && nObj.Information_From__c == '鎵嬪姩杈撳叆') {
+ nObj.Posting_Date__c = Date.newInstance(1900, 1, 1);
+ }
+
+ //鏂伴�昏緫淇濅慨鏈熼檺瀵瑰簲
+ if (nObj.New_logic_data__c) {
+ nObj.Guarantee_period_for_products__c = nObj.Guarantee_period_formula__c;
+ }
+
+ //鎴愭湰涓績鏇存柊缂栫爜Update
+ if (
+ (Trigger.isInsert && nObj.Internal_cost_center_cd__c != null) ||
+ (Trigger.isUpdate &&
+ nObj.Internal_cost_center_cd__c !=
+ oldMap.get(nObj.Id).Internal_cost_center_cd__c)
+ ) {
+ nObj.Internal_demo_incharge_demo_text__c = nObj.Internal_cost_center_formula__c;
+ }
+
+ //鎴愭湰涓績鏇存柊閫夐」Update
+ if (
+ (Trigger.isInsert && nObj.Internal_cost_center__c != null) ||
+ (Trigger.isUpdate &&
+ nObj.Internal_cost_center__c !=
+ oldMap.get(nObj.Id).Internal_cost_center__c)
+ ) {
+ nObj.Internal_cost_center_text__c = nObj.Internal_cost_center__c;
+ }
+
+ //寰呮姤搴熸棩鐧诲綍
+ if (
+ Trigger.isUpdate &&
+ nObj.Fixture_Status__c != oldMap.get(nObj.Id).Fixture_Status__c &&
+ nObj.Fixture_Status__c != '搴熷純' &&
+ (nObj.Abandoned_RealThing__c > 0 ||
+ nObj.Abandoned_Inventory__c > 0) &&
+ nObj.Manage_type__c == '涓綋绠$悊'
+ ) {
+ nObj.Status = '寰呮姤搴�';
+ nObj.Tobe_Discarded_Date__c = today;
+ }
+
+ //閫�璐ц浆澶囧搧DEL缃瓼ALSE
+ if (
+ Trigger.isUpdate &&
+ ((nObj.RecordType != oldMap.get(nObj.Id).RecordType &&
+ nObj.RecordTypeId == '01210000000kOPR') ||
+ (nObj.AccountId != oldMap.get(nObj.Id).AccountId &&
+ nObj.AccountId == '0011000000VAiwz')) &&
+ nObj.Delete_Flag__c
+ ) {
+ nObj.Delete_Flag__c = false;
+ }
+
+ //杩芥函璁惧鑰楁潗Mark鏇存柊
+ if (
+ '杩芥函绯荤粺'.equals(nObj.Information_From__c) &&
+ String.isBlank(nObj.AssetMark__c)
+ ) {
+ nObj.AssetMark__c = '鑰楁潗';
+ }
+
+ //绱嶅叆鍟嗗搧鐘舵厠澶夋洿锛堜娇鐢ㄤ腑锛�
+ if (
+ (Trigger.isInsert && nObj.Status == '浣跨敤涓�') ||
+ (Trigger.isUpdate &&
+ nObj.Status != oldMap.get(nObj.Id).Status &&
+ nObj.Status == '浣跨敤涓�')
+ ) {
+ nObj.Status_Busy_Date__c = today;
+ }
+
+ //绱嶅叆鍟嗗搧鐘舵厠澶夋洿锛堝粌妫勶級
+ if (
+ (Trigger.isInsert && nObj.Status == '寤冩') ||
+ (Trigger.isUpdate &&
+ nObj.Status != oldMap.get(nObj.Id).Status &&
+ nObj.Status == '寤冩')
+ ) {
+ nObj.Discarded_Date__c = today;
+ nObj.Quantity = 0;
+ nObj.Abandoned_Inventory__c = null;
+ nObj.Abandoned_RealThing__c = null;
+ nObj.ChangeQuantityReason__c = '搴熷純';
+ }
+
+ //绱嶅叆鍟嗗搧鐘舵厠澶夋洿锛堜笉鏄庯級
+ if (
+ (Trigger.isInsert && nObj.Status == '涓嶆槑') ||
+ (Trigger.isUpdate &&
+ nObj.Status != oldMap.get(nObj.Id).Status &&
+ nObj.Status == '涓嶆槑')
+ ) {
+ nObj.Indistinctness_Date__c = today;
+ }
+
+ //绱嶅叆鍟嗗搧鐘舵厠澶夋洿锛堟湭浣跨敤锛�
+ if (
+ (Trigger.isInsert && nObj.Status == '鏈娇鐢�') ||
+ (Trigger.isUpdate &&
+ nObj.Status != oldMap.get(nObj.Id).Status &&
+ nObj.Status == '鏈娇鐢�')
+ ) {
+ nObj.Unused_Date__c = today;
+ }
+
+ /*//绱嶅搧纰鸿獚鏇搞伄瑷虹檪绉戙偝銉笺儔_銈汇儍銉�
+ if(!(nObj.Product2.Id != null && nObj.IsCompetitorProduct == false && nObj.InstallDate != null) && nObj.Install_Account_Code__c == null) {
+ nObj.Install_Account_Code__c = acc_assMap.get(nObj.Id).Management_Code__c;
+ nObj.Install_Account_Name__c = acc_assMap.get(nObj.Id).Name;
+ nObj.Install_Hospital_Name__c = hos_assMap.get(nObj.Id).Name;
+ nObj.Install_Hospital_code__c = hos_assMap.get(nObj.Id).Management_Code__c;
+ }*/
+
+ //鐥呴櫌绠$悊鐣彿澶夋洿鏃�
+ if (
+ (Trigger.isInsert && nObj.Hospital_Manage_Number__c != null) ||
+ (Trigger.isUpdate &&
+ nObj.Hospital_Manage_Number__c !=
+ oldMap.get(nObj.Id).Hospital_Manage_Number__c)
+ ) {
+ nObj.Hospital_Manage_Number_Change_Date__c = today;
+ }
+
+ //鏇存柊-2娆″墠鐐规鏃�
+ if (
+ Trigger.isUpdate &&
+ nObj.Final_Examination_Date__c !=
+ oldMap.get(nObj.Id).Final_Examination_Date__c
+ ) {
+ nObj.X2_second_past_inspection__c = oldMap.get(nObj.Id)
+ .Final_Examination_Date__c;
+ }
+
+ // 鏂囨湰鍖� 澶氬勾淇濅慨鏈熻嚦
+ nObj.Extend_Gurantee_DateTo_Text__c = nObj.Extend_Gurantee_DateTo__c;
+
+ // 淇濅慨澶╂暟宸ヤ綔娴�
+ if (
+ Trigger.isInsert ||
+ (Trigger.isUpdate &&
+ (nObj.Guarantee_period_for_products__c !=
+ oldMap.get(nObj.Id).Guarantee_period_for_products__c ||
+ nObj.InstallDate__c != oldMap.get(nObj.Id).InstallDate__c ||
+ nObj.ChangeWarrantyStartDate__c !=
+ oldMap.get(nObj.Id).ChangeWarrantyStartDate__c))
+ ) {
+ nObj.GuaranteePeriod__c = nObj.guarantee_period__c;
+ }
+
+ // 鏈夊畨瑁呮棩锛屾洿鏂扮姸鎬佸埌锛讳娇鐢ㄤ腑锛�
+ if (
+ (Trigger.isInsert && nObj.InstallDate != null) ||
+ (Trigger.isUpdate &&
+ nObj.InstallDate != null &&
+ nObj.InstallDate != oldMap.get(nObj.Id).InstallDate)
+ ) {
+ nObj.Status_Busy_Date__c = today;
+ nObj.Status = '浣跨敤涓�';
+ }
+
+ // 澶囧搧鍐嶉��璐ц浆DEL缃甌RUE
+ if (
+ nObj.AccountId == '00110000015Bx0h' &&
+ nObj.RecordTypeId == '01210000000kOPM' &&
+ !nObj.Delete_Flag__c
+ ) {
+ nObj.Delete_Flag__c = true;
+ }
+
+ // 璁惧畾澶囧搧鎵�灞炲叕鍙革紙涓婃捣锛塅romVBA
+ if (
+ (Trigger.isInsert && nObj.CompanyCodeOfEquipment_txt__c == '5112') ||
+ (Trigger.isUpdate &&
+ nObj.CompanyCodeOfEquipment_txt__c !=
+ oldMap.get(nObj.Id).CompanyCodeOfEquipment_txt__c &&
+ nObj.CompanyCodeOfEquipment_txt__c == '5112')
+ ) {
+ nObj.CompanyOfEquipment__c = '涓婃捣';
+ }
+
+ // 璁惧畾澶囧搧鎵�灞炲叕鍙革紙娌堥槼锛塅romVBA
+ if (
+ (Trigger.isInsert && nObj.CompanyCodeOfEquipment_txt__c == '5114') ||
+ (Trigger.isUpdate &&
+ nObj.CompanyCodeOfEquipment_txt__c !=
+ oldMap.get(nObj.Id).CompanyCodeOfEquipment_txt__c &&
+ nObj.CompanyCodeOfEquipment_txt__c == '5114')
+ ) {
+ nObj.CompanyOfEquipment__c = '娌堥槼';
+ }
+
+ // 璁惧畾澶囧搧鎵�灞炲叕鍙革紙鍖椾含锛塅romVBA
+ if (
+ (Trigger.isInsert && nObj.CompanyCodeOfEquipment_txt__c == '5111') ||
+ (Trigger.isUpdate &&
+ nObj.CompanyCodeOfEquipment_txt__c !=
+ oldMap.get(nObj.Id).CompanyCodeOfEquipment_txt__c &&
+ nObj.CompanyCodeOfEquipment_txt__c == '5111')
+ ) {
+ nObj.CompanyOfEquipment__c = '鍖椾含';
+ }
+
+ // 璁惧畾澶囧搧鎵�灞炲叕鍙革紙骞垮窞锛塅romVBA
+ if (
+ (Trigger.isInsert && nObj.CompanyCodeOfEquipment_txt__c == '5113') ||
+ (Trigger.isUpdate &&
+ nObj.CompanyCodeOfEquipment_txt__c !=
+ oldMap.get(nObj.Id).CompanyCodeOfEquipment_txt__c &&
+ nObj.CompanyCodeOfEquipment_txt__c == '5113')
+ ) {
+ nObj.CompanyOfEquipment__c = '骞垮窞';
+ }
+ }
+ }
+ //20230309 sx 淇濇湁璁惧workflow浠g爜鍖� end
+
+ // 鍊熷嚭鏄庣粏鏇存柊鍊熷嚭_鍒嗛厤_鏁�(Sys)鍜屽凡鍊熷嚭鏁�(Sys)
+ private void updateRentalCount() {
+ Set<Id> idSet = new Set<Id>();
+ for (Id assId : this.newMap.keySet()) {
+ if (
+ this.newMap.get(assId).AssetManageConfirm__c &&
+ this.newMap.get(assId).Account_Management_Code__c !=
+ System.Label.Account_Asset_FJZ
+ ) {
+ idSet.add(assId);
+ this.newMap.get(assId).Out_of_wh_Sys__c = 0;
+ this.newMap.get(assId).Rental_Count_Sys__c = 0;
+ }
+ }
+ if (!idSet.isEmpty()) {
+ // 澶囧搧鎬ц兘浼樺寲鏀逛慨 20230312 by lc Start
+ List<AggregateResult> raesdTempList2 = [
+ SELECT COUNT(Id) num, Asset__c
+ FROM Rental_Apply_Equipment_Set_Detail__c
+ //澶囧搧鍙戣揣鎶ラ敊瀵瑰簲 20230413 by lc Start
+ //WHERE Detail_Finish__c = false
+ WHERE
+ Detail_Not_Finish_Text__c = TRUE
+ //澶囧搧鍙戣揣鎶ラ敊瀵瑰簲 20230413 by lc End
+ AND Asset__c IN :idSet
+ AND Shippment_loaner_time2__c != NULL
+ GROUP BY Asset__c
+ ];
+ if (raesdTempList2 != null && raesdTempList2.size() > 0) {
+ for (AggregateResult ar : raesdTempList2) {
+ String assetId = String.valueOf(ar.get('Asset__c'));
+ Integer tempNum = Integer.valueOf(ar.get('num'));
+ this.newMap.get(assetId).Rental_Count_Sys__c += tempNum;
+ }
+ }
+
+ List<AggregateResult> raesdTempList1 = [
+ SELECT COUNT(Id) num, Asset__c
+ FROM Rental_Apply_Equipment_Set_Detail__c
+ //澶囧搧鍙戣揣鎶ラ敊瀵瑰簲 20230413 by lc Start
+ //WHERE Detail_Finish__c = false
+ WHERE
+ Detail_Not_Finish_Text__c = TRUE
+ //澶囧搧鍙戣揣鎶ラ敊瀵瑰簲 20230413 by lc End
+ AND Asset__c IN :idSet
+ GROUP BY Asset__c
+ ];
+ if (raesdTempList1 != null && raesdTempList1.size() > 0) {
+ for (AggregateResult ar : raesdTempList1) {
+ String assetId = String.valueOf(ar.get('Asset__c'));
+ Integer tempNum = Integer.valueOf(ar.get('num'));
+ this.newMap.get(assetId).Out_of_wh_Sys__c += tempNum;
+ idSet.remove(assetId);
+ }
+ }
+
+ /*for (Rental_Apply_Equipment_Set_Detail__c raesd : [
SELECT Id, Shippment_loaner_time2__c, Asset__c
FROM Rental_Apply_Equipment_Set_Detail__c
WHERE Detail_Finish__c = false
@@ -86,747 +582,900 @@
this.newMap.get(raesd.Asset__c).Rental_Count_Sys__c += 1;
}
idSet.remove(raesd.Asset__c);
- }
- if(!idSet.isEmpty()) {
- // 娌℃湁瀛楁鍙互瀹屽叏鍑嗙‘鍦板尯鍒嗗鍝佽澶囦笌鑰楁潗璁惧锛屽彧濂芥妸澶囧搧閲屾病鍑虹幇杩囩殑璁惧褰撴垚鑰楁潗鏉ユ煡
- for (Consum_Apply_Equipment_Set_Detail__c caesd : [
- SELECT Id, Shippment_loaner_time2__c, Asset__c
- FROM Consum_Apply_Equipment_Set_Detail__c
- WHERE Detail_Finish__c = false
- AND Asset__c IN :idSet
- ]) {
- this.newMap.get(caesd.Asset__c).Out_of_wh_Sys__c += 1;
- if(caesd.Shippment_loaner_time2__c != null) {
- this.newMap.get(caesd.Asset__c).Rental_Count_Sys__c += 1;
- }
- }
- }
+ }*/
+ // 澶囧搧鎬ц兘浼樺寲鏀逛慨 20230312 by lc End
+ if (!idSet.isEmpty()) {
+ // 娌℃湁瀛楁鍙互瀹屽叏鍑嗙‘鍦板尯鍒嗗鍝佽澶囦笌鑰楁潗璁惧锛屽彧濂芥妸澶囧搧閲屾病鍑虹幇杩囩殑璁惧褰撴垚鑰楁潗鏉ユ煡
+ for (Consum_Apply_Equipment_Set_Detail__c caesd : [
+ SELECT Id, Shippment_loaner_time2__c, Asset__c
+ FROM Consum_Apply_Equipment_Set_Detail__c
+ WHERE Detail_Finish__c = FALSE AND Asset__c IN :idSet
+ ]) {
+ this.newMap.get(caesd.Asset__c).Out_of_wh_Sys__c += 1;
+ if (caesd.Shippment_loaner_time2__c != null) {
+ this.newMap.get(caesd.Asset__c).Rental_Count_Sys__c += 1;
+ }
}
+ }
}
- //澶氬勾淇濅慨 start
- private void updateMaintenance_Contract_Asset(){
- StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true;
- Set<id> AssetIDSet = new Set<id>();
- for(Asset tempAsset : newList){
- if(String.isNotBlank(tempAsset.warrantyType__c)){
- AssetIDSet.add(tempAsset.id);
- }
- }
- if(AssetIDSet.size() > 0 ){
- list<Maintenance_Contract_Asset__c> MCAList =
- [select id,startDateGurantee__c,
- startDateGurantee_Text__c,endDateGurantee__c,
- endDateGurantee_Text__c,Return_Flag__c,ChangeAcc_flag__c,
- Maintenance_Price_Amount__c,Maintenance_Price_Amount_text__c,
- GuaranteePrice_Amount__c,GuaranteePrice_Amount_text__c
- from Maintenance_Contract_Asset__c
- where Asset__c in : AssetIDSet
- and Maintenance_Contract__r.RecordType.DeveloperName = 'VM_Contract'
- ];
- if(MCAList.size() > 0){
- list<Maintenance_Contract_Asset__c> UpdateMcaList =
- new list<Maintenance_Contract_Asset__c> ();
- for(Maintenance_Contract_Asset__c tempMCA : MCAList ){
- if(tempMCA.startDateGurantee__c != tempMCA.startDateGurantee_Text__c
- || tempMCA.endDateGurantee__c != tempMCA.endDateGurantee_Text__c
- || tempMCA.Maintenance_Price_Amount__c != tempMCA.Maintenance_Price_Amount_Text__c
- || tempMCA.GuaranteePrice_Amount__c != tempMCA.GuaranteePrice_Amount_text__c){
- UpdateMcaList.add(tempMCA);
- }
- }
- Oly_TriggerHandler.bypass('SetContractEstimatePriceHandler');
- update UpdateMcaList;
- Oly_TriggerHandler.clearBypass('SetContractEstimatePriceHandler');
- }
- }
+ }
+ //澶氬勾淇濅慨 start
+ private void updateMaintenance_Contract_Asset() {
+ StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true;
+ Set<id> AssetIDSet = new Set<id>();
+ for (Asset tempAsset : newList) {
+ // 20230306 ljh update start
+ Id Shipment = DEVELOPERNAMEMAP.get('Shipment').getRecordTypeId();
+ // if(String.isNotBlank(tempAsset.warrantyType__c)){
+ if (
+ String.isNotBlank(tempAsset.warrantyType__c) &&
+ Shipment != tempAsset.RecordTypeId
+ ) {
+ // 20230306 ljh update end
+ AssetIDSet.add(tempAsset.id);
+ }
}
- //澶氬勾淇濅慨 end
-
- private void beforeSetValue() {
- for (Asset nObj : newList) {
- // 鏈夌嚎涓嬫暟鎹�, 鎵�浠ヤ笉闇�瑕佷笅闈㈢殑logic
- //if (nObj.Quantity == null) {
- // nObj.Quantity = 1;
- //}
- if (Trigger.isInsert) {
- nObj.Last_Reserve_RAES_Detail__c = null;
- nObj.Last_Reserve_TAES_Detail__c = null;
- nObj.Pre_Reserve_RAES_Detail__c = null;
- nObj.Pre_Reserve_TAES_Detail__c = null;
- nObj.Fixture_OneToOne_Link__c = null;
- }
-
- if (Trigger.isUpdate) {
- Asset oObj = oldMap.get(nObj.Id);
- if (oObj.Last_Reserve_RAES_Detail__c != null && nObj.Last_Reserve_RAES_Detail__c == null
- && oObj.Last_Reserve_RAES_Detail_Flag__c == true) {
- nObj.Pre_Reserve_RAES_Detail__c = oObj.Last_Reserve_RAES_Detail__c;
- }
- if (oObj.Last_Reserve_TAES_Detail__c != null && nObj.Last_Reserve_TAES_Detail__c == null
- // TODO 鐢变簬__r瓒�20锛屽瓧娈靛缓涓嶅嚭鏉�
- // && oObj.Last_Reserve_TAES_Detail_Flag__c == true
- ) {
- nObj.Pre_Reserve_TAES_Detail__c = oObj.Last_Reserve_TAES_Detail__c;
- }
- }
-
- // 蹇呫仛鏈�寰屻仹缃亸
- nObj.Fixture_Status2_text__c = nObj.Fixture_Status2__c;
- nObj.Fixture_Status3_text__c = nObj.Fixture_Status3__c;
- nObj.BTreeIndexKey__c = nObj.Asset_Owner__c
- + ':' + nObj.Asset_loaner_category__c
- + ':' + String.valueOf(nobj.Freeze_sign_Abandoned_Flag__c)
- + ':' + String.valueOf(nObj.Delete_Flag__c)
- + ':' + String.valueOf(nObj.AssetManageConfirm__c);
-
- if (nObj.Status == FixtureUtil.assetStatusMap.get(FixtureUtil.AssetStatus.Dai_Fei_Qi.ordinal())) {
- nObj.Freeze_sign__c = false;
- }
- // gzw CHAN-CCR6MW 銆愬鎵樸�戙�愪繚鏈夎澶囥�戜繚鏈夎澶囧彂璐ф棩閫昏緫 start
- if(Trigger.isInsert && nObj.Posting_Date__c == null){
- nObj.Posting_Date__c = Date.newInstance(1900, 1, 1);
- }
- // gzw CHAN-CCR6MW 銆愬鎵樸�戙�愪繚鏈夎澶囥�戜繚鏈夎澶囧彂璐ф棩閫昏緫 end
+ if (AssetIDSet.size() > 0) {
+ list<Maintenance_Contract_Asset__c> MCAList = [
+ SELECT
+ id,
+ startDateGurantee__c,
+ startDateGurantee_Text__c,
+ endDateGurantee__c,
+ endDateGurantee_Text__c,
+ Return_Flag__c,
+ ChangeAcc_flag__c,
+ Maintenance_Price_Amount__c,
+ Maintenance_Price_Amount_text__c,
+ GuaranteePrice_Amount__c,
+ GuaranteePrice_Amount_text__c
+ FROM Maintenance_Contract_Asset__c
+ WHERE
+ Asset__c IN :AssetIDSet
+ AND Maintenance_Contract__r.RecordType.DeveloperName = 'VM_Contract'
+ ];
+ if (MCAList.size() > 0) {
+ list<Maintenance_Contract_Asset__c> UpdateMcaList = new List<Maintenance_Contract_Asset__c>();
+ for (Maintenance_Contract_Asset__c tempMCA : MCAList) {
+ if (
+ tempMCA.startDateGurantee__c != tempMCA.startDateGurantee_Text__c ||
+ tempMCA.endDateGurantee__c != tempMCA.endDateGurantee_Text__c ||
+ tempMCA.Maintenance_Price_Amount__c !=
+ tempMCA.Maintenance_Price_Amount_Text__c ||
+ tempMCA.GuaranteePrice_Amount__c !=
+ tempMCA.GuaranteePrice_Amount_text__c
+ ) {
+ UpdateMcaList.add(tempMCA);
+ }
}
+ Oly_TriggerHandler.bypass('SetContractEstimatePriceHandler');
+ update UpdateMcaList;
+ Oly_TriggerHandler.clearBypass('SetContractEstimatePriceHandler');
+ }
}
+ }
+ //澶氬勾淇濅慨 end
- // 銇嬨仾銈夈仛 before
- private void updateChangeQuantityReason() {
- for (Asset nObj : newList) {
- Asset oObj;
- String oQuantity = '';
- String oAbandoned_Inventory = '';
- if (Trigger.isUpdate) {
- oObj = oldMap.get(nObj.Id);
- oQuantity = oObj.Quantity == null ? '' : String.valueOf(oObj.Quantity);
- oAbandoned_Inventory = oObj.Abandoned_Inventory__c == null ? '' : String.valueOf(oObj.Abandoned_Inventory__c);
- }
- String nQuantity = nObj.Quantity == null ? '' : String.valueOf(nObj.Quantity);
- String nAbandoned_Inventory = nObj.Abandoned_Inventory__c == null ? '' : String.valueOf(nObj.Abandoned_Inventory__c);
- if ((oQuantity != nQuantity && String.isNotBlank(nObj.ChangeQuantityReason__c)) || Trigger.isInsert) {
- String rs = nObj.ChangeQuantityReason__c;
- nObj.ChangeQuantityHistory__c = String.format(System.Label.ChangeQuantityHistory,
- new String[]{oQuantity, nQuantity, rs});
- // before閲岄潰鍏ョ珛瑙勫垯杩囦笉浜嗘敼鍒�
- // 宸茬粡鏀硅繘 Must_Input_ChangeQuantityReason 鐨� valida before鍙互瀹屾垚 ChangeQuantityReason__c = ''
- // nObj.ChangeQuantityReason__c = '';
- }
+ private void beforeSetValue() {
+ for (Asset nObj : newList) {
+ // 鏈夌嚎涓嬫暟鎹�, 鎵�浠ヤ笉闇�瑕佷笅闈㈢殑logic
+ //if (nObj.Quantity == null) {
+ // nObj.Quantity = 1;
+ //}
+ if (Trigger.isInsert) {
+ nObj.Last_Reserve_RAES_Detail__c = null;
+ nObj.Last_Reserve_TAES_Detail__c = null;
+ nObj.Pre_Reserve_RAES_Detail__c = null;
+ nObj.Pre_Reserve_TAES_Detail__c = null;
+ nObj.Fixture_OneToOne_Link__c = null;
+ }
- if (oAbandoned_Inventory != nAbandoned_Inventory || Trigger.isInsert) {
- String rs = nObj.Giveup_Return__c;
- nObj.ChangeAbandoned_InventoryHistory__c = String.format(System.Label.ChangeAbandoned_InventoryHistory,
- new String[]{oAbandoned_Inventory, nAbandoned_Inventory, rs});
- }
+ if (Trigger.isUpdate) {
+ Asset oObj = oldMap.get(nObj.Id);
+ if (
+ oObj.Last_Reserve_RAES_Detail__c != null &&
+ nObj.Last_Reserve_RAES_Detail__c == null &&
+ oObj.Last_Reserve_RAES_Detail_Flag__c == true
+ ) {
+ nObj.Pre_Reserve_RAES_Detail__c = oObj.Last_Reserve_RAES_Detail__c;
}
+ if (
+ oObj.Last_Reserve_TAES_Detail__c != null &&
+ nObj.Last_Reserve_TAES_Detail__c == null
+ ) {
+ // TODO 鐢变簬__r瓒�20锛屽瓧娈靛缓涓嶅嚭鏉�
+ // && oObj.Last_Reserve_TAES_Detail_Flag__c == true
+ nObj.Pre_Reserve_TAES_Detail__c = oObj.Last_Reserve_TAES_Detail__c;
+ }
+ }
+
+ // 蹇呫仛鏈�寰屻仹缃亸
+ nObj.Fixture_Status2_text__c = nObj.Fixture_Status2__c;
+ nObj.Fixture_Status3_text__c = nObj.Fixture_Status3__c;
+ nObj.BTreeIndexKey__c =
+ nObj.Asset_Owner__c +
+ ':' +
+ nObj.Asset_loaner_category__c +
+ ':' +
+ String.valueOf(nobj.Freeze_sign_Abandoned_Flag__c) +
+ ':' +
+ String.valueOf(nObj.Delete_Flag__c) +
+ ':' +
+ String.valueOf(nObj.AssetManageConfirm__c);
+
+ if (
+ nObj.Status ==
+ FixtureUtil.assetStatusMap.get(
+ FixtureUtil.AssetStatus.Dai_Fei_Qi.ordinal()
+ )
+ ) {
+ nObj.Freeze_sign__c = false;
+ }
+ // gzw CHAN-CCR6MW 銆愬鎵樸�戙�愪繚鏈夎澶囥�戜繚鏈夎澶囧彂璐ф棩閫昏緫 start
+ if (Trigger.isInsert && nObj.Posting_Date__c == null) {
+ nObj.Posting_Date__c = Date.newInstance(1900, 1, 1);
+ }
+ // gzw CHAN-CCR6MW 銆愬鎵樸�戙�愪繚鏈夎澶囥�戜繚鏈夎澶囧彂璐ф棩閫昏緫 end
}
+ }
- //// 銇嬨仾銈夈仛 afterUpdate
- private void cleanChangeQuantityReason() {
- // TODO 鏇存柊鑷繁table 鍘熷垯闇�瑕丼tatic鐨凜lass鍙橀噺(鍥犱负浼氭湁澶嶆暟鐨凪ethod鍘绘洿鏂拌嚜宸辩殑)
- List<Asset> assList = new List<Asset>();
- for (Asset nObj : newList) {
- if (String.isBlank(nObj.ChangeQuantityReason__c) == false) {
- assList.add(new Asset(Id = nObj.Id,
- ChangeQuantityReason__c = ''));
- }
- }
- if (!assList.isEmpty()) {
- update assList;
- }
+ // 銇嬨仾銈夈仛 before
+ private void updateChangeQuantityReason() {
+ for (Asset nObj : newList) {
+ Asset oObj;
+ String oQuantity = '';
+ String oAbandoned_Inventory = '';
+ if (Trigger.isUpdate) {
+ oObj = oldMap.get(nObj.Id);
+ oQuantity = oObj.Quantity == null ? '' : String.valueOf(oObj.Quantity);
+ oAbandoned_Inventory = oObj.Abandoned_Inventory__c == null
+ ? ''
+ : String.valueOf(oObj.Abandoned_Inventory__c);
+ }
+ String nQuantity = nObj.Quantity == null
+ ? ''
+ : String.valueOf(nObj.Quantity);
+ String nAbandoned_Inventory = nObj.Abandoned_Inventory__c == null
+ ? ''
+ : String.valueOf(nObj.Abandoned_Inventory__c);
+ if (
+ (oQuantity != nQuantity &&
+ String.isNotBlank(nObj.ChangeQuantityReason__c)) || Trigger.isInsert
+ ) {
+ String rs = nObj.ChangeQuantityReason__c;
+ nObj.ChangeQuantityHistory__c = String.format(
+ System.Label.ChangeQuantityHistory,
+ new List<String>{ oQuantity, nQuantity, rs }
+ );
+ // before閲岄潰鍏ョ珛瑙勫垯杩囦笉浜嗘敼鍒�
+ // 宸茬粡鏀硅繘 Must_Input_ChangeQuantityReason 鐨� valida before鍙互瀹屾垚 ChangeQuantityReason__c = ''
+ // nObj.ChangeQuantityReason__c = '';
+ }
+
+ if (oAbandoned_Inventory != nAbandoned_Inventory || Trigger.isInsert) {
+ String rs = nObj.Giveup_Return__c;
+ nObj.ChangeAbandoned_InventoryHistory__c = String.format(
+ System.Label.ChangeAbandoned_InventoryHistory,
+ new List<String>{ oAbandoned_Inventory, nAbandoned_Inventory, rs }
+ );
+ }
}
+ }
- // afterUpdate
- // 娓呯悊瀛楁銆屽緟搴熷純鏁帮紙涓㈠け/鐩樹簭锛変慨鏀圭悊鐢便��
- private void cleanGiveupReturnReason() {
- List<Asset> assList = new List<Asset>();
- for (Asset nObj : newList) {
- if (String.isBlank(nObj.Giveup_Return__c) == false) {
- assList.add(new Asset(
- Id = nObj.Id,
- Giveup_Return__c = ''));
- }
- }
- if (!assList.isEmpty()) {
- update assList;
- }
+ //// 銇嬨仾銈夈仛 afterUpdate
+ private void cleanChangeQuantityReason() {
+ // TODO 鏇存柊鑷繁table 鍘熷垯闇�瑕丼tatic鐨凜lass鍙橀噺(鍥犱负浼氭湁澶嶆暟鐨凪ethod鍘绘洿鏂拌嚜宸辩殑)
+ List<Asset> assList = new List<Asset>();
+ for (Asset nObj : newList) {
+ if (String.isBlank(nObj.ChangeQuantityReason__c) == false) {
+ assList.add(new Asset(Id = nObj.Id, ChangeQuantityReason__c = ''));
+ }
}
-
- // 銇嬨仾銈夈仛 after, oObj.Id 銇� nObj.Id 銈掍娇銇嗐仧銈�
- // Last_Reserve_RAES_Detail__c (涓綋绠$悊) 銇甽ink 澶夈倧銇c仧鍫村悎銆�
- // Fixture_OneToOne_Link__c 銈堛倞 Asset 銇銇夸笂銇掋仐銇︺亜銈嬫暟瀛椼倐閫e嫊銇仾銈嬨�丗ixture_OneToOne_Link__c 銈掔┖鏇存柊
- // 鏇存柊闋呯洰Fixture_OneToOne_Link__c.In_wh_Fu_Shu_Pin_You_Xiao_Ku_Cun__c = Fixture_OneToOne_Link__c.In_wh_Fu_Shu_Pin_You_Xiao_Ku_Cun_F__c
- private void mainAssetUpdateed_OneToOneRecord() {
- Set<Id> aSetIdSet = new Set<Id>();
- System.debug(LoggingLevel.INFO, '*** mainAssetUpdateed_OneToOneRecord: ');
- for (Integer i = 0; i < newList.size(); i++) {
- Asset nObj = newList[i];
- Asset oObj = oldList[i];
- if (oObj.Last_Reserve_RAES_Detail__c != nObj.Last_Reserve_RAES_Detail__c) {
- if (String.isNotBlank(oObj.Id)) {
- aSetIdSet.add(oObj.Id);
- }
- if (String.isNotBlank(nObj.Id)) {
- aSetIdSet.add(nObj.Id);
- }
- }
- }
- if (!aSetIdSet.isEmpty()) {
- List<Fixture_OneToOne_Link__c> oneToOneList = [
- SELECT Id FROM Fixture_OneToOne_Link__c WHERE Main_Asset__c IN :aSetIdSet];
- if (!oneToOneList.isEmpty()) { update oneToOneList; }
- }
+ if (!assList.isEmpty()) {
+ update assList;
}
+ }
- // * 涓嶄細鏈夋殏瀹氬垎閰嶅悗鍐嶆嬁鍘讳慨鐞嗙殑澶囧搧璧伴噸鏂拌缃殏瀹氬垎閰嶇殑閫昏緫(queueRedistribution鏂规硶)
- // * 鐞嗙敱锛氭槑缁嗘殏瀹氬垎閰嶇殑鏃跺�欏垱寤轰慨鐞嗙殑璇濅細鎶ヤ互涓嬮敊璇�
- // * 鍊熷嚭_鍒嗛厤_鏁� 涓嶈兘澶т簬 璁惧鐨勬�绘暟 ------> Asset 鍏ュ姏瑙勫垯 You_Xiao_Ku_Cun_chk
- // * 鏆傚畾鍒嗛厤-1
- // * 淇悊-1
- // * 鏁伴噺1
- // * 1-1-1 = -1
- // *
- // * 濡傛灉鏆傚畾鍒嗛厤鎯充慨鐞嗙殑璇濆垎閰嶆殏瀹氬垎閰嶇殑閭d竴鏉℃槑缁�
- // * 鐒跺悗鍐嶅嚭鍑哄簱鍓嶆娴嬬殑鏃跺�欓�夋嫨NG淇悊
- // 銇嬨仾銈夈仛 after
- private void queueRedistribution() {
- if (queueRaesdMap == null) {
- queueRaesdMap = new Map<String , List<Rental_Apply_Equipment_Set_Detail__c>>();
+ // afterUpdate
+ // 娓呯悊瀛楁銆屽緟搴熷純鏁帮紙涓㈠け/鐩樹簭锛変慨鏀圭悊鐢便��
+ private void cleanGiveupReturnReason() {
+ List<Asset> assList = new List<Asset>();
+ for (Asset nObj : newList) {
+ if (String.isBlank(nObj.Giveup_Return__c) == false) {
+ assList.add(new Asset(Id = nObj.Id, Giveup_Return__c = ''));
+ }
+ }
+ if (!assList.isEmpty()) {
+ update assList;
+ }
+ }
+
+ // 銇嬨仾銈夈仛 after, oObj.Id 銇� nObj.Id 銈掍娇銇嗐仧銈�
+ // Last_Reserve_RAES_Detail__c (涓綋绠$悊) 銇甽ink 澶夈倧銇c仧鍫村悎銆�
+ // Fixture_OneToOne_Link__c 銈堛倞 Asset 銇銇夸笂銇掋仐銇︺亜銈嬫暟瀛椼倐閫e嫊銇仾銈嬨�丗ixture_OneToOne_Link__c 銈掔┖鏇存柊
+ // 鏇存柊闋呯洰Fixture_OneToOne_Link__c.In_wh_Fu_Shu_Pin_You_Xiao_Ku_Cun__c = Fixture_OneToOne_Link__c.In_wh_Fu_Shu_Pin_You_Xiao_Ku_Cun_F__c
+ private void mainAssetUpdateed_OneToOneRecord() {
+ Set<Id> aSetIdSet = new Set<Id>();
+ System.debug(LoggingLevel.INFO, '*** mainAssetUpdateed_OneToOneRecord: ');
+ for (Integer i = 0; i < newList.size(); i++) {
+ Asset nObj = newList[i];
+ Asset oObj = oldList[i];
+ if (
+ oObj.Last_Reserve_RAES_Detail__c != nObj.Last_Reserve_RAES_Detail__c
+ ) {
+ if (String.isNotBlank(oObj.Id)) {
+ aSetIdSet.add(oObj.Id);
}
- Map<String, Set<Id>> modelNoAssetIdMap = new Map<String, Set<Id>>();
- Set<Id> raesdIdSet = new Set<Id>();
- // List<Rental_Apply_Equipment_Set_Detail__c> updList = new List<Rental_Apply_Equipment_Set_Detail__c>();
- String whkey = '';
- for (Asset nObj : newList) {
- //ToDo鐝惧湪鎺掗槦銇с亶銈嬨伄銇富浣撱仩銇戙仾銇仹锛屼粖寰屼釜浣撶鐞嗐伄闄勫睘鍝併倐鎺掗槦銇с亶銈嬨伄鍫村悎銇屻亗銇c仧銈夈亾銇甀F銇躲倱銈掔洿銇欏繀瑕併亴銇傘倞銇俱仚
- if (!(nObj.Loaner_accsessary__c == false
- && nObj.Asset_Owner__c == 'Olympus'
- && nObj.Equipment_Type__c != '妫�娴嬬敤澶囧搧'
- && nObj.Delete_Flag__c == False
- && nObj.You_Xiao_Ku_Cun__c > 0
- && nObj.Freeze_sign_Abandoned_Flag__c == False)
- ) {
- continue;
- }
+ if (String.isNotBlank(nObj.Id)) {
+ aSetIdSet.add(nObj.Id);
+ }
+ }
+ }
+ if (!aSetIdSet.isEmpty()) {
+ List<Fixture_OneToOne_Link__c> oneToOneList = [
+ SELECT Id
+ FROM Fixture_OneToOne_Link__c
+ WHERE Main_Asset__c IN :aSetIdSet
+ ];
+ if (!oneToOneList.isEmpty()) {
+ update oneToOneList;
+ }
+ }
+ }
- String key = nObj.Fixture_Model_No_F__c;
- //鏆傚畾鍒嗛厤涓嶇湅瀛樻斁鍦� OLY_OCM-722 鎭㈠瀛樻斁鍦扮殑鏉′欢
- if (String.isNotBlank(nObj.Internal_asset_location__c)) {
- key += nObj.Internal_asset_location__c;
- }
+ // * 涓嶄細鏈夋殏瀹氬垎閰嶅悗鍐嶆嬁鍘讳慨鐞嗙殑澶囧搧璧伴噸鏂拌缃殏瀹氬垎閰嶇殑閫昏緫(queueRedistribution鏂规硶)
+ // * 鐞嗙敱锛氭槑缁嗘殏瀹氬垎閰嶇殑鏃跺�欏垱寤轰慨鐞嗙殑璇濅細鎶ヤ互涓嬮敊璇�
+ // * 鍊熷嚭_鍒嗛厤_鏁� 涓嶈兘澶т簬 璁惧鐨勬�绘暟 ------> Asset 鍏ュ姏瑙勫垯 You_Xiao_Ku_Cun_chk
+ // * 鏆傚畾鍒嗛厤-1
+ // * 淇悊-1
+ // * 鏁伴噺1
+ // * 1-1-1 = -1
+ // *
+ // * 濡傛灉鏆傚畾鍒嗛厤鎯充慨鐞嗙殑璇濆垎閰嶆殏瀹氬垎閰嶇殑閭d竴鏉℃槑缁�
+ // * 鐒跺悗鍐嶅嚭鍑哄簱鍓嶆娴嬬殑鏃跺�欓�夋嫨NG淇悊
+ // 銇嬨仾銈夈仛 after
+ private void queueRedistribution() {
+ if (queueRaesdMap == null) {
+ queueRaesdMap = new Map<String, List<Rental_Apply_Equipment_Set_Detail__c>>();
+ }
+ Map<String, Set<Id>> modelNoAssetIdMap = new Map<String, Set<Id>>();
+ Set<Id> raesdIdSet = new Set<Id>();
+ // List<Rental_Apply_Equipment_Set_Detail__c> updList = new List<Rental_Apply_Equipment_Set_Detail__c>();
+ String whkey = '';
+ for (Asset nObj : newList) {
+ //ToDo鐝惧湪鎺掗槦銇с亶銈嬨伄銇富浣撱仩銇戙仾銇仹锛屼粖寰屼釜浣撶鐞嗐伄闄勫睘鍝併倐鎺掗槦銇с亶銈嬨伄鍫村悎銇屻亗銇c仧銈夈亾銇甀F銇躲倱銈掔洿銇欏繀瑕併亴銇傘倞銇俱仚
+ if (
+ !(nObj.Loaner_accsessary__c == false &&
+ nObj.Asset_Owner__c == 'Olympus' &&
+ nObj.Equipment_Type__c != '妫�娴嬬敤澶囧搧' &&
+ nObj.Delete_Flag__c == false &&
+ nObj.You_Xiao_Ku_Cun__c > 0 &&
+ nObj.Freeze_sign_Abandoned_Flag__c == false)
+ ) {
+ continue;
+ }
- if (String.isNotBlank(nObj.Salesdepartment__c)) {
- key += nObj.Salesdepartment__c;
- }
- if (String.isNotBlank(nObj.Equipment_Type__c)) {
- key += nObj.Equipment_Type__c;
- }
- if (String.isNotBlank(nObj.Product_category__c)) {
- key += nObj.Product_category__c;
- }
+ String key = nObj.Fixture_Model_No_F__c;
+ //鏆傚畾鍒嗛厤涓嶇湅瀛樻斁鍦� OLY_OCM-722 鎭㈠瀛樻斁鍦扮殑鏉′欢
+ if (String.isNotBlank(nObj.Internal_asset_location__c)) {
+ key += nObj.Internal_asset_location__c;
+ }
-
- System.debug(LoggingLevel.INFO, '*** key: ' + key);
- //鏈夋柊鐨凙sset鐨勬椂鍊� 鏆傚畾鍒嗛厤
- // You_Xiao_Ku_Cun__c > 0 鍦ㄤ笂闈㈠凡缁忓仛浜嗗垽鏂�
- if (Trigger.isInsert && String.isBlank(nObj.Last_Reserve_RAES_Detail__c)) {
- if (String.isBlank(nObj.Fixture_Model_No_F__c) == false) {
- // modelNoAssetIdMap.put(nObj.Fixture_Model_No_F__c, nObj.Id);
- if (modelNoAssetIdMap.containsKey(key) == false) {
- modelNoAssetIdMap.put(key, new Set<Id>());
- }
- modelNoAssetIdMap.get(key).add(nObj.Id);
- }
- }
- //褰撲富浣撳弬鐓х殑Asset鐨凩ast鏂紑鐨勬椂鍊欓噸鏂板鎵炬殏瀹氬垎閰�
- //ToDo鐘舵硜纰鸿獚
- /*
+ if (String.isNotBlank(nObj.Salesdepartment__c)) {
+ key += nObj.Salesdepartment__c;
+ }
+ if (String.isNotBlank(nObj.Equipment_Type__c)) {
+ key += nObj.Equipment_Type__c;
+ }
+ if (String.isNotBlank(nObj.Product_category__c)) {
+ key += nObj.Product_category__c;
+ }
+
+ System.debug(LoggingLevel.INFO, '*** key: ' + key);
+ //鏈夋柊鐨凙sset鐨勬椂鍊� 鏆傚畾鍒嗛厤
+ // You_Xiao_Ku_Cun__c > 0 鍦ㄤ笂闈㈠凡缁忓仛浜嗗垽鏂�
+ if (
+ Trigger.isInsert && String.isBlank(nObj.Last_Reserve_RAES_Detail__c)
+ ) {
+ if (String.isBlank(nObj.Fixture_Model_No_F__c) == false) {
+ // modelNoAssetIdMap.put(nObj.Fixture_Model_No_F__c, nObj.Id);
+ if (modelNoAssetIdMap.containsKey(key) == false) {
+ modelNoAssetIdMap.put(key, new Set<Id>());
+ }
+ modelNoAssetIdMap.get(key).add(nObj.Id);
+ }
+ }
+ //褰撲富浣撳弬鐓х殑Asset鐨凩ast鏂紑鐨勬椂鍊欓噸鏂板鎵炬殏瀹氬垎閰�
+ //ToDo鐘舵硜纰鸿獚
+ /*
|| (nObj.Asset_Owner__c != oObj.Asset_Owner__c && nObj.Asset_Owner__c == 'Olympus')
|| (nObj.Equipment_Type__c != oObj.Equipment_Type__c && oObj.Equipment_Type__c == '妫�娴嬬敤澶囧搧')
|| (nObj.Delete_Flag__c != oObj.Delete_Flag__c && nObj.Delete_Flag__c == false)
|| (nObj.Freeze_sign__c != oObj.Freeze_sign__c && nObj.Delete_Flag__c == false)
*/
- // You_Xiao_Ku_Cun__c > 0 鍦ㄤ笂闈㈠凡缁忓仛浜嗗垽鏂�
- else {
- Asset oObj = oldMap.get(nObj.Id);
- if (nObj.Loaner_accsessary__c == false && String.isBlank(nObj.Last_Reserve_RAES_Detail__c)
- && (nObj.Last_Reserve_RAES_Detail__c != oObj.Last_Reserve_RAES_Detail__c
- || (nObj.Asset_Owner__c != oObj.Asset_Owner__c && nObj.Asset_Owner__c == 'Olympus')
- //澶囧搧瀛樻斁鍦� OLY_OCM-722 鎭㈠瀛樻斁鍦扮殑鏉′欢
- || (nObj.Internal_asset_location__c != oObj.Internal_asset_location__c)
- //澶囧搧鍒嗙被骞朵笖涓嶆槸 妫�娴嬬敤澶囧搧
- || (nObj.Equipment_Type__c != oObj.Equipment_Type__c && nObj.Equipment_Type__c != '妫�娴嬬敤澶囧搧')
- //閿�鍞湰閮�
- || (nObj.Salesdepartment__c != oObj.Salesdepartment__c)
- //浜у搧鍒嗙被(GI/SP)
- || (nObj.Product_category__c != oObj.Product_category__c)
- //澶囧搧閰嶅鏄庣粏鍨嬪彿
- || (nObj.Fixture_Model_No_F__c != oObj.Fixture_Model_No_F__c)
- || (nObj.Delete_Flag__c != oObj.Delete_Flag__c && nObj.Delete_Flag__c == true)
- || (nObj.Freeze_sign_Abandoned_Flag__c != oObj.Freeze_sign_Abandoned_Flag__c && nObj.Freeze_sign_Abandoned_Flag__c == false)
- )
- ) {
- if (String.isBlank(nObj.Fixture_Model_No_F__c) == false) {
- if (modelNoAssetIdMap.containsKey(key) == false) {
- modelNoAssetIdMap.put(key, new Set<Id>());
- }
- modelNoAssetIdMap.get(key).add(nObj.Id);
- }
- if (String.isNotBlank(oObj.Last_Reserve_RAES_Detail__c)) {
- raesdIdSet.add(oObj.Last_Reserve_RAES_Detail__c);
- }
- }
+ // You_Xiao_Ku_Cun__c > 0 鍦ㄤ笂闈㈠凡缁忓仛浜嗗垽鏂�
+ else {
+ Asset oObj = oldMap.get(nObj.Id);
+ if (
+ nObj.Loaner_accsessary__c == false &&
+ String.isBlank(nObj.Last_Reserve_RAES_Detail__c) &&
+ (nObj.Last_Reserve_RAES_Detail__c !=
+ oObj.Last_Reserve_RAES_Detail__c ||
+ (nObj.Asset_Owner__c != oObj.Asset_Owner__c &&
+ nObj.Asset_Owner__c == 'Olympus') ||
+ //澶囧搧瀛樻斁鍦� OLY_OCM-722 鎭㈠瀛樻斁鍦扮殑鏉′欢
+ (nObj.Internal_asset_location__c !=
+ oObj.Internal_asset_location__c) ||
+ //澶囧搧鍒嗙被骞朵笖涓嶆槸 妫�娴嬬敤澶囧搧
+ (nObj.Equipment_Type__c != oObj.Equipment_Type__c &&
+ nObj.Equipment_Type__c != '妫�娴嬬敤澶囧搧') ||
+ //閿�鍞湰閮�
+ (nObj.Salesdepartment__c != oObj.Salesdepartment__c) ||
+ //浜у搧鍒嗙被(GI/SP)
+ (nObj.Product_category__c != oObj.Product_category__c) ||
+ //澶囧搧閰嶅鏄庣粏鍨嬪彿
+ (nObj.Fixture_Model_No_F__c != oObj.Fixture_Model_No_F__c) ||
+ (nObj.Delete_Flag__c != oObj.Delete_Flag__c &&
+ nObj.Delete_Flag__c == true) ||
+ (nObj.Freeze_sign_Abandoned_Flag__c !=
+ oObj.Freeze_sign_Abandoned_Flag__c &&
+ nObj.Freeze_sign_Abandoned_Flag__c == false))
+ ) {
+ if (String.isBlank(nObj.Fixture_Model_No_F__c) == false) {
+ if (modelNoAssetIdMap.containsKey(key) == false) {
+ modelNoAssetIdMap.put(key, new Set<Id>());
}
+ modelNoAssetIdMap.get(key).add(nObj.Id);
+ }
+ if (String.isNotBlank(oObj.Last_Reserve_RAES_Detail__c)) {
+ raesdIdSet.add(oObj.Last_Reserve_RAES_Detail__c);
+ }
}
- if (modelNoAssetIdMap.isEmpty()) {
- return;
- }
- System.debug(LoggingLevel.INFO, '*** raesdIdSet: ' + JSON.serialize(raesdIdSet));
- //modified by denny 2021-11-17
- List<String> keyList = new List<String>();
- keyList.addAll(modelNoAssetIdMap.keySet());
- System.debug(LoggingLevel.INFO, '*** keyList: ' + keyList);
- List<Rental_Apply_Sequence__c> targetSequence = [SELECT Id,Apply_Set_Detail__c,
- Apply_Set_Detail_ExternalKey__c,
- Demo_Purpose2__c, Equipment_Type__c, ExternalKey__c,
- Fixture_Model_No__c,
- Internal_asset_location__c, Invalid_Flag__c,
- Product_category__c,
- Rental_Apply__c,Series_No__c,
- Series_Unequal_Queue_Flag__c, Salesdepartment__c
- FROM Rental_Apply_Sequence__c
- WHERE Series_No__c > 0 AND Invalid_Flag__c =false
- AND Apply_Set_Detail__c NOT IN:raesdIdSet
- AND ExternalKey__c IN:keyList
- AND Apply_Set_Detail__r.Cancel_Select__c = false
- ORDER BY Series_No__c ];
- System.debug(LoggingLevel.INFO, '*** targetSequence: ' + targetSequence);
- Map<String,List<Rental_Apply_Sequence__c>> sequenceMap = new Map<String,List<Rental_Apply_Sequence__c>>();
- for(Rental_Apply_Sequence__c sequeuece:targetSequence){
- if(!sequenceMap.containsKey(sequeuece.Externalkey__c)){
- sequenceMap.put(sequeuece.Externalkey__c,new List<Rental_Apply_Sequence__c>());
+ }
+ }
+ if (modelNoAssetIdMap.isEmpty()) {
+ return;
+ }
+ System.debug(
+ LoggingLevel.INFO,
+ '*** raesdIdSet: ' + JSON.serialize(raesdIdSet)
+ );
+ //modified by denny 2021-11-17
+ List<String> keyList = new List<String>();
+ keyList.addAll(modelNoAssetIdMap.keySet());
+ System.debug(LoggingLevel.INFO, '*** keyList: ' + keyList);
+ List<Rental_Apply_Sequence__c> targetSequence = [
+ SELECT
+ Id,
+ Apply_Set_Detail__c,
+ Apply_Set_Detail_ExternalKey__c,
+ Demo_Purpose2__c,
+ Equipment_Type__c,
+ ExternalKey__c,
+ Fixture_Model_No__c,
+ Internal_asset_location__c,
+ Invalid_Flag__c,
+ Product_category__c,
+ Rental_Apply__c,
+ Series_No__c,
+ Series_Unequal_Queue_Flag__c,
+ Salesdepartment__c
+ FROM Rental_Apply_Sequence__c
+ WHERE
+ Series_No__c > 0
+ AND Invalid_Flag__c = FALSE
+ AND Apply_Set_Detail__c NOT IN :raesdIdSet
+ AND ExternalKey__c IN :keyList
+ AND Apply_Set_Detail__r.Cancel_Select__c = FALSE
+ ORDER BY Series_No__c
+ ];
+ System.debug(LoggingLevel.INFO, '*** targetSequence: ' + targetSequence);
+ Map<String, List<Rental_Apply_Sequence__c>> sequenceMap = new Map<String, List<Rental_Apply_Sequence__c>>();
+ for (Rental_Apply_Sequence__c sequeuece : targetSequence) {
+ if (!sequenceMap.containsKey(sequeuece.Externalkey__c)) {
+ sequenceMap.put(
+ sequeuece.Externalkey__c,
+ new List<Rental_Apply_Sequence__c>()
+ );
+ }
+ sequenceMap.get(sequeuece.Externalkey__c).add(sequeuece);
+ }
+ Map<String, Rental_Apply_Equipment_Set_Detail__c> updateMap = new Map<String, Rental_Apply_Equipment_Set_Detail__c>();
+ for (String key : sequenceMap.keySet()) {
+ for (Rental_Apply_Sequence__c sequeuece : sequenceMap.get(key)) {
+ if (!updateMap.containsKey(sequeuece.Apply_Set_Detail__c)) {
+ System.debug(
+ LoggingLevel.INFO,
+ '*** modelNoAssetIdMap: ' + JSON.serialize(modelNoAssetIdMap)
+ );
+ if (modelNoAssetIdMap.containsKey(key)) {
+ List<Id> assIdList = new List<Id>();
+ assIdList.addAll(modelNoAssetIdMap.get(key));
+ String assIdbk = assIdList.get(0);
+ Rental_Apply_Equipment_Set_Detail__c raesd = new Rental_Apply_Equipment_Set_Detail__c();
+ raesd.Id = sequeuece.Apply_Set_Detail__c;
+ raesd.Asset__c = assIdbk;
+ System.debug('raesd.Asset__c' + raesd.Asset__c);
+ raesd.Queue_Number__c = 0; // 鏆傚畾鍒嗛厤
+ updateMap.put(raesd.Id, raesd);
+
+ modelNoAssetIdMap.get(key).remove(assIdbk);
+ if (modelNoAssetIdMap.get(key).isEmpty()) {
+ modelNoAssetIdMap.remove(key);
}
- sequenceMap.get(sequeuece.Externalkey__c).add(sequeuece);
+ System.debug(
+ LoggingLevel.INFO,
+ '*** modelNoAssetIdMap: ' + JSON.serialize(modelNoAssetIdMap)
+ );
+ }
}
- Map<String,Rental_Apply_Equipment_Set_Detail__c> updateMap = new Map<String,Rental_Apply_Equipment_Set_Detail__c>();
- for(String key:sequenceMap.keySet()){
- for(Rental_Apply_Sequence__c sequeuece:sequenceMap.get(key)){
- if(!updateMap.containsKey(sequeuece.Apply_Set_Detail__c)){
- System.debug(LoggingLevel.INFO, '*** modelNoAssetIdMap: ' + JSON.serialize(modelNoAssetIdMap));
- if(modelNoAssetIdMap.containsKey(key)){
- List<Id> assIdList = new List<Id>();
- assIdList.addAll(modelNoAssetIdMap.get(key));
- String assIdbk = assIdList.get(0);
- Rental_Apply_Equipment_Set_Detail__c raesd = new Rental_Apply_Equipment_Set_Detail__c();
- raesd.Id = sequeuece.Apply_Set_Detail__c;
- raesd.Asset__c = assIdbk;
- System.debug('raesd.Asset__c' + raesd.Asset__c);
- raesd.Queue_Number__c = 0; // 鏆傚畾鍒嗛厤
- updateMap.put(raesd.Id,raesd);
+ }
+ }
+ System.debug(
+ LoggingLevel.INFO,
+ '*** updateMap.values(): ' + JSON.serialize(updateMap.values())
+ );
+ update updateMap.values();
+ // Fixture_Model_No_F__c 銈掕銈嬨亾銇ㄣ亴銇с亶銇亜銆併儑銉笺偪銇屻亰銇娿亜銇仹銆�
+ // Fixture_Set_Detail__r.Fixture_Model_No_F__c 銈掋伩銈嬨亱 Fixture_Model_No_text__c 銈掋伩銈嬨亱
+ // whkey += ' (';
+ // whkey += ' ((Fixture_Set_Detail__c != null and Fixture_Set_Detail__r.Product2__r.Fixture_Model_No_T__c =\'' + String.escapeSingleQuotes(nObj.Fixture_Model_No_F__c) + '\')';
+ // whkey += ' OR Fixture_Model_No_text__c =\'' + String.escapeSingleQuotes(nObj.Fixture_Model_No_F__c) + '\'';
+ // whkey += ' )';
- modelNoAssetIdMap.get(key).remove(assIdbk);
- if (modelNoAssetIdMap.get(key).isEmpty()) {
- modelNoAssetIdMap.remove(key);
- }
- System.debug(LoggingLevel.INFO, '*** modelNoAssetIdMap: ' + JSON.serialize(modelNoAssetIdMap));
- }
- }
-
- }
-
+ // String wher = '';
+ // //鏆傚畾鍒嗛厤涓嶇湅瀛樻斁鍦� OLY_OCM-722 鎭㈠瀛樻斁鍦扮殑鏉′欢
+ // if (String.isNotBlank(nObj.Internal_asset_location__c)) {
+ // wher += ' and Internal_asset_location_before__c =\'' + String.escapeSingleQuotes(nObj.Internal_asset_location__c) + '\'';
+ // }
+
+ // if (String.isNotBlank(nObj.Salesdepartment__c)) {
+ // wher += ' and Salesdepartment_before__c =\'' + String.escapeSingleQuotes(nObj.Salesdepartment__c) + '\'';
+ // }
+
+ // if (String.isNotBlank(nObj.Product_category__c)) {
+ // wher += ' and Product_category_text__c =\'' + String.escapeSingleQuotes(nObj.Product_category__c) + '\'';
+ // }
+
+ // if (String.isNotBlank(nObj.Equipment_Type__c)) {
+ // wher += ' and Equipment_Type_text__c =\'' + String.escapeSingleQuotes(nObj.Equipment_Type__c) + '\'';
+ // }
+
+ // whkey += wher + ' ) OR';
+ // }
+
+ // if (String.isNotBlank(whkey)) {
+ // whkey = '( ' + whkey.removeEnd('OR') + ')';
+ // }
+
+ // String soql = 'SELECT Fixture_Model_No_F__c, Substitute_flag__c, Asset__c,'
+ // + ' Queue_Number__c, Fixture_Model_No_text__c, Salesdepartment_before__c,'
+ // + ' Product_category_text__c, Equipment_Type_text__c, Internal_asset_location_before__c'
+ // + ' FROM Rental_Apply_Equipment_Set_Detail__c'
+ // + ' where Id != :raesdIdSet and '
+ // + whkey
+ // + ' and Queue_Number__c > 0'
+ // + ' and Cancel_Select__c = false'
+ // + ' order by Queue_Number__c ASC';
+ // System.debug('whkey' + whkey);
+ // System.debug('soql' + soql);
+ // List<Rental_Apply_Equipment_Set_Detail__c> targetRaesd = Database.query(soql);
+ // System.debug('targetRaesd' + targetRaesd);
+ // for (Rental_Apply_Equipment_Set_Detail__c raesd : targetRaesd) {
+ // // TODO Fixture_Set_Detail__c 銇� 銉併偋銉冦偗杩藉姞 Rental_Apply_Equipment_Set_Detail__c 鏂版暟鎹�, 鏈� 娌℃湁鍒嗛厤(鍒嗛厤鏃堕棿) 鐨勮瘽, 涓嶈兘 Delete Fixture_Set_Detail__c
+ // String key = '';
+ // if (raesd.Substitute_flag__c) {
+ // key = raesd.Fixture_Model_No_text__c;
+ // } else {
+ // key = raesd.Fixture_Model_No_F__c;
+ // }
+ // //鏆傚畾鍒嗛厤涓嶇湅瀛樻斁鍦� OLY_OCM-722 鎭㈠瀛樻斁鍦扮殑鏉′欢
+ // if (String.isNotBlank(raesd.Internal_asset_location_before__c)) {
+ // key += '_' + raesd.Internal_asset_location_before__c;
+ // }
+
+ // 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;
+ // }
+ // if (queueRaesdMap.containsKey(key) == false) {
+ // queueRaesdMap.put(key, new List<Rental_Apply_Equipment_Set_Detail__c>());
+ // }
+ // queueRaesdMap.get(key).add(raesd);
+ // }
+
+ // System.debug('queueRaesdMap' + queueRaesdMap);
+ // System.debug('modelNoAssetIdMap' + modelNoAssetIdMap);
+
+ // List<Rental_Apply_Equipment_Set_Detail__c> uplist = new List<Rental_Apply_Equipment_Set_Detail__c>();
+ // for (String raesdkey : queueRaesdMap.keySet()) {
+ // for (Rental_Apply_Equipment_Set_Detail__c raesd : queueRaesdMap.get(raesdkey)) {
+ // System.debug(raesdkey);
+ // // 杩欓噷鐨剄ueueRaesdMap鍦ㄧ敤瀹屽悗娌℃湁娓呯┖锛屽鑷翠笌鏈�鏂版煡鍑虹殑targetRaesd涓嶄竴鑷�
+ // // 鎷呭績鐩存帴娓呯┖浼氶�犳垚鍏跺畠闂锛屾墍浠ュ姞or鏉ヤ繚璇佹槑缁嗙殑Asset__c鍙細琚洿鏂颁竴娆�
+ // if (modelNoAssetIdMap.containsKey(raesdkey) == false || String.isNotBlank(raesd.Asset__c)) {
+ // // 鍩烘湰鐧虹敓銇椼仾銇勩�乹ueueRaesdMap <= modelNoAssetIdMap
+ // continue;
+ // }
+ // Id assIdbk;
+ // for (Id assId : modelNoAssetIdMap.get(raesdkey)) {
+ // assIdbk = assId;
+ // raesd.Asset__c = assId;
+ // System.debug('raesd.Asset__c' + raesd.Asset__c);
+ // raesd.Queue_Number__c = 0; // 鏆傚畾鍒嗛厤
+ // uplist.add(raesd);
+ // System.debug('raesd Idis' + raesd.Id);
+ // break;
+ // }
+ // modelNoAssetIdMap.get(raesdkey).remove(assIdbk);
+ // if (modelNoAssetIdMap.get(raesdkey).isEmpty()) {
+ // modelNoAssetIdMap.remove(raesdkey);
+ // }
+ // }
+ // }
+
+ // //鎺掗槦鏇存柊
+ // if (!uplist.isEmpty()) {
+ // update uplist;
+ // }
+ }
+
+ //before 鏁板紡銇�ゃ亴null銇仾銈嬪彲鑳芥�с亴銇傘倞銇俱仚銇仹銇撱亾銇с倐涓�鍥炪儊銈с儍銈仐銇俱仚
+ private void formulaToTextCheck() {
+ List<Asset> assets = new List<Asset>();
+ for (Asset nObj : newList) {
+ if (nObj.Fixture_Status2_text__c != nObj.Fixture_Status2__c) {
+ Asset ass = new Asset(Id = nObj.Id);
+ ass.Fixture_Status2_text__c = nObj.Fixture_Status2__c;
+ assets.add(ass);
+ }
+ }
+ if (!assets.isEmpty()) {
+ update assets;
+ }
+ }
+
+ private void checkOneToOneLink() {
+ Set<Id> otoIds = new Set<Id>(); // 寰呭垹闄ink鐨処d
+ Set<Id> assetIds = new Set<Id>();
+ Set<String> centers = new Set<String>{
+ '鍖椾含 澶囧搧涓績',
+ '涓婃捣 澶囧搧涓績',
+ '骞垮窞 澶囧搧涓績'
+ };
+ for (Asset nObj : newList) {
+ //寰呭簾寮冿紝搴熷純锛屽拰鏁伴噺0鐨勫鍝侀渶瑕佹柇寮�涓�瀵逛竴link 锛堢洰鍓嶅彧澶勭悊涓綋绠$悊鐨勶級
+ if (
+ (nObj.Fixture_Status__c ==
+ FixtureUtil.assetFixtureStatusMap.get(
+ FixtureUtil.AssetFixtureStatus.Fei_Qi.ordinal()
+ ) ||
+ nObj.Fixture_Status__c ==
+ FixtureUtil.assetFixtureStatusMap.get(
+ FixtureUtil.AssetFixtureStatus.Dai_Fei_Qi.ordinal()
+ ) ||
+ nObj.Quantity == 0) &&
+ nObj.Manage_type__c ==
+ FixtureUtil.managetypeMap.get(FixtureUtil.Managetype.Ge_Ti_Guan_Li)
+ ) {
+ //鏄竴瀵逛竴涓讳綋鎴栬�呮槸涓�瀵逛竴涓綋闄勫睘鍝�
+ if (
+ nObj.Main_OneToOne__c == true ||
+ nObj.Fixture_OneToOne_Link__c <> null
+ ) {
+ if (centers.contains(nObj.Internal_asset_location__c)) {
+ assetIds.add(nObj.Id);
+ }
}
- System.debug(LoggingLevel.INFO, '*** updateMap.values(): ' + JSON.serialize(updateMap.values()));
- update updateMap.values();
-
- // Fixture_Model_No_F__c 銈掕銈嬨亾銇ㄣ亴銇с亶銇亜銆併儑銉笺偪銇屻亰銇娿亜銇仹銆�
- // Fixture_Set_Detail__r.Fixture_Model_No_F__c 銈掋伩銈嬨亱 Fixture_Model_No_text__c 銈掋伩銈嬨亱
- // whkey += ' (';
- // whkey += ' ((Fixture_Set_Detail__c != null and Fixture_Set_Detail__r.Product2__r.Fixture_Model_No_T__c =\'' + String.escapeSingleQuotes(nObj.Fixture_Model_No_F__c) + '\')';
- // whkey += ' OR Fixture_Model_No_text__c =\'' + String.escapeSingleQuotes(nObj.Fixture_Model_No_F__c) + '\'';
- // whkey += ' )';
-
- // String wher = '';
- // //鏆傚畾鍒嗛厤涓嶇湅瀛樻斁鍦� OLY_OCM-722 鎭㈠瀛樻斁鍦扮殑鏉′欢
- // if (String.isNotBlank(nObj.Internal_asset_location__c)) {
- // wher += ' and Internal_asset_location_before__c =\'' + String.escapeSingleQuotes(nObj.Internal_asset_location__c) + '\'';
- // }
-
- // if (String.isNotBlank(nObj.Salesdepartment__c)) {
- // wher += ' and Salesdepartment_before__c =\'' + String.escapeSingleQuotes(nObj.Salesdepartment__c) + '\'';
- // }
-
- // if (String.isNotBlank(nObj.Product_category__c)) {
- // wher += ' and Product_category_text__c =\'' + String.escapeSingleQuotes(nObj.Product_category__c) + '\'';
- // }
-
- // if (String.isNotBlank(nObj.Equipment_Type__c)) {
- // wher += ' and Equipment_Type_text__c =\'' + String.escapeSingleQuotes(nObj.Equipment_Type__c) + '\'';
- // }
-
- // whkey += wher + ' ) OR';
- // }
-
-
-
- // if (String.isNotBlank(whkey)) {
- // whkey = '( ' + whkey.removeEnd('OR') + ')';
- // }
-
-
-
- // String soql = 'SELECT Fixture_Model_No_F__c, Substitute_flag__c, Asset__c,'
- // + ' Queue_Number__c, Fixture_Model_No_text__c, Salesdepartment_before__c,'
- // + ' Product_category_text__c, Equipment_Type_text__c, Internal_asset_location_before__c'
- // + ' FROM Rental_Apply_Equipment_Set_Detail__c'
- // + ' where Id != :raesdIdSet and '
- // + whkey
- // + ' and Queue_Number__c > 0'
- // + ' and Cancel_Select__c = false'
- // + ' order by Queue_Number__c ASC';
- // System.debug('whkey' + whkey);
- // System.debug('soql' + soql);
- // List<Rental_Apply_Equipment_Set_Detail__c> targetRaesd = Database.query(soql);
- // System.debug('targetRaesd' + targetRaesd);
- // for (Rental_Apply_Equipment_Set_Detail__c raesd : targetRaesd) {
- // // TODO Fixture_Set_Detail__c 銇� 銉併偋銉冦偗杩藉姞 Rental_Apply_Equipment_Set_Detail__c 鏂版暟鎹�, 鏈� 娌℃湁鍒嗛厤(鍒嗛厤鏃堕棿) 鐨勮瘽, 涓嶈兘 Delete Fixture_Set_Detail__c
- // String key = '';
- // if (raesd.Substitute_flag__c) {
- // key = raesd.Fixture_Model_No_text__c;
- // } else {
- // key = raesd.Fixture_Model_No_F__c;
- // }
- // //鏆傚畾鍒嗛厤涓嶇湅瀛樻斁鍦� OLY_OCM-722 鎭㈠瀛樻斁鍦扮殑鏉′欢
- // if (String.isNotBlank(raesd.Internal_asset_location_before__c)) {
- // key += '_' + raesd.Internal_asset_location_before__c;
- // }
-
- // 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;
- // }
- // if (queueRaesdMap.containsKey(key) == false) {
- // queueRaesdMap.put(key, new List<Rental_Apply_Equipment_Set_Detail__c>());
- // }
- // queueRaesdMap.get(key).add(raesd);
- // }
-
- // System.debug('queueRaesdMap' + queueRaesdMap);
- // System.debug('modelNoAssetIdMap' + modelNoAssetIdMap);
-
- // List<Rental_Apply_Equipment_Set_Detail__c> uplist = new List<Rental_Apply_Equipment_Set_Detail__c>();
- // for (String raesdkey : queueRaesdMap.keySet()) {
- // for (Rental_Apply_Equipment_Set_Detail__c raesd : queueRaesdMap.get(raesdkey)) {
- // System.debug(raesdkey);
- // // 杩欓噷鐨剄ueueRaesdMap鍦ㄧ敤瀹屽悗娌℃湁娓呯┖锛屽鑷翠笌鏈�鏂版煡鍑虹殑targetRaesd涓嶄竴鑷�
- // // 鎷呭績鐩存帴娓呯┖浼氶�犳垚鍏跺畠闂锛屾墍浠ュ姞or鏉ヤ繚璇佹槑缁嗙殑Asset__c鍙細琚洿鏂颁竴娆�
- // if (modelNoAssetIdMap.containsKey(raesdkey) == false || String.isNotBlank(raesd.Asset__c)) {
- // // 鍩烘湰鐧虹敓銇椼仾銇勩�乹ueueRaesdMap <= modelNoAssetIdMap
- // continue;
- // }
- // Id assIdbk;
- // for (Id assId : modelNoAssetIdMap.get(raesdkey)) {
- // assIdbk = assId;
- // raesd.Asset__c = assId;
- // System.debug('raesd.Asset__c' + raesd.Asset__c);
- // raesd.Queue_Number__c = 0; // 鏆傚畾鍒嗛厤
- // uplist.add(raesd);
- // System.debug('raesd Idis' + raesd.Id);
- // break;
- // }
- // modelNoAssetIdMap.get(raesdkey).remove(assIdbk);
- // if (modelNoAssetIdMap.get(raesdkey).isEmpty()) {
- // modelNoAssetIdMap.remove(raesdkey);
- // }
- // }
- // }
-
- // //鎺掗槦鏇存柊
- // if (!uplist.isEmpty()) {
- // update uplist;
- // }
+ }
}
- //before 鏁板紡銇�ゃ亴null銇仾銈嬪彲鑳芥�с亴銇傘倞銇俱仚銇仹銇撱亾銇с倐涓�鍥炪儊銈с儍銈仐銇俱仚
- private void formulaToTextCheck() {
- List<Asset> assets = new List<Asset>();
- for (Asset nObj : newList) {
- if (nObj.Fixture_Status2_text__c != nObj.Fixture_Status2__c) {
- Asset ass = new Asset(Id = nObj.Id);
- ass.Fixture_Status2_text__c = nObj.Fixture_Status2__c;
- assets.add(ass);
- }
- }
- if (!assets.isEmpty()) {
- update assets;
- }
+ if (assetIds.size() > 0) {
+ Map<Id, Fixture_OneToOne_Link__c> linkMap = new Map<Id, Fixture_OneToOne_Link__c>(
+ [
+ SELECT Id
+ FROM Fixture_OneToOne_Link__c
+ WHERE Main_Asset__c IN :assetIds OR Accessory_Asset__c IN :assetIds
+ ]
+ );
+ if (!linkMap.isEmpty()) {
+ delete linkMap.values();
+ }
}
+ }
- private void checkOneToOneLink() {
- Set<Id> otoIds = new Set<Id>(); // 寰呭垹闄ink鐨処d
- Set<Id> assetIds = new Set<Id>();
- Set<String> centers = new Set<String> {'鍖椾含 澶囧搧涓績', '涓婃捣 澶囧搧涓績', '骞垮窞 澶囧搧涓績'};
- for (Asset nObj : newList) {
- //寰呭簾寮冿紝搴熷純锛屽拰鏁伴噺0鐨勫鍝侀渶瑕佹柇寮�涓�瀵逛竴link 锛堢洰鍓嶅彧澶勭悊涓綋绠$悊鐨勶級
- if ((nObj.Fixture_Status__c == FixtureUtil.assetFixtureStatusMap.get(FixtureUtil.AssetFixtureStatus.Fei_Qi.ordinal())
- || nObj.Fixture_Status__c == FixtureUtil.assetFixtureStatusMap.get(FixtureUtil.AssetFixtureStatus.Dai_Fei_Qi.ordinal())
- || nObj.Quantity == 0) && nObj.Manage_type__c == FixtureUtil.managetypeMap.get(FixtureUtil.Managetype.Ge_Ti_Guan_Li)){
- //鏄竴瀵逛竴涓讳綋鎴栬�呮槸涓�瀵逛竴涓綋闄勫睘鍝�
- if (nObj.Main_OneToOne__c == true || nObj.Fixture_OneToOne_Link__c <> null) {
- if(centers.contains(nObj.Internal_asset_location__c)) {
- assetIds.add(nObj.Id);
- }
- }
- }
- }
+ /**
+ * 鍔ㄦ�佽瀹� Asset.AccountId (澶囧搧鍏变韩_鏉窞_鍗庝笢钀ヤ笟鏈儴)
+ * Condition:
+ * - before insert, before update
+ * - 纭瀛楁鍙樺寲 锛堜繚鏈夎澶囩殑澶囧搧瀛樻斁鍦帮紙Internal_asset_location__c锛�+鎵�鍦ㄥ湴鍖�(鏈儴)锛圫alesdepartment__c锛夛級
+ * - Salesdepartment__c IN ('1.鍗庡寳钀ヤ笟鏈儴','2.涓滃寳钀ヤ笟鏈儴','3.瑗垮寳钀ヤ笟鏈儴','4.鍗庝笢钀ヤ笟鏈儴','5.鍗庡崡钀ヤ笟鏈儴','6.瑗垮崡钀ヤ笟鏈儴')
+ * - Asset 鏄� 鍔炰簨澶勫鍝�
+ * Execute:
+ * - 鎵� Label: OCM_Management_Province_Mapping, 鐨� 鍔炰簨澶�, 璁惧畾 AccountId
+ * - 娌℃湁鎵剧殑璇�, 涓嶆洿鏂癆ccountId, 鑷姩鍋� Account, Group, ApexShare
+ */
+ private void beforeSetAccountId() {
+ Set<String> targetDepts = new Set<String>{
+ '1.鍗庡寳钀ヤ笟鏈儴',
+ '2.涓滃寳钀ヤ笟鏈儴',
+ '3.瑗垮寳钀ヤ笟鏈儴',
+ '4.鍗庝笢钀ヤ笟鏈儴',
+ '5.鍗庡崡钀ヤ笟鏈儴',
+ '6.瑗垮崡钀ヤ笟鏈儴'
+ };
+ Set<String> targetCenters = new Set<String>{
+ '鍖椾含 澶囧搧涓績',
+ '涓婃捣 澶囧搧涓績',
+ '骞垮窞 澶囧搧涓績'
+ };
+ if (Test.isRunningTest() && testTargetDepts != null) {
+ targetDepts = testTargetDepts;
+ }
+ // 瀛樻斁鍦� 鈫� 鐪� 鐨� Map
+ Map<String, String> targetProvs = AssetWebService.getOcmMgtProvMap();
- if (assetIds.size() > 0) {
- Map<Id, Fixture_OneToOne_Link__c> linkMap = new Map<Id, Fixture_OneToOne_Link__c>([
+ // 鏀堕泦瀵硅薄 Asset
+ Map<Asset, String> assetAccShareNameMap = new Map<Asset, String>();
+ Datetime execNow = System.now();
+ for (Asset nObj : newList) {
+ Asset oObj = (null == this.oldMap) ? null : this.oldMap.get(nObj.Id);
+
+ // 浣滄垚, 纭瀛楁鏈夋病鏈夊彉鍖�
+ if (
+ Trigger.isInsert ||
+ (oObj != null &&
+ (oObj.RecordTypeId != nObj.RecordTypeId ||
+ oObj.Asset_loaner_category__c != nObj.Asset_loaner_category__c ||
+ oObj.AssetManageConfirm__c != nObj.AssetManageConfirm__c ||
+ oObj.Internal_asset_location__c != nObj.Internal_asset_location__c ||
+ oObj.Salesdepartment__c != nObj.Salesdepartment__c ||
+ oObj.OlympusAccShareName__c != nObj.OlympusAccShareName__c) &&
+ (targetCenters.contains(nObj.Internal_asset_location__c) ||
+ targetProvs.containsKey(nObj.Internal_asset_location__c)) &&
+ !nObj.TransferToOther__c)
+ ) {
+ // 鏄笉鏄鍝佺殑纭
+ if (
+ System.Label.Asset_RecordType == nObj.RecordTypeId &&
+ true == nObj.AssetManageConfirm__c &&
+ nObj.Asset_loaner_category__c != '鑰楁潗'
+ ) {
+ // 鍔炰簨澶勫鍝� 鈫� 鍔ㄦ�佽瀹� Asset.AccountId 鐨勫璞�
+ if (
+ targetProvs.containsKey(nObj.Internal_asset_location__c) &&
+ targetDepts.contains(nObj.Salesdepartment__c)
+ ) {
+ String accShareName =
+ '澶囧搧鍏变韩_' +
+ targetProvs.get(nObj.Internal_asset_location__c) +
+ '_' +
+ nObj.Salesdepartment__c.right(6);
+ nObj.OlympusAccShareName__c = accShareName;
+ assetAccShareNameMap.put(nObj, accShareName);
+ } else {
+ if (AssetHandler.Account_Asset_Id == null) {
+ // Static 鍙細鎵ц涓�閬�
+ AssetHandler.Account_Asset_Id = [
SELECT Id
- FROM Fixture_OneToOne_Link__c
- WHERE Main_Asset__c in :assetIds
- OR Accessory_Asset__c IN: assetIds
- ]);
- if(!linkMap.isEmpty()){
- delete linkMap.values();
+ FROM Account
+ WHERE AgentCode_Ext__c = :System.Label.Account_Asset
+ ]
+ .Id;
}
+ nObj.OlympusAccShareName__c = '';
+ nObj.AccountId = AssetHandler.Account_Asset_Id;
+ }
+ } else {
+ // 鏇存柊鎴� 涓嶆槸澶囧搧 鐨勬椂鍊�, 鏇存柊鐨勭▼搴忛噷 瑕� care AccountId
+ nObj.OlympusAccShareName__c = '';
}
+ }
}
- /**
- * 鍔ㄦ�佽瀹� Asset.AccountId (澶囧搧鍏变韩_鏉窞_鍗庝笢钀ヤ笟鏈儴)
- * Condition:
- * - before insert, before update
- * - 纭瀛楁鍙樺寲 锛堜繚鏈夎澶囩殑澶囧搧瀛樻斁鍦帮紙Internal_asset_location__c锛�+鎵�鍦ㄥ湴鍖�(鏈儴)锛圫alesdepartment__c锛夛級
- * - Salesdepartment__c IN ('1.鍗庡寳钀ヤ笟鏈儴','2.涓滃寳钀ヤ笟鏈儴','3.瑗垮寳钀ヤ笟鏈儴','4.鍗庝笢钀ヤ笟鏈儴','5.鍗庡崡钀ヤ笟鏈儴','6.瑗垮崡钀ヤ笟鏈儴')
- * - Asset 鏄� 鍔炰簨澶勫鍝�
- * Execute:
- * - 鎵� Label: OCM_Management_Province_Mapping, 鐨� 鍔炰簨澶�, 璁惧畾 AccountId
- * - 娌℃湁鎵剧殑璇�, 涓嶆洿鏂癆ccountId, 鑷姩鍋� Account, Group, ApexShare
- */
- private void beforeSetAccountId() {
- Set<String> targetDepts = new Set<String> {'1.鍗庡寳钀ヤ笟鏈儴','2.涓滃寳钀ヤ笟鏈儴','3.瑗垮寳钀ヤ笟鏈儴','4.鍗庝笢钀ヤ笟鏈儴','5.鍗庡崡钀ヤ笟鏈儴','6.瑗垮崡钀ヤ笟鏈儴'};
- Set<String> targetCenters = new Set<String> {'鍖椾含 澶囧搧涓績', '涓婃捣 澶囧搧涓績', '骞垮窞 澶囧搧涓績'};
- if (Test.isRunningTest() && testTargetDepts != null) {
- targetDepts = testTargetDepts;
- }
- // 瀛樻斁鍦� 鈫� 鐪� 鐨� Map
- Map<String, String> targetProvs = AssetWebService.getOcmMgtProvMap();
+ // check 鏄笉鏄� accShareName 閮芥湁
+ Set<String> insertAccShareNameSet = new Set<String>();
+ if (assetAccShareNameMap.size() > 0) {
+ Map<String, Id> accShareId = new Map<String, Id>();
+ for (Account accShare : [
+ SELECT Id, Department_Name__c
+ FROM Account
+ WHERE
+ RecordTypeId = :System.Label.Department_OTH
+ AND Department_Name__c IN :assetAccShareNameMap.values()
+ ]) {
+ accShareId.put(accShare.Department_Name__c, accShare.Id);
+ }
- // 鏀堕泦瀵硅薄 Asset
- Map<Asset, String> assetAccShareNameMap = new Map<Asset, String>();
- Datetime execNow = System.now();
- for (Asset nObj : newList) {
- Asset oObj = (null == this.oldMap) ? null : this.oldMap.get(nObj.Id);
-
- // 浣滄垚, 纭瀛楁鏈夋病鏈夊彉鍖�
- if (Trigger.isInsert
- || (oObj != null
- && (oObj.RecordTypeId != nObj.RecordTypeId
- || oObj.Asset_loaner_category__c != nObj.Asset_loaner_category__c
- || oObj.AssetManageConfirm__c != nObj.AssetManageConfirm__c
- || oObj.Internal_asset_location__c != nObj.Internal_asset_location__c
- || oObj.Salesdepartment__c != nObj.Salesdepartment__c
- || oObj.OlympusAccShareName__c != nObj.OlympusAccShareName__c
- )
- && (targetCenters.contains(nObj.Internal_asset_location__c)
- || targetProvs.containsKey(nObj.Internal_asset_location__c)
- )
- && !nObj.TransferToOther__c
- )
- ) {
- // 鏄笉鏄鍝佺殑纭
- if (System.Label.Asset_RecordType == nObj.RecordTypeId
- && true == nObj.AssetManageConfirm__c
- && nObj.Asset_loaner_category__c != '鑰楁潗'
- ) {
- // 鍔炰簨澶勫鍝� 鈫� 鍔ㄦ�佽瀹� Asset.AccountId 鐨勫璞�
- if (targetProvs.containsKey(nObj.Internal_asset_location__c)
- && targetDepts.contains(nObj.Salesdepartment__c)
- ) {
- String accShareName = '澶囧搧鍏变韩_'
- + targetProvs.get(nObj.Internal_asset_location__c) + '_' + nObj.Salesdepartment__c.right(6);
- nObj.OlympusAccShareName__c = accShareName;
- assetAccShareNameMap.put(nObj, accShareName);
- }
- else {
- if (AssetHandler.Account_Asset_Id == null) {
- // Static 鍙細鎵ц涓�閬�
- AssetHandler.Account_Asset_Id = [SELECT Id FROM Account WHERE AgentCode_Ext__c =: System.Label.Account_Asset].Id;
- }
- nObj.OlympusAccShareName__c = '';
- nObj.AccountId = AssetHandler.Account_Asset_Id;
- }
- } else {
- // 鏇存柊鎴� 涓嶆槸澶囧搧 鐨勬椂鍊�, 鏇存柊鐨勭▼搴忛噷 瑕� care AccountId
- nObj.OlympusAccShareName__c = '';
- }
- }
+ // assetAccShareNameMap 鐨� Key浼氭湁鍙樺寲
+ // 杩欎釜 for loop鍚� 灏变笉鑳戒娇鐢� assetAccShareNameMap.get(XXXX) 浜�
+ for (Asset nObj : assetAccShareNameMap.keySet()) {
+ String accShareName = assetAccShareNameMap.get(nObj);
+ if (accShareId.containsKey(accShareName)) {
+ // 鎵惧埌 Account 璁惧畾 AccountId, "Olympus绀惧唴 鍏朵粬 澶囧搧" => "Olympus绀惧唴 鍏朵粬 澶囧搧鍏变韩_XXX"
+ nObj.AccountId = accShareId.get(accShareName);
+ } else {
+ // 鎵句笉鍒� AccountId, 鏂板缓 Account, Group, ApexShare
+ insertAccShareNameSet.add(accShareName);
}
+ }
+ }
+ if (insertAccShareNameSet.size() > 0) {
+ // AssetHandler.futureInsertAccShare(JSON.serialize(insertAccShareNameSet), execNow);
+ System.enqueueJob(
+ new MyQueueableClass(JSON.serialize(insertAccShareNameSet), execNow)
+ );
+ }
+ }
- // check 鏄笉鏄� accShareName 閮芥湁
- Set<String> insertAccShareNameSet = new Set<String>();
- if (assetAccShareNameMap.size() > 0) {
- Map<String, Id> accShareId = new Map<String, Id>();
- for (Account accShare : [SELECT Id
- , Department_Name__c
- FROM Account
- WHERE RecordTypeId =: System.Label.Department_OTH
- AND Department_Name__c IN: assetAccShareNameMap.values()]) {
- accShareId.put(accShare.Department_Name__c, accShare.Id);
- }
-
- // assetAccShareNameMap 鐨� Key浼氭湁鍙樺寲
- // 杩欎釜 for loop鍚� 灏变笉鑳戒娇鐢� assetAccShareNameMap.get(XXXX) 浜�
- for (Asset nObj : assetAccShareNameMap.keySet()) {
- String accShareName = assetAccShareNameMap.get(nObj);
- if (accShareId.containsKey(accShareName)) {
- // 鎵惧埌 Account 璁惧畾 AccountId, "Olympus绀惧唴 鍏朵粬 澶囧搧" => "Olympus绀惧唴 鍏朵粬 澶囧搧鍏变韩_XXX"
- nObj.AccountId = accShareId.get(accShareName);
- }
- else {
- // 鎵句笉鍒� AccountId, 鏂板缓 Account, Group, ApexShare
- insertAccShareNameSet.add(accShareName);
- }
- }
- }
- if (insertAccShareNameSet.size() > 0) {
- // AssetHandler.futureInsertAccShare(JSON.serialize(insertAccShareNameSet), execNow);
- System.enqueueJob(new MyQueueableClass(JSON.serialize(insertAccShareNameSet), execNow));
- }
+ /**
+ * 鏂板缓 澶囧搧鍏变韩_XXX 瀹㈡埛鏁版嵁
+ * @param insertAccShareNameJson Json String of List<String> ["澶囧搧鍏变韩_XXX", "澶囧搧鍏变韩_YYY"]
+ */
+ private static void insertAccShare(
+ String insertAccShareNameJson,
+ Datetime execNow
+ ) {
+ Set<String> insertAccShareNameSet = (Set<String>) JSON.deserialize(
+ insertAccShareNameJson,
+ Set<String>.class
+ );
+ if (insertAccShareNameSet.isEmpty()) {
+ return;
}
- /**
- * 鏂板缓 澶囧搧鍏变韩_XXX 瀹㈡埛鏁版嵁
- * @param insertAccShareNameJson Json String of List<String> ["澶囧搧鍏变韩_XXX", "澶囧搧鍏变韩_YYY"]
- */
- private static void insertAccShare(String insertAccShareNameJson, Datetime execNow) {
- Set<String> insertAccShareNameSet = (Set<String>) JSON.deserialize(insertAccShareNameJson, Set<String>.class);
- if (insertAccShareNameSet.isEmpty()) { return; }
-
- // Olympus绀惧唴 鍏朵粬
- List<Account> olympusAccount_OtherDC;
- try {
- olympusAccount_OtherDC = [SELECT Id, ParentId
- FROM Account
- WHERE Parent.AgentCode_Ext__c = '9999999' AND Department_Class_Name__c = '鍏朵粬'
- FOR Update];
- } catch (Exception e) {
- System.enqueueJob(new MyQueueableClass(insertAccShareNameJson, execNow));
- return;
- }
-
- List<Account> isInsertedList = [SELECT Id, Department_Name__c
- FROM Account
- WHERE ParentId =: olympusAccount_OtherDC[0].Id
- AND Department_Name__c IN: insertAccShareNameSet];
- if (isInsertedList.size() > 0) {
- Map<String, Account> insertedAccount = new Map<String, Account>();
- for (Account insertedAcc : isInsertedList) {
- insertedAccount.put(insertedAcc.Department_Name__c, insertedAcc);
- insertAccShareNameSet.remove(insertedAcc.Department_Name__c);
- }
- // Update Asset.AccountId
- AssetHandler.updateAssetAccount(insertedAccount, execNow);
- }
-
-
- if (insertAccShareNameSet.size() > 0) {
- Map<String, Account> insertAccount = new Map<String, Account>();
- for (String accShareName : insertAccShareNameSet) {
- insertAccount.put(accShareName, new Account(
- Name = '*',
- Hospital__c = olympusAccount_OtherDC[0].ParentId,
- ParentId = olympusAccount_OtherDC[0].Id,
- Department_Class__c = olympusAccount_OtherDC[0].Id,
- Other_dept_category__c = '鍏朵粬绉戝',
- Department_Name__c = accShareName,
- OwnerId = System.Label.Batch_User_Id,
- RecordTypeId = System.Label.Department_OTH
- ));
- }
- AssetHandler.insertAccGrantShare(insertAccount, execNow);
- }
+ // Olympus绀惧唴 鍏朵粬
+ List<Account> olympusAccount_OtherDC;
+ try {
+ olympusAccount_OtherDC = [
+ SELECT Id, ParentId
+ FROM Account
+ WHERE
+ Parent.AgentCode_Ext__c = '9999999'
+ AND Department_Class_Name__c = '鍏朵粬'
+ FOR UPDATE
+ ];
+ } catch (Exception e) {
+ System.enqueueJob(new MyQueueableClass(insertAccShareNameJson, execNow));
+ return;
}
- private static void insertAccGrantShare(Map<String, Account> insertAccountMap, Datetime execNow) {
- if (insertAccountMap.isEmpty()) { return; }
- Set<String> accShareNameSet = insertAccountMap.keySet();
- // insert Account鐨勬椂鍊�, 璺宠繃 NFM001
- // OLY_OCM-1230 闇�瑕佹墽琛孨FM001Trigger
- // ControllerUtil.EscapeNFM001Trigger = true;
- insert insertAccountMap.values();
-
- Map<String, Group> insertGroup = new Map<String, Group>();
- Map<String, Group> groupNameMap = new Map<String, Group>();
- for (String accShareName : accShareNameSet) {
- insertGroup.put(accShareName, new Group(
- Name = accShareName
- ));
- }
-
- // Check 鏈夋病鏈� Group
- for (Group grp : [SELECT Id, Name FROM Group WHERE Type = 'Regular' AND Name IN: accShareNameSet]) {
- // 宸茬粡鏈塆roup 鐨勮瘽 涓嶇敤 insert
- insertGroup.remove(grp.Name);
- groupNameMap.put(grp.Name, grp);
- }
- if (insertGroup.size() > 0) {
- insert insertGroup.values();
- // groupNameMap 鍚� 鎵�鏈� accShareNameSet 鐨� Group, 骞朵笖 閮芥湁 Id
- groupNameMap.putAll(insertGroup);
- }
-
- // 璧� Account 鍏变韩鏉冮檺
- List<AccountShare> insertShareList = new List<AccountShare>();
- for (String accShareName : accShareNameSet) {
- insertShareList.add(new AccountShare(
- UserOrGroupId = groupNameMap.get(accShareName).Id,
- AccountId = insertAccountMap.get(accShareName).Id,
- AccountAccessLevel = 'Edit',
- OpportunityAccessLevel = 'None'
- ));
- }
- insert insertShareList;
- // Update Asset.AccountId
- AssetHandler.updateAssetAccount(insertAccountMap, execNow);
+ List<Account> isInsertedList = [
+ SELECT Id, Department_Name__c
+ FROM Account
+ WHERE
+ ParentId = :olympusAccount_OtherDC[0].Id
+ AND Department_Name__c IN :insertAccShareNameSet
+ ];
+ if (isInsertedList.size() > 0) {
+ Map<String, Account> insertedAccount = new Map<String, Account>();
+ for (Account insertedAcc : isInsertedList) {
+ insertedAccount.put(insertedAcc.Department_Name__c, insertedAcc);
+ insertAccShareNameSet.remove(insertedAcc.Department_Name__c);
+ }
+ // Update Asset.AccountId
+ AssetHandler.updateAssetAccount(insertedAccount, execNow);
}
- private static void updateAssetAccount(Map<String, Account> accShareNameAccountMap, Datetime execNow) {
- if (accShareNameAccountMap.isEmpty()) { return; }
- Set<String> accShareNameSet = accShareNameAccountMap.keySet();
+ if (insertAccShareNameSet.size() > 0) {
+ Map<String, Account> insertAccount = new Map<String, Account>();
+ for (String accShareName : insertAccShareNameSet) {
+ insertAccount.put(
+ accShareName,
+ new Account(
+ Name = '*',
+ Hospital__c = olympusAccount_OtherDC[0].ParentId,
+ ParentId = olympusAccount_OtherDC[0].Id,
+ Department_Class__c = olympusAccount_OtherDC[0].Id,
+ Other_dept_category__c = '鍏朵粬绉戝',
+ Department_Name__c = accShareName,
+ OwnerId = System.Label.Batch_User_Id,
+ RecordTypeId = System.Label.Department_OTH
+ )
+ );
+ }
+ AssetHandler.insertAccGrantShare(insertAccount, execNow);
+ }
+ }
- List<Asset> updAssetAccount = new List<Asset>();
- for (Asset nObj : [SELECT Id, OlympusAccShareName__c, AccountId
- FROM Asset
- WHERE OlympusAccShareSameFlag__c = '0'
- AND OlympusAccShareName__c IN: accShareNameSet
- AND LastModifiedDate >=: execNow]) {
- nObj.AccountId = accShareNameAccountMap.get(nObj.OlympusAccShareName__c).Id;
- updAssetAccount.add(nObj);
- }
- update updAssetAccount;
+ private static void insertAccGrantShare(
+ Map<String, Account> insertAccountMap,
+ Datetime execNow
+ ) {
+ if (insertAccountMap.isEmpty()) {
+ return;
+ }
+ Set<String> accShareNameSet = insertAccountMap.keySet();
+ // insert Account鐨勬椂鍊�, 璺宠繃 NFM001
+ // OLY_OCM-1230 闇�瑕佹墽琛孨FM001Trigger
+ // ControllerUtil.EscapeNFM001Trigger = true;
+ insert insertAccountMap.values();
+
+ Map<String, Group> insertGroup = new Map<String, Group>();
+ Map<String, Group> groupNameMap = new Map<String, Group>();
+ for (String accShareName : accShareNameSet) {
+ insertGroup.put(accShareName, new Group(Name = accShareName));
}
- @TestVisible
- class MyQueueableClass implements Queueable {
- String insertAccShareNameJson;
- Datetime execNow;
-
- public MyQueueableClass(String insertAccShareNameJson, Datetime execNow) {
- this.insertAccShareNameJson = insertAccShareNameJson;
- this.execNow = execNow;
- }
-
- public void execute(QueueableContext context) {
- AssetHandler.insertAccShare(insertAccShareNameJson, execNow);
- }
+ // Check 鏈夋病鏈� Group
+ for (Group grp : [
+ SELECT Id, Name
+ FROM Group
+ WHERE Type = 'Regular' AND Name IN :accShareNameSet
+ ]) {
+ // 宸茬粡鏈塆roup 鐨勮瘽 涓嶇敤 insert
+ insertGroup.remove(grp.Name);
+ groupNameMap.put(grp.Name, grp);
}
-}
\ No newline at end of file
+ if (insertGroup.size() > 0) {
+ insert insertGroup.values();
+ // groupNameMap 鍚� 鎵�鏈� accShareNameSet 鐨� Group, 骞朵笖 閮芥湁 Id
+ groupNameMap.putAll(insertGroup);
+ }
+
+ // 璧� Account 鍏变韩鏉冮檺
+ List<AccountShare> insertShareList = new List<AccountShare>();
+ for (String accShareName : accShareNameSet) {
+ insertShareList.add(
+ new AccountShare(
+ UserOrGroupId = groupNameMap.get(accShareName).Id,
+ AccountId = insertAccountMap.get(accShareName).Id,
+ AccountAccessLevel = 'Edit',
+ OpportunityAccessLevel = 'None'
+ )
+ );
+ }
+ insert insertShareList;
+ // Update Asset.AccountId
+ AssetHandler.updateAssetAccount(insertAccountMap, execNow);
+ }
+
+ private static void updateAssetAccount(
+ Map<String, Account> accShareNameAccountMap,
+ Datetime execNow
+ ) {
+ if (accShareNameAccountMap.isEmpty()) {
+ return;
+ }
+ Set<String> accShareNameSet = accShareNameAccountMap.keySet();
+
+ List<Asset> updAssetAccount = new List<Asset>();
+ for (Asset nObj : [
+ SELECT Id, OlympusAccShareName__c, AccountId
+ FROM Asset
+ WHERE
+ OlympusAccShareSameFlag__c = '0'
+ AND OlympusAccShareName__c IN :accShareNameSet
+ AND LastModifiedDate >= :execNow
+ ]) {
+ nObj.AccountId = accShareNameAccountMap.get(nObj.OlympusAccShareName__c)
+ .Id;
+ updAssetAccount.add(nObj);
+ }
+ update updAssetAccount;
+ }
+
+ @TestVisible
+ class MyQueueableClass implements Queueable {
+ String insertAccShareNameJson;
+ Datetime execNow;
+
+ public MyQueueableClass(String insertAccShareNameJson, Datetime execNow) {
+ this.insertAccShareNameJson = insertAccShareNameJson;
+ this.execNow = execNow;
+ }
+
+ public void execute(QueueableContext context) {
+ AssetHandler.insertAccShare(insertAccShareNameJson, execNow);
+ }
+ }
+}
--
Gitblit v1.9.1