线上问诊:数仓开发(三)

系列文章目录

线上问诊:业务数据采集
线上问诊:数仓数据同步
线上问诊:数仓开发(一)
线上问诊:数仓开发(二)
线上问诊:数仓开发(三)


文章目录

  • 系列文章目录
  • 前言
  • 一、ADS
    • 1.交易主题
      • 1.交易综合统计
      • 2.各医院交易统计
      • 3.各性别患者交易统计
      • 4.各年龄段患者交易统计
    • 2.医生主题
      • 1.医生变动统计
    • 3.用户主题
      • 1.用户变动统计
    • 4.评价主题
      • 1.评价综合统计
      • 2.各医院评价统计
      • 5.数据装载脚本
  • 一、报表数据导出
    • 1.MySQL建库建表
      • 1.创建数据库
      • 2.创建表
    • 2.数据导出
      • 1.DataX配置文件生成脚本
      • 2.执行配置文件生成器
      • 3.编写每日导出脚本
  • 总结


前言

这次我们继续进行数仓的开发,应该能写完。


一、ADS

1.交易主题

1.交易综合统计

建表语句

CREATE EXTERNAL TABLE IF NOT EXISTS ads_trade_stats
(`dt`                          STRING COMMENT '统计日期',`recent_days`                 BIGINT COMMENT '统计周期: 最近1,7,30日',`consultation_amount`         DECIMAL(16, 2) COMMENT '问诊金额',`consultation_count`          BIGINT COMMENT '问诊次数',`consultation_pay_suc_amount` DECIMAL(16, 2) COMMENT '问诊支付成功金额',`consultation_pay_suc_count`  BIGINT COMMENT '问诊支付成功次数',`prescription_amount`         DECIMAL(16, 2) COMMENT '处方金额',`prescription_count`          BIGINT COMMENT '处方次数',`prescription_pay_suc_amount` DECIMAL(16, 2) COMMENT '处方支付成功金额',`prescription_pay_suc_count`  BIGINT COMMENT '处方支付成功次数'
) COMMENT '交易综合统计'ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'LOCATION '/warehouse/medical/ads/ads_trade_stats';

2.各医院交易统计

建表语句

CREATE EXTERNAL TABLE IF NOT EXISTS ads_hospital_trade_stats
(`dt`                          STRING COMMENT '统计日期',`recent_days`                 BIGINT COMMENT '统计周期: 最近1,7,30日',`hospital_id`                 STRING COMMENT '医院ID',`hospital_name`               STRING COMMENT '医院名称',`consultation_amount`         DECIMAL(16, 2) COMMENT '问诊金额',`consultation_count`          BIGINT COMMENT '问诊次数',`consultation_pay_suc_amount` DECIMAL(16, 2) COMMENT '问诊支付成功金额',`consultation_pay_suc_count`  BIGINT COMMENT '问诊支付成功次数',`prescription_amount`         DECIMAL(16, 2) COMMENT '处方金额',`prescription_count`          BIGINT COMMENT '处方次数',`prescription_pay_suc_amount` DECIMAL(16, 2) COMMENT '处方支付成功金额',`prescription_pay_suc_count`  BIGINT COMMENT '处方支付成功次数'
) COMMENT '各医院交易统计'ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'LOCATION '/warehouse/medical/ads/ads_hospital_trade_stats';

3.各性别患者交易统计

建表语句

CREATE EXTERNAL TABLE IF NOT EXISTS ads_gender_trade_stats
(`dt`                          STRING COMMENT '统计日期',`recent_days`                 BIGINT COMMENT '统计周期: 最近1,7,30日',`gender_code`                 STRING COMMENT '患者性别编码',`gender`                      STRING COMMENT '患者性别',`consultation_amount`         DECIMAL(16, 2) COMMENT '问诊金额',`consultation_count`          BIGINT COMMENT '问诊次数',`consultation_pay_suc_amount` DECIMAL(16, 2) COMMENT '问诊支付成功金额',`consultation_pay_suc_count`  BIGINT COMMENT '问诊支付成功次数',`prescription_amount`         DECIMAL(16, 2) COMMENT '处方金额',`prescription_count`          BIGINT COMMENT '处方次数',`prescription_pay_suc_amount` DECIMAL(16, 2) COMMENT '处方支付成功金额',`prescription_pay_suc_count`  BIGINT COMMENT '处方支付成功次数'
) COMMENT '各性别患者交易统计'ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'LOCATION '/warehouse/medical/ads/ads_gender_trade_stats';

4.各年龄段患者交易统计

建表语句

CREATE EXTERNAL TABLE IF NOT EXISTS ads_age_group_trade_stats
(`dt`                          STRING COMMENT '统计日期',`recent_days`                 BIGINT COMMENT '统计周期: 最近1,7,30日',`age_group`                   STRING COMMENT '患者年龄段',`consultation_amount`         DECIMAL(16, 2) COMMENT '问诊金额',`consultation_count`          BIGINT COMMENT '问诊次数',`consultation_pay_suc_amount` DECIMAL(16, 2) COMMENT '问诊支付成功金额',`consultation_pay_suc_count`  BIGINT COMMENT '问诊支付成功次数',`prescription_amount`         DECIMAL(16, 2) COMMENT '处方金额',`prescription_count`          BIGINT COMMENT '处方次数',`prescription_pay_suc_amount` DECIMAL(16, 2) COMMENT '处方支付成功金额',`prescription_pay_suc_count`  BIGINT COMMENT '处方支付成功次数'
) COMMENT '各年龄段患者交易统计'ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'LOCATION '/warehouse/medical/ads/ads_age_group_trade_stats';

数据装载

2.医生主题

1.医生变动统计

建表语句

