优化同步问题
This commit is contained in:
@@ -13,12 +13,9 @@ district_facilitys_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'district_
|
||||
seaweed_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'seaweed')
|
||||
server_area_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'server_area')
|
||||
|
||||
city_dict = list(server_area_conn.find({'city_grade': {'$ne': 0}}, {'display': 1}))
|
||||
|
||||
# 医院code
|
||||
hospital_typecode = ["090100", "090101", "090200"]
|
||||
|
||||
log.info("开始执行周边医院配套入库")
|
||||
|
||||
def find_around_by_location(city, location):
|
||||
"""
|
||||
@@ -69,37 +66,46 @@ def find_around_by_location(city, location):
|
||||
print(e)
|
||||
return []
|
||||
|
||||
|
||||
def deal(city, lng, lat):
|
||||
location = [lng, lat]
|
||||
hospital_df = find_around_by_location(city, location)
|
||||
return hospital_df
|
||||
|
||||
for city_item in city_dict:
|
||||
city = city_item['display']
|
||||
log.info('开始查找' + city + '周边医院')
|
||||
seaweed_df = pd.DataFrame(list(seaweed_conn.find({'city': city, 'cat': 'district', 'status': 0, 'lng': {'$ne': None}},
|
||||
{'city': 1, 'region': 1, 'name': 1, 'lng': 1, 'lat': 1}).batch_size(10000)))
|
||||
if len(seaweed_df) <= 0:
|
||||
continue
|
||||
seaweed_df['lng'] = seaweed_df['lng'] / 10 ** 10
|
||||
seaweed_df['lat'] = seaweed_df['lat'] / 10 ** 10
|
||||
seaweed_df['hospital'] = seaweed_df.apply(lambda x: deal(x['city'], x['lng'], x['lat']), axis=1)
|
||||
|
||||
actions = list()
|
||||
log.info(city + '周边医院开始入库')
|
||||
for index, item in seaweed_df.iterrows():
|
||||
try:
|
||||
# 周边配套库中历史原因,id可能不为小区id
|
||||
action = UpdateOne({'city': item['city'], 'region': item['region'],
|
||||
'district_name': item['name']}, {'$set': {'hospital': item['hospital'], 'city': item['city'], 'region': item['region'],
|
||||
'district_name': item['name'], 'lng': item['lng'], 'lat': item['lat']}}, upsert=True)
|
||||
actions.append(action)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
if len(actions) == 5000:
|
||||
def do():
|
||||
log.info("开始执行周边医院配套入库")
|
||||
city_dict = list(server_area_conn.find({'city_grade': {'$ne': 0}}, {'display': 1}))
|
||||
for city_item in city_dict:
|
||||
city = city_item['display']
|
||||
log.info('开始查找' + city + '周边医院')
|
||||
seaweed_df = pd.DataFrame(
|
||||
list(seaweed_conn.find({'city': city, 'cat': 'district', 'status': 0, 'lng': {'$ne': None}},
|
||||
{'city': 1, 'region': 1, 'name': 1, 'lng': 1, 'lat': 1}).batch_size(10000)))
|
||||
if len(seaweed_df) <= 0:
|
||||
continue
|
||||
seaweed_df['lng'] = seaweed_df['lng'] / 10 ** 10
|
||||
seaweed_df['lat'] = seaweed_df['lat'] / 10 ** 10
|
||||
seaweed_df['hospital'] = seaweed_df.apply(lambda x: deal(x['city'], x['lng'], x['lat']), axis=1)
|
||||
|
||||
actions = list()
|
||||
log.info(city + '周边医院开始入库')
|
||||
for index, item in seaweed_df.iterrows():
|
||||
try:
|
||||
# 周边配套库中历史原因,id可能不为小区id
|
||||
action = UpdateOne({'city': item['city'], 'region': item['region'],
|
||||
'district_name': item['name']}, {
|
||||
'$set': {'hospital': item['hospital'], 'city': item['city'],
|
||||
'region': item['region'],
|
||||
'district_name': item['name'], 'lng': item['lng'], 'lat': item['lat']}},
|
||||
upsert=True)
|
||||
actions.append(action)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
if len(actions) == 5000:
|
||||
district_facilitys_conn.bulk_write(actions)
|
||||
actions.clear()
|
||||
if len(actions) > 0:
|
||||
district_facilitys_conn.bulk_write(actions)
|
||||
actions.clear()
|
||||
if len(actions) > 0:
|
||||
district_facilitys_conn.bulk_write(actions)
|
||||
actions.clear()
|
||||
log.info(city + '周边医院入库完毕')
|
||||
log.info(city + '周边医院入库完毕')
|
||||
|
||||
Reference in New Issue
Block a user