Beispiel #1
0
def refractometerRedis():
    '''
    Redis实时数据
    :return:
    '''
    if request.method == 'GET':
        data = request.values
        try:
            jsonstr = json.dumps(data.to_dict())
            data_dict = {}
            redis_conn = redis.Redis(connection_pool=pool)
            bls = constant.REDIS_retxt
            for key in bls:
                key = key.upper()
                if "IME" in key:
                    key = key[0:-3] + "ime"
                data_dict[key] = redis_conn.hget(
                    constant.REDIS_TABLENAME, "t|" + str(key)).decode('utf-8')
            return json.dumps(data_dict,
                              cls=AlchemyEncoder,
                              ensure_ascii=False)
        except Exception as e:
            print(e)
            logger.error(e)
            insertSyslog("error", "折光仪实时数据查询报错Error:" + str(e),
                         current_user.Name)
Beispiel #2
0
def menulist():
    if request.method == 'GET':
        role_data = request.values
        if 'id' not in role_data.keys():
            try:
                data = getMenuList(role_menus=[],id=0)
                jsondata = json.dumps(data, cls=AlchemyEncoder, ensure_ascii=False)
                return jsondata.encode("utf8")
            except Exception as e:
                print(e)
                logger.error(e)
                insertSyslog("error", "加载菜单列表Error:" + str(e), current_user.Name)
                return json.dumps([{"status": "Error:" + str(e)}], cls=AlchemyEncoder, ensure_ascii=False)
        id = role_data['id']
        try:
            role_menus = db_session.query(Menu.ModuleName).join(Role_Menu, isouter=True).filter_by(Role_ID=id).all()
            r_menus = []
            for menu in role_menus:
                r_menus.append(menu[0])
            menus_data = getMenuList(r_menus, id=0)
            jsondata = json.dumps(menus_data, cls=AlchemyEncoder, ensure_ascii=False)
            return jsondata.encode("utf8")
        except Exception as e:
            print(e)
            logger.error(e)
            insertSyslog("error", "加载菜单列表Error:" + str(e), current_user.Name)
            return json.dumps([{"status": "Error:" + str(e)}], cls=AlchemyEncoder, ensure_ascii=False)
Beispiel #3
0
def allrolesSearch():
    if request.method == 'POST':
        data = request.values
        try:
            json_str = json.dumps(data.to_dict())
            if len(json_str) > 2:
                strconditon = "%" + data['condition'] + "%"
                roles = db_session.query(Role).filter(
                    Role.RoleName.like(strconditon)).all()
                total = Counter(roles)
                jsonroles = json.dumps(roles,
                                       cls=AlchemyEncoder,
                                       ensure_ascii=False)
                jsonroles = '{"total"' + ":" + str(
                    total.__len__()) + ',"rows"' + ":\n" + jsonroles + "}"
                return jsonroles
        except Exception as e:
            print(e)
            logger.error(e)
            insertSyslog("error", "擦护心角色列表报错Error:" + str(e),
                         current_user.Name)
            return json.dumps([{
                "status": "Error:" + string(e)
            }],
                              cls=AlchemyEncoder,
                              ensure_ascii=False)
Beispiel #4
0
def BrandFlagSearch():
    if request.method == 'GET':
        data = request.values
        try:
            jsonstr = json.dumps(data.to_dict())
            if len(jsonstr) > 10:
                pages = int(data.get("offset"))
                rowsnumber = int(data.get("limit"))
                inipage = pages * rowsnumber + 0
                endpage = pages * rowsnumber + rowsnumber
                BrandName = data.get('BrandName')
                if BrandName == None or BrandName == "":
                    total = db_session.query(BrandFlag).order_by(
                        ("ID")).count()
                    oclass = db_session.query(BrandFlag).order_by(
                        ("ID")).all()[inipage:endpage]
                else:
                    total = db_session.query(BrandFlag).filter(
                        BrandFlag.BrandName.like(BrandName)).order_by(
                            ("ID")).count()
                    oclass = db_session.query(BrandFlag).filter(
                        BrandFlag.BrandName.like(BrandName)).order_by(
                            ("ID")).all()[inipage:endpage]
                jsonoclass = json.dumps(oclass,
                                        cls=AlchemyEncoder,
                                        ensure_ascii=False)
                return '{"total"' + ":" + str(
                    total) + ',"rows"' + ":\n" + jsonoclass + "}"
        except Exception as e:
            print(e)
            logger.error(e)
            insertSyslog("error", "品名维护表Error:" + str(e), current_user.Name)
Beispiel #5
0
def SelectMenus():
    if request.method == 'GET':
        data = request.values
        try:
            MenuType = data.get("MenuType")
            Name = current_user.Name
            if Name == "系统管理员":
                oclass = db_session.query(ModulMenus).all()
                return json.dumps(oclass, cls=AlchemyEncoder, ensure_ascii=False)
            periss = db_session.query(Permission).filter(Permission.Name == current_user.Name, Permission.MenuType == MenuType).all()
            flag = 'OK'
            dic = []
            for i in periss:
                oclass = db_session.query(ModulMenus).filter(
                    ModulMenus.ResourceMenuName.like("%" + i.MenuName + "%")).first()
                dic.append(oclass)
                # if MenuType == "资源级":
                #     oclass = db_session.query(ResourceMenus).filter(ResourceMenus.ModulMenuName.like("%"+i.MenuName+"%")).first()
                #     dic.append(oclass)
                # else:
                #     oclass = db_session.query(ModulMenus).filter(
                #         ModulMenus.ResourceMenuName.like("%" + i.MenuName + "%")).first()
                #     dic.append(oclass)
            return json.dumps(dic, cls=AlchemyEncoder, ensure_ascii=False)
        except Exception as e:
            print(e)
            logger.error(e)
            insertSyslog("error", "菜单权限查询报错Error:" + str(e), current_user.Name)
            return json.dumps([{"status": "Error:" + str(e)}], cls=AlchemyEncoder, ensure_ascii=False)
def organizationTU():
    if request.method == 'GET':
        data = request.values
        try:
            dic = []
            facs = db_session.query(Factory).all()
            for fa in facs:
                deps = db_session.query(DepartmentManager).filter(
                    DepartmentManager.DepartLoad == fa.FactoryName).all()
                for dep in deps:
                    die = []
                    die.append(fa.FactoryName)
                    die.append(dep.DepartName)
                    dic.append(die)
                    ros = db_session.query(Role).filter(
                        Role.ParentNode == dep.DepartName).all()
                    for ro in ros:
                        dif = []
                        dif.append(dep.DepartName)
                        dif.append(ro.RoleName)
                        dic.append(dif)
            return json.dumps(dic, cls=AlchemyEncoder, ensure_ascii=False)
        except Exception as e:
            print(e)
            logger.error(e)
            insertSyslog("error", "组织架构图报错Error:" + str(e), current_user.Name)
            return json.dumps([{
                "status": "Error:" + str(e)
            }],
                              cls=AlchemyEncoder,
                              ensure_ascii=False)
Beispiel #7
0
def addUpdateEletronicBatchDataStore(PUID, BatchID, ke, val):
    try:
        oc = db_session.query(EletronicBatchDataStore).filter(
            EletronicBatchDataStore.PUID == PUID,
            EletronicBatchDataStore.BatchID == BatchID,
            EletronicBatchDataStore.Content == ke).first()
        if oc == None:
            db_session.add(
                EletronicBatchDataStore(BatchID=BatchID,
                                        PUID=PUID,
                                        Content=ke,
                                        OperationpValue=val,
                                        Operator=current_user.Name))
        else:
            oc.Content = ke
            oc.OperationpValue = val
            oc.Operator = current_user.Name
        db_session.commit()
    except Exception as e:
        db_session.rollback()
        print(e)
        logger.error(e)
        insertSyslog("error", "保存更新EletronicBatchDataStore报错:" + str(e),
                     current_user.Name)
        return json.dumps("保存更新EletronicBatchDataStore报错",
                          cls=AlchemyEncoder,
                          ensure_ascii=False)
Beispiel #8
0
def ExactQuery(tablename, field, param,type='one'):
    '''
    :param tablename: 需要精确查询的model
    :param field: 查询条件(model的字段)
    :param param: 查询条件的value
    :param type: 查询类型(查询单条type为'one',查询多条为'more')
    :return: 返回json信息,包含status,message,data
    '''
    if hasattr(tablename, '__tablename__') and hasattr(tablename, field):
        if isinstance(param, str) and len(param) > 0:
            if type == 'one':
                try:
                    one_data = db_session.query(tablename).filter_by(field=param).first()
                    if one_data:
                        return json.dumps({'status': 'OK', 'message': '数据查询成功!', 'data':one_data}, cls=AlchemyEncoder, ensure_ascii=False)
                    else:
                        return json.dumps({'status': 'OK', 'message': '未查询到相关数据!'}, cls=AlchemyEncoder, ensure_ascii=False)
                except Exception as e:
                    logger.error(e)
                    insertSyslog("error", "%s数据更新报错:" % tablename + str(e), current_user.Name)
            if type == 'more':
                try:
                    more_data = db_session.query(tablename).filter_by(field=param).all()
                    if more_data:
                        return json.dumps({'status': 'OK', 'message': '数据查询成功!', 'data':more_data}, cls=AlchemyEncoder, ensure_ascii=False)
                    else:
                        return json.dumps({'status': 'OK', 'message': '未查询到相关数据!'}, cls=AlchemyEncoder, ensure_ascii=False)
                except Exception as e:
                    logger.error(e)
                    insertSyslog("error", "%s数据更新报错:" % tablename + str(e), current_user.Name)
            else:
                return json.dumps({'status': 'error', 'message': '系统错误,请联系系统管理员解决...'}, cls=AlchemyEncoder, ensure_ascii=False)
        return json.dumps({'status': 'error', 'message': '数据查询失败,请输入正确的关键字...'}, cls=AlchemyEncoder, ensure_ascii=False)
    else:
        return json.dumps({'status': 'error', 'message': '系统错误,请联系系统管理员解决...'}, cls=AlchemyEncoder, ensure_ascii=False)
Beispiel #9
0
def delete(tablename, delete_data):
    '''
    :param tablename: 要进行删除信息的model
    :param recv_data: 要进行更新的数据,数据类型为list,list中的每个元素为需要删除的每条记录的ID
    :return: 返回json信息,包含status,message
    '''
    if hasattr(tablename, '__tablename__'):
        try:
            jsonstr = json.dumps(delete_data.to_dict())
            if len(jsonstr) > 10:
                jsonnumber = re.findall(r"\d+\.?\d*", jsonstr)
                for key in jsonnumber:
                    id = int(key)
                    try:
                        oclass = db_session.query(tablename).filter_by(ID=id).first()
                        db_session.delete(oclass)
                        db_session.commit()
                    except Exception as ee:
                        db_session.rollback()
                        insertSyslog("error", "删除户ID为"+str(id)+"报错Error:" + str(ee), current_user.Name)
                        return json.dumps("删除用户报错", cls=AlchemyEncoder,ensure_ascii=False)
                return 'OK'
        except Exception as e:
            db_session.rollback()
            logger.error(e)
            insertSyslog("error", "%s数据删除报错:"%tablename + str(e), current_user.Name)
            return json.dumps('数据删除失败!')
Beispiel #10
0
def select(table, page, rows, fieid, param):
    '''
    :param tablename: 查询表
    :param pages: 页数
    :param rowsnumber: 一页多少行
    :param fieid: 查询字段
    :param param: 查询条件
    :return: 
    '''
    try:
        inipage = (page - 1) * rows + 0
        endpage = (page - 1) * rows + rows
        if (param == "" or param == None):
            total = db_session.query(table).count()
            oclass = db_session.query(table).all()[inipage:endpage]
        else:
            # sql = "select * from "+tableName+" t where t."+fieid+" like "+"'%"+param+"%'"
            # oclass = db_session.execute(sql).fetchall()
            # total = len(oclass)
            # db_session.close()
            print(fieid)
            print(param)
            print(table)
            # obj.__tablename__ = table
            total = db_session.query(table).filter_by(fieid==param).count()
            oclass = db_session.query(table).filter_by(fieid=param).all()[inipage:endpage]
        jsonoclass = json.dumps(oclass, cls=AlchemyEncoder, ensure_ascii=False)
        jsonoclass = '{"total"' + ":" + str(total) + ',"rows"' + ":\n" + jsonoclass + "}"
        return jsonoclass
    except Exception as e:
        print(e)
        logger.error(e)
        insertSyslog("error", "查询报错Error:" + str(e), current_user.Name)
Beispiel #11
0
def saverolepermission():
    '''
    角色添加权限
    :return:
    '''
    if request.method == 'POST':
        data = request.values
        try:
            roleID = data.get("roleID")
            permissionIDs = data.get("permissionIDs")
            if permissionIDs:
                permissionIDs = eval(permissionIDs)
            roleclass = db_session.query(Role).filter(Role.ID == int(roleID)).first()
            sql = "delete from RolePermission where RoleID = " + roleID
            db_session.execute(sql)
            db_session.commit()
            for pid in permissionIDs:
                permissioncalss = db_session.query(Permission).filter(Permission.ID == int(pid)).first()
                rpclas = db_session.query(RolePermission).filter(RolePermission.RoleID == roleclass.ID, RolePermission.PermissionID == permissioncalss.ID).first()
                if not rpclas:
                    rp = RolePermission()
                    rp.RoleID = roleclass.ID
                    rp.RoleName = roleclass.RoleName
                    rp.PermissionID = permissioncalss.ID
                    rp.PermissionName = permissioncalss.PermissionName
                    db_session.add(rp)
                    db_session.commit()
            return json.dumps("OK", cls=AlchemyEncoder, ensure_ascii=False)
        except Exception as e:
            db_session.rollback()
            print(e)
            logger.error(e)
            insertSyslog("error", "角色添加权限Error:" + str(e), current_user.Name)
