Ejemplo n.º 1
0
def commentsGet():
    rules = {
        'pageNo': {
            'required': True,
            'type': 'integer'
        },
        'pageSize': {
            'required': True,
            'type': 'integer'
        }
    }
    error_msg = {
        'pageNo': {
            'required': u'当前页是必须的',
            'type': u'当前页必须是整数'
        },
        'pageSize': {
            'required': u'当前页是必须的',
            'type': u'当前页必须是整数'
        }
    }
    error = BaseController().validateInput(rules, error_msg)
    if (error is not True):
        return error
    pageNo = request.json.get('pageNo')
    pageSize = request.json.get('pageSize')
    data = Comments().getCommentsList(pageNo, pageSize)
    return BaseController().json(data)
Ejemplo n.º 2
0
def register():
    """ 注册 """
    oa_account = request.json.get('account')
    password = request.json.get('password')
    name = request.json.get('name')
    filters = {User.oa_account == oa_account}
    user_data = User().getOne(filters)
    if user_data is None:
        create_time = int(time.time())
        user = User(
            oa_account=oa_account,
            password=User.set_password(password),
            name=name,
            status=1,
            created_time=create_time,
            role_id='auditor',
        )
        status = user.add(user)
        if status:
            return BaseController().successData(result={'name': name},
                                                msg='注册成功')
        return BaseController().error('注册失败')
    # else:
    #     user = User.get(user_data['id'])
    #     create_time = int(time.time())
    #     User().update(user, oa_account, User.set_password(oa_password), company, 1, create_time, 'admin', '管理员',
    #                   create_time, 'default', 1)
    return BaseController().error('账号已注册')
Ejemplo n.º 3
0
def isExistedFile():
    dir_list = os.listdir(os.path.join('template', 'imp', 'exp_files'))
    if len(dir_list) > 0:
        return BaseController().successData(result='存在' if os.path.exists(
            os.path.join('template', 'imp', 'exp_files', dir_list[-1],
                         '智慧风电数据.zip')) else '不存在')
    else:
        return BaseController().successData(result='不存在')
Ejemplo n.º 4
0
def getInfo():
    token = request.args.get("token")
    if not token:
        return BaseController().error(msg='token为空')
    filters = {User.remember_token == token}
    field = ('id', 'name', 'oa_account', 'status', 'last_login_time', 'last_login_ip', 'created_time', 'deleted', 'role_id')
    user_info = User().getOne(filters=filters, field=field)
    if not user_info:
        return BaseController().error(msg='查询失败')
    return BaseController().successData(result=user_info, msg='获取成功')
Ejemplo n.º 5
0
def logout():
    token = request.json.get('token')
    updated_at = int(time.time())
    if not token:
        return BaseController().error(msg='token为空')
    user = User().getOne(filters={User.remember_token == token})
    if not user:
        return BaseController().error(msg='查询失败')
    User.update(user['id'], remember_token='')
    return BaseController().successData(msg='登出成功')
Ejemplo n.º 6
0
def groupChatCreate(user_info, params):
    # 加入房间号
    data = ChatService().groupChatCreate(user_info, params)
    if data:
        #添加后同步房间
        user_room_relation_data = Utils.db_l_to_d(UserRoomRelation.get(data['room_uuid']))
        for item in user_room_relation_data:
            roomList = UserRoomRelation.getRoomList(item['user_id'])['data']
            socketio.emit('groupRoom', Utils.formatBody(roomList), namespace='/room', room='@broadcast.'+str(item['user_id']))
        return BaseController().successData(data, msg='创建成功')
    return BaseController().error(msg='创建失败')
Ejemplo n.º 7
0
def documentUpload():
    """ 上传文件并验证
    https://zhuanlan.zhihu.com/p/23731819?refer=flask
    """
    files = request.files['document']
    filename = secure_filename(files.filename)
    if (files and Utils.allowed_file(filename)):
        path = os.getcwd() + "/uploads/" + filename
        files.save(path)
        return BaseController().error('你成功走通了')
    return BaseController().error('文件类型错误')
Ejemplo n.º 8
0
def register(params):
    ''' 注册 '''
    filters = {Users.email == params['email']}
    userData = Users().getOne(filters)
    if (userData == None):
        user = Users(email=params['email'],
                     password=Users.set_password(params['password']),
                     status=1)
        status = user.add(user)
        if status == True:
            return BaseController().successData(msg='注册成功')
        return BaseController().error('注册失败')
    return BaseController().error('账号已注册')
Ejemplo n.º 9
0
def upload():
    f = request.files['file']
    filename = secure_filename(f.filename)
    if (f and Utils.allowed_file(filename)):
        file_suffix = f.filename.split('.')[1]
        path = UPLOAD_FOLDER + Utils.unique_id() + '.' + file_suffix
        full_path = os.getcwd() + path
        f.save(full_path)
        return BaseController().successData(data={
            'path': path,
            'name': f.filename
        },
                                            msg='图片提交成功')
    return BaseController().error('文件类型不允许')
