|
|
@@ -61,6 +61,8 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
|
|
|
|
|
|
private final JPAQueryFactory jpaQueryFactory;
|
|
|
|
|
|
+ private List<String> deviceStateList = Arrays.asList("online", "offline", "unactivated");
|
|
|
+
|
|
|
@Override
|
|
|
public JpaRepository getBaseRepository() {
|
|
|
return deviceInfoRepository;
|
|
|
@@ -233,7 +235,6 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
|
|
|
query.where(tbDeviceInfo.deviceId.like("%" + keyword + "%")
|
|
|
.or(tbDeviceInfo.deviceName.like("%" + keyword + "%")));
|
|
|
}
|
|
|
-
|
|
|
query.orderBy(tbDeviceInfo.createAt.desc());
|
|
|
query.offset((page - 1) * size).limit(size);
|
|
|
|
|
|
@@ -273,8 +274,8 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
|
|
|
public List<DataItem> getDeviceStatsByCategory(String uid) {
|
|
|
//先按产品统计设备数量
|
|
|
JPAQuery<DataItem> query = jpaQueryFactory.select(Projections.bean(DataItem.class,
|
|
|
- tbDeviceInfo.productKey,
|
|
|
- tbDeviceInfo.count()))
|
|
|
+ tbDeviceInfo.productKey,
|
|
|
+ tbDeviceInfo.count()))
|
|
|
.from(tbDeviceInfo)
|
|
|
.groupBy(tbDeviceInfo.productKey);
|
|
|
|
|
|
@@ -299,7 +300,7 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
|
|
|
|
|
|
//按品类分组求合
|
|
|
rst.stream().collect(Collectors.groupingBy(DataItem::getName,
|
|
|
- Collectors.summarizingLong(item -> (long) item.getValue())))
|
|
|
+ Collectors.summarizingLong(item -> (long) item.getValue())))
|
|
|
.forEach((key, sum) -> stats.add(new DataItem(key, sum.getSum())));
|
|
|
|
|
|
return stats;
|
|
|
@@ -379,7 +380,7 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
|
|
|
|
|
|
@Override
|
|
|
public List<DeviceInfo> findByIds(Collection<String> ids) {
|
|
|
- return MapstructUtils.convert(deviceInfoRepository.findAllById(ids),DeviceInfo.class);
|
|
|
+ return MapstructUtils.convert(deviceInfoRepository.findAllById(ids), DeviceInfo.class);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -459,36 +460,140 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Map countStateMap() {
|
|
|
- Map<String,Long> resultMap = new HashMap();
|
|
|
- List<Tuple> result = jpaQueryFactory.select(tbDeviceInfo.id.count(),tbDeviceInfo.state).from(tbDeviceInfo).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")
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(String item : deviceStateList){
|
|
|
+ Long itemData = resultMap.get(item);
|
|
|
+ if(Objects.isNull(itemData)){
|
|
|
+ resultMap.put(item,0L);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Long> countStateMapWithTenantId(String tenantId) {
|
|
|
+ Map<String, Long> resultMap = new HashMap();
|
|
|
+ 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))
|
|
|
+ .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))
|
|
|
+ .fetchOne();
|
|
|
+ resultMap.put("unactivated", noRegistResult);
|
|
|
+ //
|
|
|
+ Long offlineNum = resultMap.get("offline");
|
|
|
+ if (Objects.nonNull(offlineNum)) {
|
|
|
+ resultMap.put("offline", offlineNum - noRegistResult);
|
|
|
+ }
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Long> countStateMapWithoutTenantId() {
|
|
|
+ Map<String, Long> resultMap = new HashMap();
|
|
|
+ List<Tuple> result = jpaQueryFactory.select(tbDeviceInfo.id.count(), tbDeviceInfo.state).from(tbDeviceInfo).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())).fetchOne();
|
|
|
- resultMap.put("unactivated",noRegistResult);
|
|
|
+ resultMap.put("unactivated", noRegistResult);
|
|
|
//
|
|
|
Long offlineNum = resultMap.get("offline");
|
|
|
- if(Objects.nonNull(offlineNum)){
|
|
|
- resultMap.put("offline",offlineNum-noRegistResult);
|
|
|
+ if (Objects.nonNull(offlineNum)) {
|
|
|
+ resultMap.put("offline", offlineNum - noRegistResult);
|
|
|
}
|
|
|
- return resultMap;
|
|
|
+ return resultMap;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Map countCategoryMap() {
|
|
|
- Map<String,Long> resultMap = new HashMap();
|
|
|
- List<Tuple> result = jpaQueryFactory.select(tbDeviceInfo.id.count(),tbDeviceInfo.productKey).from(tbDeviceInfo).groupBy(tbDeviceInfo.productKey).fetch();
|
|
|
- for(Tuple tuple: result){ resultMap.put(tuple.get(1,String.class),tuple.get(0,Long.class)); }
|
|
|
+ Map<String, Long> resultMap = new HashMap();
|
|
|
+ List<Tuple> result = jpaQueryFactory.select(tbDeviceInfo.id.count(), tbDeviceInfo.productKey).from(tbDeviceInfo).groupBy(tbDeviceInfo.productKey).fetch();
|
|
|
+ for (Tuple tuple : result) {
|
|
|
+ resultMap.put(tuple.get(1, String.class), tuple.get(0, Long.class));
|
|
|
+ }
|
|
|
return resultMap;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Long countTodayAdd() {
|
|
|
+ public Long countTodayAdd(String tenantId) {
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.set(Calendar.HOUR_OF_DAY,0);
|
|
|
- calendar.set(Calendar.MINUTE,0);
|
|
|
- calendar.set(Calendar.HOUR,0);
|
|
|
- calendar.set(Calendar.MILLISECOND,0);
|
|
|
+ calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ 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();
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Paging<DeviceInfo> findByConditionsAndTenantId(String uid, String subUid, String productKey, String group, String state, String keyword, Integer page, Integer size, String tenantId) {
|
|
|
+ JPAQuery<TbDeviceInfo> query = jpaQueryFactory.selectFrom(tbDeviceInfo);
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(uid)) {
|
|
|
+ query.where(tbDeviceInfo.uid.eq(uid));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(subUid)) {
|
|
|
+ query.join(tbDeviceSubUser).on(tbDeviceSubUser.deviceId.eq(tbDeviceInfo.deviceId));
|
|
|
+ query.where(tbDeviceSubUser.uid.eq(subUid));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(productKey)) {
|
|
|
+ query.where(tbDeviceInfo.productKey.eq(productKey));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(state)) {
|
|
|
+ query.where(tbDeviceInfo.state.eq(state));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(keyword)) {
|
|
|
+ query.where(tbDeviceInfo.deviceId.like("%" + keyword + "%")
|
|
|
+ .or(tbDeviceInfo.deviceName.like("%" + keyword + "%")));
|
|
|
+ }
|
|
|
+ if (tenantId != null && !tenantId.equals("000000")) {
|
|
|
+ query.leftJoin(tbProduct).on(tbProduct.productKey.eq(tbDeviceInfo.productKey)).where(tbProduct.tenantId.eq(tenantId));
|
|
|
+ }
|
|
|
+ query.orderBy(tbDeviceInfo.createAt.desc());
|
|
|
+ query.offset((page - 1) * size).limit(size);
|
|
|
+
|
|
|
+ List<TbDeviceInfo> tbDeviceInfos = query.fetch();
|
|
|
+ long total = query.fetchCount();
|
|
|
+ List<DeviceInfo> deviceInfos = new ArrayList<>(tbDeviceInfos.size());
|
|
|
+ for (TbDeviceInfo tbDeviceInfo : tbDeviceInfos) {
|
|
|
+ DeviceInfo deviceInfo = MapstructUtils.convert(tbDeviceInfo, DeviceInfo.class);
|
|
|
+ fillDeviceInfo(tbDeviceInfo.getDeviceId(), tbDeviceInfo, deviceInfo);
|
|
|
+ deviceInfos.add(deviceInfo);
|
|
|
+ }
|
|
|
+ return new Paging<>(total, deviceInfos);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long countByTenantId(String tenantId) {
|
|
|
+ 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();
|
|
|
+ } else {
|
|
|
+ return 0L;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|