Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
e0ae13a5
Commit
e0ae13a5
authored
May 08, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
消除成功接收处理
parent
44934bd2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
97 additions
and
131 deletions
+97
-131
TableHeadHelper.java
...main/java/com/yanzuoguang/util/table/TableHeadHelper.java
+97
-105
TableHeadItem.java
...c/main/java/com/yanzuoguang/util/table/TableHeadItem.java
+0
-26
CloudContans.java
...oud/src/main/java/com/yanzuoguang/cloud/CloudContans.java
+0
-0
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/table/TableHeadHelper.java
View file @
e0ae13a5
package
com
.
yanzuoguang
.
util
.
table
;
import
java.util.ArrayList
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
java.util.*
;
/**
* 表头计算
*
* @author 颜佐光
*/
public
class
TableHeadHelper
{
public
static
final
String
SPLIT
=
":"
;
/**
* 获取父节点路径
*
* @param from 子节点
* @return 父节点路径
*/
public
static
String
getParentPath
(
String
from
)
{
if
(
from
.
lastIndexOf
(
SPLIT
)
>=
0
)
{
return
from
.
substring
(
0
,
from
.
lastIndexOf
(
":"
));
}
else
{
return
StringHelper
.
EMPTY
;
}
}
/**
* 对列头进行排序
*
* @param columns 对列头进行排序
*/
public
static
void
sort
(
String
[]
columns
)
{
// 列头排序,同级元素排序
Arrays
.
sort
(
columns
,
new
Comparator
<
String
>()
{
@Override
public
int
compare
(
String
from
,
String
to
)
{
String
fromParent
=
getParentPath
(
from
);
String
toParent
=
getParentPath
(
to
);
if
(
fromParent
.
length
()
==
0
||
toParent
.
length
()
==
0
)
{
return
0
;
}
return
fromParent
.
compareTo
(
toParent
);
}
});
}
/**
* 列头函数
*
...
...
@@ -20,127 +56,83 @@ public class TableHeadHelper {
public
static
TableHead
getTableHead
(
String
...
columns
)
{
TableHead
head
=
new
TableHead
();
head
.
setTotalColumn
(
columns
.
length
);
// 父子级别关系映射
Map
<
String
,
TableHeadItem
>
mapHead
=
new
LinkedHashMap
<
String
,
TableHeadItem
>();
// 节点关系映射
Map
<
String
,
TableHeadItem
>
headMap
=
new
LinkedHashMap
<>();
// 当前节点的子节点元素
Map
<
String
,
List
<
TableHeadItem
>>
mapSub
=
new
LinkedHashMap
<
String
,
List
<
TableHeadItem
>>();
// 最顶层的元素
Map
<
String
,
TableHeadItem
>
mapTop
=
new
LinkedHashMap
<
String
,
TableHeadItem
>();
for
(
String
column
:
columns
)
{
TableHeadItem
item
=
setHead
(
mapHead
,
mapSub
,
mapTop
,
column
);
// 设置表格的最大行数
head
.
setTotalRow
(
Math
.
max
(
item
.
getLevel
(),
head
.
getTotalRow
()));
}
Map
<
String
,
List
<
TableHeadItem
>>
headSubs
=
new
LinkedHashMap
<>();
// 计算合并行的数量,第几行
for
(
Map
.
Entry
<
String
,
TableHeadItem
>
item
:
mapHead
.
entrySet
())
{
setCellRow
(
head
,
item
.
getValue
());
// 计算每个单元格的大小和占用的行、列
for
(
int
columnPos
=
0
;
columnPos
<
columns
.
length
;
columnPos
++)
{
String
column
=
columns
[
columnPos
];
int
totalRow
=
setHead
(
head
,
headMap
,
headSubs
,
column
,
columnPos
);
head
.
setTotalRow
(
Math
.
max
(
totalRow
,
head
.
getTotalRow
()));
}
// 计算列合并的数量,第几列
for
(
Map
.
Entry
<
String
,
TableHeadItem
>
item
:
mapTop
.
entrySet
())
{
setCellColumn
(
head
,
mapSub
,
item
.
getValue
());
// 计算最后一行的合并数量
for
(
Map
.
Entry
<
String
,
TableHeadItem
>
item
:
headMap
.
entrySet
())
{
TableHeadItem
headItem
=
item
.
getValue
();
if
(
headItem
.
isDataColumn
())
{
headItem
.
setRowCell
(
head
.
getTotalRow
()
-
headItem
.
getRow
());
}
}
return
head
;
}
private
static
TableHeadItem
setHead
(
Map
<
String
,
TableHeadItem
>
mapHead
,
Map
<
String
,
List
<
TableHeadItem
>>
mapSub
,
Map
<
String
,
TableHeadItem
>
mapTop
,
String
columnFrom
)
{
String
[]
columns
=
columnFrom
.
split
(
":"
);
/**
* 设置列头相关信息
*
* @param head 列头对象集合
* @param headMap 列头对象路径映射
* @param headSubs 列头对象路径映射
* @param fullPath 来源路径
* @param columnPos 列位置
* @return
*/
private
static
int
setHead
(
TableHead
head
,
Map
<
String
,
TableHeadItem
>
headMap
,
Map
<
String
,
List
<
TableHeadItem
>>
headSubs
,
String
fullPath
,
int
columnPos
)
{
String
[]
heads
=
fullPath
.
split
(
":"
);
StringBuilder
path
=
new
StringBuilder
();
TableHeadItem
last
=
null
;
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
for
(
int
rowIndex
=
0
;
rowIndex
<
heads
.
length
;
rowIndex
++)
{
// 列名称
String
column
=
columns
[
i
];
String
column
=
heads
[
rowIndex
].
trim
();
// 父路径与当前节点路径
String
parentPath
=
path
.
toString
();
if
(
i
>
0
)
{
String
parentPath
=
path
.
toString
()
.
trim
()
;
if
(
rowIndex
>
0
)
{
path
.
append
(
":"
);
}
path
.
append
(
column
);
String
nowPath
=
path
.
toString
();
last
=
new
TableHeadItem
();
last
.
setName
(
column
);
last
.
setPath
(
nowPath
);
last
.
setLevel
(
i
+
1
);
last
.
setDataColumn
(
columnFrom
.
equals
(
nowPath
));
if
(
i
==
0
&&
!
mapTop
.
containsKey
(
nowPath
))
{
mapTop
.
put
(
nowPath
,
last
);
}
// 添加到最顶层元素中
if
(!
mapSub
.
containsKey
(
parentPath
))
{
mapSub
.
put
(
parentPath
,
new
ArrayList
<
TableHeadItem
>());
}
// 将元素添加到当前元素中
if
(!
mapHead
.
containsKey
(
nowPath
))
{
mapHead
.
put
(
nowPath
,
last
);
// 添加到父级元素的下级元素
mapSub
.
get
(
parentPath
).
add
(
last
);
}
last
=
mapHead
.
get
(
nowPath
);
last
.
setLevelMax
(
Math
.
max
(
last
.
getLevelMax
(),
columns
.
length
));
}
return
last
;
}
String
nowPath
=
path
.
toString
();
// 设置当前单元格属性
if
(!
headMap
.
containsKey
(
nowPath
))
{
TableHeadItem
headItem
=
new
TableHeadItem
();
headItem
.
setRow
(
rowIndex
);
headItem
.
setRowCell
(
1
);
headItem
.
setColumn
(
columnPos
);
headItem
.
setColumnCell
(
1
);
headItem
.
setName
(
column
);
headItem
.
setPath
(
nowPath
);
headItem
.
setDataColumn
(
fullPath
.
equals
(
nowPath
));
// 添加到父元素的子节点
if
(!
headSubs
.
containsKey
(
parentPath
))
{
headSubs
.
put
(
parentPath
,
new
ArrayList
<>());
}
// 添加到当前元素对应缓存
head
.
getColumns
().
add
(
headItem
);
headMap
.
put
(
nowPath
,
headItem
);
headSubs
.
get
(
parentPath
).
add
(
headItem
);
private
static
void
setCellRow
(
TableHead
head
,
TableHeadItem
value
)
{
// 合并行数量
int
rowCell
=
head
.
getTotalRow
()
-
value
.
getLevelMax
()
+
1
;
value
.
setRow
(
value
.
getLevel
());
value
.
setRowCell
(
1
);
// 计算第几行,合并几行
if
(
value
.
getLevel
()
==
1
)
{
// 第一行的规则
if
(
value
.
getLevelMax
()
==
1
)
{
value
.
setRowCell
(
rowCell
);
}
}
else
if
(
value
.
getLevel
()
==
value
.
getLevelMax
())
{
// 最后一行的规则
if
(
value
.
getLevelMax
()
==
2
)
{
value
.
setRowCell
(
rowCell
);
}
else
{
value
.
setRow
(
head
.
getTotalRow
());
}
}
else
{
// 其他行
if
(
value
.
getLevel
()
==
value
.
getLevelMax
()
-
1
)
{
value
.
setRowCell
(
rowCell
);
}
}
}
private
static
void
setCellColumn
(
TableHead
head
,
Map
<
String
,
List
<
TableHeadItem
>>
mapSub
,
TableHeadItem
value
)
{
// 设置当前列号
value
.
setColumn
(
head
.
getDataColumn
()
+
1
);
// 设置默认合并单元格数量
value
.
setColumnCell
(
1
);
// 将列添加到当前列集合中
head
.
getColumns
().
add
(
value
);
// 计算合并几列
if
(
value
.
isDataColumn
())
{
head
.
setDataColumn
(
head
.
getDataColumn
()
+
1
);
}
// 假如有子节点,则合并的单元格等于子节点的想加
List
<
TableHeadItem
>
subColumns
=
mapSub
.
containsKey
(
value
.
getPath
())
?
mapSub
.
get
(
value
.
getPath
())
:
new
ArrayList
<>();
if
(
subColumns
!=
null
&&
subColumns
.
size
()
>
0
)
{
value
.
setColumnCell
(
0
);
for
(
TableHeadItem
subColumn
:
subColumns
)
{
setCellColumn
(
head
,
mapSub
,
subColumn
);
value
.
setColumnCell
(
subColumn
.
getColumnCell
());
// 当前单元格合并列增加1
TableHeadItem
headItem
=
headMap
.
get
(
nowPath
);
headItem
.
setColumnCell
(
headItem
.
getColumnCell
()
+
1
);
}
}
return
heads
.
length
;
}
}
yzg-util-base/src/main/java/com/yanzuoguang/util/table/TableHeadItem.java
View file @
e0ae13a5
...
...
@@ -16,16 +16,6 @@ public class TableHeadItem {
*/
private
String
path
;
/**
* 级别
*/
private
int
level
;
/**
* 当前列的最大级别
*/
private
int
levelMax
;
/**
* 第几行
*/
...
...
@@ -67,22 +57,6 @@ public class TableHeadItem {
this
.
path
=
path
;
}
public
int
getLevel
()
{
return
level
;
}
public
void
setLevel
(
int
level
)
{
this
.
level
=
level
;
}
public
int
getLevelMax
()
{
return
levelMax
;
}
public
void
setLevelMax
(
int
levelMax
)
{
this
.
levelMax
=
levelMax
;
}
public
int
getRow
()
{
return
row
;
}
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/CloudContans.java
100644 → 100755
View file @
e0ae13a5
File mode changed from 100644 to 100755
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment