修改小程序,前端,官网跳转路径
This commit is contained in:
150
government-backend/scripts/createSlaughterhouseTable.js
Normal file
150
government-backend/scripts/createSlaughterhouseTable.js
Normal file
@@ -0,0 +1,150 @@
|
||||
const mysql = require('mysql2/promise');
|
||||
|
||||
const createSlaughterhouseTable = async () => {
|
||||
let connection = null;
|
||||
try {
|
||||
// 创建数据库连接
|
||||
connection = await mysql.createConnection({
|
||||
host: '129.211.213.226',
|
||||
port: 9527,
|
||||
user: 'root',
|
||||
password: 'aiotAiot123!',
|
||||
database: 'ningxia_zhengfu',
|
||||
charset: 'utf8mb4'
|
||||
});
|
||||
|
||||
console.log('数据库连接成功');
|
||||
|
||||
// SQL语句数组
|
||||
const sqlStatements = [
|
||||
// 删除旧表(如果存在)
|
||||
'DROP TABLE IF EXISTS government_slaughterhouses;',
|
||||
|
||||
// 创建新表
|
||||
`CREATE TABLE government_slaughterhouses (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY COMMENT '屠宰场ID',
|
||||
name VARCHAR(100) NOT NULL UNIQUE COMMENT '屠宰场名称',
|
||||
address VARCHAR(255) NOT NULL COMMENT '地址',
|
||||
contactPerson VARCHAR(50) NOT NULL COMMENT '联系人',
|
||||
contactPhone VARCHAR(20) NOT NULL COMMENT '联系电话',
|
||||
licenseNumber VARCHAR(50) NOT NULL UNIQUE COMMENT '许可证号',
|
||||
status ENUM('active', 'inactive') NOT NULL DEFAULT 'active' COMMENT '状态(active: 正常, inactive: 停用)',
|
||||
createTime DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
created_by INT NULL COMMENT '创建人ID',
|
||||
updated_by INT NULL COMMENT '更新人ID',
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
deleted_at DATETIME NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='政府系统屠宰场表';`,
|
||||
|
||||
// 添加索引
|
||||
'CREATE INDEX idx_name ON government_slaughterhouses (name);',
|
||||
'CREATE INDEX idx_licenseNumber ON government_slaughterhouses (licenseNumber);',
|
||||
'CREATE INDEX idx_status ON government_slaughterhouses (status);'
|
||||
];
|
||||
|
||||
// 执行表创建相关SQL
|
||||
for (const sql of sqlStatements) {
|
||||
await connection.execute(sql);
|
||||
console.log(`执行SQL成功: ${sql.substring(0, 50)}...`);
|
||||
}
|
||||
|
||||
// 准备测试数据(使用参数化查询避免字符编码问题)
|
||||
const testData = [
|
||||
[
|
||||
'宁夏银川市第一屠宰场',
|
||||
'宁夏回族自治区银川市金凤区良田镇植物园路',
|
||||
'张明',
|
||||
'13800138001',
|
||||
'SC1234567890123',
|
||||
'active',
|
||||
'2023-01-15 00:00:00',
|
||||
1,
|
||||
1
|
||||
],
|
||||
[
|
||||
'宁夏石嘴山市肉类加工厂',
|
||||
'宁夏回族自治区石嘴山市大武口区星海镇',
|
||||
'李强',
|
||||
'13900139002',
|
||||
'SC1234567890124',
|
||||
'active',
|
||||
'2023-02-10 00:00:00',
|
||||
1,
|
||||
1
|
||||
],
|
||||
[
|
||||
'宁夏吴忠市清真屠宰场',
|
||||
'宁夏回族自治区吴忠市利通区金银滩镇',
|
||||
'王芳',
|
||||
'13700137003',
|
||||
'SC1234567890125',
|
||||
'active',
|
||||
'2023-03-05 00:00:00',
|
||||
1,
|
||||
1
|
||||
],
|
||||
[
|
||||
'宁夏固原市牲畜屠宰场',
|
||||
'宁夏回族自治区固原市原州区官厅镇',
|
||||
'赵伟',
|
||||
'13600136004',
|
||||
'SC1234567890126',
|
||||
'inactive',
|
||||
'2023-04-20 00:00:00',
|
||||
1,
|
||||
1
|
||||
],
|
||||
[
|
||||
'宁夏中卫市肉类屠宰加工中心',
|
||||
'宁夏回族自治区中卫市沙坡头区迎水桥镇',
|
||||
'陈静',
|
||||
'13500135005',
|
||||
'SC1234567890127',
|
||||
'active',
|
||||
'2023-05-15 00:00:00',
|
||||
1,
|
||||
1
|
||||
]
|
||||
];
|
||||
|
||||
// 插入测试数据
|
||||
const insertSql = `
|
||||
INSERT INTO government_slaughterhouses (
|
||||
name,
|
||||
address,
|
||||
contactPerson,
|
||||
contactPhone,
|
||||
licenseNumber,
|
||||
status,
|
||||
createTime,
|
||||
created_by,
|
||||
updated_by
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`;
|
||||
|
||||
let insertedCount = 0;
|
||||
for (const data of testData) {
|
||||
await connection.execute(insertSql, data);
|
||||
insertedCount++;
|
||||
console.log(`插入测试数据成功: ${data[0]}`);
|
||||
}
|
||||
|
||||
// 查询插入的记录数
|
||||
const [result] = await connection.execute('SELECT COUNT(*) AS total_records FROM government_slaughterhouses;');
|
||||
console.log(`
|
||||
成功创建屠宰场表并插入 ${result[0].total_records} 条测试数据!`);
|
||||
|
||||
} catch (error) {
|
||||
console.error('创建屠宰场表或插入测试数据失败:', error);
|
||||
} finally {
|
||||
// 关闭数据库连接
|
||||
if (connection) {
|
||||
await connection.end();
|
||||
console.log('数据库连接已关闭');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 执行函数
|
||||
createSlaughterhouseTable();
|
||||
98
government-backend/scripts/createSlaughterhouseTable.sql
Normal file
98
government-backend/scripts/createSlaughterhouseTable.sql
Normal file
@@ -0,0 +1,98 @@
|
||||
-- 直接使用SQL创建屠宰场表并添加测试数据
|
||||
USE ningxia_zhengfu;
|
||||
|
||||
-- 删除旧表(如果存在)
|
||||
DROP TABLE IF EXISTS government_slaughterhouses;
|
||||
|
||||
-- 创建新表,指定字符集支持中文
|
||||
CREATE TABLE government_slaughterhouses (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY COMMENT '屠宰场ID',
|
||||
name VARCHAR(100) NOT NULL UNIQUE COMMENT '屠宰场名称',
|
||||
address VARCHAR(255) NOT NULL COMMENT '地址',
|
||||
contactPerson VARCHAR(50) NOT NULL COMMENT '联系人',
|
||||
contactPhone VARCHAR(20) NOT NULL COMMENT '联系电话',
|
||||
licenseNumber VARCHAR(50) NOT NULL UNIQUE COMMENT '许可证号',
|
||||
status ENUM('active', 'inactive') NOT NULL DEFAULT 'active' COMMENT '状态(active: 正常, inactive: 停用)',
|
||||
createTime DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
created_by INT NULL COMMENT '创建人ID',
|
||||
updated_by INT NULL COMMENT '更新人ID',
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
deleted_at DATETIME NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='政府系统屠宰场表';
|
||||
|
||||
-- 添加索引
|
||||
CREATE INDEX idx_name ON government_slaughterhouses (name);
|
||||
CREATE INDEX idx_licenseNumber ON government_slaughterhouses (licenseNumber);
|
||||
CREATE INDEX idx_status ON government_slaughterhouses (status);
|
||||
|
||||
-- 插入测试数据
|
||||
INSERT INTO government_slaughterhouses (
|
||||
name,
|
||||
address,
|
||||
contactPerson,
|
||||
contactPhone,
|
||||
licenseNumber,
|
||||
status,
|
||||
createTime,
|
||||
created_by,
|
||||
updated_by
|
||||
) VALUES
|
||||
(
|
||||
'宁夏银川市第一屠宰场',
|
||||
'宁夏回族自治区银川市金凤区良田镇植物园路',
|
||||
'张明',
|
||||
'13800138001',
|
||||
'SC1234567890123',
|
||||
'active',
|
||||
'2023-01-15 00:00:00',
|
||||
1,
|
||||
1
|
||||
),
|
||||
(
|
||||
'宁夏石嘴山市肉类加工厂',
|
||||
'宁夏回族自治区石嘴山市大武口区星海镇',
|
||||
'李强',
|
||||
'13900139002',
|
||||
'SC1234567890124',
|
||||
'active',
|
||||
'2023-02-10 00:00:00',
|
||||
1,
|
||||
1
|
||||
),
|
||||
(
|
||||
'宁夏吴忠市清真屠宰场',
|
||||
'宁夏回族自治区吴忠市利通区金银滩镇',
|
||||
'王芳',
|
||||
'13700137003',
|
||||
'SC1234567890125',
|
||||
'active',
|
||||
'2023-03-05 00:00:00',
|
||||
1,
|
||||
1
|
||||
),
|
||||
(
|
||||
'宁夏固原市牲畜屠宰场',
|
||||
'宁夏回族自治区固原市原州区官厅镇',
|
||||
'赵伟',
|
||||
'13600136004',
|
||||
'SC1234567890126',
|
||||
'inactive',
|
||||
'2023-04-20 00:00:00',
|
||||
1,
|
||||
1
|
||||
),
|
||||
(
|
||||
'宁夏中卫市肉类屠宰加工中心',
|
||||
'宁夏回族自治区中卫市沙坡头区迎水桥镇',
|
||||
'陈静',
|
||||
'13500135005',
|
||||
'SC1234567890127',
|
||||
'active',
|
||||
'2023-05-15 00:00:00',
|
||||
1,
|
||||
1
|
||||
);
|
||||
|
||||
-- 查询插入的记录数
|
||||
SELECT COUNT(*) AS total_records FROM government_slaughterhouses;
|
||||
@@ -1,4 +1,4 @@
|
||||
const sequelize = require('../config/database');
|
||||
const sequelize = require('../config/database.js');
|
||||
const EpidemicAgency = require('../models/EpidemicAgency');
|
||||
|
||||
async function initEpidemicAgencyTable() {
|
||||
@@ -33,6 +33,7 @@ async function initEpidemicAgencyTable() {
|
||||
type: 'center',
|
||||
status: 'active',
|
||||
establishmentDate: '2010-01-15',
|
||||
epidemicScope: '负责全市所有区域的动物防疫工作统筹管理和技术指导',
|
||||
description: '负责全市动物防疫工作的统筹管理和技术指导'
|
||||
},
|
||||
{
|
||||
@@ -44,6 +45,7 @@ async function initEpidemicAgencyTable() {
|
||||
type: 'branch',
|
||||
status: 'active',
|
||||
establishmentDate: '2012-05-20',
|
||||
epidemicScope: '负责东区所有街道、乡镇的动物防疫工作',
|
||||
description: '负责东区范围内的动物防疫工作'
|
||||
},
|
||||
{
|
||||
@@ -55,6 +57,7 @@ async function initEpidemicAgencyTable() {
|
||||
type: 'branch',
|
||||
status: 'active',
|
||||
establishmentDate: '2013-03-10',
|
||||
epidemicScope: '负责西区所有街道、乡镇的动物防疫工作',
|
||||
description: '负责西区范围内的动物防疫工作'
|
||||
},
|
||||
{
|
||||
@@ -66,6 +69,7 @@ async function initEpidemicAgencyTable() {
|
||||
type: 'branch',
|
||||
status: 'active',
|
||||
establishmentDate: '2014-07-05',
|
||||
epidemicScope: '负责北区所有街道、乡镇的动物防疫工作',
|
||||
description: '负责北区范围内的动物防疫工作'
|
||||
},
|
||||
{
|
||||
@@ -77,6 +81,7 @@ async function initEpidemicAgencyTable() {
|
||||
type: 'branch',
|
||||
status: 'active',
|
||||
establishmentDate: '2015-02-28',
|
||||
epidemicScope: '负责南区所有街道、乡镇的动物防疫工作',
|
||||
description: '负责南区范围内的动物防疫工作'
|
||||
},
|
||||
{
|
||||
@@ -88,6 +93,7 @@ async function initEpidemicAgencyTable() {
|
||||
type: 'mobile',
|
||||
status: 'active',
|
||||
establishmentDate: '2016-09-15',
|
||||
epidemicScope: '负责全市偏远地区、山区及突发事件的动物防疫工作',
|
||||
description: '负责偏远地区和突发事件的动物防疫工作'
|
||||
}
|
||||
];
|
||||
|
||||
115
government-backend/scripts/initHarmlessPlaceTable.js
Normal file
115
government-backend/scripts/initHarmlessPlaceTable.js
Normal file
@@ -0,0 +1,115 @@
|
||||
const config = require('../config/index');
|
||||
const mysql = require('mysql2/promise');
|
||||
|
||||
// 初始化无害化场所表
|
||||
async function initHarmlessPlaceTable() {
|
||||
let connection = null;
|
||||
try {
|
||||
// 创建数据库连接
|
||||
console.log('测试数据库连接...');
|
||||
connection = await mysql.createConnection({
|
||||
host: config.DB_CONFIG.host,
|
||||
port: config.DB_CONFIG.port,
|
||||
user: config.DB_CONFIG.user,
|
||||
password: config.DB_CONFIG.password,
|
||||
database: config.DB_CONFIG.database
|
||||
});
|
||||
console.log('数据库连接成功');
|
||||
|
||||
// 检查表是否存在
|
||||
console.log('检查无害化场所表是否存在...');
|
||||
const [tables] = await connection.execute(
|
||||
"SHOW TABLES LIKE 'government_harmless_places'"
|
||||
);
|
||||
|
||||
// 如果表存在,删除它
|
||||
if (tables.length > 0) {
|
||||
console.log('无害化场所表已存在,删除它...');
|
||||
await connection.execute('DROP TABLE government_harmless_places');
|
||||
console.log('无害化场所表删除成功');
|
||||
}
|
||||
|
||||
// 创建无害化场所表
|
||||
console.log('创建无害化场所表...');
|
||||
await connection.execute(`
|
||||
CREATE TABLE government_harmless_places (
|
||||
id VARCHAR(36) PRIMARY KEY NOT NULL,
|
||||
name VARCHAR(100) NOT NULL COMMENT '场所名称',
|
||||
address VARCHAR(255) NOT NULL COMMENT '地址',
|
||||
contact_person VARCHAR(50) NOT NULL COMMENT '联系人',
|
||||
contact_phone VARCHAR(20) NOT NULL COMMENT '联系电话',
|
||||
license_number VARCHAR(50) NOT NULL UNIQUE COMMENT '许可证号',
|
||||
status ENUM('正常', '维护中', '停用') NOT NULL DEFAULT '正常' COMMENT '状态',
|
||||
create_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
update_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
INDEX idx_name (name),
|
||||
INDEX idx_license_number (license_number),
|
||||
INDEX idx_status (status)
|
||||
) COMMENT '无害化场所管理表'
|
||||
`);
|
||||
|
||||
console.log('无害化场所表创建成功!');
|
||||
|
||||
// 添加测试数据
|
||||
console.log('开始添加测试数据...');
|
||||
const testData = [
|
||||
[
|
||||
'1', '银川市无害化处理中心', '宁夏银川市金凤区科技园路88号',
|
||||
'张经理', '13895112345', 'HP20240001', '正常',
|
||||
'2024-06-01 10:00:00', '2024-06-01 10:00:00'
|
||||
],
|
||||
[
|
||||
'2', '石嘴山市无害化处理站', '宁夏石嘴山市大武口区环保路56号',
|
||||
'李站长', '13995123456', 'HP20240002', '正常',
|
||||
'2024-06-02 11:30:00', '2024-06-02 11:30:00'
|
||||
],
|
||||
[
|
||||
'3', '吴忠市无害化处理厂', '宁夏吴忠市利通区产业路34号',
|
||||
'王厂长', '13795134567', 'HP20240003', '维护中',
|
||||
'2024-06-03 09:15:00', '2024-06-10 14:20:00'
|
||||
],
|
||||
[
|
||||
'4', '固原市无害化处理中心', '宁夏固原市原州区生态路12号',
|
||||
'赵主任', '13695145678', 'HP20240004', '正常',
|
||||
'2024-06-04 14:45:00', '2024-06-04 14:45:00'
|
||||
],
|
||||
[
|
||||
'5', '中卫市无害化处理站', '宁夏中卫市沙坡头区环卫路23号',
|
||||
'孙主任', '13595156789', 'HP20240005', '停用',
|
||||
'2024-06-05 16:20:00', '2024-06-15 09:30:00'
|
||||
]
|
||||
];
|
||||
|
||||
// 批量插入数据
|
||||
for (const row of testData) {
|
||||
await connection.execute(
|
||||
`INSERT INTO government_harmless_places
|
||||
(id, name, address, contact_person, contact_phone, license_number, status, create_time, update_time)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
row
|
||||
);
|
||||
}
|
||||
|
||||
console.log('测试数据添加成功!');
|
||||
console.log('无害化场所表初始化完成!');
|
||||
} catch (error) {
|
||||
console.error('初始化无害化场所表失败:', error);
|
||||
throw error;
|
||||
} finally {
|
||||
// 关闭数据库连接
|
||||
if (connection) {
|
||||
await connection.end();
|
||||
console.log('数据库连接已关闭');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 执行初始化
|
||||
if (require.main === module) {
|
||||
initHarmlessPlaceTable().catch(err => {
|
||||
console.error('程序执行失败:', err);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = initHarmlessPlaceTable;
|
||||
110
government-backend/scripts/initHarmlessRegistrationTable.js
Normal file
110
government-backend/scripts/initHarmlessRegistrationTable.js
Normal file
@@ -0,0 +1,110 @@
|
||||
const config = require('../config');
|
||||
const mysql = require('mysql2/promise');
|
||||
|
||||
// 初始化无害化登记表
|
||||
async function initHarmlessRegistrationTable() {
|
||||
let connection = null;
|
||||
try {
|
||||
// 创建数据库连接
|
||||
console.log('测试数据库连接...');
|
||||
connection = await mysql.createConnection({
|
||||
host: config.DB_CONFIG.host,
|
||||
port: config.DB_CONFIG.port,
|
||||
user: config.DB_CONFIG.user,
|
||||
password: config.DB_CONFIG.password,
|
||||
database: config.DB_CONFIG.database
|
||||
});
|
||||
console.log('数据库连接成功');
|
||||
|
||||
// 检查表是否存在
|
||||
console.log('检查无害化登记表是否存在...');
|
||||
const [tables] = await connection.execute(
|
||||
"SHOW TABLES LIKE 'government_harmless_registrations'"
|
||||
);
|
||||
|
||||
// 如果表存在,删除它
|
||||
if (tables.length > 0) {
|
||||
console.log('无害化登记表已存在,删除它...');
|
||||
await connection.execute('DROP TABLE government_harmless_registrations');
|
||||
console.log('无害化登记表删除成功');
|
||||
}
|
||||
|
||||
// 创建无害化登记表
|
||||
console.log('创建无害化登记表...');
|
||||
await connection.execute(`
|
||||
CREATE TABLE government_harmless_registrations (
|
||||
id VARCHAR(36) PRIMARY KEY NOT NULL,
|
||||
registrationNumber VARCHAR(50) NOT NULL UNIQUE COMMENT '登记编号',
|
||||
animalType VARCHAR(50) NOT NULL COMMENT '动物类型',
|
||||
quantity INT NOT NULL COMMENT '数量',
|
||||
reason TEXT NOT NULL COMMENT '无害化处理原因',
|
||||
processingMethod VARCHAR(100) NOT NULL COMMENT '处理方式',
|
||||
processingPlace VARCHAR(100) NOT NULL COMMENT '处理场所',
|
||||
processingDate DATE NOT NULL COMMENT '处理日期',
|
||||
registrant VARCHAR(50) NOT NULL COMMENT '登记人',
|
||||
status ENUM('待处理', '处理中', '已完成', '已取消') NOT NULL DEFAULT '待处理' COMMENT '状态',
|
||||
createTime DATETIME NOT NULL COMMENT '创建时间',
|
||||
updateTime DATETIME NOT NULL COMMENT '更新时间',
|
||||
INDEX idx_registrationNumber (registrationNumber),
|
||||
INDEX idx_status (status),
|
||||
INDEX idx_processingDate (processingDate)
|
||||
) COMMENT '无害化登记管理表'
|
||||
`);
|
||||
|
||||
console.log('无害化登记表创建成功!');
|
||||
|
||||
// 添加测试数据
|
||||
console.log('开始添加测试数据...');
|
||||
const testData = [
|
||||
[
|
||||
'1', 'WH20240601001', '牛', 5, '疾病死亡', '焚烧处理',
|
||||
'银川市无害化处理中心', '2024-06-01', '张兽医', '已完成',
|
||||
'2024-06-01 08:30:00', '2024-06-02 14:20:00'
|
||||
],
|
||||
[
|
||||
'2', 'WH20240602002', '羊', 10, '自然灾害', '深埋处理',
|
||||
'中卫市无害化处理中心', '2024-06-02', '李技术员', '处理中',
|
||||
'2024-06-02 09:15:00', '2024-06-02 16:45:00'
|
||||
],
|
||||
[
|
||||
'3', 'WH20240603003', '猪', 8, '检疫不合格', '化制处理',
|
||||
'吴忠市无害化处理中心', '2024-06-03', '王检疫员', '待处理',
|
||||
'2024-06-03 10:00:00', '2024-06-03 10:00:00'
|
||||
],
|
||||
[
|
||||
'4', 'WH20240604004', '牛', 3, '意外死亡', '焚烧处理',
|
||||
'石嘴山市无害化处理中心', '2024-06-04', '赵管理员', '已取消',
|
||||
'2024-06-04 11:20:00', '2024-06-04 15:30:00'
|
||||
],
|
||||
[
|
||||
'5', 'WH20240605005', '羊', 12, '疫情防控', '深埋处理',
|
||||
'固原市无害化处理中心', '2024-06-05', '陈兽医', '已完成',
|
||||
'2024-06-05 09:45:00', '2024-06-06 11:15:00'
|
||||
]
|
||||
];
|
||||
|
||||
// 批量插入数据
|
||||
for (const row of testData) {
|
||||
await connection.execute(
|
||||
`INSERT INTO government_harmless_registrations
|
||||
(id, registrationNumber, animalType, quantity, reason, processingMethod,
|
||||
processingPlace, processingDate, registrant, status, createTime, updateTime)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
row
|
||||
);
|
||||
}
|
||||
|
||||
console.log('测试数据添加成功!添加了', testData.length, '条数据。');
|
||||
|
||||
} catch (error) {
|
||||
console.error('初始化无害化登记表失败:', error);
|
||||
} finally {
|
||||
// 关闭数据库连接
|
||||
if (connection) {
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 执行初始化
|
||||
initHarmlessRegistrationTable();
|
||||
92
government-backend/scripts/initSlaughterhouseData.js
Normal file
92
government-backend/scripts/initSlaughterhouseData.js
Normal file
@@ -0,0 +1,92 @@
|
||||
const sequelize = require('../config/database');
|
||||
const Slaughterhouse = require('../models/Slaughterhouse');
|
||||
|
||||
// 初始化屠宰场表并添加测试数据
|
||||
const initSlaughterhouseData = async () => {
|
||||
try {
|
||||
// 先删除旧表,再重新创建
|
||||
await Slaughterhouse.drop().catch(() => console.log('旧表不存在,跳过删除'));
|
||||
await sequelize.sync({ force: true });
|
||||
console.log('数据库同步成功,表已重新创建');
|
||||
|
||||
// 检查是否已有数据
|
||||
const existingCount = await Slaughterhouse.count();
|
||||
if (existingCount > 0) {
|
||||
console.log(`已存在 ${existingCount} 条屠宰场数据,跳过初始化`);
|
||||
return;
|
||||
}
|
||||
|
||||
// 准备测试数据
|
||||
const testData = [
|
||||
{
|
||||
name: '宁夏银川市第一屠宰场',
|
||||
address: '宁夏回族自治区银川市金凤区良田镇植物园路',
|
||||
contactPerson: '张明',
|
||||
contactPhone: '13800138001',
|
||||
licenseNumber: 'SC1234567890123',
|
||||
status: 'active',
|
||||
createTime: new Date('2023-01-15'),
|
||||
created_by: 1,
|
||||
updated_by: 1
|
||||
},
|
||||
{
|
||||
name: '宁夏石嘴山市肉类加工厂',
|
||||
address: '宁夏回族自治区石嘴山市大武口区星海镇',
|
||||
contactPerson: '李强',
|
||||
contactPhone: '13900139002',
|
||||
licenseNumber: 'SC1234567890124',
|
||||
status: 'active',
|
||||
createTime: new Date('2023-02-10'),
|
||||
created_by: 1,
|
||||
updated_by: 1
|
||||
},
|
||||
{
|
||||
name: '宁夏吴忠市清真屠宰场',
|
||||
address: '宁夏回族自治区吴忠市利通区金银滩镇',
|
||||
contactPerson: '王芳',
|
||||
contactPhone: '13700137003',
|
||||
licenseNumber: 'SC1234567890125',
|
||||
status: 'active',
|
||||
createTime: new Date('2023-03-05'),
|
||||
created_by: 1,
|
||||
updated_by: 1
|
||||
},
|
||||
{
|
||||
name: '宁夏固原市牲畜屠宰场',
|
||||
address: '宁夏回族自治区固原市原州区官厅镇',
|
||||
contactPerson: '赵伟',
|
||||
contactPhone: '13600136004',
|
||||
licenseNumber: 'SC1234567890126',
|
||||
status: 'inactive',
|
||||
createTime: new Date('2023-04-20'),
|
||||
created_by: 1,
|
||||
updated_by: 1
|
||||
},
|
||||
{
|
||||
name: '宁夏中卫市肉类屠宰加工中心',
|
||||
address: '宁夏回族自治区中卫市沙坡头区迎水桥镇',
|
||||
contactPerson: '陈静',
|
||||
contactPhone: '13500135005',
|
||||
licenseNumber: 'SC1234567890127',
|
||||
status: 'active',
|
||||
createTime: new Date('2023-05-15'),
|
||||
created_by: 1,
|
||||
updated_by: 1
|
||||
}
|
||||
];
|
||||
|
||||
// 批量创建测试数据
|
||||
const createdSlaughterhouses = await Slaughterhouse.bulkCreate(testData);
|
||||
console.log(`成功创建 ${createdSlaughterhouses.length} 条屠宰场测试数据`);
|
||||
|
||||
} catch (error) {
|
||||
console.error('初始化屠宰场数据失败:', error);
|
||||
} finally {
|
||||
// 关闭数据库连接
|
||||
await sequelize.close();
|
||||
console.log('数据库连接已关闭');
|
||||
}
|
||||
};
|
||||
|
||||
// 执行初始化函数
|
||||
initSlaughterhouseData();
|
||||
Reference in New Issue
Block a user