Browse Source

循环修改添加回滚

Newspaper 1 year ago
parent
commit
2bf29120b4

+ 4 - 1
admin/src/main/java/com/huimv/farm/damsubsidy/service/impl/BillBuyInfoServiceImpl.java

@@ -96,7 +96,10 @@ public class BillBuyInfoServiceImpl extends ServiceImpl<BillBuyInfoMapper, BillB
             baseAnimals.add(baseAnimal);
         }
         for (BaseAnimal baseAnimal : baseAnimals) {
-            baseAnimalMapper.updateById(baseAnimal);
+            if (baseAnimalMapper.updateById(baseAnimal) != 1) {
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                return new Result(10001,"操作失败",false);
+            }
         }
         String content3 = "";
         String content = uploadImage.getImageCom(image1);

+ 18 - 6
admin/src/main/java/com/huimv/farm/damsubsidy/service/impl/BillIsolatedServiceImpl.java

@@ -21,6 +21,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
 import org.springframework.util.StringUtils;
 import org.springframework.web.multipart.MultipartFile;
 import javax.annotation.Resource;
@@ -265,7 +266,7 @@ public class BillIsolatedServiceImpl extends ServiceImpl<BillIsolatedMapper, Bil
     }
 
     @Override
-    @Transactional
+    @Transactional(rollbackFor = RuntimeException.class)
     public Result cancelIsolation(HttpServletRequest httpServletRequest, MultipartFile image, String id, String isDead, String deaths) throws IOException {
         String content = uploadImage.getImageCom(image);
         BillIsolated isolation = this.getById(id);
@@ -287,8 +288,10 @@ public class BillIsolatedServiceImpl extends ServiceImpl<BillIsolatedMapper, Bil
                             return new Result(10001,"耳标号"+s+"不存在",false);
                         }
                         baseAnimal.setIsDie(1);
-                        //TODO 加回滚
-                        baseAnimalMapper.updateById(baseAnimal);
+                        if (baseAnimalMapper.updateById(baseAnimal) != 1) {
+                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                            return new Result(10001,"操作失败",false);
+                        }
                     }else {
                         String start = s.substring(0, s.indexOf("-"));
                         if (start.length() != 15){
@@ -316,7 +319,10 @@ public class BillIsolatedServiceImpl extends ServiceImpl<BillIsolatedMapper, Bil
                             }
                             animal.setIsDie(1);
                             //TODO 加回滚
-                            baseAnimalMapper.updateById(animal);
+                            if (baseAnimalMapper.updateById(animal) != 1) {
+                                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                                return new Result(10001,"操作失败",false);
+                            }
                         }
                     }
                 }
@@ -328,7 +334,10 @@ public class BillIsolatedServiceImpl extends ServiceImpl<BillIsolatedMapper, Bil
                     }
                     baseAnimal.setIsDie(1);
                     //TODO 加回滚
-                    baseAnimalMapper.updateById(baseAnimal);
+                    if (baseAnimalMapper.updateById(baseAnimal) != 1) {
+                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                        return new Result(10001,"操作失败",false);
+                    }
                 }else {
                     String start = deaths.substring(0, deaths.indexOf("-"));
                     if (start.length() != 15){
@@ -356,7 +365,10 @@ public class BillIsolatedServiceImpl extends ServiceImpl<BillIsolatedMapper, Bil
                         }
                         animal.setIsDie(1);
                         //TODO 加回滚
-                        baseAnimalMapper.updateById(animal);
+                        if (baseAnimalMapper.updateById(animal) != 1) {
+                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                            return new Result(10001,"操作失败",false);
+                        }
                     }
                 }
             }

+ 25 - 6
admin/src/main/java/com/huimv/farm/damsubsidy/service/impl/BillSubsidyServiceImpl.java

@@ -28,6 +28,7 @@ import com.huimv.farm.test.Print3;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
 import javax.annotation.Resource;
 import javax.servlet.ServletOutputStream;
@@ -107,6 +108,7 @@ public class BillSubsidyServiceImpl extends ServiceImpl<BillSubsidyMapper, BillS
     }
 
     @Override
