Commit 79e72232 authored by 李小芳's avatar 李小芳

name

parent 5fc9e94c
......@@ -15,6 +15,7 @@ from tags.services.tag import (get_tagv3_analysis_info, get_tagv3_ids_by_tagv3_n
get_first_position_ids_by_name, get_second_position_ids_by_name,
get_first_solution_ids_by_name, get_second_solution_ids_by_name,
get_tag_v3_operators_tags)
from talos.services.tag import TagService
rpc = get_rpc_invoker()
......@@ -158,7 +159,8 @@ def get_questions(pks):
question_ids = list(queryset.values_list('id', flat=True))
users = rpc['api/user/get_fundamental_info_by_user_ids'](user_ids=user_ids)
tags = rpc['api/tag/info_by_ids'](tag_ids=tag_ids)
# tags = rpc['api/tag/info_by_ids'](tag_ids=tag_ids)
tags =TagService.get_tags_info_by_ids(tag_ids=tag_ids)
doctors = rpc['doctor/user/get_doctors'](user_ids=user_ids)
user_dict = {str(user['id']): user for user in users.unwrap()}
tag_dict = {str(tag['id']): tag for tag in tags.unwrap()}
......@@ -197,8 +199,8 @@ def get_questions(pks):
filter(lambda t: str(t) in tag_dict, QuestionTag.objects.filter(question=q).values_list('tag', flat=True)))
res['tags'] = [tag_dict[str(tag_id)]['name'] for tag_id in tag_ids]
res['tag_ids'] = tag_ids
res['closure_tag_ids'] = rpc['api/tag/closure_tags'](tag_ids=tag_ids) if tag_ids else []
# res['closure_tag_ids'] = rpc['api/tag/closure_tags'](tag_ids=tag_ids) if tag_ids else []
res['closure_tag_ids'] =TagService.get_tags_info_by_ids(tag_ids=tag_ids)
fresh_tag_result = rpc["api/agile_tag/tuple_new_tags"](old_tag_ids=tag_ids)
fresh_tag_id_list = list()
fresh_tag_name_list = list()
......
......@@ -24,7 +24,7 @@ pk_data_source = source.GroupedSource.of(
source.RelatedSource(
source=source.MySQLTableSource(
logical_database_id=settings.DBMW_LOGICAL_DATABASE_ID,
table_name="api_tag",
table_name="api_sub_tag",
key_columns=['id'],
value_columns_excluded=[],
value_columns_all=True,
......
......@@ -254,7 +254,7 @@ def get_tractate(pks):
# 首页精选增加内容分类 明星列表和网红列表
tagv4 = tractate.get_tractate_tagv4_names(tractate_id=tractate.id)
if tagv4:
tags_info = tractate.get_om_tags_info(ids=tagv4)
tags_info = tractate.get_om_BRAIN_PORTs_info(ids=tagv4)
item['selected_stars'] = []
item['selected_internet_celebrity'] = []
all_tags = []
......
......@@ -379,20 +379,20 @@ class QuestionTag(models.Model):
tag = fields.MagicField(type=int, manager=TagManager, ttl=60 * 60 * 24, db_column="tag_id")
def get_name_list(self, tag_list):
logging.info("get tag_list:%s" % tag_list)
manager = TagManager()
# logging.info("get tag_list:%s" % tag_list)
# manager = TagManager()
name = list()
ma = manager.__call__(tag_list)
for i in ma:
logging.info("get manage_name:%s" % i['name'])
name.append(i['name'])
# ma = manager.__call__(tag_list)
all_tags=TagService.get_tags_info_by_ids(tag_ids=tag_list)
for i in all_tags:
name.append(i.get("name"))
return name
def get_project_tags(self, tag_list):
try:
tag_list = TagService._get_by_ids_from_cache_type(list(tag_list))
return [t.name for t in tag_list if
t.tag_type in (TAG_TYPE.BODY_PART, TAG_TYPE.BODY_PART_SUB_ITEM, TAG_TYPE.ITEM_WIKI)]
tag_list = TagService.get_tags_info_by_ids(list(tag_list))
return [t.get("name") for t in tag_list if
t.get("tag_type") in (TAG_TYPE.BODY_PART, TAG_TYPE.BODY_PART_SUB_ITEM, TAG_TYPE.ITEM_WIKI)]
except:
return []
......@@ -1115,11 +1115,11 @@ class Answer(models.Model):
def get_answer_tag(self, tag_list):
try:
association_tags_id_list = list()
tag_list = TagService._get_by_ids_from_cache_type(tag_list)
tag_list = TagService.get_tags_info_by_ids(tag_list)
for item in tag_list:
association_tags_id_list.append(
{"id": item.id, "tag_name": item.name, "recommend_type": item.recommend_type,
"tag_type": item.tag_type})
{"id": item.get("id"), "tag_name": item.get("name"), "recommend_type": item.get("recommend_type"),
"tag_type": item.get("tag_type")})
return association_tags_id_list
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
......
......@@ -43,5 +43,13 @@ git+ssh://git@git.wanmeizhensuo.com/backend/helios.git@v0.7.5
git+ssh://git@git.wanmeizhensuo.com/backend/gm-logging.git@v0.8.5
git+ssh://git@git.wanmeizhensuo.com/backend/gm-rpcd.git@v0.2.5
git+ssh://git@git.wanmeizhensuo.com/rank/gm-text-miner.git@master
brain-grpc-client==1.1.29
protobuf>=3.12.0
grpcio==1.19.0
grpcio-tools==1.19.0
sqlalchemy==1.3.20
six==1.15.0
......@@ -314,11 +314,11 @@ class Tractate(models.Model):
def get_tag(self, tag_list):
try:
association_tags_id_list = list()
tag_list = TagService._get_by_ids_from_cache_type(tag_list)
tag_list = TagService.get_tags_info_by_ids(tag_list)
for item in tag_list:
association_tags_id_list.append(
{"id": item.id, "tag_name": item.name, "recommend_type": item.recommend_type,
"tag_type": item.tag_type})
{"id": item.get("id"), "tag_name": item.get("name"), "recommend_type": item.get("recommend_type"),
"tag_type": item.get("tag_type")})
return association_tags_id_list
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
......@@ -330,7 +330,7 @@ class Tractate(models.Model):
res_list = []
result = r['pims/catalog/usertags/ids2tag'](ids=list(ids)).unwrap()
res_list = result.get("result", [])
except :
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return res_list
......@@ -338,9 +338,9 @@ class Tractate(models.Model):
def get_tag_names(self, tag_list):
try:
association_tags_id_list = list()
tag_list = TagService._get_by_ids_from_cache_type(tag_list)
tag_list = TagService.get_tags_info_by_ids(tag_list)
for item in tag_list:
if int(item.recommend_type) != 5 or int(item.tag_type) != 11:
if int(item.get("recommend_type")) != 5 or int(item.get("tag_type")) != 11:
association_tags_id_list.append(item.name)
return association_tags_id_list
except:
......@@ -363,9 +363,9 @@ class Tractate(models.Model):
def get_tag_names_content(self, tag_list):
try:
association_tags_id_list = list()
tag_list = TagService._get_by_ids_from_cache_type(tag_list)
tag_list = TagService.get_tags_info_by_ids(tag_list)
for item in tag_list:
if int(item.recommend_type) == 5 and int(item.tag_type) == 11:
if int(item.get("recommend_type")) == 5 and int(item.get("tag_type")) == 11:
association_tags_id_list.append(item.name)
return association_tags_id_list
except:
......
......@@ -7,6 +7,13 @@ from talos.services.base import ServiceBase, RpcServiceModelCache
from talos.cache.service import talos_rpc_service_model_cache
from talos.cache.gaia import talos_tagrel_cache
from talos.services.models.tag import Tag, TagType
from brain.library.v1.library_grpc_client import LibraryGrpcClient
from google.protobuf import json_format
from django.conf import settings
import json
from django.settings import BRAIN_SERVER, BRAIN_PORT
from gm_types.gaia import AUTHOR_TYPE, TAG_TYPE
class TagService(ServiceBase):
......@@ -56,12 +63,12 @@ class TagService(ServiceBase):
cached_info = cls.__cached_layer.mget(ids)
result = []
missing = cached_info.pop(cls.__cached_layer.missing_k)
if missing:
rpc_result = cls.call_rpc('api/tag/info_by_ids', tag_ids=missing)
# rpc_result = cls.call_rpc('api/tag/info_by_ids', tag_ids=missing)
rpc_result = cls.get_tags_info_by_ids(tag_ids=missing)
if rpc_result:
cls._cache_tag_info(rpc_result)
# cls._cache_tag_info(rpc_result)
result = [Tag.from_dict(i) for i in rpc_result]
for k in cached_info:
i = cached_info[k].decode()
......@@ -70,17 +77,6 @@ class TagService(ServiceBase):
return result
@classmethod
def _get_by_ids_from_cache_type(cls, ids):
result = list()
cached_info = cls.call_rpc('tag/info_by_ids_type', tag_ids=ids)
# cached_info = [TagType.from_dict(i) for i in rpc_result]
for k in cached_info:
# i = cached_info[k].decode()
# v = json.loads(k)
result.append(TagType.from_dict(k))
return result
@classmethod
def _get_closure_by_ids_from_cache(cls, ids):
"""
......@@ -105,7 +101,8 @@ class TagService(ServiceBase):
# those not in cache
for tag_id in ids:
if tag_id not in result:
closure_tag_info = cls.call_rpc('api/tag/closure_tags', tag_ids=[tag_id, ])
# closure_tag_info = cls.call_rpc('api/tag/closure_tags', tag_ids=[tag_id, ])
closure_tag_info = cls.get_tags_info_by_ids(tag_ids=[tag_id])
closure_tag_ids = [tag['id'] for tag in closure_tag_info]
result.update(closure_tag_ids)
cache.setex(str(tag_id), 6 * 60 * 60, ','.join(map(str, closure_tag_ids)))
......@@ -115,7 +112,7 @@ class TagService(ServiceBase):
@classmethod
def _get_by_id_from_cache(cls, id):
"""return obj."""
result = cls._get_by_ids_from_cache(ids=[id, ])
result = cls.get_tags_info_by_ids(tag_ids=[id])
return result and result[0] or None
@classmethod
......@@ -177,6 +174,42 @@ class TagService(ServiceBase):
return result
@classmethod
def get_tag_by_name(cls, name, count=1):
result = cls.call_rpc('api/tag/tag/query', name=name, count=count)
return result
def get_tag_by_name(cls, name):
all_tags = []
# result = cls.call_rpc('api/tag/tag/query', name=name, count=count)
client = LibraryGrpcClient(settings.BRAIN_SERVER, settings.BRAIN_PORT)
res = client.findByTagName(name=name)
if res:
stringValue = res.get("Entry", {}).get("content", {})
tag_id = stringValue.get("tag_id")
tag_name = stringValue.get("tag_name")
tag_type = stringValue.get("tag_type")
is_online = stringValue.get("is_online")
recommend_type = stringValue.get("recommend_type")
all_tags.append({"tag_id": tag_id, "tag_name": tag_name, "tag_type": tag_type, "is_online": is_online,
"recommend_type": recommend_type})
@classmethod
def get_tags_info_by_ids(cls, tag_ids):
# 测试环境
all_tags = []
client = LibraryGrpcClient(settings.BRAIN_SERVER, settings.BRAIN_PORT)
res = client.findByTagIds(tagIds=tag_ids)
res_dict = json_format.MessageToDict(res)
if res_dict:
for item in res_dict.get("Entry", []):
stringValue = item.get("Entry", {}).get("content", {}).get("data", {}).get("stringValue", {})
tag_id = stringValue.get("tag_id")
tag_name = stringValue.get("tag_name")
tag_type = stringValue.get("tag_type")
is_online = stringValue.get("is_online")
recommend_type = stringValue.get("recommend_type")
all_tags.append({"tag_id": tag_id, "tag_name": tag_name, "tag_type": tag_type, "is_online": is_online,
"recommend_type": recommend_type})
"""
{"id": item.id, "tag_name": item.name, "recommend_type": item.recommend_type,
"tag_type": item.tag_type}
"""
return all_tags
......@@ -2,7 +2,6 @@
from __future__ import unicode_literals, absolute_import, print_function
import datetime
from django.conf import settings
from django.dispatch import receiver
from django.db.models.signals import post_save
......
......@@ -334,8 +334,8 @@ def diary_update(
first_tag_id = topic_tag_ids[0]
first_tag = TagService.get_tag_by_tag_id(first_tag_id)
data = {
'tag_id': first_tag.id,
'name': first_tag.name,
'tag_id': first_tag.get("id"),
'name': first_tag.get("name"),
}
else:
diary_tags = diary.tags
......
......@@ -119,7 +119,7 @@ def create_topic(
if tag_first:
tag_id = tag_first.tag_id
tag = TagService.get_tag_by_tag_id(tag_id)
data = {'tag_id': tag.id, 'name': tag.name}
data = {'tag_id': tag.get("id"), 'name': tag.get('name')}
else:
data = {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment