| | |
| | | } |
| | | |
| | | protected override void beforeInsert(){ |
| | | |
| | | //SWAG-CKADFQ 【委托】【Last Buy】Last Buy预留管理改善新需求 start |
| | | SetUniqueKey(null); |
| | | //SWAG-CKADFQ 【委托】【Last Buy】Last Buy预留管理改善新需求 end |
| | | } |
| | | |
| | | protected override void beforeUpdate(){ |
| | | //SWAG-CKADFQ 【委托】【Last Buy】Last Buy预留管理改善新需求 start |
| | | CheckInquiryWinAboutupdate(); |
| | | SetUniqueKeyOnUpdate(); |
| | | //SWAG-CKADFQ 【委托】【Last Buy】Last Buy预留管理改善新需求 end |
| | | } |
| | | protected override void afterInsert(){ |
| | | ReservedPro(); |
| | | } |
| | |
| | | ReservedPro(); |
| | | } |
| | | |
| | | protected override void afterDelete(){ |
| | | ReservedPro(); |
| | | } |
| | | //SWAG-CKADFQ 【委托】【Last Buy】Last Buy预留管理改善新需求 start |
| | | protected override void beforeDelete(){ |
| | | CheckInquiryWin(); |
| | | } |
| | | //SWAG-CKADFQ 【委托】【Last Buy】Last Buy预留管理改善新需求 end |
| | | private void ReservedPro(){ |
| | | //1.新建或者更新产品后,若预留产品有效,“预留产品”标识为true |
| | | if(trigger.isInsert || trigger.isUpdate){ |
| | |
| | | //2.(1)"是否有效" 变为 false 检索产品主数据下的所有预留产品,全无效则把产品主数据的"预留产品"标识 变为 false |
| | | // (2)"产品" 预留产品 更改 产品主数据之前的产品 -- 检索产品主数据下的所有预留产品(没有/全无效) |
| | | // "预留产品"标识 变为 false |
| | | if(trigger.isUpdate){ |
| | | if(trigger.isUpdate || trigger.isDelete){ |
| | | //"是否有效" 变为 "否" 时 所对应的产品主数据Id &&预留产品 更改 产品主数据之前的产品 |
| | | List<Id> pfList = new List<Id>(); |
| | | |
| | | for(LastbuyProduct__c lbp1 : newList){ |
| | | LastbuyProduct__c oldLbp1 = oldMap.get(lbp1.Id); |
| | | if(oldLbp1.effectiveFLG__c != lbp1.effectiveFLG__c){ |
| | | System.debug('lt123无效?'+lbp1.effectiveFLG__c); |
| | | if(lbp1.effectiveFLG__c == false){ |
| | | System.debug('lt123无效'+lbp1.effectiveFLG__c); |
| | | pfList.add(lbp1.ProductName__c); |
| | | if(trigger.isUpdate){ |
| | | for(LastbuyProduct__c lbp1 : newList){ |
| | | LastbuyProduct__c oldLbp1 = oldMap.get(lbp1.Id); |
| | | if(oldLbp1.effectiveFLG__c != lbp1.effectiveFLG__c){ |
| | | if(lbp1.effectiveFLG__c == false){ |
| | | pfList.add(lbp1.ProductName__c); |
| | | } |
| | | } |
| | | //产品发生变化时,检索两个产品的标识 |
| | | if(oldLbp1.ProductName__c != lbp1.ProductName__c){ |
| | | pfList.add(oldLbp1.ProductName__c); |
| | | } |
| | | } |
| | | //产品发生变化时,检索两个产品的标识 |
| | | if(oldLbp1.ProductName__c != lbp1.ProductName__c){ |
| | | pfList.add(oldLbp1.ProductName__c); |
| | | } |
| | | else if(trigger.isDelete){ |
| | | for(LastbuyProduct__c lbp2 : oldList){ |
| | | pfList.add(lbp2.ProductName__c); |
| | | } |
| | | } |
| | | |
| | | |
| | | System.debug('lt123需检索所有预留产品的产品ID-pfList'+pfList); |
| | | |
| | |
| | | Map<String,LastbuyProduct__c> lbpMap = new Map<String,LastbuyProduct__c>(); |
| | | //发生变化的产品Id下的所有预留产品 |
| | | List<LastbuyProduct__c> lbpList = [select id, effectiveFLG__c,ProductName__c from LastbuyProduct__c where ProductName__c in :pfList]; |
| | | System.debug('lt123变化的预留产品lbpList'+lbpList); |
| | | //p1List effectiveFLG__c为true 的产品Id |
| | | List<Id> p1List = new List<Id>(); |
| | | //p2List 这个产品所有的预留产品都无效 的产品Id |
| | |
| | | List<Product2> prflgList = new List<Product2>(); |
| | | for(Product2 pro1 : pro1List){ |
| | | pro1.LastbuyProductFLG__c = false; |
| | | System.debug('lt123预留产品标识'+pro1.LastbuyProductFLG__c); |
| | | prflgList.add(pro1); |
| | | } |
| | | if(prflgList.size() > 0){ |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | //SWAG-CKADFQ 【委托】【Last Buy】Last Buy预留管理改善新需求 start |
| | | private void SetUniqueKey(Set<Id> lbps){ |
| | | if(trigger.isInsert) { |
| | | for (LastbuyProduct__c Lastbuyobj : this.newList){ |
| | | Lastbuyobj.productInquiryOnly__c = Lastbuyobj.ProductName__c+'_'+Lastbuyobj.InquiryCode__c; |
| | | } |
| | | } else { |
| | | if(lbps!=null&&lbps.size() > 0){ |
| | | for(String id : lbps){ |
| | | LastbuyProduct__c Lastbuyobj = this.newMap.get(id); |
| | | Lastbuyobj.productInquiryOnly__c = Lastbuyobj.ProductName__c+'_'+Lastbuyobj.InquiryCode__c; |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | private void CheckInquiryWin(){ |
| | | if(trigger.isBefore && trigger.isDelete){ |
| | | List<Id> InquiryId = new List<Id>(); |
| | | List<Id> InquiryWinId = new List<Id>(); |
| | | for(LastbuyProduct__c Lastbuyobj : oldList){ |
| | | InquiryId.add(Lastbuyobj.InquiryCode__c); |
| | | } |
| | | List<Opportunity> OppList = [select Id,SAP_Send_OK__c from Opportunity where Id =:InquiryId]; |
| | | System.debug('OppList++'+OppList); |
| | | for(Opportunity oppobj : OppList){ |
| | | if(oppobj.SAP_Send_OK__c){ |
| | | // InquiryWinId.add(oppobj.Id); |
| | | throw new ControllerUtil.myException('预留询价已经WIN不允许删除'); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 询价发生变化时验证 |
| | | private void CheckInquiryWinAboutupdate(){ |
| | | if(trigger.isBefore && trigger.isUpdate){ |
| | | List<Id> LastbuyId = new List<Id>(); |
| | | List<Id> oppId = new List<Id>(); |
| | | for(LastbuyProduct__c Lastbuyobj : newList){ |
| | | // 只取询价发生变化的数据 |
| | | if (Lastbuyobj.InquiryCode__c != oldMap.get(Lastbuyobj.Id).InquiryCode__c) { |
| | | LastbuyId.add(Lastbuyobj.Id); |
| | | oppId.add(oldMap.get(Lastbuyobj.Id).InquiryCode__c); |
| | | } |
| | | } |
| | | List<Opportunity> oppList = [select Id,SAP_Send_OK__c from Opportunity where Id =:oppId]; |
| | | for(Opportunity opp : oppList){ |
| | | if(opp.SAP_Send_OK__c){ |
| | | throw new ControllerUtil.myException('预留的询价已经WIN,不允许替换,请取消WIN后再替换'); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | // 询价或产品发生变化时更新唯一标识 |
| | | private void SetUniqueKeyOnUpdate() { |
| | | Set<Id> updateUniKeys = new Set<Id>(); |
| | | for(LastbuyProduct__c Lastbuyobj : this.newList){ |
| | | LastbuyProduct__c old_Lastbuyobj = oldMap.get(Lastbuyobj.Id); |
| | | // 产品或询价变化的时候都加进来 |
| | | if (Lastbuyobj.InquiryCode__c != old_Lastbuyobj.InquiryCode__c || |
| | | Lastbuyobj.ProductName__c != old_Lastbuyobj.ProductName__c || |
| | | String.isBlank(Lastbuyobj.productInquiryOnly__c)) { |
| | | updateUniKeys.add(Lastbuyobj.Id); |
| | | } |
| | | } |
| | | SetUniqueKey(updateUniKeys); |
| | | } |
| | | //SWAG-CKADFQ 【委托】【Last Buy】Last Buy预留管理改善新需求 end |
| | | |
| | | } |