111 lines
4.6 KiB
TypeScript
111 lines
4.6 KiB
TypeScript
import { PrismaClient } from '@prisma/client';
|
|
import * as bcrypt from 'bcryptjs';
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
// 五项污染物默认散发参数生成器(占位值;真实数据由实验室检测导入)
|
|
function ep(y0: number) {
|
|
return {
|
|
hcho: { y0, yp: y0 * 1.5, b: 0.01 },
|
|
tvoc: { y0: y0 * 0.6, yp: y0 * 0.9, b: 0.01 },
|
|
benzene: { y0: y0 * 0.05, yp: y0 * 0.08, b: 0.005 },
|
|
toluene: { y0: y0 * 0.1, yp: y0 * 0.15, b: 0.005 },
|
|
xylene: { y0: y0 * 0.08, yp: y0 * 0.12, b: 0.005 },
|
|
};
|
|
}
|
|
|
|
// 取自原系统公共材料库前若干条(散发参数为占位)
|
|
const MATERIALS = [
|
|
{ id: 'PM13000003', name: '胶合板', category: '人造板/胶合板', brand: '东营正和', manufacturer: '东营正和', spec: '2.7SE', envGrade: 'E1', y0: 0.06 },
|
|
{ id: 'PM13000004', name: '胶合板', category: '人造板/胶合板', brand: '东营正和', manufacturer: '东营正和', spec: '3N-3mm', envGrade: 'E0', y0: 0.03 },
|
|
{ id: 'PM13000005', name: '胶合板', category: '人造板/胶合板', brand: '金秋', manufacturer: '河北金秋木业有限责任公司', spec: '8mm', envGrade: null, y0: 0.05 },
|
|
{ id: 'PM13000006', name: '胶合板', category: '人造板/胶合板', brand: '金秋', manufacturer: '河北金秋木业有限责任公司', spec: '12mm', envGrade: null, y0: 0.05 },
|
|
{ id: 'PM13000007', name: '胶合板', category: '人造板/胶合板', brand: '金秋', manufacturer: '河北金秋木业有限责任公司', spec: '15mm', envGrade: null, y0: 0.055 },
|
|
{ id: 'PM13000008', name: '胶合板', category: '人造板/胶合板', brand: '金秋', manufacturer: '河北金秋木业有限责任公司', spec: '18mm', envGrade: null, y0: 0.06 },
|
|
{ id: 'PM13000009', name: '阻燃胶合板', category: '人造板/阻燃胶合板', brand: '兔宝宝', manufacturer: '德华兔宝宝装饰新材股份有限公司', spec: null, envGrade: null, y0: 0.045 },
|
|
{ id: 'PM13000010', name: '阻燃板', category: '人造板/胶合板', brand: '福益安', manufacturer: '北京江夏木业有限公司', spec: null, envGrade: 'E1', y0: 0.05 },
|
|
{ id: 'PM13000011', name: '阻燃板', category: '人造板/阻燃胶合板', brand: '莫干山', manufacturer: '浙江升华云峰新材股份有限公司', spec: 'E1', envGrade: 'E1', y0: 0.05 },
|
|
{ id: 'PM13000012', name: '非醛多层基材胶合板', category: '人造板/胶合板', brand: '升达', manufacturer: '四川升达林产业股份有限公司', spec: null, envGrade: null, y0: 0.02 },
|
|
];
|
|
|
|
async function main() {
|
|
const passwordHash = await bcrypt.hash('CBMA123456', 10);
|
|
const org = await prisma.organization.upsert({
|
|
where: { username: 'YPJKKJ' },
|
|
update: {},
|
|
create: { username: 'YPJKKJ', name: '一品健康空间', passwordHash },
|
|
});
|
|
console.log('组织已就绪:', org.username, org.name);
|
|
|
|
for (const m of MATERIALS) {
|
|
await prisma.material.upsert({
|
|
where: { id: m.id },
|
|
update: {},
|
|
create: {
|
|
id: m.id,
|
|
name: m.name,
|
|
category: m.category,
|
|
brand: m.brand,
|
|
manufacturer: m.manufacturer,
|
|
spec: m.spec ?? undefined,
|
|
envGrade: m.envGrade ?? undefined,
|
|
usageUnit: 'm²',
|
|
emissionParams: ep(m.y0),
|
|
isPublic: true,
|
|
},
|
|
});
|
|
}
|
|
console.log(`已导入 ${MATERIALS.length} 条公共材料(散发参数为占位值,待替换真实检测数据)`);
|
|
|
|
// 一条公共项目模板(含 1 个空间 + 2 种材料),供模板库展示
|
|
const tplId = 'T13000001';
|
|
await prisma.project.upsert({
|
|
where: { id: tplId },
|
|
update: {},
|
|
create: {
|
|
id: tplId,
|
|
name: '标准住宅卧室模板',
|
|
type: '住宅',
|
|
province: '北京市',
|
|
city: '北京市',
|
|
area: 90,
|
|
isTemplate: true,
|
|
isPublic: true,
|
|
ownerOrgId: org.id,
|
|
status: 'report_generated',
|
|
rating: 'A',
|
|
spaces: {
|
|
create: [
|
|
{
|
|
id: 'TS13000001',
|
|
name: '主卧',
|
|
type: '卧室',
|
|
layout: 'uniform',
|
|
height: 2.8,
|
|
area: 15,
|
|
volume: 42,
|
|
temperature: 25,
|
|
humidity: 50,
|
|
ventilationRate: 0.5,
|
|
standard: 'GB50325-2020',
|
|
materials: {
|
|
create: [
|
|
{ materialId: 'PM13000004', usageUnit: 'm²', usageAmount: 30 },
|
|
{ materialId: 'PM13000012', usageUnit: 'm²', usageAmount: 20 },
|
|
],
|
|
},
|
|
},
|
|
],
|
|
},
|
|
},
|
|
});
|
|
console.log('已导入 1 条公共项目模板');
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
})
|
|
.finally(() => prisma.$disconnect());
|