Exemple #1
0
def queryRtspServerInfo(request):
    """
    Rtsp服务信息--查询
    :return:
    """
    try:
        reqBody = json.loads(request.body)
    except Exception as err:
        return Response({"result": 16003001, "msg": getErrMsgByCode(16003001, err)}, content_type="application/json")

    if reqbody_verify(reqBody, err_code=16003001) is None:
        pass
    else:
        return reqbody_verify(reqBody, err_code=16003001)

    tokenInfo = tokenDecode(reqBody["token"])
    serverID = None

    if tokenInfo["role"] >= 10:
        if "id" in reqBody:
            serverID = reqBody["id"]
    else:
        if "id" in reqBody:
            serverID = reqBody["id"]
        else:
            return Response({"result": 16003005, "msg": getErrMsgByCode(16003005, None)},  content_type="application/json")

    resData = []

    try:
        if serverID is None:
            sipServerObjs = RTSPServerDB.objects.all()
        else:
            sipServerObjs = RTSPServerDB.objects.filter(id=serverID)

        for item in sipServerObjs:
            serverObj = {}

            serverObj["id"] = item.id
            serverObj["name"] = item.name
            serverObj["ip"] = item.ip
            serverObj["port"] = item.port

            serverObj["user"] = item.user
            serverObj["password"] = item.password
            serverObj["channels"] = item.channels
            serverObj["type"] = item.type
            serverObj["enable"] = item.enable

            resData.append(serverObj)
    except Exception as err:
        return Response({"result": 16003006, "msg": getErrMsgByCode(16003006, err)}, content_type="application/json")

    return Response({"result": 0, "msg": "OK", "data": resData}, content_type="application/json")
Exemple #2
0
def queryDeptInfo(request):
    """
    部门信息--查询
    :return:
    """
    try:
        reqBody = json.loads(request.body)
    except Exception as err:
        return Response(
            {
                "result": 11003001,
                "msg": getErrMsgByCode(11003001, err)
            },
            content_type="application/json")

    if reqbody_verify(reqBody, err_code=11003001) is None:
        pass
    else:
        return reqbody_verify(reqBody, err_code=11003001)

    resData = {}

    tokenInfo = tokenDecode(reqBody["token"])
    deptID = tokenInfo["dept"]

    try:
        deptInfo = deptDB.objects.get(id=deptID)

        resData["id"] = deptInfo.id
        resData["name"] = deptInfo.name
        resData["pid"] = deptInfo.pid
        resData["path"] = deptInfo.path
        resData["enable"] = deptInfo.enable
        resData["register"] = deptInfo.register

        subDeptList = []
        getSubDeptTreeList(deptID, subDeptList)

        resData["children"] = subDeptList
    except Exception as err:
        return Response(
            {
                "result": 11003005,
                "msg": getErrMsgByCode(11003005, err)
            },
            content_type="application/json")

    addOperationLog(tokenInfo["login"], "查询部门信息", "查询部门信息成功", "查询部门信息成功")
    return Response({
        "result": 0,
        "msg": "OK",
        "data": resData
    },
                    content_type="application/json")
Exemple #3
0
def userInfoModify(request):
    """
    用户信息--修改
    :return:
    """
    try:
        reqBody = json.loads(request.body)
    except Exception as err:
        return Response(
            {
                "result": 10003001,
                "msg": getErrMsgByCode(10003001, err)
            },
            content_type="application/json")

    if reqbody_verify(reqBody, err_code=10003001) is None:
        pass
    else:
        return reqbody_verify(reqBody, err_code=10003001)

    tokenInfo = tokenDecode(reqBody["token"])

    if "id" not in reqBody:
        return Response(
            {
                "result": 10003005,
                "msg": getErrMsgByCode(10003005, None)
            },
            content_type="application/json")
    else:
        userID = reqBody["id"]

    if userDB.objects.filter(id=userID).count() == 0:
        return Response(
            {
                "result": 10003006,
                "msg": getErrMsgByCode(10003006, None)
            },
            content_type="application/json")

    userPwd = None
    userName = None
    userEnable = None

    if "password" not in reqBody:
        pass
    else:
        userPwd = reqBody["password"]

    if "nickname" not in reqBody:
        pass
    else:
        userName = reqBody["nickname"]

    if "enable" not in reqBody:
        pass
    else:
        userEnable = reqBody["enable"]

    userObj = userDB.objects.get(id=userID)

    if userPwd is not None:
        userObj.password = mysql_password(userPwd)

    if userName is not None:
        userObj.nickname = userName

    if userEnable is not None:
        userObj.enable = userEnable

    savePoint = transaction.savepoint()

    try:
        userObj.save()
    except Exception as err:
        transaction.savepoint_rollback(savePoint)
        return Response(
            {
                "result": 10003007,
                "msg": getErrMsgByCode(10003007, err)
            },
            content_type="application/json")

    transaction.savepoint_commit(savePoint)

    return Response({
        "result": 0,
        "msg": "OK"
    },
                    content_type="application/json")
Exemple #4
0
def userLogout(request):
    """
    用户信息--登出
    :return:
    """
    try:
        reqBody = json.loads(request.body)
    except Exception as err:
        return Response(
            {
                "result": 10001001,
                "msg": getErrMsgByCode(10001001, err)
            },
            content_type="application/json")

    if "login" not in reqBody:
        return Response(
            {
                "result": 10001002,
                "msg": getErrMsgByCode(10001002, None)
            },
            content_type="application/json")
    else:
        loginName = reqBody["login"]

    if "token" not in reqBody:
        return Response(
            {
                "result": 10001003,
                "msg": getErrMsgByCode(10002002, None)
            },
            content_type="application/json")
    else:
        loginToken = reqBody["token"]

    tokenInfo = tokenDecode(loginToken)

    if tokenInfo is None:
        return Response(
            {
                "result": 10001004,
                "msg": getErrMsgByCode(10001004, None)
            },
            content_type="application/json")

    tokenCache = tokenQuery(loginName)

    if tokenCache != loginToken:
        return Response(
            {
                "result": 10001005,
                "msg": getErrMsgByCode(10001005, None)
            },
            content_type="application/json")

    if tokenDelete(loginName) is False:
        return Response(
            {
                "result": 10001006,
                "msg": getErrMsgByCode(10001006, None)
            },
            content_type="application/json")

    return Response({
        "result": 0,
        "msg": "OK"
    },
                    content_type="application/json")
Exemple #5
0
def queryDeptMemberInfo(request):
    """
    部门成员信息--查询
    :return:
    """
    try:
        reqBody = json.loads(request.body)
    except Exception as err:
        return Response(
            {
                "result": 11005001,
                "msg": getErrMsgByCode(11005001, err)
            },
            content_type="application/json")

    if reqbody_verify(reqBody, err_code=11005001) is None:
        pass
    else:
        return reqbody_verify(reqBody, err_code=11005001)

    tokenInfo = tokenDecode(reqBody["token"])
    if "id" not in reqBody:
        return Response(
            {
                "result": 11005005,
                "msg": getErrMsgByCode(11005005, None)
            },
            content_type="application/json")
    else:
        deptID = reqBody["id"]

    resData = []

    try:
        if int(deptID) == 1:
            memberInfoList = userDB.objects.all().order_by("position")
        else:
            memberInfoList = userDB.objects.filter(
                dept=deptID).order_by("position")

        if memberInfoList:
            for obj in memberInfoList:
                userObj = {}

                userObj["id"] = obj.id
                userObj["login"] = obj.login
                userObj["nickname"] = obj.nickname
                userObj["dept"] = obj.dept
                userObj["email"] = obj.email
                userObj["enable"] = obj.enable
                userObj["height"] = obj.height
                userObj["latitude"] = obj.latitude

                userObj["level"] = obj.level
                userObj["locate"] = obj.locate
                userObj["longitude"] = obj.longitude
                userObj["mobile"] = obj.mobile
                userObj["phone"] = obj.phone
                userObj["position"] = obj.position
                userObj["role"] = obj.role
                userObj["register"] = obj.register

                resData.append(userObj)
    except Exception as err:
        return Response(
            {
                "result": 11005006,
                "msg": getErrMsgByCode(11005006, None)
            },
            content_type="application/json")

    return Response({
        "result": 0,
        "msg": "OK",
        "data": resData
    },
                    content_type="application/json")
Exemple #6
0
def queryDeptDevice(request):
    """
    部门设备信息--查询
    :return:
    """
    try:
        reqBody = json.loads(request.body)
    except Exception as err:
        return Response(
            {
                "result": 11008001,
                "msg": getErrMsgByCode(11008001, err)
            },
            content_type="application/json")

    if reqbody_verify(reqBody, err_code=11008001) is None:
        pass
    else:
        return reqbody_verify(reqBody, err_code=11008001)

    tokenInfo = tokenDecode(reqBody["token"])

    if "id" not in reqBody:
        return Response(
            {
                "result": 11008006,
                "msg": getErrMsgByCode(11008006, None)
            },
            content_type="application/json")
    else:
        deptID = reqBody["id"]

    deptList = getSubDeptList(deptID)
    if deptList:
        deptList.insert(0, deptID)
    else:
        deptList = [].append(deptID)

    resData = {}
    try:
        ipcObjList = rtspDeviceDB.objects.filter(
            dept__in=deptList).order_by("position")
        iotObjList = iotDeviceDB.objects.filter(dept__in=deptList)

        if ipcObjList:
            ipcInfoList = []
            for ipcObj in ipcObjList:
                ipcInfo = {}
                ipcInfo["id"] = ipcObj.id
                ipcInfo["name"] = ipcObj.name
                ipcInfo["dept"] = ipcObj.dept
                ipcInfo["type"] = ipcObj.type
                ipcInfo["server"] = ipcObj.server
                ipcInfo["channel"] = ipcObj.channel
                ipcInfo["longitude"] = ipcObj.longitude
                ipcInfo["latitude"] = ipcObj.latitude
                ipcInfo["height"] = ipcObj.height
                ipcInfo["locate"] = ipcObj.locate
                ipcInfo["enable"] = ipcObj.enable

                ipcInfoList.append(ipcInfo)

            resData["ipc"] = ipcInfoList

        if iotObjList:
            iotInfoList = []
            for iotObj in iotObjList:
                iotInfo = {}
                iotInfo["id"] = iotObj.id
                iotInfo["name"] = iotObj.name
                iotInfo["dept"] = iotObj.dept
                iotInfo["code"] = iotObj.code
                iotInfo["type"] = iotObj.type
                iotInfo["type_name"] = iotObj.type_name
                iotInfo["ipc"] = iotObj.ipc
                iotInfo["generic_plan"] = iotObj.generic_plan
                iotInfo["sms_level_1"] = iotObj.sms_level_1
                iotInfo["sms_level_2"] = iotObj.sms_level_2
                iotInfo["longitude"] = iotObj.longitude
                iotInfo["latitude"] = iotObj.latitude
                iotInfo["height"] = iotObj.height
                iotInfo["locate"] = iotObj.locate
                iotInfo["enable"] = iotObj.enable

                iotInfoList.append(iotInfo)

            resData["iot"] = iotInfoList
    except Exception as err:
        return Response(
            {
                "result": 11008007,
                "msg": getErrMsgByCode(11008007, err)
            },
            content_type="application/json")

    addOperationLog(tokenInfo["login"], "查询部门设备信息", "查询部门设备信息成功", "查询部门设备信息成功")
    return Response({
        "result": 0,
        "msg": "OK",
        "data": resData
    },
                    content_type="application/json")
Exemple #7
0
def deleteDeptInfo(request):
    """
    部门信息--删除
    :return:
    """
    try:
        reqBody = json.loads(request.body)
    except Exception as err:
        return Response(
            {
                "result": 11004001,
                "msg": getErrMsgByCode(11004001, err)
            },
            content_type="application/json")

    if reqbody_verify_admin(reqBody, err_code=11004001) is None:
        pass
    else:
        return reqbody_verify_admin(reqBody, err_code=11004001)

    tokenInfo = tokenDecode(reqBody["token"])

    if "id" not in reqBody:
        return Response(
            {
                "result": 11004006,
                "msg": getErrMsgByCode(11004006, None)
            },
            content_type="application/json")
    else:
        deptID = reqBody["id"]

    subDeptIDs = getSubDeptList(deptID)

    if subDeptIDs is None:
        pass
    else:
        return Response(
            {
                "result": 11004007,
                "msg": getErrMsgByCode(11004007, None)
            },
            content_type="application/json")

    deptMemberIDs = getDeptMemeberList(deptID)

    if deptMemberIDs is None:
        pass
    else:
        return Response(
            {
                "result": 11004008,
                "msg": getErrMsgByCode(11004008, None)
            },
            content_type="application/json")

    try:
        deptObj = deptDB.objects.get(id=deptID)
        deptObj.delete()
    except Exception as err:
        return Response(
            {
                "result": 11004009,
                "msg": getErrMsgByCode(11004009, err)
            },
            content_type="application/json")

    addOperationLog(tokenInfo["login"], "删除部门信息", "删除部门信息成功", "删除部门信息成功")
    return Response({
        "result": 0,
        "msg": "OK"
    },
                    content_type="application/json")
Exemple #8
0
def modifyDeptInfo(request):
    """
    部门信息--修改
    :return:
    """
    try:
        reqBody = json.loads(request.body)
    except Exception as err:
        return Response(
            {
                "result": 11002001,
                "msg": getErrMsgByCode(11002001, err)
            },
            content_type="application/json")

    if reqbody_verify_admin(reqBody, err_code=11002001) is None:
        pass
    else:
        return reqbody_verify_admin(reqBody, err_code=11002001)

    tokenInfo = tokenDecode(reqBody["token"])

    if "id" not in reqBody:
        return Response(
            {
                "result": 11002006,
                "msg": getErrMsgByCode(11002006, None)
            },
            content_type="application/json")
    else:
        deptID = reqBody["id"]

    deptName = None
    deptPID = None
    deptEnable = None

    if "name" in reqBody:
        deptName = reqBody["name"]

    if "pid" in reqBody:
        deptPID = reqBody["pid"]

    if "enable" in reqBody:
        deptEnable = reqBody["enable"]

    deptPath = None

    if deptPID is not None:
        try:
            pDeptObj = deptDB.objects.get(id=deptPID)

            if pDeptObj.path == "/":
                deptPath = pDeptObj.path + str(deptPID)
            else:
                deptPath = pDeptObj.path + "/" + str(deptPID)
        except deptDB.DoesNotExist:
            return Response(
                {
                    "result": 11002007,
                    "msg": getErrMsgByCode(11002007, None)
                },
                content_type="application/json")

    try:
        deptObj = deptDB.objects.get(id=deptID)

        if deptName is not None:
            deptObj.name = deptName

        if deptPID is not None:
            deptObj.pid = deptPID

        if deptEnable is not None:
            deptObj.enable = deptEnable

        if deptPath is not None:
            deptObj.path = deptPath

        deptObj.save()
    except Exception as err:
        return Response(
            {
                "result": 11002008,
                "msg": getErrMsgByCode(11002008, err)
            },
            content_type="application/json")

    addOperationLog(tokenInfo["login"], "修改部门信息", "修改部门信息成功", "修改部门信息成功")
    return Response({
        "result": 0,
        "msg": "OK"
    },
                    content_type="application/json")
Exemple #9
0
def addDeptInfo(request):
    """
        部门信息--新增
        :return:
        """
    try:
        reqBody = json.loads(request.body)
    except Exception as err:
        return Response(
            {
                "result": 11001001,
                "msg": getErrMsgByCode(11001001, err)
            },
            content_type="application/json")

    if reqbody_verify_admin(reqBody, err_code=11001001) is None:
        pass
    else:
        return reqbody_verify_admin(reqBody, err_code=11001001)

    tokenInfo = tokenDecode(reqBody["token"])

    if "name" not in reqBody:
        return Response(
            {
                "result": 11001006,
                "msg": getErrMsgByCode(11001006, None)
            },
            content_type="application/json")
    else:
        deptName = reqBody["name"]

    if "pid" not in reqBody:
        return Response(
            {
                "result": 11001007,
                "msg": getErrMsgByCode(11001007, None)
            },
            content_type="application/json")
    else:
        deptPID = reqBody["pid"]

    if "enable" not in reqBody:
        return Response(
            {
                "result": 11001008,
                "msg": getErrMsgByCode(11001008, None)
            },
            content_type="application/json")
    else:
        deptEnable = reqBody["enable"]

    if "position" not in reqBody:
        deptPosition = 32767
    else:
        deptPosition = reqBody["position"]

    try:
        pDeptObj = deptDB.objects.get(id=deptPID)

        if pDeptObj.path == "/":
            deptPath = pDeptObj.path + str(deptPID)
        else:
            deptPath = pDeptObj.path + "/" + str(deptPID)
    except deptDB.DoesNotExist:
        return Response(
            {
                "result": 11001009,
                "msg": getErrMsgByCode(11001009, None)
            },
            content_type="application/json")

    try:
        deptInfo = deptDB(name=deptName,
                          pid=deptPID,
                          enable=deptEnable,
                          path=deptPath,
                          position=deptPosition)
        deptInfo.save()
    except Exception as err:
        return Response(
            {
                "result": 11001010,
                "msg": getErrMsgByCode(11001010, err)
            },
            content_type="application/json")

    addOperationLog(tokenInfo["login"], "新增部门信息", "新增部门信息成功", "新增部门信息成功")
    return Response({
        "result": 0,
        "msg": "OK"
    },
                    content_type="application/json")
