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
d689ca08
Commit
d689ca08
authored
Apr 07, 2022
by
284718418@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
文件存储地址配置
parent
547f91fe
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
127 additions
and
58 deletions
+127
-58
src/main/java/cn/timer/api/config/enuminterface/JxglEnumInterface.java
+19
-0
src/main/java/cn/timer/api/config/sftp/SftpConfiguration.java
+9
-0
src/main/java/cn/timer/api/controller/disk/DiskFilesController.java
+4
-13
src/main/java/cn/timer/api/controller/disk/constant/FileAddressConstant.java
+21
-0
src/main/java/cn/timer/api/service/FtpService.java
+1
-3
src/main/java/cn/timer/api/service/impl/FtpServiceImpl.java
+52
-42
src/main/resources/application-dev.yml
+7
-0
src/main/resources/application-pro.yml
+7
-0
src/main/resources/application-test.yml
+7
-0
No files found.
src/main/java/cn/timer/api/config/enuminterface/JxglEnumInterface.java
View file @
d689ca08
...
@@ -326,5 +326,24 @@ public interface JxglEnumInterface {
...
@@ -326,5 +326,24 @@ public interface JxglEnumInterface {
}
}
}
}
/**
* 招聘管理-面试流程:类型,1状态变更,2面试,3Offer,4讨论,5其他
*/
@Getter
enum
MslcLogStatus
implements
JxglEnumInterface
{
CHANGEING
(
1
,
"状态变更"
),
INTERVIEW
(
2
,
"面试"
),
OFFER
(
3
,
"Offer"
),
DISCUSS
(
4
,
"讨论"
),
OTHER
(
5
,
"其他"
);
private
Integer
type
;
private
String
name
;
MslcLogStatus
(
Integer
type
,
String
name
)
{
this
.
type
=
type
;
this
.
name
=
name
;
}
}
}
}
src/main/java/cn/timer/api/config/sftp/SftpConfiguration.java
View file @
d689ca08
...
@@ -53,6 +53,15 @@ public class SftpConfiguration {
...
@@ -53,6 +53,15 @@ public class SftpConfiguration {
@Value
(
"${sftp.client.serverUrl}"
)
@Value
(
"${sftp.client.serverUrl}"
)
private
String
serverUrl
;
private
String
serverUrl
;
@Value
(
"${sftp.client.targetPath}"
)
private
String
targetPath
;
@Value
(
"${sftp.client.reservedName}"
)
private
boolean
reservedName
;
@Value
(
"${config-8timer.file-address.type}"
)
public
String
fileAddress
;
/**
/**
* @Title: getSftpSocket
* @Title: getSftpSocket
* @Description: 获取连接
* @Description: 获取连接
...
...
src/main/java/cn/timer/api/controller/disk/DiskFilesController.java
View file @
d689ca08
...
@@ -58,17 +58,8 @@ public class DiskFilesController {
...
@@ -58,17 +58,8 @@ public class DiskFilesController {
@Autowired
@Autowired
private
DiskFilesService
diskFilesService
;
private
DiskFilesService
diskFilesService
;
@Value
(
"${sftp.client.root}"
)
@Autowired
private
String
root
;
private
SftpConfiguration
config
;
@Value
(
"${sftp.client.targetPath}"
)
private
String
targetPath
;
@Value
(
"${sftp.client.reservedName}"
)
private
boolean
reservedName
;
@Value
(
"${sftp.client.serverUrl}"
)
private
String
serverUrl
;
@ResponseBody
@ResponseBody
...
@@ -88,13 +79,13 @@ public class DiskFilesController {
...
@@ -88,13 +79,13 @@ public class DiskFilesController {
List
<
FileInfoDto
>
imageUrls
;
List
<
FileInfoDto
>
imageUrls
;
try
{
try
{
//上传文件到服务器
//上传文件到服务器
imageUrls
=
ftpService
.
uploadFile
(
targetPath
,
file
,
reservedNam
e
);
imageUrls
=
ftpService
.
uploadFile
(
fil
e
);
for
(
FileInfoDto
dto
:
imageUrls
)
{
for
(
FileInfoDto
dto
:
imageUrls
)
{
//新增资源上传文件
//新增资源上传文件
diskFiles
.
setCreateUserId
(
userBean
.
getEmpNum
());
diskFiles
.
setCreateUserId
(
userBean
.
getEmpNum
());
diskFiles
.
setFileType
(
dto
.
getFileSuffix
());
diskFiles
.
setFileType
(
dto
.
getFileSuffix
());
//"/home/disk/123456.jpg"
//"/home/disk/123456.jpg"
diskFiles
.
setDiskPath
(
root
+
targetPath
+
"/"
+
dto
.
getFileName
());
diskFiles
.
setDiskPath
(
config
.
getRoot
()
+
config
.
getTargetPath
()
+
"/"
+
dto
.
getFileName
());
diskFiles
.
setUrlPath
(
dto
.
getUrlPath
());
diskFiles
.
setUrlPath
(
dto
.
getUrlPath
());
diskFiles
.
setTitle
(
dto
.
getResourceFileName
());
diskFiles
.
setTitle
(
dto
.
getResourceFileName
());
diskFiles
.
setFileSize
(
dto
.
getFileSize
());
diskFiles
.
setFileSize
(
dto
.
getFileSize
());
...
...
src/main/java/cn/timer/api/controller/disk/constant/FileAddressConstant.java
0 → 100644
View file @
d689ca08
package
cn
.
timer
.
api
.
controller
.
disk
.
constant
;
/**
* 文件存储地址常量
*
* @author wuqingjun
* @email 284718418@qq.com
* @date 2022-04-02 11:05:49
*/
public
class
FileAddressConstant
{
/**
* aliyun-oss(阿里云OSS)
*/
public
static
final
String
ALIYUN_OSS
=
"aliyun-oss"
;
/**
* physics-oss(物理机器OSS)
*/
public
static
final
String
PHYSICS_OSS
=
"physics-oss"
;
}
src/main/java/cn/timer/api/service/FtpService.java
View file @
d689ca08
...
@@ -18,12 +18,10 @@ public interface FtpService {
...
@@ -18,12 +18,10 @@ public interface FtpService {
/**
/**
* 上传文件到服务器
* 上传文件到服务器
* @param targetPath
* @param files
* @param files
* @param reservedName
* @return
* @return
*/
*/
List
<
FileInfoDto
>
uploadFile
(
String
targetPath
,
MultipartFile
[]
files
,
boolean
reservedName
);
List
<
FileInfoDto
>
uploadFile
(
MultipartFile
[]
files
);
/**
/**
* 下载单个文件
* 下载单个文件
*
*
...
...
src/main/java/cn/timer/api/service/impl/FtpServiceImpl.java
View file @
d689ca08
package
cn
.
timer
.
api
.
service
.
impl
;
package
cn
.
timer
.
api
.
service
.
impl
;
import
cn.timer.api.config.sftp.SftpConfiguration
;
import
cn.timer.api.config.sftp.SftpConfiguration
;
import
cn.timer.api.controller.disk.constant.FileAddressConstant
;
import
cn.timer.api.dto.disk.FileInfoDto
;
import
cn.timer.api.dto.disk.FileInfoDto
;
import
cn.timer.api.service.FtpService
;
import
cn.timer.api.service.FtpService
;
import
cn.timer.api.utils.Md5
;
import
cn.timer.api.utils.Md5
;
import
cn.timer.api.utils.aliyun.OSSUtil
;
import
com.jcraft.jsch.ChannelSftp
;
import
com.jcraft.jsch.ChannelSftp
;
import
com.jcraft.jsch.SftpException
;
import
com.jcraft.jsch.SftpException
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
...
@@ -25,6 +28,8 @@ public class FtpServiceImpl implements FtpService {
...
@@ -25,6 +28,8 @@ public class FtpServiceImpl implements FtpService {
@Autowired
@Autowired
private
SftpConfiguration
config
;
private
SftpConfiguration
config
;
@Autowired
private
OSSUtil
oss
;
@Override
@Override
...
@@ -61,54 +66,59 @@ public class FtpServiceImpl implements FtpService {
...
@@ -61,54 +66,59 @@ public class FtpServiceImpl implements FtpService {
}
}
@Override
@Override
public
List
<
FileInfoDto
>
uploadFile
(
String
targetPath
,
MultipartFile
[]
files
,
boolean
reservedName
)
{
public
List
<
FileInfoDto
>
uploadFile
(
MultipartFile
[]
files
)
{
ChannelSftp
sftp
=
config
.
getSftpSocket
();
List
<
FileInfoDto
>
resultStrs
=
new
ArrayList
<
FileInfoDto
>();
List
<
FileInfoDto
>
resultStrs
=
new
ArrayList
<
FileInfoDto
>();
try
{
//存储地址判断
sftp
.
cd
(
config
.
getRoot
());
if
(
FileAddressConstant
.
PHYSICS_OSS
.
equals
(
config
.
getFileAddress
()))
{
//log.info("sftp连接host", config.getRoot());
ChannelSftp
sftp
=
config
.
getSftpSocket
();
boolean
dirs
=
this
.
createDirs
(
targetPath
,
sftp
);
try
{
if
(!
dirs
)
{
sftp
.
cd
(
config
.
getRoot
());
log
.
error
(
"sftp创建目录失败"
,
targetPath
);
//log.info("sftp连接host", config.getRoot());
throw
new
RuntimeException
(
"上传文件失败"
);
boolean
dirs
=
this
.
createDirs
(
config
.
getTargetPath
(),
sftp
);
}
if
(!
dirs
)
{
FileInfoDto
dto
=
null
;
log
.
error
(
"sftp创建目录失败"
,
config
.
getTargetPath
());
for
(
MultipartFile
file
:
files
)
{
throw
new
RuntimeException
(
"上传文件失败"
);
dto
=
new
FileInfoDto
();
String
fileName
=
""
;
String
name
=
file
.
getOriginalFilename
().
substring
(
0
,
file
.
getOriginalFilename
().
lastIndexOf
(
"."
));
String
suffix
=
file
.
getOriginalFilename
().
substring
(
file
.
getOriginalFilename
().
lastIndexOf
(
"."
));
if
(
reservedName
)
{
fileName
=
Md5
.
md5
(
name
+
UUID
.
randomUUID
().
toString
())
+
suffix
;
}
else
{
fileName
=
UUID
.
randomUUID
().
toString
()
+
suffix
;
}
}
sftp
.
put
(
file
.
getInputStream
(),
fileName
);
FileInfoDto
dto
=
null
;
dto
.
setUrlPath
(
config
.
getServerUrl
()
+
"/"
+
fileName
);
for
(
MultipartFile
file
:
files
)
{
dto
.
setResourceFileName
(
name
);
dto
=
new
FileInfoDto
();
dto
.
setFileName
(
fileName
);
String
fileName
=
""
;
String
name
=
file
.
getOriginalFilename
().
substring
(
0
,
file
.
getOriginalFilename
().
lastIndexOf
(
"."
));
String
suffix
=
file
.
getOriginalFilename
().
substring
(
file
.
getOriginalFilename
().
lastIndexOf
(
"."
));
if
(
config
.
isReservedName
())
{
fileName
=
Md5
.
md5
(
name
+
UUID
.
randomUUID
().
toString
())
+
suffix
;
}
else
{
fileName
=
UUID
.
randomUUID
().
toString
()
+
suffix
;
}
sftp
.
put
(
file
.
getInputStream
(),
fileName
);
dto
.
setUrlPath
(
config
.
getServerUrl
()
+
"/"
+
fileName
);
dto
.
setResourceFileName
(
name
);
dto
.
setFileName
(
fileName
);
/*Float size = Float.parseFloat(String.valueOf(file.getSize())) / 1024;
/*Float size = Float.parseFloat(String.valueOf(file.getSize())) / 1024;
BigDecimal b = new BigDecimal(size);
BigDecimal b = new BigDecimal(size);
// 2表示2位 ROUND_HALF_UP表明四舍五入,
// 2表示2位 ROUND_HALF_UP表明四舍五入,
size = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();*/
size = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();*/
dto
.
setFileSize
(
file
.
getSize
());
dto
.
setFileSize
(
file
.
getSize
());
dto
.
setFileSuffix
(
suffix
);
dto
.
setFileSuffix
(
suffix
);
resultStrs
.
add
(
dto
);
resultStrs
.
add
(
dto
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"上传文件失败"
,
config
.
getTargetPath
(),
e
);
e
.
printStackTrace
();
throw
new
RuntimeException
(
"上传文件失败"
);
}
finally
{
config
.
returnSftpSocket
(
sftp
);
}
}
return
resultStrs
;
}
else
if
(
FileAddressConstant
.
ALIYUN_OSS
.
equals
(
config
.
getFileAddress
()))
{
}
catch
(
Exception
e
)
{
log
.
error
(
"上传文件失败"
,
targetPath
,
e
);
e
.
printStackTrace
();
throw
new
RuntimeException
(
"上传文件失败"
);
}
finally
{
config
.
returnSftpSocket
(
sftp
);
}
}
return
resultStrs
;
}
}
/**
/**
* 下载单个文件
* 下载单个文件
*
*
...
@@ -128,11 +138,11 @@ public class FtpServiceImpl implements FtpService {
...
@@ -128,11 +138,11 @@ public class FtpServiceImpl implements FtpService {
log
.
info
(
"===DownloadFile:"
+
remotePath
+
" success from sftp."
);
log
.
info
(
"===DownloadFile:"
+
remotePath
+
" success from sftp."
);
}
}
return
nputStream
;
return
nputStream
;
}
catch
(
SftpException
e
)
{
}
catch
(
SftpException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
catch
(
Exception
e
){
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
finally
{
}
finally
{
config
.
returnSftpSocket
(
sftp
);
config
.
returnSftpSocket
(
sftp
);
}
}
return
nputStream
;
return
nputStream
;
...
...
src/main/resources/application-dev.yml
View file @
d689ca08
...
@@ -239,6 +239,13 @@ config-8timer:
...
@@ -239,6 +239,13 @@ config-8timer:
appid
:
XOATkGqX6LvCW3i3Eqd5rg6h
appid
:
XOATkGqX6LvCW3i3Eqd5rg6h
secret
:
UqqNAF1nltMjAOz9yxqHPjZlnjtC2gSS
secret
:
UqqNAF1nltMjAOz9yxqHPjZlnjtC2gSS
# 文件存储地址配置 file type:aliyun-oss,physics-oss
# 文件存储地址类型:aliyun-oss(阿里云OSS),physics-oss(物理机器OSS)
# 默认存储物理机器OSS
file-address
:
type
:
physics-oss
#type: aliyun-oss
#导出zip临时地址
#导出zip临时地址
zip
:
zip
:
path
:
'
D:/zip/'
path
:
'
D:/zip/'
...
...
src/main/resources/application-pro.yml
View file @
d689ca08
...
@@ -212,6 +212,13 @@ config-8timer:
...
@@ -212,6 +212,13 @@ config-8timer:
appid
:
XOATkGqX6LvCW3i3Eqd5rg6h
appid
:
XOATkGqX6LvCW3i3Eqd5rg6h
secret
:
UqqNAF1nltMjAOz9yxqHPjZlnjtC2gSS
secret
:
UqqNAF1nltMjAOz9yxqHPjZlnjtC2gSS
# 文件存储地址配置 file type:aliyun-oss,physics-oss
# 文件存储地址类型:aliyun-oss(阿里云OSS),physics-oss(物理机器OSS)
# 默认存储物理机器OSS
file-address
:
type
:
physics-oss
#type: aliyun-oss
#导出zip临时地址
#导出zip临时地址
zip
:
zip
:
path
:
'
/data/crm-zip/'
path
:
'
/data/crm-zip/'
...
...
src/main/resources/application-test.yml
View file @
d689ca08
...
@@ -212,6 +212,13 @@ config-8timer:
...
@@ -212,6 +212,13 @@ config-8timer:
appid
:
XOATkGqX6LvCW3i3Eqd5rg6h
appid
:
XOATkGqX6LvCW3i3Eqd5rg6h
secret
:
UqqNAF1nltMjAOz9yxqHPjZlnjtC2gSS
secret
:
UqqNAF1nltMjAOz9yxqHPjZlnjtC2gSS
# 文件存储地址配置 file type:aliyun-oss,physics-oss
# 文件存储地址类型:aliyun-oss(阿里云OSS),physics-oss(物理机器OSS)
# 默认存储物理机器OSS
file-address
:
type
:
physics-oss
#type: aliyun-oss
#导出zip临时地址
#导出zip临时地址
zip
:
zip
:
path
:
'
/data/crm-zip/'
path
:
'
/data/crm-zip/'
...
...
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