123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- # -*- coding: utf-8 -*-
- # @Time : 2023/8/15 9:43
- # @Author : XuJiakai
- # @File : case_utils
- # @Software: PyCharm
- import asyncio
- import datetime
- import json
- import re
- from data_clean.api.es_api import search
- from data_clean.api.hbase_api import get as hbase_get
- from data_clean.utils.json_utils import json_path, del_key
- from data_clean.utils.party_name_verify_utils import person_name_list_verify
- _case_no_year_pattern = re.compile("^[((](\\d{4}?)[))].+$")
- def case_no_year_datetime(case_no, add_year: int = 0):
- if not case_no:
- return None
- match = _case_no_year_pattern.match(case_no)
- if match:
- res = match.group(1)
- return datetime.datetime(year=int(res) + add_year, month=1, day=1)
- else:
- return None
- pass
- async def _general_query_case_party(case_no: str, index: str, doc_type: str = '_doc', case_no_key: str = 'case_no',
- hbase_table_name: str = None):
- if not case_no:
- return None
- result = await search(index=index, doc_type=doc_type, body={
- "query": {
- "bool": {
- "must": [
- {
- "term": {
- case_no_key: {
- "value": case_no
- }
- }
- }, {
- "terms": {
- "deleted": [
- "0",
- "1"
- ]
- }
- }
- ]
- }
- }
- })
- result = result['hits']
- total = result['total']
- if total != 1:
- return None
- pass
- record = result['hits'][0]
- plaintiff_info = json_path(record, '$._source.plaintiff_info')
- defendant_info = json_path(record, '$._source.defendant_info')
- litigant_info = json_path(record, '$._source.litigant_info')
- if not litigant_info:
- if hbase_table_name:
- rowkey = json_path(record, '$._id')
- re = await hbase_get(hbase_table_name, rowkey)
- if 'LITIGANT_INFO' in re:
- li_str = re['LITIGANT_INFO']
- litigant_info = json.loads(li_str)
- pass
- else:
- litigant_info = []
- if plaintiff_info:
- litigant_info = litigant_info + plaintiff_info
- if defendant_info:
- litigant_info = litigant_info + defendant_info
- names = [i['name'] for i in litigant_info]
- flag, error_name = person_name_list_verify(names)
- if not flag:
- return None
- pass
- if plaintiff_info is None or defendant_info is None or litigant_info is None or len(plaintiff_info) == 0 or len(
- defendant_info) == 0 or len(litigant_info) == 0:
- return None
- for i in plaintiff_info:
- del_key(i, 'lawyer_info')
- del_key(i, 'judge_tendency')
- for i in defendant_info:
- del_key(i, 'lawyer_info')
- del_key(i, 'judge_tendency')
- for i in litigant_info:
- del_key(i, 'lawyer_info')
- del_key(i, 'judge_tendency')
- return {
- "plaintiff_info": plaintiff_info,
- "defendant_info": defendant_info,
- "litigant_info": litigant_info,
- "plaintiff": ','.join([i['name'] for i in plaintiff_info]),
- "defendant": ','.join([i['name'] for i in defendant_info]),
- "litigant": ','.join([i['name'] for i in litigant_info]),
- }
- pass
- async def get_open_court_case_party(case_no: str):
- return await _general_query_case_party(case_no, "winhc_index_rt_company_court_open_announcement",
- hbase_table_name="NG_RT_COMPANY_COURT_OPEN_ANNOUNCEMENT")
- pass
- async def get_register_case_party(case_no: str):
- return await _general_query_case_party(case_no, "winhc_index_rt_company_court_register")
- pass
- async def get_judgement_document_party(case_no: str):
- return await _general_query_case_party(case_no, "old.wenshu_detail2", doc_type='wenshu_detail_type',
- case_no_key='case_no.keyword')
- pass
- async def get_case_party(case_no: str, source: str = None):
- if not case_no:
- return None
- if source == 'case_register':
- result = await get_open_court_case_party(case_no)
- if result:
- return result
- result = await get_judgement_document_party(case_no)
- if result:
- return result
- elif source == 'open_court':
- result = await get_register_case_party(case_no)
- if result:
- return result
- result = await get_judgement_document_party(case_no)
- if result:
- return result
- elif source == 'judgement_doc':
- result = await get_register_case_party(case_no)
- if result:
- return result
- result = await get_open_court_case_party(case_no)
- if result:
- return result
- else:
- result = await get_register_case_party(case_no)
- if result:
- return result
- result = await get_open_court_case_party(case_no)
- if result:
- return result
- result = await get_judgement_document_party(case_no)
- if result:
- return result
- return None
- pass
- async def test():
- from base_utils import to_string
- # print(await get_case_party("(2021)粤05民初2014号"))
- # print(await get_case_party("(2020)冀0181民初1940号"))
- # print(await get_case_party("(2020)冀0181民初2477号"))
- # print(to_string(await get_case_party("(2020)冀09民终5209号"), is_format=False))
- print(to_string(await get_case_party("(2020)苏0481民初1925号", source='open_court')))
- # print(await get_register_case_party("(2017)津0119民初2784号"))
- # print(await get_open_court_case_party("(2017)津0119民初2784号"))
- # print(await get_judgement_document_party("(2017)津0119民初2784号"))
- pass
- if __name__ == '__main__':
- asyncio.run(test())
- pass
|