Beispiel #12
0
def addUser():
    if request.method == 'POST':
        data = request.values
        str = request.get_json()
        try:
            json_str = json.dumps(data.to_dict())
            if len(json_str) > 10:
                user = User()
                user.WorkNumber=data['WorkNumber']
                ocal = db_session.query(User).filter(User.WorkNumber == user.WorkNumber).first()
                if ocal != None:
                    return "工号重复,请重新录入!"
                user.Name=data['Name']
                user.Password=user.password(data['Password'])
                # print(user.Password)
                user.Status="1" # 登录状态先设置一个默认值1:已登录,0:未登录
                user.Creater=current_user.Name
                user.CreateTime=datetime.datetime.now()
                user.LastLoginTime=datetime.datetime.now()
                user.IsLock='false' # data['IsLock'],
                user.OrganizationName=data['OrganizationName']
                user.RoleName=data['RoleName']
                db_session.add(user)
                db_session.commit()
                return 'OK'
        except Exception as e:
            db_session.rollback()
            print(e)
            logger.error(e)
            insertSyslog("error", "添加用户报错Error:" + str(e), current_user.Name)
            return json.dumps([{"status": "Error:" + str(e)}], cls=AlchemyEncoder, ensure_ascii=False)
Beispiel #13
0
def userselect(data):  #table, page, rows, fieid, param
    '''
    :param tablename: 查询表
    :param pages: 页数
    :param rowsnumber: 一页多少行
    :param fieid: 查询字段
    :param param: 查询条件
    :return:用户查询
    '''
    try:
        pages = int(data.get("offset"))
        rowsnumber = int(data.get("limit"))
        param = data.get("field")
        tableName = data.get("tableName")
        paramvalue = data.get("fieldvalue")
        if (paramvalue == "" or paramvalue == None):
            oclass = db_session.query(User).filter(
                User.WorkNumber == paramvalue).all()
            total = db_session.query(User).filter(
                User.WorkNumber == paramvalue).count()
        jsonoclass = '{"total"' + ":" + str(
            total) + ',"rows"' + ":\n" + oclass + "}"
        return jsonoclass
    except Exception as e:
        print(e)
        logger.error(e)
        insertSyslog("error", "用户查询报错Error:" + str(e), current_user.Name)
Beispiel #14
0
def MyUserSelect():
    if request.method == 'GET':
        data = request.values
        try:
            json_str = json.dumps(data.to_dict())
            if len(json_str) > 10:
                pages = int(data.get("offset"))  # 页数
                rowsnumber = int(data.get("limit"))  # 行数
                inipage = pages * rowsnumber + 0  # 起始页
                endpage = pages * rowsnumber + rowsnumber  # 截止页
                id = data.get('id')
                Name = data.get('Name')
                if id != '':
                    OrganizationCodeData = db_session.query(Organization).filter_by(ID=id).first()
                    if OrganizationCodeData != None:
                        OrganizationName = str(OrganizationCodeData.OrganizationName)
                        total = db_session.query(User).filter(and_(User.OrganizationName.like("%" + OrganizationName + "%") if OrganizationName is not None else "",
                                                           User.Name.like("%" + Name + "%") if Name is not None else "")).count()
                        oclass = db_session.query(User).filter(and_(User.OrganizationName.like("%" + OrganizationName + "%") if OrganizationName is not None else "",
                                                           User.Name.like("%" + Name + "%") if Name is not None else "")).order_by(desc("CreateTime")).all()[inipage:endpage]
                    else:
                        total = db_session.query(User).filter(User.Name.like("%" + Name + "%") if Name is not None else "").count()
                        oclass = db_session.query(User).filter(User.Name.like("%" + Name + "%") if Name is not None else "").order_by(desc("CreateTime")).all()[inipage:endpage]
                else:
                    total = db_session.query(User).filter(User.Name.like("%" + Name + "%") if Name is not None else "").count()
                    oclass = db_session.query(User).filter(User.Name.like("%" + Name + "%") if Name is not None else "").order_by(desc("CreateTime")).all()[inipage:endpage]
                jsonoclass = json.dumps(oclass, cls=AlchemyEncoder, ensure_ascii=False)
                jsonoclass = '{"total"' + ":" + str(total) + ',"rows"' + ":\n" + jsonoclass + "}"
            return jsonoclass
        except Exception as e:
            print(e)
            logger.error(e)
            insertSyslog("error", "查询用户列表报错Error:" + str(e), current_user.Name)
            return json.dumps([{"status": "Error:" + str(e)}], cls=AlchemyEncoder, ensure_ascii=False)
