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
44686417
Commit
44686417
authored
Jul 08, 2021
by
fupeiyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
值班导入导出
parent
e8470581
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
708 additions
and
42 deletions
+708
-42
DateUtils.java
...ava/com/yeejoin/amos/boot/biz/common/utils/DateUtils.java
+14
-1
DutyCarExcelDto.java
...join/amos/boot/module/common/api/dto/DutyCarExcelDto.java
+70
-0
DutyPersonExcelDto.java
...n/amos/boot/module/common/api/dto/DutyPersonExcelDto.java
+53
-0
FireExpertsDto.java
...ejoin/amos/boot/module/common/api/dto/FireExpertsDto.java
+0
-1
FirefightersExcelDto.java
...amos/boot/module/common/api/dto/FirefightersExcelDto.java
+1
-1
TitleEnum.java
.../yeejoin/amos/boot/module/common/api/enums/TitleEnum.java
+34
-0
ExcelStyleUtil.java
...oin/amos/boot/module/common/api/excel/ExcelStyleUtil.java
+183
-0
ExcelUtil.java
.../yeejoin/amos/boot/module/common/api/excel/ExcelUtil.java
+102
-33
ExcelEnums.java
...om/yeejoin/amos/boot/module/jcs/api/enums/ExcelEnums.java
+1
-0
DateUtils.java
.../yeejoin/amos/boot/module/common/biz/utils/DateUtils.java
+82
-0
ExcelController.java
.../amos/boot/module/jcs/biz/controller/ExcelController.java
+147
-6
DataSourcesImpl.java
...mos/boot/module/jcs/biz/service/impl/DataSourcesImpl.java
+21
-0
No files found.
amos-boot-biz-common/src/main/java/com/yeejoin/amos/boot/biz/common/utils/DateUtils.java
View file @
44686417
...
@@ -520,6 +520,18 @@ public class DateUtils {
...
@@ -520,6 +520,18 @@ public class DateUtils {
return
dateParse
(
dateFormat
(
date
,
MONTH_PATTERN
)
+
"-"
+
value
,
null
);
return
dateParse
(
dateFormat
(
date
,
MONTH_PATTERN
)
+
"-"
+
value
,
null
);
}
}
/**
* 当前日期毫秒.xls
*
* @return
*/
public
static
String
formatName
()
{
Calendar
calen
=
Calendar
.
getInstance
();
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyyMMddhhmmss"
);
String
name
=
sdf
.
format
(
calen
.
getTime
());
return
name
;
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
/*System.out.println(dateTimeToDate(new Date()));
/*System.out.println(dateTimeToDate(new Date()));
System.out.println(dateParse("2017-02-04 14:58:20", null));
System.out.println(dateParse("2017-02-04 14:58:20", null));
...
@@ -531,7 +543,8 @@ public class DateUtils {
...
@@ -531,7 +543,8 @@ public class DateUtils {
/*
/*
System.out.println(getDaysOfMonth(dateParse("2017-02-01", null)));
System.out.println(getDaysOfMonth(dateParse("2017-02-01", null)));
System.out.println(getDaysOfYear(dateParse("2017-01-30", null)));*/
System.out.println(getDaysOfYear(dateParse("2017-01-30", null)));*/
//System.out.println(dateFormat(dateAddMonths(dateParse("2017-02-07", StrUtils.MONTH_PATTERN), -12), StrUtils.MONTH_PATTERN));
//System.out.println(dateFormat(dateAddMonths(dateParse("2017-02-07", StrUtils.MONTH_PATTERN), -12), StrUtils
// .MONTH_PATTERN));
/*System.out.println(dateFormat(maxDateOfMonth(dateParse("2016-02", "yyyy-MM")), null));
/*System.out.println(dateFormat(maxDateOfMonth(dateParse("2016-02", "yyyy-MM")), null));
System.out.println(dateFormat(minDateOfMonth(dateParse("2016-03-31", null)), null));*/
System.out.println(dateFormat(minDateOfMonth(dateParse("2016-03-31", null)), null));*/
}
}
...
...
amos-boot-module/amos-boot-module-api/amos-boot-module-common-api/src/main/java/com/yeejoin/amos/boot/module/common/api/dto/DutyCarExcelDto.java
0 → 100644
View file @
44686417
package
com
.
yeejoin
.
amos
.
boot
.
module
.
common
.
api
.
dto
;
import
com.alibaba.excel.annotation.ExcelIgnore
;
import
com.alibaba.excel.annotation.ExcelProperty
;
import
com.yeejoin.amos.boot.module.common.api.excel.ExplicitConstraint
;
import
com.yeejoin.amos.boot.module.common.api.excel.RoleNameExplicitConstraint
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
org.typroject.tyboot.core.foundation.utils.Bean
;
import
java.io.Serializable
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* 值班班次
*
* @author system_generator
* @date 2021-07-06
*/
@Data
@ApiModel
(
value
=
"DutyCarDto"
,
description
=
"值班车辆"
)
public
class
DutyCarExcelDto
implements
Serializable
{
@ExcelIgnore
private
static
final
long
serialVersionUID
=
1L
;
@ExcelProperty
(
value
=
"序号"
,
index
=
0
)
@ApiModelProperty
(
value
=
"序号"
)
private
Integer
number
;
@ExcelIgnore
@ApiModelProperty
(
value
=
"消防队伍id"
)
private
String
teamId
;
@ExcelProperty
(
value
=
"消防队伍"
,
index
=
1
)
@ApiModelProperty
(
value
=
"消防队伍名称"
)
private
String
teamName
;
@ExcelIgnore
@ApiModelProperty
(
value
=
"用户id"
)
private
String
userId
;
@ExcelProperty
(
value
=
"姓名"
,
index
=
2
)
@ApiModelProperty
(
value
=
"用户名称"
)
private
String
userName
;
@ExcelIgnore
@ApiModelProperty
(
value
=
"岗位id"
)
private
String
postType
;
@ExcelProperty
(
value
=
"岗位"
,
index
=
3
)
@ApiModelProperty
(
value
=
"岗位名称"
)
private
String
postTypeName
;
@ExcelIgnore
@ApiModelProperty
(
value
=
"车辆id"
)
private
String
carId
;
@ExplicitConstraint
(
indexNum
=
4
,
sourceClass
=
RoleNameExplicitConstraint
.
class
,
method
=
"getCarList"
)
//固定下拉内容
@ExcelProperty
(
value
=
"车辆名称(车牌)"
,
index
=
4
)
@ApiModelProperty
(
value
=
"车辆名称"
)
private
String
carName
;
@ExcelIgnore
@ApiModelProperty
(
value
=
"值班信息"
)
private
List
<
DutyPersonShiftDto
>
dutyShift
=
new
ArrayList
<>();
}
amos-boot-module/amos-boot-module-api/amos-boot-module-common-api/src/main/java/com/yeejoin/amos/boot/module/common/api/dto/DutyPersonExcelDto.java
0 → 100644
View file @
44686417
package
com
.
yeejoin
.
amos
.
boot
.
module
.
common
.
api
.
dto
;
import
com.alibaba.excel.annotation.ExcelIgnore
;
import
com.alibaba.excel.annotation.ExcelProperty
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.util.List
;
/**
* 值班班次
*
* @author system_generator
* @date 2021-07-06
*/
@Data
@ApiModel
(
value
=
"DutyPersonDto"
,
description
=
"值班人"
)
public
class
DutyPersonExcelDto
implements
Serializable
{
@ExcelIgnore
private
static
final
long
serialVersionUID
=
1L
;
@ExcelProperty
(
value
=
"序号"
,
index
=
0
)
@ApiModelProperty
(
value
=
"序号"
)
private
Integer
number
;
@ExcelProperty
(
value
=
"用户id"
,
index
=
1
)
@ApiModelProperty
(
value
=
"用户id"
)
private
String
userId
;
@ExcelProperty
(
value
=
"姓名"
,
index
=
2
)
@ApiModelProperty
(
value
=
"用户名称"
)
private
String
userName
;
@ExcelIgnore
@ApiModelProperty
(
value
=
"部门id"
)
private
String
deptId
;
@ExcelIgnore
@ApiModelProperty
(
value
=
"部门名称"
)
private
String
deptName
;
@ApiModelProperty
(
value
=
"岗位id"
)
private
String
postType
;
@ApiModelProperty
(
value
=
"岗位名称"
)
private
String
postTypeName
;
@ApiModelProperty
(
value
=
"值班信息"
)
private
List
<
DutyPersonShiftDto
>
dutyShift
;
}
amos-boot-module/amos-boot-module-api/amos-boot-module-common-api/src/main/java/com/yeejoin/amos/boot/module/common/api/dto/FireExpertsDto.java
View file @
44686417
...
@@ -3,7 +3,6 @@ package com.yeejoin.amos.boot.module.common.api.dto;
...
@@ -3,7 +3,6 @@ package com.yeejoin.amos.boot.module.common.api.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.biz.common.dto.BaseDto
;
import
com.yeejoin.amos.boot.biz.common.dto.BaseDto
;
import
com.yeejoin.amos.boot.module.common.api.enums.ExcelSelectData
;
import
com.yeejoin.amos.boot.module.common.api.excel.ExplicitConstraint
;
import
com.yeejoin.amos.boot.module.common.api.excel.ExplicitConstraint
;
import
com.yeejoin.amos.boot.module.common.api.excel.RoleNameExplicitConstraint
;
import
com.yeejoin.amos.boot.module.common.api.excel.RoleNameExplicitConstraint
;
...
...
amos-boot-module/amos-boot-module-api/amos-boot-module-common-api/src/main/java/com/yeejoin/amos/boot/module/common/api/dto/FirefightersExcelDto.java
View file @
44686417
...
@@ -68,7 +68,7 @@ public class FirefightersExcelDto extends BaseDto {
...
@@ -68,7 +68,7 @@ public class FirefightersExcelDto extends BaseDto {
private
Date
birthdayTime
;
private
Date
birthdayTime
;
@ExplicitConstraint
(
indexNum
=
7
,
source
=
{
"男"
,
"女"
})
//固定下拉内容
@ExplicitConstraint
(
indexNum
=
7
,
source
=
{
"男"
,
"女"
})
//固定下拉内容
@ExcelProperty
(
value
=
"性别"
,
index
=
5
)
@ExcelProperty
(
value
=
"性别"
,
index
=
7
)
@ApiModelProperty
(
value
=
"性别"
)
@ApiModelProperty
(
value
=
"性别"
)
private
String
gender
;
private
String
gender
;
...
...
amos-boot-module/amos-boot-module-api/amos-boot-module-common-api/src/main/java/com/yeejoin/amos/boot/module/common/api/enums/TitleEnum.java
0 → 100644
View file @
44686417
package
com
.
yeejoin
.
amos
.
boot
.
module
.
common
.
api
.
enums
;
/**
* @Author: Xing Lei
* @Description:
* @Date: 2020/4/7 13:50
*/
public
enum
TitleEnum
{
NUMBER
(
"序号"
,
"number"
),
FIRE_TEAM
(
"消防队伍"
,
"teamName"
),
USER_ID
(
"用户ID"
,
"userId"
),
USER_NAME
(
"姓名"
,
"userName"
),
POST
(
"岗位"
,
"post"
),
CAR
(
"车辆"
,
"carName"
),
ARRANGE
(
"班次"
,
"arrange"
);
TitleEnum
(
String
name
,
String
key
)
{
this
.
name
=
name
;
this
.
key
=
key
;
}
private
String
name
;
private
String
key
;
public
String
getName
()
{
return
name
;
}
public
String
getKey
()
{
return
key
;
}
}
amos-boot-module/amos-boot-module-api/amos-boot-module-common-api/src/main/java/com/yeejoin/amos/boot/module/common/api/excel/ExcelStyleUtil.java
0 → 100644
View file @
44686417
package
com
.
yeejoin
.
amos
.
boot
.
module
.
common
.
api
.
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-common-api/src/main/java/com/yeejoin/amos/boot/module/common/api/excel/ExcelUtil.java
View file @
44686417
...
@@ -4,17 +4,23 @@ import java.io.IOException;
...
@@ -4,17 +4,23 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.io.OutputStream
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Field
;
import
java.net.URLEncoder
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.*
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.poi.ss.usermodel.BorderStyle
;
import
cn.afterturn.easypoi.excel.ExcelExportUtil
;
import
org.apache.poi.ss.usermodel.HorizontalAlignment
;
import
cn.afterturn.easypoi.excel.entity.ExportParams
;
import
org.apache.poi.ss.usermodel.IndexedColors
;
import
cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity
;
import
org.apache.poi.ss.usermodel.VerticalAlignment
;
import
com.alibaba.excel.annotation.ExcelProperty
;
import
com.yeejoin.amos.boot.biz.common.utils.DateUtils
;
import
com.yeejoin.amos.boot.module.common.api.enums.TitleEnum
;
import
org.apache.poi.hssf.usermodel.DVConstraint
;
import
org.apache.poi.hssf.usermodel.HSSFDataValidation
;
import
org.apache.poi.ss.formula.functions.T
;
import
org.apache.poi.ss.usermodel.*
;
import
org.apache.poi.ss.util.CellRangeAddressList
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
com.alibaba.excel.EasyExcel
;
import
com.alibaba.excel.EasyExcel
;
...
@@ -24,9 +30,11 @@ import com.alibaba.excel.support.ExcelTypeEnum;
...
@@ -24,9 +30,11 @@ import com.alibaba.excel.support.ExcelTypeEnum;
import
com.alibaba.excel.write.metadata.style.WriteCellStyle
;
import
com.alibaba.excel.write.metadata.style.WriteCellStyle
;
import
com.alibaba.excel.write.metadata.style.WriteFont
;
import
com.alibaba.excel.write.metadata.style.WriteFont
;
import
com.alibaba.excel.write.style.HorizontalCellStyleStrategy
;
import
com.alibaba.excel.write.style.HorizontalCellStyleStrategy
;
import
com.yeejoin.amos.boot.module.common.api.mapper.DataDictionaryMapper
;
public
class
ExcelUtil
{
public
class
ExcelUtil
{
private
static
final
Integer
DUTY_CAR_START_INDEX
=
5
;
/**
/**
* 生成excel模板
* 生成excel模板
*
*
...
@@ -39,24 +47,24 @@ public class ExcelUtil {
...
@@ -39,24 +47,24 @@ public class ExcelUtil {
*/
*/
public
static
void
createTemplate
(
HttpServletResponse
response
,
String
fileName
,
public
static
void
createTemplate
(
HttpServletResponse
response
,
String
fileName
,
String
sheetName
,
List
<?
extends
Object
>
data
,
String
sheetName
,
List
<?
extends
Object
>
data
,
Class
<?>
model
,
DataSources
dataDictionaryMapper
,
boolean
flag
)
{
Class
<?>
model
,
DataSources
dataDictionaryMapper
,
boolean
flag
)
{
HorizontalCellStyleStrategy
horizontalCellStyleStrategy
=
setMyCellStyle
();
HorizontalCellStyleStrategy
horizontalCellStyleStrategy
=
setMyCellStyle
();
try
{
try
{
//下拉列表集合
//下拉列表集合
Map
<
Integer
,
String
[]>
explicitListConstraintMap
=
new
HashMap
<>();
Map
<
Integer
,
String
[]>
explicitListConstraintMap
=
new
HashMap
<>();
if
(
flag
)
{
if
(
flag
)
{
//循环获取对应列得下拉列表信息
//循环获取对应列得下拉列表信息
Field
[]
declaredFields
=
model
.
getDeclaredFields
();
Field
[]
declaredFields
=
model
.
getDeclaredFields
();
for
(
int
i
=
0
;
i
<
declaredFields
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
declaredFields
.
length
;
i
++)
{
Field
field
=
declaredFields
[
i
];
Field
field
=
declaredFields
[
i
];
//解析注解信息
//解析注解信息
ExplicitConstraint
explicitConstraint
=
field
.
getAnnotation
(
ExplicitConstraint
.
class
);
ExplicitConstraint
explicitConstraint
=
field
.
getAnnotation
(
ExplicitConstraint
.
class
);
resolveExplicitConstraint
(
explicitListConstraintMap
,
explicitConstraint
,
dataDictionaryMapper
);
resolveExplicitConstraint
(
explicitListConstraintMap
,
explicitConstraint
,
dataDictionaryMapper
);
}
}
}
}
EasyExcel
.
write
(
getOutputStream
(
fileName
,
response
,
ExcelTypeEnum
.
XLSX
),
model
).
EasyExcel
.
write
(
getOutputStream
(
fileName
,
response
,
ExcelTypeEnum
.
XLSX
),
model
)
excelType
(
ExcelTypeEnum
.
XLSX
).
sheet
(
sheetName
)
.
excelType
(
ExcelTypeEnum
.
XLSX
).
sheet
(
sheetName
)
.
registerWriteHandler
(
new
TemplateCellWriteHandlerDate
(
explicitListConstraintMap
))
.
registerWriteHandler
(
new
TemplateCellWriteHandlerDate
(
explicitListConstraintMap
))
.
registerWriteHandler
(
new
TemplateCellWriteHandler
())
.
registerWriteHandler
(
new
TemplateCellWriteHandler
())
.
registerWriteHandler
(
horizontalCellStyleStrategy
)
.
registerWriteHandler
(
horizontalCellStyleStrategy
)
...
@@ -67,8 +75,73 @@ public class ExcelUtil {
...
@@ -67,8 +75,73 @@ public class ExcelUtil {
}
}
}
}
/**
* 生成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
{
//下拉列表集合
Map
<
Integer
,
String
[]>
explicitListConstraintMap
=
new
HashMap
<>();
List
<
List
<
String
>>
dutyCarTitleList
=
new
ArrayList
<>();
//循环获取对应列得下拉列表信息
Field
[]
declaredFields
=
model
.
getDeclaredFields
();
if
(
flag
)
{
for
(
int
i
=
0
;
i
<
declaredFields
.
length
;
i
++)
{
Field
field
=
declaredFields
[
i
];
//解析注解信息
ExplicitConstraint
explicitConstraint
=
field
.
getAnnotation
(
ExplicitConstraint
.
class
);
resolveExplicitConstraint
(
explicitListConstraintMap
,
explicitConstraint
,
dataDictionaryMapper
);
}
}
// 组装表头
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
++)
{
explicitListConstraintMap
.
put
(
size
+
i
,
dutyNameList
);
ArrayList
<
String
>
dutyDay
=
new
ArrayList
<>();
dutyDay
.
add
(
dayByMonth
.
get
(
i
));
dutyCarTitleList
.
add
(
dutyDay
);
}
}
EasyExcel
.
write
(
getOutputStream
(
fileName
,
response
,
ExcelTypeEnum
.
XLSX
)).
head
(
dutyCarTitleList
).
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(第一个 sheet) 指定行开始读取
* 读取 Excel(第一个 sheet) 指定行开始读取
*
* @param excel 文件
* @param excel 文件
* @param rowType 模板实体类
* @param rowType 模板实体类
* @param header 指定不读取的表头行数,
* @param header 指定不读取的表头行数,
...
@@ -76,7 +149,7 @@ public class ExcelUtil {
...
@@ -76,7 +149,7 @@ public class ExcelUtil {
* @return 集合数据
* @return 集合数据
* @throws Exception
* @throws Exception
*/
*/
public
static
<
T
>
List
<
T
>
readFirstSheetExcel
(
MultipartFile
excel
,
Class
<
T
>
rowType
,
int
header
)
throws
Exception
{
public
static
<
T
>
List
<
T
>
readFirstSheetExcel
(
MultipartFile
excel
,
Class
<
T
>
rowType
,
int
header
)
throws
Exception
{
ExcelReader
reader
=
getReader
(
excel
,
header
);
ExcelReader
reader
=
getReader
(
excel
,
header
);
if
(
reader
==
null
)
{
if
(
reader
==
null
)
{
return
new
ArrayList
<>();
return
new
ArrayList
<>();
...
@@ -85,9 +158,9 @@ public class ExcelUtil {
...
@@ -85,9 +158,9 @@ public class ExcelUtil {
}
}
/**
/**
* 读取 Excel(多个 sheet)
* 读取 Excel(多个 sheet)
*
* @param reader 读取的excel
* @param reader 读取的excel
* @param rowModel excel模板实体类
* @param rowModel excel模板实体类
* @param sheetCount sheet
* @param sheetCount sheet
...
@@ -108,16 +181,13 @@ public class ExcelUtil {
...
@@ -108,16 +181,13 @@ public class ExcelUtil {
}
}
/**
/**
*
* @param excel 需要解析的 Excel 文件
* @param excel 需要解析的 Excel 文件
* @param header 指定不读取表头行数,
* @param header 指定不读取表头行数,
* @return
* @return
* @throws Exception
* @throws Exception
*/
*/
public
static
ExcelReader
getReader
(
MultipartFile
excel
,
int
header
)
throws
Exception
{
public
static
ExcelReader
getReader
(
MultipartFile
excel
,
int
header
)
throws
Exception
{
String
fileName
=
excel
.
getOriginalFilename
();
String
fileName
=
excel
.
getOriginalFilename
();
if
(
fileName
==
null
)
{
if
(
fileName
==
null
)
{
throw
new
Exception
(
"文件不存在!"
);
throw
new
Exception
(
"文件不存在!"
);
...
@@ -138,13 +208,15 @@ public class ExcelUtil {
...
@@ -138,13 +208,15 @@ public class ExcelUtil {
}
}
/**
/**
* 解析注解内容 获取下列表信息
* 解析注解内容 获取下列表信息
*
* @param explicitConstraint
* @param explicitConstraint
* @return
* @return
*/
*/
public
static
Map
<
Integer
,
String
[]>
resolveExplicitConstraint
(
Map
<
Integer
,
String
[]>
explicitListConstraintMap
,
ExplicitConstraint
explicitConstraint
,
DataSources
dataDictionaryMapper
){
public
static
Map
<
Integer
,
String
[]>
resolveExplicitConstraint
(
Map
<
Integer
,
String
[]>
explicitListConstraintMap
,
ExplicitConstraint
explicitConstraint
,
DataSources
dataDictionaryMapper
)
{
if
(
explicitConstraint
==
null
)
{
if
(
explicitConstraint
==
null
)
{
return
null
;
return
null
;
}
}
...
@@ -155,12 +227,13 @@ public class ExcelUtil {
...
@@ -155,12 +227,13 @@ public class ExcelUtil {
}
}
//动态下拉信息
//动态下拉信息
Class
<?
extends
ExplicitInterface
>[]
classes
=
explicitConstraint
.
sourceClass
();
Class
<?
extends
ExplicitInterface
>[]
classes
=
explicitConstraint
.
sourceClass
();
if
(
classes
.
length
>
0
)
{
if
(
classes
.
length
>
0
)
{
ExplicitInterface
explicitInterface
=
null
;
ExplicitInterface
explicitInterface
=
null
;
try
{
try
{
explicitInterface
=
classes
[
0
].
newInstance
();
explicitInterface
=
classes
[
0
].
newInstance
();
String
[]
source1
=
explicitInterface
.
source
(
explicitConstraint
.
type
(),
explicitConstraint
.
method
(),
dataDictionaryMapper
);
String
[]
source1
=
explicitInterface
.
source
(
explicitConstraint
.
type
(),
explicitConstraint
.
method
(),
if
(
source1
.
length
>
0
){
dataDictionaryMapper
);
if
(
source1
.
length
>
0
)
{
explicitListConstraintMap
.
put
(
explicitConstraint
.
indexNum
(),
source1
);
explicitListConstraintMap
.
put
(
explicitConstraint
.
indexNum
(),
source1
);
}
}
}
catch
(
InstantiationException
e
)
{
}
catch
(
InstantiationException
e
)
{
...
@@ -175,12 +248,11 @@ public class ExcelUtil {
...
@@ -175,12 +248,11 @@ public class ExcelUtil {
}
}
/**
/**
* 导出文件时为Writer生成OutputStream
* 导出文件时为Writer生成OutputStream
*/
*/
private
static
OutputStream
getOutputStream
(
String
fileName
,
HttpServletResponse
response
,
ExcelTypeEnum
excelTypeEnum
)
throws
Exception
{
private
static
OutputStream
getOutputStream
(
String
fileName
,
HttpServletResponse
response
,
ExcelTypeEnum
excelTypeEnum
)
throws
Exception
{
//创建本地文件
//创建本地文件
String
filePath
=
fileName
+
excelTypeEnum
.
getValue
();
String
filePath
=
fileName
+
excelTypeEnum
.
getValue
();
try
{
try
{
...
@@ -218,7 +290,8 @@ public class ExcelUtil {
...
@@ -218,7 +290,8 @@ public class ExcelUtil {
// // 设置内容靠中对齐
// // 设置内容靠中对齐
// contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
// contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
// // 这个策略是 头是头的样式 内容是内容的样式 其他的策略可以自己实现
// // 这个策略是 头是头的样式 内容是内容的样式 其他的策略可以自己实现
// HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
// HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy
// (headWriteCellStyle, contentWriteCellStyle);
// // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
// // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
// return horizontalCellStyleStrategy;
// return horizontalCellStyleStrategy;
...
@@ -258,9 +331,5 @@ public class ExcelUtil {
...
@@ -258,9 +331,5 @@ public class ExcelUtil {
contentWriteCellStyle
.
setBorderBottom
(
BorderStyle
.
THIN
);
contentWriteCellStyle
.
setBorderBottom
(
BorderStyle
.
THIN
);
return
new
HorizontalCellStyleStrategy
(
headWriteCellStyle
,
contentWriteCellStyle
);
return
new
HorizontalCellStyleStrategy
(
headWriteCellStyle
,
contentWriteCellStyle
);
}
}
}
}
amos-boot-module/amos-boot-module-api/amos-boot-module-jcs-api/src/main/java/com/yeejoin/amos/boot/module/jcs/api/enums/ExcelEnums.java
View file @
44686417
...
@@ -11,4 +11,5 @@ public class ExcelEnums {
...
@@ -11,4 +11,5 @@ public class ExcelEnums {
public
static
final
String
XFDW
=
"XFDW"
;
//("XFDW","消防队伍")
public
static
final
String
XFDW
=
"XFDW"
;
//("XFDW","消防队伍")
public
static
final
String
WXXFZ
=
"WXXFZ"
;
//("WXXFZ","微型消防站")
public
static
final
String
WXXFZ
=
"WXXFZ"
;
//("WXXFZ","微型消防站")
public
static
final
String
XFRY
=
"XFRY"
;
//("XFRY","消防人员")
public
static
final
String
XFRY
=
"XFRY"
;
//("XFRY","消防人员")
public
static
final
String
CLZQ
=
"CLZQ"
;
//("CLZQ","车辆执勤")
}
}
amos-boot-module/amos-boot-module-biz/amos-boot-module-common-biz/src/main/java/com/yeejoin/amos/boot/module/common/biz/utils/DateUtils.java
0 → 100644
View file @
44686417
package
com
.
yeejoin
.
amos
.
boot
.
module
.
common
.
biz
.
utils
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
/**
* @title: DateUtils
* @Author fpy
* @Date: 2021/7/8 14:58
* @Version 1.0
*/
public
class
DateUtils
{
private
static
final
SimpleDateFormat
shortSdf
=
new
SimpleDateFormat
(
"yyyy/M/d"
);
private
static
final
Calendar
calendar
=
Calendar
.
getInstance
();
/**
* 获取某月的日期List
*
* @param yearParam
* @param monthParam
* @return
*/
public
static
List
<
String
>
getDayByMonth
(
int
yearParam
,
int
monthParam
)
{
List
list
=
new
ArrayList
();
Calendar
aCalendar
=
Calendar
.
getInstance
(
Locale
.
CHINA
);
aCalendar
.
set
(
yearParam
,
monthParam
-
1
,
1
);
int
year
=
aCalendar
.
get
(
Calendar
.
YEAR
);
//年份
int
month
=
aCalendar
.
get
(
Calendar
.
MONTH
)
+
1
;
//月份
int
day
=
aCalendar
.
getActualMaximum
(
Calendar
.
DATE
);
for
(
int
i
=
1
;
i
<=
day
;
i
++)
{
list
.
add
(
year
+
"/"
+
month
+
"/"
+
i
);
}
return
list
;
}
/**
* 获取某月的日期List
*
* @param dateStr
* @return
*/
public
static
List
<
Date
>
getDayByMonth
(
String
dateStr
)
{
List
list
=
new
ArrayList
();
Date
date
=
null
;
try
{
date
=
shortSdf
.
parse
(
dateStr
);
calendar
.
setTime
(
date
);
int
month
=
calendar
.
get
(
Calendar
.
MONTH
)
+
1
;
//月份
int
year
=
calendar
.
get
(
Calendar
.
YEAR
);
//年份
int
day
=
calendar
.
getActualMaximum
(
Calendar
.
DATE
);
for
(
int
i
=
1
;
i
<=
day
;
i
++)
{
list
.
add
(
year
+
"/"
+
month
+
"/"
+
i
);
}
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
return
list
;
}
/**
* 日期返回Date类型
*
* @param dateStr
* @return
*/
public
static
int
strToDateShort
(
String
dateStr
)
{
try
{
Date
date
=
shortSdf
.
parse
(
dateStr
);
calendar
.
setTime
(
date
);
int
month
=
calendar
.
get
(
Calendar
.
MONTH
)
+
1
;
return
month
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
0
;
}
}
\ No newline at end of file
amos-boot-module/amos-boot-module-biz/amos-boot-module-jcs-biz/src/main/java/com/yeejoin/amos/boot/module/jcs/biz/controller/ExcelController.java
View file @
44686417
package
com
.
yeejoin
.
amos
.
boot
.
module
.
jcs
.
biz
.
controller
;
package
com
.
yeejoin
.
amos
.
boot
.
module
.
jcs
.
biz
.
controller
;
import
java.util.ArrayList
;
import
java.io.InputStream
;
import
java.util.List
;
import
java.util.*
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
com.alibaba.excel.support.ExcelTypeEnum
;
import
com.yeejoin.amos.boot.biz.common.feign.AmosFeignService
;
import
com.yeejoin.amos.boot.biz.common.utils.MenuFrom
;
import
com.yeejoin.amos.boot.module.common.api.dto.*
;
import
com.yeejoin.amos.boot.module.common.api.dto.*
;
import
com.yeejoin.amos.boot.module.common.api.entity.*
;
import
com.yeejoin.amos.boot.module.common.api.entity.*
;
import
com.yeejoin.amos.boot.module.common.api.enums.TitleEnum
;
import
com.yeejoin.amos.boot.module.common.biz.service.impl.*
;
import
com.yeejoin.amos.boot.module.common.biz.service.impl.*
;
import
com.yeejoin.amos.boot.module.common.biz.utils.DateUtils
;
import
com.yeejoin.amos.boot.module.jcs.api.entity.Aircraft
;
import
com.yeejoin.amos.boot.module.jcs.api.entity.Aircraft
;
import
com.yeejoin.amos.boot.module.jcs.biz.service.impl.EquipmentServiceImpl
;
import
com.yeejoin.amos.boot.module.jcs.biz.service.impl.FireTeamServiceImpl
;
import
com.yeejoin.amos.boot.module.jcs.biz.service.impl.FireTeamServiceImpl
;
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.Row
;
import
org.apache.poi.ss.usermodel.Workbook
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.typroject.tyboot.core.foundation.enumeration.UserType
;
import
org.typroject.tyboot.core.foundation.enumeration.UserType
;
import
org.typroject.tyboot.core.foundation.utils.Bean
;
import
org.typroject.tyboot.core.foundation.utils.Bean
;
...
@@ -57,6 +68,16 @@ public class ExcelController extends BaseController {
...
@@ -57,6 +68,16 @@ public class ExcelController extends BaseController {
FireStationServiceImpl
fireStationService
;
FireStationServiceImpl
fireStationService
;
@Autowired
@Autowired
FirefightersServiceImpl
firefightersService
;
FirefightersServiceImpl
firefightersService
;
@Autowired
DutyCarServiceImpl
dutyCarService
;
@Autowired
AmosFeignService
amosFeignService
;
@Autowired
EquipmentServiceImpl
equipmentService
;
@Autowired
DutyShiftServiceImpl
dutyShiftService
;
@Autowired
DutyCommonServiceImpl
dutyCommonServiceImpl
;
@TycloudOperation
(
needAuth
=
false
,
ApiLevel
=
UserType
.
AGENCY
)
@TycloudOperation
(
needAuth
=
false
,
ApiLevel
=
UserType
.
AGENCY
)
...
@@ -151,6 +172,10 @@ public class ExcelController extends BaseController {
...
@@ -151,6 +172,10 @@ public class ExcelController extends BaseController {
case
ExcelEnums
.
XFRY
:
case
ExcelEnums
.
XFRY
:
excelImportFirefighters
(
multipartFile
);
excelImportFirefighters
(
multipartFile
);
break
;
break
;
case
ExcelEnums
.
CLZQ
:
excelImportDutyCar
(
multipartFile
);
break
;
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
@@ -158,6 +183,82 @@ public class ExcelController extends BaseController {
...
@@ -158,6 +183,82 @@ public class ExcelController extends BaseController {
}
}
}
}
private
void
excelImportDutyCar
(
MultipartFile
multipartFile
)
throws
Exception
{
String
fileName
=
multipartFile
.
getOriginalFilename
();
if
(
fileName
==
null
)
{
throw
new
Exception
(
"文件不存在!"
);
}
if
(!
fileName
.
toLowerCase
().
endsWith
(
ExcelTypeEnum
.
XLS
.
getValue
())
&&
!
fileName
.
toLowerCase
().
endsWith
(
ExcelTypeEnum
.
XLSX
.
getValue
()))
{
throw
new
Exception
(
"文件类型异常!"
);
}
InputStream
input
=
multipartFile
.
getInputStream
();
HSSFWorkbook
xssfWorkbook
=
new
HSSFWorkbook
(
input
);
HSSFSheet
sheet
=
xssfWorkbook
.
getSheetAt
(
0
);
List
<
Map
<
String
,
Object
>>
dataList
=
new
ArrayList
<>();
if
(
sheet
!=
null
)
{
//获取表头月份
String
dateStr
=
""
;
Row
titleRow
=
sheet
.
getRow
(
0
);
Cell
monthCell
=
titleRow
.
getCell
(
5
);
dateStr
=
monthCell
==
null
?
""
:
monthCell
.
toString
();
List
<
Date
>
dayByMonth
=
DateUtils
.
getDayByMonth
(
dateStr
);
initDutyCarData
(
sheet
,
dataList
,
dayByMonth
);
}
dutyCommonServiceImpl
.
saveImportData
(
dataList
);
}
private
void
initDutyCarData
(
HSSFSheet
sheet
,
List
<
Map
<
String
,
Object
>>
dataList
,
List
<
Date
>
dayByMonth
)
{
//遍历行,i = 1,从第二行开始,第一行是表头跳过。
for
(
int
i
=
1
;
i
<
sheet
.
getPhysicalNumberOfRows
();
i
++)
{
DutyCarDto
dutyCarDto
=
new
DutyCarDto
();
//row是一行数据,row.getCell(i),代表拿到这一行,第i列数据
Row
row
=
sheet
.
getRow
(
i
);
if
(
row
==
null
)
{
continue
;
}
Cell
cell
=
null
;
cell
=
row
.
getCell
(
1
);
if
(
cell
!=
null
)
{
String
[]
split
=
cell
.
toString
().
split
(
"@"
);
dutyCarDto
.
setTeamName
(
split
[
0
]);
dutyCarDto
.
setTeamId
(
split
[
1
]);
}
cell
=
row
.
getCell
(
2
);
if
(
cell
!=
null
)
{
String
[]
split
=
cell
.
toString
().
split
(
"@"
);
dutyCarDto
.
setUserName
(
split
[
0
]);
dutyCarDto
.
setUserId
(
split
[
1
]);
}
cell
=
row
.
getCell
(
3
);
if
(
cell
!=
null
)
{
String
[]
split
=
cell
.
toString
().
split
(
"@"
);
dutyCarDto
.
setPostTypeName
(
split
[
0
]);
dutyCarDto
.
setPostType
(
split
[
1
]);
}
cell
=
row
.
getCell
(
4
);
if
(
cell
!=
null
)
{
String
[]
split
=
cell
.
toString
().
split
(
"@"
);
dutyCarDto
.
setCarName
(
split
[
0
]);
dutyCarDto
.
setCarId
(
split
[
1
]);
}
List
<
DutyPersonShiftDto
>
dutyShift
=
dutyCarDto
.
getDutyShift
();
for
(
int
j
=
0
;
j
<
dayByMonth
.
size
();
j
++)
{
cell
=
row
.
getCell
(
4
+
j
);
String
dutyType
=
cell
==
null
?
""
:
cell
.
toString
();
if
(!
StringUtils
.
isEmpty
(
dutyType
))
{
DutyPersonShiftDto
dutyPersonShiftDto
=
new
DutyPersonShiftDto
();
dutyPersonShiftDto
.
setDutyDate
(
dayByMonth
.
get
(
j
));
dutyPersonShiftDto
.
setShiftId
(
Long
.
valueOf
(
dutyType
.
split
(
"@"
)[
1
]));
dutyShift
.
add
(
dutyPersonShiftDto
);
}
}
Map
<
String
,
Object
>
dutyCarDtoMap
=
Bean
.
BeantoMap
(
dutyCarDto
);
dataList
.
add
(
dutyCarDtoMap
);
}
}
private
void
excelImportFirefighters
(
MultipartFile
multipartFile
)
throws
Exception
{
private
void
excelImportFirefighters
(
MultipartFile
multipartFile
)
throws
Exception
{
List
<
FirefightersExcelDto
>
excelDtoList
=
ExcelUtil
.
readFirstSheetExcel
(
multipartFile
,
List
<
FirefightersExcelDto
>
excelDtoList
=
ExcelUtil
.
readFirstSheetExcel
(
multipartFile
,
FirefightersExcelDto
.
class
,
1
);
FirefightersExcelDto
.
class
,
1
);
...
@@ -390,5 +491,45 @@ public class ExcelController extends BaseController {
...
@@ -390,5 +491,45 @@ public class ExcelController extends BaseController {
fireExpertsServiceImpl
.
saveBatch
(
excelEntityList
);
fireExpertsServiceImpl
.
saveBatch
(
excelEntityList
);
}
}
@TycloudOperation
(
needAuth
=
false
,
ApiLevel
=
UserType
.
AGENCY
)
@ApiOperation
(
value
=
"导出值班模板"
,
notes
=
"导出值班模板"
)
@GetMapping
(
value
=
"/duty_car_template/{year}/{month}"
)
public
void
dutyCarTemplate
(
HttpServletResponse
response
,
@PathVariable
(
"year"
)
int
year
,
@PathVariable
(
"month"
)
int
month
,
ExcelDto
excelDto
,
@RequestParam
(
value
=
"orgCode"
,
required
=
false
)
String
orgCode
)
{
try
{
List
<
Map
<
String
,
Object
>>
contentList
=
new
ArrayList
<>();
// 根据id列表获取队伍下的人
List
<
DutyCarDto
>
orgTeam
=
new
ArrayList
<>();
if
(!
orgTeam
.
isEmpty
())
{
AtomicInteger
row
=
new
AtomicInteger
(
1
);
orgTeam
.
forEach
(
o
->
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
TitleEnum
.
NUMBER
.
getKey
(),
""
+
(
row
.
getAndIncrement
()));
map
.
put
(
TitleEnum
.
FIRE_TEAM
.
getKey
(),
o
.
getTeamName
());
map
.
put
(
TitleEnum
.
USER_NAME
.
getKey
(),
o
.
getUserName
());
map
.
put
(
TitleEnum
.
POST
.
getKey
(),
o
.
getPostTypeName
());
contentList
.
add
(
map
);
});
}
// 获取日期
List
<
String
>
dayByMonth
=
DateUtils
.
getDayByMonth
(
year
,
month
);
// 获取排班类型
String
[]
dutyNameList
=
getDutyNameList
();
ExcelUtil
.
createDutyTemplate
(
response
,
excelDto
.
getFileName
(),
excelDto
.
getSheetName
(),
contentList
,
DutyCarExcelDto
.
class
,
dayByMonth
,
dutyNameList
,
dataSourcesImpl
,
true
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
(
"系统异常!"
);
}
}
private
String
[]
getDutyNameList
()
{
List
<
String
>
dutyShiftList
=
new
ArrayList
<>();
List
<
DutyShiftDto
>
dutyShiftDtoList
=
dutyShiftService
.
queryForDutyShiftList
();
dutyShiftDtoList
.
forEach
(
item
->
dutyShiftList
.
add
(
item
.
getName
()
+
"@"
+
item
.
getSequenceNbr
()));
String
[]
dutyNameList
=
dutyShiftList
.
toArray
(
new
String
[
dutyShiftList
.
size
()]);
return
dutyNameList
;
}
}
}
amos-boot-module/amos-boot-module-biz/amos-boot-module-jcs-biz/src/main/java/com/yeejoin/amos/boot/module/jcs/biz/service/impl/DataSourcesImpl.java
View file @
44686417
...
@@ -3,6 +3,7 @@ package com.yeejoin.amos.boot.module.jcs.biz.service.impl;
...
@@ -3,6 +3,7 @@ package com.yeejoin.amos.boot.module.jcs.biz.service.impl;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.google.common.collect.Lists
;
import
com.yeejoin.amos.boot.biz.common.utils.MenuFrom
;
import
com.yeejoin.amos.boot.biz.common.utils.MenuFrom
;
import
com.yeejoin.amos.boot.module.common.api.dto.FireTeamCardDto
;
import
com.yeejoin.amos.boot.module.common.api.dto.FireTeamCardDto
;
import
com.yeejoin.amos.boot.module.common.api.dto.FireTeamListDto
;
import
com.yeejoin.amos.boot.module.common.api.dto.FireTeamListDto
;
...
@@ -16,16 +17,19 @@ import com.yeejoin.amos.boot.module.common.api.excel.DataSources;
...
@@ -16,16 +17,19 @@ import com.yeejoin.amos.boot.module.common.api.excel.DataSources;
import
com.yeejoin.amos.boot.module.common.api.mapper.DataDictionaryMapper
;
import
com.yeejoin.amos.boot.module.common.api.mapper.DataDictionaryMapper
;
import
com.yeejoin.amos.boot.module.common.biz.service.impl.FirefightersServiceImpl
;
import
com.yeejoin.amos.boot.module.common.biz.service.impl.FirefightersServiceImpl
;
import
com.yeejoin.amos.boot.module.common.biz.service.impl.OrgUsrServiceImpl
;
import
com.yeejoin.amos.boot.module.common.biz.service.impl.OrgUsrServiceImpl
;
import
com.yeejoin.amos.boot.module.jcs.api.feign.EquipFeignClient
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
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.http.*
;
import
org.springframework.http.*
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.client.RestTemplate
;
import
org.typroject.tyboot.core.restful.utils.ResponseModel
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
@Service
@Service
...
@@ -41,6 +45,8 @@ public class DataSourcesImpl implements DataSources {
...
@@ -41,6 +45,8 @@ public class DataSourcesImpl implements DataSources {
FirefightersServiceImpl
firefightersService
;
FirefightersServiceImpl
firefightersService
;
@Autowired
@Autowired
FireTeamServiceImpl
fireTeamService
;
FireTeamServiceImpl
fireTeamService
;
@Autowired
EquipFeignClient
equipFeignClient
;
@Autowired
@Autowired
...
@@ -94,11 +100,26 @@ public class DataSourcesImpl implements DataSources {
...
@@ -94,11 +100,26 @@ public class DataSourcesImpl implements DataSources {
break
;
break
;
case
"getMaritalStatus"
:
case
"getMaritalStatus"
:
str
=
ExcelSelectData
.
MARITAL_STATUS
;
str
=
ExcelSelectData
.
MARITAL_STATUS
;
break
;
case
"getCarList"
:
str
=
getCarList
();
break
;
}
}
}
}
return
str
;
return
str
;
}
}
private
String
[]
getCarList
()
{
ResponseModel
<
Object
>
response
=
equipFeignClient
.
getFireCarListAll
();
List
<
Map
<
String
,
Object
>>
carList
=
(
List
<
Map
<
String
,
Object
>>)
response
.
getResult
();
List
<
String
>
carNameList
=
Lists
.
newArrayList
();
carList
.
forEach
(
car
->
{
carNameList
.
add
(
car
.
get
(
"name"
)
+
"("
+
car
.
get
(
"carNum"
)
+
")"
+
"@"
+
car
.
get
(
"id"
));
});
String
[]
str
=
carNameList
.
toArray
(
new
String
[
carNameList
.
size
()]);
return
str
;
}
private
String
[]
getFireTeam
()
{
private
String
[]
getFireTeam
()
{
Page
<
FireTeamCardDto
>
pageBean
=
new
Page
<>(
1
,
Integer
.
MAX_VALUE
);
Page
<
FireTeamCardDto
>
pageBean
=
new
Page
<>(
1
,
Integer
.
MAX_VALUE
);
IPage
<
FireTeamCardDto
>
fireTeamCardDtoIPage
=
fireTeamService
.
listFireTeamByPage
(
pageBean
,
IPage
<
FireTeamCardDto
>
fireTeamCardDtoIPage
=
fireTeamService
.
listFireTeamByPage
(
pageBean
,
...
...
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