| | |
| | | trigger ContentDocumentLink on ContentDocumentLink (before insert,after insert,before delete,after delete, before update, after update) { |
| | | trigger ContentDocumentLink on ContentDocumentLink (before insert,after insert,before delete) { |
| | | if(StaticParameter.ContentDocumentLink == false){ |
| | | return; |
| | | } |
| | | if((!Test.isRunningTest())&&UserInfo.getUserId()==System.Label.ByPassTrigger){ |
| | | return; |
| | | } |
| | | // if (Trigger.isAfter && Trigger.isInsert) { |
| | | // Set<Id> Ids = new Set<id>(); |
| | | // Map<Id,ContentDocumentLink> mapcvwithid = new Map<Id,ContentDocumentLink>(); |
| | | // for(ContentDocumentLink c:Trigger.new){ |
| | | // ids.add(c.ContentDocumentId); |
| | | // mapcvwithid.put(c.ContentDocumentId,c); |
| | | // } |
| | | // if(ids.size() > 0){ |
| | | // for(ContentDocument ContentDocumentObj : [select id,FileType from ContentDocument where id in: ids]){ |
| | | // if(mapcvwithid.get(ContentDocumentObj.Id).LinkedEntityId != null && ContentDocumentObj.FileType != null){ |
| | | // String ObjectName = mapcvwithid.get(ContentDocumentObj.Id).LinkedEntityId.getSObjectType().getDescribe().getName(); |
| | | // String filetype = ContentDocumentObj.FileType.toLowerCase(); |
| | | // String CsName = ObjectName+'-'+filetype; |
| | | |
| | | // ContentDocumentLink ContentDocumentLinkObj = mapcvwithid.get(ContentDocumentObj.Id); |
| | | // ContentDocumentLinkObj.addError('Testing error'); |
| | | // return; |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | List<String> rentalIds = new List<String>(); |
| | | List<String> attIds = new List<String>(); |
| | | List<String> rentaldelIds = new List<String>(); |
| | | List<String> attdelIds = new List<String>(); |
| | | List<String> rentalApplyIds = new List<String>(); |
| | | List<String> accIds = new List<String>(); |
| | | //20221014 yc 医院审批优化 start |
| | |
| | | //20221014 yc 医院审批优化 end |
| | | // LHJ CHAN-BCLD4P 20190618 Start |
| | | List<String> specIds = new List<String>(); |
| | | List<String> specDelIds = new List<String>(); |
| | | // LHJ CHAN-BCLD4P 20190618 End |
| | | |
| | | // MZY SWAG-BXXBKA 2021-02-19 start |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | //CHAN-BCNCRB ---XHL----End----- |
| | | if (Trigger.isAfter && Trigger.isInsert) { |
| | | for (ContentDocumentLink link : Trigger.new) { |
| | | ContentVersion version = [select Id,Title from ContentVersion where ContentDocumentId =: link.ContentDocumentId]; |
| | | //if (att.Name.toUpperCase() == '合同书.PDF' && String.valueOf(att.ParentId).startsWith('a0t')) { |
| | | // 添付した契約書のファイル名は指定できない |
| | | if (String.valueOf(link.LinkedEntityId).startsWith('a2K')) { |
| | | rentalIds.add(link.LinkedEntityId); |
| | | attIds.add(version.Id); |
| | | } |
| | | if (String.valueOf(link.LinkedEntityId).startsWith('a0t')) { |
| | | rentalApplyIds.add(link.LinkedEntityId); |
| | | } |
| | | if (String.valueOf(link.LinkedEntityId).startsWith('001')) { |
| | | accIds.add(link.LinkedEntityId); |
| | | } |
| | | //20221014 yc 医院审批优化 start |
| | | if (String.valueOf(link.LinkedEntityId).startsWith('a5C') || String.valueOf(link.LinkedEntityId).startsWith('a5A')) { |
| | | accAppIds.add(link.LinkedEntityId); |
| | | } |
| | | //20221014 yc 医院审批优化 end |
| | | if(String.valueOf(link.LinkedEntityId).startsWith(System.Label.Oppor_sepKey)){ |
| | | OpporFileIds.add(link.LinkedEntityId); |
| | | } |
| | | // LHJ CHAN-BCLD4P 20190618 Start |
| | | if(String.valueOf(link.LinkedEntityId).startsWith(System.Label.OppSpecialApply)){ |
| | | specIds.add(link.LinkedEntityId); |
| | | } |
| | | // LHJ CHAN-BCLD4P 20190618 End |
| | | |
| | | // MZY SWAG-BXXBKA 2021-02-19 start |
| | | if(String.valueOf(link.LinkedEntityId).startsWith('a3E')){ |
| | | opdIds.add(link.LinkedEntityId); |
| | | opdMap.put(link.LinkedEntityId,version.Title); |
| | | } |
| | | // MZY SWAG-BXXBKA 2021-02-19 end |
| | | |
| | | if(String.valueOf(link.LinkedEntityId).startsWith('a3Z')){ |
| | | oFOrderIds.add(link.LinkedEntityId); |
| | | oFOrderIdMap.put(link.LinkedEntityId,true); |
| | | } |
| | | |
| | | //2023-2-10 sx备品 备品检测分析报告 start |
| | | Id cid = link.LinkedEntityId; |
| | | String parentLabel = cid.getSObjectType().getDescribe().getName(); |
| | | if(parentLabel.equals('Rental_Apply_Fault__c')){ |
| | | rentalApplyFaultIds.add(link.LinkedEntityId); |
| | | if(trentalImages.containskey(link.LinkedEntityId)){ |
| | | trentalImages.get(link.LinkedEntityId).add(version.Id); |
| | | }else{ |
| | | List<Id> temp = new List<Id>(); |
| | | temp.add(version.Id); |
| | | trentalImages.put(link.LinkedEntityId,temp); |
| | | } |
| | | } |
| | | //2023-2-10 sx备品 备品检测分析报告 end |
| | | } |
| | | } |
| | | |
| | | if (Trigger.isAfter && Trigger.isDelete) { |
| | | if (Trigger.isBefore && Trigger.isDelete) { |
| | | for (ContentDocumentLink link : Trigger.old) { |
| | | if (String.valueOf(link.LinkedEntityId).startsWith('001')) { |
| | | accIds.add(link.LinkedEntityId); |
| | |
| | | //20221014 yc 医院审批优化 end |
| | | } |
| | | } |
| | | //CHAN-BCNCRB ---XHL----End----- |
| | | if (Trigger.isAfter && Trigger.isInsert) { |
| | | List<Id> idList = new List<Id>(); |
| | | for (ContentDocumentLink link : Trigger.new) { |
| | | idList.add(link.ContentDocumentId); |
| | | } |
| | | List<ContentVersion> version = [select Id,Title from ContentVersion where ContentDocumentId in: idList]; |
| | | for (ContentDocumentLink link : Trigger.new) { |
| | | //if (att.Name.toUpperCase() == '合同书.PDF' && String.valueOf(att.ParentId).startsWith('a0t')) { |
| | | // 添付した契約書のファイル名は指定できない |
| | | if (String.valueOf(link.LinkedEntityId).startsWith('a2K')) { |
| | | rentalIds.add(link.LinkedEntityId); |
| | | attIds.add(version[0].Id); |
| | | } |
| | | if (String.valueOf(link.LinkedEntityId).startsWith('a0t')) { |
| | | rentalApplyIds.add(link.LinkedEntityId); |
| | | } |
| | | if (String.valueOf(link.LinkedEntityId).startsWith('001')) { |
| | | accIds.add(link.LinkedEntityId); |
| | | } |
| | | //20221014 yc 医院审批优化 start |
| | | if (String.valueOf(link.LinkedEntityId).startsWith('a5C') || String.valueOf(link.LinkedEntityId).startsWith('a5A')) { |
| | | accAppIds.add(link.LinkedEntityId); |
| | | } |
| | | //20221014 yc 医院审批优化 end |
| | | System.debug(link.LinkedEntityId +'陈京武'); |
| | | if(String.valueOf(link.LinkedEntityId).startsWith(System.Label.Oppor_sepKey)){ |
| | | OpporFileIds.add(link.LinkedEntityId); |
| | | } |
| | | // LHJ CHAN-BCLD4P 20190618 Start |
| | | if(String.valueOf(link.LinkedEntityId).startsWith(System.Label.OppSpecialApply)){ |
| | | specIds.add(link.LinkedEntityId); |
| | | } |
| | | // LHJ CHAN-BCLD4P 20190618 End |
| | | |
| | | // MZY SWAG-BXXBKA 2021-02-19 start |
| | | if(String.valueOf(link.LinkedEntityId).startsWith('a3E')){ |
| | | opdIds.add(link.LinkedEntityId); |
| | | opdMap.put(link.LinkedEntityId,version[0].Title); |
| | | } |
| | | // MZY SWAG-BXXBKA 2021-02-19 end |
| | | |
| | | if(String.valueOf(link.LinkedEntityId).startsWith('a3Z')){ |
| | | oFOrderIds.add(link.LinkedEntityId); |
| | | oFOrderIdMap.put(link.LinkedEntityId,true); |
| | | } |
| | | |
| | | //2023-2-10 sx备品 备品检测分析报告 start |
| | | Id cid = link.LinkedEntityId; |
| | | String parentLabel = cid.getSObjectType().getDescribe().getName(); |
| | | if(parentLabel.equals('Rental_Apply_Fault__c')){ |
| | | rentalApplyFaultIds.add(link.LinkedEntityId); |
| | | if(trentalImages.containskey(link.LinkedEntityId)){ |
| | | trentalImages.get(link.LinkedEntityId).add(version[0].Id); |
| | | }else{ |
| | | List<Id> temp = new List<Id>(); |
| | | temp.add(version[0].Id); |
| | | trentalImages.put(link.LinkedEntityId,temp); |
| | | } |
| | | } |
| | | //2023-2-10 sx备品 备品检测分析报告 end |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | //2023-2-10 sx备品 备品检测分析报告 start |
| | |
| | | //2023-2-10 sx备品 备品检测分析报告 end |
| | | |
| | | |
| | | if (rentaldelIds.size() > 0) { |
| | | List<Consumable_accessories_invoice__c> rentaldelList = new List<Consumable_accessories_invoice__c>(); |
| | | for (Consumable_accessories_invoice__c ra : [select Id from Consumable_accessories_invoice__c where Invoice_code__c in :rentaldelIds and Attachment_ID__c in :attdelIds]) { |
| | | rentaldelList.add(ra); |
| | | } |
| | | ControllerUtil.delConsumableAccessoriesInvoiceSet(rentaldelList); |
| | | } |
| | | |
| | | if (rentalIds.size() > 0) { |
| | | List<Consumable_order__c> rentalList = new List<Consumable_order__c>(); |
| | |
| | | if(accList.size() > 0){ |
| | | // Account acc = new Account(Id = accid); |
| | | //20221207 lt 医院审批优化 start |
| | | for(Account acc : accList){ |
| | | if(Trigger.isDelete && (Trigger.isAfter)){ |
| | | for(Account acc : accList){ |
| | | if(Trigger.isUpdate && Trigger.isAfter){ |
| | | for(ContentDocumentLink link : Trigger.New){ |
| | | |
| | | if(attMap.containsKey(link.LinkedEntityId) &&acc.Is_Active__c != '草案中'){ |
| | | System.debug('lt123---草案中---'); |
| | | link.addError('非草案中,附件不允许编辑。'); |
| | | |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | if(Trigger.isDelete && (Trigger.isBefore)){ |
| | | for(ContentDocumentLink link : Trigger.old){ |
| | | // if(attMap.containsKey(att.ParentID) && acc.Is_Active__c != '草案中'){ |
| | | if(acc.Is_Active__c != '草案中'){ |
| | | link.addError('非草案中,附件不允许删除。'); |
| | | |
| | |
| | | // acc.Is_upload_file__c = attMap.containsKey(accid); |
| | | // updAccList.add(acc); |
| | | // } |
| | | if (updAccList.size() > 0) update updAccList; |
| | | if (updAccList.size() > 0){ |
| | | StaticParameter.ContentDocumentTrigger = false; |
| | | update updAccList; |
| | | } |
| | | } |
| | | |
| | | //20221014 yc 医院审批优化 start |
| | |
| | | //20221207 lt 医院审批优化 end |
| | | |
| | | } |
| | | if (updAccAppList.size() > 0) update updAccAppList; |
| | | try { |
| | | System.debug('客户变更申请'); |
| | | if (updAccAppList.size() > 0) update updAccAppList; |
| | | } catch (Exception e) { |
| | | linkList[0].addError(e.getMessage()); |
| | | } |
| | | |
| | | } |
| | | //20221014 yc 医院审批优化 end |
| | | |
| | |
| | | ofc.Last_upload_user__c = UserInfo.getUserId(); |
| | | ofc.Last_upload_time__c = System.now(); |
| | | System.debug(ofc+'23333'); |
| | | update OpporList; |
| | | }else{ |
| | | OpporFileUndeleteMap.put(ofc.id,ofc.id); |
| | | System.debug(ofc+'23333444444'); |
| | | } |
| | | } |
| | | update OpporList; |
| | | |
| | | } |
| | | } |
| | | System.debug(Trigger.isDelete+'Trigger.isDelete'); |
| | | System.debug(Trigger.isBefore+'Trigger.isBefore'); |
| | | |
| | | if(Trigger.isDelete && Trigger.isAfter){ |
| | | if(Trigger.isDelete && Trigger.isBefore){ |
| | | for(ContentDocumentLink link : Trigger.old){ |
| | | if(OpporFileUndeleteMap.containsKey(link.LinkedEntityId)){ |
| | | link.addError('备货已审批,不可删除附件'); |
| | |
| | | if(Trigger.isInsert){ |
| | | for(ContentDocumentLink link : Trigger.new){ |
| | | if(OpporFileUndeleteMap.containsKey(link.LinkedEntityId)){ |
| | | ContentDocument doc = [select Id from ContentDocument where Id =: link.ContentDocumentId]; |
| | | doc.addError('备货已审批,不可删除附件'); |
| | | // ContentDocument doc = [select Id from ContentDocument where Id =: link.ContentDocumentId]; |
| | | link.addError('备货已审批,不可删除附件'); |
| | | // link.addError('备货已审批,不可删除附件'); |
| | | |
| | | System.debug(Trigger.isBefore+'陈京武'); |
| | | return; |
| | | }else{ |
| | | System.debug(Trigger.isBefore+'武'); |
| | | DeleteReIds.add(link.LinkedEntityId); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // List<Attachment> atcList = [select id,ParentId,createddate,createdbyid from Attachment where ParentId in:DeleteReIds]; |
| | | List<ContentDocumentLink> linkList = [select ContentDocumentId from ContentDocumentLink where LinkedEntityId in:DeleteReIds]; |
| | | List<Id> idList = new List<Id>(); |
| | | for (ContentDocumentLink link : linkList) { |
| | | idList.add(link.ContentDocumentId); |
| | | } |
| | | List<ContentDocument> docList = [select Id,ArchivedDate,ArchivedById from ContentDocument where Id =: idList]; |
| | | System.debug(DeleteReIds+'222222222222'); |
| | | if(docList.size()>0){ |
| | | for(String ids : DeleteReIds){ |
| | | for(ContentDocument doc : docList){ |
| | | if(OppordeleteReTimeMap.containsKey(ids)){ |
| | | if(doc.ArchivedDate > OppordeleteReTimeMap.get(ids)){ |
| | | OppordeleteReTimeMap.put(ids,doc.ArchivedDate); |
| | | OppordeleteReUserMap.put(ids,doc.ArchivedById); |
| | | if(DeleteReIds.size() > 0){ |
| | | // List<Attachment> atcList = [select id,ParentId,createddate,createdbyid from Attachment where ParentId in:DeleteReIds]; |
| | | List<ContentDocumentLink> linkList = [select LinkedEntityId,ContentDocumentId from ContentDocumentLink where LinkedEntityId in:DeleteReIds]; |
| | | List<Id> idList = new List<Id>(); |
| | | for (ContentDocumentLink link : linkList) { |
| | | if(link.LinkedEntityId.getSObjectType().getDescribe().getName() != 'User'){ |
| | | idList.add(link.ContentDocumentId); |
| | | } |
| | | } |
| | | List<ContentDocument> docList = [select Id,CreatedDate,CreatedById from ContentDocument where Id =: idList]; |
| | | System.debug(DeleteReIds+'222222222222'); |
| | | System.debug(docList + 'doclist'); |
| | | if(docList.size()>0){ |
| | | for(String ids : DeleteReIds){ |
| | | for(ContentDocument doc : docList){ |
| | | if(OppordeleteReTimeMap.containsKey(ids)){ |
| | | if(doc.CreatedDate > OppordeleteReTimeMap.get(ids)){ |
| | | OppordeleteReTimeMap.put(ids,doc.CreatedDate); |
| | | OppordeleteReUserMap.put(ids,doc.CreatedById); |
| | | }else{ |
| | | continue; |
| | | } |
| | | }else{ |
| | | continue; |
| | | OppordeleteReTimeMap.put(ids,doc.CreatedDate); |
| | | OppordeleteReUserMap.put(ids,doc.CreatedById); |
| | | } |
| | | }else{ |
| | | OppordeleteReTimeMap.put(ids,doc.ArchivedDate); |
| | | OppordeleteReUserMap.put(ids,doc.ArchivedById); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | List<Opportunity_File__c> reDateList = [select id,Last_upload_time__c, |
| | | Is_Locked__c, |
| | | Last_upload_user__c |
| | | from Opportunity_File__c |
| | | where id |
| | | in:DeleteReIds ]; |
| | | if(reDateList.size()>0){ |
| | | for(Opportunity_File__c ofc : reDateList){ |
| | | ofc.Last_upload_time__c = OppordeleteReTimeMap.get(ofc.id); |
| | | ofc.Last_upload_user__c = OppordeleteReUserMap.get(ofc.id); |
| | | System.debug(ofc+'233333333'); |
| | | } |
| | | update reDateList; |
| | | } |
| | | }else{ |
| | | List<Opportunity_File__c> reDateList = [select id,Last_upload_time__c, |
| | | Is_Locked__c, |
| | | Last_upload_user__c |
| | | from Opportunity_File__c |
| | | where id |
| | | in:DeleteReIds ]; |
| | | if(reDateList.size()>0){ |
| | | for(Opportunity_File__c ofc : reDateList){ |
| | | if (!ofc.Is_Locked__c) { |
| | | ofc.Last_upload_time__c = null; |
| | | ofc.Last_upload_user__c = null; |
| | | System.debug(OppordeleteReTimeMap + 'OppordeleteReTimeMap'); |
| | | System.debug(OppordeleteReUserMap + 'OppordeleteReUserMap'); |
| | | List<Opportunity_File__c> reDateList = [select id,Last_upload_time__c, |
| | | Is_Locked__c, |
| | | Last_upload_user__c |
| | | from Opportunity_File__c |
| | | where id |
| | | in:DeleteReIds ]; |
| | | if(reDateList.size()>0){ |
| | | for(Opportunity_File__c ofc : reDateList){ |
| | | ofc.Last_upload_time__c = OppordeleteReTimeMap.get(ofc.id); |
| | | ofc.Last_upload_user__c = OppordeleteReUserMap.get(ofc.id); |
| | | System.debug(ofc+'233333333'); |
| | | } |
| | | if(Trigger.isInsert && Trigger.isAfter){ |
| | | update reDateList; |
| | | } |
| | | |
| | | } |
| | | }else{ |
| | | List<Opportunity_File__c> reDateList = [select id,Last_upload_time__c, |
| | | Is_Locked__c, |
| | | Last_upload_user__c |
| | | from Opportunity_File__c |
| | | where id |
| | | in:DeleteReIds ]; |
| | | if(reDateList.size()>0){ |
| | | for(Opportunity_File__c ofc : reDateList){ |
| | | if (!ofc.Is_Locked__c) { |
| | | ofc.Last_upload_time__c = null; |
| | | ofc.Last_upload_user__c = null; |
| | | update reDateList; |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | //CHAN-BCNCRB ---XHL----Start----- |
| | | if (opportunity_FileIds.size() > 0) { |
| | |
| | | if (oFOrderList.size() > 0 ) { |
| | | |
| | | for (OpportunityFileOrder__c oFOrder :oFOrderList) { |
| | | |
| | | System.debug(oFOrderIdMap.get(oFOrder.Id)); |
| | | if (oFOrderIdMap.get(oFOrder.Id)) { |
| | | oFOrder.LatestUploadUser__c = UserInfo.getUserId(); |
| | | oFOrder.LatestUploadTime__c = System.now(); |
| | |
| | | } |
| | | } |
| | | // DB202304087063 SFDC系统附件上传自动通知功能开发需求 start |
| | | if (Trigger.isInsert && Trigger.isAfter && false) { |
| | | AttachmentReQisHandler handler = new AttachmentReQisHandler(); |
| | | handler.run(); |
| | | if (Trigger.isInsert && Trigger.isAfter) { |
| | | NotetoPdfHandler handler = new NotetoPdfHandler(); |
| | | handler.run(); |
| | | } |
| | | // DB202304087063 SFDC系统附件上传自动通知功能开发需求 end |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |