This commit is contained in:
aqu415
2022-02-16 22:10:08 +08:00
parent 01539916d6
commit f5b42e6f5f
7 changed files with 56 additions and 43 deletions
View File
+31
View File
@@ -0,0 +1,31 @@
from server.models import CooperationMindLog
import ast
class CooperationMindLogLib(object):
"""
操作日志
"""
def save_log(self, json_msg):
"""
保存操作日志
"""
if self.should_handle(json_msg):
# 避免json解析失败
json_msg = json_msg.replace(',null]', ']')
json_msg_dict = ast.literal_eval(json_msg)
log = CooperationMindLog(
coop_mind_id=json_msg_dict.get('coop_mind_id'),
log_uuid=json_msg_dict.get('log_uuid'),
log_content=json_msg,
client_id=json_msg_dict.get('client_id')
)
log.save()
json_msg_dict.update({'log_id': log.id})
return json_msg_dict
return None
def should_handle(self, json_msg):
return 'coop_mind_id' in json_msg and 'select_node' not in json_msg
+1 -2
View File
@@ -37,9 +37,8 @@ class CooperationMindLog(AbstractModel):
"""
coop_mind_id = models.BigIntegerField(verbose_name='脑图ID', null=False, blank=False)
log_uuid = models.CharField(verbose_name='操作UUID', max_length=64, null=False, blank=False)
log_event = models.CharField(verbose_name='操作事件', max_length=32, null=False, blank=False)
log_content = models.CharField(verbose_name='操作内容', max_length=1024, null=False, blank=False)
operator = models.BigIntegerField(verbose_name='操作人', null=False)
operator = models.BigIntegerField(verbose_name='操作人', null=True)
operator_ip = models.CharField(verbose_name='操作人IP', null=False, max_length=32)
client_id = models.CharField(verbose_name='客户端ID', max_length=64, null=False, blank=False)
+6 -1
View File
@@ -1,8 +1,12 @@
from asgiref.sync import async_to_sync
from channels.generic.websocket import WebsocketConsumer
from server.lib.coope_mind_lib import CooperationMindLogLib
import json
class ChatConsumer(WebsocketConsumer):
log_lib = CooperationMindLogLib()
def connect(self):
self.room_group_name = 'chat%s' % bytes.decode(self.scope['query_string'])
print(self.room_group_name)
@@ -25,12 +29,13 @@ class ChatConsumer(WebsocketConsumer):
def receive(self, text_data):
# Send message to room group
print(text_data)
log_dict = self.log_lib.save_log(text_data)
async_to_sync(self.channel_layer.group_send)(
self.room_group_name,
{
# chat_message 方法
'type': 'chat_message',
'message': text_data
'message': text_data if log_dict is None else json.dumps(log_dict)
}
)