Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
涂亚平
/
subsidy
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 80630d31
authored
Apr 18, 2023
by
涂亚平
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
oss
1 parent
59dc36cf
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
142 additions
and
41 deletions
src/main/java/com/subsidy/controller/OssController.java
src/main/java/com/subsidy/service/impl/RenSheJuServiceImpl.java
src/main/java/com/subsidy/service/impl/ShehuihuaServiceImpl.java
src/main/java/com/subsidy/vo/oss/GetSecretVO.java
src/main/java/com/subsidy/vo/oss/UploadFileVO.java
src/main/java/com/subsidy/controller/OssController.java
0 → 100644
View file @
80630d3
package
com
.
subsidy
.
controller
;
import
com.aliyun.oss.OSS
;
import
com.aliyun.oss.OSSClientBuilder
;
import
com.aliyun.oss.model.PutObjectRequest
;
import
com.aliyun.oss.model.PutObjectResult
;
import
com.subsidy.common.ResponseData
;
import
com.subsidy.common.ResponseVO
;
import
com.subsidy.vo.oss.GetSecretVO
;
import
com.subsidy.vo.oss.UploadFileVO
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
@Api
(
tags
=
"oss"
)
@RestController
@RequestMapping
(
"/oss"
)
public
class
OssController
{
public
static
final
String
keyId
=
"LTAI5tPAH7P7WQVeowo517BE"
;
public
static
final
String
secret
=
"0ueqhIfdAZyw5lWlBVSLpAxTtx37RY"
;
@Value
(
"${spring.profiles.active}"
)
private
String
env
;
@PostMapping
(
"getSecret"
)
@ApiOperation
(
"oss秘钥"
)
public
ResponseVO
getSecret
()
{
GetSecretVO
getSecretVO
=
new
GetSecretVO
();
getSecretVO
.
setKey
(
keyId
);
getSecretVO
.
setSecret
(
secret
);
return
ResponseData
.
generateCreatedResponse
(
0
,
getSecretVO
);
}
@PostMapping
(
"uploadFile"
)
@ApiOperation
(
"上传文件 file"
)
public
ResponseVO
uploadFile
(
@RequestParam
(
"file"
)
MultipartFile
file
)
{
// 创建OSSClient实例。
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
"http://oss-cn-shanghai.aliyuncs.com"
,
keyId
,
secret
);
UploadFileVO
uploadFileVO
=
new
UploadFileVO
();
try
{
if
(
env
.
equals
(
"test"
))
{
env
=
"ykhl-bigger-test"
;
}
else
{
env
=
"ykhl-bigger"
;
}
// 创建PutObjectRequest对象。
PutObjectRequest
putObjectRequest
=
new
PutObjectRequest
(
env
,
System
.
currentTimeMillis
()
+
"_"
+
file
.
getOriginalFilename
(),
file
.
getInputStream
());
// 设置该属性可以返回response。如果不设置,则返回的response为空。
putObjectRequest
.
setProcess
(
"true"
);
// 创建PutObject请求。
PutObjectResult
result
=
ossClient
.
putObject
(
putObjectRequest
);
// 如果上传成功,则返回200。
// System.out.println(result.getResponse().getUri());
uploadFileVO
.
setUrl
(
result
.
getResponse
().
getUri
());
}
catch
(
Exception
oe
)
{
oe
.
printStackTrace
();
}
finally
{
if
(
ossClient
!=
null
)
{
ossClient
.
shutdown
();
}
}
return
ResponseData
.
generateCreatedResponse
(
0
,
uploadFileVO
);
}
}
src/main/java/com/subsidy/service/impl/RenSheJuServiceImpl.java
View file @
80630d3
...
...
@@ -87,26 +87,26 @@ public class RenSheJuServiceImpl implements RenSheJuService {
System
.
out
.
println
(
JSONObject
.
fromObject
(
classBaseInfoDTO
).
toString
());
RequestBody
body
=
RequestBody
.
create
(
mediaType
,
JSONObject
.
fromObject
(
classBaseInfoDTO
).
toString
());
Request
request
=
new
Request
.
Builder
()
.
url
(
renSheConfig
.
getUrl
()
+
"/import/downstream/enterprise/uploadClass"
)
.
method
(
"POST"
,
body
)
.
addHeader
(
"User-Agent"
,
"Apifox/1.0.0 (https://www.apifox.cn)"
)
.
addHeader
(
"Content-Type"
,
"application/json"
)
.
build
();
Response
response
=
client
.
newCall
(
request
).
execute
();
RensheResponseVO
rensheResponseVO
=
JSON
.
parseObject
(
response
.
body
().
string
(),
RensheResponseVO
.
class
);
RenshejuHistoryDO
renshejuHistoryDO
=
new
RenshejuHistoryDO
();
renshejuHistoryDO
.
setInterfaceName
(
RenSheJuConstant
.
POST_2
);
renshejuHistoryDO
.
setInputParam
(
JSONObject
.
fromObject
(
classBaseInfoDTO
).
toString
());
if
(
200
==
response
.
code
())
{
renshejuHistoryDO
.
setOutputParam
(
rensheResponseVO
.
getCtt
().
toString
());
}
else
{
renshejuHistoryDO
.
setOutputParam
(
RenSheJuConstant
.
API_ERROR
);
}
renshejuHistoryMapper
.
insert
(
renshejuHistoryDO
);
return
rensheResponseVO
;
//
return null;
//
Request request = new Request.Builder()
//
.url(renSheConfig.getUrl() + "/import/downstream/enterprise/uploadClass")
//
.method("POST", body)
//
.addHeader("User-Agent", "Apifox/1.0.0 (https://www.apifox.cn)")
//
.addHeader("Content-Type", "application/json")
//
.build();
//
Response response = client.newCall(request).execute();
//
//
RensheResponseVO rensheResponseVO = JSON.parseObject(response.body().string(), RensheResponseVO.class);
//
RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
//
renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_2);
//
renshejuHistoryDO.setInputParam(JSONObject.fromObject(classBaseInfoDTO).toString());
//
if (200 == response.code()) {
//
renshejuHistoryDO.setOutputParam(rensheResponseVO.getCtt().toString());
//
} else {
//
renshejuHistoryDO.setOutputParam(RenSheJuConstant.API_ERROR);
//
}
//
renshejuHistoryMapper.insert(renshejuHistoryDO);
//
return rensheResponseVO;
return
null
;
}
else
{
RenshejuHistoryDO
renshejuHistoryDO
=
new
RenshejuHistoryDO
();
renshejuHistoryDO
.
setInterfaceName
(
RenSheJuConstant
.
POST_2
);
...
...
src/main/java/com/subsidy/service/impl/ShehuihuaServiceImpl.java
View file @
80630d3
...
...
@@ -126,27 +126,27 @@ public class ShehuihuaServiceImpl implements ShehuihuaService {
System
.
out
.
println
(
JSONObject
.
fromObject
(
classBaseInfoDTO
).
toString
());
RequestBody
body
=
RequestBody
.
create
(
mediaType
,
JSONObject
.
fromObject
(
classBaseInfoDTO
).
toString
());
Request
request
=
new
Request
.
Builder
()
.
url
(
renSheConfig
.
getUrl
()
+
"/import/downstream/social/uploadClass"
)
.
method
(
"POST"
,
body
)
.
addHeader
(
"User-Agent"
,
"Apifox/1.0.0 (https://www.apifox.cn)"
)
.
addHeader
(
"Content-Type"
,
"application/json"
)
.
build
();
Response
response
=
client
.
newCall
(
request
).
execute
();
RensheResponseVO
rensheResponseVO
=
JSON
.
parseObject
(
response
.
body
().
string
(),
RensheResponseVO
.
class
);
RenshejuHistoryDO
renshejuHistoryDO
=
new
RenshejuHistoryDO
();
renshejuHistoryDO
.
setInterfaceName
(
ShehuihuaConstant
.
POST_3
);
renshejuHistoryDO
.
setInputParam
(
JSONObject
.
fromObject
(
classBaseInfoDTO
).
toString
());
if
(
200
==
response
.
code
())
{
renshejuHistoryDO
.
setOutputParam
(
rensheResponseVO
.
getCtt
().
toString
());
}
else
{
renshejuHistoryDO
.
setOutputParam
(
RenSheJuConstant
.
API_ERROR
);
}
renshejuHistoryMapper
.
insert
(
renshejuHistoryDO
);
return
rensheResponseVO
;
//
return null;
//
RequestBody body = RequestBody.create(mediaType, JSONObject.fromObject(classBaseInfoDTO).toString());
//
Request request = new Request.Builder()
//
.url(renSheConfig.getUrl() + "/import/downstream/social/uploadClass")
//
.method("POST", body)
//
.addHeader("User-Agent", "Apifox/1.0.0 (https://www.apifox.cn)")
//
.addHeader("Content-Type", "application/json")
//
.build();
//
Response response = client.newCall(request).execute();
//
//
RensheResponseVO rensheResponseVO = JSON.parseObject(response.body().string(), RensheResponseVO.class);
//
RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
//
renshejuHistoryDO.setInterfaceName(ShehuihuaConstant.POST_3);
//
renshejuHistoryDO.setInputParam(JSONObject.fromObject(classBaseInfoDTO).toString());
//
if (200 == response.code()) {
//
renshejuHistoryDO.setOutputParam(rensheResponseVO.getCtt().toString());
//
} else {
//
renshejuHistoryDO.setOutputParam(RenSheJuConstant.API_ERROR);
//
}
//
renshejuHistoryMapper.insert(renshejuHistoryDO);
//
return rensheResponseVO;
return
null
;
}
else
{
RenshejuHistoryDO
renshejuHistoryDO
=
new
RenshejuHistoryDO
();
renshejuHistoryDO
.
setInterfaceName
(
ShehuihuaConstant
.
POST_3
);
...
...
src/main/java/com/subsidy/vo/oss/GetSecretVO.java
0 → 100644
View file @
80630d3
package
com
.
subsidy
.
vo
.
oss
;
import
lombok.Data
;
@Data
public
class
GetSecretVO
{
private
String
key
;
private
String
secret
;
}
src/main/java/com/subsidy/vo/oss/UploadFileVO.java
0 → 100644
View file @
80630d3
package
com
.
subsidy
.
vo
.
oss
;
import
lombok.Data
;
@Data
public
class
UploadFileVO
{
private
String
url
;
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment