Exemple #1
0
def selectpermissionbyuser():
    '''
    根据用户查询权限
    :return:
    '''
    if request.method == 'GET':
        data = request.values
        try:
            userid = db_session.query(User.ID).filter(
                User.WorkNumber == current_user.WorkNumber).first()[0]
            rolecos = db_session.query(RoleUser).filter(
                RoleUser.UserID == userid).all()
            permission_list = []
            for ro in rolecos:
                rps = db_session.query(RolePermission).filter(
                    RolePermission.RoleID == ro.RoleID).all()
                for rp in rps:
                    permission_list.append(rp.PermissionName)
            return json.dumps({
                "code": "200",
                "message": "请求成功",
                "data": {
                    "total": len(permission_list),
                    "rows": permission_list
                }
            })
        except Exception as e:
            print(e)
            logger.error(e)
            insertSyslog("error", "根据用户查询权限Error:" + str(e), current_user.Name)
            return {
                "code": "500",
                "message": "请求错误",
                "data": "根据用户查询权限报错Error:" + str(e)
            }
Exemple #2
0
def getMenuList(user_menus, id=0):
    sz = []
    try:
        menus = db_session.query(ModulMenus).filter_by(ParentNode=id).all()
        for obj in menus:
            if obj.ParentNode == id:
                sz.append({
                    "id": obj.ID,
                    "text": obj.ModulMenuName,
                    "ModulMenuName": obj.ModulMenuName,
                    "MenuType": obj.MenuType,
                    "ModulMenuCode": obj.ModulMenuCode,
                    "state": trueOrFalse(obj, user_menus),
                    "nodes": getMenuList(user_menus, obj.ID)
                })
        return sz
    except Exception as e:
        print(e)
        insertSyslog("error", "查询权限分配下的功能模块列表Error:" + str(e),
                     current_user.Name)
        return json.dumps([{
            "status": "Error:" + str(e)
        }],
                          cls=AlchemyEncoder,
                          ensure_ascii=False)
def selectUserShiftsGroup():
    '''
    根据用户查班组
    :return:
    '''
    if request.method == 'GET':
        data = request.values
        try:
            dir = {}
            userID = data.get("userID")
            pids = db_session.query(UserShiftsGroup).filter(
                UserShiftsGroup.UserID == int(userID)).all()
            perids_list = []
            for pid in pids:
                perids_list.append(pid.ShiftsGroupID)
            if len(perids_list) > 0:
                existingRows = db_session.query(ShiftsGroup).filter(
                    ShiftsGroup.ID.in_(perids_list)).all()
                dir["existingRows"] = existingRows
            else:
                dir["existingRows"] = []
            notHaveRows = db_session.query(ShiftsGroup).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)
Exemple #4
0
def selectpermissionbyrole():
    '''
    根据角色查询权限
    :return:
    '''
    if request.method == 'GET':
        data = request.values
        try:
            dir = {}
            roleID = data.get("roleID")
            pids = db_session.query(RolePermission).filter(
                RolePermission.RoleID == int(roleID)).all()
            perids_list = []
            for pid in pids:
                perids_list.append(pid.PermissionID)
            if len(perids_list) > 0:
                existingRows = db_session.query(Permission).filter(
                    Permission.ID.in_(perids_list)).all()
                dir["existingRows"] = existingRows
            else:
                dir["existingRows"] = []
            notHaveRows = db_session.query(Permission).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)
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)
Exemple #6
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)
Exemple #7
0
def SelectParentMenus():
    if request.method == 'GET':
        data = request.values
        try:
            pages = int(data.get("offset"))  # 页数
            rowsnumber = int(data.get("limit"))  # 行数
            inipage = pages * rowsnumber + 0  # 起始页
            endpage = pages * rowsnumber + rowsnumber  # 截止页
            total = db_session.query(ModulMenus).filter(
                ModulMenus.MenuType.in_(("系统级", "模块级"))).count()
            oclass = db_session.query(ModulMenus).filter(
                ModulMenus.MenuType.in_(("系统级", "模块级"))).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)
            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)
def selectAll():
    if request.method == 'GET':
        try:
            return json.dumps(getMyOrganizationChildrenMap(id=0), cls=AlchemyEncoder, ensure_ascii=False)
        except Exception as e:
            print(e)
            insertSyslog("error", "查询组织结构报错Error:" + str(e), current_user.Name)
            return json.dumps([{"status": "Error:" + str(e)}], cls=AlchemyEncoder, ensure_ascii=False)
