thingsboard 技术研究

汉化文件:

D:\work\code\Iot\thingsboard\ThingsBoard\ui-ngx\src\assets\locale\locale.constant-zh_CN.json

有待研究,汉化的工作机制,比如,新添加一个页面,应该如何利用现有汉化机制,
谁发起的这个请求,请求到汉化数据后,是如何作用到对应的 页面上的元素的
http://localhost:8080/assets/locale/locale.constant-zh_CN.json

用户相关

登录后刷新页面

http://localhost:8080/api/user/91e93fc0-3df0-11eb-92ac-7b6426abd32d
org.thingsboard.server.controller.UserController#getUserById

-->org.thingsboard.server.controller.BaseController#checkUserId
    -->accessControlService.checkPermission(getCurrentUser(), Resource.USER, operation, userId, user); (注意: 这里有权限坚持的动作)

select *
from tb_user userentity0_
where userentity0_.id='91e93fc0-3df0-11eb-92ac-7b6426abd32d'

验证token

http://localhost:8080/api/user/tokenAccessEnabled

org.thingsboard.server.controller.UserController#isUserTokenAccessEnabled

首页 dashboard

查看最多放多少个部件,此数在配置文件中,不需要查询数据库
http://localhost:8080/api/dashboard/maxDatapointsLimit
org.thingsboard.server.controller.DashboardController#getMaxDatapointsLimit

租户相关

查询租户列表

http://localhost:8080/api/tenants?pageSize=10&page=0&sortProperty=createdTime&sortOrder=DESC

org.thingsboard.server.controller.TenantController#getTenants
-->org.thingsboard.server.controller.BaseController#createPageLink
-->org.thingsboard.server.common.data.page.PageLink#PageLink(int, int, java.lang.String, org.thingsboard.server.common.data.page.SortOrder)
-->org.thingsboard.server.dao.tenant.TenantServiceImpl#findTenants
-->org.thingsboard.server.dao.sql.tenant.JpaTenantDao#findTenantsByRegion(TenantId tenantId, String region, PageLink pageLink)
默认根据时间排序,倒叙排序

SELECT t FROM TenantEntity t WHERE t.region = :region " +
"AND LOWER(t.searchText) LIKE LOWER(CONCAT(:textSearch, '%'));

添加租户

http://localhost:8080/api/tenant
post
org.thingsboard.server.controller.TenantController#saveTenant
添加租户时,默认区域是全局
org.thingsboard.server.dao.tenant.TenantServiceImpl#findTenants

org.thingsboard.server.dao.tenant.TenantDao#save

添加租户时,默认添加过滤器链

先从指定路径,获取默认过滤器链
D:\work\code\Iot\thingsboard\ThingsBoard\application\src\main\data\json\tenant\rule_chains

文件内容:

默认给改租户添加规则和规则元数据

INSERT INTO relation (from_id, from_type, to_id, to_type, relation_type_group, relation_type, additional_info) VALUES (?, ?, ?, ?, ?, ?, ?) ON CONFLICT (from_id, from_type, relation_type_group, relation_type, to_id, to_type) DO UPDATE SET additional_info = ? returning *

insert into rule_chain (created_time, additional_info, configuration, debug_mode, first_rule_node_id, name, root, search_text, tenant_id, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

insert into rule_node (created_time, additional_info, configuration, debug_mode, name, rule_chain_id, search_text, type, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?)

点击租户头像,显示本租户的管理员

http://localhost:8080/api/tenant/70e5b200-3e1c-11eb-b621-25965fbb57cc/users?pageSize=10&page=0&sortProperty=createdTime&sortOrder=DESC

org.thingsboard.server.controller.TenantController#getTenantById
org.thingsboard.server.dao.tenant.TenantServiceImpl#findTenantById

select * from tenant tenantenti0_ where tenantenti0_.id='70e5b200-3e1c-11eb-b621-25965fbb57cc'

给租户添加管理员

http://localhost:8080/api/user?sendActivationMail=false

org.thingsboard.server.controller.UserController#saveUser
-->org.thingsboard.server.dao.user.UserServiceImpl#saveUser
-->org.thingsboard.server.dao.user.UserDao#save
设置当前租户的id
检查是发email 激活,还是连接方式激活
如果发送email异常,会删除已添加的管理员,此步骤有程序控制

获取管理员的激活连接,根据用户id

org.thingsboard.server.controller.UserController#getActivationLink
org.thingsboard.server.dao.user.UserService#findUserCredentialsByUserId

规则链

删除规则链

DELETE /api/ruleChain/7a742c00-3e7d-11eb-b621-25965fbb57cc HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Accept: application/json, text/plain, /
Origin: http://localhost:8080
X-Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJvY2VsbHVzbHpoQDEyNi5jb20iLCJzY29wZXMiOlsiVEVOQU5UX0FETUlOIl0sInVzZXJJZCI6IjJhYzlmOTQwLTNlMWYtMTFlYi1iNjIxLTI1OTY1ZmJiNTdjYyIsImZpcnN0TmFtZSI6Inpob25naHVhIiwibGFzdE5hbWUiOiJsaSIsImVuYWJsZWQiOnRydWUsImlzUHVibGljIjpmYWxzZSwidGVuYW50SWQiOiI3MGU1YjIwMC0zZTFjLTExZWItYjYyMS0yNTk2NWZiYjU3Y2MiLCJjdXN0b21lcklkIjoiMTM4MTQwMDAtMWRkMi0xMWIyLTgwODAtODA4MDgwODA4MDgwIiwiaXNzIjoidGhpbmdzYm9hcmQuaW8iLCJpYXQiOjE2MDc5OTkwMzQsImV4cCI6MTYwODAwODAzNH0.2f4g6GcHHTpVc1kDrPioxrb_1f3oqsI-3epkvNFQ4z0j1dVrJ5uKiTuZbZLHpyzbXhTUHwFmfmy2id3glYi-RQ
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36
Content-Type: application/json
Referer: http://localhost:8080/ruleChains
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8

org.thingsboard.server.controller.RuleChainController#deleteRuleChain

org.thingsboard.server.dao.rule.BaseRuleChainService#checkRuleNodesAndDelete
private void checkRuleNodesAndDelete(TenantId tenantId, RuleChainId ruleChainId) {
List nodeRelations = getRuleChainToNodeRelations(tenantId, ruleChainId);
for (EntityRelation relation : nodeRelations) {
deleteRuleNode(tenantId, relation.getTo());
}
deleteEntityRelations(tenantId, ruleChainId);
ruleChainDao.removeById(tenantId, ruleChainId.getId());
}

select relationen0_.from_id as from_id1_12_, relationen0_.from_type as from_typ2_12_, relationen0_.relation_type as relation3_12_, relationen0_.relation_type_group as relation4_12_, relationen0_.to_id as to_id5_12_, relationen0_.to_type as to_type6_12_, relationen0_.additional_info as addition7_12_ from relation relationen0_ where relationen0_.from_id=? and relationen0_.from_type=? and relationen0_.relation_type_group=?

delete from rule_chain where id=?

客户相关

查询客户列表

http://localhost:8080/api/customers?pageSize=10&page=0&sortProperty=createdTime&sortOrder=DESC

org.thingsboard.server.controller.CustomerController#getCustomers
org.thingsboard.server.dao.customer.CustomerService#findCustomersByTenantId
org.thingsboard.server.dao.customer.CustomerDao#findCustomersByTenantId

select * from customer customeren0_ where customeren0_.tenant_id=? and (lower(customeren0_.search_text) like lower((?||'%'))) order by customeren0_.created_time desc nulls last limit ?

添加客户

http://localhost:8080/api/customer
Request Method: POST
org.thingsboard.server.controller.CustomerController#saveCustomer
org.thingsboard.server.dao.customer.CustomerService#saveCustomer

public Customer saveCustomer(Customer customer) {
log.trace("Executing saveCustomer [{}]", customer);
customerValidator.validate(customer, Customer::getTenantId);
Customer savedCustomer = customerDao.save(customer.getTenantId(), customer);
dashboardService.updateCustomerDashboards(savedCustomer.getTenantId(), savedCustomer.getId());
return savedCustomer;
}

public enum Resource {
ADMIN_SETTINGS(),
ALARM(EntityType.ALARM),
DEVICE(EntityType.DEVICE),
ASSET(EntityType.ASSET),
CUSTOMER(EntityType.CUSTOMER),
DASHBOARD(EntityType.DASHBOARD),
ENTITY_VIEW(EntityType.ENTITY_VIEW),
TENANT(EntityType.TENANT),
RULE_CHAIN(EntityType.RULE_CHAIN),
USER(EntityType.USER),
WIDGETS_BUNDLE(EntityType.WIDGETS_BUNDLE),
WIDGET_TYPE(EntityType.WIDGET_TYPE);

insert into customer (created_time, additional_info, address, address2, city, country, email, phone, search_text, state, tenant_id, title, zip, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

insert into audit_log (created_time, action_data, action_failure_details, action_status, action_type, customer_id, entity_id, entity_name, entity_type, tenant_id, user_id, user_name, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

资产相关

查询资产

http://localhost:8080/api/tenant/assetInfos?pageSize=50&page=0&sortProperty=name&sortOrder=ASC&type=
Request Method: GET
org.thingsboard.server.controller.AssetController#getTenantAssetInfos
org.thingsboard.server.dao.asset.AssetService#findAssetInfosByTenantIdAndType
org.thingsboard.server.dao.asset.AssetDao#findAssetInfosByTenantId

select distinct assetentit0_.type as col_0_0_ from asset assetentit0_ where assetentit0_.tenant_id=?

select * from asset assetentit0_
left outer join customer customeren1_ on (customeren1_.id=assetentit0_.customer_id)
where assetentit0_.tenant_id=? and (lower(assetentit0_.search_text) like lower((?||'%'))) order by assetentit0_.created_time desc nulls last limit ?

分配资产

http://localhost:8080/api/customer/4f0b39b0-3e9f-11eb-b621-25965fbb57cc/asset/3d389a00-3e1f-11eb-b621-25965fbb57cc
Request Method: POST

org.thingsboard.server.controller.AssetController#assignAssetToCustomer

org.thingsboard.server.dao.asset.AssetService#assignAssetToCustomer

update asset set created_time=?, additional_info=?, customer_id=?, label=?, name=?, search_text=?, tenant_id=?, type=? where id=?

insert into audit_log (created_time, action_data, action_failure_details, action_status, action_type, customer_id, entity_id, entity_name, entity_type, tenant_id, user_id, user_name, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

仪表盘相关

查询仪表盘

http://localhost:8080/api/tenant/dashboards?pageSize=10&page=0&sortProperty=createdTime&sortOrder=DESC
Request Method: GET

org.thingsboard.server.controller.DashboardController#getTenantDashboards(int, int, java.lang.String, java.lang.String, java.lang.String)

org.thingsboard.server.dao.dashboard.DashboardService#findDashboardsByTenantId

org.thingsboard.server.dao.dashboard.DashboardInfoDao#findDashboardsByTenantId

select * from dashboard dashboardi0_ where dashboardi0_.tenant_id=? and (lower(dashboardi0_.search_text) like lower((?||'%'))) order by dashboardi0_.created_time desc nulls last limit ?

添加仪表盘

org.thingsboard.server.controller.DashboardController#saveDashboard
org.thingsboard.server.dao.dashboard.DashboardService#saveDashboard
org.thingsboard.server.dao.dashboard.DashboardDao#save

select * from tenant tenantenti0_ where tenantenti0_.id=?
insert into dashboard (created_time, assigned_customers, configuration, search_text, tenant_id, title, id) values (?, ?, ?, ?, ?, ?, ?)
insert into audit_log (created_time, action_data, action_failure_details, action_status, action_type, customer_id, entity_id, entity_name, entity_type, tenant_id, user_id, user_name, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

实体相关

查询实体类型

http://localhost:8080/api/entityView/types
Request Method: GET

org.thingsboard.server.controller.EntityViewController#getEntityViewTypes
org.thingsboard.server.dao.entityview.EntityViewService#findEntityViewTypesByTenantId
org.thingsboard.server.dao.entityview.EntityViewDao#findTenantEntityViewTypesAsync

select distinct entityview0_.type as col_0_0_ from entity_view entityview0_ where entityview0_.tenant_id=?

查询实体列表

http://localhost:8080/api/tenant/entityViewInfos?pageSize=10&page=0&sortProperty=createdTime&sortOrder=DESC&type=
Request Method: GET

org.thingsboard.server.controller.EntityViewController#getTenantEntityViewInfos
org.thingsboard.server.dao.entityview.EntityViewService#findEntityViewInfosByTenantIdAndType
org.thingsboard.server.dao.entityview.EntityViewDao#findEntityViewInfosByTenantIdAndType

select * from entity_view entityview0_
left outer join customer customeren1_ on (customeren1_.id=entityview0_.customer_id)
where entityview0_.tenant_id=? and (lower(entityview0_.search_text) like lower((?||'%'))) order by entityview0_.created_time desc nulls last limit ?

实体分配给客户

http://localhost:8080/api/customer/4f0b39b0-3e9f-11eb-b621-25965fbb57cc/entityView/d403a660-3eaf-11eb-b621-25965fbb57cc
Request Method: POST

org.thingsboard.server.controller.EntityViewController#assignEntityViewToCustomer
org.thingsboard.server.dao.entityview.EntityViewService#assignEntityViewToCustomer
org.thingsboard.server.dao.entityview.EntityViewDao#save

部件相关

部件列表查询

http://localhost:8080/api/widgetsBundles?pageSize=10&page=0&sortProperty=createdTime&sortOrder=DESC
Request Method: GET

org.thingsboard.server.controller.WidgetsBundleController#getWidgetsBundles()
org.thingsboard.server.dao.widget.WidgetsBundleService#findAllTenantWidgetsBundlesByTenantId
org.thingsboard.server.dao.widget.WidgetsBundleDao#findAllTenantWidgetsBundlesByTenantId

select *from widgets_bundle widgetsbun0_ where (widgetsbun0_.tenant_id in (? , ?)) and (lower(widgetsbun0_.search_text) like lower((?||'%'))) order by widgetsbun0_.created_time desc nulls last limit ?
select count(widgetsbun0_.id) as col_0_0_ from widgets_bundle widgetsbun0_ where (widgetsbun0_.tenant_id in (? , ?)) and (lower(widgetsbun0_.search_text) like lower((?||'%')))

打开组件列表里的单个

http://localhost:8080/api/widgetsBundle/922f9790-3df0-11eb-92ac-7b6426abd32d
Request Method: GET

org.thingsboard.server.controller.WidgetsBundleController#getWidgetsBundleById
org.thingsboard.server.dao.widget.WidgetsBundleService#findWidgetsBundleById
org.thingsboard.server.dao.Dao#findById

select * from widgets_bundle widgetsbun0_ where widgetsbun0_.id='922892b0-3df0-11eb-92ac-7b6426abd32d';

查询某个类型下的所有部件

http://localhost:8080/api/widgetTypes?isSystem=true&bundleAlias=cards
Request Method: GET

org.thingsboard.server.controller.WidgetTypeController#getBundleWidgetTypes
org.thingsboard.server.dao.widget.WidgetTypeService#findWidgetTypesByTenantIdAndBundleAlias
org.thingsboard.server.dao.widget.WidgetTypeDao#findWidgetTypesByTenantIdAndBundleAlias

select * from widget_type widgettype0_ where widgettype0_.tenant_id='13814000-1dd2-11b2-8080-808080808080' and widgettype0_.bundle_alias='cards'

编辑某个部件

http://localhost:8080/api/widgetType/922ab590-3df0-11eb-92ac-7b6426abd32d
Request Method: GET

org.thingsboard.server.controller.WidgetTypeController#getWidgetTypeById
org.thingsboard.server.dao.widget.WidgetTypeService#findWidgetTypeById

select * from widget_type widgettype0_ where widgettype0_.id='922ab590-3df0-11eb-92ac-7b6426abd32d'

posted @ 2020-12-14 23:34  一锤定音885  阅读(871)  评论(0)    收藏  举报