public without sharing class AttachmentDisplayController {
    @AuraEnabled
    public static List<testInit> getFrameNumManage(String DNId){
        //zhj 判断是否是site站点和链接上面是否存在eSignSystem  2023-01-04 start
        String ourl =URL.getsalesforceBaseUrl().toExternalForm();
        String path =URL.getcurrentRequesturl().getPath();
        Boolean bool = false;
        // update 20240202 by DTT-亚楠 把site改成experience
        if(ourl.contains('experience') && path.contains('eSignSystem')){
            bool = true;
        }
        System.debug('ourl = ' + ourl);
        System.debug('path = ' + path);
        System.debug('bool = ' + bool);
        //zhj 判断是否是site站点和链接上面是否存在eSignSystem  2023-01-04 end

        System.debug('DNId'+DNId);
        List<testInit> newinitList = new List<testInit>();
        List<testInit> initList = new List<testInit>();
        List<FrameNumManage__c> FnmList =[SELECT Id, Name 
        ,ManagementCode__c
        ,InspectionCard__c
        ,ApplyList__c 
        ,InspectionCard_Select__c 
        ,InspectionCard_Select__r.View_Link__c
        ,InspectionCard_Select__r.ViewLink__c
        ,InspectionCard_Select__r.DownloadLink__c
        ,ApplyList_Select__c
        ,ApplyList_Select__r.DownloadLink__c
        ,ApplyList_Select__r.View_Link__c
        ,ApplyList_Select__r.ViewLink__c
        ,Num__c 
        ,SerialNumber__c
        ,Material__c 
        ,MaterialDepict__c
        ,ApplyList_Select__r.AWS_File_Key__c
        ,ApplyList_Select__r.FileName__c
        ,InspectionCard_Select__r.AWS_File_Key__c
        ,InspectionCard_Select__r.FileName__c
        ,HomeBuy__c
        //2023 0208 fy add   报关单商检证新需求，重新判断 start
        ,ApplyList_NoHave__c
        ,InspectionCard_NoHave__c  
        //2023 0208 fy add   报关单商检证新需求，重新判断 end
        from FrameNumManage__c where signInForm__c =:DNId 
        //2023 0208 fy add   报关单商检证新需求，重新判断 start
       //  order by ApplyList__c desc,InspectionCard__c desc,SerialNumber__c desc];
       order by ApplyList_NoHave__c desc,InspectionCard_NoHave__c desc ,SerialNumber__c desc];
       //2023 0208 fy add   报关单商检证新需求，重新判断 end
        set<String> FileStrSet = new set<String>();
        List<FileAddress__c> FileList = new List<FileAddress__c>();
        Map<String,String> FileStrMap = new Map<String,String>();
        // if (FnmList.size()>0) {
        //     for (FrameNumManage__c nObj : FnmList ) {
        //         FileStrSet.add(nObj.ApplyList__c);
        //     }
        //     FileList = [SELECT Id, Name, FileName__c,ViewLink__c  FROM FileAddress__c WHERE FileName__c IN: FileStrSet];
        //     if(FileList.size()>0){
        //         for (FileAddress__c file : FileList) {
        //             FileStrMap.put(file.FileName__c, file.ViewLink__c);
        //         }
        //     }
        // }
        List<FrameNumManage__c> FnmListhomebuy = new List<FrameNumManage__c>();
        List<FrameNumManage__c> notFnmListhomebuy = new List<FrameNumManage__c>();
        //2023 0208 fy add   报关单商检证新需求，重新判断 start
        // for(FrameNumManage__c fr : FnmList){
        //     if(fr.HomeBuy__c){
        //         FnmListhomebuy.add(fr);
        //     }else{
        //         notFnmListhomebuy.add(fr);
        //     }
        // }
        notFnmListhomebuy = FnmList;
        //2023 0208 fy add   报关单商检证新需求，重新判断 end
        Integer n = 0; // 初始化合并行数
        Integer n_sj = 0; // 初始化合并行数（商检证） 2023-01-10 fy add
        for (Integer i=0;i<notFnmListhomebuy.size() ;i++ ) {
            testInit init = new testInit();
            if (i==0) {
                init.Name = notFnmListhomebuy[i].ManagementCode__c;
                init.ProductName = notFnmListhomebuy[i].Material__c + '-' + notFnmListhomebuy[i].MaterialDepict__c;

                //2022-12-26 fy add 改造 start
                // init.code = notFnmListhomebuy[i].ApplyList__c;
                // if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.DownloadLink__c)) {
                // 	init.code = notFnmListhomebuy[i].ApplyList_Select__r.DownloadLink__c;
                //     init.codeyu = notFnmListhomebuy[i].ApplyList_Select__r.ViewLink__c;
                // }else{
                // 	init.code = '无';
                // } 
                //2023 0208 fy add   报关单商检证新需求，重新判断 start
                if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__c)) {
                    // 报关单预览链接判断
                    // if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.ViewLink__c)) {
                    //     init.codeyu = notFnmListhomebuy[i].ApplyList_Select__r.ViewLink__c;
                    // }else{
                    if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.View_Link__c)) {
                        init.codeyu = notFnmListhomebuy[i].ApplyList_Select__r.View_Link__c;
                    }else{
                        init.codeyu = '';
                    }
                    // 报关单下载链接判断
                    if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.DownloadLink__c)) {
                        init.code = notFnmListhomebuy[i].ApplyList_Select__r.DownloadLink__c;
                    }else{
                        init.code = '';
                    }
                    //报关单awkey,filename判断 zhj 2022-12-08 start
                    if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.AWS_File_Key__c)) {
                        init.awsKey = notFnmListhomebuy[i].ApplyList_Select__r.AWS_File_Key__c;
                    }else{
                        init.awsKey = '';
                    }
                    if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.FileName__c)) {
                        init.fileName = notFnmListhomebuy[i].ApplyList_Select__r.FileName__c;
                    }else{
                        init.fileName = '';
                    }
                    //报关单awkey,filename判断 zhj 2022-12-08 end
                }else {
                    if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_NoHave__c)) {
                        init.code = notFnmListhomebuy[i].ApplyList_NoHave__c;
                    }else{
                        init.code = '';
                    }
                    init.codeyu = '';
                    init.awsKey = '';       // zhj 2022-12-08 
                    init.fileName = '';     // zhj 2022-12-08
                } 
                // if (String.isNotBlank(notFnmListhomebuy[i].ApplyList__c)) {
                // 	if (notFnmListhomebuy[i].ApplyList__c.equals('不出证')) {
                // 		init.code = '不出证';
                // 	}else{
                // 		// 报关单预览链接判断
                // 		if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.ViewLink__c)) {
		        //         	init.codeyu = notFnmListhomebuy[i].ApplyList_Select__r.ViewLink__c;
		        //         }else{
		        //         	init.codeyu = '';
		        //         }
                // 		// 报关单下载链接判断
                // 		if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.DownloadLink__c)) {
		        //         	init.code = notFnmListhomebuy[i].ApplyList_Select__r.DownloadLink__c;
		        //         }else{
		        //         	init.code = '';
		        //         }

                //         if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.AWS_File_Key__c)) {
		        //         	init.awsKey = notFnmListhomebuy[i].ApplyList_Select__r.AWS_File_Key__c;
		        //         }else{
		        //         	init.awsKey = '';
		        //         }
                //         if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.FileName__c)) {
		        //         	init.fileName = notFnmListhomebuy[i].ApplyList_Select__r.FileName__c;
		        //         }else{
		        //         	init.fileName = '';
		        //         }
                // 	}
                // }else{
                // 	init.code = '';
                // 	init.codeyu = '';
                //     init.awsKey = '';
                //     init.fileName = '';
                // }
                //2023 0208 fy add   报关单商检证新需求，重新判断 end
                
                // //2022-12-05 fy add 报关单判断
                // //if (String.isNotBlank(FnmList[i].InspectionCard_Select__r.DownloadLink__c)) {
                // if (notFnmListhomebuy[i].InspectionCard__c =='不出证') {
                //     init.sj_code = '不出证';
                // }else if(String.isBlank(notFnmListhomebuy[i].InspectionCard_Select__r.DownloadLink__c)){
                // 	init.sj_code = '';
                // }else{
                // 	init.sj_code = notFnmListhomebuy[i].InspectionCard_Select__r.DownloadLink__c;
                //     init.sj_codeyu = notFnmListhomebuy[i].InspectionCard_Select__r.ViewLink__c;
                // } //2022-12-05 fy add 商检证判断
                 //2023 0208 fy add   报关单商检证新需求，重新判断 start
                 if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__c)) {
                    // 报关单预览链接判断
                    // if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.ViewLink__c)) {
                    //     init.sj_codeyu = notFnmListhomebuy[i].InspectionCard_Select__r.ViewLink__c;
                    // }else{
                    if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.View_Link__c)) {
                        init.sj_codeyu = notFnmListhomebuy[i].InspectionCard_Select__r.View_Link__c;
                    }else{
                        init.sj_codeyu = '';
                    }
                    // 报关单下载链接判断
                    if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.DownloadLink__c)) {
                        init.sj_code = notFnmListhomebuy[i].InspectionCard_Select__r.DownloadLink__c;
                    }else{
                        init.sj_code = '';
                    }
                    //报关单awkey,filename判断 zhj 2022-12-08 start
                    if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.AWS_File_Key__c)) {
                        init.sj_awsKey = notFnmListhomebuy[i].InspectionCard_Select__r.AWS_File_Key__c;
                    }else{
                        init.sj_awsKey = '';
                    }
                    if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.FileName__c)) {
                        init.sj_fileName = notFnmListhomebuy[i].InspectionCard_Select__r.FileName__c;
                    }else{
                        init.sj_fileName = '';
                    }
                    //报关单awkey,filename判断 zhj 2022-12-08 end
                }else {
                    if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_NoHave__c)) {
                        init.sj_code = notFnmListhomebuy[i].InspectionCard_NoHave__c;
                    }else{
                        init.sj_code = '';
                    }
                    init.sj_codeyu = '';
                    init.sj_awsKey = '';       // zhj 2022-12-08 
                    init.sj_fileName = '';     // zhj 2022-12-08
                } 
                // if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard__c)) {
                // 	if (notFnmListhomebuy[i].InspectionCard__c.equals('不出证')) {
                // 		init.sj_code = '不出证';
                // 	}else{
                // 		// 商检证预览链接判断
                // 		if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.ViewLink__c)) {
		        //         	init.sj_codeyu = notFnmListhomebuy[i].InspectionCard_Select__r.ViewLink__c;
		        //         }else{
		        //         	init.sj_codeyu = '';
		        //         }
                // 		// 商检证下载链接判断
                // 		if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.DownloadLink__c)) {
		        //         	init.sj_code = notFnmListhomebuy[i].InspectionCard_Select__r.DownloadLink__c;
		        //         }else{
		        //         	init.sj_code = '';
		        //         }
                //         //商检证awkey,filename判断 zhj 2022-12-19 start
                //         if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.AWS_File_Key__c)) {
		        //         	init.sj_awsKey = notFnmListhomebuy[i].InspectionCard_Select__r.AWS_File_Key__c;
		        //         }else{
		        //         	init.sj_awsKey = '';
		        //         }
                //         if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.FileName__c)) {
		        //         	init.sj_fileName = notFnmListhomebuy[i].InspectionCard_Select__r.FileName__c;
		        //         }else{
		        //         	init.sj_fileName = '';
		        //         }
                //         //商检证awkey,filename判断 zhj 2022-12-19 end
                // 	}
                // }else{
                // 	init.sj_code = '';
                // 	init.sj_codeyu = '';
                //     init.sj_awsKey = '';       // zhj 2022-12-19 
                //     init.sj_fileName = '';     // zhj 2022-12-19
                // }
                // //2022-12-26 fy add 改造 end
                //2023 0208 fy add   报关单商检证新需求，重新判断 end

                // init.code = FileStrMap.get(FnmList[i].ApplyList__c);
                init.Num = notFnmListhomebuy[i].Num__c;
                init.Id = notFnmListhomebuy[i].Id;
                init.FrameNo = notFnmListhomebuy[i].SerialNumber__c;
                n = n+1;
                n_sj = n_sj+1; // 2023-01-10   fy   add
                if (i != notFnmListhomebuy.size()-1) {
                    // 判断第一个与第二个是否一样，不一样赋值1
                    //2023 0208 fy add   报关单商检证新需求，重新判断 start
                    // if (notFnmListhomebuy[i].ApplyList__c != notFnmListhomebuy[i+1].ApplyList__c) {
                    if (notFnmListhomebuy[i].ApplyList_NoHave__c != notFnmListhomebuy[i+1].ApplyList_NoHave__c) {
                    //2023 0208 fy add   报关单商检证新需求，重新判断 end
                        init.count = n;
                    }
                    // 2023-01-10 fy  add start
                    // 判断第一个与下一个是否一样，不一样赋值1——商检证
                    //2023 0208 fy add   报关单商检证新需求，重新判断 start
                    // if (notFnmListhomebuy[i].InspectionCard__c != notFnmListhomebuy[i+1].InspectionCard__c) {
                    if (notFnmListhomebuy[i].InspectionCard_NoHave__c != notFnmListhomebuy[i+1].InspectionCard_NoHave__c) {
                    //2023 0208 fy add   报关单商检证新需求，重新判断 end
                        init.count_sj = n_sj;
                    }
                    // 2023-01-10 fy  add end
                }else if(notFnmListhomebuy.size() == 1){
                    init.count = 1;
                    init.count_sj = 1; // 2023-01-10   fy   add   如果只有一条  赋值合并行数
                }
            System.debug('init1===='+init);
            }else {
                // 判断与前一个编码是一致
                //2023 0208 fy add   报关单商检证新需求，重新判断 start
                // if (notFnmListhomebuy[i].ApplyList__c == notFnmListhomebuy[i-1].ApplyList__c) {
                if (notFnmListhomebuy[i].ApplyList_NoHave__c == notFnmListhomebuy[i-1].ApplyList_NoHave__c) {
                //2023 0208 fy add   报关单商检证新需求，重新判断 end
                    init.Name = notFnmListhomebuy[i].ManagementCode__c;
                    init.ProductName = notFnmListhomebuy[i].Material__c + '-' + notFnmListhomebuy[i].MaterialDepict__c;

                    //2022-12-26 fy add 改造 start
                    // // init.code = notFnmListhomebuy[i].ApplyList__c;
	                // if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.DownloadLink__c)) {
	                // 	init.code = notFnmListhomebuy[i].ApplyList_Select__r.DownloadLink__c;
                    //     init.codeyu = notFnmListhomebuy[i].ApplyList_Select__r.ViewLink__c;
	                // }else{
	                // 	init.code = '无';
	                // } //2022-12-05 fy add 报关单判断
                    //2023 0208 fy add   报关单商检证新需求，重新判断 start
                    if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__c)) {
                        // 报关单预览链接判断
                        // if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.ViewLink__c)) {
                        //     init.codeyu = notFnmListhomebuy[i].ApplyList_Select__r.ViewLink__c;
                        // }else{
                        if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.View_Link__c)) {
                            init.codeyu = notFnmListhomebuy[i].ApplyList_Select__r.View_Link__c;
                        }else{
                            init.codeyu = '';
                        }
                        // 报关单下载链接判断
                        if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.DownloadLink__c)) {
                            init.code = notFnmListhomebuy[i].ApplyList_Select__r.DownloadLink__c;
                        }else{
                            init.code = '';
                        }
                        //报关单awkey,filename判断 zhj 2022-12-08 start
                        if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.AWS_File_Key__c)) {
                            init.awsKey = notFnmListhomebuy[i].ApplyList_Select__r.AWS_File_Key__c;
                        }else{
                            init.awsKey = '';
                        }
                        if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.FileName__c)) {
                            init.fileName = notFnmListhomebuy[i].ApplyList_Select__r.FileName__c;
                        }else{
                            init.fileName = '';
                        }
                        //报关单awkey,filename判断 zhj 2022-12-08 end
                    }else {
                        if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_NoHave__c)) {
                            init.code = notFnmListhomebuy[i].ApplyList_NoHave__c;
                        }else{
                            init.code = '';
                        }
                        init.codeyu = '';
                        init.awsKey = '';       // zhj 2022-12-08 
                        init.fileName = '';     // zhj 2022-12-08
                    } 

                    // if (String.isNotBlank(notFnmListhomebuy[i].ApplyList__c)) {
	                // 	if (notFnmListhomebuy[i].ApplyList__c.equals('不出证')) {
	                // 		init.code = '不出证';
	                // 	}else{
	                // 		// 报关单预览链接判断
	                // 		if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.ViewLink__c)) {
			        //         	init.codeyu = notFnmListhomebuy[i].ApplyList_Select__r.ViewLink__c;
			        //         }else{
			        //         	init.codeyu = '';
			        //         }
	                // 		// 报关单下载链接判断
	                // 		if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.DownloadLink__c)) {
			        //         	init.code = notFnmListhomebuy[i].ApplyList_Select__r.DownloadLink__c;
			        //         }else{
			        //         	init.code = '';
			        //         }
                    //         //报关单awkey,filename判断 zhj 2022-12-08 start
                    //         if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.AWS_File_Key__c)) {
                    //             init.awsKey = notFnmListhomebuy[i].ApplyList_Select__r.AWS_File_Key__c;
                    //         }else{
                    //             init.awsKey = '';
                    //         }
                    //         if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.FileName__c)) {
                    //             init.fileName = notFnmListhomebuy[i].ApplyList_Select__r.FileName__c;
                    //         }else{
                    //             init.fileName = '';
                    //         }
                    //         //报关单awkey,filename判断 zhj 2022-12-08 end
                    //     }
	                // }else{
	                // 	init.code = '';
	                // 	init.codeyu = '';
                    //     init.awsKey = '';       // zhj 2022-12-08 
                    //     init.fileName = '';     // zhj 2022-12-08
	                // }
                    //2023 0208 fy add   报关单商检证新需求，重新判断 end

                    //if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.DownloadLink__c)) {
                    // if (notFnmListhomebuy[i].InspectionCard__c =='不出证') {
                    //     init.sj_code = '不出证';
                    // }else if(String.isBlank(notFnmListhomebuy[i].InspectionCard_Select__r.DownloadLink__c)){
                    //     init.sj_code = '';
                    // }else{
                    //     init.sj_code = notFnmListhomebuy[i].InspectionCard_Select__r.DownloadLink__c;
                    //     init.sj_codeyu = notFnmListhomebuy[i].InspectionCard_Select__r.ViewLink__c;
                    // }
                    // //2022-12-05 fy add 商检证判断

                    //2023 0208 fy add   报关单商检证新需求，重新判断 start
                    if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__c)) {
                        // 报关单预览链接判断
                        // if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.ViewLink__c)) {
                        //     init.sj_codeyu = notFnmListhomebuy[i].InspectionCard_Select__r.ViewLink__c;
                        // }else{
                        if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.View_Link__c)) {
                            init.sj_codeyu = notFnmListhomebuy[i].InspectionCard_Select__r.View_Link__c;
                        }else{
                            init.sj_codeyu = '';
                        }
                        // 报关单下载链接判断
                        if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.DownloadLink__c)) {
                            init.sj_code = notFnmListhomebuy[i].InspectionCard_Select__r.DownloadLink__c;
                        }else{
                            init.sj_code = '';
                        }
                        //报关单awkey,filename判断 zhj 2022-12-08 start
                        if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.AWS_File_Key__c)) {
                            init.sj_awsKey = notFnmListhomebuy[i].InspectionCard_Select__r.AWS_File_Key__c;
                        }else{
                            init.sj_awsKey = '';
                        }
                        if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.FileName__c)) {
                            init.sj_fileName = notFnmListhomebuy[i].InspectionCard_Select__r.FileName__c;
                        }else{
                            init.sj_fileName = '';
                        }
                        //报关单awkey,filename判断 zhj 2022-12-08 end
                    }else {
                        if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_NoHave__c)) {
                            init.sj_code = notFnmListhomebuy[i].InspectionCard_NoHave__c;
                        }else{
                            init.sj_code = '';
                        }
                        init.sj_codeyu = '';
                        init.sj_awsKey = '';       // zhj 2022-12-08 
                        init.sj_fileName = '';     // zhj 2022-12-08
                    } 

                    // if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard__c)) {
	                // 	if (notFnmListhomebuy[i].InspectionCard__c.equals('不出证')) {
	                // 		init.sj_code = '不出证';
	                // 	}else{
	                // 		// 商检证预览链接判断
	                // 		if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.ViewLink__c)) {
			        //         	init.sj_codeyu = notFnmListhomebuy[i].InspectionCard_Select__r.ViewLink__c;
			        //         }else{
			        //         	init.sj_codeyu = '';
			        //         }
	                // 		// 商检证下载链接判断
	                // 		if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.DownloadLink__c)) {
			        //         	init.sj_code = notFnmListhomebuy[i].InspectionCard_Select__r.DownloadLink__c;
			        //         }else{
			        //         	init.sj_code = '';
			        //         }
                    //         //商检证awkey,filename判断 zhj 2022-12-19 start
                    //         if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.AWS_File_Key__c)) {
                    //             init.sj_awsKey = notFnmListhomebuy[i].InspectionCard_Select__r.AWS_File_Key__c;
                    //         }else{
                    //             init.sj_awsKey = '';
                    //         }
                    //         if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.FileName__c)) {
                    //             init.sj_fileName = notFnmListhomebuy[i].InspectionCard_Select__r.FileName__c;
                    //         }else{
                    //             init.sj_fileName = '';
                    //         }
                    //         //商检证awkey,filename判断 zhj 2022-12-19 end
	                // 	}
	                // }else{
	                // 	init.sj_code = '';
	                // 	init.sj_codeyu = '';
                    //     init.sj_awsKey = '';       // zhj 2022-12-19 
                    //     init.sj_fileName = '';     // zhj 2022-12-19
	                // }
                    // //2022-12-26 fy add 改造 end
                    //2023 0208 fy add   报关单商检证新需求，重新判断 end
                    
                    // init.code = FileStrMap.get(notFnmListhomebuy[i].ApplyList__c);
                    init.Num = notFnmListhomebuy[i].Num__c;
                    init.Id = notFnmListhomebuy[i].Id;
                    init.FrameNo = notFnmListhomebuy[i].SerialNumber__c;
                    n = n+1;
                    // 判断是不是最后一个
                    if (i != notFnmListhomebuy.size()-1) {
                        // 不是最后一个，判断与下一个编码一致不一致，不一致直接赋值
                         //2023 0208 fy add   报关单商检证新需求，重新判断 start
                        // if (notFnmListhomebuy[i].ApplyList__c != notFnmListhomebuy[i+1].ApplyList__c) {
                        if (notFnmListhomebuy[i].ApplyList_NoHave__c != notFnmListhomebuy[i+1].ApplyList_NoHave__c) {
                        //2023 0208 fy add   报关单商检证新需求，重新判断 end
                            init.count = n;
                        }
                    }
                    // 最后一个直接赋值
                    if (i == notFnmListhomebuy.size()-1) {
                        init.count = n;
                    }
                System.debug('init2===='+init);
                }else {
                    // 下一组开始
                    n = 0;
                    init.Name = notFnmListhomebuy[i].ManagementCode__c;
                    init.ProductName = notFnmListhomebuy[i].Material__c + '-' + notFnmListhomebuy[i].MaterialDepict__c;
                    // init.code = notFnmListhomebuy[i].ApplyList__c;

                    //2022-12-26 fy add 改造 start
	                // if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.DownloadLink__c)) {
	                // 	init.code = notFnmListhomebuy[i].ApplyList_Select__r.DownloadLink__c;
                    //     init.codeyu = notFnmListhomebuy[i].ApplyList_Select__r.ViewLink__c;
	                // }else{
	                // 	init.code = '无';
	                // } //2022-12-05 fy add 报关单判断
                    //2023 0208 fy add   报关单商检证新需求，重新判断 start
                    if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__c)) {
                        // 报关单预览链接判断
                        // if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.ViewLink__c)) {
                        //     init.codeyu = notFnmListhomebuy[i].ApplyList_Select__r.ViewLink__c;
                        // }else{
                        if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.View_Link__c)) {
                            init.codeyu = notFnmListhomebuy[i].ApplyList_Select__r.View_Link__c;
                        }else{
                            init.codeyu = '';
                        }
                        // 报关单下载链接判断
                        if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.DownloadLink__c)) {
                            init.code = notFnmListhomebuy[i].ApplyList_Select__r.DownloadLink__c;
                        }else{
                            init.code = '';
                        }
                        //报关单awkey,filename判断 zhj 2022-12-08 start
                        if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.AWS_File_Key__c)) {
                            init.awsKey = notFnmListhomebuy[i].ApplyList_Select__r.AWS_File_Key__c;
                        }else{
                            init.awsKey = '';
                        }
                        if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.FileName__c)) {
                            init.fileName = notFnmListhomebuy[i].ApplyList_Select__r.FileName__c;
                        }else{
                            init.fileName = '';
                        }
                        //报关单awkey,filename判断 zhj 2022-12-08 end
                    }else {
                        if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_NoHave__c)){
                            init.code = notFnmListhomebuy[i].ApplyList_NoHave__c;
                        }else{
                            init.code = '';
                        }
                        init.codeyu = '';
                        init.awsKey = '';       // zhj 2022-12-08 
                        init.fileName = '';     // zhj 2022-12-08
                    } 

                    // if (String.isNotBlank(notFnmListhomebuy[i].ApplyList__c)) {
	                // 	if (notFnmListhomebuy[i].ApplyList__c.equals('不出证')) {
	                // 		init.code = '不出证';
	                // 	}else{
	                // 		// 报关单预览链接判断
	                // 		if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.ViewLink__c)) {
			        //         	init.codeyu = notFnmListhomebuy[i].ApplyList_Select__r.ViewLink__c;
			        //         }else{
			        //         	init.codeyu = '';
			        //         }
	                // 		// 报关单下载链接判断
	                // 		if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.DownloadLink__c)) {
			        //         	init.code = notFnmListhomebuy[i].ApplyList_Select__r.DownloadLink__c;
			        //         }else{
			        //         	init.code = '';
			        //         }
                    //         //报关单awkey,filename判断 zhj 2022-12-08 start
                    //         if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.AWS_File_Key__c)) {
                    //             init.awsKey = notFnmListhomebuy[i].ApplyList_Select__r.AWS_File_Key__c;
                    //         }else{
                    //             init.awsKey = '';
                    //         }
                    //         if (String.isNotBlank(notFnmListhomebuy[i].ApplyList_Select__r.FileName__c)) {
                    //             init.fileName = notFnmListhomebuy[i].ApplyList_Select__r.FileName__c;
                    //         }else{
                    //             init.fileName = '';
                    //         }
                    //         //报关单awkey,filename判断 zhj 2022-12-08 end
	                // 	}
	                // }else{
	                // 	init.code = '';
	                // 	init.codeyu = '';
                    //     init.awsKey = '';       // zhj 2022-12-08 
                    //     init.fileName = '';     // zhj 2022-12-08
	                // }
                    //2023 0208 fy add   报关单商检证新需求，重新判断 end
                    
                    //if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.DownloadLink__c)) {
                    // if (notFnmListhomebuy[i].InspectionCard__c =='不出证') {
                    //     init.sj_code = '不出证';
                    // }else if(String.isBlank(notFnmListhomebuy[i].InspectionCard_Select__r.DownloadLink__c)){
                    //     init.sj_code = '';
                    // }else{
                    //     init.sj_code = notFnmListhomebuy[i].InspectionCard_Select__r.DownloadLink__c;
                    //     init.sj_codeyu = notFnmListhomebuy[i].InspectionCard_Select__r.ViewLink__c;
                    // }
                    //2022-12-05 fy add 商检证判断

                    //2023 0208 fy add   报关单商检证新需求，重新判断 start
                    if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__c)) {
                        // 报关单预览链接判断
                        // if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.ViewLink__c)) {
                            // init.sj_codeyu = notFnmListhomebuy[i].InspectionCard_Select__r.ViewLink__c;
                        // }else{
                        if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.View_Link__c)) {
                            init.sj_codeyu = notFnmListhomebuy[i].InspectionCard_Select__r.View_Link__c;
                        }else{
                            init.sj_codeyu = '';
                        }
                        // 报关单下载链接判断
                        if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.DownloadLink__c)) {
                            init.sj_code = notFnmListhomebuy[i].InspectionCard_Select__r.DownloadLink__c;
                        }else{
                            init.sj_code = '';
                        }
                        //报关单awkey,filename判断 zhj 2022-12-08 start
                        if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.AWS_File_Key__c)) {
                            init.sj_awsKey = notFnmListhomebuy[i].InspectionCard_Select__r.AWS_File_Key__c;
                        }else{
                            init.sj_awsKey = '';
                        }
                        if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.FileName__c)) {
                            init.sj_fileName = notFnmListhomebuy[i].InspectionCard_Select__r.FileName__c;
                        }else{
                            init.sj_fileName = '';
                        }
                        //报关单awkey,filename判断 zhj 2022-12-08 end
                    }else {
                        if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_NoHave__c)) {
                            init.sj_code = notFnmListhomebuy[i].InspectionCard_NoHave__c;
                        }else{
                            init.sj_code = '';
                        }
                        init.sj_codeyu = '';
                        init.sj_awsKey = '';       // zhj 2022-12-08 
                        init.sj_fileName = '';     // zhj 2022-12-08
                    } 

                    // if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard__c)) {
	                // 	if (notFnmListhomebuy[i].InspectionCard__c.equals('不出证')) {
	                // 		init.sj_code = '不出证';
	                // 	}else{
	                // 		// 商检证预览链接判断
	                // 		if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.ViewLink__c)) {
			        //         	init.sj_codeyu = notFnmListhomebuy[i].InspectionCard_Select__r.ViewLink__c;
			        //         }else{
			        //         	init.sj_codeyu = '';
			        //         }
	                // 		// 商检证下载链接判断
	                // 		if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.DownloadLink__c)) {
			        //         	init.sj_code = notFnmListhomebuy[i].InspectionCard_Select__r.DownloadLink__c;
			        //         }else{
			        //         	init.sj_code = '';
			        //         }
                    //         //商检证awkey,filename判断 zhj 2022-12-19 start
                    //         if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.AWS_File_Key__c)) {
                    //             init.sj_awsKey = notFnmListhomebuy[i].InspectionCard_Select__r.AWS_File_Key__c;
                    //         }else{
                    //             init.sj_awsKey = '';
                    //         }
                    //         if (String.isNotBlank(notFnmListhomebuy[i].InspectionCard_Select__r.FileName__c)) {
                    //             init.sj_fileName = notFnmListhomebuy[i].InspectionCard_Select__r.FileName__c;
                    //         }else{
                    //             init.sj_fileName = '';
                    //         }
                    //         //商检证awkey,filename判断 zhj 2022-12-19 end
	                // 	}
	                // }else{
	                // 	init.sj_code = '';
	                // 	init.sj_codeyu = '';
                    //     init.sj_awsKey = '';       // zhj 2022-12-19 
                    //     init.sj_fileName = '';     // zhj 2022-12-19
	                // }
                    // //2022-12-26 fy add 改造 end
                    //2023 0208 fy add   报关单商检证新需求，重新判断 end

                    // init.code = FileStrMap.get(notFnmListhomebuy[i].ApplyList__c);
                    init.Num = notFnmListhomebuy[i].Num__c;
                    init.Id = notFnmListhomebuy[i].Id;
                    init.FrameNo = notFnmListhomebuy[i].SerialNumber__c;
                    n = n+1;

                    //2023 0208 fy add   报关单商检证新需求，重新判断 start
                    // if((i<notFnmListhomebuy.size()-1 && notFnmListhomebuy[i].ApplyList__c != notFnmListhomebuy[i+1].ApplyList__c)||(i == notFnmListhomebuy.size()-1)){
                    if((i<notFnmListhomebuy.size()-1 && notFnmListhomebuy[i].ApplyList_NoHave__c != notFnmListhomebuy[i+1].ApplyList_NoHave__c)||(i == notFnmListhomebuy.size()-1)){
                    //2023 0208 fy add   报关单商检证新需求，重新判断 end

                      init.count =n;
                    }
                System.debug('init3===='+init);
                }
                // 2023-01-10   fy   add   start   商检证排序合并
                //2023 0208 fy add   报关单商检证新需求，重新判断 start
                // if (notFnmListhomebuy[i].InspectionCard__c == notFnmListhomebuy[i-1].InspectionCard__c) {
                if (notFnmListhomebuy[i].InspectionCard_NoHave__c == notFnmListhomebuy[i-1].InspectionCard_NoHave__c) {
                //2023 0208 fy add   报关单商检证新需求，重新判断 end
                    n_sj = n_sj+1;
                    if (i != notFnmListhomebuy.size()-1) {
                        //2023 0208 fy add   报关单商检证新需求，重新判断 start
                        // if (notFnmListhomebuy[i].InspectionCard__c != notFnmListhomebuy[i+1].InspectionCard__c) {
                        if (notFnmListhomebuy[i].InspectionCard_NoHave__c != notFnmListhomebuy[i+1].InspectionCard_NoHave__c) {
                        //2023 0208 fy add   报关单商检证新需求，重新判断 end
                            init.count_sj = n_sj;
                        }
                    }else{
                        init.count_sj = n_sj;
                    }

                }else{
                    n_sj = 0;
                    n_sj = n_sj+1;
                    if (i == notFnmListhomebuy.size()-1) {
                        init.count_sj = n_sj;
                    }else{
                        //2023 0208 fy add   报关单商检证新需求，重新判断 start
                        // if (notFnmListhomebuy[i].InspectionCard__c != notFnmListhomebuy[i+1].InspectionCard__c) {
                            if (notFnmListhomebuy[i].InspectionCard_NoHave__c != notFnmListhomebuy[i+1].InspectionCard_NoHave__c) {
                        //2023 0208 fy add   报关单商检证新需求，重新判断 end
                            init.count_sj = n_sj;
                        }
                    }
                }
                // 2023-01-10   fy   add   end   商检证排序合并
            }
            //zhj 如果是eSignSystem需要加上这个前缀链接  2023-01-04 start
            if(bool){
                init.iseSignSystem = '/eSignSystem';
            }else {
                init.iseSignSystem = '';
            }
            //zhj 如果是eSignSystem需要加上这个前缀链接  2023-01-04 end
            initList.add(init);
        }
         //2023 0208 fy add   报关单商检证新需求，重新判断 start
        // List<testInit> newinitListhomebuy = new List<testInit>();
        // for(FrameNumManage__c fr : FnmListhomebuy){
        //     testInit init = new testInit();
        //     init.Name=fr.ManagementCode__c;
        //     init.ProductName=fr.Material__c + '-' + fr.MaterialDepict__c;
        //     init.FrameNo=fr.SerialNumber__c;
        //     init.code='国内采购';
        //     init.sj_code='国内采购';
        //     init.Num=fr.Num__c;
        //     init.Id=fr.Id;
        //     init.count=1;
        //     newinitListhomebuy.add(init);
        // }
        //2023 0208 fy add   报关单商检证新需求，重新判断 end
        // 倒序显示
        for (Integer i = initList.size()-1; i>=0 ; i--) {
            testInit init = new testInit();
            init = initList[i];
            newinitList.add(init);
        }
         // newinitList.addAll(newinitListhomebuy);
        //2023 0208 fy add   报关单商检证新需求，重新判断 start
        //  newinitListhomebuy.addAll(newinitList);
        //  newinitList=newinitListhomebuy;
        //2023 0208 fy add   报关单商检证新需求，重新判断 end
        System.debug('newinitList'+newinitList);
        System.debug('FnmList'+FnmList);
        // System.debug('newinitListhomebuy'+newinitListhomebuy);
        return newinitList;

    }
    // 定义内部类，自定义参数
    class testInit{
        @AuraEnabled
        public Boolean check;
        @AuraEnabled
        public String Name;
        @AuraEnabled
        public String ProductName;
        @AuraEnabled
        public String FrameNo;
        @AuraEnabled
        public String code;
        @AuraEnabled
        public String codeyu;
        @AuraEnabled
        public String sj_code;
        @AuraEnabled
        public String sj_codeyu;
        @AuraEnabled
        public Decimal Num;
        @AuraEnabled
        public String Id;
        @AuraEnabled
        public Integer count;
        @AuraEnabled
        public Integer count_sj;//2023-01-10 fy add 商检证单独合并
        @AuraEnabled
        public String awsKey;
        @AuraEnabled          
        public String fileName;
        @AuraEnabled        
        public String sj_awsKey; 
        @AuraEnabled     
        public String sj_fileName;
        @AuraEnabled
        public String iseSignSystem; //zhj 站点链接 2023-01-04
    }
}