Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
ioc_sixiang_license
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zengtianlai3
ioc_sixiang_license
Commits
3316d7f1
Commit
3316d7f1
authored
Jun 10, 2022
by
zengtianlai3
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Excel表格导出功能
parent
f657c7e0
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
153 additions
and
3 deletions
+153
-3
pom.xml
license/pom.xml
+6
-0
AlarmController.java
.../java/iot/sixiang/license/controller/AlarmController.java
+3
-1
AlarmReadController.java
...a/iot/sixiang/license/controller/AlarmReadController.java
+3
-2
ResourceContrller.java
...ava/iot/sixiang/license/controller/ResourceContrller.java
+31
-0
ResourceMnnager.java
...in/java/iot/sixiang/license/resource/ResourceMnnager.java
+110
-0
No files found.
license/pom.xml
View file @
3316d7f1
...
...
@@ -70,6 +70,12 @@
<artifactId>
fastjson
</artifactId>
<version>
1.2.28
</version>
</dependency>
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi
</artifactId>
<version>
3.17
</version>
</dependency>
</dependencies>
...
...
license/src/main/java/iot/sixiang/license/controller/AlarmController.java
View file @
3316d7f1
...
...
@@ -25,7 +25,9 @@ public class AlarmController {
private
AlarmService
alarmService
;
@GetMapping
(
"list"
)
public
ResResult
getAlarmList
(
@RequestParam
(
value
=
"userId"
,
defaultValue
=
"0"
)
int
userId
)
{
// public ResResult getAlarmList(@RequestParam(value = "userId", defaultValue = "0") int userId) {
public
ResResult
getAlarmList
()
{
int
userId
=
2147483647
;
List
<
AlarmVo
>
alarmList
=
alarmService
.
getAlarmList
(
userId
);
return
ResResult
.
success
().
record
(
alarmList
);
}
...
...
license/src/main/java/iot/sixiang/license/controller/AlarmReadController.java
View file @
3316d7f1
...
...
@@ -26,8 +26,9 @@ public class AlarmReadController {
private
AlarmReadService
alarmReadService
;
@PostMapping
(
"read"
)
public
BaseResult
readAlarm
(
@RequestBody
JSONObject
jsonObject
){
int
userId
=
jsonObject
.
getIntValue
(
"userId"
);
public
BaseResult
readAlarm
(){
// int userId = jsonObject.getIntValue("userId");
int
userId
=
2147483647
;
boolean
res
=
alarmReadService
.
readAlarm
(
userId
);
if
(
res
)
{
return
BaseResult
.
success
();
...
...
license/src/main/java/iot/sixiang/license/controller/ResourceContrller.java
0 → 100644
View file @
3316d7f1
package
iot
.
sixiang
.
license
.
controller
;
import
iot.sixiang.license.resource.ResourceMnnager
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
@RestController
@RequestMapping
(
"/iot_license/resource"
)
public
class
ResourceContrller
{
@Autowired
ResourceMnnager
resourceMnnager
;
@GetMapping
(
"/download"
)
public
void
downloadWorkHourRecordTemplate
(
HttpServletResponse
response
,
@RequestParam
(
value
=
"userId"
)
int
userId
)
{
try
{
resourceMnnager
.
downloadDeviceInfoExcle
(
response
,
userId
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
license/src/main/java/iot/sixiang/license/resource/ResourceMnnager.java
0 → 100644
View file @
3316d7f1
package
iot
.
sixiang
.
license
.
resource
;
import
iot.sixiang.license.model.vo.ResourceVo
;
import
iot.sixiang.license.service.ResourceService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.poi.hssf.usermodel.*
;
import
org.apache.poi.ss.usermodel.HorizontalAlignment
;
import
org.apache.poi.ss.util.CellRangeAddress
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.util.List
;
@Component
@Slf4j
public
class
ResourceMnnager
{
@Autowired
ResourceService
resourceService
;
public
void
downloadDeviceInfoExcle
(
HttpServletResponse
response
,
int
userId
)
throws
IOException
{
OutputStream
os
=
null
;
HSSFWorkbook
wb
=
null
;
try
{
String
filename
=
"用户设备信息表.xls"
;
os
=
response
.
getOutputStream
();
// response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(filename, "UTF-8"));
response
.
setContentType
(
"application/x-zip-compressed;charset=UTF-8"
);
// 修改后
String
name
=
new
String
(
filename
.
getBytes
(
"utf-8"
),
"iso-8859-1"
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename = "
+
name
);
String
sheetName
=
"用户设备信息表"
;
//第一步创建workbook
wb
=
new
HSSFWorkbook
();
//第二步创建sheet
HSSFSheet
sheet
=
wb
.
createSheet
();
//第三步创建行row:添加表头0行
//4个参数依次为:开始行,结束行,开始列,结束列
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
0
,
0
,
0
,
5
));
HSSFRow
row
=
sheet
.
createRow
(
0
);
HSSFCell
cell1
=
row
.
createCell
(
0
);
cell1
.
setCellValue
(
"用户设备信息表"
);
HSSFCellStyle
style
=
wb
.
createCellStyle
();
style
.
setAlignment
(
HorizontalAlignment
.
CENTER
);
//居中
HSSFRow
row1
=
sheet
.
createRow
(
1
);
//第四步创建单元格
HSSFCell
cell
=
row1
.
createCell
(
0
);
//第一个单元格
cell
.
setCellValue
(
"用户"
);
//设定值
cell
.
setCellStyle
(
style
);
//内容居中
cell
=
row1
.
createCell
(
1
);
//第二个单元格
cell
.
setCellValue
(
"密码"
);
cell
.
setCellStyle
(
style
);
cell
=
row1
.
createCell
(
2
);
//第三个单元格
cell
.
setCellValue
(
"公司名称"
);
cell
.
setCellStyle
(
style
);
cell
=
row1
.
createCell
(
3
);
//第四个单元格
cell
.
setCellValue
(
"应用名称"
);
cell
.
setCellStyle
(
style
);
cell
=
row1
.
createCell
(
4
);
//第五个单元格
cell
.
setCellValue
(
"appKey"
);
cell
.
setCellStyle
(
style
);
cell
=
row1
.
createCell
(
5
);
//第六个单元格
cell
.
setCellValue
(
"SN"
);
cell
.
setCellStyle
(
style
);
//第五步插入数据
List
<
ResourceVo
>
resourceList
=
resourceService
.
getResource
(
userId
);
for
(
int
i
=
0
;
i
<
resourceList
.
size
();
i
++)
{
ResourceVo
resourceVo
=
resourceList
.
get
(
i
);
//创建行
row
=
sheet
.
createRow
(
i
+
2
);
//创建单元格并且添加数据
row
.
createCell
(
0
).
setCellValue
(
resourceVo
.
getUserName
());
row
.
createCell
(
1
).
setCellValue
(
resourceVo
.
getPassword
());
row
.
createCell
(
2
).
setCellValue
(
resourceVo
.
getCompany
());
row
.
createCell
(
3
).
setCellValue
(
resourceVo
.
getAppName
());
row
.
createCell
(
4
).
setCellValue
(
resourceVo
.
getAppKey
());
row
.
createCell
(
5
).
setCellValue
(
resourceVo
.
getSn
());
}
wb
.
write
(
os
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
os
!=
null
)
{
os
.
close
();
}
if
(
wb
!=
null
)
{
wb
.
close
();
}
}
}
}
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