1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import logging
import time
from gm_types.gaia import TOPIC_TYPE
from gm_types.mimas import SOFT_ARTICLE_TYPE
from live.models import LiveStream, ZhiboConfig, LiveChannel
from talos.models.topic.activity import Activity
from talos.models.soft_article import SoftArticle
from talos.services.user import UserService
from talos.services.doctor import DoctorService
from data_sync.utils import tzlc
from talos.models.topic import Problem
# 直播
def get_live_stream(pks):
# 回放的
lives = LiveStream.objects.filter(id__in=pks)
_channel_ids = list(filter(None, lives.values_list("channel_id", flat=True).distinct()))
person_ids = set(LiveChannel.objects.filter(pk__in=_channel_ids).values_list("person_id", flat=True))
user_ids = UserService._get_user_data_by_person_ids(list(person_ids))
data = []
for live in lives:
item = {}
item["id"] = live.id
person_id = live.get_live_stream_user_id()
user_id_id = user_ids.get(person_id, None)
user_id = None
if user_id_id is not None:
user_id = user_id_id.id
item["doctor_id"] = DoctorService.get_doctor_by_user_id_v1(user_id)
item["user_id"] = user_id
item["is_online"] = live.is_finish
item["principal_type"] = 1
try:
start_time = tzlc(live.created_time)
item["start_time"] = int(time.mktime(start_time.timetuple()))
except:
pass
item["end_time"] = None
item["zhibo_time"] = None
item["show_order"] = 999
item["article_type"] = None
item["status"] = None
item["live_status"] = live.status
item["hera_is_online"] = None
item["topic_isnull"] = True if live.topic else False
item["topic_is_online"] = live.get_topic_is_online()
data.append(item)
logging.info("get data:%s" % data)
return data
# 预告
def get_live_notice(pks):
notices = ZhiboConfig.objects.filter(id__in=pks)
data = []
for notice in notices:
item = {}
item["id"] = notice.id
item["doctor_id"] = DoctorService.get_doctor_by_user_id_v1(notice.anchor_user_id)
item["user_id"] = notice.anchor_user_id
item["is_online"] = notice.is_online
item["principal_type"] = 3
try:
start_time = tzlc(notice.start_time)
item["start_time"] = int(time.mktime(start_time.timetuple()))
end_time = tzlc(notice.end_time)
item["end_time"] = int(time.mktime(end_time.timetuple()))
zhibo_time = tzlc(notice.zhibo_time)
item["zhibo_time"] = int(time.mktime(zhibo_time.timetuple()))
except:
pass
item["show_order"] = 999
item["article_type"] = None
item["status"] = None
item["live_status"] = None
item["hera_is_online"] = None
item["topic_isnull"] = None
item["topic_is_online"] = None
data.append(item)
logging.info("get data:%s" % data)
return data
# 免费招募
def get_activity(pks):
activities = Activity.objects.filter(id__in=pks)
data = []
for activity in activities:
item = {}
item["id"] = activity.id
item["doctor_id"] = activity.doctor_id
item["user_id"] = ''
item["is_online"] = activity.is_online
item["principal_type"] = 2
try:
start_time = tzlc(activity.start_time)
item["start_time"] = int(time.mktime(start_time.timetuple()))
end_time = tzlc(activity.end_time)
item["end_time"] = int(time.mktime(end_time.timetuple()))
except:
pass
item["zhibo_time"] = None
item["show_order"] = 999
item["article_type"] = None
item["status"] = None
item["live_status"] = None
item["hera_is_online"] = None
item["topic_isnull"] = None
item["topic_is_online"] = None
data.append(item)
logging.info("get data:%s" % data)
return data
# 视频贴
def get_video_tractate(pks):
softarticles = SoftArticle.objects.filter(id__in=pks, article_type=SOFT_ARTICLE_TYPE.VIDEO)
data = []
for softarticle in softarticles:
item = {}
item["id"] = softarticle.id
item["doctor_id"] = softarticle.doctor_id
item["user_id"] = ""
item["is_online"] = softarticle.is_online
item["principal_type"] = 4
try:
start_time = tzlc(softarticle.create_time)
item["start_time"] = int(time.mktime(start_time.timetuple()))
except:
pass
item["end_time"] = None
item["zhibo_time"] = None
item["show_order"] = softarticle.show_order
item["article_type"] = softarticle.article_type
item["status"] = softarticle.status
item["live_status"] = None
item["hera_is_online"] = softarticle.hera_is_online
item["topic_isnull"] = None
item["topic_is_online"] = None
data.append(item)
logging.info("get data:%s" % data)
return data
# 文本帖
def get_word_tractate(pks):
softarticles = SoftArticle.objects.filter(id__in=pks, article_type=SOFT_ARTICLE_TYPE.ORDINARY)
data = []
for softarticle in softarticles:
item = {}
item["id"] = softarticle.id
item["doctor_id"] = softarticle.doctor_id
item["user_id"] = ""
item["is_online"] = softarticle.is_online
item["principal_type"] = 5
try:
start_time = tzlc(softarticle.create_time)
item["start_time"] = int(time.mktime(start_time.timetuple()))
except:
pass
item["end_time"] = None
item["zhibo_time"] = None
item["show_order"] = softarticle.show_order
item["article_type"] = softarticle.article_type
item["status"] = softarticle.status
item["live_status"] = None
item["hera_is_online"] = softarticle.hera_is_online
item["topic_isnull"] = None
item["topic_is_online"] = None
data.append(item)
logging.info("get data:%s" % data)
return data
# 专栏
def get_article(pks):
articles = Problem.objects.filter(
id__in=pks,
topic_type__in=[TOPIC_TYPE.COLUMN_ARTICLE, TOPIC_TYPE.USER_ARTICLE]
)
data = []
for article in articles:
item = {}
item["id"] = article.id
item["user_id"] = article.user_id
item["doctor_id"] = UserService.get_doctor_id_from_user_id(article.user_id)
logging.info("get doctor_id:%s" % item["doctor_id"])
item["is_online"] = article.is_online
item["principal_type"] = 6
try:
start_time = tzlc(article.created_time)
item["start_time"] = int(time.mktime(start_time.timetuple()))
except:
pass
item["end_time"] = None
item["zhibo_time"] = None
item["show_order"] = 999
item["article_type"] = None
item["status"] = None
item["live_status"] = None
item["hera_is_online"] = None
item["topic_isnull"] = None
item["topic_is_online"] = None
data.append(item)
logging.info("get data:%s" % data)
return data