Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
项目统一框架
amos-boot-biz
Commits
c1cd94c4
Commit
c1cd94c4
authored
Sep 24, 2021
by
suhuiguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.修改依赖问题
parent
26ea6622
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
876 additions
and
21 deletions
+876
-21
CommonExplicitConstraint.java
...join/amos/supervision/excel/CommonExplicitConstraint.java
+15
-0
DataSources.java
.../java/com/yeejoin/amos/supervision/excel/DataSources.java
+13
-0
ExcelListener.java
...ava/com/yeejoin/amos/supervision/excel/ExcelListener.java
+47
-0
ExcelStyleUtil.java
...va/com/yeejoin/amos/supervision/excel/ExcelStyleUtil.java
+183
-0
ExcelUtil.java
...in/java/com/yeejoin/amos/supervision/excel/ExcelUtil.java
+338
-0
ExplicitConstraint.java
...om/yeejoin/amos/supervision/excel/ExplicitConstraint.java
+23
-0
ExplicitInterface.java
...com/yeejoin/amos/supervision/excel/ExplicitInterface.java
+11
-0
TemplateCellWriteHandler.java
...join/amos/supervision/excel/TemplateCellWriteHandler.java
+73
-0
TemplateCellWriteHandlerDate.java
.../amos/supervision/excel/TemplateCellWriteHandlerDate.java
+120
-0
pom.xml
...-boot-module-biz/amos-boot-module-supervision-biz/pom.xml
+0
-16
HiddenDangerTemplateDto.java
...mos/supervision/business/dto/HiddenDangerTemplateDto.java
+2
-2
DataSourcesImpl.java
...os/supervision/business/service/impl/DataSourcesImpl.java
+1
-1
HiddenDangerServiceImpl.java
...vision/business/service/impl/HiddenDangerServiceImpl.java
+2
-2
logback-jcs.xml
...oot-system-supervision/src/main/resources/logback-jcs.xml
+48
-0
No files found.
amos-boot-module/amos-boot-module-api/amos-boot-module-supervision-api/src/main/java/com/yeejoin/amos/supervision/excel/CommonExplicitConstraint.java
0 → 100644
View file @
c1cd94c4
package
com
.
yeejoin
.
amos
.
supervision
.
excel
;
/***
*
* 获取动态值
*
* **/
public
class
CommonExplicitConstraint
implements
ExplicitInterface
{
@Override
public
String
[]
source
(
String
type
,
String
method
,
DataSources
dataDictionaryMapper
)
throws
Exception
{
return
dataDictionaryMapper
.
selectList
(
type
,
method
);
}
}
amos-boot-module/amos-boot-module-api/amos-boot-module-supervision-api/src/main/java/com/yeejoin/amos/supervision/excel/DataSources.java
0 → 100644
View file @
c1cd94c4
package
com
.
yeejoin
.
amos
.
supervision
.
excel
;
/**
*
* 字段列动态值获取
*
* ***/
public
interface
DataSources
{
String
[]
selectList
(
String
type
,
String
method
)
throws
Exception
;
}
amos-boot-module/amos-boot-module-api/amos-boot-module-supervision-api/src/main/java/com/yeejoin/amos/supervision/excel/ExcelListener.java
0 → 100644
View file @
c1cd94c4
package
com
.
yeejoin
.
amos
.
supervision
.
excel
;
import
com.alibaba.excel.context.AnalysisContext
;
import
com.alibaba.excel.event.AnalysisEventListener
;
import
java.util.ArrayList
;
import
java.util.List
;
//如果没有特殊说明,下面的案例将默认使用这个监听器
public
class
ExcelListener
<
T
>
extends
AnalysisEventListener
<
T
>
{
List
<
T
>
list
=
new
ArrayList
<
T
>();
public
List
<
T
>
getList
()
{
return
list
;
}
public
void
setList
(
List
<
T
>
list
)
{
this
.
list
=
list
;
}
/**
* 如果使用了spring,请使用这个构造方法。每次创建Listener的时候需要把spring管理的类传进来
*/
public
ExcelListener
()
{}
/**
* 这个每一条数据解析都会来调用
*
* @param data
* @param context
*/
@Override
public
void
invoke
(
T
data
,
AnalysisContext
context
)
{
list
.
add
(
data
);
}
/**
* 所有数据解析完成了 都会来调用
*
* @param context
*/
@Override
public
void
doAfterAllAnalysed
(
AnalysisContext
context
)
{
}
}
amos-boot-module/amos-boot-module-api/amos-boot-module-supervision-api/src/main/java/com/yeejoin/amos/supervision/excel/ExcelStyleUtil.java
0 → 100644
View file @
c1cd94c4
package
com
.
yeejoin
.
amos
.
supervision
.
excel
;
import
cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity
;
import
cn.afterturn.easypoi.excel.entity.params.ExcelForEachParams
;
import
cn.afterturn.easypoi.excel.export.styler.IExcelExportStyler
;
import
org.apache.poi.ss.usermodel.*
;
/**
* @title: ExcelStyleUtil
* @Author fpy
* @Date: 2021/7/8 15:36
* @Version 1.0
*/
public
class
ExcelStyleUtil
implements
IExcelExportStyler
{
private
static
final
short
STRING_FORMAT
=
(
short
)
BuiltinFormats
.
getBuiltinFormat
(
"TEXT"
);
private
static
final
short
FONT_SIZE_TEN
=
10
;
private
static
final
short
FONT_SIZE_ELEVEN
=
11
;
private
static
final
short
FONT_SIZE_TWELVE
=
12
;
/**
* 大标题样式
*/
private
CellStyle
headerStyle
;
/**
* 每列标题样式
*/
private
CellStyle
titleStyle
;
/**
* 数据行样式
*/
private
CellStyle
styles
;
public
ExcelStyleUtil
(
Workbook
workbook
)
{
this
.
init
(
workbook
);
}
/**
* 初始化样式
*
* @param workbook
*/
private
void
init
(
Workbook
workbook
)
{
//this.headerStyle = initHeaderStyle(workbook);
this
.
titleStyle
=
initTitleStyle
(
workbook
);
this
.
styles
=
initStyles
(
workbook
);
}
/**
* 大标题样式
*
* @param color
* @return
*/
@Override
public
CellStyle
getHeaderStyle
(
short
color
)
{
return
headerStyle
;
}
/**
* 每列标题样式
*
* @param color
* @return
*/
@Override
public
CellStyle
getTitleStyle
(
short
color
)
{
return
titleStyle
;
}
/**
* 数据行样式
*
* @param parity 可以用来表示奇偶行
* @param entity 数据内容
* @return 样式
*/
@Override
public
CellStyle
getStyles
(
boolean
parity
,
ExcelExportEntity
entity
)
{
return
styles
;
}
/**
* 获取样式方法
*
* @param dataRow 数据行
* @param obj 对象
* @param data 数据
*/
@Override
public
CellStyle
getStyles
(
Cell
cell
,
int
dataRow
,
ExcelExportEntity
entity
,
Object
obj
,
Object
data
)
{
return
getStyles
(
true
,
entity
);
}
/**
* 模板使用的样式设置
*/
@Override
public
CellStyle
getTemplateStyles
(
boolean
isSingle
,
ExcelForEachParams
excelForEachParams
)
{
return
null
;
}
/**
* 初始化--大标题样式
*
* @param workbook
* @return
*/
private
CellStyle
initHeaderStyle
(
Workbook
workbook
)
{
CellStyle
style
=
getBaseCellStyle
(
workbook
);
style
.
setFont
(
getFont
(
workbook
,
FONT_SIZE_TWELVE
,
true
));
return
style
;
}
/**
* 初始化--每列标题样式
*
* @param workbook
* @return
*/
private
CellStyle
initTitleStyle
(
Workbook
workbook
)
{
CellStyle
style
=
getBaseCellStyle
(
workbook
);
//style.setFont(getFont(workbook, FONT_SIZE_ELEVEN, false));
//背景色
style
.
setFillForegroundColor
(
IndexedColors
.
PALE_BLUE
.
getIndex
());
style
.
setFillPattern
(
FillPatternType
.
SOLID_FOREGROUND
);
return
style
;
}
/**
* 初始化--数据行样式
*
* @param workbook
* @return
*/
private
CellStyle
initStyles
(
Workbook
workbook
)
{
CellStyle
style
=
getBaseCellStyle
(
workbook
);
style
.
setFont
(
getFont
(
workbook
,
FONT_SIZE_TEN
,
false
));
style
.
setDataFormat
(
STRING_FORMAT
);
return
style
;
}
/**
* 基础样式
*
* @return
*/
private
CellStyle
getBaseCellStyle
(
Workbook
workbook
)
{
CellStyle
style
=
workbook
.
createCellStyle
();
//下边框
style
.
setBorderBottom
(
BorderStyle
.
THIN
);
//左边框
style
.
setBorderLeft
(
BorderStyle
.
THIN
);
//上边框
style
.
setBorderTop
(
BorderStyle
.
THIN
);
//右边框
style
.
setBorderRight
(
BorderStyle
.
THIN
);
//水平居中
style
.
setAlignment
(
HorizontalAlignment
.
CENTER
);
//上下居中
style
.
setVerticalAlignment
(
VerticalAlignment
.
CENTER
);
//设置自动换行
style
.
setWrapText
(
true
);
return
style
;
}
/**
* 字体样式
*
* @param size 字体大小
* @param isBold 是否加粗
* @return
*/
private
Font
getFont
(
Workbook
workbook
,
short
size
,
boolean
isBold
)
{
Font
font
=
workbook
.
createFont
();
//字体样式
font
.
setFontName
(
"宋体"
);
//是否加粗
font
.
setBold
(
isBold
);
//字体大小
font
.
setFontHeightInPoints
(
size
);
return
font
;
}
}
\ No newline at end of file
amos-boot-module/amos-boot-module-api/amos-boot-module-supervision-api/src/main/java/com/yeejoin/amos/supervision/excel/ExcelUtil.java
0 → 100644
View file @
c1cd94c4
package
com
.
yeejoin
.
amos
.
supervision
.
excel
;
import
com.alibaba.excel.EasyExcel
;
import
com.alibaba.excel.ExcelReader
;
import
com.alibaba.excel.annotation.ExcelProperty
;
import
com.alibaba.excel.read.metadata.ReadSheet
;
import
com.alibaba.excel.support.ExcelTypeEnum
;
import
com.alibaba.excel.write.builder.ExcelWriterSheetBuilder
;
import
com.alibaba.excel.write.metadata.style.WriteCellStyle
;
import
com.alibaba.excel.write.metadata.style.WriteFont
;
import
com.alibaba.excel.write.style.HorizontalCellStyleStrategy
;
import
org.apache.poi.ss.usermodel.BorderStyle
;
import
org.apache.poi.ss.usermodel.HorizontalAlignment
;
import
org.apache.poi.ss.usermodel.IndexedColors
;
import
org.apache.poi.ss.usermodel.VerticalAlignment
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.lang.reflect.Field
;
import
java.net.URLEncoder
;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
public
class
ExcelUtil
{
private
static
final
Integer
DUTY_CAR_START_INDEX
=
5
;
/**
* 生成excel模板
*
* @param response
* @param fileName 下载的文件名,
* @param sheetName sheet名
* @param data 导出的数据
* @param model 导出的头
* @param flag true模板填充下拉 false 不填充
*/
public
static
void
createTemplate
(
HttpServletResponse
response
,
String
fileName
,
String
sheetName
,
List
<?
extends
Object
>
data
,
Class
<?>
model
,
DataSources
dataDictionaryMapper
,
boolean
flag
)
{
HorizontalCellStyleStrategy
horizontalCellStyleStrategy
=
setMyCellStyle
();
try
{
//下拉列表集合
Map
<
Integer
,
String
[]>
explicitListConstraintMap
=
new
HashMap
<>();
if
(
flag
)
{
//循环获取对应列得下拉列表信息
Field
[]
declaredFields
=
model
.
getDeclaredFields
();
for
(
int
i
=
0
;
i
<
declaredFields
.
length
;
i
++)
{
Field
field
=
declaredFields
[
i
];
//解析注解信息
ExplicitConstraint
explicitConstraint
=
field
.
getAnnotation
(
ExplicitConstraint
.
class
);
resolveExplicitConstraint
(
explicitListConstraintMap
,
explicitConstraint
,
dataDictionaryMapper
);
}
}
EasyExcel
.
write
(
getOutputStream
(
fileName
,
response
,
ExcelTypeEnum
.
XLSX
),
model
)
.
excelType
(
ExcelTypeEnum
.
XLSX
).
sheet
(
sheetName
)
.
registerWriteHandler
(
new
TemplateCellWriteHandlerDate
(
explicitListConstraintMap
))
.
registerWriteHandler
(
new
TemplateCellWriteHandler
())
.
registerWriteHandler
(
horizontalCellStyleStrategy
)
.
doWrite
(
data
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
(
"系统异常!"
);
}
}
/**
* 生成excel模板
*
* @param response
* @param fileName 下载的文件名,
* @param sheetName sheet名
* @param data 导出的数据
* @param model 导出的头
* @param flag true模板填充下拉 false 不填充
*/
public
static
void
createDutyTemplate
(
HttpServletResponse
response
,
String
fileName
,
String
sheetName
,
List
<?
extends
Object
>
data
,
Class
<?>
model
,
List
<
String
>
dayByMonth
,
String
[]
dutyNameList
,
DataSources
dataDictionaryMapper
,
boolean
flag
)
{
HorizontalCellStyleStrategy
horizontalCellStyleStrategy
=
setMyCellStyle
();
try
{
// 组装表头
List
<
List
<
String
>>
dutyCarTitleList
=
new
ArrayList
<>();
Field
[]
declaredFields
=
model
.
getDeclaredFields
();
for
(
int
i
=
0
;
i
<
declaredFields
.
length
;
i
++)
{
Field
field
=
declaredFields
[
i
];
ExcelProperty
excelProperty
=
field
.
getAnnotation
(
ExcelProperty
.
class
);
if
(
excelProperty
!=
null
)
{
ArrayList
<
String
>
head
=
new
ArrayList
<>();
head
.
add
(
excelProperty
.
value
()[
0
]);
dutyCarTitleList
.
add
(
head
);
}
}
int
size
=
dutyCarTitleList
.
size
();
if
(
dayByMonth
!=
null
)
{
for
(
int
i
=
0
;
i
<
dayByMonth
.
size
();
i
++)
{
ArrayList
<
String
>
dutyDay
=
new
ArrayList
<>();
dutyDay
.
add
(
dayByMonth
.
get
(
i
));
dutyCarTitleList
.
add
(
dutyDay
);
}
}
//下拉列表集合
Map
<
Integer
,
String
[]>
explicitListConstraintMap
=
new
HashMap
<>();
if
(
flag
)
{
// 组装下拉列表
for
(
int
i
=
0
;
i
<
declaredFields
.
length
;
i
++)
{
Field
field
=
declaredFields
[
i
];
//解析注解信息
ExplicitConstraint
explicitConstraint
=
field
.
getAnnotation
(
ExplicitConstraint
.
class
);
resolveExplicitConstraint
(
explicitListConstraintMap
,
explicitConstraint
,
dataDictionaryMapper
);
}
if
(
dayByMonth
!=
null
)
{
for
(
int
i
=
0
;
i
<
dayByMonth
.
size
();
i
++)
{
explicitListConstraintMap
.
put
(
size
+
i
,
dutyNameList
);
}
}
}
// String s = new String(fileName.getBytes(), "UTF-8");
// response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(s, "UTF-8"));
ExcelWriterSheetBuilder
excelWriterSheetBuilder
=
EasyExcel
.
write
(
getOutputStream
(
fileName
,
response
,
ExcelTypeEnum
.
XLSX
)).
head
(
dutyCarTitleList
).
excelType
(
ExcelTypeEnum
.
XLSX
)
.
sheet
(
sheetName
).
registerWriteHandler
(
new
TemplateCellWriteHandlerDate
(
explicitListConstraintMap
))
.
registerWriteHandler
(
new
TemplateCellWriteHandler
())
.
registerWriteHandler
(
horizontalCellStyleStrategy
);
excelWriterSheetBuilder
.
doWrite
(
data
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
(
"系统异常!"
);
}
}
/**
* 读取 Excel(第一个 sheet) 指定行开始读取
*
* @param excel 文件
* @param rowType 模板实体类
* @param header 指定不读取的表头行数,
* @param <T>
* @return 集合数据
* @throws Exception
*/
public
static
<
T
>
List
<
T
>
readFirstSheetExcel
(
MultipartFile
excel
,
Class
<
T
>
rowType
,
int
header
)
throws
Exception
{
ExcelReader
reader
=
getReader
(
excel
,
header
);
if
(
reader
==
null
)
{
return
new
ArrayList
<>();
}
return
readExcel
(
reader
,
rowType
,
0
);
}
/**
* 读取 Excel(多个 sheet)
*
* @param reader 读取的excel
* @param rowModel excel模板实体类
* @param sheetCount sheet
* @param <T>
* @return
*/
public
static
<
T
>
List
<
T
>
readExcel
(
ExcelReader
reader
,
Class
<
T
>
rowModel
,
int
sheetCount
)
{
if
(
reader
==
null
)
{
return
new
ArrayList
<>();
}
ExcelListener
<
T
>
excelListener
=
new
ExcelListener
<>();
ReadSheet
readSheet
=
EasyExcel
.
readSheet
(
sheetCount
)
.
head
(
rowModel
)
.
registerReadListener
(
excelListener
)
.
build
();
reader
.
read
(
readSheet
);
return
excelListener
.
getList
();
}
/**
* @param excel 需要解析的 Excel 文件
* @param header 指定不读取表头行数,
* @return
* @throws Exception
*/
public
static
ExcelReader
getReader
(
MultipartFile
excel
,
int
header
)
throws
Exception
{
String
fileName
=
excel
.
getOriginalFilename
();
if
(
fileName
==
null
)
{
throw
new
Exception
(
"文件不存在!"
);
}
if
(!
fileName
.
toLowerCase
().
endsWith
(
ExcelTypeEnum
.
XLS
.
getValue
())
&&
!
fileName
.
toLowerCase
().
endsWith
(
ExcelTypeEnum
.
XLSX
.
getValue
()))
{
throw
new
Exception
(
"文件类型异常!"
);
}
InputStream
inputStream
;
try
{
inputStream
=
excel
.
getInputStream
();
return
EasyExcel
.
read
(
inputStream
).
headRowNumber
(
header
).
build
();
}
catch
(
IOException
e
)
{
//do something
}
return
null
;
}
/**
* 解析注解内容 获取下列表信息
*
* @param explicitConstraint
* @return
*/
public
static
Map
<
Integer
,
String
[]>
resolveExplicitConstraint
(
Map
<
Integer
,
String
[]>
explicitListConstraintMap
,
ExplicitConstraint
explicitConstraint
,
DataSources
dataDictionaryMapper
)
{
if
(
explicitConstraint
==
null
)
{
return
null
;
}
//固定下拉信息
String
[]
source
=
explicitConstraint
.
source
();
if
(
source
.
length
>
0
)
{
explicitListConstraintMap
.
put
(
explicitConstraint
.
indexNum
(),
source
);
}
//动态下拉信息
Class
<?
extends
ExplicitInterface
>[]
classes
=
explicitConstraint
.
sourceClass
();
if
(
classes
.
length
>
0
)
{
ExplicitInterface
explicitInterface
=
null
;
try
{
explicitInterface
=
classes
[
0
].
newInstance
();
String
[]
source1
=
explicitInterface
.
source
(
explicitConstraint
.
type
(),
explicitConstraint
.
method
(),
dataDictionaryMapper
);
if
(
source1
.
length
>
0
)
{
explicitListConstraintMap
.
put
(
explicitConstraint
.
indexNum
(),
source1
);
}
}
catch
(
InstantiationException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
return
null
;
}
/**
* 导出文件时为Writer生成OutputStream
*/
private
static
OutputStream
getOutputStream
(
String
fileName
,
HttpServletResponse
response
,
ExcelTypeEnum
excelTypeEnum
)
throws
Exception
{
//创建本地文件
String
filePath
=
fileName
+
excelTypeEnum
.
getValue
();
try
{
fileName
=
new
String
(
filePath
.
getBytes
(),
"UTF-8"
);
response
.
setCharacterEncoding
(
StandardCharsets
.
UTF_8
.
name
());
response
.
setContentType
(
"application/vnd.ms-excel"
);
response
.
addHeader
(
"Content-Disposition"
,
"filename="
+
fileName
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename="
+
URLEncoder
.
encode
(
fileName
,
StandardCharsets
.
UTF_8
.
name
()));
return
response
.
getOutputStream
();
}
catch
(
IOException
e
)
{
throw
new
Exception
(
"系统异常"
);
}
}
/**
* 创建我的cell 策略
*
* @return
*/
public
static
HorizontalCellStyleStrategy
setMyCellStyle
()
{
// // 头的策略
// WriteCellStyle headWriteCellStyle = new WriteCellStyle();
// // 设置表头居中对齐
// headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
// // 颜色
// headWriteCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
//
// WriteFont headWriteFont = new WriteFont();
// headWriteFont.setFontHeightInPoints((short) 10);
// // 字体
// headWriteCellStyle.setWriteFont(headWriteFont);
// headWriteCellStyle.setWrapped(true);
// // 内容的策略
// WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
// // 设置内容靠中对齐
// contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
// // 这个策略是 头是头的样式 内容是内容的样式 其他的策略可以自己实现
// HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy
// (headWriteCellStyle, contentWriteCellStyle);
// // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
// return horizontalCellStyleStrategy;
// 表头样式策略
WriteCellStyle
headWriteCellStyle
=
new
WriteCellStyle
();
//设置表头居中对齐
headWriteCellStyle
.
setHorizontalAlignment
(
HorizontalAlignment
.
CENTER
);
//表头前景色
headWriteCellStyle
.
setFillForegroundColor
(
IndexedColors
.
GREY_25_PERCENT
.
getIndex
());
WriteFont
headWriteFont
=
new
WriteFont
();
headWriteFont
.
setBold
(
true
);
headWriteFont
.
setFontName
(
"宋体"
);
headWriteFont
.
setFontHeightInPoints
((
short
)
10
);
headWriteCellStyle
.
setWriteFont
(
headWriteFont
);
//2 内容样式策略
WriteCellStyle
contentWriteCellStyle
=
new
WriteCellStyle
();
WriteFont
contentWriteFont
=
new
WriteFont
();
//内容字体大小
contentWriteFont
.
setFontName
(
"宋体"
);
contentWriteFont
.
setFontHeightInPoints
((
short
)
10
);
contentWriteCellStyle
.
setWriteFont
(
contentWriteFont
);
//设置自动换行
contentWriteCellStyle
.
setWrapped
(
true
);
//设置垂直居中
contentWriteCellStyle
.
setVerticalAlignment
(
VerticalAlignment
.
CENTER
);
// 头默认了 FillPatternType所以可以不指定。
// contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
//设置水平居中
contentWriteCellStyle
.
setHorizontalAlignment
(
HorizontalAlignment
.
CENTER
);
//设置边框样式
contentWriteCellStyle
.
setBorderLeft
(
BorderStyle
.
THIN
);
contentWriteCellStyle
.
setBorderTop
(
BorderStyle
.
THIN
);
contentWriteCellStyle
.
setBorderRight
(
BorderStyle
.
THIN
);
contentWriteCellStyle
.
setBorderBottom
(
BorderStyle
.
THIN
);
return
new
HorizontalCellStyleStrategy
(
headWriteCellStyle
,
contentWriteCellStyle
);
}
}
amos-boot-module/amos-boot-module-api/amos-boot-module-supervision-api/src/main/java/com/yeejoin/amos/supervision/excel/ExplicitConstraint.java
0 → 100644
View file @
c1cd94c4
package
com
.
yeejoin
.
amos
.
supervision
.
excel
;
import
java.lang.annotation.*
;
/**
* 导出模板数据
*/
@Documented
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Target
({
ElementType
.
FIELD
})
public
@interface
ExplicitConstraint
{
//定义固定下拉内容
String
[]
source
()
default
{};
//定义动态下拉内容,
Class
[]
sourceClass
()
default
{};
//列标号必须和字段下标一致
int
indexNum
()
default
0
;
//字典type
String
type
()
default
""
;
//接口查询
String
method
()
default
""
;
}
amos-boot-module/amos-boot-module-api/amos-boot-module-supervision-api/src/main/java/com/yeejoin/amos/supervision/excel/ExplicitInterface.java
0 → 100644
View file @
c1cd94c4
package
com
.
yeejoin
.
amos
.
supervision
.
excel
;
public
interface
ExplicitInterface
{
/**
* 动态下拉列表的内容数组
* @return
* type 字典类型
*/
String
[]
source
(
String
type
,
String
method
,
DataSources
dataDictionaryMapper
)
throws
Exception
;
}
amos-boot-module/amos-boot-module-api/amos-boot-module-supervision-api/src/main/java/com/yeejoin/amos/supervision/excel/TemplateCellWriteHandler.java
0 → 100644
View file @
c1cd94c4
package
com
.
yeejoin
.
amos
.
supervision
.
excel
;
import
com.alibaba.excel.metadata.CellData
;
import
com.alibaba.excel.metadata.Head
;
import
com.alibaba.excel.write.handler.CellWriteHandler
;
import
com.alibaba.excel.write.metadata.holder.WriteSheetHolder
;
import
com.alibaba.excel.write.metadata.holder.WriteTableHolder
;
import
org.apache.poi.ss.usermodel.*
;
/**
* excel通用单元格格式类
*/
public
class
TemplateCellWriteHandler
implements
CellWriteHandler
{
@Override
public
void
beforeCellCreate
(
WriteSheetHolder
writeSheetHolder
,
WriteTableHolder
writeTableHolder
,
Row
row
,
Head
head
,
int
relativeRowIndex
,
boolean
isHead
)
{
// TODO Auto-generated method stub
}
@Override
public
void
afterCellCreate
(
WriteSheetHolder
writeSheetHolder
,
WriteTableHolder
writeTableHolder
,
CellData
cellData
,
Cell
cell
,
Head
head
,
int
relativeRowIndex
,
boolean
isHead
)
{
Workbook
workbooks
=
writeSheetHolder
.
getSheet
().
getWorkbook
();
if
(
0
==
cell
.
getRowIndex
())
{
writeSheetHolder
.
getSheet
().
setColumnWidth
(
cell
.
getColumnIndex
(),
20
*
256
);
CellStyle
cellStyle
=
workbooks
.
createCellStyle
();
cellStyle
.
setVerticalAlignment
(
VerticalAlignment
.
CENTER
);
//居中
cellStyle
.
setAlignment
(
HorizontalAlignment
.
CENTER
);
cellStyle
.
setFillPattern
(
FillPatternType
.
SOLID_FOREGROUND
);
//设置前景填充样式
cellStyle
.
setFillForegroundColor
(
IndexedColors
.
ROYAL_BLUE
.
getIndex
());
//前景填充色
Font
font1
=
workbooks
.
createFont
();
//设置字体
font1
.
setBold
(
true
);
font1
.
setColor
((
short
)
1
);
font1
.
setFontHeightInPoints
((
short
)
15
);
cellStyle
.
setFont
(
font1
);
cell
.
setCellStyle
(
cellStyle
);
}
// //其他列
// if (!isHead){
// CellStyle style = workbooks.createCellStyle();
// DataFormat dataFormat = workbooks.createDataFormat();
// style.setDataFormat(dataFormat.getFormat("@"));
// style.setVerticalAlignment(VerticalAlignment.CENTER);
// style.setAlignment(HorizontalAlignment.CENTER);
// cell.setCellStyle(style);
// }
// //设置日期
// if (!isHead && cell.getColumnIndex()==19 || !isHead && cell.getColumnIndex()==21|| !isHead && cell.getColumnIndex()==20){
// CellStyle style = workbooks.createCellStyle();
// DataFormat dataFormat = workbooks.createDataFormat();
// style.setDataFormat(dataFormat.getFormat("yyyy/mm/dd hh:mm:ss"));
// style.setVerticalAlignment(VerticalAlignment.CENTER);
// style.setAlignment(HorizontalAlignment.CENTER);
// cell.setCellStyle(style);
// }
// //设置金额
// if (!isHead && cell.getColumnIndex()==15 ||!isHead && cell.getColumnIndex()==16||!isHead && cell.getColumnIndex()==22 ||!isHead && cell.getColumnIndex()==24||!isHead && cell.getColumnIndex()==25){
// CellStyle style = workbooks.createCellStyle();
// DataFormat dataFormat = workbooks.createDataFormat();
// style.setDataFormat(dataFormat.getFormat("0.00"));
// style.setVerticalAlignment(VerticalAlignment.CENTER);
// style.setAlignment(HorizontalAlignment.CENTER);
// cell.setCellStyle(style);
// }
}
}
amos-boot-module/amos-boot-module-api/amos-boot-module-supervision-api/src/main/java/com/yeejoin/amos/supervision/excel/TemplateCellWriteHandlerDate.java
0 → 100644
View file @
c1cd94c4
package
com
.
yeejoin
.
amos
.
supervision
.
excel
;
import
com.alibaba.excel.write.handler.SheetWriteHandler
;
import
com.alibaba.excel.write.metadata.holder.WriteSheetHolder
;
import
com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder
;
import
org.apache.poi.ss.usermodel.*
;
import
org.apache.poi.ss.util.CellRangeAddressList
;
import
org.apache.poi.xssf.usermodel.XSSFDataValidation
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* excel通用单元格格式类下拉框赋值
*/
public
class
TemplateCellWriteHandlerDate
implements
SheetWriteHandler
{
/**
* 构造器注入
*/
private
Map
<
Integer
,
String
[]>
explicitListConstraintMap
=
new
HashMap
<>();
public
TemplateCellWriteHandlerDate
(
Map
<
Integer
,
String
[]>
explicitListConstraintMap
)
{
this
.
explicitListConstraintMap
=
explicitListConstraintMap
;
}
/**
* 避免生成的导入模板下拉值获取不到
*/
private
static
final
Integer
LIMIT_NUMBER
=
1
;
/**
* 返回excel列标A-Z-AA-ZZ
*
* @param num 列数
* @return java.lang.String
*/
private
String
getExcelLine
(
int
num
)
{
String
line
=
""
;
int
first
=
num
/
26
;
int
second
=
num
%
26
;
if
(
first
>
0
)
{
line
=
(
char
)
(
'A'
+
first
-
1
)
+
""
;
}
line
+=
(
char
)
(
'A'
+
second
)
+
""
;
return
line
;
}
@Override
public
void
beforeSheetCreate
(
WriteWorkbookHolder
writeWorkbookHolder
,
WriteSheetHolder
writeSheetHolder
)
{
// TODO Auto-generated method stub
}
@Override
public
void
afterSheetCreate
(
WriteWorkbookHolder
writeWorkbookHolder
,
WriteSheetHolder
writeSheetHolder
)
{
if
(
explicitListConstraintMap
!=
null
)
{
// 这里可以对cell进行任何操作
Sheet
sheet
=
writeSheetHolder
.
getSheet
();
DataValidationHelper
helper
=
sheet
.
getDataValidationHelper
();
// k 为存在下拉数据集的单元格下表 v为下拉数据集
explicitListConstraintMap
.
forEach
((
k
,
v
)
->
{
// 设置下拉单元格的首行 末行 首列 末列
CellRangeAddressList
rangeList
=
new
CellRangeAddressList
(
1
,
65536
,
k
,
k
);
// 如果下拉值总数大于100,则使用一个新sheet存储,避免生成的导入模板下拉值获取不到
if
(
v
.
length
>
LIMIT_NUMBER
)
{
//定义sheet的名称
//1.创建一个隐藏的sheet 名称为 hidden + k
String
sheetName
=
"hidden"
+
k
;
Workbook
workbook
=
writeWorkbookHolder
.
getWorkbook
();
Sheet
hiddenSheet
=
workbook
.
createSheet
(
sheetName
);
for
(
int
i
=
0
,
length
=
v
.
length
;
i
<
length
;
i
++)
{
// 开始的行数i,列数k
hiddenSheet
.
createRow
(
i
).
createCell
(
k
).
setCellValue
(
v
[
i
]);
}
Name
category1Name
=
workbook
.
createName
();
category1Name
.
setNameName
(
sheetName
);
String
excelLine
=
getExcelLine
(
k
);
// =hidden!$H:$1:$H$50 sheet为hidden的 H1列开始H50行数据获取下拉数组
String
refers
=
"="
+
sheetName
+
"!$"
+
excelLine
+
"$1:$"
+
excelLine
+
"$"
+
(
v
.
length
+
1
);
// 将刚才设置的sheet引用到你的下拉列表中
DataValidationConstraint
constraint
=
helper
.
createFormulaListConstraint
(
refers
);
DataValidation
dataValidation
=
helper
.
createValidation
(
constraint
,
rangeList
);
if
(
dataValidation
instanceof
XSSFDataValidation
){
dataValidation
.
setSuppressDropDownArrow
(
true
);
dataValidation
.
setShowErrorBox
(
true
);
}
else
{
dataValidation
.
setSuppressDropDownArrow
(
false
);
}
writeSheetHolder
.
getSheet
().
addValidationData
(
dataValidation
);
// 设置存储下拉列值得sheet为隐藏
int
hiddenIndex
=
workbook
.
getSheetIndex
(
sheetName
);
if
(!
workbook
.
isSheetHidden
(
hiddenIndex
))
{
workbook
.
setSheetHidden
(
hiddenIndex
,
true
);
}
}
// // 下拉列表约束数据
// DataValidationConstraint constraint = helper.createExplicitListConstraint(v);
// // 设置约束
// DataValidation validation = helper.createValidation(constraint, rangeList);
// // 阻止输入非下拉选项的值
// validation.setErrorStyle(DataValidation.ErrorStyle.STOP);
// validation.setShowErrorBox(true);
// validation.setSuppressDropDownArrow(true);
// validation.createErrorBox("提示", "此值与单元格定义格式不一致");
// // validation.createPromptBox("填写说明:","填写内容只能为下拉数据集中的单位,其他单位将会导致无法入仓");
// sheet.addValidationData(validation);
});
}
}
}
amos-boot-module/amos-boot-module-biz/amos-boot-module-supervision-biz/pom.xml
View file @
c1cd94c4
...
@@ -96,21 +96,5 @@
...
@@ -96,21 +96,5 @@
<groupId>
cn.jpush.api
</groupId>
<groupId>
cn.jpush.api
</groupId>
<artifactId>
jpush-client
</artifactId>
<artifactId>
jpush-client
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
com.amosframework.boot
</groupId>
<artifactId>
amos-boot-module-common-api
</artifactId>
<version>
1.0.0
</version>
<scope>
compile
</scope>
<exclusions>
<exclusion>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-elasticsearch
</artifactId>
</exclusion>
<exclusion>
<groupId>
com.yeejoin
</groupId>
<artifactId>
amos-component-rule
</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
amos-boot-module/amos-boot-module-biz/amos-boot-module-supervision-biz/src/main/java/com/yeejoin/amos/supervision/business/dto/HiddenDangerTemplateDto.java
View file @
c1cd94c4
...
@@ -2,8 +2,8 @@ package com.yeejoin.amos.supervision.business.dto;
...
@@ -2,8 +2,8 @@ package com.yeejoin.amos.supervision.business.dto;
import
com.alibaba.excel.annotation.ExcelIgnore
;
import
com.alibaba.excel.annotation.ExcelIgnore
;
import
com.alibaba.excel.annotation.ExcelProperty
;
import
com.alibaba.excel.annotation.ExcelProperty
;
import
com.yeejoin.amos.
boot.module.common.api
.excel.CommonExplicitConstraint
;
import
com.yeejoin.amos.
supervision
.excel.CommonExplicitConstraint
;
import
com.yeejoin.amos.
boot.module.common.api
.excel.ExplicitConstraint
;
import
com.yeejoin.amos.
supervision
.excel.ExplicitConstraint
;
import
lombok.Data
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.io.Serializable
;
...
...
amos-boot-module/amos-boot-module-biz/amos-boot-module-supervision-biz/src/main/java/com/yeejoin/amos/supervision/business/service/impl/DataSourcesImpl.java
View file @
c1cd94c4
package
com
.
yeejoin
.
amos
.
supervision
.
business
.
service
.
impl
;
package
com
.
yeejoin
.
amos
.
supervision
.
business
.
service
.
impl
;
import
com.yeejoin.amos.boot.module.common.api.excel.DataSources
;
import
com.yeejoin.amos.component.feign.model.FeignClientResult
;
import
com.yeejoin.amos.component.feign.model.FeignClientResult
;
import
com.yeejoin.amos.feign.systemctl.model.DictionarieValueModel
;
import
com.yeejoin.amos.feign.systemctl.model.DictionarieValueModel
;
import
com.yeejoin.amos.supervision.business.dao.mapper.PointMapper
;
import
com.yeejoin.amos.supervision.business.dao.mapper.PointMapper
;
import
com.yeejoin.amos.supervision.business.feign.DangerFeignClient
;
import
com.yeejoin.amos.supervision.business.feign.DangerFeignClient
;
import
com.yeejoin.amos.supervision.dao.entity.Point
;
import
com.yeejoin.amos.supervision.dao.entity.Point
;
import
com.yeejoin.amos.supervision.excel.DataSources
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.typroject.tyboot.core.foundation.utils.ValidationUtil
;
import
org.typroject.tyboot.core.foundation.utils.ValidationUtil
;
...
...
amos-boot-module/amos-boot-module-biz/amos-boot-module-supervision-biz/src/main/java/com/yeejoin/amos/supervision/business/service/impl/HiddenDangerServiceImpl.java
View file @
c1cd94c4
...
@@ -5,8 +5,6 @@ import com.baomidou.mybatisplus.core.toolkit.Sequence;
...
@@ -5,8 +5,6 @@ import com.baomidou.mybatisplus.core.toolkit.Sequence;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.google.common.base.Joiner
;
import
com.google.common.base.Joiner
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
import
com.yeejoin.amos.boot.module.common.api.excel.DataSources
;
import
com.yeejoin.amos.boot.module.common.api.excel.ExcelUtil
;
import
com.yeejoin.amos.component.feign.model.FeignClientResult
;
import
com.yeejoin.amos.component.feign.model.FeignClientResult
;
import
com.yeejoin.amos.supervision.business.dao.mapper.HiddenDangerMapper
;
import
com.yeejoin.amos.supervision.business.dao.mapper.HiddenDangerMapper
;
import
com.yeejoin.amos.supervision.business.dao.repository.IHiddenDangerDao
;
import
com.yeejoin.amos.supervision.business.dao.repository.IHiddenDangerDao
;
...
@@ -17,6 +15,8 @@ import com.yeejoin.amos.supervision.business.feign.DangerFeignClient;
...
@@ -17,6 +15,8 @@ import com.yeejoin.amos.supervision.business.feign.DangerFeignClient;
import
com.yeejoin.amos.supervision.business.service.intfc.IHiddenDangerService
;
import
com.yeejoin.amos.supervision.business.service.intfc.IHiddenDangerService
;
import
com.yeejoin.amos.supervision.core.common.dto.DangerDto
;
import
com.yeejoin.amos.supervision.core.common.dto.DangerDto
;
import
com.yeejoin.amos.supervision.dao.entity.HiddenDanger
;
import
com.yeejoin.amos.supervision.dao.entity.HiddenDanger
;
import
com.yeejoin.amos.supervision.excel.DataSources
;
import
com.yeejoin.amos.supervision.excel.ExcelUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
...
amos-boot-system-supervision/src/main/resources/logback-jcs.xml
0 → 100644
View file @
c1cd94c4
<?xml version="1.0" encoding="UTF-8"?>
<configuration
debug=
"false"
>
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
<property
name=
"LOG_HOME"
value=
"log"
/>
<!-- 按照每天生成日志文件 -->
<appender
name=
"FILE"
class=
"ch.qos.logback.core.rolling.RollingFileAppender"
>
<rollingPolicy
class=
"ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"
>
<!--日志文件输出的文件名-->
<FileNamePattern>
${LOG_HOME}/maintenance.log.%d{yyyy-MM-dd}.%i.log
</FileNamePattern>
<!--日志文件保留天数-->
<MaxHistory>
30
</MaxHistory>
<!--日志文件大小-->
<MaxFileSize>
30mb
</MaxFileSize>
</rollingPolicy>
<encoder
class=
"ch.qos.logback.classic.encoder.PatternLayoutEncoder"
>
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>
%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
</pattern>
</encoder>
</appender>
<!-- 控制台输出 -->
<appender
name=
"STDOUT"
class=
"ch.qos.logback.core.ConsoleAppender"
>
<encoder
class=
"ch.qos.logback.classic.encoder.PatternLayoutEncoder"
>
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>
%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
</pattern>
</encoder>
</appender>
<!-- show parameters for hibernate sql 专为 Hibernate 定制
<logger name="org.hibernate.type.descriptor.sql.BasicBinder" level="TRACE" />
<logger name="org.hibernate.type.descriptor.sql.BasicExtractor" level="DEBUG" />
<logger name="org.hibernate.SQL" level="DEBUG" />
<logger name="org.hibernate.engine.QueryParameters" level="DEBUG" />
<logger name="org.hibernate.engine.query.HQLQueryPlan" level="DEBUG" />
-->
<!--myibatis log configure-->
<logger
name=
"com.apache.ibatis"
level=
"DEBUG"
/>
<logger
name=
"org.mybatis"
level=
"DEBUG"
/>
<logger
name=
"java.sql.Connection"
level=
"DEBUG"
/>
<logger
name=
"java.sql.Statement"
level=
"DEBUG"
/>
<logger
name=
"java.sql.PreparedStatement"
level=
"DEBUG"
/>
<logger
name=
"org.springframework"
level=
"DEBUG"
/>
<!-- 日志输出级别 -->
<root
level=
"DEBUG"
>
<appender-ref
ref=
"FILE"
/>
<appender-ref
ref=
"STDOUT"
/>
</root>
</configuration>
\ 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