Only emit time_conflict_resolved when a conflict has actually existed
This commit is contained in:
parent
409f3140c9
commit
98d713234b
@ -135,15 +135,22 @@ class ValidationRules(ValidationRuleFunctions):
|
||||
for participant in participants:
|
||||
commands.execute(query, param={"shipcall_id" : int(shipcall_id), "participant_id" : participant["participant_id"], "message" : violation})
|
||||
|
||||
if state_new == 1 and state_old != 0: # this resolves the time conflict
|
||||
resolves_time_conflict = (state_old == StatusFlags.RED.value) and (state_new in [StatusFlags.GREEN.value, StatusFlags.YELLOW.value])
|
||||
if resolves_time_conflict:
|
||||
notification_type = 3 # time_conflict
|
||||
logging.info(f"Resolving notifications for shipcall {shipcall_id}, type={notification_type}")
|
||||
query = f"DELETE from notification where shipcall_id = ?shipcall_id? and type = {notification_type} and level = 0"
|
||||
deleted_count = commands.execute(query, param={"shipcall_id" : int(shipcall_id)})
|
||||
logging.info(f"Deleted {deleted_count} existing notifications (yet unsent)")
|
||||
if deleted_count == 0:
|
||||
query = "SELECT COUNT(*) as cnt FROM notification WHERE shipcall_id = ?shipcall_id? AND type = ?type?"
|
||||
result = commands.query(query, model=dict, param={"shipcall_id" : int(shipcall_id), "type" : notification_type})
|
||||
has_conflict_notification = (len(result) > 0) and (result[0].get("cnt", 0) > 0)
|
||||
if has_conflict_notification:
|
||||
query = "DELETE from notification where shipcall_id = ?shipcall_id? and type = ?type? and level = 0"
|
||||
deleted_count = commands.execute(query, param={"shipcall_id" : int(shipcall_id), "type" : notification_type})
|
||||
logging.info(f"Deleted {deleted_count} existing notifications (yet unsent)")
|
||||
query = "INSERT INTO notification (shipcall_id, participant_id, type, level) VALUES (?shipcall_id?, ?participant_id?, 4, 0)"
|
||||
for participant in participants:
|
||||
commands.execute(query, param={"shipcall_id" : int(shipcall_id), "participant_id" : participant["participant_id"]})
|
||||
else:
|
||||
logging.info(f"Skipping resolve notification for shipcall {shipcall_id} because no prior time_conflict exists")
|
||||
finally:
|
||||
if pooledConnection is not None:
|
||||
pooledConnection.close()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user