trigger SIUploadFile on SI_Attachment__c (before insert,after insert,after update) {
|
List<Id> copyUserIds = new List<Id>();
|
List<SI_Attachment__c> newList = new List<SI_Attachment__c>();
|
Map<String,Integer> countNumber = new Map<String,Integer>();
|
Map<id,id> SODOwnerMap = new Map<id,id>();
|
Map<id,id> SODOwnerManMap = new Map<id,id>();
|
Map<id,id> SODOwnerMinisterMap = new Map<id,id>();
|
Map<id,id> SODOwnerMajorMap = new Map<id,id>();//总监
|
Map<id,id> SODOOpporAssisMap = new Map<id,id>();//询价助理
|
if(trigger.isInsert&&trigger.isAfter){
|
List<id> SI_attidList = new List<id>();
|
for(SI_Attachment__c sia : trigger.new){
|
if( sia.Type__c == 'CAD图纸'||
|
sia.Type__c =='手术室净化平面图(含设备定位)'||
|
sia.Type__c == '目标术间吊塔定位图' ||
|
sia.Type__c =='目标术间净化立体图' ||
|
sia.Type__c =='示教点楼层平面图' ||
|
sia.Type__c =='楼层建筑平面图' ||
|
sia.Type__c =='其他工程文件清单'||
|
sia.Type__c == '招标参数'||
|
sia.Type__c == '标书'||
|
sia.Type__c == '项目方案书'){
|
SI_attidList.add(sia.id);
|
}
|
}
|
if(SI_attidList.size()>0){
|
ControllerUtil.UpdateSIFunctionStatus(SI_attidList);
|
system.debug(SI_attidList);
|
}
|
}
|
|
if(trigger.isInsert && trigger.isBefore){
|
|
List<id> oppsId = new List<id>();
|
for(SI_Attachment__c siAc : trigger.new){
|
oppsId.add(siAc.Opportunity_ID__c);
|
siAc.Opportunity_sub_owner__c = siAc.Opportunity_sub_ownerID__c;
|
newList.add(siAc);
|
copyUserIds.add(siAc.OwnerId);
|
}
|
AggregateResult[] CountSAIList = [select count(id) countID,Opportunity_ID__c oppoid
|
from SI_Attachment__c
|
where Opportunity_ID__c in:oppsId
|
group by Opportunity_ID__c];
|
for(AggregateResult siA : CountSAIList){
|
countNumber.put((Id)siA.get('oppoid'),(Integer)siA.get('countID'));
|
}
|
for(SI_Attachment__c siAc : trigger.new){
|
siAc.Last_Two_Number__c = 1+(countNumber.get(siAc.Opportunity_ID__c)==null?0:countNumber.get(siAc.Opportunity_ID__c));
|
}
|
List<IS_Opportunity_Demand__c> sodList = [select OwnerId,id,Opportunity_ID__c,SI_SalesManager__c,
|
SI_Majordomo__c,SI_Minister_Sell__c,Opportunity_ID__r.Sales_assistant_ID__c from IS_Opportunity_Demand__c where Opportunity_ID__c in:oppsId
|
and Abort_Date__c = null ];
|
for(IS_Opportunity_Demand__c sod: sodList){
|
SODOwnerMap.put(sod.Opportunity_ID__c, sod.OwnerId);
|
SODOwnerManMap.put(sod.Opportunity_ID__c, sod.SI_SalesManager__c);
|
SODOwnerMinisterMap.put(sod.Opportunity_ID__c, sod.SI_Minister_Sell__c);
|
SODOwnerMajorMap.put(sod.Opportunity_ID__c, sod.SI_Majordomo__c);
|
SODOOpporAssisMap.put(sod.Opportunity_ID__c, sod.Opportunity_ID__r.Sales_assistant_ID__c);
|
}
|
|
}
|
if(trigger.isUpdate){
|
//=============================================================================================================
|
if(trigger.isBefore){
|
List<id> oppsId = new List<id>();
|
|
for(SI_Attachment__c siAc : trigger.new){
|
oppsId.add(siAc.Opportunity_ID__c);
|
newList.add(siAc);
|
copyUserIds.add(siAc.OwnerId);
|
}
|
List<IS_Opportunity_Demand__c> sodList = [select OwnerId,id,Opportunity_ID__c,SI_SalesManager__c,
|
SI_Majordomo__c,SI_Minister_Sell__c,Opportunity_ID__r.Sales_assistant_ID__c from IS_Opportunity_Demand__c where Opportunity_ID__c in:oppsId
|
and Abort_Date__c = null ];
|
for(IS_Opportunity_Demand__c sod: sodList){
|
SODOwnerMap.put(sod.Opportunity_ID__c, sod.OwnerId);
|
SODOwnerManMap.put(sod.Opportunity_ID__c, sod.SI_SalesManager__c);
|
SODOwnerMinisterMap.put(sod.Opportunity_ID__c, sod.SI_Minister_Sell__c);
|
SODOwnerMajorMap.put(sod.Opportunity_ID__c, sod.SI_Majordomo__c);
|
SODOOpporAssisMap.put(sod.Opportunity_ID__c, sod.Opportunity_ID__r.Sales_assistant_ID__c);
|
}
|
}
|
|
|
//=============================================================================================================
|
List<id> oppid = new List<id>();
|
Map<id,Date> idMapDate = new Map<id,Date>();
|
Map<id,Date> BidMapDate = new Map<id,Date>();
|
for(SI_Attachment__c Sa : trigger.new){
|
oppid.add(Sa.Opportunity_ID__c);
|
idMapDate.put(Sa.Opportunity_ID__c, Sa.ProJect_Confirm_Date__c);
|
BidMapDate.put(Sa.Opportunity_ID__c, Sa.bid_Confrim_Date__c);
|
}
|
List<Opportunity> OppList = [select Project_decide_date__c,bid_Confrim_Date__c from Opportunity where id In:oppid];
|
for(Opportunity op : OppList){
|
if(idMapDate.get(op.id)!=null){
|
op.Project_decide_date__c = idMapDate.get(op.id);
|
}
|
if(BidMapDate.get(op.id)!=null){
|
op.bid_Confrim_Date__c = BidMapDate.get(op.id);
|
}
|
|
}
|
update OppList;
|
}
|
if (copyUserIds.size() > 0) {
|
Map<Id, User> copyUserMap = new Map<Id, User>([
|
SELECT Id, Name, SalesManager__c, BuchangApprovalManagerSales__c, JingliApprovalManager__c, BuchangApprovalManager__c, ZongjianApprovalManager__c FROM User WHERE Id IN :copyUserIds
|
]);
|
|
for (Integer i = 0; i < copyUserIds.size(); i++) {
|
SI_Attachment__c local = newList[i];
|
User loginUser = copyUserMap.get(copyUserIds[i]);
|
local.SI_File_Manager_Sell__c = loginUser.SalesManager__c == null ? loginUser.Id : loginUser.SalesManager__c;
|
local.SI_File_Minister_Sell__c = loginUser.BuchangApprovalManagerSales__c == null ? loginUser.Id : loginUser.BuchangApprovalManagerSales__c;
|
local.SI_File_Minister_Service__c = loginUser.BuchangApprovalManager__c == null ? loginUser.Id : loginUser.BuchangApprovalManager__c;
|
local.SI_File_Majordomo_Sell__c = loginUser.ZongjianApprovalManager__c == null ? loginUser.Id : loginUser.ZongjianApprovalManager__c;
|
local.File_Upload_Date__c = Date.today();
|
local.SI_SOD_Owner__c = SODOwnerMap.get(local.Opportunity_ID__c);
|
local.SI_SOD_Owner_Manager__c = SODOwnerManMap.get(local.Opportunity_ID__c);
|
local.Oppor_Assistant__c = SODOOpporAssisMap.get(local.Opportunity_ID__c);
|
}
|
}
|
|
}
|