search_winhc_latest_date.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # -*- coding: utf-8 -*-
  2. # @Time : 2022/12/1 9:13
  3. # @Author : XuJiakai
  4. # @File : search_winhc_latest_date
  5. # @Software: PyCharm
  6. from sdk import get_es_sdk
  7. from utils import map_2_json_str
  8. from utils.dim_name_mapping import get_latest_date_map
  9. from sdk.WinhcAllClient import get_all_client
  10. from utils.base_utils import tuple_max
  11. all_client = get_all_client()
  12. hbase_client = all_client.get_hbase_client()
  13. es_sdk = get_es_sdk("new")
  14. def get_latest_date(index: str, company_id_f: str, company_id: str, latest_date_f: str):
  15. dsl = {
  16. "size": 1,
  17. "_source": [latest_date_f],
  18. "query": {
  19. "term": {
  20. company_id_f: {
  21. "value": company_id
  22. }
  23. }
  24. }
  25. , "sort": [
  26. {
  27. latest_date_f: {
  28. "order": "desc"
  29. }
  30. }
  31. ]
  32. }
  33. res = es_sdk.query(index=index, doc_type='_doc', dsl=dsl)
  34. if len(res) == 0:
  35. return None
  36. return res[0][latest_date_f]
  37. pass
  38. latest_date_map = get_latest_date_map()
  39. def search_latest_date(company_id: str):
  40. result_data = {}
  41. for i in latest_date_map:
  42. str = latest_date_map[i]
  43. max_date = ''
  44. for j in str.split(','):
  45. tmp_str = j.split(':')
  46. index = tmp_str[0]
  47. company_id_f = tmp_str[1]
  48. latest_date_f = tmp_str[2]
  49. tmp_date = get_latest_date(index=index, company_id_f=company_id_f, company_id=company_id,
  50. latest_date_f=latest_date_f)
  51. max_date = tuple_max(max_date, tmp_date)
  52. pass
  53. result_data[i] = max_date
  54. pass
  55. tmp_res = hbase_client.get_record('ng_company', company_id)
  56. if tmp_res is not None and 'APPROVED_TIME' in tmp_res:
  57. result_data['基本信息'] = tmp_res['APPROVED_TIME']
  58. return result_data
  59. pass
  60. if __name__ == '__main__':
  61. # d = get_latest_date(index='winhc_index_rt_company_punishment_info', company_id_f='company_id',
  62. # company_id='059f83641cc4df8b9577cb1e2d89939e', latest_date_f='decision_date')
  63. # print(d)
  64. d = search_latest_date(company_id='059f83641cc4df8b9577cb1e2d89939e')
  65. print(map_2_json_str(d))
  66. pass