• 助力工业物联网,工业大数据之安装事实指标需求分析【二十一】


    1:安装事实指标需求分析

    • 目标:掌握DWB层安装事实指标表的需求分析

    • 路径

      • step1:目标需求
      • step2:数据来源
    • 实施

      • 目标需求:基于设备安装信息统计安装设备个数、收费安装个数、审核安装个数等指标

        image-20211003164551461

        • 全新安装数量:install_type = 1
        • 联调安装数量:install_way = 2
        • 产生维修数量:is_repair = 1
        • 额外收费数量:is_pay = 1
        • 安装设备数量:与服务单关联,统计设备的id个数
        • 安装费用:通过工单id从报销单信息中关联得到报销金额
        • 审核完成工单个数:
      • 数据来源

        • ciss_service_install:安装单信息表

          select
              id,--安装单id
              code,--安装单号
              install_way, --安装方式 
              service_id --服务单id
          from ciss_service_install;
          
          • 1
          • 2
          • 3
          • 4
          • 5
          • 6
          • ciss_service_workorder:工单详情事实表
        select
            service_userid,--工程师id
            service_station_id,--服务站点id
            oil_station_id,--油站id
            create_time --创建时间
        from ciss_service_workorder;
        
        • 1
        • 2
        • 3
        • 4
        • 5
        • 6
        • ciss_service_order:服务单信息表
        select
          id,            --服务单id
          workorder_id,  --工单id
          type           --工单类型,1-安装,2-维修,3-巡检
        from ciss_service_order;
        
        • 1
        • 2
        • 3
        • 4
        • 5

        image-20211012144040987

        • ciss_service_order_device:服务单设备信息表
        select
            id,               --设备id
            service_order_id  --服务单id
        from ciss_service_order_device;
        
        • 1
        • 2
        • 3
        • 4
        • ciss_s_install_exp_rep_02_dtl:报销单明细表
        select
            id,          --报销ID
            workorder_id,--工单id
            money5       --报销金额
        from ciss_s_install_exp_rep_02_dtl;
        
        • 1
        • 2
        • 3
        • 4
        • 5
        • ciss_service_install_validate:设备安装审核信息表
        select
            id,          --审核ID
            workorder_id,--工单id
            has_validate --审核状态,1-已审核,0-未审核
        from ciss_service_install_validate;
        
        • 1
        • 2
        • 3
        • 4
        • 5
    • 小结

      • 掌握DWB层安装事实指标表的需求分析

    2:安装事实指标构建

    • 目标:实现DWB层安装事实指标表的构建

    • 实施

      • 建表

        -- 创建安装单事实表
        drop table if exists one_make_dwb.fact_srv_install;
        create table if not exists one_make_dwb.fact_srv_install(
            inst_id string comment '安装单id'
            , inst_code string comment '安装单编码'
            , inst_type_id string comment '安装方式id'
            , srv_user_id string comment '服务人员用户id'
            , ss_id string comment '服务网点id'
            , os_id string comment '油站id'
            , date_id string comment '日期id'
            , new_inst_num int comment '全新安装数量'
            , debug_inst_num int comment '设备联调安装数量'
            , repair_num int comment '产生维修安装单数量'
            , ext_exp_num int comment '额外收费安装单数量'
            , inst_device_num int comment '安装设备数量'
            , exp_device_money int comment '安装费用'
            , validated_inst_num int comment '审核安装单数量'
        ) comment '安装单事实表'
        partitioned by (dt string)
        stored as orc
        location '/data/dw/dwb/one_make/fact_srv_install';
        
        • 1
        • 2
        • 3
        • 4
        • 5
        • 6
        • 7
        • 8
        • 9
        • 10
        • 11
        • 12
        • 13
        • 14
        • 15
        • 16
        • 17
        • 18
        • 19
        • 20
        • 21
        • 抽取
      insert overwrite table one_make_dwb.fact_srv_install partition(dt = '20210101')
      select
          sinstall.id inst_id						--安装单id
      	, sinstall.code inst_code               --安装单号
      	, sinstall.install_way inst_type_id     --安装方式
      	, swo.service_userid srv_user_id        --工程师id
      	, swo.service_station_id ss_id          --服务网点id
      	, swo.oil_station_id os_id              --油站id
      	, swo.create_time date_id               --创建时间
      	, new_inst_num                          --全新安装数量
      	, debug_inst_num                        --设备联调安装数量
      	, repair_num                            --产生维修安装数量
      	, ext_exp_num                           --额外收费安装数量
      	, inst_device_num                       --安装设备数量
      	, exp_device_money                      --安装费用
      	, validated_inst_num                    --已审核安装单数量
      	--安装信息表
      from one_make_dwd.ciss_service_install sinstall
      	--服务单表
      	left join one_make_dwd.ciss_service_order sorder on sinstall.service_id = sorder.id
      	--工单表
      	left join one_make_dwd.ciss_service_workorder swo on sorder.workorder_id = swo.id
      	--获取全新、联调、维度、收费的安装数量
      	left join (
      	   select 
      	       id, 
      		   case when install_type = 1 then 1 else 0 end new_inst_num,
      	       case when install_way = 2 then 1 else 0 end debug_inst_num,
      	       case when is_repair = 1 then 1 else 0 end repair_num,
      	       case when is_pay = 1 then 1 else 0 end ext_exp_num 
      	   from one_make_dwd.ciss_service_install
      	) installtype on sinstall.id = installtype.id
      	--获取每个服务单的安装设备数量
      	left join (
      	   select 
      	       sorder.id, count(sodevice.id) inst_device_num 
      	   from one_make_dwd.ciss_service_order sorder
      	   left join one_make_dwd.ciss_service_order_device sodevice on sorder.id = sodevice.service_order_id 
      	   group by sorder.id
      	) sodev on sorder.id = sodev.id
      	--获取每个工单的报销总金额
      	left join ( 
      	  select 
      	      swo.id, sum(dtl.money5) exp_device_money 
            from one_make_dwd.ciss_service_workorder swo 
      	  left join one_make_dwd.ciss_s_install_exp_rep_02_dtl dtl on swo.id = dtl.workorder_id
      	  where dtl.dt = '20210101' and dtl.money5 is not null 
      	  group by swo.id
      	) dtl on swo.id = dtl.id
      	--获取每个安装工单的审核状态
      	left join (
      	  select 
      	      swo.id, case when ivalida.has_validate = 1 then 1 else 0 end validated_inst_num 
      	  from one_make_dwd.ciss_service_workorder swo
      	  left join one_make_dwd.ciss_service_install_validate ivalida on swo.id = ivalida.workorder_id
      	) validate on swo.id = validate.id where swo.service_userid is not null and sinstall.dt = '20210101';
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15
      • 16
      • 17
      • 18
      • 19
      • 20
      • 21
      • 22
      • 23
      • 24
      • 25
      • 26
      • 27
      • 28
      • 29
      • 30
      • 31
      • 32
      • 33
      • 34
      • 35
      • 36
      • 37
      • 38
      • 39
      • 40
      • 41
      • 42
      • 43
      • 44
      • 45
      • 46
      • 47
      • 48
      • 49
      • 50
      • 51
      • 52
      • 53
      • 54
      • 55
      • 56
    • 小结

      • 实现DWB层安装事实指标表的构建
  • 相关阅读:
    hwk4:C++ 运算符重载
    泛型通配符,上下限 ,生活案例介绍
    Python接口自动化之unittest单元测试
    Spring 源码学习笔记10——Spring AOP
    vscode带命令行参数进行调试Golang go-admin:正确配置如下:
    【Java 进阶篇】数据定义语言(DDL)详解
    jsp获取数据 jsp直接获取后端数据 获取input选中的值 单选 没 checked属性
    LeetCode力扣刷题——玩转双指针
    PCG——程序化地形生成(1)
    springboot整合FTP实现文件传输
  • 原文地址:https://blog.csdn.net/xianyu120/article/details/132043103