|
@@ -84,6 +84,10 @@ class UserRelationManager(abc.ABC):
|
|
def get_user_tags(self, user_id: str) -> List[str]:
|
|
def get_user_tags(self, user_id: str) -> List[str]:
|
|
pass
|
|
pass
|
|
|
|
|
|
|
|
+ @abc.abstractmethod
|
|
|
|
+ def stop_user_daily_push(self, user_id: str) -> bool:
|
|
|
|
+ pass
|
|
|
|
+
|
|
class LocalUserManager(UserManager):
|
|
class LocalUserManager(UserManager):
|
|
def get_user_profile(self, user_id) -> Dict:
|
|
def get_user_profile(self, user_id) -> Dict:
|
|
"""加载用户个人资料,如不存在则创建默认资料。主要用于本地调试"""
|
|
"""加载用户个人资料,如不存在则创建默认资料。主要用于本地调试"""
|
|
@@ -305,24 +309,45 @@ class MySQLUserRelationManager(UserRelationManager):
|
|
ret.extend(staff_user_pairs)
|
|
ret.extend(staff_user_pairs)
|
|
return ret
|
|
return ret
|
|
|
|
|
|
- def get_user_tags(self, user_id: str) -> List[str]:
|
|
|
|
|
|
+ def get_user_union_id(self, user_id: str) -> Optional[str]:
|
|
sql = f"SELECT wxid FROM {self.agent_user_table} WHERE third_party_user_id = '{user_id}' AND wxid is not null"
|
|
sql = f"SELECT wxid FROM {self.agent_user_table} WHERE third_party_user_id = '{user_id}' AND wxid is not null"
|
|
user_data = self.agent_db.select(sql, pymysql.cursors.DictCursor)
|
|
user_data = self.agent_db.select(sql, pymysql.cursors.DictCursor)
|
|
if not user_data:
|
|
if not user_data:
|
|
- logger.error(f"user[{user_id}] has no wxid")
|
|
|
|
|
|
+ logger.error(f"user[{user_id}] has no union id")
|
|
|
|
+ return None
|
|
|
|
+ union_id = user_data[0]['wxid']
|
|
|
|
+ return union_id
|
|
|
|
+
|
|
|
|
+ def get_user_tags(self, user_id: str) -> List[str]:
|
|
|
|
+ union_id = self.get_user_union_id(user_id)
|
|
|
|
+ if not union_id:
|
|
return []
|
|
return []
|
|
- user_wxid = user_data[0]['wxid']
|
|
|
|
sql = f"""
|
|
sql = f"""
|
|
select b.tag_id, c.`tag_name` from `we_com_user` as a
|
|
select b.tag_id, c.`tag_name` from `we_com_user` as a
|
|
join `we_com_user_with_tag` as b
|
|
join `we_com_user_with_tag` as b
|
|
join `we_com_tag` as c
|
|
join `we_com_tag` as c
|
|
on a.`id` = b.`user_id`
|
|
on a.`id` = b.`user_id`
|
|
and b.`tag_id` = c.id
|
|
and b.`tag_id` = c.id
|
|
- where a.union_id = '{user_wxid}' """
|
|
|
|
|
|
+ where a.union_id = '{union_id}' """
|
|
tag_data = self.wecom_db.select(sql, pymysql.cursors.DictCursor)
|
|
tag_data = self.wecom_db.select(sql, pymysql.cursors.DictCursor)
|
|
tag_names = [tag['tag_name'] for tag in tag_data]
|
|
tag_names = [tag['tag_name'] for tag in tag_data]
|
|
return tag_names
|
|
return tag_names
|
|
|
|
|
|
|
|
+ def stop_user_daily_push(self, user_id: str) -> bool:
|
|
|
|
+ try:
|
|
|
|
+ union_id = self.get_user_union_id(user_id)
|
|
|
|
+ if not union_id:
|
|
|
|
+ return False
|
|
|
|
+ sql = f"UPDATE {self.user_table} SET group_msg_disabled = 1 WHERE union_id = %s"
|
|
|
|
+ rows = self.wecom_db.execute(sql, (union_id, ))
|
|
|
|
+ if rows > 0:
|
|
|
|
+ return True
|
|
|
|
+ else:
|
|
|
|
+ return False
|
|
|
|
+ except Exception as e:
|
|
|
|
+ logger.error(f"stop_user_daily_push failed: {e}")
|
|
|
|
+ return False
|
|
|
|
+
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
config = configs.get()
|
|
config = configs.get()
|