case_utils.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. # -*- coding: utf-8 -*-
  2. # @Time : 2023/8/15 9:43
  3. # @Author : XuJiakai
  4. # @File : case_utils
  5. # @Software: PyCharm
  6. import asyncio
  7. import datetime
  8. import json
  9. import re
  10. from data_clean.api.es_api import search
  11. from data_clean.api.hbase_api import get as hbase_get
  12. from data_clean.utils.json_utils import json_path, del_key
  13. from data_clean.utils.party_name_verify_utils import person_name_list_verify
  14. _case_no_year_pattern = re.compile("^[((](\\d{4}?)[))].+$")
  15. def case_no_year_datetime(case_no, add_year: int = 0):
  16. if not case_no:
  17. return None
  18. match = _case_no_year_pattern.match(case_no)
  19. if match:
  20. res = match.group(1)
  21. return datetime.datetime(year=int(res) + add_year, month=1, day=1)
  22. else:
  23. return None
  24. pass
  25. async def _general_query_case_party(case_no: str, index: str, doc_type: str = '_doc', case_no_key: str = 'case_no',
  26. hbase_table_name: str = None):
  27. if not case_no:
  28. return None
  29. result = await search(index=index, doc_type=doc_type, body={
  30. "query": {
  31. "bool": {
  32. "must": [
  33. {
  34. "term": {
  35. case_no_key: {
  36. "value": case_no
  37. }
  38. }
  39. }, {
  40. "terms": {
  41. "deleted": [
  42. "0",
  43. "1"
  44. ]
  45. }
  46. }
  47. ]
  48. }
  49. }
  50. })
  51. result = result['hits']
  52. total = result['total']
  53. if total != 1:
  54. return None
  55. pass
  56. record = result['hits'][0]
  57. plaintiff_info = json_path(record, '$._source.plaintiff_info')
  58. defendant_info = json_path(record, '$._source.defendant_info')
  59. litigant_info = json_path(record, '$._source.litigant_info')
  60. if not litigant_info:
  61. if hbase_table_name:
  62. rowkey = json_path(record, '$._id')
  63. re = await hbase_get(hbase_table_name, rowkey)
  64. if 'LITIGANT_INFO' in re:
  65. li_str = re['LITIGANT_INFO']
  66. litigant_info = json.loads(li_str)
  67. pass
  68. else:
  69. litigant_info = []
  70. if plaintiff_info:
  71. litigant_info = litigant_info + plaintiff_info
  72. if defendant_info:
  73. litigant_info = litigant_info + defendant_info
  74. names = [i['name'] for i in litigant_info]
  75. flag, error_name = person_name_list_verify(names)
  76. if not flag:
  77. return None
  78. pass
  79. if plaintiff_info is None or defendant_info is None or litigant_info is None or len(plaintiff_info) == 0 or len(
  80. defendant_info) == 0 or len(litigant_info) == 0:
  81. return None
  82. for i in plaintiff_info:
  83. del_key(i, 'lawyer_info')
  84. del_key(i, 'judge_tendency')
  85. for i in defendant_info:
  86. del_key(i, 'lawyer_info')
  87. del_key(i, 'judge_tendency')
  88. for i in litigant_info:
  89. del_key(i, 'lawyer_info')
  90. del_key(i, 'judge_tendency')
  91. return {
  92. "plaintiff_info": plaintiff_info,
  93. "defendant_info": defendant_info,
  94. "litigant_info": litigant_info,
  95. "plaintiff": ','.join([i['name'] for i in plaintiff_info]),
  96. "defendant": ','.join([i['name'] for i in defendant_info]),
  97. "litigant": ','.join([i['name'] for i in litigant_info]),
  98. }
  99. pass
  100. async def get_open_court_case_party(case_no: str):
  101. return await _general_query_case_party(case_no, "winhc_index_rt_company_court_open_announcement",
  102. hbase_table_name="NG_RT_COMPANY_COURT_OPEN_ANNOUNCEMENT")
  103. pass
  104. async def get_register_case_party(case_no: str):
  105. return await _general_query_case_party(case_no, "winhc_index_rt_company_court_register")
  106. pass
  107. async def get_judgement_document_party(case_no: str):
  108. return await _general_query_case_party(case_no, "old.wenshu_detail2", doc_type='wenshu_detail_type',
  109. case_no_key='case_no.keyword')
  110. pass
  111. async def get_case_party(case_no: str, source: str = None):
  112. if not case_no:
  113. return None
  114. if source == 'case_register':
  115. result = await get_open_court_case_party(case_no)
  116. if result:
  117. return result
  118. result = await get_judgement_document_party(case_no)
  119. if result:
  120. return result
  121. elif source == 'open_court':
  122. result = await get_register_case_party(case_no)
  123. if result:
  124. return result
  125. result = await get_judgement_document_party(case_no)
  126. if result:
  127. return result
  128. elif source == 'judgement_doc':
  129. result = await get_register_case_party(case_no)
  130. if result:
  131. return result
  132. result = await get_open_court_case_party(case_no)
  133. if result:
  134. return result
  135. else:
  136. result = await get_register_case_party(case_no)
  137. if result:
  138. return result
  139. result = await get_open_court_case_party(case_no)
  140. if result:
  141. return result
  142. result = await get_judgement_document_party(case_no)
  143. if result:
  144. return result
  145. return None
  146. pass
  147. async def test():
  148. from base_utils import to_string
  149. # print(await get_case_party("(2021)粤05民初2014号"))
  150. # print(await get_case_party("(2020)冀0181民初1940号"))
  151. # print(await get_case_party("(2020)冀0181民初2477号"))
  152. # print(to_string(await get_case_party("(2020)冀09民终5209号"), is_format=False))
  153. print(to_string(await get_case_party("(2020)苏0481民初1925号", source='open_court')))
  154. # print(await get_register_case_party("(2017)津0119民初2784号"))
  155. # print(await get_open_court_case_party("(2017)津0119民初2784号"))
  156. # print(await get_judgement_document_party("(2017)津0119民初2784号"))
  157. pass
  158. if __name__ == '__main__':
  159. asyncio.run(test())
  160. pass