Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
hg-smart
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
platform
hg-smart
Commits
774ca0af
Commit
774ca0af
authored
Aug 09, 2024
by
宋祥
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.增加S3文件删除功能
parent
99af012a
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
310 additions
and
5 deletions
+310
-5
FileController.java
...ain/java/com/baosight/hggp/controller/FileController.java
+46
-0
S3Constant.java
...main/java/com/baosight/hggp/core/constant/S3Constant.java
+39
-0
Iplat4jTools.java
src/main/java/com/baosight/hggp/core/tools/Iplat4jTools.java
+26
-3
Iplat4jUtils.java
src/main/java/com/baosight/hggp/core/utils/Iplat4jUtils.java
+58
-0
S3ClientUtils.java
...main/java/com/baosight/hggp/core/utils/S3ClientUtils.java
+96
-0
S3Utils.java
src/main/java/com/baosight/hggp/core/utils/S3Utils.java
+42
-0
XS0702.xml
src/main/java/com/baosight/xservices/xs/sql/XS0702.xml
+3
-2
No files found.
src/main/java/com/baosight/hggp/controller/FileController.java
0 → 100644
View file @
774ca0af
package
com
.
baosight
.
hggp
.
controller
;
import
com.baosight.hggp.core.utils.Iplat4jUtils
;
import
com.baosight.hggp.util.LogUtils
;
import
com.baosight.iplat4j.core.ei.EiConstant
;
import
org.springframework.web.bind.annotation.CrossOrigin
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* @author:songx
* @date:2024/3/14,14:26
*/
@CrossOrigin
@RestController
@RequestMapping
({
"/file"
})
public
class
FileController
{
/**
* 删除文件
*
* @param docId
* @throws IOException
*/
@RequestMapping
(
value
=
"/delete/{docId}"
,
method
=
RequestMethod
.
GET
)
public
Map
delete
(
@PathVariable
String
docId
)
throws
IOException
{
Map
resultMap
=
new
HashMap
();
try
{
Iplat4jUtils
.
deleteFileByDocId
(
docId
);
resultMap
.
put
(
"id"
,
docId
);
resultMap
.
put
(
"status"
,
EiConstant
.
STATUS_SUCCESS
);
resultMap
.
put
(
"message"
,
"SUCCESS"
);
}
catch
(
Exception
e
)
{
resultMap
.
put
(
"status"
,
500
);
resultMap
.
put
(
"message"
,
LogUtils
.
getMsg
(
e
));
}
return
resultMap
;
}
}
src/main/java/com/baosight/hggp/core/constant/S3Constant.java
0 → 100644
View file @
774ca0af
package
com
.
baosight
.
hggp
.
core
.
constant
;
import
com.baosight.iplat4j.core.ioc.spring.PlatApplicationContext
;
import
lombok.Data
;
/**
* @author:songx
* @date:2023/8/28,10:05
*/
@Data
public
class
S3Constant
{
/**
* s3、local
*/
public
static
String
FILE_LOCATION
=
PlatApplicationContext
.
getProperty
(
"iplat4j.admin.upload.fileLocation"
);
/**
* endpoint
*/
public
static
String
ENDPOINT
=
PlatApplicationContext
.
getProperty
(
"iplat4j.admin.objectStorage.s3.endpoint"
);
/**
* bucket名称
*/
public
static
String
BUCKET_NAME
=
PlatApplicationContext
.
getProperty
(
"iplat4j.admin.objectStorage.s3.bucket"
);
/**
* AK
*/
public
static
String
ACCESS_KEY
=
PlatApplicationContext
.
getProperty
(
"iplat4j.admin.objectStorage.s3.accessKey"
);
/**
* SK
*/
public
static
String
SECRET_KEY
=
PlatApplicationContext
.
getProperty
(
"iplat4j.admin.objectStorage.s3.secretKey"
);
}
src/main/java/com/baosight/hggp/core/tools/
ED
Tools.java
→
src/main/java/com/baosight/hggp/core/tools/
Iplat4j
Tools.java
View file @
774ca0af
...
...
@@ -3,6 +3,7 @@ package com.baosight.hggp.core.tools;
import
com.baosight.hggp.core.dao.DaoBase
;
import
com.baosight.hggp.util.AssertUtils
;
import
com.baosight.iplat4j.common.ed.domain.TEDFA00
;
import
com.baosight.iplat4j.common.eu.domain.Teudm05
;
import
com.baosight.iplat4j.core.exception.PlatException
;
import
org.apache.commons.collections.CollectionUtils
;
...
...
@@ -16,7 +17,7 @@ import java.util.Map;
* @author:songx
* @date:2022/8/10,13:55
*/
public
class
ED
Tools
{
public
class
Iplat4j
Tools
{
/**
* 页面工具类
...
...
@@ -33,7 +34,7 @@ public class EDTools {
* @return
*/
public
static
TEDFA00
query
(
String
ename
)
{
AssertUtils
.
is
Null
(
ename
,
"页面英文名称不能为空!"
);
AssertUtils
.
is
Empty
(
ename
,
"页面英文名称不能为空!"
);
Map
<
String
,
String
>
paramMap
=
new
HashMap
();
paramMap
.
put
(
"form_ename"
,
ename
);
List
<
TEDFA00
>
results
=
DaoBase
.
getInstance
().
query
(
"tedfa00.query"
,
paramMap
);
...
...
@@ -56,7 +57,7 @@ public class EDTools {
* @return
*/
public
static
List
<
Map
<
String
,
Object
>>
list
(
String
codeSetCode
)
{
AssertUtils
.
is
Null
(
codeSetCode
,
"代码分类编码不能为空!"
);
AssertUtils
.
is
Empty
(
codeSetCode
,
"代码分类编码不能为空!"
);
Map
<
String
,
String
>
paramMap
=
new
HashMap
();
paramMap
.
put
(
"codesetCode"
,
codeSetCode
);
List
<
Map
<
String
,
Object
>>
results
=
DaoBase
.
getInstance
().
query
(
"EDCM01.queryDetail"
,
paramMap
);
...
...
@@ -68,4 +69,26 @@ public class EDTools {
}
/**
* 上传的文件
*
* @author:songx
* @date:2024/8/8,16:47
*/
public
static
class
EuDm05
{
/**
* 查询页面信息
*
* @param docId
* @return
*/
public
static
Teudm05
getDocByDocId
(
String
docId
)
{
AssertUtils
.
isEmpty
(
docId
,
"文件ID不能为空!"
);
Map
<
String
,
String
>
paramMap
=
new
HashMap
();
paramMap
.
put
(
"resId"
,
docId
);
List
<
Teudm05
>
results
=
DaoBase
.
getInstance
().
query
(
"EUDM05.getDocByDocId"
,
paramMap
);
return
CollectionUtils
.
isEmpty
(
results
)
?
null
:
results
.
get
(
0
);
}
}
}
src/main/java/com/baosight/hggp/core/utils/Iplat4jUtils.java
0 → 100644
View file @
774ca0af
package
com
.
baosight
.
hggp
.
core
.
utils
;
import
com.baosight.hggp.core.constant.S3Constant
;
import
com.baosight.hggp.core.tools.Iplat4jTools
;
import
com.baosight.hggp.util.FileUtils
;
import
com.baosight.hggp.util.StringUtils
;
import
com.baosight.iplat4j.common.eu.domain.Teudm05
;
import
com.baosight.iplat4j.core.exception.PlatException
;
import
com.baosight.iplat4j.core.ioc.spring.PlatApplicationContext
;
import
com.baosight.iplat4j.eu.dm.util.PlatFileUploader
;
import
java.util.Map
;
/**
* @author:songx
* @date:2024/8/8,17:00
*/
public
class
Iplat4jUtils
{
static
PlatFileUploader
platFileUploader
=
PlatApplicationContext
.
getApplicationContext
()
.
getBean
(
"platFileUploader"
,
PlatFileUploader
.
class
);
/**
* 删除文件
*
* @param docId
* @return
*/
public
static
boolean
deleteFileByDocId
(
String
docId
)
{
// 判断文件上传的地址
String
fileLocation
=
S3Constant
.
FILE_LOCATION
;
if
(
"s3"
.
equalsIgnoreCase
(
fileLocation
))
{
Teudm05
dbDm05
=
Iplat4jTools
.
EuDm05
.
getDocByDocId
(
docId
);
if
(
dbDm05
==
null
)
{
throw
new
PlatException
(
"文件在服务器中不存在"
);
}
String
url
=
dbDm05
.
getUrl
();
if
(
StringUtils
.
isBlank
(
url
))
{
return
false
;
}
// 删除本地记录
// platFileUploader.deleteDocById(docId);
// 删除S3文件,从文件路径中截取key,不包含域名
String
key
=
url
.
replace
(
S3Constant
.
ENDPOINT
+
"/"
,
""
);
return
S3Utils
.
deleteFile
(
key
);
}
else
{
Map
document
=
platFileUploader
.
getDocument
(
docId
);
String
chgName
=
document
.
get
(
"chgName"
).
toString
();
String
docPath
=
document
.
get
(
"realPath"
).
toString
();
String
filePath
=
docPath
+
chgName
;
// if (platFileUploader.deleteDocById(docId) > 0) {
return
FileUtils
.
deleteFile
(
filePath
);
// }
// return false;
}
}
}
src/main/java/com/baosight/hggp/core/utils/S3ClientUtils.java
0 → 100644
View file @
774ca0af
package
com
.
baosight
.
hggp
.
core
.
utils
;
import
com.amazonaws.ClientConfiguration
;
import
com.amazonaws.auth.AWSStaticCredentialsProvider
;
import
com.amazonaws.auth.BasicAWSCredentials
;
import
com.amazonaws.client.builder.AwsClientBuilder
;
import
com.amazonaws.services.s3.AmazonS3
;
import
com.amazonaws.services.s3.AmazonS3ClientBuilder
;
import
com.baosight.hggp.core.constant.S3Constant
;
import
lombok.extern.slf4j.Slf4j
;
/**
* OSS凭证
*
* @author:songx
* @date:2023/8/28,11:26
*/
@Slf4j
public
class
S3ClientUtils
{
private
S3ClientUtils
()
{
}
/**
* 初始化配置信息(纯粹就打印日志而已,因为会加载该类的全局变量)
*/
public
static
void
init
()
{
AmazonS3
s3Client
=
Instance
.
s3Client
;
log
.
info
(
"初始化OSS客户端完成:isReady -> {}"
,
s3Client
!=
null
);
}
/**
* 获取S3客户端
*
* @return
*/
public
static
AmazonS3
getS3Client
()
{
return
Instance
.
s3Client
;
}
/**
* 刷新客户端
*/
public
static
void
refresh
()
{
Instance
.
refresh
();
}
/**
* 初始化Instance
*
* @author:songx
* @date:2022/4/2,9:58
*/
private
static
class
Instance
{
/**
* 客户端实例
*/
private
static
AmazonS3
s3Client
=
buildAmazonS3
();
/**
* 刷新S3客户端
*/
private
static
void
refresh
()
{
s3Client
=
buildAmazonS3
();
log
.
info
(
"刷新OSS客户端完成:isReady->{}"
,
s3Client
!=
null
);
}
/**
* 获取AmazonS3Client实例
*
* @return
*/
private
static
synchronized
AmazonS3
buildAmazonS3
()
{
if
(!
"s3"
.
equalsIgnoreCase
(
S3Constant
.
FILE_LOCATION
))
{
return
null
;
}
// 判断上传类型是否S3
AmazonS3ClientBuilder
client
=
AmazonS3ClientBuilder
.
standard
();
ClientConfiguration
config
=
new
ClientConfiguration
();
config
.
setProtocol
(
com
.
amazonaws
.
Protocol
.
HTTPS
);
config
.
setConnectionTimeout
(
10001
);
config
.
setSignerOverride
(
"S3SignerType"
);
client
.
setClientConfiguration
(
config
);
client
.
setCredentials
(
new
AWSStaticCredentialsProvider
(
new
BasicAWSCredentials
(
S3Constant
.
ACCESS_KEY
,
S3Constant
.
SECRET_KEY
)));
// 去掉地址中的bucket前缀
String
endpoint
=
S3Constant
.
ENDPOINT
.
replace
(
S3Constant
.
BUCKET_NAME
+
"."
,
""
);
client
.
setEndpointConfiguration
(
new
AwsClientBuilder
.
EndpointConfiguration
(
endpoint
,
null
));
return
client
.
build
();
}
}
}
src/main/java/com/baosight/hggp/core/utils/S3Utils.java
0 → 100644
View file @
774ca0af
package
com
.
baosight
.
hggp
.
core
.
utils
;
import
com.amazonaws.services.s3.AmazonS3
;
import
com.baosight.hggp.core.constant.S3Constant
;
import
com.baosight.hggp.util.AssertUtils
;
import
java.io.File
;
/**
* OSS工具类
*
* @author:songx
* @date:2023/8/28,11:25
*/
public
class
S3Utils
{
/**
* 上传文件
*
* @param key 默认不指定key的情况下,以文件内容的hash值作为文件名
* @param file
*/
public
static
boolean
uploadFile
(
String
key
,
File
file
)
{
AmazonS3
client
=
S3ClientUtils
.
getS3Client
();
AssertUtils
.
isNull
(
client
,
"上传失败,OSS客户端未初始化,请检查"
);
client
.
putObject
(
S3Constant
.
BUCKET_NAME
,
key
,
file
);
return
true
;
}
/**
* 删除文件
*
* @param key
*/
public
static
boolean
deleteFile
(
String
key
)
{
AmazonS3
client
=
S3ClientUtils
.
getS3Client
();
AssertUtils
.
isNull
(
client
,
"删除失败,OSS客户端未初始化,请检查"
);
client
.
deleteObject
(
S3Constant
.
BUCKET_NAME
,
key
);
return
true
;
}
}
src/main/java/com/baosight/xservices/xs/sql/XS0702.xml
View file @
774ca0af
...
...
@@ -2,6 +2,7 @@
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd">
<sqlMap
namespace=
"XS0702"
>
<select
id=
"query"
resultClass=
"java.util.HashMap"
>
SELECT
tree_ename as "parent",
...
...
@@ -23,7 +24,7 @@
<!-- 非管理员非root节点仅显示有权限的菜单 added by songx at 20240126 -->
<isNotEqual
property=
"node"
compareValue=
"root"
>
<isEqual
prepend=
" AND "
property=
"isUserAdmin"
compareValue=
"0"
>
exists (
(
exists (
select
c. object_id, d.resource_ename
from ${platSchema}.xs_user a,
...
...
@@ -36,7 +37,7 @@
and a.login_name = #loginName#
and d.type = 'PAGE'
and m.node_ename = d.resource_ename
)
)
or node_type = '2')
</isEqual>
</isNotEqual>
</dynamic>
...
...
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