Exemplo n.º 1
0
def add():
    myRes = MyResponse()
    OPER_NAME = MyRequest.get_verify_empty("OPER_NAME", errmsg="操作名称不能为空")
    OPER_PKEY = MyRequest.get_verify_empty("OPER_PKEY", errmsg="OPER_PKEY不能为空")
    OPER_URL = MyRequest.get("OPER_URL", type=str)
    OPER_TYPE = MyRequest.get("OPER_TYPE", type=int)
    OPER_SOFT = MyRequest.get("OPER_SOFT", type=int)
    try:
        mybrother = db_session.query(
            OperInfo.OPER_KEY).filter(OperInfo.OPER_PKEY == OPER_PKEY).all()
        if mybrother:
            array_id = [int(x.OPER_KEY) for x in mybrother]
            ###取最大的ID
            OPER_KEY = str(max(array_id) + 1)
        elif OPER_PKEY == "0":
            OPER_KEY = "101"
        else:
            OPER_KEY = OPER_PKEY + "001"
        operInfo = OperInfo()
        operInfo.OPER_KEY = OPER_KEY
        operInfo.OPER_NAME = OPER_NAME
        operInfo.OPER_URL = OPER_URL
        operInfo.OPER_TYPE = OPER_TYPE
        operInfo.OPER_PKEY = OPER_PKEY
        operInfo.OPER_SOFT = OPER_SOFT
        MySqlalchemy.comAdd(operInfo)
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except SQLAlchemyError as ex:
        mylog.error(ex)
        myRes.msg = str(ex)
    return myRes.to_json()
Exemplo n.º 2
0
def add():
    myRes = MyResponse()
    MENU_NAME = MyRequest.get_verify_empty("MENU_NAME", errmsg="菜单名称不能为空")
    MENU_PKEY = MyRequest.get_verify_empty("MENU_PKEY", errmsg="MENU_PKEY")
    MENU_URL = MyRequest.get("MENU_URL", type=str)
    MENU_ICON = MyRequest.get("MENU_ICON", type=str)
    MENU_SOFT = MyRequest.get("MENU_SOFT", type=str)
    try:
        mybrother = db_session.query(
            MenuInfo.MENU_KEY).filter(MenuInfo.MENU_PKEY == MENU_PKEY).all()
        if mybrother:
            array_id = [int(x.MENU_KEY) for x in mybrother]
            ###取最大的ID
            MENU_KEY = str(max(array_id) + 1)
        elif MENU_PKEY == "0":
            MENU_KEY = "101"
        else:
            MENU_KEY = MENU_PKEY + "001"
        menu = MenuInfo()
        menu.MENU_KEY = MENU_KEY
        menu.MENU_NAME = MENU_NAME
        menu.MENU_PKEY = MENU_PKEY
        menu.MENU_URL = MENU_URL
        menu.MENU_ICON = MENU_ICON
        menu.MENU_SOFT = MENU_SOFT
        MySqlalchemy.comAdd(menu)
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except SQLAlchemyError as ex:
        mylog.error(ex)
        myRes.msg = str(ex)
    return myRes.to_json()
Exemplo n.º 3
0
def add():
    myRes = MyResponse()
    DPT_PKEY = MyRequest.get_verify_empty("DPT_PKEY", errmsg="请选择一个父节点")
    DPT_NAME = MyRequest.get_verify_empty("DPT_NAME", errmsg="部门名称不能为空")
    DPT_SOFT = MyRequest.get("DPT_SOFT", type=int)
    try:
        mybrother = db_session.query(DptInfo.DPT_KEY).filter(DptInfo.DPT_PKEY == DPT_PKEY).all()
        if mybrother:
            array_id = [int(x.DPT_KEY) for x in mybrother]
            ###取最大的ID
            DPT_KEY = str(max(array_id) + 1)
        elif DPT_PKEY=="0":
            DPT_KEY = "101"
        else:
            DPT_KEY=DPT_PKEY+"001"
        dpt = DptInfo()
        dpt.DPT_KEY=DPT_KEY
        dpt.DPT_PKEY = DPT_PKEY
        dpt.DPT_NAME = DPT_NAME
        dpt.DPT_SOFT = DPT_SOFT
        MySqlalchemy.comAdd(dpt)
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except SQLAlchemyError as ex:
        mylog.error(ex)
        myRes.msg=ResState.ERROR_DB
    return myRes.to_json()
Exemplo n.º 4
0
def update():
    myRes = MyResponse()
    DPT_KEY = MyRequest.get_verify_empty("DPT_KEY", errmsg="ID不能为空")
    upd_attr={}
    upd_attr["DPT_NAME"] = MyRequest.get_verify_empty("DPT_NAME", errmsg="部门名称不能为空")
    upd_attr["DPT_SOFT"] = MyRequest.get("DPT_SOFT", type=int)
    try:
        MySqlalchemy.comUpdate(DptInfo,[DptInfo.DPT_KEY==DPT_KEY],upd_attr)
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except SQLAlchemyError as ex:
        mylog.error(ex)
        myRes.msg = ResState.ERROR_DB
    return myRes.to_json()
