Search in sources :

Example 1 with KmFile

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();
}
Also used : KmFile(org.jeecg.modules.KM.entity.KmFile) KmDoc(org.jeecg.modules.KM.entity.KmDoc) ParseException(java.text.ParseException) AutoLog(org.jeecg.common.aspect.annotation.AutoLog) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with KmFile

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;
}
Also used : KmFile(org.jeecg.modules.KM.entity.KmFile) IOException(java.io.IOException) KmFile(org.jeecg.modules.KM.entity.KmFile) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile)

Example 3 with KmFile

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;
}
Also used : KmFile(org.jeecg.modules.KM.entity.KmFile) IOException(java.io.IOException) KmFile(org.jeecg.modules.KM.entity.KmFile) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile)

Example 4 with KmFile

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;
    }
}
Also used : KmFile(org.jeecg.modules.KM.entity.KmFile) KmFile(org.jeecg.modules.KM.entity.KmFile) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile)

Example 5 with KmFile

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;
    }
}
Also used : KmFile(org.jeecg.modules.KM.entity.KmFile) KmFile(org.jeecg.modules.KM.entity.KmFile) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile)

Aggregations

KmFile (org.jeecg.modules.KM.entity.KmFile)14 File (java.io.File)8 IOException (java.io.IOException)8 MultipartFile (org.springframework.web.multipart.MultipartFile)8 ApiOperation (io.swagger.annotations.ApiOperation)4 ParseException (java.text.ParseException)4 AutoLog (org.jeecg.common.aspect.annotation.AutoLog)4 KmDoc (org.jeecg.modules.KM.entity.KmDoc)4