ck преди 4 години
родител
ревизия
0c07972bdf
променени са 2 файла, в които са добавени 30 реда и са изтрити 0 реда
  1. 23 0
      app/etl/data_stat_task.py
  2. 7 0
      model/DataBaseOperation.py

+ 23 - 0
app/etl/data_stat_task.py

@@ -51,4 +51,27 @@ def dw_daily_channel(dt):
     db.quchen_text.execute(insert_sql)
 
 
+def clean_order(dt):
+    sql="""	replace into ods_order
+			select 
+			case platform when '掌中云' then DATE_FORMAT(STR_TO_DATE(order_time,'%Y-%m-%dT%H:%i:%s'),'%Y-%m-%d') 
+            when '掌读' then from_unixtime(order_time, '%Y-%m-%d') 
+            ELSE left(order_time,10) end  date,
+            stage,platform,channel,channel_id,user_id,
+            case when platform='掌中云' then DATE_FORMAT(STR_TO_DATE(order_time,'%Y-%m-%dT%H:%i:%s'),'%Y-%m-%d %H:%i:%s') 
+            when platform='掌读' then from_unixtime(order_time, '%Y-%m-%d %H:%i:%s') 
+            ELSE order_time end order_time,
+            case when platform='掌中云' then DATE_FORMAT(STR_TO_DATE(reg_time,'%Y-%m-%dT%H:%i:%s'),'%Y-%m-%d %H:%i:%s') 
+            when platform='掌读' then from_unixtime(reg_time, '%Y-%m-%d %H:%i:%s') 
+            ELSE reg_time end reg_time,
+			amount,from_novel,order_id from `order` where date=UNIX_TIMESTAMP('{}')
+			""".format(dt)
+    db.quchen_text.execute(sql)
+
+if __name__ == '__main__':
+
+    li=dt.getDateLists('2019-03-01','2020-01-01')
+    for i in  li:
+        print(i)
+        clean_order(i)
 

+ 7 - 0
model/DataBaseOperation.py

@@ -76,6 +76,13 @@ class MysqlOperation:
             log.info('sql: \n' + sql)
             log.info('sql cost: %s' % (time.time() - start))
 
+    def executeMany(self,sql,data):
+        start = time.time()
+        self.cursor.executemany(sql,data)
+        self.conn.commit()
+        if MYSQL_DEBUG:
+            log.info('sql: \n' + sql)
+            log.info('sql cost: %s' % (time.time() - start))
 
     def getOne(self,sql, args=None):
         result = self.getData(sql, args)