global without sharing class ImportDocTController {
|
public List<ImportDocT__c> testList{get; set;}
|
public List<testInit> initList{get; set;}
|
public List<testInit> newinitList{get; set;}
|
public Map<String,ImportDocT__c> testMap{get; set;}
|
public List<Map<String,ImportDocT__c>> mapList{get; set;}
|
public List<String> strList{get; set;}
|
public ImportDocTController() {
|
testList = [SELECT Id, Name , code__c from ImportDocT__c];
|
testList = new List<ImportDocT__c>();
|
initList = new List<testInit>();
|
newinitList = new List<testInit>();
|
}
|
public void init(){
|
testMap = new Map<String,ImportDocT__c>();
|
testList = [SELECT Id, Name , code__c , Num__c from ImportDocT__c order by code__c desc];
|
// 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<testList.size() ;i++ ) {
|
testInit init = new testInit();
|
if (i==0) {
|
init.Name = testList[i].Name;
|
init.code = testList[i].code__c;
|
init.Num = testList[i].Num__c;
|
init.Id = testList[i].Id;
|
n = n+1;
|
if (i != testList.size()-1) {
|
// 判断第一个与第二个是否一样,不一样赋值1
|
if (testList[i].code__c != testList[i+1].code__c) {
|
init.count = n;
|
}
|
}
|
}else {
|
// 判断与前一个编码是一致
|
if (testList[i].code__c == testList[i-1].code__c) {
|
init.Name = testList[i].Name;
|
init.code = testList[i].code__c;
|
init.Num = testList[i].Num__c;
|
init.Id = testList[i].Id;
|
n = n+1;
|
// 判断是不是最后一个
|
if (i != testList.size()-1) {
|
// 不是最后一个,判断与下一个编码一致不一致,不一致直接赋值
|
if (testList[i].code__c != testList[i+1].code__c) {
|
init.count = n;
|
}
|
}
|
// 最后一个直接赋值
|
if (i == testList.size()-1) {
|
init.count = n;
|
}
|
}else {
|
// 下一组开始
|
n = 0;
|
init.Name = testList[i].Name;
|
init.code = testList[i].code__c;
|
init.Num = testList[i].Num__c;
|
init.Id = testList[i].Id;
|
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 Name{get; set;}
|
public String code{get; set;}
|
public Decimal Num{get; set;}
|
public String Id{get; set;}
|
public Integer count{get; set;}
|
}
|
}
|