Exemple #10
0
def userInfoDelete(request):
    """
    用户信息--删除
    :return:
    """
    try:
        reqBody = json.loads(request.body)
    except Exception as err:
        return Response(
            {
                "result": 10005001,
                "msg": getErrMsgByCode(10005001, err)
            },
            content_type="application/json")

    if reqbody_verify(reqBody, err_code=10005001) is None:
        pass
    else:
        return reqbody_verify(reqBody, err_code=10005001)

    tokenInfo = tokenDecode(reqBody["token"])

    if "id" not in reqBody:
        return Response(
            {
                "result": 10005005,
                "msg": getErrMsgByCode(10005005, None)
            },
            content_type="application/json")
    else:
        userID = reqBody["id"]

    if (tokenInfo["role"] < 10) or (tokenInfo["id"] == userID):
        return Response(
            {
                "result": 10005006,
                "msg": getErrMsgByCode(10005006, None)
            },
            content_type="application/json")

    try:
        userObj = userDB.objects.get(id=userID)
    except Exception as err:
        return Response(
            {
                "result": 10005007,
                "msg": getErrMsgByCode(10005007, err)
            },
            content_type="application/json")

    if userObj.login == "admin":
        return Response(
            {
                "result": 10005008,
                "msg": getErrMsgByCode(10005008, None)
            },
            content_type="application/json")

    savePoint = transaction.savepoint()

    try:
        userObj.delete()
    except Exception as err:
        transaction.savepoint_rollback(savePoint)
        return Response(
            {
                "result": 10005009,
                "msg": getErrMsgByCode(10005009, err)
            },
            content_type="application/json")

    transaction.savepoint_commit(savePoint)

    addOperationLog(tokenInfo["login"], "删除用户信息", "删除用户信息成功", "删除用户信息成功")
    return Response({
        "result": 0,
        "msg": "OK"
    },
                    content_type="application/json")
Exemple #11
0
def userInfoQuery(request):
    """
    用户信息--查询
    :return:
    """
    print(format(request.body))
    try:
        reqBody = json.loads(request.body)
    except Exception as err:
        return Response(
            {
                "result": 10004001,
                "msg": getErrMsgByCode(10004001, err)
            },
            content_type="application/json")

    if reqbody_verify(reqBody, err_code=10004001) is None:
        pass
    else:
        return reqbody_verify(reqBody, err_code=10004001)

    tokenInfo = tokenDecode(reqBody["token"])

    if "id" not in reqBody:
        userID = tokenInfo["id"]
    else:
        userID = reqBody["id"]

    if (tokenInfo["role"] < 9) and (tokenInfo["id"] != reqBody["id"]):
        return Response(
            {
                "result": 10004006,
                "msg": getErrMsgByCode(10004006, None)
            },
            content_type="application/json")

    try:
        userObj = userDB.objects.get(id=userID)
    except Exception as err:
        return Response(
            {
                "result": 10004007,
                "msg": getErrMsgByCode(10004007, err)
            },
            content_type="application/json")

    resData = {}

    resData["id"] = userObj.id
    resData["login"] = userObj.login
    resData["nickname"] = userObj.nickname
    resData["dept"] = userObj.dept
    resData["email"] = userObj.email
    resData["enable"] = userObj.enable
    resData["height"] = userObj.height
    resData["latitude"] = userObj.latitude

    resData["level"] = userObj.level
    resData["locate"] = userObj.locate
    resData["longitude"] = userObj.longitude
    resData["mobile"] = userObj.mobile
    resData["phone"] = userObj.phone
    resData["register"] = userObj.register
    resData["role"] = userObj.role
    resData["position"] = userObj.position

    addOperationLog(userObj.login, "查询用户信息", "查询用户信息成功", "查询用户信息成功")
    return Response({
        "result": 0,
        "msg": "OK",
        "data": resData
    },
                    content_type="application/json")
Exemple #12
0
def userInfoModify(request):
    """
    用户信息--修改
    :return:
    """
    try:
        reqBody = json.loads(request.body)
    except Exception as err:
        return Response(
            {
                "result": 10003001,
                "msg": getErrMsgByCode(10003001, err)
            },
            content_type="application/json")

    if reqbody_verify(reqBody, err_code=10003001) is None:
        pass
    else:
        return reqbody_verify(reqBody, err_code=10003001)

    tokenInfo = tokenDecode(reqBody["token"])

    if "id" not in reqBody:
        return Response(
            {
                "result": 10003005,
                "msg": getErrMsgByCode(10003005, None)
            },
            content_type="application/json")
    else:
        userID = reqBody["id"]

    if (tokenInfo["role"] < 10) and (tokenInfo["id"] != reqBody["id"]):
        return Response(
            {
                "result": 10003006,
                "msg": getErrMsgByCode(10003006, None)
            },
            content_type="application/json")

    if userDB.objects.filter(id=userID).count() == 0:
        return Response(
            {
                "result": 10003007,
                "msg": getErrMsgByCode(10003007, None)
            },
            content_type="application/json")

    userPwd = None
    userName = None
    userDept = None
    userEmail = None
    userEnable = None
    userHeight = None

    userLat = None
    userLevel = None
    userLocate = None
    userLon = None
    userMobile = None
    userPhone = None

    if "password" not in reqBody:
        pass
    else:
        userPwd = reqBody["password"]

    if "nickname" not in reqBody:
        pass
    else:
        userName = reqBody["nickname"]

    if "dept" not in reqBody:
        pass
    else:
        userDept = reqBody["dept"]

    if "default_group" not in reqBody:
        pass
    else:
        userGroup = reqBody["default_group"]

    if "email" not in reqBody:
        pass
    else:
        userEmail = reqBody["email"]

    if "enable" not in reqBody:
        pass
    else:
        userEnable = reqBody["enable"]

    if "height" not in reqBody:
        pass
    else:
        userHeight = reqBody["height"]

    if "latitude" not in reqBody:
        pass
    else:
        userLat = reqBody["latitude"]

    if "level" not in reqBody:
        pass
    else:
        userLevel = reqBody["level"]

    if "locate" not in reqBody:
        pass
    else:
        userLocate = reqBody["locate"]

    if "longitude" not in reqBody:
        pass
    else:
        userLon = reqBody["longitude"]

    if "mobile" not in reqBody:
        pass
    else:
        userMobile = reqBody["mobile"]

    if "phone" not in reqBody:
        pass
    else:
        userPhone = reqBody["phone"]

    userObj = userDB.objects.get(id=userID)

    if userPwd is not None:
        userObj.password = mysql_password(userPwd)

    if userName is not None:
        userObj.nickname = userName

    if userDept is not None:
        userObj.dept = userDept

    if userEmail is not None:
        userObj.email = userEmail

    if userEnable is not None:
        userObj.enable = userEnable

    if userHeight is not None:
        userObj.height = userHeight

    if userLat is not None:
        userObj.latitude = userLat

    if userLevel is not None:
        userObj.level = userLevel

    if userLocate is not None:
        userObj.locate = userLocate

    if userLon is not None:
        userObj.longitude = userLon

    if userMobile is not None:
        userObj.mobile = userMobile

    if userPhone is not None:
        userObj.phone = userPhone

    savePoint = transaction.savepoint()

    try:
        userObj.save()
    except Exception as err:
        transaction.savepoint_rollback(savePoint)
        return Response(
            {
                "result": 10003008,
                "msg": getErrMsgByCode(10003008, err)
            },
            content_type="application/json")

    transaction.savepoint_commit(savePoint)

    addOperationLog(userObj.login, "修改用户信息", "用户信息修改成功", "用户信息修改成功")
    return Response({
        "result": 0,
        "msg": "OK"
    },
                    content_type="application/json")