예제 #1
0
def regist_requesters(obj_data_input):
    connection = None
    cursor = None
    response = response_json.get_response_common(None, None)
    try:
        connection = mysql_connection.get_connection_info()
        cursor = connection.cursor()

        sql_search_exist = f"SELECT * FROM requesters WHERE user_name=\"{obj_data_input['user_name']}\" "

        cursor.execute(sql_search_exist)

        if cursor.rowcount > 0:
            response['code'] = 1

        elif cursor.rowcount == 0:
            sql_insert = f"INSERT INTO requesters(user_name, password, created_date, update_date) values(\"{obj_data_input['user_name']}\", \"{obj_data_input['password']}\", now(), now())"

            cursor.execute(sql_insert)
            connection.commit()

            response['code'] = 0

    except Exception as e:
        print('regist.models -> regist_requesters -> ex: ', e)

    finally:
        if connection is not None:
            connection.close()

        if cursor is not None:
            cursor.close()

    return response
예제 #2
0
def requesters_del(obj_data_input):
    connection = None
    cursor = None
    response = response_json.get_response_common(None, None)
    try:
        connection = mysql_connection.get_connection_info()
        cursor = connection.cursor()

        sql_del = "UPDATE requests SET del_flg = 1 WHERE id = %s"

        cursor.execute(sql_del, (obj_data_input['id']))

        connection.commit()
        response['code'] = 0

    except Exception as e:
        print('regist.models -> requesters_del -> ex: ', e)

    finally:
        if connection is not None:
            connection.close()

        if cursor is not None:
            cursor.close()

    return response
예제 #3
0
def requesters_search(obj_input_data):
    connection = None
    cursor = None
    response = response_json.get_response_common(None, None)
    obj_output_data = []
    try:
        connection = mysql_connection.get_connection_info()
        cursor = connection.cursor()
        sql_search = f"SELECT device,request_date, name, user_name FROM requests r join requesters rs on r.requesters_id = rs.id WHERE user_name = '{obj_input_data['user_id']}'"
        sql_search += f" and (request_date like '%{obj_input_data['search_data']}%' "

        sql_search += f" OR device like '%{obj_input_data['search_data']}%'"

        sql_search += f" OR name like '%{obj_input_data['search_data']}%')"

        cursor.execute(sql_search)

        list_request = cursor.fetchall() if cursor.rowcount > 0 else []

        response['code'] = 0
        response['list_request'] = list_request

    except Exception as e:
        print('search.models -> requesters_search -> ex: ', e)

    finally:
        if connection is not None:
            connection.close()

        if cursor is not None:
            cursor.close()

    return response
예제 #4
0
def technical_login(username, password):
    connection = None
    cursor = None
    response = response_json.get_response_common(None, None)
    try:
        connection = mysql_connection.get_connection_info()
        cursor = connection.cursor()

        sql_select_technical = "SELECT * FROM technicals WHERE user_name=%s"
        cursor.execute(sql_select_technical, username)

        if cursor.rowcount == 0:
            response['code'] = 1

        elif cursor.rowcount == 1:
            data_user = cursor.fetchone()

            if password != data_user['password']:
                response['code'] = 2
            else:
                response['code'] = 0

    except Exception as e:
        print('authen.models -> technical_login -> ex: ', e)

    finally:
        if connection is not None:
            connection.close()

        if cursor is not None:
            cursor.close()

    return response
예제 #5
0
def technicals_search(obj_input_data):
    connection = None
    cursor = None
    response = response_json.get_response_common(None, None)
    obj_output_data = []
    try:
        connection = mysql_connection.get_connection_info()
        cursor = connection.cursor()
        sql_search = f"SELECT * FROM requests WHERE technicals_id={obj_input_data['user_id']}"

        if obj_input_data['search_type'] == 0:
            return response

        else:
            if obj_input_data['search_type'] == 1:
                sql_search += f" AND request_date=\"{obj_input_data['search_data']}\" "

            elif obj_input_data['search_type'] == 2:
                sql_search += f" AND device=\"{obj_input_data['search_data']}\" "

            elif obj_input_data['search_type'] == 3:
                sql_search += f" AND name=\"{obj_input_data['search_data']}\" "

            cursor.execute(sql_search)

            list_request = cursor.fetchall() if cursor.rowcount > 0 else []

        response['code'] = 0
        response['list_request'] = list_request

    except Exception as e:
        print('search.models -> technicals_search -> ex: ', e)

    finally:
        if connection is not None:
            connection.close()

        if cursor is not None:
            cursor.close()

    return response
예제 #6
0
def requesters_add(obj_data_input):
    connection = None
    cursor = None
    response = response_json.get_response_common(None, None)
    try:
        connection = mysql_connection.get_connection_info()
        cursor = connection.cursor()

        sql_add = """INSERT INTO requests (
            requesters_id,
            technicals_id,
            name,
            device,
            detail,
            status,
            request_date,
            start_time,
            end_time
            ) VALUES (%s,%s,%s,%s,%s,%s,NOW(),CURTIME(),CURTIME())"""

        cursor.execute(
            sql_add,
            (obj_data_input['requesters_id'], obj_data_input['technicals_id'],
             obj_data_input['name'], obj_data_input['device'],
             obj_data_input['detail'], obj_data_input['status']))

        connection.commit()
        response['code'] = 0

    except Exception as e:
        print('regist.models -> requesters_add -> ex: ', e)

    finally:
        if connection is not None:
            connection.close()

        if cursor is not None:
            cursor.close()

    return response
예제 #7
0
def requesters_edit(obj_data_input):
    connection = None
    cursor = None
    response = response_json.get_response_common(None, None)
    try:
        connection = mysql_connection.get_connection_info()
        cursor = connection.cursor()

        sql_edit = """UPDATE requests SET 
                name = %s,
                device = %s,
                detail = %s,
                status = %s,
                request_date = NOW(),
                start_time = CURTIME(),
                end_time = CURTIME()
            WHERE id = %s"""

        cursor.execute(sql_edit,
                       (obj_data_input['name'], obj_data_input['device'],
                        obj_data_input['detail'], obj_data_input['status'],
                        obj_data_input['id']))

        connection.commit()
        response['code'] = 0

    except Exception as e:
        print('regist.models -> requesters_edit -> ex: ', e)

    finally:
        if connection is not None:
            connection.close()

        if cursor is not None:
            cursor.close()

    return response