Search in sources :

Example 1 with SysFilesEntity

use of com.jun.plugin.system.entity.SysFilesEntity in project jun_springboot_api_service by wujun728.

the class SysFilesController method findListByPage.

@ApiOperation(value = "查询分页数据")
@PostMapping("/listByPage")
@RequiresPermissions("sysFiles:list")
public DataResult findListByPage(@RequestBody SysFilesEntity sysFiles) {
    Page page = new Page(sysFiles.getPage(), sysFiles.getLimit());
    IPage<SysFilesEntity> iPage = sysFilesService.page(page, Wrappers.<SysFilesEntity>lambdaQuery().orderByDesc(SysFilesEntity::getCreateDate));
    return DataResult.success(iPage);
}
Also used : Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) SysFilesEntity(com.jun.plugin.system.entity.SysFilesEntity) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with SysFilesEntity

use of com.jun.plugin.system.entity.SysFilesEntity in project jun_springboot_api_service by wujun728.

the class SysFilesServiceImpl method removeByIdsAndFiles.

@Override
public void removeByIdsAndFiles(List<String> ids) {
    List<SysFilesEntity> list = this.listByIds(ids);
    list.forEach(entity -> {
        // 如果之前的文件存在,删除
        File file = new File(entity.getFilePath());
        if (file.exists()) {
            file.delete();
        }
    });
    this.removeByIds(ids);
}
Also used : SysFilesEntity(com.jun.plugin.system.entity.SysFilesEntity) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile)

Example 3 with SysFilesEntity

use of com.jun.plugin.system.entity.SysFilesEntity in project jun_springboot_api_service by wujun728.

the class SysFilesServiceImpl method saveFile.

@Override
public DataResult saveFile(MultipartFile file) {
    // 存储文件夹
    String createTime = DateUtils.format(new Date(), DateUtils.DATEPATTERN);
    String newPath = fileUploadProperties.getPath() + createTime + File.separator;
    File uploadDirectory = new File(newPath);
    if (uploadDirectory.exists()) {
        if (!uploadDirectory.isDirectory()) {
            uploadDirectory.delete();
        }
    } else {
        uploadDirectory.mkdir();
    }
    try {
        String fileName = file.getOriginalFilename();
        // id与filename保持一直,删除文件
        String fileNameNew = UUID.randomUUID().toString().replace("-", "") + getFileType(fileName);
        String newFilePathName = newPath + fileNameNew;
        String url = fileUploadProperties.getUrl() + "/" + createTime + "/" + fileNameNew;
        // 创建输出文件对象
        File outFile = new File(newFilePathName);
        // 拷贝文件到输出文件对象
        FileUtils.copyInputStreamToFile(file.getInputStream(), outFile);
        // 保存文件记录
        SysFilesEntity sysFilesEntity = new SysFilesEntity();
        sysFilesEntity.setFileName(fileName);
        sysFilesEntity.setFilePath(newFilePathName);
        sysFilesEntity.setUrl(url);
        this.save(sysFilesEntity);
        Map<String, String> resultMap = new HashMap<>();
        resultMap.put("src", url);
        return DataResult.success(resultMap);
    } catch (Exception e) {
        throw new BusinessException("上传文件失败");
    }
}
Also used : BusinessException(com.jun.plugin.system.common.exception.BusinessException) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) SysFilesEntity(com.jun.plugin.system.entity.SysFilesEntity) BusinessException(com.jun.plugin.system.common.exception.BusinessException)

Aggregations

SysFilesEntity (com.jun.plugin.system.entity.SysFilesEntity)3 File (java.io.File)2 MultipartFile (org.springframework.web.multipart.MultipartFile)2 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 BusinessException (com.jun.plugin.system.common.exception.BusinessException)1 ApiOperation (io.swagger.annotations.ApiOperation)1 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)1