Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
manager
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
reyun
manager
Commits
00227a49
Commit
00227a49
authored
3 years ago
by
kangxiaoshan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
上传附件
parent
c3405769
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
149 additions
and
28 deletions
+149
-28
pom.xml
pom.xml
+2
-1
AttachmnetUploadController.java
...in/java/common/controller/AttachmnetUploadController.java
+65
-0
PdController.java
src/main/java/common/controller/PdController.java
+18
-17
PdAttachment.java
src/main/java/common/model/PdAttachment.java
+30
-0
PdAttachmentRepository.java
src/main/java/common/repository/PdAttachmentRepository.java
+8
-0
DmpIncomeService.java
src/main/java/common/service/DmpIncomeService.java
+1
-1
DmpIncomeServiceImpl.java
src/main/java/common/service/impl/DmpIncomeServiceImpl.java
+21
-9
Constant.java
src/main/java/util/Constant.java
+1
-0
ddb.properties
src/main/resources/ddb.properties
+3
-0
No files found.
pom.xml
View file @
00227a49
...
...
@@ -178,7 +178,7 @@
<redis.event.database>
13
</redis.event.database>
<!--Redis setting//end-->
<downhost>
http://172.23.6.108:9001
</downhost>
<ddb.accesskey>
AKIAOS2UEXIFNVER2O6A
</ddb.accesskey>
<ddb.secretkey>
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
</ddb.secretkey>
<ddb.region>
cn-north-1
</ddb.region>
...
...
@@ -286,6 +286,7 @@
<redis.event.database>
13
</redis.event.database>
<!--Redis setting//end-->
<downhost>
http://172.31.25.137:9001
</downhost>
<ddb.accesskey>
AKIA3XXNRTS2KXU632MD
</ddb.accesskey>
<ddb.secretkey>
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
</ddb.secretkey>
<ddb.region>
cn-north-1
</ddb.region>
...
...
This diff is collapsed.
Click to expand it.
src/main/java/common/controller/AttachmnetUploadController.java
0 → 100644
View file @
00227a49
package
common
.
controller
;
import
common.model.DmpIncome
;
import
common.model.PdAttachment
;
import
common.model.User
;
import
common.service.DmpIncomeService
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
security.annotation.CurrentAccount
;
import
util.ResultModel
;
@Controller
@RequestMapping
(
"{platform}"
)
public
class
AttachmnetUploadController
{
@Autowired
DmpIncomeService
dmpIncomeService
;
//上传附件
@PostMapping
(
"/upload/attachment"
)
@ResponseBody
public
ResultModel
uploadAttach
(
@RequestParam
(
"file"
)
MultipartFile
[]
files
,
String
contractCode
,
@CurrentAccount
User
user
)
{
String
erroNames
=
""
;
for
(
MultipartFile
file
:
files
)
{
PdAttachment
attachment
=
dmpIncomeService
.
uploadPdAttach
(
file
,
contractCode
,
user
);
if
(
attachment
.
getFaild
())
{
erroNames
+=
" "
+
attachment
.
getFileOrginName
();
}
}
if
(!
StringUtils
.
isEmpty
(
erroNames
))
{
return
ResultModel
.
ERROR
(
5001
,
"文件:"
+
erroNames
+
"上传失败"
);
}
return
ResultModel
.
OK
();
}
//下载附加
@RequestMapping
(
value
=
"/download/attachment/{id}"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
APPLICATION_OCTET_STREAM_VALUE
)
public
ResponseEntity
<
byte
[]>
getDownloadResponseEntity
(
@PathVariable
Long
id
)
{
return
dmpIncomeService
.
downloadAttach
(
id
);
}
//删除附件
@PostMapping
(
"/delete/attachment/{id}"
)
@ResponseBody
public
ResultModel
deleteAttach
(
@PathVariable
Long
id
)
{
return
ResultModel
.
OK
(
dmpIncomeService
.
deleteAttach
(
id
));
}
//附件列表
@GetMapping
(
"/list/attachment"
)
@ResponseBody
public
ResultModel
attachList
(
String
code
,
String
startDate
,
String
endDate
,
@PathVariable
String
platform
)
{
return
dmpIncomeService
.
attachList
(
code
,
startDate
,
endDate
,
platform
);
}
}
This diff is collapsed.
Click to expand it.
src/main/java/common/controller/PdController.java
View file @
00227a49
...
...
@@ -48,22 +48,23 @@ public class PdController {
return
ResultModel
.
OK
(
dmpIncomeService
.
pdDelete
(
income
));
}
//上传附件
@PostMapping
(
"/upload/attachment"
)
public
ResultModel
uploadAttach
(
@RequestParam
(
"file"
)
MultipartFile
file
,
String
contractCode
,
@CurrentAccount
User
user
)
{
////上传附件
//@PostMapping("/upload/attachment")
//public ResultModel uploadAttach(@RequestParam("file") MultipartFile file, String contractCode, @CurrentAccount User user) {
//
// return ResultModel.OK(dmpIncomeService.uploadPdAttach(file, contractCode, user));
//}
//
////下载附加
//@RequestMapping(value = "download/attachment/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
//public ResponseEntity<byte[]> getDownloadResponseEntity(@PathVariable Long id) {
// return dmpIncomeService.downloadAttach(id);
//}
//
////删除附件
//@PostMapping("/delete/load/attachment/{id}")
//public ResultModel deleteAttach(@PathVariable Long id) {
// return ResultModel.OK(dmpIncomeService.deleteAttach(id));
//}
return
ResultModel
.
OK
(
dmpIncomeService
.
uploadPdAttach
(
file
,
contractCode
,
user
));
}
//下载附加
@RequestMapping
(
value
=
"download/attachment/{id}"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
APPLICATION_OCTET_STREAM_VALUE
)
public
ResponseEntity
<
byte
[]>
getDownloadResponseEntity
(
@PathVariable
Long
id
)
{
return
dmpIncomeService
.
downloadAttach
(
id
);
}
//删除附件
@PostMapping
(
"/delete/load/attachment/{id}"
)
public
ResultModel
deleteAttach
(
@PathVariable
Long
id
)
{
return
ResultModel
.
OK
(
dmpIncomeService
.
deleteAttach
(
id
));
}
}
This diff is collapsed.
Click to expand it.
src/main/java/common/model/PdAttachment.java
View file @
00227a49
...
...
@@ -3,6 +3,7 @@ package common.model;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
import
javax.persistence.Transient
;
import
java.util.Date
;
@Entity
...
...
@@ -13,7 +14,10 @@ public class PdAttachment {
private
String
fileName
;
//文件名
private
String
fileType
;
//文件类型
private
Date
uploadDate
;
//上传日期
private
String
uploadDateValue
;
private
String
uploadUser
;
private
Boolean
isFaild
;
// 是否失败
private
String
downloadUrl
;
@Id
@GeneratedValue
...
...
@@ -72,4 +76,30 @@ public class PdAttachment {
public
void
setFileType
(
String
fileType
)
{
this
.
fileType
=
fileType
;
}
@Transient
public
Boolean
getFaild
()
{
return
isFaild
;
}
public
void
setFaild
(
Boolean
faild
)
{
isFaild
=
faild
;
}
public
String
getUploadDateValue
()
{
return
uploadDateValue
;
}
public
void
setUploadDateValue
(
String
uploadDateValue
)
{
this
.
uploadDateValue
=
uploadDateValue
;
}
@Transient
public
String
getDownloadUrl
()
{
return
downloadUrl
;
}
public
void
setDownloadUrl
(
String
downloadUrl
)
{
this
.
downloadUrl
=
downloadUrl
;
}
}
This diff is collapsed.
Click to expand it.
src/main/java/common/repository/PdAttachmentRepository.java
View file @
00227a49
...
...
@@ -2,6 +2,14 @@ package common.repository;
import
common.model.PdAttachment
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.Query
;
import
java.util.List
;
public
interface
PdAttachmentRepository
extends
JpaRepository
<
PdAttachment
,
Long
>
{
List
<
PdAttachment
>
findBycontractCode
(
String
code
);
@Query
(
value
=
"select * from pd_attachment where contract_code=?1 and upload_date >= ?2 and upload_date <= ?3"
,
nativeQuery
=
true
)
List
<
PdAttachment
>
findBycontractCodeAndDate
(
String
code
,
String
startDate
,
String
endDate
);
}
This diff is collapsed.
Click to expand it.
src/main/java/common/service/DmpIncomeService.java
View file @
00227a49
...
...
@@ -7,7 +7,6 @@ import common.model.User;
import
org.apache.poi.hssf.usermodel.HSSFWorkbook
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.multipart.MultipartFile
;
import
tkio.model.Account
;
import
util.ResultModel
;
import
java.util.List
;
...
...
@@ -46,4 +45,5 @@ public interface DmpIncomeService {
HSSFWorkbook
exportPdIncomeList
(
String
startDate
,
String
endDate
,
String
bodyCode
,
String
serchName
);
ResultModel
attachList
(
String
code
,
String
startDate
,
String
endDate
,
String
platform
);
}
This diff is collapsed.
Click to expand it.
src/main/java/common/service/impl/DmpIncomeServiceImpl.java
View file @
00227a49
...
...
@@ -26,7 +26,7 @@ import util.ResultModel;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.math.BigDecimal
;
import
java.
math.MathContext
;
import
java.
net.URLEncoder
;
import
java.text.DateFormat
;
import
java.text.DecimalFormat
;
import
java.text.SimpleDateFormat
;
...
...
@@ -70,7 +70,6 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
PdAttachmentRepository
pdAttachmentRepository
;
public
static
final
Map
<
String
,
String
>
SHEET_NAMES
=
new
HashMap
();
private
static
final
Map
<
String
,
String
>
CONTRACT_TYPE_NAME
=
new
HashMap
();
private
static
final
Map
<
String
,
String
>
BUSINESS_TYPE_NAME
=
new
HashMap
();
...
...
@@ -716,23 +715,23 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
@Override
public
PdAttachment
uploadPdAttach
(
MultipartFile
file
,
String
contractCode
,
User
user
)
{
InputStream
inputStream
=
null
;
PdAttachment
attachment
=
new
PdAttachment
();
try
{
inputStream
=
file
.
getInputStream
();
PdAttachment
attachment
=
new
PdAttachment
();
attachment
.
setUploadDate
(
new
Date
());
attachment
.
setUploadDateValue
(
new
DateTime
(
attachment
.
getUploadDate
()).
toString
(
"yyyy-MM-dd HH:mm:ss"
));
attachment
.
setUploadUser
(
user
.
getName
());
attachment
.
setFileOrginName
(
file
.
getOriginalFilename
());
attachment
.
setFileName
(
contractCode
+
"_"
+
file
.
getOriginalFilename
());
attachment
.
setContractCode
(
contractCode
);
attachment
.
setFileType
(
file
.
getContentType
());
attachment
.
setFaild
(
false
);
// 上传文件
String
s3key
=
Constant
.
uploadPath
+
attachment
.
getFileName
();
String
s3key
=
Constant
.
uploadPath
+
"/"
+
attachment
.
getFileName
();
String
contentType
=
file
.
getContentType
();
AwsS3Util
.
getInstance
().
uploadStreamToS3
(
Constant
.
bucket
,
s3key
,
inputStream
,
contentType
,
file
.
getSize
());
pdAttachmentRepository
.
save
(
attachment
);
return
attachment
;
}
catch
(
IOException
e
)
{
...
...
@@ -744,24 +743,27 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
}
}
}
return
null
;
attachment
.
setFaild
(
true
);
return
attachment
;
}
@Override
public
ResponseEntity
<
byte
[]>
downloadAttach
(
Long
id
)
{
PdAttachment
attachment
=
pdAttachmentRepository
.
findOne
(
id
);
final
String
s3key
=
Constant
.
uploadPath
+
attachment
.
getFileName
();
final
String
s3key
=
Constant
.
uploadPath
+
"/"
+
attachment
.
getFileName
();
String
fileName
=
attachment
.
getFileOrginName
();
InputStream
in
=
null
;
byte
[]
content
;
String
fileType
=
attachment
.
getFileType
();
try
{
fileName
=
URLEncoder
.
encode
(
fileName
,
"UTF-8"
);
in
=
AwsS3Util
.
getInstance
().
downloadStreamFromS3
(
Constant
.
bucket
,
s3key
);
content
=
IOUtils
.
toByteArray
(
in
);
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
set
(
"filename"
,
fileName
);
headers
.
add
(
"content-disposition"
,
"attachment;
filename="
+
fileName
);
headers
.
add
(
"content-disposition"
,
"attachment;
filename="
+
fileName
);
headers
.
add
(
"Content-Type"
,
fileType
);
return
new
ResponseEntity
<>(
content
,
headers
,
org
.
springframework
.
http
.
HttpStatus
.
CREATED
);
}
catch
(
Exception
e
)
{
...
...
@@ -781,4 +783,14 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
return
attachment
;
}
@Override
public
ResultModel
attachList
(
String
code
,
String
startDate
,
String
endDate
,
String
platform
)
{
List
<
PdAttachment
>
attachments
;
if
(
StringUtils
.
isEmpty
(
startDate
))
{
attachments
=
pdAttachmentRepository
.
findBycontractCodeAndDate
(
code
,
startDate
,
endDate
);
}
else
{
attachments
=
pdAttachmentRepository
.
findBycontractCode
(
code
);
}
return
ResultModel
.
OK
(
attachments
);
}
}
This diff is collapsed.
Click to expand it.
src/main/java/util/Constant.java
View file @
00227a49
...
...
@@ -45,6 +45,7 @@ public class Constant {
public
static
String
ddbregion
=
ddbBundle
.
getString
(
"ddb.region"
);
public
static
String
bucket
=
ddbBundle
.
getString
(
"ddb.bucket"
);
public
static
String
uploadPath
=
ddbBundle
.
getString
(
"ddb.upload.path"
);
public
static
String
downhost
=
ddbBundle
.
getString
(
"downhost"
);
}
This diff is collapsed.
Click to expand it.
src/main/resources/ddb.properties
View file @
00227a49
...
...
@@ -3,3 +3,5 @@ ddb.secretkey=${ddb.secretkey}
ddb.region
=
${ddb.region}
ddb.bucket
=
${ddb.bucket}
ddb.upload.path
=
${ddb.upload.path}
downhost
=
${downhost}
\ No newline at end of file
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