Parcourir la source

删除栋舍失败手动回滚

Newspaper il y a 1 an
Parent
commit
91be1c02ac

+ 3 - 1
src/main/java/com/huimv/admin/service/impl/BasePigpenServiceImpl.java

@@ -25,6 +25,7 @@ import org.apache.commons.lang.time.DateUtils;
 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.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
@@ -138,7 +139,7 @@ public class BasePigpenServiceImpl extends ServiceImpl<BasePigpenMapper, BasePig
     }
 
     @Override
-    @Transactional
+    @Transactional(rollbackFor = RuntimeException.class)
     public Result deletePigpen(Map<String, Integer> map) {
         Integer integer = map.get("id");
         Integer integer1 = envDeviceMapper.selectCount(new QueryWrapper<EnvDevice>().eq("unit_id", integer));
@@ -149,6 +150,7 @@ public class BasePigpenServiceImpl extends ServiceImpl<BasePigpenMapper, BasePig
         for (BasePigpen basePigpen : other2) {
             Integer count = envDeviceMapper.selectCount(new QueryWrapper<EnvDevice>().eq("unit_id", basePigpen.getId()));
             if (count > 0) {
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                 return new Result(10001, "删除失败,该栋舍下有采集器", false);
             }
             basePigpenMapper.deleteById(basePigpen);