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. all_client = get_all_client()
  11. hbase_client = all_client.get_hbase_client()
  12. es_sdk = get_es_sdk("new")
  13. def get_latest_date(index: str, company_id_f: str, company_id: str, latest_date_f: str):
  14. dsl = {
  15. "size": 1,
  16. "_source": [latest_date_f],
  17. "query": {
  18. "term": {
  19. company_id_f: {
  20. "value": company_id
  21. }
  22. }
  23. }
  24. , "sort": [
  25. {
  26. latest_date_f: {
  27. "order": "desc"
  28. }
  29. }
  30. ]
  31. }
  32. res = es_sdk.query(index=index, doc_type='_doc', dsl=dsl)
  33. if len(res) == 0:
  34. return None
  35. return res[0][latest_date_f]
  36. pass
  37. latest_date_map = get_latest_date_map()
  38. def search_latest_date(company_id: str):
  39. result_data = {}
  40. for i in latest_date_map:
  41. str = latest_date_map[i]
  42. max_date = ''
  43. for j in str.split(','):
  44. tmp_str = j.split(':')
  45. index = tmp_str[0]
  46. company_id_f = tmp_str[1]
  47. latest_date_f = tmp_str[2]
  48. tmp_date = get_latest_date(index=index, company_id_f=company_id_f, company_id=company_id,
  49. latest_date_f=latest_date_f)
  50. max_date = max(max_date, tmp_date)
  51. pass
  52. result_data[i] = max_date
  53. pass
  54. tmp_res = hbase_client.get_record('ng_company', company_id)
  55. if 'APPROVED_TIME' in tmp_res:
  56. result_data['基本信息'] = tmp_res['APPROVED_TIME']
  57. return result_data
  58. pass
  59. if __name__ == '__main__':
  60. # d = get_latest_date(index='winhc_index_rt_company_punishment_info', company_id_f='company_id',
  61. # company_id='059f83641cc4df8b9577cb1e2d89939e', latest_date_f='decision_date')
  62. # print(d)
  63. d = search_latest_date(company_id='059f83641cc4df8b9577cb1e2d89939e')
  64. print(map_2_json_str(d))
  65. pass