File size: 9,959 Bytes
f8b03c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
"""
文档相关 Protocol 接口定义

包含:IDocumentService
"""

from typing import Any, Protocol

from apps.core.dto import DocumentTemplateDTO, EvidenceItemDigestDTO, GenerationTaskDTO


class IDocumentService(Protocol):
    """
    文档服务接口

    定义文档模块对外提供的核心方法,供其他模块(如合同模块、案件模块)调用.
    主要用于查询匹配的文书模板和文件夹模板.

    Requirements: 2.1, 5.1, 7.1, 7.2, 8.1, 8.2
    """

    def find_matching_contract_templates(self, case_type: str) -> list[dict[str, Any]]:
        """
        查找匹配的合同文书模板

        根据案件类型查找适用的文书模板,返回模板的基本信息.

        Args:
            case_type: 案件类型(如 'civil', 'criminal', 'administrative')

        Returns:
            模板信息列表,每个元素包含:
            - id: 模板 ID
            - name: 模板名称
            - type_display: 模板类型显示名称(如 "委托代理合同")

        Raises:
            ValidationException: 案件类型无效
        """
        ...

    def find_matching_folder_templates(
        self, template_type: str, case_type: str | None = None
    ) -> list[dict[str, Any]]: ...

    def check_has_matching_templates(self, case_type: str) -> dict[str, bool]: ...

    def get_matched_folder_templates(self, case_type: str) -> str: ...

    def get_matched_folder_templates_with_legal_status(self, case_type: str, legal_statuses: list[str]) -> str: ...

    def get_folder_binding_path(self, case_type: str, subdir_key: str) -> str | None: ...

    def find_matching_case_file_templates(
        self,
        case_type: str,
        case_stage: str,
        applicable_institutions: list[str] | None = None,
    ) -> list[dict[str, Any]]: ...

    def get_template_by_id_internal(self, template_id: int) -> DocumentTemplateDTO | None: ...

    def get_template_by_function_code_internal(
        self, function_code: str, case_type: str | None = None, is_active: bool = True
    ) -> DocumentTemplateDTO | None: ...

    def list_templates_by_function_code_internal(
        self, function_code: str, case_type: str | None = None, is_active: bool = True
    ) -> list[DocumentTemplateDTO]: ...

    def list_case_templates_internal(self, is_active: bool = True) -> list[DocumentTemplateDTO]: ...

    def get_templates_by_ids_internal(self, template_ids: list[int]) -> list[DocumentTemplateDTO]: ...


class IDocumentTemplateBindingService(Protocol):
    def get_contract_subdir_path_internal(self, case_type: str, contract_sub_type: str) -> str | None: ...


class IEvidenceQueryService(Protocol):
    def list_evidence_items_for_digest_internal(
        self,
        evidence_list_ids: list[int],
        evidence_item_ids: list[int],
    ) -> list[EvidenceItemDigestDTO]: ...

    def list_evidence_item_ids_with_files_internal(
        self, evidence_item_ids: list[int]
    ) -> list[EvidenceItemDigestDTO]: ...

    def list_evidence_items_for_case_internal(self, case_id: int) -> list[EvidenceItemDigestDTO]: ...


