Skip to content

Commit

Permalink
[MODAUD-174] - Fixed sql query
Browse files Browse the repository at this point in the history
  • Loading branch information
azizbekxm committed Nov 15, 2023
1 parent f8c661e commit 82b48db
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public class PieceEventsDaoImpl implements PieceEventsDao {
private static final String TABLE_NAME = "acquisition_piece_log";
private static final String GET_BY_PIECE_ID_SQL = "SELECT id, action, piece_id, user_id, event_date, action_date, modified_content_snapshot, " +
" (SELECT count(*) AS total_records FROM %s WHERE piece_id = $1) FROM %s WHERE piece_id = $1 %s LIMIT $2 OFFSET $3";
private static final String GET_STATUS_CHANGE_HISTORY_BY_PIECE_ID_SQL =
"""
WITH StatusChanges AS (SELECT id, action, piece_id, user_id, event_date, action_date, modified_content_snapshot,
LAG(modified_content_snapshot ->> 'receivingStatus') OVER (PARTITION BY piece_id ORDER BY action_date) AS previous_status
FROM %s WHERE piece_id=$1
private static final String GET_STATUS_CHANGE_HISTORY_BY_PIECE_ID_SQL = """
WITH StatusChanges AS (
SELECT id, action, piece_id, user_id, event_date, action_date, modified_content_snapshot,
LAG(modified_content_snapshot ->> 'receivingStatus') OVER (PARTITION BY piece_id ORDER BY action_date) AS previous_status
FROM %s WHERE piece_id=$1
)
SELECT id, action, piece_id, user_id, event_date, action_date, modified_content_snapshot,
(SELECT COUNT(*) AS total_records FROM StatusChanges
WHERE modified_content_snapshot ->> 'receivingStatus' <> COALESCE(previous_status, ''))
SELECT id, action, piece_id, user_id, event_date, action_date, modified_content_snapshot,
(SELECT COUNT(*) AS total_records FROM StatusChanges
WHERE modified_content_snapshot ->> 'receivingStatus' <> COALESCE(previous_status, ''))
FROM StatusChanges WHERE modified_content_snapshot ->> 'receivingStatus' <> COALESCE(previous_status, '')
%s LIMIT $2 OFFSET $3
""";
Expand Down

0 comments on commit 82b48db

Please sign in to comment.