示例#1
0
def mburst_companys(req):
    dict = {}
    dict['version'] = 1
    dict['success'] = True
    dict['total'] = 0
    dict['data'] = []

    try:
        if req.method == 'GET':
            rj = req.GET.get('data', '').replace('\'', '\"')
            rj = json.loads(rj)
            equipment_id = rj['equip_id']
            offset = rj['start']
            limit = rj['limit']

            # get total user number by company_id and user type
            cursor = connection.cursor()

            sql = 'SELECT COUNT(*) AS total FROM app_company WHERE company_type_id=4'
            cursor.execute(sql)
            total = dictfetchall(cursor)[0]
            dict['total'] = total['total']

            # get user info by company id, user type, start and limit
            sql = 'SELECT id, company_name AS name FROM app_company WHERE company_type_id=4'
            sql = sql + ' LIMIT ' + str(limit) + ' OFFSET ' + str(offset)
            cursor.execute(sql)
            dict['data'] = dictfetchall(cursor)
    except:
        sys_info()
        dict['success'] = False
    return HttpResponse(json.dumps(dict))
示例#2
0
def mfingers_company(company_id):
    dict = {}
    dict['version'] = 1
    dict['success'] = True
    dict['user_fingers'] = []

    cursor = connection.cursor()
    sql = 'SELECT * FROM view_finger WHERE company_id=\'' + company_id + '\''
    cursor.execute(sql)
    results = dictfetchall(cursor)

    user_fingers = {}
    for result in results:
        user_id = result['user_id']
        finger = {"id": result['id'], "value": result['finger_data']}

        if user_id in user_fingers.keys():
            user_fingers[user_id]["fingers"].append(finger)
        else:
            user_fingers[user_id] = {
                "user_name": result['user_name'],
                "user_id": user_id,
                "user_type": result['user_type'],
                "fingers": [finger]
            }

    for each in user_fingers:
        dict['user_fingers'].append(user_fingers[each])

    return json.dumps(dict)
示例#3
0
def get_equip_id(equip_code):
    try:
        cursor = connection.cursor()
        sql = 'SELECT id AS equip_id FROM app_equipment WHERE equipment_code=\'' + equip_code + '\''
        cursor.execute(sql)
        equipment = dictfetchall(cursor)[0]
        return equipment['equip_id']
    except:
        sys_info()
        return ''
示例#4
0
def muser_info(req):
    try:
        if req.method == 'GET':
            company_id = req.COOKIES.get('company_id', '')
            user_id = req.COOKIES.get("usercode", '')

            id = SysUser.objects.get(user_id=user_id)
            uid = uuidToString(str(id.id))

            cursor = connection.cursor()
            cursor.execute(
                '''
                SELECT a.id AS person_id, a.user_name AS person_name,
                    b.id as company_id, b.company_name, b.company_short_name
                FROM app_sysuser a
                LEFT JOIN app_company b ON b.id=a.company_id
                WHERE a.user_id = %s
            ''', [user_id])

            dict = dictfetchall(cursor)[0]
            dict['person_id'] = uuidToString(str(dict['person_id']))
            dict['company_id'] = uuidToString(str(dict['company_id']))
            dict['success'] = True
            dict['version'] = 1

            cursor.execute(
                '''
                SELECT (a.certificate_type_id + 8) AS code, b.cert_name AS name
                FROM app_sysuser a
                LEFT JOIN app_certificatetype b ON b.id=a.certificate_type_id
                WHERE a.id = %s
            ''', [uid])

            dict['roles'] = dictfetchall(cursor)
            return HttpResponse(json.dumps(dict))
        return render_to_response('403.html')
    except:
        sys_info()
        return render_to_response('403.html')
示例#5
0
def mburst_districts(req):
    dict = {}
    dict['work_status'] = 1
    dict['version'] = 1
    dict['create_time'] = now()
    dict['success'] = True
    dict['blast_areas'] = []

    try:
        if req.method == 'GET':
            rj = req.GET.get('data', '').replace('\'', '\"')
            rjl = json.loads(rj)
            equipment_id = rjl['equip_id']
            company_id = rjl['company_id']

            # get equipment valid time by equipment id
            cursor = connection.cursor()
            sql = 'SELECT TIMESTAMPDIFF(SECOND, \'1970-01-01\', valid_time) - 28800 AS valid_time FROM app_equipment WHERE equipment_code=\'' + equipment_id + '\''

            cursor.execute(sql)
            equipment = dictfetchall(cursor)[0]
            dict['valid_time'] = equipment['valid_time']

            # get blast area info by company id
            # add status=2 => only 'jinxingzhong' area can be used
            sql = 'SELECT id, name, gps_latitude AS position_y, gps_longitude AS position_x, radius FROM app_area WHERE status_id=2 AND company_id=\'' + company_id + '\''

            cursor.execute(sql)

            # to convert Decimal(x.y) in sql output to x.y
            str = renderers.JSONRenderer().render(dictfetchall(cursor))
            dict['blast_areas'] = json.loads(str)
        else:
            dict['success'] = False
    except:
        sys_info()
        dict['success'] = False
    return HttpResponse(json.dumps(dict))
