Esempio n. 1
0
def importLogLogin():
    myRes = MyResponse()
    try:
        ###添加注入清单信息
        f = request.files['Ffile']
        uploadFile = UploadFile(f)
        uploadFile.import_file()
        xlrdReader = XlrdReader(
            os.path.join(uploadFile.filepath, uploadFile.filename))
        xlrdReader.readSheetToList()
        reader_data = xlrdReader.datas
        reader_titles = xlrdReader.titles
        for index_row, row in enumerate(reader_data):
            sysLog = LogLogin()
            sysLog.FuserId = row[0]
            sysLog.FcreateTime = getSysDateTime()
            sysLog.Ffunc = row[1]
            sysLog.FipAddress = row[2]
            sysLog.Fremark = row[5]
            db_session.add(sysLog)
        db_session.commit()
        myRes.code = ResState.HTTP_SUCCESS
    except ExcelError as ex:
        mylog.error(ex)
        abort(404, "读取excel错误")
    except SQLAlchemyError as ex:
        db_session.rollback()
        mylog.error(ex)
        abort(404, sys.exc_info()[1])
    finally:
        pass
    return myRes.to_json()
Esempio n. 2
0
def updRolePermission():
    myRes = MyResponse()
    RESOURCE_KEYS = MyRequest.get_verify_list("RESOURCE_KEYS")
    ROLE_KEY = MyRequest.get("ROLE_KEY", type=int)
    RESOURCE_TYPE = MyRequest.get("RESOURCE_TYPE", type=int)
    try:
        db_session.begin_nested()
        db_session.query(RolePermission).filter(
            RolePermission.ROLE_KEY == ROLE_KEY).filter(
                RolePermission.RESOURCE_TYPE == RESOURCE_TYPE).delete(
                    synchronize_session=False)
        for key in RESOURCE_KEYS:
            rolePermission = RolePermission()
            rolePermission.ROLE_KEY = ROLE_KEY
            rolePermission.RESOURCE_KEY = key
            rolePermission.RESOURCE_TYPE = RESOURCE_TYPE
            db_session.add(rolePermission)
        db_session.commit()
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except SQLAlchemyError as ex:
        db_session.rollback()
        mylog.error(ex)
        myRes.msg = str(ex)
    finally:
        db_session.close()
    return myRes.to_json()
Esempio n. 3
0
def delete():
    myRes = MyResponse()
    ROLE_KEY = MyRequest.get("ROLE_KEY", type=int)
    try:
        MySqlalchemy.comDel(RoleInfo, [RoleInfo.ROLE_KEY == ROLE_KEY])
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except SQLAlchemyError as ex:
        db_session.rollback()
        mylog.error(ex)
        myRes.msg = str(ex)
    finally:
        db_session.close()
    return myRes.to_json()
Esempio n. 4
0
 def comAdds(cls, models):
     """
     批量添加
     :param models:
     :return:
     """
     try:
         if isinstance(models, (list, tuple)):
             db_session.begin_nested()
             for model in models:
                 db_session.add(model)
             db_session.commit()
         else:
             raise MyError("Models mast be list or tuple.")
     except SQLAlchemyError as ex:
         db_session.rollback()
         raise ex
     finally:
         db_session.close()
Esempio n. 5
0
 def comUpdates(cls, list_model, id, attrs):
     """
     批量修改
     :param list_model:
     :param id:
     :param attrs:
     :return:
     """
     try:
         db_session.begin_nested()
         for model in list_model:
             rows = db_session.query(model).filter(
                 model.Fid == id).update(attrs)
             if rows < 1:
                 raise SQLAlchemyError("操作失败")
         db_session.commit()
     except SQLAlchemyError as ex:
         db_session.rollback()
         raise ex
     finally:
         db_session.close()
Esempio n. 6
0
def updUserRole():
    myRes = MyResponse()
    ROLE_KEYS = MyRequest.getList("ROLE_KEYS[]")
    USER_KEY = MyRequest.get("USER_KEY", type=int)
    try:
        db_session.begin_nested()
        db_session.query(UserRole).filter(
            UserRole.USER_KEY == USER_KEY).delete()
        for key in ROLE_KEYS:
            userRole = UserRole()
            userRole.USER_KEY = USER_KEY
            userRole.ROLE_KEY = key
            db_session.add(userRole)
        db_session.commit()
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except SQLAlchemyError as ex:
        db_session.rollback()
        mylog.error(ex)
        myRes.msg = str(ex)
    finally:
        db_session.close()
    return myRes.to_json()
Esempio n. 7
0
 def comDels(cls, models, ids):
     """
     批量删除
     :param models:
     :param ids:
     :return:
     """
     try:
         if isinstance(models,
                       (list, tuple)) and isinstance(ids, (list, tuple)):
             db_session.begin_nested()
             for model in models:
                 rows = db_session.query(models).filter(
                     model.Fid == id).delete(synchronize_session=False)
                 if rows < 1:
                     raise SQLAlchemyError("操作失败")
             db_session.commit()
         else:
             raise MyError("Models and ids mast be list or tuple.")
     except SQLAlchemyError as ex:
         db_session.rollback()
         raise ex
     finally:
         db_session.close()
Esempio n. 8
0
def delete():
    myRes = MyResponse()
    OPER_KEY = MyRequest.get_verify_empty("OPER_KEY", errmsg="OPER_KEY不能为空")
    try:
        db_session.begin_nested()
        ###删除按钮相关的角色权限信息
        db_session.query(RolePermission).filter(
            RolePermission.RESOURCE_TYPE == 1).filter(
                RolePermission.RESOURCE_KEY.like(OPER_KEY + "%")).delete(
                    synchronize_session=False)
        ###删除按钮信息
        db_session.query(OperInfo).filter(
            OperInfo.OPER_KEY.like(OPER_KEY +
                                   "%")).delete(synchronize_session=False)
        db_session.commit()
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except SQLAlchemyError as ex:
        db_session.rollback()
        mylog.error(ex)
        myRes.msg = str(ex)
    finally:
        db_session.close()
    return myRes.to_json()