Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
winsun-tools
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
吕伟康
winsun-tools
Commits
855da282
Commit
855da282
authored
Jun 02, 2020
by
黄福龙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
上传项目
parent
b54f80b7
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
4095 additions
and
0 deletions
+4095
-0
Generator/DBProject/pom.xml
+63
-0
Generator/DBProject/src/main/java/com/winsun/db/controller/BaseController.java
+679
-0
Generator/DBProject/src/main/java/com/winsun/db/controller/ExcelController.java
+265
-0
Generator/DBProject/src/main/java/com/winsun/db/controller/SqlBaseController.java
+105
-0
Generator/DBProject/src/main/resources/applicationContext.xml
+44
-0
Generator/DBProject/src/main/resources/db.properties
+158
-0
Generator/genTable/pom.xml
+57
-0
Generator/genTable/src/main/java/com/winsun/tools/data/TreeNodeData.java
+135
-0
Generator/genTable/src/main/java/com/winsun/tools/entity/TreeNode.java
+468
-0
Generator/genTable/src/main/java/com/winsun/tools/entity/TreeNodeReComplie.java
+126
-0
Generator/genTable/src/main/java/com/winsun/tools/entity/TreeNodeSql.java
+94
-0
Generator/genTable/src/main/java/com/winsun/tools/utils/ExcelCellUtils.java
+52
-0
Generator/genTable/src/main/java/com/winsun/tools/utils/ExcelTreeNodeHelper.java
+275
-0
Generator/genTable/src/main/java/com/winsun/tools/utils/SQLHelper.java
+528
-0
Generator/genTable/src/main/java/com/winsun/tools/utils/THeadJsonUtils.java
+236
-0
Generator/genTable/src/main/java/com/winsun/tools/utils/THeadUtils.java
+145
-0
Generator/genTable/src/main/java/com/winsun/tools/utils/TreeNodeDataCreator.java
+184
-0
Generator/genTable/src/main/resources/WEND.txt
+53
-0
Generator/genTable/src/main/resources/index.html
+115
-0
Generator/genTable/src/test/java/com/winsun/test/TestJsonUtils.java
+31
-0
Generator/genTable/src/test/java/com/winsun/test/TestTreeNodeDataCreator.java
+184
-0
Generator/pom.xml
+98
-0
No files found.
Generator/DBProject/pom.xml
0 → 100644
View file @
855da282
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
Generator
</artifactId>
<groupId>
com.winsun.tools
</groupId>
<version>
1.0-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
DBProject
</artifactId>
<dependencies>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid
</artifactId>
<version>
1.1.22
</version>
</dependency>
<!--mysql-connector-java-->
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
</dependency>
<!--jdbc-->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-jdbc
</artifactId>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
cn.hutool
</groupId>
<artifactId>
hutool-all
</artifactId>
<version>
5.1.0
</version>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<version>
4.12
</version>
<!-- 不设置scope就是全局 -->
<!-- <scope>test</scope>-->
</dependency>
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi-ooxml
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter
</artifactId>
<version>
2.2.2.RELEASE
</version>
<scope>
compile
</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
Generator/DBProject/src/main/java/com/winsun/db/controller/BaseController.java
0 → 100644
View file @
855da282
package
com
.
winsun
.
db
.
controller
;
import
java.io.BufferedOutputStream
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.text.DecimalFormat
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Set
;
import
java.util.regex.Pattern
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.util.StrUtil
;
import
org.apache.poi.hssf.usermodel.HSSFCell
;
import
org.apache.poi.hssf.usermodel.HSSFRow
;
import
org.apache.poi.hssf.usermodel.HSSFSheet
;
import
org.apache.poi.hssf.usermodel.HSSFWorkbook
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.FormulaEvaluator
;
import
org.apache.poi.xssf.usermodel.XSSFCell
;
import
org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator
;
import
org.apache.poi.xssf.usermodel.XSSFRow
;
import
org.apache.poi.xssf.usermodel.XSSFSheet
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.support.ClassPathXmlApplicationContext
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
;
import
org.springframework.jdbc.datasource.DataSourceTransactionManager
;
import
org.springframework.transaction.TransactionDefinition
;
import
org.springframework.transaction.TransactionStatus
;
import
org.springframework.transaction.support.DefaultTransactionDefinition
;
public
class
BaseController
{
protected
static
ApplicationContext
ctx
=
new
ClassPathXmlApplicationContext
(
"applicationContext.xml"
);
protected
static
JdbcTemplate
jdbcTemplate
=
(
JdbcTemplate
)
ctx
.
getBean
(
"jdbcTemplate"
);
protected
static
NamedParameterJdbcTemplate
namedParameterJdbcTemplate
=
ctx
.
getBean
(
NamedParameterJdbcTemplate
.
class
);
public
static
void
main
(
String
[]
args
)
{
System
.
err
.
println
(
1
);
}
/**
* 执行批量语句
*
* @param arry
* @return
*/
public
static
int
batchSQLData
(
String
[]
arry
)
{
int
result
=
0
;
// 添加事务
DataSourceTransactionManager
transactionManager
=
new
DataSourceTransactionManager
(
jdbcTemplate
.
getDataSource
());
DefaultTransactionDefinition
def
=
new
DefaultTransactionDefinition
();
def
.
setPropagationBehavior
(
TransactionDefinition
.
PROPAGATION_REQUIRES_NEW
);
TransactionStatus
status
=
transactionManager
.
getTransaction
(
def
);
try
{
if
(
null
!=
arry
&&
arry
.
length
>
0
)
{
int
[]
res
=
jdbcTemplate
.
batchUpdate
(
arry
);
for
(
int
i
:
res
)
{
result
+=
i
;
}
transactionManager
.
commit
(
status
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
transactionManager
.
rollback
(
status
);
return
-
1
;
}
return
result
;
}
public
static
int
batchSQLData
(
String
sql
,
List
<
Object
[]>
params
)
{
int
result
=
0
;
// 添加事务
DataSourceTransactionManager
transactionManager
=
new
DataSourceTransactionManager
(
jdbcTemplate
.
getDataSource
());
DefaultTransactionDefinition
def
=
new
DefaultTransactionDefinition
();
def
.
setPropagationBehavior
(
TransactionDefinition
.
PROPAGATION_REQUIRES_NEW
);
TransactionStatus
status
=
transactionManager
.
getTransaction
(
def
);
try
{
if
(
null
!=
params
&&
params
.
size
()
>
0
)
{
int
[]
res
=
jdbcTemplate
.
batchUpdate
(
sql
,
params
);
for
(
int
i
:
res
)
{
result
+=
i
;
}
transactionManager
.
commit
(
status
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
transactionManager
.
rollback
(
status
);
return
-
1
;
}
return
result
;
}
/**
* 获取单元格的值
*/
public
static
Object
getCellValue
(
HSSFCell
cell
)
{
Object
val
=
""
;
if
(
cell
!=
null
)
{
if
(
cell
.
getCellType
()
==
Cell
.
CELL_TYPE_NUMERIC
)
{
DecimalFormat
df
=
new
DecimalFormat
(
"0"
);
val
=
df
.
format
(
cell
.
getNumericCellValue
());
}
else
if
(
cell
.
getCellType
()
==
Cell
.
CELL_TYPE_STRING
)
{
val
=
cell
.
getStringCellValue
();
}
else
if
(
cell
.
getCellType
()
==
Cell
.
CELL_TYPE_FORMULA
)
{
val
=
cell
.
getCellFormula
();
}
else
if
(
cell
.
getCellType
()
==
Cell
.
CELL_TYPE_BOOLEAN
)
{
val
=
cell
.
getBooleanCellValue
();
}
else
if
(
cell
.
getCellType
()
==
Cell
.
CELL_TYPE_ERROR
)
{
val
=
cell
.
getErrorCellValue
();
}
}
return
new
String
(
val
.
toString
()).
trim
();
}
//处理公式
public
static
String
getCellValueFormula
(
Cell
cell
,
FormulaEvaluator
formulaEvaluator
)
{
if
(
cell
==
null
||
formulaEvaluator
==
null
)
{
return
null
;
}
return
String
.
valueOf
(
formulaEvaluator
.
evaluate
(
cell
).
getNumberValue
());
}
public
static
Object
getCellValue
(
XSSFCell
cell
)
{
Object
val
=
""
;
if
(
cell
!=
null
)
{
if
(
cell
.
getCellType
()
==
Cell
.
CELL_TYPE_NUMERIC
)
{
DecimalFormat
df
=
new
DecimalFormat
();
val
=
df
.
format
(
cell
.
getNumericCellValue
());
}
else
if
(
cell
.
getCellType
()
==
Cell
.
CELL_TYPE_STRING
)
{
val
=
cell
.
getStringCellValue
();
}
else
if
(
cell
.
getCellType
()
==
Cell
.
CELL_TYPE_FORMULA
)
{
FormulaEvaluator
formulaEvaluator
=
new
XSSFFormulaEvaluator
((
XSSFWorkbook
)
cell
.
getRow
().
getSheet
().
getWorkbook
());;
val
=
getCellValueFormula
(
cell
,
formulaEvaluator
);
}
else
if
(
cell
.
getCellType
()
==
Cell
.
CELL_TYPE_BOOLEAN
)
{
val
=
cell
.
getBooleanCellValue
();
}
else
if
(
cell
.
getCellType
()
==
Cell
.
CELL_TYPE_ERROR
)
{
val
=
cell
.
getErrorCellValue
();
}
}
return
new
String
(
val
.
toString
()).
trim
();
}
private
static
String
reg
=
"(?:')|(?:--)|(/\\*(?:.|[\\n\\r])*?\\*/)|"
+
"(\\b(select|update|and|or|delete|insert|trancate|char|into|substr|ascii|declare|exec|count|master|into|drop|execute)\\b)"
;
private
static
Pattern
sqlPattern
=
Pattern
.
compile
(
reg
,
Pattern
.
CASE_INSENSITIVE
);
/**
* POI解析Excel文件内容 再读取
*
* @author David
* @param
*/
public
void
readTemplate
(
String
filePath
)
{
// 需要解析的Excel文件
File
file
=
new
File
(
filePath
);
// "G:/项目资料/客户画像/111.xls"
try
{
// 创建Excel,读取文件内容
HSSFWorkbook
workbook
=
new
HSSFWorkbook
(
FileUtil
.
getInputStream
(
file
));
// 获取第一个工作表workbook.getSheet("Sheet0");
// HSSFSheet sheet = workbook.getSheet("Sheet0");
// 读取默认第一个工作表sheet
HSSFSheet
sheet
=
workbook
.
getSheetAt
(
0
);
int
firstRowNum
=
0
;
List
<
String
>
list
=
new
ArrayList
<
String
>();
// 获取sheet中最后一行行号
int
lastRowNum
=
sheet
.
getLastRowNum
();
// System.err.println(lastRowNum);
int
total
=
0
;
for
(
int
i
=
firstRowNum
;
i
<=
lastRowNum
;
i
++)
{
HSSFRow
row
=
sheet
.
getRow
(
i
);
// 获取当前行最后单元格列号
int
lastCellNum
=
row
.
getLastCellNum
();
for
(
int
j
=
0
;
j
<
lastCellNum
;
j
++)
{
HSSFCell
cell
=
row
.
getCell
(
j
);
if
(
cell
==
null
)
{
continue
;
}
String
value
=
getCellValue
(
cell
).
toString
();
value
.
replace
(
"/r/n"
,
""
);
System
.
out
.
print
(
value
+
" "
);
}
System
.
out
.
println
();
}
String
[]
arr
=
new
String
[
list
.
size
()];
for
(
int
i
=
0
,
s
=
list
.
size
();
i
<
s
;
i
++){
arr
[
i
]
=
list
.
get
(
i
);
System
.
out
.
println
(
list
.
get
(
i
)+
";"
);
}
// int sum = batchSQLData(arr);
// System.err.println(sum);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
public
void
readTemplate2
(
String
filePath
)
{
// 需要解析的Excel文件
File
file
=
new
File
(
filePath
);
// "G:/项目资料/客户画像/111.xls"
try
{
// 创建Excel,读取文件内容
XSSFWorkbook
workbook
=
new
XSSFWorkbook
(
FileUtil
.
getInputStream
(
file
));
// 获取第一个工作表workbook.getSheet("Sheet0");
// HSSFSheet sheet = workbook.getSheet("Sheet0");
// 读取默认第一个工作表sheet
XSSFSheet
sheet
=
workbook
.
getSheetAt
(
0
);
int
firstRowNum
=
0
;
List
<
String
>
list
=
new
ArrayList
<
String
>();
// 获取sheet中最后一行行号
int
lastRowNum
=
sheet
.
getLastRowNum
();
// System.err.println(lastRowNum);
int
total
=
0
;
for
(
int
i
=
firstRowNum
;
i
<=
lastRowNum
;
i
++)
{
XSSFRow
row
=
sheet
.
getRow
(
i
);
// SQLHelper sqlHelper = new SQLHelper("", "");
// 获取当前行最后单元格列号
int
lastCellNum
=
row
.
getLastCellNum
();
for
(
int
j
=
0
;
j
<
lastCellNum
;
j
++)
{
XSSFCell
cell
=
row
.
getCell
(
j
);
if
(
cell
==
null
)
{
continue
;
}
String
value
=
getCellValue
(
cell
).
toString
();
value
=
value
.
replace
(
"/r/n"
,
""
);
System
.
out
.
print
(
value
+
" "
);
}
System
.
out
.
println
();
}
// String []arr = new String[list.size()];
// for(int i=0,s=list.size();i<s;i++){
// arr[i] = list.get(i);
// System.out.println(list.get(i)+";");
// }
// System.out.println(list.size());
// int sum = batchSQLData(arr);
// System.err.println(sum);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
public
List
readExcelToList
(
String
filePath
)
{
return
readExcelToList
(
filePath
,
0
);
}
/**
* excel转化成List<List<String>>
* @param filePath
* @return
*/
public
List
readExcelToList
(
String
filePath
,
int
index
)
{
// 需要解析的Excel文件
File
file
=
new
File
(
filePath
);
//
List
<
List
<
String
>>
list
=
new
ArrayList
<>();
try
{
// 创建Excel,读取文件内容
XSSFWorkbook
workbook
=
new
XSSFWorkbook
(
FileUtil
.
getInputStream
(
file
));
// 获取第一个工作表workbook.getSheet("Sheet0");
// HSSFSheet sheet = workbook.getSheet("Sheet0");
// 读取默认第一个工作表sheet
XSSFSheet
sheet
=
workbook
.
getSheetAt
(
0
);
int
firstRowNum
=
0
;
// 获取sheet中最后一行行号
int
lastRowNum
=
sheet
.
getLastRowNum
();
// System.err.println(lastRowNum);
int
total
=
0
;
System
.
out
.
println
(
"excel:"
);
for
(
int
i
=
firstRowNum
+
index
;
i
<=
lastRowNum
;
i
++)
{
XSSFRow
row
=
sheet
.
getRow
(
i
);
// 获取当前行最后单元格列号
int
lastCellNum
=
row
.
getLastCellNum
();
List
<
String
>
data
=
new
ArrayList
<>();
for
(
int
j
=
0
;
j
<
lastCellNum
;
j
++)
{
XSSFCell
cell
=
row
.
getCell
(
j
);
if
(
cell
==
null
){
continue
;
}
String
value
=
getCellValue
(
cell
).
toString
();
value
.
replace
(
"/r/n"
,
""
);
// System.out.print(value + ",");
data
.
add
(
value
);
}
// System.out.println();
list
.
add
(
data
);
}
// System.out.println("++++++++++++++++++++++++");
// System.out.println("List<List>:");
// displayList(list);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
list
;
}
public
List
<
Map
<
String
,
Object
>>
readExcelToListMap
(
String
filePath
)
{
return
readExcelToListMap
(
filePath
,
0
);
}
/**
* excel转化成List<List<String>>
* @param filePath
* @return
*/
public
List
<
Map
<
String
,
Object
>>
readExcelToListMap
(
String
filePath
,
int
index
)
{
// 需要解析的Excel文件
File
file
=
new
File
(
filePath
);
//
List
<
Map
<
String
,
Object
>>
list
=
new
ArrayList
<>();
try
{
// 创建Excel,读取文件内容
XSSFWorkbook
workbook
=
new
XSSFWorkbook
(
FileUtil
.
getInputStream
(
file
));
// 获取第一个工作表workbook.getSheet("Sheet0");
// HSSFSheet sheet = workbook.getSheet("Sheet0");
// 读取默认第一个工作表sheet
XSSFSheet
sheet
=
workbook
.
getSheetAt
(
0
);
int
firstRowNum
=
0
;
// 获取sheet中最后一行行号
int
lastRowNum
=
sheet
.
getLastRowNum
();
// System.err.println(lastRowNum);
int
total
=
0
;
System
.
out
.
println
(
"excel:"
);
for
(
int
i
=
firstRowNum
+
index
;
i
<=
lastRowNum
;
i
++)
{
XSSFRow
row
=
sheet
.
getRow
(
i
);
// 获取当前行最后单元格列号
int
lastCellNum
=
row
.
getLastCellNum
();
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
for
(
int
j
=
0
;
j
<
lastCellNum
;
j
++)
{
XSSFCell
cell
=
row
.
getCell
(
j
);
if
(
cell
==
null
){
continue
;
}
String
value
=
getCellValue
(
cell
).
toString
();
value
.
replace
(
"/r/n"
,
""
);
// System.out.print(value + ",");
data
.
put
(
indexColunm
[
j
],
value
);
}
// System.out.println();
list
.
add
(
data
);
}
// System.out.println("++++++++++++++++++++++++");
// System.out.println("List<List>:");
// displayList(list);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
list
;
}
String
[]
indexColunm
=
{
"a"
,
"b"
,
"c"
,
"d"
,
"e"
,
"f"
,
"g"
,
"h"
,
"i"
,
"j"
,
"k"
,
"l"
,
"m"
,
"n"
,
"o"
,
"p"
,
"q"
,
"r"
,
"s"
,
"t"
,
"u"
,
"v"
,
"w"
,
"x"
,
"y"
,
"z"
,
"aa"
,
"ab"
,
"ac"
,
"ad"
,
"ae"
,
"af"
,
"ag"
,
"ah"
,
"ai"
,
"aj"
,
"ak"
,
"al"
,
"am"
,
"an"
,
"ao"
,
"ap"
,
"aq"
,
"ar"
,
"as"
,
"at"
,
"au"
,
"av"
,
"aw"
,
"ax"
,
"ay"
,
"az"
,
"ba"
,
"bb"
,
"bc"
,
"bd"
,
"be"
,
"bf"
,
"bg"
,
"bh"
,
"bi"
,
"bj"
,
"bk"
,
"bl"
,
"bm"
,
"bn"
,
"bo"
,
"bp"
,
"bq"
,
"br"
,
"bs"
,
"bt"
,
"bu"
,
"bv"
,
"bw"
,
"bx"
,
"by"
,
"bz"
,
"ca"
,
"cb"
,
"cc"
,
"cd"
,
"ce"
,
"cf"
,
"cg"
,
"ch"
,
"ci"
,
"cj"
,
"ck"
,
"cl"
,
"cm"
,
"cn"
,
"co"
,
"cp"
,
"cq"
,
"cr"
,
"cs"
,
"ct"
,
"cu"
,
"cv"
,
"cw"
,
"cx"
,
"cy"
,
"cz"
};
/**
* 打印list
* @param list
*/
public
static
void
displayList
(
List
list
)
{
for
(
Object
obj
:
list
)
{
System
.
out
.
println
(
obj
+
""
);
}
}
/**
* 打印Map
* @param map
*/
public
static
void
displayMap
(
Map
<
String
,
Object
>
map
)
{
for
(
Entry
<
String
,
Object
>
obj
:
map
.
entrySet
())
{
System
.
out
.
println
(
obj
.
getKey
()
+
":"
+
obj
.
getValue
());
}
}
/**
* 打印Set
* @param codeSet
*/
public
static
void
displaySet
(
Set
<
String
>
codeSet
)
{
for
(
String
str:
codeSet
){
System
.
out
.
println
(
str
);
}
}
/**
* List转化成Map
* 取出list<Map>某唯一值的key列作为key,value列作为锁对应的value,组成一个Map
* @param list
* @param key 键
* @param value 值
* @return
*/
public
Map
<
String
,
String
>
listToMap
(
List
<
Map
<
String
,
Object
>>
list
,
String
key
,
String
value
)
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
for
(
int
i
=
0
,
s
=
list
.
size
();
i
<
s
;
i
++)
{
Map
<
String
,
Object
>
m
=
list
.
get
(
i
);
String
key0
=
(
String
)
m
.
get
(
key
).
toString
();
Object
obj
=
(
Object
)
m
.
get
(
value
);
String
value0
=
null
;
if
(
obj
!=
null
)
{
value0
=
obj
.
toString
();
}
map
.
put
(
key0
,
value0
);
}
return
map
;
}
/**
* List转化成Map
* 取出list<Map>某唯一值的key列作为key,value列作为锁对应的value,组成一个Map
* @param list
* @param key 键
* @param value 值
* @return
*/
public
Map
<
String
,
Object
>
listToMap2
(
List
<
Map
<
String
,
Object
>>
list
,
String
key
,
String
value
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
for
(
int
i
=
0
,
s
=
list
.
size
();
i
<
s
;
i
++)
{
Map
<
String
,
Object
>
m
=
list
.
get
(
i
);
String
key0
=
(
String
)
m
.
get
(
key
);
Object
value0
=
(
Object
)
m
.
get
(
value
);
map
.
put
(
key0
,
value0
);
}
return
map
;
}
/**
* List转化成Map<String,List<Object>>
* 取出list<Map>中需要进行分组的key,对valueKey进行汇总,汇总成List<String>
* @param list
* @param key 分组key
* @param value 汇总key
* @return
*/
public
static
Map
<
String
,
List
>
listToMapList
(
List
<
Map
<
String
,
Object
>>
list
,
String
key
,
String
value
)
{
Map
<
String
,
List
>
map
=
new
HashMap
<>();
for
(
int
i
=
0
,
s
=
list
.
size
();
i
<
s
;
i
++)
{
Map
<
String
,
Object
>
m
=
list
.
get
(
i
);
String
key0
=
(
String
)
m
.
get
(
key
);
Object
value0
=
m
.
get
(
value
);
List
temp
=
map
.
get
(
key0
);
if
(
temp
==
null
){
temp
=
new
ArrayList
<>();
map
.
put
(
key0
,
temp
);
}
temp
.
add
(
value0
);
}
return
map
;
}
/**
* List转化成Map<String,List>
* @param list
* @param key 键
* @return
*/
public
Map
<
String
,
Object
>
listToMapList
(
List
<
Map
<
String
,
Object
>>
list
,
String
key
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>(
list
.
size
());
for
(
int
i
=
0
,
s
=
list
.
size
();
i
<
s
;
i
++)
{
Map
<
String
,
Object
>
m
=
list
.
get
(
i
);
String
key0
=
(
String
)
m
.
get
(
key
);
Object
obj
=
map
.
get
(
key0
);
if
(
obj
!=
null
){
((
List
)
obj
).
add
(
m
);
}
else
{
List
l
=
new
ArrayList
<>();
l
.
add
(
m
);
map
.
put
(
key0
,
l
);
}
}
return
map
;
}
/**
* List转化成Map<String,Map>
* @param list
* @param key 键
* @return
*/
public
Map
<
String
,
Object
>
listToMap
(
List
<
Map
<
String
,
Object
>>
list
,
String
key
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>(
list
.
size
());
for
(
int
i
=
0
,
s
=
list
.
size
();
i
<
s
;
i
++)
{
Map
<
String
,
Object
>
m
=
list
.
get
(
i
);
String
key0
=
(
String
)
m
.
get
(
key
);
map
.
put
(
key0
,
m
);
}
return
map
;
}
/**
* list转换成set
* 取出list<Map>中某个值放入set中
* @param list
* @param key
* @return
*/
public
Set
<
String
>
listToSet
(
List
<
Map
<
String
,
Object
>>
list
,
String
key
){
Set
<
String
>
set
=
new
HashSet
<>(
list
.
size
());
for
(
Map
map:
list
){
String
value
=
(
String
)
map
.
get
(
key
);
if
(
StrUtil
.
isNotBlank
(
value
))
{
set
.
add
(
value
);
}
}
return
set
;
}
public
static
String
getDateValue
(
String
tableName
,
String
dateCol
){
String
sql
=
"SELECT max("
+
dateCol
+
") FROM "
+
tableName
;
return
jdbcTemplate
.
queryForObject
(
sql
,
String
.
class
);
}
// @Test
public
void
test
(){
String
s
=
getDateValue
(
"HD_MK_SQYX_YHYA_DXGZDY"
,
"load_date"
);
System
.
out
.
println
(
s
);
}
/**
* 读取txt
* @param file
* @return
*/
public
static
List
<
String
>
readTxt
(
File
file
)
{
List
<
String
>
dataList
=
new
ArrayList
<
String
>();
BufferedReader
br
=
null
;
try
{
br
=
new
BufferedReader
(
new
FileReader
(
file
));
String
line
=
""
;
while
((
line
=
br
.
readLine
())
!=
null
)
{
dataList
.
add
(
line
.
trim
());
}
}
catch
(
Exception
e
)
{
}
finally
{
if
(
br
!=
null
)
{
try
{
br
.
close
();
br
=
null
;
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
return
dataList
;
}
public
void
toTxt
(){
}
// 输出TXT
public
void
writeListToTxt
(
List
list
)
{
FileOutputStream
outSTr
=
null
;
BufferedOutputStream
Buff
=
null
;
String
fileName
=
"txt_"
+
System
.
currentTimeMillis
();
String
path
=
"F://"
+
fileName
+
".txt"
;
System
.
out
.
println
(
path
);
if
(
StrUtil
.
isNotBlank
(
fileName
))
{
path
=
fileName
;
}
String
tab
=
" "
;
String
enter
=
"\r\n"
;
String
content
=
""
;
StringBuffer
write
;
try
{
outSTr
=
new
FileOutputStream
(
new
File
(
path
));
Buff
=
new
BufferedOutputStream
(
outSTr
);
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
Object
obj
=
list
.
get
(
i
);
content
=
obj
.
toString
();
write
=
new
StringBuffer
();
write
.
append
(
content
+
tab
);
write
.
append
(
enter
);
Buff
.
write
(
write
.
toString
().
getBytes
(
"UTF-8"
));
}
Buff
.
flush
();
Buff
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
Buff
.
close
();
outSTr
.
close
();
System
.
out
.
println
(
"finished..."
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
// @Test
public
void
writeToTxt
(
List
<
String
>
list
)
{
writeToTxt
(
list
,
null
);
}
public
void
writeToTxt
(
List
<
String
>
list
,
String
fileName
)
{
FileOutputStream
outSTr
=
null
;
BufferedOutputStream
Buff
=
null
;
String
path
=
"f://txt_"
+
Math
.
round
(
Math
.
random
()*
1000
)+
".txt"
;
if
(
StrUtil
.
isNotBlank
(
fileName
))
{
path
=
fileName
;
}
String
tab
=
""
;
String
enter
=
"\r\n"
;
String
content
=
""
;
StringBuffer
write
;
try
{
outSTr
=
new
FileOutputStream
(
new
File
(
path
));
Buff
=
new
BufferedOutputStream
(
outSTr
);
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
Object
obj
=
list
.
get
(
i
);
content
=
obj
.
toString
();
write
=
new
StringBuffer
();
write
.
append
(
content
+
tab
);
write
.
append
(
enter
);
Buff
.
write
(
write
.
toString
().
getBytes
(
"UTF-8"
));
}
Buff
.
flush
();
Buff
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
Buff
.
close
();
outSTr
.
close
();
System
.
out
.
println
(
"finished..."
);
System
.
out
.
println
(
path
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
public
static
List
<
File
>
getTargetFiles
(
String
path
)
{
int
fileNum
=
0
,
folderNum
=
0
;
File
file
=
new
File
(
path
);
List
<
File
>
targetList
=
new
LinkedList
<
File
>();
if
(
file
.
exists
())
{
LinkedList
<
File
>
list
=
new
LinkedList
<
File
>();
File
[]
files
=
file
.
listFiles
();
for
(
File
file2
:
files
)
{
if
(
file2
.
isDirectory
())
{
list
.
add
(
file2
);
}
else
{
targetList
.
add
(
file2
);
}
}
File
temp_file
;
while
(!
list
.
isEmpty
())
{
temp_file
=
list
.
removeFirst
();
files
=
temp_file
.
listFiles
();
for
(
File
file2
:
files
)
{
if
(
file2
.
isDirectory
())
{
list
.
add
(
file2
);
}
else
{
targetList
.
add
(
file2
);
}
}
}
}
return
targetList
;
}
}
Generator/DBProject/src/main/java/com/winsun/db/controller/ExcelController.java
0 → 100644
View file @
855da282
package
com
.
winsun
.
db
.
controller
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.text.DecimalFormat
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.Map.Entry
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.util.StrUtil
;
import
org.apache.poi.hssf.usermodel.HSSFCell
;
import
org.apache.poi.hssf.usermodel.HSSFRow
;
import
org.apache.poi.hssf.usermodel.HSSFSheet
;
import
org.apache.poi.hssf.usermodel.HSSFWorkbook
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.FormulaEvaluator
;
import
org.apache.poi.xssf.usermodel.XSSFCell
;
import
org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator
;
import
org.apache.poi.xssf.usermodel.XSSFRow
;
import
org.apache.poi.xssf.usermodel.XSSFSheet
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
org.junit.Test
;
public
class
ExcelController
{
@Test
public
void
test1
(){
String
path
=
"e:/poi_test22.xls"
;
readTemplate
(
path
);
}
@Test
public
void
test2
(){
String
path
=
"e:/poi_test22.xlsx"
;
readTemplate2
(
path
);
}
/**
* 获取单元格的值
*/
public
static
Object
getCellValue
(
HSSFCell
cell
)
{
Object
val
=
""
;
if
(
cell
!=
null
)
{
if
(
cell
.
getCellType
()
==
Cell
.
CELL_TYPE_NUMERIC
)
{
DecimalFormat
df
=
new
DecimalFormat
(
"0"
);
val
=
df
.
format
(
cell
.
getNumericCellValue
());
}
else
if
(
cell
.
getCellType
()
==
Cell
.
CELL_TYPE_STRING
)
{
val
=
cell
.
getStringCellValue
();
}
else
if
(
cell
.
getCellType
()
==
Cell
.
CELL_TYPE_FORMULA
)
{
val
=
cell
.
getCellFormula
();
}
else
if
(
cell
.
getCellType
()
==
Cell
.
CELL_TYPE_BOOLEAN
)
{
val
=
cell
.
getBooleanCellValue
();
}
else
if
(
cell
.
getCellType
()
==
Cell
.
CELL_TYPE_ERROR
)
{
val
=
cell
.
getErrorCellValue
();
}
}
return
new
String
(
val
.
toString
()).
trim
();
}
/**
* 处理公式
* @param cell
* @param formulaEvaluator
* @return
*/
public
static
String
getCellValueFormula
(
Cell
cell
,
FormulaEvaluator
formulaEvaluator
)
{
if
(
cell
==
null
||
formulaEvaluator
==
null
)
{
return
null
;
}
return
String
.
valueOf
(
formulaEvaluator
.
evaluate
(
cell
).
getNumberValue
());
}
public
static
Object
getCellValue
(
XSSFCell
cell
)
{
Object
val
=
""
;
if
(
cell
!=
null
)
{
if
(
cell
.
getCellType
()
==
Cell
.
CELL_TYPE_NUMERIC
)
{
DecimalFormat
df
=
new
DecimalFormat
(
"0"
);
val
=
df
.
format
(
cell
.
getNumericCellValue
());
}
else
if
(
cell
.
getCellType
()
==
Cell
.
CELL_TYPE_STRING
)
{
val
=
cell
.
getStringCellValue
();
}
else
if
(
cell
.
getCellType
()
==
Cell
.
CELL_TYPE_FORMULA
)
{
FormulaEvaluator
formulaEvaluator
=
new
XSSFFormulaEvaluator
((
XSSFWorkbook
)
cell
.
getRow
().
getSheet
().
getWorkbook
());;
val
=
getCellValueFormula
(
cell
,
formulaEvaluator
);
}
else
if
(
cell
.
getCellType
()
==
Cell
.
CELL_TYPE_BOOLEAN
)
{
val
=
cell
.
getBooleanCellValue
();
}
else
if
(
cell
.
getCellType
()
==
Cell
.
CELL_TYPE_ERROR
)
{
val
=
cell
.
getErrorCellValue
();
}
}
return
new
String
(
val
.
toString
()).
trim
();
}
/**
* POI解析Excel文件内容 再读取
*
* @author David
* @param
*/
public
void
readTemplate
(
String
filePath
)
{
// 需要解析的Excel文件
File
file
=
new
File
(
filePath
);
// "G:/项目资料/客户画像/111.xls"
try
{
// 创建Excel,读取文件内容
HSSFWorkbook
workbook
=
new
HSSFWorkbook
(
FileUtil
.
getInputStream
(
file
));
// 获取第一个工作表workbook.getSheet("Sheet0");
// HSSFSheet sheet = workbook.getSheet("Sheet0");
// 读取默认第一个工作表sheet
HSSFSheet
sheet
=
workbook
.
getSheetAt
(
0
);
int
firstRowNum
=
0
;
// 获取sheet中最后一行行号
int
lastRowNum
=
sheet
.
getLastRowNum
();
// System.err.println(lastRowNum);
int
total
=
0
;
for
(
int
i
=
firstRowNum
;
i
<=
lastRowNum
;
i
++)
{
HSSFRow
row
=
sheet
.
getRow
(
i
);
// 获取当前行最后单元格列号
int
lastCellNum
=
row
.
getLastCellNum
();
for
(
int
j
=
0
;
j
<
lastCellNum
;
j
++)
{
HSSFCell
cell
=
row
.
getCell
(
j
);
if
(
cell
==
null
)
{
continue
;
}
String
value
=
getCellValue
(
cell
).
toString
();
value
.
replace
(
"/r/n"
,
""
);
System
.
out
.
print
(
value
+
" "
);
}
System
.
out
.
println
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
/**
* 导出生成excel.xls
* @param workbook
*/
public
static
void
export
(
HSSFWorkbook
workbook
)
{
File
file
=
new
File
(
"e:/poi_test"
+
Math
.
round
(
Math
.
random
()
*
100
)
+
".xls"
);
try
{
file
.
createNewFile
();
// 将Excel内容存盘
workbook
.
write
(
FileUtil
.
getOutputStream
(
file
));
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
System
.
out
.
println
(
"完成"
);
}
}
public
void
readTemplate2
(
String
filePath
)
{
// 需要解析的Excel文件
File
file
=
new
File
(
filePath
);
// "G:/项目资料/客户画像/111.xls"
try
{
// 创建Excel,读取文件内容
XSSFWorkbook
workbook
=
new
XSSFWorkbook
(
FileUtil
.
getInputStream
(
file
));
// 获取第一个工作表workbook.getSheet("Sheet0");
// 读取默认第一个工作表sheet
XSSFSheet
sheet
=
workbook
.
getSheetAt
(
0
);
int
firstRowNum
=
0
;
// 获取sheet中最后一行行号
int
lastRowNum
=
sheet
.
getLastRowNum
();
// System.err.println(lastRowNum);
int
total
=
0
;
for
(
int
i
=
firstRowNum
;
i
<=
lastRowNum
;
i
++)
{
XSSFRow
row
=
sheet
.
getRow
(
i
);
// 获取当前行最后单元格列号
int
lastCellNum
=
row
.
getLastCellNum
();
for
(
int
j
=
0
;
j
<
lastCellNum
;
j
++)
{
XSSFCell
cell
=
row
.
getCell
(
j
);
if
(
cell
==
null
)
{
continue
;
}
String
value
=
getCellValue
(
cell
).
toString
();
value
=
value
.
replace
(
"/r/n"
,
""
);
System
.
out
.
print
(
value
+
" "
);
}
System
.
out
.
println
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
/**
* 导出生成excel.xlsx
* @param workbook
*/
public
static
void
export
(
XSSFWorkbook
workbook
){
String
name
=
"f:/poi1_test"
+
Math
.
round
(
Math
.
random
()*
100
)+
".xlsx"
;
File
file
=
new
File
(
name
);
try
{
file
.
createNewFile
();
// 将Excel内容存盘
workbook
.
write
(
FileUtil
.
getOutputStream
(
file
));
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
System
.
out
.
println
(
"完成"
);
System
.
out
.
println
(
name
);
}
}
/**
* 导出生成excel.xlsx
* @param workbook
*/
public
static
void
export
(
XSSFWorkbook
workbook
,
String
name
){
String
fileName
;
if
(
StrUtil
.
isBlank
(
name
))
{
fileName
=
"f:/poi1_test"
+
Math
.
round
(
Math
.
random
()
*
100
)
+
".xlsx"
;
}
else
{
fileName
=
"f:/"
+
name
+
".xlsx"
;
}
File
file
=
new
File
(
fileName
);
try
{
file
.
createNewFile
();
// 将Excel内容存盘
workbook
.
write
(
FileUtil
.
getOutputStream
(
file
));
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
System
.
out
.
println
(
"完成"
);
System
.
out
.
println
(
fileName
);
}
}
/**
* 打印list
* @param list
*/
public
static
void
displayList
(
List
list
)
{
for
(
Object
obj
:
list
)
{
System
.
out
.
println
(
obj
+
""
);
}
}
/**
* 打印Map
* @param map
*/
public
static
void
displayMap
(
Map
<
String
,
Object
>
map
)
{
for
(
Entry
<
String
,
Object
>
obj
:
map
.
entrySet
())
{
System
.
out
.
println
(
obj
.
getKey
()
+
":"
+
obj
.
getValue
());
}
}
/**
* 打印Set
* @param codeSet
*/
public
static
void
displaySet
(
Set
<
String
>
codeSet
)
{
for
(
String
str:
codeSet
){
System
.
out
.
println
(
str
);
}
}
}
Generator/DBProject/src/main/java/com/winsun/db/controller/SqlBaseController.java
0 → 100644
View file @
855da282
package
com
.
winsun
.
db
.
controller
;
import
java.util.List
;
import
java.util.Map
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.support.ClassPathXmlApplicationContext
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
;
import
org.springframework.jdbc.datasource.DataSourceTransactionManager
;
import
org.springframework.transaction.TransactionDefinition
;
import
org.springframework.transaction.TransactionStatus
;
import
org.springframework.transaction.support.DefaultTransactionDefinition
;
public
class
SqlBaseController
extends
BaseController
{
protected
static
ApplicationContext
ctx
=
new
ClassPathXmlApplicationContext
(
"applicationContext.xml"
);
protected
static
JdbcTemplate
jdbcTemplate
=
(
JdbcTemplate
)
ctx
.
getBean
(
"jdbcTemplate"
);
protected
static
NamedParameterJdbcTemplate
namedParameterJdbcTemplate
=
ctx
.
getBean
(
NamedParameterJdbcTemplate
.
class
);
/**
* 查询
* @param sql
* @return
*/
public
List
<
Map
<
String
,
Object
>>
queryForList
(
String
sql
){
return
jdbcTemplate
.
queryForList
(
sql
);
}
/**
*
* 插入、更新、删除
* @param sql
* @return
*/
public
int
jdbcUpdate
(
String
sql
){
return
jdbcTemplate
.
update
(
sql
);
}
/**
* 执行批量语句
* 写语句的sql可不一样
* @param arry
* @return
*/
public
static
int
batchSQLData
(
String
[]
arry
)
{
int
result
=
0
;
// 添加事务
DataSourceTransactionManager
transactionManager
=
new
DataSourceTransactionManager
(
jdbcTemplate
.
getDataSource
());
DefaultTransactionDefinition
def
=
new
DefaultTransactionDefinition
();
def
.
setPropagationBehavior
(
TransactionDefinition
.
PROPAGATION_REQUIRES_NEW
);
TransactionStatus
status
=
transactionManager
.
getTransaction
(
def
);
try
{
if
(
null
!=
arry
&&
arry
.
length
>
0
)
{
int
[]
res
=
jdbcTemplate
.
batchUpdate
(
arry
);
for
(
int
i
:
res
)
{
result
+=
i
;
}
transactionManager
.
commit
(
status
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
transactionManager
.
rollback
(
status
);
return
-
1
;
}
return
result
;
}
/**
* 批量执行,统一条写sql,通过每组的参数进行区分。
* @param sql
* @param params
* @return
*/
public
static
int
batchSQLData
(
String
sql
,
List
<
Object
[]>
params
)
{
int
result
=
0
;
// 添加事务
DataSourceTransactionManager
transactionManager
=
new
DataSourceTransactionManager
(
jdbcTemplate
.
getDataSource
());
DefaultTransactionDefinition
def
=
new
DefaultTransactionDefinition
();
def
.
setPropagationBehavior
(
TransactionDefinition
.
PROPAGATION_REQUIRES_NEW
);
TransactionStatus
status
=
transactionManager
.
getTransaction
(
def
);
try
{
if
(
null
!=
params
&&
params
.
size
()
>
0
)
{
int
[]
res
=
jdbcTemplate
.
batchUpdate
(
sql
,
params
);
for
(
int
i
:
res
)
{
result
+=
i
;
}
transactionManager
.
commit
(
status
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
transactionManager
.
rollback
(
status
);
return
-
1
;
}
return
result
;
}
public
static
String
getDateValue
(
String
tableName
,
String
dateCol
){
String
sql
=
"SELECT max("
+
dateCol
+
") FROM "
+
tableName
;
return
jdbcTemplate
.
queryForObject
(
sql
,
String
.
class
);
}
}
Generator/DBProject/src/main/resources/applicationContext.xml
0 → 100644
View file @
855da282
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns=
"http://www.springframework.org/schema/beans"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:context=
"http://www.springframework.org/schema/context"
xmlns:tx=
"http://www.springframework.org/schema/tx"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"
>
<!-- 导入资源文件 -->
<context:property-placeholder
location=
"classpath:db.properties"
/>
<!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入 -->
<context:component-scan
base-package=
"com"
/>
<!-- 配置 C3P0 数据源 -->
<bean
id=
"dataSource"
class=
"com.alibaba.druid.pool.DruidDataSource"
>
<property
name=
"username"
value=
"${jdbc.username}"
></property>
<property
name=
"password"
value=
"${jdbc.password}"
></property>
<property
name=
"url"
value=
"${jdbc.jdbcUrl}"
></property>
<property
name=
"driverClassName"
value=
"${jdbc.driverClass}"
></property>
</bean>
<!-- 配置 Spirng 的 JdbcTemplate -->
<bean
id=
"jdbcTemplate"
class=
"org.springframework.jdbc.core.JdbcTemplate"
>
<property
name=
"dataSource"
ref=
"dataSource"
></property>
</bean>
<!-- 配置 NamedParameterJdbcTemplate, 该对象可以使用具名参数, 其没有无参数的构造器, 所以必须为其构造器指定参数 -->
<bean
id=
"namedParameterJdbcTemplate"
class=
"org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate"
>
<constructor-arg
ref=
"dataSource"
></constructor-arg>
</bean>
<!-- 配置事务管理器 -->
<bean
id=
"transactionManager"
class=
"org.springframework.jdbc.datasource.DataSourceTransactionManager"
>
<property
name=
"dataSource"
ref=
"dataSource"
></property>
</bean>
<!-- 启用事务注解 -->
<tx:annotation-driven
transaction-manager=
"transactionManager"
/>
</beans>
Generator/DBProject/src/main/resources/db.properties
0 → 100644
View file @
855da282
jdbc.driverClass
=
com.mysql.jdbc.Driver
#ke hu hua xiang
#jdbc.jdbcUrl = jdbc:mysql://112.74.202.190:3306/customerPortrait?useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
#jdbc.username= winsun2017
#jdbc.password= winsun
#dian jiang
#jdbc.jdbcUrl = jdbc:mysql://120.24.88.216:3306/dyjl?useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
#jdbc.jdbcUrl = jdbc:mysql://120.24.88.216:3306/dyjl-test?useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
#jdbc.username = winsun_dev
#jdbc.password = winsun098!@#
#xiao yuan
#jdbc.jdbcUrl = jdbc:mysql://120.24.88.216:3306/xyjl?useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
#jdbc.jdbcUrl = jdbc:mysql://120.24.88.216:3306/xyjl-test?useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
#jdbc.username = winsun_dev
#jdbc.password = winsun098!@#
#ben di
#jdbc.jdbcUrl = jdbc:mysql://localhost:3306/merchant?useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
#jdbc.jdbcUrl = jdbc:mysql://localhost:3306/workload?useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
#jdbc.username = root
#jdbc.password = root
#jdbc.jdbcUrl = jdbc:mysql://localhost:3306/location?useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
#jdbc.jdbcUrl = jdbc:mysql://localhost:3306/dept?useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
#jdbc.jdbcUrl = jdbc:mysql://localhost:3306/dzqd?useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
#jdbc.jdbcUrl = jdbc:mysql://localhost:3306/winsun-admin?useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
#jdbc.username = zero
#jdbc.password = zero
#yi zhi fu
#jdbc.jdbcUrl = jdbc:mysql://132.97.54.60:58333/yzf_data?useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
#jdbc.username = yzf_user
#jdbc.password = yzfuser1!
#jdbc.jdbcUrl = jdbc:mysql://112.74.202.190:3306/lwkb?useUnicode=true&characterEncoding=utf-8
#jdbc.username = lwkb
#jdbc.password = lwkb123
#yong jin
#jdbc.jdbcUrl = jdbc:mysql://132.97.54.10:13306/yjfx?useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
#jdbc.username = tpss_gz
#jdbc.password = abc123!@#
#czc
#jdbc.jdbcUrl = jdbc:mysql://132.97.54.36:58333/czc?useUnicode=true&characterEncoding=utf-8
#jdbc.jdbcUrl = jdbc:mysql://132.97.54.36:58333/czc-test?useUnicode=true&characterEncoding=utf-8
#jdbc.username = czc_user
#jdbc.password = czc_user123
#bhy
#jdbc.jdbcUrl = jdbc:mysql://132.97.54.31:58333/baheyi?useUnicode=true&characterEncoding=utf-8
#jdbc.username = root
#jdbc.password = root123
#linux
#jdbc.jdbcUrl = jdbc:mysql://47.106.133.4:3306/location?useUnicode=true&characterEncoding=utf-8
#jdbc.username = locationuser
#jdbc.password = location_123!@#
#jdbc.jdbcUrl = jdbc:mysql://47.106.133.4:3306/edu_cms?useUnicode=true&characterEncoding=utf-8
#jdbc.username = eduuser
#jdbc.password = eduuser123!@#
#ciop
#jdbc.jdbcUrl = jdbc:mysql://47.106.133.4:3306/winsun_admin?useUnicode=true&characterEncoding=utf-8
#jdbc.username = ciopuser
#jdbc.password = Ciop123!@#
#stqd
#jdbc.jdbcUrl = jdbc:mysql://132.97.54.11:58333/address?&useSSL=false&characterEncoding=utf-8
#jdbc.username = address
#jdbc.password = address@181126
#stqd
#jdbc.jdbcUrl = jdbc:mysql://132.97.55.95:18066/mysqlsc?&useSSL=false&characterEncoding=utf-8
#jdbc.username = mycat_user
#jdbc.password = zhyyptmycat$2019
#jdbc.username = root
#jdbc.password = zhyypt888$2019
#stqd-67
jdbc.jdbcUrl
=
jdbc:mysql://132.97.54.67:3306/stqd_admin?&useSSL=false&characterEncoding=utf-8
jdbc.username
=
stqd_user
jdbc.password
=
stqd666$2019
#stqd-60
#jdbc.jdbcUrl = jdbc:mysql://132.97.54.60:58333/stqd_admin?&useSSL=false&characterEncoding=utf-8
#jdbc.username = stqd
#jdbc.password = stqd888$2019
#dskb
#jdbc.jdbcUrl=jdbc:mysql://132.97.153.45:3306/dskb?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
#jdbc.username=root
#jdbc.password=my45$%^
#ka hao
#jdbc.jdbcUrl=jdbc:mysql://132.97.54.14:13306/card
#jdbc.username=card_user
#jdbc.password=card12345678
#zqks
#jdbc.jdbcUrl=jdbc:mysql://132.97.54.60:58333/zqks_admin?&useSSL=false&characterEncoding=utf-8
#jdbc.username=zqks_user
#jdbc.password=zqksuser12!
#jdbc.driverClass=oracle.jdbc.driver.OracleDriver
#louyu
#jdbc.jdbcUrl = jdbc:oracle:thin:@132.97.172.223:1521:ZWFX
#jdbc.username = sk_user
#jdbc.password = SK_user_456
#she qu
#jdbc.jdbcUrl = jdbc:oracle:thin:@132.97.172.223:1521:ZWFX
#jdbc.username = scbuser
#jdbc.password = scb_USER_789
#ceo
#jdbc.jdbcUrl = jdbc:oracle:thin:@132.97.172.223:1521:ZWFX
#jdbc.username = ceouser
#jdbc.password = ceo_USER_789
#ke fu
#jdbc.jdbcUrl = jdbc:oracle:thin:@112.74.202.190:1521:orcl
#jdbc.username = build_user
#jdbc.password = build123
#yi zhi fu
#jdbc.jdbcUrl = jdbc:oracle:thin:@132.97.20.41:1521:orcl
#jdbc.username=merchant_user
#jdbc.password=merchant_user123
#jdbc.username=merchant_temp
#jdbc.password=merchant_temp123
#zzdt
#jdbc.jdbcUrl = jdbc:oracle:thin:@132.97.20.41:1521:orcl
#jdbc.username=yh_user
#jdbc.password=yh_123
#jihe
#jdbc.jdbcUrl = jdbc:oracle:thin:@132.97.172.223:1521:zwfx
#jdbc.username = yz_ywjh
#jdbc.password = ls123
#jdbc.driverClass=com.sybase.jdbc2.jdbc.SybDriver
#IQcom.sybase.jdbc.SybDrive
#jdbc.jdbcUrl = jdbc:sybase:Tds:132.97.93.192:5000/iq_n2
#jdbc.username= sqyx
#jdbc.password= ywzc2016
jdbc.initPoolSize
=
5
jdbc.maxPoolSize
=
10
\ No newline at end of file
Generator/genTable/pom.xml
0 → 100644
View file @
855da282
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
Generator
</artifactId>
<groupId>
com.winsun.tools
</groupId>
<version>
1.0-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
genTable
</artifactId>
<dependencies>
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi
</artifactId>
<version>
3.17
</version>
</dependency>
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi-ooxml
</artifactId>
<version>
3.17
</version>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
cn.hutool
</groupId>
<artifactId>
hutool-all
</artifactId>
<version>
5.1.0
</version>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<version>
4.12
</version>
<!-- 不设置scope就是全局 -->
<!-- <scope>test</scope>-->
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<configuration>
<fork>
true
</fork>
<addResources>
true
</addResources>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
Generator/genTable/src/main/java/com/winsun/tools/data/TreeNodeData.java
0 → 100644
View file @
855da282
package
com
.
winsun
.
tools
.
data
;
import
com.winsun.tools.entity.TreeNode
;
/**
* @author zero
* @version 1.0
* @date 2020/5/24 16:43
*/
public
class
TreeNodeData
{
public
static
TreeNode
getData1
(){
TreeNode
treeNode
=
new
TreeNode
(-
1
,
""
,
null
);
TreeNode
treeNode0
=
new
TreeNode
(
0
,
"单位"
,
"subst_name"
,
treeNode
);
TreeNode
treeNode1
=
new
TreeNode
(
1
,
"到期总数"
,
treeNode
);
TreeNode
treeNode2
=
new
TreeNode
(
2
,
"派单数"
,
treeNode
);
TreeNode
treeNode3
=
new
TreeNode
(
3
,
"跟进情况"
,
treeNode
);
TreeNode
treeNode4
=
new
TreeNode
(
4
,
"跟进结果"
,
treeNode
);
TreeNode
treeNode5
=
new
TreeNode
(
5
,
"合计"
,
"total"
,
treeNode1
);
TreeNode
treeNode6
=
new
TreeNode
(
6
,
"互联网专线"
,
"toal_hlwzx"
,
treeNode1
);
TreeNode
treeNode7
=
new
TreeNode
(
7
,
"组网专线"
,
"total_zwzx"
,
treeNode1
);
TreeNode
treeNode8
=
new
TreeNode
(
8
,
"合计"
,
"total_pd"
,
treeNode2
);
TreeNode
treeNode9
=
new
TreeNode
(
9
,
"互联网专线"
,
"v1"
,
treeNode2
);
TreeNode
treeNode10
=
new
TreeNode
(
10
,
"组网专线"
,
"v2"
,
treeNode2
);
TreeNode
treeNode11
=
new
TreeNode
(
11
,
"接单数"
,
"v3"
,
treeNode3
);
TreeNode
treeNode12
=
new
TreeNode
(
12
,
"执行率"
,
"v4"
,
treeNode3
);
TreeNode
treeNode13
=
new
TreeNode
(
13
,
"洽谈中"
,
"v5"
,
treeNode3
);
TreeNode
treeNode14
=
new
TreeNode
(
14
,
"资审合同审批中"
,
"v6"
,
treeNode3
);
TreeNode
treeNode15
=
new
TreeNode
(
15
,
"受理实施中"
,
"v7"
,
treeNode3
);
TreeNode
treeNode16
=
new
TreeNode
(
16
,
"洽谈成功"
,
"v8"
,
treeNode3
);
TreeNode
treeNode17
=
new
TreeNode
(
17
,
"失败"
,
"v9"
,
treeNode3
);
TreeNode
treeNode18
=
new
TreeNode
(
18
,
"续约数"
,
"v10"
,
treeNode4
);
TreeNode
treeNode19
=
new
TreeNode
(
19
,
"续约率"
,
"v11"
,
treeNode4
);
TreeNode
treeNode20
=
new
TreeNode
(
20
,
"提速数"
,
"v12"
,
treeNode4
);
TreeNode
treeNode21
=
new
TreeNode
(
21
,
"占比"
,
"v13"
,
treeNode4
);
TreeNode
treeNode22
=
new
TreeNode
(
22
,
"提值数"
,
"v14"
,
treeNode4
);
TreeNode
treeNode23
=
new
TreeNode
(
23
,
"占比"
,
"v15"
,
treeNode4
);
TreeNode
treeNode24
=
new
TreeNode
(
24
,
"提值月租"
,
"v16"
,
treeNode4
);
TreeNode
treeNode25
=
new
TreeNode
(
25
,
"拆机数"
,
"v17"
,
treeNode4
);
TreeNode
treeNode26
=
new
TreeNode
(
26
,
"占比"
,
"v18"
,
treeNode4
);
treeNode
.
calLeavesAmount
(
treeNode
);
treeNode
.
calNodeLevel
(
treeNode
);
return
treeNode
;
}
public
static
TreeNode
getVpnXySubst
(){
TreeNode
treeNode
=
new
TreeNode
(-
1
,
""
,
null
);
TreeNode
treeNode0
=
new
TreeNode
(
0
,
"县分"
,
"subst"
,
treeNode
);
TreeNode
treeNode1
=
new
TreeNode
(
1
,
"业务/活动名称"
,
"fname"
,
treeNode
);
TreeNode
treeNode2
=
new
TreeNode
(
2
,
"渠道"
,
"task_type"
,
treeNode
);
TreeNode
treeNode3
=
new
TreeNode
(
3
,
"到期客户数"
,
"count_customer_due"
,
treeNode
);
TreeNode
treeNode4
=
new
TreeNode
(
4
,
"目标号码数"
,
"count_target_phone"
,
treeNode
);
TreeNode
treeNode5
=
new
TreeNode
(
5
,
"累计续约数"
,
"count_cumulative_renewals"
,
treeNode
);
TreeNode
treeNode6
=
new
TreeNode
(
6
,
"续约率"
,
"renewal_rate"
,
treeNode
);
TreeNode
treeNode7
=
new
TreeNode
(
7
,
"其中续约类型终补"
,
"count_renewal_type_final"
,
treeNode
);
TreeNode
treeNode8
=
new
TreeNode
(
8
,
"其中续约类型话补"
,
"count_renewal_huabu"
,
treeNode
);
TreeNode
treeNode9
=
new
TreeNode
(
9
,
"其中续约类型套餐打折"
,
"count_renewal_discount"
,
treeNode
);
TreeNode
treeNode10
=
new
TreeNode
(
10
,
"其中续约类型战狼团购"
,
"count_renewal_coyote"
,
treeNode
);
TreeNode
treeNode11
=
new
TreeNode
(
11
,
"其中续约融升套餐"
,
"count_renewal_rs"
,
treeNode
);
TreeNode
treeNode12
=
new
TreeNode
(
12
,
"其中续约无条件或违约金"
,
"count_renewal_wtj_wyj"
,
treeNode
);
TreeNode
treeNode13
=
new
TreeNode
(
13
,
"续约升级5G数"
,
"count_renewal_5g"
,
treeNode
);
treeNode
.
calLeavesAmount
(
treeNode
);
treeNode
.
calNodeLevel
(
treeNode
);
return
treeNode
;
}
public
static
TreeNode
getVpnXyBranch
(){
TreeNode
treeNode
=
new
TreeNode
(-
1
,
""
,
null
);
TreeNode
treeNode0
=
new
TreeNode
(
0
,
"县分"
,
"subst"
,
treeNode
);
TreeNode
treeNode1
=
new
TreeNode
(
1
,
"营服"
,
"branch"
,
treeNode
);
TreeNode
treeNode2
=
new
TreeNode
(
2
,
"业务/活动名称"
,
"fname"
,
treeNode
);
TreeNode
treeNode3
=
new
TreeNode
(
3
,
"渠道"
,
"task_type"
,
treeNode
);
TreeNode
treeNode4
=
new
TreeNode
(
4
,
"到期客户数"
,
"count_customer_due"
,
treeNode
);
TreeNode
treeNode5
=
new
TreeNode
(
5
,
"目标号码数"
,
"count_target_phone"
,
treeNode
);
TreeNode
treeNode6
=
new
TreeNode
(
6
,
"累计续约数"
,
"count_cumulative_renewals"
,
treeNode
);
TreeNode
treeNode7
=
new
TreeNode
(
7
,
"续约率"
,
"renewal_rate"
,
treeNode
);
TreeNode
treeNode8
=
new
TreeNode
(
8
,
"其中续约类型终补"
,
"count_renewal_type_final"
,
treeNode
);
TreeNode
treeNode9
=
new
TreeNode
(
9
,
"其中续约类型话补"
,
"count_renewal_huabu"
,
treeNode
);
TreeNode
treeNode10
=
new
TreeNode
(
10
,
"其中续约类型套餐打折"
,
"count_renewal_discount"
,
treeNode
);
TreeNode
treeNode11
=
new
TreeNode
(
11
,
"其中续约类型战狼团购"
,
"count_renewal_coyote"
,
treeNode
);
TreeNode
treeNode12
=
new
TreeNode
(
12
,
"其中续约融升套餐"
,
"count_renewal_rs"
,
treeNode
);
TreeNode
treeNode13
=
new
TreeNode
(
13
,
"其中续约无条件或违约金"
,
"count_renewal_wtj_wyj"
,
treeNode
);
TreeNode
treeNode14
=
new
TreeNode
(
14
,
"续约升级5G数"
,
"count_renewal_5g"
,
treeNode
);
treeNode
.
calLeavesAmount
(
treeNode
);
treeNode
.
calNodeLevel
(
treeNode
);
return
treeNode
;
}
public
static
TreeNode
getVpnXyAcc
(){
TreeNode
treeNode
=
new
TreeNode
(-
1
,
""
,
null
);
TreeNode
treeNode0
=
new
TreeNode
(
0
,
"县分"
,
"subst"
,
treeNode
);
TreeNode
treeNode1
=
new
TreeNode
(
1
,
"营服"
,
"branch"
,
treeNode
);
TreeNode
treeNode2
=
new
TreeNode
(
2
,
"客户经理"
,
"acc_name"
,
treeNode
);
TreeNode
treeNode3
=
new
TreeNode
(
3
,
"客户经理acc"
,
"acc_code"
,
treeNode
);
TreeNode
treeNode4
=
new
TreeNode
(
4
,
"业务/活动名称"
,
"fname"
,
treeNode
);
TreeNode
treeNode5
=
new
TreeNode
(
5
,
"渠道"
,
"task_type"
,
treeNode
);
TreeNode
treeNode6
=
new
TreeNode
(
6
,
"到期客户数"
,
"count_customer_due"
,
treeNode
);
TreeNode
treeNode7
=
new
TreeNode
(
7
,
"目标号码数"
,
"count_target_phone"
,
treeNode
);
TreeNode
treeNode8
=
new
TreeNode
(
8
,
"累计续约数"
,
"count_cumulative_renewals"
,
treeNode
);
TreeNode
treeNode9
=
new
TreeNode
(
9
,
"续约率"
,
"renewal_rate"
,
treeNode
);
TreeNode
treeNode10
=
new
TreeNode
(
10
,
"其中续约类型终补"
,
"count_renewal_type_final"
,
treeNode
);
TreeNode
treeNode11
=
new
TreeNode
(
11
,
"其中续约类型话补"
,
"count_renewal_huabu"
,
treeNode
);
TreeNode
treeNode12
=
new
TreeNode
(
12
,
"其中续约类型套餐打折"
,
"count_renewal_discount"
,
treeNode
);
TreeNode
treeNode13
=
new
TreeNode
(
13
,
"其中续约类型战狼团购"
,
"count_renewal_coyote"
,
treeNode
);
TreeNode
treeNode14
=
new
TreeNode
(
14
,
"其中续约融升套餐"
,
"count_renewal_rs"
,
treeNode
);
TreeNode
treeNode15
=
new
TreeNode
(
15
,
"其中续约无条件或违约金"
,
"count_renewal_wtj_wyj"
,
treeNode
);
TreeNode
treeNode16
=
new
TreeNode
(
16
,
"续约升级5G数"
,
"count_renewal_5g"
,
treeNode
);
treeNode
.
calLeavesAmount
(
treeNode
);
treeNode
.
calNodeLevel
(
treeNode
);
return
treeNode
;
}
public
static
TreeNode
getHk4s5ACC
(){
TreeNode
treeNode
=
new
TreeNode
(-
1
,
""
,
null
);
TreeNode
treeNode0
=
new
TreeNode
(
0
,
"县分"
,
"subst"
,
treeNode
);
TreeNode
treeNode1
=
new
TreeNode
(
1
,
"营服"
,
"branch"
,
treeNode
);
TreeNode
treeNode2
=
new
TreeNode
(
2
,
"客户经理"
,
treeNode
);
TreeNode
treeNode3
=
new
TreeNode
(
3
,
"客户经理帐号"
,
treeNode
);
TreeNode
treeNode4
=
new
TreeNode
(
4
,
"业务/活动名称"
,
"fname"
,
treeNode
);
TreeNode
treeNode5
=
new
TreeNode
(
5
,
"渠道"
,
"task_type"
,
treeNode
);
TreeNode
treeNode6
=
new
TreeNode
(
6
,
"目标数"
,
"total_target"
,
treeNode
);
TreeNode
treeNode7
=
new
TreeNode
(
7
,
"累计5G升级数"
,
"total_5g"
,
treeNode
);
TreeNode
treeNode8
=
new
TreeNode
(
8
,
"升级率"
,
"rate_upgrade"
,
treeNode
);
TreeNode
treeNode9
=
new
TreeNode
(
9
,
"依案办理数"
,
"total_yabl"
,
treeNode
);
TreeNode
treeNode10
=
new
TreeNode
(
10
,
"依案办理率"
,
"rate_yabl"
,
treeNode
);
TreeNode
treeNode11
=
new
TreeNode
(
11
,
"其中5G加包数"
,
"count_5g_packets"
,
treeNode
);
TreeNode
treeNode12
=
new
TreeNode
(
12
,
"其中5G套餐数"
,
"count_5g_packages"
,
treeNode
);
TreeNode
treeNode13
=
new
TreeNode
(
13
,
"5G套餐价值区间129元以下"
,
"count_5g_packages_below_129"
,
treeNode
);
TreeNode
treeNode14
=
new
TreeNode
(
14
,
"G套餐价值区间129-299"
,
"count_5g_packages_129_299"
,
treeNode
);
TreeNode
treeNode15
=
new
TreeNode
(
15
,
"5G套餐价值区间299元以上"
,
"count_5g_packages_above_299"
,
treeNode
);
treeNode
.
calLeavesAmount
(
treeNode
);
treeNode
.
calNodeLevel
(
treeNode
);
return
treeNode
;
}
}
Generator/genTable/src/main/java/com/winsun/tools/entity/TreeNode.java
0 → 100644
View file @
855da282
package
com
.
winsun
.
tools
.
entity
;
import
cn.hutool.core.util.StrUtil
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* 数结构用于保存Excel表头, 主要用于需要合并单元格的表头
*
* @author ZERO
*
*/
@Data
public
class
TreeNode
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
private
int
parentId
;
private
int
selfId
;
protected
int
level
;
protected
int
leafSize
;
//
protected
String
key
;
protected
String
nodeName
;
protected
TreeNode
parentNode
;
protected
int
color
;
protected
List
<
TreeNode
>
childList
;
protected
TreeNode
rootNode
;
public
TreeNode
()
{
initChildList
();
}
public
TreeNode
(
String
name
)
{
this
.
setNodeName
(
name
);
initChildList
();
}
public
TreeNode
(
String
name
,
TreeNode
parentNode
)
{
this
.
setNodeName
(
name
);
if
(
parentNode
!=
null
)
{
this
.
setParentNode
(
parentNode
);
this
.
setParentId
(
parentNode
.
selfId
);
}
initChildList
();
}
public
TreeNode
(
int
id
,
TreeNode
parentNode
)
{
this
.
setSelfId
(
id
);
this
.
setNodeName
(
""
);
if
(
parentNode
!=
null
)
{
this
.
setParentNode
(
parentNode
);
this
.
setParentId
(
parentNode
.
selfId
);
}
initChildList
();
}
public
TreeNode
(
int
id
,
String
name
,
TreeNode
parentNode
)
{
this
.
setSelfId
(
id
);
this
.
setNodeName
(
name
);
if
(
parentNode
!=
null
)
{
this
.
setParentNode
(
parentNode
);
this
.
setParentId
(
parentNode
.
selfId
);
parentNode
.
addChildNode
(
this
);
}
initChildList
();
}
public
TreeNode
(
int
id
,
String
name
,
TreeNode
parentNode
,
int
color
)
{
this
.
setSelfId
(
id
);
this
.
setNodeName
(
name
);
if
(
parentNode
!=
null
)
{
this
.
setParentNode
(
parentNode
);
this
.
setParentId
(
parentNode
.
selfId
);
parentNode
.
addChildNode
(
this
);
}
this
.
setColor
(
color
);
initChildList
();
}
public
TreeNode
(
int
id
,
String
name
,
String
key
,
TreeNode
parentNode
)
{
this
.
setSelfId
(
id
);
this
.
setNodeName
(
name
);
this
.
setKey
(
key
);
if
(
parentNode
!=
null
)
{
this
.
setParentNode
(
parentNode
);
this
.
setParentId
(
parentNode
.
selfId
);
parentNode
.
addChildNode
(
this
);
}
initChildList
();
}
public
TreeNode
(
int
id
,
String
name
,
String
key
,
TreeNode
parentNode
,
int
color
)
{
this
.
setSelfId
(
id
);
this
.
setNodeName
(
name
);
this
.
setKey
(
key
);
if
(
parentNode
!=
null
)
{
this
.
setParentNode
(
parentNode
);
this
.
setParentId
(
parentNode
.
selfId
);
parentNode
.
addChildNode
(
this
);
}
this
.
setColor
(
color
);
initChildList
();
}
public
TreeNode
(
TreeNode
parentNode
)
{
if
(
parentNode
!=
null
)
{
this
.
setParentNode
(
parentNode
);
this
.
setParentId
(
parentNode
.
selfId
);
parentNode
.
addChildNode
(
this
);
}
initChildList
();
}
public
boolean
isLeaf
()
{
if
(
childList
==
null
)
{
return
true
;
}
else
{
if
(
childList
.
isEmpty
())
{
return
true
;
}
else
{
return
false
;
}
}
}
/* 插入一个child节点到当前节点中 */
public
void
addChildNode
(
TreeNode
treeNode
)
{
initChildList
();
childList
.
add
(
treeNode
);
treeNode
.
setParentNode
(
this
);
}
public
void
initChildList
()
{
if
(
childList
==
null
)
{
childList
=
new
ArrayList
<
TreeNode
>();
}
}
public
boolean
isValidTree
()
{
return
true
;
}
/* 返回当前节点的父辈节点集合 */
public
List
<
TreeNode
>
getElders
()
{
List
<
TreeNode
>
elderList
=
new
ArrayList
<
TreeNode
>();
TreeNode
parentNode
=
this
.
getParentNode
();
if
(
parentNode
==
null
)
{
return
elderList
;
}
else
{
elderList
.
add
(
parentNode
);
elderList
.
addAll
(
parentNode
.
getElders
());
return
elderList
;
}
}
/* 返回当前节点的晚辈集合 */
public
List
<
TreeNode
>
getJuniors
()
{
List
<
TreeNode
>
juniorList
=
new
ArrayList
<
TreeNode
>();
List
<
TreeNode
>
childList
=
this
.
getChildList
();
if
(
childList
==
null
)
{
return
juniorList
;
}
else
{
int
childNumber
=
childList
.
size
();
for
(
int
i
=
0
;
i
<
childNumber
;
i
++)
{
TreeNode
junior
=
childList
.
get
(
i
);
juniorList
.
add
(
junior
);
juniorList
.
addAll
(
junior
.
getJuniors
());
}
return
juniorList
;
}
}
/**
* 返回当前层的下一层节点
*
* @author SongBaoYu
* @param currLevelNodes
* @return
*/
public
static
List
<
TreeNode
>
getNextLevelNodes
(
List
<
TreeNode
>
currLevelNodes
)
{
List
<
TreeNode
>
resList
=
new
ArrayList
<
TreeNode
>();
for
(
TreeNode
currNode
:
currLevelNodes
)
{
List
<
TreeNode
>
childList
=
currNode
.
getChildList
();
for
(
TreeNode
node
:
childList
)
{
if
(
StrUtil
.
isBlank
(
node
.
getKey
()))
{
resList
.
add
(
node
);
}
}
}
return
resList
;
}
/* 返回当前节点的孩子集合 */
public
List
<
TreeNode
>
getChildList
()
{
return
childList
;
}
/* 删除节点和它下面的晚辈 */
public
void
deleteNode
()
{
TreeNode
parentNode
=
this
.
getParentNode
();
int
id
=
this
.
getSelfId
();
if
(
parentNode
!=
null
)
{
parentNode
.
deleteChildNode
(
id
);
}
}
/* 删除当前节点的某个子节点 */
public
void
deleteChildNode
(
int
childId
)
{
List
<
TreeNode
>
childList
=
this
.
getChildList
();
int
childNumber
=
childList
.
size
();
for
(
int
i
=
0
;
i
<
childNumber
;
i
++)
{
TreeNode
child
=
childList
.
get
(
i
);
if
(
child
.
getSelfId
()
==
childId
)
{
childList
.
remove
(
i
);
return
;
}
}
}
/* 动态的插入一个新的节点到当前树中 */
public
boolean
insertJuniorNode
(
TreeNode
treeNode
)
{
int
juniorParentId
=
treeNode
.
getParentId
();
if
(
this
.
parentId
==
juniorParentId
)
{
addChildNode
(
treeNode
);
return
true
;
}
else
{
List
<
TreeNode
>
childList
=
this
.
getChildList
();
int
childNumber
=
childList
.
size
();
boolean
insertFlag
;
for
(
int
i
=
0
;
i
<
childNumber
;
i
++)
{
TreeNode
childNode
=
childList
.
get
(
i
);
insertFlag
=
childNode
.
insertJuniorNode
(
treeNode
);
if
(
insertFlag
==
true
)
return
true
;
}
return
false
;
}
}
/* 找到一颗树中某个节点 */
public
TreeNode
findTreeNodeById
(
int
id
)
{
if
(
this
.
selfId
==
id
)
{
return
this
;
}
if
(
childList
.
isEmpty
()
||
childList
==
null
)
{
return
null
;
}
else
{
int
childNumber
=
childList
.
size
();
for
(
int
i
=
0
;
i
<
childNumber
;
i
++)
{
TreeNode
child
=
childList
.
get
(
i
);
TreeNode
resultNode
=
child
.
findTreeNodeById
(
id
);
if
(
resultNode
!=
null
)
{
return
resultNode
;
}
}
return
null
;
}
}
/* 找到一颗树中某个节点 */
public
TreeNode
findTreeNodeByKey
(
String
key
)
{
if
(
key
.
equals
(
this
.
getKey
()))
{
return
this
;
}
if
(
isLeaf
())
{
return
null
;
}
else
{
int
childNumber
=
childList
.
size
();
for
(
int
i
=
0
;
i
<
childNumber
;
i
++)
{
TreeNode
child
=
childList
.
get
(
i
);
TreeNode
resultNode
=
child
.
findTreeNodeByKey
(
key
);
if
(
resultNode
!=
null
)
{
return
resultNode
;
}
}
return
null
;
}
}
/* 遍历一棵树,层次遍历 */
public
void
traverse
()
{
if
(
selfId
<
0
)
{
return
;
}
// print(this.selfId);
System
.
out
.
print
(
this
.
level
+
" "
);
if
(
this
.
isLeaf
())
{
return
;
}
int
childNumber
=
childList
.
size
();
for
(
int
i
=
0
;
i
<
childNumber
;
i
++)
{
TreeNode
child
=
childList
.
get
(
i
);
child
.
traverse
();
}
}
public
void
traverseNode
()
{
if
(
selfId
<
0
)
{
return
;
}
// print(this.selfId);
System
.
out
.
print
(
this
.
nodeName
+
","
);
if
(
this
.
isLeaf
())
{
return
;
}
int
childNumber
=
childList
.
size
();
for
(
int
i
=
0
;
i
<
childNumber
;
i
++)
{
TreeNode
child
=
childList
.
get
(
i
);
child
.
traverseNode
();
}
}
/**
* 从左到右获取叶子的key
*/
public
List
<
String
>
getKeyList
()
{
List
<
String
>
keyList
=
new
ArrayList
<
String
>();
List
<
TreeNode
>
nodeList
=
this
.
getJuniors
();
for
(
int
i
=
0
,
s
=
nodeList
.
size
();
i
<
s
;
i
++)
{
String
key
=
nodeList
.
get
(
i
).
getKey
();
if
(
nodeList
.
get
(
i
).
isLeaf
()
&&
StrUtil
.
isNotBlank
(
key
))
{
keyList
.
add
(
key
);
}
}
return
keyList
;
}
/** 计算叶子数,即该节点所占的长度 */
public
int
calLeavesAmount
(
TreeNode
treeNode
)
{
if
(
treeNode
.
isLeaf
())
{
treeNode
.
setLeafSize
(
1
);
return
1
;
}
else
{
int
sum
=
0
;
for
(
TreeNode
node
:
treeNode
.
childList
)
{
sum
+=
calLeavesAmount
(
node
);
}
treeNode
.
setLeafSize
(
sum
);
return
sum
;
}
}
/** 填写所有节点的等级(层数) */
public
void
calNodeLevel
(
TreeNode
treeNode
)
{
if
(
treeNode
.
parentNode
==
null
)
{
treeNode
.
setLevel
(-
1
);
}
else
{
treeNode
.
setLevel
(
treeNode
.
parentNode
.
getLevel
()
+
1
);
}
if
(!
treeNode
.
isLeaf
())
{
for
(
TreeNode
node
:
treeNode
.
getChildList
())
{
calNodeLevel
(
node
);
}
}
}
/* 获取最大层数 */
public
int
getMaxLevel
()
{
List
<
TreeNode
>
list
=
this
.
getJuniors
();
int
max
=
0
;
for
(
TreeNode
node
:
list
)
{
int
l
=
node
.
getLevel
();
max
=
max
<
l
?
l
:
max
;
}
return
max
;
}
public
void
print
(
String
content
)
{
System
.
out
.
println
(
content
);
}
public
void
print
(
int
content
)
{
System
.
out
.
println
(
String
.
valueOf
(
content
));
}
public
void
setChildList
(
List
<
TreeNode
>
childList
)
{
this
.
childList
=
childList
;
}
public
int
getParentId
()
{
return
parentId
;
}
public
void
setParentId
(
int
parentId
)
{
this
.
parentId
=
parentId
;
}
public
int
getSelfId
()
{
return
selfId
;
}
public
void
setSelfId
(
int
selfId
)
{
this
.
selfId
=
selfId
;
}
public
TreeNode
getParentNode
()
{
return
parentNode
;
}
public
void
setParentNode
(
TreeNode
parentNode
)
{
this
.
parentNode
=
parentNode
;
this
.
setParentId
(
parentNode
.
getSelfId
());
}
public
String
getNodeName
()
{
return
nodeName
;
}
public
void
setNodeName
(
String
nodeName
)
{
this
.
nodeName
=
nodeName
;
}
public
int
getLeafSize
()
{
return
leafSize
;
}
public
void
setLeafSize
(
int
leafSize
)
{
this
.
leafSize
=
leafSize
;
}
public
String
getKey
()
{
return
key
;
}
public
void
setKey
(
String
key
)
{
this
.
key
=
key
!=
null
?
key
:
""
;
}
public
int
getLevel
()
{
return
level
;
}
public
void
setLevel
(
int
level
)
{
this
.
level
=
level
;
}
public
int
getColor
()
{
return
color
;
}
public
void
setColor
(
int
color
)
{
this
.
color
=
color
;
}
@Override
public
String
toString
()
{
String
str
=
"TreeNode [parentId="
+
parentId
+
", selfId="
+
selfId
+
", nodeName="
+
nodeName
+
", leafSize="
+
leafSize
+
", color="
+
color
+
", key="
+
key
+
", level="
+
level
+
", \nchildList="
;
if
(
childList
!=
null
||
!
childList
.
isEmpty
())
{
for
(
Object
obj
:
childList
)
{
str
+=
"\n"
+
obj
.
toString
();
}
}
else
{
str
+=
"null"
;
}
str
+=
"]"
;
return
str
;
}
}
Generator/genTable/src/main/java/com/winsun/tools/entity/TreeNodeReComplie.java
0 → 100644
View file @
855da282
package
com
.
winsun
.
tools
.
entity
;
/**
* 树结构反向编译类
*
* @author 吕伟康
* @date 2018年4月14日上午1:05:40
*/
public
class
TreeNodeReComplie
{
private
String
content
;
private
int
id
;
private
String
clazzName
;
private
String
name
;
private
String
key
;
private
TreeNodeReComplie
parent
;
public
TreeNodeReComplie
()
{
}
public
TreeNodeReComplie
(
String
clazzName
)
{
this
.
clazzName
=
clazzName
;
}
public
TreeNodeReComplie
(
int
id
,
String
content
)
{
this
.
setId
(
id
);
this
.
setContent
(
content
);
}
public
String
getContent
()
{
if
(
this
.
content
==
null
)
{
return
null
;
}
return
content
;
}
public
void
setContent
(
String
content
)
{
this
.
content
=
content
;
String
[]
arr
=
content
.
split
(
"#"
);
this
.
setName
(
arr
[
0
]);
if
(
arr
.
length
>
1
)
{
this
.
setKey
(
arr
[
1
]);
}
}
public
int
getId
()
{
return
id
;
}
public
void
setId
(
int
id
)
{
this
.
id
=
id
;
this
.
setClazzName
(
"treeNode"
+
id
);
}
public
String
getClazzName
()
{
return
clazzName
;
}
public
void
setClazzName
(
String
clazzName
)
{
this
.
clazzName
=
clazzName
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getKey
()
{
return
key
;
}
public
void
setKey
(
String
key
)
{
this
.
key
=
key
;
}
public
TreeNodeReComplie
getParent
()
{
return
parent
;
}
public
void
setParent
(
TreeNodeReComplie
parent
)
{
this
.
parent
=
parent
;
}
public
String
getJavaCode
()
{
StringBuilder
sBuilder
=
new
StringBuilder
();
sBuilder
.
append
(
"TreeNode treeNode"
).
append
(
id
).
append
(
" = new TreeNode("
).
append
(
id
);
sBuilder
.
append
(
", \""
).
append
(
name
).
append
(
"\""
);
if
(
key
!=
null
&&
!
key
.
equals
(
""
))
{
// sBuilder.append(",\"").append(key.toUpperCase()).append("\"");
sBuilder
.
append
(
",\""
).
append
(
key
).
append
(
"\""
);
}
if
(
this
.
parent
!=
null
)
{
sBuilder
.
append
(
", "
).
append
(
parent
.
getClazzName
()).
append
(
");"
);
}
else
{
sBuilder
.
append
(
", "
).
append
(
"null"
).
append
(
");"
);
}
return
sBuilder
.
toString
();
}
public
TreeNodeSql
getTreeNodeSql
()
{
TreeNodeSql
treeNodeSql
=
new
TreeNodeSql
();
treeNodeSql
.
setIndex
(
id
);
treeNodeSql
.
setName
(
name
);
if
(
key
!=
null
&&
!
key
.
equals
(
""
))
{
treeNodeSql
.
setKey
(
key
);
}
if
(
this
.
parent
!=
null
)
{
String
parentNodeName
=
parent
.
getClazzName
();
String
parentNodeId
=
parentNodeName
.
replace
(
"treeNode"
,
""
);
int
index
=
parentNodeId
.
length
()
==
0
?
-
1
:
Integer
.
parseInt
(
parentNodeId
);
treeNodeSql
.
setParentIndex
(
index
);
}
else
{
treeNodeSql
.
setParentIndex
(-
1
);
}
return
treeNodeSql
;
}
@Override
public
String
toString
()
{
return
"TreeNodeReComplie [content="
+
content
+
", id="
+
id
+
", name="
+
name
+
", key="
+
key
+
"]"
;
}
}
Generator/genTable/src/main/java/com/winsun/tools/entity/TreeNodeSql.java
0 → 100644
View file @
855da282
package
com
.
winsun
.
tools
.
entity
;
import
cn.hutool.core.util.StrUtil
;
import
com.winsun.tools.utils.SQLHelper
;
/**
* @author zero
* @version 1.0
* @date 2020/5/27 10:32
*/
public
class
TreeNodeSql
{
private
int
index
;
private
String
name
;
private
String
key
;
private
int
parentIndex
;
public
TreeNodeSql
()
{
// TODO Auto-generated constructor stub
}
public
TreeNodeSql
(
int
index
,
String
name
,
int
parentIndex
)
{
super
();
this
.
index
=
index
;
this
.
name
=
name
;
this
.
parentIndex
=
parentIndex
;
}
public
TreeNodeSql
(
int
orderId
,
String
name
,
String
key
,
int
parentIndex
)
{
super
();
this
.
index
=
orderId
;
this
.
name
=
name
;
this
.
key
=
key
;
this
.
parentIndex
=
parentIndex
;
}
public
int
getIndex
()
{
return
index
;
}
public
void
setIndex
(
int
index
)
{
this
.
index
=
index
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getKey
()
{
return
key
;
}
public
void
setKey
(
String
key
)
{
this
.
key
=
key
;
}
public
int
getParentIndex
()
{
return
parentIndex
;
}
public
void
setParentIndex
(
int
parentIndex
)
{
this
.
parentIndex
=
parentIndex
;
}
@Override
public
String
toString
()
{
return
"TreeNodeSql [index="
+
index
+
", name="
+
name
+
", key="
+
key
+
", parentIndex="
+
parentIndex
+
"]"
;
}
public
String
toSql
(
String
table
,
String
tableName
){
SQLHelper
sqlHelper
=
new
SQLHelper
(
table
,
""
);
sqlHelper
.
addInsertClause
(
"index"
,
index
+
""
)
.
addInsertClause
(
"name"
,
"'"
+
name
+
"'"
)
.
addInsertClause
(
StrUtil
.
isNotBlank
(
key
),
"key"
,
"'"
+
key
+
"'"
)
.
addInsertClause
(
"parent_index"
,
parentIndex
+
""
)
.
addInsertClause
(
"table_name"
,
"'"
+
tableName
+
"'"
);
return
sqlHelper
.
getInsertSQL
()
+
";"
;
}
// CREATE TABLE `sys_table_config` (
// `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id',
// `index` int(11) NOT NULL COMMENT '内部自增下标',
// `name` varchar(100) NOT NULL COMMENT '名称',
// `key` varchar(100) DEFAULT NULL COMMENT '字段值',
// `parent_index` int(11) NOT NULL COMMENT '父级下标',
// `table_name` varchar(100) DEFAULT NULL COMMENT '所属表格',
// PRIMARY KEY (`id`)
// ) ENGINE=InnoDB DEFAULT CHARSET=utf8
}
Generator/genTable/src/main/java/com/winsun/tools/utils/ExcelCellUtils.java
0 → 100644
View file @
855da282
package
com
.
winsun
.
tools
.
utils
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.FormulaEvaluator
;
import
org.apache.poi.xssf.usermodel.XSSFCell
;
import
org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
java.text.DecimalFormat
;
/**
* @author zero
* @version 1.0
* @date 2020/5/24 0:36
*/
public
class
ExcelCellUtils
{
//处理公式
public
static
String
getCellValueFormula
(
Cell
cell
,
FormulaEvaluator
formulaEvaluator
)
{
if
(
cell
==
null
||
formulaEvaluator
==
null
)
{
return
null
;
}
return
String
.
valueOf
(
formulaEvaluator
.
evaluate
(
cell
).
getNumberValue
());
}
public
static
Object
getCellValue
(
XSSFCell
cell
)
{
Object
val
=
""
;
if
(
cell
!=
null
)
{
if
(
cell
.
getCellType
()
==
Cell
.
CELL_TYPE_NUMERIC
)
{
DecimalFormat
df
=
new
DecimalFormat
();
val
=
df
.
format
(
cell
.
getNumericCellValue
());
}
else
if
(
cell
.
getCellType
()
==
Cell
.
CELL_TYPE_STRING
)
{
val
=
cell
.
getStringCellValue
();
}
else
if
(
cell
.
getCellType
()
==
Cell
.
CELL_TYPE_FORMULA
)
{
FormulaEvaluator
formulaEvaluator
=
new
XSSFFormulaEvaluator
((
XSSFWorkbook
)
cell
.
getRow
().
getSheet
().
getWorkbook
());;
val
=
getCellValueFormula
(
cell
,
formulaEvaluator
);
}
else
if
(
cell
.
getCellType
()
==
Cell
.
CELL_TYPE_BOOLEAN
)
{
val
=
cell
.
getBooleanCellValue
();
}
else
if
(
cell
.
getCellType
()
==
Cell
.
CELL_TYPE_ERROR
)
{
val
=
cell
.
getErrorCellValue
();
}
}
return
new
String
(
val
.
toString
()).
trim
();
}
}
Generator/genTable/src/main/java/com/winsun/tools/utils/ExcelTreeNodeHelper.java
0 → 100644
View file @
855da282
package
com
.
winsun
.
tools
.
utils
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.winsun.tools.data.TreeNodeData
;
import
com.winsun.tools.entity.TreeNode
;
import
org.apache.poi.ss.usermodel.*
;
import
org.apache.poi.ss.util.CellRangeAddress
;
import
org.apache.poi.xssf.usermodel.XSSFCell
;
import
org.apache.poi.xssf.usermodel.XSSFCellStyle
;
import
org.apache.poi.xssf.usermodel.XSSFFont
;
import
org.apache.poi.xssf.usermodel.XSSFRow
;
import
org.apache.poi.xssf.usermodel.XSSFSheet
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
/**
* 根据TreeNode生成Exccel表
*
* @author ZERO
*/
public
class
ExcelTreeNodeHelper
{
public
static
void
main
(
String
[]
args
)
{
TreeNode
treeNode
=
TreeNodeData
.
getData1
();
XSSFWorkbook
workbook
=
getWorkbook
(
treeNode
);
export
(
workbook
);
}
/**
* @param treeNode
* @return
*/
public
static
XSSFWorkbook
getWorkbook
(
TreeNode
treeNode
)
{
return
getWorkbook
(
treeNode
,
null
);
}
/**
* @param treeNode
* @param dataList
* @return
*/
public
static
XSSFWorkbook
getWorkbook
(
TreeNode
treeNode
,
List
dataList
)
{
XSSFWorkbook
workBook
=
new
XSSFWorkbook
();
// 创建工作本
Sheet
sheet
=
workBook
.
createSheet
(
"1"
);
// 创建工作表
sheet
.
setDefaultColumnWidth
(
10
);
int
max
=
treeNode
.
getMaxLevel
();
// 获取最大的层次 n-1
int
[]
arr
=
new
int
[
max
+
1
];
// n层
for
(
int
i
=
0
;
i
<
arr
.
length
;
i
++)
{
// 创建行
sheet
.
createRow
(
i
);
// 创建n行表头
arr
[
i
]
=
0
;
}
setTableHeader
(
treeNode
.
getChildList
(),
sheet
,
arr
);
XSSFCellStyle
style
=
workBook
.
createCellStyle
();
// 样式对象
style
.
setAlignment
(
HorizontalAlignment
.
CENTER
);
// 水平居中
style
.
setVerticalAlignment
(
VerticalAlignment
.
CENTER
);
// 垂直居中
XSSFFont
font
=
workBook
.
createFont
();
font
.
setFontName
(
"Arial"
);
style
.
setFont
(
font
);
if
(
dataList
==
null
||
dataList
.
size
()
==
0
)
{
return
workBook
;
}
System
.
out
.
println
(
"========================================"
);
List
keyList
=
treeNode
.
getKeyList
();
Iterator
it
=
dataList
.
iterator
();
for
(
int
i
=
max
+
1
;
it
.
hasNext
();
i
++)
{
Map
dataMap
=
(
Map
)
it
.
next
();
Iterator
it2
=
keyList
.
iterator
();
Row
row
=
sheet
.
createRow
(
i
);
for
(
int
j
=
0
;
it2
.
hasNext
();
j
++)
{
Object
obj
=
dataMap
.
get
(
it2
.
next
());
if
(
obj
!=
null
)
{
Cell
cell
=
row
.
createCell
(
j
);
style
.
setAlignment
(
HorizontalAlignment
.
CENTER
);
// 水平左对齐
cell
.
setCellStyle
(
style
);
if
(!
"null"
.
equals
(
String
.
valueOf
(
obj
)))
{
cell
.
setCellValue
(
String
.
valueOf
(
obj
));
}
else
{
cell
.
setCellValue
(
""
);
}
}
}
}
return
workBook
;
}
/**
* @param workBook
* @param treeNode
* @param sheetName
* @param sheetIndex
*/
public
static
void
createSheetData
(
XSSFWorkbook
workBook
,
TreeNode
treeNode
,
String
sheetName
,
int
sheetIndex
)
{
Sheet
sheet
=
workBook
.
createSheet
();
// 创建工作表
workBook
.
setSheetName
(
sheetIndex
,
sheetName
);
// TreeNode treeNode = TestTree.getTreeNode();
int
max
=
treeNode
.
getMaxLevel
();
// 获取最大的层次 n-1
int
[]
arr
=
new
int
[
max
+
1
];
// n层
for
(
int
i
=
0
;
i
<
arr
.
length
;
i
++)
{
// 创建行
sheet
.
createRow
(
i
);
// 创建n行表头
arr
[
i
]
=
0
;
}
setTableHeader
(
treeNode
.
getChildList
(),
sheet
,
arr
);
}
/**
* 利用递归遍历子数据,向excel填入excel表头
*
* @param childList
* @param sheet
* @param arr
*/
private
static
void
setTableHeader
(
List
<
TreeNode
>
childList
,
Sheet
sheet
,
int
[]
arr
)
{
for
(
TreeNode
node
:
childList
)
{
CellRangeAddress
cra
;
if
(
node
.
isLeaf
())
{
cra
=
new
CellRangeAddress
(
node
.
getLevel
(),
arr
.
length
-
1
,
arr
[
node
.
getLevel
()],
arr
[
node
.
getLevel
()]
+
node
.
getLeafSize
()
-
1
);
if
(
node
.
getLevel
()
!=
arr
.
length
-
1
)
{
for
(
int
i
=
node
.
getLevel
()
+
1
;
i
<
arr
.
length
;
i
++)
{
arr
[
i
]
+=
1
;
}
}
}
else
{
// 不是叶子节点
cra
=
new
CellRangeAddress
(
node
.
getLevel
(),
node
.
getLevel
(),
arr
[
node
.
getLevel
()],
arr
[
node
.
getLevel
()]
+
node
.
getLeafSize
()
-
1
);
}
if
(
cra
.
getFirstColumn
()
!=
cra
.
getLastColumn
()
||
cra
.
getFirstRow
()
!=
cra
.
getLastRow
())
{
sheet
.
addMergedRegion
(
cra
);
// 合并单元格
}
Row
row
=
sheet
.
getRow
(
node
.
getLevel
());
Cell
cell
=
row
.
createCell
(
arr
[
node
.
getLevel
()]);
XSSFCellStyle
cellStyle
=
(
XSSFCellStyle
)
sheet
.
getWorkbook
().
createCellStyle
();
// 设置自动换行以及居中样式
short
color
=
(
short
)
node
.
getColor
();
System
.
out
.
println
(
"color:"
+
color
);
if
(
color
!=
0
)
{
cellStyle
.
setFillForegroundColor
(
color
);
}
cellStyle
.
setWrapText
(
true
);
cellStyle
.
setAlignment
(
HorizontalAlignment
.
CENTER
);
// 水平居中
cellStyle
.
setVerticalAlignment
(
VerticalAlignment
.
CENTER
);
// 垂直居中
cell
.
setCellStyle
(
cellStyle
);
cell
.
setCellValue
(
node
.
getNodeName
());
arr
[
node
.
getLevel
()]
+=
node
.
getLeafSize
();
// 更新X轴指针位置
if
(!
node
.
isLeaf
())
{
setTableHeader
(
node
.
getChildList
(),
sheet
,
arr
);
}
}
}
/**
* 遍历子数据
*
* @param childList
* @param sheet
* @param arr
*/
public
static
void
showChildNode
(
List
<
TreeNode
>
childList
,
XSSFSheet
sheet
,
int
[]
arr
)
{
for
(
TreeNode
node
:
childList
)
{
CellRangeAddress
cra
;
if
(
node
.
isLeaf
())
{
cra
=
new
CellRangeAddress
(
node
.
getLevel
(),
arr
.
length
-
1
,
arr
[
node
.
getLevel
()],
arr
[
node
.
getLevel
()]
+
node
.
getLeafSize
()
-
1
);
if
(
node
.
getLevel
()
!=
arr
.
length
-
1
)
{
for
(
int
i
=
node
.
getLevel
()
+
1
;
i
<
arr
.
length
;
i
++)
{
arr
[
i
]
+=
1
;
}
}
}
else
{
//不是叶子节点
cra
=
new
CellRangeAddress
(
node
.
getLevel
(),
node
.
getLevel
(),
arr
[
node
.
getLevel
()],
arr
[
node
.
getLevel
()]
+
node
.
getLeafSize
()
-
1
);
}
if
(
cra
.
getFirstColumn
()
!=
cra
.
getLastColumn
()
||
cra
.
getFirstRow
()
!=
cra
.
getLastRow
())
{
sheet
.
addMergedRegion
(
cra
);
// 合并单元格
}
XSSFRow
row
=
sheet
.
getRow
(
node
.
getLevel
());
XSSFCell
cell
=
row
.
createCell
(
arr
[
node
.
getLevel
()]);
cell
.
setCellValue
(
node
.
getNodeName
());
XSSFCellStyle
cellStyle
=
(
XSSFCellStyle
)
sheet
.
getWorkbook
().
createCellStyle
();
cellStyle
.
setWrapText
(
true
);
cellStyle
.
setAlignment
(
HorizontalAlignment
.
CENTER
);
// 水平居中
cellStyle
.
setVerticalAlignment
(
VerticalAlignment
.
CENTER
);
// 垂直居中
cellStyle
.
setWrapText
(
true
);
//自动换行
cell
.
setCellStyle
(
cellStyle
);
arr
[
node
.
getLevel
()]
+=
node
.
getLeafSize
();
if
(
node
.
getChildList
()
!=
null
)
{
showChildNode
(
node
.
getChildList
(),
sheet
,
arr
);
}
}
}
/**
* @param workbook
*/
public
static
void
export
(
XSSFWorkbook
workbook
)
{
export
(
workbook
,
null
);
}
/**
* @param workbook
* @param name
*/
public
static
void
export
(
XSSFWorkbook
workbook
,
String
name
)
{
String
fileName
;
if
(
StrUtil
.
isBlank
(
name
))
{
fileName
=
"f:/poi1_test"
+
Math
.
round
(
Math
.
random
()
*
100
)
+
".xlsx"
;
}
else
{
fileName
=
"f:/"
+
name
+
".xlsx"
;
}
File
file
=
new
File
(
fileName
);
try
{
file
.
createNewFile
();
// 将Excel内容存盘
workbook
.
write
(
FileUtil
.
getOutputStream
(
file
));
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
System
.
out
.
println
(
"完成"
);
System
.
out
.
println
(
fileName
);
}
}
/**
* 列合并
*
* @param keys
* @param mergeKeys
* @param list
* @param workbook
* @param level
*/
public
static
void
mergeRow
(
List
<
String
>
keys
,
List
<
String
>
mergeKeys
,
List
<
Map
<
String
,
Object
>>
list
,
XSSFWorkbook
workbook
,
int
level
)
{
Sheet
sheet
=
workbook
.
getSheetAt
(
0
);
if
(
mergeKeys
==
null
||
mergeKeys
.
isEmpty
())
{
return
;
}
for
(
int
j
=
0
;
j
<
keys
.
size
();
j
++)
{
String
key
=
keys
.
get
(
j
);
if
(!
mergeKeys
.
contains
(
key
))
{
continue
;
}
mergeKeys
.
remove
(
key
);
int
start
=
0
;
int
end
=
0
;
int
temp
=
0
;
Map
<
String
,
Object
>
tempMap
=
list
.
get
(
temp
);
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
Map
m
=
list
.
get
(
i
);
if
(
tempMap
.
get
(
key
).
equals
(
m
.
get
(
key
)))
{
end
=
i
;
if
(
i
==
list
.
size
()
-
1
&&
end
-
start
>
0
)
{
CellRangeAddress
ca
=
new
CellRangeAddress
(
start
+
level
+
1
,
end
+
level
+
1
,
j
,
j
);
sheet
.
addMergedRegion
(
ca
);
// 合并单元格
}
}
else
{
if
(
end
-
start
>
0
)
{
CellRangeAddress
ca
=
new
CellRangeAddress
(
start
+
level
+
1
,
end
+
level
+
1
,
j
,
j
);
sheet
.
addMergedRegion
(
ca
);
// 合并单元格
}
tempMap
=
list
.
get
(
i
);
start
=
i
;
end
=
i
;
}
}
}
}
}
Generator/genTable/src/main/java/com/winsun/tools/utils/SQLHelper.java
0 → 100644
View file @
855da282
package
com
.
winsun
.
tools
.
utils
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
/**
* SQL语句拼接工具类
*
* @author 吕伟康
*
*/
public
class
SQLHelper
{
private
StringBuilder
selectClause
=
new
StringBuilder
(
64
);
private
StringBuilder
whereClause
=
new
StringBuilder
();
private
StringBuilder
orderByClause
=
new
StringBuilder
();
private
StringBuilder
fromClause
=
new
StringBuilder
();
private
StringBuilder
limitClause
=
new
StringBuilder
();
private
StringBuilder
joinClause
=
new
StringBuilder
();
private
StringBuilder
ortherClause
=
new
StringBuilder
();
private
List
params
;
private
StringBuilder
insertClause
;
private
StringBuilder
valuesClause
;
private
StringBuilder
updateClause
;
public
SQLHelper
(
String
table
,
String
alias
)
{
fromClause
.
append
(
table
).
append
(
" "
+
alias
+
" "
);
params
=
new
ArrayList
<>();
}
/**
* 用于多表查询 要符合一个String对一个别名
* 一般表连接查询写法
* @param object
*/
public
SQLHelper
(
String
...
object
)
{
if
(
object
.
length
%
2
==
0
){
for
(
int
num
=
0
;
num
<
object
.
length
;
num
+=
2
){
fromClause
.
append
(
object
[
num
]).
append
(
" "
+
object
[
num
+
1
]
+
" "
);
if
(
num
!=
object
.
length
-
2
){
fromClause
.
append
(
","
);
}
}
params
=
new
ArrayList
<>();
}
}
/**
* 拼接SELECT 语句
*
* @param
* @return
*/
public
SQLHelper
addSelect
(
String
...
columns
)
{
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
if
(
selectClause
.
length
()
==
0
)
{
selectClause
.
append
(
"SELECT "
).
append
(
columns
[
i
]);
}
else
{
selectClause
.
append
(
", "
).
append
(
columns
[
i
]);
}
}
return
this
;
}
/**
* 拼接Where子句,And
*
* @param
* @param
* @return
*/
public
SQLHelper
addCondition
(
String
condition
)
{
// 拼接
if
(
whereClause
.
length
()
==
0
)
{
whereClause
.
append
(
" WHERE "
).
append
(
condition
);
}
else
{
whereClause
.
append
(
" AND "
).
append
(
condition
);
}
return
this
;
}
/**
* 拼接Where子句,And
*
* @param condition
* @param
* @return
*/
public
SQLHelper
addCondition
(
String
condition
,
Object
...
obj
)
{
// 拼接
if
(
whereClause
.
length
()
==
0
)
{
whereClause
.
append
(
" WHERE "
).
append
(
condition
);
}
else
{
whereClause
.
append
(
" AND "
).
append
(
condition
);
}
if
(
obj
!=
null
)
{
Collections
.
addAll
(
params
,
obj
);
}
return
this
;
}
/**
* 拼接Where子句,Or
*
* @param
* @param
* @return
*/
@Deprecated
public
SQLHelper
addOrCondition
(
String
condition
)
{
// 拼接
if
(
whereClause
.
length
()
==
0
)
{
whereClause
.
append
(
"WHERE "
).
append
(
condition
);
}
else
{
whereClause
.
append
(
" Or "
).
append
(
condition
);
}
return
this
;
}
/**
* 如果第一个参数为true,则拼接Where子句
*
* @param append
* @param condition
* @param
*/
public
SQLHelper
addCondition
(
boolean
append
,
String
condition
)
{
if
(
append
)
{
addCondition
(
condition
);
}
return
this
;
}
/**
* 如果第一个参数为true,则拼接Where子句
*
* @param append
* @param condition
* @param
*/
public
SQLHelper
addCondition
(
boolean
append
,
String
condition
,
Object
...
obj
)
{
if
(
append
)
{
addCondition
(
condition
,
obj
);
}
return
this
;
}
/**
* 如果第一个参数为true,则拼接Where子句
*
* @param append
* @param condition
* @param
*/
@Deprecated
public
SQLHelper
addOrCondition
(
boolean
append
,
String
condition
)
{
if
(
append
)
{
addOrCondition
(
condition
);
}
return
this
;
}
/**
* 添加插入语句
* @param column
* @param value
* @return
*/
public
SQLHelper
addInsertClause
(
boolean
flag
,
String
column
,
String
value
,
Object
obj
)
{
if
(
flag
){
addInsertClause
(
column
,
value
);
params
.
add
(
obj
);
}
return
this
;
}
/**
* 添加插入语句
* @param column
* @param value
* @return
*/
public
SQLHelper
addInsertClause
(
String
column
,
String
value
,
Object
obj
)
{
addInsertClause
(
column
,
value
);
params
.
add
(
obj
);
return
this
;
}
/**
* 添加插入语句
* @param column
* @param value
* @return
*/
public
SQLHelper
addInsertClause
(
String
column
,
String
value
)
{
if
(
insertClause
==
null
)
{
insertClause
=
new
StringBuilder
();
insertClause
.
append
(
column
);
}
else
{
insertClause
.
append
(
","
+
column
);
}
if
(
valuesClause
==
null
)
{
valuesClause
=
new
StringBuilder
();
valuesClause
.
append
(
value
);
}
else
{
valuesClause
.
append
(
","
+
value
);
}
return
this
;
}
/**
* 添加插入语句,可根据条件选择是否添加
* @param append
* @param column
* @param value
* @return
*/
public
SQLHelper
addInsertClause
(
Boolean
append
,
String
column
,
String
value
)
{
if
(
append
)
{
addInsertClause
(
column
,
value
);
}
return
this
;
}
/**
* 如果第一个参数为true,则拼接Limit子句
*
* @param append
* @param pageSize
* @param pageNumber
* @return
*/
public
SQLHelper
addLimitProperty
(
boolean
append
,
int
pageNumber
,
int
pageSize
)
{
if
(
append
&&
limitClause
.
length
()
==
0
)
{
addLimitProperty
(
pageNumber
,
pageSize
);
}
return
this
;
}
/**
* 添加更新信息
*
* @return
*/
public
SQLHelper
addUpdateClause
(
String
column
,
String
value
,
Object
obj
)
{
addUpdateClause
(
column
,
value
);
params
.
add
(
obj
);
return
this
;
}
/**
* 添加更新信息
*
* @return
*/
public
SQLHelper
addUpdateClause
(
boolean
flag
,
String
column
,
String
value
,
Object
obj
)
{
if
(
flag
){
addUpdateClause
(
column
,
value
);
params
.
add
(
obj
);
}
return
this
;
}
/**
* 添加更新信息
*
* @return
*/
public
SQLHelper
addUpdateClause
(
String
column
,
String
value
)
{
if
(
updateClause
==
null
)
{
updateClause
=
new
StringBuilder
();
updateClause
.
append
(
column
).
append
(
"="
).
append
(
value
);
}
else
{
updateClause
.
append
(
","
).
append
(
column
).
append
(
"="
).
append
(
value
);
}
return
this
;
}
/**
* 添加更新信息,添加条件判断
* @param append
* @param column
* @param value
* @return
*/
public
SQLHelper
addUpdateClause
(
Boolean
append
,
String
column
,
String
value
)
{
if
(
append
)
{
addUpdateClause
(
column
,
value
);
}
return
this
;
}
/**
* 添加内(左右)接查询
*
* @param sql
* @return
*/
public
SQLHelper
addJoinClauses
(
String
sql
)
{
joinClause
.
append
(
sql
).
append
(
" "
);
return
this
;
}
/**
* 添加内(左右)接查询,添加条件判断
* @param flag
* @param sql
* @return
*/
public
SQLHelper
addJoinClauses
(
boolean
flag
,
String
sql
)
{
if
(
flag
)
addJoinClauses
(
sql
);
return
this
;
}
/**
* 添加其它的语句,例如:GROUP BY / HAVING
* 注意看看获取方法中它们的位置
*
* @param sql
* @return
*/
public
SQLHelper
addOrtherClauseBeforeOrderBy
(
String
sql
)
{
ortherClause
.
append
(
" "
).
append
(
sql
);
return
this
;
}
/**
* 拼接OrderBy子句
*
* @param propertyName
* 参与排序的属性名
* @param asc
* true表示升序,false表示降序
*/
public
SQLHelper
addOrderProperty
(
String
propertyName
,
boolean
asc
)
{
if
(
orderByClause
.
length
()
==
0
)
{
orderByClause
.
append
(
" ORDER BY "
).
append
(
propertyName
)
.
append
(
asc
?
" ASC"
:
" DESC"
);
}
else
{
orderByClause
.
append
(
", "
+
propertyName
).
append
(
asc
?
" ASC"
:
" DESC"
);
}
return
this
;
}
/**
* 如果第一个参数为true,则拼接OrderBy子句
*
* @param append
* @param propertyName
* @param asc
*/
public
SQLHelper
addOrderProperty
(
boolean
append
,
String
propertyName
,
boolean
asc
)
{
if
(
append
)
{
addOrderProperty
(
propertyName
,
asc
);
}
return
this
;
}
/**
* 拼接分页信息
*
* @param pageSize
* @param pageNumber
* @return
*/
public
SQLHelper
addLimitProperty
(
int
pageNumber
,
int
pageSize
)
{
limitClause
=
new
StringBuilder
();
limitClause
.
append
(
" LIMIT "
+
pageNumber
+
", "
+
pageSize
);
return
this
;
}
/**
* 获取生成的用于查询数据列表的SQL语句
*
* @return
*/
public
String
getListQuerySQL
()
{
return
selectClause
.
toString
()
+
" FROM "
+
fromClause
.
toString
()
+
joinClause
.
toString
()
+
whereClause
.
toString
()
+
ortherClause
.
toString
()
+
orderByClause
.
toString
()
+
limitClause
.
toString
();
}
/**
* 获取删除的SQL语句
*
* @return
*/
public
String
getDeleteSQL
()
{
return
"DELETE FROM "
+
fromClause
.
toString
()
+
whereClause
.
toString
();
}
/**
* 更新插入语句互换
* @return
*/
@Deprecated
public
SQLHelper
exchangeUpdateAndInsert
(){
if
(
updateClause
!=
null
){
//更新语句转插入语句
String
str
=
updateClause
.
toString
();
String
[]
element
=
str
.
split
(
","
);
for
(
int
i
=
0
,
l
=
element
.
length
;
i
<
l
;
i
++){
String
[]
ele
=
element
[
i
].
split
(
"="
);
if
(
ele
.
length
==
2
)
addInsertClause
(
ele
[
0
],
ele
[
1
]);
}
}
else
if
(
insertClause
!=
null
&&
valuesClause
!=
null
){
//插入语句转更新语句
String
[]
inserts
=
insertClause
.
toString
().
split
(
","
);
String
[]
values
=
valuesClause
.
toString
().
split
(
","
);
for
(
int
i
=
0
,
l
=
inserts
.
length
;
i
<
l
;
i
++){
addUpdateClause
(
inserts
[
i
],
values
[
i
]);
}
}
return
this
;
}
/**
* 获取insert into 的SQL语句
*
* @return
*/
public
String
getInsertSQL
()
{
return
"INSERT INTO "
+
fromClause
.
toString
()
+
"("
+
insertClause
.
toString
()
+
")"
+
" VALUES("
+
valuesClause
.
toString
()
+
")"
;
}
/**
* 获取update set 的SQL语句
* @return
*/
public
String
getUpdateSQL
()
{
return
"UPDATE "
+
fromClause
.
toString
()
+
"SET "
+
updateClause
.
toString
()
+
whereClause
.
toString
();
}
/**
* 获取insert select from的SQL语句
*
* @return
*/
public
String
getInsertSelectSQL
()
{
return
"INSERT INTO "
+
fromClause
.
toString
()
+
"("
+
insertClause
.
toString
()
+
")"
+
" SELECT "
+
valuesClause
.
toString
()
+
" FROM DUAL WHERE NOT EXISTS "
+
"(SELECT "
+
insertClause
.
toString
()+
" FROM "
+
fromClause
.
toString
()+
""
+
" "
+
whereClause
.
toString
()+
")"
;
}
/**
* 获取insert select from的SQL语句
*
* @return
*/
public
String
getInsertSelectSimpleSQL
(
String
dataTable
)
{
return
"INSERT INTO "
+
fromClause
.
toString
()
+
"("
+
insertClause
.
toString
()
+
")"
+
" SELECT "
+
valuesClause
.
toString
()
+
" FROM "
+
dataTable
+
" "
+
whereClause
.
toString
();
}
/**
* 获取生成的用于查询总记录数的SQL语句
*
* @return
*/
public
String
getCountQuerySQL
()
{
return
" SELECT COUNT(*) FROM ( "
+
this
.
getListQuerySQL
()
+
" )"
;
}
/**
* Oracle的分页方式
* @param pageNo 从1开始计数
* @param pageSize
* @return
*/
public
String
getListQuerySQLWithPageOracle
(
int
pageNo
,
int
pageSize
)
{
int
startRow
=
(
pageNo
-
1
)*
pageSize
,
endRow
=
pageNo
*
pageSize
;
if
(
startRow
==
0
)
{
return
"select row_.* from ("
+
this
.
getListQuerySQL
()
+
") row_ where rownum <= "
+
endRow
;
}
else
{
return
"select * from ( select row_.*, rownum rownum_ from ("
+
this
.
getListQuerySQL
()
+
") row_ where rownum <= "
+
endRow
+
") where rownum_ > "
+
startRow
;
}
}
public
Object
[]
getObjectParams
()
{
Object
[]
objs
=
new
Object
[
params
.
size
()];
for
(
int
i
=
0
;
i
<
params
.
size
();
i
++){
objs
[
i
]
=
params
.
get
(
i
);
}
return
objs
;
}
public
StringBuilder
getFromClause
()
{
return
fromClause
;
}
public
void
setFromClause
(
StringBuilder
fromClause
)
{
this
.
fromClause
=
fromClause
;
}
public
StringBuilder
getInsertClause
()
{
return
insertClause
;
}
public
void
setInsertClause
(
StringBuilder
insertClause
)
{
this
.
insertClause
=
insertClause
;
}
public
StringBuilder
getValuesClause
()
{
return
valuesClause
;
}
public
void
setValuesClause
(
StringBuilder
valuesClause
)
{
this
.
valuesClause
=
valuesClause
;
}
}
Generator/genTable/src/main/java/com/winsun/tools/utils/THeadJsonUtils.java
0 → 100644
View file @
855da282
package
com
.
winsun
.
tools
.
utils
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.json.JSONArray
;
import
com.winsun.tools.entity.TreeNode
;
import
com.winsun.tools.entity.TreeNodeSql
;
import
java.io.BufferedOutputStream
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.util.ArrayList
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
/**
* 报表头HTML代码生成
*
* @author 吕伟康
* @date 2018年4月13日下午2:26:45
*/
public
class
THeadJsonUtils
{
public
static
void
main
(
String
[]
args
)
{
// TreeNode treeNode = TreeNodeData.getData1();
// writeLayuiJsonResult(treeNode);
// readData();
writeAppJsonResult
(
initData
());
}
/**
* 输出layui的json结构
* @param treeNode
*/
public
static
void
writeLayuiJsonResult
(
TreeNode
treeNode
)
{
int
max
=
treeNode
.
getMaxLevel
();
// 获取最大的层次 n-1
int
[]
arr
=
new
int
[
max
+
1
];
// n层
for
(
int
i
=
0
;
i
<
arr
.
length
;
i
++)
{
// 创建行
arr
[
i
]
=
0
;
}
List
<
String
>
htmlList
=
new
ArrayList
<>();
Map
<
String
,
List
<
String
>>
map
=
new
LinkedHashMap
<>();
map
=
getColumnList
(
treeNode
,
max
);
htmlList
.
add
(
"["
);
//输出每个级别的表头
for
(
Entry
<
String
,
List
<
String
>>
s
:
map
.
entrySet
())
{
htmlList
.
add
(
"["
);
htmlList
.
addAll
(
s
.
getValue
());
htmlList
.
add
(
"],"
);
}
htmlList
.
add
(
"]"
);
int
size
=
htmlList
.
size
();
String
lastStr
=
htmlList
.
get
(
size
-
1
);
htmlList
.
set
(
size
-
1
,
lastStr
.
substring
(
0
,
lastStr
.
length
()
-
1
));
displayList
(
htmlList
);
System
.
out
.
println
(
"--------将html表头输出到html.txt-----------"
);
//writeToTxt(htmlList);
}
/**
* 解析表头行于列
*
* @param treeNodes
* @param max
* @return
*/
public
static
Map
<
String
,
List
<
String
>>
getColumnList
(
TreeNode
treeNodes
,
int
max
)
{
List
<
String
>
keyList
=
new
ArrayList
<
String
>();
Map
<
String
,
List
<
String
>>
map
=
new
LinkedHashMap
<>();
List
<
TreeNode
>
nodeList
=
treeNodes
.
getJuniors
();
int
count
=
0
;
for
(
int
i
=
0
,
s
=
nodeList
.
size
();
i
<
s
;
i
++)
{
TreeNode
treeNode
=
nodeList
.
get
(
i
);
String
key
=
treeNode
.
getKey
();
int
leafSize
=
treeNode
.
getLeafSize
();
int
level
=
treeNode
.
getLevel
();
String
name
=
treeNode
.
getNodeName
();
List
thList
=
map
.
get
(
""
+
level
);
if
(
thList
==
null
)
{
thList
=
new
ArrayList
<>();
map
.
put
(
""
+
level
,
thList
);
}
boolean
isLeaf
=
treeNode
.
isLeaf
();
//开始拼接
StringBuilder
sBuilder
=
new
StringBuilder
();
sBuilder
.
append
(
"\t { "
);
//表头
sBuilder
.
append
(
"'title' : '"
+
name
+
"' "
);
if
(
StrUtil
.
isNotBlank
(
key
))
{
//赋值
sBuilder
.
append
(
", 'field' : '"
+
key
+
"'"
);
}
//其它属性
//列合并
if
(
leafSize
!=
1
)
{
sBuilder
.
append
(
", 'colspan' : "
+
leafSize
+
" "
);
}
//行合并
if
(
level
!=
max
&&
leafSize
==
1
&&
isLeaf
)
{
sBuilder
.
append
(
", 'rowspan' : "
+
(
max
-
level
+
1
)
+
" "
);
}
sBuilder
.
append
(
", 'align' : 'center'"
);
sBuilder
.
append
(
"},"
);
thList
.
add
(
sBuilder
.
toString
());
}
for
(
Entry
<
String
,
List
<
String
>>
s
:
map
.
entrySet
())
{
List
<
String
>
list
=
s
.
getValue
();
int
size
=
list
.
size
();
String
lastStr
=
list
.
get
(
size
-
1
);
list
.
set
(
size
-
1
,
lastStr
.
substring
(
0
,
lastStr
.
length
()
-
1
));
}
return
map
;
}
/**
* 打印list
*
* @param list
*/
public
static
void
displayList
(
List
list
)
{
for
(
Object
obj
:
list
)
{
System
.
out
.
println
(
obj
);
}
}
public
static
void
writeToTxt
(
List
<
String
>
list
)
{
writeToTxt
(
list
,
null
);
}
public
static
void
writeToTxt
(
List
<
String
>
list
,
String
fileName
)
{
FileOutputStream
outSTr
=
null
;
BufferedOutputStream
Buff
=
null
;
String
path
=
"f://txt_"
+
Math
.
round
(
Math
.
random
()
*
1000
)
+
".txt"
;
if
(
StrUtil
.
isNotBlank
(
fileName
))
{
path
=
fileName
;
//全路径
}
String
tab
=
""
;
String
enter
=
"\r\n"
;
String
content
=
""
;
StringBuffer
write
;
try
{
outSTr
=
new
FileOutputStream
(
new
File
(
path
));
Buff
=
new
BufferedOutputStream
(
outSTr
);
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
Object
obj
=
list
.
get
(
i
);
content
=
obj
.
toString
();
write
=
new
StringBuffer
();
write
.
append
(
content
).
append
(
tab
).
append
(
enter
);
Buff
.
write
(
write
.
toString
().
getBytes
(
"UTF-8"
));
}
Buff
.
flush
();
Buff
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
Buff
.
close
();
outSTr
.
close
();
System
.
out
.
println
(
"finished..."
);
System
.
out
.
println
(
path
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
/**
* 初始化数据,集成到项目中可使用读数据库的方式
* @return
*/
public
static
List
<
TreeNodeSql
>
initData
(){
String
filePath
=
"F:\\项目资料\\实时战报\\社区运营平台\\02 社区智慧运营平台\\02需求开发\\三期\\社区派单报表\\表头.xlsx"
;
//createCode(filePath, 5);
List
<
TreeNodeSql
>
list
=
TreeNodeDataCreator
.
getTreeNodeByExcel
(
filePath
,
6
);
return
list
;
}
/**
* 根据数据源读取,进行json输出
*/
public
static
void
readData
(
List
<
TreeNodeSql
>
list
){
List
<
TreeNode
>
treeNodeList
=
new
ArrayList
<>(
list
.
size
());
TreeNode
treeNode
=
new
TreeNode
(-
1
,
""
,
null
);
//初始化头
treeNodeList
.
add
(
treeNode
);
for
(
TreeNodeSql
sql
:
list
){
TreeNode
treeNode0
=
new
TreeNode
(
sql
.
getIndex
(),
sql
.
getName
(),
treeNodeList
.
get
(
sql
.
getParentIndex
()+
1
));
if
(
StrUtil
.
isNotBlank
(
sql
.
getKey
())){
treeNode0
.
setKey
(
sql
.
getKey
());
}
treeNodeList
.
add
(
treeNode0
);
}
treeNode
.
calLeavesAmount
(
treeNode
);
treeNode
.
calNodeLevel
(
treeNode
);
writeLayuiJsonResult
(
treeNode
);
}
public
static
void
writeAppJsonResult
(
List
<
TreeNodeSql
>
list
){
Map
<
String
,
Map
<
String
,
Object
>>
targetMap
=
new
LinkedHashMap
<>();
List
<
Map
>
topList
=
new
ArrayList
<>();
for
(
TreeNodeSql
nodeSql
:
list
){
int
index
=
nodeSql
.
getIndex
();
Map
<
String
,
Object
>
map
=
new
LinkedHashMap
<>();
map
.
put
(
"title"
,
nodeSql
.
getName
());
map
.
put
(
"align"
,
"center"
);
if
(
StrUtil
.
isNotBlank
(
nodeSql
.
getKey
())){
map
.
put
(
"field"
,
nodeSql
.
getKey
());
}
int
pIndex
=
nodeSql
.
getParentIndex
();
if
(
pIndex
!=
-
1
){
Map
<
String
,
Object
>
paranetMap
=
targetMap
.
get
(
pIndex
+
""
);
List
<
Map
<
String
,
Object
>>
children
=
(
List
<
Map
<
String
,
Object
>>)
paranetMap
.
get
(
"children"
);
if
(
children
==
null
){
children
=
new
ArrayList
<>();
paranetMap
.
put
(
"children"
,
children
);
}
children
.
add
(
map
);
}
else
{
topList
.
add
(
map
);
}
targetMap
.
put
(
index
+
""
,
map
);
}
JSONArray
array
=
new
JSONArray
(
topList
);
System
.
out
.
println
(
array
.
toString
());
System
.
out
.
println
(
"--------将html表头输出到html.txt-----------"
);
List
<
String
>
l
=
new
ArrayList
<
String
>();
l
.
add
(
array
.
toString
());
writeToTxt
(
l
);
}
}
Generator/genTable/src/main/java/com/winsun/tools/utils/THeadUtils.java
0 → 100644
View file @
855da282
package
com
.
winsun
.
tools
.
utils
;
import
java.io.BufferedOutputStream
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.util.ArrayList
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
cn.hutool.core.util.StrUtil
;
import
com.winsun.tools.data.TreeNodeData
;
import
com.winsun.tools.entity.TreeNode
;
import
org.junit.Test
;
/**
* 报表头HTML代码生成
* @author 吕伟康
* @date 2018年4月13日下午2:26:45
*/
public
class
THeadUtils
{
@Test
public
void
test2
(){
TreeNode
treeNode
=
TreeNodeData
.
getData1
();
int
max
=
treeNode
.
getMaxLevel
();
// 获取最大的层次 n-1
int
[]
arr
=
new
int
[
max
+
1
];
// n层
for
(
int
i
=
0
;
i
<
arr
.
length
;
i
++)
{
// 创建行
arr
[
i
]
=
0
;
}
List
<
String
>
htmlList
=
new
ArrayList
<>();
Map
<
String
,
List
<
String
>>
map
=
new
LinkedHashMap
<>();
map
=
getKeyList
(
treeNode
,
max
);
for
(
Entry
<
String
,
List
<
String
>>
s
:
map
.
entrySet
()){
System
.
out
.
println
(
"<tr class=\"tabTh\">"
);
displayList
(
s
.
getValue
());
System
.
out
.
println
(
"</tr>"
);
htmlList
.
add
(
"<tr class=\"tabTh\">"
);
htmlList
.
addAll
(
s
.
getValue
());
htmlList
.
add
(
"</tr>"
);
}
System
.
out
.
println
(
"--------将html表头输出到html.txt-----------"
);
writeToTxt
(
htmlList
);
}
public
Map
<
String
,
List
<
String
>>
getKeyList
(
TreeNode
treeNodes
,
int
max
){
List
<
String
>
keyList
=
new
ArrayList
<
String
>();
Map
<
String
,
List
<
String
>>
map
=
new
LinkedHashMap
<>();
List
<
TreeNode
>
nodeList
=
treeNodes
.
getJuniors
();
int
count
=
0
;
for
(
int
i
=
0
,
s
=
nodeList
.
size
()
;
i
<
s
;
i
++){
TreeNode
treeNode
=
nodeList
.
get
(
i
);
String
key
=
treeNode
.
getKey
();
int
leafSize
=
treeNode
.
getLeafSize
();
int
level
=
treeNode
.
getLevel
();
String
name
=
treeNode
.
getNodeName
();
List
thList
=
map
.
get
(
""
+
level
);
if
(
thList
==
null
){
thList
=
new
ArrayList
<>();
map
.
put
(
""
+
level
,
thList
);
}
boolean
isLeaf
=
treeNode
.
isLeaf
();
StringBuilder
sBuilder
=
new
StringBuilder
();
sBuilder
.
append
(
"\t<td class=\"tabTh\" "
);
//其它属性
//列合并
if
(
leafSize
!=
1
)
{
sBuilder
.
append
(
"colspan='"
+
leafSize
+
"' "
);
}
//行合并
if
(
level
!=
max
&&
leafSize
==
1
&&
isLeaf
){
sBuilder
.
append
(
"rowspan='"
+(
max
-
level
+
1
)+
"' "
);
}
if
(
StrUtil
.
isNotBlank
(
key
)){
sBuilder
.
append
(
"value = '"
+
key
+
"' "
);
sBuilder
.
append
(
"key = '"
+
count
++
+
"'"
);
}
sBuilder
.
append
(
"\n\t\tstyle=\"word-wrap: break-word; white-space: nowrap; text-align: center; vertical-align: middle;\" "
);
sBuilder
.
append
(
">"
)
.
append
(
name
)
.
append
(
"</td>"
);
thList
.
add
(
sBuilder
.
toString
());
}
return
map
;
}
/**
* 打印list
* @param list
*/
public
static
void
displayList
(
List
list
)
{
for
(
Object
obj
:
list
)
{
System
.
out
.
println
(
obj
);
}
}
public
void
writeToTxt
(
List
<
String
>
list
)
{
writeToTxt
(
list
,
null
);
}
public
void
writeToTxt
(
List
<
String
>
list
,
String
fileName
)
{
FileOutputStream
outSTr
=
null
;
BufferedOutputStream
Buff
=
null
;
String
path
=
"f://txt_"
+
Math
.
round
(
Math
.
random
()*
1000
)+
".txt"
;
if
(
StrUtil
.
isNotBlank
(
fileName
))
{
path
=
fileName
;
//全路径
}
String
tab
=
""
;
String
enter
=
"\r\n"
;
String
content
=
""
;
StringBuffer
write
;
try
{
outSTr
=
new
FileOutputStream
(
new
File
(
path
));
Buff
=
new
BufferedOutputStream
(
outSTr
);
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
Object
obj
=
list
.
get
(
i
);
content
=
obj
.
toString
();
write
=
new
StringBuffer
();
write
.
append
(
content
).
append
(
tab
).
append
(
enter
);
Buff
.
write
(
write
.
toString
().
getBytes
(
"UTF-8"
));
}
Buff
.
flush
();
Buff
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
Buff
.
close
();
outSTr
.
close
();
System
.
out
.
println
(
"finished..."
);
System
.
out
.
println
(
path
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
}
Generator/genTable/src/main/java/com/winsun/tools/utils/TreeNodeDataCreator.java
0 → 100644
View file @
855da282
package
com
.
winsun
.
tools
.
utils
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.LinkedHashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
cn.hutool.core.io.FileUtil
;
import
com.winsun.tools.entity.TreeNode
;
import
com.winsun.tools.entity.TreeNodeReComplie
;
import
com.winsun.tools.entity.TreeNodeSql
;
import
org.apache.poi.xssf.usermodel.*
;
public
class
TreeNodeDataCreator
{
/**
* 控制台输出结果
*
* @param filePath 文件路径
*/
public
static
void
createCode
(
String
filePath
)
{
createCode
(
filePath
,
0
);
}
/**
* 控制台输出结果
*
* @param filePath 文件路径
* @param sheetIndex sheet下标
*/
public
static
void
createCode
(
String
filePath
,
int
sheetIndex
)
{
File
file
=
new
File
(
filePath
);
// "G:/项目资料/客户画像/111.xls"
try
{
// 创建Excel,读取文件内容
XSSFWorkbook
workbook
=
new
XSSFWorkbook
(
FileUtil
.
getInputStream
(
filePath
));
// 读取默认第一个工作表sheet
XSSFSheet
sheet
=
workbook
.
getSheetAt
(
sheetIndex
);
int
firstRowNum
=
0
;
List
<
String
>
javaList
=
new
ArrayList
<
String
>();
// 获取sheet中最后一行行号
int
lastRowNum
=
sheet
.
getLastRowNum
();
int
total
=
0
;
List
<
TreeNodeReComplie
>
dataList
=
new
LinkedList
<>();
Map
<
String
,
TreeNodeReComplie
>
map
=
new
LinkedHashMap
<>();
System
.
out
.
println
(
"TreeNode treeNode = new TreeNode(-1, \"\", null);"
);
for
(
int
i
=
firstRowNum
;
i
<=
lastRowNum
;
i
++)
{
XSSFRow
row
=
sheet
.
getRow
(
i
);
// 获取当前行最后单元格列号
int
lastCellNum
=
row
.
getLastCellNum
();
for
(
int
j
=
0
;
j
<
lastCellNum
;
j
++)
{
XSSFCell
cell
=
row
.
getCell
(
j
);
if
(
cell
==
null
)
{
continue
;
}
String
value
=
ExcelCellUtils
.
getCellValue
(
cell
).
toString
();
if
(
value
.
equals
(
""
))
{
continue
;
}
TreeNodeReComplie
treeNodeReComplie
=
new
TreeNodeReComplie
(
total
,
value
);
if
(
i
!=
firstRowNum
)
{
XSSFRow
row0
=
sheet
.
getRow
(
i
-
1
);
XSSFCell
cell0
=
row0
.
getCell
(
j
);
if
(
cell0
==
null
)
{
treeNodeReComplie
.
setParent
(
dataList
.
get
(
total
-
1
).
getParent
());
}
else
{
String
value0
=
ExcelCellUtils
.
getCellValue
(
cell0
).
toString
();
if
(
value0
.
equals
(
""
))
{
treeNodeReComplie
.
setParent
(
dataList
.
get
(
total
-
1
).
getParent
());
}
else
{
treeNodeReComplie
.
setParent
(
map
.
get
(
value0
+
(
i
-
1
)
+
""
+
j
));
}
}
}
else
{
treeNodeReComplie
.
setParent
(
new
TreeNodeReComplie
(
"treeNode"
));
}
map
.
put
(
value
+
i
+
""
+
j
,
treeNodeReComplie
);
dataList
.
add
(
treeNodeReComplie
);
total
++;
System
.
out
.
println
(
treeNodeReComplie
.
getJavaCode
());
}
}
System
.
out
.
println
(
"treeNode.calLeavesAmount(treeNode);"
);
System
.
out
.
println
(
"treeNode.calNodeLevel(treeNode);"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
public
static
void
main
(
String
[]
args
)
{
// String filePath = "F:\\项目资料\\实时战报\\社区运营平台\\02 社区智慧运营平台\\02需求开发\\三期\\社区派单报表\\表头.xlsx";
String
filePath
=
"E:\\Documents\\WeChat Files\\WeChat Files\\zero13168599099\\FileStorage\\File\\2020-05\\表头(3)(1)(1).xlsx"
;
// createCode(filePath, 0);
List
<
TreeNodeSql
>
list
=
getTreeNodeByExcel
(
filePath
,
0
);
for
(
TreeNodeSql
sql
:
list
){
System
.
out
.
println
(
sql
.
toSql
(
"tableConfig"
,
"name"
));
}
}
/**
* 动态获取treeNode类
*
* @param filePath
* @return
*/
public
static
List
<
TreeNodeSql
>
getTreeNodeByExcel
(
String
filePath
)
{
return
getTreeNodeByExcel
(
filePath
,
0
);
}
/**
* 动态获取treeNode类
*
* @param filePath
* @param sheetIndex
* @return
*/
public
static
List
<
TreeNodeSql
>
getTreeNodeByExcel
(
String
filePath
,
int
sheetIndex
)
{
File
file
=
new
File
(
filePath
);
// "G:/项目资料/客户画像/111.xls"
try
{
// 创建Excel,读取文件内容
XSSFWorkbook
workbook
=
new
XSSFWorkbook
(
FileUtil
.
getInputStream
(
filePath
));
// 读取默认第一个工作表sheet
XSSFSheet
sheet
=
workbook
.
getSheetAt
(
sheetIndex
);
int
firstRowNum
=
0
;
List
<
String
>
javaList
=
new
ArrayList
<
String
>();
// 获取sheet中最后一行行号
int
lastRowNum
=
sheet
.
getLastRowNum
();
int
total
=
0
;
List
<
TreeNodeReComplie
>
dataList
=
new
LinkedList
<>();
Map
<
String
,
TreeNodeReComplie
>
map
=
new
LinkedHashMap
<>();
TreeNode
treeNode
=
new
TreeNode
(-
1
,
""
,
null
);
List
<
TreeNodeSql
>
nodeSqlList
=
new
LinkedList
<>();
for
(
int
i
=
firstRowNum
;
i
<=
lastRowNum
;
i
++)
{
XSSFRow
row
=
sheet
.
getRow
(
i
);
// 获取当前行最后单元格列号
int
lastCellNum
=
row
.
getLastCellNum
();
for
(
int
j
=
0
;
j
<
lastCellNum
;
j
++)
{
XSSFCell
cell
=
row
.
getCell
(
j
);
if
(
cell
==
null
)
{
continue
;
}
String
value
=
ExcelCellUtils
.
getCellValue
(
cell
).
toString
();
if
(
value
.
equals
(
""
))
{
continue
;
}
TreeNodeReComplie
treeNodeReComplie
=
new
TreeNodeReComplie
(
total
,
value
);
if
(
i
!=
firstRowNum
)
{
XSSFRow
row0
=
sheet
.
getRow
(
i
-
1
);
XSSFCell
cell0
=
row0
.
getCell
(
j
);
if
(
cell0
==
null
)
{
treeNodeReComplie
.
setParent
(
dataList
.
get
(
total
-
1
).
getParent
());
}
else
{
String
value0
=
ExcelCellUtils
.
getCellValue
(
cell0
).
toString
();
if
(
value0
.
equals
(
""
))
{
treeNodeReComplie
.
setParent
(
dataList
.
get
(
total
-
1
).
getParent
());
}
else
{
treeNodeReComplie
.
setParent
(
map
.
get
(
value0
+
(
i
-
1
)
+
""
+
j
));
}
}
}
else
{
treeNodeReComplie
.
setParent
(
new
TreeNodeReComplie
(
"treeNode"
));
}
map
.
put
(
value
+
i
+
""
+
j
,
treeNodeReComplie
);
dataList
.
add
(
treeNodeReComplie
);
nodeSqlList
.
add
(
treeNodeReComplie
.
getTreeNodeSql
());
total
++;
System
.
out
.
println
(
treeNodeReComplie
.
getTreeNodeSql
());
}
}
return
nodeSqlList
;
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
}
Generator/genTable/src/main/resources/WEND.txt
0 → 100644
View file @
855da282
[
[
{title: '序号',rowspan: 2, align: 'center', type: 'numbers'},
{
field: 'subst',width: 100,rowspan: 2, title: '县分', align: 'center'
},
{field: 'batch_num',width: 120,rowspan: 2, title: '批次号',align: 'center'},
{field: 'fname', rowspan: 2,width: 120,title: '业务/活动名称',align: 'center'},
{field: 'task_type',rowspan: 2,width: 70, title: '渠道',align: 'center'},
{
field: 'send',width: 80, rowspan: 2,title: '派单数', align: 'center', templet: function (d) {
return '<div><a href="javascript:void(1);" onclick="openQd(\''+ d.batch_num + '\',\''+ d.task_type + '\',\'' + d.fname + '\',1,\'' + d.subst + '\')">' + d.send + '</a></div>';
}
},
{
field: 'deal',width: 80,rowspan: 2, title: '接单数', align: 'center', templet: function (d) {
return '<div><a href="javascript:void(1);" onclick="openQd(\''+ d.batch_num + '\',\''+ d.task_type + '\',\'' + d.fname + '\',1,\'' + d.subst + '\',\'' + this.field + '\')">' + d.deal + '</a></div>';
}
},
{field: 'confirm',width: 120,rowspan: 2, title: '确认为本人负责客户',align: 'center', templet: function (d) {
return '<div><a href="javascript:void(1);" onclick="openQd(\''+ d.batch_num + '\',\''+ d.task_type + '\',\'' + d.fname + '\',1,\'' + d.subst + '\',\'' + this.field+ '\')">' + d.confirm + '</a></div>';
}},
{field: 'lose',width: 120, rowspan: 2,title: '存在流失风险',align: 'center', templet: function (d) {
return '<div><a href="javascript:void(1);" onclick="openQd(\''+ d.batch_num + '\',\''+ d.task_type + '\',\'' + d.fname + '\',1,\'' + d.subst + '\',\'' + this.field + '\')">' + d.lose + '</a></div>';
}},
{field: 'complete',width: 120,rowspan: 2, title: '已完成方案制定',align: 'center', templet: function (d) {
return '<div><a href="javascript:void(1);" onclick="openQd(\''+ d.batch_num + '\',\''+ d.task_type + '\',\'' + d.fname + '\',1,\'' + d.subst + '\',\'' + this.field + '\')">' + d.complete + '</a></div>';
}},
{field: 'visited',width: 120,rowspan: 2, title: '已上门拜访',align: 'center', templet: function (d) {
return '<div><a href="javascript:void(1);" onclick="openQd(\''+ d.batch_num + '\',\''+ d.task_type + '\',\'' + d.fname + '\',1,\'' + d.subst + '\',\'' + this.field + '\')">' + d.visited + '</a></div>';
}},
{field: 'keep_success',width: 120,rowspan: 2, title: '维系成功',align: 'center', templet: function (d) {
return '<div><a href="javascript:void(1);" onclick="openQd(\''+ d.batch_num + '\',\''+ d.task_type + '\',\'' + d.fname + '\',1,\'' + d.subst + '\',\'' + this.field + '\')">' + d.keep_success + '</a></div>';
}},
{field: 'keep_failure',width: 120,rowspan: 2, title: '维系失败',align: 'center', templet: function (d) {
return '<div><a href="javascript:void(1);" onclick="openQd(\''+ d.batch_num + '\',\''+ d.task_type + '\',\'' + d.fname + '\',1,\'' + d.subst + '\',\'' + this.field + '\')">' + d.keep_failure + '</a></div>';
}},
{field: '', colspan: 11, title: '年内到期跟进结果(双线合计)', align: 'center'},
],[
{field: 'dq_sum',width: 100, title: '年内到期数量', align: 'center'},
{field: 'dq_yz',width: 120, title: '年内到期月租',align: 'center'},
{field: 'xy_sum',width: 100, title: '续约数',align: 'center'},
{field: 'xy_sr',width: 100, title: '续约收入', align: 'center'},
{field: 'ts',width: 100, title: '提速数',align: 'center'},
{field: 'ts_zb',width: 100, title: '提速占比',align: 'center'},
{field: 'tz',width: 100, title: '提值数', align: 'center'},
{field: 'tz_zb',width: 100, title: '提值占比',align: 'center'},
{field: 'tz_yz',width: 100, title: '提值月租',align: 'center'},
{field: 'cj_sum',width: 100, title: '拆机数', align: 'center'},
{field: 'cj_zb',width: 100, title: '拆机占比',align: 'center'},
]
]
\ No newline at end of file
Generator/genTable/src/main/resources/index.html
0 → 100644
View file @
855da282
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"utf-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1, maximum-scale=1"
>
<title></title>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"https://www.layuicdn.com/layui/css/layui.css"
/>
</head>
<body>
<div
id=
"table1"
class=
"table-box"
>
</div>
<div
id=
"table2"
class=
"table-box"
>
</div>
<script
src=
"https://www.layuicdn.com/layui/layui.js"
></script>
<script
src=
"https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"
></script>
<script>
//这个是单行表头的
var
col1
=
[
[{
field
:
'id'
,
title
:
'ID'
,
align
:
'center'
},
{
field
:
'username'
,
title
:
'用户名'
,
align
:
'center'
},
{
field
:
'sex'
,
title
:
'性别'
,
align
:
'center'
},
{
field
:
'city'
,
title
:
'城市'
,
align
:
'center'
},
{
field
:
'sign'
,
title
:
'签名'
,
align
:
'center'
},
{
field
:
'experience'
,
title
:
'积分'
,
align
:
'center'
},
{
field
:
'score'
,
title
:
'评分'
,
align
:
'center'
},
{
field
:
'classify'
,
title
:
'职业'
,
align
:
'center'
},
{
field
:
'wealth'
,
title
:
'财富'
,
align
:
'center'
}]
];
//复杂表头
var
col2
=
[
[
{
title
:
'单位'
,
field
:
'subst_name'
,
rowspan
:
2
,
align
:
'center'
},
{
title
:
'到期总数'
,
colspan
:
3
,
align
:
'center'
},
{
title
:
'派单数'
,
colspan
:
3
,
align
:
'center'
},
{
title
:
'跟进情况'
,
colspan
:
7
,
align
:
'center'
},
{
title
:
'跟进结果'
,
colspan
:
9
,
align
:
'center'
}
],
[
{
title
:
'合计'
,
field
:
'total'
,
align
:
'center'
},
{
title
:
'互联网专线'
,
field
:
'toal_hlwzx'
,
align
:
'center'
},
{
title
:
'组网专线'
,
field
:
'total_zwzx'
,
align
:
'center'
},
{
title
:
'合计'
,
field
:
'total_pd'
,
align
:
'center'
},
{
title
:
'互联网专线'
,
field
:
'v1'
,
align
:
'center'
},
{
title
:
'组网专线'
,
field
:
'v2'
,
align
:
'center'
},
{
title
:
'接单数'
,
field
:
'v3'
,
align
:
'center'
},
{
title
:
'执行率'
,
field
:
'v4'
,
align
:
'center'
},
{
title
:
'洽谈中'
,
field
:
'v5'
,
align
:
'center'
},
{
title
:
'资审合同审批中'
,
field
:
'v6'
,
align
:
'center'
},
{
title
:
'受理实施中'
,
field
:
'v7'
,
align
:
'center'
},
{
title
:
'洽谈成功'
,
field
:
'v8'
,
align
:
'center'
},
{
title
:
'失败'
,
field
:
'v9'
,
align
:
'center'
},
{
title
:
'续约数'
,
field
:
'v10'
,
align
:
'center'
},
{
title
:
'续约率'
,
field
:
'v11'
,
align
:
'center'
},
{
title
:
'提速数'
,
field
:
'v12'
,
align
:
'center'
},
{
title
:
'占比'
,
field
:
'v13'
,
align
:
'center'
},
{
title
:
'提值数'
,
field
:
'v14'
,
align
:
'center'
},
{
title
:
'占比'
,
field
:
'v15'
,
align
:
'center'
},
{
title
:
'提值月租'
,
field
:
'v16'
,
align
:
'center'
},
{
title
:
'拆机数'
,
field
:
'v17'
,
align
:
'center'
},
{
title
:
'占比'
,
field
:
'v18'
,
align
:
'center'
}
]
];
var
table
;
//表格对象
layui
.
use
([
'table'
],
function
()
{
table
=
layui
.
table
;
loadTable
(
'#table1'
,
col1
);
loadTable
(
'#table2'
,
col2
);
})
function
loadTable
(
id
,
col
)
{
table
.
render
({
elem
:
id
,
//url: '/layui-table/api/table1.json',
data
:[{
"id"
:
10000
,
"username"
:
"user-0"
,
"sex"
:
"女"
,
"city"
:
"城市-0"
,
"sign"
:
"签名-0"
,
"experience"
:
255
,
"logins"
:
24
,
"wealth"
:
82830700
,
"classify"
:
"作家"
,
"score"
:
57
},{
"id"
:
10001
,
"username"
:
"user-1"
,
"sex"
:
"男"
,
"city"
:
"城市-1"
,
"sign"
:
"签名-1"
,
"experience"
:
884
,
"logins"
:
58
,
"wealth"
:
64928690
,
"classify"
:
"词人"
,
"score"
:
27
},{
"id"
:
10002
,
"username"
:
"user-2"
,
"sex"
:
"女"
,
"city"
:
"城市-2"
,
"sign"
:
"签名-2"
,
"experience"
:
650
,
"logins"
:
77
,
"wealth"
:
6298078
,
"classify"
:
"酱油"
,
"score"
:
31
},{
"id"
:
10003
,
"username"
:
"user-3"
,
"sex"
:
"女"
,
"city"
:
"城市-3"
,
"sign"
:
"签名-3"
,
"experience"
:
362
,
"logins"
:
157
,
"wealth"
:
37117017
,
"classify"
:
"诗人"
,
"score"
:
68
},{
"id"
:
10004
,
"username"
:
"user-4"
,
"sex"
:
"男"
,
"city"
:
"城市-4"
,
"sign"
:
"签名-4"
,
"experience"
:
807
,
"logins"
:
51
,
"wealth"
:
76263262
,
"classify"
:
"作家"
,
"score"
:
6
},{
"id"
:
10005
,
"username"
:
"user-5"
,
"sex"
:
"女"
,
"city"
:
"城市-5"
,
"sign"
:
"签名-5"
,
"experience"
:
173
,
"logins"
:
68
,
"wealth"
:
60344147
,
"classify"
:
"作家"
,
"score"
:
87
},{
"id"
:
10006
,
"username"
:
"user-6"
,
"sex"
:
"女"
,
"city"
:
"城市-6"
,
"sign"
:
"签名-6"
,
"experience"
:
982
,
"logins"
:
37
,
"wealth"
:
57768166
,
"classify"
:
"作家"
,
"score"
:
34
},{
"id"
:
10007
,
"username"
:
"user-7"
,
"sex"
:
"男"
,
"city"
:
"城市-7"
,
"sign"
:
"签名-7"
,
"experience"
:
727
,
"logins"
:
150
,
"wealth"
:
82030578
,
"classify"
:
"作家"
,
"score"
:
28
},{
"id"
:
10008
,
"username"
:
"user-8"
,
"sex"
:
"男"
,
"city"
:
"城市-8"
,
"sign"
:
"签名-8"
,
"experience"
:
951
,
"logins"
:
133
,
"wealth"
:
16503371
,
"classify"
:
"词人"
,
"score"
:
14
},{
"id"
:
10009
,
"username"
:
"user-9"
,
"sex"
:
"女"
,
"city"
:
"城市-9"
,
"sign"
:
"签名-9"
,
"experience"
:
484
,
"logins"
:
25
,
"wealth"
:
86801934
,
"classify"
:
"词人"
,
"score"
:
75
}]
,
cols
:
col
});
}
</script>
</body>
</html>
Generator/genTable/src/test/java/com/winsun/test/TestJsonUtils.java
0 → 100644
View file @
855da282
package
com
.
winsun
.
test
;
import
cn.hutool.core.util.StrUtil
;
import
com.winsun.tools.entity.TreeNode
;
import
com.winsun.tools.entity.TreeNodeSql
;
import
com.winsun.tools.utils.THeadJsonUtils
;
import
com.winsun.tools.utils.TreeNodeDataCreator
;
import
org.junit.Test
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* @author zero
* @version 1.0
* @date 2020/5/27 12:04
*/
public
class
TestJsonUtils
{
@Test
public
void
test1
(){
String
filePath
=
"E:\\Documents\\WeChat Files\\WeChat Files\\zero13168599099\\FileStorage\\File\\2020-05\\表头(3)(1)(1)(1).xlsx"
;
List
<
TreeNodeSql
>
list
=
TreeNodeDataCreator
.
getTreeNodeByExcel
(
filePath
,
4
);
//layui json
THeadJsonUtils
.
readData
(
list
);
//app json
// THeadJsonUtils.writeAppJsonResult(list);
// for(TreeNodeSql sql : list){
// System.out.println(sql.toSql("sys_table_config", "能云必云情况"));
// }
}
}
Generator/genTable/src/test/java/com/winsun/test/TestTreeNodeDataCreator.java
0 → 100644
View file @
855da282
package
com
.
winsun
.
test
;
import
cn.hutool.core.io.FileUtil
;
import
com.winsun.tools.entity.TreeNodeReComplie
;
import
com.winsun.tools.utils.ExcelCellUtils
;
import
com.winsun.tools.utils.TreeNodeDataCreator
;
import
org.apache.poi.xssf.usermodel.XSSFCell
;
import
org.apache.poi.xssf.usermodel.XSSFRow
;
import
org.apache.poi.xssf.usermodel.XSSFSheet
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
org.junit.Test
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.*
;
/**
* @author zero
* @version 1.0
* @date 2020/5/24 0:34
*/
public
class
TestTreeNodeDataCreator
{
@Test
public
void
testCreateCode
()
{
String
filePath
=
"F:\\123.xlsx"
;
TreeNodeDataCreator
.
createCode
(
filePath
);
}
@Test
public
void
testSplit
()
{
String
str
=
"12#45"
;
String
[]
arr
=
str
.
split
(
"#"
);
System
.
out
.
println
(
arr
[
0
]);
System
.
out
.
println
(
arr
[
1
]);
}
@Test
public
void
test1
()
{
String
filePath
=
"F:\\123.xlsx"
;
// 需要解析的Excel文件
File
file
=
new
File
(
filePath
);
// "G:/项目资料/客户画像/111.xls"
try
{
// 创建Excel,读取文件内容
XSSFWorkbook
workbook
=
new
XSSFWorkbook
(
FileUtil
.
getInputStream
(
filePath
));
// 读取默认第一个工作表sheet
XSSFSheet
sheet
=
workbook
.
getSheetAt
(
0
);
int
firstRowNum
=
0
;
List
<
String
>
list
=
new
ArrayList
<
String
>();
// 获取sheet中最后一行行号
int
lastRowNum
=
sheet
.
getLastRowNum
();
// System.err.println(lastRowNum);
int
total
=
0
;
for
(
int
i
=
firstRowNum
;
i
<=
lastRowNum
;
i
++)
{
XSSFRow
row
=
sheet
.
getRow
(
i
);
// 获取当前行最后单元格列号
int
lastCellNum
=
row
.
getLastCellNum
();
for
(
int
j
=
0
;
j
<
lastCellNum
;
j
++)
{
XSSFCell
cell
=
row
.
getCell
(
j
);
if
(
cell
==
null
)
{
continue
;
}
String
value
=
ExcelCellUtils
.
getCellValue
(
cell
).
toString
();
if
(
value
.
equals
(
""
))
{
continue
;
}
System
.
out
.
print
(
value
+
"1"
);
}
System
.
out
.
println
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
test2
()
{
String
filePath
=
"F:\\123.xlsx"
;
// 需要解析的Excel文件
File
file
=
new
File
(
filePath
);
// "G:/项目资料/客户画像/111.xls"
try
{
// 创建Excel,读取文件内容
XSSFWorkbook
workbook
=
new
XSSFWorkbook
(
FileUtil
.
getInputStream
(
filePath
));
// 读取默认第一个工作表sheet
XSSFSheet
sheet
=
workbook
.
getSheetAt
(
0
);
int
firstRowNum
=
0
;
List
<
String
>
list
=
new
ArrayList
<
String
>();
// 获取sheet中最后一行行号
int
lastRowNum
=
sheet
.
getLastRowNum
();
int
total
=
0
;
for
(
int
i
=
firstRowNum
;
i
<=
lastRowNum
;
i
++)
{
XSSFRow
row
=
sheet
.
getRow
(
i
);
// 获取当前行最后单元格列号
int
lastCellNum
=
row
.
getLastCellNum
();
for
(
int
j
=
0
;
j
<
lastCellNum
;
j
++)
{
XSSFCell
cell
=
row
.
getCell
(
j
);
String
value
=
ExcelCellUtils
.
getCellValue
(
cell
).
toString
();
System
.
out
.
print
(
value
+
"1 "
);
}
System
.
out
.
println
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
test3
()
{
String
filePath
=
"F:\\123.xlsx"
;
// 需要解析的Excel文件
File
file
=
new
File
(
filePath
);
// "G:/项目资料/客户画像/111.xls"
try
{
// 创建Excel,读取文件内容
XSSFWorkbook
workbook
=
new
XSSFWorkbook
(
FileUtil
.
getInputStream
(
filePath
));
// 读取默认第一个工作表sheet
XSSFSheet
sheet
=
workbook
.
getSheetAt
(
0
);
int
firstRowNum
=
0
;
List
<
String
>
javaList
=
new
ArrayList
<
String
>();
// 获取sheet中最后一行行号
int
lastRowNum
=
sheet
.
getLastRowNum
();
// System.err.println(lastRowNum);
int
total
=
0
;
List
<
TreeNodeReComplie
>
dataList
=
new
LinkedList
<>();
Map
<
String
,
TreeNodeReComplie
>
map
=
new
LinkedHashMap
<>();
System
.
out
.
println
(
"TreeNode treeNode = new TreeNode(-1, \"\", null);"
);
for
(
int
i
=
firstRowNum
;
i
<=
lastRowNum
;
i
++)
{
XSSFRow
row
=
sheet
.
getRow
(
i
);
// 获取当前行最后单元格列号
int
lastCellNum
=
row
.
getLastCellNum
();
for
(
int
j
=
0
;
j
<
lastCellNum
;
j
++)
{
XSSFCell
cell
=
row
.
getCell
(
j
);
if
(
cell
==
null
)
{
continue
;
}
String
value
=
ExcelCellUtils
.
getCellValue
(
cell
).
toString
();
if
(
value
.
equals
(
""
))
{
continue
;
}
TreeNodeReComplie
treeNodeReComplie
=
new
TreeNodeReComplie
(
total
,
value
);
if
(
i
!=
firstRowNum
)
{
XSSFRow
row0
=
sheet
.
getRow
(
i
-
1
);
XSSFCell
cell0
=
row0
.
getCell
(
j
);
if
(
cell0
==
null
)
{
treeNodeReComplie
.
setParent
(
dataList
.
get
(
total
-
1
).
getParent
());
}
else
{
String
value0
=
ExcelCellUtils
.
getCellValue
(
cell0
).
toString
();
if
(
value0
.
equals
(
""
))
{
treeNodeReComplie
.
setParent
(
dataList
.
get
(
total
-
1
).
getParent
());
}
else
{
treeNodeReComplie
.
setParent
(
map
.
get
(
value0
+
(
i
-
1
)
+
""
+
j
));
}
}
}
else
{
treeNodeReComplie
.
setParent
(
new
TreeNodeReComplie
(
"treeNode"
));
}
map
.
put
(
value
+
i
+
""
+
j
,
treeNodeReComplie
);
dataList
.
add
(
treeNodeReComplie
);
total
++;
System
.
out
.
println
(
treeNodeReComplie
.
getJavaCode
());
}
}
System
.
out
.
println
(
"treeNode.calLeavesAmount(treeNode);"
);
System
.
out
.
println
(
"treeNode.calNodeLevel(treeNode);"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
/*
@Test
public void test(){
TreeNode treeNode = TreeNodeData.test();
// TreeNode treeNode = TreeNodeData.getMpsSalesTreeNodeData();
XSSFWorkbook workbook = ExcelTreeNodeHelper.getWorkbook(treeNode);
ExcelTreeNodeHelper.export(workbook);
}
*/
}
Generator/pom.xml
0 → 100644
View file @
855da282
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.winsun.tools
</groupId>
<artifactId>
Generator
</artifactId>
<packaging>
pom
</packaging>
<version>
1.0-SNAPSHOT
</version>
<modules>
<module>
genTable
</module>
<module>
DBProject
</module>
</modules>
<!--统一管理jar包版本-->
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<maven.compiler.source>
1.8
</maven.compiler.source>
<maven.compiler.target>
1.8
</maven.compiler.target>
<junit.version>
4.12
</junit.version>
<lombok.version>
1.18.8
</lombok.version>
<log4j.version>
1.2.17
</log4j.version>
<mysql.version>
5.1.47
</mysql.version>
<druid.version>
1.1.16
</druid.version>
<mybatis.spring.boot.version>
1.3.0
</mybatis.spring.boot.version>
</properties>
<dependencyManagement>
<dependencies>
<!--lombok-->
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
<version>
${lombok.version}
</version>
</dependency>
<!--junit-->
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<version>
${junit.version}
</version>
</dependency>
<!--log4j-->
<dependency>
<groupId>
log4j
</groupId>
<artifactId>
log4j
</artifactId>
<version>
${log4j.version}
</version>
</dependency>
<dependency>
<groupId>
net.sf.json-lib
</groupId>
<artifactId>
json-lib
</artifactId>
<version>
2.4
</version>
<classifier>
jdk15
</classifier>
</dependency>
<!-- poi-->
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi
</artifactId>
<version>
3.17
</version>
</dependency>
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi-ooxml
</artifactId>
<version>
3.17
</version>
</dependency>
<!--spring boot 2.2.2-->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-dependencies
</artifactId>
<version>
2.2.2.RELEASE
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
<!--mysql-->
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<version>
${mysql.version}
</version>
<scope>
runtime
</scope>
</dependency>
<!-- druid-->
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid
</artifactId>
<version>
${druid.version}
</version>
</dependency>
<!--mybatis-->
<dependency>
<groupId>
org.mybatis.spring.boot
</groupId>
<artifactId>
mybatis-spring-boot-starter
</artifactId>
<version>
${mybatis.spring.boot.version}
</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
\ No newline at end of file
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