|
@@ -18,6 +18,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.File;
|
|
@@ -158,4 +160,30 @@ public class FileManageServiceImpl implements FileManageService {
|
|
|
sysLogServices.save(sysLog);
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public boolean delete(Integer id) {
|
|
|
+ //删除磁盘文件
|
|
|
+ FileInfo fileInfo = fileManageMapper.selectById(id);
|
|
|
+ //DB删除
|
|
|
+ try {
|
|
|
+ int i = fileManageMapper.deleteById(fileInfo);
|
|
|
+ boolean b = false;
|
|
|
+ if (i==1) {
|
|
|
+ String path = localPath + fileInfo.getUrl().replaceFirst("/file/","");
|
|
|
+ b = Files.deleteIfExists(Paths.get(path));
|
|
|
+ if (!b){
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return b;
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|