CREATE EXTERNAL TABLE IF NOT EXISTS ads_doctor_change_stats(`dt` STRING COMMENT '统计日期',`recent_days` BIGINT COMMENT '统计周期: 最近1,7,30日',`new_doctor_count` BIGINT COMMENT '新增医生数',`activated_doctor_count` BIGINT COMMENT '激活医生数',`active_doctor_count` BIGINT COMMENT '活跃医生数'
) COMMENT '医生变动统计'ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'LOCATION '/warehouse/medical/ads/ads_doctor_change_stats';

3.用户主题

1.用户变动统计

建表语句

CREATE EXTERNAL TABLE IF NOT EXISTS ads_user_change_stats(`dt` STRING COMMENT '统计日期',`recent_days` BIGINT COMMENT '统计周期: 最近1,7,30日',`new_user_count` BIGINT COMMENT '新增用户数',`new_patient_count` BIGINT COMMENT '新增患者数'
) COMMENT '用户变动统计'ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'LOCATION '/warehouse/medical/ads/ads_user_change_stats';

4.评价主题

1.评价综合统计

建表语句

CREATE EXTERNAL TABLE IF NOT EXISTS ads_review_stats(`dt` STRING COMMENT '统计日期',`review_user_count` BIGINT COMMENT '评价人数',`review_count` BIGINT COMMENT '评价次数',`good_review_rate` DECIMAL(16,2) COMMENT '好评率'
) COMMENT '用户变动统计'ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'LOCATION '/warehouse/medical/ads/ads_review_stats';

2.各医院评价统计

建表语句

CREATE EXTERNAL TABLE IF NOT EXISTS ads_hospital_review_stats(`dt` STRING COMMENT '统计日期',`hospital_id` STRING COMMENT '医院ID',`hospital_name` STRING COMMENT '医院名称',`review_user_count` BIGINT COMMENT '评价人数',`review_count` BIGINT COMMENT '评价次数',`good_review_rate` DECIMAL(16,2) COMMENT '好评率'
) COMMENT '各医院评价统计'ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'LOCATION '/warehouse/medical/ads/ads_hospital_review_stats';

5.数据装载脚本

vim ~/bin/medical_dws_to_ads.sh

