Browse Source

优化图片删除代码

wrh 2 years ago
parent
commit
f91491502b

+ 4 - 2
nngkxxdp/src/main/java/com/example/nngkxxdp/service/impl/CanteenServiceImpl.java

@@ -166,8 +166,10 @@ public class CanteenServiceImpl implements CanteenService {
                             return SendUtil.send(false, ConstStr.UPDATEUSER_FAILED, "");
                         }
                         File oldFile = new File(location + sFile.getPath());
-                        if (!oldFile.delete()) {
-                            return SendUtil.send(false, ConstStr.UPDATEUSER_FAILED, "");
+                        if (oldFile.exists()) {
+                            if (!oldFile.delete()) {
+                                return SendUtil.send(false, ConstStr.UPDATEUSER_FAILED, "");
+                            }
                         }
                         newPicList.remove(s);
                     }

+ 8 - 4
nngkxxdp/src/main/java/com/example/nngkxxdp/service/impl/FoodServiceImpl.java

@@ -120,8 +120,10 @@ public class FoodServiceImpl implements FoodService {
                             return SendUtil.send(false, ConstStr.UPDATEUSER_FAILED, "");
                         }
                         File oldFile = new File(location + sFile.getPath());
-                        if (!oldFile.delete()) {
-                            return SendUtil.send(false, ConstStr.UPDATEUSER_FAILED, "");
+                        if (oldFile.exists()) {
+                            if (!oldFile.delete()) {
+                                return SendUtil.send(false, ConstStr.UPDATEUSER_FAILED, "");
+                            }
                         }
                         newPicList.remove(s);
                         i--;
@@ -218,8 +220,10 @@ public class FoodServiceImpl implements FoodService {
                     return SendUtil.send(false, ConstStr.DELETEUSER_FAILED, "");
                 }
                 File oldFile = new File(location + stringObjectMap.get("path"));
-                if (!oldFile.delete()) {
-                    return SendUtil.send(false, ConstStr.DELETEUSER_FAILED, "");
+                if (oldFile.exists()) {
+                    if (!oldFile.delete()) {
+                        return SendUtil.send(false, ConstStr.DELETEUSER_FAILED, "");
+                    }
                 }
             }
         }