Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
polysoft-nafmii
/
polysoft-parent
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit ed7ce71d
authored
May 08, 2021
by
ypenglv
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'dev' of
http://gitlab.polyhome.net/polysoft-nafmii/polysoft-parent
into dev
2 parents
d151c550
7cc6d569
Show whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
1749 additions
and
7 deletions
nafmii-admin/src/main/java/org/nafmii/admin/att/controller/AttController.java
nafmii-admin/src/main/java/org/nafmii/admin/att/dao/AttachmentInfoMapper.java
nafmii-admin/src/main/java/org/nafmii/admin/att/dao/BusinessAttachmentInfoMapper.java
nafmii-admin/src/main/java/org/nafmii/admin/att/dto/AttachmentInfoDto.java
nafmii-admin/src/main/java/org/nafmii/admin/att/dto/AttachmentInfoListDto.java
nafmii-admin/src/main/java/org/nafmii/admin/att/entity/AttachmentInfoPO.java
nafmii-admin/src/main/java/org/nafmii/admin/att/entity/BusinessAttachmentInfoPO.java
nafmii-admin/src/main/java/org/nafmii/admin/att/service/AttService.java
nafmii-admin/src/main/java/org/nafmii/admin/att/service/impl/AttServiceImpl.java
nafmii-admin/src/main/java/org/nafmii/admin/att/service/test.java
nafmii-admin/src/main/java/org/nafmii/admin/att/vo/EshopAttachmentInfoVo.java
nafmii-admin/src/main/resources/mapper/AttachmentInfoMapper.xml
nafmii-admin/src/main/resources/mapper/BusinessAttachmentInfoMapper.xml
nafmii-app/src/main/java/org/nafmii/app/user/service/impl/UserServiceImpl.java
nafmii-common/pom.xml
nafmii-common/src/main/java/org/nafmii/common/constant/MessageEnum.java
nafmii-common/src/main/java/org/nafmii/enums/RedisEnum.java → nafmii-common/src/main/java/org/nafmii/common/constant/RedisEnum.java
nafmii-common/src/main/java/org/nafmii/common/constant/UserEnum.java
nafmii-common/src/main/java/org/nafmii/common/utils/FtpUtil.java
nafmii-common/src/main/java/org/nafmii/common/utils/JwtUtils.java
nafmii-common/src/main/java/org/nafmii/common/utils/StringUtil.java
nafmii-common/src/main/resources/application.properties
nafmii-admin/src/main/java/org/nafmii/admin/att/controller/AttController.java
0 → 100644
View file @
ed7ce71
package
org
.
nafmii
.
admin
.
att
.
controller
;
import
cn.hutool.core.io.FileUtil
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.nafmii.admin.att.service.AttService
;
import
org.nafmii.common.response.ApiResponse
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.File
;
import
java.io.InputStream
;
/**
* @author:zhoujh
* @Function:TODO
* @date 2021/5/7 14:30
* @ClassName:文件服务公共接口
* @version:
* @remark:
*/
@RestController
@RequestMapping
(
"/nafmii/admin/att"
)
@Api
(
tags
=
"2.0.2"
,
description
=
"上传文件到文件服务器【zjh】"
)
@Slf4j
public
class
AttController
{
@Autowired
private
AttService
attService
;
/**上传文件到ftp
*
* @param description 描述
* @param userId 用户id
* @param files 文件
* @return
*/
@ApiOperation
(
value
=
"上传文件到ftp"
,
notes
=
"上传文件到ftp"
)
@PostMapping
(
value
=
"/uploadToFtp"
,
headers
=
"content-type=multipart/form-data"
)
@ResponseBody
public
ApiResponse
uploadToFtp
(
@RequestParam
(
"description"
)
String
description
,
@RequestParam
(
"userId"
)
String
userId
,
@RequestParam
(
"files"
)
MultipartFile
[]
files
)
{
log
.
info
(
"外部网关通过ftp批量上传文件名称参数================》{}"
,
files
);
ApiResponse
apiResponse
=
attService
.
uploadToFtp
(
files
,
description
,
Long
.
valueOf
(
userId
));
return
apiResponse
;
}
/**
* 下载ftp上文件到本地
*@param newFileName 新文件名
*@param fileName 原文件(路径+文件名)
*@param downUrl 下载路径
*@return
*/
@ApiOperation
(
value
=
"下载ftp上文件到本地"
,
notes
=
"下载ftp上文件到本地"
)
@PostMapping
(
value
=
"/downloadFile"
,
headers
=
"content-type=multipart/form-data"
)
@ResponseBody
public
ApiResponse
downloadFile
(
@RequestParam
(
"newFileName"
)
String
newFileName
,
@RequestParam
(
"fileName"
)
String
fileName
,
@RequestParam
(
"downUrl"
)
String
downUrl
)
{
ApiResponse
apiResponse
=
attService
.
downloadFile
(
newFileName
,
fileName
,
downUrl
);
return
apiResponse
;
}
}
nafmii-admin/src/main/java/org/nafmii/admin/att/dao/AttachmentInfoMapper.java
0 → 100644
View file @
ed7ce71
package
org
.
nafmii
.
admin
.
att
.
dao
;
import
org.nafmii.admin.att.entity.AttachmentInfoPO
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
/**
* <p>
* 公用附件表 Mapper 接口
* </p>
*
* @author zjh
* @since 2021-05-07
*/
public
interface
AttachmentInfoMapper
extends
BaseMapper
<
AttachmentInfoPO
>
{
}
nafmii-admin/src/main/java/org/nafmii/admin/att/dao/BusinessAttachmentInfoMapper.java
0 → 100644
View file @
ed7ce71
package
org
.
nafmii
.
admin
.
att
.
dao
;
import
org.nafmii.admin.att.entity.BusinessAttachmentInfoPO
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
/**
* <p>
* Mapper 接口
* </p>
*
* @author zjh
* @since 2021-05-07
*/
public
interface
BusinessAttachmentInfoMapper
extends
BaseMapper
<
BusinessAttachmentInfoPO
>
{
}
nafmii-admin/src/main/java/org/nafmii/admin/att/dto/AttachmentInfoDto.java
0 → 100644
View file @
ed7ce71
package
org
.
nafmii
.
admin
.
att
.
dto
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.util.Date
;
/**
* AttachmentInfoDto对象.对应实体描述:公用附件表
*/
@Data
@ApiModel
(
"AttachmentInfoDto对象"
)
public
class
AttachmentInfoDto
{
@ApiModelProperty
(
"附件id"
)
private
String
id
;
@ApiModelProperty
(
"源文件名称包括后缀"
)
private
String
fileName
;
@ApiModelProperty
(
"相对url"
)
private
String
fileUrl
;
@ApiModelProperty
(
"文件存储相对目录"
)
private
String
filePath
;
@ApiModelProperty
(
"描述"
)
private
String
description
;
@ApiModelProperty
(
"软删除字段0未删除1已删除"
)
private
String
delFlag
;
@ApiModelProperty
(
"创建人"
)
private
Long
createUser
;
@ApiModelProperty
(
"创建时间"
)
private
Date
createDate
;
@ApiModelProperty
(
"修改人"
)
private
Long
updateUser
;
@ApiModelProperty
(
"修改时间"
)
private
Date
updateDate
;
}
nafmii-admin/src/main/java/org/nafmii/admin/att/dto/AttachmentInfoListDto.java
0 → 100644
View file @
ed7ce71
package
org
.
nafmii
.
admin
.
att
.
dto
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.util.List
;
/**
* AttachmentInfoDto对象.对应实体描述:公用附件表
*/
@Data
@ApiModel
(
"AttachmentInfoListDto对象"
)
public
class
AttachmentInfoListDto
{
@ApiModelProperty
(
"附件集合信息"
)
List
<
AttachmentInfoDto
>
attachmentInfoDtoList
;
}
nafmii-admin/src/main/java/org/nafmii/admin/att/entity/AttachmentInfoPO.java
0 → 100644
View file @
ed7ce71
package
org
.
nafmii
.
admin
.
att
.
entity
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.baomidou.mybatisplus.extension.activerecord.Model
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
java.time.LocalDateTime
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
lombok.experimental.Accessors
;
/**
* <p>
* 公用附件表
* </p>
*
* @author zjh
* @since 2021-05-07
*/
@Data
@EqualsAndHashCode
(
callSuper
=
true
)
@Accessors
(
chain
=
true
)
@TableName
(
"ATTACHMENT_INFO"
)
@ApiModel
(
value
=
"AttachmentInfoPO对象"
,
description
=
"公用附件表"
)
public
class
AttachmentInfoPO
extends
Model
{
private
static
final
long
serialVersionUID
=
1L
;
@ApiModelProperty
(
value
=
"附件id"
)
@TableId
(
"ID"
)
private
Long
id
;
@ApiModelProperty
(
value
=
"源文件名称"
)
@TableField
(
"FILE_NAME"
)
private
String
fileName
;
@ApiModelProperty
(
value
=
"相对url"
)
@TableField
(
"FILE_URL"
)
private
String
fileUrl
;
@ApiModelProperty
(
value
=
"文件存储相对目录"
)
@TableField
(
"FILE_PATH"
)
private
String
filePath
;
@ApiModelProperty
(
value
=
"描述"
)
@TableField
(
"DESCRIPTION"
)
private
String
description
;
@ApiModelProperty
(
value
=
"是否有效 0 有效 1无效"
)
@TableField
(
"IS_ENABLE"
)
private
String
isEnable
;
@ApiModelProperty
(
value
=
"创建人"
)
@TableField
(
"CREATE_USER_ID"
)
private
Long
createUserId
;
@ApiModelProperty
(
value
=
"修改人"
)
@TableField
(
"UPDATE_USER_ID"
)
private
Long
updateUserId
;
@ApiModelProperty
(
value
=
"创建时间"
)
@TableField
(
"CREATE_TIME"
)
private
LocalDateTime
createTime
;
@ApiModelProperty
(
value
=
"更新时间"
)
@TableField
(
"UPDATE_TIME"
)
private
LocalDateTime
updateTime
;
}
nafmii-admin/src/main/java/org/nafmii/admin/att/entity/BusinessAttachmentInfoPO.java
0 → 100644
View file @
ed7ce71
package
org
.
nafmii
.
admin
.
att
.
entity
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.baomidou.mybatisplus.extension.activerecord.Model
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
java.time.LocalDateTime
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
lombok.experimental.Accessors
;
/**
* <p>
*
* </p>
*
* @author zjh
* @since 2021-05-07
*/
@Data
@EqualsAndHashCode
(
callSuper
=
true
)
@Accessors
(
chain
=
true
)
@TableName
(
"BUSINESS_ATTACHMENT_INFO"
)
@ApiModel
(
value
=
"BusinessAttachmentInfoPO对象"
,
description
=
""
)
public
class
BusinessAttachmentInfoPO
extends
Model
{
private
static
final
long
serialVersionUID
=
1L
;
@ApiModelProperty
(
value
=
"主键id"
)
@TableId
(
"ID"
)
private
Long
id
;
@ApiModelProperty
(
value
=
"业务类型"
)
@TableField
(
"BUSINESS"
)
private
String
business
;
@ApiModelProperty
(
value
=
"业务id"
)
@TableField
(
"BUSINESS_ID"
)
private
Long
businessId
;
@ApiModelProperty
(
value
=
"附件id"
)
@TableField
(
"ATTACHMENT_ID"
)
private
Long
attachmentId
;
@ApiModelProperty
(
value
=
"创建人"
)
@TableField
(
"CREATE_USER_ID"
)
private
Long
createUserId
;
@ApiModelProperty
(
value
=
"修改人"
)
@TableField
(
"UPDATE_USER_ID"
)
private
Long
updateUserId
;
@ApiModelProperty
(
value
=
"创建时间"
)
@TableField
(
"CREATE_TIME"
)
private
LocalDateTime
createTime
;
@ApiModelProperty
(
value
=
"更新时间"
)
@TableField
(
"UPDATE_TIME"
)
private
LocalDateTime
updateTime
;
@ApiModelProperty
(
value
=
"排序"
)
@TableField
(
"SORT"
)
private
Integer
sort
;
@ApiModelProperty
(
value
=
"描述"
)
@TableField
(
"DESCRIPTION"
)
private
String
description
;
@ApiModelProperty
(
value
=
"是否有效 0 有效 1无效"
)
@TableField
(
"IS_ENABLE"
)
private
String
isEnable
;
}
nafmii-admin/src/main/java/org/nafmii/admin/att/service/AttService.java
0 → 100644
View file @
ed7ce71
package
org
.
nafmii
.
admin
.
att
.
service
;
import
org.nafmii.admin.att.dto.AttachmentInfoListDto
;
import
org.nafmii.common.response.ApiResponse
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.File
;
import
java.util.List
;
/**
* @author:zhoujh
* @Function:TODO
* @date 2021/5/7 14:42
* @ClassName:
* @version:
* @remark:
*/
public
interface
AttService
{
//下载ftp上文件到本地
ApiResponse
downloadFile
(
String
newFileName
,
String
fileName
,
String
downUrl
);
//上传文件到ftp
ApiResponse
uploadToFtp
(
MultipartFile
[]
files
,
String
description
,
Long
userId
);
//ftp上传存库操作
ApiResponse
uploadByFtp
(
AttachmentInfoListDto
attachmentInfoListDto
);
}
nafmii-admin/src/main/java/org/nafmii/admin/att/service/impl/AttServiceImpl.java
0 → 100644
View file @
ed7ce71
package
org
.
nafmii
.
admin
.
att
.
service
.
impl
;
import
cn.hutool.core.bean.copier.BeanCopier
;
import
cn.hutool.core.io.FileUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
lombok.extern.slf4j.Slf4j
;
import
org.nafmii.admin.att.dao.AttachmentInfoMapper
;
import
org.nafmii.admin.att.dto.AttachmentInfoDto
;
import
org.nafmii.admin.att.dto.AttachmentInfoListDto
;
import
org.nafmii.admin.att.entity.AttachmentInfoPO
;
import
org.nafmii.admin.att.service.AttService
;
import
org.nafmii.admin.att.vo.EshopAttachmentInfoVo
;
import
org.nafmii.common.constant.CommonEnum
;
import
org.nafmii.common.constant.MessageEnum
;
import
org.nafmii.common.param.BeanTransferUtils
;
import
org.nafmii.common.response.ApiResponse
;
import
org.nafmii.common.utils.FtpUtil
;
import
org.nafmii.common.utils.SnowFlakeUtil
;
import
org.nafmii.common.utils.StringUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.annotation.Resource
;
import
java.io.*
;
import
java.util.*
;
/**
* @author:zhoujh
* @Function:TODO
* @date 2021/5/7 14:42
* @ClassName:
* @version:
* @remark:
*/
@Service
@Slf4j
public
class
AttServiceImpl
implements
AttService
{
@Value
(
"${att.upload.docBase}"
)
private
String
ftpPath
;
@Value
(
"${att.upload.path}"
)
private
String
downLoad
;
@Value
(
"${web.upload.path}"
)
private
String
fileRootPath
;
@Resource
private
AttachmentInfoMapper
infoMapper
;
/**
* 下载ftp上文件到本地
*@param newFileName 新文件名
*@param fileName 原文件(路径+文件名)
*@param downUrl 下载路径
*@return
*/
@Override
public
ApiResponse
downloadFile
(
String
newFileName
,
String
fileName
,
String
downUrl
)
{
log
.
info
(
"下载文件参数newFileName:{}fileName:{}downUrl:"
,
newFileName
,
fileName
,
downUrl
);
OutputStream
os
=
null
;
String
lastPath
=
""
;
File
localFile
=
new
File
(
downUrl
+
"/"
+
newFileName
);
if
(!
localFile
.
getParentFile
().
exists
()){
//文件夹目录不存在创建目录
localFile
.
getParentFile
().
mkdirs
();
//存放图片的路径地址
StringBuilder
sb
=
new
StringBuilder
(
ftpPath
).
append
(
"/"
);
String
path
=
sb
.
toString
();
lastPath
=
path
;
try
{
localFile
.
createNewFile
();
os
=
new
FileOutputStream
(
localFile
);
FtpUtil
fileFtp
=
new
FtpUtil
();
log
.
info
(
"通过ftp下载文件参数lastPath:{}ileName:{}downUrl:"
,
lastPath
,
fileName
,
downUrl
);
fileFtp
.
downloadFile
(
lastPath
,
fileName
,
downUrl
);
os
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
return
new
ApiResponse
(
ApiResponse
.
SUCCESS
,
ApiResponse
.
SUCCESS_TEXT
);
}
/**
* 上传文件到ftp
* @param files
* @return
*/
@Override
public
ApiResponse
uploadToFtp
(
MultipartFile
[]
files
,
String
description
,
Long
userId
)
{
log
.
info
(
"-----uploadByFtp-----MultipartFile files长度--------"
+
files
.
length
);
if
(
files
==
null
){
return
new
ApiResponse
(
ApiResponse
.
FAIL
,
MessageEnum
.
FAIL_PARAM
.
getRemarks
());
}
else
{
List
<
AttachmentInfoDto
>
attachList
=
new
ArrayList
<>();
String
lastPath
=
""
;
LinkedList
<
String
>
newNameList
=
new
LinkedList
<
String
>();
LinkedList
<
InputStream
>
fileList
=
new
LinkedList
<
InputStream
>();
for
(
MultipartFile
file
:
files
)
{
AttachmentInfoDto
attachVo
=
new
AttachmentInfoDto
();
//获取上传的附件原名包括后缀
String
realFileName
=
file
.
getOriginalFilename
();
attachVo
.
setFileName
(
realFileName
);
//获取后缀名,如.jpg.png
log
.
info
(
"--------源文件名开始 realFileName--------"
+
realFileName
);
String
suffixes
=
realFileName
.
substring
(
realFileName
.
lastIndexOf
(
"."
));
List
<
String
>
extList
=
Arrays
.
asList
(
".jpg"
,
".png"
,
".jpeg"
,
".gif"
);
if
(!
extList
.
contains
(
suffixes
))
{
return
new
ApiResponse
(
ApiResponse
.
FAIL
,
MessageEnum
.
FILE_PICTURE
.
getRemarks
());
}
//重新命名包括后缀名
String
newName
=
StringUtil
.
getRandomOrderNumber
()
+
"_"
+
StringUtil
.
getRandomOrderNumberString
()
+
suffixes
;
// String newName= UUID.randomUUID().toString().replaceAll("\\-", "")+suffixes;
newNameList
.
add
(
newName
);
try
{
fileList
.
add
(
file
.
getInputStream
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
//存放图片的路径地址
StringBuilder
sb
=
new
StringBuilder
(
ftpPath
).
append
(
"/"
);
String
path
=
sb
.
toString
();
lastPath
=
path
;
// fileFtp.uploadFile(path,newName,file.getInputStream());
//文件服务器地址**********************************************
String
filePath
=
path
+
newName
;
//赋值附件数据存储的信息**********************************************
attachVo
.
setCreateDate
(
new
Date
());
attachVo
.
setCreateUser
(
userId
);
attachVo
.
setUpdateDate
(
new
Date
());
attachVo
.
setUpdateUser
(
userId
);
attachVo
.
setDelFlag
(
CommonEnum
.
USED
.
getCode
());
attachVo
.
setDescription
(
description
);
attachVo
.
setFilePath
(
filePath
);
attachVo
.
setFileUrl
(
downLoad
+
"/"
+
newName
);
attachList
.
add
(
attachVo
);
}
//ftp上传
try
{
FtpUtil
fileFtp
=
new
FtpUtil
();
fileFtp
.
uploadArrFile
(
lastPath
,
newNameList
,
fileList
);
}
catch
(
Exception
e
)
{
log
.
error
(
"服务器上传附件异常----------"
,
e
);
e
.
printStackTrace
();
}
//相关数据存储到数据库里
AttachmentInfoListDto
infoListDto
=
new
AttachmentInfoListDto
();
infoListDto
.
setAttachmentInfoDtoList
(
attachList
);
ApiResponse
apiResponse
=
uploadByFtp
(
infoListDto
);
return
apiResponse
;
}
}
@Override
public
ApiResponse
uploadByFtp
(
AttachmentInfoListDto
attachmentInfoListDto
)
{
if
(
attachmentInfoListDto
==
null
||
attachmentInfoListDto
.
getAttachmentInfoDtoList
()==
null
||
attachmentInfoListDto
.
getAttachmentInfoDtoList
().
size
()<=
0
)
{
return
new
ApiResponse
(
MessageEnum
.
FILE_DOWN_FAIL
.
getCode
(),
MessageEnum
.
FILE_DOWN_FAIL
.
getRemarks
(),
null
);
}
List
<
EshopAttachmentInfoVo
>
infoVoList
=
new
ArrayList
<
EshopAttachmentInfoVo
>();
List
<
AttachmentInfoDto
>
attList
=
attachmentInfoListDto
.
getAttachmentInfoDtoList
();
for
(
AttachmentInfoDto
infoDto
:
attList
)
{
AttachmentInfoPO
attachmentInfoPO
=
BeanTransferUtils
.
transfer
(
infoDto
,
AttachmentInfoPO
.
class
);
attachmentInfoPO
.
setId
(
SnowFlakeUtil
.
nextId
());
int
add
=
infoMapper
.
insert
(
attachmentInfoPO
);
if
(
add
>
0
)
{
EshopAttachmentInfoVo
addVo
=
new
EshopAttachmentInfoVo
();
addVo
.
setId
(
attachmentInfoPO
.
getId
()+
""
);
addVo
.
setFileName
(
attachmentInfoPO
.
getFileName
());
addVo
.
setFileUrl
(
attachmentInfoPO
.
getFileUrl
());
infoVoList
.
add
(
addVo
);
}
}
log
.
info
(
"文件业务数据存储完毕 {}"
,
System
.
currentTimeMillis
());
return
new
ApiResponse
(
ApiResponse
.
SUCCESS
,
ApiResponse
.
SUCCESS_TEXT
,
infoVoList
);
}
}
nafmii-admin/src/main/java/org/nafmii/admin/att/service/test.java
0 → 100644
View file @
ed7ce71
package
org
.
nafmii
.
admin
.
att
.
service
;
/**
* @author:zhoujh
* @Function:TODO
* @date 2021/5/7 14:41
* @ClassName:
* @version:
* @remark:
*/
public
class
test
{
}
nafmii-admin/src/main/java/org/nafmii/admin/att/vo/EshopAttachmentInfoVo.java
0 → 100644
View file @
ed7ce71
package
org
.
nafmii
.
admin
.
att
.
vo
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
*
* EshopAttachmentInfoVo对象.对应实体描述:公用附件表
*
*
*/
@Data
@ApiModel
(
"EshopAttachmentInfoVo对象"
)
public
class
EshopAttachmentInfoVo
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/** 对应字段:id,备注:附件id */
@ApiModelProperty
(
"附件id"
)
private
String
id
;
/** 对应字段:file_name,备注:源文件名称 */
@ApiModelProperty
(
"源文件名称"
)
private
String
fileName
;
/** 对应字段:file_url,备注:相对url */
@ApiModelProperty
(
"相对url"
)
private
String
fileUrl
;
/** 对应字段:file_path,备注:文件存储相对目录 */
@ApiModelProperty
(
"文件存储相对目录"
)
private
String
filePath
;
/** 对应字段:description,备注:描述 */
@ApiModelProperty
(
"描述"
)
private
String
description
;
/** 对应字段:del_flag,备注:软删除字段0未删除1已删除 */
@ApiModelProperty
(
"软删除字段0未删除1已删除"
)
private
Integer
delFlag
;
/** 对应字段:create_id,备注:创建人 */
@ApiModelProperty
(
"创建人"
)
private
Long
createUser
;
/** 对应字段:create_date,备注:创建时间 */
@ApiModelProperty
(
"创建时间"
)
private
Date
createDate
;
/** 对应字段:update_id,备注:修改时间 */
@ApiModelProperty
(
"修改人"
)
private
Long
updateUser
;
/** 对应字段:update_date,备注:修改时间 */
@ApiModelProperty
(
"修改时间"
)
private
Date
updateDate
;
/**
* 对应字段:page,备注:页码
*/
@ApiModelProperty
(
"页码"
)
private
int
page
;
/**
* 对应字段:limit,备注:每页数量
*/
@ApiModelProperty
(
"每页数量"
)
private
int
limit
;
}
nafmii-admin/src/main/resources/mapper/AttachmentInfoMapper.xml
0 → 100644
View file @
ed7ce71
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"org.nafmii.admin.dao.AttachmentInfoMapper"
>
<!-- 通用查询映射结果 -->
<resultMap
id=
"BaseResultMap"
type=
"org.nafmii.admin.entity.AttachmentInfoPO"
>
<id
column=
"ID"
property=
"id"
/>
<result
column=
"FILE_NAME"
property=
"fileName"
/>
<result
column=
"FILE_URL"
property=
"fileUrl"
/>
<result
column=
"FILE_PATH"
property=
"filePath"
/>
<result
column=
"DESCRIPTION"
property=
"description"
/>
<result
column=
"IS_ENABLE"
property=
"isEnable"
/>
<result
column=
"CREATE_USER_ID"
property=
"createUserId"
/>
<result
column=
"UPDATE_USER_ID"
property=
"updateUserId"
/>
<result
column=
"CREATE_TIME"
property=
"createTime"
/>
<result
column=
"UPDATE_TIME"
property=
"updateTime"
/>
</resultMap>
<!-- 通用查询结果列 -->
<sql
id=
"Base_Column_List"
>
ID, FILE_NAME, FILE_URL, FILE_PATH, DESCRIPTION, IS_ENABLE, CREATE_USER_ID, UPDATE_USER_ID, CREATE_TIME, UPDATE_TIME
</sql>
</mapper>
nafmii-admin/src/main/resources/mapper/BusinessAttachmentInfoMapper.xml
0 → 100644
View file @
ed7ce71
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"org.nafmii.admin.att.dao.BusinessAttachmentInfoMapper"
>
<!-- 通用查询映射结果 -->
<resultMap
id=
"BaseResultMap"
type=
"org.nafmii.admin.att.entity.BusinessAttachmentInfoPO"
>
<id
column=
"ID"
property=
"id"
/>
<result
column=
"BUSINESS"
property=
"business"
/>
<result
column=
"BUSINESS_ID"
property=
"businessId"
/>
<result
column=
"ATTACHMENT_ID"
property=
"attachmentId"
/>
<result
column=
"CREATE_USER_ID"
property=
"createUserId"
/>
<result
column=
"UPDATE_USER_ID"
property=
"updateUserId"
/>
<result
column=
"CREATE_TIME"
property=
"createTime"
/>
<result
column=
"UPDATE_TIME"
property=
"updateTime"
/>
<result
column=
"SORT"
property=
"sort"
/>
<result
column=
"DESCRIPTION"
property=
"description"
/>
<result
column=
"IS_ENABLE"
property=
"isEnable"
/>
</resultMap>
<!-- 通用查询结果列 -->
<sql
id=
"Base_Column_List"
>
ID, BUSINESS, BUSINESS_ID, ATTACHMENT_ID, CREATE_USER_ID, UPDATE_USER_ID, CREATE_TIME, UPDATE_TIME, SORT, DESCRIPTION, IS_ENABLE
</sql>
</mapper>
nafmii-app/src/main/java/org/nafmii/app/user/service/impl/UserServiceImpl.java
View file @
ed7ce71
...
...
@@ -12,21 +12,17 @@ import org.nafmii.app.user.service.UserService;
import
org.nafmii.app.user.vo.UserAndRoleVo
;
import
org.nafmii.app.user.vo.UserVO
;
import
org.nafmii.common.constant.HttpClientHeaderEnum
;
import
org.nafmii.common.exception.BusinessException
;
import
org.nafmii.common.param.BeanTransferUtils
;
import
org.nafmii.common.response.ApiResponse
;
import
org.nafmii.common.utils.GuavaUtil
;
import
org.nafmii.common.utils.JwtUtils
;
import
org.nafmii.common.utils.SnowFlakeUtil
;
import
org.nafmii.common.constant.UserEnum
;
import
org.nafmii.common.vo.UserJwtVO
;
import
org.nafmii.enums.RedisEnum
;
import
org.nafmii.common.constant.RedisEnum
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
...
...
nafmii-common/pom.xml
View file @
ed7ce71
...
...
@@ -37,7 +37,13 @@
<artifactId>
springfox-swagger2
</artifactId>
<version>
2.8.0
</version>
</dependency>
<!--- ftp-->
<dependency>
<groupId>
commons-net
</groupId>
<artifactId>
commons-net
</artifactId>
<version>
3.3
</version>
</dependency>
<!--- swagger-->
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger-ui
</artifactId>
...
...
nafmii-common/src/main/java/org/nafmii/common/constant/MessageEnum.java
View file @
ed7ce71
...
...
@@ -19,6 +19,7 @@ public enum MessageEnum {
FILE_TYPE_ERROR
(-
110L
,
"文件类型不允许上传!"
),
FILE_UPLOAD_FAIL
(-
111L
,
"文件上传失败!"
),
FILE_DOWN_FAIL
(-
112L
,
"文件不存在或已被删除!"
),
FILE_PICTURE
(-
113L
,
"图片格式非法!"
),
;
private
Long
code
;
...
...
nafmii-common/src/main/java/org/nafmii/
enums
/RedisEnum.java
→
nafmii-common/src/main/java/org/nafmii/
common/constant
/RedisEnum.java
View file @
ed7ce71
package
org
.
nafmii
.
enums
;
package
org
.
nafmii
.
common
.
constant
;
/**
* @author:zhoujh
...
...
nafmii-common/src/main/java/org/nafmii/common/constant/UserEnum.java
View file @
ed7ce71
...
...
@@ -28,6 +28,8 @@ public enum UserEnum{
LOGINPHONE
(
"1"
,
"验证码"
),
LOGINPWD
(
"0"
,
"密码"
),
;
UserEnum
(
String
code
,
String
name
){
...
...
nafmii-common/src/main/java/org/nafmii/common/utils/FtpUtil.java
0 → 100644
View file @
ed7ce71
package
org
.
nafmii
.
common
.
utils
;
import
com.alibaba.excel.util.DateUtils
;
import
com.google.common.collect.Maps
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.net.ftp.FTPClient
;
import
org.apache.commons.net.ftp.FTPFile
;
import
org.apache.commons.net.ftp.FTPReply
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartHttpServletRequest
;
import
org.springframework.web.multipart.commons.CommonsMultipartResolver
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.*
;
import
java.net.MalformedURLException
;
import
java.nio.charset.StandardCharsets
;
import
java.util.*
;
/**
* @author:zhoujh
* @Function:TODO
* @date 2020/5/21 15:13
* @ClassName:
* @version:
* @remark:
*/
@Slf4j
@Configuration
public
class
FtpUtil
{
/**访问地址*/
@Value
(
"${att.upload.path}"
)
private
static
String
path
;
/**存放地址*/
@Value
(
"${att.upload.docBase}"
)
private
static
String
docBase
;
//ftp服务器地址
@Value
(
"${att.hostname}"
)
private
String
hostname
;
//ftp服务器端口号默认为21
@Value
(
"${att.port}"
)
private
Integer
port
;
//ftp登录账号
@Value
(
"${att.username}"
)
private
String
username
;
//ftp登录密码
@Value
(
"${att.password}"
)
private
String
password
;
public
FTPClient
ftpClient
=
null
;
public
Map
<
String
,
Object
>
upload
(
HttpServletRequest
request
){
final
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
//初始化多部份解析器
CommonsMultipartResolver
multipartResolver
=
new
CommonsMultipartResolver
(
request
.
getSession
().
getServletContext
());
//检查了request是否为null,请求是否为post,form中是否有enctype="multipart/form-data"
if
(
multipartResolver
.
isMultipart
(
request
)){
//转换为多部份request
MultipartHttpServletRequest
multiRequest
=
(
MultipartHttpServletRequest
)
request
;
//获取multiRequest中所有文件名
Iterator
it
=
multiRequest
.
getFileNames
();
while
(
it
.
hasNext
()){
MultipartFile
file
=
multiRequest
.
getFile
(
it
.
next
().
toString
());
if
(
file
!=
null
){
//获取文件名
String
fileName
=
file
.
getOriginalFilename
();
// 文件后缀
String
suffixes
=
fileName
.
substring
(
fileName
.
lastIndexOf
(
"."
));
// 重命名文件
String
nowName
=
getNewName
(
suffixes
);
final
ByteArrayOutputStream
fileStream
=
new
ByteArrayOutputStream
();
// 存放位置
String
savePath
=
getFilePath
(
docBase
,
nowName
);
try
{
// 复制文件内容
IOUtils
.
copy
(
file
.
getInputStream
(),
fileStream
);
//向session中存入文件内容的引用,为保存文件做准备
request
.
getSession
().
setAttribute
(
nowName
,
fileStream
);
// 复制文件
FileUtils
.
copyInputStreamToFile
(
new
ByteArrayInputStream
(
fileStream
.
toByteArray
()),
new
File
(
savePath
));
}
catch
(
Exception
e
)
{
return
null
;
}
result
.
put
(
"nowName"
,
nowName
);
result
.
put
(
"savePath"
,
savePath
);
result
.
put
(
"fileSize"
,
file
.
getSize
());
result
.
put
(
"url"
,
getFilePath
(
path
,
nowName
));
}
else
{
return
result
;
}
}
}
return
result
;
}
public
static
Map
<
String
,
String
>
upload
(
String
imgBase64
){
log
.
info
(
"==============开始上传图片============="
);
Map
<
String
,
String
>
result
=
new
HashMap
<>();
if
(
imgBase64
!=
null
){
// 文件后缀
String
suffixes
=
".jpg"
;
// 重命名
String
nowName
=
getNewName
(
suffixes
);
// 存放位置
String
savePath
=
getFilePath
(
docBase
,
nowName
);
try
{
// IOUtils.copy(file.getInputStream(), fileStream);
mkdir
(
savePath
.
substring
(
0
,
savePath
.
lastIndexOf
(
"/"
)));
FtpUtil
.
base64MultipartFile
(
imgBase64
,
savePath
);
// file.transferTo(new File(savePath));
log
.
info
(
"==============上传成功=============="
);
}
catch
(
Exception
e
)
{
log
.
error
(
"==============出现异常,上传失败=============="
);
return
null
;
}
result
.
put
(
"nowName"
,
nowName
);
result
.
put
(
"path"
,
getFilePath
(
nowName
));
result
.
put
(
"savePath"
,
savePath
);
// result.put("url",getFilePath(path,nowName));
}
return
result
;
}
/**
* 初始化ftp服务器
*/
public
void
initFtpClient
()
{
ftpClient
=
new
FTPClient
();
ftpClient
.
setControlEncoding
(
"utf-8"
);
try
{
log
.
info
(
"...ftp服务器:connecting"
+
hostname
+
":"
+
port
+
"...."
+
DateUtils
.
format
(
new
Date
()));
ftpClient
.
connect
(
hostname
,
port
);
//连接ftp服务器
if
(!
ftpClient
.
isConnected
()){
ftpClient
.
connect
(
hostname
,
port
);
}
ftpClient
.
login
(
username
,
password
);
//登录ftp服务器
int
replyCode
=
ftpClient
.
getReplyCode
();
//是否成功登录服务器
if
(!
FTPReply
.
isPositiveCompletion
(
replyCode
)){
log
.
info
(
"connect failed...ftp服务器:"
+
hostname
+
":"
+
port
+
"...."
+
DateUtils
.
format
(
new
Date
()));
}
log
.
info
(
"connect successfu...ftp服务器:"
+
hostname
+
":"
+
port
+
"...."
+
DateUtils
.
format
(
new
Date
()));
}
catch
(
MalformedURLException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
/**
* 上传文件
* @param pathname ftp服务保存地址
* @param fileName 上传到ftp的文件名
* @param originfilename 待上传文件的名称(绝对地址) *
* @return
*/
public
boolean
uploadFile
(
String
pathname
,
String
fileName
,
String
originfilename
){
boolean
flag
=
false
;
InputStream
inputStream
=
null
;
try
{
log
.
info
(
"开始上传文件"
);
inputStream
=
new
FileInputStream
(
new
File
(
originfilename
));
initFtpClient
();
ftpClient
.
setFileType
(
FTPClient
.
BINARY_FILE_TYPE
);
CreateDirecroty
(
pathname
);
ftpClient
.
makeDirectory
(
pathname
);
ftpClient
.
changeWorkingDirectory
(
pathname
);
ftpClient
.
storeFile
(
fileName
,
inputStream
);
inputStream
.
close
();
ftpClient
.
logout
();
flag
=
true
;
log
.
info
(
"上传文件成功"
);
}
catch
(
Exception
e
)
{
log
.
info
(
"上传文件失败"
);
e
.
printStackTrace
();
}
finally
{
if
(
ftpClient
.
isConnected
()){
try
{
ftpClient
.
disconnect
();
}
catch
(
IOException
e
){
e
.
printStackTrace
();
}
}
if
(
null
!=
inputStream
){
try
{
inputStream
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
return
true
;
}
/**
* 上传文件
* @param path ftp服务保存地址
* @param fileName 上传到ftp的文件名重命名的文件名
* @param inputStream 输入文件流
* @return
*/
public
Map
<
Boolean
,
String
>
uploadArrFile
(
String
path
,
LinkedList
<
String
>
fileName
,
LinkedList
<
InputStream
>
inputStream
){
boolean
flag
=
false
;
Map
<
Boolean
,
String
>
map
=
Maps
.
newHashMap
();
String
realPath
=
""
;
try
{
log
.
info
(
"======开始上传文件======"
);
log
.
info
(
"======上传文件地址======"
+
path
+
"====系统存储文件名=="
+
fileName
);
initFtpClient
();
ftpClient
.
setFileType
(
FTPClient
.
BINARY_FILE_TYPE
);
realPath
=
path
+
"/"
+
fileName
;
CreateDirecroty
(
path
);
ftpClient
.
makeDirectory
(
path
);
ftpClient
.
changeWorkingDirectory
(
path
);
for
(
int
i
=
0
;
i
<
fileName
.
size
();
i
++){
ftpClient
.
storeFile
(
fileName
.
get
(
i
),
inputStream
.
get
(
i
));
inputStream
.
get
(
i
).
close
();
}
ftpClient
.
logout
();
flag
=
true
;
log
.
info
(
"======上传文件成功======"
);
}
catch
(
Exception
e
)
{
log
.
error
(
"======上传文件失败======"
);
e
.
printStackTrace
();
}
finally
{
if
(
ftpClient
.
isConnected
()){
try
{
ftpClient
.
disconnect
();
}
catch
(
IOException
e
){
e
.
printStackTrace
();
}
}
for
(
int
i
=
0
;
i
<
inputStream
.
size
();
i
++){
if
(
null
!=
inputStream
.
get
(
i
)){
try
{
inputStream
.
get
(
i
).
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
map
.
put
(
flag
,
realPath
);
return
map
;
}
/**
* 上传文件
* @param path ftp服务保存地址
* @param fileName 上传到ftp的文件名重命名的文件名
* @param inputStream 输入文件流
* @return
*/
public
Map
<
Boolean
,
String
>
uploadFile
(
String
path
,
String
fileName
,
InputStream
inputStream
){
boolean
flag
=
false
;
Map
<
Boolean
,
String
>
map
=
Maps
.
newHashMap
();
String
realPath
=
""
;
try
{
log
.
info
(
"======开始上传文件======"
);
log
.
info
(
"======上传文件地址======"
+
path
+
"====系统存储文件名=="
+
fileName
);
initFtpClient
();
ftpClient
.
setFileType
(
FTPClient
.
BINARY_FILE_TYPE
);
realPath
=
path
+
"/"
+
fileName
;
CreateDirecroty
(
path
);
ftpClient
.
makeDirectory
(
path
);
ftpClient
.
changeWorkingDirectory
(
path
);
ftpClient
.
storeFile
(
fileName
,
inputStream
);
inputStream
.
close
();
ftpClient
.
logout
();
flag
=
true
;
log
.
info
(
"======上传文件成功======"
);
}
catch
(
Exception
e
)
{
log
.
error
(
"======上传文件失败======"
);
e
.
printStackTrace
();
}
finally
{
if
(
ftpClient
.
isConnected
()){
try
{
ftpClient
.
disconnect
();
}
catch
(
IOException
e
){
e
.
printStackTrace
();
}
}
if
(
null
!=
inputStream
){
try
{
inputStream
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
map
.
put
(
flag
,
realPath
);
return
map
;
}
//改变目录路径
public
boolean
changeWorkingDirectory
(
String
directory
)
{
boolean
flag
=
true
;
try
{
flag
=
ftpClient
.
changeWorkingDirectory
(
directory
);
}
catch
(
IOException
ioe
)
{
ioe
.
printStackTrace
();
}
return
flag
;
}
//创建多层目录文件,如果有ftp服务器已存在该文件,则不创建,如果无,则创建
public
boolean
CreateDirecroty
(
String
remote
)
throws
IOException
{
boolean
success
=
true
;
String
directory
=
remote
+
"/"
;
// 如果远程目录不存在,则递归创建远程服务器目录
if
(!
directory
.
equalsIgnoreCase
(
"/"
)
&&
!
changeWorkingDirectory
(
directory
))
{
int
start
=
0
;
int
end
=
0
;
if
(
directory
.
startsWith
(
"/"
))
{
start
=
1
;
}
else
{
start
=
0
;
}
end
=
directory
.
indexOf
(
"/"
,
start
);
String
path
=
""
;
String
paths
=
""
;
while
(
true
)
{
String
subDirectory
=
new
String
(
remote
.
substring
(
start
,
end
).
getBytes
(
"GBK"
),
StandardCharsets
.
ISO_8859_1
);
path
=
path
+
"/"
+
subDirectory
;
if
(!
existFile
(
path
))
{
if
(
makeDirectory
(
subDirectory
))
{
changeWorkingDirectory
(
subDirectory
);
}
else
{
log
.
info
(
"创建目录["
+
subDirectory
+
"]失败"
);
changeWorkingDirectory
(
subDirectory
);
}
}
else
{
changeWorkingDirectory
(
subDirectory
);
}
paths
=
paths
+
"/"
+
subDirectory
;
start
=
end
+
1
;
end
=
directory
.
indexOf
(
"/"
,
start
);
// 检查所有目录是否创建完毕
if
(
end
<=
start
)
{
break
;
}
}
}
return
success
;
}
//判断ftp服务器文件是否存在
public
boolean
existFile
(
String
path
)
throws
IOException
{
boolean
flag
=
false
;
FTPFile
[]
ftpFileArr
=
ftpClient
.
listFiles
(
path
);
if
(
ftpFileArr
.
length
>
0
)
{
flag
=
true
;
}
return
flag
;
}
//创建目录
public
boolean
makeDirectory
(
String
dir
)
{
boolean
flag
=
true
;
try
{
flag
=
ftpClient
.
makeDirectory
(
dir
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
flag
;
}
/** * 下载文件 *
* @param pathname FTP服务器文件目录 *
* @param filename 文件名称 *
* @param localpath 下载后的文件路径 *
* @return */
public
boolean
downloadFile
(
String
pathname
,
String
filename
,
String
localpath
){
boolean
flag
=
false
;
OutputStream
os
=
null
;
try
{
log
.
info
(
"======开始下载文件======"
);
initFtpClient
();
//切换FTP目录
ftpClient
.
changeWorkingDirectory
(
pathname
);
FTPFile
[]
ftpFiles
=
ftpClient
.
listFiles
();
for
(
FTPFile
file
:
ftpFiles
){
if
(
filename
.
equalsIgnoreCase
(
file
.
getName
())){
File
localFile
=
new
File
(
localpath
+
"/"
+
file
.
getName
());
os
=
new
FileOutputStream
(
localFile
);
ftpClient
.
retrieveFile
(
file
.
getName
(),
os
);
os
.
close
();
}
}
ftpClient
.
logout
();
flag
=
true
;
log
.
info
(
"======下载文件成功======"
);
}
catch
(
Exception
e
)
{
log
.
error
(
"======下载文件失败======"
);
e
.
printStackTrace
();
}
finally
{
if
(
ftpClient
.
isConnected
()){
try
{
ftpClient
.
disconnect
();
}
catch
(
IOException
e
){
e
.
printStackTrace
();
}
}
if
(
null
!=
os
){
try
{
os
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
return
flag
;
}
/** * 删除文件 *
* @param pathname FTP服务器保存目录 *
* @param filename 要删除的文件名称 *
* @return */
public
boolean
deleteFile
(
String
pathname
,
String
filename
){
boolean
flag
=
false
;
try
{
log
.
info
(
"======开始删除文件======"
);
initFtpClient
();
//切换FTP目录
ftpClient
.
changeWorkingDirectory
(
pathname
);
ftpClient
.
dele
(
filename
);
ftpClient
.
logout
();
flag
=
true
;
log
.
info
(
"======删除文件成功======"
);
}
catch
(
Exception
e
)
{
log
.
error
(
"======删除文件失败======"
);
e
.
printStackTrace
();
}
finally
{
if
(
ftpClient
.
isConnected
()){
try
{
ftpClient
.
disconnect
();
}
catch
(
IOException
e
){
e
.
printStackTrace
();
}
}
}
return
flag
;
}
public
static
void
mkdir
(
String
path
)
{
File
dir
=
new
File
(
path
);
if
(
dir
.
exists
())
{
if
(!
dir
.
isFile
())
{
return
;
}
dir
.
delete
();
}
dir
.
mkdirs
();
}
/**
* 获取文件绝对路径
* @param request
* @param host
* @return
*/
public
static
String
getFileUrl
(
HttpServletRequest
request
,
String
host
)
{
String
path
=
request
.
getScheme
()
+
"://"
+
host
+
request
.
getContextPath
()
+
"/"
;
int
port
=
request
.
getServerPort
();
if
(
80
!=
port
)
{
path
=
request
.
getScheme
()
+
"://"
+
host
+
":"
+
request
.
getServerPort
()
+
request
.
getContextPath
()
+
"/"
;
}
return
path
;
}
/**
* 文件路径
* @param pathname
* @return
*/
public
static
String
getFilePath
(
String
pathname
)
{
StringBuilder
sb
=
new
StringBuilder
().
append
(
DateUtils
.
format
(
new
Date
())).
append
(
"/"
).
append
(
pathname
);
return
sb
.
toString
();
}
/**
* 文件路径
* @param filepath
* @param filename
* @return
*/
public
static
String
getFilePath
(
String
filepath
,
String
filename
)
{
StringBuilder
sb
=
new
StringBuilder
(
filepath
).
append
(
DateUtils
.
format
(
new
Date
())).
append
(
"/"
).
append
(
filename
);
return
sb
.
toString
();
}
/**
* 文件重命名
* @param suffixes
* @return
*/
public
static
String
getNewName
(
String
suffixes
){
return
UUID
.
randomUUID
().
toString
().
replaceAll
(
"\\-"
,
""
)
+
suffixes
;
}
/**
* 删除文件
* @param path
*/
public
static
void
delFiles
(
String
path
)
{
File
file
=
new
File
(
path
);
if
(
file
.
exists
())
{
file
.
delete
();
}
}
public
static
boolean
base64MultipartFile
(
String
imgStr
,
String
imagePath
){
if
(
imgStr
==
null
){
return
false
;
}
try
{
String
[]
baseStr
=
imgStr
.
split
(
","
);
Base64
.
Decoder
decoder
=
Base64
.
getMimeDecoder
();
byte
[]
b
=
new
byte
[
0
];
b
=
decoder
.
decode
(
baseStr
[
1
]);
for
(
int
i
=
0
;
i
<
b
.
length
;
++
i
)
{
if
(
b
[
i
]
<
0
)
{
b
[
i
]
+=
256
;
}
}
OutputStream
out
=
new
FileOutputStream
(
imagePath
);
out
.
write
(
b
);
out
.
flush
();
out
.
close
();
return
true
;
}
catch
(
Exception
e
){
e
.
printStackTrace
();
return
false
;
}
}
}
nafmii-common/src/main/java/org/nafmii/common/utils/JwtUtils.java
View file @
ed7ce71
...
...
@@ -8,6 +8,10 @@ import org.nafmii.common.constant.HttpClientHeaderEnum;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* zjh
*/
@Slf4j
public
class
JwtUtils
{
public
static
final
String
TOKEN_HEADER
=
"Authorization"
;
...
...
nafmii-common/src/main/java/org/nafmii/common/utils/StringUtil.java
0 → 100644
View file @
ed7ce71
package
org
.
nafmii
.
common
.
utils
;
import
java.math.RoundingMode
;
import
java.nio.charset.StandardCharsets
;
import
java.text.DecimalFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
* String字符串操作工具类
* @author sea
* @version 1.2.0
*/
public
class
StringUtil
{
/**
* 过滤文本HTML标签
* @param html
* @return
*/
public
static
String
removeHTML
(
String
html
){
String
regEx_script
=
"<script[^>]*?>[\\s\\S]*?<\\/script>"
;
//定义script的正则表达式
String
regEx_style
=
"<style[^>]*?>[\\s\\S]*?<\\/style>"
;
//定义style的正则表达式
String
regEx_html
=
"<[^>]+>"
;
//定义HTML标签的正则表达式
Pattern
p_script
=
Pattern
.
compile
(
regEx_script
,
Pattern
.
CASE_INSENSITIVE
);
Matcher
m_script
=
p_script
.
matcher
(
html
);
html
=
m_script
.
replaceAll
(
""
);
//过滤script标签
Pattern
p_style
=
Pattern
.
compile
(
regEx_style
,
Pattern
.
CASE_INSENSITIVE
);
Matcher
m_style
=
p_style
.
matcher
(
html
);
html
=
m_style
.
replaceAll
(
""
);
//过滤style标签
Pattern
p_html
=
Pattern
.
compile
(
regEx_html
,
Pattern
.
CASE_INSENSITIVE
);
Matcher
m_html
=
p_html
.
matcher
(
html
);
html
=
m_html
.
replaceAll
(
""
);
//过滤html标签
return
html
.
trim
();
//返回文本字符串
}
/**
* 判断字符是否为null,为null就返回空字符串
* @param object
* @return
*/
public
static
String
getEmptyString
(
Object
object
){
try
{
if
(
object
==
null
){
return
""
;
}
String
content
=
String
.
valueOf
(
object
);
return
content
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
""
;
}
}
/**
* 判断字符是否为null,为null就返回false
* @param object
* @return
*/
public
static
boolean
isEmptyString
(
Object
object
){
return
object
!=
null
&&
!
""
.
equals
(
object
.
toString
().
trim
());
}
/**
* 校验日期格式
* @param pattern
* @param dateString
* @return
*/
public
static
boolean
isValidDateFormat
(
String
pattern
,
String
dateString
)
{
try
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
pattern
);
format
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"GMT+8"
));
format
.
setLenient
(
false
);
format
.
parse
(
dateString
);
return
true
;
}
catch
(
Exception
e
)
{
return
false
;
}
}
/**
* 判断对象的值是否包含在该目标数组中(数组为空时候,只判断对象自己)
* @param object
* @param filters
* @return
*/
public
static
boolean
isContain
(
Integer
object
,
int
[]
filters
){
if
(
object
==
null
){
return
false
;
}
if
(
filters
!=
null
&&
filters
.
length
>
0
){
for
(
int
i
=
0
;
i
<
filters
.
length
;
i
++)
{
if
(
object
.
intValue
()==
filters
[
i
]){
return
true
;
}
}
return
false
;
}
return
true
;
}
/**
* 获取相应的显示格式时候
* @param dateTime
* @return
*/
public
static
String
getShowDate
(
String
dateTime
){
String
createDate
=
""
;
try
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
,
Locale
.
US
);
format
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"GMT+8"
));
SimpleDateFormat
formatShow
=
new
SimpleDateFormat
(
"MM-dd HH:mm"
);
Date
oldDate
=
format
.
parse
(
dateTime
);
Date
nowDate
=
new
Date
();
long
longTime
=
nowDate
.
getTime
()-
oldDate
.
getTime
();
long
day
=
longTime
/(
24
*
60
*
60
*
1000
);
long
hour
=(
longTime
/(
60
*
60
*
1000
)-
day
*
24
);
long
min
=((
longTime
/(
60
*
1000
))-
day
*
24
*
60
-
hour
*
60
);
long
s
=(
longTime
/
1000
-
day
*
24
*
60
*
60
-
hour
*
60
*
60
-
min
*
60
);
if
(
day
>
0
){
createDate
=
formatShow
.
format
(
oldDate
);
}
else
{
if
(
hour
>
0
){
createDate
=
hour
+
"小时前"
;
}
else
{
if
(
min
>
0
){
createDate
=
min
+
"分钟前"
;
}
else
{
createDate
=
s
+
"秒前"
;
}
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
createDate
;
}
/**
* 获取时间天数
* @param startDate
* @param endDate
* @return
*/
public
static
Long
getDay
(
String
startDate
,
String
endDate
)
{
try
{
if
(!
StringUtil
.
isEmptyString
(
startDate
)
||
!
StringUtil
.
isEmptyString
(
endDate
)){
return
-
10000L
;
}
if
(
startDate
.
length
()>
20
){
startDate
=
startDate
.
substring
(
0
,
20
);
}
if
(
endDate
.
length
()>
20
){
endDate
=
endDate
.
substring
(
0
,
20
);
}
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
,
Locale
.
US
);
format
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"GMT+8"
));
Date
oldDate
=
format
.
parse
(
startDate
);
Date
nowDate
=
format
.
parse
(
endDate
);
return
getDay
(
oldDate
,
nowDate
);
}
catch
(
Exception
e
)
{
return
-
10000L
;
}
}
/**
* 获取时间天数
* @param startDate
* @param endDate
* @return
*/
public
static
Long
getDay
(
Date
startDate
,
Date
endDate
)
{
try
{
long
longTime
=
endDate
.
getTime
()-
startDate
.
getTime
();
long
day
=
longTime
/(
24
*
60
*
60
*
1000
);
return
day
;
}
catch
(
Exception
e
)
{
return
-
10000L
;
}
}
/**
* unicode转UTF-8
* @param theString
* @return
*/
public
static
String
unicodeToUtf8
(
String
theString
)
{
char
aChar
;
int
len
=
theString
.
length
();
StringBuffer
outBuffer
=
new
StringBuffer
(
len
);
for
(
int
x
=
0
;
x
<
len
;)
{
aChar
=
theString
.
charAt
(
x
++);
if
(
aChar
==
'\\'
)
{
aChar
=
theString
.
charAt
(
x
++);
if
(
aChar
==
'u'
)
{
// Read the xxxx
int
value
=
0
;
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
aChar
=
theString
.
charAt
(
x
++);
switch
(
aChar
)
{
case
'0'
:
case
'1'
:
case
'2'
:
case
'3'
:
case
'4'
:
case
'5'
:
case
'6'
:
case
'7'
:
case
'8'
:
case
'9'
:
value
=
(
value
<<
4
)
+
aChar
-
'0'
;
break
;
case
'a'
:
case
'b'
:
case
'c'
:
case
'd'
:
case
'e'
:
case
'f'
:
value
=
(
value
<<
4
)
+
10
+
aChar
-
'a'
;
break
;
case
'A'
:
case
'B'
:
case
'C'
:
case
'D'
:
case
'E'
:
case
'F'
:
value
=
(
value
<<
4
)
+
10
+
aChar
-
'A'
;
break
;
default
:
throw
new
IllegalArgumentException
(
"Malformed \\uxxxx encoding."
);
}
}
outBuffer
.
append
((
char
)
value
);
}
else
{
if
(
aChar
==
't'
)
aChar
=
'\t'
;
else
if
(
aChar
==
'r'
)
aChar
=
'\r'
;
else
if
(
aChar
==
'n'
)
aChar
=
'\n'
;
else
if
(
aChar
==
'f'
)
aChar
=
'\f'
;
outBuffer
.
append
(
aChar
);
}
}
else
outBuffer
.
append
(
aChar
);
}
return
outBuffer
.
toString
();
}
/**
* ISO-8859-1 转 UTF-8
* @param content
* @return
*/
public
static
String
isoToUtf8
(
String
content
)
{
if
(!
StringUtil
.
isEmptyString
(
content
)){
return
content
;
}
try
{
content
=
new
String
(
content
.
getBytes
(
StandardCharsets
.
ISO_8859_1
),
StandardCharsets
.
UTF_8
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
content
;
}
/**
* 保留小数点后两位数字
* @param number
* @return
*/
public
static
String
doubleFormatByTwo
(
Double
number
)
{
if
(
number
==
null
){
return
""
;
}
if
(
number
.
doubleValue
()==
0
){
return
"0"
;
}
DecimalFormat
df
=
new
DecimalFormat
(
"0.00"
);
return
df
.
format
(
number
);
}
/**
* 保留小数点后两位数字(不保留四舍五入)
* @param number
* @return
*/
public
static
String
doubleFormatByTwoA
(
Double
number
)
{
if
(
number
==
null
){
return
""
;
}
DecimalFormat
df
=
new
DecimalFormat
();
df
.
setMaximumFractionDigits
(
2
);
df
.
setGroupingSize
(
0
);
df
.
setRoundingMode
(
RoundingMode
.
FLOOR
);
return
df
.
format
(
number
);
}
/**
* 保留小数点后一位数字
* @param number
* @return
*/
public
static
String
doubleFormatByOne
(
Double
number
)
{
if
(
number
==
null
){
return
""
;
}
if
(
number
.
doubleValue
()==
0
){
return
"0"
;
}
DecimalFormat
df
=
new
DecimalFormat
(
"0.0"
);
return
df
.
format
(
number
);
}
/**
* 过滤JSON格式内容
* @param content
* @return
*/
public
static
String
replaceAllByJson
(
String
content
)
{
if
(!
StringUtil
.
isEmptyString
(
content
)){
return
content
;
}
content
=
content
.
replaceAll
(
"'"
,
""
);
content
=
content
.
replaceAll
(
"\""
,
""
);
content
=
content
.
replaceAll
(
":"
,
""
);
content
=
content
.
replaceAll
(
";"
,
""
);
content
=
content
.
replaceAll
(
"[\\[\\]]"
,
""
);
content
=
content
.
replaceAll
(
"[\\{\\}]"
,
""
);
return
content
;
}
/**
* 将数字补全后返回字符串(9->009)
* @param pattern 补全格式(000)
* @param number 数字
* @return
*/
public
static
String
numberFormat
(
String
pattern
,
long
number
){
DecimalFormat
df
=
new
DecimalFormat
(
pattern
);
return
df
.
format
(
number
);
}
/**
* 获取随机数(按时间)
* @return
*/
public
static
String
getRandomOrderNumber
(){
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyyMMddHHmmssSSS"
,
Locale
.
US
);
format
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"GMT+8"
));
int
randomNumber
=(
int
)(
Math
.
random
()*
10000
);
String
number
=
StringUtil
.
numberFormat
(
"00000"
,
randomNumber
);
return
format
.
format
(
new
Date
())+
number
;
}
/**
* 获取随机数(按时间)
* @return
*/
public
static
String
getRandomFiveNumber
(){
int
randomNumber
=(
int
)(
Math
.
random
()*
10000
);
String
number
=
StringUtil
.
numberFormat
(
"00000"
,
randomNumber
);
return
number
;
}
/**
* 获取随机数(按时间)
* @return
*/
public
static
String
getRandomSixNumber
(){
int
randomNumber
=(
int
)(
Math
.
random
()*
100000
);
String
number
=
StringUtil
.
numberFormat
(
"000000"
,
randomNumber
);
return
number
;
}
/**
* 获取日期数字
*
* @param randomNumber
* @return
*/
public
static
String
getRandomOrderNumber
(
int
randomNumber
)
{
return
getRandomOrderNumber
(
randomNumber
,
5
);
}
/**
* 获取日期数字
*
* @param randomNumber
* @param index
* @return
*/
public
static
String
getRandomOrderNumber
(
int
randomNumber
,
int
index
)
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyyMMdd"
,
Locale
.
US
);
format
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"GMT+8"
));
String
pattern
=
""
;
for
(
int
i
=
0
;
i
<
index
;
i
++)
{
pattern
+=
"0"
;
}
String
number
=
StringUtil
.
numberFormat
(
pattern
,
randomNumber
);
return
format
.
format
(
new
Date
())
+
number
;
}
/**
* 获取随机字符串
*
* @return
*/
public
static
String
getRandomOrderNumberString
()
{
String
chars
=
"abcdefghijklmnopqrstuvwxyz"
;
int
index1
=
(
int
)
(
Math
.
random
()
*
26
);
int
index2
=
(
int
)
(
Math
.
random
()
*
26
);
int
index3
=
(
int
)
(
Math
.
random
()
*
26
);
int
index4
=
(
int
)
(
Math
.
random
()
*
26
);
int
index5
=
(
int
)
(
Math
.
random
()
*
26
);
char
[]
charArray
=
new
char
[]{
chars
.
charAt
(
index1
),
chars
.
charAt
(
index2
),
chars
.
charAt
(
index3
),
chars
.
charAt
(
index4
),
chars
.
charAt
(
index5
)
};
return
String
.
valueOf
(
charArray
);
}
/**
* 过滤emoji 或者 其他非文字类型的字符
* @param source
* @return
*/
public
static
String
removeFourChar
(
String
source
)
{
if
(!
containsEmoji
(
source
))
{
return
source
;
// 如果不包含,直接返回
}
// 到这里铁定包含
StringBuilder
buf
=
null
;
int
len
=
source
.
length
();
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
char
codePoint
=
source
.
charAt
(
i
);
if
(
isEmojiCharacter
(
codePoint
))
{
if
(
buf
==
null
)
{
buf
=
new
StringBuilder
(
source
.
length
());
}
buf
.
append
(
codePoint
);
}
}
if
(
buf
==
null
)
{
return
source
;
// 如果没有找到 emoji表情,则返回源字符串
}
else
{
if
(
buf
.
length
()
==
len
)
{
buf
=
null
;
return
source
;
}
else
{
return
buf
.
toString
();
}
}
}
/**
* 检测是否有emoji字符
* @param source
* @return
*/
private
static
boolean
containsEmoji
(
String
source
)
{
if
(
source
==
null
||
""
.
equals
(
source
.
trim
()))
{
return
false
;
}
int
len
=
source
.
length
();
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
char
codePoint
=
source
.
charAt
(
i
);
if
(
isEmojiCharacter
(
codePoint
))
{
// do nothing,判断到了这里表明,确认有表情字符
return
true
;
}
}
return
false
;
}
/**
* 检测是否有emoji字符
* @param codePoint
* @return
*/
private
static
boolean
isEmojiCharacter
(
char
codePoint
)
{
return
(
codePoint
==
0x0
)
||
(
codePoint
==
0x9
)
||
(
codePoint
==
0xA
)
||
(
codePoint
==
0xD
)
||
((
codePoint
>=
0x20
)
&&
(
codePoint
<=
0xD7FF
))
||
((
codePoint
>=
0xE000
)
&&
(
codePoint
<=
0xFFFD
));
}
/**
* 把输入字符串分割成指定长度的字符串列表
* @param inputString
* @param length
* @return
*/
public
static
List
<
String
>
splitStringByLength
(
String
inputString
,
int
length
)
{
int
size
=
inputString
.
length
()
/
length
;
if
(
inputString
.
length
()
%
length
!=
0
)
{
size
+=
1
;
}
List
<
String
>
list
=
new
ArrayList
<
String
>();
if
(
length
>
inputString
.
length
()){
list
.
add
(
inputString
);
return
list
;
}
String
childStr
=
null
;
for
(
int
index
=
0
;
index
<
size
;
index
++)
{
int
f
=
index
*
length
;
int
t
=
(
index
+
1
)
*
length
;
if
(
f
>
inputString
.
length
())
break
;
if
(
t
>
inputString
.
length
()
)
childStr
=
inputString
.
substring
(
f
);
else
childStr
=
inputString
.
substring
(
f
,
t
);
list
.
add
(
childStr
);
}
return
list
;
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
getRandomFiveNumber
());
}
}
nafmii-common/src/main/resources/application.properties
View file @
ed7ce71
#ftp地址-ftp请求。
ftp.host
=
127.0.0.1
#ftp端口号
ftp.port
=
21
#ftp请求的用户名
ftp.username
=
ftpUser2
#ftp请求的密码
ftp.password
=
ftpUser2
#ftp请求读取写入的文件路径
ftp.filepath
=
/data/ftp
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment