环境检测场景中的几个动态表单示例
先看源数据
主键 |
样品编号 |
检测项 |
点位名称 |
日期 |
时间 |
频次 |
属性名 |
检测值 |
参考值 |
判断结果 |
ID |
SAMPLE_CODE |
ITEM_NAME |
POINT_NAME |
YMD |
HMS |
RT |
FIELD_NAME |
VAL |
REF |
CHK |
1 |
SAMP001 |
铜 |
A |
2022-1-1 |
10:10:00 |
第1次 |
深度 |
1 |
1 |
合格 |
2 |
SAMP001 |
铜 |
A |
2022-1-1 |
10:10:00 |
第1次 |
含量 |
2 |
2 |
合格 |
3 |
SAMP001 |
CO2 |
A |
2022-1-2 |
12:10:00 |
第1次 |
浓度 |
1% |
5% |
合格 |
4 |
SAMP001 |
CO2 |
B |
2022-1-2 |
15:30:00 |
第1次 |
含量 |
6 |
1 |
不合格 |
5 |
SAMP001 |
CO2 |
C |
2022-1-2 |
16:30:00 |
第1次 |
深度 |
300 |
300 |
合格 |
6 |
SAMP001 |
硫化氢 |
A |
2022-1-2 |
10:10:00 |
第1次 |
含量 |
200 |
200 |
合格 |
7 |
SAMP001 |
硫化氢 |
C |
2022-1-2 |
12:10:00 |
第1次 |
浓度 |
100 |
100 |
合格 |
8 |
SAMP001 |
铜 |
A |
2022-1-1 |
10:10:00 |
第2次 |
深度 |
11 |
11 |
合格 |
9 |
SAMP001 |
铜 |
A |
2022-1-1 |
10:10:00 |
第2次 |
含量 |
21 |
21 |
合格 |
10 |
SAMP001 |
CO2 |
A |
2022-1-2 |
12:10:00 |
第2次 |
浓度 |
11% |
2% |
不合格 |
11 |
SAMP001 |
CO2 |
B |
2022-1-2 |
15:30:00 |
第2次 |
含量 |
31 |
20 |
不合格 |
12 |
SAMP001 |
CO2 |
C |
2022-1-2 |
16:30:00 |
第2次 |
深度 |
3001 |
3001 |
合格 |
13 |
SAMP001 |
硫化氢 |
A |
2022-1-2 |
10:10:00 |
第2次 |
含量 |
2001 |
2001 |
合格 |
14 |
SAMP001 |
铜 |
A |
2022-1-1 |
10:10:00 |
第3次 |
深度 |
11 |
11 |
合格 |
15 |
SAMP001 |
铜 |
A |
2022-1-1 |
10:10:00 |
第3次 |
含量 |
21 |
21 |
合格 |
16 |
SAMP001 |
CO2 |
A |
2022-1-2 |
12:10:00 |
第3次 |
浓度 |
11% |
2% |
不合格 |
17 |
SAMP001 |
CO2 |
B |
2022-1-2 |
15:30:00 |
第3次 |
含量 |
31 |
20 |
不合格 |
18 |
SAMP001 |
CO2 |
C |
2022-1-2 |
16:30:00 |
第3次 |
深度 |
33 |
22 |
合格 |
19 |
SAMP001 |
硫化氢 |
A |
2022-1-2 |
10:10:00 |
第4次 |
含量 |
99 |
2001 |
合格 |
20 |
SAMP001 |
铜 |
A |
2022-1-1 |
10:10:00 |
第4次 |
深度 |
11 |
11 |
合格 |
21 |
SAMP001 |
铜 |
A |
2022-1-1 |
10:10:00 |
第4次 |
含量 |
21 |
21 |
合格 |
22 |
SAMP001 |
CO2 |
A |
2022-1-2 |
12:10:00 |
第4次 |
浓度 |
11% |
2% |
不合格 |
23 |
SAMP001 |
CO2 |
B |
2022-1-2 |
15:30:00 |
第4次 |
含量 |
31 |
20 |
不合格 |
24 |
SAMP001 |
CO2 |
C |
2022-1-2 |
16:30:00 |
第4次 |
深度 |
77 |
3001 |
合格 |
25 |
SAMP001 |
硫化氢 |
A |
2022-1-2 |
10:10:00 |
第4次 |
含量 |
22 |
2001 |
合格 |
26 |
SAMP001 |
硫化氢 |
A |
2022-1-2 |
10:10:00 |
第5次 |
含量 |
55 |
2001 |
合格 |
27 |
SAMP001 |
铜 |
A |
2022-1-1 |
10:10:00 |
第5次 |
深度 |
11 |
11 |
合格 |
28 |
SAMP001 |
铜 |
A |
2022-1-1 |
10:10:00 |
第5次 |
含量 |
6 |
21 |
合格 |
29 |
SAMP001 |
CO2 |
A |
2022-1-2 |
12:10:00 |
第5次 |
浓度 |
15% |
2% |
不合格 |
30 |
SAMP001 |
CO2 |
B |
2022-1-2 |
15:30:00 |
第5次 |
含量 |
5 |
20 |
不合格 |
31 |
SAMP001 |
CO2 |
C |
2022-1-2 |
16:30:00 |
第5次 |
深度 |
301 |
3001 |
合格 |
111//取出数据集
DataSet set = service.querys("rpt_check_result");
======================================取单列值 频次作表头=========================================
要求输出表格 :
检测项 |
属性 |
第1次 |
第2次 |
第3次 |
第4次 |
第5次 |
铜 |
深度 |
1 |
11 |
11 |
11 |
11 |
含量 |
2 |
21 |
21 |
21 |
6 |
|
CO2 |
浓度 |
1% |
11% |
11% |
11% |
15% |
含量 |
6 |
31 |
31 |
31 |
5 |
|
深度 |
300 |
3001 |
33 |
77 |
301 |
|
硫化氢 |
含量 |
200 |
2001 |
# |
99 |
55 |
浓度 |
100 |
# |
# |
# |
# |
String union = "ITEM_NAME"; //需要合同的列 String pks = "ITEM_NAME,FIELD_NAME"; //逻辑主键 String clazzKey = "RT"; //根据RT列的值把行转成列 String valueKey = "VAL"; //取值 String headers = "检测项,属性"; //显示的表头 DataSet ds = set.pivot(pks, clazzKey, valueKey); List<String> clazzList = set.getDistinctStrings(clazzKey); //取出不重复的clazzKey值列表 Table table = TableBuilder.init() .setDatas(ds) //设置数据源 .setReplaceEmpty("#") //替换空值成# .setHeaders(headers.split(",")).addHeaders(clazzList) //添加表头 .setFields(pks.split(",")).addFields(clazzList) //需要显示的属性与表头要对应 .addUnions(union) //需要合并的列 .build();
转换后格式
[ { "ITEM_NAME":"铜", "FIELD_NAME":"深度", "第1次":"1", "第2次":"11", "第3次":"11", "第4次":"11", "第5次":"11" }, { "ITEM_NAME":"铜", "FIELD_NAME":"含量", "第1次":"2", "第2次":"21", "第3次":"21", "第4次":"21", "第5次":"6" }, { "ITEM_NAME":"CO2", "FIELD_NAME":"浓度", "第1次":"1%", "第2次":"11%", "第3次":"11%", "第4次":"11%", "第5次":"15%" }, { "ITEM_NAME":"CO2", "FIELD_NAME":"含量", "第1次":"6", "第2次":"31", "第3次":"31", "第4次":"31", "第5次":"5" }, { "ITEM_NAME":"CO2", "FIELD_NAME":"深度", "第1次":"300", "第2次":"3001", "第3次":"33", "第4次":"77", "第5次":"301" }, { "ITEM_NAME":"硫化氢", "FIELD_NAME":"含量", "第1次":"200", "第2次":"2001", "第3次":null, "第4次":"99", "第5次":"55" }, { "ITEM_NAME":"硫化氢", "FIELD_NAME":"浓度", "第1次":"100", "第2次":null, "第3次":null, "第4次":null, "第5次":null } ]
======================================取单列值 属性作表头=========================================
要求输出表格:
检测项 |
频次 |
浓度 |
含量 |
深度 |
CO2 |
第1次 |
1% |
6 |
300 |
第2次 |
11% |
31 |
3001 |
|
第3次 |
11% |
31 |
33 |
|
第4次 |
11% |
31 |
77 |
|
第5次 |
15% |
5 |
301 |
|
硫化氢 |
第1次 |
100 |
200 |
# |
第2次 |
# |
2001 |
# |
|
第4次 |
# |
99 |
# |
|
第5次 |
# |
55 |
# |
|
铜 |
第1次 |
# |
2 |
1 |
第2次 |
# |
21 |
11 |
|
第3次 |
# |
21 |
11 |
|
第4次 |
# |
21 |
11 |
|
第5次 |
# |
6 |
11 |
union = "ITEM_NAME"; //需需合并的列 pks = "ITEM_NAME,RT"; //逻辑主键 clazzKey = "FIELD_NAME"; //根据FIELD_NAME把行转成列 valueKey = "VAL"; //取值 valueLabel = "检测值"; headers = "检测项,频次"; //显示表头 set.order("ITEM_NAME"); //排序 ds = set.pivot(pks, clazzKey,valueKey); clazzList = set.getDistinctStrings(clazzKey); html = TableBuilder.init() .setDatas(ds) //设置数据源 .setReplaceEmpty("#") //替换空值 .setHeaders(headers.split(",")).addHeaders(clazzList) //设置表头 .setFields(pks.split(",")).addFields(clazzList) //需要显示的属性值与表头要对应 .addUnions(union) //合并列 .build().build();
转换后格式:
[ { "ITEM_NAME":"CO2", "RT":"第1次", "浓度":"1%", "含量":"6", "深度":"300" }, { "ITEM_NAME":"CO2", "RT":"第2次", "浓度":"11%", "含量":"31", "深度":"3001" }, { "ITEM_NAME":"CO2", "RT":"第3次", "浓度":"11%", "含量":"31", "深度":"33" }, { "ITEM_NAME":"CO2", "RT":"第4次", "浓度":"11%", "含量":"31", "深度":"77" }, { "ITEM_NAME":"CO2", "RT":"第5次", "浓度":"15%", "含量":"5", "深度":"301" }, { "ITEM_NAME":"硫化氢", "RT":"第1次", "浓度":"100", "含量":"200", "深度":null }, { "ITEM_NAME":"硫化氢", "RT":"第2次", "浓度":null, "含量":"2001", "深度":null }, { "ITEM_NAME":"硫化氢", "RT":"第4次", "浓度":null, "含量":"99", "深度":null }, { "ITEM_NAME":"硫化氢", "RT":"第5次", "浓度":null, "含量":"55", "深度":null }, { "ITEM_NAME":"铜", "RT":"第1次", "浓度":null, "含量":"2", "深度":"1" }, { "ITEM_NAME":"铜", "RT":"第2次", "浓度":null, "含量":"21", "深度":"11" }, { "ITEM_NAME":"铜", "RT":"第3次", "浓度":null, "含量":"21", "深度":"11" }, { "ITEM_NAME":"铜", "RT":"第4次", "浓度":null, "含量":"21", "深度":"11" }, { "ITEM_NAME":"铜", "RT":"第5次", "浓度":null, "含量":"6", "深度":"11" } ]
========================================取多列值 频次+类别作表头=================================
要求输出表格:
检测项 |
属性 |
第1次-检测值 |
第1次-参考值 |
第1次-判定结果 |
第2次-检测值 |
第2次-参考值 |
第2次-判定结果 |
第3次-检测值 |
第3次-参考值 |
第3次-判定结果 |
第4次-检测值 |
第4次-参考值 |
第4次-判定结果 |
第5次-检测值 |
第5次-参考值 |
第5次-判定结果 |
CO2 |
浓度 |
1% |
5% |
合格 |
11% |
2% |
不合格 |
11% |
2% |
不合格 |
11% |
2% |
不合格 |
15% |
2% |
不合格 |
含量 |
6 |
1 |
不合格 |
31 |
20 |
不合格 |
31 |
20 |
不合格 |
31 |
20 |
不合格 |
5 |
20 |
不合格 |
|
深度 |
300 |
300 |
合格 |
3001 |
3001 |
合格 |
33 |
22 |
合格 |
77 |
3001 |
合格 |
301 |
3001 |
合格 |
|
硫化氢 |
含量 |
200 |
200 |
合格 |
2001 |
2001 |
合格 |
# |
# |
# |
99 |
2001 |
合格 |
55 |
2001 |
合格 |
浓度 |
100 |
100 |
合格 |
# |
# |
# |
# |
# |
# |
# |
# |
# |
# |
# |
# |
|
铜 |
深度 |
1 |
1 |
合格 |
11 |
11 |
合格 |
11 |
11 |
合格 |
11 |
11 |
合格 |
11 |
11 |
合格 |
含量 |
2 |
2 |
合格 |
21 |
21 |
合格 |
21 |
21 |
合格 |
21 |
21 |
合格 |
6 |
21 |
合格 |
union = "ITEM_NAME"; //需要合并的列 pks = "ITEM_NAME,FIELD_NAME"; //逻辑主键 clazzKey = "RT"; //根据RT把行转成列 valueKey = "VAL,REF,CHK"; //多列取值 headers = "检测项,属性"; //表头(与逻辑主键对应) valueLabel = "检测值,参考值,判定结果"; //表头(与取值列对应) set.order("ITEM_NAME"); ds = set.pivot(pks, clazzKey,valueKey); clazzList = set.getDistinctStrings(clazzKey); //组合表头与取值列 List<List<String>> fieldArrays = BeanUtil.descartes(clazzList, BeanUtil.array2list(valueKey.split(","))); List<List<String>> headArrays = BeanUtil.descartes(clazzList, BeanUtil.array2list(valueLabel.split(","))); List<String> fields = new ArrayList<>(); List<String> heads = new ArrayList<>(); heads.addAll(BeanUtil.array2list(headers.split(","))); fields.addAll(BeanUtil.array2list(pks.split(","))); for(List<String> headArray:headArrays){ String head = BeanUtil.concat(headArray,"-"); heads.add(head); } for(List<String> fieldArray:fieldArrays){ String field = BeanUtil.concat(fieldArray,"-"); fields.add(field); } html = TableBuilder.init() .setDatas(ds) .setReplaceEmpty("#") .setHeaders(heads) .setFields(fields) .addUnions(union) .build().build();
转换后数据结构:
[ { "ITEM_NAME":"CO2", "FIELD_NAME":"浓度", "第1次-VAL":"1%", "第1次-REF":"5%", "第1次-CHK":"合格", "第2次-VAL":"11%", "第2次-REF":"2%", "第2次-CHK":"不合格", "第3次-VAL":"11%", "第3次-REF":"2%", "第3次-CHK":"不合格", "第4次-VAL":"11%", "第4次-REF":"2%", "第4次-CHK":"不合格", "第5次-VAL":"15%", "第5次-REF":"2%", "第5次-CHK":"不合格" }, { "ITEM_NAME":"CO2", "FIELD_NAME":"含量", "第1次-VAL":"6", "第1次-REF":"1", "第1次-CHK":"不合格", "第2次-VAL":"31", "第2次-REF":"20", "第2次-CHK":"不合格", "第3次-VAL":"31", "第3次-REF":"20", "第3次-CHK":"不合格", "第4次-VAL":"31", "第4次-REF":"20", "第4次-CHK":"不合格", "第5次-VAL":"5", "第5次-REF":"20", "第5次-CHK":"不合格" }, { "ITEM_NAME":"CO2", "FIELD_NAME":"深度", "第1次-VAL":"300", "第1次-REF":"300", "第1次-CHK":"合格", "第2次-VAL":"3001", "第2次-REF":"3001", "第2次-CHK":"合格", "第3次-VAL":"33", "第3次-REF":"22", "第3次-CHK":"合格", "第4次-VAL":"77", "第4次-REF":"3001", "第4次-CHK":"合格", "第5次-VAL":"301", "第5次-REF":"3001", "第5次-CHK":"合格" }, { "ITEM_NAME":"硫化氢", "FIELD_NAME":"含量", "第1次-VAL":"200", "第1次-REF":"200", "第1次-CHK":"合格", "第2次-VAL":"2001", "第2次-REF":"2001", "第2次-CHK":"合格", "第3次-VAL":null, "第3次-REF":null, "第3次-CHK":null, "第4次-VAL":"99", "第4次-REF":"2001", "第4次-CHK":"合格", "第5次-VAL":"55", "第5次-REF":"2001", "第5次-CHK":"合格" }, { "ITEM_NAME":"硫化氢", "FIELD_NAME":"浓度", "第1次-VAL":"100", "第1次-REF":"100", "第1次-CHK":"合格", "第2次-VAL":null, "第2次-REF":null, "第2次-CHK":null, "第3次-VAL":null, "第3次-REF":null, "第3次-CHK":null, "第4次-VAL":null, "第4次-REF":null, "第4次-CHK":null, "第5次-VAL":null, "第5次-REF":null, "第5次-CHK":null }, { "ITEM_NAME":"铜", "FIELD_NAME":"深度", "第1次-VAL":"1", "第1次-REF":"1", "第1次-CHK":"合格", "第2次-VAL":"11", "第2次-REF":"11", "第2次-CHK":"合格", "第3次-VAL":"11", "第3次-REF":"11", "第3次-CHK":"合格", "第4次-VAL":"11", "第4次-REF":"11", "第4次-CHK":"合格", "第5次-VAL":"11", "第5次-REF":"11", "第5次-CHK":"合格" }, { "ITEM_NAME":"铜", "FIELD_NAME":"含量", "第1次-VAL":"2", "第1次-REF":"2", "第1次-CHK":"合格", "第2次-VAL":"21", "第2次-REF":"21", "第2次-CHK":"合格", "第3次-VAL":"21", "第3次-REF":"21", "第3次-CHK":"合格", "第4次-VAL":"21", "第4次-REF":"21", "第4次-CHK":"合格", "第5次-VAL":"6", "第5次-REF":"21", "第5次-CHK":"合格" } ]
===========================取多列值 频次+类别作表头 分页显示======================================
要求输出表格:
第1页
检测项 |
属性 |
第1次-检测值 |
第1次-参考值 |
第1次-判定结果 |
第2次-检测值 |
第2次-参考值 |
第2次-判定结果 |
CO2 |
浓度 |
1% |
5% |
合格 |
11% |
2% |
不合格 |
含量 |
6 |
1 |
不合格 |
31 |
20 |
不合格 |
|
深度 |
300 |
300 |
合格 |
3001 |
3001 |
合格 |
|
硫化氢 |
含量 |
200 |
200 |
合格 |
2001 |
2001 |
合格 |
浓度 |
100 |
100 |
合格 |
# |
# |
# |
|
铜 |
深度 |
1 |
1 |
合格 |
11 |
11 |
合格 |
含量 |
2 |
2 |
合格 |
21 |
21 |
合格 |
第2页
检测项 |
属性 |
第3次-检测值 |
第3次-参考值 |
第3次-判定结果 |
第4次-检测值 |
第4次-参考值 |
第4次-判定结果 |
CO2 |
浓度 |
11% |
2% |
不合格 |
11% |
2% |
不合格 |
含量 |
31 |
20 |
不合格 |
31 |
20 |
不合格 |
|
深度 |
33 |
22 |
合格 |
77 |
3001 |
合格 |
|
硫化氢 |
含量 |
# |
# |
# |
99 |
2001 |
合格 |
铜 |
深度 |
11 |
11 |
合格 |
11 |
11 |
合格 |
含量 |
21 |
21 |
合格 |
21 |
21 |
合格 |
第3页
检测项 |
属性 |
第5次-检测值 |
第5次-参考值 |
第5次-判定结果 |
CO2 |
浓度 |
15% |
2% |
不合格 |
含量 |
5 |
20 |
不合格 |
|
深度 |
301 |
3001 |
合格 |
|
硫化氢 |
含量 |
55 |
2001 |
合格 |
union = "ITEM_NAME"; //需要合并的列 pks = "ITEM_NAME,FIELD_NAME"; //逻辑主键 clazzKey = "RT"; //根据RT把行转成列 valueKey = "VAL,REF,CHK"; //多列取值 headers = "检测项,属性"; //表头(与逻辑主键对应) set.order("ITEM_NAME"); int vol = 2; //每2次一页 clazzList = set.getDistinctStrings(clazzKey); int size = clazzList.size(); html = ""; int page = (size-1)/vol+1; for(int i=0; i<page; i++){ List<String> pageClazzList = BeanUtil.cuts(clazzList, i*vol, i*vol+vol-1); ds = set.select.in(clazzKey, pageClazzList).pivot(pks, clazzKey,valueKey); fieldArrays = BeanUtil.descartes(pageClazzList, BeanUtil.array2list(valueKey.split(","))); headArrays = BeanUtil.descartes(pageClazzList, BeanUtil.array2list(valueLabel.split(","))); fields = new ArrayList<>(); heads = new ArrayList<>(); heads.addAll(BeanUtil.array2list(headers.split(","))); fields.addAll(BeanUtil.array2list(pks.split(","))); for(List<String> headArray:headArrays){ String head = BeanUtil.concat(headArray,"-"); heads.add(head); } for(List<String> fieldArray:fieldArrays){ String field = BeanUtil.concat(fieldArray,"-"); fields.add(field); } html += "<div>第"+(i+1)+"页</div>"; html += TableBuilder.init().setHeaders(heads) .setDatas(ds).setFields(fields).addUnions(union) .setReplaceEmpty("#") .build().build(); }
[{"ITEM_NAME":"CO2","FIELD_NAME":"浓度","第1次-VAL":"1%","第1次-REF":"5%","第1次-CHK":"合格","第2次-VAL":"11%","第2次-REF":"2%","第2次-CHK":"不合格"},{"ITEM_NAME":"CO2","FIELD_NAME":"含量","第1次-VAL":"6","第1次-REF":"1","第1次-CHK":"不合格","第2次-VAL":"31","第2次-REF":"20","第2次-CHK":"不合格"},{"ITEM_NAME":"CO2","FIELD_NAME":"深度","第1次-VAL":"300","第1次-REF":"300","第1次-CHK":"合格","第2次-VAL":"3001","第2次-REF":"3001","第2次-CHK":"合格"},{"ITEM_NAME":"硫化氢","FIELD_NAME":"含量","第1次-VAL":"200","第1次-REF":"200","第1次-CHK":"合格","第2次-VAL":"2001","第2次-REF":"2001","第2次-CHK":"合格"},{"ITEM_NAME":"硫化氢","FIELD_NAME":"浓度","第1次-VAL":"100","第1次-REF":"100","第1次-CHK":"合格","第2次-VAL":null,"第2次-REF":null,"第2次-CHK":null},{"ITEM_NAME":"铜","FIELD_NAME":"深度","第1次-VAL":"1","第1次-REF":"1","第1次-CHK":"合格","第2次-VAL":"11","第2次-REF":"11","第2次-CHK":"合格"},{"ITEM_NAME":"铜","FIELD_NAME":"含量","第1次-VAL":"2","第1次-REF":"2","第1次-CHK":"合格","第2次-VAL":"21","第2次-REF":"21","第2次-CHK":"合格"}]
[{"ITEM_NAME":"CO2","FIELD_NAME":"浓度","第3次-VAL":"11%","第3次-REF":"2%","第3次-CHK":"不合格","第4次-VAL":"11%","第4次-REF":"2%","第4次-CHK":"不合格"},{"ITEM_NAME":"CO2","FIELD_NAME":"含量","第3次-VAL":"31","第3次-REF":"20","第3次-CHK":"不合格","第4次-VAL":"31","第4次-REF":"20","第4次-CHK":"不合格"},{"ITEM_NAME":"CO2","FIELD_NAME":"深度","第3次-VAL":"33","第3次-REF":"22","第3次-CHK":"合格","第4次-VAL":"77","第4次-REF":"3001","第4次-CHK":"合格"},{"ITEM_NAME":"硫化氢","FIELD_NAME":"含量","第3次-VAL":null,"第3次-REF":null,"第3次-CHK":null,"第4次-VAL":"99","第4次-REF":"2001","第4次-CHK":"合格"},{"ITEM_NAME":"铜","FIELD_NAME":"深度","第3次-VAL":"11","第3次-REF":"11","第3次-CHK":"合格","第4次-VAL":"11","第4次-REF":"11","第4次-CHK":"合格"},{"ITEM_NAME":"铜","FIELD_NAME":"含量","第3次-VAL":"21","第3次-REF":"21","第3次-CHK":"合格","第4次-VAL":"21","第4次-REF":"21","第4次-CHK":"合格"}]
[{"ITEM_NAME":"CO2","FIELD_NAME":"浓度","第5次-VAL":"15%","第5次-REF":"2%","第5次-CHK":"不合格"},{"ITEM_NAME":"CO2","FIELD_NAME":"含量","第5次-VAL":"5","第5次-REF":"20","第5次-CHK":"不合格"},{"ITEM_NAME":"CO2","FIELD_NAME":"深度","第5次-VAL":"301","第5次-REF":"3001","第5次-CHK":"合格"},{"ITEM_NAME":"硫化氢","FIELD_NAME":"含量","第5次-VAL":"55","第5次-REF":"2001","第5次-CHK":"合格"},{"ITEM_NAME":"铜","FIELD_NAME":"深度","第5次-VAL":"11","第5次-REF":"11","第5次-CHK":"合格"},{"ITEM_NAME":"铜","FIELD_NAME":"含量","第5次-VAL":"6","第5次-REF":"21","第5次-CHK":"合格"}]
=============================取多列值 属性+类别作表头===============================
要求输出表格
检测项 |
频次 |
浓度-检测值 |
浓度-参考值 |
浓度-判定结果 |
含量-检测值 |
含量-参考值 |
含量-判定结果 |
深度-检测值 |
深度-参考值 |
深度-判定结果 |
CO2 |
第1次 |
1% |
5% |
合格 |
6 |
1 |
不合格 |
300 |
300 |
合格 |
第2次 |
11% |
2% |
不合格 |
31 |
20 |
不合格 |
3001 |
3001 |
合格 |
|
第3次 |
11% |
2% |
不合格 |
31 |
20 |
不合格 |
33 |
22 |
合格 |
|
第4次 |
11% |
2% |
不合格 |
31 |
20 |
不合格 |
77 |
3001 |
合格 |
|
第5次 |
15% |
2% |
不合格 |
5 |
20 |
不合格 |
301 |
3001 |
合格 |
|
硫化氢 |
第1次 |
100 |
100 |
合格 |
200 |
200 |
合格 |
# |
# |
# |
第2次 |
# |
# |
# |
2001 |
2001 |
合格 |
# |
# |
# |
|
第4次 |
# |
# |
# |
99 |
2001 |
合格 |
# |
# |
# |
|
第5次 |
# |
# |
# |
55 |
2001 |
合格 |
# |
# |
# |
|
铜 |
第1次 |
# |
# |
# |
2 |
2 |
合格 |
1 |
1 |
合格 |
第2次 |
# |
# |
# |
21 |
21 |
合格 |
11 |
11 |
合格 |
|
第3次 |
# |
# |
# |
21 |
21 |
合格 |
11 |
11 |
合格 |
|
第4次 |
# |
# |
# |
21 |
21 |
合格 |
11 |
11 |
合格 |
|
第5次 |
# |
# |
# |
6 |
21 |
合格 |
11 |
11 |
合格 |
union = "ITEM_NAME"; //需要合并的列 pks = "ITEM_NAME,RT"; //逻辑主键 clazzKey = "FIELD_NAME"; //根据FIELD_NAME把行转成列 valueKey = "VAL,REF,CHK"; //多列取值 headers = "检测项,频次"; //表头(与逻辑主键对应) set.order("ITEM_NAME"); ds = set.pivot(pks, clazzKey,valueKey); clazzList = set.getDistinctStrings(clazzKey); //组合表头(属性与类别 两两组合) headArrays = BeanUtil.descartes(clazzList, BeanUtil.array2list(valueLabel.split(","))); fieldArrays = BeanUtil.descartes(clazzList, BeanUtil.array2list(valueKey.split(","))); heads = new ArrayList<>(); fields = new ArrayList<>(); heads.addAll(BeanUtil.array2list(headers.split(","))); fields.addAll(BeanUtil.array2list(pks.split(","))); for(List<String> headArray:headArrays){ String head = BeanUtil.concat(headArray,"-"); heads.add(head); } for(List<String> fieldArray:fieldArrays){ String field = BeanUtil.concat(fieldArray,"-"); fields.add(field); } html = TableBuilder.init() .setDatas(ds) .setReplaceEmpty("#") .setHeaders(heads) .setFields(fields) .addUnions(union) .build().build();
转换成数据结构:
[ { "ITEM_NAME":"CO2", "RT":"第1次", "浓度-VAL":"1%", "浓度-REF":"5%", "浓度-CHK":"合格", "含量-VAL":"6", "含量-REF":"1", "含量-CHK":"不合格", "深度-VAL":"300", "深度-REF":"300", "深度-CHK":"合格" }, { "ITEM_NAME":"CO2", "RT":"第2次", "浓度-VAL":"11%", "浓度-REF":"2%", "浓度-CHK":"不合格", "含量-VAL":"31", "含量-REF":"20", "含量-CHK":"不合格", "深度-VAL":"3001", "深度-REF":"3001", "深度-CHK":"合格" }, { "ITEM_NAME":"CO2", "RT":"第3次", "浓度-VAL":"11%", "浓度-REF":"2%", "浓度-CHK":"不合格", "含量-VAL":"31", "含量-REF":"20", "含量-CHK":"不合格", "深度-VAL":"33", "深度-REF":"22", "深度-CHK":"合格" }, { "ITEM_NAME":"CO2", "RT":"第4次", "浓度-VAL":"11%", "浓度-REF":"2%", "浓度-CHK":"不合格", "含量-VAL":"31", "含量-REF":"20", "含量-CHK":"不合格", "深度-VAL":"77", "深度-REF":"3001", "深度-CHK":"合格" }, { "ITEM_NAME":"CO2", "RT":"第5次", "浓度-VAL":"15%", "浓度-REF":"2%", "浓度-CHK":"不合格", "含量-VAL":"5", "含量-REF":"20", "含量-CHK":"不合格", "深度-VAL":"301", "深度-REF":"3001", "深度-CHK":"合格" }, { "ITEM_NAME":"硫化氢", "RT":"第1次", "浓度-VAL":"100", "浓度-REF":"100", "浓度-CHK":"合格", "含量-VAL":"200", "含量-REF":"200", "含量-CHK":"合格", "深度-VAL":null, "深度-REF":null, "深度-CHK":null }, { "ITEM_NAME":"硫化氢", "RT":"第2次", "浓度-VAL":null, "浓度-REF":null, "浓度-CHK":null, "含量-VAL":"2001", "含量-REF":"2001", "含量-CHK":"合格", "深度-VAL":null, "深度-REF":null, "深度-CHK":null }, { "ITEM_NAME":"硫化氢", "RT":"第4次", "浓度-VAL":null, "浓度-REF":null, "浓度-CHK":null, "含量-VAL":"99", "含量-REF":"2001", "含量-CHK":"合格", "深度-VAL":null, "深度-REF":null, "深度-CHK":null }, { "ITEM_NAME":"硫化氢", "RT":"第5次", "浓度-VAL":null, "浓度-REF":null, "浓度-CHK":null, "含量-VAL":"55", "含量-REF":"2001", "含量-CHK":"合格", "深度-VAL":null, "深度-REF":null, "深度-CHK":null }, { "ITEM_NAME":"铜", "RT":"第1次", "浓度-VAL":null, "浓度-REF":null, "浓度-CHK":null, "含量-VAL":"2", "含量-REF":"2", "含量-CHK":"合格", "深度-VAL":"1", "深度-REF":"1", "深度-CHK":"合格" }, { "ITEM_NAME":"铜", "RT":"第2次", "浓度-VAL":null, "浓度-REF":null, "浓度-CHK":null, "含量-VAL":"21", "含量-REF":"21", "含量-CHK":"合格", "深度-VAL":"11", "深度-REF":"11", "深度-CHK":"合格" }, { "ITEM_NAME":"铜", "RT":"第3次", "浓度-VAL":null, "浓度-REF":null, "浓度-CHK":null, "含量-VAL":"21", "含量-REF":"21", "含量-CHK":"合格", "深度-VAL":"11", "深度-REF":"11", "深度-CHK":"合格" }, { "ITEM_NAME":"铜", "RT":"第4次", "浓度-VAL":null, "浓度-REF":null, "浓度-CHK":null, "含量-VAL":"21", "含量-REF":"21", "含量-CHK":"合格", "深度-VAL":"11", "深度-REF":"11", "深度-CHK":"合格" }, { "ITEM_NAME":"铜", "RT":"第5次", "浓度-VAL":null, "浓度-REF":null, "浓度-CHK":null, "含量-VAL":"6", "含量-REF":"21", "含量-CHK":"合格", "深度-VAL":"11", "深度-REF":"11", "深度-CHK":"合格" } ]