Browse Source

添加空调操作记录

wdl 2 years ago
parent
commit
25810d1d39

+ 31 - 0
energy/dayTask/bus_hive.sql

@@ -0,0 +1,31 @@
+create table ods_bus_feedback
+(
+    id             STRING comment '主键',
+    project_id     STRING  comment '项目ID',
+    object_id      STRING comment '空间ID',
+    source_type    STRING comment '反馈来源分类',
+    user_id        STRING,
+    user_phone     STRING,
+    user_name      STRING,
+    `value_type`   STRING comment '调节方式:1按调节项2按精确值',
+    item_id        STRING comment '吐槽内容ID',
+    value          DECIMAL(15, 5),
+    create_time    STRING,
+    next_open_time STRING comment '下次开启时间',
+    model          STRING comment '反馈模式 1.一般模式 2.专业模式',
+    duration_type  STRING comment '时效, 1.未来两个小时 2.未来24小时(不包含非定制区间)3.每天此刻都保持该温度',
+    custom_plan    STRING comment '温度计划',
+    curr_temp      decimal(4, 2)  comment '反馈实际温度',
+    nick_name      STRING comment '反馈人微信昵称',
+    result         STRING comment '控制模块获取结果是否成功',
+    exe_result     STRING comment '控制模块返回结果',
+    fb_temp        decimal(4, 2) comment '反馈后目标温度',
+    remark         STRING comment '备注'
+) COMMENT '空调操作记录表'
+    PARTITIONED BY (`dt` string)
+    ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001'
+    STORED AS TEXTFILE
+    LOCATION
+        'hdfs://sagaCluster:8020/warehouse/saga_dw/ods/tmp/ods_bus_feedback'
+    TBLPROPERTIES (
+        'orc.compress'='lzo');

+ 60 - 0
energy/dayTask/bus_mysql_to_hdfs.sh

@@ -0,0 +1,60 @@
+#!/bin/bash
+
+. /opt/app/bi-app/energy/dayTask/config.sh
+. ./config.sh
+
+if [ -n "$2" ] ;then
+    echo "如果是输入的日期按照取输入日期"
+    do_date=$2
+else
+    echo "====没有输入数据的日期,取当前时间的前一天===="
+    do_date=$(date -d yesterday +"%Y-%m-%d")
+fi
+
+SAGA_DATABASE=sagacloud_customization
+url=$SAGA_URL_PRE$SAGA_DATABASE$SAGA_URL_SUF
+username=$SAGA_USER
+password=$SAGA_PASSWORD
+
+echo "$do_date"
+mysql_to_hdfs_lzo() {
+	sqoop import  \
+	-D mapred.job.queue.name=default  \
+	--connect "$1" \
+	--username "$2" \
+	--password "$3" \
+	--target-dir "$4""$7"/"$do_date" \
+	--delete-target-dir \
+	--columns "$5" \
+	--query "$6 and \$CONDITIONS" \
+	--num-mappers 1 \
+	--hive-drop-import-delims \
+	--fields-terminated-by '\001' \
+	--compress \
+	--compression-codec lzo \
+	--hive-import \
+	--hive-database saga_dw \
+	--hive-table "$7" \
+	--hive-overwrite \
+	--hive-partition-key dt \
+	--hive-partition-value "$do_date" \
+	--null-string '\\N' \
+	--null-non-string '\\N'
+}
+
+## 空调操作记录表
+ods_feedback(){
+  mysql_to_hdfs_lzo "$url" "$username" "$password" /warehouse/saga_dw/ods/tmp/  \
+  "id, project_id, object_id, source_type, user_id, user_phone, user_name, value_type, item_id, value, create_time, next_open_time, model, duration_type, custom_plan, curr_temp, nick_name, result, exe_result, fb_temp, remark" \
+  "select id, project_id, object_id, source_type, user_id, user_phone, user_name, value_type, item_id, value, create_time, next_open_time, model, duration_type, custom_plan, curr_temp, nick_name, result, exe_result, fb_temp, remark from feedback where  date_format(create_time, '%Y-%m-%d') = $do_date and 1 = 1 " \
+  ods_bus_feedback
+}
+
+case $1 in
+"all")
+  ods_feedback
+  ;;
+"ods_feedback")
+  ods_feedback
+  ;;
+esac