Beispiel #15
0
def UpdateUser():
    if request.method == 'POST':
        data = request.values
        str = request.get_json()
        try:
            json_str = json.dumps(data.to_dict())
            if len(json_str) > 10:
                id = int(data['ID'])
                user = db_session.query(User).filter_by(id=id).first()
                user.Name = data['Name']
                user.WorkNumber = data['WorkNumber']
                ocal = db_session.query(User).filter(User.WorkNumber == user.WorkNumber).first()
                if ocal != None:
                    if ocal.id != id:
                        return "工号重复,请重新修改!"
                user.Password = user.password(data['Password'])
                user.OrganizationName = data['OrganizationName']
                user.RoleName = data['RoleName']
                db_session.commit()
                return 'OK'
        except Exception as e:
            db_session.rollback()
            print(e)
            logger.error(e)
            insertSyslog("error", "更新用户报错Error:" + str(e), current_user.Name)
            return json.dumps([{"status": "Error:" + str(e)}], cls=AlchemyEncoder, ensure_ascii=False)
Beispiel #16
0
def userloginauthentication():
    '''
    用户登陆认证
    :return:
    '''
    try:
        if request.method == 'POST':
            data = request.values
            WorkNumber = data.get('WorkNumber')
            password = data.get('password')
            # 验证账户与密码
            user = db_session.query(User).filter_by(WorkNumber=WorkNumber).first()
            resp = make_response()
            if user and (user.confirm_password(password) or user.Password == password):
                login_user(user)  # login_user(user)调用user_loader()把用户设置到db_session中
                user.session_id = str(time.time())
                user.LastLoginTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
                db_session.commit()
                return 'OK'
            else:
                return '用户名密码错误'
    except Exception as e:
        print(e)
        db_session.rollback()
        logger.error(e)
        return json.dumps([{"status": "Error:" + str(e)}], cls=AlchemyEncoder, ensure_ascii=False)
Beispiel #17
0
def PermissionsSave():
    if request.method == 'POST':
        data = request.values
        try:
            datastr = json.loads(data.get("data"))
            #删除之前的权限
            perss = db_session.query(Permission).filter(Permission.WorkNumber == datastr[0].get("WorkNumber")).all()
            for pe in perss:
                db_session.delete(pe)
            db_session.commit()
            for i in datastr:
                per = Permission()
                per.MenuName = i.get("MenuName")
                per.MenuType = i.get("MenuType")
                per.MenuCode = i.get("MenuCode")
                per.Name = i.get("Name")
                per.WorkNumber = i.get("WorkNumber")
                db_session.add(per)
            db_session.commit()
            return 'OK'
        except Exception as e:
            db_session.rollback()
            print(e)
            logger.error(e)
            insertSyslog("error", "添加用户报错Error:" + str(e), current_user.Name)
            return json.dumps([{"status": "Error:" + str(e)}], cls=AlchemyEncoder, ensure_ascii=False)
Beispiel #18
0
def FuzzyQuery(tablename, params):
    '''
    :param tablename: 要进行查询的model
    :param params: 一个字典,字典中的key为model的字段,value为进行查询的关键字
    :return: 返回json信息,包含status,message,data
    '''
    if hasattr(tablename, '__tablename__'):
        if isinstance(params, dict) and len(params) > 0:
            for key in params.keys():
                if hasattr(tablename, key):
                    try:
                        data = db_session.query(tablename).filter_by(key = params[key]).all()
                        if data:
                            return json.dumps({'status': 'OK', 'message': '数据更新成功!', 'data':data}, cls=AlchemyEncoder, ensure_ascii=False)
                        else:
                            return json.dumps({'status': 'OK', 'message': '未查询到相关的数据!'}, cls=AlchemyEncoder, ensure_ascii=False)
                    except Exception as e:
                        logger.error(e)
                        insertSyslog("error", "%s数据更新报错:"%tablename + str(e), current_user.Name)
                return json.dumps({'status':'error', 'message': '数据查询失败,请输入正确的关键字...'}, cls=AlchemyEncoder, ensure_ascii=False)

        else:
            return json.dumps({'status': 'error', 'message': '系统错误,请联系系统管理员解决...'}, cls=AlchemyEncoder, ensure_ascii=False)
    else:
        return json.dumps({'status': 'error', 'message': '系统错误,请联系系统管理员解决...'}, cls=AlchemyEncoder, ensure_ascii=False)
