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);
}
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);
}
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("上传文件失败");
}
}
Aggregations