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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
865 additions
and
722 deletions
+865
-722
src/main/java/cn/timer/api/controller/htzz/HtzzController.java
+315
-237
src/main/java/cn/timer/api/utils/aliyun/OSSUtil.java
+550
-485
No files found.
src/main/java/cn/timer/api/controller/htzz/HtzzController.java
View file @
f0d99869
package
cn
.
timer
.
api
.
controller
.
htzz
;
package
cn
.
timer
.
api
.
controller
.
htzz
;
import
java.
util.ArrayList
;
import
java.
io.*
;
import
java.
util.Date
;
import
java.
nio.charset.StandardCharsets
;
import
java.util.
List
;
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.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
...
@@ -26,7 +32,6 @@ import com.google.common.collect.Lists;
...
@@ -26,7 +32,6 @@ import com.google.common.collect.Lists;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.cron.CronUtil
;
import
cn.hutool.cron.CronUtil
;
import
cn.hutool.cron.task.Task
;
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.HtzzAdminZzda
;
import
cn.timer.api.bean.htzz.HtzzAssoHtgx
;
import
cn.timer.api.bean.htzz.HtzzAssoHtgx
;
import
cn.timer.api.bean.htzz.HtzzAssoZztx
;
import
cn.timer.api.bean.htzz.HtzzAssoZztx
;
...
@@ -37,248 +42,321 @@ import cn.timer.api.config.annotation.UserBean;
...
@@ -37,248 +42,321 @@ import cn.timer.api.config.annotation.UserBean;
import
cn.timer.api.dao.htzz.HtzzAdminZzdaMapper
;
import
cn.timer.api.dao.htzz.HtzzAdminZzdaMapper
;
import
cn.timer.api.dto.htzz.HtzzQueryDto
;
import
cn.timer.api.dto.htzz.HtzzQueryDto
;
import
cn.timer.api.dto.htzz.NotifyPersonDto
;
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.Result
;
import
cn.timer.api.utils.ResultUtil
;
import
cn.timer.api.utils.ResultUtil
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
@Api
(
tags
=
"7.0合同证照"
)
@Api
(
tags
=
"7.0合同证照"
)
@RestController
@RestController
@Transactional
@Transactional
@RequestMapping
(
value
=
"/htzz"
,
produces
=
{
"application/json"
})
@RequestMapping
(
value
=
"/htzz"
,
produces
=
{
"application/json"
})
public
class
HtzzController
{
public
class
HtzzController
{
@Autowired
@Autowired
private
HtzzAdminZzdaMapper
htzzAdminZzdaMapper
;
private
HtzzAdminZzdaMapper
htzzAdminZzdaMapper
;
@Autowired
private
OSSUtil
oss
;
/**
@Value
(
"${config-8timer.Aliyun.project_package}"
)
* 新增证件
private
String
project_package
;
*
@Value
(
"${zip.path}"
)
* @param userBean
private
String
zipPath
;
* @param htzzAdminZzda 证照档案实体
* @return 新增证件结果
*/
/**
@PostMapping
(
"/addzj"
)
* 新增证件
@ApiOperation
(
value
=
"新增合同证件"
,
httpMethod
=
"POST"
,
notes
=
"接口发布说明"
)
*
public
Result
<
Object
>
addzj
(
@CurrentUser
UserBean
userBean
,
@RequestBody
HtzzAdminZzda
zzda
)
{
* @param userBean
Integer
orgCode
=
userBean
.
getOrgCode
();
* @param htzzAdminZzda 证照档案实体
* @return 新增证件结果
QyzxRemainingQuantity
quantity
=
QyzxRemainingQuantity
.
builder
().
build
().
selectOne
(
*/
new
LambdaQueryWrapper
<
QyzxRemainingQuantity
>().
eq
(
QyzxRemainingQuantity:
:
getOrgCode
,
orgCode
)
@PostMapping
(
"/addzj"
)
.
eq
(
QyzxRemainingQuantity:
:
getPmid
,
1
).
gt
(
QyzxRemainingQuantity:
:
getRemainder
,
0
));
@ApiOperation
(
value
=
"新增合同证件"
,
httpMethod
=
"POST"
,
notes
=
"接口发布说明"
)
Date
date
=
null
;
public
Result
<
Object
>
addzj
(
@CurrentUser
UserBean
userBean
,
@RequestBody
HtzzAdminZzda
zzda
)
{
Integer
remainder
=
null
;
Integer
orgCode
=
userBean
.
getOrgCode
();
if
(
quantity
!=
null
)
{
remainder
=
quantity
.
getRemainder
();
QyzxRemainingQuantity
quantity
=
QyzxRemainingQuantity
.
builder
().
build
().
selectOne
(
date
=
quantity
.
getExpireDate
();
new
LambdaQueryWrapper
<
QyzxRemainingQuantity
>().
eq
(
QyzxRemainingQuantity:
:
getOrgCode
,
orgCode
)
}
.
eq
(
QyzxRemainingQuantity:
:
getPmid
,
1
).
gt
(
QyzxRemainingQuantity:
:
getRemainder
,
0
));
if
(
quantity
==
null
||
remainder
==
null
||
remainder
<=
0
)
{
// 判断充了钱没
Date
date
=
null
;
return
ResultUtil
.
error
(
"请充值后使用短信功能!"
);
Integer
remainder
=
null
;
}
if
(
quantity
!=
null
)
{
if
(
date
!=
null
&&
date
.
getTime
()
<=
new
Date
().
getTime
())
{
remainder
=
quantity
.
getRemainder
();
Logoutput
(
"企业 "
+
orgCode
+
" :短信套餐已过期"
);
date
=
quantity
.
getExpireDate
();
return
ResultUtil
.
error
(
"短信套餐已到期!"
);
}
}
if
(
quantity
==
null
||
remainder
==
null
||
remainder
<=
0
)
{
// 判断充了钱没
if
(
zzda
.
getId
()
==
null
)
{
return
ResultUtil
.
error
(
"请充值后使用短信功能!"
);
zzda
.
setTxkgType
(
1
);
//默认开启提醒
}
}
if
(
date
!=
null
&&
date
.
getTime
()
<=
new
Date
().
getTime
())
{
zzda
.
setLrrid
(
userBean
.
getEmpNum
());
Logoutput
(
"企业 "
+
orgCode
+
" :短信套餐已过期"
);
zzda
.
setLrsjTime
(
new
Date
());
// return ResultUtil.error("短信套餐已到期!");
zzda
.
setOrgCode
(
orgCode
);
}
if
(
zzda
.
getId
()
==
null
)
{
zzda
.
setSendingStatus
(
0
);
//0:未发;1:已发
zzda
.
setTxkgType
(
1
);
//默认开启提醒
zzda
.
setTemplateId
(
zzda
.
getTemplateId
());
//消息模板id
}
zzda
.
setLrrid
(
userBean
.
getEmpNum
());
zzda
.
setLrsjTime
(
new
Date
());
zzda
.
setOrgCode
(
orgCode
);
zzda
.
setSendingStatus
(
0
);
//0:未发;1:已发
zzda
.
setTemplateId
(
zzda
.
getTemplateId
());
//消息模板id
// zzda.insert();
// zzda.insert();
zzda
.
insertOrUpdate
();
zzda
.
insertOrUpdate
();
/**
/**
* 新增通知关系表,每人一个
* 新增通知关系表,每人一个
*/
*/
List
<
NotifyPersonDto
>
ids
=
zzda
.
getIds
();
//通知人 用户id+手机号码
List
<
NotifyPersonDto
>
ids
=
zzda
.
getIds
();
//通知人 用户id+手机号码
List
<
HtzzAssoHtgx
>
htgxs
=
Lists
.
newArrayList
();
List
<
HtzzAssoHtgx
>
htgxs
=
Lists
.
newArrayList
();
for
(
NotifyPersonDto
pre
:
ids
)
{
for
(
NotifyPersonDto
pre
:
ids
)
{
HtzzAssoHtgx
.
builder
().
build
().
delete
(
new
QueryWrapper
<
HtzzAssoHtgx
>().
lambda
().
eq
(
HtzzAssoHtgx:
:
getOrgCode
,
orgCode
).
eq
(
HtzzAssoHtgx:
:
getTzrid
,
pre
.
getEmpNum
())
HtzzAssoHtgx
.
builder
().
build
().
delete
(
new
QueryWrapper
<
HtzzAssoHtgx
>().
lambda
().
eq
(
HtzzAssoHtgx:
:
getOrgCode
,
orgCode
).
eq
(
HtzzAssoHtgx:
:
getTzrid
,
pre
.
getEmpNum
())
.
eq
(
HtzzAssoHtgx:
:
getPhone
,
pre
.
getPhone
()));
.
eq
(
HtzzAssoHtgx:
:
getPhone
,
pre
.
getPhone
()));
HtzzAssoHtgx
htgx
=
HtzzAssoHtgx
.
builder
().
build
();
HtzzAssoHtgx
htgx
=
HtzzAssoHtgx
.
builder
().
build
();
htgx
.
setHtid
(
zzda
.
getId
());
htgx
.
setHtid
(
zzda
.
getId
());
htgx
.
setTzrid
(
pre
.
getEmpNum
());
htgx
.
setTzrid
(
pre
.
getEmpNum
());
htgx
.
setName
(
pre
.
getEmpName
());
htgx
.
setName
(
pre
.
getEmpName
());
htgx
.
setPhone
(
pre
.
getPhone
());
htgx
.
setPhone
(
pre
.
getPhone
());
htgx
.
setOrgCode
(
orgCode
);
htgx
.
setOrgCode
(
orgCode
);
htgx
.
insert
();
htgx
.
insert
();
htgxs
.
add
(
htgx
);
htgxs
.
add
(
htgx
);
}
}
HtzzAssoZztx
zztx
=
zzda
.
getZztx
();
HtzzAssoZztx
zztx
=
zzda
.
getZztx
();
zztx
.
setZzdaId
(
zzda
.
getId
());
zztx
.
setZzdaId
(
zzda
.
getId
());
zztx
.
setOrgCode
(
orgCode
);
zztx
.
setOrgCode
(
orgCode
);
zztx
.
setLrrid
(
userBean
.
getEmpNum
());
zztx
.
setLrrid
(
userBean
.
getEmpNum
());
zztx
.
setLrsjTime
(
new
Date
());
zztx
.
setLrsjTime
(
new
Date
());
zztx
.
insertOrUpdate
();
zztx
.
insertOrUpdate
();
return
ResultUtil
.
datas
(
zzda
,
htgxs
,
"新增证件成功!"
);
return
ResultUtil
.
datas
(
zzda
,
htgxs
,
"新增证件成功!"
);
}
}
@GetMapping
(
"/modifytx/{id}"
)
@GetMapping
(
"/modifytx/{id}"
)
@ApiOperation
(
value
=
"修改提醒数据"
,
httpMethod
=
"GET"
,
notes
=
"接口发布说明"
)
@ApiOperation
(
value
=
"修改提醒数据"
,
httpMethod
=
"GET"
,
notes
=
"接口发布说明"
)
public
Result
<
Object
>
modifytx
(
@CurrentUser
UserBean
userBean
,
@PathVariable
Integer
id
)
{
public
Result
<
Object
>
modifytx
(
@CurrentUser
UserBean
userBean
,
@PathVariable
Integer
id
)
{
List
<
NotifyPersonDto
>
tzids
=
new
ArrayList
<
NotifyPersonDto
>();
List
<
NotifyPersonDto
>
tzids
=
new
ArrayList
<
NotifyPersonDto
>();
List
<
HtzzAssoHtgx
>
httxs
=
HtzzAssoHtgx
.
builder
().
build
().
selectList
(
new
QueryWrapper
<
HtzzAssoHtgx
>().
lambda
().
eq
(
HtzzAssoHtgx:
:
getHtid
,
id
));
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
();
NotifyPersonDto
predto
=
NotifyPersonDto
.
builder
().
build
();
predto
.
setEmpName
(
gx
.
getName
());
predto
.
setEmpName
(
gx
.
getName
());
predto
.
setEmpNum
(
gx
.
getTzrid
());
predto
.
setEmpNum
(
gx
.
getTzrid
());
predto
.
setPhone
(
gx
.
getPhone
());
predto
.
setPhone
(
gx
.
getPhone
());
tzids
.
add
(
predto
);
tzids
.
add
(
predto
);
}
}
HtzzAdminZzda
zzda
=
HtzzAdminZzda
.
builder
().
id
(
id
).
build
().
selectById
();
HtzzAdminZzda
zzda
=
HtzzAdminZzda
.
builder
().
id
(
id
).
build
().
selectById
();
HtzzAssoZztx
zztx
=
HtzzAssoZztx
.
builder
().
build
().
selectOne
(
new
QueryWrapper
<
HtzzAssoZztx
>().
lambda
().
eq
(
HtzzAssoZztx:
:
getZzdaId
,
id
));
HtzzAssoZztx
zztx
=
HtzzAssoZztx
.
builder
().
build
().
selectOne
(
new
QueryWrapper
<
HtzzAssoZztx
>().
lambda
().
eq
(
HtzzAssoZztx:
:
getZzdaId
,
id
));
zzda
.
setZztx
(
zztx
);
zzda
.
setZztx
(
zztx
);
zzda
.
setIds
(
tzids
);
zzda
.
setIds
(
tzids
);
return
ResultUtil
.
data
(
zzda
,
"新增成功"
);
return
ResultUtil
.
data
(
zzda
,
"新增成功"
);
}
}
/**
/**
* 按条件搜索(关键字、到期时间)
* 按条件搜索(关键字、到期时间)
*
*
* @param userBean
* @param userBean
* @return
* @return
*/
*/
@GetMapping
(
"/queryht"
)
@GetMapping
(
"/queryht"
)
@ApiOperation
(
value
=
"按条件搜索(关键字、到期时间)"
,
httpMethod
=
"GET"
,
notes
=
"接口发布说明"
)
@ApiOperation
(
value
=
"按条件搜索(关键字、到期时间)"
,
httpMethod
=
"GET"
,
notes
=
"接口发布说明"
)
public
Result
<
Object
>
queryht
(
@CurrentUser
UserBean
userBean
,
HtzzQueryDto
htzzQueryDto
)
{
public
Result
<
Object
>
queryht
(
@CurrentUser
UserBean
userBean
,
HtzzQueryDto
htzzQueryDto
)
{
String
e
=
htzzQueryDto
.
getEndTime
();
String
e
=
htzzQueryDto
.
getEndTime
();
String
q
=
htzzQueryDto
.
getQuery
();
String
q
=
htzzQueryDto
.
getQuery
();
Page
<
HtzzAdminZzda
>
page
=
new
Page
<
HtzzAdminZzda
>(
Page
<
HtzzAdminZzda
>
page
=
new
Page
<
HtzzAdminZzda
>(
htzzQueryDto
.
getCurrentPage
()
==
null
?
1
:
htzzQueryDto
.
getCurrentPage
(),
htzzQueryDto
.
getCurrentPage
()
==
null
?
1
:
htzzQueryDto
.
getCurrentPage
(),
htzzQueryDto
.
getTotalPage
()
==
null
?
10
:
htzzQueryDto
.
getTotalPage
());
htzzQueryDto
.
getTotalPage
()
==
null
?
10
:
htzzQueryDto
.
getTotalPage
());
QueryWrapper
<
HtzzAdminZzda
>
queryWrapper
=
new
QueryWrapper
<>();
QueryWrapper
<
HtzzAdminZzda
>
queryWrapper
=
new
QueryWrapper
<>();
queryWrapper
.
eq
(
"org_code"
,
userBean
.
getOrgCode
())
queryWrapper
.
eq
(
"org_code"
,
userBean
.
getOrgCode
())
.
select
(
"id"
,
"zjmc"
,
"czry"
,
"fzjg"
,
"fzrq"
,
"yxdqr"
,
"txkg_type"
).
eq
(
"is_delete"
,
0
).
eq
(
"document_type"
,
htzzQueryDto
.
getDocumentType
())
.
select
(
"id"
,
"zjmc"
,
"czry"
,
"fzjg"
,
"fzrq"
,
"yxdqr"
,
"txkg_type"
).
eq
(
"is_delete"
,
0
).
eq
(
"document_type"
,
htzzQueryDto
.
getDocumentType
())
.
gt
(!
StrUtil
.
hasBlank
(
e
),
"yxdqr"
,
!
StrUtil
.
hasBlank
(
e
)
?
e
:
"9999-01-01 00:00:00"
)
.
gt
(!
StrUtil
.
hasBlank
(
e
),
"yxdqr"
,
!
StrUtil
.
hasBlank
(
e
)
?
e
:
"9999-01-01 00:00:00"
)
.
and
(!
StrUtil
.
hasBlank
(
q
),
wq
->
wq
.
like
(
"zjmc"
,
q
).
or
().
like
(
"czry"
,
q
)).
orderByDesc
(
"lrsj_time"
);
.
and
(!
StrUtil
.
hasBlank
(
q
),
wq
->
wq
.
like
(
"zjmc"
,
q
).
or
().
like
(
"czry"
,
q
)).
orderByDesc
(
"lrsj_time"
);
IPage
<
HtzzAdminZzda
>
zPage
=
HtzzAdminZzda
.
builder
().
build
().
selectPage
(
page
,
queryWrapper
);
IPage
<
HtzzAdminZzda
>
zPage
=
HtzzAdminZzda
.
builder
().
build
().
selectPage
(
page
,
queryWrapper
);
List
<
HtzzAdminZzda
>
zccrkgls
=
zPage
.
getRecords
();
List
<
HtzzAdminZzda
>
zccrkgls
=
zPage
.
getRecords
();
zPage
.
getCurrent
();
zPage
.
getCurrent
();
zPage
.
getPages
();
zPage
.
getPages
();
zPage
.
getTotal
();
zPage
.
getTotal
();
zPage
.
getSize
();
zPage
.
getSize
();
return
ResultUtil
.
data
(
zPage
,
zccrkgls
,
"搜索成功"
);
return
ResultUtil
.
data
(
zPage
,
zccrkgls
,
"搜索成功"
);
}
}
/**
/**
* 根据id查合同
* 根据id查合同
*
*
* @param id
* @param id
* @return
* @return
*/
*/
@PostMapping
(
value
=
"/queryHt/{id}"
)
@PostMapping
(
value
=
"/queryHt/{id}"
)
@ApiOperation
(
value
=
"根据id查合同"
,
httpMethod
=
"POST"
,
notes
=
"接口发布说明"
)
@ApiOperation
(
value
=
"根据id查合同"
,
httpMethod
=
"POST"
,
notes
=
"接口发布说明"
)
public
Result
<
Object
>
queryHt
(
@CurrentUser
UserBean
userBean
,
@PathVariable
Integer
id
)
{
public
Result
<
Object
>
queryHt
(
@CurrentUser
UserBean
userBean
,
@PathVariable
Integer
id
)
{
List
<
Object
>
list
=
new
ArrayList
<
Object
>();
List
<
Object
>
list
=
new
ArrayList
<
Object
>();
list
.
add
(
HtzzAdminZzda
.
builder
().
build
().
selectOne
(
new
QueryWrapper
<
HtzzAdminZzda
>()
list
.
add
(
HtzzAdminZzda
.
builder
().
build
().
selectOne
(
new
QueryWrapper
<
HtzzAdminZzda
>()
.
eq
(
"org_code"
,
userBean
.
getOrgCode
()).
eq
(
"is_delete"
,
0
).
eq
(
"id"
,
id
)));
.
eq
(
"org_code"
,
userBean
.
getOrgCode
()).
eq
(
"is_delete"
,
0
).
eq
(
"id"
,
id
)));
QueryWrapper
<
HtzzAssoHtgx
>
q
=
new
QueryWrapper
<
HtzzAssoHtgx
>();
QueryWrapper
<
HtzzAssoHtgx
>
q
=
new
QueryWrapper
<
HtzzAssoHtgx
>();
q
.
select
(
"id"
,
"name"
).
eq
(
"htid"
,
id
);
q
.
select
(
"id"
,
"name"
).
eq
(
"htid"
,
id
);
List
<
HtzzAssoHtgx
>
htgx
=
HtzzAssoHtgx
.
builder
().
build
().
selectList
(
q
);
List
<
HtzzAssoHtgx
>
htgx
=
HtzzAssoHtgx
.
builder
().
build
().
selectList
(
q
);
for
(
HtzzAssoHtgx
gx
:
htgx
)
{
for
(
HtzzAssoHtgx
gx
:
htgx
)
{
String
name
=
gx
.
getName
();
String
name
=
gx
.
getName
();
list
.
add
(
name
);
list
.
add
(
name
);
}
}
return
ResultUtil
.
data
(
list
);
return
ResultUtil
.
data
(
list
);
}
}
/**
/**
* 根据id删除合同
* 根据id删除合同
*
*
* @param id
* @param id
* @return
* @return
*/
*/
@DeleteMapping
(
value
=
"/delHt"
)
@DeleteMapping
(
value
=
"/delHt"
)
@ApiOperation
(
value
=
"根据id删除合同"
,
httpMethod
=
"DELETE"
,
notes
=
"接口发布说明"
)
@ApiOperation
(
value
=
"根据id删除合同"
,
httpMethod
=
"DELETE"
,
notes
=
"接口发布说明"
)
public
Result
<
Object
>
delHt
(
@CurrentUser
UserBean
userBean
,
@RequestParam
Integer
htid
)
{
public
Result
<
Object
>
delHt
(
@CurrentUser
UserBean
userBean
,
@RequestParam
Integer
htid
)
{
// 删除提醒关系
// 删除提醒关系
HtzzAssoHtgx
.
builder
().
build
().
delete
(
new
QueryWrapper
<
HtzzAssoHtgx
>().
eq
(
"org_code"
,
userBean
.
getOrgCode
()).
eq
(
"htid"
,
htid
));
HtzzAssoHtgx
.
builder
().
build
().
delete
(
new
QueryWrapper
<
HtzzAssoHtgx
>().
eq
(
"org_code"
,
userBean
.
getOrgCode
()).
eq
(
"htid"
,
htid
));
//删除证照提醒表配置
//删除证照提醒表配置
HtzzAssoZztx
.
builder
().
build
().
delete
(
new
QueryWrapper
<
HtzzAssoZztx
>().
lambda
().
eq
(
HtzzAssoZztx:
:
getZzdaId
,
htid
));
HtzzAssoZztx
.
builder
().
build
().
delete
(
new
QueryWrapper
<
HtzzAssoZztx
>().
lambda
().
eq
(
HtzzAssoZztx:
:
getZzdaId
,
htid
));
// 设置证照删除状态
// 设置证照删除状态
return
ResultUtil
.
data
(
HtzzAdminZzda
.
builder
().
id
(
htid
).
isDelete
(
1
).
build
().
updateById
());
return
ResultUtil
.
data
(
HtzzAdminZzda
.
builder
().
id
(
htid
).
isDelete
(
1
).
build
().
updateById
());
}
}
/**
/**
* 修改提醒状态
* 修改提醒状态
*
*
* @param id
* @param id
* @return
* @return
*/
*/
@PostMapping
(
value
=
"/changeTx"
)
@PostMapping
(
value
=
"/changeTx"
)
@ApiOperation
(
value
=
"修改提醒状态"
,
httpMethod
=
"POST"
,
notes
=
"接口发布说明"
)
@ApiOperation
(
value
=
"修改提醒状态"
,
httpMethod
=
"POST"
,
notes
=
"接口发布说明"
)
public
Result
<
Object
>
changeTx
(
@CurrentUser
UserBean
userBean
,
@RequestParam
Integer
htid
)
{
public
Result
<
Object
>
changeTx
(
@CurrentUser
UserBean
userBean
,
@RequestParam
Integer
htid
)
{
QueryWrapper
<
HtzzAdminZzda
>
queryWrapper
=
new
QueryWrapper
<>();
QueryWrapper
<
HtzzAdminZzda
>
queryWrapper
=
new
QueryWrapper
<>();
queryWrapper
.
select
(
"txkg_type"
).
eq
(
"id"
,
htid
);
queryWrapper
.
select
(
"txkg_type"
).
eq
(
"id"
,
htid
);
HtzzAdminZzda
zzda
=
HtzzAdminZzda
.
builder
().
build
().
selectOne
(
queryWrapper
);
HtzzAdminZzda
zzda
=
HtzzAdminZzda
.
builder
().
build
().
selectOne
(
queryWrapper
);
UpdateWrapper
<
HtzzAdminZzda
>
updateWrapper
=
new
UpdateWrapper
<>();
UpdateWrapper
<
HtzzAdminZzda
>
updateWrapper
=
new
UpdateWrapper
<>();
updateWrapper
.
eq
(
"id"
,
htid
);
updateWrapper
.
eq
(
"id"
,
htid
);
HtzzAdminZzda
w
=
HtzzAdminZzda
.
builder
().
orgCode
(
userBean
.
getOrgCode
()).
id
(
htid
)
HtzzAdminZzda
w
=
HtzzAdminZzda
.
builder
().
orgCode
(
userBean
.
getOrgCode
()).
id
(
htid
)
.
txkgType
(
zzda
.
getTxkgType
()
==
0
?
1
:
0
).
build
();
.
txkgType
(
zzda
.
getTxkgType
()
==
0
?
1
:
0
).
build
();
htzzAdminZzdaMapper
.
update
(
w
,
updateWrapper
);
htzzAdminZzdaMapper
.
update
(
w
,
updateWrapper
);
return
ResultUtil
.
success
(
"修改成功"
);
return
ResultUtil
.
success
(
"修改成功"
);
}
}
/**
/**
* 查詢全部員工id、姓名
* 查詢全部員工id、姓名
*
*
* @param id
* @param id
* @return
* @return
*/
*/
@GetMapping
(
value
=
"/queryYg"
)
@GetMapping
(
value
=
"/queryYg"
)
@ApiOperation
(
value
=
"查詢全部員工id、姓名"
,
httpMethod
=
"GET"
,
notes
=
"接口发布说明"
)
@ApiOperation
(
value
=
"查詢全部員工id、姓名"
,
httpMethod
=
"GET"
,
notes
=
"接口发布说明"
)
public
Result
<
Object
>
queryYg
(
@CurrentUser
UserBean
userBean
)
{
public
Result
<
Object
>
queryYg
(
@CurrentUser
UserBean
userBean
)
{
return
ResultUtil
.
data
(
YgglMainEmp
.
builder
().
build
().
selectList
(
return
ResultUtil
.
data
(
YgglMainEmp
.
builder
().
build
().
selectList
(
new
QueryWrapper
<
YgglMainEmp
>().
select
(
"emp_num"
,
"name"
,
"phone"
).
eq
(
"org_code"
,
userBean
.
getOrgCode
())));
new
QueryWrapper
<
YgglMainEmp
>().
select
(
"emp_num"
,
"name"
,
"phone"
).
eq
(
"org_code"
,
userBean
.
getOrgCode
())));
}
}
@GetMapping
(
value
=
"/test"
)
@GetMapping
(
value
=
"/test"
)
@ApiOperation
(
value
=
"test"
,
httpMethod
=
"GET"
,
notes
=
"接口发布说明"
)
@ApiOperation
(
value
=
"test"
,
httpMethod
=
"GET"
,
notes
=
"接口发布说明"
)
public
Result
<
Void
>
test
(
String
schedulingPattern
)
{
public
Result
<
Void
>
test
(
String
schedulingPattern
)
{
CronUtil
.
schedule
(
"*/2 * * 24 * *"
,
new
Task
()
{
CronUtil
.
schedule
(
"*/2 * * 24 * *"
,
new
Task
()
{
@Override
@Override
public
void
execute
()
{
public
void
execute
()
{
Logoutput
(
"start:"
+
new
Date
());
Logoutput
(
"start:"
+
new
Date
());
}
}
});
});
CronUtil
.
setMatchSecond
(
true
);
CronUtil
.
setMatchSecond
(
true
);
CronUtil
.
start
();
CronUtil
.
start
();
return
ResultUtil
.
success
(
"操作成功"
);
return
ResultUtil
.
success
(
"操作成功"
);
}
}
@Value
(
"${config-8timer.environmental-science}"
)
@Value
(
"${config-8timer.environmental-science}"
)
public
String
environmental_science
;
public
String
environmental_science
;
public
void
Logoutput
(
String
science
)
{
public
void
Logoutput
(
String
science
)
{
if
(!(
"pro"
).
equals
(
environmental_science
))
{
if
(!(
"pro"
).
equals
(
environmental_science
))
{
System
.
out
.
println
(
science
);
System
.
out
.
println
(
science
);
}
else
{
}
else
{
System
.
out
.
println
(
""
);
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
;
package
cn
.
timer
.
api
.
utils
.
aliyun
;
import
java.io.BufferedReader
;
import
java.io.*
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.net.URL
;
import
java.net.URL
;
import
java.util.ArrayList
;
import
java.text.DateFormat
;
import
java.util.Date
;
import
java.text.SimpleDateFormat
;
import
java.util.Iterator
;
import
java.util.*
;
import
java.util.List
;
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.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
...
@@ -38,315 +40,319 @@ import cn.hutool.core.util.StrUtil;
...
@@ -38,315 +40,319 @@ import cn.hutool.core.util.StrUtil;
import
cn.timer.api.utils.Result
;
import
cn.timer.api.utils.Result
;
import
cn.timer.api.utils.ResultUtil
;
import
cn.timer.api.utils.ResultUtil
;
import
javax.servlet.http.HttpServletResponse
;
/**
/**
* OSS接口操作示例 1.创建空间 2.上传文件 3.下载文件
* OSS接口操作示例 1.创建空间 2.上传文件 3.下载文件
*
* @author dsc
*
*
* @author dsc
*/
*/
@Component
@Component
public
class
OSSUtil
{
public
class
OSSUtil
{
@Value
(
"${config-8timer.Aliyun.endpoint}"
)
@Value
(
"${config-8timer.Aliyun.endpoint}"
)
private
String
endpoint
;
private
String
endpoint
;
@Value
(
"${config-8timer.Aliyun.ACCESSKEY_ID}"
)
@Value
(
"${config-8timer.Aliyun.ACCESSKEY_ID}"
)
private
String
accessKeyId
;
private
String
accessKeyId
;
@Value
(
"${config-8timer.Aliyun.SECRET}"
)
@Value
(
"${config-8timer.Aliyun.SECRET}"
)
private
String
accessKeySecret
;
private
String
accessKeySecret
;
@Value
(
"${config-8timer.Aliyun.bucketName}"
)
@Value
(
"${config-8timer.Aliyun.bucketName}"
)
private
String
bucketName
;
private
String
bucketName
;
@Value
(
"${config-8timer.Aliyun.bucketName_pri}"
)
@Value
(
"${config-8timer.Aliyun.bucketName_pri}"
)
private
String
bucketName_pri
;
private
String
bucketName_pri
;
@Value
(
"${config-8timer.Aliyun.project_package}"
)
@Value
(
"${config-8timer.Aliyun.project_package}"
)
private
String
project_package
;
private
String
project_package
;
@Value
(
"${config-8timer.Aliyun.expirationTime}"
)
@Value
(
"${config-8timer.Aliyun.expirationTime}"
)
private
String
expirationTime
;
private
String
expirationTime
;
@Value
(
"${config-8timer.Aliyun.expirationTime_pri}"
)
@Value
(
"${config-8timer.Aliyun.expirationTime_pri}"
)
private
String
expirationTime_pri
;
private
String
expirationTime_pri
;
/**
@Value
(
"${zip.path}"
)
* 1.创建储存空间 sout控制台輸出 储存空间名
private
String
zipPath
;
*
* @param bucketName OSS空间名
/**
* @return 成功信息
* 1.创建储存空间 sout控制台輸出 储存空间名
*/
*
public
Result
<
Void
>
createZone
(
String
bucketName
)
{
* @param bucketName OSS空间名
// Endpoint以杭州为例,其它Region请按实际情况填写。
* @return 成功信息
// 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录
*/
// https://ram.console.aliyun.com 创建RAM账号。
public
Result
<
Void
>
createZone
(
String
bucketName
)
{
// 创建OSSClient实例。
// Endpoint以杭州为例,其它Region请按实际情况填写。
// 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
// https://ram.console.aliyun.com 创建RAM账号。
// 创建存储空间。
// 创建OSSClient实例。
ossClient
.
createBucket
(
bucketName
);
// 关闭OSSClient。
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
ossClient
.
shutdown
();
// 创建存储空间。
// 控制台输出空间名
ossClient
.
createBucket
(
bucketName
);
Logoutput
(
"bucketName:"
+
bucketName
);
// 关闭OSSClient。
// 返回成功
ossClient
.
shutdown
();
return
ResultUtil
.
success
(
"创建OSS空间成功"
);
// 控制台输出空间名
}
Logoutput
(
"bucketName:"
+
bucketName
);
// 返回成功
/**
return
ResultUtil
.
success
(
"创建OSS空间成功"
);
* 2.上传文件到8time-v2
}
*
* @param path 上传路径(用'/'分包)
/**
* @param ins 输入流
* 2.上传文件到8time-v2
* @return
*
*/
* @param path 上传路径(用'/'分包)
public
String
uploadFile
(
File
path
,
InputStream
ins
)
{
* @param ins 输入流
// <yourObjectName>上传文件到OSS时需要指定包含文件后缀在内的完整路径,例如abc/efg/123.jpg。
* @return
// String objectName = "8time-v2/test/123.jpg";
*/
// 创建OSSClient实例。
public
String
uploadFile
(
File
path
,
InputStream
ins
)
{
Logoutput
(
endpoint
);
// <yourObjectName>上传文件到OSS时需要指定包含文件后缀在内的完整路径,例如abc/efg/123.jpg。
Logoutput
(
accessKeyId
);
// String objectName = "8time-v2/test/123.jpg";
Logoutput
(
accessKeySecret
);
// 创建OSSClient实例。
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
Logoutput
(
endpoint
);
Logoutput
(
accessKeyId
);
// 创建PutObjectRequest对象。
Logoutput
(
accessKeySecret
);
// 项目名+用户公司id+模块名+文件夹名+文件名
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
PutObjectRequest
putObjectRequest
=
new
PutObjectRequest
(
bucketName
,
path
.
getPath
(),
ins
);
// [file1,file2,file3],["mk1/img","mk1"]
// 创建PutObjectRequest对象。
// 如果需要上传时设置存储类型与访问权限,请参考以下示例代码。
// 项目名+用户公司id+模块名+文件夹名+文件名
// ObjectMetadata metadata = new ObjectMetadata();
PutObjectRequest
putObjectRequest
=
new
PutObjectRequest
(
bucketName
,
path
.
getPath
(),
ins
);
// metadata.setHeader(OSSHeaders.OSS_STORAGE_CLASS,
// [file1,file2,file3],["mk1/img","mk1"]
// StorageClass.Standard.toString());
// 如果需要上传时设置存储类型与访问权限,请参考以下示例代码。
// metadata.setObjectAcl(CannedAccessControlList.Private);
// ObjectMetadata metadata = new ObjectMetadata();
// putObjectRequest.setMetadata(metadata);
// metadata.setHeader(OSSHeaders.OSS_STORAGE_CLASS,
// StorageClass.Standard.toString());
// 上传文件。
// metadata.setObjectAcl(CannedAccessControlList.Private);
ossClient
.
putObject
(
putObjectRequest
);
// putObjectRequest.setMetadata(metadata);
// 设置URL过期时间为100年。 1s 1h 1d 1y 100y
// 上传文件。
ossClient
.
putObject
(
putObjectRequest
);
// 设置URL过期时间为100年。 1s 1h 1d 1y 100y
// Date expiration = new Date(new Date().getTime() + 1000L * 3600 * 24 * 365 * 100);
// Date expiration = new Date(new Date().getTime() + 1000L * 3600 * 24 * 365 * 100);
Date
now
=
new
Date
();
Date
now
=
new
Date
();
Date
expiration
=
DateUtil
.
offset
(
now
,
DateField
.
YEAR
,
100
);
// 一百年之后过期
Date
expiration
=
DateUtil
.
offset
(
now
,
DateField
.
YEAR
,
100
);
// 一百年之后过期
// 生成以GET方法访问的签名URL,访客可以直接通过浏览器访问相关内容。
// 生成以GET方法访问的签名URL,访客可以直接通过浏览器访问相关内容。
URL
url
=
ossClient
.
generatePresignedUrl
(
bucketName
,
path
.
getPath
(),
expiration
);
URL
url
=
ossClient
.
generatePresignedUrl
(
bucketName
,
path
.
getPath
(),
expiration
);
Logoutput
(
String
.
valueOf
(
url
));
Logoutput
(
String
.
valueOf
(
url
));
// 关闭OSSClient。
// 关闭OSSClient。
ossClient
.
shutdown
();
ossClient
.
shutdown
();
// 返回上传成功的文件名
// 返回上传成功的文件名
return
url
.
toString
().
substring
(
0
,
url
.
toString
().
lastIndexOf
(
"?"
));
return
url
.
toString
().
substring
(
0
,
url
.
toString
().
lastIndexOf
(
"?"
));
}
}
/**
/**
* 3.上传文件到8time-v2-private
* 3.上传文件到8time-v2-private
*
*
* @param path 上传路径(用'/'分包)
* @param path 上传路径(用'/'分包)
* @param ins 输入流
* @param ins 输入流
* @return 文件路径
* @return 文件路径
*/
*/
public
String
uploadPrivateFile
(
String
path
,
InputStream
ins
)
{
public
String
uploadPrivateFile
(
String
path
,
InputStream
ins
)
{
// <yourObjectName>上传文件到OSS时需要指定包含文件后缀在内的完整路径,例如abc/efg/123.jpg。
// <yourObjectName>上传文件到OSS时需要指定包含文件后缀在内的完整路径,例如abc/efg/123.jpg。
// String objectName = "8time-v2/test/123.jpg";
// String objectName = "8time-v2/test/123.jpg";
// 创建OSSClient实例。
// 创建OSSClient实例。
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
// 创建PutObjectRequest对象。
// 创建PutObjectRequest对象。
// 项目名+用户公司id+模块名+文件夹名+文件名
// 项目名+用户公司id+模块名+文件夹名+文件名
PutObjectRequest
putObjectRequest
=
new
PutObjectRequest
(
bucketName_pri
,
path
,
ins
);
PutObjectRequest
putObjectRequest
=
new
PutObjectRequest
(
bucketName_pri
,
path
,
ins
);
// [file1,file2,file3],["mk1/img","mk1"]
// [file1,file2,file3],["mk1/img","mk1"]
// 如果需要上传时设置存储类型与访问权限,请参考以下示例代码。
// 如果需要上传时设置存储类型与访问权限,请参考以下示例代码。
// ObjectMetadata metadata = new ObjectMetadata();
// ObjectMetadata metadata = new ObjectMetadata();
// metadata.setHeader(OSSHeaders.OSS_STORAGE_CLASS,
// metadata.setHeader(OSSHeaders.OSS_STORAGE_CLASS,
// StorageClass.Standard.toString());
// StorageClass.Standard.toString());
// metadata.setObjectAcl(CannedAccessControlList.Private);
// metadata.setObjectAcl(CannedAccessControlList.Private);
// putObjectRequest.setMetadata(metadata);
// putObjectRequest.setMetadata(metadata);
// 上传文件。
// 上传文件。
ossClient
.
putObject
(
putObjectRequest
);
ossClient
.
putObject
(
putObjectRequest
);
// 设置URL过期时间为10分钟
// 设置URL过期时间为10分钟
Date
expiration
=
new
Date
(
new
Date
().
getTime
()
+
1000
*
600
);
Date
expiration
=
new
Date
(
new
Date
().
getTime
()
+
1000
*
600
);
// 生成以GET方法访问的签名URL,访客可以直接通过浏览器访问相关内容。
// 生成以GET方法访问的签名URL,访客可以直接通过浏览器访问相关内容。
URL
url
=
ossClient
.
generatePresignedUrl
(
bucketName_pri
,
path
,
expiration
);
URL
url
=
ossClient
.
generatePresignedUrl
(
bucketName_pri
,
path
,
expiration
);
Logoutput
(
String
.
valueOf
(
url
));
Logoutput
(
String
.
valueOf
(
url
));
// 关闭OSSClient。
// 关闭OSSClient。
ossClient
.
shutdown
();
ossClient
.
shutdown
();
// 返回上传成功的文件名
// 返回上传成功的文件名
return
path
;
return
path
;
}
}
/**
/**
* 4.从OSS下载文件
* 4.从OSS下载文件
*
*
* @param path
本地储存文件路径
* @param path
本地储存文件路径
* @param orgCode
公司id
* @param orgCode
公司id
* @param dir
包名
* @param dir
包名
* @param fileName
文件名
* @param fileName
文件名
* @param moudle
模块名
* @param moudle
模块名
* @return 完整文件名
* @return 完整文件名
*/
*/
public
Result
<
String
>
downloadFile
(
String
orgCode
,
String
moudle
,
String
dir
,
String
fileName
,
String
path
)
{
public
Result
<
String
>
downloadFile
(
String
orgCode
,
String
moudle
,
String
dir
,
String
fileName
,
String
path
)
{
// <yourObjectName>从OSS下载文件时需要指定包含文件后缀在内的完整路径,例如abc/efg/123.jpg。
// <yourObjectName>从OSS下载文件时需要指定包含文件后缀在内的完整路径,例如abc/efg/123.jpg。
// String objectName = "8time-v2/test/123.jpg";
// String objectName = "8time-v2/test/123.jpg";
// 创建OSSClient实例。
// 创建OSSClient实例。
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
// 下载OSS文件到本地文件。如果指定的本地文件存在会覆盖,不存在则新建。
// 下载OSS文件到本地文件。如果指定的本地文件存在会覆盖,不存在则新建。
ossClient
.
getObject
(
ossClient
.
getObject
(
new
GetObjectRequest
(
bucketName
,
project_package
+
orgCode
+
"/"
+
moudle
+
"/"
+
dir
+
"/"
+
fileName
),
new
GetObjectRequest
(
bucketName
,
project_package
+
orgCode
+
"/"
+
moudle
+
"/"
+
dir
+
"/"
+
fileName
),
new
File
(
path
+
fileName
));
new
File
(
path
+
fileName
));
// 关闭OSSClient。
// 关闭OSSClient。
ossClient
.
shutdown
();
ossClient
.
shutdown
();
// 完整路径的文件名
// 完整路径的文件名
Logoutput
(
"objectName:"
+
project_package
+
orgCode
+
"/"
+
moudle
+
"/"
+
dir
+
"/"
+
fileName
);
Logoutput
(
"objectName:"
+
project_package
+
orgCode
+
"/"
+
moudle
+
"/"
+
dir
+
"/"
+
fileName
);
Logoutput
(
"path:"
+
path
+
fileName
);
Logoutput
(
"path:"
+
path
+
fileName
);
// 返回成功的本地路径
// 返回成功的本地路径
return
ResultUtil
.
success
(
path
+
fileName
);
return
ResultUtil
.
success
(
path
+
fileName
);
}
}
public
Result
<
BufferedReader
>
downloadFile
(
String
objectName
)
throws
IOException
{
public
Result
<
BufferedReader
>
downloadFile
(
String
objectName
)
throws
IOException
{
// 创建OSSClient实例。
// 创建OSSClient实例。
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
// ossObject包含文件所在的存储空间名称、文件名称、文件元信息以及一个输入流。
// ossObject包含文件所在的存储空间名称、文件名称、文件元信息以及一个输入流。
OSSObject
ossObject
=
ossClient
.
getObject
(
bucketName
,
objectName
);
OSSObject
ossObject
=
ossClient
.
getObject
(
bucketName
,
objectName
);
// 读取文件内容。
// 读取文件内容。
System
.
out
.
println
(
"Object content:"
);
System
.
out
.
println
(
"Object content:"
);
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
ossObject
.
getObjectContent
()));
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
ossObject
.
getObjectContent
()));
while
(
true
)
{
while
(
true
)
{
String
line
=
reader
.
readLine
();
String
line
=
reader
.
readLine
();
if
(
line
==
null
)
if
(
line
==
null
)
break
;
break
;
System
.
out
.
println
(
"\n"
+
line
);
System
.
out
.
println
(
"\n"
+
line
);
}
}
// 数据读取完成后,获取的流必须关闭,否则会造成连接泄漏,导致请求无连接可用,程序无法正常工作。
// 数据读取完成后,获取的流必须关闭,否则会造成连接泄漏,导致请求无连接可用,程序无法正常工作。
reader
.
close
();
reader
.
close
();
// 关闭OSSClient。
// 关闭OSSClient。
ossClient
.
shutdown
();
ossClient
.
shutdown
();
return
ResultUtil
.
data
(
reader
,
"下载成功"
);
return
ResultUtil
.
data
(
reader
,
"下载成功"
);
}
}
/**
/**
* 文件输入流批量上传
* 文件输入流批量上传
*
*
* @param request 获取参数
* @param request 获取参数
* @param files
批量文件
* @param files
批量文件
* @return 返回上传成功或失败的信息
* @return 返回上传成功或失败的信息
*/
*/
public
String
uploadFile
(
MultipartHttpServletRequest
request
,
List
<
MultipartFile
>
files
)
{
public
String
uploadFile
(
MultipartHttpServletRequest
request
,
List
<
MultipartFile
>
files
)
{
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
String
newFileName
=
null
;
String
newFileName
=
null
;
URL
url
=
null
;
URL
url
=
null
;
try
{
try
{
// 上传文件
// 上传文件
CommonsMultipartResolver
multipartResolver
=
new
CommonsMultipartResolver
(
CommonsMultipartResolver
multipartResolver
=
new
CommonsMultipartResolver
(
request
.
getSession
().
getServletContext
());
request
.
getSession
().
getServletContext
());
// 判断 request 是否有文件上传,即多部分请求
// 判断 request 是否有文件上传,即多部分请求
if
(
multipartResolver
.
isMultipart
(
request
))
{
if
(
multipartResolver
.
isMultipart
(
request
))
{
// 转换成多部分request
// 转换成多部分request
MultipartHttpServletRequest
multiRequest
=
(
MultipartHttpServletRequest
)
request
;
MultipartHttpServletRequest
multiRequest
=
(
MultipartHttpServletRequest
)
request
;
// 取得request中的所有文件名
// 取得request中的所有文件名
Iterator
<
String
>
iter
=
multiRequest
.
getFileNames
();
Iterator
<
String
>
iter
=
multiRequest
.
getFileNames
();
// 此处上传单个文件,如需多个文件改为while循环
// 此处上传单个文件,如需多个文件改为while循环
while
(
iter
.
hasNext
())
{
while
(
iter
.
hasNext
())
{
// 取得上传文件
// 取得上传文件
files
=
multiRequest
.
getFiles
(
iter
.
next
());
files
=
multiRequest
.
getFiles
(
iter
.
next
());
if
(
files
!=
null
)
{
if
(
files
!=
null
)
{
// 取得当前上传文件的文件名称
// 取得当前上传文件的文件名称
String
myFileName
=
null
;
String
myFileName
=
null
;
for
(
MultipartFile
file
:
files
)
{
for
(
MultipartFile
file
:
files
)
{
myFileName
=
file
.
getOriginalFilename
();
myFileName
=
file
.
getOriginalFilename
();
// 如果名称不为“”,说明该文件存在,否则说明该文件不存在
// 如果名称不为“”,说明该文件存在,否则说明该文件不存在
if
(
StrUtil
.
isNotEmpty
(
myFileName
.
trim
()))
{
if
(
StrUtil
.
isNotEmpty
(
myFileName
.
trim
()))
{
newFileName
=
System
.
currentTimeMillis
()
newFileName
=
System
.
currentTimeMillis
()
+
myFileName
.
substring
(
myFileName
.
lastIndexOf
(
"."
));
+
myFileName
.
substring
(
myFileName
.
lastIndexOf
(
"."
));
// 上传客户端文件到oss,如直接上传服务器文件到oss,可使用new FileInputStream( new File("服务器文件路径"))
// 上传客户端文件到oss,如直接上传服务器文件到oss,可使用new FileInputStream( new File("服务器文件路径"))
ossClient
.
putObject
(
bucketName
,
newFileName
,
file
.
getInputStream
());
ossClient
.
putObject
(
bucketName
,
newFileName
,
file
.
getInputStream
());
// 设置URL过期时间为100年。 1s 1h 1d 1y 100y
// 设置URL过期时间为100年。 1s 1h 1d 1y 100y
Date
expiration
=
new
Date
(
new
Date
().
getTime
()
+
Long
.
parseLong
(
expirationTime
));
Date
expiration
=
new
Date
(
new
Date
().
getTime
()
+
Long
.
parseLong
(
expirationTime
));
// 生成以GET方法访问的签名URL,访客可以直接通过浏览器访问相关内容。
// 生成以GET方法访问的签名URL,访客可以直接通过浏览器访问相关内容。
url
=
ossClient
.
generatePresignedUrl
(
bucketName
,
newFileName
,
expiration
);
url
=
ossClient
.
generatePresignedUrl
(
bucketName
,
newFileName
,
expiration
);
Logoutput
(
String
.
valueOf
(
url
));
Logoutput
(
String
.
valueOf
(
url
));
}
}
}
}
}
}
}
}
}
}
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
getStackTrace
();
e
.
getStackTrace
();
}
finally
{
}
finally
{
// 关闭ossClient
// 关闭ossClient
if
(
null
!=
ossClient
)
if
(
null
!=
ossClient
)
ossClient
.
shutdown
();
ossClient
.
shutdown
();
}
}
return
url
.
toString
();
return
url
.
toString
();
/*
/*
* if (file == null || file.getSize() <= 0) { return
* if (file == null || file.getSize() <= 0) { return
* ResultUtil.error("上传的文件为空,请重新选择!"); } else { try {
* ResultUtil.error("上传的文件为空,请重新选择!"); } else { try {
* OSSUtil.uploadFile(userBean.getOrgCode(), className,
* OSSUtil.uploadFile(userBean.getOrgCode(), className,
* file.getOriginalFilename(), file.getInputStream()); } catch (IOException e) {
* file.getOriginalFilename(), file.getInputStream()); } catch (IOException e) {
* e.printStackTrace(); } return ResultUtil.success("上传成功"); }
* e.printStackTrace(); } return ResultUtil.success("上传成功"); }
*/
*/
}
}
/**
/**
* 获取8time-v2文件的url
* 获取8time-v2文件的url
*
*
* @return url地址
* @return url地址
*/
*/
public
String
getUrl
(
String
path
)
{
public
String
getUrl
(
String
path
)
{
// 创建OSSClient实例。
// 创建OSSClient实例。
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
// 设置URL过期时间为100年。 1s 1h 1d 1y 10y
// 设置URL过期时间为100年。 1s 1h 1d 1y 10y
Date
expiration
=
new
Date
(
new
Date
().
getTime
()
+
Long
.
parseLong
(
expirationTime
));
Date
expiration
=
new
Date
(
new
Date
().
getTime
()
+
Long
.
parseLong
(
expirationTime
));
// 生成以GET方法访问的签名URL,访客可以直接通过浏览器访问相关内容。
// 生成以GET方法访问的签名URL,访客可以直接通过浏览器访问相关内容。
URL
url
=
ossClient
.
generatePresignedUrl
(
bucketName
,
path
,
expiration
);
URL
url
=
ossClient
.
generatePresignedUrl
(
bucketName
,
path
,
expiration
);
Logoutput
(
String
.
valueOf
(
url
));
Logoutput
(
String
.
valueOf
(
url
));
// 关闭OSSClient。
// 关闭OSSClient。
ossClient
.
shutdown
();
ossClient
.
shutdown
();
return
url
.
toString
();
return
url
.
toString
();
}
}
/**
/**
* 获取8time-v2-private文件的url
* 获取8time-v2-private文件的url
*
*
* @return url地址
* @return url地址
*/
*/
public
String
getUrlP
(
String
path
)
{
public
String
getUrlP
(
String
path
)
{
// 创建OSSClient实例。
// 创建OSSClient实例。
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
// 设置URL过期时间为10分钟。
// 设置URL过期时间为10分钟。
Date
expiration
=
new
Date
(
new
Date
().
getTime
()
+
Long
.
parseLong
(
expirationTime_pri
));
Date
expiration
=
new
Date
(
new
Date
().
getTime
()
+
Long
.
parseLong
(
expirationTime_pri
));
// 生成以GET方法访问的签名URL,访客可以直接通过浏览器访问相关内容。
// 生成以GET方法访问的签名URL,访客可以直接通过浏览器访问相关内容。
URL
url
=
ossClient
.
generatePresignedUrl
(
bucketName
,
path
,
expiration
);
URL
url
=
ossClient
.
generatePresignedUrl
(
bucketName
,
path
,
expiration
);
Logoutput
(
String
.
valueOf
(
url
));
Logoutput
(
String
.
valueOf
(
url
));
// 关闭OSSClient。
// 关闭OSSClient。
ossClient
.
shutdown
();
ossClient
.
shutdown
();
return
url
.
toString
();
return
url
.
toString
();
}
}
/**
/**
* 删除单个
* 删除单个
*
*
* @param objectName 文件名
* @param objectName 文件名
*/
*/
public
void
delSingleFile
(
String
objectName
)
{
public
void
delSingleFile
(
String
objectName
)
{
// // Endpoint以杭州为例,其它Region请按实际情况填写。
// // Endpoint以杭州为例,其它Region请按实际情况填写。
// String endpoint = "http://oss-cn-hangzhou.aliyuncs.com";
// String endpoint = "http://oss-cn-hangzhou.aliyuncs.com";
// // 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
// // 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
...
@@ -355,24 +361,24 @@ public class OSSUtil {
...
@@ -355,24 +361,24 @@ public class OSSUtil {
// String bucketName = "<yourBucketName>";
// String bucketName = "<yourBucketName>";
// String objectName = "<yourObjectName>";
// String objectName = "<yourObjectName>";
// 创建OSSClient实例。
// 创建OSSClient实例。
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
// 删除文件。如需删除文件夹,请将ObjectName设置为对应的文件夹名称。如果文件夹非空,则需要将文件夹下的所有object删除后才能删除该文件夹。
// 删除文件。如需删除文件夹,请将ObjectName设置为对应的文件夹名称。如果文件夹非空,则需要将文件夹下的所有object删除后才能删除该文件夹。
ossClient
.
deleteObject
(
bucketName
,
objectName
);
ossClient
.
deleteObject
(
bucketName
,
objectName
);
// 关闭OSSClient。
// 关闭OSSClient。
ossClient
.
shutdown
();
ossClient
.
shutdown
();
}
}
/**
/**
* 删除多个文件
* 删除多个文件
*
*
* @param keys 需要删除的文件。
* @param keys 需要删除的文件。
* @param quiet 返回模式。true表示简单模式,false表示详细模式。默认为详细模式。
* @param quiet 返回模式。true表示简单模式,false表示详细模式。默认为详细模式。
* @return 删除结果。详细模式下为删除成功的文件列表,简单模式下为删除失败的文件列表。
* @return 删除结果。详细模式下为删除成功的文件列表,简单模式下为删除失败的文件列表。
*/
*/
public
List
<
String
>
delFiles
(
List
<
String
>
keys
,
boolean
quiet
)
{
public
List
<
String
>
delFiles
(
List
<
String
>
keys
,
boolean
quiet
)
{
// // Endpoint以杭州为例,其它Region请按实际情况填写。
// // Endpoint以杭州为例,其它Region请按实际情况填写。
// String endpoint = "http://oss-cn-hangzhou.aliyuncs.com";
// String endpoint = "http://oss-cn-hangzhou.aliyuncs.com";
// // 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
// // 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
...
@@ -380,31 +386,31 @@ public class OSSUtil {
...
@@ -380,31 +386,31 @@ public class OSSUtil {
// String accessKeySecret = "<yourAccessKeySecret>";
// String accessKeySecret = "<yourAccessKeySecret>";
// String bucketName = "<yourBucketName>";
// String bucketName = "<yourBucketName>";
// 创建OSSClient实例。
// 创建OSSClient实例。
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
// 删除文件。key等同于ObjectName,表示删除OSS文件时需要指定包含文件后缀在内的完整路径,例如abc/efg/123.jpg。
// 删除文件。key等同于ObjectName,表示删除OSS文件时需要指定包含文件后缀在内的完整路径,例如abc/efg/123.jpg。
// List<String> keys = new ArrayList<String>();
// List<String> keys = new ArrayList<String>();
// keys.add("key0");
// keys.add("key0");
// keys.add("key1");
// keys.add("key1");
// keys.add("key2");
// keys.add("key2");
DeleteObjectsResult
deleteObjectsResult
=
ossClient
DeleteObjectsResult
deleteObjectsResult
=
ossClient
.
deleteObjects
(
new
DeleteObjectsRequest
(
bucketName
).
withKeys
(
keys
).
withQuiet
(
quiet
));
.
deleteObjects
(
new
DeleteObjectsRequest
(
bucketName
).
withKeys
(
keys
).
withQuiet
(
quiet
));
List
<
String
>
deletedObjects
=
deleteObjectsResult
.
getDeletedObjects
();
List
<
String
>
deletedObjects
=
deleteObjectsResult
.
getDeletedObjects
();
// 关闭OSSClient。
// 关闭OSSClient。
ossClient
.
shutdown
();
ossClient
.
shutdown
();
return
deletedObjects
;
return
deletedObjects
;
}
}
/**
/**
* 删除指定前缀(prefix)的文件
* 删除指定前缀(prefix)的文件
*
*
* @param prefix
* @param prefix
*/
*/
public
void
delPrefixWith
(
String
prefix
)
{
public
void
delPrefixWith
(
String
prefix
)
{
// // Endpoint以杭州为例,其它Region请按实际情况填写。
// // Endpoint以杭州为例,其它Region请按实际情况填写。
// String endpoint = "http://oss-cn-hangzhou.aliyuncs.com";
// String endpoint = "http://oss-cn-hangzhou.aliyuncs.com";
// // 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录
// // 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录
...
@@ -416,79 +422,79 @@ public class OSSUtil {
...
@@ -416,79 +422,79 @@ public class OSSUtil {
// // 指定前缀。
// // 指定前缀。
// final String prefix = "<yourkeyPrefix>";
// final String prefix = "<yourkeyPrefix>";
// 创建OSSClient实例。
// 创建OSSClient实例。
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
// 列举所有包含指定前缀的文件并删除。
// 列举所有包含指定前缀的文件并删除。
String
nextMarker
=
null
;
String
nextMarker
=
null
;
ObjectListing
objectListing
=
null
;
ObjectListing
objectListing
=
null
;
do
{
do
{
ListObjectsRequest
listObjectsRequest
=
new
ListObjectsRequest
(
bucketName
).
withPrefix
(
prefix
)
ListObjectsRequest
listObjectsRequest
=
new
ListObjectsRequest
(
bucketName
).
withPrefix
(
prefix
)
.
withMarker
(
nextMarker
);
.
withMarker
(
nextMarker
);
objectListing
=
ossClient
.
listObjects
(
listObjectsRequest
);
objectListing
=
ossClient
.
listObjects
(
listObjectsRequest
);
if
(
objectListing
.
getObjectSummaries
().
size
()
>
0
)
{
if
(
objectListing
.
getObjectSummaries
().
size
()
>
0
)
{
List
<
String
>
keys
=
new
ArrayList
<
String
>();
List
<
String
>
keys
=
new
ArrayList
<
String
>();
for
(
OSSObjectSummary
s
:
objectListing
.
getObjectSummaries
())
{
for
(
OSSObjectSummary
s
:
objectListing
.
getObjectSummaries
())
{
Logoutput
(
"key name: "
+
s
.
getKey
());
Logoutput
(
"key name: "
+
s
.
getKey
());
keys
.
add
(
s
.
getKey
());
keys
.
add
(
s
.
getKey
());
}
}
DeleteObjectsRequest
deleteObjectsRequest
=
new
DeleteObjectsRequest
(
bucketName
).
withKeys
(
keys
);
DeleteObjectsRequest
deleteObjectsRequest
=
new
DeleteObjectsRequest
(
bucketName
).
withKeys
(
keys
);
ossClient
.
deleteObjects
(
deleteObjectsRequest
);
ossClient
.
deleteObjects
(
deleteObjectsRequest
);
}
}
nextMarker
=
objectListing
.
getNextMarker
();
nextMarker
=
objectListing
.
getNextMarker
();
}
while
(
objectListing
.
isTruncated
());
}
while
(
objectListing
.
isTruncated
());
// 关闭OSSClient。
// 关闭OSSClient。
ossClient
.
shutdown
();
ossClient
.
shutdown
();
}
}
/*
/*
* (跨域资源) // Endpoint以杭州为例,其它Region请按实际情况填写。 String endpoint =
* (跨域资源) // Endpoint以杭州为例,其它Region请按实际情况填写。 String endpoint =
* "http://oss-cn-hangzhou.aliyuncs.com"; //
* "http://oss-cn-hangzhou.aliyuncs.com"; //
* 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录
* 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录
* https://ram.console.aliyun.com 创建RAM账号 String accessKeyId =
* https://ram.console.aliyun.com 创建RAM账号 String accessKeyId =
* "<yourAccessKeyId>"; String accessKeySecret = "<yourAccessKeySecret>"; String
* "<yourAccessKeyId>"; String accessKeySecret = "<yourAccessKeySecret>"; String
* bucketName = "<yourBucketName>";
* bucketName = "<yourBucketName>";
*
*
* // 创建OSSClient实例。 OSS ossClient = new OSSClientBuilder().build(endpoint,
* // 创建OSSClient实例。 OSS ossClient = new OSSClientBuilder().build(endpoint,
* accessKeyId, accessKeySecret);
* accessKeyId, accessKeySecret);
*
*
* SetBucketCORSRequest request = new SetBucketCORSRequest(bucketName);
* SetBucketCORSRequest request = new SetBucketCORSRequest(bucketName);
*
*
* // 跨域资源共享规则的容器,每个存储空间最多允许10条规则。 ArrayList<CORSRule> putCorsRules = new
* // 跨域资源共享规则的容器,每个存储空间最多允许10条规则。 ArrayList<CORSRule> putCorsRules = new
* ArrayList<CORSRule>();
* ArrayList<CORSRule>();
*
*
* CORSRule corRule = new CORSRule();
* CORSRule corRule = new CORSRule();
*
*
* ArrayList<String> allowedOrigin = new ArrayList<String>(); // 指定允许跨域请求的来源。
* ArrayList<String> allowedOrigin = new ArrayList<String>(); // 指定允许跨域请求的来源。
* allowedOrigin.add( "http://www.b.com");
* allowedOrigin.add( "http://www.b.com");
*
*
* ArrayList<String> allowedMethod = new ArrayList<String>(); //
* ArrayList<String> allowedMethod = new ArrayList<String>(); //
* 指定允许的跨域请求方法(GET/PUT/DELETE/POST/HEAD)。 allowedMethod.add("GET");
* 指定允许的跨域请求方法(GET/PUT/DELETE/POST/HEAD)。 allowedMethod.add("GET");
*
*
* ArrayList<String> allowedHeader = new ArrayList<String>(); //
* ArrayList<String> allowedHeader = new ArrayList<String>(); //
* 是否允许预取指令(OPTIONS)中Access-Control-Request-Headers头中指定的Header。
* 是否允许预取指令(OPTIONS)中Access-Control-Request-Headers头中指定的Header。
* allowedHeader.add("x-oss-test");
* allowedHeader.add("x-oss-test");
*
*
* ArrayList<String> exposedHeader = new ArrayList<String>(); //
* ArrayList<String> exposedHeader = new ArrayList<String>(); //
* 指定允许用户从应用程序中访问的响应头。 exposedHeader.add("x-oss-test1"); //
* 指定允许用户从应用程序中访问的响应头。 exposedHeader.add("x-oss-test1"); //
* AllowedOrigins和AllowedMethods最多支持一个星号(*)通配符。星号(*)表示允许所有的域来源或者操作。
* AllowedOrigins和AllowedMethods最多支持一个星号(*)通配符。星号(*)表示允许所有的域来源或者操作。
* corRule.setAllowedMethods(allowedMethod);
* corRule.setAllowedMethods(allowedMethod);
* corRule.setAllowedOrigins(allowedOrigin); //
* corRule.setAllowedOrigins(allowedOrigin); //
* AllowedHeaders和ExposeHeaders不支持通配符。 corRule.setAllowedHeaders(allowedHeader);
* AllowedHeaders和ExposeHeaders不支持通配符。 corRule.setAllowedHeaders(allowedHeader);
* corRule.setExposeHeaders(exposedHeader); //
* corRule.setExposeHeaders(exposedHeader); //
* 指定浏览器对特定资源的预取(OPTIONS)请求返回结果的缓存时间,单位为秒。 corRule.setMaxAgeSeconds(10);
* 指定浏览器对特定资源的预取(OPTIONS)请求返回结果的缓存时间,单位为秒。 corRule.setMaxAgeSeconds(10);
*
*
* // 最多允许10条规则。 putCorsRules.add(corRule); // 已存在的规则将被覆盖。
* // 最多允许10条规则。 putCorsRules.add(corRule); // 已存在的规则将被覆盖。
* request.setCorsRules(putCorsRules); ossClient.setBucketCORS(request);
* request.setCorsRules(putCorsRules); ossClient.setBucketCORS(request);
*
*
* // 关闭OSSClient。 ossClient.shutdown();
* // 关闭OSSClient。 ossClient.shutdown();
*/
*/
public
void
download
(
String
url
,
String
savePath
)
{
public
void
download
(
String
url
,
String
savePath
)
{
// Endpoint以杭州为例,其它Region请按实际情况填写。
// Endpoint以杭州为例,其它Region请按实际情况填写。
// String endpoint = "http://oss-cn-shenzhen.aliyuncs.com";
// String endpoint = "http://oss-cn-shenzhen.aliyuncs.com";
// // 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录
// // 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录
// // https://ram.console.aliyun.com 创建RAM账号。
// // https://ram.console.aliyun.com 创建RAM账号。
...
@@ -497,79 +503,138 @@ public class OSSUtil {
...
@@ -497,79 +503,138 @@ public class OSSUtil {
// String bucketName = "8time-v2";
// String bucketName = "8time-v2";
// String objectName = "8timer2.0/117/test/测试.pdf";
// String objectName = "8timer2.0/117/test/测试.pdf";
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
// String url = "http://8time-v2.oss-cn-shenzhen.aliyuncs.com/8timer2.0/310/qyxx/filepath/158872957193802f4a85a-9dd9-483a-9049-86fac5c73bd5.pdf?Expires=4747952308&OSSAccessKeyId=LTAI4FuaShJWQ1dggsFWG5CC&Signature=z%2FNIX0RrxnLuBLAS9olPpxxsCrI%3D";
// String url = "http://8time-v2.oss-cn-shenzhen.aliyuncs.com/8timer2.0/310/qyxx/filepath/158872957193802f4a85a-9dd9-483a-9049-86fac5c73bd5.pdf?Expires=4747952308&OSSAccessKeyId=LTAI4FuaShJWQ1dggsFWG5CC&Signature=z%2FNIX0RrxnLuBLAS9olPpxxsCrI%3D";
try
{
try
{
// 带进度条的下载。
// 带进度条的下载。
ObjectMetadata
a
=
ossClient
.
getObject
(
new
GetObjectRequest
(
new
URL
(
url
),
null
),
new
File
(
savePath
));
ObjectMetadata
a
=
ossClient
.
getObject
(
new
GetObjectRequest
(
new
URL
(
url
),
null
),
new
File
(
savePath
));
System
.
err
.
println
(
a
);
System
.
err
.
println
(
a
);
// new File("C:\\Users\\Lenovo\\Desktop\\8小时\\test2.pdf"));
// new File("C:\\Users\\Lenovo\\Desktop\\8小时\\test2.pdf"));
// // 带进度条的下载。
// // 带进度条的下载。
// ossClient.getObject(new GetObjectRequest(bucketName, objectName).<GetObjectRequest>withProgressListener(
// ossClient.getObject(new GetObjectRequest(bucketName, objectName).<GetObjectRequest>withProgressListener(
// new GetObjectProgressListener()), new File("C:\\Users\\Lenovo\\Desktop\\8小时\\test.pdf"));
// new GetObjectProgressListener()), new File("C:\\Users\\Lenovo\\Desktop\\8小时\\test.pdf"));
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
// 关闭OSSClient。
// 关闭OSSClient。
ossClient
.
shutdown
();
ossClient
.
shutdown
();
}
}
static
class
GetObjectProgressListener
implements
ProgressListener
{
static
class
GetObjectProgressListener
implements
ProgressListener
{
private
long
bytesRead
=
0
;
private
long
bytesRead
=
0
;
private
long
totalBytes
=
-
1
;
private
long
totalBytes
=
-
1
;
private
boolean
succeed
=
false
;
private
boolean
succeed
=
false
;
@Override
@Override
public
void
progressChanged
(
ProgressEvent
progressEvent
)
{
public
void
progressChanged
(
ProgressEvent
progressEvent
)
{
long
bytes
=
progressEvent
.
getBytes
();
long
bytes
=
progressEvent
.
getBytes
();
ProgressEventType
eventType
=
progressEvent
.
getEventType
();
ProgressEventType
eventType
=
progressEvent
.
getEventType
();
switch
(
eventType
)
{
switch
(
eventType
)
{
case
TRANSFER_STARTED_EVENT:
case
TRANSFER_STARTED_EVENT:
System
.
out
.
println
(
"Start to download......"
);
System
.
out
.
println
(
"Start to download......"
);
break
;
break
;
case
RESPONSE_CONTENT_LENGTH_EVENT:
case
RESPONSE_CONTENT_LENGTH_EVENT:
this
.
totalBytes
=
bytes
;
this
.
totalBytes
=
bytes
;
System
.
out
.
println
(
this
.
totalBytes
+
" bytes in total will be downloaded to a local file"
);
System
.
out
.
println
(
this
.
totalBytes
+
" bytes in total will be downloaded to a local file"
);
break
;
break
;
case
RESPONSE_BYTE_TRANSFER_EVENT:
case
RESPONSE_BYTE_TRANSFER_EVENT:
this
.
bytesRead
+=
bytes
;
this
.
bytesRead
+=
bytes
;
if
(
this
.
totalBytes
!=
-
1
)
{
if
(
this
.
totalBytes
!=
-
1
)
{
int
percent
=
(
int
)
(
this
.
bytesRead
*
100.0
/
this
.
totalBytes
);
int
percent
=
(
int
)
(
this
.
bytesRead
*
100.0
/
this
.
totalBytes
);
System
.
out
.
println
(
bytes
+
" bytes have been read at this time, download progress: "
+
percent
System
.
out
.
println
(
bytes
+
" bytes have been read at this time, download progress: "
+
percent
+
"%("
+
this
.
bytesRead
+
"/"
+
this
.
totalBytes
+
")"
);
+
"%("
+
this
.
bytesRead
+
"/"
+
this
.
totalBytes
+
")"
);
}
else
{
}
else
{
System
.
out
.
println
(
bytes
+
" bytes have been read at this time, download ratio: unknown"
+
"("
System
.
out
.
println
(
bytes
+
" bytes have been read at this time, download ratio: unknown"
+
"("
+
this
.
bytesRead
+
"/...)"
);
+
this
.
bytesRead
+
"/...)"
);
}
}
break
;
break
;
case
TRANSFER_COMPLETED_EVENT:
case
TRANSFER_COMPLETED_EVENT:
this
.
succeed
=
true
;
this
.
succeed
=
true
;
System
.
out
.
println
(
"Succeed to download, "
+
this
.
bytesRead
+
" bytes have been transferred in total"
);
System
.
out
.
println
(
"Succeed to download, "
+
this
.
bytesRead
+
" bytes have been transferred in total"
);
break
;
break
;
case
TRANSFER_FAILED_EVENT:
case
TRANSFER_FAILED_EVENT:
System
.
out
.
println
(
"Failed to download, "
+
this
.
bytesRead
+
" bytes have been transferred"
);
System
.
out
.
println
(
"Failed to download, "
+
this
.
bytesRead
+
" bytes have been transferred"
);
break
;
break
;
default
:
default
:
break
;
break
;
}
}
}
}
public
boolean
isSucceed
()
{
public
boolean
isSucceed
()
{
return
succeed
;
return
succeed
;
}
}
}
}
@Value
(
"${config-8timer.environmental-science}"
)
@Value
(
"${config-8timer.environmental-science}"
)
public
String
environmental_science
;
public
String
environmental_science
;
public
void
Logoutput
(
String
science
)
{
public
void
Logoutput
(
String
science
)
{
if
(!(
"pro"
).
equals
(
environmental_science
))
{
if
(!(
"pro"
).
equals
(
environmental_science
))
{
System
.
out
.
println
(
science
);
System
.
out
.
println
(
science
);
}
else
{
}
else
{
System
.
out
.
println
(
""
);
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