dernier mise a jour university
This commit is contained in:
parent
eb7d02e472
commit
82b5e6a68e
@ -77,22 +77,22 @@ const createEtudiantsTableQuery = `
|
|||||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
nom VARCHAR(250) DEFAULT NULL,
|
nom VARCHAR(250) DEFAULT NULL,
|
||||||
prenom VARCHAR(250) DEFAULT NULL,
|
prenom VARCHAR(250) DEFAULT NULL,
|
||||||
photos TEXT NOT NULL,
|
photos TEXT DEFAULT NULL,
|
||||||
date_de_naissances DATE NOT NULL,
|
date_de_naissances DATE DEFAULT NULL,
|
||||||
niveau VARCHAR(250) NOT NULL, -- Clé étrangère vers niveaus
|
niveau VARCHAR(250) NOT NULL, -- Clé étrangère vers niveaus
|
||||||
annee_scolaire VARCHAR(20) NOT NULL,
|
annee_scolaire VARCHAR(20) NOT NULL,
|
||||||
status INTEGER NOT NULL,
|
status INTEGER DEFAULT NULL,
|
||||||
mention_id INTEGER NOT NULL, -- Clé étrangère vers mentions
|
mention_id INTEGER NOT NULL, -- Clé étrangère vers mentions
|
||||||
num_inscription TEXT NOT NULL UNIQUE,
|
num_inscription TEXT NOT NULL,
|
||||||
sexe VARCHAR(20) NOT NULL,
|
sexe VARCHAR(20) DEFAULT NULL,
|
||||||
cin VARCHAR(250) DEFAULT NULL,
|
cin VARCHAR(250) DEFAULT NULL,
|
||||||
date_delivrance DEFAULT NULL,
|
date_delivrance DEFAULT NULL,
|
||||||
nationalite DATE NOT NULL,
|
nationalite DATE DEFAULT NULL,
|
||||||
annee_bacc DATE NOT NULL,
|
annee_bacc DATE DEFAULT NULL,
|
||||||
serie VARCHAR(20) NOT NULL,
|
serie VARCHAR(20) DEFAULT NULL,
|
||||||
boursier BOOLEAN DEFAULT FALSE,
|
boursier BOOLEAN DEFAULT FALSE,
|
||||||
domaine VARCHAR(250) NOT NULL,
|
domaine VARCHAR(250) DEFAULT NULL,
|
||||||
contact VARCHAR(20) NOT NULL,
|
contact VARCHAR(20) DEFAULT NULL,
|
||||||
parcours VARCHAR(250) DEFAULT NULL,
|
parcours VARCHAR(250) DEFAULT NULL,
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
|||||||
@ -3,12 +3,13 @@ const path = require('path')
|
|||||||
const XLSX = require('xlsx')
|
const XLSX = require('xlsx')
|
||||||
const { getCompressedDefaultImage } = require('../function/GetImageDefaault')
|
const { getCompressedDefaultImage } = require('../function/GetImageDefaault')
|
||||||
const { parse } = require('csv-parse/sync')
|
const { parse } = require('csv-parse/sync')
|
||||||
const { insertEtudiant, updateEtudiant } = require('../Models/Etudiants')
|
const { insertEtudiant } = require('../Models/Etudiants')
|
||||||
const { database } = require('../database')
|
const { database } = require('../database')
|
||||||
const { getMentions } = require('../Models/Mentions')
|
const { getMentions } = require('../Models/Mentions')
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const { getStatusMention } = require('../function/Helper')
|
const { getStatusMention } = require('../function/Helper')
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
// const customParseFormatt = require('dayjs/plu')
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
|
|
||||||
// Function to convert any date format to 'YYYY-MM-DD'
|
// Function to convert any date format to 'YYYY-MM-DD'
|
||||||
@ -21,7 +22,8 @@ function convertToISODate(input) {
|
|||||||
'DD-MM-YYYY',
|
'DD-MM-YYYY',
|
||||||
'MM-DD-YYYY',
|
'MM-DD-YYYY',
|
||||||
'DD/MM/YY',
|
'DD/MM/YY',
|
||||||
'MM/DD/YY'
|
'MM/DD/YY',
|
||||||
|
'DD-MMM-YY'
|
||||||
]
|
]
|
||||||
const parsedDate = dayjs(input, formats, true) // Strict parsing to ensure formats are matched correctly
|
const parsedDate = dayjs(input, formats, true) // Strict parsing to ensure formats are matched correctly
|
||||||
|
|
||||||
@ -30,6 +32,12 @@ function convertToISODate(input) {
|
|||||||
return parsedDate.format('YYYY-MM-DD')
|
return parsedDate.format('YYYY-MM-DD')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle cases like "Vers 2000"
|
||||||
|
const versMatch = typeof input === 'string' && input.match(/vers\s*(\d{4})/i);
|
||||||
|
if (versMatch) {
|
||||||
|
return `${versMatch[1]}-01-01`; // Return in ISO format
|
||||||
|
}
|
||||||
|
|
||||||
function excelDateToJSDate(serial) {
|
function excelDateToJSDate(serial) {
|
||||||
const utc_days = Math.floor(serial - 25569); // days from Jan 1, 1970
|
const utc_days = Math.floor(serial - 25569); // days from Jan 1, 1970
|
||||||
const utc_value = utc_days * 86400; // seconds in a day
|
const utc_value = utc_days * 86400; // seconds in a day
|
||||||
@ -75,11 +83,17 @@ async function importFileToDatabase(filePath) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ✅ Count number of data rows
|
||||||
|
const numberOfLines = records.length;
|
||||||
|
console.log(`Number of data rows: ${numberOfLines}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let error = true
|
let error = true
|
||||||
let message = ''
|
let message = ''
|
||||||
|
|
||||||
// Vérifier les données en une seule boucle
|
// Vérifier les données en une seule boucle
|
||||||
|
let ar = [];
|
||||||
|
let oldNum = '';
|
||||||
for (const row of records) {
|
for (const row of records) {
|
||||||
if (
|
if (
|
||||||
!row.nom ||
|
!row.nom ||
|
||||||
@ -97,8 +111,9 @@ async function importFileToDatabase(filePath) {
|
|||||||
!row.serie ||
|
!row.serie ||
|
||||||
!row.code_redoublement ||
|
!row.code_redoublement ||
|
||||||
!row.boursier ||
|
!row.boursier ||
|
||||||
!row.domaine ||
|
!row.domaine
|
||||||
!row.contact
|
// ||
|
||||||
|
// !row.contact
|
||||||
) {
|
) {
|
||||||
if (!row.nom) {
|
if (!row.nom) {
|
||||||
message = "Le champ 'nom' est inconnu"
|
message = "Le champ 'nom' est inconnu"
|
||||||
@ -136,9 +151,10 @@ async function importFileToDatabase(filePath) {
|
|||||||
message = "Le champ 'boursier' est inconnu"
|
message = "Le champ 'boursier' est inconnu"
|
||||||
} else if (!row.domaine) {
|
} else if (!row.domaine) {
|
||||||
message = "Le champ 'domaine' est inconnu"
|
message = "Le champ 'domaine' est inconnu"
|
||||||
} else if (!row.contact) {
|
|
||||||
message = "Le champ 'contact' est inconnu"
|
|
||||||
}
|
}
|
||||||
|
// else if (!row.contact) {
|
||||||
|
// message = "Le champ 'contact' est inconnu"
|
||||||
|
// }
|
||||||
error = false
|
error = false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -153,7 +169,7 @@ async function importFileToDatabase(filePath) {
|
|||||||
// Si aucune erreur, insérer les données en batch
|
// Si aucune erreur, insérer les données en batch
|
||||||
if (error !== false) {
|
if (error !== false) {
|
||||||
// Utiliser transaction pour éviter une latence si l'insertion dépasse 100
|
// Utiliser transaction pour éviter une latence si l'insertion dépasse 100
|
||||||
database.transaction(async () => {
|
database.transaction(() => {
|
||||||
for (const row of records) {
|
for (const row of records) {
|
||||||
// Convert row.mention to uppercase and compare with ListMention.nom and ListMention.uniter (also converted to uppercase)
|
// Convert row.mention to uppercase and compare with ListMention.nom and ListMention.uniter (also converted to uppercase)
|
||||||
const matchedMention = ListMention.find(
|
const matchedMention = ListMention.find(
|
||||||
@ -166,62 +182,43 @@ async function importFileToDatabase(filePath) {
|
|||||||
if (matchedMention) {
|
if (matchedMention) {
|
||||||
row.mention = matchedMention.id
|
row.mention = matchedMention.id
|
||||||
}
|
}
|
||||||
|
row.num_inscription = row.num_inscription.toString()
|
||||||
|
|
||||||
const inscription = database.prepare(
|
ar.push(row)
|
||||||
'SELECT id FROM etudiants WHERE num_inscription = ?'
|
console.log(ar.length, 'create');
|
||||||
).get(row.num_inscription)
|
try {
|
||||||
|
let compare = row.num_inscription;
|
||||||
// Check if the student already exists in the database
|
if (compare == oldNum) {
|
||||||
if (inscription) {
|
row.num_inscription = Number(row.num_inscription + 1);
|
||||||
|
}
|
||||||
updateEtudiant(
|
console.log(
|
||||||
row.nom,
|
insertEtudiant(
|
||||||
row.prenom,
|
row.nom,
|
||||||
getCompressedDefaultImage(),
|
row.prenom,
|
||||||
convertToISODate(row.date_naissance),
|
getCompressedDefaultImage(),
|
||||||
row.niveau,
|
convertToISODate(row.date_naissance),
|
||||||
row.annee_scolaire,
|
row.niveau,
|
||||||
getStatusMention(row.code_redoublement),
|
row.annee_scolaire,
|
||||||
row.mention,
|
getStatusMention(row.code_redoublement),
|
||||||
row.num_inscription,
|
row.num_inscription,
|
||||||
inscription.id, // Assuming 'id' is the primary key of the student
|
row.mention,
|
||||||
row.sexe,
|
row.sexe,
|
||||||
row.nationaliter,
|
row.nationaliter,
|
||||||
row.cin,
|
row.cin,
|
||||||
row.date_de_delivrance ? convertToISODate(row.date_de_delivrance) : null,
|
row.date_de_delivrance,
|
||||||
row.annee_baccalaureat,
|
row.annee_baccalaureat,
|
||||||
row.serie,
|
row.serie,
|
||||||
row.boursier,
|
row.boursier,
|
||||||
row.domaine,
|
row.domaine,
|
||||||
row.contact,
|
row.contact,
|
||||||
null
|
null
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
oldNum = compare
|
||||||
|
|
||||||
console.log(inscription)
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// Insert the student data with the updated mention ID
|
|
||||||
insertEtudiant(
|
|
||||||
row.nom,
|
|
||||||
row.prenom,
|
|
||||||
getCompressedDefaultImage(),
|
|
||||||
convertToISODate(row.date_naissance),
|
|
||||||
row.niveau,
|
|
||||||
row.annee_scolaire,
|
|
||||||
getStatusMention(row.code_redoublement),
|
|
||||||
row.num_inscription,
|
|
||||||
row.mention,
|
|
||||||
row.sexe,
|
|
||||||
row.nationaliter,
|
|
||||||
row.cin,
|
|
||||||
row.date_de_delivrance,
|
|
||||||
row.annee_baccalaureat,
|
|
||||||
row.serie,
|
|
||||||
row.boursier,
|
|
||||||
row.domaine,
|
|
||||||
row.contact
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user