Thingsboard二次开发系列拷贝篇-06关联关系

素材和版本

tb-release:3.2.2

目标

为了熟悉“关联”这个组件的功能,也看是否能运用到当期系统上:

比如针对“车辆”,那可以用关联关系,从项目那引出“包含”车辆关系,从“工人”那引出使用车辆关系,从“工单”那引出“使用”车辆关系。总之是能使用任何关系将多个实体进行关联。优势在于灵活,劣势在于数据量会级数增长,并且查询关系会稍微复杂一些。

有点类似以前设计的中间关联表的概念,这里的关联属于通用类型的中间关联表。



涉及表“relation”


涉及代码

1)前端


srcappcorehttpentity-relation.service.ts

 

srcappmoduleshomecomponents elation elation-dialog.component.html

srcappmoduleshomecomponents elation elation-dialog.component.scss

srcappmoduleshomecomponents elation elation-dialog.component.ts

srcappmoduleshomecomponents elation elation-filters.component.html

srcappmoduleshomecomponents elation elation-filters.component.scss

srcappmoduleshomecomponents elation elation-filters.component.ts

srcappmoduleshomecomponents elation elation-table.component.html

srcappmoduleshomecomponents elation elation-table.component.scss

srcappmoduleshomecomponents elation elation-table.component.ts

 

srcappsharedmodels elation.models.ts

 

srcappsharedcomponents elation elation-type-autocomplete.component.html

srcappsharedcomponents elation elation-type-autocomplete.component.ts





srcappmoduleshomecomponents elation elation-table.component.html


selector: 'tb-relation-table',


使用方法(srcappmoduleshomepagesassetasset-tabs.component.html):


一般会被运用于tab组件里面,直接用于关联。



关联实体类型组件:

tb-relation-type-autocomplete

srcappcorehttpentity.service.ts-》prepareAllowedEntityTypesList



srcappmoduleshomecomponents elation elation-dialog.component.html


关联类型:

<tb-relation-type-autocomplete

        formControlName="type"

        required="true">

      </tb-relation-type-autocomplete>

实体(类型):

<small>{{(direction === entitySearchDirection.FROM ?

          'relation.to-entity' : 'relation.from-entity') | translate}}</small>

      <tb-entity-list-select

        formControlName="targetEntityIds"

        required="true">

      </tb-entity-list-select>


<tb-entity-type-select

    style="min-width: 100px; padding-right: 8px;"

    *ngIf="displayEntityTypeSelect"

    [showLabel]="true"

    [required]="required"

    [useAliasEntityTypes]="useAliasEntityTypes"

    [allowedEntityTypes]="allowedEntityTypes"

    formControlName="entityType">

  </tb-entity-type-select>



实体列表:

<tb-entity-list

    [ngClass]="{'tb-not-empty': this.modelValue.ids?.length > 0}"

    fxFlex

    *ngIf="modelValue.entityType"

    [required]="required"

    [entityType]="modelValue.entityType"

    formControlName="entityIds">

  </tb-entity-list>




其实它这里是分两种获取方式,一种是获取所有数据,一种是按分页来获取。


    2)后端


增加车辆的关联关系分类后,发现可以增加成功,但是加载关系表数据的时候出错了,调试后发现了问题所在 BaseEntityService.java。



src/main/java/org/thingsboard/server/dao/entity/BaseEntityService.java




    增加关联类型




    下一步


关联关系能够起到关联所有的主表,使得完全松耦合。

简介:

关注Scratch、Microbit、MCU、ESP、少儿编程、编程小车、开源IoT框架等

更多交流请嘉Q群:217567614


©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • application [ˌæplɪ'keɪʃ(ə)n]应用程式应用、应用程序 application frame...
    我不白先生阅读 6,787评论 0 3
  • 导语: 如果你已经加入了iOS攻城狮队伍,那么我们由衷地祝贺您正式成为一名终身学习的程序猿;有人觉得这句话...
    超人猿阅读 7,077评论 3 19
  • 我是黑夜里大雨纷飞的人啊 1 “又到一年六月,有人笑有人哭,有人欢乐有人忧愁,有人惊喜有人失落,有的觉得收获满满有...
    陌忘宇阅读 12,735评论 28 53
  • 步骤:发微博01-导航栏内容 -> 发微博02-自定义TextView -> 发微博03-完善TextView和...
    dibadalu阅读 8,400评论 1 3
  • 人工智能是什么?什么是人工智能?人工智能是未来发展的必然趋势吗?以后人工智能技术真的能达到电影里机器人的智能水平吗...
    ZLLZ阅读 9,392评论 0 5