Esempio n. 1
0
def query_users():
    """
    查询用户列表
    :return: 
    """
    request_params = loadParams()
    if request_params.has_key('userId'):
        userId = request_params['userId']
        if userId == '-1':
            data = BaseDao.query(User, type=1)
        else:
            data = BaseDao.query(User, text('id="' + userId + '"'), type=0)
    return parseResponse(0, {"userlist": data})
Esempio n. 2
0
def upload_avator():
    # 上传的头像字段为 img
    # 表单参数: token
   try:
       file: FileStorage = request.files.get('img', None)
       token = request.args.get('token', None)

       if all((bool(file), bool(token))):
           # 验证文件的类型, png/jpeg/jpg, 单张不能超过2M
           # content-type: image/png, image/jpeg
           if file.content_type in ('image/png',
                                    'image/jpeg'):
               filename = uuid.uuid4().hex \
                          + os.path.splitext(file.filename)[-1]
               file.save(filename)

               # 上传到oss云服务器上
               key = oss.upload_file(filename)

               os.remove(filename)  # 删除临时文件

               # token = request.args.get('token')
               # 将key写入到DB中
               id = get_token_user_id(token)

               sql = "update yl_user set photo=(%s) where id=%s"
               db = BaseDao()
               db.query(sql, key, id)

               return jsonify({
                   'code': 200,
                   'msg': '上传文件成功',
                   'file_key': key
               })
           else:
               return jsonify({
                   'code': 201,
                   'msg': '图片格式只支持png或jpeg'
               })

       return jsonify({
           'code': 100,
           'msg': 'POST请求参数必须有img和token'
       })
   except:
       return jsonify({
           "code":400,
           "msg":"更换头像失败"
       })
Esempio n. 3
0
def queryTaskStatusByTaskJobId():
    params = loadParams()
    taskJobId = params["taskJobId"]
    data = BaseDao.query(TaskStatusInfoField, text('task_job_id="'+taskJobId+'"'))
    json = stringify(data).encode("utf8")
    # WebSocket.sendMessage("{'action':'queryTaskStatusByTaskJobId','data':" + json + ",'returnCode':'0','returnMsg':'SUCCESS'}")
    return parseResponse(0, {"data": data})
Esempio n. 4
0
def queryTortDate():
    # params = loadParams()
    # periodType = params["periodType"]
    data = BaseDao.query(TortReInfoField)
    # 制造动态假数据begin
    if data:
        for d in data:
            if isinstance(d, TortReInfoField):
                value = RandomUtil.random(0, 50)
                d.totalCnt += value
    # 制造动态假数据end
    json = stringify(data).encode("utf8")
    # WebSocket.sendMessage( "{'action':'queryTortDate','data':" + json + ",'returnCode':'0','returnMsg':'SUCCESS'}")
    return parseResponse(0, {"data": data})
Esempio n. 5
0
def get_img_url():
    try:
        token = request.args.get('token')
        id = get_token_user_id(token)
        sql = "select photo from yl_user where id=%s"
        db = BaseDao()
        key = db.query(sql, id)[0]['photo']
        img_url = oss.get_small_url(key)
        return jsonify({
            "code": 400,
            'url': img_url
        })
    except:
        return jsonify({
            "code":400,
            "msg":"获取失败"
        })