#!/bin/bashAPP=medicalif [ -n $2 ]
then do_date=$2
else echo "请传入日期参数!!!"exit
fiads_trade_stats="
insert overwrite table ${APP}.ads_trade_stats
select dt,recent_days,consultation_amount,consultation_count,consultation_pay_suc_amount,consultation_pay_suc_count,prescription_amount,prescription_count,prescription_pay_suc_amount,prescription_pay_suc_count
from ${APP}.ads_trade_stats
union
select '$do_date' dt,consul.recent_days,consultation_amount,consultation_count,consultation_pay_suc_amount,consultation_pay_suc_count,prescription_amount,prescription_count,prescription_pay_suc_amount,prescription_pay_suc_count
from (select 1                        recent_days,sum(consultation_amount) consultation_amount,sum(consultation_count)  consultation_countfrom ${APP}.dws_trade_hospital_gender_age_group_consultation_1dwhere dt = '$do_date'unionselect recent_days,sum(if(recent_days = 7, consultation_amount_7d, consultation_amount_30d)) consultation_amount,sum(if(recent_days = 7, consultation_count_7d, consultation_count_30d))   consultation_countfrom ${APP}.dws_trade_hospital_gender_age_group_consultation_nd lateral view explode(array(7, 30)) tmp as recent_dayswhere dt = '$do_date'group by recent_days) consulleft join(select 1                                recent_days,sum(consultation_pay_suc_amount) consultation_pay_suc_amount,sum(consultation_pay_suc_count)  consultation_pay_suc_countfrom ${APP}.dws_trade_hospital_gender_age_group_consultation_pay_suc_1dwhere dt = '$do_date'unionselect recent_days,sum(if(recent_days = 7, consultation_pay_suc_amount_7d,consultation_pay_suc_amount_30d)) consultation_pay_suc_amount,sum(if(recent_days = 7, consultation_pay_suc_count_7d,consultation_pay_suc_count_30d))  consultation_pay_suc_countfrom ${APP}.dws_trade_hospital_gender_age_group_consultation_pay_suc_nd lateral view explode(array(7, 30)) tmp as recent_dayswhere dt = '$do_date'group by recent_days) consul_pay_sucon consul.recent_days = consul_pay_suc.recent_daysleft join(select 1                        recent_days,sum(prescription_amount) prescription_amount,sum(prescription_count)  prescription_countfrom ${APP}.dws_trade_hospital_gender_age_group_prescription_1dwhere dt = '$do_date'unionselect recent_days,sum(if(recent_days = 7, prescription_amount_7d, prescription_amount_30d)) prescription_amount,sum(if(recent_days = 7, prescription_count_7d, prescription_count_30d))   prescription_countfrom ${APP}.dws_trade_hospital_gender_age_group_prescription_nd lateral view explode(array(7, 30)) tmp as recent_dayswhere dt = '$do_date'group by recent_days) prescriptionon consul.recent_days = prescription.recent_daysleft join(select 1                                recent_days,sum(prescription_pay_suc_amount) prescription_pay_suc_amount,sum(prescription_pay_suc_count)  prescription_pay_suc_countfrom ${APP}.dws_trade_hospital_gender_age_group_prescription_pay_suc_1dwhere dt = '$do_date'unionselect recent_days,sum(if(recent_days = 7, prescription_pay_suc_amount_7d,prescription_pay_suc_amount_30d)) prescription_pay_suc_amount,sum(if(recent_days = 7, prescription_pay_suc_count_7d,prescription_pay_suc_count_30d))  prescription_pay_suc_countfrom ${APP}.dws_trade_hospital_gender_age_group_prescription_pay_suc_nd lateral view explode(array(7, 30)) tmp as recent_dayswhere dt = '$do_date'group by recent_days) prescription_pay_sucon consul.recent_days = prescription_pay_suc.recent_days;
"
ads_hospital_trade_stats="
insert overwrite table ${APP}.ads_hospital_trade_stats
select dt,recent_days,hospital_id,hospital_name,consultation_amount,consultation_count,consultation_pay_suc_amount,consultation_pay_suc_count,prescription_amount,prescription_count,prescription_pay_suc_amount,prescription_pay_suc_count
from ${APP}.ads_hospital_trade_stats
union
select '$do_date' dt,consul.recent_days,consul.hospital_id,consul.hospital_name,consultation_amount,consultation_count,consultation_pay_suc_amount,consultation_pay_suc_count,prescription_amount,prescription_count,prescription_pay_suc_amount,prescription_pay_suc_count
from (select 1                        recent_days,hospital_id,hospital_name,sum(consultation_amount) consultation_amount,sum(consultation_count)  consultation_countfrom ${APP}.dws_trade_hospital_gender_age_group_consultation_1dwhere dt = '$do_date'group by hospital_id,hospital_nameunionselect recent_days,hospital_id,hospital_name,sum(if(recent_days = 7, consultation_amount_7d, consultation_amount_30d)) consultation_amount,sum(if(recent_days = 7, consultation_count_7d, consultation_count_30d))   consultation_countfrom ${APP}.dws_trade_hospital_gender_age_group_consultation_nd lateral view explode(array(7, 30)) tmp as recent_dayswhere dt = '$do_date'group by recent_days,hospital_id,hospital_name) consulleft join(select 1                                recent_days,hospital_id,hospital_name,sum(consultation_pay_suc_amount) consultation_pay_suc_amount,sum(consultation_pay_suc_count)  consultation_pay_suc_countfrom ${APP}.dws_trade_hospital_gender_age_group_consultation_pay_suc_1dwhere dt = '$do_date'group by hospital_id,hospital_nameunionselect recent_days,hospital_id,hospital_name,sum(if(recent_days = 7, consultation_pay_suc_amount_7d,consultation_pay_suc_amount_30d)) consultation_pay_suc_amount,sum(if(recent_days = 7, consultation_pay_suc_count_7d,consultation_pay_suc_count_30d))  consultation_pay_suc_countfrom ${APP}.dws_trade_hospital_gender_age_group_consultation_pay_suc_nd lateral view explode(array(7, 30)) tmp as recent_dayswhere dt = '$do_date'group by recent_days,hospital_id,hospital_name) consul_pay_sucon consul.recent_days = consul_pay_suc.recent_daysand consul.hospital_id = consul_pay_suc.hospital_idand consul.hospital_name = consul_pay_suc.hospital_nameleft join(select 1                        recent_days,hospital_id,hospital_name,sum(prescription_amount) prescription_amount,sum(prescription_count)  prescription_countfrom ${APP}.dws_trade_hospital_gender_age_group_prescription_1dwhere dt = '$do_date'group by hospital_id,hospital_nameunionselect recent_days,hospital_id,hospital_name,sum(if(recent_days = 7, prescription_amount_7d, prescription_amount_30d)) prescription_amount,sum(if(recent_days = 7, prescription_count_7d, prescription_count_30d))   prescription_countfrom ${APP}.dws_trade_hospital_gender_age_group_prescription_nd lateral view explode(array(7, 30)) tmp as recent_dayswhere dt = '$do_date'group by recent_days,hospital_id,hospital_name) prescriptionon consul.recent_days = prescription.recent_daysand consul.hospital_id = prescription.hospital_idand consul.hospital_name = prescription.hospital_nameleft join(select 1                                recent_days,hospital_id,hospital_name,sum(prescription_pay_suc_amount) prescription_pay_suc_amount,sum(prescription_pay_suc_count)  prescription_pay_suc_countfrom ${APP}.dws_trade_hospital_gender_age_group_prescription_pay_suc_1dwhere dt = '$do_date'group by hospital_id,hospital_nameunionselect recent_days,hospital_id,hospital_name,sum(if(recent_days = 7, prescription_pay_suc_amount_7d,prescription_pay_suc_amount_30d)) prescription_pay_suc_amount,sum(if(recent_days = 7, prescription_pay_suc_count_7d,prescription_pay_suc_count_30d))  prescription_pay_suc_countfrom ${APP}.dws_trade_hospital_gender_age_group_prescription_pay_suc_nd lateral view explode(array(7, 30)) tmp as recent_dayswhere dt = '$do_date'group by recent_days,hospital_id,hospital_name) prescription_pay_sucon consul.recent_days = prescription_pay_suc.recent_daysand consul.hospital_id = prescription_pay_suc.hospital_idand consul.hospital_name = prescription_pay_suc.hospital_name;
"
ads_gender_trade_stats="
insert overwrite table ${APP}.ads_gender_trade_stats
select dt,recent_days,gender_code,gender,consultation_amount,consultation_count,consultation_pay_suc_amount,consultation_pay_suc_count,prescription_amount,prescription_count,prescription_pay_suc_amount,prescription_pay_suc_count
from ${APP}.ads_gender_trade_stats
union
select '$do_date' dt,consul.recent_days,consul.gender_code,consul.gender,consultation_amount,consultation_count,consultation_pay_suc_amount,consultation_pay_suc_count,prescription_amount,prescription_count,prescription_pay_suc_amount,prescription_pay_suc_count
from (select 1                        recent_days,gender_code,gender,sum(consultation_amount) consultation_amount,sum(consultation_count)  consultation_countfrom ${APP}.dws_trade_hospital_gender_age_group_consultation_1dwhere dt = '$do_date'group by gender_code,genderunionselect recent_days,gender_code,gender,sum(if(recent_days = 7, consultation_amount_7d, consultation_amount_30d)) consultation_amount,sum(if(recent_days = 7, consultation_count_7d, consultation_count_30d))   consultation_countfrom ${APP}.dws_trade_hospital_gender_age_group_consultation_nd lateral view explode(array(7, 30)) tmp as recent_dayswhere dt = '$do_date'group by recent_days,gender_code,gender) consulleft join(select 1                                recent_days,gender_code,gender,sum(consultation_pay_suc_amount) consultation_pay_suc_amount,sum(consultation_pay_suc_count)  consultation_pay_suc_countfrom ${APP}.dws_trade_hospital_gender_age_group_consultation_pay_suc_1dwhere dt = '$do_date'group by gender_code,genderunionselect recent_days,gender_code,gender,sum(if(recent_days = 7, consultation_pay_suc_amount_7d,consultation_pay_suc_amount_30d)) consultation_pay_suc_amount,sum(if(recent_days = 7, consultation_pay_suc_count_7d,consultation_pay_suc_count_30d))  consultation_pay_suc_countfrom ${APP}.dws_trade_hospital_gender_age_group_consultation_pay_suc_nd lateral view explode(array(7, 30)) tmp as recent_dayswhere dt = '$do_date'group by recent_days,gender_code,gender) consul_pay_sucon consul.recent_days = consul_pay_suc.recent_daysand consul.gender_code = consul_pay_suc.gender_codeand consul.gender = consul_pay_suc.genderleft join(select 1                        recent_days,gender_code,gender,sum(prescription_amount) prescription_amount,sum(prescription_count)  prescription_countfrom ${APP}.dws_trade_hospital_gender_age_group_prescription_1dwhere dt = '$do_date'group by gender_code,genderunionselect recent_days,gender_code,gender,sum(if(recent_days = 7, prescription_amount_7d, prescription_amount_30d)) prescription_amount,sum(if(recent_days = 7, prescription_count_7d, prescription_count_30d))   prescription_countfrom ${APP}.dws_trade_hospital_gender_age_group_prescription_nd lateral view explode(array(7, 30)) tmp as recent_dayswhere dt = '$do_date'group by recent_days,gender_code,gender) prescriptionon consul.recent_days = prescription.recent_daysand consul.gender_code = prescription.gender_codeand consul.gender = prescription.genderleft join(select 1                                recent_days,gender_code,gender,sum(prescription_pay_suc_amount) prescription_pay_suc_amount,sum(prescription_pay_suc_count)  prescription_pay_suc_countfrom ${APP}.dws_trade_hospital_gender_age_group_prescription_pay_suc_1dwhere dt = '$do_date'group by gender_code,genderunionselect recent_days,gender_code,gender,sum(if(recent_days = 7, prescription_pay_suc_amount_7d,prescription_pay_suc_amount_30d)) prescription_pay_suc_amount,sum(if(recent_days = 7, prescription_pay_suc_count_7d,prescription_pay_suc_count_30d))  prescription_pay_suc_countfrom ${APP}.dws_trade_hospital_gender_age_group_prescription_pay_suc_nd lateral view explode(array(7, 30)) tmp as recent_dayswhere dt = '$do_date'group by recent_days,gender_code,gender) prescription_pay_sucon consul.recent_days = prescription_pay_suc.recent_daysand consul.gender_code = prescription_pay_suc.gender_codeand consul.gender = prescription_pay_suc.gender;
"
ads_age_group_trade_stats="
insert overwrite table ${APP}.ads_age_group_trade_stats
select dt,recent_days,age_group,consultation_amount,consultation_count,consultation_pay_suc_amount,consultation_pay_suc_count,prescription_amount,prescription_count,prescription_pay_suc_amount,prescription_pay_suc_count
from ${APP}.ads_age_group_trade_stats
union
select '$do_date' dt,consul.recent_days,consul.age_group,consultation_amount,consultation_count,consultation_pay_suc_amount,consultation_pay_suc_count,prescription_amount,prescription_count,prescription_pay_suc_amount,prescription_pay_suc_count
from (select 1                        recent_days,age_group,sum(consultation_amount) consultation_amount,sum(consultation_count)  consultation_countfrom ${APP}.dws_trade_hospital_gender_age_group_consultation_1dwhere dt = '$do_date'group by age_groupunionselect recent_days,age_group,sum(if(recent_days = 7, consultation_amount_7d, consultation_amount_30d)) consultation_amount,sum(if(recent_days = 7, consultation_count_7d, consultation_count_30d))   consultation_countfrom ${APP}.dws_trade_hospital_gender_age_group_consultation_nd lateral view explode(array(7, 30)) tmp as recent_dayswhere dt = '$do_date'group by recent_days,age_group) consulleft join(select 1                                recent_days,age_group,sum(consultation_pay_suc_amount) consultation_pay_suc_amount,sum(consultation_pay_suc_count)  consultation_pay_suc_countfrom ${APP}.dws_trade_hospital_gender_age_group_consultation_pay_suc_1dwhere dt = '$do_date'group by age_groupunionselect recent_days,age_group,sum(if(recent_days = 7, consultation_pay_suc_amount_7d,consultation_pay_suc_amount_30d)) consultation_pay_suc_amount,sum(if(recent_days = 7, consultation_pay_suc_count_7d,consultation_pay_suc_count_30d))  consultation_pay_suc_countfrom ${APP}.dws_trade_hospital_gender_age_group_consultation_pay_suc_nd lateral view explode(array(7, 30)) tmp as recent_dayswhere dt = '$do_date'group by recent_days,age_group) consul_pay_sucon consul.recent_days = consul_pay_suc.recent_daysand consul.age_group = consul_pay_suc.age_groupleft join(select 1                        recent_days,age_group,sum(prescription_amount) prescription_amount,sum(prescription_count)  prescription_countfrom ${APP}.dws_trade_hospital_gender_age_group_prescription_1dwhere dt = '$do_date'group by age_groupunionselect recent_days,age_group,sum(if(recent_days = 7, prescription_amount_7d, prescription_amount_30d)) prescription_amount,sum(if(recent_days = 7, prescription_count_7d, prescription_count_30d))   prescription_countfrom ${APP}.dws_trade_hospital_gender_age_group_prescription_nd lateral view explode(array(7, 30)) tmp as recent_dayswhere dt = '$do_date'group by recent_days,age_group) prescriptionon consul.recent_days = prescription.recent_daysand consul.age_group = prescription.age_groupleft join(select 1                                recent_days,age_group,sum(prescription_pay_suc_amount) prescription_pay_suc_amount,sum(prescription_pay_suc_count)  prescription_pay_suc_countfrom ${APP}.dws_trade_hospital_gender_age_group_prescription_pay_suc_1dwhere dt = '$do_date'group by age_groupunionselect recent_days,age_group,sum(if(recent_days = 7, prescription_pay_suc_amount_7d,prescription_pay_suc_amount_30d)) prescription_pay_suc_amount,sum(if(recent_days = 7, prescription_pay_suc_count_7d,prescription_pay_suc_count_30d))  prescription_pay_suc_countfrom ${APP}.dws_trade_hospital_gender_age_group_prescription_pay_suc_nd lateral view explode(array(7, 30)) tmp as recent_dayswhere dt = '$do_date'group by recent_days,age_group) prescription_pay_sucon consul.recent_days = prescription_pay_suc.recent_daysand consul.age_group = prescription_pay_suc.age_group;
"
ads_doctor_change_stats="
insert overwrite table ${APP}.ads_doctor_change_stats
select dt,recent_days,new_doctor_count,activated_doctor_count,active_doctor_count
from ${APP}.ads_doctor_change_stats
union
select '$do_date' dt,new.recent_days,new_doctor_count,activated_doctor_count,active_doctor_count
from (select recent_days,count(*) new_doctor_countfrom ${APP}.dwd_doctor_register_inc lateral view explode(array(1, 7, 30)) tmp as recent_dayswhere dt >= date_add('$do_date', -recent_days + 1)group by recent_days) newleft join(select recent_days,count(*) activated_doctor_countfrom ${APP}.dws_trade_doctor_consultation_td lateral view explode(array(1, 7, 30)) tmp as recent_dayswhere dt = '$do_date'and first_consultation_dt >= date_add('$do_date', -recent_days + 1)group by recent_days) activatedon new.recent_days = activated.recent_daysleft join(select 1        recent_days,count(*) active_doctor_countfrom ${APP}.dws_trade_doctor_consultation_1dwhere dt = '$do_date'and consultation_count >= 2unionselect recent_days,count(*) active_doctor_countfrom ${APP}.dws_trade_doctor_consultation_nd lateral view explode(array(7, 30)) tmp as recent_dayswhere dt = '$do_date'and ((recent_days = 7 and consultation_count_7d >= 2)or (recent_days = 30 and consultation_count_30d >= 2))group by recent_days) activeon new.recent_days = active.recent_days;
"
ads_user_change_stats="
insert overwrite table ${APP}.ads_user_change_stats
select dt,recent_days,new_user_count,new_patient_count
from ${APP}.ads_user_change_stats
union
select '$do_date' dt,new_user.recent_days,new_user_count,new_patient_count
from (select recent_days,count(*) new_user_countfrom ${APP}.dwd_user_register_inc lateral view explode(array(1, 7, 30)) tmp as recent_dayswhere dt >= date_add('$do_date', -recent_days + 1)group by recent_days) new_userleft join(select recent_days,count(*) new_patient_countfrom ${APP}.dwd_user_patient_add_inc lateral view explode(array(1, 7, 30)) tmp as recent_dayswhere dt >= date_add('$do_date', -recent_days + 1)group by recent_days) new_patienton new_user.recent_days = new_patient.recent_days;
"
ads_review_stats="
insert overwrite table ${APP}.ads_review_stats
select dt,review_user_count,review_count,good_review_rate
from ${APP}.ads_review_stats
union
select '$do_date' dt,review_user_count,review_count,good_review_rate
from (select count(distinct user_id) review_user_countfrom ${APP}.dws_interaction_hospital_user_review_tdwhere dt = '$do_date') user_countleft join(select sum(review_count)                          review_count,sum(good_review_count) / sum(review_count) good_review_ratefrom ${APP}.dws_interaction_hospital_review_tdwhere dt = '$do_date') review_stats;
"
ads_hospital_review_stats="
insert overwrite table ${APP}.ads_hospital_review_stats
select dt,hospital_id,hospital_name,review_user_count,review_count,good_review_rate
from ${APP}.ads_hospital_review_stats
union
select '$do_date' dt,user_count.hospital_id,user_count.hospital_name,review_user_count,review_count,good_review_rate
from (select hospital_id,hospital_name,count(user_id) review_user_countfrom ${APP}.dws_interaction_hospital_user_review_tdwhere dt = '$do_date'group by hospital_id,hospital_name) user_countleft join(select hospital_id,hospital_name,review_count,good_review_count / review_count good_review_ratefrom ${APP}.dws_interaction_hospital_review_tdwhere dt = '$do_date') review_statson user_count.hospital_id = review_stats.hospital_idand user_count.hospital_name = review_stats.hospital_name;
"case $1 in ads_trade_stats | ads_hospital_trade_stats | ads_gender_trade_stats | ads_age_group_trade_stats | ads_doctor_change_stats | ads_user_change_stats | ads_review_stats | ads_hospital_review_stats)hive -e "${!1}";;"all")hive -e "$ads_trade_stats$ads_hospital_trade_stats$ads_gender_trade_stats$ads_age_group_trade_stats$ads_doctor_change_stats$ads_user_change_stats$ads_review_stats$ads_hospital_review_stats";;"*")echo "非法参数!!!";;
esac

