Search in sources :

Example 1 with FileDeleteCommand

use of com.whoiszxl.cqrs.command.FileDeleteCommand in project shopzz by whoiszxl.

the class AbstractFileStrategy method delete.

@Override
public boolean delete(List<FileDeleteCommand> commandList) {
    if (commandList.isEmpty()) {
        return true;
    }
    boolean flag = false;
    for (FileDeleteCommand fileDeleteCommand : commandList) {
        try {
            delete(fileDeleteCommand);
            flag = true;
        } catch (Exception e) {
            log.error("删除文件失败", e);
        }
    }
    return flag;
}
Also used : FileDeleteCommand(com.whoiszxl.cqrs.command.FileDeleteCommand)

Example 2 with FileDeleteCommand

use of com.whoiszxl.cqrs.command.FileDeleteCommand in project shopzz by whoiszxl.

the class FileServiceImpl method delete.

@Override
public void delete(Long[] ids) {
    if (ArrayUtils.isEmpty(ids)) {
        ExceptionCatcher.catchValidateEx(ResponseResult.buildError("传参无效"));
    }
    List<FmsFile> fileList = list(Wrappers.<FmsFile>lambdaQuery().in(FmsFile::getId, ids));
    if (fileList.isEmpty()) {
        ExceptionCatcher.catchValidateEx(ResponseResult.buildError("传参无效"));
    }
    removeByIds(Arrays.asList(ids));
    List<FileDeleteCommand> fileDeleteCommandList = fileList.stream().map(file -> {
        FileDeleteCommand deleteCommand = new FileDeleteCommand();
        deleteCommand.setRelativePath(file.getRelativePath());
        deleteCommand.setFinalFileName(file.getFinalFileName());
        deleteCommand.setId(file.getId());
        return deleteCommand;
    }).collect(Collectors.toList());
    fileStrategy.delete(fileDeleteCommandList);
}
Also used : ServiceImpl(com.baomidou.mybatisplus.extension.service.impl.ServiceImpl) Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) ResponseResult(com.whoiszxl.bean.ResponseResult) Arrays(java.util.Arrays) Autowired(org.springframework.beans.factory.annotation.Autowired) FileStrategy(com.whoiszxl.strategy.FileStrategy) ArrayUtils(org.apache.commons.lang3.ArrayUtils) FileDeleteCommand(com.whoiszxl.cqrs.command.FileDeleteCommand) Collectors(java.util.stream.Collectors) FileMapper(com.whoiszxl.mapper.FileMapper) List(java.util.List) FileService(com.whoiszxl.service.FileService) Service(org.springframework.stereotype.Service) ExceptionCatcher(com.whoiszxl.exception.ExceptionCatcher) MultipartFile(org.springframework.web.multipart.MultipartFile) FmsFile(com.whoiszxl.entity.FmsFile) FmsFile(com.whoiszxl.entity.FmsFile) FileDeleteCommand(com.whoiszxl.cqrs.command.FileDeleteCommand)

Aggregations

FileDeleteCommand (com.whoiszxl.cqrs.command.FileDeleteCommand)2 Wrappers (com.baomidou.mybatisplus.core.toolkit.Wrappers)1 ServiceImpl (com.baomidou.mybatisplus.extension.service.impl.ServiceImpl)1 ResponseResult (com.whoiszxl.bean.ResponseResult)1 FmsFile (com.whoiszxl.entity.FmsFile)1 ExceptionCatcher (com.whoiszxl.exception.ExceptionCatcher)1 FileMapper (com.whoiszxl.mapper.FileMapper)1 FileService (com.whoiszxl.service.FileService)1 FileStrategy (com.whoiszxl.strategy.FileStrategy)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ArrayUtils (org.apache.commons.lang3.ArrayUtils)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Service (org.springframework.stereotype.Service)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1