Implement daily political salary management: Introduced a new function run_daily_political_salary to calculate and distribute daily salaries for players with active political offices, utilizing configured values or fallback based on office rank. Updated SQL queries to support this functionality, including checks for the readiness of the necessary database column. Enhanced the PoliticsWorker to trigger daily salary processing, ensuring timely updates for users. Improved documentation for clarity on the new salary management features and their integration into the existing political benefits system.
All checks were successful
Deploy yourpart (blue-green) / deploy (push) Successful in 2m51s
All checks were successful
Deploy yourpart (blue-green) / deploy (push) Successful in 2m51s
This commit is contained in:
@@ -1370,6 +1370,46 @@ pub const QUERY_POLITICAL_APPOINTMENT_EXPIRE_PENDING: &str = r#"
|
||||
AND expires_at < NOW();
|
||||
"#;
|
||||
|
||||
/// Spalte `last_political_daily_salary_on` (Migration `013_falukant_political_daily_salary.sql`).
|
||||
pub const QUERY_POLITICAL_DAILY_SALARY_USER_COLUMN_READY: &str = r#"
|
||||
SELECT EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = 'falukant_data'
|
||||
AND table_name = 'falukant_user'
|
||||
AND column_name = 'last_political_daily_salary_on'
|
||||
) AS ready;
|
||||
"#;
|
||||
|
||||
/// Aktive Ämter mit Spieler-Charakter, noch **kein** Gehalt heute (UTC).
|
||||
/// `configured_daily_salary`: Summe aus `political_office_benefit` mit `daily_salary` im JSON; sonst 0 → Fallback im Daemon nach Amts-Rang.
|
||||
pub const QUERY_POLITICAL_DAILY_SALARY_OFFICE_ROWS: &str = r#"
|
||||
SELECT
|
||||
ch.user_id AS falukant_user_id,
|
||||
COALESCE(pot.name, '') AS office_name,
|
||||
COALESCE((
|
||||
SELECT SUM(GREATEST(0, COALESCE(NULLIF(TRIM(sb.value::jsonb->>'daily_salary'), '')::numeric, 0)))
|
||||
FROM falukant_predefine.political_office_benefit sb
|
||||
WHERE sb.political_office_type_id = po.office_type_id
|
||||
AND COALESCE(sb.value::jsonb->>'tr', sb.value::jsonb->>'benefitType') = 'daily_salary'
|
||||
), 0::numeric) AS configured_daily_salary
|
||||
FROM falukant_data.political_office po
|
||||
JOIN falukant_type.political_office_type pot ON pot.id = po.office_type_id
|
||||
JOIN falukant_data.character ch ON ch.id = po.character_id
|
||||
JOIN falukant_data.falukant_user fu ON fu.id = ch.user_id
|
||||
WHERE ch.user_id IS NOT NULL
|
||||
AND (po.created_at + (pot.term_length * INTERVAL '1 day')) > NOW()
|
||||
AND (fu.last_political_daily_salary_on IS NULL OR fu.last_political_daily_salary_on < CURRENT_DATE);
|
||||
"#;
|
||||
|
||||
pub const QUERY_UPDATE_LAST_POLITICAL_DAILY_SALARY_ON: &str = r#"
|
||||
UPDATE falukant_data.falukant_user
|
||||
SET last_political_daily_salary_on = CURRENT_DATE,
|
||||
updated_at = NOW()
|
||||
WHERE id = $1::int
|
||||
AND (last_political_daily_salary_on IS NULL OR last_political_daily_salary_on < CURRENT_DATE);
|
||||
"#;
|
||||
|
||||
/// Summe `count` aus `free_lover_slots`-Benefits (JSON `tr`/`benefitType`), gedeckelt.
|
||||
pub const QUERY_SUM_FREE_LOVER_SLOTS_FOR_CHARACTER: &str = r#"
|
||||
SELECT LEAST(
|
||||
@@ -3330,7 +3370,7 @@ pub const QUERY_GET_ACTIVE_LOVER_ROWS_FOR_MONTHLY: &str = r#"
|
||||
WHERE rs.active = true
|
||||
AND (
|
||||
rs.last_monthly_processed_at IS NULL
|
||||
OR date_trunc('month', rs.last_monthly_processed_at) < date_trunc('month', CURRENT_TIMESTAMP)
|
||||
OR rs.last_monthly_processed_at::date < CURRENT_DATE
|
||||
);
|
||||
"#;
|
||||
|
||||
@@ -3575,6 +3615,7 @@ pub const QUERY_GET_LOVER_PREGNANCY_CANDIDATES: &str = r#"
|
||||
OR (c1.gender = 'male' AND c2.gender = 'female')
|
||||
AND rs.affection >= 45
|
||||
AND rs.maintenance_level >= 30
|
||||
-- `last_monthly_processed_at` wird im Familien-Tageslauf mitgeführt (1 Spieljahr = 1 Kalendertag).
|
||||
AND rs.last_monthly_processed_at IS NOT NULL
|
||||
AND rs.last_monthly_processed_at >= NOW() - INTERVAL '50 days'
|
||||
AND NOT EXISTS (
|
||||
@@ -3582,7 +3623,7 @@ pub const QUERY_GET_LOVER_PREGNANCY_CANDIDATES: &str = r#"
|
||||
FROM falukant_data.child_relation cr
|
||||
WHERE cr.father_character_id = (CASE WHEN c1.gender = 'male' THEN c1.id ELSE c2.id END)
|
||||
AND cr.mother_character_id = (CASE WHEN c1.gender = 'female' THEN c1.id ELSE c2.id END)
|
||||
AND cr.created_at >= date_trunc('month', CURRENT_TIMESTAMP)
|
||||
AND cr.created_at::date >= CURRENT_DATE
|
||||
)
|
||||
AND (CURRENT_DATE - c_female.birthdate::date) >= 4380
|
||||
AND (CURRENT_DATE - c_female.birthdate::date) < 18993
|
||||
|
||||
Reference in New Issue
Block a user