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
Hide 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
;
package
com
.
yanzuoguang
.
util
.
table
;
import
java.util.ArrayList
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.*
;
import
java.util.Map
;
/**
/**
* 表头计算
* 表头计算
*
* @author 颜佐光
* @author 颜佐光
*/
*/
public
class
TableHeadHelper
{
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 {
...
@@ -20,127 +56,83 @@ public class TableHeadHelper {
public
static
TableHead
getTableHead
(
String
...
columns
)
{
public
static
TableHead
getTableHead
(
String
...
columns
)
{
TableHead
head
=
new
TableHead
();
TableHead
head
=
new
TableHead
();
head
.
setTotalColumn
(
columns
.
length
);
head
.
setTotalColumn
(
columns
.
length
);
// 节点关系映射
// 父子级别关系映射
Map
<
String
,
TableHeadItem
>
headMap
=
new
LinkedHashMap
<>();
Map
<
String
,
TableHeadItem
>
mapHead
=
new
LinkedHashMap
<
String
,
TableHeadItem
>();
// 当前节点的子节点元素
// 当前节点的子节点元素
Map
<
String
,
List
<
TableHeadItem
>>
mapSub
=
new
LinkedHashMap
<
String
,
List
<
TableHeadItem
>>();
Map
<
String
,
List
<
TableHeadItem
>>
headSubs
=
new
LinkedHashMap
<>();
// 最顶层的元素
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
()));
}
// 计算合并行的数量,第几行
// 计算每个单元格的大小和占用的行、列
for
(
Map
.
Entry
<
String
,
TableHeadItem
>
item
:
mapHead
.
entrySet
())
{
for
(
int
columnPos
=
0
;
columnPos
<
columns
.
length
;
columnPos
++)
{
setCellRow
(
head
,
item
.
getValue
());
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
())
{
for
(
Map
.
Entry
<
String
,
TableHeadItem
>
item
:
headMap
.
entrySet
())
{
setCellColumn
(
head
,
mapSub
,
item
.
getValue
());
TableHeadItem
headItem
=
item
.
getValue
();
if
(
headItem
.
isDataColumn
())
{
headItem
.
setRowCell
(
head
.
getTotalRow
()
-
headItem
.
getRow
());
}
}
}
return
head
;
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
();
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
();
String
parentPath
=
path
.
toString
()
.
trim
()
;
if
(
i
>
0
)
{
if
(
rowIndex
>
0
)
{
path
.
append
(
":"
);
path
.
append
(
":"
);
}
}
path
.
append
(
column
);
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
))
{
String
nowPath
=
path
.
toString
();
mapTop
.
put
(
nowPath
,
last
);
// 设置当前单元格属性
}
if
(!
headMap
.
containsKey
(
nowPath
))
{
TableHeadItem
headItem
=
new
TableHeadItem
();
// 添加到最顶层元素中
headItem
.
setRow
(
rowIndex
);
if
(!
mapSub
.
containsKey
(
parentPath
))
{
headItem
.
setRowCell
(
1
);
mapSub
.
put
(
parentPath
,
new
ArrayList
<
TableHeadItem
>());
headItem
.
setColumn
(
columnPos
);
}
headItem
.
setColumnCell
(
1
);
headItem
.
setName
(
column
);
// 将元素添加到当前元素中
headItem
.
setPath
(
nowPath
);
if
(!
mapHead
.
containsKey
(
nowPath
))
{
headItem
.
setDataColumn
(
fullPath
.
equals
(
nowPath
));
mapHead
.
put
(
nowPath
,
last
);
// 添加到父元素的子节点
// 添加到父级元素的下级元素
if
(!
headSubs
.
containsKey
(
parentPath
))
{
mapSub
.
get
(
parentPath
).
add
(
last
);
headSubs
.
put
(
parentPath
,
new
ArrayList
<>());
}
}
last
=
mapHead
.
get
(
nowPath
);
// 添加到当前元素对应缓存
last
.
setLevelMax
(
Math
.
max
(
last
.
getLevelMax
(),
columns
.
length
));
head
.
getColumns
().
add
(
headItem
);
}
headMap
.
put
(
nowPath
,
headItem
);
return
last
;
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
{
}
else
{
value
.
setRow
(
head
.
getTotalRow
());
// 当前单元格合并列增加1
}
TableHeadItem
headItem
=
headMap
.
get
(
nowPath
);
}
else
{
headItem
.
setColumnCell
(
headItem
.
getColumnCell
()
+
1
);
// 其他行
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
());
}
}
}
}
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 {
...
@@ -16,16 +16,6 @@ public class TableHeadItem {
*/
*/
private
String
path
;
private
String
path
;
/**
* 级别
*/
private
int
level
;
/**
* 当前列的最大级别
*/
private
int
levelMax
;
/**
/**
* 第几行
* 第几行
*/
*/
...
@@ -67,22 +57,6 @@ public class TableHeadItem {
...
@@ -67,22 +57,6 @@ public class TableHeadItem {
this
.
path
=
path
;
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
()
{
public
int
getRow
()
{
return
row
;
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