def statistic_member_info(race_cid: str, province_code, yesterday): """ 会员信息导入,只根据race_mapping表中race_cid删选,没有过滤address为空的 :param race_cid: :return: """ city_code_list = AdministrativeDivision.sync_distinct( 'code', {'parent_code': province_code}) city_name_list = AdministrativeDivision.sync_distinct( 'title', {'parent_code': province_code}) district_name_list = AdministrativeDivision.sync_distinct( 'title', {'parent_code': { '$in': city_code_list }}) # race_member_match = {"race_cid": race_cid, 'record_flag': 1, 'auth_address.province': {'$ne': None}, # 'auth_address.city': {"$in": city_name_list}, # 'auth_address.district': {"$in": district_name_list}, # 'created_dt': {'$lte': datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)}} race_member_match = { "race_cid": race_cid, 'record_flag': 1, 'auth_address.province': { '$ne': None }, 'auth_address.city': { "$in": city_name_list }, 'auth_address.district': { "$in": district_name_list }, 'created_dt': { '$lte': yesterday } } match = {"race_cid": race_cid, 'record_flag': 1} # 当前活动参与会员 memberCidList = RaceMapping.sync_distinct("member_cid", race_member_match) memberCidList.sort() # 当前活动关卡cid checkPointList = RaceGameCheckPoint.sync_aggregate([MatchStage(match)]) checkPointMap = {} lastCheckPoint = None maxCheckPointIndex = 0 for check_point in checkPointList: checkPointMap[check_point.cid] = check_point.alias if check_point.index > maxCheckPointIndex: maxCheckPointIndex = check_point.index lastCheckPoint = check_point.cid checkPointCidList = list(checkPointMap.keys()) # print("该活动下的会员", len(memberCidList), memberCidList) # print("该活动下的会员数", len(set(memberCidList))) # print("该活动下的关卡", len(checkPointCidList), checkPointCidList) temp_list = splitList(memberCidList, 2000) threads = [] thread_num = 1 for my_list in temp_list: # print(my_list) t = MyThread(get_member_info, args=(thread_num, my_list, race_cid, checkPointCidList, lastCheckPoint, checkPointMap)) threads.append(t) t.start() thread_num += 1 results = [] for each_thread in threads: each_thread.join() result = each_thread.get_result() if len(result) > 0: results.extend(result) return results
Member, RedPacketAwardHistory, RedPacketLotteryHistory, RaceGameCheckPoint from motorengine import ASC from motorengine.stages import MatchStage, SortStage STATUS_REDPACKET_AWARDED = 0 # 已被领取 STATUS_REDPACKET_NOT_AWARDED = 1 # 还没有被领取 STATUS_REDPACKET_AWARDING = 2 # 奖励发放 STATUS_REDPACKET_AWARD_FAILED = 5 # 领取失败 # 活动 race_title = '2019扬州市迎新春科学素质大擂台' race = Race.sync_find_one({'title': race_title}) # 关卡 checkpoint_list = RaceGameCheckPoint.sync_aggregate([ MatchStage({'race_cid': race.cid}), SortStage([('index', ASC)]) ]).to_list(None) last_ck = checkpoint_list[-1] # 红包规则 rule = RedPacketRule.sync_find_one({'race_cid': race.cid}) if not rule: rule = RedPacketRule() rule.code = 'rule01' rule.title = 'rule01' rule.status = STATUS_ACTIVE rule.race_cid = race.cid rule.category = CATEGORY_REDPACKET_RULE_LOTTERY rule_oid = rule.sync_save()