From 025beffb2f11ee696caa2771ac799890308dc58e Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期四, 16 十一月 2023 11:12:51 +0800
Subject: [PATCH] 行政区划Ctrl,接收前端提交的form为json类型

---
 pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictSv.java |   75 +++++++++++++++++++++++++++++++++++--
 1 files changed, 71 insertions(+), 4 deletions(-)

diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictSv.java
index 9faba57..ff2cfeb 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictSv.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictSv.java
@@ -5,20 +5,87 @@
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
 
 @Slf4j
 @Service
 public class DistrictSv {
 
-    private BaDistrictMapper baDistrictMapper ;
+    private BaDistrictMapper dao;
 
     @Autowired
-    private void setBaDistrictMapper(BaDistrictMapper baDistrictMapper){
-        this.baDistrictMapper = baDistrictMapper ;
+    private void setDao(BaDistrictMapper dao){
+        this.dao = dao;
     }
 
+    /**
+     * 浠庣涓�绾ц鏀垮尯鍒掑紑濮嬶紝寰楀埌鎵�鏈夎鏀垮尯鍒掍俊鎭�
+     * @param firstLevel 绗竴绾ц涓嬪尯 level
+     * @return 鎵�鏈夎鏀垮尯鍒掗泦鍚�
+     */
+    public List<BaDistrict> selectAllByLevel(byte firstLevel){
+        List<BaDistrict> list = this.dao.selectByLevel(firstLevel) ;
+        if(list != null && list.size() > 0){
+            for(BaDistrict po : list){
+                getSubDistrict(po) ;
+            }
+        }
+        return list ;
+    }
 
+    /**
+     * 寰楀埌涓�涓鏀垮尯
+     * @param id 琛屾斂鍖篒D
+     * @return 琛屾斂鍖哄疄浣�
+     */
+    public BaDistrict selectById(Long id){
+        return this.dao.selectByPrimaryKey(id) ;
+    }
+
+    /**
+     * 淇濆瓨瀹炰綋
+     * @param po 瀹炰綋
+     * @return 鏁伴噺
+     */
+    @Transactional
     public int save(BaDistrict po){
-        return this.baDistrictMapper.insert(po) ;
+        return this.dao.insert(po) ;
+    }
+
+    /**
+     * 淇濆瓨淇敼瀹炰綋
+     * @param po 瀹炰綋
+     * @return 鏁伴噺
+     */
+    @Transactional
+    public int update(BaDistrict po){
+        return this.dao.updateByPrimaryKeySelective(po) ;
+    }
+
+    /**
+     * 淇濆瓨淇敼瀹炰綋
+     * @param id 瀹炰綋ID
+     * @return 鏁伴噺
+     */
+    @Transactional
+    public int delete(Long id){
+        return this.dao.deleteLogicById(id) ;
+    }
+
+    /**
+     * 寰楀埌涓嬬骇琛屾斂鍖哄垝
+     * @param po 涓婄骇琛屾斂鍖哄垝
+     */
+    private void getSubDistrict(BaDistrict po){
+        if(po != null && po.id != null){
+            po.subDistricts = this.dao.selectBySupperId(po.id) ;
+            if(po.subDistricts != null && po.subDistricts.size() > 0){
+                for(BaDistrict subPo : po.subDistricts){
+                    getSubDistrict(subPo) ;
+                }
+            }
+        }
     }
 }

--
Gitblit v1.8.0