public without sharing class AttachmentDisplayController {
    @AuraEnabled
    public static List<testInit> getFrameNumManage(String DNId){
        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, ApplyList__c ,InspectionCard_Select__c ,InspectionCard_Select__r.ViewLink__c,InspectionCard_Select__r.DownloadLink__c, ApplyList_Select__c,ApplyList_Select__r.DownloadLink__c,ApplyList_Select__r.ViewLink__c,  Num__c , SerialNumber__c,Material__c , MaterialDepict__c from FrameNumManage__c where signInForm__c =:DNId order by ApplyList__c desc];
        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);
        //         }
        //     }
        // }

        Integer n = 0; // 初始化合并行数
        for (Integer i=0;i<FnmList.size() ;i++ ) {
            testInit init = new testInit();
            if (i==0) {
                init.Name = FnmList[i].ManagementCode__c;
                init.ProductName = FnmList[i].Material__c + '-' + FnmList[i].MaterialDepict__c;
                // init.code = FnmList[i].ApplyList__c;
                if (String.isNotBlank(FnmList[i].ApplyList_Select__r.DownloadLink__c)) {
                	init.code = FnmList[i].ApplyList_Select__r.DownloadLink__c;
                }else{
                	init.code = '不出证';
                } //2022-11-21 zyh add 报关单判断
                if (String.isNotBlank(FnmList[i].InspectionCard_Select__r.DownloadLink__c)) {
                	init.sj_code = FnmList[i].InspectionCard_Select__r.DownloadLink__c;
                }else{
                	init.sj_code = '不出证';
                } //2022-11-21 zyh add 商检证判断
                
                // init.code = FileStrMap.get(FnmList[i].ApplyList__c);
                init.Num = FnmList[i].Num__c;
                init.Id = FnmList[i].Id;
                init.FrameNo = FnmList[i].SerialNumber__c;
                n = n+1;
                if (i != FnmList.size()-1) {
                    // 判断第一个与第二个是否一样，不一样赋值1
                    if (FnmList[i].ApplyList__c != FnmList[i+1].ApplyList__c) {
                        init.count = n;
                    }
                }
            }else {
                // 判断与前一个编码是一致
                if (FnmList[i].ApplyList__c == FnmList[i-1].ApplyList__c) {
                    init.Name = FnmList[i].ManagementCode__c;
                    init.ProductName = FnmList[i].Material__c + '-' + FnmList[i].MaterialDepict__c;
                    // init.code = FnmList[i].ApplyList__c;
	                if (String.isNotBlank(FnmList[i].ApplyList_Select__r.DownloadLink__c)) {
	                	init.code = FnmList[i].ApplyList_Select__r.DownloadLink__c;
	                }else{
	                	init.code = '不出证';
	                } //2022-11-21 zyh add 报关单判断
	                if (String.isNotBlank(FnmList[i].InspectionCard_Select__r.DownloadLink__c)) {
	                	init.sj_code = FnmList[i].InspectionCard_Select__r.DownloadLink__c;
	                }else{
	                	init.sj_code = '不出证';
	                } //2022-11-21 zyh add 商检证判断
                    // init.code = FileStrMap.get(FnmList[i].ApplyList__c);
                    init.Num = FnmList[i].Num__c;
                    init.Id = FnmList[i].Id;
                    init.FrameNo = FnmList[i].SerialNumber__c;
                    n = n+1;
                    // 判断是不是最后一个
                    if (i != FnmList.size()-1) {
                        // 不是最后一个，判断与下一个编码一致不一致，不一致直接赋值
                        if (FnmList[i].ApplyList__c != FnmList[i+1].ApplyList__c) {
                            init.count = n;
                        }
                    }
                    // 最后一个直接赋值
                    if (i == FnmList.size()-1) {
                        init.count = n;
                    }
                }else {
                    // 下一组开始
                    n = 0;
                    init.Name = FnmList[i].ManagementCode__c;
                    init.ProductName = FnmList[i].Material__c + '-' + FnmList[i].MaterialDepict__c;
                    // init.code = FnmList[i].ApplyList__c;
	                if (String.isNotBlank(FnmList[i].ApplyList_Select__r.DownloadLink__c)) {
	                	init.code = FnmList[i].ApplyList_Select__r.DownloadLink__c;
	                }else{
	                	init.code = '不出证';
	                } //2022-11-21 zyh add 报关单判断
	                if (String.isNotBlank(FnmList[i].InspectionCard_Select__r.DownloadLink__c)) {
	                	init.sj_code = FnmList[i].InspectionCard_Select__r.DownloadLink__c;
	                }else{
	                	init.sj_code = '不出证';
	                } //2022-11-21 zyh add 商检证判断
                    // init.code = FileStrMap.get(FnmList[i].ApplyList__c);
                    init.Num = FnmList[i].Num__c;
                    init.Id = FnmList[i].Id;
                    init.FrameNo = FnmList[i].SerialNumber__c;
                    n = n+1;
                }
            }
            initList.add(init);
        }
        // 倒序显示
        for (Integer i = initList.size()-1; i>=0 ; i--) {
            testInit init = new testInit();
            init = initList[i];
            newinitList.add(init);
        }
        System.debug('newinitList'+newinitList);
        System.debug('FnmList'+FnmList);
        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 sj_code;
        @AuraEnabled
        public Decimal Num;
        @AuraEnabled
        public String Id;
        @AuraEnabled
        public Integer count;
    }
}