Jelajahi Sumber

添加查询省、市、县、门店机构列表接口并测试

hxl13994548489 2 tahun lalu
induk
melakukan
d714329a34

+ 13 - 0
src/main/java/com/ydtech/modules/admin/controller/SysDeptController.java

@@ -138,4 +138,17 @@ public class SysDeptController extends BaseController {
         queryWrapper.eq(SysDept::getDelFlag, 0);
         return HttpResult.ok(sysDeptService.findTree("9",null));
     }
+    @ApiOperation(value = "省市区门店列表查询 省级parentId=99 市县传值上级id,level传值省市县门店1,2,3,4")
+    @PostMapping(value = "/queryListByParentId/{level}/{parentId}")
+    public HttpResult<List<SysDept>> queryListByParentId(@PathVariable("level")  String level, @PathVariable("parentId") String parentId) {
+        if(parentId==null || "".equals(parentId)) {
+            return HttpResult.error("parentId父级id不能为空");
+        }
+        if(level==null || "".equals(level)) {
+            return HttpResult.error("level类型不能为空");
+        }
+        List<SysDept> sysDeptList = sysDeptService.queryListByParentId(level,parentId);
+        return HttpResult.ok(sysDeptList);
+    }
+
 }

+ 9 - 1
src/main/java/com/ydtech/modules/admin/dao/SysDeptMapper.java

@@ -4,11 +4,19 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.ydtech.modules.admin.model.SysDept;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
+
 public interface SysDeptMapper extends BaseMapper<SysDept> {
 
 
     String getMaxId(@Param(value = "deptId") String deptId);
-
+    /**
+     *  @version
+     *  @author: hxl
+     *  @Date: 2024/4/28 10:01
+     *  @Description: 通过县级code查询门店列表
+     */
+    List<SysDept> queryListByParentId(@Param(value = "level") String level,@Param(value = "parentId") String parentId);
 }
 
 

+ 7 - 2
src/main/java/com/ydtech/modules/admin/service/SysDeptService.java

@@ -1,7 +1,6 @@
 package com.ydtech.modules.admin.service;
 
 
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.ydtech.core.page.HttpResult;
 import com.ydtech.core.page.PageRequest;
@@ -76,7 +75,13 @@ public interface SysDeptService extends IService<SysDept> {
      * @return
      */
     public List<SysDept> findTeamList(String deptId);
-
+    /**
+     *  @version
+     *  @author: hxl
+     *  @Date: 2024/4/28 10:22
+     *  @Description:  查询省、市、县、门店列表信息
+     */
+    List<SysDept> queryListByParentId(String level, String parentId);
 }
 
 

+ 13 - 1
src/main/java/com/ydtech/modules/admin/service/impl/SysDeptServiceImpl.java

@@ -17,6 +17,7 @@ import com.ydtech.modules.admin.service.SysDeptService;
 import com.ydtech.modules.protocol.utils.AssertionUtils;
 import com.ydtech.utils.StringUtils;
 import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.ObjectUtils;
@@ -32,7 +33,8 @@ import java.util.stream.Collectors;
 public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
         implements SysDeptService {
 
-
+    @Autowired
+    private SysDeptMapper sysDeptMapper;
     @Override
     public List<SysDept> findTree(String deptId,String managementSource) {
         if(null == deptId || "".equals(deptId) || "undefined".equals(deptId)){
@@ -366,6 +368,16 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
         List<SysDept> sysDeptList = list(lqw);
         return sysDeptList;
     }
+    /**
+     *  @version
+     *  @author: hxl
+     *  @Date: 2024/4/28 10:24
+     *  @Description: 查询省、市、县 、门店的列表
+     */
+    @Override
+    public List<SysDept> queryListByParentId(String level, String parentId) {
+        return sysDeptMapper.queryListByParentId(level,parentId);
+    }
 
 }
 

+ 33 - 0
src/main/resources/mapper/modules/admin/SysDeptMapper.xml

@@ -47,4 +47,37 @@
         WHERE parent_id = #{deptId}
     </select>
 
+
+    <select id="queryListByParentId" resultType="com.ydtech.modules.admin.model.SysDept">
+        SELECT
+            dept.*
+        FROM
+            sys_dept dept
+        WHERE
+            dept.del_flag = 0
+        <if test='level == "1"'>
+            AND dept.province IN ( SELECT area_code FROM sys_area WHERE LEVEL = 1 )
+            AND LENGTH(
+            IFNULL( dept.province, '' )) + LENGTH( IFNULL( dept.city, '' ) ) + LENGTH(
+            IFNULL( dept.area, '' ))=6
+            AND dept.parent_id = #{parentId}
+        </if>
+        <if test='level == "2"'>
+            AND dept.city IN ( SELECT area_code FROM sys_area WHERE LEVEL = 2 )
+            AND LENGTH(
+            IFNULL( dept.province, '' )) + LENGTH( IFNULL( dept.city, '' ) ) + LENGTH(
+            IFNULL( dept.area, '' ))= 12
+            AND dept.parent_id = #{parentId}
+        </if>
+        <if test='level == "3"'>
+            AND dept.area IN ( SELECT area_code FROM sys_area WHERE LEVEL = 3)
+            AND LENGTH(
+            IFNULL( dept.province, '' )) + LENGTH( IFNULL( dept.city, '' ) ) + LENGTH(
+            IFNULL( dept.area, '' ))= 18
+            AND dept.parent_id = #{parentId}
+        </if>
+        <if test='level == "4"'>
+            AND dept.parent_id = #{parentId}
+        </if>
+    </select>
 </mapper>