Browse Source

[CODE]:客户删除 判断是否存在库存

maxianghua 4 years ago
parent
commit
30b613be9d

+ 2 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/warehouse/basicData/TCorpsController.java

@@ -103,6 +103,7 @@ public class TCorpsController extends BaseController {
     @Log(title = "客户详情", businessType = BusinessType.DELETE)
     @DeleteMapping("/{fIds}")
     public AjaxResult remove(@PathVariable Long[] fIds) {
-        return toAjax(tCorpsService.deleteTCorpsByIds(fIds));
+
+        return tCorpsService.deleteTCorpsByIds(fIds);
     }
 }

+ 1 - 1
ruoyi-warehouse/src/main/java/com/ruoyi/basicData/service/ITCorpsService.java

@@ -55,7 +55,7 @@ public interface ITCorpsService {
      * @param fIds 需要删除的客户详情ID
      * @return 结果
      */
-    public int deleteTCorpsByIds(Long[] fIds);
+    public AjaxResult deleteTCorpsByIds(Long[] fIds);
 
     /**
      * 删除客户详情信息

+ 23 - 2
ruoyi-warehouse/src/main/java/com/ruoyi/basicData/service/impl/TCorpsServiceImpl.java

@@ -13,9 +13,12 @@ import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.model.LoginUser;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.warehouseBusiness.domain.TWarehouseBills;
+import com.ruoyi.warehouseBusiness.mapper.TWarehouseBillsMapper;
 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 java.util.*;
 
@@ -33,6 +36,9 @@ public class TCorpsServiceImpl implements ITCorpsService {
     @Autowired
     private TCustomerContactMapper tCustomerContactMapper;
 
+    @Autowired
+    private TWarehouseBillsMapper tWarehouseBillsMapper;
+
     /**
      * 查询客户详情
      *
@@ -131,8 +137,23 @@ public class TCorpsServiceImpl implements ITCorpsService {
      * @return 结果
      */
     @Override
-    public int deleteTCorpsByIds(Long[] fIds) {
-        return tCorpsMapper.deleteTCorpsByIds(fIds);
+    @Transactional
+    public AjaxResult deleteTCorpsByIds(Long[] fIds) {
+        //return tCorpsMapper.deleteTCorpsByIds(fIds);
+        // 查询仓库主表 是否有客户存在
+        int i = 1;
+        for(Long id:fIds){
+            TWarehouseBills tWarehouseBill =new TWarehouseBills();
+            tWarehouseBill.setfCorpid(id);
+            List<TWarehouseBills>   tWarehouseBillList=tWarehouseBillsMapper.selectTWarehousebillsList(tWarehouseBill);
+            if(tWarehouseBillList!=null && !tWarehouseBillList.isEmpty()){
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                return AjaxResult.error("客户第" + i + "行仓库有货物不可删除");
+            }
+            tCorpsMapper.deleteTCorpsById(id);
+            i++;
+        }
+        return AjaxResult.success();
     }
 
     /**

+ 2 - 0
ruoyi-warehouse/src/main/java/com/ruoyi/basicData/service/impl/TWarehouseServiceImpl.java

@@ -17,6 +17,7 @@ import com.ruoyi.warehouseBusiness.mapper.TWarehouseBillsMapper;
 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 java.util.Date;
 import java.util.HashMap;
@@ -154,6 +155,7 @@ public class TWarehouseServiceImpl implements ITWarehouseService {
             tWarehouseBill.setfWarehouseid(id);
             List<TWarehouseBills>   tWarehouseBillList=tWarehouseBillsMapper.selectTWarehousebillsList(tWarehouseBill);
             if(tWarehouseBillList!=null && !tWarehouseBillList.isEmpty()){
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                 return AjaxResult.error("仓库第" + i + "行仓库有货物不可删除");
             }
             tWarehouseMapper.deleteTWarehouseById(id);