数据装载
medical_dws_to_ads.sh all 2023-05-09
在这里插入图片描述
找个表看一下数据就行。

一、报表数据导出

1.MySQL建库建表

1.创建数据库

CREATE DATABASE IF NOT EXISTS medical_report DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

2.创建表

1.交易综合统计

CREATE TABLE `ads_trade_stats` (`dt` date NOT NULL COMMENT '统计日期',`recent_days` bigint NOT NULL COMMENT '统计周期: 最近1,7,30日',`consultation_amount` decimal(16,2) DEFAULT NULL COMMENT '问诊金额',`consultation_count` bigint DEFAULT NULL COMMENT '问诊次数',`consultation_pay_suc_amount` decimal(16,2) DEFAULT NULL COMMENT '问诊支付成功金额',`consultation_pay_suc_count` bigint DEFAULT NULL COMMENT '问诊支付成功次数',`prescription_amount` decimal(16,2) DEFAULT NULL COMMENT '处方金额',`prescription_count` bigint DEFAULT NULL COMMENT '处方次数',`prescription_pay_suc_amount` decimal(16,2) DEFAULT NULL COMMENT '处方支付成功金额',`prescription_pay_suc_count` bigint DEFAULT NULL COMMENT '处方支付成功次数',PRIMARY KEY (`dt`,`recent_days`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='交易综合统计';

2.各医院交易统计

CREATE TABLE `ads_hospital_trade_stats` (`dt` date NOT NULL COMMENT '统计日期',`recent_days` bigint NOT NULL COMMENT '统计周期: 最近1,7,30日',`hospital_id` varchar(255) NOT NULL COMMENT '医院ID',`hospital_name` varchar(255) NOT NULL COMMENT '医院名称',`consultation_amount` decimal(16,2) DEFAULT NULL COMMENT '问诊金额',`consultation_count` bigint DEFAULT NULL COMMENT '问诊次数',`consultation_pay_suc_amount` decimal(16,2) DEFAULT NULL COMMENT '问诊支付成功金额',`consultation_pay_suc_count` bigint DEFAULT NULL COMMENT '问诊支付成功次数',`prescription_amount` decimal(16,2) DEFAULT NULL COMMENT '处方金额',`prescription_count` bigint DEFAULT NULL COMMENT '处方次数',`prescription_pay_suc_amount` decimal(16,2) DEFAULT NULL COMMENT '处方支付成功金额',`prescription_pay_suc_count` bigint DEFAULT NULL COMMENT '处方支付成功次数',PRIMARY KEY (`dt`,`recent_days`,`hospital_id`,`hospital_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='各医院交易统计';

3.各性别患者交易统计

CREATE TABLE `ads_gender_trade_stats` (`dt` date NOT NULL COMMENT '统计日期',`recent_days` bigint NOT NULL COMMENT '统计周期: 最近1,7,30日',`gender_code` varchar(255) NOT NULL COMMENT '患者性别编码',`gender` varchar(255) NOT NULL COMMENT '患者性别',`consultation_amount` decimal(16,2) DEFAULT NULL COMMENT '问诊金额',`consultation_count` bigint DEFAULT NULL COMMENT '问诊次数',`consultation_pay_suc_amount` decimal(16,2) DEFAULT NULL COMMENT '问诊支付成功金额',`consultation_pay_suc_count` bigint DEFAULT NULL COMMENT '问诊支付成功次数',`prescription_amount` decimal(16,2) DEFAULT NULL COMMENT '处方金额',`prescription_count` bigint DEFAULT NULL COMMENT '处方次数',`prescription_pay_suc_amount` decimal(16,2) DEFAULT NULL COMMENT '处方支付成功金额',`prescription_pay_suc_count` bigint DEFAULT NULL COMMENT '处方支付成功次数',PRIMARY KEY (`dt`,`recent_days`,`gender_code`,`gender`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='各性别患者交易统计';

4.各年龄段患者交易统计

CREATE TABLE `ads_age_group_trade_stats` (`dt` date NOT NULL COMMENT '统计日期',`recent_days` bigint NOT NULL COMMENT '统计周期: 最近1,7,30日',`age_group` varchar(255) NOT NULL COMMENT '患者年龄段',`consultation_amount` decimal(16,2) DEFAULT NULL COMMENT '问诊金额',`consultation_count` bigint DEFAULT NULL COMMENT '问诊次数',`consultation_pay_suc_amount` decimal(16,2) DEFAULT NULL COMMENT '问诊支付成功金额',`consultation_pay_suc_count` bigint DEFAULT NULL COMMENT '问诊支付成功次数',`prescription_amount` decimal(16,2) DEFAULT NULL COMMENT '处方金额',`prescription_count` bigint DEFAULT NULL COMMENT '处方次数',`prescription_pay_suc_amount` decimal(16,2) DEFAULT NULL COMMENT '处方支付成功金额',`prescription_pay_suc_count` bigint DEFAULT NULL COMMENT '处方支付成功次数',PRIMARY KEY (`dt`,`recent_days`,`age_group`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='各年龄段患者交易统计';

5.医生变动统计

CREATE TABLE `ads_doctor_change_stats` (`dt` date NOT NULL COMMENT '统计日期',`recent_days` bigint NOT NULL COMMENT '统计周期: 最近1,7,30日',`new_doctor_count` bigint DEFAULT NULL COMMENT '新增医生数',`activated_doctor_count` bigint DEFAULT NULL COMMENT '激活医生数',`active_doctor_count` bigint DEFAULT NULL COMMENT '活跃医生数',PRIMARY KEY (`dt`,`recent_days`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='医生变动统计';

6.用户变动统计

CREATE TABLE `ads_user_change_stats` (`dt` date NOT NULL COMMENT '统计日期',`recent_days` bigint NOT NULL COMMENT '统计周期: 最近1,7,30日',`new_user_count` bigint DEFAULT NULL COMMENT '新增用户数',`new_patient_count` bigint DEFAULT NULL COMMENT '新增患者数',PRIMARY KEY (`dt`,`recent_days`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='用户变动统计';

7.评价综合统计

CREATE TABLE `ads_review_stats` (`dt` date NOT NULL COMMENT '统计日期',`review_user_count` bigint DEFAULT NULL COMMENT '评价人数',`review_count` bigint DEFAULT NULL COMMENT '评价次数',`good_review_rate` decimal(16,2) DEFAULT NULL COMMENT '好评率',PRIMARY KEY (`dt`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='用户变动统计';

8.各医院评价统计

CREATE TABLE `ads_hospital_review_stats` (`dt` date NOT NULL COMMENT '统计日期',`hospital_id` varchar(255) NOT NULL COMMENT '医院ID',`hospital_name` varchar(255) NOT NULL COMMENT '医院名称',`review_user_count` bigint DEFAULT NULL COMMENT '评价人数',`review_count` bigint DEFAULT NULL COMMENT '评价次数',`good_review_rate` decimal(16,2) DEFAULT NULL COMMENT '好评率',PRIMARY KEY (`dt`,`hospital_id`,`hospital_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='各医院评价统计';

2.数据导出

1.DataX配置文件生成脚本

vim /opt/module/gen_datax_config/configuration.properties
在这里插入图片描述

mysql.username=root
mysql.password=000000
mysql.host=hadoop102
mysql.port=3306
mysql.database.import=medical
# 从HDFS导出进入的 MySQL 数据库名称
mysql.database.export=medical_report
mysql.tables.import=dict,doctor,hospital,medicine,patient,user
# MySQL 库中需要导出的表,空串表示导出库的所有表
mysql.tables.export=
is.seperated.tables=0
hdfs.uri=hdfs://hadoop102:8020
import_out_dir=/opt/module/datax/job/medical/import
# DataX 导出配置文件存放路径
export_out_dir=/opt/module/datax/job/medical/export

2.执行配置文件生成器

java -jar datax-config-generator-1.0-SNAPSHOT-jar-with-dependencies.jar
在这里插入图片描述

3.编写每日导出脚本

vim ~/bin/medical_hdfs_to_mysql.sh

#!/bin/bashDATAX_HOME=/opt/module/dataxhandle_path(){for file in `hadoop fs -ls -R $1 | awk '{print $8}'`dohadoop fs -test -z $fileif [[ $? -eq 0 ]]then echo "文件 $file 大小为零,正在删除..."hadoop fs -rm -f -r $filefidone
}export_data(){export_dir=$1datax_config=$2echo "正在校验目录 $export_dir ..."handle_path $export_dircount=`hadoop fs -count $export_dir | awk '{print $2}'`if [[ $count -eq 0 ]]then echo "目录为空,跳过"elseecho "正在处理目录 $export_dir ..."$DATAX_HOME/bin/datax.py -p"-Dexportdir=$export_dir" $datax_config >$DATAX_HOME/job/medical/export.log 2>&1if [[ $? -ne 0 ]]then echo "执行出错,日志如下 ..."cat $DATAX_HOME/job/medical/export.logfifi
}case $1 inads_trade_stats | ads_hospital_trade_stats | ads_gender_trade_stats | ads_age_group_trade_stats | ads_doctor_change_stats | ads_user_change_stats | ads_review_stats | ads_hospital_review_stats)export_data /warehouse/medical/ads/$1 $DATAX_HOME/job/medical/export/medical_report.$1.json;;"all")for tab in ads_trade_stats ads_hospital_trade_stats ads_gender_trade_stats ads_age_group_trade_stats ads_doctor_change_stats ads_user_change_stats ads_review_stats ads_hospital_review_statsdo export_data /warehouse/medical/ads/${tab} $DATAX_HOME/job/medical/export/medical_report.${tab}.jsondone;;"*")echo "非法参数!!!";;
esac

