|
|
|
@ -3,7 +3,6 @@ package cn.estsh.i3plus.core.apiservice.controller.busi;
|
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysDictionaryService;
|
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysFileService;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.StringTool;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.BaseConstWords;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.ListPager;
|
|
|
|
@ -26,7 +25,6 @@ import org.slf4j.LoggerFactory;
|
|
|
|
|
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.BufferedInputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
@ -57,13 +55,14 @@ public class SysFileController extends CoreBaseController{
|
|
|
|
|
private FastDFSClient dfsClient;
|
|
|
|
|
|
|
|
|
|
@PutMapping(value = "/update")
|
|
|
|
|
@ApiOperation(value = "修改文件资源",notes = "修改文件资源")
|
|
|
|
|
@ApiOperation(value = "修改文件资源", notes = "修改文件资源")
|
|
|
|
|
public ResultBean updateSysFile(SysFile sysFile){
|
|
|
|
|
try {
|
|
|
|
|
// 条件验证
|
|
|
|
|
ValidatorBean.beginValid(sysFile)
|
|
|
|
|
.notNull("id",sysFile.getId())
|
|
|
|
|
.notNull("name",sysFile.getName());
|
|
|
|
|
.notNull("id", sysFile.getId())
|
|
|
|
|
.notNull("fileSoftType", sysFile.getFileSoftType())
|
|
|
|
|
.notNull("name", sysFile.getName());
|
|
|
|
|
|
|
|
|
|
sysFileService.updateSysFile(sysFile);
|
|
|
|
|
return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
@ -75,10 +74,18 @@ public class SysFileController extends CoreBaseController{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@DeleteMapping(value = "/delete/{id}")
|
|
|
|
|
@ApiOperation(value = "根据id删除文件资源",notes = "根据id删除文件资源")
|
|
|
|
|
public ResultBean deleteSysFileById(@PathVariable("id") String id){
|
|
|
|
|
@ApiOperation(value = "根据id删除文件资源", notes = "根据id删除文件资源")
|
|
|
|
|
public ResultBean deleteSysFileById(@PathVariable("id") String idStr){
|
|
|
|
|
try {
|
|
|
|
|
sysFileService.deleteSysFileById(Long.parseLong(id));
|
|
|
|
|
ValidatorBean.checkNotNull(idStr, "id不能为空");
|
|
|
|
|
SysFile sysFile = sysFileService.getSysFileById(Long.parseLong(idStr));
|
|
|
|
|
ValidatorBean.checkNotNull(sysFile, "文件信息不存在");
|
|
|
|
|
|
|
|
|
|
LOGGER.info("FastDFS删除文件 == groupName: {},name:{}", sysFile.getDfsGroupName(), sysFile.getDfsFileName());
|
|
|
|
|
dfsClient.deleteFile(sysFile.getDfsGroupName(), sysFile.getDfsFileName());
|
|
|
|
|
|
|
|
|
|
sysFileService.deleteSysFileById(Long.parseLong(idStr));
|
|
|
|
|
|
|
|
|
|
return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
|
}catch(ImppBusiException busExcep){
|
|
|
|
|
return ResultBean.fail(busExcep);
|
|
|
|
@ -88,7 +95,7 @@ public class SysFileController extends CoreBaseController{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping(value = "/list")
|
|
|
|
|
@ApiOperation(value = "查询全部文件资源",notes = "查询全部文件资源")
|
|
|
|
|
@ApiOperation(value = "查询全部文件资源", notes = "查询全部文件资源")
|
|
|
|
|
public ResultBean findSysFileAll(SysFile sysFile){
|
|
|
|
|
try {
|
|
|
|
|
List<SysFile> sysFileList = sysFileService.listSysFile();
|
|
|
|
@ -103,12 +110,14 @@ public class SysFileController extends CoreBaseController{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping(value = "/get/{id}")
|
|
|
|
|
@ApiOperation(value = "根据id查询文件资源",notes = "根据id查询文件资源")
|
|
|
|
|
@ApiOperation(value = "根据id查询文件资源", notes = "根据id查询文件资源")
|
|
|
|
|
public ResultBean getSysFileById(@PathVariable("id") String id){
|
|
|
|
|
try {
|
|
|
|
|
ValidatorBean.checkIsNumber(id,"id必须为数字");
|
|
|
|
|
ValidatorBean.checkIsNumber(id, "id必须为数字");
|
|
|
|
|
|
|
|
|
|
SysFile sysFile = sysFileService.getSysFileById(Long.parseLong(id));
|
|
|
|
|
ValidatorBean.checkNotNull(sysFile, "文件信息不存在");
|
|
|
|
|
|
|
|
|
|
return ResultBean.success("操作成功")
|
|
|
|
|
.setResultObject(sysFile)
|
|
|
|
|
.setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
@ -120,10 +129,10 @@ public class SysFileController extends CoreBaseController{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping(value = "/query")
|
|
|
|
|
@ApiOperation(value = "文件资源复杂查询,分页,排序",notes = "文件资源复杂查询,分页,排序")
|
|
|
|
|
@ApiOperation(value = "文件资源复杂查询,分页,排序", notes = "文件资源复杂查询,分页,排序")
|
|
|
|
|
public ResultBean querySysFileByPager(SysFile sysFile, Pager pager){
|
|
|
|
|
try {
|
|
|
|
|
ListPager sysFileListPager = sysFileService.querySysFileByPager(sysFile,pager);
|
|
|
|
|
ListPager sysFileListPager = sysFileService.querySysFileByPager(sysFile, pager);
|
|
|
|
|
return ResultBean.success("操作成功").setListPager(sysFileListPager).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
|
}catch(ImppBusiException busExcep){
|
|
|
|
|
return ResultBean.fail(busExcep);
|
|
|
|
@ -133,7 +142,7 @@ public class SysFileController extends CoreBaseController{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@DeleteMapping(value = "/batch-delete")
|
|
|
|
|
@ApiOperation(value = "批量删除文件资源",notes = "批量删除文件资源")
|
|
|
|
|
@ApiOperation(value = "批量删除文件资源", notes = "批量删除文件资源")
|
|
|
|
|
public ResultBean deleteSysFileByIds(String[] ids){
|
|
|
|
|
try{
|
|
|
|
|
if(ids.length == 0){
|
|
|
|
@ -154,7 +163,7 @@ public class SysFileController extends CoreBaseController{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/upload")
|
|
|
|
|
@ApiOperation(value = "文件上传",notes = "文件上传")
|
|
|
|
|
@ApiOperation(value = "文件上传", notes = "文件上传")
|
|
|
|
|
public ResultBean singleFileUpload(@RequestParam("file") MultipartFile file) {
|
|
|
|
|
try {
|
|
|
|
|
if(file.isEmpty()){
|
|
|
|
@ -186,10 +195,10 @@ public class SysFileController extends CoreBaseController{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/download/{id}")
|
|
|
|
|
@ApiOperation(value = "文件下载",notes = "文件下载")
|
|
|
|
|
@ApiOperation(value = "文件下载", notes = "文件下载")
|
|
|
|
|
public ResultBean singleDownload(@PathVariable("id")String id, HttpServletResponse response) {
|
|
|
|
|
try {
|
|
|
|
|
ValidatorBean.checkIsNumber(id,"文件ID不能为空");
|
|
|
|
|
ValidatorBean.checkIsNumber(id, "文件ID不能为空");
|
|
|
|
|
|
|
|
|
|
SysFile sysFile = sysFileService.getSysFileById(Long.parseLong(id));
|
|
|
|
|
if(sysFile == null){
|
|
|
|
@ -210,22 +219,22 @@ public class SysFileController extends CoreBaseController{
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response.setContentType("application/force-download");// 设置强制下载不打开
|
|
|
|
|
response.addHeader("Content-Disposition", "attachment;fileName=" + sysFile.getFileOriginalName());// 设置文件名
|
|
|
|
|
response.addHeader("Content-type", "application/octet-stream");// 设置文件名
|
|
|
|
|
response.setContentType("application/force-download"); // 设置强制下载不打开
|
|
|
|
|
response.addHeader("Content-Disposition", "attachment;fileName=" + sysFile.getFileOriginalName()); // 设置文件名
|
|
|
|
|
response.addHeader("Content-type", "application/octet-stream"); // 设置文件名
|
|
|
|
|
|
|
|
|
|
BufferedInputStream bis = null;
|
|
|
|
|
try {
|
|
|
|
|
bis = new BufferedInputStream(fis);
|
|
|
|
|
OutputStream os = response.getOutputStream();
|
|
|
|
|
byte[] buffer = new byte[1024];
|
|
|
|
|
int i = bis.read(buffer);
|
|
|
|
|
while (i != -1) {
|
|
|
|
|
os.write(buffer, 0, i);
|
|
|
|
|
i = bis.read(buffer);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
try {
|
|
|
|
|
bis = new BufferedInputStream(fis);
|
|
|
|
|
OutputStream os = response.getOutputStream();
|
|
|
|
|
byte[] buffer = new byte[1024];
|
|
|
|
|
int i = bis.read(buffer);
|
|
|
|
|
while (i != -1) {
|
|
|
|
|
os.write(buffer, 0, i);
|
|
|
|
|
i = bis.read(buffer);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} finally {
|
|
|
|
|
if (bis != null) {
|
|
|
|
|
try {
|
|
|
|
@ -248,18 +257,19 @@ public class SysFileController extends CoreBaseController{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping(value = "/insert")
|
|
|
|
|
@ApiOperation(value = "新增文件资源",notes = "新增文件资源")
|
|
|
|
|
@ApiOperation(value = "新增文件资源", notes = "新增文件资源")
|
|
|
|
|
public ResultBean insertSysFile(@RequestBody SysFile sysFile){
|
|
|
|
|
try {
|
|
|
|
|
// 条件验证
|
|
|
|
|
ValidatorBean.beginValid(sysFile)
|
|
|
|
|
.notNull("dfsFileName",sysFile.getDfsFileName())
|
|
|
|
|
.notNull("dfsGroupName",sysFile.getDfsGroupName())
|
|
|
|
|
.notNull("fileOriginalName",sysFile.getFileOriginalName());
|
|
|
|
|
.notNull("dfsFileName", sysFile.getDfsFileName())
|
|
|
|
|
.notNull("dfsGroupName", sysFile.getDfsGroupName())
|
|
|
|
|
.notNull("fileSoftType", sysFile.getFileSoftType())
|
|
|
|
|
.notNull("fileOriginalName", sysFile.getFileOriginalName());
|
|
|
|
|
|
|
|
|
|
// 文件类型验证
|
|
|
|
|
SysDictionary dictionary = dictionaryService.getSysDictionaryByParentCodeAndCode(BaseConstWords.DICTIONARY_FILE_TYPE,
|
|
|
|
|
StringTool.getStringFileSuffix(sysFile.getFileOriginalName(),false));
|
|
|
|
|
StringTool.getStringFileSuffix(sysFile.getFileOriginalName(), false));
|
|
|
|
|
if(dictionary == null){
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
@ -282,4 +292,25 @@ public class SysFileController extends CoreBaseController{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 根据文件代码查询文件信息
|
|
|
|
|
* @param fileCode 文件代码
|
|
|
|
|
* @return 处理结果
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/get-file-code/{code}")
|
|
|
|
|
@ApiOperation(value = "根据文件代码查询文件信息")
|
|
|
|
|
public ResultBean getSysFileByFileCode(@PathVariable("code") String fileCode) {
|
|
|
|
|
try {
|
|
|
|
|
// 条件验证
|
|
|
|
|
ValidatorBean.checkNotNull(fileCode, "文件代码不能为空");
|
|
|
|
|
SysFile sysFile = sysFileService.getSysFileByFileCode(fileCode);
|
|
|
|
|
ValidatorBean.checkNotNull(sysFile, "文件信息不存在");
|
|
|
|
|
|
|
|
|
|
return ResultBean.success().setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultObject(sysFile);
|
|
|
|
|
}catch(ImppBusiException busExcep){
|
|
|
|
|
return ResultBean.fail(busExcep);
|
|
|
|
|
}catch(Exception e){
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|