示例#6
0
def mburst_persons(req):
    dict = {}
    dict['version'] = 1
    dict['success'] = True
    dict['total'] = 0
    dict['data'] = []

    try:
        if req.method == 'GET':
            rj = req.GET.get('data', '').replace('\'', '\"')
            rj = json.loads(rj)

            equipment_id = rj['equip_id']
            company_id = rj['company_id']
            offset = rj['start']  # offset is start from 0
            limit = rj['limit']
            #user_name = rj['name']

            # get total user number by company_id and user type
            cursor = connection.cursor()

            sql = 'SELECT COUNT(*) AS total FROM app_sysuser WHERE reg_status = 1 AND certificate_type_id IN (3,4,5,6) AND company_id=\'' + company_id + '\''
            cursor.execute(sql)
            total = dictfetchall(cursor)[0]
            dict['total'] = total['total']

            # get user info by company id, user type, start and limit
            sql = 'SELECT id, user_name as fullname, certificate_type_id AS user_type FROM app_sysuser WHERE reg_status = 1 AND certificate_type_id IN (3,4,5,6)'
            sql = sql + ' AND company_id=\'' + str(
                company_id) + '\'' + ' LIMIT ' + str(limit) + ' OFFSET ' + str(
                    offset)
            cursor.execute(sql)
            dict['data'] = dictfetchall(cursor)
    except:
        sys_info()
        dict['success'] = False
    return HttpResponse(json.dumps(dict))
示例#7
0
def mfingers_company(req):
    company_id = req.COOKIES.get('company_id', '')
    user_name = req.COOKIES.get('usercode', '')
    print 'Finger Company: ' + user_name

    dict = {}
    dict['version'] = 1
    dict['success'] = True
    dict['user_fingers'] = []

    if user_name != 'zhiwen':
        dict['success'] = False
        return HttpResponse(json.dumps(dict))

    try:
        if req.method == 'GET':
            rj = req.GET.get('data', '')
            rj = json.loads(rj)
            equipment_id = rj['equip_id']
            company_id = rj['company_id']

            cursor = connection.cursor()
            sql = 'SELECT * FROM view_finger WHERE company_id=\'' + company_id + '\''
            cursor.execute(sql)
            results = dictfetchall(cursor)

            user_fingers = {}
            for result in results:
                user_id = result['user_id']
                finger = {"id": result['id'], "value": result['finger_data']}

                if user_id in user_fingers.keys():
                    user_fingers[user_id]["fingers"].append(finger)
                else:
                    user_fingers[user_id] = {
                        "user_name": result['user_name'],
                        "user_id": user_id,
                        "user_type": result['user_type'],
                        "fingers": [finger]
                    }

            for each in user_fingers:
                dict['user_fingers'].append(user_fingers[each])

    except:
        sys_info()
        dict['success'] = False
    return HttpResponse(json.dumps(dict))
示例#8
0
def get_area_info(area_id):
    try:
        cursor = connection.cursor()
        #sql = '''SELECT b.province_id, b.city_id, b.county_id, b.police_company_id, a.company_id, a.project_id
        #    FROM app_area a
        #    LEFT JOIN app_project b ON b.id=a.project_id
        #    WHERE a.id = '''

        sql = '''SELECT a.province_id, a.city_id, a.county_id, a.police_company_id, a.company_id, a.company_name, a.project_id, a.name
	        FROM view_area a
	        WHERE a.id = '''

        sql = sql + '\'' + area_id + '\''
        cursor.execute(sql)
        return dictfetchall(cursor)[0]
    except:
        sys_info()
        return {}
示例#9
0
def mfingers_project(req):
    dict = {}
    dict['version'] = 1
    dict['success'] = True
    dict['self_user_fingers'] = []
    dict['supervisor_user_fingers'] = []
    dict['projects'] = []

    try:
        if req.method == 'GET':
            rj = req.GET.get('data', '')
            rj = json.loads(rj)
            equipment_id = rj['equip_id']
            company_id = rj['company_id']

            cursor = connection.cursor()
            sql = 'SELECT * FROM view_finger WHERE user_type IN (3,4,5,6) AND company_id=\'' + company_id + '\''
            cursor.execute(sql)
            results = dictfetchall(cursor)

            user_fingers = {}
            for result in results:
                user_id = result['user_id']
                finger = {"id": result['id'], "value": result['finger_data']}

                if user_id in user_fingers.keys():
                    user_fingers[user_id]["fingers"].append(finger)
                else:
                    user_fingers[str(user_id)] = {
                        "user_name": result['user_name'],
                        "user_id": user_id,
                        "user_type": result['user_type'],
                        "fingers": [finger]
                    }

            for each in user_fingers:
                dict['self_user_fingers'].append(user_fingers[each])

            sql = 'SELECT * FROM view_finger WHERE is_supervisor=1 AND company_id=\'' + company_id + '\''
            cursor.execute(sql)
            results = dictfetchall(cursor)

            user_fingers = {}
            for result in results:
                user_id = result['user_id']
                finger = {"id": result['id'], "value": result['finger_data']}

                if user_id in user_fingers.keys():
                    user_fingers[user_id]["fingers"].append(finger)
                else:
                    user_fingers[str(user_id)] = {
                        "user_name": result['user_name'],
                        "user_id": user_id,
                        "user_type": result['user_type'],
                        "fingers": [finger]
                    }

            for each in user_fingers:
                dict['supervisor_user_fingers'].append(user_fingers[each])

            sql = 'SELECT id, name FROM app_project WHERE company_id=\'' + company_id + '\''
            cursor.execute(sql)
            dict['projects'] = dictfetchall(cursor)

    except:
        sys_info()
        dict['success'] = False

    return HttpResponse(json.dumps(dict))