Ejemplo n.º 10
0
def addressBookBeg(params):
    if params['focused_user_id'] == params['be_focused_user_id']:
        return BaseController().error(msg='无法添加自己为新朋友')
    addressBookdata = AddressBook.getAdddressBookByFocusedUserId(params['focused_user_id'], params['be_focused_user_id'])
    if addressBookdata != None:
        return BaseController().error(msg='已添加')
    msg_uuid = Utils.unique_id()
    userData = Users().getOne({Users.id == params['focused_user_id']})
    socketio.emit('beg', Utils.formatBody({
        'data':userData, 
        'action':'beg_add', 
        'msg_uuid': msg_uuid, 
        'be_focused_user_id': params['be_focused_user_id']
    }), namespace='/room', room='@broadcast.'+str(params['be_focused_user_id']), callback=success)
    return BaseController().successData(msg='发送成功')
Ejemplo n.º 11
0
def userRoomRelationUpdateAlert(params, user_info):
    """ 更新对否提醒 """
    filters = {
        Room.room_uuid == params['room_uuid']
    }
    roomData = Room().getOne(filters)
    if roomData['type'] == 0:
        filters = {
            AddressBook.room_uuid == params['room_uuid'],
            AddressBook.be_focused_user_id == user_info['data']['id']
        }
        data = {
            'is_alert': params['is_alert']
        }
        status = AddressBook().edit(data, filters)
    else:
        filters = {
            UserRoomRelation.room_uuid == params['room_uuid'],
            UserRoomRelation.user_id == user_info['data']['id']
        }
        data = {
            'is_alert': params['is_alert']
        }
        status = UserRoomRelation().edit(data, filters)
    if status:
        return BaseController().successData()
Ejemplo n.º 12
0
def userRoomRelationGetByRoomUuid(params, user_info):
    """ 获取群组或单聊信息 """
    filters = {
        Room.room_uuid == params['room_uuid']
    }
    roomData = Room().getOne(filters)
    if roomData['type'] == 0:
        filters = {
            AddressBook.room_uuid == params['room_uuid']
        }
        data = AddressBook().getList( filters, AddressBook.updated_at.desc())
        filters.add(
            AddressBook.be_focused_user_id == user_info['data']['id']
        )
        data['room'] = AddressBook().getOne( filters)
    else:
        filters = {
            UserRoomRelation.room_uuid == params['room_uuid']
        }
        data = UserRoomRelation().getList( filters, UserRoomRelation.updated_at.desc())
        filters.add(
            UserRoomRelation.user_id == user_info['data']['id']
        )
        data['room'] = UserRoomRelation().getOne( filters)
    return BaseController().successData(data)
Ejemplo n.º 13
0
def userRoomRelationGet(user_info):
    """ 获取通讯录列表 """
    filters = {
        UserRoomRelation.user_id == user_info['data']['id']
    }
    data = UserRoomRelation().getAll(filters, 'updated_at desc')
    return BaseController().successData(data)
Ejemplo n.º 14
0
def get_gp_plans():
    """
    自动化对发电量计划进行读取
    """
    gpplan = pd.read_excel(
        r"C:\Users\admin\Desktop\1报表文件夹\日报表\2020年\山东分公司2020年发电量计划(2020.5调整版).xlsx",
        usecols=range(14),
        skiprows=range(1))
    gpplan.fillna(0)
    print(gpplan)
    year = 2020
    for x in range(40):
        if gpplan.loc[x].values[0] == '合计':
            break
        if gpplan.loc[x].values[0] == '石桥一期':
            for col_num in range(1, 13):
                gpp = GpPlan(year=year,
                             month=col_num,
                             num=1,
                             plan_gp=int(gpplan.loc[x].values[col_num]))
                GpPlan().add(gpp)
        if gpplan.loc[x].values[0] == '石桥二期':
            for col_num in range(1, 13):
                gpp = GpPlan(year=year,
                             month=col_num,
                             num=2,
                             plan_gp=int(gpplan.loc[x].values[col_num]))
                GpPlan().add(gpp)
    return BaseController().successData(msg='读取并写入成功!')
Ejemplo n.º 15
0
def roomDel(user_info, params):
    filters = {
        Room.room_uuid == params['room_uuid']
    }
    roomData = Room().getOne(filters)
    if roomData['type'] == 0:
        filters = {
            AddressBook.room_uuid == params['room_uuid']
        }
        AddressBook().delete(filters)
        filters = {
            Room.room_uuid == params['room_uuid']
        }
        Room().delete(filters)
    else:
        filters = {
            UserRoomRelation.room_uuid == params['room_uuid'],
            UserRoomRelation.user_id == params['user_id']
        }
        data = UserRoomRelation().delete(filters)
        filters = {
            Room.room_uuid == params['room_uuid'],
            Room.user_id == params['user_id']
        }
        Room().delete(filters)

    return BaseController().successData()