Beispiel #19
0
def PermissionsMenus():
    if request.method == 'GET':
        data = request.values
        try:
            MenuName = data.get("MenuName")
            MenuType = data.get("MenuType")
            if MenuName == None:
                MenuNames = db_session.query(Permission.MenuName).filter(Permission.WorkNumber == current_user.WorkNumber, Permission.MenuType == MenuType).all()
            else:
                ParentNode = db_session.query(ModulMenus.ID).filter(ModulMenus.ModulMenuName == MenuName).first()
                pmenus = db_session.query(ModulMenus.ModulMenuName).filter(ModulMenus.ParentNode == ParentNode,ModulMenus.MenuType == MenuType).all()
                cmenus = db_session.query(Permission.MenuName).filter(Permission.WorkNumber == current_user.WorkNumber).all()
                MenuNames = list(set(pmenus).intersection(set(cmenus)))
            dir = []
            for mn in MenuNames:
                meu = db_session.query(ModulMenus).filter(ModulMenus.ModulMenuName == mn).first()
                dir.append(meu)
            if dir:
                dir = sorted(dir, key=lambda aa: aa.ID)
            return json.dumps(dir, cls=AlchemyEncoder, ensure_ascii=False)
        except Exception as e:
            db_session.rollback()
            print(e)
            logger.error(e)
            insertSyslog("error", "添加用户报错Error:" + str(e), current_user.Name)
            return json.dumps([{"status": "Error:" + str(e)}], cls=AlchemyEncoder, ensure_ascii=False)
Beispiel #20
0
def menuToUser():
    if request.method == 'GET':
        data = request.values  # 返回请求中的参数和form
        try:
            # 获取菜单和用户并存入数据库
            role_id = data['role_id']  # 获取角色ID
            if role_id is None:
                return
            menus = db_session.query(Menu).join(Role_Menu, isouter=True).filter_by(Role_ID=id).all()
            if menus:
                db_session.delete(menus)
                db_session.commit()
            menu_id = data['menu_id'] # 获取菜单ID
            if menu_id is None:
                return
            menu_id = re.findall(r'\d+\.?\d*', menu_id)
            for r in menu_id:
                role = db_session.query(Role).filter_by(ID=role_id).first()
                menu = db_session.query(Menu).filter_by(ID=r).first()
                # 将菜单ID和角色ID存入User_Role
                menu.roles.append(role)
                db_session.add(menu)
                db_session.commit()
            # 存入数据库后跳转到权限分配页面
            return redirect(url_for("roleright"))
        except Exception as e:
            print(e)
            logger.error(e)
            insertSyslog("error", "权限分配下为角色添加权限Error:" + str(e), current_user.Name)
            return json.dumps([{"status": "Error:" + str(e)}], cls=AlchemyEncoder, ensure_ascii=False)
Beispiel #21
0
def BatchInfoDetailSearch():
    if request.method == 'GET':
        data = request.values
        try:
            jsonstr = json.dumps(data.to_dict())
            if len(jsonstr) > 10:
                pages = int(data.get("offset"))
                rowsnumber = int(data.get("limit"))
                inipage = pages * rowsnumber + 0
                endpage = pages * rowsnumber + rowsnumber
                BatchNum = data.get('BatchNum')
                total = db_session.query(BatchInfoDetail).filter(
                    BatchInfoDetail.BatchNum == BatchNum).count()
                oclass = db_session.query(BatchInfoDetail).filter(
                    BatchInfoDetail.BatchNum ==
                    BatchNum).all()[inipage:endpage]
                jsonoclass = json.dumps(oclass,
                                        cls=AlchemyEncoder,
                                        ensure_ascii=False)
                return '{"total"' + ":" + str(
                    total) + ',"rows"' + ":\n" + jsonoclass + "}"
        except Exception as e:
            print(e)
            logger.error(e)
            insertSyslog("error", "设备建模查询报错Error:" + str(e), current_user.Name)
Beispiel #22
0
def allrolesFind():
    if request.method == 'GET':
        data = request.values
        try:
            json_str = json.dumps(data.to_dict())
            if len(json_str) > 10:
                pages = int(data.get("offset"))  # 页数
                rowsnumber = int(data.get("limit"))  # 行数
                inipage = pages * rowsnumber + 0  # 起始页
                endpage = pages * rowsnumber + rowsnumber  # 截止页
                total = db_session.query(func.count(Role.ID)).scalar()
                roles = db_session.query(Role).all()[inipage:endpage]
                # ORM模型转换json格式
                jsonroles = json.dumps(roles,
                                       cls=AlchemyEncoder,
                                       ensure_ascii=False)
                jsonroles = '{"total"' + ":" + str(
                    total) + ',"rows"' + ":\n" + jsonroles + "}"
                return jsonroles
        except Exception as e:
            print(e)
            logger.error(e)
            insertSyslog("error", "查询角色列表报错Error:" + str(e), current_user.Name)
            return json.dumps([{
                "status": "Error:" + string(e)
            }],
                              cls=AlchemyEncoder,
                              ensure_ascii=False)
