py-zkhb-sdk 1.0.0__py3-none-any.whl
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.
- py_zkhb_sdk/__init__.py +19 -0
- py_zkhb_sdk/_version.py +18 -0
- py_zkhb_sdk/core/__init__.py +6 -0
- py_zkhb_sdk/core/_models.py +17 -0
- py_zkhb_sdk/core/_utils.py +153 -0
- py_zkhb_sdk/core/_web_service.py +72 -0
- py_zkhb_sdk/provider.py +26 -0
- py_zkhb_sdk-1.0.0.dist-info/METADATA +204 -0
- py_zkhb_sdk-1.0.0.dist-info/RECORD +11 -0
- py_zkhb_sdk-1.0.0.dist-info/WHEEL +4 -0
- py_zkhb_sdk-1.0.0.dist-info/licenses/LICENSE +21 -0
py_zkhb_sdk/__init__.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""py_zkhb_sdk 包入口。
|
|
2
|
+
|
|
3
|
+
对外暴露统一的访问点:通过 :mod:`provider` 获取所有公共类,
|
|
4
|
+
通过 ``__version__`` 读取当前 SDK 版本号。
|
|
5
|
+
|
|
6
|
+
外部调用方式:
|
|
7
|
+
>>> from py_zkhb_sdk import __version__
|
|
8
|
+
>>> from py_zkhb_sdk.provider import ZkhbWebServiceAPI, ZkhbWebServiceAPIConfig, ZkhbWebServiceAPIResponse
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from . import provider
|
|
14
|
+
from ._version import __version__
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"__version__",
|
|
18
|
+
"provider",
|
|
19
|
+
]
|
py_zkhb_sdk/_version.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""py_zkhb_sdk 版本信息。
|
|
2
|
+
|
|
3
|
+
唯一维护的版本号变量。``pyproject.toml`` 通过 hatchling
|
|
4
|
+
的 ``[tool.hatch.version]`` 配置自动读取本文件,
|
|
5
|
+
避免版本号在多处重复维护。
|
|
6
|
+
|
|
7
|
+
遵循语义化版本 (SemVer) 规范:主版本号 . 次版本号 . 修订号。
|
|
8
|
+
|
|
9
|
+
Example::
|
|
10
|
+
|
|
11
|
+
>>> from py_zkhb_sdk import __version__
|
|
12
|
+
>>> print(__version__)
|
|
13
|
+
'0.1.0'
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
__version__ = "1.0.0"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""zkhb Web Service API 相关的数据模型定义。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel, Field
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ZkhbWebServiceAPIConfig(BaseModel):
|
|
9
|
+
"""zkhb 平台 SOAP Web Service API 的运行配置。
|
|
10
|
+
|
|
11
|
+
Attributes:
|
|
12
|
+
wsdl: 完整的 WSDL 地址(含 ``?WSDL`` 查询串),
|
|
13
|
+
例如 ``http://host/estate/webService/ForcelandEstateService.asmx?WSDL``。
|
|
14
|
+
为必填字段。
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
wsdl: str = Field(..., description="WSDL 地址")
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"""收费明细相关的 SQL 生成、SOAP 响应解析与对冲过滤工具。
|
|
2
|
+
|
|
3
|
+
本文件是纯函数集合,不依赖外部网络或数据库,便于单元测试。
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from collections import defaultdict
|
|
9
|
+
from decimal import Decimal, InvalidOperation
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def build_zkhb_web_service_api_query_charge_fee_item_list_sql(
|
|
14
|
+
columns: str = "",
|
|
15
|
+
conditions: str = "",
|
|
16
|
+
order_by: str = "order by cfi.ChargeFeeItemID",
|
|
17
|
+
) -> str:
|
|
18
|
+
"""拼接收费明细全链路查询的 SQL。
|
|
19
|
+
|
|
20
|
+
涉及主表 ``chargeMasterList``、子表 ``ChargeFeeItem``
|
|
21
|
+
及 ``EstateDetail`` / ``RoomDetail`` / ``ChargeBillItem`` 左连接,
|
|
22
|
+
默认返回 20 个字段并按 ``ChargeFeeItemID`` 升序。
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
columns: 额外要加到 SELECT 最前面的列(原始 SQL 片段,
|
|
26
|
+
如 ``"foo.col1, foo.col2"``)。会自动被 join 到
|
|
27
|
+
默认列名之前;可为空。
|
|
28
|
+
conditions: 追加到 ``where 1=1`` 之后的条件片段
|
|
29
|
+
(如 ``"and cml.EstateID=51"``);可为空。
|
|
30
|
+
order_by: 完整的 ORDER BY 子句,需包含 ``order by`` 关键字;
|
|
31
|
+
默认 ``order by cfi.ChargeFeeItemID``。
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
拼好的完整 SQL 字符串,尾部带分号。
|
|
35
|
+
"""
|
|
36
|
+
charge_fee_items_columns = (
|
|
37
|
+
"cml.ChargeMListID",
|
|
38
|
+
"cml.ChargeMListNo",
|
|
39
|
+
"cml.ChargeTime",
|
|
40
|
+
"cml.PayerName",
|
|
41
|
+
"cml.ChargePersonName",
|
|
42
|
+
"cml.ActualPayMoney",
|
|
43
|
+
"cml.EstateID",
|
|
44
|
+
"cml.ItemNames",
|
|
45
|
+
"ed.Caption as EstateName",
|
|
46
|
+
"cfi.ChargeFeeItemID",
|
|
47
|
+
"cfi.ActualAmount",
|
|
48
|
+
"cfi.SDate",
|
|
49
|
+
"cfi.EDate",
|
|
50
|
+
"cfi.RmId",
|
|
51
|
+
"rd.RmNo",
|
|
52
|
+
"cml.CreateTime",
|
|
53
|
+
"cml.LastUpdateTime",
|
|
54
|
+
"cbi.ItemName",
|
|
55
|
+
"cbi.IsPayFull",
|
|
56
|
+
"ABS(DATEDIFF(dd,cfi.EDate, cfi.SDate)) as PayDays",
|
|
57
|
+
)
|
|
58
|
+
charge_fee_items_joins = (
|
|
59
|
+
" from chargeMasterList as cml"
|
|
60
|
+
" left join EstateDetail as ed on cml.EstateID=ed.EstateID"
|
|
61
|
+
" left join ChargeFeeItem as cfi on cml.ChargeMListID=cfi.ChargeMListID"
|
|
62
|
+
" left join RoomDetail as rd on cfi.RmId=rd.RmId"
|
|
63
|
+
" left join ChargeBillItem as cbi on cfi.CBillItemID=cbi.CBillItemID"
|
|
64
|
+
)
|
|
65
|
+
select_columns = ", ".join([column for column in (columns.strip(), *charge_fee_items_columns) if column])
|
|
66
|
+
return f"select {select_columns}{charge_fee_items_joins} where 1=1 {conditions.strip()} {order_by.strip()};"
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def hedging_zkhb_web_service_api_charge_fee_item_list(
|
|
70
|
+
records: list[dict[str, Any]],
|
|
71
|
+
) -> list[dict[str, Any]]:
|
|
72
|
+
"""对冲过滤同一收款周期内金额相等的收款和退款记录。
|
|
73
|
+
|
|
74
|
+
每个 ``(SDate, EDate)`` 周期内,正金额与负金额按绝对值一一配对,
|
|
75
|
+
成功配对的两条记录均被排除;未配对、零值、非数字金额或
|
|
76
|
+
``ActualAmount`` 缺失的记录保留。
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
records: 来自
|
|
80
|
+
:func:`extract_zkhb_web_service_api_charge_fee_item_list`
|
|
81
|
+
的字典列表。每条字典需包含 ``ActualAmount``、``SDate``、
|
|
82
|
+
``EDate`` 三个键。
|
|
83
|
+
|
|
84
|
+
Returns:
|
|
85
|
+
对冲后的记录列表(原列表的子集,顺序保持不变)。
|
|
86
|
+
"""
|
|
87
|
+
period_groups: dict[tuple[str | None, str | None], list[int]] = defaultdict(list)
|
|
88
|
+
for index, record in enumerate(records):
|
|
89
|
+
start_date = record.get("SDate")
|
|
90
|
+
end_date = record.get("EDate")
|
|
91
|
+
period_groups[
|
|
92
|
+
(
|
|
93
|
+
str(start_date) if start_date is not None else None,
|
|
94
|
+
str(end_date) if end_date is not None else None,
|
|
95
|
+
)
|
|
96
|
+
].append(index)
|
|
97
|
+
|
|
98
|
+
excluded_indices: set[int] = set()
|
|
99
|
+
for indices in period_groups.values():
|
|
100
|
+
positive_indices: dict[Decimal, list[int]] = defaultdict(list)
|
|
101
|
+
negative_indices: dict[Decimal, list[int]] = defaultdict(list)
|
|
102
|
+
for index in indices:
|
|
103
|
+
try:
|
|
104
|
+
amount = Decimal(str(records[index].get("ActualAmount", 0)))
|
|
105
|
+
except (InvalidOperation, TypeError, ValueError):
|
|
106
|
+
continue
|
|
107
|
+
if not amount.is_finite() or amount == 0:
|
|
108
|
+
continue
|
|
109
|
+
if amount > 0:
|
|
110
|
+
positive_indices[amount].append(index)
|
|
111
|
+
else:
|
|
112
|
+
negative_indices[abs(amount)].append(index)
|
|
113
|
+
|
|
114
|
+
for amount, negative_group in negative_indices.items():
|
|
115
|
+
positive_group = positive_indices.get(amount, [])
|
|
116
|
+
matched_count = min(len(positive_group), len(negative_group))
|
|
117
|
+
excluded_indices.update(positive_group[:matched_count])
|
|
118
|
+
excluded_indices.update(negative_group[:matched_count])
|
|
119
|
+
|
|
120
|
+
return [record for index, record in enumerate(records) if index not in excluded_indices]
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def extract_zkhb_web_service_api_charge_fee_item_list(
|
|
124
|
+
data: dict[str, Any] | None = None,
|
|
125
|
+
) -> list[dict[str, Any]]:
|
|
126
|
+
"""从 zeep 序列化后的 SOAP 返回体中抽出收费明细行。
|
|
127
|
+
|
|
128
|
+
``GetDataSet`` 返回的 ``GetDataSetResult`` 结构形如::
|
|
129
|
+
|
|
130
|
+
{
|
|
131
|
+
"_value_1": {
|
|
132
|
+
"_value_1": [{"Table": {...}}, ...]
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
本函数沿路径 ``_value_1._value_1`` 取到行列表,
|
|
137
|
+
再从每行里剥掉 ``Table`` 外壳。路径缺失或类型不对时安全返回空列表。
|
|
138
|
+
|
|
139
|
+
Args:
|
|
140
|
+
data: 由 ``zeep.helpers.serialize_object`` 得到的字典;
|
|
141
|
+
可为 ``None`` 或缺 key,均返回空列表。
|
|
142
|
+
|
|
143
|
+
Returns:
|
|
144
|
+
行字典列表(每行就是 ``Table`` 里的内容)。
|
|
145
|
+
"""
|
|
146
|
+
results: list[dict[str, Any]] = []
|
|
147
|
+
data = data or {}
|
|
148
|
+
tables = data.get("_value_1", {}).get("_value_1", [])
|
|
149
|
+
if isinstance(tables, list):
|
|
150
|
+
for row in tables:
|
|
151
|
+
if isinstance(row, dict):
|
|
152
|
+
results.append(row.get("Table", {}))
|
|
153
|
+
return results
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""SOAP Web Service 主入口封装。
|
|
2
|
+
|
|
3
|
+
把 zeep 客户端的创建与常用 SOAP 操作暴露成易用的 Python 接口,
|
|
4
|
+
让调用方无需关心 WSDL 解析、操作名和响应结构。
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
import zeep
|
|
12
|
+
|
|
13
|
+
from ._models import ZkhbWebServiceAPIConfig
|
|
14
|
+
from ._utils import extract_zkhb_web_service_api_charge_fee_item_list
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ZkhbWebServiceAPI:
|
|
18
|
+
"""zkhb 平台 SOAP Web Service 主入口。
|
|
19
|
+
|
|
20
|
+
构造时会基于 ``ZkhbWebServiceAPIConfig.wsdl`` 初始化一个
|
|
21
|
+
``zeep.Client`` 实例;后续通过 ``client`` 属性直接访问
|
|
22
|
+
所有原始 SOAP 操作,或使用本类提供的高层封装方法。
|
|
23
|
+
|
|
24
|
+
Attributes:
|
|
25
|
+
config: 构造时传入的配置(含 WSDL 地址)。
|
|
26
|
+
client: zeep 客户端实例,暴露 ``service``、``wsdl`` 等。
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
def __init__(
|
|
30
|
+
self,
|
|
31
|
+
config: ZkhbWebServiceAPIConfig | None = None,
|
|
32
|
+
client_kwargs: dict[str, Any] | None = None,
|
|
33
|
+
) -> None:
|
|
34
|
+
"""初始化 Web Service 客户端。
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
config: API 配置。为 ``None`` 时内部按默认值构造,
|
|
38
|
+
但 ``wsdl`` 仍是必填,会触发 pydantic 校验。
|
|
39
|
+
client_kwargs: 透传给 ``zeep.Client`` 的额外参数
|
|
40
|
+
(如 ``transport``、``settings``)。
|
|
41
|
+
"""
|
|
42
|
+
# pydantic BaseModel 的动态构造签名 mypy 无法识别, wsdl 在运行时必传
|
|
43
|
+
self.config = config or ZkhbWebServiceAPIConfig() # type: ignore[call-arg]
|
|
44
|
+
client_kwargs = client_kwargs or {}
|
|
45
|
+
client_kwargs.setdefault("wsdl", self.config.wsdl)
|
|
46
|
+
self.client = zeep.Client(**client_kwargs) # type: ignore[no-untyped-call]
|
|
47
|
+
|
|
48
|
+
def query_charge_fee_item_list(
|
|
49
|
+
self,
|
|
50
|
+
sql: str = "",
|
|
51
|
+
url: str = "",
|
|
52
|
+
) -> list[dict[str, Any]]:
|
|
53
|
+
"""通过 ``GetDataSet`` 执行 SQL,返回解析后的收费明细列表。
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
sql: 完整的 SQL 语句(通常由
|
|
57
|
+
:func:`build_zkhb_web_service_api_query_charge_fee_item_list_sql`
|
|
58
|
+
生成)。
|
|
59
|
+
url: SOAP 接口预留的第二个参数,通常传空字符串。
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
收费明细 ``Table`` 字典列表;调用失败时返回空列表。
|
|
63
|
+
"""
|
|
64
|
+
try:
|
|
65
|
+
result = self.client.service.GetDataSet(sql=sql, url=url)
|
|
66
|
+
import zeep.helpers as zeep_helpers
|
|
67
|
+
|
|
68
|
+
return extract_zkhb_web_service_api_charge_fee_item_list(
|
|
69
|
+
zeep_helpers.serialize_object(result, dict) # type: ignore[no-untyped-call]
|
|
70
|
+
)
|
|
71
|
+
except Exception:
|
|
72
|
+
return []
|
py_zkhb_sdk/provider.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""包门面模块,所有公共类的唯一导出入口。
|
|
2
|
+
|
|
3
|
+
外部项目只需::
|
|
4
|
+
|
|
5
|
+
from py_zkhb_sdk.provider import ZkhbWebServiceAPI, ZkhbWebServiceAPIConfig, ZkhbWebServiceAPIResponse
|
|
6
|
+
|
|
7
|
+
即可使用 SDK 全部能力,无需关心内部模块路径。
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from .core._models import ZkhbWebServiceAPIConfig
|
|
13
|
+
from .core._utils import (
|
|
14
|
+
build_zkhb_web_service_api_query_charge_fee_item_list_sql,
|
|
15
|
+
extract_zkhb_web_service_api_charge_fee_item_list,
|
|
16
|
+
hedging_zkhb_web_service_api_charge_fee_item_list,
|
|
17
|
+
)
|
|
18
|
+
from .core._web_service import ZkhbWebServiceAPI
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"ZkhbWebServiceAPI",
|
|
22
|
+
"ZkhbWebServiceAPIConfig",
|
|
23
|
+
"build_zkhb_web_service_api_query_charge_fee_item_list_sql",
|
|
24
|
+
"extract_zkhb_web_service_api_charge_fee_item_list",
|
|
25
|
+
"hedging_zkhb_web_service_api_charge_fee_item_list",
|
|
26
|
+
]
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: py-zkhb-sdk
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: zkhb WebService 平台 Python SDK - 同步接口调用(官方文档: 待补充)
|
|
5
|
+
Project-URL: Homepage, https://gitee.com/guolei19850528/py_zkhb_sdk
|
|
6
|
+
Project-URL: Repository, https://gitee.com/guolei19850528/py_zkhb_sdk.git
|
|
7
|
+
Project-URL: Issues, https://gitee.com/guolei19850528/py_zkhb_sdk/issues
|
|
8
|
+
Author-email: guolei <174000902@qq.com>
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Requires-Dist: pydantic>=2.7
|
|
12
|
+
Requires-Dist: zeep[async,xmlsec]>=4.3.3
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# py_zkhb_sdk
|
|
16
|
+
|
|
17
|
+
zkhb 平台 SOAP Web Service Python SDK,基于 `zeep` 封装,提供收费明细查询、响应解析与对冲过滤等高层能力。
|
|
18
|
+
|
|
19
|
+
## 功能概览
|
|
20
|
+
|
|
21
|
+
- **SOAP 便捷封装**:`ZkhbWebServiceAPI` 自动创建 zeep 客户端,一行调用 `GetDataSet`
|
|
22
|
+
- **收费明细查询 SQL 生成**:`build_zkhb_web_service_api_query_charge_fee_item_list_sql` 封装多表 join
|
|
23
|
+
- **SOAP 响应解析**:`extract_zkhb_web_service_api_charge_fee_item_list` 从 `GetDataSetResult` 中抽取行数据
|
|
24
|
+
- **对冲过滤**:`hedging_zkhb_web_service_api_charge_fee_item_list` 同一收款周期内正/负金额配对抵消
|
|
25
|
+
- **类型安全**:全部公开符号带类型注解 + Google 风格 docstring,mypy strict 通过
|
|
26
|
+
- **代码风格**:PEP 8 + ruff + Google Python Style Guide
|
|
27
|
+
|
|
28
|
+
## 目录结构
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
py_zkhb_sdk/
|
|
32
|
+
├── src/py_zkhb_sdk/
|
|
33
|
+
│ ├── __init__.py # 包入口, 暴露 __version__
|
|
34
|
+
│ ├── _version.py # 唯一维护的版本号
|
|
35
|
+
│ ├── provider.py # 门面模块, 所有公共符号从此导出
|
|
36
|
+
│ └── core/
|
|
37
|
+
│ ├── _models.py # ZkhbWebServiceAPIConfig (pydantic)
|
|
38
|
+
│ ├── _web_service.py # ZkhbWebServiceAPI 主入口类
|
|
39
|
+
│ └── _utils.py # SQL 构造 / 响应解析 / 对冲过滤
|
|
40
|
+
├── tests/ # pytest 集成测试 (真实 SOAP 请求)
|
|
41
|
+
└── pyproject.toml # hatchling + ruff + mypy 配置
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 安装
|
|
45
|
+
|
|
46
|
+
### PyPI
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install py-zkhb-sdk
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 本地开发
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# 克隆并进入
|
|
56
|
+
git clone https://gitee.com/guolei19850528/py_zkhb_sdk.git
|
|
57
|
+
cd py_zkhb_sdk
|
|
58
|
+
|
|
59
|
+
# 推荐用 uv
|
|
60
|
+
uv sync --dev
|
|
61
|
+
|
|
62
|
+
# 或使用 pip editable 安装
|
|
63
|
+
pip install -e .
|
|
64
|
+
pip install pytest python-dotenv ruff mypy # 开发工具
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
要求:Python ≥ 3.10
|
|
68
|
+
|
|
69
|
+
## 快速开始
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from py_zkhb_sdk.provider import (
|
|
73
|
+
ZkhbWebServiceAPI,
|
|
74
|
+
ZkhbWebServiceAPIConfig,
|
|
75
|
+
build_zkhb_web_service_api_query_charge_fee_item_list_sql,
|
|
76
|
+
extract_zkhb_web_service_api_charge_fee_item_list,
|
|
77
|
+
hedging_zkhb_web_service_api_charge_fee_item_list,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
# 1) 配置 WSDL
|
|
81
|
+
cfg = ZkhbWebServiceAPIConfig(
|
|
82
|
+
wsdl="http://host/estate/webService/ForcelandEstateService.asmx?WSDL"
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
# 2) 创建客户端
|
|
86
|
+
api = ZkhbWebServiceAPI(config=cfg)
|
|
87
|
+
|
|
88
|
+
# 3) 构造查询 SQL
|
|
89
|
+
sql = build_zkhb_web_service_api_query_charge_fee_item_list_sql(
|
|
90
|
+
conditions="and cml.EstateID=51",
|
|
91
|
+
order_by="order by cml.ChargeTime desc",
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
# 4) 调用封装方法 (自动抽取 Table)
|
|
95
|
+
rows = api.query_charge_fee_item_list(sql=sql)
|
|
96
|
+
|
|
97
|
+
# 5) 对冲过滤 (同周期正/负金额配对抵消)
|
|
98
|
+
cleaned = hedging_zkhb_web_service_api_charge_fee_item_list(rows)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### 直接使用原始 SOAP 操作
|
|
102
|
+
|
|
103
|
+
封装方法之外, `api.client.service` 直接暴露 WSDL 上所有 SOAP 操作:
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
# 直接调用 GetDataSet
|
|
107
|
+
result = api.client.service.GetDataSet(sql="select top 10 * from chargeMasterList", url="")
|
|
108
|
+
|
|
109
|
+
# 手动从返回体抽取行数据
|
|
110
|
+
from zeep.helpers import serialize_object
|
|
111
|
+
data = serialize_object(result, dict)
|
|
112
|
+
rows = extract_zkhb_web_service_api_charge_fee_item_list(data)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## 门面导出清单
|
|
116
|
+
|
|
117
|
+
全部公共符号从 `py_zkhb_sdk.provider` 导入即可, 无需关心内部路径:
|
|
118
|
+
|
|
119
|
+
| 名称 | 类型 | 说明 |
|
|
120
|
+
|---|---|---|
|
|
121
|
+
| `ZkhbWebServiceAPI` | class | SOAP 主入口, 封装 zeep 客户端 |
|
|
122
|
+
| `ZkhbWebServiceAPIConfig` | class | 运行配置 (pydantic), 含必填的 `wsdl` 字段 |
|
|
123
|
+
| `build_zkhb_web_service_api_query_charge_fee_item_list_sql` | function | 生成收费明细全链路 SQL |
|
|
124
|
+
| `extract_zkhb_web_service_api_charge_fee_item_list` | function | 从 SOAP 返回体抽取 `Table` 列表 |
|
|
125
|
+
| `hedging_zkhb_web_service_api_charge_fee_item_list` | function | 同一收款周期正/负金额配对抵消 |
|
|
126
|
+
|
|
127
|
+
## 测试
|
|
128
|
+
|
|
129
|
+
### 运行
|
|
130
|
+
|
|
131
|
+
测试分为两部分:
|
|
132
|
+
|
|
133
|
+
- `TestBuildZkhbWebServiceApiQueryChargeFeeItemListSql` / `TestExtractZkhbWebServiceApiChargeFeeItemList` / `TestHedgingZkhbWebServiceApiChargeFeeItemList` — 纯函数, 自生成合成数据, **不发网络请求**, 可直接跑
|
|
134
|
+
- `TestZkhbWebServiceAPIInit` / `TestGetDataSetRaw` / `TestEndToEndPipeline` — **真实 SOAP 调用**, 需要 `.env` 里的 WSDL
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
# 1) 复制环境变量模板
|
|
138
|
+
cp .env.example .env
|
|
139
|
+
# 填入你的 zkhb WSDL 地址
|
|
140
|
+
# ZKHB_WEB_SERVICE_WSDL=http://host/estate/webService/ForcelandEstateService.asmx?WSDL
|
|
141
|
+
|
|
142
|
+
# 2) 跑全部测试 (含真实 SOAP 请求)
|
|
143
|
+
pytest tests/ -v
|
|
144
|
+
|
|
145
|
+
# 3) 只跑单元测试 (不需要网络)
|
|
146
|
+
pytest tests/ -v -k "Build or Extract or Hedging"
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
当前测试覆盖: **40 个用例 / 32 个通过 (含真实 SOAP) / 单元测试全过**
|
|
150
|
+
|
|
151
|
+
### 规则
|
|
152
|
+
|
|
153
|
+
- 没有配置 `ZKHB_WEB_SERVICE_WSDL` 时, 集成测试类自动 skip
|
|
154
|
+
- `Hedging` 测试全部使用自生成合成数据, 不依赖外部环境
|
|
155
|
+
|
|
156
|
+
## 代码规范
|
|
157
|
+
|
|
158
|
+
本项目遵循 Google Python Style Guide + PEP 8:
|
|
159
|
+
|
|
160
|
+
| 工具 | 配置 | 用途 |
|
|
161
|
+
|---|---|---|
|
|
162
|
+
| ruff | pyproject.toml `[tool.ruff]` | Lint + 格式化 + isort |
|
|
163
|
+
| mypy | pyproject.toml `[tool.mypy]` (strict) | 静态类型检查 |
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
# 自动修复 + 格式化
|
|
167
|
+
ruff check --fix src/ tests/
|
|
168
|
+
ruff format src/ tests/
|
|
169
|
+
|
|
170
|
+
# 只检查, 不改文件
|
|
171
|
+
ruff check src/ tests/
|
|
172
|
+
ruff format --check src/ tests/
|
|
173
|
+
mypy src/
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## 构建 & 发布 (仅维护者)
|
|
177
|
+
|
|
178
|
+
发布流程封装在项目级 Skill `release-publish` 中, 触发词: "发布 X.Y.Z" / "release" / "推到 PyPI". 执行前先确认:
|
|
179
|
+
|
|
180
|
+
- 当前分支 = `develop`, 工作区干净
|
|
181
|
+
- `.venv` 里装了 `build` / `twine`, `~/.pypirc` 有 PyPI token
|
|
182
|
+
- `ruff check` / `ruff format --check` / `mypy` 全部通过
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
# 最终产物位于 dist/
|
|
186
|
+
.venv/bin/python -m build
|
|
187
|
+
.venv/bin/twine upload dist/py_zkhb-sdk-X.Y.Z*
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
发布后自动合并 `develop → release → master`, 打 annotated tag, 三分支推送到 Gitee.
|
|
191
|
+
|
|
192
|
+
## 版本
|
|
193
|
+
|
|
194
|
+
遵循 SemVer. 版本号只在一处维护: [`src/py_zkhb_sdk/_version.py`](./src/py_zkhb_sdk/_version.py) 中的 `__version__`, hatchling 构建时自动读取.
|
|
195
|
+
|
|
196
|
+
## 社区
|
|
197
|
+
|
|
198
|
+
- **Gitee**: <https://gitee.com/guolei19850528/py_zkhb_sdk>
|
|
199
|
+
- **Issues**: <https://gitee.com/guolei19850528/py_zkhb_sdk/issues>
|
|
200
|
+
- **作者**: guolei <174000902@qq.com>
|
|
201
|
+
|
|
202
|
+
## License
|
|
203
|
+
|
|
204
|
+
MIT License
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
py_zkhb_sdk/__init__.py,sha256=2sXFs4ZgJUDR7g5XzuKd0m_hndYfPYbIg5UXnMsTz0o,489
|
|
2
|
+
py_zkhb_sdk/_version.py,sha256=mcw4dyADuT001Tbb_nOQYOlVvYMtvIp0mCIBKFcQve4,443
|
|
3
|
+
py_zkhb_sdk/provider.py,sha256=YVjrdW2oQSjsDrm_WWFqQvbNR8k4OCF1WDzSNlzdaUk,850
|
|
4
|
+
py_zkhb_sdk/core/__init__.py,sha256=M_3-lTNMXMk01B_7Mip9HDDkFj07c9uqh01OCtGByYk,140
|
|
5
|
+
py_zkhb_sdk/core/_models.py,sha256=9y1BMU0afFF6FTthp-fDU-7oUchkzAbmWuWvSoAPUzo,504
|
|
6
|
+
py_zkhb_sdk/core/_utils.py,sha256=M9OPYTUCQ0DRRwolu9QBiOHtlMccBv1VV6oOXra_CMg,5829
|
|
7
|
+
py_zkhb_sdk/core/_web_service.py,sha256=F-ABIjISTh24BkorhqtcPDK9xixHRac7PY9xMHnIfos,2660
|
|
8
|
+
py_zkhb_sdk-1.0.0.dist-info/METADATA,sha256=8JLOr8q-QNgda_OQ1s9AivydJf0wkiR2OQqzOikVB7M,6715
|
|
9
|
+
py_zkhb_sdk-1.0.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
10
|
+
py_zkhb_sdk-1.0.0.dist-info/licenses/LICENSE,sha256=HazFJNaQP3rbY1dvg3hAmO-FZ6v7DwM0YHwXvWsGG3A,1063
|
|
11
|
+
py_zkhb_sdk-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 郭磊
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|