| trigger OpponentBidInformation2Asset on Opponent_Bid_Information__c (after delete, after insert, after update) { | 
| // 2018年7月12日 为'对手中标信息'添加trigger by 张玉山 | 
|     List<Opponent_Bid_Information__c> targetInsertObis = new List<Opponent_Bid_Information__c>(); | 
|     List<Opponent_Bid_Information__c> targetUpdateObis = new List<Opponent_Bid_Information__c>(); | 
|     List<Id> delAstIds = new List<Id>(); | 
|     List<String> OppoList = new List<String>(); | 
|     if (Trigger.isInsert) { | 
|         for (Opponent_Bid_Information__c obi : Trigger.new) { | 
|             if (obi.RecordType_DevName__c == 'OpponentBidInformation' && obi.HP_RecordType_DevName__c == 'HP') { | 
|                 targetInsertObis.add(obi); | 
|             } | 
|             OppoList.add(obi.Opportunity__c); | 
|         } | 
|         system.debug('1234' + targetInsertObis); | 
|         //ControllerUtil.updateSIodcList(OppoList);//询价失单,SI需求表无效化 | 
|     } | 
|     else if (Trigger.isUpdate) { | 
|         for (Opponent_Bid_Information__c obi : Trigger.new) { | 
|             if (obi.RecordType_DevName__c == 'OpponentBidInformation' && obi.HP_RecordType_DevName__c == 'HP' | 
|                 && (obi.CompetitorProduct1__c != Trigger.oldMap.get(obi.Id).get('CompetitorProduct1__c') | 
|                     || obi.CompetitorProduct2__c != Trigger.oldMap.get(obi.Id).get('CompetitorProduct2__c') | 
|                     || obi.CompetitorProduct3__c != Trigger.oldMap.get(obi.Id).get('CompetitorProduct3__c') | 
|                     || obi.CompetitorProduct4__c != Trigger.oldMap.get(obi.Id).get('CompetitorProduct4__c') | 
|                 ) | 
|             ) { | 
|                 targetUpdateObis.add(obi); | 
|             } | 
|         } | 
|     } | 
|     else if (Trigger.isDelete) { | 
|         for (Opponent_Bid_Information__c obi : Trigger.old) { | 
|             if (obi.CompetitorAsset1__c != null) { | 
|                 delAstIds.add(obi.CompetitorAsset1__c); | 
|             } | 
|             if (obi.CompetitorAsset2__c != null) { | 
|                 delAstIds.add(obi.CompetitorAsset2__c); | 
|             } | 
|             if (obi.CompetitorAsset3__c != null) { | 
|                 delAstIds.add(obi.CompetitorAsset3__c); | 
|             } | 
|             if (obi.CompetitorAsset4__c != null) { | 
|                 delAstIds.add(obi.CompetitorAsset4__c); | 
|             } | 
|         } | 
|     } | 
|      | 
|     if (targetInsertObis.size() > 0 || targetUpdateObis.size() > 0) { | 
|         Map<String, Asset> upsertAstMap = new Map<String, Asset>();   // obi.id + 枝番 ==> Asset  | 
|         for (Opponent_Bid_Information__c obi : [ | 
|                  Select CompetitorAsset1__c, CompetitorProduct1__c, | 
|                         CompetitorAsset2__c, CompetitorProduct2__c, | 
|                         CompetitorAsset3__c, CompetitorProduct3__c, | 
|                         CompetitorAsset4__c, CompetitorProduct4__c, | 
|                         Opportunity__c, Submit_Day__c, | 
|                         Lost_By_Product__c, | 
|                         Lost_By_Brand__c, | 
|                         Opportunity__r.Hospital__c, Opportunity__r.Department_Class__c, Opportunity__r.AccountId | 
|                    From Opponent_Bid_Information__c | 
|                   Where (id IN :targetInsertObis or id IN :targetUpdateObis) | 
|                 ] | 
|         ) { | 
|             if (obi.CompetitorProduct1__c != null) { | 
|                 Asset upsertAssert = new Asset( | 
|                     Id = obi.CompetitorAsset1__c, | 
|                     Name = '*', | 
|                     Product2Id = obi.CompetitorProduct1__c, | 
|                     Opportunity__c = obi.Opportunity__c, | 
|                     InstallDate = obi.Submit_Day__c, | 
|                     Hospital__c = obi.Opportunity__r.Hospital__c, | 
|                     Department_Class__c = obi.Opportunity__r.Department_Class__c, | 
|                     AccountId = obi.Opportunity__r.AccountId, | 
|                     Status = '使用中', | 
|                     Asset_Owner__c = '病院資産', | 
|                     IsCompetitorProduct = True | 
|                 ); | 
|                 if(obi.Lost_By_Product__c != null){ | 
|                     upsertAssert.Manual_competitor_product_code__c = obi.Lost_By_Product__c; | 
|                 } | 
|                 if(obi.Lost_By_Brand__c != null){ | 
|                     upsertAssert.Manual_competitor_product_company__c = obi.Lost_By_Brand__c; | 
|                 } | 
|   | 
|                 upsertAstMap.put(obi.Id + '_1', upsertAssert); | 
|             } | 
|             if (obi.CompetitorProduct2__c != null) { | 
|                 Asset upsertAssert = new Asset( | 
|                     Id = obi.CompetitorAsset2__c, | 
|                     Name = '*', | 
|                     Product2Id = obi.CompetitorProduct2__c, | 
|                     Opportunity__c = obi.Opportunity__c, | 
|                     InstallDate = obi.Submit_Day__c, | 
|                     Hospital__c = obi.Opportunity__r.Hospital__c, | 
|                     Department_Class__c = obi.Opportunity__r.Department_Class__c, | 
|                     AccountId = obi.Opportunity__r.AccountId, | 
|                     Status = '使用中', | 
|                     Asset_Owner__c = '病院資産', | 
|                     IsCompetitorProduct = True | 
|                 ); | 
|                 upsertAstMap.put(obi.Id + '_2', upsertAssert); | 
|             } | 
|             if (obi.CompetitorProduct3__c != null) { | 
|                 Asset upsertAssert = new Asset( | 
|                     Id = obi.CompetitorAsset3__c, | 
|                     Name = '*', | 
|                     Product2Id = obi.CompetitorProduct3__c, | 
|                     Opportunity__c = obi.Opportunity__c, | 
|                     InstallDate = obi.Submit_Day__c, | 
|                     Hospital__c = obi.Opportunity__r.Hospital__c, | 
|                     Department_Class__c = obi.Opportunity__r.Department_Class__c, | 
|                     AccountId = obi.Opportunity__r.AccountId, | 
|                     Status = '使用中', | 
|                     Asset_Owner__c = '病院資産', | 
|                     IsCompetitorProduct = True | 
|                 ); | 
|                 upsertAstMap.put(obi.Id + '_3', upsertAssert); | 
|             } | 
|             if (obi.CompetitorProduct4__c != null) { | 
|                 Asset upsertAssert = new Asset( | 
|                     Id = obi.CompetitorAsset4__c, | 
|                     Name = '*', | 
|                     Product2Id = obi.CompetitorProduct4__c, | 
|                     Opportunity__c = obi.Opportunity__c, | 
|                     InstallDate = obi.Submit_Day__c, | 
|                     Hospital__c = obi.Opportunity__r.Hospital__c, | 
|                     Department_Class__c = obi.Opportunity__r.Department_Class__c, | 
|                     AccountId = obi.Opportunity__r.AccountId, | 
|                     Status = '使用中', | 
|                     Asset_Owner__c = '病院資産', | 
|                     IsCompetitorProduct = True | 
|                 ); | 
|                 upsertAstMap.put(obi.Id + '_4', upsertAssert); | 
|             } | 
|         } | 
|         system.debug('233332'+upsertAstMap.values()); | 
|         ControllerUtil.upsertAsset(upsertAstMap.values()); | 
|         List<Opponent_Bid_Information__c> updateObis = new List<Opponent_Bid_Information__c>(); | 
|         for (Opponent_Bid_Information__c obi : targetInsertObis) { | 
|             if (upsertAstMap.containsKey(obi.Id + '_1') || upsertAstMap.containsKey(obi.Id + '_2') | 
|                     || upsertAstMap.containsKey(obi.Id + '_3') || upsertAstMap.containsKey(obi.Id + '_4') | 
|             ) { | 
|                 Opponent_Bid_Information__c updObi = new Opponent_Bid_Information__c(Id = obi.Id); | 
|                 updateObis.add(updObi); | 
|                 if (upsertAstMap.containsKey(obi.Id + '_1')) { | 
|                     updObi.CompetitorAsset1__c = upsertAstMap.get(obi.Id + '_1').Id; | 
|                 } | 
|                 if (upsertAstMap.containsKey(obi.Id + '_2')) { | 
|                     updObi.CompetitorAsset2__c = upsertAstMap.get(obi.Id + '_2').Id; | 
|                 } | 
|                 if (upsertAstMap.containsKey(obi.Id + '_3')) { | 
|                     updObi.CompetitorAsset3__c = upsertAstMap.get(obi.Id + '_3').Id; | 
|                 } | 
|                 if (upsertAstMap.containsKey(obi.Id + '_4')) { | 
|                     updObi.CompetitorAsset4__c = upsertAstMap.get(obi.Id + '_4').Id; | 
|                 } | 
|             } | 
|         } | 
|         for (Opponent_Bid_Information__c obi : targetUpdateObis) { | 
|             if (upsertAstMap.containsKey(obi.Id + '_1') || upsertAstMap.containsKey(obi.Id + '_2') | 
|                     || upsertAstMap.containsKey(obi.Id + '_3') || upsertAstMap.containsKey(obi.Id + '_4') | 
|             ) { | 
|                 Opponent_Bid_Information__c updObi = new Opponent_Bid_Information__c(Id = obi.Id); | 
|                 updateObis.add(updObi); | 
|                 if (upsertAstMap.containsKey(obi.Id + '_1')) { | 
|                     updObi.CompetitorAsset1__c = upsertAstMap.get(obi.Id + '_1').Id; | 
|                 } | 
|                 if (upsertAstMap.containsKey(obi.Id + '_2')) { | 
|                     updObi.CompetitorAsset2__c = upsertAstMap.get(obi.Id + '_2').Id; | 
|                 } | 
|                 if (upsertAstMap.containsKey(obi.Id + '_3')) { | 
|                     updObi.CompetitorAsset3__c = upsertAstMap.get(obi.Id + '_3').Id; | 
|                 } | 
|                 if (upsertAstMap.containsKey(obi.Id + '_4')) { | 
|                     updObi.CompetitorAsset4__c = upsertAstMap.get(obi.Id + '_4').Id; | 
|                 } | 
|             } | 
|         } | 
|         update updateObis; | 
|     } | 
|     if (delAstIds.size() > 0) { | 
|         ControllerUtil.deleteAsset(delAstIds); | 
|     }/* | 
|     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++;*/ | 
| } |