def getMyEnterprise(id=0):
    sz = []
    try:
        orgs = db_session.query(Organization).filter().all()
        for obj in orgs:
            sz.append({"id": obj.ID, "text": obj.OrganizationName, "group": obj.ParentNode})
        return sz
    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)
Exemple #11
0
def paiban():
    if request.method == 'GET':
        data = request.values
        try:
            dir = {}
            StartClass = data.get("StartClass")
            Month = data.get("Month")
            sfs = db_session.query(ShiftsClass).filter().order_by(
                ("ShiftsClassNum")).all()
            sum = None
            new_list = ""
            for sf in sfs:
                if sf.ShiftsClassName == StartClass:
                    sum = None if sf.ShiftsClassNum is None else float(
                        sf.ShiftsClassNum)
            if sum:
                for i in sfs:
                    if (0 if sf.ShiftsClassNum is None else float(
                            sf.ShiftsClassNum)) >= sum:
                        if i == 1:
                            new_list = i.ShiftsClassName
                        else:
                            new_list = new_list + "," + i.ShiftsClassName
                for i in sfs:
                    if (0 if sf.ShiftsClassNum is None else float(
                            sf.ShiftsClassNum)) < sum:
                        new_list = new_list + "," + i.ShiftsClassName
            re_date = getMonthFirstDayAndLastDay(Month[0:4], int(Month[5:7]))
            for t in range(1, int(re_date[1][8:10])):
                rest = db_session.query(plantCalendarScheduling).filter(
                    plantCalendarScheduling.start == Month + "-" +
                    ("0" + str(t) if t < 10 else str(t)),
                    plantCalendarScheduling.title == "休息")
                if rest:
                    continue
                if t == 1:
                    pcs = plantCalendarScheduling()
                    pcs.color = "#FFA500"
                    pcs.title = new_list
                    pcs.start = Month + "-" + ("0" +
                                               str(t) if t < 10 else str(t))
                    pcs.end = ""
                    db_session.commit()
            return json.dumps(dir, cls=AlchemyEncoder, ensure_ascii=False)
        except Exception as e:
            print(e)
            insertSyslog("error", "日历排班报错Error:" + str(e), current_user.Name)
            return json.dumps([{
                "status": "Error:" + str(e)
            }],
                              cls=AlchemyEncoder,
                              ensure_ascii=False)
Exemple #12
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()
                count = db_session.query(ModulMenus).count()
                return {
                    "code": "200",
                    "message": "请求成功",
                    "data": {
                        "total": count,
                        "rows": oclass
                    }
                }
            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 {
                "code": "200",
                "message": "请求成功",
                "data": {
                    "total": len(dic),
                    "rows": dic
                }
            }
        except Exception as e:
            print(e)
            logger.error(e)
            insertSyslog("error", "菜单权限查询报错Error:" + str(e), current_user.Name)
            return {
                "code": "500",
                "message": "请求错误",
                "data": "菜单权限查询报错Error:" + str(e)
            }
Exemple #13
0
def syslogsFindByDate():
    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.get('startTime')  # 开始时间
                endTime = data.get('endTime')  # 结束时间
                if startTime == "" and endTime == "":
                    total = db_session.query(SysLog).count()
                    syslogs = db_session.query(SysLog).order_by(
                        desc("OperationDate")).all()[inipage:endpage]
                elif startTime != "" and endTime == "":
                    nowTime = datetime.datetime.now().strftime(
                        '%Y-%m-%d %H:%M:%S')
                    total = db_session.query(SysLog).filter(
                        SysLog.OperationDate.between(startTime,
                                                     nowTime)).count()
                    syslogs = db_session.query(SysLog).filter(
                        SysLog.OperationDate.between(
                            startTime, nowTime)).order_by(
                                desc("OperationDate")).all()[inipage:endpage]
                else:
                    total = db_session.query(SysLog).filter(
                        SysLog.OperationDate.between(startTime,
                                                     endTime)).count()
                    syslogs = db_session.query(SysLog).filter(
                        SysLog.OperationDate.between(
                            startTime, endTime)).order_by(
                                desc("OperationDate")).all()[inipage:endpage]
                return {
                    "code": "200",
                    "message": "请求成功",
                    "data": {
                        "total": total,
                        "rows": syslogs
                    }
                }
        except Exception as e:
            print(e)
            logger.error(e)
            insertSyslog("error", "查询日志报错Error:" + str(e), current_user.Name)
            return {
                "code": "500",
                "message": "请求错误",
                "data": "查询日志报错Error:" + str(e)
            }
