async def post(self): r_dict = {'code': 0} try: query_timestamp = self.i_args.get('query_timestamp', None) query_all = self.i_args.get('query_all', None) data_list = [] if query_all: subject_cursor = Subject.find(dict(record_flag=1)) else: if query_timestamp: query_timestamp = int(query_timestamp) else: query_timestamp = self.client_timestamp query_time = timestamp2datetime(query_timestamp) subject_cursor = Subject.find({ '$and': [ {"record_flag": 1}, {"updated_dt": {'$gte': query_time}}, ] }) while await subject_cursor.fetch_next: subject = subject_cursor.next_object() if subject: data = self.subject_2_dict(subject) if data: data_list.append(data) r_dict['code'] = 1000 r_dict['data_list'] = data_list except RuntimeError: r_dict['code'] = -1 logger.error(traceback.format_exc()) return r_dict
async def post(self): race_cid = self.get_argument('race_cid', '') r_dict = {'code': 0} try: if race_cid: refer_subject_list = [] exist_refer_subject_list = await RaceSubjectRefer.distinct('subject_cid', filtered={'race_cid': race_cid}) kw_name = self.get_argument('kw_name', '') kw_difficulty = self.get_argument('kw_difficulty', '') category_use = self.get_argument('category_use', '') query_params = {'status': STATUS_SUBJECT_ACTIVE, 'cid': {'$nin': exist_refer_subject_list}} subject_cursor = await Subject.find(filtered=query_params).to_list(None) if kw_name: query_params['$or'] = [ {"custom_code": {'$regex': kw_name, '$options': 'i'}}, {"title": {'$regex': kw_name, '$options': 'i'}}, {"code": {'$regex': kw_name, '$options': 'i'}} ] if kw_difficulty: query_params['difficulty'] = int(kw_difficulty) if category_use: query_params['category'] = int(category_use) subject_cursor = Subject.find(filtered=query_params) while await subject_cursor.fetch_next: subject = subject_cursor.next_object() if not subject: break refer_subject_list.append( RaceSubjectRefer( race_cid=race_cid, subject_cid=subject.cid, title=subject.title, status=subject.status, dimension_dict=subject.dimension_dict, created_dt=datetime.datetime.now(), created_id=self.current_user.oid ) ) if refer_subject_list: await RaceSubjectRefer.insert_many(refer_subject_list) r_dict['code'] = 1 else: r_dict['code'] = -1 except Exception: logger.error(traceback.format_exc()) return r_dict