Beispiel #23
0
def selectrolebyuser():
    '''
    根据用户查询角色
    :return:
    '''
    if request.method == 'GET':
        data = request.values
        try:
            dir = {}
            UserID = data.get("UserID")
            pids = db_session.query(RoleUser).filter(
                RoleUser.UserID == int(UserID)).all()
            perids_list = []
            for pid in pids:
                perids_list.append(pid.RoleID)
            if len(perids_list) > 0:
                existingRows = db_session.query(Role).filter(
                    Role.ID.in_(perids_list)).all()
                dir["existingRows"] = existingRows
            else:
                dir["existingRows"] = []
            notHaveRows = db_session.query(Role).filter().all()
            dir["notHaveRows"] = notHaveRows
            return json.dumps(dir, cls=AlchemyEncoder, ensure_ascii=False)
        except Exception as e:
            print(e)
            logger.error(e)
            insertSyslog("error", "根据用户查询角色Error:" + str(e), current_user.Name)
Beispiel #24
0
def AuditTraceSelecct():
    if request.method == 'GET':
        data = request.values  # 返回请求中的参数和form
        try:
            json_str = json.dumps(data.to_dict())
            if len(json_str) > 10:
                pages = int(data.get("offset"))  # 页数
                rowsnumber = int(data.get("limit"))  # 行数
                inipage = pages * rowsnumber + 0  # 起始页
                endpage = pages * rowsnumber + rowsnumber  # 截止页
                startTime = data['startTime']  # 开始时间
                endTime = data['endTime']  # 结束时间
                if startTime == "" and endTime == "":
                    total = db_session.query(AuditTrace).count()
                    syslogs = db_session.query(AuditTrace).order_by(desc("ReviseDate")).all()[inipage:endpage]
                elif startTime != "" and endTime == "":
                    nowTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
                    total = db_session.query(AuditTrace).filter(AuditTrace.ReviseDate.between(startTime, nowTime)).count()
                    syslogs = db_session.query(AuditTrace).filter(
                        SysLog.OperationDate.between(startTime, nowTime)).order_by(desc("ReviseDate")).all()[
                              inipage:endpage]
                else:
                    total = db_session.query(AuditTrace).filter(AuditTrace.ReviseDate.between(startTime, endTime)).count()
                    syslogs = db_session.query(AuditTrace).filter(
                        AuditTrace.ReviseDate.between(startTime, endTime)).order_by(desc("OperationDate")).all()[
                              inipage:endpage]
                jsonsyslogs = json.dumps(syslogs, cls=AlchemyEncoder, ensure_ascii=False)
                jsonsyslogs = '{"total"' + ":" + str(total) + ',"rows"' + ":\n" + jsonsyslogs + "}"
                return jsonsyslogs
        except Exception as e:
            print(e)
            logger.error(e)
            return json.dumps([{"status": "Error:" + str(e)}], cls=AlchemyEncoder, ensure_ascii=False)
Beispiel #25
0
def make_model():
    if request.method == 'POST':
        data = request.values
        try:
            jsonstr = json.dumps(data.to_dict())
            return autocode.make_model_main(data)
        except Exception as e:
            print(e)
            logger.error(e)
Beispiel #26
0
def BatchSearch():
    if request.method == 'GET':
        data = request.values
        try:
            json_str = json.dumps(data.to_dict())
            if len(json_str) > 2:
                BatchNum = data.get("BatchNum")
                Name = data.get("Name")
                dic = {}
                oclass = db_session.query(BatchInfo).filter(
                    BatchInfo.BatchNum == BatchNum).first()
                if Name == "提取":
                    if oclass.PUIDLineName == "篮式":
                        PUID = "1"
                    elif oclass.PUIDLineName == "搅拌":
                        PUID = "3"
                    eqps = db_session.query(
                        ElectronicBatchTwo.EQPID).distinct().filter(
                            ElectronicBatchTwo.BatchID == BatchNum,
                            ElectronicBatchTwo.PDUnitRouteID == PUID).order_by(
                                ("EQPID")).all()
                    j = 1
                    for i in eqps:
                        EQPName = db_session.query(Equipment.EQPName).filter(
                            Equipment.ID == i[0]).first()
                        btss = db_session.query(BatchType).filter(
                            BatchType.Descrip.like("%" + oclass.PUIDLineName +
                                                   "%")).all()
                        for bt in btss:
                            type = bt.Type
                            if type == "_Batch_LS_Action01" or type == "_Batch_JB_Action01":
                                dic[type + "_" + str(j)] = EQPName[0]
                            else:
                                ret = queryvalue(BatchNum, int(i[0]),
                                                 bt.Descrip)
                                dic[type + "_" + str(j) + "_1"] = ret[0]
                                dic[type + "_" + str(j) + "_2"] = ret[1]
                        j = j + 1
                    dic["BatchNum"] = oclass.BatchNum
                    dic["MedicinalType"] = oclass.MedicinalType
                    dic["BrandName"] = oclass.BrandName
                    return json.dumps(dic,
                                      cls=AlchemyEncoder,
                                      ensure_ascii=False)
                else:
                    return ""
        except Exception as e:
            print(e)
            logger.error(e)
            insertSyslog("error", "电子批记录查询报错Error:" + str(e),
                         current_user.Name)
            return json.dumps("电子批记录查询",
                              cls=AlchemyEncoder,
                              ensure_ascii=False)