def deleteRedisBykey(data):
    '''通过key查询增加修改Redis单个的值'''
    try:
        key = data.get("key")
        redis_conn.delete(key)
        return json.dumps("OK", cls=AlchemyEncoder, ensure_ascii=False)
    except Exception as e:
        print(e)
        insertSyslog("error", "删除redis单个值报错Error:" + str(e), current_user.Name)
        return json.dumps([{
            "status": "Error:" + str(e)
        }],
                          cls=AlchemyEncoder,
                          ensure_ascii=False)
Exemple #15
0
def selectRedisBykey(data):
    '''通过key查询增加修改Redis单个的值'''
    try:
        key = data.get("key")
        value = redis_conn.hget(connect_db.REDIS_TABLENAME, key)
        return json.dumps(value, cls=AlchemyEncoder, ensure_ascii=False)
    except Exception as e:
        print(e)
        insertSyslog("error", "通过key查询Redis单个的值报错Error:" + str(e),
                     current_user.Name)
        return json.dumps([{
            "status": "Error:" + str(e)
        }],
                          cls=AlchemyEncoder,
                          ensure_ascii=False)
def addUpdateRedisBykey(data):
    '''通过key查询增加修改Redis单个的值'''
    try:
        key = data.get("key")
        value = data.get("value")
        redis_conn.hset(db_operate.REDIS_TABLENAME, key, value)
        return json.dumps("OK", cls=AlchemyEncoder, ensure_ascii=False)
    except Exception as e:
        print(e)
        insertSyslog("error", "增加redis单个值报错Error:" + str(e), current_user.Name)
        return json.dumps([{
            "status": "Error:" + str(e)
        }],
                          cls=AlchemyEncoder,
                          ensure_ascii=False)
Exemple #17
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)
Exemple #18
0
def keep_record(p):
    """
    查看保养记录
    :param p: 设备号
    :return: 该设备的所有保养记录记录
    """
    try:
        # 当前页码
        page = int(request.values.get('offset'))
        # 每页多少条
        per_page = int(request.values.get('limit'))

        query_data = db_session.query(KeepRecord).order_by(
            KeepRecord.ApplyTime.desc()).all()
        # data_list = [item for item in query_data]
        result = []
        for data in query_data:
            if p in data.EquipmentCode:
                result.append(data)
        result_data = result[(page - 1) * per_page:page * per_page]
        return json.dumps(
            {
                'code': '10001',
                'message': '操作成功',
                'data': {
                    'rows': result_data,
                    'total': len(result)
                }
            },
            cls=AlchemyEncoder,
            ensure_ascii=False)
        # total = db_session.query(KeepRecord).filter_by(EquipmentCode=p).count()
        # data = db_session.query(KeepRecord).filter(KeepRecord.EquipmentCode == p).order_by(
        #     KeepRecord.ApplyTime.desc()).limit(per_page).offset((page - 1) * per_page)
        # return json.dumps({'code': '10001', 'message': '操作成功', 'data': {'rows': data.all(), 'total': total}},
        #                   cls=AlchemyEncoder, ensure_ascii=False)
    except Exception as e:
        logger.error(e)
        insertSyslog("error", "保养记录查询错误:" + str(e), current_user.Name)
        return json.dumps({
            'code': '20002',
            'message': str(e)
        },
                          cls=AlchemyEncoder,
                          ensure_ascii=False)
Exemple #19
0
def saveuserusershiftsgroup():
    '''
    用户添加班组
    :return:
    '''
    if request.method == 'POST':
        data = request.values
        try:
            userID = data.get("userID")
            shiftsgroupIDs = data.get("shiftsgroupIDs")
            if shiftsgroupIDs:
                shiftsgroupIDs = eval(shiftsgroupIDs)
            userclass = db_session.query(User).filter(
                User.ID == int(userID)).first()
            sql = "delete from usershiftsgroup where UserID = " + userID
            db_session.execute(sql)
            db_session.commit()
            for pid in shiftsgroupIDs:
                shiftsgroupcalss = db_session.query(ShiftsGroup).filter(
                    ShiftsGroup.ID == int(pid)).first()
                rpclas = db_session.query(UserShiftsGroup).filter(
                    UserShiftsGroup.UserID == userclass.ID,
                    UserShiftsGroup.ShiftsGroupID ==
                    shiftsgroupcalss.ID).first()
                if not rpclas:
                    rp = UserShiftsGroup()
                    rp.UserID = userclass.ID
                    rp.Name = userclass.Name
                    rp.ShiftsGroupID = shiftsgroupcalss.ID
                    rp.ShiftsGroupName = shiftsgroupcalss.ShiftsGroupName
                    db_session.add(rp)
                    db_session.commit()
            return json.dumps({
                "code": "200",
                "message": "请求成功"
            },
                              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)
