lishuangjiang@potevio.com 1 rok temu
rodzic
commit
e3f58981fd

+ 1 - 1
iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceInfoData.java

@@ -141,7 +141,7 @@ public interface IDeviceInfoData extends IOwnedData<DeviceInfo, String> {
      */
     boolean existByProductKey(String productKey);
 
-    Map countCategoryMap();
+    Map countCategoryMap(String tenantId);
 
     Map countStateMap(String tenantId);
 

+ 2 - 2
iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/DeviceInfoDataCache.java

@@ -319,8 +319,8 @@ public class DeviceInfoDataCache implements IDeviceInfoData, SmartInitializingSi
     }
 
     @Override
-    public Map countCategoryMap() {
-        return deviceInfoData.countCategoryMap();
+    public Map countCategoryMap(String tenantId) {
+        return deviceInfoData.countCategoryMap(tenantId);
     }
 
     @Override

+ 2 - 2
iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/DeviceInfoPropertyDataCache.java

@@ -193,8 +193,8 @@ public class DeviceInfoPropertyDataCache implements IDeviceInfoData {
     }
 
     @Override
-    public Map countCategoryMap() {
-        return deviceInfoData.countCategoryMap();
+    public Map countCategoryMap(String tenantId) {
+        return deviceInfoData.countCategoryMap(tenantId);
     }
 
     @Override

+ 32 - 22
iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceInfoDataImpl.java

@@ -464,13 +464,13 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
     @Override
     public Map countStateMap(String tenantId) {
         Map<String, Long> resultMap = new HashMap();
-        if (StringUtils.isNotBlank(tenantId) && tenantId.equals("000000")) {
-            resultMap = countStateMapWithoutTenantId();
-        } else {
-            if (StringUtils.isNotBlank(tenantId)) {
-                resultMap = countStateMapWithTenantId(tenantId);
-            }
-        }
+//        if (StringUtils.isNotBlank(tenantId) && tenantId.equals("000000")) {
+//            resultMap = countStateMapWithoutTenantId();
+//        } else {
+         if (StringUtils.isNotBlank(tenantId)) {
+            resultMap = countStateMapWithTenantId(tenantId);
+         }
+//        }
         for(String item : deviceStateList){
             Long itemData = resultMap.get(item);
             if(Objects.isNull(itemData)){
@@ -482,17 +482,18 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
 
     private Map<String, Long> countStateMapWithTenantId(String tenantId) {
         Map<String, Long> resultMap = new HashMap();
+        List<Long> finalDeptList = PredicateBuilder.queryCacheChildDeptIds(tenantId);
         List<Tuple> result = jpaQueryFactory.select(tbDeviceInfo.id.count(), tbDeviceInfo.state).from(tbDeviceInfo)
-                .leftJoin(tbProduct).on(tbProduct.productKey.eq(tbDeviceInfo.productKey))
-                .where(tbProduct.tenantId.eq(tenantId))
+//                .leftJoin(tbProduct).on(tbProduct.productKey.eq(tbDeviceInfo.productKey))
+                .where(tbDeviceInfo.tenantId.eq(tenantId).and(tbDeviceInfo.createDept.in(finalDeptList)))
                 .groupBy(tbDeviceInfo.state).fetch();
         for (Tuple tuple : result) {
             resultMap.put(tuple.get(1, String.class), tuple.get(0, Long.class));
         }
         Long noRegistResult = jpaQueryFactory.select(tbDeviceInfo.id.count()).from(tbDeviceInfo).where(tbDeviceInfo.state.eq("offline")
-                .and(tbDeviceInfo.onlineTime.isNull()))
-                .leftJoin(tbProduct).on(tbProduct.productKey.eq(tbDeviceInfo.productKey))
-                .where(tbProduct.tenantId.eq(tenantId))
+                .and(tbDeviceInfo.onlineTime.isNull().and(tbDeviceInfo.tenantId.eq(tenantId)).and(tbDeviceInfo.createDept.in(finalDeptList))))
+//                .leftJoin(tbProduct).on(tbProduct.productKey.eq(tbDeviceInfo.productKey))
+//                .where(tbProduct.tenantId.eq(tenantId))
                 .fetchOne();
         resultMap.put("unactivated", noRegistResult);
         //
@@ -521,9 +522,11 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
     }
 
     @Override
-    public Map countCategoryMap() {
+    public Map countCategoryMap(String tenantId) {
         Map<String, Long> resultMap = new HashMap();
-        List<Tuple> result = jpaQueryFactory.select(tbDeviceInfo.id.count(), tbDeviceInfo.productKey).from(tbDeviceInfo).groupBy(tbDeviceInfo.productKey).fetch();
+        List<Long> finalDeptList = PredicateBuilder.queryCacheChildDeptIds(tenantId);
+        List<Tuple> result = jpaQueryFactory.select(tbDeviceInfo.id.count(), tbDeviceInfo.productKey).from(tbDeviceInfo)
+                .where(tbDeviceInfo.tenantId.eq(tenantId).and(tbDeviceInfo.createDept.in(finalDeptList))).groupBy(tbDeviceInfo.productKey).fetch();
         for (Tuple tuple : result) {
             resultMap.put(tuple.get(1, String.class), tuple.get(0, Long.class));
         }
@@ -537,7 +540,9 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
         calendar.set(Calendar.MINUTE, 0);
         calendar.set(Calendar.HOUR, 0);
         calendar.set(Calendar.MILLISECOND, 0);
-        return jpaQueryFactory.select(tbDeviceInfo.id.count()).from(tbDeviceInfo).where(tbDeviceInfo.createAt.gt(calendar.getTime().getTime())).fetchOne();
+        List<Long> finalDeptList = PredicateBuilder.queryCacheChildDeptIds(tenantId);
+        return jpaQueryFactory.select(tbDeviceInfo.id.count()).from(tbDeviceInfo).where(tbDeviceInfo.createAt.gt(calendar.getTime().getTime())
+                .and(tbDeviceInfo.tenantId.eq(tenantId)).and(tbDeviceInfo.createDept.in(finalDeptList))).fetchOne();
     }
 
 
@@ -595,16 +600,21 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
 
     @Override
     public Long countByTenantId(String tenantId) {
-        if (StringUtils.isNotBlank(tenantId) && tenantId.equals("000000")) {
-            return this.count();
-        } else {
+//        if (StringUtils.isNotBlank(tenantId) && tenantId.equals("000000")) {
+//            return this.count();
+//        } else {
             if (StringUtils.isNotBlank(tenantId)) {
-                return jpaQueryFactory.select(tbDeviceInfo.id.count()).from(tbDeviceInfo).leftJoin(tbProduct)
-                        .on(tbDeviceInfo.productKey.eq(tbProduct.productKey)).where(tbProduct.tenantId.eq(tenantId)
-                        ).fetchOne();
+                List<Long> finalDeptList = PredicateBuilder.queryCacheChildDeptIds(tenantId);
+//                if(CollectionUtil.isNotEmpty(finalDeptList)){
+                return jpaQueryFactory.select(tbDeviceInfo.id.count()).from(tbDeviceInfo).where(tbDeviceInfo.tenantId.eq(tenantId).and(tbDeviceInfo.createDept.in(finalDeptList))
+                    ).fetchOne();
+//                }else{
+//                    return jpaQueryFactory.select(tbDeviceInfo.id.count()).from(tbDeviceInfo).where(tbDeviceInfo.tenantId.eq(tenantId)).fetchOne();
+//                }
+
             } else {
                 return 0L;
-            }
+//            }
         }
 
     }

+ 1 - 0
iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/util/PredicateBuilder.java

@@ -139,6 +139,7 @@ public class PredicateBuilder {
         deptList = Collections.singletonList(deptId);
       }
     }
+    System.out.println("##########################"+deptList);
     return deptList;
   }
 }

+ 2 - 1
iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/HomeController.java

@@ -130,7 +130,8 @@ public class HomeController {
             productMap = productVos.stream().collect(Collectors.toMap(ProductVo::getProductKey,ProductVo::getCategory));
         }
         Long allNum = 0L;
-        Map statisMap = deviceServiceImpl.countCategoryMap();
+        String tenantId = TenantHelper.getTenantId();
+        Map statisMap = deviceServiceImpl.countCategoryMap(tenantId);
         for (Object key :statisMap.keySet()){
             String category  = productMap.get(key);
             Long tmpNum = (Long)statisMap.get(key);

+ 1 - 1
iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IDeviceManagerService.java

@@ -79,7 +79,7 @@ public interface IDeviceManagerService {
 
     Map countMap( String tenantId);
 
-    Map countCategoryMap();
+    Map countCategoryMap(String tenantId);
 
     Map countStateMap( String tenantId);
 }

+ 1 - 1
iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/NotifyService.java

@@ -95,7 +95,7 @@ public class NotifyService {
     }
 
     public Paging<NotifyMessage> getNotifyMessageList(PageRequest<NotifyMessage> request) {
-        return iNotifyMessageData.findAll(request.to(NotifyMessage.class));
+        return iNotifyMessageData.findAll(request);
 //        return iNotifyMessageData.findAll(request);
     }
 }

+ 2 - 2
iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/DeviceManagerServiceImpl.java

@@ -442,8 +442,8 @@ public class DeviceManagerServiceImpl implements IDeviceManagerService {
     }
 
     @Override
-    public Map countCategoryMap() {
-        return deviceInfoData.countCategoryMap();
+    public Map countCategoryMap(String tenantId) {
+        return deviceInfoData.countCategoryMap(tenantId);
     }
 
     @Override