Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
long-tern-care-service
Project
Project
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
hubin
long-tern-care-service
Commits
a04876b7
Commit
a04876b7
authored
May 24, 2021
by
zhangch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
上传文件接口
parent
dc2d0f07
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
340 additions
and
0 deletions
+340
-0
ChFndAttach.java
...a/com/hungraim/ltc/pojo/entity/SysConfig/ChFndAttach.java
+73
-0
AttachType.java
...-core/src/main/java/com/hungraim/ltc/util/AttachType.java
+72
-0
FileUtils.java
...n-core/src/main/java/com/hungraim/ltc/util/FileUtils.java
+57
-0
FileUploadConfig.java
...java/com/hungraim/ltc/system/config/FileUploadConfig.java
+14
-0
FileUploadController.java
.../hungraim/ltc/system/controller/FileUploadController.java
+46
-0
ChFndAttachMapper.java
...n/java/com/hungraim/ltc/system/dao/ChFndAttachMapper.java
+12
-0
AttachService.java
...n/java/com/hungraim/ltc/system/service/AttachService.java
+15
-0
AttachServiceImpl.java
...m/hungraim/ltc/system/service/impl/AttachServiceImpl.java
+30
-0
ChFndAttachMapper.xml
...n-service/src/main/resources/mapper/ChFndAttachMapper.xml
+21
-0
No files found.
common/common-core/src/main/java/com/hungraim/ltc/pojo/entity/SysConfig/ChFndAttach.java
0 → 100644
View file @
a04876b7
package
com
.
hungraim
.
ltc
.
pojo
.
entity
.
SysConfig
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.KeySequence
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
* CH_FND_ATTACH
* @author zhangch
*/
@Data
@TableName
(
"CH_FND_ATTACH"
)
@KeySequence
(
"SEQ_CH_FND_ATTACH"
)
public
class
ChFndAttach
implements
Serializable
{
/**
* 上传文件id
*/
@TableId
(
type
=
IdType
.
INPUT
)
private
Long
attachId
;
/**
* 文件名称
*/
private
String
fileName
;
/**
* 文件路径
*/
private
String
filePath
;
/**
* 上传时间
*/
private
Date
fileTime
;
/**
* 关联id
*/
private
Long
ctrlId
;
/**
* 附件类型(1:失能人员附件;2:鉴定任务附件;3:服务方案附件;4:稽核巡查;5:护理机构基金结算申请新增;6:无锡长护保险自评申请;7:失能信息变更附件;8:评估结论书;9:参保人员及家属;10:评定人员1;11:评定人员2;12:鉴定机构附件;13:护理机构附件;14:鉴定人员附件;15:护理人员附件 16-护理人员服务项目结束附件,17:建床,18:撤床)
*/
private
Short
attachType
;
/**
* 首次操作时间
*/
private
Date
fcd
;
/**
* 首次操作人
*/
private
Long
fcu
;
/**
* 文件类型
*/
private
Short
docType
;
/**
* 0有效,1无效
*/
private
Short
status
;
private
static
final
long
serialVersionUID
=
1L
;
}
\ No newline at end of file
common/common-core/src/main/java/com/hungraim/ltc/util/AttachType.java
0 → 100644
View file @
a04876b7
package
com
.
hungraim
.
ltc
.
util
;
import
lombok.AllArgsConstructor
;
import
lombok.NoArgsConstructor
;
/**
* 文件类型枚举类
*/
@AllArgsConstructor
@NoArgsConstructor
public
enum
AttachType
{
/**
* 附件类型(1:失能人员附件;2:鉴定任务附件;3:服务方案附件;4:稽核巡查;5:护理机构基金结算申请新增;6:无锡长护保险自评申请;7:失能信息变更附件;
* 8:评估结论书;9:参保人员及家属;10:评定人员1;11:评定人员2;12:鉴定机构附件;13:护理机构附件;14:鉴定人员附件;15:护理人员附件 16-护理人员服务项目结束附件,17:建床,18:撤床)
*/
/**
* 1:失能人员附件;
*/
DISABLE
((
short
)
1
),
/**
* 2:鉴定任务附件;
*/
TASK
((
short
)
2
),
/**
* 3:服务方案附件;
*/
PROGRAM
((
short
)
3
),
/**
* 4:稽核巡查;
*/
AUDIT
((
short
)
4
),
/**
* 7:失能信息变更附件;
*/
DISABLE_UPDATE
((
short
)
7
),
/**
* 12:鉴定机构附件
*/
APR_ORGAN
((
short
)
12
),
/**
* 13:护理机构附件;
*/
SRV_ORGAN
((
short
)
13
),
/**
* 14:鉴定人员附件;
*/
APR_ORGAN_EMP
((
short
)
14
),
/**
* 15:护理人员附件;
*/
SRV_ORGAN_EMP
((
short
)
15
);
private
Short
uploadType
;
public
Short
getUploadType
()
{
return
uploadType
;
}
public
void
setUploadType
(
Short
uploadType
)
{
this
.
uploadType
=
uploadType
;
}
}
common/common-core/src/main/java/com/hungraim/ltc/util/FileUtils.java
0 → 100644
View file @
a04876b7
package
com
.
hungraim
.
ltc
.
util
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.File
;
import
java.io.IOException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.UUID
;
/**
* 文件工具类
*/
@Slf4j
public
class
FileUtils
{
/**
* 上传文件
*
* @param uploadFile controller接收到的文件对象
* @param path 存放文件的根路径
* @return 返回文件具体保存的路径,包含文件名称
*/
public
static
String
uploadFile
(
MultipartFile
uploadFile
,
String
path
)
{
log
.
info
(
"开始进行文件上传"
);
try
{
//获取到文件名
String
fileName
=
uploadFile
.
getOriginalFilename
();
log
.
info
(
"文件名称:{}"
,
fileName
);
//使用日期格式创建文件夹
String
dataPathDir
=
new
SimpleDateFormat
(
"yyyy/MM/dd"
).
format
(
new
Date
());
//真实的文件夹路径
String
realDirPath
=
path
+
"/"
+
dataPathDir
;
//判断文件夹是否存在
File
dirFile
=
new
File
(
realDirPath
);
if
(!
dirFile
.
exists
())
{
dirFile
.
mkdirs
();
}
String
uuid
=
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
);
//截取原先文件的类型
String
fileType
=
fileName
.
substring
(
fileName
.
lastIndexOf
(
"."
));
String
realName
=
uuid
+
fileType
;
//文件上传
String
realFilePath
=
realDirPath
+
"/"
+
realName
;
log
.
info
(
"文件上传路径以及名称:{}"
,
realFilePath
);
File
file
=
new
File
(
realFilePath
);
uploadFile
.
transferTo
(
file
);
return
realFilePath
;
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
}
system/system-admin-service/src/main/java/com/hungraim/ltc/system/config/FileUploadConfig.java
0 → 100644
View file @
a04876b7
package
com
.
hungraim
.
ltc
.
system
.
config
;
import
lombok.Data
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.stereotype.Component
;
@Component
@Data
@ConfigurationProperties
(
prefix
=
"file.upload"
)
public
class
FileUploadConfig
{
private
String
path
;
}
system/system-admin-service/src/main/java/com/hungraim/ltc/system/controller/FileUploadController.java
0 → 100644
View file @
a04876b7
package
com
.
hungraim
.
ltc
.
system
.
controller
;
import
com.hungraim.ltc.system.config.FileUploadConfig
;
import
com.hungraim.ltc.system.service.AttachService
;
import
com.hungraim.ltc.util.FileUtils
;
import
com.hungraim.ltc.util.Result
;
import
com.hungraim.ltc.util.ResultCode
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
@RestController
@RequestMapping
(
"/api.system/resource"
)
@Slf4j
public
class
FileUploadController
{
@Autowired
private
FileUploadConfig
fileUploadConfig
;
@Autowired
private
AttachService
attachService
;
/**
* 上传文件接口
*
* @param file 上传的文件
* @param uploadType 附件类型 附件类型(1:失能人员附件;2:鉴定任务附件;3:服务方案附件;4:稽核巡查;5:护理机构基金结算申请新增;6:无锡长护保险自评申请;7:失能信息变更附件;
* 8:评估结论书;9:参保人员及家属;10:评定人员1;11:评定人员2;12:鉴定机构附件;13:护理机构附件;14:鉴定人员附件;15:护理人员附件 16-护理人员服务项目结束附件,17:建床,18:撤床)
* @return 返回保存到数据库之后的文件id
*/
@PostMapping
(
"/uploadFile"
)
public
Result
uploadFile
(
MultipartFile
file
,
Short
uploadType
)
{
if
(
null
==
uploadType
||
null
==
file
)
{
return
Result
.
failed
(
ResultCode
.
REQUEST_PARAM_ERROR
);
}
String
originalFilename
=
file
.
getOriginalFilename
();
String
realPath
=
FileUtils
.
uploadFile
(
file
,
fileUploadConfig
.
getPath
());
log
.
info
(
"文件上传成功:{}"
,
realPath
);
Long
attachId
=
attachService
.
saveFileInfo
(
originalFilename
,
realPath
,
uploadType
);
log
.
info
(
"保存成功,文件id:{}"
,
attachId
);
return
Result
.
success
(
attachId
);
}
}
system/system-admin-service/src/main/java/com/hungraim/ltc/system/dao/ChFndAttachMapper.java
0 → 100644
View file @
a04876b7
package
com
.
hungraim
.
ltc
.
system
.
dao
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.hungraim.ltc.pojo.entity.SysConfig.ChFndAttach
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.springframework.stereotype.Repository
;
@Mapper
@Repository
public
interface
ChFndAttachMapper
extends
BaseMapper
<
ChFndAttach
>
{
}
\ No newline at end of file
system/system-admin-service/src/main/java/com/hungraim/ltc/system/service/AttachService.java
0 → 100644
View file @
a04876b7
package
com
.
hungraim
.
ltc
.
system
.
service
;
public
interface
AttachService
{
/**
* 保存上传文件的文件信息
*
* @param originalFilename 源文件名称
* @param realPath 上传的真实路径
* @param attachType 附件类型
* @return 返回保存后的文件id
*/
Long
saveFileInfo
(
String
originalFilename
,
String
realPath
,
Short
attachType
);
}
system/system-admin-service/src/main/java/com/hungraim/ltc/system/service/impl/AttachServiceImpl.java
0 → 100644
View file @
a04876b7
package
com
.
hungraim
.
ltc
.
system
.
service
.
impl
;
import
com.hungraim.ltc.pojo.entity.SysConfig.ChFndAttach
;
import
com.hungraim.ltc.system.dao.ChFndAttachMapper
;
import
com.hungraim.ltc.system.service.AttachService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.Date
;
@Service
public
class
AttachServiceImpl
implements
AttachService
{
@Autowired
private
ChFndAttachMapper
chFndAttachMapper
;
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Override
public
Long
saveFileInfo
(
String
originalFilename
,
String
realPath
,
Short
attachType
)
{
ChFndAttach
chFndAttach
=
new
ChFndAttach
();
chFndAttach
.
setFileName
(
originalFilename
);
chFndAttach
.
setFilePath
(
realPath
);
chFndAttach
.
setFileTime
(
new
Date
());
chFndAttach
.
setAttachType
(
attachType
);
chFndAttach
.
setStatus
((
short
)
0
);
chFndAttachMapper
.
insert
(
chFndAttach
);
return
chFndAttach
.
getAttachId
();
}
}
system/system-admin-service/src/main/resources/mapper/ChFndAttachMapper.xml
0 → 100644
View file @
a04876b7
<?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=
"com.hungraim.ltc.system.dao.ChFndAttachMapper"
>
<resultMap
id=
"BaseResultMap"
type=
"com.hungraim.ltc.pojo.entity.SysConfig.ChFndAttach"
>
<id
column=
"ATTACH_ID"
jdbcType=
"DECIMAL"
property=
"attachId"
/>
<result
column=
"FILE_NAME"
jdbcType=
"VARCHAR"
property=
"fileName"
/>
<result
column=
"FILE_PATH"
jdbcType=
"VARCHAR"
property=
"filePath"
/>
<result
column=
"FILE_TIME"
jdbcType=
"TIMESTAMP"
property=
"fileTime"
/>
<result
column=
"CTRL_ID"
jdbcType=
"DECIMAL"
property=
"ctrlId"
/>
<result
column=
"ATTACH_TYPE"
jdbcType=
"DECIMAL"
property=
"attachType"
/>
<result
column=
"FCD"
jdbcType=
"TIMESTAMP"
property=
"fcd"
/>
<result
column=
"FCU"
jdbcType=
"DECIMAL"
property=
"fcu"
/>
<result
column=
"DOC_TYPE"
jdbcType=
"DECIMAL"
property=
"docType"
/>
<result
column=
"STATUS"
jdbcType=
"DECIMAL"
property=
"status"
/>
</resultMap>
<sql
id=
"Base_Column_List"
>
ATTACH_ID, FILE_NAME, FILE_PATH, FILE_TIME, CTRL_ID, ATTACH_TYPE, FCD, FCU, DOC_TYPE,
"STATUS"
</sql>
</mapper>
\ No newline at end of file
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