Forráskód Böngészése

单元测试部门所属区域功能。

bruce 2 éve
szülő
commit
af34c68700

+ 2 - 2
imcs-bt-be/imcs-authority-biz/src/main/java/com/github/zuihou/authority/dao/core/OrgRegionMapper.java

@@ -31,7 +31,7 @@ public interface OrgRegionMapper extends SuperMapper<OrgRegion>
       "FROM" +
       "(" +
       "  SELECT a.org_id, a.region_id, b.name " +
-      "  FROM bt_org_region a " +
+      "  FROM c_core_org_region a " +
       "  LEFT JOIN c_common_dictionary_item b ON a.region_id = b.id " +
       "  WHERE a.org_id IN (${ids})" +
       ") c " +
@@ -44,6 +44,6 @@ public interface OrgRegionMapper extends SuperMapper<OrgRegion>
      *
      * @param id id
      */
-    @Delete("DELETE FROM bt_org_region WHERE org_id = #{id}")
+    @Delete("DELETE FROM c_core_org_region WHERE org_id = #{id}")
     void deleteByOrgId(Long id);
 }

+ 32 - 5
imcs-bt-be/imcs-authority-controller/src/main/java/com/github/zuihou/authority/controller/core/OrgController.java

@@ -23,6 +23,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -88,7 +89,7 @@ public class OrgController extends SuperCacheController<OrgService, Long, Org, O
         return success(org);
     }
 
-    private Org fillOrg(Org org)
+    private void fillOrg(Org org)
     {
         if (org.getParentId() == null || org.getParentId() <= 0)
         {
@@ -103,12 +104,12 @@ public class OrgController extends SuperCacheController<OrgService, Long, Org, O
             org.setTreePath(StringUtils.join(parent.getTreePath(), parent.getId(), DEF_ROOT_PATH));
         }
 
-        return org;
     }
 
     @Override
     public R<Boolean> handlerDelete(List<Long> ids)
     {
+        // TODO 删除所属区域
         return this.success(baseService.remove(ids));
     }
 
@@ -125,9 +126,35 @@ public class OrgController extends SuperCacheController<OrgService, Long, Org, O
     public R<List<Org>> tree(@RequestParam(value = "name", required = false) String name,
                              @RequestParam(value = "status", required = false) Boolean status)
     {
-        List<Org> list = this.baseService.list(Wraps.<Org>lbQ()
-                .like(Org::getLabel, name).eq(Org::getStatus, status).orderByAsc(Org::getSortValue));
-        return this.success(TreeUtil.buildTree(list));
+        // 查询平面数据
+        List<Org> rows = this.baseService.list(Wraps.<Org>lbQ()
+          .like(Org::getLabel, name)
+          .eq(Org::getStatus, status)
+          .orderByAsc(Org::getSortValue));
+
+        // 部门ID列表
+        List<Long> ids = rows.stream()
+          .map(Org::getId)
+          .collect(Collectors.toCollection(LinkedList::new));
+
+        // 补充所属区域
+        if (ids.size() > 0)
+        {
+            Map<Long, Map<String, Object>> regions = orgRegionMapper.findByOrgIds(StringUtils.join(ids, ","));
+
+            Map<String, Object> r;
+            for (Org o : rows)
+            {
+                r = regions.get(o.getId());
+                if (null != r)
+                {
+                    o.setRegionIds((String) r.getOrDefault("RegionIds", ""));
+                    o.setRegions((String) r.getOrDefault("Regions", ""));
+                }
+            }
+        }
+
+        return this.success(TreeUtil.buildTree(rows));
     }
 
     @Override

+ 1 - 1
imcs-bt-be/imcs-authority-entity/src/main/java/com/github/zuihou/authority/entity/core/OrgRegion.java

@@ -13,7 +13,7 @@ import lombok.experimental.Accessors;
  * @author bruce
  * @since 2023-02-23
  */
-@TableName("bt_org_region")
+@TableName("c_core_org_region")
 @ApiModel(value = "OrgRegion", description = "组织-所属区域")
 @ToString(callSuper = true) @EqualsAndHashCode(callSuper = true)
 @Data @Builder @NoArgsConstructor @AllArgsConstructor @Accessors(chain = true)

+ 2 - 6
imcs-bt-be/imcs-business-controller/src/main/java/com/github/zuihou/business/controller/place/PlaceController.java

@@ -2,10 +2,7 @@ package com.github.zuihou.business.controller.place;
 
 import cn.hutool.core.bean.BeanUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.github.zuihou.authority.dao.common.DictionaryItemMapper;
-import com.github.zuihou.authority.dto.core.OrgSaveDTO;
 import com.github.zuihou.authority.entity.auth.User;
-import com.github.zuihou.authority.entity.common.DictionaryItem;
 import com.github.zuihou.authority.entity.core.Org;
 import com.github.zuihou.authority.service.auth.UserService;
 import com.github.zuihou.authority.service.core.OrgService;
@@ -27,7 +24,6 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
-import org.springframework.data.redis.connection.ReactiveGeoCommands;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -95,12 +91,12 @@ public class PlaceController extends SuperController<PlaceService, Long, Place,
         // 补充所属区域属性
         if (ids.size() > 0)
         {
-            Map<Long, Map<String, Object>> placeRegions = placeRegionMapper.findByPlaceIds(StringUtils.join(ids, ","));
+            Map<Long, Map<String, Object>> regions = placeRegionMapper.findByPlaceIds(StringUtils.join(ids, ","));
 
             Map<String, Object> rows;
             for (Place place : placeList)
             {
-                rows = placeRegions.get(place.getId());
+                rows = regions.get(place.getId());
                 if (null != rows)
                 {
                     place.setRegionIds((String) rows.getOrDefault("RegionIds", ""));