Exemplo n.º 5
0
def update():
    myRes = MyResponse()
    OPER_KEY = MyRequest.get_verify_empty("OPER_KEY", errmsg="OPER_KEY不能为空")
    oper_attrs = {}
    oper_attrs["OPER_NAME"] = MyRequest.get_verify_empty("OPER_NAME",
                                                         errmsg="按钮编码不能为空")
    oper_attrs["OPER_URL"] = MyRequest.get("OPER_URL", type=str)
    oper_attrs["OPER_TYPE"] = MyRequest.get("OPER_TYPE", type=int)
    oper_attrs["OPER_SOFT"] = MyRequest.get("OPER_SOFT", type=int)
    try:
        MySqlalchemy.comUpdate(OperInfo, [OperInfo.OPER_KEY == OPER_KEY],
                               oper_attrs)
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except SQLAlchemyError as ex:
        mylog.error(ex)
        myRes.msg = str(ex)
    return myRes.to_json()
Exemplo n.º 6
0
def login():
    myRes = MyResponse()
    try:
        FloginName = MyRequest.get_verify_empty("FloginName", errmsg="用户名不能为空")
        Fpwd = MyRequest.get_verify_empty("Fpwd", errmsg="密码不能为空")
        from app.apis.utils.auth_helper import Auth
        dict_user, token = Auth.authenticate(FloginName, Fpwd)
        userInfo = {
            "USER_NAME": dict_user["USER_NAME"],
            "LOGIN_NAME": dict_user["LOGIN_NAME"],
            "PHONE": dict_user["PHONE"]
        }
        g.FuserId = dict_user["USER_KEY"]
        myRes.data = {"userInfo": userInfo, "token": token}
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "登录成功"
        login_logger("用户登录")
    except SQLAlchemyError as ex:
        mylog.error(ex)
        return myRes.to_json_msg(ResState.ERROR_DB)
    return myRes.to_json()
Exemplo n.º 7
0
def add():
    myRes = MyResponse()
    user = UserInfo()
    user.LOGIN_NAME = MyRequest.get_verify_empty("LOGIN_NAME",
                                                 errmsg="用户名不能为空")
    user.USER_NAME = MyRequest.get_verify_empty("USER_NAME", errmsg="姓名不能为空")
    user.USER_SEX = MyRequest.get("USER_SEX", type=int)
    user.DPT_KEY = MyRequest.get_verify_empty("DPT_KEY", errmsg="DPT_KEY不能为空")
    user.set_password("123456")
    user.USER_POSITION = MyRequest.get("USER_POSITION", type=str)
    user.PHONE = MyRequest.get("PHONE", type=str)
    user.TIME_CREATE = getSysDateTime()
    user.TIME_MODIFY = getSysDateTime()
    try:
        MySqlalchemy.comAdd(user)
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except SQLAlchemyError as ex:
        mylog.error(ex)
        myRes.msg = ResState.ERROR_DB
    return myRes.to_json()
Exemplo n.º 8
0
def update():
    myRes = MyResponse()
    USER_KEY = MyRequest.get("USER_KEY", type=int)
    upd_attr = {}
    upd_attr["USER_NAME"] = MyRequest.get_verify_empty("USER_NAME",
                                                       errmsg="姓名不能为空")
    upd_attr["USER_SEX"] = MyRequest.get("USER_SEX", type=int, default=1)
    upd_attr["DPT_KEY"] = MyRequest.get_verify_empty("DPT_KEY",
                                                     errmsg="部门ID不能为空")
    upd_attr["USER_POSITION"] = MyRequest.get("USER_POSITION", type=str)
    upd_attr["PHONE"] = MyRequest.get("PHONE", type=str)
    upd_attr["TIME_MODIFY"] = getSysDateTime()
    try:
        MySqlalchemy.comUpdate(UserInfo, [UserInfo.USER_KEY == USER_KEY],
                               upd_attr)
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except SQLAlchemyError as ex:
        mylog.error(ex)
        myRes.msg = str(ex)
    return myRes.to_json()
Exemplo n.º 9
0
def getDetail():
    myRes = MyResponse()
    DPT_KEY = MyRequest.get_verify_empty("DPT_KEY", errmsg="部门ID不能为空")
    try:
        query_data=db_session.query(DptInfo).filter(DptInfo.DPT_KEY==DPT_KEY).one()
        dict_menu=MySqlalchemy.convertToDict(query_data)
        myRes.data = dict_menu
        myRes.code = ResState.HTTP_SUCCESS
    except SQLAlchemyError as ex:
        mylog.error(ex)
        myRes.msg=str(ex)
    return myRes.to_json()
