Browse Source

iiiii

Signed-off-by: binren <zhangbr@elab-plus.com>
binren 4 years ago
parent
commit
89d39d6ea8
2 changed files with 34 additions and 27 deletions
  1. 33 26
      jianye_report.py
  2. 1 1
      sql.py

+ 33 - 26
jianye_report.py

@@ -237,6 +237,8 @@ class JianYeReport(object):
             for x in city_info:
                 if str(id) == str(x[1]):
                     sub.extend([x[3], x[2]])
+            if len(sub) == 0:
+                sub.extend(['0000', '0000'])
             for x in data_1:
                 if str(id) == str(x[0]):
                     sub.extend(x[1:])
@@ -435,7 +437,6 @@ class JianYeReport(object):
                     elif customer_type == 3:
                         # 区域
                         table_2 = self.house_data(self.get_house_ids(ids))
-                        message['table2'] = table_2
                         send_data.append(
                             [table_2, self.sheet_names_1, title, [self.head_1, self.head_1, self.head_1], file_path,
                              content, name, mail])
@@ -443,38 +444,44 @@ class JianYeReport(object):
                         message['customer_type'] = '客户类型错误'
                 except Exception as e:
                     message['数据查询失败'] = str(e)
-            else:
-                message['error'] = '客户id错误:{}'.format(customer_id)
+        else:
+            message['error'] = '客户id错误:{}'.format(customer_id)
 
         # 生成文件
         rfu = ReportFileUtils()
         send_mail_log = []
         send_mail_info = []
-        for data in send_data:
-            try:
-                rfu.create_excel_file(data[0], data[1], data[2], data[3], data[4])
-                send_mail_info.append([data[2], data[5], data[7], data[4], data[2] + '.xls', data[6]])
-            except Exception as e:
-                print(e)
-                message['excel文件创建失败'] = str(e)
-                send_mail_log.append([data[6], data[7], data[2], -1, '文件创建失败:{}'.format(str(e))])
+        if len(send_data) > 0:
+            for data in send_data:
+                try:
+                    rfu.create_excel_file(data[0], data[1], data[2], data[3], data[4])
+                    send_mail_info.append([data[2], data[5], data[7], data[4], data[2] + '.xls', data[6]])
+                except Exception as e:
+                    print(e)
+                    message['excel文件创建失败'] = str(e)
+                    send_mail_log.append([data[6], data[7], data[2], -1, '文件创建失败:{}'.format(str(e))])
+        else:
+            message['excel_info'] = '需要生成excel的数据空'
         # 发送邮件
         mail_util = EmailUtil()
-        for mail in send_mail_info:
-            try:
-                if new_mail:
-                    result = mail_util.send_mail_by_admin(mail[0], mail[1], new_mail, mail[3], mail[4])
-                else:
-                    result = mail_util.send_mail_by_admin(mail[0], mail[1], mail[7], mail[3], mail[4])
-                if result:
-                    # name, mail, report_name, push_time, send_status, status, error_message
-                    send_mail_log.append([mail[5], mail[2], mail[3], 1, 'success'])
-                else:
-                    send_mail_log.append([mail[5], mail[2], mail[3], -1, 'fail'])
-            except Exception as e:
-                print(str(e))
-                message['邮件发送失败'] = str(e)
-                send_mail_log.append([mail[5], mail[2], mail[3], -1, '邮件发送失败:{}'.format(str(e))])
+        if len(send_data) > 0:
+            for mail in send_mail_info:
+                try:
+                    if new_mail:
+                        result = mail_util.send_mail_by_admin(mail[0], mail[1], new_mail, mail[3], mail[4])
+                    else:
+                        result = mail_util.send_mail_by_admin(mail[0], mail[1], mail[7], mail[3], mail[4])
+                    if result:
+                        # name, mail, report_name, push_time, send_status, status, error_message
+                        send_mail_log.append([mail[5], mail[2], mail[3], 1, 'success'])
+                    else:
+                        send_mail_log.append([mail[5], mail[2], mail[3], -1, 'fail'])
+                except Exception as e:
+                    print(str(e))
+                    message['邮件发送失败'] = str(e)
+                    send_mail_log.append([mail[5], mail[2], mail[3], -1, '邮件发送失败:{}'.format(str(e))])
+        else:
+            message['mail_info'] = '需要发送邮件的数据为空'
         # 写入日志
         self.db.add_some(Sql.sql_12, send_mail_log)
         return message

+ 1 - 1
sql.py

@@ -3,7 +3,7 @@
 class Sql:
     # 获取项目的城市信息
     sql_1 = """
-        select IFNULL(brand_id, -1), house_id, house_name, city from d_house a where status = 1
+        select IFNULL(brand_id, -1), house_id, house_name, city from d_house a
     """
 
     # 根据任务id获取推送客户信息