修改小程序,前端,官网跳转路径
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
const sequelize = require('../config/database');
|
||||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../config/database.js');
|
||||
|
||||
const EpidemicAgency = sequelize.define('EpidemicAgency', {
|
||||
id: {
|
||||
@@ -49,6 +49,11 @@ const EpidemicAgency = sequelize.define('EpidemicAgency', {
|
||||
allowNull: false,
|
||||
comment: '成立日期'
|
||||
},
|
||||
epidemicScope: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
comment: '防疫范围'
|
||||
},
|
||||
description: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
|
||||
67
government-backend/models/HarmlessPlace.js
Normal file
67
government-backend/models/HarmlessPlace.js
Normal file
@@ -0,0 +1,67 @@
|
||||
const sequelize = require('../config/database');
|
||||
const { DataTypes } = require('sequelize');
|
||||
|
||||
const HarmlessPlace = sequelize.define('HarmlessPlace', {
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true,
|
||||
allowNull: false
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING(100),
|
||||
allowNull: false,
|
||||
comment: '场所名称'
|
||||
},
|
||||
address: {
|
||||
type: DataTypes.STRING(255),
|
||||
allowNull: false,
|
||||
comment: '地址'
|
||||
},
|
||||
contactPerson: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: false,
|
||||
comment: '联系人'
|
||||
},
|
||||
contactPhone: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: false,
|
||||
comment: '联系电话'
|
||||
},
|
||||
licenseNumber: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
comment: '许可证号'
|
||||
},
|
||||
status: {
|
||||
type: DataTypes.ENUM('正常', '维护中', '停用'),
|
||||
allowNull: false,
|
||||
defaultValue: '正常',
|
||||
comment: '状态'
|
||||
}
|
||||
}, {
|
||||
tableName: 'government_harmless_places',
|
||||
timestamps: true,
|
||||
createdAt: 'created_at',
|
||||
updatedAt: 'updated_at',
|
||||
paranoid: false,
|
||||
indexes: [
|
||||
{
|
||||
name: 'idx_name',
|
||||
fields: ['name']
|
||||
},
|
||||
{
|
||||
name: 'idx_status',
|
||||
fields: ['status']
|
||||
},
|
||||
{
|
||||
name: 'idx_license_number',
|
||||
fields: ['licenseNumber'],
|
||||
unique: true
|
||||
}
|
||||
],
|
||||
comment: '无害化场所管理表'
|
||||
});
|
||||
|
||||
module.exports = HarmlessPlace;
|
||||
85
government-backend/models/HarmlessRegistration.js
Normal file
85
government-backend/models/HarmlessRegistration.js
Normal file
@@ -0,0 +1,85 @@
|
||||
const { DataTypes, Sequelize } = require('sequelize');
|
||||
|
||||
module.exports = (sequelize) => {
|
||||
const HarmlessRegistration = sequelize.define('HarmlessRegistration', {
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true,
|
||||
allowNull: false
|
||||
},
|
||||
registrationNumber: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
comment: '登记编号'
|
||||
},
|
||||
animalType: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: false,
|
||||
comment: '动物类型'
|
||||
},
|
||||
quantity: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
comment: '数量',
|
||||
validate: {
|
||||
min: 1
|
||||
}
|
||||
},
|
||||
reason: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: false,
|
||||
comment: '无害化处理原因'
|
||||
},
|
||||
processingMethod: {
|
||||
type: DataTypes.STRING(100),
|
||||
allowNull: false,
|
||||
comment: '处理方式'
|
||||
},
|
||||
processingPlace: {
|
||||
type: DataTypes.STRING(100),
|
||||
allowNull: false,
|
||||
comment: '处理场所'
|
||||
},
|
||||
processingDate: {
|
||||
type: DataTypes.DATEONLY,
|
||||
allowNull: false,
|
||||
comment: '处理日期'
|
||||
},
|
||||
registrant: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: false,
|
||||
comment: '登记人'
|
||||
},
|
||||
status: {
|
||||
type: DataTypes.ENUM('待处理', '处理中', '已完成', '已取消'),
|
||||
allowNull: false,
|
||||
defaultValue: '待处理',
|
||||
comment: '状态'
|
||||
},
|
||||
createTime: {
|
||||
type: DataTypes.DATE,
|
||||
defaultValue: Sequelize.fn('NOW'),
|
||||
allowNull: false,
|
||||
comment: '创建时间'
|
||||
},
|
||||
updateTime: {
|
||||
type: DataTypes.DATE,
|
||||
defaultValue: Sequelize.fn('NOW'),
|
||||
allowNull: false,
|
||||
comment: '更新时间'
|
||||
}
|
||||
}, {
|
||||
tableName: 'government_harmless_registrations',
|
||||
timestamps: false,
|
||||
indexes: [
|
||||
{ name: 'idx_registrationNumber', fields: ['registrationNumber'] },
|
||||
{ name: 'idx_status', fields: ['status'] },
|
||||
{ name: 'idx_processingDate', fields: ['processingDate'] }
|
||||
],
|
||||
comment: '无害化登记管理表'
|
||||
});
|
||||
|
||||
return HarmlessRegistration;
|
||||
};
|
||||
78
government-backend/models/Slaughterhouse.js
Normal file
78
government-backend/models/Slaughterhouse.js
Normal file
@@ -0,0 +1,78 @@
|
||||
// 导入sequelize
|
||||
const sequelize = require('../config/database');
|
||||
const { DataTypes } = require('sequelize');
|
||||
|
||||
// 屠宰场数据模型
|
||||
const Slaughterhouse = sequelize.define('Slaughterhouse', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true,
|
||||
comment: '屠宰场ID'
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING(100),
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
comment: '屠宰场名称'
|
||||
},
|
||||
address: {
|
||||
type: DataTypes.STRING(255),
|
||||
allowNull: false,
|
||||
comment: '地址'
|
||||
},
|
||||
contactPerson: {
|
||||
field: 'contactPerson',
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
comment: '联系人'
|
||||
},
|
||||
contactPhone: {
|
||||
field: 'contactPhone',
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
comment: '联系电话'
|
||||
},
|
||||
licenseNumber: {
|
||||
field: 'licenseNumber',
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
comment: '许可证号'
|
||||
},
|
||||
status: {
|
||||
type: DataTypes.ENUM('active', 'inactive'),
|
||||
allowNull: false,
|
||||
defaultValue: 'active',
|
||||
comment: '状态(active: 正常, inactive: 停用)'
|
||||
},
|
||||
createTime: {
|
||||
field: 'createTime',
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW,
|
||||
comment: '创建时间'
|
||||
},
|
||||
created_by: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
comment: '创建人ID'
|
||||
},
|
||||
updated_by: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
comment: '更新人ID'
|
||||
}
|
||||
}, {
|
||||
tableName: 'government_slaughterhouses',
|
||||
timestamps: true,
|
||||
createdAt: 'created_at',
|
||||
updatedAt: 'updated_at',
|
||||
paranoid: false,
|
||||
indexes: [
|
||||
{ name: 'idx_name', fields: ['name'] },
|
||||
{ name: 'idx_licenseNumber', fields: ['licenseNumber'] },
|
||||
{ name: 'idx_status', fields: ['status'] }
|
||||
]
|
||||
});
|
||||
|
||||
module.exports = Slaughterhouse;
|
||||
100
government-backend/models/index.js
Normal file
100
government-backend/models/index.js
Normal file
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* 政府后端模型索引文件
|
||||
* @file index.js
|
||||
* @description 导出所有模型并建立关联关系
|
||||
*/
|
||||
const { sequelize } = require('../config/database');
|
||||
|
||||
// 导入所有模型
|
||||
const User = require('./User');
|
||||
const AdminStaff = require('./AdminStaff');
|
||||
const Department = require('./Department');
|
||||
const Position = require('./Position');
|
||||
const Farmer = require('./Farmer');
|
||||
const HarmlessPlace = require('./HarmlessPlace');
|
||||
const HarmlessRegistration = require('./HarmlessRegistration');
|
||||
const Material = require('./Material');
|
||||
const Slaughterhouse = require('./Slaughterhouse');
|
||||
const EpidemicAgency = require('./EpidemicAgency');
|
||||
const SmartCollar = require('./SmartCollar');
|
||||
const SmartEarmark = require('./SmartEarmark');
|
||||
const SmartHost = require('./SmartHost');
|
||||
const WarehouseTransaction = require('./WarehouseTransaction');
|
||||
|
||||
// 初始化所有模型
|
||||
const initModels = () => {
|
||||
try {
|
||||
// 处理直接导出的模型
|
||||
if (User && typeof User !== 'function') {
|
||||
// User模型已经直接导出,不需要额外处理
|
||||
}
|
||||
|
||||
// 处理需要sequelize参数的模型
|
||||
const modelsToInit = [
|
||||
AdminStaff,
|
||||
Department,
|
||||
Position,
|
||||
Farmer,
|
||||
HarmlessPlace,
|
||||
HarmlessRegistration,
|
||||
Material,
|
||||
Slaughterhouse,
|
||||
EpidemicAgency,
|
||||
SmartCollar,
|
||||
SmartEarmark,
|
||||
SmartHost,
|
||||
WarehouseTransaction
|
||||
];
|
||||
|
||||
// 初始化模型
|
||||
modelsToInit.forEach(modelFactory => {
|
||||
if (typeof modelFactory === 'function') {
|
||||
// 调用函数获取模型实例
|
||||
const model = modelFactory(sequelize);
|
||||
// 将初始化后的模型赋值回原来的变量
|
||||
Object.assign(module.exports, { [model.name]: model });
|
||||
}
|
||||
});
|
||||
|
||||
console.log('✅ 所有政府后端模型初始化完成');
|
||||
} catch (error) {
|
||||
console.error('❌ 政府后端模型初始化失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
// 初始化模型
|
||||
initModels();
|
||||
|
||||
// 导出sequelize和所有模型
|
||||
module.exports = {
|
||||
sequelize,
|
||||
User,
|
||||
AdminStaff,
|
||||
Department,
|
||||
Position,
|
||||
Farmer,
|
||||
HarmlessPlace,
|
||||
HarmlessRegistration,
|
||||
Material,
|
||||
Slaughterhouse,
|
||||
EpidemicAgency,
|
||||
SmartCollar,
|
||||
SmartEarmark,
|
||||
SmartHost,
|
||||
WarehouseTransaction
|
||||
};
|
||||
|
||||
// 同步所有模型到数据库(可选)
|
||||
const syncModels = async (options = {}) => {
|
||||
try {
|
||||
await sequelize.sync(options);
|
||||
console.log('✅ 政府后端所有模型已同步到数据库');
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('❌ 政府后端模型同步失败:', error);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// 添加syncModels到导出
|
||||
module.exports.syncModels = syncModels;
|
||||
Reference in New Issue
Block a user