diff --git a/resources/db/hoksit/select_non_tuva_hoksit_created_between.sql b/resources/db/hoksit/select_non_tuva_hoksit_started_between.sql similarity index 71% rename from resources/db/hoksit/select_non_tuva_hoksit_created_between.sql rename to resources/db/hoksit/select_non_tuva_hoksit_started_between.sql index 6af7cb3f4..a10018d42 100644 --- a/resources/db/hoksit/select_non_tuva_hoksit_created_between.sql +++ b/resources/db/hoksit/select_non_tuva_hoksit_started_between.sql @@ -1,6 +1,6 @@ SELECT * FROM hoksit h - WHERE h.created_at >= ? -- FIXME: is this correct, what about updated_at? - AND h.created_at <= ? + WHERE h.ensikertainen_hyvaksyminen >= ? + AND h.ensikertainen_hyvaksyminen <= ? AND h.deleted_at IS NULL AND h.tuva_opiskeluoikeus_oid IS NULL AND NOT EXISTS (SELECT 1 FROM hankittavat_koulutuksen_osat hko diff --git a/src/oph/ehoks/db/db_operations/hoks.clj b/src/oph/ehoks/db/db_operations/hoks.clj index ba4b53ad8..c7980e49f 100644 --- a/src/oph/ehoks/db/db_operations/hoks.clj +++ b/src/oph/ehoks/db/db_operations/hoks.clj @@ -426,17 +426,17 @@ [queries/select-hoksit-finished-between from to] {:row-fn hoks-from-sql})) -(defn select-non-tuva-hoksit-created-between - "Hakee tietokannasta ne HOKSit, jotka on luotu annettujen ajankohtien - välillä ja jotka eivät ole TUVA-HOKSeja tai TUVA-HOKSien kanssa - rinnakkaisia ammatillisia HOKSeja." +(defn select-non-tuva-hoksit-started-between + "Hakee tietokannasta ne HOKSit, jotka on merkitty alkaneiksi annettujen + ajankohtien välillä ja jotka eivät ole TUVA-HOKSeja tai TUVA-HOKSien + kanssa rinnakkaisia ammatillisia HOKSeja." [from to] (db-ops/query - [queries/select-non-tuva-hoksit-created-between from to] + [queries/select-non-tuva-hoksit-started-between from to] {:row-fn hoks-from-sql})) (defn select-non-tuva-hoksit-finished-between - "Hakee tietokannasta ne HOKSit, jotka on merkattu valmiiksi annettujen + "Hakee tietokannasta ne HOKSit, jotka on merkitty valmiiksi annettujen ajankohtien välillä ja jotka eivät ole TUVA-HOKSeja tai TUVA-HOKSien kanssa rinnakkaisia ammatillisia HOKSeja." [from to] diff --git a/src/oph/ehoks/db/queries.clj b/src/oph/ehoks/db/queries.clj index 76b998e31..214c06b65 100644 --- a/src/oph/ehoks/db/queries.clj +++ b/src/oph/ehoks/db/queries.clj @@ -60,8 +60,8 @@ (defq select-hoksit-created-between "hoksit/select_hoksit_created_between.sql") (defq select-hoksit-finished-between "hoksit/select_hoksit_finished_between.sql") -(defq select-non-tuva-hoksit-created-between - "hoksit/select_non_tuva_hoksit_created_between.sql") +(defq select-non-tuva-hoksit-started-between + "hoksit/select_non_tuva_hoksit_started_between.sql") (defq select-non-tuva-hoksit-finished-between "hoksit/select_non_tuva_hoksit_finished_between.sql") (defq select-hoks-oppijat-without-index diff --git a/src/oph/ehoks/palaute/opiskelija.clj b/src/oph/ehoks/palaute/opiskelija.clj index 5265b758a..78bccda67 100644 --- a/src/oph/ehoks/palaute/opiskelija.clj +++ b/src/oph/ehoks/palaute/opiskelija.clj @@ -169,8 +169,10 @@ juuri tallennettu." [kyselytyyppi from to] (log/info "Reinitiating" kyselytyyppi "for HOKSit between" from "and" to) - (->> (db-hoks/select-non-tuva-hoksit-created-between from to) - (initiate-every-needed! kyselytyyppi))) + (let [fetcher (case kyselytyyppi + :aloituskysely db-hoks/select-non-tuva-hoksit-started-between + :paattokysely db-hoks/select-non-tuva-hoksit-finished-between)] + (initiate-every-needed! kyselytyyppi (fetcher from to)))) (defn create-arvo-kyselylinkki! "For the given palaute, make Arvo call for creating its kyselylinkki diff --git a/test/oph/ehoks/hoks/hoks_save_test.clj b/test/oph/ehoks/hoks/hoks_save_test.clj index f620d13b8..66b18a5bc 100644 --- a/test/oph/ehoks/hoks/hoks_save_test.clj +++ b/test/oph/ehoks/hoks/hoks_save_test.clj @@ -734,10 +734,10 @@ ["lahetetty" "aloittaneet" (LocalDate/of 2019 3 18)]}) (is (= @sqs-call-counter 3)) (is (= 1 (opalaute/reinitiate-hoksit-between! - :aloituskysely (LocalDate/now) (.plusDays (LocalDate/now) 1)))) + :aloituskysely (LocalDate/of 2021 1 1) (LocalDate/of 2021 6 1)))) (is (= @sqs-call-counter 4)) (is (= 1 (opalaute/reinitiate-hoksit-between! - :paattokysely (LocalDate/now) (.plusDays (LocalDate/now) 1)))) + :paattokysely (LocalDate/of 2022 12 1) (LocalDate/of 2022 12 30)))) (is (= @sqs-call-counter 5)) (eq (set (map (juxt :tila :kyselytyyppi :heratepvm) (palaute/get-by-hoks-id-and-kyselytyypit!