Ejemplo n.º 16
0
def login():
    oa_account = request.json.get('account')
    password = request.json.get('password')
    if not oa_account or not password:
        return BaseController().error('账号和密码不能为空')
    else:
        result = UsersAuthJWT.authenticate(oa_account, password)
        return result
Ejemplo n.º 17
0
def index():
    """ 测试 """
    Log().add({
        "type": 1,
        "level": 1,
        "data": "1"
    })
    return BaseController().successData(msg='启动成功')
Ejemplo n.º 18
0
def get_firms_today():
    parms = request.get_json() or ''
    filters = {}
    if parms:
        filters = {Gzp.firm.contains(parms['value'])}
    resList = Gzp().getFirmList(filters)
    if not len(resList):
        resList.append(parms['value'])
    return BaseController().successData(result=resList)
Ejemplo n.º 19
0
def addRoomMsg(user_info, params):
    """ 
        添加聊天数据
        :param dict user_info
        :param dict params
        :return dict 
    """
    Msg().add(params)
    return BaseController().successData()
Ejemplo n.º 20
0
def login():
    ''' 登录 '''
    email = request.json.get('email')
    password = request.json.get('password')
    if (not email or not password):
        return BaseController().error('用户名和密码不能为空')
    else:
        result = UsersAuthJWT.authenticate(email, password)
        return result
Ejemplo n.º 21
0
def submitGzpform():
    form = request.get_json() or ''
    df = pd.read_excel(os.getcwd() + r'\template\风机检修工作票模板.xls', header=None)
    wb = xlrd.open_workbook(os.getcwd() + r'\template\风机检修工作票模板.xls',
                            formatting_info=True)
    ws = wb.sheet_by_index(0)

    # 格式设定
    # 设置字体
    font = xlwt.Font()
    # 字体类型
    font.name = '宋体'
    # 字体大小,11为字号,20为衡量单位
    font.height = 20 * 9
    # 设置单元格对齐方式
    alignment_center = xlwt.Alignment()
    alignment_left = xlwt.Alignment()
    # 0x01(左端对齐)、0x02(水平方向上居中对齐)、0x03(右端对齐)
    alignment_center.horz = 0x02
    alignment_left.horz = 0x01
    # 设置边框
    borders = xlwt.Borders()
    borders.bottom = 1

    # 样式1
    style0 = xlwt.XFStyle()
    style0.font = font
    style0.alignment = alignment_center
    style0.borders = borders

    # 样式2 左对齐
    style1 = xlwt.XFStyle()
    style1.font = font
    style1.borders = borders
    style1.alignment = alignment_left

    # 复制
    new_wb = copy(wb)
    new_ws = new_wb.get_sheet(0)

    # 写入
    new_ws.write(2, 13, 'FJGZ-SD-SQ-' + form['gzpId'], style0)
    new_ws.write(2, 1, form['firm']['key'], style0)
    new_ws.write(4, 11, form['group'], style0)
    new_ws.write(4, 4, form['manager']['key'], style0)
    if len(form['members']) > 1:
        new_ws.write(
            7, 0,
            reduce(lambda x, y: x + '、' + y,
                   map(lambda x: x['key'], form['members'])), style1)
    else:
        new_ws.write(7, 0, form['members']['key'], style1)
    new_ws.write(7, 16, len(form['members']) + 1, style0)
    new_ws.write(
        14, 0, '机组' + form['terminalWt'] + '/' + '机组' + form['terminalPower'])
    new_wb.save(os.getcwd() + r'\template\风机检修工作票模板1.xls')
    return BaseController().successData(msg='成功')
Ejemplo n.º 22
0
def get():
    '''
    *获取用户信息 
    *jwt中修改error处理方法,统一响应头
    *_default_jwt_error_handler
    '''
    result = UsersAuthJWT().identify(request)
    if isinstance(result, str):
        return BaseController().error(result)
    if (result['data']):
        user = Users.get(result['data']['id'])
        returnUser = {
            'id': user.id,
            'name': user.name,
            'email': user.email,
            'login_time': user.updated_at
        }
        return BaseController().successData(returnUser)
    return BaseController().error('未找到用户')
