Esempio n. 1
0
    async def _verify_choice_rules(self, race_cid=None):
        """
        检查抽题规则是否正确
        :param race_cid:
        :return:
        """
        try:
            rules_cids = list()
            query_dict = {
                'race_cid': race_cid,
                'status': STATUS_SUBJECT_CHOICE_RULE_ACTIVE,
                'dimension_rules': {
                    '$ne': {}
                }
            }
            if await self._verify_check_point(race_cid):
                # 如果关卡存在,则查找关卡关联的抽题规则是否正确
                point_cursor = RaceGameCheckPoint.find({
                    'race_cid':
                    race_cid,
                    'status':
                    STATUS_GAME_CHECK_POINT_ACTIVE
                })
                while await point_cursor.fetch_next:
                    point = point_cursor.next_object()
                    if point and point.rule_cid:
                        rules_cids.append(point.rule_cid)

                    query_dict['cid'] = {'$in': rules_cids}

            rules_cids = set(rules_cids)  # 去重
            rules_count = await RaceSubjectChoiceRules.count(query_dict)
            if 'cid' in query_dict.keys():
                if rules_count == len(rules_cids):
                    return True
            else:
                if rules_count > 0:
                    return True

            return False

        except:
            logger.error(traceback.format_exc())
            return False
Esempio n. 2
0
async def do_copy_checkpoint(race_cid, new_race_cid, user_cid):
    """
    复制关卡
    :param race_cid:
    :param new_race_cid:
    :param user_cid:
    :return:
    """

    if not race_cid or not new_race_cid or not user_cid:
        raise Exception('miss parameters')

    old_checkpoint_cursor = RaceGameCheckPoint.find(
        {
            'race_cid': race_cid
        }, read_preference=ReadPreference.PRIMARY).batch_size(32)

    rule_map = json.loads(
        RedisCache.get(KEY_CACHE_RACE_COPY_MAP + race_cid + '_rule_copy'))
    red_packet_map = json.loads(
        RedisCache.get(KEY_CACHE_RACE_COPY_MAP + race_cid +
                       '_red_packet_rule_copy'))
    new_checkpoint_list = []
    checkpoint_map = {}
    while await old_checkpoint_cursor.fetch_next:
        checkpoint = old_checkpoint_cursor.next_object()
        new_checkpoint = copy.deepcopy(checkpoint)
        new_checkpoint.cid = get_new_cid()
        new_checkpoint.race_cid = new_race_cid
        new_checkpoint.rule_cid = rule_map[checkpoint.rule_cid]
        new_checkpoint.redpkt_rule_cid = red_packet_map[
            checkpoint.redpkt_rule_cid] if checkpoint.redpkt_rule_cid else ''
        new_checkpoint.updated_id = user_cid
        checkpoint_map[checkpoint.cid] = new_checkpoint.cid
        new_checkpoint_list.append(new_checkpoint)
    RedisCache.set(KEY_CACHE_RACE_COPY_MAP + race_cid + '_checkpoint_copy',
                   json.dumps(checkpoint_map))
    await RaceGameCheckPoint.insert_many(new_checkpoint_list)