chore(avs): avs problem resolution revoke fradrives licences implemented

This commit is contained in:
Steffen Jost 2022-12-21 18:04:17 +01:00
parent 90a5f07c04
commit 92b28a7085
3 changed files with 28 additions and 3 deletions

View File

@ -18,6 +18,7 @@ BtnRevokeAvsLicences: Fahrberechtigungen im AVS sofort entziehen
BtnImportUnknownAvsIds: Daten unbekannter Personen importieren BtnImportUnknownAvsIds: Daten unbekannter Personen importieren
AvsImportIDs n@Int m@Int: AVS Persondendaten importiert: #{show n}/#{show m} AvsImportIDs n@Int m@Int: AVS Persondendaten importiert: #{show n}/#{show m}
AvsSetLicences alic@AvsLicence n@Int m@Int: _{alic} im AVS gesetzt: #{show n}/#{show m} AvsSetLicences alic@AvsLicence n@Int m@Int: _{alic} im AVS gesetzt: #{show n}/#{show m}
RevokeFraDriveLicences alic@AvsLicence n@Int: _{alic} in FRADrive zum Vortag beendet für #{show n} Fahrer
RevokeUnknownLicencesOk: AVS Fahrberechtigungen unbekannter Fahrer wurden gesperrt RevokeUnknownLicencesOk: AVS Fahrberechtigungen unbekannter Fahrer wurden gesperrt
RevokeUnknownLicencesFail: Nicht alle AVS Fahrberechtigungen unbekannter Fahrer konnten entzogen werden, siehe Log für Details RevokeUnknownLicencesFail: Nicht alle AVS Fahrberechtigungen unbekannter Fahrer konnten entzogen werden, siehe Log für Details
AvsCommunicationError: AVS Schnittstelle lieferte einen unerwarteten Fehler. AvsCommunicationError: AVS Schnittstelle lieferte einen unerwarteten Fehler.

View File

@ -18,6 +18,7 @@ BtnRevokeAvsLicences: Revoke AVS driving licences immediately
BtnImportUnknownAvsIds: Import unknown person data BtnImportUnknownAvsIds: Import unknown person data
AvsImportIDs n m: AVS person data imported: #{show n}/#{show m} AvsImportIDs n m: AVS person data imported: #{show n}/#{show m}
AvsSetLicences alic n m: _{alic} set in AVS: #{show n}/#{show m} AvsSetLicences alic n m: _{alic} set in AVS: #{show n}/#{show m}
RevokeFraDriveLicences alic@AvsLicence n@Int: _{alic} now ended yesterday in FRADrive for #{show n} drivers
RevokeUnknownLicencesOk: AVS driving licences of unknown drivers revoked RevokeUnknownLicencesOk: AVS driving licences of unknown drivers revoked
RevokeUnknownLicencesFail: Not all AVS driving licences of unknown drivers could be revoked, see log for details RevokeUnknownLicencesFail: Not all AVS driving licences of unknown drivers could be revoked, see log for details
AvsCommunicationError: AVS interface returned an unexpected error. AvsCommunicationError: AVS interface returned an unexpected error.

View File

@ -19,6 +19,7 @@ import qualified Data.Text as Text
import qualified Data.CaseInsensitive as CI import qualified Data.CaseInsensitive as CI
import qualified Data.Set as Set import qualified Data.Set as Set
import qualified Data.Map as Map import qualified Data.Map as Map
import Database.Persist.Sql (updateWhereCount)
import Handler.Utils import Handler.Utils
import Handler.Utils.Avs import Handler.Utils.Avs
@ -306,7 +307,7 @@ postProblemAvsSynchR, getProblemAvsSynchR :: Handler Html
postProblemAvsSynchR = getProblemAvsSynchR postProblemAvsSynchR = getProblemAvsSynchR
getProblemAvsSynchR = do getProblemAvsSynchR = do
now <- liftIO getCurrentTime now <- liftIO getCurrentTime
let _nowaday = utctDay now let nowaday = utctDay now
-- TODO: just for Testing -- TODO: just for Testing
-- let TimeOfDay hours minutes _seconds = timeToTimeOfDay (utctDayTime now) -- let TimeOfDay hours minutes _seconds = timeToTimeOfDay (utctDayTime now)
@ -361,8 +362,30 @@ getProblemAvsSynchR = do
in addMessageI mkind $ MsgAvsSetLicences aLic no_ok no_req in addMessageI mkind $ MsgAvsSetLicences aLic no_ok no_req
(Left err) -> addMessageModal Error (i18n MsgAvsCommunicationError) (Right (text2widget $ tshow (err :: SomeException))) (Left err) -> addMessageModal Error (i18n MsgAvsCommunicationError) (Right (text2widget $ tshow (err :: SomeException)))
redirect ProblemAvsSynchR -- reload to update all tables redirect ProblemAvsSynchR -- reload to update all tables
-- procRes alic (LicenceTableRevokeFDriveData, apids) = do -- TODO: continue here !!! procRes alic (LicenceTableRevokeFDriveData, apids) = do
-- qId <- runDB $ getBy UniqueQualificationAvsLicence alic runDB $ do
qId <- getKeyBy404 $ UniqueQualificationAvsLicence $ Just alic
uas <- selectList [UserAvsPersonId <-. Set.toList apids] []
let uids = view _userAvsUser <$> uas
endday = pred nowaday
crits = [QualificationUserQualification ==. qId, QualificationUserUser <-. uids]
oks <- fromIntegral <$> updateWhereCount crits [QualificationUserValidUntil =. endday, QualificationUserLastRefresh =. nowaday]
qus <- selectList crits []
forM_ qus $ \qu ->
audit TransactionQualificationUserEdit
{ transactionQualificationUser = qu ^. _entityKey
, transactionQualification = qId -- qu ^. _qualificationUserQualification
, transactionUser = qu ^. _qualificationUserUser
, transactionQualificationValidUntil = endday -- qu ^. _qualificationUserValidUntil
}
if oks /= length qus || oks /= Set.size apids
then do
$logErrorS "AVS" $ "Revoke FRADrive licences discrepancy! Requested: " <> tshow (Set.size apids) <> " Updated: " <> tshow oks <> " Found: " <> tshow (length qus)
liftHandler $ addMessageI Error $ MsgRevokeFraDriveLicences alic oks
else
liftHandler $ addMessageI Success $ MsgRevokeFraDriveLicences alic oks
redirect ProblemAvsSynchR -- must be outside runDB
-- procRes alic (LicenceTableGrantFDriveData{..}, apids ) = do -- TODO: continue here !!! -- procRes alic (LicenceTableGrantFDriveData{..}, apids ) = do -- TODO: continue here !!!
procRes _alic r@(_, _apids) = addMessage Error $ toHtml $ "NOT YET IMPLEMENTED !!! " <> tshow r procRes _alic r@(_, _apids) = addMessage Error $ toHtml $ "NOT YET IMPLEMENTED !!! " <> tshow r
formResult tres2 $ procRes AvsLicenceRollfeld formResult tres2 $ procRes AvsLicenceRollfeld