|
|
@ -0,0 +1,199 @@ |
|
|
|
|
|
|
|
const { Sequelize, DataTypes, Op, literal } = require("sequelize"); |
|
|
|
|
|
|
|
const sequelize = new Sequelize( |
|
|
|
|
|
|
|
"postgres://postgres:postgres@localhost:5432/drink-water-unit" |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const data = require("./data.json"); |
|
|
|
|
|
|
|
//----------------------- MODELS
|
|
|
|
|
|
|
|
const waterSample = sequelize.define("waterSample", { |
|
|
|
|
|
|
|
pid: { |
|
|
|
|
|
|
|
type: DataTypes.INTEGER, |
|
|
|
|
|
|
|
allowNull: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
ord: { |
|
|
|
|
|
|
|
type: DataTypes.INTEGER, |
|
|
|
|
|
|
|
allowNull: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
type: { |
|
|
|
|
|
|
|
type: DataTypes.STRING, |
|
|
|
|
|
|
|
allowNull: false, |
|
|
|
|
|
|
|
desc: `:نوع نمونه
|
|
|
|
|
|
|
|
1.آب آشامیدنی |
|
|
|
|
|
|
|
2. آب سامانه نمک زدایی |
|
|
|
|
|
|
|
3.آب معدنی طبیعی |
|
|
|
|
|
|
|
4.آب بسته بندی |
|
|
|
|
|
|
|
5.آب استخر |
|
|
|
|
|
|
|
6.آب شناگاه های طبیعی |
|
|
|
|
|
|
|
7.فاضلاب/پساب |
|
|
|
|
|
|
|
8.یخ`,
|
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
mainGroupTest: { |
|
|
|
|
|
|
|
type: DataTypes.STRING, |
|
|
|
|
|
|
|
allowNull: false, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
desc: `:گروه اصلی آزمایش
|
|
|
|
|
|
|
|
1.رادیو اکتیو |
|
|
|
|
|
|
|
2.شیمیایی |
|
|
|
|
|
|
|
3.فیزیکی |
|
|
|
|
|
|
|
4.کلرسنجی |
|
|
|
|
|
|
|
5.میکروبی`,
|
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
subGroupTest: { |
|
|
|
|
|
|
|
type: DataTypes.STRING(128), |
|
|
|
|
|
|
|
allowNull: false, |
|
|
|
|
|
|
|
desc: `گروه فرعی آزمایش`, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
latinName: { |
|
|
|
|
|
|
|
type: DataTypes.STRING(128), |
|
|
|
|
|
|
|
allowNull: true, |
|
|
|
|
|
|
|
desc: `نام لاتینِ پارامتر`, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
name: { |
|
|
|
|
|
|
|
type: DataTypes.STRING(128), |
|
|
|
|
|
|
|
allowNull: true, |
|
|
|
|
|
|
|
desc: `نام فارسی پارامتر`, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
symbol: { |
|
|
|
|
|
|
|
type: DataTypes.STRING(10), |
|
|
|
|
|
|
|
allowNull: true, |
|
|
|
|
|
|
|
desc: `علامت اختصاری`, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
measureUnit: { |
|
|
|
|
|
|
|
type: DataTypes.STRING(32), |
|
|
|
|
|
|
|
allowNull: true, |
|
|
|
|
|
|
|
desc: "واحد اندازه گیری", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
paramCode: { |
|
|
|
|
|
|
|
type: DataTypes.STRING(8), |
|
|
|
|
|
|
|
allowNull: true, |
|
|
|
|
|
|
|
desc: "کد پارامتر", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
minValid: { |
|
|
|
|
|
|
|
type: DataTypes.STRING(128), |
|
|
|
|
|
|
|
allowNull: true, |
|
|
|
|
|
|
|
desc: "حداقل مجاز", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
maxValid: { |
|
|
|
|
|
|
|
type: DataTypes.STRING(128), |
|
|
|
|
|
|
|
allowNull: true, |
|
|
|
|
|
|
|
desc: "حداکثر مجاز", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
minOptimal: { |
|
|
|
|
|
|
|
type: DataTypes.STRING(128), |
|
|
|
|
|
|
|
allowNull: true, |
|
|
|
|
|
|
|
desc: "حداقل مطلوب", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
maxOptimal: { |
|
|
|
|
|
|
|
type: DataTypes.STRING(128), |
|
|
|
|
|
|
|
allowNull: true, |
|
|
|
|
|
|
|
desc: "حداکثر مطلوب", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
maxTransportTime: { |
|
|
|
|
|
|
|
type: DataTypes.STRING, |
|
|
|
|
|
|
|
allowNull: true, |
|
|
|
|
|
|
|
desc: "حداکثر زمان انتقال نمونه به آزمایشگاه", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
maxWriteInTime: { |
|
|
|
|
|
|
|
type: DataTypes.STRING(8), |
|
|
|
|
|
|
|
allowNull: true, |
|
|
|
|
|
|
|
desc: "حداکثر زمان ثبت نتیجه نمونه برداری", |
|
|
|
|
|
|
|
sample: ` |
|
|
|
|
|
|
|
null => در محل |
|
|
|
|
|
|
|
30 mi => سی دقیقه |
|
|
|
|
|
|
|
1 h => یک ساعت |
|
|
|
|
|
|
|
1 d => یک روز |
|
|
|
|
|
|
|
1 mo => یک ماه |
|
|
|
|
|
|
|
1 y => یک سال |
|
|
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
containerProperty: { |
|
|
|
|
|
|
|
type: DataTypes.STRING, |
|
|
|
|
|
|
|
allowNull: true, |
|
|
|
|
|
|
|
desc: "ویژگی ظرف نگهداری", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
keepCondition: { |
|
|
|
|
|
|
|
type: DataTypes.STRING, |
|
|
|
|
|
|
|
allowNull: true, |
|
|
|
|
|
|
|
desc: "شرایط نگهداری", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
minSampleAmount: { |
|
|
|
|
|
|
|
type: DataTypes.STRING, |
|
|
|
|
|
|
|
allowNull: true, |
|
|
|
|
|
|
|
desc: "حداقل حجم نمونه مورد نیاز ", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
examinMethod: { |
|
|
|
|
|
|
|
type: DataTypes.TEXT, |
|
|
|
|
|
|
|
allowNull: true, |
|
|
|
|
|
|
|
desc: "روش انجام آزمایش", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
standardNum: { |
|
|
|
|
|
|
|
type: DataTypes.STRING(64), |
|
|
|
|
|
|
|
allowNull: true, |
|
|
|
|
|
|
|
desc: "شماره استاندارد", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
workflowId: { |
|
|
|
|
|
|
|
type: DataTypes.INTEGER, |
|
|
|
|
|
|
|
allowNull: false, |
|
|
|
|
|
|
|
desc: "شناسه روند کار", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const workflowMap = new Map([ |
|
|
|
|
|
|
|
["آب آشامیدنی عمومی", 11], |
|
|
|
|
|
|
|
["آب سامانه نمک زدایی", 14], |
|
|
|
|
|
|
|
["آب معدنی طبیعی", 11], |
|
|
|
|
|
|
|
["آب بسته بندی", 11], |
|
|
|
|
|
|
|
["آب استخر", 15], |
|
|
|
|
|
|
|
["آب شناگاه های طبیعی", 17], |
|
|
|
|
|
|
|
["فاضلاب/پساب", 16], |
|
|
|
|
|
|
|
["یخ", 13], |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
sequelize |
|
|
|
|
|
|
|
.authenticate() |
|
|
|
|
|
|
|
.then(async () => { |
|
|
|
|
|
|
|
console.log("Connection has been established successfully."); |
|
|
|
|
|
|
|
let result; |
|
|
|
|
|
|
|
await sequelize.sync({ force: true }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const arrayToBulk = []; |
|
|
|
|
|
|
|
for (const item of data.array) { |
|
|
|
|
|
|
|
let workflowId; |
|
|
|
|
|
|
|
const typePeaces = item.type.split(" "); |
|
|
|
|
|
|
|
if (typePeaces.includes("آشامیدنی")) workflowId = 11; |
|
|
|
|
|
|
|
else if (typePeaces.includes("سامانه")) workflowId = 14; |
|
|
|
|
|
|
|
else if (typePeaces.includes("معدنی")) workflowId = 11; |
|
|
|
|
|
|
|
else if (typePeaces.includes("بسته")) workflowId = 11; |
|
|
|
|
|
|
|
else if (typePeaces.includes("استخر")) workflowId = 15; |
|
|
|
|
|
|
|
else if (typePeaces.includes("شناگاه")) workflowId = 17; |
|
|
|
|
|
|
|
else if (typePeaces.includes("یخ")) workflowId = 13; |
|
|
|
|
|
|
|
else workflowId = 16; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
arrayToBulk.push({ |
|
|
|
|
|
|
|
type: item.type, |
|
|
|
|
|
|
|
mainGroupTest: item.mainGroupTest, |
|
|
|
|
|
|
|
subGroupTest: item.subGroupTest, |
|
|
|
|
|
|
|
latinName: item.latinName, |
|
|
|
|
|
|
|
name: item.name, |
|
|
|
|
|
|
|
symbol: item.symbol, |
|
|
|
|
|
|
|
measureUnit: item.measureUnit, |
|
|
|
|
|
|
|
paramCode: item.paramCode, |
|
|
|
|
|
|
|
minValid: item.minValid, |
|
|
|
|
|
|
|
maxValid: item.maxValid, |
|
|
|
|
|
|
|
minOptimal: item.minOptimal, |
|
|
|
|
|
|
|
maxOptimal: item.maxOptimal, |
|
|
|
|
|
|
|
maxTransportTime: item.maxTransportTime, |
|
|
|
|
|
|
|
maxWriteInTime: item.maxWriteInTime, |
|
|
|
|
|
|
|
containerProperty: item.containerProperty, |
|
|
|
|
|
|
|
keepCondition: item.keepCondition, |
|
|
|
|
|
|
|
minSampleAmount: item.minSampleAmount, |
|
|
|
|
|
|
|
examinMethod: item.examinMethod, |
|
|
|
|
|
|
|
standardNum: item.standardNum, |
|
|
|
|
|
|
|
workflowId, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
await waterSample.bulkCreate(arrayToBulk); |
|
|
|
|
|
|
|
sequelize.close(); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.catch((err) => { |
|
|
|
|
|
|
|
console.error("Unable to connect to the database:", err); |
|
|
|
|
|
|
|
}); |