Exemple #1
0
async def zxb_list(
        collection: str,
        page: Optional[int] = 1,
        page_size: Optional[int] = 10,
        mgo_collections=Depends(deps.get_mgo_collections)):
    if collection not in mgo_collections:
        return response_code.resp_4001(message=f'{collection} not support')
    records = []
    query = {}
    count = await mgo_collections[collection].count_documents(query)
    pages = math.ceil(count/page_size)
    out_fields = {
        '_id': 0
    }
    cursor = mgo_collections[collection].\
        find(query, out_fields).\
        skip((page-1) * page_size).\
        limit(page_size)
    async for rec in cursor:
        records.append(rec)
    data = {
        'totalCount': count,
        'totalPage': pages,
        'list': records
    }
    return response_code.resp_200(data=data)
Exemple #2
0
async def callback(
        click_id: str,
        idfa: Optional[str] = ''
):
    return response_code.resp_200(data={
        'click_id': click_id,
        'idfa': idfa
    })
Exemple #3
0
async def login(username: str,
                password: str,
                mgo_collections=Depends(deps.get_mgo_collections)):
    query = {'username': username, 'password': password}
    count = await mgo_collections[settings.USER_COLLECTION
                                  ].count_documents(query)
    data = {'token': md5(), 'count': count}
    return response_code.resp_200(data=data)
Exemple #4
0
async def read_course_id(collection: str,
                         course_id: int,
                         mgo_collections=Depends(deps.get_mgo_collections)):
    if collection not in mgo_collections:
        return response_code.resp_4001(message=f'{collection} not support')
    rec = await mgo_collections[collection].find_one({'id': course_id},
                                                     {'_id': 0})
    return response_code.resp_200(data=rec)
Exemple #5
0
async def zxb_company(
        collection: str,
        company_id: int,
        mgo_collections=Depends(deps.get_mgo_collections)):
    if collection not in mgo_collections:
        return response_code.resp_4001(message=f'{collection} not support')
    query = {'companyId': company_id}
    rec = await mgo_collections[collection].find_one(query, {'_id': 0})
    return response_code.resp_200(data=rec)
Exemple #6
0
async def company(collection: str,
                  company_id: int,
                  check_status: Optional[int] = 0,
                  mgo_collections=Depends(deps.get_mgo_collections)):
    if collection not in mgo_collections:
        return response_code.resp_4001(message=f'{collection} not support')
    query = {'companyId': company_id}
    if check_status == 0:
        # 默认查找
        rec = await mgo_collections[collection].find_one(query, {'_id': 0})
        return response_code.resp_200(data=rec)
    # 更新
    update = {'$set': {'check_status': check_status}}
    res = await mgo_collections[collection].update_one(query, update)
    if res.raw_result['nModified'] > 0:
        message = 'update success'
    else:
        message = 'nothing updated, nModified is the update rec count'
    return response_code.resp_200(message=message, data=res.raw_result)
Exemple #7
0
async def click(
        channel_id: str,
        call_back_url: str,
        idfa: Optional[str] = ''
):
    return response_code.resp_200(data={
        'channelId': channel_id,
        'callBackUrl': call_back_url,
        'idfa': idfa
    })
Exemple #8
0
async def aggregate(collection: str,
                    fields: str,
                    mgo_collections=Depends(deps.get_mgo_collections)):
    if collection not in mgo_collections:
        return response_code.resp_4001(message=f'{collection} not support')
    splits = fields.split(',')
    dic = {}
    for field in splits:
        field = field.strip()
        dic[field] = f'${field}'
    group_dic = {'$group': {'_id': dic, 'count': {'$sum': 1}}}
    rec = await mgo_collections[collection].aggregate([group_dic])
    return response_code.resp_200(data=rec)
Exemple #9
0
async def read_course_list(collection: str,
                           page: Optional[int] = 1,
                           page_size: Optional[int] = 10,
                           mgo_collections=Depends(deps.get_mgo_collections)):
    if collection not in mgo_collections:
        return response_code.resp_4001(message=f'{collection} not support')
    records = []
    cursor = mgo_collections[collection].\
        find({}, {'_id': 0, 'id': 1}).\
        skip((page-1) * page_size).\
        limit(page_size)
    async for rec in cursor:
        records.append(rec['id'])
    return response_code.resp_200(data=records)
Exemple #10
0
def cmcc_search(mobile: Optional[int] = 0,
                name: Optional[str] = '',
                cert_id: Optional[str] = '',
                es=Depends(deps.get_es)):
    condition = {}
    if mobile > 0:
        condition['mobile'] = mobile
    if len(name) > 0:
        condition['name'] = name
    if len(cert_id) > 0:
        condition['cert_id'] = cert_id
    query = {'query': {'term': condition}}
    res = es.search(index=settings.CMCC_ES_INDEX, body=query)
    num = res['hits']['total']['value']
    if num > 0:
        data = res['hits']['hits'][0]['_source']
    else:
        data = None
    return response_code.resp_200(data=data)
Exemple #11
0
async def company_list(collection: str,
                       province: Optional[str] = '',
                       city: Optional[str] = '',
                       page: Optional[int] = 1,
                       page_size: Optional[int] = 10,
                       check_status: Optional[int] = 0,
                       mgo_collections=Depends(deps.get_mgo_collections)):
    if collection not in mgo_collections:
        return response_code.resp_4001(message=f'{collection} not support')
    records = []
    query = {}
    if len(province) > 0:
        query['province'] = province
    if len(city) > 0:
        query['city'] = city
    if check_status == 0:
        query['check_status'] = {'$exists': False}
    else:
        query['check_status'] = check_status
    count = await mgo_collections[collection].count_documents(query)
    pages = math.ceil(count / page_size)
    out_fields = {
        '_id': 0,
        'companyId': 1,
        'name': 1,
        'province': 1,
        'city': 1,
        'address': 1,
        'establishTime': 1,
        'legalPersonName': 1,
        'regCapital': 1,
        'regCapitalCurrency': 1
    }
    cursor = mgo_collections[collection].\
        find(query, out_fields).\
        skip((page-1) * page_size).\
        limit(page_size)
    async for rec in cursor:
        records.append(rec)
    data = {'totalCount': count, 'totalPage': pages, 'list': records}
    return response_code.resp_200(data=data)
Exemple #12
0
async def mobile_location(mobile: int,
                          mgo_collections=Depends(deps.get_mgo_collections)):
    prefix = int(mobile / 10000) if mobile > 1999999 else mobile
    rec = await mgo_collections[settings.MOBILE_PREFIX_COLLECTION
                                ].find_one({'prefix': prefix}, {'_id': 0})
    return response_code.resp_200(data=rec)