Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cloud-fb
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王衍超
cloud-fb
Commits
eacc3981
Commit
eacc3981
authored
Apr 13, 2021
by
shiwenbo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改功能树,增加购砂单位与场站附件查询接口
parent
8780c738
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
1114 additions
and
42 deletions
+1114
-42
CompanyFunctionTree.jmx
...m/beecode/inz/portal/functiontree/CompanyFunctionTree.jmx
+1
-40
DefaultFunctionTree.jmx
...m/beecode/inz/portal/functiontree/DefaultFunctionTree.jmx
+2
-2
DinasCommonConfiguration.java
...a/com/xyst/dinas/biz/config/DinasCommonConfiguration.java
+15
-0
SandAttachmentController.java
...java/com/xyst/dinas/biz/web/SandAttachmentController.java
+534
-0
SandQueryController.java
...main/java/com/xyst/dinas/biz/web/SandQueryController.java
+14
-0
WarehouseAttachmentController.java
...com/xyst/dinas/biz/web/WarehouseAttachmentController.java
+534
-0
WarehouseQueryController.java
...java/com/xyst/dinas/biz/web/WarehouseQueryController.java
+14
-0
No files found.
backend/inz.basis/src/main/resources/com/beecode/inz/portal/functiontree/CompanyFunctionTree.jmx
View file @
eacc3981
...
@@ -141,19 +141,6 @@
...
@@ -141,19 +141,6 @@
</m:function-definition>
</m:function-definition>
<m:icon>
iconfont icon-qiyeshezhi
</m:icon>
<m:icon>
iconfont icon-qiyeshezhi
</m:icon>
</m:function-node>
</m:function-node>
<m:function-node>
<m:id>
b078b97e-4e8f-40f9-b015-f3de02b29f6e
</m:id>
<m:name>
refund_detail_company
</m:name>
<m:title>
退款记录
</m:title>
<m:index>
2000
</m:index>
<m:license></m:license>
<m:privilege></m:privilege>
<m:function-definition>
<m:view>
function-refund-detail-company
</m:view>
<m:view-config></m:view-config>
</m:function-definition>
<m:icon>
iconfont icon-qiyeshezhi
</m:icon>
</m:function-node>
</m:children>
</m:children>
</m:function-node>
</m:function-node>
<m:function-node>
<m:function-node>
...
@@ -168,36 +155,10 @@
...
@@ -168,36 +155,10 @@
<m:view-config></m:view-config>
<m:view-config></m:view-config>
</m:function-definition>
</m:function-definition>
<m:children>
<m:children>
<m:function-node>
<m:id>
c555b699-841c-4b73-b67e-efbe95603678
</m:id>
<m:name>
advance_detail_company
</m:name>
<m:title>
预付款明细
</m:title>
<m:index>
1000
</m:index>
<m:license></m:license>
<m:privilege></m:privilege>
<m:function-definition>
<m:view>
function-advance-detail-company
</m:view>
<m:view-config></m:view-config>
</m:function-definition>
<m:icon>
iconfont icon-qiyeshezhi
</m:icon>
</m:function-node>
<m:function-node>
<m:id>
0d1f2b6e-804d-4a86-ac72-50d98e2452fd
</m:id>
<m:name>
guarantee_detail_company
</m:name>
<m:title>
保证金明细
</m:title>
<m:index>
2000
</m:index>
<m:license></m:license>
<m:privilege></m:privilege>
<m:function-definition>
<m:view>
function-guarantee-detail-company
</m:view>
<m:view-config></m:view-config>
</m:function-definition>
<m:icon>
iconfont icon-qiyeshezhi
</m:icon>
</m:function-node>
<m:function-node>
<m:function-node>
<m:id>
a03d8f90-25f8-46ed-acc1-afba97a62017
</m:id>
<m:id>
a03d8f90-25f8-46ed-acc1-afba97a62017
</m:id>
<m:name>
payment_detail
</m:name>
<m:name>
payment_detail
</m:name>
<m:title>
扣款
明细
</m:title>
<m:title>
销售
明细
</m:title>
<m:index>
3000
</m:index>
<m:index>
3000
</m:index>
<m:license></m:license>
<m:license></m:license>
<m:privilege></m:privilege>
<m:privilege></m:privilege>
...
...
backend/inz.basis/src/main/resources/com/beecode/inz/portal/functiontree/DefaultFunctionTree.jmx
View file @
eacc3981
...
@@ -446,7 +446,7 @@
...
@@ -446,7 +446,7 @@
<m:function-node>
<m:function-node>
<m:id>
72809fb1-acab-496d-874d-a75580468a29
</m:id>
<m:id>
72809fb1-acab-496d-874d-a75580468a29
</m:id>
<m:name>
finance
</m:name>
<m:name>
finance
</m:name>
<m:title>
财务
</m:title>
<m:title>
资金
</m:title>
<m:index>
7000
</m:index>
<m:index>
7000
</m:index>
<m:license></m:license>
<m:license></m:license>
<m:privilege></m:privilege>
<m:privilege></m:privilege>
...
@@ -471,7 +471,7 @@
...
@@ -471,7 +471,7 @@
<m:function-node>
<m:function-node>
<m:id>
971f8462-4554-4ce0-bbf6-29c7b9a53d7e
</m:id>
<m:id>
971f8462-4554-4ce0-bbf6-29c7b9a53d7e
</m:id>
<m:name>
charge_detail
</m:name>
<m:name>
charge_detail
</m:name>
<m:title>
充值明细
</m:title>
<m:title>
银行入账
</m:title>
<m:index>
1000
</m:index>
<m:index>
1000
</m:index>
<m:license></m:license>
<m:license></m:license>
<m:privilege></m:privilege>
<m:privilege></m:privilege>
...
...
backend/xyst.dinas.biz/src/main/java/com/xyst/dinas/biz/config/DinasCommonConfiguration.java
View file @
eacc3981
...
@@ -7,8 +7,10 @@ import com.xyst.dinas.biz.internal.dao.PlanningCycleDao;
...
@@ -7,8 +7,10 @@ import com.xyst.dinas.biz.internal.dao.PlanningCycleDao;
import
com.xyst.dinas.biz.internal.service.PlanningCycleServiceImpl
;
import
com.xyst.dinas.biz.internal.service.PlanningCycleServiceImpl
;
import
com.xyst.dinas.biz.service.PlanningCycleService
;
import
com.xyst.dinas.biz.service.PlanningCycleService
;
import
com.xyst.dinas.biz.web.DinasCommonController
;
import
com.xyst.dinas.biz.web.DinasCommonController
;
import
com.xyst.dinas.biz.web.SandAttachmentController
;
import
com.xyst.dinas.biz.web.SandDictController
;
import
com.xyst.dinas.biz.web.SandDictController
;
import
com.xyst.dinas.biz.web.SandQueryController
;
import
com.xyst.dinas.biz.web.SandQueryController
;
import
com.xyst.dinas.biz.web.WarehouseAttachmentController
;
import
com.xyst.dinas.biz.web.WarehouseDictController
;
import
com.xyst.dinas.biz.web.WarehouseDictController
;
import
com.xyst.dinas.biz.web.WarehouseQueryController
;
import
com.xyst.dinas.biz.web.WarehouseQueryController
;
...
@@ -20,6 +22,7 @@ public class DinasCommonConfiguration {
...
@@ -20,6 +22,7 @@ public class DinasCommonConfiguration {
return
new
DinasCommonController
();
return
new
DinasCommonController
();
}
}
/**********购砂单位与场站单据通用查询接口************/
@Bean
@Bean
public
WarehouseQueryController
warehouseQueryController
()
{
public
WarehouseQueryController
warehouseQueryController
()
{
return
new
WarehouseQueryController
();
return
new
WarehouseQueryController
();
...
@@ -30,6 +33,7 @@ public class DinasCommonConfiguration {
...
@@ -30,6 +33,7 @@ public class DinasCommonConfiguration {
return
new
SandQueryController
();
return
new
SandQueryController
();
}
}
/**********购砂单位与场站数据字典查询接口************/
@Bean
@Bean
public
WarehouseDictController
warehouseDictController
()
{
public
WarehouseDictController
warehouseDictController
()
{
return
new
WarehouseDictController
();
return
new
WarehouseDictController
();
...
@@ -40,6 +44,17 @@ public class DinasCommonConfiguration {
...
@@ -40,6 +44,17 @@ public class DinasCommonConfiguration {
return
new
SandDictController
();
return
new
SandDictController
();
}
}
/**********购砂单位与场站附件查询接口************/
@Bean
public
WarehouseAttachmentController
warehouseAttachmentController
()
{
return
new
WarehouseAttachmentController
();
}
@Bean
public
SandAttachmentController
sandAttachmentController
()
{
return
new
SandAttachmentController
();
}
/***************计划周期 ************/
/***************计划周期 ************/
@Bean
@Bean
...
...
backend/xyst.dinas.biz/src/main/java/com/xyst/dinas/biz/web/SandAttachmentController.java
0 → 100644
View file @
eacc3981
package
com
.
xyst
.
dinas
.
biz
.
web
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.UnsupportedEncodingException
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Modifier
;
import
java.net.URLEncoder
;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
import
java.time.format.DateTimeFormatter
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.UUID
;
import
java.util.zip.CRC32
;
import
java.util.zip.CheckedOutputStream
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipOutputStream
;
import
javax.servlet.http.HttpServletRequest
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.core.io.ByteArrayResource
;
import
org.springframework.core.io.InputStreamResource
;
import
org.springframework.core.io.Resource
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.ui.ModelMap
;
import
org.springframework.util.Assert
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestHeader
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
com.beecode.bap.attachment.AttachmentConstants.FileCheck
;
import
com.beecode.bap.attachment.AttachmentInfo
;
import
com.beecode.bap.attachment.common.Utils
;
import
com.beecode.bap.attachment.exception.AttachmentDataDownLoadException
;
import
com.beecode.bap.attachment.exception.AttachmentDataUploadException
;
import
com.beecode.bap.attachment.exception.AttachmentException
;
import
com.beecode.bap.attachment.internal.CreatorAdapterService
;
import
com.beecode.bap.attachment.service.AttachmentService
;
import
com.jiuqi.np.tenant.spring.TenantRuntime
;
@RestController
@RequestMapping
(
value
=
"/sand/user/basis/attachments"
)
public
class
SandAttachmentController
{
private
static
final
String
DATESTYLE
=
"yyyy-MM-dd HH:mm:ss"
;
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
@Autowired
private
TenantRuntime
tenantRuntime
;
/* 用于非登录状态下获取图片的接口 */
public
List
<
AttachmentInfo
>
attachmentInfoImg
=
null
;
public
ResponseEntity
<
Resource
>
response
=
null
;
/* 用于非登录状态下获取图片的接口 */
@Autowired
private
AttachmentService
attachmentService
;
@RequestMapping
(
value
=
"files"
,
method
=
RequestMethod
.
POST
)
@Transactional
public
UUID
upload
(
@RequestParam
(
name
=
"belongId"
,
required
=
false
)
UUID
belongId
,
@RequestParam
(
name
=
"category"
,
required
=
false
)
String
category
,
@RequestParam
(
"file"
)
MultipartFile
[]
files
,
@RequestParam
(
name
=
"anonymous"
,
required
=
false
)
boolean
anonymous
,
@RequestHeader
(
name
=
HttpHeaders
.
USER_AGENT
,
required
=
false
)
String
userAgent
)
{
if
(
belongId
==
null
)
{
belongId
=
UUID
.
randomUUID
();
}
chechFileUpload
(
files
);
try
{
for
(
MultipartFile
file
:
files
)
{
if
(!
file
.
isEmpty
())
{
AttachmentInfo
info
=
generateInfo
(
belongId
,
category
,
anonymous
,
userAgent
,
file
);
attachmentService
.
insert
(
info
,
file
.
getInputStream
());
}
}
}
catch
(
IOException
e
)
{
logger
.
error
(
"数据上传异常!"
,
e
);
throw
new
AttachmentDataUploadException
(
"数据上传失败,"
+
e
.
getMessage
(),
e
);
}
return
belongId
;
}
@RequestMapping
(
value
=
"fileInfo/name"
,
method
=
RequestMethod
.
PUT
)
@Transactional
public
AttachmentInfo
updateFileName
(
@RequestBody
AttachmentInfo
attachmentInfo
)
{
Assert
.
notNull
(
attachmentInfo
.
getId
(),
"附件id不能为空!"
);
Assert
.
notNull
(
attachmentInfo
.
getFileName
(),
"附件名称不能为空!"
);
AttachmentInfo
result
=
attachmentService
.
updateFileName
(
attachmentInfo
);
return
result
;
}
@RequestMapping
(
value
=
"file"
,
method
=
RequestMethod
.
POST
)
@Transactional
public
AttachmentInfo
uploadASingle
(
@RequestParam
(
name
=
"belongId"
,
required
=
false
)
UUID
belongId
,
@RequestParam
(
name
=
"category"
,
required
=
false
)
String
category
,
@RequestParam
(
"file"
)
MultipartFile
file
,
@RequestParam
(
name
=
"anonymous"
,
required
=
false
)
boolean
anonymous
,
@RequestHeader
(
name
=
HttpHeaders
.
USER_AGENT
,
required
=
false
)
String
userAgent
)
{
if
(
belongId
==
null
)
{
belongId
=
UUID
.
randomUUID
();
}
chechFileUpload
(
file
);
AttachmentInfo
info
=
null
;
try
{
if
(!
file
.
isEmpty
())
{
info
=
generateInfo
(
belongId
,
category
,
anonymous
,
userAgent
,
file
);
attachmentService
.
insert
(
info
,
file
.
getInputStream
());
}
}
catch
(
IOException
e
)
{
logger
.
error
(
"数据上传异常!"
,
e
);
throw
new
AttachmentDataUploadException
(
"数据上传失败,"
+
e
.
getMessage
(),
e
);
}
return
info
;
}
private
AttachmentInfo
generateInfo
(
UUID
belongId
,
String
category
,
boolean
anonymous
,
String
userAgent
,
MultipartFile
file
)
{
AttachmentInfo
attachmentInfo
=
new
AttachmentInfo
();
attachmentInfo
.
setBelongId
(
belongId
);
if
(
category
!=
null
&&
!
""
.
equals
(
category
))
{
attachmentInfo
.
setCategory
(
category
);
}
if
(
anonymous
)
{
attachmentInfo
.
setFileName
(
UUID
.
randomUUID
()
+
"."
+
Utils
.
getFileType
(
file
.
getOriginalFilename
()));
}
else
if
(
isIE
(
userAgent
))
{
// macOS系统存在含‘\’文件名的文件所以分开写
attachmentInfo
.
setFileName
(
getFileNameByIE
(
file
.
getOriginalFilename
()));
}
else
{
attachmentInfo
.
setFileName
(
file
.
getOriginalFilename
());
}
attachmentInfo
.
setFileType
(
Utils
.
getFileType
(
file
.
getOriginalFilename
()));
attachmentInfo
.
setSize
(
file
.
getSize
());
UUID
currentCreatorId
=
getCurrentCreatorId
();
if
(
currentCreatorId
!=
null
)
{
attachmentInfo
.
setCreatorId
(
currentCreatorId
);
}
return
attachmentInfo
;
}
private
String
getFileNameByIE
(
String
fileName
)
{
String
[]
fileNameArray
=
fileName
.
split
(
"\\\\"
);
return
fileNameArray
[
fileNameArray
.
length
-
1
];
}
private
void
chechFileUpload
(
MultipartFile
[]
files
)
{
Assert
.
isTrue
(
files
.
length
<
FileCheck
.
MAXTOTAL
,
"文件数量不能超过30!"
);
for
(
MultipartFile
file
:
files
)
{
chechFileUpload
(
file
);
}
}
private
void
chechFileUpload
(
MultipartFile
file
)
{
Assert
.
isTrue
(!
FileCheck
.
NOTSUPPORTFILETYPE
.
contains
(
Utils
.
getFileType
(
file
.
getOriginalFilename
())),
"不支持的文件类型"
);
Assert
.
isTrue
(
file
.
getSize
()
<
FileCheck
.
MAXLENGTH
,
"单个文件大小不能超过10m!"
);
}
@SuppressWarnings
(
"unchecked"
)
@RequestMapping
(
value
=
"files"
,
method
=
RequestMethod
.
DELETE
)
@Transactional
public
void
delete
(
@RequestBody
ModelMap
modelMap
)
{
Object
fileIdObjects
=
modelMap
.
get
(
"fileIds"
);
if
(
fileIdObjects
!=
null
&&
fileIdObjects
instanceof
List
)
{
List
<
String
>
fileIds
=
(
List
<
String
>)
fileIdObjects
;
for
(
String
str
:
fileIds
)
{
attachmentService
.
delete
(
UUID
.
fromString
(
str
));
}
}
}
@RequestMapping
(
value
=
"files/{belongId}"
,
method
=
RequestMethod
.
DELETE
)
@Transactional
public
void
deleteByBelongId
(
@PathVariable
(
"belongId"
)
UUID
belongId
)
{
attachmentService
.
deleteByBelongId
(
belongId
);
}
@RequestMapping
(
value
=
"fileInfos/{fileId}"
,
method
=
RequestMethod
.
GET
)
public
Map
<
String
,
Object
>
getFileInfo
(
@PathVariable
(
"fileId"
)
UUID
fileId
)
{
Optional
<
AttachmentInfo
>
attachmentInfo
=
attachmentService
.
find
(
fileId
);
if
(
attachmentInfo
.
isPresent
())
{
Map
<
String
,
Object
>
map
=
toMap
(
attachmentInfo
.
get
());
map
.
put
(
"accessUrl"
,
attachmentService
.
getAccessUrl
(
attachmentInfo
.
get
()));
map
.
put
(
"createTime"
,
LocalDateTime
.
ofInstant
(
attachmentInfo
.
get
().
getCreateTime
(),
ZoneId
.
systemDefault
())
.
format
(
DateTimeFormatter
.
ofPattern
(
DATESTYLE
)));
if
(
attachmentInfo
.
get
().
getCreatorId
()
!=
null
)
{
map
.
put
(
"creatorName"
,
getCreatorName
(
attachmentInfo
.
get
().
getCreatorId
()));
}
return
map
;
}
else
{
return
null
;
}
}
@RequestMapping
(
value
=
"fileInfos"
,
method
=
RequestMethod
.
GET
)
public
List
<
Map
<
String
,
Object
>>
getFileInfoByBelongId
(
@RequestParam
(
"belongId"
)
UUID
belongId
)
{
List
<
Map
<
String
,
Object
>>
result
=
new
ArrayList
<>();
List
<
AttachmentInfo
>
attachmentInfos
=
attachmentService
.
findByBelongId
(
belongId
);
for
(
AttachmentInfo
attachmentInfo
:
attachmentInfos
)
{
Map
<
String
,
Object
>
item
=
toMap
(
attachmentInfo
);
item
.
put
(
"accessUrl"
,
attachmentService
.
getAccessUrl
(
attachmentInfo
));
item
.
put
(
"createTime"
,
LocalDateTime
.
ofInstant
(
attachmentInfo
.
getCreateTime
(),
ZoneId
.
systemDefault
())
.
format
(
DateTimeFormatter
.
ofPattern
(
DATESTYLE
)));
if
(
attachmentInfo
.
getCreatorId
()
!=
null
)
{
item
.
put
(
"creatorName"
,
getCreatorName
(
attachmentInfo
.
getCreatorId
()));
}
result
.
add
(
item
);
}
return
result
;
}
@RequestMapping
(
value
=
"{category}/fileInfos"
,
method
=
RequestMethod
.
GET
)
public
List
<
Map
<
String
,
Object
>>
getFileInfoByBelongId
(
@RequestParam
(
"belongId"
)
UUID
belongId
,
@PathVariable
(
"category"
)
String
category
)
{
List
<
Map
<
String
,
Object
>>
result
=
new
ArrayList
<>();
List
<
AttachmentInfo
>
attachmentInfos
=
attachmentService
.
findByBelongIdAndCategory
(
belongId
,
category
,
-
1
,
-
1
);
for
(
AttachmentInfo
attachmentInfo
:
attachmentInfos
)
{
Map
<
String
,
Object
>
item
=
toMap
(
attachmentInfo
);
item
.
put
(
"accessUrl"
,
attachmentService
.
getAccessUrl
(
attachmentInfo
));
item
.
put
(
"createTime"
,
LocalDateTime
.
ofInstant
(
attachmentInfo
.
getCreateTime
(),
ZoneId
.
systemDefault
())
.
format
(
DateTimeFormatter
.
ofPattern
(
DATESTYLE
)));
if
(
attachmentInfo
.
getCreatorId
()
!=
null
)
{
item
.
put
(
"creatorName"
,
getCreatorName
(
attachmentInfo
.
getCreatorId
()));
}
result
.
add
(
item
);
}
return
result
;
}
@RequestMapping
(
value
=
"files/{fileId}"
,
method
=
RequestMethod
.
GET
)
public
ResponseEntity
<
Resource
>
download
(
@PathVariable
UUID
fileId
,
HttpServletRequest
request
)
{
Optional
<
AttachmentInfo
>
attachmentInfo
=
attachmentService
.
find
(
fileId
);
if
(
attachmentInfo
.
isPresent
())
{
InputStream
inputStream
=
attachmentService
.
getInputStream
(
fileId
);
String
fileName
=
encodeFileName
(
request
,
attachmentInfo
.
get
().
getFileName
());
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"charset"
,
"utf-8"
);
headers
.
add
(
"Content-Disposition"
,
"attachment;filename=\""
+
fileName
+
"\""
);
Resource
resource
=
new
InputStreamResource
(
inputStream
);
return
ResponseEntity
.
ok
().
headers
(
headers
).
contentType
(
MediaType
.
APPLICATION_OCTET_STREAM
).
body
(
resource
);
}
else
{
logger
.
warn
(
"没有找到要下载的文件! 文件id: "
+
fileId
);
}
return
null
;
}
@RequestMapping
(
value
=
"files/preview/{fileId}"
,
method
=
RequestMethod
.
GET
)
public
ResponseEntity
<
Resource
>
preview
(
@PathVariable
UUID
fileId
,
HttpServletRequest
request
)
{
Optional
<
AttachmentInfo
>
attachmentInfo
=
attachmentService
.
find
(
fileId
);
if
(
attachmentInfo
.
isPresent
())
{
InputStream
inputStream
=
attachmentService
.
getInputStream
(
fileId
);
String
fileName
=
encodeFileName
(
request
,
attachmentInfo
.
get
().
getFileName
());
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"charset"
,
"utf-8"
);
headers
.
add
(
"Content-Disposition"
,
"inline;filename=\""
+
fileName
+
"\""
);
Resource
resource
=
new
InputStreamResource
(
inputStream
);
return
ResponseEntity
.
ok
().
headers
(
headers
)
.
contentType
(
MediaType
.
valueOf
(
Utils
.
getContentType
(
Utils
.
getFileType
(
attachmentInfo
.
get
().
getFileName
()))))
.
body
(
resource
);
}
else
{
logger
.
warn
(
"没有找到要预览的文件! 文件id: "
+
fileId
);
}
return
null
;
}
@RequestMapping
(
value
=
"files/preview/open/{fileId}"
,
method
=
RequestMethod
.
GET
)
public
ResponseEntity
<
Resource
>
previewOpen
(
@PathVariable
UUID
fileId
,
@RequestParam
(
value
=
"tenant"
)
String
tenant
,
HttpServletRequest
request
)
{
final
List
<
Optional
<
AttachmentInfo
>>
attachmentInfos
=
new
ArrayList
<>();
Optional
<
AttachmentInfo
>
attachmentInfo
=
null
;
try
{
tenantRuntime
.
runAsTenant
(
tenant
,
()
->
findByOpenWay
(
attachmentInfos
,
fileId
));
attachmentInfo
=
attachmentInfos
.
get
(
0
);
if
(
attachmentInfo
.
isPresent
())
{
List
<
InputStream
>
inputStreams
=
new
ArrayList
<>();
tenantRuntime
.
runAsTenant
(
tenant
,
()
->
getInputStreamByOpenWay
(
inputStreams
,
fileId
));
InputStream
inputStream
=
inputStreams
.
get
(
0
);
String
fileName
=
encodeFileName
(
request
,
attachmentInfo
.
get
().
getFileName
());
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"charset"
,
"utf-8"
);
headers
.
add
(
"Content-Disposition"
,
"inline;filename=\""
+
fileName
+
"\""
);
Resource
resource
=
new
InputStreamResource
(
inputStream
);
return
ResponseEntity
.
ok
().
headers
(
headers
)
.
contentType
(
MediaType
.
valueOf
(
Utils
.
getContentType
(
Utils
.
getFileType
(
attachmentInfo
.
get
().
getFileName
()))))
.
body
(
resource
);
}
else
{
logger
.
warn
(
"1没有找到要预览的文件! 文件id: "
+
fileId
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
logger
.
warn
(
"2没有找到要预览的文件! 文件id: "
+
fileId
);
}
return
null
;
}
private
void
getInputStreamByOpenWay
(
List
<
InputStream
>
inputStreams
,
UUID
fileId
){
InputStream
inputStream
=
attachmentService
.
getInputStream
(
fileId
);
inputStreams
.
add
(
inputStream
);
}
private
void
findByOpenWay
(
List
<
Optional
<
AttachmentInfo
>>
attachmentInfos
,
UUID
fileId
)
{
Optional
<
AttachmentInfo
>
attachmentInfo
=
attachmentService
.
find
(
fileId
);
attachmentInfos
.
add
(
attachmentInfo
);
}
@RequestMapping
(
value
=
"files/preview/single/{belongId}"
,
method
=
RequestMethod
.
GET
)
public
ResponseEntity
<
Resource
>
singlePreview
(
@PathVariable
UUID
belongId
,
HttpServletRequest
request
)
{
List
<
AttachmentInfo
>
attachmentInfo
=
attachmentService
.
findByBelongId
(
belongId
);
if
(
attachmentInfo
.
size
()
>
0
)
{
InputStream
inputStream
=
attachmentService
.
getInputStream
(
attachmentInfo
.
get
(
0
).
getId
());
String
fileName
=
encodeFileName
(
request
,
attachmentInfo
.
get
(
0
).
getFileName
());
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"charset"
,
"utf-8"
);
headers
.
add
(
"Content-Disposition"
,
"inline;filename=\""
+
fileName
+
"\""
);
Resource
resource
=
new
InputStreamResource
(
inputStream
);
return
ResponseEntity
.
ok
().
headers
(
headers
)
.
contentType
(
MediaType
.
valueOf
(
Utils
.
getContentType
(
Utils
.
getFileType
(
attachmentInfo
.
get
(
0
).
getFileName
()))))
.
body
(
resource
);
}
else
{
logger
.
warn
(
"单文件模式下没有找到要预览的文件! 文件belongId: "
+
belongId
);
}
return
null
;
}
/**
* 该controller是提供了一个在非登录状态下预览图片的接口
*
* @param belongId
* @param request
* @param tenant
* @return
*/
@RequestMapping
(
value
=
"files/previewWithTenant/single/{belongId}"
,
method
=
RequestMethod
.
GET
)
public
ResponseEntity
<
Resource
>
singlePreviewWithTenant
(
@PathVariable
UUID
belongId
,
HttpServletRequest
request
,
@RequestParam
(
value
=
"tenant"
)
String
tenant
)
{
try
{
tenantRuntime
.
runAsTenant
(
tenant
,
()
->
{
attachmentInfoImg
=
attachmentService
.
findByBelongId
(
belongId
);
if
(
attachmentInfoImg
.
size
()
>
0
)
{
InputStream
inputStream
=
attachmentService
.
getInputStream
(
attachmentInfoImg
.
get
(
0
).
getId
());
String
fileName
=
encodeFileName
(
request
,
attachmentInfoImg
.
get
(
0
).
getFileName
());
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"charset"
,
"utf-8"
);
headers
.
add
(
"Content-Disposition"
,
"inline;filename=\""
+
fileName
+
"\""
);
Resource
resource
=
new
InputStreamResource
(
inputStream
);
response
=
ResponseEntity
.
ok
().
headers
(
headers
)
.
contentType
(
MediaType
.
valueOf
(
Utils
.
getContentType
(
Utils
.
getFileType
(
attachmentInfoImg
.
get
(
0
).
getFileName
()))))
.
body
(
resource
);
}
else
{
logger
.
warn
(
"单文件模式下没有找到要预览的文件! 文件belongId: "
+
belongId
);
}
});
return
response
;
}
catch
(
Exception
e
)
{
return
null
;
}
}
@RequestMapping
(
value
=
"files/preview/{belongId}/{index}"
,
method
=
RequestMethod
.
GET
)
public
ResponseEntity
<
Resource
>
previewByBelong
(
@PathVariable
UUID
belongId
,
@PathVariable
Integer
index
,
HttpServletRequest
request
)
{
List
<
AttachmentInfo
>
attachmentInfos
=
attachmentService
.
findByBelongId
(
belongId
);
if
(
attachmentInfos
.
size
()
>
index
)
{
InputStream
inputStream
=
attachmentService
.
getInputStream
(
attachmentInfos
.
get
(
index
).
getId
());
String
fileName
=
encodeFileName
(
request
,
attachmentInfos
.
get
(
index
).
getFileName
());
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"charset"
,
"utf-8"
);
headers
.
add
(
"Content-Disposition"
,
"inline;filename=\""
+
fileName
+
"\""
);
Resource
resource
=
new
InputStreamResource
(
inputStream
);
return
ResponseEntity
.
ok
().
headers
(
headers
)
.
contentType
(
MediaType
.
valueOf
(
Utils
.
getContentType
(
Utils
.
getFileType
(
attachmentInfos
.
get
(
index
).
getFileName
()))))
.
body
(
resource
);
}
else
{
logger
.
warn
(
"单文件模式下没有找到要预览的文件! 文件belongId: "
+
belongId
+
", index:"
+
index
);
}
return
null
;
}
@RequestMapping
(
value
=
"files"
,
method
=
RequestMethod
.
GET
)
public
ResponseEntity
<
Resource
>
downloadZip
(
@RequestParam
(
"belongId"
)
UUID
belongId
,
@RequestParam
(
name
=
"fileIds"
,
required
=
false
)
List
<
UUID
>
fileIds
,
@RequestHeader
(
name
=
HttpHeaders
.
USER_AGENT
,
required
=
false
)
String
userAgent
)
{
List
<
AttachmentInfo
>
attachmentInfos
=
attachmentService
.
findByBelongId
(
belongId
);
if
(
attachmentInfos
!=
null
&&
attachmentInfos
.
size
()
>
0
)
{
ZipOutputStream
zipOutputStream
=
null
;
try
{
ByteArrayOutputStream
arrayOutputStream
=
new
ByteArrayOutputStream
();
CheckedOutputStream
checkedOutputStream
=
new
CheckedOutputStream
(
arrayOutputStream
,
new
CRC32
());
zipOutputStream
=
new
ZipOutputStream
(
checkedOutputStream
);
for
(
AttachmentInfo
attachmentInfo
:
attachmentInfos
)
{
if
(
fileIds
!=
null
&&
!
fileIds
.
contains
(
attachmentInfo
.
getId
()))
{
continue
;
}
ZipEntry
zipEntry
=
new
ZipEntry
(
attachmentInfo
.
getFileName
());
zipOutputStream
.
putNextEntry
(
zipEntry
);
InputStream
inputStream
=
attachmentService
.
getInputStream
(
attachmentInfo
.
getId
());
int
count
=
-
1
;
byte
[]
temp
=
new
byte
[
1024
];
try
{
while
((
count
=
inputStream
.
read
(
temp
))
!=
-
1
)
{
zipOutputStream
.
write
(
temp
,
0
,
count
);
}
zipOutputStream
.
closeEntry
();
}
catch
(
IOException
e
)
{
logger
.
error
(
"数据下载异常: 数据读写异常"
,
e
);
throw
new
AttachmentDataDownLoadException
(
"数据下载异常: 数据读写异常"
,
e
);
}
finally
{
try
{
inputStream
.
close
();
}
catch
(
IOException
e
)
{
logger
.
error
(
"数据下载异常: 流关闭异常!"
,
e
);
throw
new
AttachmentDataDownLoadException
(
"数据下载异常: 流关闭异常!"
,
e
);
}
}
}
zipOutputStream
.
flush
();
zipOutputStream
.
finish
();
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"charset"
,
"utf-8"
);
String
fileName
=
new
String
(
"附件.zip"
.
getBytes
(
"utf-8"
),
"iso-8859-1"
);
if
(
isIE
(
userAgent
))
{
fileName
=
URLEncoder
.
encode
(
fileName
,
"UTF-8"
);
}
headers
.
add
(
"Content-Disposition"
,
"attachment;filename=\""
+
fileName
+
"\""
);
Resource
resource
=
new
ByteArrayResource
(
arrayOutputStream
.
toByteArray
());
return
ResponseEntity
.
ok
().
headers
(
headers
).
contentType
(
MediaType
.
APPLICATION_OCTET_STREAM
)
.
body
(
resource
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"数据下载异常: 创建流错误!"
,
e
);
throw
new
AttachmentDataDownLoadException
(
"数据下载异常: 创建流错误!"
,
e
);
}
finally
{
try
{
if
(
zipOutputStream
!=
null
)
{
zipOutputStream
.
close
();
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"数据下载异常: 流关闭异常!"
,
e
);
throw
new
AttachmentDataDownLoadException
(
"数据下载异常: 流关闭异常!"
,
e
);
}
}
}
else
{
logger
.
warn
(
"没有找到要下载的文件! 文件belongId: "
+
belongId
);
}
return
null
;
}
/**
* 判断是否是ie
*
* @return
*/
private
boolean
isIE
(
String
userAgent
)
{
if
(
userAgent
!=
null
)
{
userAgent
=
userAgent
.
toLowerCase
();
return
userAgent
.
contains
(
"msie"
)
||
userAgent
.
contains
(
"trident"
)
||
userAgent
.
contains
(
"edge"
);
}
return
false
;
}
@Autowired
private
CreatorAdapterService
creatorAdapterService
;
private
UUID
getCurrentCreatorId
()
{
return
creatorAdapterService
.
getCurrentCreatorId
();
}
private
String
getCreatorName
(
UUID
id
)
{
return
creatorAdapterService
.
getCreatorName
(
id
);
}
private
Map
<
String
,
Object
>
toMap
(
AttachmentInfo
info
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>(
20
);
Field
[]
fields
=
info
.
getClass
().
getDeclaredFields
();
for
(
Field
field
:
fields
)
{
int
mod
=
field
.
getModifiers
();
if
(
Modifier
.
isStatic
(
mod
)
||
Modifier
.
isFinal
(
mod
))
{
continue
;
}
field
.
setAccessible
(
true
);
try
{
map
.
put
(
field
.
getName
(),
field
.
get
(
info
));
}
catch
(
Exception
e
)
{
throw
new
AttachmentException
(
"数据转换异常!"
,
e
);
}
}
return
map
;
}
private
String
encodeFileName
(
HttpServletRequest
request
,
String
infoFileName
)
{
String
fileName
=
null
;
String
userAgent
=
request
.
getHeader
(
"user-agent"
).
toLowerCase
();
try
{
if
(
isIE
(
userAgent
))
{
// win10 ie edge 浏览器 和其他系统的ie
fileName
=
URLEncoder
.
encode
(
infoFileName
,
"UTF-8"
);
}
else
{
// 其他的浏览器
fileName
=
new
String
(
infoFileName
.
getBytes
(
"utf-8"
),
"iso-8859-1"
);
}
}
catch
(
UnsupportedEncodingException
e
)
{
logger
.
error
(
"数据下载异常:文件名编码错误"
,
e
);
throw
new
AttachmentDataDownLoadException
(
"数据下载异常:文件名编码错误"
,
e
);
}
return
fileName
;
}
}
backend/xyst.dinas.biz/src/main/java/com/xyst/dinas/biz/web/SandQueryController.java
View file @
eacc3981
...
@@ -6,9 +6,11 @@ import java.util.List;
...
@@ -6,9 +6,11 @@ import java.util.List;
import
java.util.UUID
;
import
java.util.UUID
;
import
org.json.JSONArray
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.web.servlet.MultipartProperties
;
import
org.springframework.security.access.AccessDeniedException
;
import
org.springframework.security.access.AccessDeniedException
;
import
org.springframework.web.bind.annotation.CrossOrigin
;
import
org.springframework.web.bind.annotation.CrossOrigin
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
...
@@ -58,11 +60,23 @@ public class SandQueryController {
...
@@ -58,11 +60,23 @@ public class SandQueryController {
@Autowired
@Autowired
private
PrivilegeService
privilegeService
;
private
PrivilegeService
privilegeService
;
@Autowired
MultipartProperties
multipartProperties
;
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
SandQueryController
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
SandQueryController
.
class
);
private
static
final
ObjectMapper
OBJECTMAPPER
=
new
ObjectMapper
();
private
static
final
ObjectMapper
OBJECTMAPPER
=
new
ObjectMapper
();
@ResponseBody
@RequestMapping
(
value
=
"/sand/user/common/config/getMaxFileSize"
,
method
=
RequestMethod
.
GET
,
consumes
=
"application/json"
)
public
String
getMaxFileSize
()
{
JSONObject
o
=
new
JSONObject
();
o
.
put
(
"result"
,
true
);
o
.
put
(
"data"
,
multipartProperties
.
getMaxFileSize
());
return
o
.
toString
();
}
/**
/**
* 查询分页
* 查询分页
*
*
...
...
backend/xyst.dinas.biz/src/main/java/com/xyst/dinas/biz/web/WarehouseAttachmentController.java
0 → 100644
View file @
eacc3981
package
com
.
xyst
.
dinas
.
biz
.
web
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.UnsupportedEncodingException
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Modifier
;
import
java.net.URLEncoder
;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
import
java.time.format.DateTimeFormatter
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.UUID
;
import
java.util.zip.CRC32
;
import
java.util.zip.CheckedOutputStream
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipOutputStream
;
import
javax.servlet.http.HttpServletRequest
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.core.io.ByteArrayResource
;
import
org.springframework.core.io.InputStreamResource
;
import
org.springframework.core.io.Resource
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.ui.ModelMap
;
import
org.springframework.util.Assert
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestHeader
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
com.beecode.bap.attachment.AttachmentConstants.FileCheck
;
import
com.beecode.bap.attachment.AttachmentInfo
;
import
com.beecode.bap.attachment.common.Utils
;
import
com.beecode.bap.attachment.exception.AttachmentDataDownLoadException
;
import
com.beecode.bap.attachment.exception.AttachmentDataUploadException
;
import
com.beecode.bap.attachment.exception.AttachmentException
;
import
com.beecode.bap.attachment.internal.CreatorAdapterService
;
import
com.beecode.bap.attachment.service.AttachmentService
;
import
com.jiuqi.np.tenant.spring.TenantRuntime
;
@RestController
@RequestMapping
(
value
=
"/warehouse/api/basis/attachments"
)
public
class
WarehouseAttachmentController
{
private
static
final
String
DATESTYLE
=
"yyyy-MM-dd HH:mm:ss"
;
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
@Autowired
private
TenantRuntime
tenantRuntime
;
/* 用于非登录状态下获取图片的接口 */
public
List
<
AttachmentInfo
>
attachmentInfoImg
=
null
;
public
ResponseEntity
<
Resource
>
response
=
null
;
/* 用于非登录状态下获取图片的接口 */
@Autowired
private
AttachmentService
attachmentService
;
@RequestMapping
(
value
=
"files"
,
method
=
RequestMethod
.
POST
)
@Transactional
public
UUID
upload
(
@RequestParam
(
name
=
"belongId"
,
required
=
false
)
UUID
belongId
,
@RequestParam
(
name
=
"category"
,
required
=
false
)
String
category
,
@RequestParam
(
"file"
)
MultipartFile
[]
files
,
@RequestParam
(
name
=
"anonymous"
,
required
=
false
)
boolean
anonymous
,
@RequestHeader
(
name
=
HttpHeaders
.
USER_AGENT
,
required
=
false
)
String
userAgent
)
{
if
(
belongId
==
null
)
{
belongId
=
UUID
.
randomUUID
();
}
chechFileUpload
(
files
);
try
{
for
(
MultipartFile
file
:
files
)
{
if
(!
file
.
isEmpty
())
{
AttachmentInfo
info
=
generateInfo
(
belongId
,
category
,
anonymous
,
userAgent
,
file
);
attachmentService
.
insert
(
info
,
file
.
getInputStream
());
}
}
}
catch
(
IOException
e
)
{
logger
.
error
(
"数据上传异常!"
,
e
);
throw
new
AttachmentDataUploadException
(
"数据上传失败,"
+
e
.
getMessage
(),
e
);
}
return
belongId
;
}
@RequestMapping
(
value
=
"fileInfo/name"
,
method
=
RequestMethod
.
PUT
)
@Transactional
public
AttachmentInfo
updateFileName
(
@RequestBody
AttachmentInfo
attachmentInfo
)
{
Assert
.
notNull
(
attachmentInfo
.
getId
(),
"附件id不能为空!"
);
Assert
.
notNull
(
attachmentInfo
.
getFileName
(),
"附件名称不能为空!"
);
AttachmentInfo
result
=
attachmentService
.
updateFileName
(
attachmentInfo
);
return
result
;
}
@RequestMapping
(
value
=
"file"
,
method
=
RequestMethod
.
POST
)
@Transactional
public
AttachmentInfo
uploadASingle
(
@RequestParam
(
name
=
"belongId"
,
required
=
false
)
UUID
belongId
,
@RequestParam
(
name
=
"category"
,
required
=
false
)
String
category
,
@RequestParam
(
"file"
)
MultipartFile
file
,
@RequestParam
(
name
=
"anonymous"
,
required
=
false
)
boolean
anonymous
,
@RequestHeader
(
name
=
HttpHeaders
.
USER_AGENT
,
required
=
false
)
String
userAgent
)
{
if
(
belongId
==
null
)
{
belongId
=
UUID
.
randomUUID
();
}
chechFileUpload
(
file
);
AttachmentInfo
info
=
null
;
try
{
if
(!
file
.
isEmpty
())
{
info
=
generateInfo
(
belongId
,
category
,
anonymous
,
userAgent
,
file
);
attachmentService
.
insert
(
info
,
file
.
getInputStream
());
}
}
catch
(
IOException
e
)
{
logger
.
error
(
"数据上传异常!"
,
e
);
throw
new
AttachmentDataUploadException
(
"数据上传失败,"
+
e
.
getMessage
(),
e
);
}
return
info
;
}
private
AttachmentInfo
generateInfo
(
UUID
belongId
,
String
category
,
boolean
anonymous
,
String
userAgent
,
MultipartFile
file
)
{
AttachmentInfo
attachmentInfo
=
new
AttachmentInfo
();
attachmentInfo
.
setBelongId
(
belongId
);
if
(
category
!=
null
&&
!
""
.
equals
(
category
))
{
attachmentInfo
.
setCategory
(
category
);
}
if
(
anonymous
)
{
attachmentInfo
.
setFileName
(
UUID
.
randomUUID
()
+
"."
+
Utils
.
getFileType
(
file
.
getOriginalFilename
()));
}
else
if
(
isIE
(
userAgent
))
{
// macOS系统存在含‘\’文件名的文件所以分开写
attachmentInfo
.
setFileName
(
getFileNameByIE
(
file
.
getOriginalFilename
()));
}
else
{
attachmentInfo
.
setFileName
(
file
.
getOriginalFilename
());
}
attachmentInfo
.
setFileType
(
Utils
.
getFileType
(
file
.
getOriginalFilename
()));
attachmentInfo
.
setSize
(
file
.
getSize
());
UUID
currentCreatorId
=
getCurrentCreatorId
();
if
(
currentCreatorId
!=
null
)
{
attachmentInfo
.
setCreatorId
(
currentCreatorId
);
}
return
attachmentInfo
;
}
private
String
getFileNameByIE
(
String
fileName
)
{
String
[]
fileNameArray
=
fileName
.
split
(
"\\\\"
);
return
fileNameArray
[
fileNameArray
.
length
-
1
];
}
private
void
chechFileUpload
(
MultipartFile
[]
files
)
{
Assert
.
isTrue
(
files
.
length
<
FileCheck
.
MAXTOTAL
,
"文件数量不能超过30!"
);
for
(
MultipartFile
file
:
files
)
{
chechFileUpload
(
file
);
}
}
private
void
chechFileUpload
(
MultipartFile
file
)
{
Assert
.
isTrue
(!
FileCheck
.
NOTSUPPORTFILETYPE
.
contains
(
Utils
.
getFileType
(
file
.
getOriginalFilename
())),
"不支持的文件类型"
);
Assert
.
isTrue
(
file
.
getSize
()
<
FileCheck
.
MAXLENGTH
,
"单个文件大小不能超过10m!"
);
}
@SuppressWarnings
(
"unchecked"
)
@RequestMapping
(
value
=
"files"
,
method
=
RequestMethod
.
DELETE
)
@Transactional
public
void
delete
(
@RequestBody
ModelMap
modelMap
)
{
Object
fileIdObjects
=
modelMap
.
get
(
"fileIds"
);
if
(
fileIdObjects
!=
null
&&
fileIdObjects
instanceof
List
)
{
List
<
String
>
fileIds
=
(
List
<
String
>)
fileIdObjects
;
for
(
String
str
:
fileIds
)
{
attachmentService
.
delete
(
UUID
.
fromString
(
str
));
}
}
}
@RequestMapping
(
value
=
"files/{belongId}"
,
method
=
RequestMethod
.
DELETE
)
@Transactional
public
void
deleteByBelongId
(
@PathVariable
(
"belongId"
)
UUID
belongId
)
{
attachmentService
.
deleteByBelongId
(
belongId
);
}
@RequestMapping
(
value
=
"fileInfos/{fileId}"
,
method
=
RequestMethod
.
GET
)
public
Map
<
String
,
Object
>
getFileInfo
(
@PathVariable
(
"fileId"
)
UUID
fileId
)
{
Optional
<
AttachmentInfo
>
attachmentInfo
=
attachmentService
.
find
(
fileId
);
if
(
attachmentInfo
.
isPresent
())
{
Map
<
String
,
Object
>
map
=
toMap
(
attachmentInfo
.
get
());
map
.
put
(
"accessUrl"
,
attachmentService
.
getAccessUrl
(
attachmentInfo
.
get
()));
map
.
put
(
"createTime"
,
LocalDateTime
.
ofInstant
(
attachmentInfo
.
get
().
getCreateTime
(),
ZoneId
.
systemDefault
())
.
format
(
DateTimeFormatter
.
ofPattern
(
DATESTYLE
)));
if
(
attachmentInfo
.
get
().
getCreatorId
()
!=
null
)
{
map
.
put
(
"creatorName"
,
getCreatorName
(
attachmentInfo
.
get
().
getCreatorId
()));
}
return
map
;
}
else
{
return
null
;
}
}
@RequestMapping
(
value
=
"fileInfos"
,
method
=
RequestMethod
.
GET
)
public
List
<
Map
<
String
,
Object
>>
getFileInfoByBelongId
(
@RequestParam
(
"belongId"
)
UUID
belongId
)
{
List
<
Map
<
String
,
Object
>>
result
=
new
ArrayList
<>();
List
<
AttachmentInfo
>
attachmentInfos
=
attachmentService
.
findByBelongId
(
belongId
);
for
(
AttachmentInfo
attachmentInfo
:
attachmentInfos
)
{
Map
<
String
,
Object
>
item
=
toMap
(
attachmentInfo
);
item
.
put
(
"accessUrl"
,
attachmentService
.
getAccessUrl
(
attachmentInfo
));
item
.
put
(
"createTime"
,
LocalDateTime
.
ofInstant
(
attachmentInfo
.
getCreateTime
(),
ZoneId
.
systemDefault
())
.
format
(
DateTimeFormatter
.
ofPattern
(
DATESTYLE
)));
if
(
attachmentInfo
.
getCreatorId
()
!=
null
)
{
item
.
put
(
"creatorName"
,
getCreatorName
(
attachmentInfo
.
getCreatorId
()));
}
result
.
add
(
item
);
}
return
result
;
}
@RequestMapping
(
value
=
"{category}/fileInfos"
,
method
=
RequestMethod
.
GET
)
public
List
<
Map
<
String
,
Object
>>
getFileInfoByBelongId
(
@RequestParam
(
"belongId"
)
UUID
belongId
,
@PathVariable
(
"category"
)
String
category
)
{
List
<
Map
<
String
,
Object
>>
result
=
new
ArrayList
<>();
List
<
AttachmentInfo
>
attachmentInfos
=
attachmentService
.
findByBelongIdAndCategory
(
belongId
,
category
,
-
1
,
-
1
);
for
(
AttachmentInfo
attachmentInfo
:
attachmentInfos
)
{
Map
<
String
,
Object
>
item
=
toMap
(
attachmentInfo
);
item
.
put
(
"accessUrl"
,
attachmentService
.
getAccessUrl
(
attachmentInfo
));
item
.
put
(
"createTime"
,
LocalDateTime
.
ofInstant
(
attachmentInfo
.
getCreateTime
(),
ZoneId
.
systemDefault
())
.
format
(
DateTimeFormatter
.
ofPattern
(
DATESTYLE
)));
if
(
attachmentInfo
.
getCreatorId
()
!=
null
)
{
item
.
put
(
"creatorName"
,
getCreatorName
(
attachmentInfo
.
getCreatorId
()));
}
result
.
add
(
item
);
}
return
result
;
}
@RequestMapping
(
value
=
"files/{fileId}"
,
method
=
RequestMethod
.
GET
)
public
ResponseEntity
<
Resource
>
download
(
@PathVariable
UUID
fileId
,
HttpServletRequest
request
)
{
Optional
<
AttachmentInfo
>
attachmentInfo
=
attachmentService
.
find
(
fileId
);
if
(
attachmentInfo
.
isPresent
())
{
InputStream
inputStream
=
attachmentService
.
getInputStream
(
fileId
);
String
fileName
=
encodeFileName
(
request
,
attachmentInfo
.
get
().
getFileName
());
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"charset"
,
"utf-8"
);
headers
.
add
(
"Content-Disposition"
,
"attachment;filename=\""
+
fileName
+
"\""
);
Resource
resource
=
new
InputStreamResource
(
inputStream
);
return
ResponseEntity
.
ok
().
headers
(
headers
).
contentType
(
MediaType
.
APPLICATION_OCTET_STREAM
).
body
(
resource
);
}
else
{
logger
.
warn
(
"没有找到要下载的文件! 文件id: "
+
fileId
);
}
return
null
;
}
@RequestMapping
(
value
=
"files/preview/{fileId}"
,
method
=
RequestMethod
.
GET
)
public
ResponseEntity
<
Resource
>
preview
(
@PathVariable
UUID
fileId
,
HttpServletRequest
request
)
{
Optional
<
AttachmentInfo
>
attachmentInfo
=
attachmentService
.
find
(
fileId
);
if
(
attachmentInfo
.
isPresent
())
{
InputStream
inputStream
=
attachmentService
.
getInputStream
(
fileId
);
String
fileName
=
encodeFileName
(
request
,
attachmentInfo
.
get
().
getFileName
());
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"charset"
,
"utf-8"
);
headers
.
add
(
"Content-Disposition"
,
"inline;filename=\""
+
fileName
+
"\""
);
Resource
resource
=
new
InputStreamResource
(
inputStream
);
return
ResponseEntity
.
ok
().
headers
(
headers
)
.
contentType
(
MediaType
.
valueOf
(
Utils
.
getContentType
(
Utils
.
getFileType
(
attachmentInfo
.
get
().
getFileName
()))))
.
body
(
resource
);
}
else
{
logger
.
warn
(
"没有找到要预览的文件! 文件id: "
+
fileId
);
}
return
null
;
}
@RequestMapping
(
value
=
"files/preview/open/{fileId}"
,
method
=
RequestMethod
.
GET
)
public
ResponseEntity
<
Resource
>
previewOpen
(
@PathVariable
UUID
fileId
,
@RequestParam
(
value
=
"tenant"
)
String
tenant
,
HttpServletRequest
request
)
{
final
List
<
Optional
<
AttachmentInfo
>>
attachmentInfos
=
new
ArrayList
<>();
Optional
<
AttachmentInfo
>
attachmentInfo
=
null
;
try
{
tenantRuntime
.
runAsTenant
(
tenant
,
()
->
findByOpenWay
(
attachmentInfos
,
fileId
));
attachmentInfo
=
attachmentInfos
.
get
(
0
);
if
(
attachmentInfo
.
isPresent
())
{
List
<
InputStream
>
inputStreams
=
new
ArrayList
<>();
tenantRuntime
.
runAsTenant
(
tenant
,
()
->
getInputStreamByOpenWay
(
inputStreams
,
fileId
));
InputStream
inputStream
=
inputStreams
.
get
(
0
);
String
fileName
=
encodeFileName
(
request
,
attachmentInfo
.
get
().
getFileName
());
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"charset"
,
"utf-8"
);
headers
.
add
(
"Content-Disposition"
,
"inline;filename=\""
+
fileName
+
"\""
);
Resource
resource
=
new
InputStreamResource
(
inputStream
);
return
ResponseEntity
.
ok
().
headers
(
headers
)
.
contentType
(
MediaType
.
valueOf
(
Utils
.
getContentType
(
Utils
.
getFileType
(
attachmentInfo
.
get
().
getFileName
()))))
.
body
(
resource
);
}
else
{
logger
.
warn
(
"1没有找到要预览的文件! 文件id: "
+
fileId
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
logger
.
warn
(
"2没有找到要预览的文件! 文件id: "
+
fileId
);
}
return
null
;
}
private
void
getInputStreamByOpenWay
(
List
<
InputStream
>
inputStreams
,
UUID
fileId
){
InputStream
inputStream
=
attachmentService
.
getInputStream
(
fileId
);
inputStreams
.
add
(
inputStream
);
}
private
void
findByOpenWay
(
List
<
Optional
<
AttachmentInfo
>>
attachmentInfos
,
UUID
fileId
)
{
Optional
<
AttachmentInfo
>
attachmentInfo
=
attachmentService
.
find
(
fileId
);
attachmentInfos
.
add
(
attachmentInfo
);
}
@RequestMapping
(
value
=
"files/preview/single/{belongId}"
,
method
=
RequestMethod
.
GET
)
public
ResponseEntity
<
Resource
>
singlePreview
(
@PathVariable
UUID
belongId
,
HttpServletRequest
request
)
{
List
<
AttachmentInfo
>
attachmentInfo
=
attachmentService
.
findByBelongId
(
belongId
);
if
(
attachmentInfo
.
size
()
>
0
)
{
InputStream
inputStream
=
attachmentService
.
getInputStream
(
attachmentInfo
.
get
(
0
).
getId
());
String
fileName
=
encodeFileName
(
request
,
attachmentInfo
.
get
(
0
).
getFileName
());
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"charset"
,
"utf-8"
);
headers
.
add
(
"Content-Disposition"
,
"inline;filename=\""
+
fileName
+
"\""
);
Resource
resource
=
new
InputStreamResource
(
inputStream
);
return
ResponseEntity
.
ok
().
headers
(
headers
)
.
contentType
(
MediaType
.
valueOf
(
Utils
.
getContentType
(
Utils
.
getFileType
(
attachmentInfo
.
get
(
0
).
getFileName
()))))
.
body
(
resource
);
}
else
{
logger
.
warn
(
"单文件模式下没有找到要预览的文件! 文件belongId: "
+
belongId
);
}
return
null
;
}
/**
* 该controller是提供了一个在非登录状态下预览图片的接口
*
* @param belongId
* @param request
* @param tenant
* @return
*/
@RequestMapping
(
value
=
"files/previewWithTenant/single/{belongId}"
,
method
=
RequestMethod
.
GET
)
public
ResponseEntity
<
Resource
>
singlePreviewWithTenant
(
@PathVariable
UUID
belongId
,
HttpServletRequest
request
,
@RequestParam
(
value
=
"tenant"
)
String
tenant
)
{
try
{
tenantRuntime
.
runAsTenant
(
tenant
,
()
->
{
attachmentInfoImg
=
attachmentService
.
findByBelongId
(
belongId
);
if
(
attachmentInfoImg
.
size
()
>
0
)
{
InputStream
inputStream
=
attachmentService
.
getInputStream
(
attachmentInfoImg
.
get
(
0
).
getId
());
String
fileName
=
encodeFileName
(
request
,
attachmentInfoImg
.
get
(
0
).
getFileName
());
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"charset"
,
"utf-8"
);
headers
.
add
(
"Content-Disposition"
,
"inline;filename=\""
+
fileName
+
"\""
);
Resource
resource
=
new
InputStreamResource
(
inputStream
);
response
=
ResponseEntity
.
ok
().
headers
(
headers
)
.
contentType
(
MediaType
.
valueOf
(
Utils
.
getContentType
(
Utils
.
getFileType
(
attachmentInfoImg
.
get
(
0
).
getFileName
()))))
.
body
(
resource
);
}
else
{
logger
.
warn
(
"单文件模式下没有找到要预览的文件! 文件belongId: "
+
belongId
);
}
});
return
response
;
}
catch
(
Exception
e
)
{
return
null
;
}
}
@RequestMapping
(
value
=
"files/preview/{belongId}/{index}"
,
method
=
RequestMethod
.
GET
)
public
ResponseEntity
<
Resource
>
previewByBelong
(
@PathVariable
UUID
belongId
,
@PathVariable
Integer
index
,
HttpServletRequest
request
)
{
List
<
AttachmentInfo
>
attachmentInfos
=
attachmentService
.
findByBelongId
(
belongId
);
if
(
attachmentInfos
.
size
()
>
index
)
{
InputStream
inputStream
=
attachmentService
.
getInputStream
(
attachmentInfos
.
get
(
index
).
getId
());
String
fileName
=
encodeFileName
(
request
,
attachmentInfos
.
get
(
index
).
getFileName
());
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"charset"
,
"utf-8"
);
headers
.
add
(
"Content-Disposition"
,
"inline;filename=\""
+
fileName
+
"\""
);
Resource
resource
=
new
InputStreamResource
(
inputStream
);
return
ResponseEntity
.
ok
().
headers
(
headers
)
.
contentType
(
MediaType
.
valueOf
(
Utils
.
getContentType
(
Utils
.
getFileType
(
attachmentInfos
.
get
(
index
).
getFileName
()))))
.
body
(
resource
);
}
else
{
logger
.
warn
(
"单文件模式下没有找到要预览的文件! 文件belongId: "
+
belongId
+
", index:"
+
index
);
}
return
null
;
}
@RequestMapping
(
value
=
"files"
,
method
=
RequestMethod
.
GET
)
public
ResponseEntity
<
Resource
>
downloadZip
(
@RequestParam
(
"belongId"
)
UUID
belongId
,
@RequestParam
(
name
=
"fileIds"
,
required
=
false
)
List
<
UUID
>
fileIds
,
@RequestHeader
(
name
=
HttpHeaders
.
USER_AGENT
,
required
=
false
)
String
userAgent
)
{
List
<
AttachmentInfo
>
attachmentInfos
=
attachmentService
.
findByBelongId
(
belongId
);
if
(
attachmentInfos
!=
null
&&
attachmentInfos
.
size
()
>
0
)
{
ZipOutputStream
zipOutputStream
=
null
;
try
{
ByteArrayOutputStream
arrayOutputStream
=
new
ByteArrayOutputStream
();
CheckedOutputStream
checkedOutputStream
=
new
CheckedOutputStream
(
arrayOutputStream
,
new
CRC32
());
zipOutputStream
=
new
ZipOutputStream
(
checkedOutputStream
);
for
(
AttachmentInfo
attachmentInfo
:
attachmentInfos
)
{
if
(
fileIds
!=
null
&&
!
fileIds
.
contains
(
attachmentInfo
.
getId
()))
{
continue
;
}
ZipEntry
zipEntry
=
new
ZipEntry
(
attachmentInfo
.
getFileName
());
zipOutputStream
.
putNextEntry
(
zipEntry
);
InputStream
inputStream
=
attachmentService
.
getInputStream
(
attachmentInfo
.
getId
());
int
count
=
-
1
;
byte
[]
temp
=
new
byte
[
1024
];
try
{
while
((
count
=
inputStream
.
read
(
temp
))
!=
-
1
)
{
zipOutputStream
.
write
(
temp
,
0
,
count
);
}
zipOutputStream
.
closeEntry
();
}
catch
(
IOException
e
)
{
logger
.
error
(
"数据下载异常: 数据读写异常"
,
e
);
throw
new
AttachmentDataDownLoadException
(
"数据下载异常: 数据读写异常"
,
e
);
}
finally
{
try
{
inputStream
.
close
();
}
catch
(
IOException
e
)
{
logger
.
error
(
"数据下载异常: 流关闭异常!"
,
e
);
throw
new
AttachmentDataDownLoadException
(
"数据下载异常: 流关闭异常!"
,
e
);
}
}
}
zipOutputStream
.
flush
();
zipOutputStream
.
finish
();
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"charset"
,
"utf-8"
);
String
fileName
=
new
String
(
"附件.zip"
.
getBytes
(
"utf-8"
),
"iso-8859-1"
);
if
(
isIE
(
userAgent
))
{
fileName
=
URLEncoder
.
encode
(
fileName
,
"UTF-8"
);
}
headers
.
add
(
"Content-Disposition"
,
"attachment;filename=\""
+
fileName
+
"\""
);
Resource
resource
=
new
ByteArrayResource
(
arrayOutputStream
.
toByteArray
());
return
ResponseEntity
.
ok
().
headers
(
headers
).
contentType
(
MediaType
.
APPLICATION_OCTET_STREAM
)
.
body
(
resource
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"数据下载异常: 创建流错误!"
,
e
);
throw
new
AttachmentDataDownLoadException
(
"数据下载异常: 创建流错误!"
,
e
);
}
finally
{
try
{
if
(
zipOutputStream
!=
null
)
{
zipOutputStream
.
close
();
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"数据下载异常: 流关闭异常!"
,
e
);
throw
new
AttachmentDataDownLoadException
(
"数据下载异常: 流关闭异常!"
,
e
);
}
}
}
else
{
logger
.
warn
(
"没有找到要下载的文件! 文件belongId: "
+
belongId
);
}
return
null
;
}
/**
* 判断是否是ie
*
* @return
*/
private
boolean
isIE
(
String
userAgent
)
{
if
(
userAgent
!=
null
)
{
userAgent
=
userAgent
.
toLowerCase
();
return
userAgent
.
contains
(
"msie"
)
||
userAgent
.
contains
(
"trident"
)
||
userAgent
.
contains
(
"edge"
);
}
return
false
;
}
@Autowired
private
CreatorAdapterService
creatorAdapterService
;
private
UUID
getCurrentCreatorId
()
{
return
creatorAdapterService
.
getCurrentCreatorId
();
}
private
String
getCreatorName
(
UUID
id
)
{
return
creatorAdapterService
.
getCreatorName
(
id
);
}
private
Map
<
String
,
Object
>
toMap
(
AttachmentInfo
info
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>(
20
);
Field
[]
fields
=
info
.
getClass
().
getDeclaredFields
();
for
(
Field
field
:
fields
)
{
int
mod
=
field
.
getModifiers
();
if
(
Modifier
.
isStatic
(
mod
)
||
Modifier
.
isFinal
(
mod
))
{
continue
;
}
field
.
setAccessible
(
true
);
try
{
map
.
put
(
field
.
getName
(),
field
.
get
(
info
));
}
catch
(
Exception
e
)
{
throw
new
AttachmentException
(
"数据转换异常!"
,
e
);
}
}
return
map
;
}
private
String
encodeFileName
(
HttpServletRequest
request
,
String
infoFileName
)
{
String
fileName
=
null
;
String
userAgent
=
request
.
getHeader
(
"user-agent"
).
toLowerCase
();
try
{
if
(
isIE
(
userAgent
))
{
// win10 ie edge 浏览器 和其他系统的ie
fileName
=
URLEncoder
.
encode
(
infoFileName
,
"UTF-8"
);
}
else
{
// 其他的浏览器
fileName
=
new
String
(
infoFileName
.
getBytes
(
"utf-8"
),
"iso-8859-1"
);
}
}
catch
(
UnsupportedEncodingException
e
)
{
logger
.
error
(
"数据下载异常:文件名编码错误"
,
e
);
throw
new
AttachmentDataDownLoadException
(
"数据下载异常:文件名编码错误"
,
e
);
}
return
fileName
;
}
}
backend/xyst.dinas.biz/src/main/java/com/xyst/dinas/biz/web/WarehouseQueryController.java
View file @
eacc3981
...
@@ -6,9 +6,11 @@ import java.util.List;
...
@@ -6,9 +6,11 @@ import java.util.List;
import
java.util.UUID
;
import
java.util.UUID
;
import
org.json.JSONArray
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.web.servlet.MultipartProperties
;
import
org.springframework.security.access.AccessDeniedException
;
import
org.springframework.security.access.AccessDeniedException
;
import
org.springframework.web.bind.annotation.CrossOrigin
;
import
org.springframework.web.bind.annotation.CrossOrigin
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
...
@@ -58,11 +60,23 @@ public class WarehouseQueryController {
...
@@ -58,11 +60,23 @@ public class WarehouseQueryController {
@Autowired
@Autowired
private
PrivilegeService
privilegeService
;
private
PrivilegeService
privilegeService
;
@Autowired
MultipartProperties
multipartProperties
;
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
WarehouseQueryController
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
WarehouseQueryController
.
class
);
private
static
final
ObjectMapper
OBJECTMAPPER
=
new
ObjectMapper
();
private
static
final
ObjectMapper
OBJECTMAPPER
=
new
ObjectMapper
();
@ResponseBody
@RequestMapping
(
value
=
"/warehouse/api/common/config/getMaxFileSize"
,
method
=
RequestMethod
.
GET
,
consumes
=
"application/json"
)
public
String
getMaxFileSize
()
{
JSONObject
o
=
new
JSONObject
();
o
.
put
(
"result"
,
true
);
o
.
put
(
"data"
,
multipartProperties
.
getMaxFileSize
());
return
o
.
toString
();
}
/**
/**
* 查询分页
* 查询分页
*
*
...
...
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