+    @Transactional(rollbackFor = RuntimeException.class)
     public Result edit(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
         Integer type = Integer.parseInt(paramsMap.get("type"));
         String id = paramsMap.get("id");
@@ -125,7 +127,10 @@ public class BillSubsidyServiceImpl extends ServiceImpl<BillSubsidyMapper, BillS
             List<BaseAnimal> baseAnimals = animalMapper.selectList(animalQueryWrapper);
             for (BaseAnimal baseAnimal : baseAnimals) {
                 baseAnimal.setIsLoated(0);
-                animalMapper.updateById(baseAnimal);
+                if (animalMapper.updateById(baseAnimal) != 1) {
+                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                    return new Result(10001,"操作失败",false);
+                }
             }
             billSubsidy.setRefuseReason(refuseReason);
             billSubsidy.setSubsidySch(2);
@@ -146,6 +151,7 @@ public class BillSubsidyServiceImpl extends ServiceImpl<BillSubsidyMapper, BillS
     }
 
     @Override
+    @Transactional(rollbackFor = RuntimeException.class)
     public Result edit2(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
         Integer type = Integer.parseInt(paramsMap.get("type"));
         String id = paramsMap.get("id");
@@ -173,7 +179,10 @@ public class BillSubsidyServiceImpl extends ServiceImpl<BillSubsidyMapper, BillS
             for (BaseAnimal baseAnimal : baseAnimals) {
                 baseAnimal.setIsLoated(0);
                 baseAnimal.setAnimalStatus(1);
-                animalMapper.updateById(baseAnimal);
+                if (animalMapper.updateById(baseAnimal) != 1) {
+                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                    return new Result(10001,"操作失败",false);
+                }
             }
             subsidyMapper.updateById(billSubsidy);
             return new Result(ResultCode.SUCCESS, billSubsidy);
@@ -222,7 +231,7 @@ public class BillSubsidyServiceImpl extends ServiceImpl<BillSubsidyMapper, BillS
     private BillBuyInfoMapper billBuyInfoMapper;
 
     @Override
-    @Transactional
+    @Transactional(rollbackFor = RuntimeException.class)
     public Result addApplication(HttpServletRequest httpServletRequest, BillSubsidy billSubsidy) {
         Integer type = sysUserMapper.selectOne(new QueryWrapper<SysUser>().eq("id", TokenSign.getMemberIdByJwtToken(httpServletRequest))).getUserType();
 
@@ -272,7 +281,10 @@ public class BillSubsidyServiceImpl extends ServiceImpl<BillSubsidyMapper, BillS
             if (!eartag.contains("-")) {
                 BaseAnimal animal = baseAnimalMapper.selectOne(new QueryWrapper<BaseAnimal>().eq("earatg_no", eartag));
                 animal.setIsLoated(1);
-                baseAnimalMapper.updateById(animal);
+                if (baseAnimalMapper.updateById(animal) != 1) {
+                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                    return new Result(10001,"操作失败",false);
+                }
             } else {
                 String start = eartag.substring(0, eartag.indexOf("-"));
                 String end = eartag.substring(eartag.indexOf("-") + 1);
@@ -286,7 +298,10 @@ public class BillSubsidyServiceImpl extends ServiceImpl<BillSubsidyMapper, BillS
                     String earatgNo = number.toString();
                     BaseAnimal animal = baseAnimalMapper.selectOne(new QueryWrapper<BaseAnimal>().eq("earatg_no", earatgNo));
                     animal.setIsLoated(1);
-                    baseAnimalMapper.updateById(animal);
+                    if (baseAnimalMapper.updateById(animal) != 1) {
+                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                        return new Result(10001,"操作失败",false);
+                    }
                 }
             }
         }
@@ -372,6 +387,7 @@ public class BillSubsidyServiceImpl extends ServiceImpl<BillSubsidyMapper, BillS
     }
 
     @Override
+    @Transactional(rollbackFor = RuntimeException.class)
     public Result editApplication(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
         String id = paramsMap.get("id");
         String type = paramsMap.get("type");
@@ -394,7 +410,10 @@ public class BillSubsidyServiceImpl extends ServiceImpl<BillSubsidyMapper, BillS
                     .eq("belong_to_user", TokenSign.getMemberIdByJwtToken(httpServletRequest)));
             for (BaseAnimal baseAnimal : baseAnimals) {
                 baseAnimal.setIsLoated(0);
-                baseAnimalMapper.updateById(baseAnimal);
+                if (baseAnimalMapper.updateById(baseAnimal) != 1) {
+                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                    return new Result(10001,"操作失败",false);
+                }
             }
             this.removeById(billSubsidy);
             return Result.SUCCESS();