|
|
|
@ -1,18 +1,24 @@
|
|
|
|
|
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.convert.ConvertBean;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.StringTool;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.ListPager;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.common.Pager;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SessionUser;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysDictionary;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysFile;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysMessage;
|
|
|
|
|
import cn.estsh.impp.framework.boot.auth.AuthUtil;
|
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
|
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppExceptionEnum;
|
|
|
|
|
import cn.estsh.impp.framework.boot.fastdfs.FastDFSClient;
|
|
|
|
|
import cn.estsh.impp.framework.boot.fastdfs.FastDFSFile;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.ResultBean;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.ValidatorBean;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
@ -21,7 +27,10 @@ import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -40,30 +49,11 @@ public class SysFileController {
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISysFileService sysFileService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISysDictionaryService dictionaryService;
|
|
|
|
|
|
|
|
|
|
@PostMapping(value = "/insert")
|
|
|
|
|
@ApiOperation(value = "添加文件资源",notes = "添加文件资源")
|
|
|
|
|
public ResultBean insertSysFile(SysFile sysFile){
|
|
|
|
|
try {
|
|
|
|
|
// 登录用户
|
|
|
|
|
SessionUser user = AuthUtil.getSessionUser();
|
|
|
|
|
|
|
|
|
|
// 条件校验
|
|
|
|
|
ValidatorBean.beginValid(sysFile).notNull("name",sysFile.getName());
|
|
|
|
|
|
|
|
|
|
// 添加初始化
|
|
|
|
|
ConvertBean.modelInitialize(sysFile,user);
|
|
|
|
|
|
|
|
|
|
sysFileService.insertSysFile(sysFile);
|
|
|
|
|
return ResultBean.success("添加成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
|
}catch(ImppBusiException busExcep){
|
|
|
|
|
LOGGER.error(busExcep.getErrorMsg() + ":{}",busExcep.getErrorDetail(),busExcep);
|
|
|
|
|
return ResultBean.fail(busExcep.getErrorShow());
|
|
|
|
|
}catch(Exception e){
|
|
|
|
|
LOGGER.error(ImppExceptionEnum.SYSTEM_EXCEPTION.getDescription() + ":{}",e.getMessage(),e);
|
|
|
|
|
return ResultBean.fail().setCode(ImppExceptionEnum.SYSTEM_EXCEPTION.getCode());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@Autowired
|
|
|
|
|
private FastDFSClient dfsClient;
|
|
|
|
|
|
|
|
|
|
@PutMapping(value = "/update")
|
|
|
|
|
@ApiOperation(value = "修改文件资源",notes = "修改文件资源")
|
|
|
|
@ -122,7 +112,7 @@ public class SysFileController {
|
|
|
|
|
@ApiOperation(value = "根据id查询文件资源",notes = "根据id查询文件资源")
|
|
|
|
|
public ResultBean getSysFileById(@PathVariable("id") String id){
|
|
|
|
|
try {
|
|
|
|
|
SysFile sysFile = sysFileService.getSysFileById(id);
|
|
|
|
|
SysFile sysFile = sysFileService.getSysFileById(Long.parseLong(id));
|
|
|
|
|
return ResultBean.success("查询成功")
|
|
|
|
|
.setResultObject(sysFile)
|
|
|
|
|
.setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
@ -173,6 +163,53 @@ public class SysFileController {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************** 对文件操作 ******************/
|
|
|
|
|
@PostMapping("/upload")
|
|
|
|
|
@ApiOperation(value = "文件上传",notes = "文件上传")
|
|
|
|
|
public ResultBean singleFileUpload(@RequestParam("file") MultipartFile file, RedirectAttributes redirectAttributes) {
|
|
|
|
|
try {
|
|
|
|
|
if(file.isEmpty()){
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
|
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
|
|
|
|
|
.setErrorDetail("请选择需要上传的文件。")
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean checkFileN = dictionaryService.checkFileName(file.getOriginalFilename());
|
|
|
|
|
if(!checkFileN){
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
|
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION_FORMAT.getCode())
|
|
|
|
|
.setErrorDetail("文件格式不支持")
|
|
|
|
|
.setErrorSolution("请到字典管理中添加文件类型")
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FastDFSFile dfsFile = dfsClient.saveFile(file);
|
|
|
|
|
String filePath = dfsClient.getHostUi() + "/" + dfsFile.getDfsGroupName() + "/" + dfsFile.getDfsFileName();
|
|
|
|
|
SysDictionary dictionary = dictionaryService.getSysDictionaryByParentCodeAndCode(
|
|
|
|
|
CommonConstWords.DICTIONARY_FILE_TYPE,
|
|
|
|
|
StringTool.getStringFileSuffix(file.getOriginalFilename(),false));
|
|
|
|
|
|
|
|
|
|
SysFile sysFile = new SysFile();
|
|
|
|
|
sysFile.setDfsGroupName(dfsFile.getDfsGroupName());
|
|
|
|
|
sysFile.setDfsFileName(dfsFile.getDfsFileName());
|
|
|
|
|
sysFile.setFileSize(dfsFile.getContent().length);
|
|
|
|
|
sysFile.setFilePath(filePath);
|
|
|
|
|
sysFile.setFileOriginalName(file.getOriginalFilename());
|
|
|
|
|
sysFile.setFileTypeId(dictionary.getId());
|
|
|
|
|
sysFile.setFileTypeName(dictionary.getName());
|
|
|
|
|
|
|
|
|
|
SysFile fileDb = sysFileService.insertSysFile(sysFile);
|
|
|
|
|
|
|
|
|
|
return ResultBean.success("上传成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultObject(fileDb);
|
|
|
|
|
}catch(ImppBusiException busExcep){
|
|
|
|
|
LOGGER.error(busExcep.getErrorMsg() + ":{}",busExcep.getErrorDetail(),busExcep);
|
|
|
|
|
return ResultBean.fail(busExcep.getErrorShow());
|
|
|
|
|
}catch(Exception e){
|
|
|
|
|
LOGGER.error(ImppExceptionEnum.SYSTEM_EXCEPTION.getDescription() + ":{}",e.getMessage(),e);
|
|
|
|
|
return ResultBean.fail().setCode(ImppExceptionEnum.SYSTEM_EXCEPTION.getCode());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|