Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
T
tianjin-cement
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
竹天卫
tianjin-cement
Commits
62fa9a5a
Commit
62fa9a5a
authored
Oct 11, 2020
by
qinhu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
报告-导出
parent
f3cce5c9
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
796 additions
and
15 deletions
+796
-15
pom.xml
cement-business/pom.xml
+13
-1
ReportController.java
.../wise/sc/cement/business/controller/ReportController.java
+45
-10
EntrustServiceImpl.java
...e/sc/cement/business/service/impl/EntrustServiceImpl.java
+4
-4
WordUtil.java
...c/main/java/cn/wise/sc/cement/business/util/WordUtil.java
+94
-0
report.ftl
cement-business/src/main/resources/templates/report.ftl
+637
-0
report1.ftl
cement-business/src/main/resources/templates/report1.ftl
+3
-0
No files found.
cement-business/pom.xml
View file @
62fa9a5a
...
...
@@ -97,7 +97,11 @@
<artifactId>
hutool-all
</artifactId>
<version>
4.6.8
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.freemarker/freemarker -->
<dependency>
<groupId>
org.freemarker
</groupId>
<artifactId>
freemarker
</artifactId>
</dependency>
<!-- JwtUtil类需要jjwt -->
<dependency>
<groupId>
io.jsonwebtoken
</groupId>
...
...
@@ -163,6 +167,14 @@
<include>
*
</include>
</includes>
</resource>
<resource>
<directory>
src/main/resources/templates
</directory>
<filtering>
true
</filtering>
<includes>
<include>
*
</include>
</includes>
<targetPath>
/templates
</targetPath>
</resource>
<resource>
<directory>
src/main/java/cn/wise/sc/cement/business/mapper/xml
</directory>
<filtering>
true
</filtering>
...
...
cement-business/src/main/java/cn/wise/sc/cement/business/controller/ReportController.java
View file @
62fa9a5a
package
cn
.
wise
.
sc
.
cement
.
business
.
controller
;
import
cn.wise.sc.cement.business.entity.EntrustReport
;
import
cn.wise.sc.cement.business.model.BaseResponse
;
import
cn.wise.sc.cement.business.model.PageQuery
;
import
cn.wise.sc.cement.business.model.ReportDetailVo
;
import
cn.wise.sc.cement.business.model.vo.EntrustVo
;
import
cn.wise.sc.cement.business.service.IEntrustService
;
import
cn.wise.sc.cement.business.util.
Page
Util
;
import
cn.wise.sc.cement.business.util.
Word
Util
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
...
...
@@ -20,8 +18,10 @@ import org.springframework.web.bind.annotation.PathVariable;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Set
;
/**
* @description: 报告管理
...
...
@@ -39,6 +39,7 @@ public class ReportController {
public
ReportController
(
IEntrustService
iEntrustService
)
{
this
.
iEntrustService
=
iEntrustService
;
}
@ApiOperation
(
value
=
"报告分页列表"
)
...
...
@@ -74,14 +75,48 @@ public class ReportController {
@GetMapping
(
"/{entrustId}"
)
@ApiOperation
(
"获取报告详情"
)
public
BaseResponse
<
ReportDetailVo
>
getReportDetail
(
@PathVariable
(
"entrustId"
)
Integer
entrustId
,
PageQuery
pageQuery
)
{
public
void
getReportDetail
(
@PathVariable
(
"entrustId"
)
Integer
entrustId
,
HttpServletResponse
response
)
{
ReportDetailVo
rts
=
iEntrustService
.
getReportDetail
(
entrustId
);
if
(
rts
==
null
)
{
return
BaseResponse
.
errorMsg
(
"没找到相关数据!"
);
}
else
{
return
BaseResponse
.
okData
(
rts
);
Map
<
String
,
Object
>
beanParams
=
new
HashMap
<>();
beanParams
.
put
(
"sendName"
,
rts
.
getSendName
());
beanParams
.
put
(
"sender"
,
rts
.
getSender
());
beanParams
.
put
(
"sendDate"
,
rts
.
getSendDate
());
beanParams
.
put
(
"sampleNum"
,
rts
.
getSampleNum
());
beanParams
.
put
(
"sampleNames"
,
set2String
(
rts
.
getSampleNames
()));
beanParams
.
put
(
"teamNames"
,
set2String
(
rts
.
getTeamNames
()));
beanParams
.
put
(
"methodNames"
,
set2StringN
(
rts
.
getMethodNames
()));
beanParams
.
put
(
"equipmentNames"
,
set2StringN
(
rts
.
getEquipmentNames
()));
beanParams
.
put
(
"projectName"
,
rts
.
getProjectName
());
beanParams
.
put
(
"printDate"
,
rts
.
getPrintDate
());
WordUtil
.
writeWordReport
(
rts
.
getProjectName
()
+
"(报告)"
,
"report.ftl"
,
beanParams
,
response
);
}
private
String
set2String
(
Set
<
String
>
source
)
{
if
(
source
.
size
()
==
0
)
{
return
""
;
}
StringBuilder
strBuilder
=
new
StringBuilder
();
for
(
String
target
:
source
)
{
strBuilder
.
append
(
"、"
).
append
(
target
);
}
return
strBuilder
.
replace
(
0
,
1
,
""
).
toString
();
}
private
String
set2StringN
(
Set
<
String
>
source
)
{
if
(
source
.
size
()
==
0
)
{
return
""
;
}
StringBuilder
strBuilder
=
new
StringBuilder
();
for
(
String
target
:
source
)
{
strBuilder
.
append
(
" "
).
append
(
target
);
}
return
strBuilder
.
replace
(
0
,
5
,
""
).
toString
();
}
}
cement-business/src/main/java/cn/wise/sc/cement/business/service/impl/EntrustServiceImpl.java
View file @
62fa9a5a
...
...
@@ -1917,7 +1917,7 @@ public class EntrustServiceImpl extends ServiceImpl<EntrustMapper, Entrust> impl
for
(
String
idStr
:
teamSplit
)
{
int
id
=
Integer
.
parseInt
(
idStr
);
teams
.
forEach
(
opt
->
{
if
(
opt
.
getId
()
==
id
)
{
if
(
opt
.
getId
()
==
id
&&
"1"
.
equals
(
opt
.
getQualifications
())
)
{
if
(
StrUtil
.
isBlank
(
arg
.
getTeamName
()))
{
arg
.
setTeamName
(
opt
.
getName
());
}
else
{
...
...
@@ -1929,9 +1929,9 @@ public class EntrustServiceImpl extends ServiceImpl<EntrustMapper, Entrust> impl
String
methodNumbers
=
arg
.
getMethodNumbers
();
String
[]
methodSplit
=
methodNumbers
.
split
(
"、"
);
for
(
String
idStr
:
methodSplit
)
{
int
id
=
Integer
.
parseInt
(
idStr
)
;
String
id
=
Integer
.
parseInt
(
idStr
)
+
""
;
methods
.
forEach
(
opt
->
{
if
(
opt
.
getId
()
==
id
)
{
if
(
id
.
equals
(
opt
.
getNumber
())
)
{
if
(
StrUtil
.
isBlank
(
arg
.
getMethodName
()))
{
arg
.
setMethodName
(
opt
.
getName
()
+
" "
+
opt
.
getStandard
());
}
else
{
...
...
@@ -2146,7 +2146,7 @@ public class EntrustServiceImpl extends ServiceImpl<EntrustMapper, Entrust> impl
}
//关联检测依据
if
(
StrUtil
.
isNotBlank
(
arg
.
getMethodName
()))
{
String
[]
methodSplits
=
arg
.
getMethodN
umbers
().
split
(
"、"
);
String
[]
methodSplits
=
arg
.
getMethodN
ame
().
split
(
"、"
);
for
(
String
methodName
:
methodSplits
)
{
rts
.
getMethodNames
().
add
(
methodName
);
}
...
...
cement-business/src/main/java/cn/wise/sc/cement/business/util/WordUtil.java
0 → 100644
View file @
62fa9a5a
package
cn
.
wise
.
sc
.
cement
.
business
.
util
;
import
freemarker.template.Configuration
;
import
freemarker.template.Template
;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.OutputStreamWriter
;
import
java.io.Writer
;
import
java.net.URLEncoder
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Map
;
/**
* @description:
* @author: qh
* @create: 2020-10-10 15:22
**/
public
class
WordUtil
{
/**
* 模板路径
*/
private
static
final
String
FTL_FP
=
"/templates/"
;
private
static
Configuration
configuration
;
static
{
configuration
=
new
Configuration
(
Configuration
.
DEFAULT_INCOMPATIBLE_IMPROVEMENTS
);
configuration
.
setDefaultEncoding
(
"utf-8"
);
//读配置文件
// path = PropertiesUtil.get("FILE_PATH")+"/";
}
public
static
Boolean
writeWordReport
(
String
templeName
,
String
templateFileName
,
Map
<
String
,
Object
>
beanParams
,
HttpServletResponse
response
)
{
Writer
out
=
null
;
File
file
=
null
;
try
{
configuration
.
setClassForTemplateLoading
(
WordUtil
.
class
,
FTL_FP
);
Template
template
=
configuration
.
getTemplate
(
templateFileName
,
"UTF-8"
);
//将文件输出到response,返回给客户端
String
filePath
;
filePath
=
""
;
File
file1
=
new
File
(
filePath
);
if
(!
file1
.
exists
())
{
file1
.
mkdirs
();
}
//变量替换
//输出文件
file
=
new
File
(
filePath
+
templeName
);
FileOutputStream
fos
=
new
FileOutputStream
(
file
);
out
=
new
OutputStreamWriter
(
fos
,
StandardCharsets
.
UTF_8
);
template
.
process
(
beanParams
,
out
);
FileInputStream
in
=
new
FileInputStream
(
file
);
byte
[]
buffer
=
new
byte
[
in
.
available
()];
in
.
read
(
buffer
);
in
.
close
();
response
.
reset
();
ServletOutputStream
outputStream
=
response
.
getOutputStream
();
response
.
setCharacterEncoding
(
StandardCharsets
.
UTF_8
.
toString
());
response
.
setContentType
(
"application/octet-stream"
);
templeName
=
new
String
((
templeName
).
getBytes
(
StandardCharsets
.
UTF_8
),
StandardCharsets
.
ISO_8859_1
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment;filename="
+
templeName
+
".xls"
);
outputStream
.
write
(
buffer
);
outputStream
.
flush
();
outputStream
.
close
();
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
finally
{
try
{
if
(
out
!=
null
)
{
out
.
close
();
file
.
delete
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
cement-business/src/main/resources/templates/report.ftl
0 → 100644
View file @
62fa9a5a
This diff is collapsed.
Click to expand it.
cement-business/src/main/resources/templates/report1.ftl
0 → 100644
View file @
62fa9a5a
This diff is collapsed.
Click to expand it.
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