• 利用Graphviz绘制逻辑关系依赖图


    说明:在很多情况下,需要将复杂且有些规律的代码整理成逻辑片段,这个时候就需要画图,很多时候图比代码更加直观

    Graphviz是一个比较好的绘图工具,可以通过简单的代码绘制出复杂的逻辑图,且其代码就像平时说话的语言一样直观

    案例中是我在开发中整理的一个复杂的sql中的表依赖关系:

    代码:

    digraph sbjob{
    graph [fontname=Arial, nodesep=0.125, ranksep=0.25];
    node [fontcolor=black, fontname=Arial, height=0, shape=box, style=filled, width=0];
    edge [fontname=Arial, len=3.5];

    INT_STG_OCS_TB_OCS_ACCOUNTEXT_SUBSCRIBER_SD [label="INT_STG_OCS_ TB_OCS_ACCOUNTEXT_ SUBSCRIBER_SD"]

    STG_OCS_TB_OCS_ACCOUNTEXT_SUBSCRIBER [label="STG_OCS_TB_ OCS_ACCOUNTEXT _SUBSCRIBER"]

    LOAD_DATE_PARAMETERS_TBL [label="LOAD_DATE_ PARAMETERS_TBL"]

    SUBSCRIBER_AUDIT_TB [label="SUBSCRIBER_ AUDIT_TB"]

    STG_INF_CONTACT_PERSON [label="STG_INF_CONTACT _PERSON"]

    INT_STG_INF_CONTACT_PERSON [label="INT_STG_INF_ CONTACT_PERSON"]

    STG_INF_CUSTOMER_ALL [label="STG_INF_ CUSTOMER_ALL"]

    INT_STG_INF_CUSTOMER_ALL [label="INT_STG_INF_ CUSTOMER_ALL"]

    STG_OCS_ACCOUNTS_SUBCRIBER [label="STG_OCS_ACCOUNTS _SUBCRIBER"]

    INT_STG_OCS_ACCOUNTS_SUBCRIBER [label="INT_STG_OCS_ ACCOUNTS_SUBCRIBER"]

    STG_CRM_PERSON_SUBSCRIBER [label="STG_CRM_PERSON_ SUBSCRIBER"]

    INT_STG_CRM_PERSON_SUBSCRIBER [label="INT_STG_CRM_PERSON_ SUBSCRIBER"]

    STG_T_S_OCS_TSNATIVENUMHEAD [label="STG_T_S_OCS_ TSNATIVENUMHEAD"]

    INT_STG_T_S_OCS_TSNATIVENUMHEAD [label="INT_STG_T_S_OCS_ TSNATIVENUMHEAD"]

    SUBSCRIBER_DIMENSION_STG [label="SUBSCRIBER_ DIMENSION_STG"]

    INT_STG_CRM_SUBSCRIBER_SD [label="INT_STG_CRM_ SUBSCRIBER_SD"]

    INT_STG_CBE_SUBSCRIBER_SD [label="INT_STG_CBE_ SUBSCRIBER_SD"]

    IMEI_MOBILEBRAND [label="IMEI_MOBILEBRAND"]

    SUBSCRIBER_TEMP_TB [label="SUBSCRIBER_ TEMP_TB"]

    SUBSCRIBER_DIMENSION [label="SUBSCRIBER_ DIMENSION"]

    SUBSCRIBER_REGION_TB [label="SUBSCRIBER_ REGION_TB"]

    SUBSCRIBER_TEMP_TB [label="SUBSCRIBER_TEMP_TB"]

    AUDIT_TB [label="AUDIT_TB"]

    //////////////////////////////////////////////////////

    INT_STG_OCS_TB_OCS_ACCOUNTEXT_SUBSCRIBER_SD ->
    {STG_OCS_TB_OCS_ACCOUNTEXT_SUBSCRIBER,
    LOAD_DATE_PARAMETERS_TBL}[color="#0d1976", fontcolor="#0d1976", label="1"]
    //---

    SUBSCRIBER_AUDIT_TB ->
    AUDIT_TB[color="#BBFFFF", fontcolor="#BBFFFF", label="2"]
    //---
    STG_INF_CONTACT_PERSON ->
    {AUDIT_TB,
    LOAD_DATE_PARAMETERS_TBL,
    INT_STG_INF_CONTACT_PERSON}[color="#FFFF00", fontcolor="#FFFF00", label="3"]
    //---
    STG_INF_CUSTOMER_ALL ->
    {AUDIT_TB,
    LOAD_DATE_PARAMETERS_TBL,
    INT_STG_INF_CUSTOMER_ALL}[color="#EE0000", fontcolor="#EE0000", label="4"]
    //---
    STG_OCS_ACCOUNTS_SUBCRIBER ->
    {SUBSCRIBER_AUDIT_TB,
    LOAD_DATE_PARAMETERS_TBL,
    INT_STG_OCS_ACCOUNTS_SUBCRIBER}[color="#9ACD32", fontcolor="#9ACD32", label="5"]

    STG_CRM_PERSON_SUBSCRIBER ->
    {SUBSCRIBER_AUDIT_TB,
    LOAD_DATE_PARAMETERS_TBL,
    INT_STG_CRM_PERSON_SUBSCRIBER}[color="#98F5FF", fontcolor="#98F5FF", label="6"]
    //---
    STG_T_S_OCS_TSNATIVENUMHEAD ->
    {AUDIT_TB,
    LOAD_DATE_PARAMETERS_TBL,
    INT_STG_T_S_OCS_TSNATIVENUMHEAD}[color="#7D26CD", fontcolor="#7D26CD", label="7"]
    //---
    SUBSCRIBER_DIMENSION_STG ->
    {INT_STG_CRM_SUBSCRIBER_SD,
    INT_STG_CRM_PERSON_SUBSCRIBER,
    INT_STG_CBE_SUBSCRIBER_SD,
    INT_STG_OCS_TB_OCS_ACCOUNTEXT_SUBSCRIBER_SD,
    INT_STG_OCS_ACCOUNTS_SUBCRIBER,
    IMEI_MOBILEBRAND,
    SUBSCRIBER_AUDIT_TB,
    INT_STG_INF_CONTACT_PERSON,
    INT_STG_INF_CUSTOMER_ALL}[color="#838B83", fontcolor="#838B83", label="8"]
    //---
    SUBSCRIBER_TEMP_TB ->
    {AUDIT_TB,
    SUBSCRIBER_DIMENSION,
    SUBSCRIBER_DIMENSION_STG}[color="#B8860B", fontcolor="#B8860B", label="9"]

    SUBSCRIBER_REGION_TB ->
    {INT_STG_T_S_OCS_TSNATIVENUMHEAD,
    SUBSCRIBER_DIMENSION_STG,
    SUBSCRIBER_TEMP_TB,
    SUBSCRIBER_DIMENSION_STG,
    SUBSCRIBER_TEMP_TB} [color="#B3EE3A", fontcolor="#B3EE3A", label="10"]

    // update
    SUBSCRIBER_AUDIT_TB ->
    {SUBSCRIBER_TEMP_TB,
    SUBSCRIBER_DIMENSION_STG,
    SUBSCRIBER_AUDIT_TB}[color="#B22222", fontcolor="#B22222", label="11"]

    // update
    SUBSCRIBER_DIMENSION ->
    SUBSCRIBER_TEMP_TB[color="#030303", fontcolor="#030303", label="12"]

    SUBSCRIBER_DIMENSION ->
    {SUBSCRIBER_DIMENSION_STG,
    SUBSCRIBER_TEMP_TB,
    SUBSCRIBER_REGION_TB}[color="#32CD32", fontcolor="#32CD32", label="13"]

    // update
    SUBSCRIBER_DIMENSION ->
    {SUBSCRIBER_DIMENSION_STG,
    SUBSCRIBER_TEMP_TB}[color="#8B0000", fontcolor="#8B0000", label="14"]

    }

    保存为.dot文件

    在cmd下执行命令(前提是你安装了Graphviz并配置了环境变量,这个请自行百度):

    neato C:UsersmeijDesktopgraph3.gv -Tpng -o sb_job_tab.png

    解释:neato是生成某一种图形样式,Graphviz提供了很多样式

            也可以生成.img文件

    大家安装客户端后可以按照上面的代码和步骤就可以实现生成图片,结果因为图片太大不在这里展示。

    参考网址:http://www.graphviz.org/

                  http://m.blog.csdn.net/article/details?id=49472949

  • 相关阅读:
    C# DataTable 和List之间相互转换的方法
    毫秒级百万数据分页存储过程(mssql)
    lambdas vs. method groups
    关于优化C#程序的五十种方法
    Retrieving failed records after an SqlBulkCopy exception
    将数字按照3位一组添加逗号的正则替换
    生成互不相同随机数的一种算法
    2018年ElasticSearch6.2.2教程ELK搭建日志采集分析系统(教程详情)
    2018年ElasticSearch6.2.2教程ELK搭建日志采集分析系统(目录)
    JMeter接口压力测试课程入门到高级实战
  • 原文地址:https://www.cnblogs.com/jiashengmei/p/5978270.html
Copyright © 2020-2023  润新知