添加权限
chmod +x ~/bin/medical_hdfs_to_mysql.sh
数据装载
medical_hdfs_to_mysql.sh all
在这里插入图片描述


总结

数仓开发到这里就结束了。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/67495.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Golang的类型断言的使用

1.把接口转为结构体,再塞给一个结构体的变量 package main//把接口转为结构体,再塞给一个结构体的变量 // 结构体接口.(结构体) import "fmt"type Point struct {x inty int }func main() {var a interface{}var point Point Point{1, 2}a …

js+html实现打字游戏v2

实现逻辑&#xff0c;看jshtml实现打字游戏v1&#xff0c;在此基础之上增加了从文件读取到的单词&#xff0c;随机选取10个单词。 效果演示 上代码&#xff1a; <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8">&l…

window系统 bat脚本开启和关闭防火墙

前言 手动去关闭和开启防火墙太麻烦 命令 开始防火墙 netsh advfirewall set allprofiles state on关闭防火墙 netsh advfirewall set allprofiles state off

Maven高级

目录 1.分模块设计与开发 2.继承与聚合 ​编辑 3.私服 资源上传和下载 1.分模块设计与开发 将项目按照功能拆分成若干个子模块&#xff0c;方便项目的管理维护、扩展&#xff0c;也方便模块间的相互调用&#xff0c;资源共享。 分模块设计需要先针对模块功能进行设计&…

Python+Requests+Pytest+Excel+Allure 接口自动化测试项目实战【框架之间的对比】

--------UnitTest框架和PyTest框架的简单认识对比与项目实战-------- 定义&#xff1a; Unittest是Python标准库中自带的单元测试框架&#xff0c;Unittest有时候也被称为PyUnit&#xff0c;就像JUnit是Java语言的标准单元测试框架一样&#xff0c;Unittest则是Python语言的标…

MySQL——连接查询与子查询

一、连接查询 单表查询&#xff1a;在一张表当中查询数据&#xff0c;叫做单表查询。 连接查询&#xff0c;结合俩&#xff08;多&#xff09;张表&#xff0c;在俩张&#xff08;多&#xff09;表当中查询数据&#xff0c;在一张表当中查询一部分&#xff0c;在另一张表当中…

5个强大的Java分布式缓存框架推荐

在开发中大型Java软件项目时&#xff0c;很多Java架构师都会遇到数据库读写瓶颈&#xff0c;如果你在系统架构时并没有将缓存策略考虑进去&#xff0c;或者并没有选择更优的缓存策略&#xff0c;那么到时候重构起来将会是一个噩梦。 在开发中大型Java软件项目时&#xff0c;很…

C语言之练习题

欢迎来到我的&#xff1a;世界 希望作者的文章对你有所帮助&#xff0c;有不足的地方还请指正&#xff0c;大家一起学习交流 ! 目录 前言填空题&#xff1a;第一题第二题第三题 编程题&#xff1a;第一题&#xff1a;不用加减乘除做加法第二题&#xff1a;完全数计算第三题&am…

