改用es作为数据存储,大版本调整,增加版权信息

V0.5.x
xiwa 2022-06-21 17:00:56 +08:00
parent 6fd9f41b75
commit 58a633dbe0
233 changed files with 5836 additions and 630 deletions

1
.gitignore vendored
View File

@ -26,3 +26,4 @@ target
*.yml *.yml
log log
data/elasticsearch data/elasticsearch
.init

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iotkit-parent</artifactId> <artifactId>iotkit-parent</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.2.2-SNAPSHOT</version> <version>0.3.0-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.common; package cc.iotkit.common;
import java.io.File; import java.io.File;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.common; package cc.iotkit.common;
public interface Constants { public interface Constants {

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.common.exception; package cc.iotkit.common.exception;
public class BizException extends RuntimeException{ public class BizException extends RuntimeException{

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.common.exception; package cc.iotkit.common.exception;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.common.exception; package cc.iotkit.common.exception;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.common.thing; package cc.iotkit.common.thing;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.common.utils; package cc.iotkit.common.utils;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.common.utils; package cc.iotkit.common.utils;
import org.apache.commons.lang3.RandomUtils; import org.apache.commons.lang3.RandomUtils;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.common.utils; package cc.iotkit.common.utils;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.common.utils; package cc.iotkit.common.utils;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.common.utils; package cc.iotkit.common.utils;
@ -29,5 +38,4 @@ public class ReflectUtil {
BeanUtils.populate(to, map); BeanUtils.populate(to, map);
return to; return to;
} }
} }

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.common.utils; package cc.iotkit.common.utils;
import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ScheduledThreadPoolExecutor;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.common.utils; package cc.iotkit.common.utils;
import org.apache.commons.lang3.RandomUtils; import org.apache.commons.lang3.RandomUtils;

View File

@ -5,27 +5,22 @@
<parent> <parent>
<artifactId>iotkit-parent</artifactId> <artifactId>iotkit-parent</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.2.2-SNAPSHOT</version> <version>0.3.0-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>dao</artifactId> <artifactId>dao</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>jakarta.annotation</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId> <artifactId>jakarta.annotation-api</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-beanutils</groupId> <groupId>cn.hutool</groupId>
<artifactId>commons-beanutils</artifactId> <artifactId>hutool-core</artifactId>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -1,13 +1,20 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.aligenie.AligenieDevice; import cc.iotkit.model.aligenie.AligenieDevice;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@Repository public interface AligenieDeviceRepository extends ElasticsearchRepository<AligenieDevice, String> {
public interface AligenieDeviceRepository extends MongoRepository<AligenieDevice, String> {
void deleteByUid(String uid); void deleteByUid(String uid);

View File

@ -1,13 +1,20 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.aligenie.AligenieProduct; import cc.iotkit.model.aligenie.AligenieProduct;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@Repository public interface AligenieProductRepository extends ElasticsearchRepository<AligenieProduct, String> {
public interface AligenieProductRepository extends MongoRepository<AligenieProduct, String> {
List<AligenieProduct> findByUid(String uid); List<AligenieProduct> findByUid(String uid);

View File

@ -1,9 +1,23 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.product.AppDesign; import cc.iotkit.model.product.AppDesign;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
public interface AppDesignRepository extends ElasticsearchRepository<AppDesign, String> {
AppDesign findByProductKey(String productKey);
List<AppDesign> findByUid(String uid);
@Repository
public interface AppDesignRepository extends MongoRepository<AppDesign, String> {
} }

View File

@ -1,9 +1,16 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.AppInfo; import cc.iotkit.model.AppInfo;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
@Repository public interface AppInfoRepository extends ElasticsearchRepository<AppInfo, String> {
public interface AppInfoRepository extends MongoRepository<AppInfo, String> {
} }

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.common.Constants; import cc.iotkit.common.Constants;
@ -8,6 +17,7 @@ import org.springframework.stereotype.Repository;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
@Repository @Repository
public class CategoryCache { public class CategoryCache {

View File

@ -1,13 +1,19 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.product.Category; import cc.iotkit.model.product.Category;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
@Repository public interface CategoryRepository extends ElasticsearchRepository<Category, String> {
public interface CategoryRepository extends MongoRepository<Category, String> {
int countBy(); int countBy();
} }

View File

@ -0,0 +1,61 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao;
import cc.iotkit.model.Paging;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.SearchHit;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.data.elasticsearch.core.query.Criteria;
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
import org.springframework.data.elasticsearch.core.query.Query;
import org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.List;
@Repository
public class CommonDao {
@Autowired
private ElasticsearchRestTemplate elasticsearchRestTemplate;
/**
*
*/
public <T> Paging<T> pagedFind(Class<T> cls, Criteria condition, Sort.Order order, int size, int page) {
Query query = new CriteriaQuery(condition);
long total = elasticsearchRestTemplate.count(query, cls);
query = query.setPageable(PageRequest.of(page - 1, size, Sort.by(order)));
SearchHits<T> searchHits = elasticsearchRestTemplate.search(query, cls);
List<T> list = new ArrayList<>();
for (SearchHit<T> searchHit : searchHits) {
list.add(searchHit.getContent());
}
return new Paging<>(total, list);
}
/**
*
*/
public <T> List<T> find(Class<T> cls, Criteria condition) {
Query query = new CriteriaQuery(condition);
SearchHits<T> searchHits = elasticsearchRestTemplate.search(query, cls);
List<T> list = new ArrayList<>();
for (SearchHit<T> searchHit : searchHits) {
list.add(searchHit.getContent());
}
return list;
}
}

View File

@ -1,53 +0,0 @@
package cc.iotkit.dao;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.SneakyThrows;
import org.apache.commons.beanutils.BeanMap;
import org.springframework.data.mongodb.core.query.Update;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class DaoTool {
public static void update(Update update, List<Prop> props) {
for (Prop pro : props) {
update.set(pro.getName(), pro.getValue());
}
}
public static List<Prop> getProp(String key, Object value) {
List<Prop> props = new ArrayList<>();
if (value instanceof Map) {
Set<Map.Entry<String, Object>> entrySet = ((Map) value).entrySet();
for (Map.Entry<String, Object> entry : entrySet) {
props.addAll(getProp(key + "." + entry.getKey(), entry.getValue()));
}
} else if (value != null && !(value instanceof Class)) {
props.add(new Prop(key, value));
}
return props;
}
@SneakyThrows
public static <T> Update update(T obj) {
Map<Object, Object> pros = new BeanMap(obj);
Update update = new Update();
for (Map.Entry<Object, Object> entry : pros.entrySet()) {
update(update, DaoTool.getProp(entry.getKey().toString(), entry.getValue()));
}
return update;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
static class Prop {
private String name;
private Object value;
}
}

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.common.Constants; import cc.iotkit.common.Constants;
@ -14,7 +23,7 @@ import java.util.List;
public class DeviceCache { public class DeviceCache {
@Autowired @Autowired
private DeviceRepository deviceRepository; private DeviceInfoRepository deviceInfoRepository;
@Autowired @Autowired
private DeviceDao deviceDao; private DeviceDao deviceDao;
@ -31,12 +40,12 @@ public class DeviceCache {
@Cacheable(value = Constants.DEVICE_CACHE, key = "#pk+'_'+#dn") @Cacheable(value = Constants.DEVICE_CACHE, key = "#pk+'_'+#dn")
public DeviceInfo getDeviceInfo(String pk, String dn) { public DeviceInfo getDeviceInfo(String pk, String dn) {
return deviceRepository.findByProductKeyAndDeviceName(pk, dn); return deviceInfoRepository.findByProductKeyAndDeviceName(pk, dn);
} }
@Cacheable(value = Constants.DEVICE_CACHE, key = "#deviceId") @Cacheable(value = Constants.DEVICE_CACHE, key = "#deviceId")
public DeviceInfo get(String deviceId) { public DeviceInfo get(String deviceId) {
return deviceRepository.findById(deviceId).orElse(null); return deviceInfoRepository.findById(deviceId).orElse(null);
} }
@Cacheable(value = Constants.DEVICE_STATS_CACHE, key = "#uid") @Cacheable(value = Constants.DEVICE_STATS_CACHE, key = "#uid")

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.Paging; import cc.iotkit.model.Paging;
@ -5,16 +14,23 @@ import cc.iotkit.model.device.DeviceInfo;
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 cn.hutool.core.bean.BeanUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair; import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.mongodb.core.aggregation.*; import org.springframework.data.elasticsearch.core.ScriptType;
import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.elasticsearch.core.SearchHit;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.data.mongodb.core.query.Update; import org.springframework.data.elasticsearch.core.clients.elasticsearch7.ElasticsearchAggregations;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
import org.springframework.data.elasticsearch.core.query.*;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.ArrayList; import java.util.ArrayList;
@ -27,20 +43,25 @@ import java.util.stream.Collectors;
public class DeviceDao { public class DeviceDao {
@Autowired @Autowired
private MongoTemplate mongoTemplate; private ElasticsearchRestTemplate elasticsearchRestTemplate;
@Autowired
private DeviceInfoRepository deviceInfoRepository;
@Autowired @Autowired
private ProductRepository productRepository; private ProductRepository productRepository;
@Autowired @Autowired
private CategoryRepository categoryRepository; private CategoryRepository categoryRepository;
public Paging<DeviceInfo> find(Criteria condition, int size, int page) { public Paging<DeviceInfo> find(Criteria condition, int size, int page) {
Query query = Query.query(condition); Query query = new CriteriaQuery(condition);
return new Paging<>( long total = elasticsearchRestTemplate.count(query, DeviceInfo.class);
mongoTemplate.count(query, DeviceInfo.class), query = query.setPageable(PageRequest.of(page - 1, size, Sort.by(Sort.Order.desc("createAt"))));
mongoTemplate.find( SearchHits<DeviceInfo> searchHits = elasticsearchRestTemplate.search(query, DeviceInfo.class);
query.with(PageRequest.of(page - 1, size, Sort.by(Sort.Order.desc("createAt")))) List<DeviceInfo> list = new ArrayList<>();
, DeviceInfo.class) for (SearchHit<DeviceInfo> searchHit : searchHits) {
); list.add(searchHit.getContent());
}
return new Paging<>(total, list);
} }
/** /**
@ -50,80 +71,101 @@ public class DeviceDao {
if (properties == null) { if (properties == null) {
return; return;
} }
Query query = Query.query(new Criteria().and("deviceId").is(deviceId));
Update update = new Update(); Map<String, Object> param = new HashMap<>();
for (String key : properties.keySet()) { param.put("property", BeanUtil.beanToMap(properties));
update.set("property." + key, properties.get(key)); param.put("keys", properties.keySet());
}
mongoTemplate.updateFirst(query, update, DeviceInfo.class); UpdateQuery updateQuery = UpdateQuery.builder(new CriteriaQuery(new Criteria()
.and("deviceId").is(deviceId)))
.withParams(param)
.withScript("for(key in params.keys){ctx._source.property[key]=params.property[key];}")
.withScriptType(ScriptType.INLINE)
.build();
elasticsearchRestTemplate.updateByQuery(updateQuery, IndexCoordinates.of("device_info"));
} }
/** /**
* *
*/ */
public void updateTag(String deviceId, DeviceInfo.Tag tag) { public void updateTag(String deviceId, DeviceInfo.Tag tag) {
Query query = Query.query(new Criteria().and("deviceId").is(deviceId)); Map<String, Object> param = new HashMap<>();
Update update = new Update(); param.put("tag", BeanUtil.beanToMap(tag));
update.set("tag." + tag.getId(), tag);
mongoTemplate.updateFirst(query, update, DeviceInfo.class); UpdateQuery updateQuery = UpdateQuery.builder(new CriteriaQuery(new Criteria()
.and("deviceId").is(deviceId)))
.withParams(param)
.withScript(String.format("ctx._source.tag.%s=params.tag", tag.getId()))
.withScriptType(ScriptType.INLINE)
.build();
elasticsearchRestTemplate.updateByQuery(updateQuery, IndexCoordinates.of("device_info"));
} }
/** /**
* *
*/ */
public void setTagNull(String deviceId, String tagId) { public void setTagNull(String deviceId, String tagId) {
Query query = Query.query(new Criteria().and("deviceId").is(deviceId)); // Query query = Query.query(new Criteria().and("deviceId").is(deviceId));
Update update = new Update(); // Update update = new Update();
update.set("tag." + tagId, null); // update.set("tag." + tagId, null);
mongoTemplate.updateFirst(query, update, DeviceInfo.class); // mongoTemplate.updateFirst(query, update, DeviceInfo.class);
} }
/** /**
* *
*/ */
public List<DataItem> getDeviceStatsByCategory(String uid) { public List<DataItem> getDeviceStatsByCategory(String uid) {
MatchOperation matchOperation; BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
if (StringUtils.isBlank(uid)) { if (StringUtils.isNotBlank(uid)) {
matchOperation = Aggregation.match(new Criteria()); queryBuilder =
} else { queryBuilder.must(QueryBuilders.termQuery("uid.keyword", uid));
matchOperation = Aggregation.match(Criteria.where("uid").is(uid));
} }
//先按产品分组统计 //先按产品分组统计
GroupOperation groupOperation = Aggregation.group("productKey").count().as("total"); NativeSearchQuery query = new NativeSearchQueryBuilder()
ProjectionOperation projectionOperation = Aggregation.project("productKey", "uid"); .withQuery(queryBuilder)
Aggregation aggregation = Aggregation.newAggregation(projectionOperation, groupOperation, matchOperation); .withAggregations(
AggregationResults<Map> result = mongoTemplate.aggregate(aggregation, DeviceInfo.class, Map.class); AggregationBuilders.terms("countByPk").field("productKey.keyword")
List<Map> stats = result.getMappedResults(); .size(1000)
.subAggregation(AggregationBuilders.count("count").field("productKey.keyword"))
)
.build();
//取用户产品列表 ElasticsearchAggregations result = (ElasticsearchAggregations) elasticsearchRestTemplate
List<Product> products; .search(query, DeviceInfo.class).getAggregations();
if (StringUtils.isBlank(uid)) { ParsedStringTerms terms = result.aggregations().get("countByPk");
products = productRepository.findAll(); List<? extends Terms.Bucket> buckets = terms.getBuckets();
} else { Map<String, Long> productCount = new HashMap<>();
for (Terms.Bucket bucket : buckets) {
productCount.put(bucket.getKeyAsString(), bucket.getDocCount());
}
//取用户下产品列表
Iterable<Product> products;
if (StringUtils.isNotBlank(uid)) {
products = productRepository.findByUid(uid); products = productRepository.findByUid(uid);
} else {
products = productRepository.findAll();
} }
Map<String, String> pkCateMap = new HashMap<>(); Map<String, String> pkCateMap = new HashMap<>();
for (Product product : products) { for (Product product : products) {
pkCateMap.put(product.getId(), product.getCategory()); pkCateMap.put(product.getId(), product.getCategory());
} }
//取品类 //取品类列表
List<Category> categories = categoryRepository.findAll();
Map<String, String> cateNames = new HashMap<>(); Map<String, String> cateNames = new HashMap<>();
for (Category category : categories) { for (Category category : categoryRepository.findAll()) {
cateNames.put(category.getId(), category.getName()); cateNames.put(category.getId(), category.getName());
} }
Map<String, Long> cateStats = new HashMap<>(); Map<String, Long> cateStats = new HashMap<>();
for (Map stat : stats) { productCount.forEach((key, val) -> {
String productKey = stat.get("_id").toString(); String cateName = cateNames.get(pkCateMap.get(key));
String cateName = cateNames.get(pkCateMap.get(productKey));
//按品类汇总 //按品类汇总
long total = cateStats.getOrDefault(cateName, 0L); long total = cateStats.getOrDefault(cateName, 0L);
total += (Integer) stat.get("total"); total += val;
cateStats.put(cateName, total); cateStats.put(cateName, total);
} });
List<DataItem> items = new ArrayList<>(); List<DataItem> items = new ArrayList<>();
cateStats.forEach((key, val) -> { cateStats.forEach((key, val) -> {
@ -144,55 +186,75 @@ public class DeviceDao {
* id * id
*/ */
public List<DeviceInfo> findByGroupId(String groupId) { public List<DeviceInfo> findByGroupId(String groupId) {
Query query = Query.query(new Criteria().and("group." + groupId).exists(true)); Query query = new CriteriaQuery(new Criteria().and("group." + groupId).exists());
return mongoTemplate.find(query, DeviceInfo.class); SearchHits<DeviceInfo> searchHits = elasticsearchRestTemplate.search(query, DeviceInfo.class);
return searchHits.stream().map(SearchHit::getContent).collect(Collectors.toList());
} }
/** /**
* id * id
*/ */
public long countByGroupId(String groupId) { public long countByGroupId(String groupId) {
Query query = Query.query(new Criteria().and("group." + groupId).exists(true)); Query query = new CriteriaQuery(new Criteria().and("group." + groupId).exists());
return mongoTemplate.count(query, DeviceInfo.class); return elasticsearchRestTemplate.count(query, DeviceInfo.class);
} }
/** /**
* id * id
*/ */
public void updateGroupByDeviceId(String deviceId, DeviceInfo.Group group) { public void updateGroupByDeviceId(String deviceId, DeviceInfo.Group group) {
Query query = Query.query(new Criteria().and("deviceId").is(deviceId)); Map<String, Object> param = new HashMap<>();
Update update = new Update(); param.put("group", BeanUtil.beanToMap(group));
update.set("group." + group.getId(), group);
mongoTemplate.updateFirst(query, update, DeviceInfo.class); UpdateQuery updateQuery = UpdateQuery.builder(new CriteriaQuery(new Criteria()
.and("deviceId").is(deviceId)))
.withParams(param)
.withScript(String.format("ctx._source.group.%s=params.group", group.getId()))
.withScriptType(ScriptType.INLINE)
.build();
elasticsearchRestTemplate.updateByQuery(updateQuery, IndexCoordinates.of("device_info"));
} }
/** /**
* id * id
*/ */
public void updateGroup(String groupId, DeviceInfo.Group group) { public void updateGroup(String groupId, DeviceInfo.Group group) {
Query query = Query.query(new Criteria().and("group." + groupId).exists(true)); Map<String, Object> param = new HashMap<>();
Update update = new Update(); param.put("group", BeanUtil.beanToMap(group));
update.set("group." + group.getId(), group);
mongoTemplate.updateMulti(query, update, DeviceInfo.class); UpdateQuery updateQuery = UpdateQuery.builder(new CriteriaQuery(new Criteria()
.and("group." + groupId).exists()))
.withParams(param)
.withScript(String.format("ctx._source.group.%s=params.group", groupId))
.withScriptType(ScriptType.INLINE)
.build();
elasticsearchRestTemplate.update(updateQuery, IndexCoordinates.of("device_info"));
} }
/** /**
* *
*/ */
public void removeGroup(String deviceId, String groupId) { public void removeGroup(String deviceId, String groupId) {
Query query = Query.query(new Criteria().and("deviceId").is(deviceId).and("group." + groupId).exists(true)); UpdateQuery updateQuery = UpdateQuery.builder(new CriteriaQuery(
Update update = new Update(); Criteria.where("deviceId").is(deviceId)))
update.unset("group." + groupId); .withScript(String.format("ctx._source.group.remove('%s')", groupId))
mongoTemplate.updateFirst(query, update, DeviceInfo.class); .withScriptType(ScriptType.INLINE)
.build();
elasticsearchRestTemplate.updateByQuery(updateQuery, IndexCoordinates.of("device_info"));
} }
/** /**
* *
*/ */
public void removeGroup(String groupId) { public void removeGroup(String groupId) {
Query query = Query.query(new Criteria().and("group." + groupId).exists(true)); UpdateQuery updateQuery = UpdateQuery.builder(new CriteriaQuery(new Criteria()
Update update = new Update(); .and("group." + groupId).exists()))
update.unset("group." + groupId); .withScript(String.format("ctx._source.group.remove('%s')", groupId))
mongoTemplate.updateMulti(query, update, DeviceInfo.class); .withScriptType(ScriptType.INLINE)
.build();
elasticsearchRestTemplate.update(updateQuery, IndexCoordinates.of("device_info"));
} }
} }

View File

@ -1,13 +1,20 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.device.DeviceGroup; import cc.iotkit.model.device.DeviceGroup;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
@Repository public interface DeviceGroupRepository extends ElasticsearchRepository<DeviceGroup, String> {
public interface DeviceGroupRepository extends MongoRepository<DeviceGroup, String> {
Page<DeviceGroup> findByNameLike(String name, Pageable pageable); Page<DeviceGroup> findByNameLike(String name, Pageable pageable);

View File

@ -0,0 +1,31 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao;
import cc.iotkit.model.device.DeviceInfo;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import java.util.List;
public interface DeviceInfoRepository extends ElasticsearchRepository<DeviceInfo, String> {
DeviceInfo findByProductKeyAndDeviceName(String productKey, String deviceName);
DeviceInfo findByDeviceId(String deviceId);
List<DeviceInfo> findByParentId(String parentId);
List<DeviceInfo> findByParentIdAndUid(String parentId, String uid);
List<DeviceInfo> findByDeviceName(String deviceName);
long countByUid(String uid);
}

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.device.message.DeviceProperty; import cc.iotkit.model.device.message.DeviceProperty;

View File

@ -1,10 +1,17 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.device.message.DeviceProperty; import cc.iotkit.model.device.message.DeviceProperty;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface DevicePropertyRepository extends ElasticsearchRepository<DeviceProperty, String> { public interface DevicePropertyRepository extends ElasticsearchRepository<DeviceProperty, String> {

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.device.message.DeviceReport; import cc.iotkit.model.device.message.DeviceReport;

View File

@ -1,10 +1,17 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.device.message.DeviceReport; import cc.iotkit.model.device.message.DeviceReport;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface DeviceReportRepository extends ElasticsearchRepository<DeviceReport, String> { public interface DeviceReportRepository extends ElasticsearchRepository<DeviceReport, String> {
long countByUid(String uid); long countByUid(String uid);

View File

@ -1,22 +0,0 @@
package cc.iotkit.dao;
import cc.iotkit.model.device.DeviceInfo;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface DeviceRepository extends MongoRepository<DeviceInfo, String> {
DeviceInfo findByProductKeyAndDeviceName(String productKey, String deviceName);
DeviceInfo findByDeviceId(String deviceId);
List<DeviceInfo> findByParentId(String parentId);
List<DeviceInfo> findByDeviceName(String deviceName);
long countByUid(String uid);
}

View File

@ -1,15 +1,25 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.space.Home; import cc.iotkit.model.space.Home;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@Repository public interface HomeRepository extends ElasticsearchRepository<Home, String> {
public interface HomeRepository extends MongoRepository<Home, String> {
List<Home> findByUid(String uid); List<Home> findByUid(String uid);
Home findByUidAndCurrent(String uid,boolean current); Home findByUidAndCurrent(String uid, boolean current);
Home findByUidAndId(String uid, String id);
} }

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.common.Constants; import cc.iotkit.common.Constants;

View File

@ -1,11 +1,18 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.OauthClient; import cc.iotkit.model.OauthClient;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
@Repository public interface OauthClientRepository extends ElasticsearchRepository<OauthClient, String> {
public interface OauthClientRepository extends MongoRepository<OauthClient, String> {
} }

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.common.Constants; import cc.iotkit.common.Constants;

View File

@ -1,13 +1,20 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.product.ProductModel; import cc.iotkit.model.product.ProductModel;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@Repository public interface ProductModelRepository extends ElasticsearchRepository<ProductModel, String> {
public interface ProductModelRepository extends MongoRepository<ProductModel, String> {
ProductModel findByModel(String model); ProductModel findByModel(String model);

View File

@ -1,15 +1,25 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.product.Product; import cc.iotkit.model.product.Product;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@Repository public interface ProductRepository extends ElasticsearchRepository<Product, String> {
public interface ProductRepository extends MongoRepository<Product, String> {
long countByUid(String uid); long countByUid(String uid);
List<Product> findByUid(String uid); List<Product> findByUid(String uid);
List<Product> findByCategory(String category);
} }

View File

@ -1,13 +1,20 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.protocol.ProtocolComponent; import cc.iotkit.model.protocol.ProtocolComponent;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@Repository public interface ProtocolComponentRepository extends ElasticsearchRepository<ProtocolComponent, String> {
public interface ProtocolComponentRepository extends MongoRepository<ProtocolComponent, String> {
List<ProtocolComponent> findByState(String state); List<ProtocolComponent> findByState(String state);

View File

@ -1,9 +1,16 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.protocol.ProtocolConverter; import cc.iotkit.model.protocol.ProtocolConverter;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
@Repository public interface ProtocolConverterRepository extends ElasticsearchRepository<ProtocolConverter, String> {
public interface ProtocolConverterRepository extends MongoRepository<ProtocolConverter, String> {
} }

View File

@ -1,11 +0,0 @@
package cc.iotkit.dao;
import cc.iotkit.model.protocol.ProtocolComponent;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface ProtocolGatewayRepository extends MongoRepository<ProtocolComponent, String> {
}

View File

@ -1,14 +1,27 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.rule.RuleInfo; import cc.iotkit.model.rule.RuleInfo;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.domain.Page;
import org.springframework.stereotype.Repository; import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import java.util.List; import java.util.List;
@Repository public interface RuleInfoRepository extends ElasticsearchRepository<RuleInfo, String> {
public interface RuleInfoRepository extends MongoRepository<RuleInfo, String> {
List<RuleInfo> findByUidAndType(String uid, String type); List<RuleInfo> findByUidAndType(String uid, String type);
Page<RuleInfo> findByUidAndType(String uid, String type, Pageable pageable);
Page<RuleInfo> findByType(String type, Pageable pageable);
} }

View File

@ -1,12 +1,19 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.rule.RuleLog; import cc.iotkit.model.rule.RuleLog;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface RuleLogRepository extends ElasticsearchRepository<RuleLog, String> { public interface RuleLogRepository extends ElasticsearchRepository<RuleLog, String> {
void deleteByRuleId(String ruleId); void deleteByRuleId(String ruleId);

View File

@ -1,18 +1,29 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.space.SpaceDevice; import cc.iotkit.model.space.SpaceDevice;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@Repository public interface SpaceDeviceRepository extends ElasticsearchRepository<SpaceDevice, String> {
public interface SpaceDeviceRepository extends MongoRepository<SpaceDevice, String> {
List<SpaceDevice> findByUidOrderByUseAtDesc(String uid); List<SpaceDevice> findByUidOrderByUseAtDesc(String uid);
List<SpaceDevice> findByUidOrderByAddAtDesc(String uid); List<SpaceDevice> findByUidOrderByAddAtDesc(String uid);
List<SpaceDevice> findByUid(String uid);
List<SpaceDevice> findBySpaceIdOrderByAddAtDesc(String spaceId);
List<SpaceDevice> findByUidAndSpaceIdOrderByAddAtDesc(String uid, String spaceId); List<SpaceDevice> findByUidAndSpaceIdOrderByAddAtDesc(String uid, String spaceId);
SpaceDevice findByDeviceId(String deviceId); SpaceDevice findByDeviceId(String deviceId);

View File

@ -1,16 +1,25 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.space.Space; import cc.iotkit.model.space.Space;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@Repository public interface SpaceRepository extends ElasticsearchRepository<Space, String> {
public interface SpaceRepository extends MongoRepository<Space, String> {
List<Space> findByUidOrderByCreateAtDesc(String uid); List<Space> findByUidOrderByCreateAtDesc(String uid);
List<Space> findByUidAndHomeIdOrderByCreateAtDesc(String uid, String homeId); List<Space> findByUidAndHomeIdOrderByCreateAtDesc(String uid, String homeId);
List<Space> findByHomeId(String homeId);
} }

View File

@ -1,9 +1,21 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.rule.TaskInfo; import cc.iotkit.model.rule.TaskInfo;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
public interface TaskInfoRepository extends ElasticsearchRepository<TaskInfo, String> {
List<TaskInfo> findByUid(String uid);
@Repository
public interface TaskInfoRepository extends MongoRepository<TaskInfo, String> {
} }

View File

@ -1,12 +1,19 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.rule.TaskLog; import cc.iotkit.model.rule.TaskLog;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface TaskLogRepository extends ElasticsearchRepository<TaskLog, String> { public interface TaskLogRepository extends ElasticsearchRepository<TaskLog, String> {
void deleteByTaskId(String taskId); void deleteByTaskId(String taskId);

View File

@ -1,12 +1,19 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.device.message.ThingModelMessage; import cc.iotkit.model.device.message.ThingModelMessage;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface ThingModelMessageRepository extends ElasticsearchRepository<ThingModelMessage, String> { public interface ThingModelMessageRepository extends ElasticsearchRepository<ThingModelMessage, String> {
Page<ThingModelMessage> findByTypeAndIdentifier(String type, String identifier, Pageable pageable); Page<ThingModelMessage> findByTypeAndIdentifier(String type, String identifier, Pageable pageable);

View File

@ -1,11 +1,18 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.product.ThingModel; import cc.iotkit.model.product.ThingModel;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
@Repository public interface ThingModelRepository extends ElasticsearchRepository<ThingModel, String> {
public interface ThingModelRepository extends MongoRepository<ThingModel, String> {
ThingModel findByProductKey(String productKey); ThingModel findByProductKey(String productKey);

View File

@ -1,11 +1,9 @@
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.ThirdUserSession; import cc.iotkit.model.ThirdUserSession;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
@Repository public interface ThirdUserSessionRepository extends ElasticsearchRepository<ThirdUserSession, String> {
public interface ThirdUserSessionRepository extends MongoRepository<ThirdUserSession, String> {
} }

View File

@ -1,10 +1,17 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.UserActionLog; import cc.iotkit.model.UserActionLog;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
@Repository public interface UserActionLogRepository extends ElasticsearchRepository<UserActionLog, String> {
public interface UserActionLogRepository extends MongoRepository<UserActionLog, String> {
} }

View File

@ -1,13 +1,20 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.UserInfo; import cc.iotkit.model.UserInfo;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@Repository public interface UserInfoRepository extends ElasticsearchRepository<UserInfo, String> {
public interface UserInfoRepository extends MongoRepository<UserInfo, String> {
UserInfo findByUid(String uid); UserInfo findByUid(String uid);

View File

@ -1,12 +1,19 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.device.VirtualDeviceLog; import cc.iotkit.model.device.VirtualDeviceLog;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface VirtualDeviceLogRepository extends ElasticsearchRepository<VirtualDeviceLog, String> { public interface VirtualDeviceLogRepository extends ElasticsearchRepository<VirtualDeviceLog, String> {
Page<VirtualDeviceLog> findByVirtualDeviceId(String virtualDeviceId, Pageable pageable); Page<VirtualDeviceLog> findByVirtualDeviceId(String virtualDeviceId, Pageable pageable);

View File

@ -1,15 +1,22 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao; package cc.iotkit.dao;
import cc.iotkit.model.device.VirtualDevice; import cc.iotkit.model.device.VirtualDevice;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@Repository public interface VirtualDeviceRepository extends ElasticsearchRepository<VirtualDevice, String> {
public interface VirtualDeviceRepository extends MongoRepository<VirtualDevice, String> {
Page<VirtualDevice> findByUid(String uid, Pageable pageable); Page<VirtualDevice> findByUid(String uid, Pageable pageable);

View File

@ -1,3 +1,13 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.dao.config; package cc.iotkit.dao.config;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;

View File

@ -1,48 +0,0 @@
package cc.iotkit.dao.config;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.context.annotation.*;
import org.springframework.data.convert.CustomConversions;
import org.springframework.data.mongodb.MongoDatabaseFactory;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.convert.*;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import java.util.Collections;
@Configuration
@Import(value = MongoAutoConfiguration.class)
@EnableMongoRepositories(basePackages = "cc.iotkit.dao", includeFilters = @ComponentScan.Filter(
type = FilterType.ASSIGNABLE_TYPE, value = MongoRepository.class))
public class RepositoryConfig {
@Bean
public MappingMongoConverter mappingMongoConverter(
MongoDatabaseFactory factory,
MongoMappingContext context,
BeanFactory beanFactory) {
DbRefResolver dbRefResolver = new DefaultDbRefResolver(factory);
MappingMongoConverter mappingMongoConverter = new MappingMongoConverter(dbRefResolver, context);
mappingMongoConverter.setCustomConversions(beanFactory.getBean(CustomConversions.class));
mappingMongoConverter.setTypeMapper(new DefaultMongoTypeMapper(null));
return mappingMongoConverter;
}
@Bean
@ConditionalOnMissingBean({MongoOperations.class})
MongoTemplate mongoTemplate(MongoDatabaseFactory factory, MongoConverter converter) {
return new MongoTemplate(factory, converter);
}
@Bean
@Primary
MongoCustomConversions mongoCustomConversions() {
return new MongoCustomConversions(Collections.emptyList());
}
}

42
data/init/category.json Normal file
View File

@ -0,0 +1,42 @@
[
{
"id": "switch",
"name": "开关",
"createAt": 1647599367057
},
{
"id": "sensor",
"name": "传感器",
"createAt": 1649743382683
},
{
"id": "meter",
"name": "表计",
"createAt": 1654237582120
},
{
"id": "light",
"name": "灯",
"createAt": 1650174762755
},
{
"id": "gateway",
"name": "网关",
"createAt": 1646637047902
},
{
"id": "fan",
"name": "风扇",
"createAt": 1646630215889
},
{
"id": "door",
"name": "门磁",
"createAt": 1650173898298
},
{
"id": "SmartPlug",
"name": "智能插座",
"createAt": 1645409421118
}
]

View File

@ -0,0 +1,26 @@
[
{
"id": "g3",
"name": "组3",
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"remark": "2223333",
"deviceQty": 7,
"createAt": 0
},
{
"id": "g2",
"name": "组2",
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"remark": "222",
"deviceQty": 12,
"createAt": 0
},
{
"id": "g1",
"name": "分组1",
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"remark": "1111",
"deviceQty": 10,
"createAt": 0
}
]

1655
data/init/deviceInfo.json Normal file

File diff suppressed because it is too large Load Diff

54
data/init/home.json Normal file
View File

@ -0,0 +1,54 @@
[
{
"id": "629e1d80a176d816952f1e82",
"name": "我的家庭",
"address": "",
"uid": "629e1d7fa176d816952f1e81",
"spaceNum": 0,
"deviceNum": 0,
"current": true
},
{
"id": "629e18e96b16ad6a3e158645",
"name": "我的家",
"uid": "629daa3de5a005209d182876",
"current": true
},
{
"id": "6238a49fecf37861bed7ad11",
"name": "我深圳的家",
"address": "广东省深圳市南山区西丽镇",
"uid": "04c6722f-9a6d-40f3-ac9b-cd791b4c8933",
"current": true
},
{
"id":"6238a485ecf37861bed7ad10",
"name": "我深圳的家",
"address": "广东省深圳市南山区西丽镇",
"uid": "232f506f-76c0-46eb-890b-15edd1022ba1"
},
{
"id": "6238a2caecf37861bed7ad0f",
"name": "我深圳的家",
"address": "广东省深圳市南山区西丽镇",
"uid": "232f506f-76c0-46eb-890b-15edd1022ba1"
},
{
"id": "6238a2adecf37861bed7ad0e",
"name": "我深圳的家",
"address": "广东省深圳市南山区西丽镇",
"uid": "232f506f-76c0-46eb-890b-15edd1022ba1"
},
{
"id": "61bafc1e16cb60612ab95f98",
"name": "myhome",
"address": "shengzhen nanshan",
"uid": "183b4732-ce7f-4e4c-9c18-7e49fbf45579"
},
{
"id": "61bafb6fb8477d132da69513",
"name": "myhome",
"address": "shengzhen nanshan",
"uid": "183b4732-ce7f-4e4c-9c18-7e49fbf45579"
}
]

View File

@ -0,0 +1,16 @@
[
{
"id": "iotkit",
"name": "奇特物联",
"clientSecret": "b86cb53d-c005-48a3-bb02-3c262151b68c",
"allowUrl": "*",
"createAt": 1652840868485
},
{
"id": "dueros",
"name": "小度音箱",
"clientSecret": "750c67c2-29cb-40c3-bf4d-c0b9bf3eed88",
"allowUrl": "*",
"createAt": 1652840868485
}
]

133
data/init/product.json Normal file
View File

@ -0,0 +1,133 @@
[
{
"id": "xpsYHExTKPFaQMS7",
"name": "调光灯",
"category": "light",
"nodeType": 1,
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"createAt": 1650174777304
},
{
"id": "hdX3PCMcFrCYpesJ",
"code": "hdX3PCMcFrCYpesJ",
"name": "智能风扇",
"category": "fan",
"nodeType": 1,
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"createAt": 1646571291131
},
{
"id": "hbtgIA0SuVw9lxjB",
"name": "GW01网关",
"category": "gateway",
"nodeType": 0,
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"img": "http://iotkit-img.oss-cn-shenzhen.aliyuncs.com/product/hbtgIA0SuVw9lxjB/cover.jpg?Expires=1967598154&OSSAccessKeyId=LTAI5tGEHNoVu5tWHUWnosrs&Signature=2gh2jad14mVHGvWThwOd%2FykiB5g%3D",
"transparent": false,
"createAt": 1652238155938
},
{
"id": "eDhXKwEzwFybM5R7",
"name": "三路开关",
"category": "switch",
"nodeType": 1,
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"img": "http://iotkit-img.oss-cn-shenzhen.aliyuncs.com/product/eDhXKwEzwFybM5R7/cover.jpeg?Expires=1967598172&OSSAccessKeyId=LTAI5tGEHNoVu5tWHUWnosrs&Signature=ZrFgANkomVEDQRV5JdmONL0S2sY%3D",
"transparent": false,
"createAt": 1652238173536
},
{
"id": "cGCrkK7Ex4FESAwe",
"name": "插座",
"category": "SmartPlug",
"nodeType": 1,
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"img": "http://iotkit-img.oss-cn-shenzhen.aliyuncs.com/product/cGCrkK7Ex4FESAwe/cover.jpeg?Expires=1967598137&OSSAccessKeyId=LTAI5tGEHNoVu5tWHUWnosrs&Signature=vOjqav0pRZqQFgx8xBo99WhgWXk%3D",
"transparent": false,
"createAt": 1652238138626
},
{
"id": "Rf4QSjbm65X45753",
"name": "一路开关",
"category": "switch",
"nodeType": 1,
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"img": "http://iotkit-img.oss-cn-shenzhen.aliyuncs.com/product/Rf4QSjbm65X45753/cover.jpeg?Expires=1967598145&OSSAccessKeyId=LTAI5tGEHNoVu5tWHUWnosrs&Signature=ksQhmEm5Rn7C7FFqY09o9l%2BZ%2BIQ%3D",
"transparent": false,
"createAt": 1652238147123
},
{
"id": "PN3EDmkBZDD8whDd",
"name": "门磁",
"category": "door",
"nodeType": 1,
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"img": "null",
"createAt": 1650190400357
},
{
"id": "N523nWsCiG3CAn6X",
"name": "ZGW01",
"category": "gateway",
"nodeType": 0,
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"img": "http://iotkit-img.oss-cn-shenzhen.aliyuncs.com/product/N523nWsCiG3CAn6X/cover.jpg?Expires=1967597641&OSSAccessKeyId=LTAI5tGEHNoVu5tWHUWnosrs&Signature=%2BaGcHBT%2FHA3s%2BrZ687U50b4YE0A%3D",
"transparent": false,
"createAt": 1652237643216
},
{
"id": "KdJYpTp5ywNhmrmC",
"name": "第三方接入",
"category": "",
"nodeType": 0,
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"img": "http://iotkit-img.oss-cn-shenzhen.aliyuncs.com/product/KdJYpTp5ywNhmrmC/cover.png?Expires=1968261336&OSSAccessKeyId=LTAI5t8UFEH5eGrBUS5zSiof&Signature=df%2F6JEcxBlXitSNIENPMYJlRE8Y%3D",
"transparent": false,
"createAt": 1655637610215
},
{
"id": "Eit3kmGJtxSHfCKT",
"name": "燃气表",
"category": "meter",
"nodeType": 2,
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"transparent": false,
"createAt": 1654237604221
},
{
"id": "DSGxxKk6E8mmDk6C",
"name": "通断器",
"category": "switch",
"nodeType": 1,
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"img": "http://iotkit-img.oss-cn-shenzhen.aliyuncs.com/product/DSGxxKk6E8mmDk6C/cover.jpeg?Expires=1967598201&OSSAccessKeyId=LTAI5tGEHNoVu5tWHUWnosrs&Signature=k2PqHc%2BI14DfCwD8kQIflwoBAog%3D",
"transparent": false,
"createAt": 1652238202310
},
{
"id": "D8c5pXFmt2KJDxNm",
"name": "四路场景面板",
"category": "switch",
"nodeType": 1,
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"createAt": 1650187781637
},
{
"id": "AWcJnf7ymGSkaz5M",
"name": "smart pulg",
"category": "SmartPlug",
"nodeType": 1,
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"img": "http://iotkit-img.oss-cn-shenzhen.aliyuncs.com/product/AWcJnf7ymGSkaz5M/cover.jpeg?Expires=1967598035&OSSAccessKeyId=LTAI5tGEHNoVu5tWHUWnosrs&Signature=tXzWH5%2B4JNcnuTFrJbvGwsbx97c%3D",
"transparent": true,
"createAt": 1652279098100
},
{
"id": "6kYp6jszrDns2yh4",
"name": "温湿度传感器",
"category": "sensor",
"nodeType": 1,
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"createAt": 1649653149339
}
]

View File

@ -0,0 +1,11 @@
[
{
"id": "M1",
"name": "型号1",
"productKey": "AWcJnf7ymGSkaz5M",
"type": "LuaScript",
"script": "\nfunction decode(msg)\n return {\n ['identifier'] = 'report',\n ['mid'] = '1',\n ['type'] = 'property',\n ['data'] ={\n ['power']=string.sub(msg.data,3,3)\n }\n }\nend\n\nfunction encode(service)\n return {\n\t['mid'] = 1,\n\t['model'] = 'M1',\n\t['mac'] = service.deviceName,\n\t['data'] = 'BB2'\n }\nend\n",
"state": "publish",
"modifyAt": 1651466083339
}
]

View File

@ -0,0 +1,62 @@
[
{
"id": "fee0e826-963f-4e53-a2cf-11e3e5f784ea",
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"name": "移动Onenet Studio接入",
"type": "biz",
"protocol": "http",
"jarFile": "http-biz-component-0.1.0-SNAPSHOT.jar",
"config": "{\"port\":\"8086\"}",
"converter": "6260396d67aced2696184053",
"state": "running",
"createAt": 1652238780184
},
{
"id": "eabb131d-8fd1-43a8-88d9-a198abfd3d42",
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"name": "MQTT标准协议组件",
"type": "device",
"protocol": "mqtt",
"jarFile": "mqtt-component-0.2.1-SNAPSHOT.jar",
"config": "{\"port\":1883,\"ssl\":false,\"type\":\"server\"}",
"converter": "6260396d67aced2696184053",
"state": "running",
"createAt": 1650473458084
},
{
"id": "cd8253c1-b489-434c-845d-d18c7b70dcea",
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"name": "电信NB协议接入组件",
"type": "device",
"protocol": "http",
"jarFile": "ctwing-component-0.2.1-SNAPSHOT.jar",
"config": "{\"port\":\"8087\"}",
"converter": "62995ba4dbf51a5ec41d5f7b",
"state": "stopped",
"createAt": 1654235056032
},
{
"id": "6c095554-35e7-4e9d-a8d2-bb919e9479f4",
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"name": "EMQX标准协议组件",
"type": "device",
"protocol": "mqtt",
"jarFile": "emqx-component-0.2.1-SNAPSHOT.jar",
"config": "{\"port\":\"1884\",\"ssl\":false,\"type\":\"client\",\"subscribeTopics\":[\"/sys/+/+/s/#\",\"/sys/client/connected\",\"/sys/client/disconnected\",\"/sys/session/subscribed\",\"/sys/session/unsubscribed\"],\"authPort\":\"8088\",\"broker\":\"127.0.0.1\",\"clientId\":\"test\",\"username\":\"test\",\"password\":\"123\"}",
"converter": "6260396d67aced2696184053",
"state": "running",
"createAt": 1653180468724
},
{
"id": "3ababc5e-15e9-45a7-8f38-2a6afd45c780",
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"name": "小度音箱接入组件",
"type": "biz",
"protocol": "http",
"jarFile": "http-biz-component-0.1.0-SNAPSHOT.jar",
"config": "{\"port\":\"8084\"}",
"converter": "",
"state": "running",
"createAt": 1650685502665
}
]

View File

@ -0,0 +1,23 @@
[
{
"id": "62995ba4dbf51a5ec41d5f7b",
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"name": "自定义表计协议",
"desc": "用于燃气表的协议",
"createAt": 1654217636597
},
{
"id": "628ceb14addfdb2a3b4b5727",
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"name": "奇特HTTP标准协议",
"desc": "奇特HTTP标准协议转换器",
"createAt": 1653402388275
},
{
"id": "6260396d67aced2696184053",
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"name": "奇特MQTT标准协议",
"desc": "奇特MQTT标准协议转换器",
"createAt": 1650473325173
}
]

95
data/init/ruleInfo.json Normal file
View File

@ -0,0 +1,95 @@
[
{
"id": "6b253651-f4f9-44b9-a802-115b668b68e1",
"name": "天猫精灵设备属性和状态推送",
"type": "flow",
"listeners": [
{
"type": "device",
"config": "{\"id\":\"077319c3-325b-4bb6-8e07-dd2eed617f6f\",\"type\":\"device\",\"topic\":\"\",\"conditions\":[{\"id\":0.6683545166149798,\"type\":\"property\",\"device\":\"cGCrkK7Ex4FESAwe/#\",\"identifier\":\"report\",\"parameters\":[{\"identifier\":\"powerstate\",\"comparator\":\"*\"}]},{\"id\":0.6047040921280786,\"type\":\"state\",\"device\":\"cGCrkK7Ex4FESAwe/#\",\"identifier\":\"state:*\",\"parameters\":[]}]}"
},
{
"type": "device",
"config": "{\"id\":\"08d72321-39d4-4dcc-ba69-b09c4af187a3\",\"type\":\"device\",\"topic\":\"\",\"conditions\":[{\"id\":0.7992853094329277,\"type\":\"event\",\"device\":\"KdJYpTp5ywNhmrmC/001\",\"identifier\":\"userDevicesChange\",\"parameters\":[{\"comparator\":\"*\"}]}]}"
},
{
"type": "device",
"config": "{\"id\":\"554aba1c-9684-4e36-8f72-cdb325f86712\",\"type\":\"device\",\"topic\":\"\",\"conditions\":[{\"id\":0.9179545682030454,\"type\":\"property\",\"device\":\"PN3EDmkBZDD8whDd/#\",\"identifier\":\"report\",\"parameters\":[{\"identifier\":\"doorStatus\",\"comparator\":\"*\"}]}]}"
}
],
"filters": [
{
"type": "device",
"config": "{\"id\":\"0a8285df-f778-4e20-b26b-2b569fc1d3dd\",\"type\":\"device\",\"conditions\":[{\"id\":0.11425312074571847,\"device\":\"\",\"type\":\"tag\",\"identifier\":\"aligenie\",\"value\":\"是\",\"comparator\":\"==\"}]}"
}
],
"actions": [
{
"type": "http",
"config": "{\"id\":\"de533da1-18cb-48ef-b913-22bdd96dcac9\",\"type\":\"http\",\"services\":[{\"url\":\"http://localhost:8087/aligenie/push\",\"script\":\"this.translate=function(msg){\\n var data={};\\n for(var p in msg.data){\\n\\tdata[p]=msg.data[p];\\n }\\n \\nreturn {\\n\\t//指定相对路径\\n path:\\\"/\\\",\\n method:\\\"post\\\",\\n header:{\\n //指定请求头\\n contentType:\\\"application/json; charset=utf-8\\\"\\n },\\n body:JSON.stringify({\\n deviceId:msg.deviceId,\\n type:msg.type,\\n identifier:msg.identifier,\\n data:data\\n })\\n }\\n}\"}]}"
}
],
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"state": "stopped",
"desc": "ss",
"createAt": 1649218592640
},
{
"id": "2c10229b-dcb2-439e-b411-5425b49657a1",
"name": "小度设备属性更新推送",
"type": "flow",
"listeners": [
{
"type": "device",
"config": "{\"id\":\"11ae4827-d58b-44d7-8a4d-090bac2ddce8\",\"type\":\"device\",\"topic\":\"\",\"conditions\":[{\"id\":0.5375444987425966,\"type\":\"property\",\"device\":\"cGCrkK7Ex4FESAwe/#\",\"identifier\":\"report\",\"parameters\":[{\"identifier\":\"powerstate\",\"comparator\":\"*\"}]}]}"
},
{
"type": "device",
"config": "{\"id\":\"f0752ba9-38d8-4ee8-91cc-7f267875c358\",\"type\":\"device\",\"topic\":\"\",\"conditions\":[{\"id\":0.20619179667807042,\"type\":\"property\",\"device\":\"Rf4QSjbm65X45753/#\",\"identifier\":\"report\",\"parameters\":[{\"identifier\":\"powerstate\",\"comparator\":\"*\"}]}]}"
}
],
"filters": [
{
"type": "device",
"config": "{\"id\":\"747eb070-92ed-4e60-9a39-3b9a71afee9e\",\"type\":\"device\",\"conditions\":[{\"id\":0.7199397992080254,\"device\":\"\",\"type\":\"tag\",\"comparator\":\"==\",\"identifier\":\"dueros\",\"value\":\"是\"}]}"
}
],
"actions": [
{
"type": "http",
"config": "{\"id\":\"35781aae-360f-4931-9d72-69f27e326e68\",\"type\":\"http\",\"services\":[{\"url\":\"https://xiaodu.baidu.com/saiya/smarthome/changereport\",\"script\":\"this.translate=function(msg,device){\\n var pk=msg.productKey;\\n var attributeName=\\\"\\\";\\n //插座/开关\\n if(pk==\\\"cGCrkK7Ex4FESAwe\\\" || pk==\\\"Rf4QSjbm65X45753\\\"){\\n\\tattributeName=\\\"turnOnState\\\";\\n }\\n //取openUid\\n var tag=device.tag;\\n if(!tag || !tag.duerosOpenUid){\\n\\treturn null;\\n }\\n var openUid=tag.duerosOpenUid.value;\\n \\n return {\\n \\\"path\\\":\\\"\\\",\\n \\\"method\\\":\\\"post\\\",\\n \\\"header\\\":{\\n //指定请求头\\n \\\"contentType\\\":\\\"application/json; charset=utf-8\\\"\\n },\\n \\\"body\\\":JSON.stringify({\\n\\t \\\"header\\\": {\\n\\t\\t \\\"namespace\\\": \\\"DuerOS.ConnectedHome.Control\\\",\\n\\t\\t \\\"name\\\": \\\"ChangeReportRequest\\\",\\n\\t\\t \\\"messageId\\\": new Date().getTime()+\\\"\\\",\\n\\t\\t \\\"payloadVersion\\\": \\\"1\\\"\\n\\t },\\n\\t \\\"payload\\\": {\\n\\t\\t \\\"botId\\\": \\\"eb20e515-f505-8d31-abef-46da3345f114\\\",\\n\\t\\t \\\"openUid\\\": openUid,\\n\\t\\t \\\"appliance\\\": {\\n\\t\\t\\t \\\"applianceId\\\": msg.deviceId,\\n\\t\\t\\t \\\"attributeName\\\": attributeName\\n\\t\\t }\\n\\t }\\n \\t})\\n }\\n}\"}]}"
}
],
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"state": "running",
"desc": "开关插座开关状态推送",
"createAt": 1652515471242
},
{
"id": "2820c218-660e-48ff-a234-c7b6793a5bb8",
"name": "测试场景1",
"type": "scene",
"listeners": [
{
"type": "device",
"config": "{\"id\":\"4ff98e8c-e6f6-4e96-8932-de488a0a4bfb\",\"type\":\"device\",\"topic\":\"\",\"conditions\":[{\"id\":0.8212160690052512,\"type\":\"property\",\"device\":\"Rf4QSjbm65X45753/ABC12400001\",\"identifier\":\"report\",\"parameters\":[{\"identifier\":\"powerstate\",\"comparator\":\">\",\"value\":\"0\"}]}]}"
}
],
"filters": [
{
"type": "device",
"config": "{\"id\":\"24b4b975-d8ac-431d-881d-8c8b40e92861\",\"type\":\"device\",\"conditions\":[{\"id\":0.08981222614734863,\"device\":\"hdX3PCMcFrCYpesJ/ABD12300002\",\"identifier\":\"powerSwitch\",\"type\":\"property\",\"comparator\":\"==\",\"value\":\"0\"}]}"
}
],
"actions": [
{
"type": "device",
"config": "{\"id\":\"fde024b5-5105-4639-8602-d04300613af9\",\"type\":\"device\",\"services\":[{\"device\":\"hdX3PCMcFrCYpesJ/ABD12300002\",\"identifier\":\"set\",\"inputData\":[{\"identifier\":\"powerSwitch\",\"value\":\"1\"}]},{\"device\":\"hdX3PCMcFrCYpesJ/ABD12300002\",\"identifier\":\"set\",\"inputData\":[{\"identifier\":\"windSpeed\",\"value\":\"20\"}]}]}"
}
],
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"state": "stopped",
"desc": "test",
"createAt": 1649167998895
}
]

65
data/init/space.json Normal file
View File

@ -0,0 +1,65 @@
[
{
"id": "62a6a897f60ef7500d1a916b",
"homeId": "6238a49fecf37861bed7ad11",
"uid": "04c6722f-9a6d-40f3-ac9b-cd791b4c8933",
"name": "123",
"createAt": 1655089303228
},
{
"id": "62a6a894f60ef7500d1a916a",
"homeId": "6238a49fecf37861bed7ad11",
"uid": "04c6722f-9a6d-40f3-ac9b-cd791b4c8933",
"name": "123",
"createAt": 1655089300741
},
{
"id": "629e233be0dc6d4171e1a023",
"homeId": "629e1d80a176d816952f1e82",
"uid": "629e1d7fa176d816952f1e81",
"name": "客厅",
"createAt": 1654530875839
},
{
"id": "629e18fee0dc6d4171e1a021",
"homeId": "629e18e96b16ad6a3e158645",
"uid": "629daa3de5a005209d182876",
"name": "卧室",
"createAt": 1654528254438
},
{
"id": "629e18f3e0dc6d4171e1a020",
"homeId": "629e18e96b16ad6a3e158645",
"uid": "629daa3de5a005209d182876",
"name": "客厅",
"createAt": 1654528243058
},
{
"id": "62794a820b0776663635e636",
"homeId": "6238a49fecf37861bed7ad11",
"uid": "04c6722f-9a6d-40f3-ac9b-cd791b4c8933",
"name": "阳台",
"createAt": 1652116098020
},
{
"id": "62794a7d0b0776663635e635",
"homeId": "6238a49fecf37861bed7ad11",
"uid": "04c6722f-9a6d-40f3-ac9b-cd791b4c8933",
"name": "厨房",
"createAt": 1652116093323
},
{
"id": "62794a740b0776663635e634",
"homeId": "6238a49fecf37861bed7ad11",
"uid": "04c6722f-9a6d-40f3-ac9b-cd791b4c8933",
"name": "卧室",
"createAt": 1652116084721
},
{
"id": "62794a5c0b0776663635e633",
"homeId": "6238a49fecf37861bed7ad11",
"uid": "04c6722f-9a6d-40f3-ac9b-cd791b4c8933",
"name": "客厅",
"createAt": 1652116060926
}
]

101
data/init/spaceDevice.json Normal file
View File

@ -0,0 +1,101 @@
[
{
"id": "629f5821e0dc6d4171e1a029",
"uid": "629daa3de5a005209d182876",
"deviceId": "164785263238900cefafcfeeab0000125",
"name": "卧室的ZGW01",
"homeId": "629e18e96b16ad6a3e158645",
"spaceId": "629e18fee0dc6d4171e1a021",
"addAt": 1654609953349
},
{
"id": "629f581ee0dc6d4171e1a028",
"uid": "629daa3de5a005209d182876",
"deviceId": "164776322117404acb9f03008d1500168",
"name": "卧室的插座",
"homeId": "629e18e96b16ad6a3e158645",
"spaceId": "629e18fee0dc6d4171e1a021",
"addAt": 1654609950464,
"useAt": 1655653227177
},
{
"id": "629f581ce0dc6d4171e1a027",
"uid": "629daa3de5a005209d182876",
"deviceId": "1647763221972019a89f03008d1500163",
"name": "卧室的插座",
"homeId": "629e18e96b16ad6a3e158645",
"spaceId": "629e18fee0dc6d4171e1a021",
"addAt": 1654609948550,
"useAt": 1655653294372
},
{
"id": "629f581ae0dc6d4171e1a026",
"uid": "629daa3de5a005209d182876",
"deviceId": "164776322227201472a803008d150016e",
"name": "卧室的插座",
"homeId": "629e18e96b16ad6a3e158645",
"spaceId": "629e18fee0dc6d4171e1a021",
"addAt": 1654609946750,
"useAt": 1655653552172
},
{
"id": "629f5818e0dc6d4171e1a025",
"uid": "629daa3de5a005209d182876",
"deviceId": "16477632226720c2cc9f03008d1500166",
"name": "卧室的插座",
"homeId": "629e18e96b16ad6a3e158645",
"spaceId": "629e18fee0dc6d4171e1a021",
"addAt": 1654609944061,
"useAt": 1655653548172
},
{
"id": "629f5734e0dc6d4171e1a024",
"uid": "629daa3de5a005209d182876",
"deviceId": "16477632215720c11b1602008d1500160",
"name": "卧室的插座",
"homeId": "629e18e96b16ad6a3e158645",
"spaceId": "629e18fee0dc6d4171e1a021",
"addAt": 1654609716856,
"useAt": 1655653590474
},
{
"id": "629e1a1de0dc6d4171e1a022",
"uid": "629daa3de5a005209d182876",
"deviceId": "1647690908735019dd9f03008d1500163",
"name": "卧室的插座",
"homeId": "629e18e96b16ad6a3e158645",
"spaceId": "629e18fee0dc6d4171e1a021",
"addAt": 1654528541149,
"useAt": 1655653255089
},
{
"id": "629db2e1e5a005209d182877",
"uid": "04c6722f-9a6d-40f3-ac9b-cd791b4c8933",
"deviceId": "16538390924670pulg0a001006000012a",
"name": "阳台的插座",
"homeId": "6238a49fecf37861bed7ad11",
"spaceId": "62794a820b0776663635e636",
"addAt": 1654502113734,
"useAt": 1655653724374
},
{
"id": "6280d7cd7e234141ee9d1fd2",
"uid": "04c6722f-9a6d-40f3-ac9b-cd791b4c8933",
"deviceId": "16501806313260000833feffac33bc16c",
"name": "灯的插座",
"homeId": "6238a49fecf37861bed7ad11",
"spaceId": "62794a5c0b0776663635e633",
"addAt": 1652611021619,
"useAt": 1655181137254
},
{
"id": "6280b17d7e234141ee9d1fcf",
"uid": "04c6722f-9a6d-40f3-ac9b-cd791b4c8933",
"deviceId": "165017126122400cefafcfee61000012b",
"name": "客厅网关",
"homeId": "6238a49fecf37861bed7ad11",
"spaceId": "62794a5c0b0776663635e633",
"addAt": 1652601213676,
"useAt": 1655189186348
}
]

35
data/init/taskInfo.json Normal file
View File

@ -0,0 +1,35 @@
[
{
"id": "97f79dde-bf3c-4d5b-bfd8-8102539002ad",
"name": "测试111",
"type": "timer",
"expression": "*/25 * * * * ? *",
"desc": "sss入网",
"actions": [
{
"type": "device",
"config": "{\"id\":\"f8de6282-771d-4cdb-9929-299db46f361d\",\"type\":\"device\",\"services\":[{\"device\":\"hbtgIA0SuVw9lxjB/AA:BB:CC:DD:11\",\"identifier\":\"allowJoin\",\"inputData\":[]}]}"
}
],
"state": "stopped",
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"createAt": 1645928016031,
"reason": "stop by fa1c5eaa-de6e-48b6-805e-8f091c7bb831"
},
{
"id": "667bbfa1-a7ed-4ce8-9ce0-cfa8cac90e6c",
"name": "2222",
"type": "delay",
"expression": "22",
"desc": "2222",
"actions": [
{
"type": "device",
"config": "{\"id\":\"24fd7df7-5c7d-4964-83af-a83d04b4db58\",\"type\":\"device\",\"services\":[{\"device\":\"Rf4QSjbm65X45753/ABC12300001\",\"identifier\":\"set\",\"inputData\":[{\"identifier\":\"powerstate\",\"value\":\"1\"}]}]}"
}
],
"state": "stopped",
"createAt": 1645871966035,
"reason": "stop by 6286886077b91b031115e6a6"
}
]

980
data/init/thingModel.json Normal file
View File

@ -0,0 +1,980 @@
[
{
"id": "xpsYHExTKPFaQMS7",
"productKey": "xpsYHExTKPFaQMS7",
"model": {
"properties": [
{
"identifier": "powerstate",
"dataType": {
"type": "enum",
"specs": {
"0": "关",
"1": "开"
}
},
"name": "开关",
"accessMode": "rw"
},
{
"identifier": "brightness",
"dataType": {
"type": "int32",
"specs": {
"min": "1",
"max": "100"
}
},
"name": "亮度",
"accessMode": "rw"
}
],
"services": [],
"events": []
}
},
{
"id": "hdX3PCMcFrCYpesJ",
"productKey": "hdX3PCMcFrCYpesJ",
"model": {
"properties": [
{
"identifier": "windSpeed",
"dataType": {
"type": "int32",
"specs": {
"min": "1",
"max": "10"
}
},
"name": "风速",
"accessMode": "rw"
},
{
"identifier": "powerSwitch",
"dataType": {
"type": "bool",
"specs": {
"0": "关",
"1": "开"
}
},
"name": "电源开关",
"accessMode": "rw"
},
{
"identifier": "workMode",
"dataType": {
"type": "enum",
"specs": {
"1": "正常风",
"2": "自然风",
"3": "睡眠风",
"4": "静音风"
}
},
"name": "工作模式",
"accessMode": "rw"
}
],
"services": [],
"events": []
}
},
{
"id": "hbtgIA0SuVw9lxjB",
"productKey": "hbtgIA0SuVw9lxjB",
"model": {
"properties": [],
"services": [
{
"identifier": "allowJoin",
"inputData": [],
"outputData": [],
"name": "开启入网"
},
{
"identifier": "rawSend",
"inputData": [
{
"identifier": "data",
"dataType": {
"type": "text",
"specs": {
"length": "10240"
}
},
"name": "数据"
},
{
"identifier": "mac",
"dataType": {
"type": "text",
"specs": {
"length": "128"
}
},
"name": "设备mac"
},
{
"identifier": "model",
"dataType": {
"type": "text",
"specs": {
"length": "128"
}
},
"name": "设备型号"
}
],
"outputData": [],
"name": "透传下发"
}
],
"events": [
{
"identifier": "rawReport",
"outputData": [
{
"identifier": "data",
"dataType": {
"type": "text",
"specs": {
"length": "10240"
}
},
"name": "数据"
},
{
"identifier": "mac",
"dataType": {
"type": "text",
"specs": {
"length": "128"
}
},
"name": "设备mac"
},
{
"identifier": "model",
"dataType": {
"type": "text",
"specs": {
"length": "128"
}
},
"name": "设备型号"
}
],
"name": "透传上报"
}
]
}
},
{
"id": "eDhXKwEzwFybM5R7",
"productKey": "eDhXKwEzwFybM5R7",
"model": {
"properties": [
{
"identifier": "powerstate",
"dataType": {
"type": "enum",
"specs": {
"0": "关",
"1": "开"
}
},
"name": "全开关",
"accessMode": "rw"
},
{
"identifier": "powerstate_1",
"dataType": {
"type": "enum",
"specs": {
"0": "关",
"1": "开"
}
},
"name": "开关1",
"accessMode": "rw"
},
{
"identifier": "powerstate_2",
"dataType": {
"type": "enum",
"specs": {
"0": "关",
"1": "开"
}
},
"name": "开关2",
"accessMode": "rw"
},
{
"identifier": "powerstate_3",
"dataType": {
"type": "enum",
"specs": {
"0": "关",
"1": "开"
}
},
"name": "开关3",
"accessMode": "rw"
},
{
"identifier": "DeviceType",
"dataType": {
"type": "text",
"specs": {
"length": "128"
}
},
"name": "型号",
"accessMode": "r"
},
{
"identifier": "rssi",
"dataType": {
"type": "int32",
"specs": {
"min": "-127",
"max": "127"
}
},
"name": "信号强度",
"accessMode": "r"
}
],
"services": [],
"events": [
{
"identifier": "faultReportEvent",
"outputData": [
{
"identifier": "code",
"dataType": {
"type": "int32",
"specs": {}
},
"name": "错误代码"
}
],
"name": "故障上报"
}
]
}
},
{
"id": "cGCrkK7Ex4FESAwe",
"productKey": "cGCrkK7Ex4FESAwe",
"model": {
"properties": [
{
"identifier": "rssi",
"dataType": {
"type": "int32",
"specs": {
"min": "-127",
"max": "127"
}
},
"name": "信号强度",
"accessMode": "r"
},
{
"identifier": "DeviceType",
"dataType": {
"type": "text",
"specs": {
"length": "128"
}
},
"name": "设备型号",
"accessMode": "r"
},
{
"identifier": "powerstate",
"dataType": {
"type": "bool",
"specs": {
"0": "关",
"1": "开"
}
},
"name": "开关",
"accessMode": "rw"
}
],
"services": [
{
"identifier": "Toggle",
"inputData": [],
"outputData": [],
"name": "开关切换"
}
],
"events": [
{
"identifier": "faultReportEvent",
"outputData": [
{
"identifier": "code",
"dataType": {
"type": "int32",
"specs": {
"min": "0",
"max": "255"
}
},
"name": "错误代码"
}
],
"name": "故障上报"
}
]
}
},
{
"id": "Rf4QSjbm65X45753",
"productKey": "Rf4QSjbm65X45753",
"model": {
"properties": [
{
"identifier": "powerstate",
"dataType": {
"type": "bool",
"specs": {
"0": "关",
"1": "开"
}
},
"name": "开关状态",
"accessMode": "rw"
},
{
"identifier": "volt",
"dataType": {
"type": "int32",
"specs": {
"min": "0",
"max": "100"
}
},
"name": "电压",
"accessMode": "r"
}
],
"services": [
{
"identifier": "service1",
"inputData": [
{
"identifier": "p1",
"dataType": {
"type": "int32",
"specs": {
"min": "1",
"max": "100"
}
},
"name": "参数1"
},
{
"identifier": "p2",
"dataType": {
"type": "text",
"specs": {
"length": "90"
}
},
"name": "参数2"
}
],
"outputData": [],
"name": "服务1"
}
],
"events": [
{
"identifier": "event1",
"outputData": [
{
"identifier": "p1",
"dataType": {
"type": "int32",
"specs": {
"min": "0",
"max": "100"
}
},
"name": "参数p1"
},
{
"identifier": "p2",
"dataType": {
"type": "text",
"specs": {
"length": "100"
}
},
"name": "参数p2"
}
],
"name": "测试event1"
}
]
},
"_class": "cc.iotkit.model.ThingModel"
},
{
"id": "PN3EDmkBZDD8whDd",
"productKey": "PN3EDmkBZDD8whDd",
"model": {
"properties": [
{
"identifier": "power",
"dataType": {
"type": "int32",
"specs": {}
},
"name": "电量",
"accessMode": "r"
},
{
"identifier": "DeviceType",
"dataType": {
"type": "text",
"specs": {
"length": "128"
}
},
"name": "设备型号",
"accessMode": "r"
},
{
"identifier": "rssi",
"dataType": {
"type": "int32",
"specs": {
"min": "-127",
"max": "127"
}
},
"name": "信号强度",
"accessMode": "r"
},
{
"identifier": "doorStatus",
"dataType": {
"type": "enum",
"specs": {
"0": "关",
"1": "开"
}
},
"name": "门状态",
"accessMode": "r"
}
],
"services": [],
"events": [
{
"identifier": "prylockEvent",
"outputData": [],
"name": "防撬报警事件"
}
]
}
},
{
"id": "N523nWsCiG3CAn6X",
"productKey": "N523nWsCiG3CAn6X",
"model": {
"properties": [
{
"identifier": "DeviceType",
"dataType": {
"type": "text",
"specs": {
"length": "128"
}
},
"name": "设备型号",
"accessMode": "r"
},
{
"identifier": "UnbindAndDelete",
"dataType": {
"type": "bool",
"specs": {
"0": "否",
"1": "是"
}
},
"name": "解绑并删除设备",
"accessMode": "rw"
}
],
"services": [
{
"identifier": "Reboot",
"inputData": [],
"outputData": [],
"name": "重启"
},
{
"identifier": "AllowJoin",
"inputData": [],
"outputData": [],
"name": "开启组网"
},
{
"identifier": "OpenTrace",
"inputData": [
{
"identifier": "enable",
"dataType": {
"type": "bool",
"specs": {
"0": "Close",
"1": "Open"
}
},
"name": "值"
}
],
"outputData": [],
"name": "打开调试"
},
{
"identifier": "ShowDesc",
"inputData": [
{
"identifier": "ieee",
"dataType": {
"type": "text",
"specs": {
"length": "32"
}
},
"name": "设备地址"
}
],
"outputData": [],
"name": "显示设备信息"
},
{
"identifier": "rawSend",
"inputData": [
{
"identifier": "model",
"dataType": {
"type": "text",
"specs": {}
},
"name": "设备型号"
},
{
"identifier": "mac",
"dataType": {
"type": "text",
"specs": {}
},
"name": "设备mac"
},
{
"identifier": "data",
"dataType": {
"type": "text",
"specs": {}
},
"name": "数据"
}
],
"outputData": [],
"name": "透传下发"
}
],
"events": [
{
"identifier": "faultReport",
"outputData": [
{
"identifier": "code",
"dataType": {
"type": "int32",
"specs": {
"min": "0",
"max": "255"
}
},
"name": "错误码"
}
],
"name": "故障上报"
},
{
"identifier": "rawReport",
"outputData": [
{
"identifier": "model",
"dataType": {
"type": "text",
"specs": {
"length": "128"
}
},
"name": "设备型号"
},
{
"identifier": "mac",
"dataType": {
"type": "text",
"specs": {}
},
"name": "设备mac"
},
{
"identifier": "data",
"dataType": {
"type": "text",
"specs": {}
},
"name": "数据"
}
],
"name": "透传上报"
}
]
}
},
{
"id": "KdJYpTp5ywNhmrmC",
"productKey": "KdJYpTp5ywNhmrmC",
"model": {
"properties": [],
"services": [],
"events": [
{
"identifier": "userDevicesChange",
"outputData": [
{
"identifier": "uid",
"dataType": {
"type": "text",
"specs": {
"length": "100"
}
},
"name": "用户Id"
}
],
"name": "用户设备列表变更"
}
]
}
},
{
"id": "Eit3kmGJtxSHfCKT",
"productKey": "Eit3kmGJtxSHfCKT",
"model": {
"properties": [
{
"identifier": "flow",
"dataType": {
"type": "int32",
"specs": {
"min": "0",
"max": "100000"
}
},
"name": "用量",
"accessMode": "r"
},
{
"identifier": "fee",
"dataType": {
"type": "int32",
"specs": {
"min": "0",
"max": "100000"
}
},
"name": "费用",
"accessMode": "rw"
}
],
"services": [],
"events": []
}
},
{
"id": "D8c5pXFmt2KJDxNm",
"productKey": "D8c5pXFmt2KJDxNm",
"model": {
"properties": [
{
"identifier": "powerstate_1",
"dataType": {
"type": "enum",
"specs": {
"0": "关",
"1": "开"
}
},
"name": "开关1",
"accessMode": "r"
},
{
"identifier": "powerstate_2",
"dataType": {
"type": "enum",
"specs": {
"0": "关",
"1": "开"
}
},
"name": "开关2",
"accessMode": "r"
},
{
"identifier": "powerstate_3",
"dataType": {
"type": "enum",
"specs": {
"0": "关",
"1": "开"
}
},
"name": "开关3",
"accessMode": "r"
},
{
"identifier": "powerstate_4",
"dataType": {
"type": "enum",
"specs": {
"0": "关",
"1": "开"
}
},
"name": "开关4",
"accessMode": "r"
},
{
"identifier": "DeviceType",
"dataType": {
"type": "text",
"specs": {
"length": "128"
}
},
"name": "型号",
"accessMode": "r"
},
{
"identifier": "rssi",
"dataType": {
"type": "int32",
"specs": {
"min": "-127",
"max": "127"
}
},
"name": "信号强度",
"accessMode": "r"
}
],
"services": [],
"events": [
{
"identifier": "faultReportEvent",
"outputData": [
{
"identifier": "code",
"dataType": {
"type": "int32",
"specs": {}
},
"name": "错误代码"
}
],
"name": "故障上报"
}
]
}
},
{
"id": "AWcJnf7ymGSkaz5M",
"productKey": "AWcJnf7ymGSkaz5M",
"model": {
"properties": [
{
"identifier": "rssi",
"dataType": {
"type": "int32",
"specs": {
"min": "-128",
"max": "128"
}
},
"name": "信号强度",
"accessMode": "r"
},
{
"identifier": "switch",
"dataType": {
"type": "bool",
"specs": {
"0": "关",
"1": "开"
}
},
"name": "开关",
"accessMode": "rw"
},
{
"identifier": "voltage",
"dataType": {
"type": "int32",
"specs": {
"min": "0",
"max": "1000"
}
},
"name": "电压",
"accessMode": "r"
},
{
"identifier": "current",
"dataType": {
"type": "int32",
"specs": {
"min": "0",
"max": "1000"
}
},
"name": "电流",
"accessMode": "r"
},
{
"identifier": "power",
"dataType": {
"type": "int32",
"specs": {
"min": "0",
"max": "1000000"
}
},
"name": "功率",
"accessMode": "r"
},
{
"identifier": "electricty",
"dataType": {
"type": "int32",
"specs": {
"min": "0",
"max": "1000000000"
}
},
"name": "电量",
"accessMode": "r"
},
{
"identifier": "back_light",
"dataType": {
"type": "bool",
"specs": {
"0": "关",
"1": "开"
}
},
"name": "背光灯",
"accessMode": "rw"
},
{
"identifier": "start_onoff",
"dataType": {
"type": "enum",
"specs": {
"0": "off",
"1": "onoff with swithc",
"2": "on"
}
},
"name": "上电启动配置",
"accessMode": "rw"
},
{
"identifier": "cycle_timer",
"dataType": {
"type": "text",
"specs": {
"length": "64"
}
},
"name": "循环定时",
"accessMode": "rw"
},
{
"identifier": "countdown",
"dataType": {
"type": "int32",
"specs": {
"min": "0",
"max": "1000000"
}
},
"name": "倒计时",
"accessMode": "rw"
}
],
"services": [],
"events": []
}
},
{
"id": "6kYp6jszrDns2yh4",
"productKey": "6kYp6jszrDns2yh4",
"model": {
"properties": [
{
"identifier": "humidity",
"dataType": {
"type": "int32",
"specs": {
"min": "0",
"max": "100"
}
},
"name": "湿度\t",
"accessMode": "r"
},
{
"identifier": "temperature",
"dataType": {
"type": "int32",
"specs": {
"min": "-38",
"max": "656"
}
},
"name": "温度\t",
"accessMode": "r"
}
],
"services": [],
"events": [
{
"identifier": "temperatureTooLowEvent",
"outputData": [],
"name": "温度过低事件"
}
]
}
}
]

140
data/init/userInfo.json Normal file
View File

@ -0,0 +1,140 @@
[
{
"id": "629e1d7fa176d816952f1e81",
"uid": "13480802157",
"ownerId": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"secret": "483752384B473759556E685768796B6F644E48634F76486C51646A41576B545A2B396C34474244414F334F78574F4778613764564338594E666770595A376177",
"nickName": "song2",
"type": 1,
"roles": [
"iot_client"
],
"permissions": [],
"usePlatforms": [
"dueros"
],
"createAt": 1654529407977
},
{
"id": "629daa3de5a005209d182876",
"uid": "13510470342",
"ownerId": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"secret": "483752384B473759556E685768796B6F644E48634F76486C51646A41576B545A2B396C34474244414F335066526F6E3331625374634F663249335661756B7049",
"nickName": "涛",
"type": 1,
"roles": [
"iot_client"
],
"permissions": [],
"usePlatforms": [
"dueros"
],
"createAt": 1654499901296
},
{
"id": "6286886077b91b031115e6a6",
"uid": "guest1",
"ownerId": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"nickName": "演示账户",
"secret": "48774861346645676F51324A4D6E6639306E6474437741634C4333746C4575666C316F76503455542B5836763065315A2F676244695056557356704D49513569",
"type": 0,
"roles": [
"iot_system",
"iot_admin"
],
"permissions": [],
"usePlatforms": [],
"createAt": 1647592821770
},
{
"id": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"uid": "iotkit",
"ownerId": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"nickName": "管理员",
"secret": "326F3251526A7A3364496136384A737A584A734B366546547458654F734E514D57706762324361576646753377634B745542494A762F32317535786939742F33",
"type": 0,
"roles": [
"iot_system",
"iot_admin"
],
"permissions": [
"write"
],
"usePlatforms": [],
"createAt": 1647592821770
},
{
"id": "a1051e81-f4fc-4182-a750-1a53a27f4c71",
"uid": "du2",
"ownerId": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"nickName": "小度接入2",
"type": 1,
"roles": [
"iot_client"
],
"usePlatforms": [
"dueros"
],
"createAt": 1651230139460
},
{
"id": "5c0bea53-a318-42ed-a7c5-6e05e6db4ef2",
"uid": "tm3",
"ownerId": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"nickName": "天猫精灵test3",
"type": 1,
"roles": [
"iot_client"
],
"usePlatforms": [
"aligenie"
],
"createAt": 1647982036151
},
{
"id": "2bb3e6f1-17ba-4bf5-9d5e-85fdffd8b85d",
"uid": "du1",
"ownerId": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"nickName": "小度接入1",
"secret": "483752384B473759556E685768796B6F644E48634F76486C51646A41576B545A2B396C34474244414F334F517674507547437A72627A7154302B724441734C5A",
"type": 1,
"roles": [
"iot_client"
],
"usePlatforms": [
"dueros",
"aligenie"
],
"createAt": 1651226639006
},
{
"id": "0ca377e2-66ff-49f3-90c3-108a86bc90eb",
"uid": "tm1",
"ownerId": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"nickName": "天猫精灵1",
"type": 1,
"roles": [
"iot_client"
],
"usePlatforms": [
"aligenie"
],
"createAt": 1648486563107
},
{
"id": "04c6722f-9a6d-40f3-ac9b-cd791b4c8933",
"uid": "18126045687",
"ownerId": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"nickName": "song",
"secret": "483752384B473759556E685768796B6F644E48634F76486C51646A41576B545A2B396C34474244414F334F517674507547437A72627A7154302B724441734C5A",
"type": 1,
"roles": [
"iot_client"
],
"usePlatforms": [
"aligenie",
"dueros"
],
"createAt": 1652115298592
}
]

View File

@ -0,0 +1,137 @@
[
{
"id":"6293953092084e2df303ba3e",
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"name": "三路开关",
"productKey": "eDhXKwEzwFybM5R7",
"devices": [
"16538390097670switch0300100500143",
"16538390048670switch0300100400141",
"16538390008670switch0300100300145",
"16538389971670switch0300100200140",
"16538389915670switch030010010014c"
],
"type": "thingModel",
"script": "\nvar mid=1000;\n\nfunction getMid(){\n mid++;\n if(mid>9999){\n\tmid=1;\n }\n return mid+\"\";\n}\n\nfunction getRequestId(){\n return \"RID\"+new Date().getTime()+getMid();\n}\n\n\nthis.receive=function(service,device){\n return [];\n}\n\nthis.report=function(device){\n return {\n \"mid\":getRequestId(),\n \"productKey\":device.productKey, \n \"deviceName\":device.deviceName,\n \"type\":\"property\",\n \"identifier\":\"report\",\n \"occurred\":new Date().getTime(),\t//时间戳,设备上的事件或数据产生的本地时间\n \"time\":new Date().getTime(),\t\t//时间戳,消息上报时间\n \"data\":{\n\t \"rssi\":127-parseInt(Math.random()*127),\n\t \"powerstate_1\":Math.random()>0.5?1:0,\n\t \"powerstate_2\":Math.random()>0.5?1:0,\n\t \"powerstate_3\":Math.random()>0.5?1:0\n }\n }\n}",
"trigger": "random",
"triggerExpression": "second",
"state": "running",
"createAt": 1653839152090
},
{
"id":"629391ae92084e2df303ba3d",
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"name": "温湿度传感器",
"productKey": "6kYp6jszrDns2yh4",
"devices": [
"16538383943670wenshidu01008000139",
"16538383910670wenshidu01007000136",
"16538383880670wenshidu0100600013b",
"16538383850710wenshidu01005000134",
"16538383810690wenshidu01004000132",
"16537594784840wenshidu0100300013a",
"16537594752710wenshidu0100200013d",
"16537594707840wenshidu0100100013c",
"16514626218250abe124000010000011a"
],
"type": "thingModel",
"script": "\nvar mid=1000;\n\nfunction getMid(){\n mid++;\n if(mid>9999){\n\tmid=1;\n }\n return mid+\"\";\n}\n\nfunction getRequestId(){\n return \"RID\"+new Date().getTime()+getMid();\n}\n\n\nthis.receive=function(service,device){\n return [];\n}\n\nthis.report=function(device){\n return {\n \"mid\":getRequestId(),\n \"productKey\":device.productKey, \n \"deviceName\":device.deviceName,\n \"type\":\"property\",\n \"identifier\":\"report\",\n \"occurred\":new Date().getTime(),\t//时间戳,设备上的事件或数据产生的本地时间\n \"time\":new Date().getTime(),\t\t//时间戳,消息上报时间\n \"data\":{\n \"humidity\":parseInt(Math.random()*100),\n\t \"temperature\":parseInt(Math.random()*500)-38\n }\n }\n}",
"trigger": "random",
"triggerExpression": "second",
"state": "running",
"createAt": 1653838254989
},
{
"id": "629390f492084e2df303ba3c",
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"name": "调光灯",
"productKey": "xpsYHExTKPFaQMS7",
"devices": [
"16537595658790linght0010030000128",
"16537595624750linght001002000012c",
"16537595591780linght0010010000121",
"16552594933210linght001007000012f",
"16552594898210linght0010060000129",
"16552594863210linght001005000012c",
"16552594812210linght001004000012d"
],
"type": "thingModel",
"script": "\nvar mid=1000;\n\nfunction getMid(){\n mid++;\n if(mid>9999){\n\tmid=1;\n }\n return mid+\"\";\n}\n\nfunction getRequestId(){\n return \"RID\"+new Date().getTime()+getMid();\n}\n\n\nthis.receive=function(service,device){\n return [];\n}\n\nthis.report=function(device){\n return {\n \"mid\":getRequestId(),\n \"productKey\":device.productKey, \n \"deviceName\":device.deviceName,\n \"type\":\"property\",\n \"identifier\":\"report\",\n \"occurred\":new Date().getTime(),\t//时间戳,设备上的事件或数据产生的本地时间\n \"time\":new Date().getTime(),\t\t//时间戳,消息上报时间\n \"data\":{\n \"brightness\":parseInt(Math.random()*100),\n\t \"powerstate\":Math.random()>0.5?1:0\n }\n }\n}",
"trigger": "random",
"triggerExpression": "second",
"state": "running",
"createAt": 1653838068860
},
{
"id": "62925cb72002b44c15caeb1c",
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"name": "虚拟门磁1",
"productKey": "PN3EDmkBZDD8whDd",
"devices": [
"16537591055800menci0001003000012e",
"16537590838150menci00010020000128",
"16537590780810menci0001001000012b",
"16552595723210menci0001008000012f",
"16552595685220menci00010070000127",
"16552595656210menci0001006000012d",
"16552595626260menci0001005000012b",
"16552595580220menci0001004000012a",
"16501898583770f4cce4feffbd1bec164"
],
"type": "thingModel",
"script": "\nvar mid=1000;\n\nfunction getMid(){\n mid++;\n if(mid>9999){\n\tmid=1;\n }\n return mid+\"\";\n}\n\nfunction getRequestId(){\n return \"RID\"+new Date().getTime()+getMid();\n}\n\n\nthis.receive=function(service,device){\n return [];\n}\n\nthis.report=function(device){\n return {\n \"mid\":getRequestId(),\n \"productKey\":device.productKey, \n \"deviceName\":device.deviceName,\n \"type\":\"property\",\n \"identifier\":\"report\",\n \"occurred\":new Date().getTime(),\t//时间戳,设备上的事件或数据产生的本地时间\n \"time\":new Date().getTime(),\t\t//时间戳,消息上报时间\n \"data\":{\n \"rssi\":127-parseInt(Math.random()*127),\n \"power\":parseInt(Math.random()*100),\n\t \"doorStatus\":Math.random()>0.5?1:0\n }\n }\n}",
"trigger": "random",
"triggerExpression": "minute",
"state": "running",
"createAt": 1653759159567
},
{
"id": "628fd800fba69e633a972e12",
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"name": "开关1",
"productKey": "Rf4QSjbm65X45753",
"devices": [
"16465723451670abc123000030000011a",
"16465723448670abc1230000200000115"
],
"type": "thingModel",
"script": "\nvar mid=1000;\n\nfunction getMid(){\n mid++;\n if(mid>9999){\n\tmid=1;\n }\n return mid+\"\";\n}\n\nfunction getRequestId(){\n return \"RID\"+new Date().getTime()+getMid();\n}\n\n\nthis.receive=function(service,device){\n return [{\n \"productKey\":service.productKey,\n \"deviceName\":service.deviceName,\n \"mid\":service.mid,\n \"type\":\"service\",\n \"identifier\":\"reboot_reply\",\n \"data\":{},\n \"code\":0\n },{\n \"mid\":getRequestId(),\n \"productKey\":service.productKey, \n \"deviceName\":service.deviceName,\n \"type\":\"property\",\n \"identifier\":\"report\",\n \"occurred\":new Date().getTime(),\n \"time\":new Date().getTime(),\n \"data\":{\n \"volt\":parseInt(Math.random()*100),\n\t \"powerstate\":Math.random()>0.5?1:0\n }\n }]\n}\n\nthis.report=function(device){\n return {\n \"mid\":getRequestId(),\n \"productKey\":device.productKey, \n \"deviceName\":device.deviceName,\n \"type\":\"property\",\n \"identifier\":\"report\",\n \"occurred\":new Date().getTime(),\t//时间戳,设备上的事件或数据产生的本地时间\n \"time\":new Date().getTime(),\t\t//时间戳,消息上报时间\n \"data\":{\n \"volt\":parseInt(Math.random()*100)\n }\n }\n}",
"trigger": "cron",
"triggerExpression": "0 * * * * ? ",
"state": "running",
"createAt": 1653594112764
},
{
"id": "628fa6bc1b735b73cb260042",
"uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
"name": "虚拟插座12",
"productKey": "cGCrkK7Ex4FESAwe",
"devices": [
"16534030209640test001230100000118",
"16514626216250abe1230000200000114",
"16514626214280abe1230000100000116",
"16538390924670pulg0a001006000012a",
"16538390885690pulg0a0010050000126",
"16538390853670pulg0a0010040000121",
"16538390820760pulg0a0010030000127",
"16538390787670pulg0a0010020000124",
"16538390738670pulg0a0010010000125",
"16552594646210pulg0a0010160000122",
"16552594604220pulg0a0010150000127",
"16552594572370pulg0a001014000012e",
"16552594542310pulg0a0010130000123",
"16552594511210pulg0a001012000012c",
"16552594475270pulg0a0010110000125",
"16552594444210pulg0a0010100000128",
"16552594405220pulg0a0010090000124",
"16552594368340pulg0a0010080000126",
"16552594320310pulg0a0010070000126"
],
"type": "thingModel",
"script": "\nvar mid=1000;\n\nfunction getMid(){\n mid++;\n if(mid>9999){\n\tmid=1;\n }\n return mid+\"\";\n}\n\nfunction getRequestId(){\n return \"RID\"+new Date().getTime()+getMid();\n}\n\n\nthis.receive=function(service,device){\n var identifier=service.identifier;\n var result= [{\n \"productKey\":service.productKey,\n \"deviceName\":service.deviceName,\n \"mid\":service.mid,\n \"type\":\"service\",\n \"identifier\":identifier+\"_reply\",\n \"data\":{},\n \"code\":0\n }]\n \n if(service.type==\"property\" && (identifier==\"get\" || identifier==\"set\")){\n\tresult.push({\n\t \"mid\":getRequestId(),\n\t \"productKey\":device.productKey, \n\t \"deviceName\":device.deviceName,\n\t \"type\":\"property\",\n\t \"identifier\":\"report\",\n\t \"occurred\":new Date().getTime(),\n\t \"time\":new Date().getTime(),\n\t \"data\":service.params\n\t});\n }\n \n return result;\n}\n\nthis.report=function(device){\n return {\n \"mid\":getRequestId(),\n \"productKey\":device.productKey, \n \"deviceName\":device.deviceName,\n \"type\":\"property\",\n \"identifier\":\"report\",\n \"occurred\":new Date().getTime(),\t//时间戳,设备上的事件或数据产生的本地时间\n \"time\":new Date().getTime(),\t\t//时间戳,消息上报时间\n \"data\":{\n \"rssi\":127-parseInt(Math.random()*127),\n\t \"powerstate\":Math.random()>0.5?1:0\n }\n }\n}",
"trigger": "random",
"triggerExpression": "second",
"state": "running",
"createAt": 1653581500076
}
]

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iotkit-parent</artifactId> <artifactId>iotkit-parent</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.2.2-SNAPSHOT</version> <version>0.3.0-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -15,7 +15,7 @@
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId> <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.manager; package cc.iotkit.manager;
import cc.iotkit.manager.config.EmbeddedElasticSearchConfig; import cc.iotkit.manager.config.EmbeddedElasticSearchConfig;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.manager.config; package cc.iotkit.manager.config;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.manager.config; package cc.iotkit.manager.config;
import cc.iotkit.common.Constants; import cc.iotkit.common.Constants;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.manager.config; package cc.iotkit.manager.config;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.manager.config; package cc.iotkit.manager.config;
import lombok.SneakyThrows; import lombok.SneakyThrows;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.manager.controller; package cc.iotkit.manager.controller;
import cc.iotkit.dao.AppDesignRepository; import cc.iotkit.dao.AppDesignRepository;
@ -9,10 +18,10 @@ import cc.iotkit.model.Paging;
import cc.iotkit.model.product.AppDesign; import cc.iotkit.model.product.AppDesign;
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.utils.AuthUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -40,11 +49,15 @@ public class AppController {
public Paging<AppDesignVo> getDesigns() { public Paging<AppDesignVo> getDesigns() {
List<AppDesignVo> appDesignVos = new ArrayList<>(); List<AppDesignVo> appDesignVos = new ArrayList<>();
List<Product> products = productRepository.findAll(Example Iterable<Product> products;
.of(dataOwnerService.wrapExample(new Product()))); Iterable<AppDesign> appDesigns;
if (AuthUtil.isAdmin()) {
List<AppDesign> appDesigns = appDesignRepository.findAll(Example products = productRepository.findAll();
.of(dataOwnerService.wrapExample(new AppDesign()))); appDesigns = appDesignRepository.findAll();
} else {
products = productRepository.findByUid(AuthUtil.getUserId());
appDesigns = appDesignRepository.findByUid(AuthUtil.getUserId());
}
products.forEach(product -> { products.forEach(product -> {
Category category = categoryRepository.findById(product.getCategory()).orElse(new Category()); Category category = categoryRepository.findById(product.getCategory()).orElse(new Category());

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.manager.controller; package cc.iotkit.manager.controller;
import cc.iotkit.common.Constants; import cc.iotkit.common.Constants;
@ -24,18 +33,16 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.elasticsearch.core.query.Criteria;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.async.DeferredResult; import org.springframework.web.context.request.async.DeferredResult;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.regex.Pattern;
@Slf4j @Slf4j
@RestController @RestController
@ -45,7 +52,7 @@ public class DeviceController {
@Autowired @Autowired
private DeviceService deviceService; private DeviceService deviceService;
@Autowired @Autowired
private DeviceRepository deviceRepository; private DeviceInfoRepository deviceInfoRepository;
@Autowired @Autowired
private ProductRepository productRepository; private ProductRepository productRepository;
@Autowired @Autowired
@ -96,32 +103,30 @@ public class DeviceController {
if (!AuthUtil.isAdmin()) { if (!AuthUtil.isAdmin()) {
//客户端用户使用绑定子用户查询 //客户端用户使用绑定子用户查询
if (AuthUtil.isClientUser()) { if (AuthUtil.isClientUser()) {
condition.and("subUid").elemMatch(new Criteria().is(uid)); condition = condition.and("subUid").matches(uid);
} else { } else {
condition.and("uid").is(uid); condition = condition.and("uid").is(uid);
} }
} }
String pk = query.getProductKey(); String pk = query.getProductKey();
if (StringUtils.isNotBlank(pk)) { if (StringUtils.isNotBlank(pk)) {
condition.and("productKey").is(pk); condition = condition.and("productKey").is(pk);
} }
//关键字查询 //关键字查询
String keyword = query.getKeyword(); String keyword = query.getKeyword();
if (StringUtils.isNotBlank(keyword)) { if (StringUtils.isNotBlank(keyword)) {
Pattern pattern = Pattern.compile("^.*" + keyword + ".*$", Pattern.CASE_INSENSITIVE); condition = condition.and(
condition.orOperator( Criteria.where("deviceName").contains(keyword).and("deviceId").contains(keyword)
Criteria.where("deviceName").regex(pattern),
Criteria.where("deviceId").regex(pattern)
); );
} }
String group = query.getGroup(); String group = query.getGroup();
if (StringUtils.isNotBlank(group)) { if (StringUtils.isNotBlank(group)) {
condition.and("group." + group).exists(true); condition = condition.and("group." + group).exists();
} }
String state = query.getState(); String state = query.getState();
if (StringUtils.isNotBlank(state)) { if (StringUtils.isNotBlank(state)) {
condition.and("state.online").is(state.equals("online")); condition = condition.and("state.online").is(state.equals("online"));
} }
return deviceDao.find(condition, size, page); return deviceDao.find(condition, size, page);
@ -152,37 +157,33 @@ public class DeviceController {
device.setState(new DeviceInfo.State(false, null, null)); device.setState(new DeviceInfo.State(false, null, null));
device.setCreateAt(System.currentTimeMillis()); device.setCreateAt(System.currentTimeMillis());
deviceRepository.save(device); deviceInfoRepository.save(device);
} }
@GetMapping("/{deviceId}/children") @GetMapping("/{deviceId}/children")
public List<DeviceInfo> getChildren(@PathVariable("deviceId") String deviceId) { public List<DeviceInfo> getChildren(@PathVariable("deviceId") String deviceId) {
return deviceRepository.findAll(Example.of( if (AuthUtil.isAdmin()) {
dataOwnerService.wrapExample( return deviceInfoRepository.findByParentId(deviceId);
DeviceInfo.builder() }
.parentId(deviceId) return deviceInfoRepository.findByParentIdAndUid(deviceId, AuthUtil.getUserId());
.build())));
} }
@GetMapping(Constants.API_DEVICE.DETAIL) @GetMapping(Constants.API_DEVICE.DETAIL)
public DeviceInfo getDetail(@PathVariable("deviceId") String deviceId) { public DeviceInfo getDetail(@PathVariable("deviceId") String deviceId) {
return dataOwnerService.checkOwner(deviceRepository.findById(deviceId).orElse(new DeviceInfo())); return dataOwnerService.checkOwner(deviceInfoRepository.findById(deviceId).orElse(new DeviceInfo()));
} }
@GetMapping("/{pk}/{dn}") @GetMapping("/{pk}/{dn}")
public DeviceInfo getByPkDn(@PathVariable("pk") String pk, public DeviceInfo getByPkDn(@PathVariable("pk") String pk,
@PathVariable("dn") String dn) { @PathVariable("dn") String dn) {
return dataOwnerService.checkOwner( return dataOwnerService.checkOwner(
deviceRepository.findOne(Example.of(DeviceInfo.builder() deviceInfoRepository.findByProductKeyAndDeviceName(pk, dn));
.productKey(pk)
.deviceName(dn)
.build())).orElse(new DeviceInfo()));
} }
@PostMapping("/{deviceId}/delete") @PostMapping("/{deviceId}/delete")
public void deleteDevice(@PathVariable("deviceId") String deviceId) { public void deleteDevice(@PathVariable("deviceId") String deviceId) {
deviceId = getDetail(deviceId).getDeviceId(); deviceId = getDetail(deviceId).getDeviceId();
deviceRepository.deleteById(deviceId); deviceInfoRepository.deleteById(deviceId);
} }
@PostMapping("/{deviceId}/logs/{size}/{page}") @PostMapping("/{deviceId}/logs/{size}/{page}")
@ -218,7 +219,7 @@ public class DeviceController {
@PostMapping("/{deviceId}/tag/add") @PostMapping("/{deviceId}/tag/add")
public void addTag(@PathVariable("deviceId") String deviceId, public void addTag(@PathVariable("deviceId") String deviceId,
DeviceInfo.Tag tag) { DeviceInfo.Tag tag) {
DeviceInfo device = deviceRepository.findByDeviceId(deviceId); DeviceInfo device = deviceInfoRepository.findByDeviceId(deviceId);
dataOwnerService.checkOwner(device); dataOwnerService.checkOwner(device);
deviceDao.updateTag(deviceId, tag); deviceDao.updateTag(deviceId, tag);
} }
@ -227,7 +228,7 @@ public class DeviceController {
public void simulateSend( public void simulateSend(
@PathVariable("deviceId") String deviceId, @PathVariable("deviceId") String deviceId,
@RequestBody ThingModelMessage message) { @RequestBody ThingModelMessage message) {
DeviceInfo device = deviceRepository.findByDeviceId(deviceId); DeviceInfo device = deviceInfoRepository.findByDeviceId(deviceId);
dataOwnerService.checkOwner(device); dataOwnerService.checkOwner(device);
message.setMid(UniqueIdUtil.newRequestId()); message.setMid(UniqueIdUtil.newRequestId());
@ -245,7 +246,7 @@ public class DeviceController {
@PathVariable("clientId") String clientId @PathVariable("clientId") String clientId
) { ) {
String uid = AuthUtil.getUserId(); String uid = AuthUtil.getUserId();
DeviceInfo deviceInfo = deviceRepository.findByDeviceId(deviceId); DeviceInfo deviceInfo = deviceInfoRepository.findByDeviceId(deviceId);
dataOwnerService.checkOwner(deviceInfo); dataOwnerService.checkOwner(deviceInfo);
//按用户+客户端ID订阅 //按用户+客户端ID订阅

View File

@ -1,11 +1,17 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.manager.controller; package cc.iotkit.manager.controller;
import cc.iotkit.common.exception.BizException; import cc.iotkit.common.exception.BizException;
import cc.iotkit.common.utils.JsonUtil; import cc.iotkit.common.utils.JsonUtil;
import cc.iotkit.dao.CategoryRepository; import cc.iotkit.dao.*;
import cc.iotkit.dao.ProductRepository;
import cc.iotkit.dao.ProductModelRepository;
import cc.iotkit.dao.ThingModelRepository;
import cc.iotkit.manager.config.AliyunConfig; import cc.iotkit.manager.config.AliyunConfig;
import cc.iotkit.manager.service.DataOwnerService; import cc.iotkit.manager.service.DataOwnerService;
import cc.iotkit.model.Paging; import cc.iotkit.model.Paging;
@ -13,20 +19,21 @@ import cc.iotkit.model.product.Category;
import cc.iotkit.model.product.Product; import cc.iotkit.model.product.Product;
import cc.iotkit.model.product.ProductModel; import cc.iotkit.model.product.ProductModel;
import cc.iotkit.model.product.ThingModel; import cc.iotkit.model.product.ThingModel;
import cc.iotkit.utils.AuthUtil;
import cn.dev33.satoken.annotation.SaCheckRole; import cn.dev33.satoken.annotation.SaCheckRole;
import com.aliyun.oss.OSS; import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder; import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.PutObjectResult; import com.aliyun.oss.model.PutObjectResult;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.elasticsearch.core.query.Criteria;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -48,6 +55,9 @@ public class ProductController {
private AliyunConfig aliyunConfig; private AliyunConfig aliyunConfig;
@Autowired @Autowired
private ProductModelRepository productModelRepository; private ProductModelRepository productModelRepository;
@Autowired
private CommonDao commonDao;
private OSS ossClient; private OSS ossClient;
@ -55,12 +65,16 @@ public class ProductController {
public Paging<Product> getProducts( public Paging<Product> getProducts(
@PathVariable("size") int size, @PathVariable("size") int size,
@PathVariable("page") int page, @PathVariable("page") int page,
Product form) { String id) {
form = dataOwnerService.wrapExample(form); Criteria criteria = new Criteria();
Page<Product> products = productRepository.findAll(Example.of(form),
PageRequest.of(page - 1, size, Sort.by(Sort.Order.desc("createAt"))) if (StringUtils.isNotBlank(id)) {
); criteria = criteria.and("id").is(id);
return new Paging<>(products.getTotalElements(), products.getContent()); }
if (!AuthUtil.isAdmin()) {
criteria = criteria.and("uid").is(AuthUtil.getUserId());
}
return commonDao.pagedFind(Product.class, criteria, Sort.Order.desc("createAt"), size, page);
} }
@PostMapping("/save") @PostMapping("/save")
@ -98,7 +112,9 @@ public class ProductController {
@GetMapping("/categories") @GetMapping("/categories")
public List<Category> getCategories() { public List<Category> getCategories() {
return categoryRepository.findAll(); List<Category> list = new ArrayList<>();
categoryRepository.findAll().forEach(list::add);
return list;
} }
@SaCheckRole("iot_admin") @SaCheckRole("iot_admin")

View File

@ -204,8 +204,6 @@ public class ProtocolController {
public Paging<ProtocolConverter> getConverters( public Paging<ProtocolConverter> getConverters(
@PathVariable("size") int size, @PathVariable("size") int size,
@PathVariable("page") int page) { @PathVariable("page") int page) {
protocolConverterRepository.deleteById("");
protocolConverterRepository.deleteById("null");
Page<ProtocolConverter> converters = protocolConverterRepository.findAll( Page<ProtocolConverter> converters = protocolConverterRepository.findAll(
PageRequest.of(page - 1, size, Sort.by(Sort.Order.desc("createAt")))); PageRequest.of(page - 1, size, Sort.by(Sort.Order.desc("createAt"))));
return new Paging<>(converters.getTotalElements(), converters.getContent()); return new Paging<>(converters.getTotalElements(), converters.getContent());

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.manager.controller; package cc.iotkit.manager.controller;
import cc.iotkit.common.exception.BizException; import cc.iotkit.common.exception.BizException;
@ -20,6 +29,7 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.*; import org.springframework.data.domain.*;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
@ -60,8 +70,12 @@ public class RuleEngineController {
) { ) {
RuleInfo ruleInfo = new RuleInfo(); RuleInfo ruleInfo = new RuleInfo();
ruleInfo.setType(type); ruleInfo.setType(type);
Page<RuleInfo> rules = ruleInfoRepository.findAll(Example.of(dataOwnerService Page<RuleInfo> rules;
.wrapExample(ruleInfo)), Pageable.ofSize(size).withPage(page - 1)); if (AuthUtil.isAdmin()) {
rules = ruleInfoRepository.findByType(type, Pageable.ofSize(size).withPage(page - 1));
} else {
rules = ruleInfoRepository.findByUidAndType(AuthUtil.getUserId(), type, Pageable.ofSize(size).withPage(page - 1));
}
return new Paging<>(rules.getTotalElements(), rules.getContent()); return new Paging<>(rules.getTotalElements(), rules.getContent());
} }
@ -155,9 +169,12 @@ public class RuleEngineController {
@PostMapping("/tasks") @PostMapping("/tasks")
public List<TaskInfo> tasks() { public List<TaskInfo> tasks() {
return taskInfoRepository.findAll(Example.of(dataOwnerService List<TaskInfo> list = new ArrayList<>();
.wrapExample(new TaskInfo())) if (AuthUtil.isAdmin()) {
); taskInfoRepository.findAll().forEach(list::add);
return list;
}
return taskInfoRepository.findByUid(AuthUtil.getUserId());
} }
@PostMapping("/saveTask") @PostMapping("/saveTask")

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.manager.controller; package cc.iotkit.manager.controller;
import cc.iotkit.common.Constants; import cc.iotkit.common.Constants;
@ -15,7 +24,6 @@ import cc.iotkit.model.space.Space;
import cc.iotkit.model.space.SpaceDevice; import cc.iotkit.model.space.SpaceDevice;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.ArrayList; import java.util.ArrayList;
@ -32,7 +40,7 @@ public class SpaceDeviceController {
@Autowired @Autowired
private SpaceDeviceRepository spaceDeviceRepository; private SpaceDeviceRepository spaceDeviceRepository;
@Autowired @Autowired
private DeviceRepository deviceRepository; private DeviceInfoRepository deviceInfoRepository;
@Autowired @Autowired
private DeviceCache deviceCache; private DeviceCache deviceCache;
@Autowired @Autowired
@ -78,7 +86,7 @@ public class SpaceDeviceController {
} }
private SpaceDeviceVo parseSpaceDevice(SpaceDevice sd) { private SpaceDeviceVo parseSpaceDevice(SpaceDevice sd) {
DeviceInfo device = deviceRepository.findByDeviceId(sd.getDeviceId()); DeviceInfo device = deviceInfoRepository.findByDeviceId(sd.getDeviceId());
Space space = spaceCache.getSpace(sd.getSpaceId()); Space space = spaceCache.getSpace(sd.getSpaceId());
Product product = productCache.findById(device.getProductKey()); Product product = productCache.findById(device.getProductKey());
Category category = categoryCache.getById(product.getCategory()); Category category = categoryCache.getById(product.getCategory());
@ -107,7 +115,7 @@ public class SpaceDeviceController {
*/ */
@GetMapping("/{userId}/devices") @GetMapping("/{userId}/devices")
public List<SpaceDeviceVo> getDevices(@PathVariable("userId") String userId) { public List<SpaceDeviceVo> getDevices(@PathVariable("userId") String userId) {
List<SpaceDevice> spaceDevices = spaceDeviceRepository.findAll(Example.of(SpaceDevice.builder().uid(userId).build())); List<SpaceDevice> spaceDevices = spaceDeviceRepository.findByUid(userId);
return spaceDevices.stream().map((this::parseSpaceDevice)).collect(Collectors.toList()); return spaceDevices.stream().map((this::parseSpaceDevice)).collect(Collectors.toList());
} }
@ -121,7 +129,7 @@ public class SpaceDeviceController {
} }
List<FindDeviceVo> findDeviceVos = new ArrayList<>(); List<FindDeviceVo> findDeviceVos = new ArrayList<>();
List<DeviceInfo> devices = deviceRepository.findByDeviceName(mac); List<DeviceInfo> devices = deviceInfoRepository.findByDeviceName(mac);
if (devices == null) { if (devices == null) {
return findDeviceVos; return findDeviceVos;
} }
@ -130,7 +138,7 @@ public class SpaceDeviceController {
List<DeviceInfo> subDevices = new ArrayList<>(); List<DeviceInfo> subDevices = new ArrayList<>();
for (DeviceInfo device : devices) { for (DeviceInfo device : devices) {
if (device.getParentId() == null) { if (device.getParentId() == null) {
subDevices = deviceRepository.findByParentId(device.getDeviceId()); subDevices = deviceInfoRepository.findByParentId(device.getDeviceId());
} }
} }
devices.addAll(subDevices); devices.addAll(subDevices);
@ -167,7 +175,7 @@ public class SpaceDeviceController {
@PostMapping(Constants.API_SPACE.ADD_DEVICE) @PostMapping(Constants.API_SPACE.ADD_DEVICE)
public void addDevice(SpaceDevice device) { public void addDevice(SpaceDevice device) {
String deviceId = device.getDeviceId(); String deviceId = device.getDeviceId();
DeviceInfo deviceInfo = deviceRepository.findByDeviceId(deviceId); DeviceInfo deviceInfo = deviceInfoRepository.findByDeviceId(deviceId);
if (deviceInfo == null) { if (deviceInfo == null) {
throw new BizException("device does not exist"); throw new BizException("device does not exist");
} }
@ -219,7 +227,7 @@ public class SpaceDeviceController {
tags.put(platform, new DeviceInfo.Tag(platform, thirdPlatform.desc, "是")); tags.put(platform, new DeviceInfo.Tag(platform, thirdPlatform.desc, "是"));
} }
deviceRepository.save(deviceInfo); deviceInfoRepository.save(deviceInfo);
} }
/** /**
@ -235,7 +243,7 @@ public class SpaceDeviceController {
dataOwnerService.checkOwner(spaceDevice); dataOwnerService.checkOwner(spaceDevice);
spaceDeviceRepository.deleteById(spaceDevice.getId()); spaceDeviceRepository.deleteById(spaceDevice.getId());
DeviceInfo deviceInfo = deviceRepository.findByDeviceId(deviceId); DeviceInfo deviceInfo = deviceInfoRepository.findByDeviceId(deviceId);
Optional<UserInfo> optUser = userInfoRepository.findById(uid); Optional<UserInfo> optUser = userInfoRepository.findById(uid);
if (optUser.isEmpty()) { if (optUser.isEmpty()) {
throw new BizException("user does not exist"); throw new BizException("user does not exist");
@ -249,7 +257,7 @@ public class SpaceDeviceController {
deviceInfo.getTag().remove(platform); deviceInfo.getTag().remove(platform);
} }
deviceRepository.save(deviceInfo); deviceInfoRepository.save(deviceInfo);
} }
/** /**
@ -296,12 +304,12 @@ public class SpaceDeviceController {
dataOwnerService.checkOwner(spaceDevice); dataOwnerService.checkOwner(spaceDevice);
//找到设备 //找到设备
DeviceInfo deviceInfo = deviceRepository.findByDeviceId(deviceId); DeviceInfo deviceInfo = deviceInfoRepository.findByDeviceId(deviceId);
Map<String, DeviceInfo.Tag> tags = deviceInfo.getTag(); Map<String, DeviceInfo.Tag> tags = deviceInfo.getTag();
String openUidName = platform + "OpenUid"; String openUidName = platform + "OpenUid";
//给设备添加对应平台openUid的设备标签 //给设备添加对应平台openUid的设备标签
Constants.ThirdOpenUid thirdOpenUid = Constants.ThirdOpenUid.valueOf(openUidName); Constants.ThirdOpenUid thirdOpenUid = Constants.ThirdOpenUid.valueOf(openUidName);
tags.put(openUidName, new DeviceInfo.Tag(openUidName, thirdOpenUid.desc, openUid)); tags.put(openUidName, new DeviceInfo.Tag(openUidName, thirdOpenUid.desc, openUid));
deviceRepository.save(deviceInfo); deviceInfoRepository.save(deviceInfo);
} }
} }

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.manager.controller; package cc.iotkit.manager.controller;
import cc.iotkit.dao.*; import cc.iotkit.dao.*;
@ -19,7 +28,7 @@ public class StatsController {
@Autowired @Autowired
private ProductRepository productRepository; private ProductRepository productRepository;
@Autowired @Autowired
private DeviceRepository deviceRepository; private DeviceInfoRepository deviceInfoRepository;
@Autowired @Autowired
private DeviceReportRepository deviceReportRepository; private DeviceReportRepository deviceReportRepository;
@Autowired @Autowired
@ -36,7 +45,7 @@ public class StatsController {
if (AuthUtil.isAdmin()) { if (AuthUtil.isAdmin()) {
mainStats.setCategoryTotal(categoryRepository.count()); mainStats.setCategoryTotal(categoryRepository.count());
mainStats.setProductTotal(productRepository.count()); mainStats.setProductTotal(productRepository.count());
mainStats.setDeviceTotal(deviceRepository.count()); mainStats.setDeviceTotal(deviceInfoRepository.count());
mainStats.setReportTotal(deviceReportRepository.count()); mainStats.setReportTotal(deviceReportRepository.count());
//上报数据统计 //上报数据统计
mainStats.setReportDataStats(deviceReportDao.getDeviceMessageStats(now - 48 * 3600 * 1000, now)); mainStats.setReportDataStats(deviceReportDao.getDeviceMessageStats(now - 48 * 3600 * 1000, now));
@ -45,7 +54,7 @@ public class StatsController {
} else { } else {
mainStats.setCategoryTotal(categoryRepository.count()); mainStats.setCategoryTotal(categoryRepository.count());
mainStats.setProductTotal(productRepository.countByUid(uid)); mainStats.setProductTotal(productRepository.countByUid(uid));
mainStats.setDeviceTotal(deviceRepository.countByUid(uid)); mainStats.setDeviceTotal(deviceInfoRepository.countByUid(uid));
mainStats.setReportTotal(deviceReportRepository.countByUid(uid)); mainStats.setReportTotal(deviceReportRepository.countByUid(uid));
//上报数据统计 //上报数据统计
mainStats.setReportDataStats(deviceReportDao.getDeviceMessageStatsWithUid(uid, now - 48 * 3600 * 1000, now)); mainStats.setReportDataStats(deviceReportDao.getDeviceMessageStatsWithUid(uid, now - 48 * 3600 * 1000, now));

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.manager.controller; package cc.iotkit.manager.controller;
import cc.iotkit.common.exception.BizException; import cc.iotkit.common.exception.BizException;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.manager.controller.aligenie; package cc.iotkit.manager.controller.aligenie;
import cc.iotkit.common.exception.BizException; import cc.iotkit.common.exception.BizException;
@ -29,7 +38,7 @@ public class AligenieDeviceController {
@Autowired @Autowired
private DataOwnerService ownerService; private DataOwnerService ownerService;
@Autowired @Autowired
private DeviceRepository deviceRepository; private DeviceInfoRepository deviceInfoRepository;
@Autowired @Autowired
private AligenieProductRepository aligenieProductRepository; private AligenieProductRepository aligenieProductRepository;
@Autowired @Autowired
@ -66,7 +75,7 @@ public class AligenieDeviceController {
aligenieDeviceRepository.deleteByUid(uid); aligenieDeviceRepository.deleteByUid(uid);
for (Device device : devices) { for (Device device : devices) {
DeviceInfo deviceInfo = deviceRepository.findById(device.getDeviceId()).get(); DeviceInfo deviceInfo = deviceInfoRepository.findById(device.getDeviceId()).get();
AligenieProduct product = aligenieProductRepository.findByProductKey(deviceInfo.getProductKey()); AligenieProduct product = aligenieProductRepository.findByProductKey(deviceInfo.getProductKey());
aligenieDeviceRepository.save(AligenieDevice.builder() aligenieDeviceRepository.save(AligenieDevice.builder()
.uid(user.getId()) .uid(user.getId())

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.manager.controller.aligenie; package cc.iotkit.manager.controller.aligenie;
import cc.iotkit.dao.AligenieProductRepository; import cc.iotkit.dao.AligenieProductRepository;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.manager.controller.api; package cc.iotkit.manager.controller.api;
import cc.iotkit.dao.AppInfoRepository; import cc.iotkit.dao.AppInfoRepository;
@ -37,8 +46,10 @@ public class AccountController {
throw new RuntimeException("用户不属于该家庭"); throw new RuntimeException("用户不属于该家庭");
} }
UserInfo userInfo = userInfoRepository.findOne(Example.of(UserInfo.builder().uid(uid).build())) UserInfo userInfo = userInfoRepository.findByUid(uid);
.orElseThrow(() -> new RuntimeException(("用户信息不存在"))); if (userInfo == null) {
throw new RuntimeException("用户信息不存在");
}
userInfo.setCurrHomeId(homeId); userInfo.setCurrHomeId(homeId);
userInfoRepository.save(userInfo); userInfoRepository.save(userInfo);
} }
@ -52,6 +63,6 @@ public class AccountController {
@GetMapping("/getAppInfo") @GetMapping("/getAppInfo")
public AppInfo getAppInfo() { public AppInfo getAppInfo() {
return appInfoRepository.findAll().get(0); return appInfoRepository.findAll().iterator().next();
} }
} }

View File

@ -1,7 +1,16 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.manager.controller.api; package cc.iotkit.manager.controller.api;
import cc.iotkit.dao.AppDesignRepository; import cc.iotkit.dao.AppDesignRepository;
import cc.iotkit.dao.DeviceRepository; import cc.iotkit.dao.DeviceInfoRepository;
import cc.iotkit.dao.SpaceDeviceRepository; import cc.iotkit.dao.SpaceDeviceRepository;
import cc.iotkit.manager.model.vo.AppPageNode; import cc.iotkit.manager.model.vo.AppPageNode;
import cc.iotkit.manager.service.AppDesignService; import cc.iotkit.manager.service.AppDesignService;
@ -12,12 +21,12 @@ import cc.iotkit.utils.AuthUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -29,7 +38,7 @@ public class DeviceController {
@Autowired @Autowired
private DeviceService deviceService; private DeviceService deviceService;
@Autowired @Autowired
private DeviceRepository deviceRepository; private DeviceInfoRepository deviceInfoRepository;
@Autowired @Autowired
private SpaceDeviceRepository spaceDeviceRepository; private SpaceDeviceRepository spaceDeviceRepository;
@Autowired @Autowired
@ -39,7 +48,9 @@ public class DeviceController {
@GetMapping("/list") @GetMapping("/list")
public List<DeviceInfo> list() { public List<DeviceInfo> list() {
return deviceRepository.findAll(); List<DeviceInfo> list = new ArrayList<>();
deviceInfoRepository.findAll().forEach(list::add);
return list;
} }
@GetMapping("/{deviceId}") @GetMapping("/{deviceId}")
@ -47,13 +58,12 @@ public class DeviceController {
if (StringUtils.isBlank(deviceId)) { if (StringUtils.isBlank(deviceId)) {
throw new RuntimeException("deviceId is blank."); throw new RuntimeException("deviceId is blank.");
} }
return deviceRepository.findById(deviceId).orElseThrow(() -> new RuntimeException("device not found.")); return deviceInfoRepository.findById(deviceId).orElseThrow(() -> new RuntimeException("device not found."));
} }
@GetMapping("/getAllDeviceIds") @GetMapping("/getAllDeviceIds")
public List<String> getAllDeviceIds() { public List<String> getAllDeviceIds() {
List<SpaceDevice> spaceDevices = spaceDeviceRepository.findAll( List<SpaceDevice> spaceDevices = spaceDeviceRepository.findByUid(AuthUtil.getUserId());
Example.of(SpaceDevice.builder().uid(AuthUtil.getUserId()).build()));
return spaceDevices.stream() return spaceDevices.stream()
.map(SpaceDevice::getDeviceId) .map(SpaceDevice::getDeviceId)
.collect(Collectors.toList()); .collect(Collectors.toList());
@ -61,7 +71,7 @@ public class DeviceController {
@GetMapping("/detailPage/{deviceId}") @GetMapping("/detailPage/{deviceId}")
public List<AppPageNode> deviceDetailPage(@PathVariable("deviceId") String deviceId) { public List<AppPageNode> deviceDetailPage(@PathVariable("deviceId") String deviceId) {
DeviceInfo device = deviceRepository.findById(deviceId).orElseThrow(() -> new RuntimeException("device not found")); DeviceInfo device = deviceInfoRepository.findById(deviceId).orElseThrow(() -> new RuntimeException("device not found"));
return appDesignService.getAppPageNodes(device.getProductKey()); return appDesignService.getAppPageNodes(device.getProductKey());
} }

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.manager.controller.api; package cc.iotkit.manager.controller.api;
import cc.iotkit.dao.HomeRepository; import cc.iotkit.dao.HomeRepository;
@ -51,9 +60,7 @@ public class HomeController {
@GetMapping("/list") @GetMapping("/list")
public List<Home> list() { public List<Home> list() {
// return homeRepository.findAll(); return homeRepository.findByUid(AuthUtil.getUserId());
return homeRepository.findAll(Example.of(Home.builder()
.uid(AuthUtil.getUserId()).build()));
} }
@PostMapping("/addSpace") @PostMapping("/addSpace")
@ -62,8 +69,10 @@ public class HomeController {
throw new RuntimeException("name/homeId is blank."); throw new RuntimeException("name/homeId is blank.");
} }
String uid = AuthUtil.getUserId(); String uid = AuthUtil.getUserId();
Home home = homeRepository.findOne(Example.of(Home.builder().uid(uid).id(homeId).build())) Home home = homeRepository.findByUidAndId(uid, homeId);
.orElseThrow(() -> new RuntimeException("用户家庭不存在")); if (home == null) {
throw new RuntimeException("用户家庭不存在");
}
Space s = spaceRepository.save(Space.builder() Space s = spaceRepository.save(Space.builder()
.name(name) .name(name)
@ -96,8 +105,7 @@ public class HomeController {
if (StringUtils.isBlank(homeId)) { if (StringUtils.isBlank(homeId)) {
throw new RuntimeException("homeId is blank."); throw new RuntimeException("homeId is blank.");
} }
// return spaceRepository.findAll(); return spaceRepository.findByHomeId(homeId);
return spaceRepository.findAll(Example.of(Space.builder().homeId(homeId).build()));
} }
@GetMapping("/getCurrentHome") @GetMapping("/getCurrentHome")

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.manager.controller.api; package cc.iotkit.manager.controller.api;
import cc.iotkit.dao.ProductRepository; import cc.iotkit.dao.ProductRepository;
@ -10,6 +19,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@RestController("api-product") @RestController("api-product")
@ -23,7 +33,9 @@ public class ProductController {
@GetMapping("/list") @GetMapping("/list")
public List<Product> list() { public List<Product> list() {
return productRepository.findAll(); List<Product> list = new ArrayList<>();
productRepository.findAll().forEach(list::add);
return list;
} }
@GetMapping("/{pk}") @GetMapping("/{pk}")

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.manager.controller.api; package cc.iotkit.manager.controller.api;
import cc.iotkit.dao.*; import cc.iotkit.dao.*;
@ -10,7 +19,7 @@ import cc.iotkit.model.space.SpaceDevice;
import cc.iotkit.utils.AuthUtil; import cc.iotkit.utils.AuthUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example; import org.springframework.data.elasticsearch.core.query.Criteria;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -28,7 +37,7 @@ public class SpaceController {
@Autowired @Autowired
private SpaceDeviceRepository spaceDeviceRepository; private SpaceDeviceRepository spaceDeviceRepository;
@Autowired @Autowired
private DeviceRepository deviceRepository; private DeviceInfoRepository deviceInfoRepository;
@Autowired @Autowired
private CategoryRepository categoryRepository; private CategoryRepository categoryRepository;
@Autowired @Autowired
@ -41,6 +50,8 @@ public class SpaceController {
private DeviceCache deviceCache; private DeviceCache deviceCache;
@Autowired @Autowired
private SpaceDeviceService spaceDeviceService; private SpaceDeviceService spaceDeviceService;
@Autowired
private CommonDao commonDao;
@PostMapping("/addGateway") @PostMapping("/addGateway")
public void addGateway(String pk, String mac, String name, String spaceId) { public void addGateway(String pk, String mac, String name, String spaceId) {
@ -48,14 +59,12 @@ public class SpaceController {
throw new RuntimeException("pk/name/mac/spaceId is blank."); throw new RuntimeException("pk/name/mac/spaceId is blank.");
} }
mac = mac.toUpperCase(); mac = mac.toUpperCase();
DeviceInfo device = deviceRepository.findOne(Example.of(DeviceInfo.builder() DeviceInfo device = deviceInfoRepository.findByProductKeyAndDeviceName(pk, mac);
.productKey(pk) if (device == null) {
.deviceName(mac).build())).orElseThrow(() -> new RuntimeException("未找到该设备")); throw new RuntimeException("未找到该设备");
}
Space space = spaceRepository.findById(spaceId).orElseThrow(() -> new RuntimeException("未找到空间")); Space space = spaceRepository.findById(spaceId).orElseThrow(() -> new RuntimeException("未找到空间"));
addSpaceDevice(name, device, space); addSpaceDevice(name, device, space);
//
// List<DeviceInfo> addDevices = deviceRepository.findAll(Example.of(DeviceInfo.builder().parentId(device.getDeviceId()).build()));
// addDevices.forEach((d -> addSpaceDevice(null, d, space)));
} }
@PostMapping("/add") @PostMapping("/add")
@ -63,7 +72,7 @@ public class SpaceController {
if (StringUtils.isBlank(deviceId) || StringUtils.isBlank(name) || StringUtils.isBlank(spaceId)) { if (StringUtils.isBlank(deviceId) || StringUtils.isBlank(name) || StringUtils.isBlank(spaceId)) {
throw new RuntimeException("deviceId/name/spaceId is blank."); throw new RuntimeException("deviceId/name/spaceId is blank.");
} }
DeviceInfo device = deviceRepository.findById(deviceId) DeviceInfo device = deviceInfoRepository.findById(deviceId)
.orElseThrow(() -> new RuntimeException("device not found.")); .orElseThrow(() -> new RuntimeException("device not found."));
Space space = spaceRepository.findById(spaceId) Space space = spaceRepository.findById(spaceId)
.orElseThrow(() -> new RuntimeException("space not found.")); .orElseThrow(() -> new RuntimeException("space not found."));
@ -73,8 +82,7 @@ public class SpaceController {
@PostMapping("/scan") @PostMapping("/scan")
public List<SpaceDeviceVo> scan() { public List<SpaceDeviceVo> scan() {
//找到网关产品id //找到网关产品id
List<String> gateways = productRepository.findAll(Example List<String> gateways = productRepository.findByCategory("gateway")
.of(Product.builder().category("gateway").build()))
.stream().map(Product::getId).collect(Collectors.toList()); .stream().map(Product::getId).collect(Collectors.toList());
//找到用户已添加的所有设备 //找到用户已添加的所有设备
List<SpaceDeviceVo> spaceDeviceVos = spaceDeviceService.getUserDevices(AuthUtil.getUserId(), ""); List<SpaceDeviceVo> spaceDeviceVos = spaceDeviceService.getUserDevices(AuthUtil.getUserId(), "");
@ -84,8 +92,8 @@ public class SpaceController {
List<DeviceInfo> foundDevices = new ArrayList<>(); List<DeviceInfo> foundDevices = new ArrayList<>();
//找到网关下的所有设备 //找到网关下的所有设备
userGateways.forEach((g) -> foundDevices.addAll(deviceRepository.findAll(Example.of(DeviceInfo.builder() userGateways.forEach((g) -> foundDevices.addAll(
.parentId(g.getDeviceId()).build())))); deviceInfoRepository.findByParentId(g.getDeviceId())));
//过滤已添加的设备 //过滤已添加的设备
return foundDevices.stream().filter((d) -> { return foundDevices.stream().filter((d) -> {
@ -105,15 +113,16 @@ public class SpaceController {
@GetMapping("/devices") @GetMapping("/devices")
public List<SpaceDeviceVo> devices(String homeId, String spaceId) { public List<SpaceDeviceVo> devices(String homeId, String spaceId) {
Criteria criteria = new Criteria();
SpaceDevice device = new SpaceDevice(); SpaceDevice device = new SpaceDevice();
device.setUid(AuthUtil.getUserId()); device.setUid(AuthUtil.getUserId());
if (StringUtils.isNotBlank(spaceId)) { if (StringUtils.isNotBlank(spaceId)) {
device.setSpaceId(spaceId); criteria = criteria.and("spaceId").is(spaceId);
} else { } else {
device.setHomeId(homeId); criteria = criteria.and("homeId").is(homeId);
} }
List<SpaceDevice> spaceDevices = commonDao.find(SpaceDevice.class, criteria);
List<SpaceDevice> spaceDevices = spaceDeviceRepository.findAll(Example.of(device));
List<SpaceDeviceVo> spaceDeviceVos = new ArrayList<>(); List<SpaceDeviceVo> spaceDeviceVos = new ArrayList<>();
spaceDevices.forEach(sd -> spaceDeviceVos.add(buildSpaceDeviceVo( spaceDevices.forEach(sd -> spaceDeviceVos.add(buildSpaceDeviceVo(
sd.getId(), sd.getDeviceId(), sd.getId(), sd.getDeviceId(),
@ -133,10 +142,12 @@ public class SpaceController {
@GetMapping("/getDeviceByMac") @GetMapping("/getDeviceByMac")
public SpaceDeviceVo getDeviceByMac(String mac) { public SpaceDeviceVo getDeviceByMac(String mac) {
DeviceInfo device = deviceRepository.findOne(Example.of(DeviceInfo.builder().deviceName(mac).build())) List<DeviceInfo> devices = deviceInfoRepository.findByDeviceName(mac);
.orElseThrow(() -> new RuntimeException("device not found by mac")); if (devices.size() == 0) {
throw new RuntimeException("device not found by mac");
}
return buildSpaceDeviceVo("", device.getDeviceId(), return buildSpaceDeviceVo("", devices.get(0).getDeviceId(),
AuthUtil.getUserId(), "", ""); AuthUtil.getUserId(), "", "");
} }
@ -170,10 +181,7 @@ public class SpaceController {
private void addSpaceDevice(String name, DeviceInfo device, Space space) { private void addSpaceDevice(String name, DeviceInfo device, Space space) {
String uid = AuthUtil.getUserId(); String uid = AuthUtil.getUserId();
SpaceDevice sd = spaceDeviceRepository.findOne(Example.of(SpaceDevice SpaceDevice sd = spaceDeviceRepository.findByDeviceId(device.getDeviceId());
.builder()
.deviceId(device.getDeviceId()).build())
).orElse(null);
String id = null; String id = null;
//重复添加,更新 //重复添加,更新

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.manager.model.aligenie; package cc.iotkit.manager.model.aligenie;
import cc.iotkit.model.aligenie.AligenieProduct; import cc.iotkit.model.aligenie.AligenieProduct;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.manager.model.vo; package cc.iotkit.manager.model.vo;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.manager.model.vo; package cc.iotkit.manager.model.vo;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.manager.model.vo; package cc.iotkit.manager.model.vo;
import lombok.Data; import lombok.Data;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.manager.model.vo; package cc.iotkit.manager.model.vo;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;

Some files were not shown because too many files have changed in this diff Show More