sycommon-python-lib 0.1.1__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of sycommon-python-lib might be problematic. Click here for more details.
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/PKG-INFO +2 -1
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/pyproject.toml +2 -1
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/config/EmbeddingConfig.py +0 -1
- sycommon_python_lib-0.1.2/src/sycommon/config/MQConfig.py +15 -0
- sycommon_python_lib-0.1.2/src/sycommon/database/base_db_service.py +30 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/logging/kafka_log.py +14 -38
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/middleware/middleware.py +4 -0
- sycommon_python_lib-0.1.2/src/sycommon/middleware/mq.py +9 -0
- sycommon_python_lib-0.1.2/src/sycommon/models/mqlistener_config.py +38 -0
- sycommon_python_lib-0.1.2/src/sycommon/models/mqmsg_model.py +11 -0
- sycommon_python_lib-0.1.2/src/sycommon/models/mqsend_config.py +8 -0
- sycommon_python_lib-0.1.2/src/sycommon/models/sso_user.py +60 -0
- sycommon_python_lib-0.1.2/src/sycommon/rabbitmq/rabbitmq_client.py +721 -0
- sycommon_python_lib-0.1.2/src/sycommon/rabbitmq/rabbitmq_service.py +476 -0
- sycommon_python_lib-0.1.2/src/sycommon/services.py +173 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/synacos/feign.py +14 -10
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/synacos/nacos_service.py +252 -188
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon_python_lib.egg-info/PKG-INFO +2 -1
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon_python_lib.egg-info/SOURCES.txt +9 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon_python_lib.egg-info/requires.txt +1 -0
- sycommon_python_lib-0.1.1/src/sycommon/services.py +0 -29
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/README.md +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/setup.cfg +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/__init__.py +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/config/Config.py +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/config/DatabaseConfig.py +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/config/LLMConfig.py +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/config/RerankerConfig.py +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/config/__init__.py +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/database/database_service.py +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/health/__init__.py +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/health/health_check.py +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/health/ping.py +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/logging/__init__.py +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/logging/logger_wrapper.py +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/middleware/__init__.py +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/middleware/context.py +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/middleware/cors.py +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/middleware/exception.py +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/middleware/monitor_memory.py +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/middleware/timeout.py +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/middleware/traceid.py +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/models/__init__.py +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/models/log.py +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/synacos/__init__.py +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/tools/__init__.py +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/tools/snowflake.py +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/tools/timing.py +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon_python_lib.egg-info/dependency_links.txt +0 -0
- {sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon_python_lib.egg-info/top_level.txt +0 -0
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sycommon-python-lib
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Add your description here
|
|
5
5
|
Requires-Python: >=3.10
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: aio-pika>=9.5.7
|
|
7
8
|
Requires-Dist: aiohttp>=3.12.13
|
|
8
9
|
Requires-Dist: decorator>=5.2.1
|
|
9
10
|
Requires-Dist: fastapi>=0.115.14
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "sycommon-python-lib"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.2"
|
|
4
4
|
description = "Add your description here"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.10"
|
|
7
7
|
dependencies = [
|
|
8
|
+
"aio-pika>=9.5.7",
|
|
8
9
|
"aiohttp>=3.12.13",
|
|
9
10
|
"decorator>=5.2.1",
|
|
10
11
|
"fastapi>=0.115.14",
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from contextlib import contextmanager
|
|
2
|
+
from sqlalchemy.orm import sessionmaker
|
|
3
|
+
from sycommon.config.Config import SingletonMeta
|
|
4
|
+
from sycommon.database.database_service import DatabaseService
|
|
5
|
+
from sycommon.logging.kafka_log import SYLogger
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class BaseDBService(metaclass=SingletonMeta):
|
|
9
|
+
"""数据库操作基础服务类,封装会话管理功能"""
|
|
10
|
+
|
|
11
|
+
def __init__(self):
|
|
12
|
+
self.engine = DatabaseService.engine()
|
|
13
|
+
self.Session = sessionmaker(bind=self.engine)
|
|
14
|
+
|
|
15
|
+
@contextmanager
|
|
16
|
+
def session(self):
|
|
17
|
+
"""
|
|
18
|
+
数据库会话上下文管理器
|
|
19
|
+
自动处理会话的创建、提交、回滚和关闭
|
|
20
|
+
"""
|
|
21
|
+
session = self.Session()
|
|
22
|
+
try:
|
|
23
|
+
yield session
|
|
24
|
+
session.commit()
|
|
25
|
+
except Exception as e:
|
|
26
|
+
session.rollback()
|
|
27
|
+
SYLogger.error(f"Database operation failed: {str(e)}")
|
|
28
|
+
raise
|
|
29
|
+
finally:
|
|
30
|
+
session.close()
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import os
|
|
1
2
|
import sys
|
|
2
3
|
import traceback
|
|
3
4
|
import asyncio
|
|
@@ -8,10 +9,10 @@ import re
|
|
|
8
9
|
import socket
|
|
9
10
|
import time
|
|
10
11
|
import threading
|
|
11
|
-
import loguru
|
|
12
12
|
from queue import Queue, Full, Empty
|
|
13
13
|
from kafka import KafkaProducer
|
|
14
14
|
from loguru import logger
|
|
15
|
+
import loguru
|
|
15
16
|
from sycommon.config.Config import Config, SingletonMeta
|
|
16
17
|
from sycommon.middleware.context import current_trace_id
|
|
17
18
|
from sycommon.tools.snowflake import Snowflake
|
|
@@ -39,7 +40,7 @@ class KafkaLogger(metaclass=SingletonMeta):
|
|
|
39
40
|
_queue_warning_interval = 60 # 秒
|
|
40
41
|
_last_queue_warning = 0
|
|
41
42
|
_shutdown_timeout = 15 # 关闭超时时间,秒
|
|
42
|
-
_config = None #
|
|
43
|
+
_config = None # 配置变量存储
|
|
43
44
|
|
|
44
45
|
@staticmethod
|
|
45
46
|
def setup_logger(config: dict):
|
|
@@ -84,38 +85,6 @@ class KafkaLogger(metaclass=SingletonMeta):
|
|
|
84
85
|
# 设置全局异常处理器
|
|
85
86
|
sys.excepthook = KafkaLogger._handle_exception
|
|
86
87
|
|
|
87
|
-
def pars_log(record):
|
|
88
|
-
match = KafkaLogger._log_pattern.match(record.strip())
|
|
89
|
-
if match:
|
|
90
|
-
time_str = match.group(1)
|
|
91
|
-
level = match.group(2)
|
|
92
|
-
module = match.group(3)
|
|
93
|
-
function = match.group(4)
|
|
94
|
-
line = int(match.group(5))
|
|
95
|
-
message_str = match.group(6)
|
|
96
|
-
|
|
97
|
-
try:
|
|
98
|
-
message = json.loads(message_str)
|
|
99
|
-
except json.JSONDecodeError:
|
|
100
|
-
message = message_str
|
|
101
|
-
|
|
102
|
-
return {
|
|
103
|
-
"time": time_str,
|
|
104
|
-
"level": level,
|
|
105
|
-
"module": module,
|
|
106
|
-
"function": function,
|
|
107
|
-
"line": line,
|
|
108
|
-
"message": message
|
|
109
|
-
}
|
|
110
|
-
else:
|
|
111
|
-
# 使用当前时间避免重复创建相同的时间字符串
|
|
112
|
-
current_time = datetime.now()
|
|
113
|
-
return {
|
|
114
|
-
"message": record,
|
|
115
|
-
"level": "ERROR",
|
|
116
|
-
"time": current_time.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]
|
|
117
|
-
}
|
|
118
|
-
|
|
119
88
|
def custom_log_handler(record):
|
|
120
89
|
# 检查record是否是Message对象
|
|
121
90
|
if isinstance(record, loguru._handler.Message):
|
|
@@ -156,7 +125,7 @@ class KafkaLogger(metaclass=SingletonMeta):
|
|
|
156
125
|
|
|
157
126
|
# 检查是否有错误信息并设置detail字段
|
|
158
127
|
error_detail = ""
|
|
159
|
-
if level == "ERROR" and record
|
|
128
|
+
if level == "ERROR" and record["exception"] is not None:
|
|
160
129
|
error_detail = "".join(traceback.format_exception(
|
|
161
130
|
record["exception"].type,
|
|
162
131
|
record["exception"].value,
|
|
@@ -506,12 +475,19 @@ class SYLogger:
|
|
|
506
475
|
}
|
|
507
476
|
|
|
508
477
|
# 选择日志级别
|
|
478
|
+
_log = ''
|
|
509
479
|
if level == "ERROR":
|
|
510
|
-
|
|
480
|
+
_log = json.dumps(request_log, ensure_ascii=False)
|
|
481
|
+
logger.error(_log)
|
|
511
482
|
elif level == "WARNING":
|
|
512
|
-
|
|
483
|
+
_log = json.dumps(request_log, ensure_ascii=False)
|
|
484
|
+
logger.warning(_log)
|
|
513
485
|
else:
|
|
514
|
-
|
|
486
|
+
_log = json.dumps(request_log, ensure_ascii=False)
|
|
487
|
+
logger.info(_log)
|
|
488
|
+
|
|
489
|
+
if os.getenv('DEV-LOG', 'false').lower() == 'true':
|
|
490
|
+
print(_log)
|
|
515
491
|
|
|
516
492
|
@staticmethod
|
|
517
493
|
def info(msg: any):
|
{sycommon_python_lib-0.1.1 → sycommon_python_lib-0.1.2}/src/sycommon/middleware/middleware.py
RENAMED
|
@@ -2,6 +2,7 @@ from sycommon.health.ping import setup_ping_handler
|
|
|
2
2
|
from sycommon.middleware.cors import setup_cors_handler
|
|
3
3
|
from sycommon.middleware.exception import setup_exception_handler
|
|
4
4
|
from sycommon.middleware.monitor_memory import setup_monitor_memory_middleware
|
|
5
|
+
from sycommon.middleware.mq import setup_mq_middleware
|
|
5
6
|
from sycommon.middleware.timeout import setup_request_timeout_middleware
|
|
6
7
|
from sycommon.middleware.traceid import setup_trace_id_handler
|
|
7
8
|
from sycommon.health.health_check import setup_health_handler
|
|
@@ -29,4 +30,7 @@ def setup_middleware(app, config: dict):
|
|
|
29
30
|
# ping
|
|
30
31
|
app = setup_ping_handler(app)
|
|
31
32
|
|
|
33
|
+
# 添加mq中间件
|
|
34
|
+
# app = setup_mq_middleware(app)
|
|
35
|
+
|
|
32
36
|
return app
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from pydantic import BaseModel, Field
|
|
2
|
+
from typing import Callable, Coroutine, Optional
|
|
3
|
+
from aio_pika.abc import AbstractIncomingMessage
|
|
4
|
+
|
|
5
|
+
from sycommon.models.mqmsg_model import MQMsgModel
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class RabbitMQListenerConfig(BaseModel):
|
|
9
|
+
"""RabbitMQ监听器配置模型"""
|
|
10
|
+
# 监听器唯一名称
|
|
11
|
+
# name: str = Field(..., description="监听器唯一标识名称")
|
|
12
|
+
|
|
13
|
+
# 队列配置
|
|
14
|
+
queue_name: str = Field(..., description="队列名称")
|
|
15
|
+
# 使用.分割queue_name取出第一部分
|
|
16
|
+
# routing_key: str = Field(..., description="路由键")
|
|
17
|
+
|
|
18
|
+
# 消息处理器
|
|
19
|
+
handler: Callable[[MQMsgModel, AbstractIncomingMessage], Coroutine] | None = Field(
|
|
20
|
+
None, description="消息处理函数"
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
# 可选配置参数
|
|
24
|
+
host: Optional[str] = Field(None, description="RabbitMQ主机地址")
|
|
25
|
+
port: Optional[int] = Field(None, description="RabbitMQ端口")
|
|
26
|
+
username: Optional[str] = Field(None, description="用户名")
|
|
27
|
+
password: Optional[str] = Field(None, description="密码")
|
|
28
|
+
virtualhost: Optional[str] = Field(None, description="虚拟主机")
|
|
29
|
+
exchange_name: Optional[str] = Field(None, description="交换机名称")
|
|
30
|
+
exchange_type: str = Field("topic", description="交换机类型")
|
|
31
|
+
durable: bool = Field(True, description="是否持久化")
|
|
32
|
+
auto_delete: bool = Field(False, description="是否自动删除队列")
|
|
33
|
+
auto_parse_json: bool = Field(True, description="是否自动解析JSON消息")
|
|
34
|
+
|
|
35
|
+
class Config:
|
|
36
|
+
"""模型配置"""
|
|
37
|
+
# 允许存储函数类型
|
|
38
|
+
arbitrary_types_allowed = True
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from pydantic import BaseModel
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class MQMsgModel(BaseModel):
|
|
5
|
+
topicCode: str
|
|
6
|
+
msg: str | None = None
|
|
7
|
+
correlationDataId: str | None = None
|
|
8
|
+
dataKey: str | None = None
|
|
9
|
+
manualFlag: bool | None = None
|
|
10
|
+
groupId: str | None = None
|
|
11
|
+
traceId: str | None = None
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
from pydantic import BaseModel
|
|
2
|
+
from typing import List, Optional
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class SsoUser(BaseModel):
|
|
7
|
+
"""SSO用户模型,对应Java的SsoUser类"""
|
|
8
|
+
tenant_id: Optional[str] = None
|
|
9
|
+
customer_id: Optional[str] = None
|
|
10
|
+
customer_name: Optional[str] = None
|
|
11
|
+
user_type: Optional[str] = None # 用户类型
|
|
12
|
+
auth_type: Optional[str] = None # 认证类型
|
|
13
|
+
system_type: Optional[str] = None # 系统类型
|
|
14
|
+
role_type: Optional[str] = None # 角色类型
|
|
15
|
+
user_id: Optional[str] = None # 用户代码
|
|
16
|
+
user_name: Optional[str] = None # 用户名称
|
|
17
|
+
real_name: Optional[str] = None # 用户真实名称
|
|
18
|
+
user_status: Optional[str] = None # 用户状态
|
|
19
|
+
last_logon_time: Optional[datetime] = None # 上次登录时间
|
|
20
|
+
num_logon_try: Optional[int] = None # 登录重试次数
|
|
21
|
+
working_right_codes: Optional[List[str]] = None # 用户资源代码
|
|
22
|
+
group_ids: Optional[List[str]] = None # 用户组Ids
|
|
23
|
+
password: Optional[str] = None # 密码
|
|
24
|
+
old_password: Optional[str] = None # 盛易通旧密码
|
|
25
|
+
request_path: Optional[str] = None # 请求ID
|
|
26
|
+
pwd_expiry_date: Optional[datetime] = None # 过期时间
|
|
27
|
+
model_flag: Optional[str] = None # 当前模式
|
|
28
|
+
sign_key: Optional[str] = None # 签名key
|
|
29
|
+
security_token: Optional[str] = None # 安全秘钥
|
|
30
|
+
mur: Optional[str] = None # 指纹
|
|
31
|
+
init_status: str = "N" # 默认是N初始化(没有权限),Y表示权限初始化
|
|
32
|
+
mobile_brand: Optional[str] = None # 手机品牌
|
|
33
|
+
mobile_type: Optional[str] = None # 手机型号
|
|
34
|
+
mobile_system_version: Optional[str] = None # 系统版本
|
|
35
|
+
platform: Optional[str] = None # 手机平台
|
|
36
|
+
ip: Optional[str] = None # ip地址
|
|
37
|
+
browser_type: Optional[str] = None # 浏览器类型
|
|
38
|
+
os_type: Optional[str] = None # 系统类型
|
|
39
|
+
access_token: Optional[str] = None # 用于给在线用户使用
|
|
40
|
+
|
|
41
|
+
# 申请渠道 PC-“PC”、APP-“APP”、SYSTEM-“系统生成”、YYD-“租户端”
|
|
42
|
+
req_type: Optional[str] = None
|
|
43
|
+
pri_req_source: Optional[str] = None # 原始请求来源
|
|
44
|
+
req_source: Optional[str] = None # 请求来源
|
|
45
|
+
identitys: Optional[List[str]] = None # 客户身份
|
|
46
|
+
|
|
47
|
+
# 修可登录终端,为空默认全部,1=PC,2=小程序,9=其他
|
|
48
|
+
login_terminal: Optional[str] = None
|
|
49
|
+
|
|
50
|
+
# 用户来源 3=无担保撮合(小微贷)
|
|
51
|
+
user_source: Optional[str] = None
|
|
52
|
+
|
|
53
|
+
# 登录方式 手机验证码登录:phoneCode
|
|
54
|
+
login_type: Optional[str] = None
|
|
55
|
+
|
|
56
|
+
# 是否个人账户 Y是/N否
|
|
57
|
+
is_person_user: Optional[str] = None
|
|
58
|
+
|
|
59
|
+
# 请求上下文traceId,用于MQ重发等场景
|
|
60
|
+
trace_id: Optional[str] = None
|