字节9.3秋招研发笔试 【后端方向】第三题

题目 小红拿到了一个无向图&#xff0c;初始每人节点是白色&#xff0c;其中有若干个节点被染成了红色。小红想知道&#xff0c;若将 i 号节点染成红色&#xff0c;当前的红色连块的数量是多少? 你需要回答i∈[1,n] 的答案。 定义&#xff0c;若干节点组成一个红色连通块&am…

lintcode 1827 · 停在原地的方案数2 【动态规划 中等 vip】

题目 https://www.lintcode.com/problem/1827/ 有一个长度为 arrLen 的数组&#xff0c;开始有一个指针在索引 0 处。 每一步操作中&#xff0c;你可以将指针向左或向右移动 1 步&#xff0c;或者停在原地&#xff08;指针不能被移动到数组范围外&#xff09;。 给你两个整数…

Redis快速入门

文章目录 1. Centos下Redis安装2. redis.conf配置文件介绍3. redis相关命令4. redis封装系统服务5. 问题与解决 1. Centos下Redis安装 Linux_Study 目录&#xff1a;5.2 https://blog.csdn.net/meini32/article/details/128562114 2. redis.conf配置文件介绍 https://blog.c…

【GPT引领前沿】GPT4技术与AI绘图

推荐阅读&#xff1a; 1、遥感云大数据在灾害、水体与湿地领域典型案例实践及GPT模型应用 2、GPT模型支持下的Python-GEE遥感云大数据分析、管理与可视化技术 GPT对于每个科研人员已经成为不可或缺的辅助工具&#xff0c;不同的研究领域和项目具有不同的需求。例如在科研编程…

