
- •Задание на работу
- •Аннотация
- •Summary
- •Описание выполненной работы
- •2.1 Маршрутная технология и маршрутные карты
- •2.2 Разработка функциональных требований к подсистеме
- •2.3 Разработка модели классов этапа анализа
- •2.4 Разработка модели классов этапа проектирования
- •2.5 Разработка модели хранения
- •2.6 Создание базы данных
- •2.7 Разработка основных процедур
- •2.7.1 Процедура, создающая запись в таблице “prod_operation”:
- •2.7.2 Процедура, создающая запись в таблице “input_resources”
- •2.7.3 Процедура удаления записи о операции в таблице “prod_operation”
- •2.7.4 Процедура, создающая запись о схд в таблице “terminal_classifier”
- •2.7.5 Процедура, создающая грц класс в таблице terminal_classifier
- •2.7.6 Процедура создания экземпляра грц
- •2.7.7 Процедура, меняющая порядок операции, позволяя вставлять ее в начало, середину, конец тм
- •2.7.8 Процедура удаления записи в таблице “input_resources”
- •2.7.9 Процедура изменения количества ресурса в таблице “inputs_resources”
- •2.7.10 Процедура нахождения информации об операции по id
- •2.7.11 Процедура поиска tm, сортируя их по приоритету (порядок формируется приоритетом операции при ее создании / вставке в началу/середину/конец)
- •2.7.12 Поиск затрат ресурсов на тм на партию объектов
- •2.7.13 Поиск затрат ресурсов на одну операцию для партии изделий
2.7.7 Процедура, меняющая порядок операции, позволяя вставлять ее в начало, середину, конец тм
функция: insert_in_tm - изменение приоритета (порядка) операций в ТМ
-- вход:
-- 1. prod_id - id объекта
-- 2. some_operation_id1 - id операции 1
-- 3. some_operation_id2 - id операции 1
-- 4. operation_id - id операции вставки
-- выход: 1 успех / 0 ошибка
-- эффекты:
-- 1. изменение приоритета (порядка) операций в ТМ
-- требования:
-- 1. передаваемые аргументы должны существовать
def insert_in_tm(prod_id, some_operation_id1, some_operation_id2, operation_id):
try:
# Check if the operation to modify exists
cursor.execute(f"SELECT prod_id FROM {PROD_OPERATION_TABLE} WHERE id = ?", (operation_id,))
operation_prod_id = cursor.fetchone()
if operation_prod_id is None:
print(f'Operation with ID {operation_id} does not exist')
return
# Ensure the product ID matches the target product
if operation_prod_id[0] != prod_id:
print(f'Операция с id={operation_id} не принадлежит к объекту с id={prod_id}')
return
# Check if the provided product ID exists
cursor.execute("SELECT COUNT(*) FROM product WHERE id = ?", (prod_id,))
if cursor.fetchone()[0] == 0:
print(f'Product with ID {prod_id} does not exist')
return
# Fetch current operation priorities and validate neighbors
if some_operation_id1 is None and some_operation_id2 is not None:
# Case 1: Insert at the beginning
cursor.execute(f"SELECT operation_priority FROM {PROD_OPERATION_TABLE} WHERE id = ?", (some_operation_id2,))
next_priority = cursor.fetchone()
if next_priority is None:
print(f'Operation with ID {some_operation_id2} does not exist')
return
new_priority = (next_priority[0] + 0.0) / 2
elif some_operation_id1 is not None and some_operation_id2 is not None:
# Case 2: Insert in the middle
cursor.execute(f"SELECT operation_priority FROM {PROD_OPERATION_TABLE} WHERE id = ?", (some_operation_id1,))
priority1 = cursor.fetchone()
cursor.execute(f"SELECT operation_priority FROM {PROD_OPERATION_TABLE} WHERE id = ?", (some_operation_id2,))
priority2 = cursor.fetchone()
if priority1 is None or priority2 is None:
print(f'One or both neighbor operation IDs do not exist')
return
new_priority = (priority1[0] + priority2[0]) / 2
elif some_operation_id1 is not None and some_operation_id2 is None:
# Case 3: Insert at the end
cursor.execute(f"SELECT operation_priority FROM {PROD_OPERATION_TABLE} WHERE id = ?", (some_operation_id1,))
last_priority = cursor.fetchone()
if last_priority is None:
print(f'Operation with ID {some_operation_id1} does not exist')
return
new_priority = last_priority[0] + 1.0
else:
print("Invalid combination of parameters")
return
# Update the operation_priority for the given operation
cursor.execute(f"UPDATE {PROD_OPERATION_TABLE} SET operation_priority = ? WHERE id = ?", (new_priority, operation_id))
conn.commit()
print(f'Operation {operation_id} successfully updated with new priority {new_priority}')
except Exception as e:
conn.rollback()
print(f"Error in insert_in_tm: {e}")