|
@@ -3,6 +3,7 @@ from sql import Sql
|
|
from report_public_funs_utils import ReportPublicFunsUtils as rpfu
|
|
from report_public_funs_utils import ReportPublicFunsUtils as rpfu
|
|
from mail_content_text import MailContentText
|
|
from mail_content_text import MailContentText
|
|
from email_util import EmailUtil
|
|
from email_util import EmailUtil
|
|
|
|
+from file_util import FileUtil
|
|
from report_file_utils import ReportFileUtils
|
|
from report_file_utils import ReportFileUtils
|
|
|
|
|
|
|
|
|
|
@@ -10,7 +11,8 @@ class JianYeReport(object):
|
|
"""
|
|
"""
|
|
建业报表数据处理
|
|
建业报表数据处理
|
|
"""
|
|
"""
|
|
- customer_mails = ['plf@centralchina.com', 'liutt@elab-plus.com', 'binrenzhang@qq.com']
|
|
|
|
|
|
+ # customer_mails = ['plf@centralchina.com', 'liutt@elab-plus.com', 'binrenzhang@qq.com']
|
|
|
|
+ customer_mails = ['binrenzhang@qq.com']
|
|
|
|
|
|
#
|
|
#
|
|
index_type = {
|
|
index_type = {
|
|
@@ -26,6 +28,8 @@ class JianYeReport(object):
|
|
head_1 = ['城市', '项目名称', '浏览量', '浏览人数', '新增用户', '新增获电', '推荐用户', '分享获电', '裂变获电', '扫码到访数', '全民经纪人注册数', '报备成功数', '报备到访数']
|
|
head_1 = ['城市', '项目名称', '浏览量', '浏览人数', '新增用户', '新增获电', '推荐用户', '分享获电', '裂变获电', '扫码到访数', '全民经纪人注册数', '报备成功数', '报备到访数']
|
|
brand_id = '13'
|
|
brand_id = '13'
|
|
|
|
|
|
|
|
+ sheet_names_1 = ['当日数据', '当月数据', '上线以来所有数据']
|
|
|
|
+
|
|
def __init__(self):
|
|
def __init__(self):
|
|
self.db = MysqlDB('bi_report')
|
|
self.db = MysqlDB('bi_report')
|
|
|
|
|
|
@@ -35,7 +39,7 @@ class JianYeReport(object):
|
|
def get_report_customers(self, task_key):
|
|
def get_report_customers(self, task_key):
|
|
return self.db.select(Sql.sql_2, [task_key])
|
|
return self.db.select(Sql.sql_2, [task_key])
|
|
|
|
|
|
- def get_mail_title(self, type, name):
|
|
|
|
|
|
+ def get_mail_title(self, type, region_name,name):
|
|
"""
|
|
"""
|
|
获取邮件名称
|
|
获取邮件名称
|
|
:param type:1:项目,2:集团,3:区域
|
|
:param type:1:项目,2:集团,3:区域
|
|
@@ -44,11 +48,11 @@ class JianYeReport(object):
|
|
"""
|
|
"""
|
|
month_day = rpfu.get_montho_day()
|
|
month_day = rpfu.get_montho_day()
|
|
if type == 1:
|
|
if type == 1:
|
|
- return '[{}]{}数据报表'.format(month_day, name)
|
|
|
|
|
|
+ return '[{}]{}数据报表_{}'.format(month_day, region_name,name)
|
|
elif type == 2:
|
|
elif type == 2:
|
|
- return '[{}]建业云集团数据报表'.format(month_day)
|
|
|
|
|
|
+ return '[{}]建业云集团数据报表_{}'.format(month_day, name)
|
|
elif type == 3:
|
|
elif type == 3:
|
|
- return '[{}]建业云{}数据报表'.format(month_day, name)
|
|
|
|
|
|
+ return '[{}]建业云{}数据报表_{}'.format(month_day, region_name, name)
|
|
|
|
|
|
def get_mail_content(self, customer_type):
|
|
def get_mail_content(self, customer_type):
|
|
"""
|
|
"""
|
|
@@ -59,7 +63,7 @@ class JianYeReport(object):
|
|
if customer_type == 2:
|
|
if customer_type == 2:
|
|
return MailContentText.text_1
|
|
return MailContentText.text_1
|
|
else:
|
|
else:
|
|
- return '本期的数据报告已经准备完成,请点击附件查阅.'
|
|
|
|
|
|
+ return '本期数据报告已经准备完成,请点击附件查阅.'
|
|
|
|
|
|
# 项目级别的统计
|
|
# 项目级别的统计
|
|
def house_data_detail(self, time_range):
|
|
def house_data_detail(self, time_range):
|
|
@@ -114,18 +118,21 @@ class JianYeReport(object):
|
|
result = []
|
|
result = []
|
|
ids = self.get_house_id_by_brand_id(self.brand_id)
|
|
ids = self.get_house_id_by_brand_id(self.brand_id)
|
|
data_1 = self.user_data_volume_statistics(time_range, ids)
|
|
data_1 = self.user_data_volume_statistics(time_range, ids)
|
|
- data_2 = 0
|
|
|
|
|
|
+ data_2 = []
|
|
|
|
+ number_2 = 0
|
|
for x in self.get_recommend_data(time_range):
|
|
for x in self.get_recommend_data(time_range):
|
|
if str(x[0]) == self.brand_id:
|
|
if str(x[0]) == self.brand_id:
|
|
- data_2 = x[1]
|
|
|
|
|
|
+ number_2 = x[1]
|
|
|
|
+ data_2.append(number_2)
|
|
data_3 = []
|
|
data_3 = []
|
|
|
|
|
|
for key in self.index_type.keys():
|
|
for key in self.index_type.keys():
|
|
type_value = self.index_type.get(key)
|
|
type_value = self.index_type.get(key)
|
|
|
|
+ number = 0
|
|
for x in self.db.select(Sql.sql_10, [time_range[0], time_range[1]]):
|
|
for x in self.db.select(Sql.sql_10, [time_range[0], time_range[1]]):
|
|
if x[0] == type_value:
|
|
if x[0] == type_value:
|
|
- data_3.append(x[1])
|
|
|
|
-
|
|
|
|
|
|
+ number = x[1]
|
|
|
|
+ data_3.append(number_2)
|
|
result.extend(data_1)
|
|
result.extend(data_1)
|
|
result.extend(data_2)
|
|
result.extend(data_2)
|
|
result.extend(data_3)
|
|
result.extend(data_3)
|
|
@@ -155,11 +162,13 @@ class JianYeReport(object):
|
|
data_1.append(sub)
|
|
data_1.append(sub)
|
|
data_2 = []
|
|
data_2 = []
|
|
for id in house_ids:
|
|
for id in house_ids:
|
|
|
|
+ sub = [id]
|
|
|
|
+ number = 0
|
|
for x in self.get_recommend_data(time_range):
|
|
for x in self.get_recommend_data(time_range):
|
|
if id == x[0]:
|
|
if id == x[0]:
|
|
- sub = [id]
|
|
|
|
- sub.append(x[1])
|
|
|
|
- data_2.append(sub)
|
|
|
|
|
|
+ number = x[1]
|
|
|
|
+ sub.append(number)
|
|
|
|
+ data_2.append(sub)
|
|
data_3 = []
|
|
data_3 = []
|
|
for house_id in house_ids:
|
|
for house_id in house_ids:
|
|
sub = []
|
|
sub = []
|
|
@@ -170,9 +179,11 @@ class JianYeReport(object):
|
|
house_data = []
|
|
house_data = []
|
|
for key in self.index_type.keys():
|
|
for key in self.index_type.keys():
|
|
value = self.index_type.get(key)
|
|
value = self.index_type.get(key)
|
|
|
|
+ number = 0
|
|
for x in sub:
|
|
for x in sub:
|
|
if value == x[1]:
|
|
if value == x[1]:
|
|
- house_data.append(x[2])
|
|
|
|
|
|
+ number = x[2]
|
|
|
|
+ house_data.append(number)
|
|
data_3.append(house_data)
|
|
data_3.append(house_data)
|
|
result = []
|
|
result = []
|
|
for id in house_ids:
|
|
for id in house_ids:
|
|
@@ -200,7 +211,7 @@ class JianYeReport(object):
|
|
result.append(self.house_data_of_time(time_rang_1, house_ids))
|
|
result.append(self.house_data_of_time(time_rang_1, house_ids))
|
|
result.append(self.house_data_of_time(time_rang_2, house_ids))
|
|
result.append(self.house_data_of_time(time_rang_2, house_ids))
|
|
result.append(self.house_data_of_time(time_range_3, house_ids))
|
|
result.append(self.house_data_of_time(time_range_3, house_ids))
|
|
- pass
|
|
|
|
|
|
+ return result
|
|
|
|
|
|
def send_mail_to_customer(self, task_key):
|
|
def send_mail_to_customer(self, task_key):
|
|
"""
|
|
"""
|
|
@@ -208,21 +219,84 @@ class JianYeReport(object):
|
|
:param: task_key
|
|
:param: task_key
|
|
:return:
|
|
:return:
|
|
"""
|
|
"""
|
|
|
|
+ # 邮件发送参数
|
|
|
|
+ # mail_title,
|
|
|
|
+ # content,
|
|
|
|
+ # receiver,
|
|
|
|
+ # mail_excel,
|
|
|
|
+ # file_name,
|
|
|
|
+ # mail_excel_1=None,
|
|
|
|
+ # file_name_1=None
|
|
|
|
+ message = {}
|
|
send_mail_info = []
|
|
send_mail_info = []
|
|
|
|
+ mail_util = EmailUtil()
|
|
|
|
+ rfu = ReportFileUtils()
|
|
customers = self.get_report_customers(task_key)
|
|
customers = self.get_report_customers(task_key)
|
|
- for customer in customers:
|
|
|
|
- name = customer[3]
|
|
|
|
- customer_type = customer[2]
|
|
|
|
- mail = customer[4]
|
|
|
|
- ids = customer[5]
|
|
|
|
- if customer_type == 2:
|
|
|
|
- # 集团
|
|
|
|
-
|
|
|
|
- pass
|
|
|
|
- else:
|
|
|
|
- # 项目或区域
|
|
|
|
- pass
|
|
|
|
- pass
|
|
|
|
|
|
+ try:
|
|
|
|
+ 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)
|
|
|
|
+ save_path = FileUtil().save_path_create()
|
|
|
|
+ file_path = save_path + '/' + title
|
|
|
|
+ if customer_type == 2:
|
|
|
|
+ # 集团
|
|
|
|
+ table_1 = self.brand_data()
|
|
|
|
+ house_ids = self.get_house_id_by_brand_id(ids)
|
|
|
|
+ table_2 = self.house_data(house_ids)
|
|
|
|
+ # data, sheet_names, title, headers, save_path
|
|
|
|
+ content = content.format(table_1[0], table_1[1], table_1[2], table_1[3], table_1[4], table_1[5],
|
|
|
|
+ table_1[6], table_1[7], table_1[8], table_1[9], table_1[10], table_1[11], table_1[12],table_1[13], table_1[14],
|
|
|
|
+ table_1[15], table_1[16], table_1[17], table_1[18],
|
|
|
|
+ table_1[19], table_1[20], table_1[21], table_1[22], table_1[23], table_1[24], table_1[25],
|
|
|
|
+ table_1[26], table_1[27], table_1[28], table_1[29], table_1[30], table_1[31],
|
|
|
|
+ table_1[32], table_1[33], table_1[34], table_1[35]
|
|
|
|
+ )
|
|
|
|
+ rfu.create_excel_file(table_2, self.sheet_names_1, title, [self.head_1, self.head_1, self.head_1], save_path)
|
|
|
|
+ elif customer_type == 1:
|
|
|
|
+ # 项目
|
|
|
|
+ table_2 = self.house_data(self.get_house_ids(ids))
|
|
|
|
+ rfu.create_excel_file(table_2, self.sheet_names_1, title, [self.head_1, self.head_1, self.head_1], save_path)
|
|
|
|
+ elif customer_type == 3:
|
|
|
|
+ # 区域
|
|
|
|
+ table_2 = self.house_data(self.get_house_ids(ids))
|
|
|
|
+ rfu.create_excel_file(table_2, self.sheet_names_1, title, [self.head_1, self.head_1, self.head_1], save_path)
|
|
|
|
+ else:
|
|
|
|
+ pass
|
|
|
|
+ send_mail_info.append([title, content, mail, file_path, title + '.xlsx'])
|
|
|
|
+ message[1] = '数据查询和excel生成完毕'
|
|
|
|
+ # 发送邮件
|
|
|
|
+ send_mail_log = []
|
|
|
|
+ for mail in send_mail_info:
|
|
|
|
+ try:
|
|
|
|
+ for m in self.customer_mails:
|
|
|
|
+ result = mail_util.send_mail_by_admin(mail[0], mail[1], m, mail[3], mail[4])
|
|
|
|
+ if result:
|
|
|
|
+ # name, mail, report_name, push_time, send_status, status, error_message
|
|
|
|
+ send_mail_log.append([name, mail[2], mail[3], 1, 'success'])
|
|
|
|
+ else:
|
|
|
|
+ send_mail_log.append([name, mail[2], mail[3], -1, 'fail'])
|
|
|
|
+ except Exception as e:
|
|
|
|
+ print(str(e))
|
|
|
|
+ send_mail_log.append([name, mail[2], mail[3], -1, str(e)])
|
|
|
|
+ self.db.add_some(send_mail_info, Sql.sql_12)
|
|
|
|
+ message[2] = '遇见发送完毕, 共:{}份邮件'.format(len(send_mail_info))
|
|
|
|
+ except Exception as e:
|
|
|
|
+ message['error'] = str(e)
|
|
|
|
+ finally:
|
|
|
|
+ return message
|
|
|
|
+
|
|
|
|
+ def get_house_ids(self, ids_str):
|
|
|
|
+ if str(ids_str).find(',') != -1:
|
|
|
|
+ pass
|
|
|
|
+ return [x for x in str(ids_str).split(',')]
|
|
|
|
+ else:
|
|
|
|
+ return [ids_str]
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|