Union类型和集合的union()方法-set.union()

Union类型和集合的Union 方法 一、Union类型1.Union类型由来2.Union类型的语法3.Union类型的使用4.一些等价写法 二、Set.union()union() 语法示例代码 一、Union类型 1.Union类型由来 Python中的Union类型是 3.10版本引入的新功能之一。它是一种特殊的类型注释&#xff0c;用…

ChatGPT AIGC 完成动态堆积面积图实例

先使用ChatGPT AIGC描述一下堆积面积图的功能与作用。 接下来一起看一下ChatGPT做出的动态可视化效果图: 这样的动态图案例代码使用ChatGPT AIGC完成。 将完整代码复制如下: <!DOCTYPE html> <html> <head><meta charset="utf-8"><tit…

Ansible_自动化运维实战(一)

1.DELL的一款服务器的价格、型号、配置&#xff08;CPU&#xff0c;内存、硬盘、支持的RAID功能&#xff09; DELL 服务器的定价、型号和配置因型号而异&#xff0c;可以通过访问 DELL 官方网站或联系 DELL 客户服务获取具体信息。一种示例是 DELL PowerEdge R740&#xff0c;其…

使用kubasz快速搭建Kubernetes集群

Kubernetes安装 Kubernetes 也称为 K8s,是用于自动部署、扩缩和管理容器化应用程序的开源系统。ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运行命令等功能。使用ans…

Python Flask Web开发二:数据库创建和使用

前言 数据库在 Web 开发中起着至关重要的作用。它不仅提供了数据的持久化存储和管理功能&#xff0c;还支持数据的关联和连接&#xff0c;保证数据的一致性和安全性。通过合理地设计和使用数据库&#xff0c;开发人员可以构建强大、可靠的 Web 应用程序&#xff0c;满足用户的…

Ubuntu系统下使用宝塔面板实现一键搭建Z-Blog个人博客的方法和流程

文章目录 1.前言2.网站搭建2.1. 网页下载和安装2.2.网页测试2.3.cpolar的安装和注册 3.本地网页发布3.1.Cpolar临时数据隧道3.2.Cpolar稳定隧道&#xff08;云端设置&#xff09;3.3.Cpolar稳定隧道&#xff08;本地设置&#xff09; 4.公网访问测试5.结语 1.前言 Ubuntu系统作…

Ansible之playbook剧本

一、playbook概述1.1 playbook 介绍1.2 playbook 组成部分 二、playbook 示例2.1 playbook 启动及检测2.2 实例一2.3 vars 定义、引用变量2.4 指定远程主机sudo切换用户2.5 when条件判断2.6 迭代2.7 Templates 模块1.先准备一个以 .j2 为后缀的 template 模板文件&#xff0c;设…

算法leetcode|76. 最小覆盖子串(rust重拳出击)

文章目录 76. 最小覆盖子串&#xff1a;样例 1&#xff1a;样例 2&#xff1a;样例 3&#xff1a;提示&#xff1a;进阶&#xff1a; 分析&#xff1a;在这里插入图片描述 题解&#xff1a;rust&#xff1a;go&#xff1a;c&#xff1a;python&#xff1a;java&#xff1a; 76.…