فهرست منبع

web设备接口调整展示租户名称

hxd 2 ماه پیش
والد
کامیت
cdd727cb45

+ 5 - 0
portal-service-common/src/main/java/com/hfln/portal/common/dto/data/device/DeviceDTO.java

@@ -29,6 +29,11 @@ public class DeviceDTO extends BaseVO {
     @Schema(description = "租户Id")
     private Long tenantId;
 
+    /**
+     * 租户名称
+     */
+    @Schema(description = "租户名称")
+    private String tenantName;
 
     /**
      * 用户openid

+ 8 - 0
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/DeviceGatewayImpl.java

@@ -96,6 +96,9 @@ public class DeviceGatewayImpl implements DeviceGateway {
     @Autowired
     private WxRelationService wxRelationService;
 
+    @Autowired
+    private TblTenantService tblTenantService;
+
 
     @Override
     public HomeInfoDTO queryHomeInfo(Long userId) {
@@ -266,8 +269,13 @@ public class DeviceGatewayImpl implements DeviceGateway {
         if (Objects.isNull(devInfo)) {
             throw new BizException(ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorCode(), ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorMessage());
         }
+        String tenantName = tblTenantService.getOne(
+                Wrappers.<TblTenant>lambdaQuery()
+                        .eq(TblTenant::getTenantId, devInfo.getTenantId()))
+                .getTenantName();
         DeviceDTO dto = new DeviceDTO();
         BeanUtils.copyProperties(devInfo, dto);
+        dto.setTenantName(tenantName);
         return dto;
     }
 

+ 23 - 2
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/WebGatewayImpl.java

@@ -84,6 +84,8 @@ public class WebGatewayImpl implements WebGateway {
     private TblDicItemService tblDicItemService;
     @Autowired
     private UserService userService;
+    @Autowired
+    private TblTenantService tblTenantService;
 
     @Override
     public UploadRes uploadDev(MultipartFile file) throws IOException {
@@ -140,8 +142,27 @@ public class WebGatewayImpl implements WebGateway {
         Long tenantId =  (Long) StpUtil.getSession().get(UserConstants.SA_USER_TENANT_ID);
         Page<DevInfo> devInfoPage = devInfoService.queryDevList(queryReq, tenantId);
         // 换为目标DTO
-        List<DeviceDTO> targets = CopyUtils.copyList(devInfoPage.getRecords(), DeviceDTO.class);
-        return CopyUtils.copyPage(devInfoPage, targets);
+        List<DeviceDTO> deviceDTOList = CopyUtils.copyList(devInfoPage.getRecords(), DeviceDTO.class);
+
+        //收集所有tenantId
+        Set<Long> tenantIds = deviceDTOList.stream()
+                .map(DeviceDTO::getTenantId)
+                .filter(Objects::nonNull)
+                .collect(Collectors.toSet());
+
+        // 批量查询租户信息
+        List<TblTenant> tenantList = tblTenantService.listByIds(tenantIds);
+        Map<Long, String> tenantIdNameMap = tenantList.stream()
+                .collect(Collectors.toMap(TblTenant::getTenantId, TblTenant::getTenantName));
+
+        //设置tenantName到DTO
+        deviceDTOList.forEach(dto -> {
+            if (dto.getTenantId() != null) {
+                dto.setTenantName(tenantIdNameMap.get(dto.getTenantId()));
+            }
+        });
+
+        return CopyUtils.copyPage(devInfoPage, deviceDTOList);
     }
 
     @Override