Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
8
8timerapiv200
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
8timerv2
8timerapiv200
Commits
f0d99869
Commit
f0d99869
authored
Dec 07, 2021
by
翁国栋
Committed by
284718418@qq.com
Mar 30, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
禅道id--
395、在合同证照当中添加一个导出合同证照的功能
parent
87abdea7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
168 additions
and
25 deletions
+168
-25
src/main/java/cn/timer/api/controller/htzz/HtzzController.java
+89
-11
src/main/java/cn/timer/api/utils/aliyun/OSSUtil.java
+79
-14
No files found.
src/main/java/cn/timer/api/controller/htzz/HtzzController.java
View file @
f0d99869
package
cn
.
timer
.
api
.
controller
.
htzz
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.io.*
;
import
java.nio.charset.StandardCharsets
;
import
java.util.*
;
import
cn.timer.api.utils.aliyun.OSSUtil
;
import
com.google.common.base.Strings
;
import
com.google.common.collect.Maps
;
import
io.swagger.models.auth.In
;
import
org.bouncycastle.util.encoders.UrlBase64Encoder
;
import
org.eclipse.jetty.util.UrlEncoded
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -26,7 +32,6 @@ import com.google.common.collect.Lists;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.cron.CronUtil
;
import
cn.hutool.cron.task.Task
;
import
cn.timer.api.bean.admin.AdminAssoTxjlb
;
import
cn.timer.api.bean.htzz.HtzzAdminZzda
;
import
cn.timer.api.bean.htzz.HtzzAssoHtgx
;
import
cn.timer.api.bean.htzz.HtzzAssoZztx
;
...
...
@@ -37,20 +42,28 @@ import cn.timer.api.config.annotation.UserBean;
import
cn.timer.api.dao.htzz.HtzzAdminZzdaMapper
;
import
cn.timer.api.dto.htzz.HtzzQueryDto
;
import
cn.timer.api.dto.htzz.NotifyPersonDto
;
import
cn.timer.api.dto.htzz.QueryNoReadingDto
;
import
cn.timer.api.utils.Result
;
import
cn.timer.api.utils.ResultUtil
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
@Api
(
tags
=
"7.0合同证照"
)
@RestController
@Transactional
@RequestMapping
(
value
=
"/htzz"
,
produces
=
{
"application/json"
})
@RequestMapping
(
value
=
"/htzz"
,
produces
=
{
"application/json"
})
public
class
HtzzController
{
@Autowired
private
HtzzAdminZzdaMapper
htzzAdminZzdaMapper
;
@Autowired
private
OSSUtil
oss
;
@Value
(
"${config-8timer.Aliyun.project_package}"
)
private
String
project_package
;
@Value
(
"${zip.path}"
)
private
String
zipPath
;
/**
...
...
@@ -79,7 +92,7 @@ public class HtzzController {
}
if
(
date
!=
null
&&
date
.
getTime
()
<=
new
Date
().
getTime
())
{
Logoutput
(
"企业 "
+
orgCode
+
" :短信套餐已过期"
);
return
ResultUtil
.
error
(
"短信套餐已到期!"
);
//
return ResultUtil.error("短信套餐已到期!");
}
if
(
zzda
.
getId
()
==
null
)
{
zzda
.
setTxkgType
(
1
);
//默认开启提醒
...
...
@@ -128,7 +141,7 @@ public class HtzzController {
List
<
NotifyPersonDto
>
tzids
=
new
ArrayList
<
NotifyPersonDto
>();
List
<
HtzzAssoHtgx
>
httxs
=
HtzzAssoHtgx
.
builder
().
build
().
selectList
(
new
QueryWrapper
<
HtzzAssoHtgx
>().
lambda
().
eq
(
HtzzAssoHtgx:
:
getHtid
,
id
));
for
(
HtzzAssoHtgx
gx
:
httxs
)
{
for
(
HtzzAssoHtgx
gx
:
httxs
)
{
NotifyPersonDto
predto
=
NotifyPersonDto
.
builder
().
build
();
predto
.
setEmpName
(
gx
.
getName
());
predto
.
setEmpNum
(
gx
.
getTzrid
());
...
...
@@ -273,12 +286,77 @@ public class HtzzController {
public
void
Logoutput
(
String
science
)
{
if
(!(
"pro"
).
equals
(
environmental_science
))
{
if
(!(
"pro"
).
equals
(
environmental_science
))
{
System
.
out
.
println
(
science
);
}
else
{
}
else
{
System
.
out
.
println
(
""
);
}
}
/**
* @Author wgd
* @Description 导出勾选的合同
* @Date 2021/12/2 17:05
**/
@PostMapping
(
value
=
"/exportContract"
)
public
Result
<
Object
>
exportContract
(
@CurrentUser
UserBean
userBean
,
@RequestBody
List
<
Integer
>
ids
,
HttpServletRequest
request
,
HttpServletResponse
resp
)
{
if
(
ids
.
size
()
<=
0
)
{
return
ResultUtil
.
error
(
"操作失败"
);
}
Map
<
String
,
String
>
url
=
Maps
.
newHashMap
();
ids
.
forEach
(
i
->
{
HtzzAdminZzda
htzzAdminZzda
=
HtzzAdminZzda
.
builder
().
id
(
i
).
build
().
selectById
();
/*格式化获取文字*/
String
urla
=
UrlEncoded
.
decodeString
(
htzzAdminZzda
.
getZjfj
());
int
index
=
urla
.
indexOf
(
project_package
);
url
.
put
(
htzzAdminZzda
.
getId
()
+
"_"
+
htzzAdminZzda
.
getZjmc
(),
urla
.
substring
(
index
));
});
String
zipUrl
=
null
;
try
{
zipUrl
=
oss
.
createZip
(
url
);
return
ResultUtil
.
data
(
zipUrl
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
ResultUtil
.
error
(
"操作失败"
);
}
@GetMapping
(
value
=
"/exportContract"
)
public
void
exportContract
(
@CurrentUser
UserBean
userBean
,
@RequestParam
(
"url"
)
String
url
,
HttpServletRequest
request
,
HttpServletResponse
resp
)
{
FileInputStream
fis
=
null
;
BufferedInputStream
bis
=
null
;
OutputStream
os
;
File
filePath
=
null
;
try
{
resp
.
setContentType
(
"application/octet-stream"
);
resp
.
setHeader
(
"content-disposition"
,
"attachment; filename="
+
new
String
(
url
.
getBytes
(
"UTF8"
),
"ISO-8859-1"
));
resp
.
setCharacterEncoding
(
"UTF-8"
);
filePath
=
new
File
(
zipPath
+
url
);
byte
[]
buffer
=
new
byte
[
1024
];
fis
=
new
FileInputStream
(
filePath
);
bis
=
new
BufferedInputStream
(
fis
);
os
=
resp
.
getOutputStream
();
int
i
=
bis
.
read
(
buffer
);
while
(
i
!=
-
1
)
{
os
.
write
(
buffer
,
0
,
i
);
i
=
bis
.
read
(
buffer
);
}
os
.
flush
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
bis
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
try
{
fis
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
filePath
.
delete
();
}
}
}
src/main/java/cn/timer/api/utils/aliyun/OSSUtil.java
View file @
f0d99869
package
cn
.
timer
.
api
.
utils
.
aliyun
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.*
;
import
java.net.URL
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.text.DateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipOutputStream
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.io.IOUtils
;
import
org.bouncycastle.jce.exception.ExtIOException
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.multipart.MultipartFile
;
...
...
@@ -38,11 +40,12 @@ import cn.hutool.core.util.StrUtil;
import
cn.timer.api.utils.Result
;
import
cn.timer.api.utils.ResultUtil
;
import
javax.servlet.http.HttpServletResponse
;
/**
* OSS接口操作示例 1.创建空间 2.上传文件 3.下载文件
*
* @author dsc
*
*/
@Component
public
class
OSSUtil
{
...
...
@@ -71,6 +74,9 @@ public class OSSUtil {
@Value
(
"${config-8timer.Aliyun.expirationTime_pri}"
)
private
String
expirationTime_pri
;
@Value
(
"${zip.path}"
)
private
String
zipPath
;
/**
* 1.创建储存空间 sout控制台輸出 储存空间名
*
...
...
@@ -135,7 +141,7 @@ public class OSSUtil {
// 关闭OSSClient。
ossClient
.
shutdown
();
// 返回上传成功的文件名
return
url
.
toString
().
substring
(
0
,
url
.
toString
().
lastIndexOf
(
"?"
));
return
url
.
toString
().
substring
(
0
,
url
.
toString
().
lastIndexOf
(
"?"
));
}
/**
...
...
@@ -564,12 +570,71 @@ public class OSSUtil {
public
void
Logoutput
(
String
science
)
{
if
(!(
"pro"
).
equals
(
environmental_science
))
{
if
(!(
"pro"
).
equals
(
environmental_science
))
{
System
.
out
.
println
(
science
);
}
else
{
}
else
{
System
.
out
.
println
(
""
);
}
}
/**
* @Author wgd
* @Description 创建zip
* @Date 2021/12/2 18:06
**/
public
String
createZip
(
Map
<
String
,
String
>
urlMap
)
throws
Exception
{
DateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyyMMddHHmmss"
);
String
fileName
=
dateFormat
.
format
(
new
Date
())
+
".zip"
;
FileOutputStream
fos
=
null
;
ZipOutputStream
zos
=
null
;
BufferedInputStream
inputStream
;
OSSObject
ossObject
;
String
Suffix
;
try
{
fos
=
new
FileOutputStream
(
zipPath
+
fileName
);
zos
=
new
ZipOutputStream
(
fos
);
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
for
(
String
m
:
urlMap
.
keySet
())
{
Suffix
=
urlMap
.
get
(
m
).
substring
(
urlMap
.
get
(
m
).
lastIndexOf
(
"."
));
ossObject
=
ossClient
.
getObject
(
bucketName
,
urlMap
.
get
(
m
));
inputStream
=
new
BufferedInputStream
(
ossObject
.
getObjectContent
());
ZipEntry
entry
=
new
ZipEntry
(
m
+
Suffix
);
try
{
zos
.
putNextEntry
(
entry
);
int
nNumber
;
byte
[]
buffer
=
new
byte
[
4096
];
while
((
nNumber
=
inputStream
.
read
(
buffer
))
>
0
)
{
zos
.
write
(
buffer
,
0
,
nNumber
);
}
}
catch
(
IOException
e
)
{
throw
new
Exception
(
"写入失败"
);
//TODO 应作为自定义异常
}
finally
{
try
{
inputStream
.
close
();
}
catch
(
IOException
e
)
{
throw
new
Exception
(
"关闭失败"
);
//TODO 应作为自定义异常
}
}
}
ossClient
.
shutdown
();
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
finally
{
// 关闭创建的流对象
try
{
if
(
zos
!=
null
)
{
zos
.
closeEntry
();
zos
.
close
();
}
if
(
fos
!=
null
)
{
fos
.
close
();
}
}
catch
(
IOException
e
)
{
throw
new
Exception
(
"关闭失败"
);
//TODO 应作为自定义异常
}
}
return
fileName
;
}
}
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