def systemcollecting():
    '''
    系统体检
    :return:
    '''
    if request.method == 'GET':
        data = request.values
        try:
            dir = {}
            pool = redis.ConnectionPool(host=db_operate.REDIS_HOST)
            redis_conn = redis.Redis(connection_pool=pool,
                                     password=db_operate.REDIS_PASSWORD,
                                     decode_responses=True)
            dir["name"] = "采集服务"
            dir["startTime"] = returnb(
                redis_conn.hget(db_operate.REDIS_TABLENAME,
                                "collecting_server_start"))
            dir["endTime"] = returnb(
                redis_conn.hget(db_operate.REDIS_TABLENAME,
                                "collecting_server_end"))
            dir["successNumber"] = returnb(
                redis_conn.hget(db_operate.REDIS_TABLENAME,
                                "collecting_server_runcount"))
            dir["errorNumber"] = returnb(
                redis_conn.hget(db_operate.REDIS_TABLENAME,
                                "collecting_server_failcount"))
            dir["totalNumber"] = int(
                returnb(
                    redis_conn.hget(
                        db_operate.REDIS_TABLENAME,
                        "collecting_server_runcount"))) + int(
                            returnb(
                                redis_conn.hget(
                                    db_operate.REDIS_TABLENAME,
                                    "collecting_server_failcount")))
            dir["state"] = returnb(
                redis_conn.hget(db_operate.REDIS_TABLENAME,
                                "collecting_server_status"))
            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)
Exemple #21
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({
                "code": "200",
                "message": "请求成功"
            },
                              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)
Exemple #22
0
def saveroleuser():
    '''
    用户添加角色
    :return:
    '''
    if request.method == 'POST':
        data = request.values
        try:
            UserID = data.get("UserID")
            RoleIDs = data.get("RoleIDs")
            if RoleIDs:
                RoleIDs = eval(RoleIDs)
            userclass = db_session.query(User).filter(
                User.ID == int(UserID)).first()
            sql = "delete from RoleUser where UserID = " + UserID
            db_session.execute(sql)
            db_session.commit()
            for pid in RoleIDs:
                rolecalss = db_session.query(Role).filter(
                    Role.ID == int(pid)).first()
                rpclas = db_session.query(RoleUser).filter(
                    RoleUser.UserID == userclass.ID,
                    RoleUser.RoleID == rolecalss.ID).first()
                if not rpclas:
                    rp = RoleUser()
                    rp.UserID = userclass.ID
                    rp.UserName = userclass.Name
                    rp.RoleID = rolecalss.ID
                    rp.RoleName = rolecalss.RoleName
                    db_session.add(rp)
                    db_session.commit()
            return json.dumps({
                "code": "200",
                "message": "请求成功"
            },
                              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)
Exemple #23
0
def keep_plans():
    """保养计划"""
    try:
        json_data = request.get_json()
        # equipments = ['XXF-2', 'XXF-1', 'PYF-1']
        equipments = json_data.get('EquipmentCode')
        if len(equipments) == 1:
            equipment_code = equipments[0]
        else:
            equipment_code = '  '.join(equipments)
        work_time = add_date(json_data.get('WeekTime'),
                             json_data.get('StartTime'))
        work_type = json_data.get('Type')
        week_time = '单次' if work_type == '单次' else json_data.get('WeekTime')
        data = KeepPlan(EquipmentCode=equipment_code,
                        No=get_no(json_data.get('ApplyTime')),
                        Worker=current_user.Name,
                        ApplyTime=json_data.get('ApplyTime'),
                        Type=json_data.get('Type'),
                        StartTime=json_data.get('StartTime'),
                        Describe=json_data.get('Describe'),
                        WorkTime=work_time,
                        WeekTime=week_time)
        db_session.add(data)
        db_session.commit()
        db_session.close()
        return json.dumps({
            'code': '10001',
            'message': '操作成功'
        },
                          cls=AlchemyEncoder,
                          ensure_ascii=False)
    except Exception as e:
        logger.error(e)
        insertSyslog("error", "保养计划表添加错误:" + str(e), current_user.Name)
        return json.dumps({
            'code': '20002',
            'message': str(e)
        },
                          cls=AlchemyEncoder,
                          ensure_ascii=False)
