Selaa lähdekoodia

iiiiii

Signed-off-by: Binren Zhnag <zhangbr@elab-plus.com>
Binren Zhnag 4 vuotta sitten
vanhempi
commit
f39f7411e5
2 muutettua tiedostoa jossa 28 lisäystä ja 13 poistoa
  1. 13 0
      flask_app.py
  2. 15 13
      jianye_report.py

+ 13 - 0
flask_app.py

@@ -244,6 +244,19 @@ def report_jianye():
     return json.dumps(result, ensure_ascii=False, cls=DecimalEncoder)
 
 
+@app.route('/debug_test', methods=['GET', 'POST'])
+def debug_func():
+    result = {}
+    rj = JianYeReport()
+    try:
+        rj.brand_data()
+        result['success'] = True
+    except Exception as e:
+        result['error'] = str(e)
+    finally:
+        return json.dumps(result, ensure_ascii=False, cls=DecimalEncoder)
+
+
 class DecimalEncoder(json.JSONEncoder):
 
     def default(self, o):

+ 15 - 13
jianye_report.py

@@ -234,22 +234,24 @@ class JianYeReport(object):
         rfu = ReportFileUtils()
         customers = self.get_report_customers(task_key)
         message[0] = '客户信息获取成功'
+        send_mail_log = []
         try:
             save_path = FileUtil().save_path_create()
             send_data = []
             error_customer = []
             # 查询数据
             for customer in customers:
+                # a.task_key, b.customer_type, b.name, b.mail, b.house_or_region, a.customer_id, GROUP_CONCAT(c.house_or_brand_id) as ids
+                name = customer[2]
+                customer_type = customer[1]
+                mail = customer[3]
+                ids = customer[6]
+                region_name = customer[4]
+                title = self.get_mail_title(customer_type, region_name, name)
+                content = self.get_mail_content(customer_type)
+                file_path = save_path + '/' + title + '.xlsx'
                 try:
-                    # a.task_key, b.customer_type, b.name, b.mail, b.house_or_region, a.customer_id, GROUP_CONCAT(c.house_or_brand_id) as ids
-                    name = customer[2]
-                    customer_type = customer[1]
-                    mail = customer[3]
-                    ids = customer[6]
-                    region_name = customer[4]
-                    title = self.get_mail_title(customer_type, region_name, name)
-                    content = self.get_mail_content(customer_type)
-                    file_path = save_path + '/' + title + '.xlsx'
+
                     if customer_type == 2:
                         # 集团
                         table_1 = self.brand_data()
@@ -293,8 +295,8 @@ class JianYeReport(object):
                         pass
                 except Exception as e:
                     print(str(e))
-                    error_customer.append(str(e))
-            message['errors'] = e
+                    #  # name, mail, report_name, push_time, send_status, status, error_message
+                    send_mail_log.append([name, mail, title, -1, '数据查询失败'])
             message['query_data'] = 'success'
             # 生成文件
             for data in send_data:
@@ -304,9 +306,9 @@ class JianYeReport(object):
                     send_mail_info.append([data[2], data[5], data[7], data[4], data[2] + '.xlsx', data[6]])
                 except Exception as e:
                     print(e)
+                    send_mail_log.append([data[6], data[7], data[2], -1, '文件创建失败'])
             message['file'] = 'success'
             # 发送邮件
-            send_mail_log = []
             for mail in send_mail_info:
                 try:
                     for m in self.customer_mails:
@@ -322,7 +324,7 @@ class JianYeReport(object):
                     send_mail_log.append([mail[5], mail[2], mail[3], -1, str(e)])
             message['mail'] = 'success'
             # 写入日志
-            self.db.add_some(send_mail_log, Sql.sql_12)
+            self.db.add_some(Sql.sql_12, send_mail_log)
             message['log'] = 'success'
         except Exception as e:
             message['error'] = str(e)