10 changed files with 276 additions and 105 deletions
@ -0,0 +1,72 @@ |
|||||
|
package com.win.module.eam.job; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.win.framework.common.exception.ErrorCode; |
||||
|
import com.win.framework.common.exception.util.ServiceExceptionUtil; |
||||
|
import com.win.framework.mybatis.core.dataobject.BaseDO; |
||||
|
import com.win.framework.quartz.core.handler.JobHandler; |
||||
|
import com.win.module.eam.dal.dataobject.attachmentfile.AttachmentFileDO; |
||||
|
import com.win.module.eam.dal.mysql.attachmentfile.AttachmentFileMapper; |
||||
|
import com.win.module.eam.job.vo.DeleteFileVO; |
||||
|
import com.win.module.eam.service.common.DeleteFileService; |
||||
|
import com.win.module.infra.service.file.FileService; |
||||
|
import com.win.module.system.util.StringUtils; |
||||
|
import org.apache.commons.lang3.exception.ExceptionUtils; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
import java.util.List; |
||||
|
|
||||
|
@Component |
||||
|
public class DeleteFileJob implements JobHandler { |
||||
|
|
||||
|
@Resource |
||||
|
private List<DeleteFileService> list; |
||||
|
@Resource |
||||
|
private AttachmentFileMapper attachmentFileMapper; |
||||
|
@Resource |
||||
|
private FileService fileService; |
||||
|
|
||||
|
@Override |
||||
|
public String execute(String param) throws Exception { |
||||
|
list.forEach(item -> { |
||||
|
DeleteFileVO<?> deleteVO = item.findeDeleteFileVO(); |
||||
|
deleteFile(deleteVO); |
||||
|
}); |
||||
|
return "删除成功"; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public <T extends BaseDO> void deleteFile(DeleteFileVO<T> vo) { |
||||
|
if (vo == null) { |
||||
|
return; |
||||
|
} |
||||
|
List<?> ids = vo.getIds(); |
||||
|
DeleteFileVO<?> subVO = vo.getSubVO(); |
||||
|
deleteFile(subVO); |
||||
|
String funcCode = subVO.getFuncCode(); |
||||
|
if (StringUtils.isNotBlank(funcCode)) { |
||||
|
List<AttachmentFileDO> attachmentFileDOS = attachmentFileMapper.selectList( |
||||
|
new LambdaQueryWrapper<AttachmentFileDO>() |
||||
|
.eq(AttachmentFileDO::getFuncCode, funcCode) |
||||
|
.in(AttachmentFileDO::getNumber, vo.getNumberList())); |
||||
|
for (AttachmentFileDO attachmentFileDO : attachmentFileDOS) { |
||||
|
try { |
||||
|
fileService.deleteFile(attachmentFileDO.getId()); |
||||
|
} catch (Exception e) { |
||||
|
ServiceExceptionUtil.exception(new ErrorCode(50001, String.format("删除文件失败:%s", ExceptionUtils.getStackTrace(e)))); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
BaseMapper<T> baseMapper = vo.getBaseMapper(); |
||||
|
UpdateWrapper<T> updateWrapper = new UpdateWrapper<>(); |
||||
|
updateWrapper.in("id", ids); |
||||
|
updateWrapper.set("is_file_delete", 1); |
||||
|
baseMapper.update(null, updateWrapper); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,16 @@ |
|||||
|
package com.win.module.eam.job.vo; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.win.framework.mybatis.core.dataobject.BaseDO; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
@Data |
||||
|
public class DeleteFileVO<T extends BaseDO> { |
||||
|
private List<?> ids; |
||||
|
private List<?> numberList; |
||||
|
private BaseMapper<T> baseMapper; |
||||
|
private String funcCode; |
||||
|
private DeleteFileVO<?> subVO; |
||||
|
} |
@ -0,0 +1,9 @@ |
|||||
|
package com.win.module.eam.service.common; |
||||
|
|
||||
|
import com.win.framework.mybatis.core.dataobject.BaseDO; |
||||
|
import com.win.module.eam.job.vo.DeleteFileVO; |
||||
|
|
||||
|
public interface DeleteFileService { |
||||
|
|
||||
|
<T extends BaseDO> DeleteFileVO<T> findeDeleteFileVO(); |
||||
|
} |
Loading…
Reference in new issue