Exemplo n.º 10
0
def getDetail():
    myRes = MyResponse()
    Fid = MyRequest.get_verify_empty("Fid", errmsg="Fid不能为空")
    try:
        query_menu = db_session.query(MenuInfo).filter(
            MenuInfo.Fid == Fid).one()
        dict_menu = MySqlalchemy.convertToDict(query_menu)
        myRes.data = dict_menu
        myRes.code = ResState.HTTP_SUCCESS
    except SQLAlchemyError as ex:
        mylog.error(ex)
        myRes.msg = str(ex)
    return myRes.to_json()
Exemplo n.º 11
0
def resetMyPwd():
    myRes = MyResponse()
    FuserId = g.USER_KEY
    FoldPwd = MyRequest.get_verify_empty("FoldPwd", errmsg="旧密码不能为空")
    FnewPwd = MyRequest.get_verify_empty("FnewPwd", errmsg="新密码不能为空")
    FnewPwdOk = MyRequest.get("FnewPwdOk", type=str)
    try:
        if FnewPwd != FnewPwdOk:
            return myRes.to_json_msg("新旧密码不一致")
        userInfo = db_session.query(UserInfo).filter(
            UserInfo.USER_KEY == FuserId).one()
        if not userInfo.check_password(userInfo.USER_PWD, FoldPwd):
            return myRes.to_json_msg("旧密码错误,请重新输入")
        userInfo.set_password(FnewPwd)
        db_session.commit()
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except SQLAlchemyError as ex:
        mylog.error(ex)
        myRes.msg = str(ex)
    finally:
        db_session.close()
    return myRes.to_json()
Exemplo n.º 12
0
def update():
    myRes = MyResponse()
    ROLE_KEY = MyRequest.get("ROLE_KEY", type=int)
    role_attrs = {}
    role_attrs["ROLE_NAME"] = MyRequest.get_verify_empty("ROLE_NAME")
    role_attrs["DESCRIPT"] = MyRequest.get("DESCRIPT")
    role_attrs["TIME_MODIFY"] = getSysDateTime()
    try:
        MySqlalchemy.comUpdate(RoleInfo, [RoleInfo.ROLE_KEY == ROLE_KEY],
                               role_attrs)
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except SQLAlchemyError as ex:
        mylog.error(ex)
        myRes.msg = str(ex)
    return myRes.to_json()
Exemplo n.º 13
0
def delete():
    myRes = MyResponse()
    DPT_KEY = MyRequest.get_verify_empty("DPT_KEY", errmsg="ID不能为空")
    try:
        rows = db_session.query(DptInfo).filter(DptInfo.DPT_KEY.like(DPT_KEY+"%")).delete(synchronize_session=False)
        db_session.commit()
        if rows < 1:
            raise SQLAlchemyError("操作失败")
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except SQLAlchemyError as ex:
        mylog.error(ex)
        myRes.msg = ResState.ERROR_DB
    finally:
        db_session.close()
    return myRes.to_json()
Exemplo n.º 14
0
def update():
    myRes = MyResponse()
    MENU_KEY = MyRequest.get_verify_empty("MENU_KEY", errmsg="MENU_KEY不能为空")
    menu_attrs = {}
    menu_attrs["MENU_NAME"] = MyRequest.get("MENU_NAME", type=str)
    menu_attrs["MENU_URL"] = MyRequest.get("MENU_URL", type=str)
    menu_attrs["MENU_ICON"] = MyRequest.get("MENU_ICON", type=str)
    menu_attrs["MENU_SOFT"] = MyRequest.get("MENU_SOFT", type=str)
    try:
        MySqlalchemy.comUpdate(MenuInfo, [MenuInfo.MENU_KEY == MENU_KEY],
                               menu_attrs)
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except SQLAlchemyError as ex:
        mylog.error(ex)
        myRes.msg = str(ex)
    return myRes.to_json()
Exemplo n.º 15
0
def updMyInfo():
    myRes = MyResponse()
    USER_KEY = g.USER_KEY
    upd_attr = {}
    upd_attr["USER_NAME"] = MyRequest.get_verify_empty("USER_NAME",
                                                       errmsg="姓名不能为空")
    upd_attr["PHONE"] = MyRequest.get("PHONE", type=str)
    try:
        MySqlalchemy.comUpdate(UserInfo, [UserInfo.USER_KEY == USER_KEY],
                               upd_attr)
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except SQLAlchemyError as ex:
        mylog.error(ex)
        myRes.msg = str(ex)
    finally:
        db_session.close()
    return myRes.to_json()
Exemplo n.º 16
0
def add():
    myRes = MyResponse()
    ROLE_NAME = MyRequest.get_verify_empty("ROLE_NAME")
    DESCRIPT = MyRequest.get("DESCRIPT")
    try:
        role = RoleInfo()
        role.ROLE_NAME = ROLE_NAME
        role.DESCRIPT = DESCRIPT
        role.TIME_CREATE = getSysDateTime()
        role.TIME_MODIFY = getSysDateTime()
        MySqlalchemy.comAdd(role)
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except MyError as ex:
        myRes.msg = ex
    except SQLAlchemyError as ex:
        mylog.error(ex)
        myRes.msg = ResState.ERROR_DB
    return myRes.to_json()
Exemplo n.º 17
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()