Pārlūkot izejas kodu

用户管理接口 接口

chejianzheng 3 mēneši atpakaļ
vecāks
revīzija
b378f62c22

+ 8 - 1
portal-service-application/src/main/java/com/hfln/portal/application/controller/web/WebTenantController.java

@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
 import java.io.IOException;
+import java.util.List;
 
 @RestController
 @CatchAndLog
@@ -46,9 +47,15 @@ public class WebTenantController {
         return ApiResult.success(webTenantGateway.queryTenant(req));
     }
 
+    @GetMapping("/queryTenantInfo")
+    @Operation(summary = "查询租户信息")
+    public ApiResult<List<TenantInfoDto>> queryTenantInfo(@RequestParam Long tenantId) throws IOException {
+        return ApiResult.success(webTenantGateway.queryTenantInfo(tenantId));
+    }
+
     @GetMapping("/del")
     @Operation(summary = "删除租户 逻辑待定")
-    public ApiResult<Void> del(@Valid @RequestParam Long req) throws IOException {
+    public ApiResult<Void> del(@RequestParam Long req) throws IOException {
 //        webTenantGateway.del(req);
         return ApiResult.success();
     }

+ 4 - 4
portal-service-common/src/main/java/com/hfln/portal/common/dto/data/tenant/TenantDto.java

@@ -5,8 +5,6 @@ import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
-import java.util.List;
-
 @EqualsAndHashCode(callSuper = true)
 @Data
 @Schema(description = "租户")
@@ -39,6 +37,8 @@ public class TenantDto extends BaseDto {
     @Schema(description = "租户地址--详细地址")
     private String address;
 
-    @Schema(description = "子信息")
-    List<TenantInfoDto> children;
+//    @Schema(description = "子信息")
+////    List<TenantInfoDto> children;
+//    @Schema(description = "当前管理员信息")
+//    private AdminUserDto adminUser;
 }

+ 0 - 6
portal-service-common/src/main/java/com/hfln/portal/common/request/tenant/TenantQueryReq.java

@@ -13,12 +13,6 @@ public class TenantQueryReq extends PageVo {
     @Schema(description = "租户名称")
     private String tenantName;
 
-//    @Schema(description = "父租户 ID")
-//    private Long parentId;
-
     @Schema(description = "租户类型")
     private String tenantType;
-
-    @Schema(description = "是否启用级联查询 楼栋,楼层信息")
-    private boolean enabled = false;
 }

+ 2 - 0
portal-service-common/src/main/java/com/hfln/portal/common/vo/BaseDto.java

@@ -1,10 +1,12 @@
 package com.hfln.portal.common.vo;
 
 import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
 
 import java.io.Serializable;
 import java.time.LocalDateTime;
 
+@Data
 public class BaseDto implements Serializable {
 
     @Schema(description = "创建人")

+ 4 - 0
portal-service-domain/src/main/java/com/hfln/portal/domain/gateway/WebTenantGateway.java

@@ -5,6 +5,8 @@ import com.hfln.portal.common.dto.data.tenant.TenantInfoDto;
 import com.hfln.portal.common.request.tenant.*;
 import com.hfln.portal.common.vo.PageRecord;
 
+import java.util.List;
+
 public interface WebTenantGateway {
 
 
@@ -21,5 +23,7 @@ public interface WebTenantGateway {
     TenantInfoDto queryInfo(Long tinfoId);
 
     void addTenantAdmin(TenantAdminAddParam req);
+
+    List<TenantInfoDto> queryTenantInfo(Long tenantId);
 }
 

+ 5 - 5
portal-service-infrastructure/pom.xml

@@ -53,11 +53,11 @@
             <artifactId>sa-token-redis-template</artifactId>
         </dependency>
 
-        <!-- websocket -->
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-websocket</artifactId>
-        </dependency>
+<!--        &lt;!&ndash; websocket &ndash;&gt;-->
+<!--        <dependency>-->
+<!--            <groupId>org.springframework.boot</groupId>-->
+<!--            <artifactId>spring-boot-starter-websocket</artifactId>-->
+<!--        </dependency>-->
 
         <!-- oss存储 -->
         <dependency>

+ 0 - 107
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/config/PushMsgWebSocket.java

@@ -1,107 +0,0 @@
-package com.hfln.portal.infrastructure.config;
-
-import com.hfln.portal.infrastructure.po.GroupDevMap;
-import com.hfln.portal.infrastructure.service.GroupDevMapService;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import javax.annotation.PostConstruct;
-import javax.websocket.OnClose;
-import javax.websocket.OnError;
-import javax.websocket.OnOpen;
-import javax.websocket.Session;
-import javax.websocket.server.PathParam;
-import javax.websocket.server.ServerEndpoint;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-@Slf4j
-@ServerEndpoint("/ws/PushMsgWebSocket/{key}")
-@Component
-public class PushMsgWebSocket {
-	
-//	private BaseDAO baseDAO =SpringContext.getContext().getBean(BaseDAO.class);
-
-	private static GroupDevMapService groupDevMapService;
-	
-	private static Map<String, PushMsgWebSocket> clients = new ConcurrentHashMap<String, PushMsgWebSocket>();
-	private static Map<String, List<String>> groups =new ConcurrentHashMap<String,List<String>>();
-	private Session session;
-	private String key;
-
-	@Autowired
-	private GroupDevMapService transfer;
-
-	@PostConstruct
-	public void init() {
-		groupDevMapService = transfer;
-	}
-
-	@OnOpen
-	public void onOpen(@PathParam("key") String key, Session session) throws IOException {
-		log.info("ws连接" + key);
-		this.session = session;
-		this.key = key;
-		clients.put(key, this);
-		
-		String groupUuid =key.split(":")[0];
-		List<GroupDevMap> maps = groupDevMapService.queryByGroupUuid(groupUuid);
-		if(maps != null && maps.size()>0) {
-			List<String> group =new ArrayList<String>();
-			for(int i =0;i<maps.size();i++) {
-				group.add(maps.get(i).getClientId());
-			}
-			groups.put(groupUuid, group);
-		}
-	}
-
-	@OnClose
-	public void onClose() throws IOException {
-		log.error("ws关闭"+key);
-		clients.remove(key);
-	}
-
-	@OnError
-	public void onError(Session session, Throwable error) {
-		log.error("ws异常", error);
-		clients.remove(key);
-	}
-
-	public static void sendMessageTo(String message, String code) {
-		Set<String> keys = clients.keySet();
-		for (String s : keys) {
-			// 单雷达建立连接
-			if (s.contains(code)) {
-				PushMsgWebSocket item = clients.get(s);
-				if (item != null) {
-					try {
-						item.session.getAsyncRemote().sendText(message);
-					} catch (Exception e) {
-						log.error("ws推送报错", e);
-						clients.remove(s);
-					}
-				}
-			}
-			// 数组建立连接
-			if (s.contains(":")) {
-				String group_uuid =s.split(":")[0];		
-				if(groups.containsKey(group_uuid) && groups.get(group_uuid).contains(code)) {
-					PushMsgWebSocket item = clients.get(s);
-					if (item != null) {
-						try {
-							item.session.getAsyncRemote().sendText(message);
-						} catch (Exception e) {
-							log.error("ws推送报错", e);
-							clients.remove(s);
-						}
-					}
-				}
-			}
-		}
-	}
-}

+ 0 - 16
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/config/WebSocketConfig.java

@@ -1,16 +0,0 @@
-package com.hfln.portal.infrastructure.config;
-
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.web.socket.config.annotation.EnableWebSocket;
-import org.springframework.web.socket.server.standard.ServerEndpointExporter;
-
-@EnableWebSocket
-@Configuration
-public class WebSocketConfig {
-
-    @Bean
-    public ServerEndpointExporter serverEndpointExporter() {
-        return new ServerEndpointExporter();
-    }
-}

+ 36 - 35
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/WebTenantGatewayImpl.java

@@ -86,42 +86,7 @@ public class WebTenantGatewayImpl implements WebTenantGateway {
         Page<TblTenant> tenantList = tblTenantService.queryTenantList(req);
         // 换为目标VO
         List<TenantDto> targets = CopyUtils.copyList(tenantList.getRecords(), TenantDto.class);
-        if (!req.isEnabled() || CollectionUtils.isEmpty(targets)) {
-            return CopyUtils.copyPage(tenantList, targets);
-        }
 
-        // 如果需要级联查询 查询三级信息 租户信息 --》 楼栋信息 --》 楼层信息
-        List<TblTenantInfo> list = tblTenantInfoService.queryByTenantIds(targets.stream().map(TenantDto::getTenantId).collect(Collectors.toList()));
-        Map<Long, Map<String, List<TblTenantInfo>>> map = list.stream().collect(Collectors.groupingBy(
-                info -> Optional.ofNullable(info.getTenantId()).orElse(-1L),
-                Collectors.groupingBy(
-                        info -> Optional.ofNullable(info.getTinfoType()).orElse("DEFAULT"),
-                        Collectors.toList()
-                )
-        ));
-
-        for (TenantDto target : targets) {
-            Map<String, List<TblTenantInfo>> tenantInfoMap = map.get(target.getTenantId());
-            if (!CollectionUtils.isEmpty(tenantInfoMap)) {
-
-                List<TblTenantInfo> buildings = tenantInfoMap.get(TinfoType.COMMUNITY_BUILDING.getCode());
-                List<TblTenantInfo> floors = tenantInfoMap.get(TinfoType.UNIT_FLOOR.getCode());
-                Map<Long, List<TblTenantInfo>> floorMap = new HashMap<>();
-                if (!CollectionUtils.isEmpty(floors)) {
-                    floorMap = floors.stream().collect(Collectors.groupingBy(TblTenantInfo::getParentId));
-                }
-
-                if (!CollectionUtils.isEmpty(buildings)) {
-                    List<TenantInfoDto> buildingList = new ArrayList<>();
-                    for (TblTenantInfo building : buildings) {
-                        TenantInfoDto copy = CopyUtils.copy(building, TenantInfoDto.class);
-                        copy.setChildren(CopyUtils.copyList(floorMap.get(building.getTinfoId()), TenantInfoDto.class));
-                        buildingList.add(copy);
-                    }
-                    target.setChildren(buildingList);
-                }
-            }
-        }
         return CopyUtils.copyPage(tenantList, targets);
     }
 
@@ -209,4 +174,40 @@ public class WebTenantGatewayImpl implements WebTenantGateway {
         userRole.setRoleId(req.getRoleId());
         tblUserRoleService.save(userRole);
     }
+
+    @Override
+    public List<TenantInfoDto> queryTenantInfo(Long tenantId) {
+
+        TblTenant tblTenant = tblTenantService.getById(tenantId);
+        if (tblTenant == null) {
+            throw new BizException(ErrorEnum.DATA_NOT_EXISTS.getErrorCode(), ErrorEnum.DATA_NOT_EXISTS.getErrorMessage());
+        }
+
+        List<TblTenantInfo> list = tblTenantInfoService.queryByTenantIds(Arrays.asList(tenantId));
+
+        Map<String, List<TblTenantInfo>> tenantInfoMap = list.stream().collect(
+                Collectors.groupingBy(
+                        info -> Optional.ofNullable(info.getTinfoType()).orElse("DEFAULT"),
+                        Collectors.toList()
+        ));
+
+        List<TblTenantInfo> buildings = tenantInfoMap.get(TinfoType.COMMUNITY_BUILDING.getCode());
+        List<TblTenantInfo> floors = tenantInfoMap.get(TinfoType.UNIT_FLOOR.getCode());
+
+        List<TenantInfoDto> buildingList = new ArrayList<>();
+        if (!CollectionUtils.isEmpty(buildings)) {
+            Map<Long, List<TblTenantInfo>> floorMap = new HashMap<>();
+            if (!CollectionUtils.isEmpty(floors)) {
+                floorMap = floors.stream().collect(Collectors.groupingBy(TblTenantInfo::getParentId));
+            }
+            for (TblTenantInfo building : buildings) {
+                TenantInfoDto copy = CopyUtils.copy(building, TenantInfoDto.class);
+                copy.setChildren(CopyUtils.copyList(floorMap.get(building.getTinfoId()), TenantInfoDto.class));
+                buildingList.add(copy);
+            }
+        }
+
+
+        return buildingList;
+    }
 }

+ 80 - 0
portal-service-server/src/test/java/com/hfln/portal/test/service/TblDicItemServiceTest.java

@@ -0,0 +1,80 @@
+package com.hfln.portal.test.service;
+
+
+import cn.dev33.satoken.SaManager;
+import cn.dev33.satoken.context.SaTokenContext;
+import cn.dev33.satoken.spring.SaTokenContextForSpring;
+import cn.dev33.satoken.stp.StpUtil;
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONWriter;
+import com.hfln.portal.infrastructure.mapper.TblDicItemMapper;
+import com.hfln.portal.infrastructure.po.TblDicItem;
+import com.hfln.portal.infrastructure.service.TblDicItemService;
+import com.hfln.portal.server.Application;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.List;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = Application.class)
+public class TblDicItemServiceTest {
+
+    @Before
+    public void setUp() {
+
+        // 如果是 SpringBoot 环境
+        SaTokenContext context = new SaTokenContextForSpring();
+        SaManager.setSaTokenContext(context);
+        StpUtil.login(110);
+    }
+
+    @After
+    public void clear() {
+        StpUtil.logout();
+    }
+
+
+    @Autowired
+    private TblDicItemService tblDicItemService;
+
+    @Autowired
+    private TblDicItemMapper tblDicItemMapper;
+
+    @Test
+    public void add() {
+
+        TblDicItem tblDicItem = new TblDicItem();
+        tblDicItem.setDicType("test");
+        tblDicItem.setItemCode("test");
+        tblDicItem.setItemName("test");
+        boolean save = tblDicItemService.save(tblDicItem);
+        System.out.println(JSON.toJSONString(save, JSONWriter.Feature.PrettyFormat));
+    }
+
+    @Test
+    public void del() {
+
+        int i = tblDicItemMapper.deleteById(1946019819595919361L);
+        System.out.println(JSON.toJSONString(i, JSONWriter.Feature.PrettyFormat));
+    }
+
+    @Test
+    public void remove() {
+
+        boolean save = tblDicItemService.removeById(1946019819595919361L);
+        System.out.println(JSON.toJSONString(save, JSONWriter.Feature.PrettyFormat));
+    }
+
+    @Test
+    public void queryByDicType() {
+
+        List<TblDicItem> tblDicItems = tblDicItemService.queryByDicType("install_position");
+        System.out.println(JSON.toJSONString(tblDicItems, JSONWriter.Feature.PrettyFormat));
+    }
+}