def selectTree():
    '''查询树形结构'''
    data = request.values
    if request.method == 'GET':
        try:
            ParentCode = data.get("ParentCode")  #父节点字段名
            tableName = data.get("tableName")  #表名
            Name = data.get("Name")  #展示的字段名
            Code = data.get("Code")  #展示的字段code
            id = 0
            return json.dumps(getTreeChildrenMap(id, ParentCode, tableName,
                                                 Name, Code),
                              cls=AlchemyEncoder,
                              ensure_ascii=False)
        except Exception as e:
            print(e)
            insertSyslog("error", "查询树形结构报错Error:" + str(e), current_user.Name)
            return json.dumps([{
                "status": "Error:" + str(e)
            }],
                              cls=AlchemyEncoder,
                              ensure_ascii=False)
Exemple #25
0
def getRoleList(id=0):
    sz = []
    try:
        roles = db_session.query(Role).filter().all()
        for obj in roles:
            if obj.ParentNode == id:
                sz.append({
                    "id": obj.ID,
                    "text": obj.RoleName,
                    "children": getRoleList(obj.ID)
                })
        srep = ',' + 'items' + ':' + '[]'
        return sz
    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)
Exemple #26
0
def menulisttree():
    if request.method == 'GET':
        data = request.values
        try:
            WorkNumber = data.get("WorkNumber")
            user_menus = []
            usermenus = db_session.query(Permission.MenuName).filter(
                Permission.WorkNumber == WorkNumber).all()
            for menu in usermenus:
                user_menus.append(menu[0])
            data = getMenuList(user_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)
Exemple #27
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)
Exemple #28
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)
Exemple #29
0
def keep_tasks():
    """保养任务表"""
    try:
        query_data = db_session.query(KeepPlan).filter_by(Status='待保养').all()
        if request.method == 'GET':
            # 每页多少条
            limit = int(request.values.get('limit', '5'))
            # 当前页
            offset = int(request.values.get('offset', '1'))
            for item in query_data:
                q = db_session.query(KeepTask).filter_by(No=item.No).first()
                if not q and get_time_stamp(item.WorkTime):
                    data = KeepTask(EquipmentCode=item.EquipmentCode,
                                    No=item.No,
                                    Worker=item.Worker,
                                    Status=item.Status,
                                    ApplyTime=item.ApplyTime,
                                    StartTime=item.StartTime,
                                    WorkTime=item.WorkTime,
                                    WeekTime=item.WeekTime,
                                    Type=item.Type)
                    db_session.add(data)
                    db_session.commit()
                # if item.Type == '单次':
                #     pass
                # db_session.delete(item)
                # db_session.commit()
            data = db_session.query(KeepTask).order_by(
                KeepTask.ApplyTime.desc()).limit(limit).offset(
                    (offset - 1) * limit)
            total = db_session.query(KeepTask).count()
            return json.dumps(
                {
                    'code': '10001',
                    'message': '操作成功',
                    'data': {
                        'rows': data.all(),
                        'total': total
                    }
                },
                cls=AlchemyEncoder,
                ensure_ascii=False)
        if request.method == 'POST':
            json_data = request.values
            no = json_data.get('No')
            end_time = json_data.get('EndTime')
            content = json_data.get('Content')
            item = db_session.query(KeepTask).filter_by(No=no).first()
            data = KeepRecord(EquipmentCode=item.EquipmentCode,
                              No=no,
                              Worker=item.Worker,
                              Status='已完成',
                              Type=item.Type,
                              KeepWorker=current_user.Name,
                              ApplyTime=item.ApplyTime,
                              StartTime=item.StartTime,
                              Describe=item.Describe,
                              Content=content,
                              WeekTime=item.WeekTime,
                              EndTime=end_time)
            db_session.delete(item)
            db_session.commit()
            keep_plan = db_session.query(KeepPlan).filter_by(No=no).first()
            if keep_plan and keep_plan.Type == '周期':
                keep_plan.WorkTime = add_date(keep_plan.WeekTime,
                                              keep_plan.WorkTime)
                db_session.add_all([data, keep_plan])
                db_session.commit()
                db_session.close()
                return json.dumps({
                    'code': '10001',
                    'message': '操作成功'
                },
                                  cls=AlchemyEncoder,
                                  ensure_ascii=False)
            else:
                db_session.delete(keep_plan)
                db_session.add(data)
                db_session.commit()
                db_session.close()
            return json.dumps({
                'code': '10001',
                'message': '操作成功'
            },
                              cls=AlchemyEncoder,
                              ensure_ascii=False)
    except Exception as e:
        logger.error(e)
        insertSyslog("error", "保养任务表修改错误:" + str(e), current_user.Name)
        return json.dumps({
            'code': '20002',
            'message': str(e)
        },
                          cls=AlchemyEncoder,
                          ensure_ascii=False)