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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
from __future__ import unicode_literals, absolute_import, print_function
import random
from gm_protocol import GmProtocol
from gm_types.push import PUSH_INFO_TYPE, AUTOMATED_PUSH
from gm_types.error import ERROR
from gm_types.gaia import (
CONST_STRINGS,
LIST_TRACTATE_FROM,
)
from gm_types.mimas import TRACTATE_DATA_TYPE
from gm_rpcd.all import bind
from talos.cache.base import vote_cache
from utils.push import vote_push
from talos.services.user import UserService
from talos.services.soft_article.soft_article import SoftArticleService
from talos.services.soft_article.reply import SoftArticleReplyService
from talos.services.soft_article.vote import SoftArticleReplyVoteService, SoftArticleVoteService
from talos.tools.vote_tool import VoteTool
from talos.services import DoctorService
from utils.rpc import gen, get_current_user
class Test():
pass
@bind('mimas/soft_article_vote/create')
def create_vote(reply_id):
"""医生后台点赞"""
reply = SoftArticleReplyService.get_by_id(pk=reply_id)
soft_article = SoftArticleService.get_by_id(pk=reply.softarticle_id)
reply.is_vote = True
reply.save()
user = UserService.get_user_by_user_id(user_id=reply.user_id)
doctor_user_id = UserService.get_user_id_by_doctor_id(doctor_id=soft_article.doctor_id)
reply, reply_vote = SoftArticleReplyVoteService.create(user_id=doctor_user_id, reply=reply)
vote_num = SoftArticleReplyService.inc_reply_vote(reply)
# vote_tool = VoteTool(redis_c=vote_cache, user_id=reply.user_id, new_version=True)
# vote_tool.receive_soft_article_reply_vote(reply_vote.id)
# 消息推送
if reply.user_id:
push_url = GmProtocol().get_tractate_detail(
comment_id=reply_id,
tractate_id=reply_vote.softarticle_id,
data_type=TRACTATE_DATA_TYPE.DOCTOR,
tractate_detail_from=LIST_TRACTATE_FROM.NOTICE_VOTE
)
vote_push(
user_id=reply.user_id,
push_url=push_url,
alert=u'{user_name}赞了你的回复{content}'.format(
user_name=str(user.nickname), content=reply.content[:10]
),
push_type=AUTOMATED_PUSH.TRACTATE_REPLY_GET_VOTED
)
return {
"vote_amount": vote_num
}
@bind('mimas/soft_article_vote/cancel')
def reply_cancel_vote(reply_id):
"""
医生后台回复取消点赞
:param reply_id:
:return:
"""
reply = SoftArticleReplyService.healthy(reply_id)
reply.is_vote = False
reply.save()
soft_article = SoftArticleService.get_by_id(pk=reply.softarticle_id)
doctor_user_id = UserService.get_user_id_by_doctor_id(doctor_id=soft_article.doctor_id)
SoftArticleReplyVoteService.cancel(doctor_user_id, reply)
vote_num = SoftArticleReplyService.dec_reply_vote(reply)
return {
"vote_amount": vote_num
}
@bind('mimas/soft_article/vote')
def create(soft_article_id):
"""
用户点赞
:return:
"""
user = get_current_user()
if not user:
return gen(ERROR.LOGIN_REQUIRED)
soft_article = SoftArticleService.healthy(soft_article_id)
tv = SoftArticleVoteService.create(softarticle_id=soft_article.id, user_id=user.id)
# 对作者添加点赞数
doctor_user_id = UserService.get_user_id_by_doctor_id(doctor_id=soft_article.doctor_id)
author = UserService.get_user_by_user_id(doctor_user_id)
author.incr_vote_count()
vote_num = SoftArticleService.inc_soft_article_vote(soft_article.id)
# vote_tool = VoteTool(redis_c=vote_cache, user_id=doctor_user_id, new_version=True)
# vote_tool.receive_soft_article_vote(tv.id)
return {
"vote_amount": vote_num
}
@bind('mimas/soft_article/vote_cancel')
def cancel(soft_article_id):
"""
新帖子取消点赞
:return:
"""
user = get_current_user()
if not user:
return gen(ERROR.LOGIN_REQUIRED)
soft_article = SoftArticleService.healthy(soft_article_id)
tv = SoftArticleVoteService.cancel(soft_article_id, user.id)
doctor_user_id = UserService.get_user_id_by_doctor_id(doctor_id=soft_article.doctor_id)
author = UserService.get_user_by_user_id(doctor_user_id)
author.decr_vote_count()
vote_num = SoftArticleService.dec_soft_article_vote(soft_article.id)
# vote_tool = VoteTool(redis_c=vote_cache, user_id=doctor_user_id, new_version=True)
# vote_tool.receive_soft_article_vote(tv.id)
return {
"vote_amount": vote_num
}
@bind('mimas/soft_article/reply_vote')
def reply_vote_create(reply_id):
"""
回复点赞
:return:
"""
user = get_current_user()
if not user:
return gen(ERROR.LOGIN_REQUIRED)
reply = SoftArticleReplyService.healthy(reply_id)
reply, reply_vote = SoftArticleReplyVoteService.create(user_id=user.id, reply=reply)
vote_num = SoftArticleReplyService.inc_reply_vote(reply)
if reply.user_id:
# vote_tool = VoteTool(redis_c=vote_cache, user_id=reply.user_id, new_version=True)
# vote_tool.receive_soft_article_reply_vote(reply_vote.id)
# 消息推送
push_url = GmProtocol().get_tractate_detail(
comment_id=reply_id,
tractate_id=reply_vote.softarticle_id,
data_type=TRACTATE_DATA_TYPE.DOCTOR,
tractate_detail_from=LIST_TRACTATE_FROM.NOTICE_VOTE
)
vote_push(
user_id=reply.user_id,
push_url=push_url,
alert=u'{user_name}赞了你的回复{content}'.format(
user_name=str(user.nick_name), content=reply.content[:10]
),
push_type=AUTOMATED_PUSH.TRACTATE_REPLY_GET_VOTED
)
return {
"vote_amount": vote_num
}
@bind('mimas/soft_article/reply_vote_cancel')
def reply_vote_cancel(reply_id):
"""
新帖子回复取消点赞
:param reply_id:
:return:
"""
user = get_current_user()
if not user:
return gen(ERROR.LOGIN_REQUIRED)
reply = SoftArticleReplyService.healthy(reply_id)
SoftArticleReplyVoteService.cancel(user.id, reply)
vote_num = SoftArticleReplyService.dec_reply_vote(reply)
return {
"vote_amount": vote_num
}
@bind('mimas/soft_article/read_votes')
def soft_article_read_all():
"""
更新未读消息状态
:return:
"""
user = get_current_user()
if not user:
return gen(ERROR.LOGIN_REQUIRED)
SoftArticleVoteService.set_read_by_user_id(user.id)
@bind('mimas/soft_article/read_reply_votes')
def soft_article_reply_read_all():
"""
更新未读消息状态
:return:
"""
user = get_current_user()
if not user:
return gen(ERROR.LOGIN_REQUIRED)
SoftArticleVoteService.set_read_by_user_id(user.id)
@bind('mimas/soft_article/unread_count')
def soft_article_unread_num(soft_article_id):
"""
点赞未读数
:return:
"""
count = SoftArticleVoteService.unread_count(softarticle_id=soft_article_id)
return {'count': count}