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()
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()
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()
def login_logger(oper_descript=""): logLogin = LogLogin() logLogin.USER_KEY = g.FuserId logLogin.IP_ADDRESS = request.remote_addr logLogin.TIME_CREATE = getSysDateTime() logLogin.DESCRIPT = oper_descript try: MySqlalchemy.comAdd(logLogin) except SQLAlchemyError as ex: mylog.error(ex)
def delete(): myRes = MyResponse() USER_KEY = MyRequest.get("USER_KEY", type=int) try: MySqlalchemy.comDel(UserInfo, [UserInfo.USER_KEY == USER_KEY]) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = ResState.ERROR_DB return myRes.to_json()
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()
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()
def getPageList(): myRes = MyResponse() currentPage = MyRequest.get("currentPage", type=int) pageSize = MyRequest.get("pageSize", type=int) searchDptKey = MyRequest.get("searchDptKey", type=str) searchName = MyRequest.get("searchName", type=str).strip() columns = [ UserInfo.USER_KEY, UserInfo.USER_NAME, UserInfo.LOGIN_NAME, UserInfo.USER_SEX, UserInfo.USER_POSITION, UserInfo.DPT_KEY, DptInfo.DPT_NAME, UserInfo.TIME_MODIFY, UserInfo.PHONE ] filters = [] outerjoins = [(DptInfo, DptInfo.DPT_KEY == UserInfo.DPT_KEY)] try: USER_KEY = g.USER_KEY if USER_KEY != 1: filters.append(UserInfo.USER_KEY != 1) if searchDptKey != 0: filters.append(UserInfo.DPT_KEY.like(searchDptKey + "%")) if searchName is not None: filters.append(UserInfo.USER_NAME.like("%" + searchName + "%")) user_page_info = MySqlalchemy.get_page_list( currentPage, pageSize, UserInfo.USER_KEY, columns, outerjoins=outerjoins, filters=filters, orders=[UserInfo.TIME_MODIFY.desc()]) ###拼接用户角色 query_data_role = db_session.query( UserRole.USER_KEY, RoleInfo.ROLE_NAME, UserRole.ROLE_KEY).outerjoin( RoleInfo, RoleInfo.ROLE_KEY == UserRole.ROLE_KEY) list_role = MySqlalchemy.convertToList(query_data_role) for xuser in user_page_info["data"]: list_roleName = [] for xrole in list_role: if xuser["USER_KEY"] == xrole["USER_KEY"]: list_roleName.append(xrole["ROLE_NAME"]) xuser["ROLE_NAMES"] = ",".join(list_roleName) myRes.data = user_page_info myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
def getPageListLogin(): myRes = MyResponse() currentPage = MyRequest.get("currentPage", type=int) pageSize = MyRequest.get("pageSize", type=int) searchName = MyRequest.get("searchName", type=str).strip() startDate = MyRequest.get_verify_date("startDate") endDate = MyRequest.get_verify_date("endDate") try: columns = [ LogLogin.LOGL_KEY, LogLogin.TIME_CREATE, LogLogin.DESCRIPT, LogLogin.IP_ADDRESS, UserInfo.LOGIN_NAME, UserInfo.USER_NAME ] outerjoins = [(UserInfo, UserInfo.USER_KEY == LogLogin.USER_KEY)] filters = [LogLogin.TIME_CREATE.between(startDate, endDate)] if searchName != '': filters.append(UserInfo.FloginName.like("%" + searchName + "%")) myRes.data = MySqlalchemy.get_page_list( currentPage, pageSize, LogLogin.LOGL_KEY, columns, outerjoins=outerjoins, filters=filters, orders=[LogLogin.TIME_CREATE.desc()]) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
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()
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()
def getLoginUserPermissionList(): myRes = MyResponse() try: USER_KEY = g.USER_KEY outerjoins_menu = [] outerjoins_oper = [] filters = [] columns_menu = [ MenuInfo.MENU_SOFT, MenuInfo.MENU_KEY, MenuInfo.MENU_ICON, MenuInfo.MENU_URL, MenuInfo.MENU_PKEY, MenuInfo.MENU_NAME ] columns_oper = [OperInfo.OPER_NAME, OperInfo.OPER_URL] if USER_KEY != 12: outerjoins_menu = [ (RolePermission, and_(MenuInfo.MENU_KEY == RolePermission.RESOURCE_KEY, RolePermission.RESOURCE_TYPE == 0)), (UserRole, UserRole.ROLE_KEY == RolePermission.ROLE_KEY) ] outerjoins_oper = [ (RolePermission, and_(OperInfo.OPER_KEY == RolePermission.RESOURCE_KEY, RolePermission.RESOURCE_TYPE == 1)), (UserRole, UserRole.ROLE_KEY == RolePermission.ROLE_KEY) ] filters = [(UserRole.USER_KEY == USER_KEY)] query_data_menu = MySqlalchemy.get_all(columns_menu, outerjoins=outerjoins_menu, filters=filters, orders=[ (MenuInfo.MENU_SOFT.asc()) ]) query_data_oper = MySqlalchemy.get_all(columns_oper, outerjoins=outerjoins_oper, filters=filters, orders=[ (OperInfo.OPER_SOFT.asc()) ]) myRes.data = {"menuList": query_data_menu, "operList": query_data_oper} myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
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()
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()
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()
def getList(): myRes = MyResponse() try: myRes.data=MySqlalchemy.get_all(DptInfo,orders=DptInfo.DPT_SOFT.asc()) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = ResState.ERROR_DB return myRes.to_json()
def getList(): myRes = MyResponse() try: query_data = db_session.query(UserInfo).all() myRes.data = MySqlalchemy.convertToList(query_data) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
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()
def getList(): myRes = MyResponse() try: query_data = db_session.query(RoleInfo).order_by( RoleInfo.TIME_MODIFY.desc()) myRes.data = MySqlalchemy.convertToList(query_data) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
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()
def wrapper(*args, **kargs): responseInfo = func() ###操作成功后,记录操作日志 if json.loads(responseInfo.data)["code"] == ResState.HTTP_SUCCESS: try: logOper = LogOper() logOper.USER_KEY = g.USER_KEY logOper.IP_ADDRESS = request.remote_addr logOper.LOGO_FUNC = "function(name=%s,args=%s,kargs=%s)" % ( func.__name__, args, kargs) logOper.LOGO_REQ_PARAMS = json.dumps(MyRequest.getAll()) logOper.TIME_CREATE = getSysDateTime() logOper.DESCRIPT = oper_descript try: MySqlalchemy.comAdd(logOper) except SQLAlchemyError as ex: mylog.error(ex) except: print(sys.exc_info()) pass return responseInfo
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()
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()
def getDetail(): myRes = MyResponse() ROLE_KEY = MyRequest.get("ROLE_KEY", type=int) try: query_data = db_session.query(RoleInfo).filter( RoleInfo.ROLE_KEY == ROLE_KEY).one() dict_data = MySqlalchemy.convertToDict(query_data) myRes.code = ResState.HTTP_SUCCESS myRes.data = dict_data except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
def getList(): myRes = MyResponse() try: query_menuButton = db_session.query(OperInfo).order_by( OperInfo.OPER_SOFT.asc()).all() myRes.data = MySqlalchemy.convertToList(query_menuButton) print(myRes.data) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
def getList(): myRes = MyResponse() try: query_menu = db_session.query( MenuInfo.MENU_KEY, MenuInfo.MENU_PKEY, MenuInfo.MENU_NAME, MenuInfo.MENU_URL, MenuInfo.MENU_ICON, MenuInfo.MENU_SOFT).order_by(MenuInfo.MENU_SOFT.asc()).all() myRes.data = MySqlalchemy.convertToList(query_menu) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
def getRoleMenuAndOperList(): myRes = MyResponse() ROLE_KEY = MyRequest.get("ROLE_KEY", type=int) try: query_data = db_session.query(RolePermission.ROLE_KEY, RolePermission.RESOURCE_KEY, RolePermission.RESOURCE_TYPE).filter( RolePermission.ROLE_KEY == ROLE_KEY) myRes.data = MySqlalchemy.convertToList(query_data) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
def getRoleListByUserKey(): myRes = MyResponse() USER_KEY = MyRequest.get("USER_KEY", type=int) try: clomns = [UserRole.USER_KEY, RoleInfo.ROLE_NAME, UserRole.ROLE_KEY] query_data = db_session.query(*clomns).outerjoin( RoleInfo, RoleInfo.ROLE_KEY == UserRole.ROLE_KEY).filter( UserRole.USER_KEY == USER_KEY) myRes.data = MySqlalchemy.convertToList(query_data) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
def getDptAndUserList(): myRes = MyResponse() try: query_data_dpt = db_session.query(DptInfo.DPT_KEY, DptInfo.DPT_PKEY, DptInfo.DPT_NAME) query_data_user = db_session.query( UserInfo.USER_KEY, UserInfo.DPT_KEY, UserInfo.USER_NAME).filter(UserInfo.USER_KEY != 1) query_data = query_data_dpt.union_all(query_data_user) myRes.data = MySqlalchemy.convertToList(query_data) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
def getDetail(): myRes = MyResponse() USER_KEY = MyRequest.get("USER_KEY", type=int) try: columns = [ UserInfo.USER_KEY, UserInfo.DPT_KEY, UserInfo.USER_NAME, UserInfo.LOGIN_NAME, UserInfo.USER_SEX, UserInfo.USER_POSITION, UserInfo.PHONE, UserInfo.TIME_CREATE, UserRole.ROLE_KEY ] dict_user = MySqlalchemy.get_detail( columns, outerjoins=[UserRole, UserRole.USER_KEY == UserInfo.USER_KEY], filters=[UserInfo.USER_KEY == USER_KEY]) myRes.code = ResState.HTTP_SUCCESS myRes.data = dict_user except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()