Beispiel #27
0
def SelectRoles():
    if request.method == 'GET':
        try:
            data = getRoleList(id=0)
            jsondata = json.dumps(data, cls=AlchemyEncoder, ensure_ascii=False)
            return jsondata.encode("utf8")
        except Exception as e:
            print(e)
            logger.error(e)
            insertSyslog("error", "查询权限分配下的角色列表报错Error:" + str(e), current_user.Name)
            return json.dumps([{"status": "Error:" + str(e)}], cls=AlchemyEncoder, ensure_ascii=False)
Beispiel #28
0
def MyOpFind():
    if request.method == 'GET':
        try:
            data = getMyOP(id=0)
            return json.dumps(data, cls=AlchemyEncoder, ensure_ascii=False)
        except Exception as e:
            print(e)
            logger.error(e)
            return json.dumps([{
                "status": "Error:" + str(e)
            }],
                              cls=AlchemyEncoder,
                              ensure_ascii=False)
Beispiel #29
0
def userList():
    # 获取用户列表
    if request.method == 'GET':
        data = request.values  # 返回请求中的参数和form
        # 默认返回所有用户
        ID = data['ID']
        if ID == '':
            try:
                json_str = json.dumps(data.to_dict())
                if len(json_str) > 10:
                    pages = int(data.get("offset"))  # 页数
                    rowsnumber = int(data.get("limit"))  # 行数
                    inipage = pages * rowsnumber + 0  # 起始页
                    endpage = pages * rowsnumber + rowsnumber  # 截止页
                    total = db_session.query(User).count()
                    users_data = db_session.query(User)[inipage:endpage]
                    # ORM模型转换json格式
                    jsonusers = json.dumps(users_data, cls=AlchemyEncoder, ensure_ascii=False)
                    jsonusers = '{"total"' + ":" + str(total) + ',"rows"' + ":\n" + jsonusers + "}"
                    return jsonusers.encode("utf8")
            except Exception as e:
                print(e)
                logger.error(e)
                insertSyslog("error", "查询权限分配下的用户列表报错Error:" + str(e), current_user.Name)
                return json.dumps([{"status": "Error:" + str(e)}], cls=AlchemyEncoder, ensure_ascii=False)
        if ID != '':
            data = request.values  # 返回请求中的参数和form
            try:
                json_str = json.dumps(data.to_dict())
                if len(json_str) > 10:
                    pages = int(data['page'])  # 页数
                    rowsnumber = int(data['rows'])  # 行数
                    inipage = (pages - 1) * rowsnumber + 0  # 起始页
                    endpage = (pages - 1) * rowsnumber + rowsnumber  # 截止页
                    # 通过角色ID获取当前角色对应的用户
                    role_id = data['ID']
                    role_name= db_session.query(Role.RoleName).filter_by(ID=role_id).first()
                    if role_name is None:  # 判断当前角色是否存在
                        return
                    total = db_session.query(User).filter_by(RoleName=role_name).count()
                    users_data = db_session.query(User).filter_by(RoleName=role_name).all()[
                                 inipage:endpage]
                    # ORM模型转换json格式
                    jsonusers = json.dumps(users_data, cls=AlchemyEncoder, ensure_ascii=False)
                    jsonusers = '{"total"' + ":" + str(total) + ',"rows"' + ":\n" + jsonusers + "}"
                    return jsonusers
            except Exception as e:
                print(e)
                logger.error(e)
                insertSyslog("error", "通过点击角色查询用户报错Error:" + str(e), current_user.Name)
                return json.dumps([{"status": "Error:" + str(e)}], cls=AlchemyEncoder, ensure_ascii=False)
Beispiel #30
0
def myenterprise():
    if request.method == 'GET':
        try:
            return json.dumps(getMyEnterprise(id=0),
                              cls=AlchemyEncoder,
                              ensure_ascii=False)
        except Exception as e:
            print(e)
            logger.error(e)
            return json.dumps([{
                "status": "Error:" + str(e)
            }],
                              cls=AlchemyEncoder,
                              ensure_ascii=False)