123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- # -*- coding: utf-8 -*-
- # @Time : 2022/12/1 9:13
- # @Author : XuJiakai
- # @File : search_winhc_latest_date
- # @Software: PyCharm
- from sdk import get_es_sdk
- from utils import map_2_json_str
- from utils.dim_name_mapping import get_latest_date_map
- from sdk.WinhcAllClient import get_all_client
- from utils.base_utils import tuple_max
- all_client = get_all_client()
- hbase_client = all_client.get_hbase_client()
- es_sdk = get_es_sdk("new")
- old_es_sdk = get_es_sdk("old")
- old_es_index = ['wenshu_detail2']
- def get_latest_date(index: str, company_id_f: str, company_id: str, latest_date_f: str):
- dsl = {
- "size": 1,
- "_source": [latest_date_f],
- "query": {
- "bool": {
- "must": [
- {
- "term": {
- company_id_f: {
- "value": company_id
- }
- }
- },
- # {
- # "term": {
- # "deleted": {
- # "value": 0
- # }
- # }
- # }
- ]
- }
- }
- , "sort": [
- {
- latest_date_f: {
- "order": "desc"
- }
- }
- ]
- }
- if index in old_es_index:
- res = old_es_sdk.query(index=index, doc_type=None, dsl=dsl)
- pass
- else:
- res = es_sdk.query(index=index, doc_type='_doc', dsl=dsl)
- if len(res) == 0:
- return None
- return res[0][latest_date_f]
- pass
- latest_date_map = get_latest_date_map()
- def search_latest_date(company_id: str):
- result_data = {}
- for i in latest_date_map:
- str = latest_date_map[i]
- max_date = None
- for j in str.split(','):
- tmp_str = j.split(':')
- index = tmp_str[0]
- company_id_f = tmp_str[1]
- latest_date_f = tmp_str[2]
- tmp_date = get_latest_date(index=index, company_id_f=company_id_f, company_id=company_id,
- latest_date_f=latest_date_f)
- max_date = tuple_max(max_date, tmp_date)
- pass
- result_data[i] = max_date
- pass
- tmp_res = hbase_client.get_record('ng_company', company_id)
- if tmp_res is not None and 'APPROVED_TIME' in tmp_res:
- result_data['基本信息'] = tmp_res['APPROVED_TIME']
- else:
- result_data['基本信息'] = None
- return result_data
- pass
- if __name__ == '__main__':
- # d = get_latest_date(index='winhc_index_rt_company_punishment_info', company_id_f='company_id',
- # company_id='059f83641cc4df8b9577cb1e2d89939e', latest_date_f='decision_date')
- # print(d)
- d = search_latest_date(company_id='eda3ee85ad34656bd45bc587b21b6c26')
- print(map_2_json_str(d))
- pass
|