|
|
|
@ -15,6 +15,7 @@ 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 com.mchange.lang.IntegerUtils;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
@ -61,7 +62,7 @@ public class SysFileServiceImpl implements ISysFileService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sysFileRDao.insert(sysFile);
|
|
|
|
|
return sysFileRDao.save(sysFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -127,18 +128,49 @@ public class SysFileServiceImpl implements ISysFileService {
|
|
|
|
|
@Override
|
|
|
|
|
@ApiOperation(value = "上传文件资源", notes = "上传文件资源")
|
|
|
|
|
public SysFile uploadFile(Object file) throws Exception {
|
|
|
|
|
SysFile sysFile = uploadFastDfs(file, null);
|
|
|
|
|
return insertSysFile(sysFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@ApiOperation(value = "上传文件资源", notes = "上传文件资源")
|
|
|
|
|
public SysFile uploadFile(Object file,SysFile sysFile) throws Exception {
|
|
|
|
|
sysFile = uploadFastDfs(file, sysFile);
|
|
|
|
|
return insertSysFile(sysFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 上传文件至fastdfs
|
|
|
|
|
* @param file
|
|
|
|
|
* @param sysFile
|
|
|
|
|
* @return
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
private SysFile uploadFastDfs(Object file,SysFile sysFile) throws Exception {
|
|
|
|
|
if(sysFile == null){
|
|
|
|
|
sysFile = new SysFile();
|
|
|
|
|
}
|
|
|
|
|
// 设置文件默认所属模块
|
|
|
|
|
if(sysFile.getFileSoftTypeVal() == 0){
|
|
|
|
|
sysFile.setFileSoftType(CommonEnumUtil.SOFT_TYPE.CORE.getValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FastDFSFile fastDFSFile;
|
|
|
|
|
SysFile uploadFile;
|
|
|
|
|
// 判断参数类型
|
|
|
|
|
if (file instanceof File) {
|
|
|
|
|
fastDFSFile = new FastDFSFile((( File ) file).getName(), FileTool.file2Byte((( File ) file).getPath()),
|
|
|
|
|
StringTool.getStringFileSuffix((( File ) file).getName(), true));
|
|
|
|
|
fastDFSFile = new FastDFSFile(((File) file).getName(), FileTool.file2Byte(((File) file).getPath()),
|
|
|
|
|
StringTool.getStringFileSuffix(((File) file).getName(), true));
|
|
|
|
|
uploadFile = dfsClient.upload(fastDFSFile, sysFile.getFileSoftTypeVal());
|
|
|
|
|
} else {
|
|
|
|
|
fastDFSFile = dfsClient.saveFile(( MultipartFile ) file);
|
|
|
|
|
uploadFile = dfsClient.saveFile((MultipartFile) file, sysFile.getFileSoftTypeVal());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SysFile sysFile = dfsClient.upload(fastDFSFile,CommonEnumUtil.SOFT_TYPE.CORE.getValue());
|
|
|
|
|
uploadFile.setId(sysFile.getId());
|
|
|
|
|
// 设置文件代码
|
|
|
|
|
uploadFile.setFileCode(sysFile.getFileCode());
|
|
|
|
|
|
|
|
|
|
return insertSysFile(sysFile);
|
|
|
|
|
return uploadFile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|