Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fuzzBackEnd
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
钱炳权
fuzzBackEnd
Commits
fa5f986d
Commit
fa5f986d
authored
8 months ago
by
钱炳权
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
知识库完成,但下载文件存在问题
parent
c91b88f6
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
451 additions
and
0 deletions
+451
-0
KnowledgeBaseController.java
...ll/controller/dataController/KnowledgeBaseController.java
+67
-0
KnowledgeBaseFiles.java
...om/example/fuzzControll/domain/po/KnowledgeBaseFiles.java
+70
-0
KnowledgeBaseMapper.java
.../com/example/fuzzControll/mapper/KnowledgeBaseMapper.java
+17
-0
KnowledgeBaseService.java
...om/example/fuzzControll/service/KnowledgeBaseService.java
+15
-0
KnowledgeBaseServiceImpl.java
...e/fuzzControll/service/impl/KnowledgeBaseServiceImpl.java
+54
-0
TestMissionServiceImpl.java
...ple/fuzzControll/service/impl/TestMissionServiceImpl.java
+5
-0
KnowledgeBaseMapper.xml
...gration/src/main/resources/mapper/KnowledgeBaseMapper.xml
+29
-0
KnowledgeBaseController.java
...fuzzbackendmaster/controller/KnowledgeBaseController.java
+55
-0
KnowledgeBaseFiles.java
...example/fuzzbackendmaster/pojo/vo/KnowledgeBaseFiles.java
+70
-0
FileDownloadService.java
...xample/fuzzbackendmaster/service/FileDownloadService.java
+7
-0
FuzzIntegrationFileApi.java
...ple/fuzzbackendmaster/service/FuzzIntegrationFileApi.java
+15
-0
FileDownloadServiceImpl.java
...zzbackendmaster/service/impl/FileDownloadServiceImpl.java
+47
-0
No files found.
fuzzIntegration/src/main/java/com/example/fuzzControll/controller/dataController/KnowledgeBaseController.java
0 → 100644
View file @
fa5f986d
package
com
.
example
.
fuzzControll
.
controller
.
dataController
;
import
com.alibaba.fastjson.JSON
;
import
com.example.fuzzControll.domain.bo.FuzzLogTransEntity
;
import
com.example.fuzzControll.domain.po.KnowledgeBaseFiles
;
import
com.example.fuzzControll.domain.vo.AjaxResult
;
import
com.example.fuzzControll.exception.fileExcption.FileException
;
import
com.example.fuzzControll.exception.serverException.ServerException
;
import
com.example.fuzzControll.exception.testException.CmdException
;
import
com.example.fuzzControll.service.KnowledgeBaseService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.IOException
;
import
java.util.List
;
/**
* 知识库控制器
*/
@RestController
@RequestMapping
(
"/KnowledgeBase"
)
@Slf4j
public
class
KnowledgeBaseController
{
@Autowired
KnowledgeBaseService
knowledgeBaseService
;
/**
* 知识库文件上传、默认文件不是复合文件
*/
@RequestMapping
(
value
=
"/upload"
,
method
=
RequestMethod
.
POST
)
public
AjaxResult
upload
(
@RequestParam
(
"file"
)
MultipartFile
file
)
{
try
{
knowledgeBaseService
.
upload
(
file
);
return
AjaxResult
.
success
(
"文件上传成功!"
);
}
catch
(
ServerException
e
)
{
log
.
error
(
e
.
getDefaultMessage
());
return
AjaxResult
.
error
(
"文件上传失败!"
);
}
}
/**
* 知识库文件信息查看//todo有莫名其妙的错误
*/
@RequestMapping
(
value
=
"/getallmessage"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
getallmessage
()
{
try
{
return
AjaxResult
.
success
(
knowledgeBaseService
.
getAllMessage
());
}
catch
(
ServerException
e
)
{
log
.
error
(
e
.
getDefaultMessage
());
return
AjaxResult
.
error
(
"知识库信息获取失败!"
);
}
}
/**
* 跟据id获取知识库数据
*/
@RequestMapping
(
value
=
"/getById/{id}"
,
method
=
RequestMethod
.
GET
)
public
KnowledgeBaseFiles
getById
(
@PathVariable
(
"id"
)
int
id
)
{
try
{
return
knowledgeBaseService
.
getKnowledgeBaseFilesById
(
id
);
}
catch
(
ServerException
e
)
{
log
.
error
(
e
.
getDefaultMessage
());
return
null
;
}
}
}
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/domain/po/KnowledgeBaseFiles.java
0 → 100644
View file @
fa5f986d
package
com
.
example
.
fuzzControll
.
domain
.
po
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
lombok.Data
;
import
lombok.Getter
;
import
lombok.Setter
;
import
java.util.Date
;
/**
* 知识库类
*/
@Data
@Setter
@Getter
public
class
KnowledgeBaseFiles
{
private
int
id
;
@JsonIgnore
private
byte
[]
fileBytes
;
private
Date
createTime
;
private
String
fileName
;
public
KnowledgeBaseFiles
()
{
}
public
KnowledgeBaseFiles
(
int
id
,
byte
[]
fileBytes
,
Date
createTime
,
String
fileName
)
{
this
.
id
=
id
;
this
.
fileBytes
=
fileBytes
;
this
.
createTime
=
createTime
;
this
.
fileName
=
fileName
;
}
public
KnowledgeBaseFiles
(
byte
[]
fileBytes
,
Date
createTime
,
String
fileName
)
{
this
.
fileBytes
=
fileBytes
;
this
.
createTime
=
createTime
;
this
.
fileName
=
fileName
;
}
public
void
setId
(
int
id
)
{
this
.
id
=
id
;
}
public
void
setFileBytes
(
byte
[]
fileBytes
)
{
this
.
fileBytes
=
fileBytes
;
}
public
void
setCreateTime
(
Date
createTime
)
{
this
.
createTime
=
createTime
;
}
public
void
setFileName
(
String
fileName
)
{
this
.
fileName
=
fileName
;
}
public
int
getId
()
{
return
id
;
}
public
byte
[]
getFileBytes
()
{
return
fileBytes
;
}
public
Date
getCreateTime
()
{
return
createTime
;
}
public
String
getFileName
()
{
return
fileName
;
}
}
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/mapper/KnowledgeBaseMapper.java
0 → 100644
View file @
fa5f986d
package
com
.
example
.
fuzzControll
.
mapper
;
import
com.example.fuzzControll.domain.po.KnowledgeBaseFiles
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
@Mapper
@Component
(
"KnowledgeBaseMapper"
)
public
interface
KnowledgeBaseMapper
{
KnowledgeBaseFiles
getKnowledgeBaseFilesById
(
int
id
);
void
insert
(
KnowledgeBaseFiles
knowledgeBaseFiles
);
List
<
KnowledgeBaseFiles
>
getAllMessage
();
}
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/service/KnowledgeBaseService.java
0 → 100644
View file @
fa5f986d
package
com
.
example
.
fuzzControll
.
service
;
import
com.example.fuzzControll.domain.po.KnowledgeBaseFiles
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.util.List
;
public
interface
KnowledgeBaseService
{
void
upload
(
MultipartFile
file
);
List
<
KnowledgeBaseFiles
>
getAllMessage
();
KnowledgeBaseFiles
getKnowledgeBaseFilesById
(
int
id
);
}
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/service/impl/KnowledgeBaseServiceImpl.java
0 → 100644
View file @
fa5f986d
package
com
.
example
.
fuzzControll
.
service
.
impl
;
import
com.example.fuzzControll.domain.po.KnowledgeBaseFiles
;
import
com.example.fuzzControll.mapper.KnowledgeBaseMapper
;
import
com.example.fuzzControll.service.KnowledgeBaseService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.IOException
;
import
java.util.Date
;
import
java.util.List
;
@Service
(
"KnowledgeBaseService"
)
@Slf4j
public
class
KnowledgeBaseServiceImpl
implements
KnowledgeBaseService
{
@Autowired
KnowledgeBaseMapper
knowledgeBaseMapper
;
@Override
public
void
upload
(
MultipartFile
file
)
{
try
{
KnowledgeBaseFiles
knowledgeBaseFiles
=
new
KnowledgeBaseFiles
(
file
.
getBytes
(),
new
Date
(),
file
.
getOriginalFilename
());
knowledgeBaseMapper
.
insert
(
knowledgeBaseFiles
);
}
catch
(
IOException
e
)
{
log
.
error
(
"Creat and insert KnowledgeBaseFiles error:[{}] "
,
e
.
getMessage
());
throw
new
RuntimeException
(
e
);
}
}
@Override
public
List
<
KnowledgeBaseFiles
>
getAllMessage
()
{
try
{
return
knowledgeBaseMapper
.
getAllMessage
();
}
catch
(
Exception
e
)
{
log
.
error
(
"GetAllMessage error:[{}] "
,
e
.
getMessage
());
throw
new
RuntimeException
(
e
);
}
}
@Override
public
KnowledgeBaseFiles
getKnowledgeBaseFilesById
(
int
id
)
{
KnowledgeBaseFiles
knowledgeBaseFiles
=
null
;
try
{
knowledgeBaseFiles
=
knowledgeBaseMapper
.
getKnowledgeBaseFilesById
(
id
);
}
catch
(
Exception
e
)
{
log
.
error
(
"GetKnowledgeBaseFilesById error:[{}] "
,
e
.
getMessage
());
throw
new
RuntimeException
(
e
);
}
return
knowledgeBaseFiles
;
}
}
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/service/impl/TestMissionServiceImpl.java
View file @
fa5f986d
...
...
@@ -91,7 +91,12 @@ public class TestMissionServiceImpl implements TestMissionService {
@Override
public
void
insert
(
TestAndParams
testAndParams
)
{
Test
test
=
new
Test
(
new
Date
(),
new
Date
(),
testAndParams
.
getTestName
());
try
{
testMapper
.
insert
(
test
);
}
catch
(
Exception
e
)
{
log
.
error
(
"Insert error:{}"
,
e
.
getMessage
());
throw
new
RuntimeException
(
e
);
}
}
@Transactional
(
rollbackFor
=
MysqlException
.
class
)
...
...
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/resources/mapper/KnowledgeBaseMapper.xml
0 → 100644
View file @
fa5f986d
<?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.example.fuzzControll.mapper.KnowledgeBaseMapper"
>
<resultMap
type=
"com.example.fuzzControll.domain.po.KnowledgeBaseFiles"
id=
"KnowledgeBaseFiles"
>
<result
property=
"id"
column=
"id"
/>
<result
property=
"fileBytes"
column=
"fileBytes"
/>
<result
property=
"fileName"
column=
"fileName"
/>
<result
property=
"createTime"
column=
"createTime"
/>
</resultMap>
<sql
id=
"getAll"
>
select id,fileBytes,fileName,createTime from KnowledgeBase
</sql>
<insert
id=
"insert"
parameterType=
"com.example.fuzzControll.domain.po.KnowledgeBaseFiles"
>
insert into KnowledgeBase(fileBytes,fileName,createTime) values(#{fileBytes},#{fileName},#{createTime})
</insert>
<select
id=
"getAllMessage"
resultMap=
"KnowledgeBaseFiles"
>
<include
refid=
"getAll"
/>
</select>
<select
id=
"getKnowledgeBaseFilesById"
resultType=
"com.example.fuzzControll.domain.po.KnowledgeBaseFiles"
>
<include
refid=
"getAll"
/>
where id = #{id}
</select>
</mapper>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/controller/KnowledgeBaseController.java
0 → 100644
View file @
fa5f986d
package
com
.
example
.
fuzzbackendmaster
.
controller
;
import
com.alibaba.fastjson.JSON
;
import
com.example.fuzzbackendmaster.pojo.vo.AjaxResult
;
import
com.example.fuzzbackendmaster.pojo.vo.KnowledgeBaseFiles
;
import
com.example.fuzzbackendmaster.service.FileDownloadService
;
import
com.example.fuzzbackendmaster.service.FuzzIntegrationFileApi
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
/**
* 知识库控制器
*/
@RestController
@RequestMapping
(
"/KnowledgeBase"
)
@Slf4j
public
class
KnowledgeBaseController
{
@Autowired
FileDownloadService
fileDownloadService
;
@Autowired
FuzzIntegrationFileApi
fuzzIntegrationFileApi
;
/**
* 知识库文件上传、默认文件不是复合文件
*/
@RequestMapping
(
value
=
"/upload"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
upload
(
@RequestPart
(
"file"
)
MultipartFile
file
)
{
return
fuzzIntegrationFileApi
.
KnowledgeBaseUpload
(
file
);
}
/**
* 知识库文件信息查看
*/
@RequestMapping
(
value
=
"/getallmessage"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
getallmessage
()
{
return
fuzzIntegrationFileApi
.
getallmessage
();
}
/**
* 知识库文件下载
*/
//todo增加批量处理功能
@RequestMapping
(
value
=
"/download/{id}"
,
method
=
RequestMethod
.
GET
)
public
void
download
(
@PathVariable
(
"id"
)
int
id
,
HttpServletResponse
response
)
throws
IOException
{
try
{
fileDownloadService
.
getFile
(
id
,
response
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
response
.
sendError
(
500
,
"Download failed!"
);
}
}
//todo增加批量处理功能
}
This diff is collapsed.
Click to expand it.
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/pojo/vo/KnowledgeBaseFiles.java
0 → 100644
View file @
fa5f986d
package
com
.
example
.
fuzzbackendmaster
.
pojo
.
vo
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
lombok.Data
;
import
lombok.Getter
;
import
lombok.Setter
;
import
java.util.Date
;
/**
* 知识库类
*/
@Data
@Setter
@Getter
public
class
KnowledgeBaseFiles
{
private
int
id
;
@JsonIgnore
private
byte
[]
fileBytes
;
private
Date
createTime
;
private
String
fileName
;
public
KnowledgeBaseFiles
()
{
}
public
KnowledgeBaseFiles
(
int
id
,
byte
[]
fileBytes
,
Date
createTime
,
String
fileName
)
{
this
.
id
=
id
;
this
.
fileBytes
=
fileBytes
;
this
.
createTime
=
createTime
;
this
.
fileName
=
fileName
;
}
public
KnowledgeBaseFiles
(
byte
[]
fileBytes
,
Date
createTime
,
String
fileName
)
{
this
.
fileBytes
=
fileBytes
;
this
.
createTime
=
createTime
;
this
.
fileName
=
fileName
;
}
public
void
setId
(
int
id
)
{
this
.
id
=
id
;
}
public
void
setFileBytes
(
byte
[]
fileBytes
)
{
this
.
fileBytes
=
fileBytes
;
}
public
void
setCreateTime
(
Date
createTime
)
{
this
.
createTime
=
createTime
;
}
public
void
setFileName
(
String
fileName
)
{
this
.
fileName
=
fileName
;
}
public
int
getId
()
{
return
id
;
}
public
byte
[]
getFileBytes
()
{
return
fileBytes
;
}
public
Date
getCreateTime
()
{
return
createTime
;
}
public
String
getFileName
()
{
return
fileName
;
}
}
This diff is collapsed.
Click to expand it.
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/service/FileDownloadService.java
0 → 100644
View file @
fa5f986d
package
com
.
example
.
fuzzbackendmaster
.
service
;
import
javax.servlet.http.HttpServletResponse
;
public
interface
FileDownloadService
{
void
getFile
(
int
id
,
HttpServletResponse
response
);
}
This diff is collapsed.
Click to expand it.
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/service/FuzzIntegrationFileApi.java
View file @
fa5f986d
...
...
@@ -193,4 +193,19 @@ public interface FuzzIntegrationFileApi {
*/
@RequestMapping
(
value
=
"/mission/delMissionInfo"
,
method
=
RequestMethod
.
GET
)
AjaxResult
delMissionInfoById
(
@RequestParam
int
id
);
/**
*
* @param file
* @return
*/
@RequestMapping
(
value
=
"/KnowledgeBase/upload"
,
method
=
RequestMethod
.
POST
,
consumes
=
MediaType
.
MULTIPART_FORM_DATA_VALUE
)
AjaxResult
KnowledgeBaseUpload
(
@RequestPart
(
"file"
)
MultipartFile
file
);
@RequestMapping
(
value
=
"/KnowledgeBase/getallmessage"
,
method
=
RequestMethod
.
GET
)
AjaxResult
getallmessage
();
/**
* 获取文件二进制文件
*/
@RequestMapping
(
value
=
"/KnowledgeBase/getById/{id}"
,
method
=
RequestMethod
.
GET
)
KnowledgeBaseFiles
getKnowledgeBaseFilesBytes
(
@PathVariable
(
"id"
)
int
id
);
}
This diff is collapsed.
Click to expand it.
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/service/impl/FileDownloadServiceImpl.java
0 → 100644
View file @
fa5f986d
package
com
.
example
.
fuzzbackendmaster
.
service
.
impl
;
import
com.example.fuzzbackendmaster.pojo.vo.FuzzLogTransEntity
;
import
com.example.fuzzbackendmaster.pojo.vo.KnowledgeBaseFiles
;
import
com.example.fuzzbackendmaster.service.FileDownloadService
;
import
com.example.fuzzbackendmaster.service.FuzzIntegrationFileApi
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.OutputStream
;
import
java.util.List
;
@Service
@Slf4j
public
class
FileDownloadServiceImpl
implements
FileDownloadService
{
@Autowired
FuzzIntegrationFileApi
fuzzIntegrationFileApi
;
@Override
public
void
getFile
(
int
id
,
HttpServletResponse
response
)
{
KnowledgeBaseFiles
knowledgeBaseFiles
=
fuzzIntegrationFileApi
.
getKnowledgeBaseFilesBytes
(
id
);
if
(
knowledgeBaseFiles
==
null
||
knowledgeBaseFiles
.
getFileBytes
()
==
null
)
{
log
.
error
(
"File is null"
);
throw
new
IllegalStateException
();
}
downloadFile
(
knowledgeBaseFiles
.
getFileName
(),
knowledgeBaseFiles
.
getFileBytes
(),
response
);
}
/**
* 浏览器前端下载后台文件,文件为二进制格式
*/
public
void
downloadFile
(
String
fileName
,
byte
[]
file
,
HttpServletResponse
response
)
{
if
(
fileName
!=
null
&&
!
""
.
equals
(
fileName
))
{
if
(
file
!=
null
&&
file
.
length
!=
0
)
{
response
.
setContentType
(
"application/force-download"
);
// 设置强制下载不打开
response
.
addHeader
(
"Content-Disposition"
,
"attachment;fileName="
+
fileName
);
// 设置文件名
try
(
OutputStream
os
=
response
.
getOutputStream
();)
{
os
.
write
(
file
,
0
,
file
.
length
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
}
}
This diff is collapsed.
Click to expand it.
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