class IGenerationTaskService(Protocol):
    def create_ai_task_internal(
        self,
        *,
        case_id: int,
        litigation_session_id: int,
        document_type: str,
        template_id: int | None,
        created_by_id: int | None,
        metadata: dict[str, Any],
    ) -> GenerationTaskDTO: ...

    def mark_task_completed_internal(
        self,
        *,
        task_id: int,
        result_file: str,
        metadata_updates: dict[str, Any],
    ) -> GenerationTaskDTO: ...

    def mark_task_failed_internal(
        self,
        *,
        task_id: int,
        error_message: str,
    ) -> GenerationTaskDTO: ...

    def get_task_internal(self, task_id: int) -> GenerationTaskDTO | None: ...

    def find_matching_folder_templates(self, template_type: str, case_type: str | None = None) -> list[dict[str, Any]]:
        """
        查找匹配的文件夹模板

        根据模板类型和案件类型查找适用的文件夹模板.

        Args:
            template_type: 模板类型('contract' 或 'case')
            case_type: 案件类型(可选,如 'civil', 'criminal')

        Returns:
            模板信息列表,每个元素包含:
            - id: 模板 ID
            - name: 模板名称

        Raises:
            ValidationException: 模板类型无效
        """
        ...

    def check_has_matching_templates(self, case_type: str) -> dict[str, bool]:
        """
        检查是否有匹配的模板

        检查指定案件类型是否同时有文件夹模板和文书模板.

        Args:
            case_type: 案件类型(如 'civil', 'criminal', 'administrative')

        Returns:
            包含检查结果的字典:
            - has_folder: 是否有匹配的文件夹模板
            - has_document: 是否有匹配的文书模板

        Raises:
            ValidationException: 案件类型无效
        """
        ...

    def get_matched_document_templates(self, case_type: str) -> str:
        """
        获取匹配的文书模板名称

        根据案件类型查找适用的文书模板,返回模板名称字符串.

        Args:
            case_type: 案件类型(如 'civil', 'criminal', 'administrative')

        Returns:
            模板名称字符串,多个模板用"、"分隔.
            如果没有匹配返回 "无匹配模板"

        Requirements: 5.1
        """
        ...

    def get_matched_folder_templates(self, case_type: str) -> str:
        """
        获取匹配的文件夹模板名称

        根据案件类型查找适用的文件夹模板,返回模板名称字符串.

        Args:
            case_type: 案件类型(如 'civil', 'criminal', 'administrative')

        Returns:
            模板名称字符串,多个模板用"、"分隔.
            如果没有匹配返回 "无匹配模板"

        Requirements: 5.2
        """
        ...

    def get_matched_folder_templates_with_legal_status(self, case_type: str, legal_statuses: list[str]) -> str:
        """
        获取匹配的文件夹模板名称(支持诉讼地位匹配)

        根据案件类型和诉讼地位查找适用的文件夹模板,返回模板名称字符串.

        Args:
            case_type: 案件类型(如 'civil', 'criminal', 'administrative')
            legal_statuses: 案件的诉讼地位列表(我方当事人的诉讼地位)

        Returns:
            模板名称字符串,多个模板用"、"分隔.
            如果没有匹配返回 "无匹配模板"

        Requirements: 5.2
        """
        ...

    def get_folder_binding_path(self, case_type: str, subdir_key: str) -> str | None:
        """
        获取文书模板绑定配置的文件夹路径

        根据案件类型和子目录键名查找配置的文件夹路径.

        Args:
            case_type: 案件类型(如 'civil', 'criminal', 'administrative')
            subdir_key: 子目录键名(如 'case_documents')

        Returns:
            配置的子目录路径,如 "1-律师资料/2-案件文书"
            如果没有配置则返回 None

        Requirements: 5.4
        """
        ...

    def list_case_templates_internal(self, is_active: bool = True) -> list["DocumentTemplateDTO"]:
        """
        内部方法:获取案件类型的所有模板列表

        Args:
            is_active: 是否只查询活跃模板

        Returns:
            DocumentTemplateDTO 列表
        """
        ...

    def get_templates_by_ids_internal(self, template_ids: list[int]) -> list["DocumentTemplateDTO"]:
        """
        内部方法:批量根据 ID 获取文档模板

        Args:
            template_ids: 模板 ID 列表

        Returns:
            DocumentTemplateDTO 列表(不存在的 ID 会被忽略)
        """
        ...

    def get_template_by_id_internal(self, template_id: int) -> DocumentTemplateDTO | None:
        """
        内部方法:根据 ID 获取文档模板

        Args:
            template_id: 模板 ID

        Returns:
            DocumentTemplateDTO,不存在返回 None

        Requirements: 7.1, 4.4
        """
        ...

    def get_template_by_function_code_internal(
        self, function_code: str, case_type: str | None = None, is_active: bool = True
    ) -> DocumentTemplateDTO | None:
        """
        内部方法:根据功能代码获取文档模板

        Args:
            function_code: 功能代码
            case_type: 案件类型(可选)
            is_active: 是否只查询活跃模板

        Returns:
            DocumentTemplateDTO,不存在返回 None

        Requirements: 7.1, 4.4
        """
        ...

    def list_templates_by_function_code_internal(
        self, function_code: str, case_type: str | None = None, is_active: bool = True
    ) -> list[DocumentTemplateDTO]:
        """
        内部方法:根据功能代码获取模板列表

        Args:
            function_code: 功能代码
            case_type: 案件类型(可选)
            is_active: 是否只查询活跃模板

        Returns:
            DocumentTemplateDTO 列表

        Requirements: 7.1, 4.4
        """
        ...

    def get_templates_by_case_type_internal(self, case_type: str, is_active: bool = True) -> list[DocumentTemplateDTO]:
        """
        内部方法:根据案件类型获取模板列表

        Args:
            case_type: 案件类型
            is_active: 是否只查询活跃模板

        Returns:
            DocumentTemplateDTO 列表
        """
        ...


class IContractGenerationService(Protocol):
    def generate_contract_document(self, contract_id: int) -> tuple[bytes, str, str | None]: ...


class ISupplementaryAgreementGenerationService(Protocol):
    def generate_supplementary_agreement(
        self, contract_id: int, agreement_id: int
    ) -> tuple[bytes, str, str | None]: ...