+ 0 - 6
energy/dayTask/clean_mysql.sh

@@ -17,18 +17,12 @@ username=$MYSQL_USER
 password=$MYSQL_PASSWORD
 database=saga_dev
 
-#del_energy_15_min="delete from energy_15_min where 1 = 1;"
-#del_energy_15_min_fjd="delete from energy_15_min_fjd where 1 = 1;"
-
 del_energy_15_min="truncate table energy_15_min;"
 del_co2_15_min="truncate table co2_15_min;"
 del_pm25_15_min="truncate table pm25_15_min;"
 del_hcho_15_min="truncate table hcho_15_min;"
 del_temperature_15_min="truncate table temperature_15_min;"
 del_humidity_15_min="truncate table humidity_15_min;"
-#del_energy_5_min="truncate table energy_5_min;"
-#del_energy_15_min_fjd="truncate table energy_15_min_fjd;"
-#del_energy_5_min_fjd="truncate table energy_5_min_fjd;"
 
 ## 历史数据一次性导入后,需要删除 mysql 中的冗余数据
 clean_energy_15(){

+ 7 - 0
energy/dayTask/config.sh

@@ -4,3 +4,10 @@ MYSQL_HOST=hadoop01
 MYSQL_URL="jdbc:mysql://$MYSQL_HOST:3306/saga_dev?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&tinyInt1isBit=false"
 MYSQL_USER=root
 MYSQL_PASSWORD=j5ry0#jZ7vaUt5f4
+
+# 上格云数据库
+SAGA_HOST=39.106.8.246
+SAGA_URL_PRE="jdbc:mysql://$SAGA_HOST:53309/"
+SAGA_URL_SUF="?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&tinyInt1isBit=false"
+SAGA_USER=root
+SAGA_PASSWORD=H%k3!BHw1kQXIc70

+ 5 - 5
energy/dayTask/energy_hive.sql

@@ -114,7 +114,7 @@ create table ods_co2_15_min
     meter      string,
     data_time  string,
     data_value decimal(30, 15)
-) COMMENT '能源原始数据15min差值数据'
+) COMMENT 'CO2 15min 分精度'
     PARTITIONED BY (`dt` string)
     ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001'
     STORED AS TEXTFILE
@@ -131,7 +131,7 @@ create table ods_pm25_15_min
     meter      string,
     data_time  string,
     data_value decimal(30, 15)
-) COMMENT '能源原始数据15min差值数据'
+) COMMENT 'PM2.5 15min 分精度'
     PARTITIONED BY (`dt` string)
     ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001'
     STORED AS TEXTFILE
@@ -148,7 +148,7 @@ create table ods_hcho_15_min
     meter      string,
     data_time  string,
     data_value decimal(30, 15)
-) COMMENT '能源原始数据15min差值数据'
+) COMMENT '甲醛 15 分钟分精度'
     PARTITIONED BY (`dt` string)
     ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001'
     STORED AS TEXTFILE
@@ -165,7 +165,7 @@ create table ods_temperature_15_min
     meter      string,
     data_time  string,
     data_value decimal(30, 15)
-) COMMENT '能源原始数据15min差值数据'
+) COMMENT '温度 15 分钟分精度'
     PARTITIONED BY (`dt` string)
     ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001'
     STORED AS TEXTFILE
@@ -182,7 +182,7 @@ create table ods_humidity_15_min
     meter      string,
     data_time  string,
     data_value decimal(30, 15)
-) COMMENT '能源原始数据15min差值数据'
+) COMMENT '湿度 15 分钟分精度'
     PARTITIONED BY (`dt` string)
     ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001'
     STORED AS TEXTFILE