111
沙世明
2022-11-22 928399eceec50e3d37ea08669a12789a9410a9d2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
public without sharing class FrameNumController {
 
    public List<FrameNumManage__c> FnmList{get; set;}
    public List<FileAddress__c> FileList{get; set;}
    public List<String> FileStrList{get; set;} //用于存文件名
    public List<testInit> initList{get; set;}
    public List<testInit> newinitList{get; set;}
    public Map<String,FrameNumManage__c> FnmMap{get; set;}
    public Map<String,String> FnmStrMap{get; set;} //用于存管理表的单名
    public Map<String,FileAddress__c> FileMap{get; set;}
    public Map<String,String> FileStrMap{get; set;} //用于存文件下载链接
    public List<Map<String,FrameNumManage__c>> mapList{get; set;}
    public List<String> strList{get; set;}
    public FrameNumController() { 
        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, SerialNumber__c,Material__c , MaterialDepict__c from FrameNumManage__c];
        FnmList = new List<FrameNumManage__c>();
        initList = new List<testInit>();
        newinitList = new List<testInit>();
    }
    public void init(){
        FnmMap = new Map<String,FrameNumManage__c>();
        FileStrMap = new Map<String,String>();
        FnmStrMap = new Map<String,String>();
        FileStrList = new List<String>();
        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 order by ApplyList__c desc];
        /*if (FnmList.size()>0) {
            for (FrameNumManage__c nObj : FnmList ) {
                FnmStrMap.put(nObj.ApplyList__c, nObj.ApplyList__c);
            }
            for (String str : FnmStrMap.keySet()) {
                FileStrList.add(str);
            }
            FileList = [SELECT Id, Name, FileName__c,ViewLink__c  FROM FileAddress__c WHERE FileName__c IN: FileStrList];
            for (FileAddress__c file : FileList) {
                FileStrMap.put(file.FileName__c, file.ViewLink__c);
            }
        }*/ // 2022-11-21 zyh 注释:ljh的Batch直接赋值,暂时无需再次查找
        // for (ImportDocT__c nObj : testList) {
        //  if (testMap==null) {
        //      testMap.put(nObj.code__c, nObj);
        //  }else{
        //      testMap.put(nObj.code__c, nObj);
        //  }
        //  if (testMap.size() > 0) {
        //      mapList.add(testMap);
        //  }
        // }
        // for (ImportDocT__c mObj : testMap) {
        //  strList.add(testMap.get(mObj.code__c).size());
        // }
        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);
        }
    }
    // 定义内部类,自定义参数
    class testInit{
        public Boolean check{get; set;}
        public String ProductName{get; set;}
        public String Name{get; set;}
        public String FrameNo{get; set;}
        public String code{get; set;}
        public String sj_code{get; set;}
        public Decimal Num{get; set;}
        public String Id{get; set;}
        public Integer count{get; set;}
    }
}