Ejemplo n.º 23
0
def imgSwitch():
    """ 接收图片uuid并转换成图片 """
    rules = {'uuid': {'required': True, 'type': 'string'}}
    error_msg = {'uuid': {'required': u'唯一id是必须的', 'type': u'唯一id必须是字符串'}}
    error = BaseController().validateInput(rules, error_msg)
    if (error is not True):
        return error
    uuid = request.json.get('uuid')
    data = ImgShard.getData(uuid)
    base64Data = ''
    for i in data:
        base64Data = base64Data + i['imgString']
    userImg = base64Data.split(',')[1]
    imgdata = base64.b64decode(userImg)
    rela_path = "/uploads/" + Utils.unique_id() + '.jpg'
    path = os.getcwd() + rela_path
    file = open(path, 'wb')
    file.write(imgdata)
    file.close()
    return BaseController().successData(data={"url": rela_path}, msg='图片提交成功')
Ejemplo n.º 24
0
def addUser():
    name = request.json.get('name')
    oa_account = request.json.get('oa_account')
    company = request.json.get('company')
    new_user = User()
    new_user.name = name
    new_user.oa_account = oa_account
    new_user.company = company
    new_user.status = 0
    User().add(new_user)
    return BaseController().successData(msg='用户增加成功')
Ejemplo n.º 25
0
def imgShard():
    """ 接收图片分片数据并存入数据库 """
    rules = {
        'index': {
            'required': True,
            'type': 'integer'
        },
        'uuid': {
            'required': True,
            'type': 'string'
        },
        'imgString': {
            'required': True,
            'type': 'string'
        }
    }
    error_msg = {
        'index': {
            'required': u'图片索引是必须的',
            'type': u'图片索引必须是字符串'
        },
        'uuid': {
            'required': u'唯一id是必须的',
            'type': u'唯一id必须是字符串'
        },
        'imgString': {
            'required': u'当前页是必须的',
            'type': u'当前页必须是字符串'
        }
    }
    error = BaseController().validateInput(rules, error_msg)
    if (error is not True):
        return error
    index = request.json.get('index')
    uuid = request.json.get('uuid')
    imgString = request.json.get('imgString')
    data = ImgShard.add(index, uuid, imgString)
    if data:
        return BaseController().successData(data=0, msg='图片分片提交失败')
    else:
        return BaseController().successData(data=index, msg='图片分片提交成功')
Ejemplo n.º 26
0
def delRoomMsg(user_info, params):
    """ 删除聊天数据
        :param dict user_info
        :param dict params
        :return dict
    """
    filters = {
        Msg.room_uuid == params['room_uuid'],
        Msg.user_id == user_info['data']['id']
    }
    Msg().delete(filters)
    return BaseController().successData()
 def authenticate(email, password):
     """
     用户登录,登录成功返回token,写将登录时间写入数据库;登录失败返回失败原因
     :param password:
     :return: json
     """
     filters = {
         Users.email == email
     }
     userInfo = Users().getOne(filters)
     userInfoPas = Users().getOne(filters, order = 'id desc', field = ('password',))
     if(userInfo is None):
         return BaseController().error('找不到用户')
     else:
         if (Users.check_password(userInfoPas['password'], password)):
             updated_at = int(time.time())
             Users.update(email, updated_at)
             token = UsersAuthJWT.encode_auth_token(userInfo['id'], updated_at)
             return BaseController().successData({'token': token.decode(), 'user': userInfo}, '登陆成功')
         else:
             return BaseController().error('密码不正确')
Ejemplo n.º 28
0
 def authenticate(oa_account, password):
     """
     用户登录,登录成功返回token,写将登录时间写入数据库;登录失败返回失败原因
     :param oa_account:
     :param password:
     :return: json
     """
     filters = {
         User.oa_account == oa_account
     }
     userInfo = User().getOne(filters)
     userInfoPas = User().getOne(filters, order='id desc', field=('password',))
     if userInfo is None:
         return BaseController().error('找不到用户')
     else:
         if User.check_password(userInfoPas['password'], password):
             updated_at = int(time.time())
             token = UsersAuthJWT.encode_auth_token(userInfo['id'], updated_at)
             User.update(userInfo['id'], remember_token=token.decode(), last_login_time=updated_at)
             return BaseController().successData({'token': token.decode()}, '登陆成功')
         else:
             return BaseController().error('密码不正确')
Ejemplo n.º 29
0
def getRoomMsg(user_info, params):
    """
    查询聊天数据
    :param dict user_info
    :param dict params
    :return dict
    """
    filters = {
        Msg.room_uuid == params['room_uuid']
    }
    data = Msg().getList(filters, Msg.created_at.desc(), (), params['page_no'], params['per_page'])
    return BaseController().successData(data)
    
Ejemplo n.º 30
0
def updateRoomMsg(user_info, params):
    """ 
        更新聊天数据
        :param dict user_info
        :param dict params
        :return dict
    """
    filters = {
        Msg.room_uuid == params['room_uuid'],
        Msg.created_at == params['created_at'],
        Msg.user_id == user_info['data']['id']
    }
    Msg().edit({'send_status': params['send_status']}, filters)
    return BaseController().successData()