use of org.jeecg.modules.KM.entity.KmFile in project kms by mahonelau.
the class KmDocController method uploadDoc.
@AutoLog(value = "km_doc-文件上传")
@ApiOperation(value = "km_doc-文件上传", notes = "km_doc-文件上传")
@PostMapping("/uploadDoc")
@ResponseBody
public Result<?> uploadDoc(@RequestParam(value = "file") MultipartFile file, HttpServletRequest req) {
try {
if (!commonConstant.isFileTypeSupport(StringUtils.getFileSuffix(file.getOriginalFilename()))) {
return Result.error("不支持的文件格式");
}
KmFile dupFile = kmFileService.getKmFileBySha256(HashUtil.sha256(file.getInputStream()));
if (dupFile != null) {
return Result.error("该文件已经存在无需重复上传,源文件:" + dupFile.getOriginalName());
}
KmFile kmFile = kmFileService.saveFile(file);
KmDoc kmDoc = kmDocService.saveDoc(kmFile);
kmDocService.indexDocSync(kmDoc);
kmDocVisitRecordService.logVisit(kmDoc.getId(), IpUtils.getIpAddr(req), DocVisitTypeEnum.Upload.getCode());
} catch (Exception e) {
log.error("uploadDoc", e);
return Result.error(e.getMessage());
}
return Result.OK();
}
use of org.jeecg.modules.KM.entity.KmFile in project kms by mahonelau.
the class KmFileServiceImpl method saveFile.
@Override
public KmFile saveFile(MultipartFile file) {
try {
File todayDir = baseConfig.getTodayUploadDir();
String fileId = UUIDGenerator.generate();
String suffix = StringUtils.getFileSuffix(file.getOriginalFilename());
File dist = new File(todayDir, fileId + "." + suffix);
file.transferTo(dist);
KmFile kmFile = new KmFile();
kmFile.setId(fileId);
kmFile.setOriginalName(file.getOriginalFilename());
kmFile.setPhysicalPath(baseConfig.getRelativePath(dist));
kmFile.setSha256(HashUtil.sha256(dist));
baseMapper.insert(kmFile);
return kmFile;
} catch (IOException e) {
logger.error("文件上传transferTo错误", e);
}
return null;
}
use of org.jeecg.modules.KM.entity.KmFile in project kms by mahonelau.
the class KmFileServiceImpl method saveFile.
@Override
public KmFile saveFile(String content, String suffix) {
try {
File todayDir = baseConfig.getTodayUploadDir();
String fileId = UUIDGenerator.generate();
// String suffix=StringUtils.getFileSuffix(file.getOriginalFilename());
File dist = new File(todayDir, fileId + "." + suffix);
FileUtils.writeStringToFile(dist, content, "utf-8");
KmFile KmFile = new KmFile();
KmFile.setId(fileId);
KmFile.setOriginalName("");
KmFile.setPhysicalPath(baseConfig.getRelativePath(dist));
// KmFile.setUrl(""); //下载路径,待定
KmFile.setSha256(HashUtil.sha256(dist));
baseMapper.insert(KmFile);
return KmFile;
} catch (IOException e) {
logger.error("文件上传transferTo错误", e);
}
return null;
}
use of org.jeecg.modules.KM.entity.KmFile in project kms by mahonelau.
the class KmFileServiceImpl method deleteKmFile.
@Override
public boolean deleteKmFile(String fileId) {
KmFile KmFile = getKmFile(fileId);
if (KmFile != null) {
String filePath = KmFile.getPhysicalPath();
File f = new File(filePath);
if (f.exists()) {
f.delete();
}
super.removeById(fileId);
return true;
} else {
return false;
}
}
use of org.jeecg.modules.KM.entity.KmFile in project kykms by mahonelau.
the class KmFileServiceImpl method deleteKmFile.
@Override
public boolean deleteKmFile(String fileId) {
KmFile KmFile = getKmFile(fileId);
if (KmFile != null) {
String filePath = KmFile.getPhysicalPath();
File f = new File(baseConfig.getUploadDir(), filePath);
if (f.exists()) {
f.delete();
}
super.removeById(fileId);
return true;
} else {
return false;
}
}
Aggregations