|
@@ -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
|