GWM : Automation for Survey and iip calculation
This commit is contained in:
parent
9edfaa5ca5
commit
2d4c8f8b11
@ -55,6 +55,10 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
assigned: { type: DataTypes.INTEGER },
|
assigned: { type: DataTypes.INTEGER },
|
||||||
responded: { type: DataTypes.INTEGER },
|
responded: { type: DataTypes.INTEGER },
|
||||||
not_responded: { type: DataTypes.INTEGER },
|
not_responded: { type: DataTypes.INTEGER },
|
||||||
|
ipi_calculated:{
|
||||||
|
type: DataTypes.BOOLEAN,
|
||||||
|
defaultValue: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
tableName: "quarterly_windows_configuration_master",
|
tableName: "quarterly_windows_configuration_master",
|
||||||
|
|||||||
@ -41,6 +41,7 @@ class AutomatedSchedulerService {
|
|||||||
end_date,
|
end_date,
|
||||||
start_date
|
start_date
|
||||||
FROM quarterly_windows_configuration_master
|
FROM quarterly_windows_configuration_master
|
||||||
|
WHERE ipi_calculated = 0
|
||||||
ORDER BY year DESC,
|
ORDER BY year DESC,
|
||||||
CASE quarter
|
CASE quarter
|
||||||
WHEN 'Q1' THEN 1
|
WHEN 'Q1' THEN 1
|
||||||
@ -145,6 +146,28 @@ class AutomatedSchedulerService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update ipi_calculated flag in quarterly_windows_configuration_master
|
||||||
|
*/
|
||||||
|
async updateIPICalculatedFlag(year, quarter) {
|
||||||
|
const connection = await this.pool.getConnection();
|
||||||
|
try {
|
||||||
|
const query = `
|
||||||
|
UPDATE quarterly_windows_configuration_master
|
||||||
|
SET ipi_calculated = 1
|
||||||
|
WHERE year = ? AND quarter = ?
|
||||||
|
`;
|
||||||
|
|
||||||
|
await connection.query(query, [year, quarter]);
|
||||||
|
console.log(`[${new Date().toISOString()}] Updated ipi_calculated flag to 1 for ${year} ${quarter}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`[${new Date().toISOString()}] Error updating ipi_calculated flag:`, error);
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
connection.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main scheduler logic - runs daily
|
* Main scheduler logic - runs daily
|
||||||
*/
|
*/
|
||||||
@ -197,6 +220,9 @@ class AutomatedSchedulerService {
|
|||||||
latestWindow.quarter
|
latestWindow.quarter
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Step 5: Update ipi_calculated flag to 1
|
||||||
|
await this.updateIPICalculatedFlag(latestWindow.year, latestWindow.quarter);
|
||||||
|
|
||||||
console.log(`[${new Date().toISOString()}] ========================================`);
|
console.log(`[${new Date().toISOString()}] ========================================`);
|
||||||
console.log(`[${new Date().toISOString()}] All scheduled tasks completed successfully`);
|
console.log(`[${new Date().toISOString()}] All scheduled tasks completed successfully`);
|
||||||
console.log(`[${new Date().toISOString()}] Survey Result:`, JSON.stringify(surveyResult, null, 2));
|
console.log(`[${new Date().toISOString()}] Survey Result:`, JSON.stringify(surveyResult, null, 2));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user