feat: 首页数据统计
parent
3af34fbc11
commit
d456f41a1a
|
@ -148,4 +148,10 @@ public interface IDeviceInfoData extends IOwnedData<DeviceInfo, String> {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
boolean existByProductKey(String productKey);
|
boolean existByProductKey(String productKey);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查找待激活设备
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<DeviceInfo> findNeverUsedDevices();
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,6 +155,11 @@ public class DeviceInfoDataCache implements IDeviceInfoData, SmartInitializingSi
|
||||||
return deviceInfoData.existByProductKey(productKey);
|
return deviceInfoData.existByProductKey(productKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DeviceInfo> findNeverUsedDevices() {
|
||||||
|
return deviceInfoData.findNeverUsedDevices();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> findSubDeviceIds(String parentId) {
|
public List<String> findSubDeviceIds(String parentId) {
|
||||||
return deviceInfoData.findSubDeviceIds(parentId);
|
return deviceInfoData.findSubDeviceIds(parentId);
|
||||||
|
|
|
@ -182,6 +182,11 @@ public class DeviceInfoPropertyDataCache implements IDeviceInfoData {
|
||||||
return deviceInfoData.existByProductKey(productKey);
|
return deviceInfoData.existByProductKey(productKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DeviceInfo> findNeverUsedDevices() {
|
||||||
|
return deviceInfoData.findNeverUsedDevices();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DeviceInfo> findByUid(String uid) {
|
public List<DeviceInfo> findByUid(String uid) {
|
||||||
return deviceInfoData.findByUid(uid);
|
return deviceInfoData.findByUid(uid);
|
||||||
|
|
|
@ -4,17 +4,24 @@ import cc.iotkit.common.api.PageRequest;
|
||||||
import cc.iotkit.common.api.Paging;
|
import cc.iotkit.common.api.Paging;
|
||||||
import cc.iotkit.common.utils.MapstructUtils;
|
import cc.iotkit.common.utils.MapstructUtils;
|
||||||
import cc.iotkit.common.utils.ReflectUtil;
|
import cc.iotkit.common.utils.ReflectUtil;
|
||||||
|
import cc.iotkit.common.utils.StreamUtils;
|
||||||
import cc.iotkit.data.dao.*;
|
import cc.iotkit.data.dao.*;
|
||||||
import cc.iotkit.data.manager.ICategoryData;
|
import cc.iotkit.data.manager.ICategoryData;
|
||||||
import cc.iotkit.data.manager.IDeviceInfoData;
|
import cc.iotkit.data.manager.IDeviceInfoData;
|
||||||
import cc.iotkit.data.manager.IProductData;
|
import cc.iotkit.data.manager.IProductData;
|
||||||
import cc.iotkit.data.model.*;
|
import cc.iotkit.data.model.*;
|
||||||
import cc.iotkit.data.util.PageBuilder;
|
import cc.iotkit.data.util.PageBuilder;
|
||||||
|
import cc.iotkit.data.util.PredicateBuilder;
|
||||||
import cc.iotkit.model.device.DeviceInfo;
|
import cc.iotkit.model.device.DeviceInfo;
|
||||||
import cc.iotkit.model.device.message.DevicePropertyCache;
|
import cc.iotkit.model.device.message.DevicePropertyCache;
|
||||||
import cc.iotkit.model.product.Category;
|
import cc.iotkit.model.product.Category;
|
||||||
import cc.iotkit.model.product.Product;
|
import cc.iotkit.model.product.Product;
|
||||||
import cc.iotkit.model.stats.DataItem;
|
import cc.iotkit.model.stats.DataItem;
|
||||||
|
import cc.iotkit.model.system.SysDept;
|
||||||
|
import cc.iotkit.model.system.SysUser;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.querydsl.core.types.Expression;
|
||||||
|
import com.querydsl.core.types.Predicate;
|
||||||
import com.querydsl.core.types.Projections;
|
import com.querydsl.core.types.Projections;
|
||||||
import com.querydsl.jpa.impl.JPAQuery;
|
import com.querydsl.jpa.impl.JPAQuery;
|
||||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||||
|
@ -34,6 +41,8 @@ import static cc.iotkit.data.model.QTbDeviceGroupMapping.tbDeviceGroupMapping;
|
||||||
import static cc.iotkit.data.model.QTbDeviceInfo.tbDeviceInfo;
|
import static cc.iotkit.data.model.QTbDeviceInfo.tbDeviceInfo;
|
||||||
import static cc.iotkit.data.model.QTbDeviceSubUser.tbDeviceSubUser;
|
import static cc.iotkit.data.model.QTbDeviceSubUser.tbDeviceSubUser;
|
||||||
import static cc.iotkit.data.model.QTbProduct.tbProduct;
|
import static cc.iotkit.data.model.QTbProduct.tbProduct;
|
||||||
|
import static cc.iotkit.data.model.QTbSysDept.tbSysDept;
|
||||||
|
import static cc.iotkit.data.model.QTbSysUser.tbSysUser;
|
||||||
|
|
||||||
@Primary
|
@Primary
|
||||||
@Service
|
@Service
|
||||||
|
@ -51,7 +60,6 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
|
||||||
|
|
||||||
private final DeviceTagRepository deviceTagRepository;
|
private final DeviceTagRepository deviceTagRepository;
|
||||||
|
|
||||||
|
|
||||||
@Qualifier("productDataCache")
|
@Qualifier("productDataCache")
|
||||||
private final IProductData productData;
|
private final IProductData productData;
|
||||||
|
|
||||||
|
@ -210,6 +218,14 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
|
||||||
return Optional.ofNullable(jpaQueryFactory.selectOne().from(tbDeviceInfo).where(tbDeviceInfo.productKey.eq(productKey)).fetchOne()).orElse(0) > 0;
|
return Optional.ofNullable(jpaQueryFactory.selectOne().from(tbDeviceInfo).where(tbDeviceInfo.productKey.eq(productKey)).fetchOne()).orElse(0) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DeviceInfo> findNeverUsedDevices() {
|
||||||
|
JPAQuery<TbDeviceInfo> query = jpaQueryFactory.selectFrom(tbDeviceInfo);
|
||||||
|
query.where(tbDeviceInfo.onlineTime.isNull());
|
||||||
|
List<TbDeviceInfo> devices = query.fetch();
|
||||||
|
return MapstructUtils.convert(devices, DeviceInfo.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Paging<DeviceInfo> findByConditions(String uid, String subUid,
|
public Paging<DeviceInfo> findByConditions(String uid, String subUid,
|
||||||
String productKey, String groupId,
|
String productKey, String groupId,
|
||||||
|
@ -284,8 +300,8 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
|
||||||
public List<DataItem> getDeviceStatsByCategory(String uid) {
|
public List<DataItem> getDeviceStatsByCategory(String uid) {
|
||||||
//先按产品统计设备数量
|
//先按产品统计设备数量
|
||||||
JPAQuery<DataItem> query = jpaQueryFactory.select(Projections.bean(DataItem.class,
|
JPAQuery<DataItem> query = jpaQueryFactory.select(Projections.bean(DataItem.class,
|
||||||
tbDeviceInfo.productKey,
|
tbDeviceInfo.productKey.as("name"),
|
||||||
tbDeviceInfo.count()))
|
tbDeviceInfo.productKey.count().as("value")))
|
||||||
.from(tbDeviceInfo)
|
.from(tbDeviceInfo)
|
||||||
.groupBy(tbDeviceInfo.productKey);
|
.groupBy(tbDeviceInfo.productKey);
|
||||||
|
|
||||||
|
@ -463,5 +479,24 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DeviceInfo> findAllByCondition(DeviceInfo data) {
|
||||||
|
return buildQuery(buildQueryCondition(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<DeviceInfo> buildQuery(Predicate predicate) {
|
||||||
|
List<TbDeviceInfo> devices = jpaQueryFactory.select(Projections.bean(TbDeviceInfo.class,
|
||||||
|
tbDeviceInfo.deviceId, tbDeviceInfo.deviceName, tbDeviceInfo.state ))
|
||||||
|
.from(tbDeviceInfo)
|
||||||
|
.where(predicate).fetch();
|
||||||
|
return MapstructUtils.convert(devices, DeviceInfo.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Predicate buildQueryCondition(DeviceInfo device) {
|
||||||
|
return PredicateBuilder.instance()
|
||||||
|
.and(ObjectUtil.isNotNull(device.getId()), () -> tbDeviceInfo.id.eq(device.getId()))
|
||||||
|
.and(ObjectUtil.isNotNull(device.getState().isOnline()), () -> tbDeviceInfo.state.eq(device.getState().isOnline() ? "online" : "offline"))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import cc.iotkit.data.manager.ICategoryData;
|
||||||
import cc.iotkit.data.manager.IDeviceInfoData;
|
import cc.iotkit.data.manager.IDeviceInfoData;
|
||||||
import cc.iotkit.data.manager.IProductData;
|
import cc.iotkit.data.manager.IProductData;
|
||||||
import cc.iotkit.manager.model.stats.MainStats;
|
import cc.iotkit.manager.model.stats.MainStats;
|
||||||
|
import cc.iotkit.model.device.DeviceInfo;
|
||||||
import cc.iotkit.temporal.IThingModelMessageData;
|
import cc.iotkit.temporal.IThingModelMessageData;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
@ -50,6 +51,20 @@ public class StatsController {
|
||||||
mainStats.setCategoryTotal(ICategoryData.count());
|
mainStats.setCategoryTotal(ICategoryData.count());
|
||||||
mainStats.setProductTotal(productData.count());
|
mainStats.setProductTotal(productData.count());
|
||||||
mainStats.setDeviceTotal(deviceInfoData.count());
|
mainStats.setDeviceTotal(deviceInfoData.count());
|
||||||
|
|
||||||
|
DeviceInfo condition = new DeviceInfo();
|
||||||
|
DeviceInfo.State state = new DeviceInfo.State();
|
||||||
|
state.setOnline(true);
|
||||||
|
condition.setState(state);
|
||||||
|
mainStats.setOnlineTotal(deviceInfoData.findAllByCondition(condition).size());
|
||||||
|
|
||||||
|
state.setOnline(false);
|
||||||
|
condition.setState(state);
|
||||||
|
mainStats.setOfflineTotal(deviceInfoData.findAllByCondition(condition).size());
|
||||||
|
|
||||||
|
// 待激活设备
|
||||||
|
mainStats.setNeverOnlineTotal(deviceInfoData.findNeverUsedDevices().size());
|
||||||
|
|
||||||
mainStats.setReportTotal(thingModelMessageData.count());
|
mainStats.setReportTotal(thingModelMessageData.count());
|
||||||
//上报数据统计
|
//上报数据统计
|
||||||
mainStats.setReportDataStats(thingModelMessageData.getDeviceMessageStatsWithUid(null, now - 48 * 3600 * 1000, now));
|
mainStats.setReportDataStats(thingModelMessageData.getDeviceMessageStatsWithUid(null, now - 48 * 3600 * 1000, now));
|
||||||
|
|
|
@ -41,6 +41,21 @@ public class MainStats {
|
||||||
*/
|
*/
|
||||||
private long reportTotal;
|
private long reportTotal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在线数量
|
||||||
|
*/
|
||||||
|
private long onlineTotal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 离线数量
|
||||||
|
*/
|
||||||
|
private long offlineTotal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 待激活设备
|
||||||
|
*/
|
||||||
|
private long neverOnlineTotal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上报数据数量统计
|
* 上报数据数量统计
|
||||||
*/
|
*/
|
||||||
|
@ -51,4 +66,7 @@ public class MainStats {
|
||||||
*/
|
*/
|
||||||
private List<DataItem> deviceStatsOfCategory;
|
private List<DataItem> deviceStatsOfCategory;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue