完善保险端前后端和养殖端小程序

This commit is contained in:
xuqiuyun
2025-09-22 19:09:45 +08:00
parent 02a25515a9
commit 325c114c38
256 changed files with 48348 additions and 4444 deletions

View File

@@ -85,21 +85,21 @@ const CattleBatch = sequelize.define('CattleBatch', {
comment: '批次设置表'
});
// 定义关联关系
CattleBatch.associate = (models) => {
// 批次属于农场
CattleBatch.belongsTo(models.Farm, {
foreignKey: 'farmId',
as: 'farm'
});
// 关联关系已在 models/index.js 中定义
// CattleBatch.associate = (models) => {
// // 批次属于农场
// CattleBatch.belongsTo(models.Farm, {
// foreignKey: 'farmId',
// as: 'farm'
// });
// 批次与动物的多对多关系
CattleBatch.belongsToMany(models.Animal, {
through: 'cattle_batch_animals',
foreignKey: 'batch_id',
otherKey: 'animal_id',
as: 'animals'
});
};
// // 批次与动物的多对多关系
// CattleBatch.belongsToMany(models.Animal, {
// through: 'cattle_batch_animals',
// foreignKey: 'batch_id',
// otherKey: 'animal_id',
// as: 'animals'
// });
// };
module.exports = CattleBatch;

View File

@@ -86,25 +86,25 @@ const CattleExitRecord = sequelize.define('CattleExitRecord', {
comment: '离栏记录表'
});
// 定义关联关系
CattleExitRecord.associate = (models) => {
// 离栏记录属于牛只
CattleExitRecord.belongsTo(models.IotCattle, {
foreignKey: 'animalId',
as: 'cattle'
});
// 关联关系已在 models/index.js 中定义
// CattleExitRecord.associate = (models) => {
// // 离栏记录属于牛只
// CattleExitRecord.belongsTo(models.IotCattle, {
// foreignKey: 'animalId',
// as: 'cattle'
// });
// 离栏记录属于原栏舍
CattleExitRecord.belongsTo(models.CattlePen, {
foreignKey: 'originalPenId',
as: 'originalPen'
});
// // 离栏记录属于原栏舍
// CattleExitRecord.belongsTo(models.CattlePen, {
// foreignKey: 'originalPenId',
// as: 'originalPen'
// });
// 离栏记录属于农场
CattleExitRecord.belongsTo(models.Farm, {
foreignKey: 'farmId',
as: 'farm'
});
};
// // 离栏记录属于农场
// CattleExitRecord.belongsTo(models.Farm, {
// foreignKey: 'farmId',
// as: 'farm'
// });
// };
module.exports = CattleExitRecord;

View File

@@ -71,19 +71,19 @@ const CattlePen = sequelize.define('CattlePen', {
comment: '栏舍设置表'
});
// 定义关联关系
CattlePen.associate = (models) => {
// 栏舍属于农场
CattlePen.belongsTo(models.Farm, {
foreignKey: 'farmId',
as: 'farm'
});
// 关联关系已在 models/index.js 中定义
// CattlePen.associate = (models) => {
// // 栏舍属于农场
// CattlePen.belongsTo(models.Farm, {
// foreignKey: 'farmId',
// as: 'farm'
// });
// 栏舍有多个动物
CattlePen.hasMany(models.Animal, {
foreignKey: 'penId',
as: 'animals'
});
};
// // 栏舍有多个动物
// CattlePen.hasMany(models.Animal, {
// foreignKey: 'penId',
// as: 'animals'
// });
// };
module.exports = CattlePen;

View File

@@ -80,31 +80,31 @@ const CattleTransferRecord = sequelize.define('CattleTransferRecord', {
comment: '转栏记录表'
});
// 定义关联关系
CattleTransferRecord.associate = (models) => {
// 转栏记录属于牛只
CattleTransferRecord.belongsTo(models.IotCattle, {
foreignKey: 'animalId',
as: 'cattle'
});
// 关联关系已在 models/index.js 中定义
// CattleTransferRecord.associate = (models) => {
// // 转栏记录属于牛只
// CattleTransferRecord.belongsTo(models.IotCattle, {
// foreignKey: 'animalId',
// as: 'cattle'
// });
// 转栏记录属于转出栏舍
CattleTransferRecord.belongsTo(models.CattlePen, {
foreignKey: 'fromPenId',
as: 'fromPen'
});
// // 转栏记录属于转出栏舍
// CattleTransferRecord.belongsTo(models.CattlePen, {
// foreignKey: 'fromPenId',
// as: 'fromPen'
// });
// 转栏记录属于转入栏舍
CattleTransferRecord.belongsTo(models.CattlePen, {
foreignKey: 'toPenId',
as: 'toPen'
});
// // 转栏记录属于转入栏舍
// CattleTransferRecord.belongsTo(models.CattlePen, {
// foreignKey: 'toPenId',
// as: 'toPen'
// });
// 转栏记录属于农场
CattleTransferRecord.belongsTo(models.Farm, {
foreignKey: 'farmId',
as: 'farm'
});
};
// // 转栏记录属于农场
// CattleTransferRecord.belongsTo(models.Farm, {
// foreignKey: 'farmId',
// as: 'farm'
// });
// };
module.exports = CattleTransferRecord;

View File

@@ -33,13 +33,14 @@ class CattleType extends BaseModel {
});
}
static associate(models) {
// 一个品种可以有多个牛只
this.hasMany(models.IotCattle, {
foreignKey: 'varieties',
as: 'cattle'
});
}
// 关联关系已在 models/index.js 中定义
// static associate(models) {
// // 一个品种可以有多个牛只
// this.hasMany(models.IotCattle, {
// foreignKey: 'varieties',
// as: 'cattle'
// });
// }
}
module.exports = CattleType;

View File

@@ -33,13 +33,14 @@ class CattleUser extends BaseModel {
});
}
static associate(models) {
// 一个用途可以有多个牛只
this.hasMany(models.IotCattle, {
foreignKey: 'user_id',
as: 'cattle'
});
}
// 关联关系已在 models/index.js 中定义
// static associate(models) {
// // 一个用途可以有多个牛只
// this.hasMany(models.IotCattle, {
// foreignKey: 'user_id',
// as: 'cattle'
// });
// }
}
module.exports = CattleUser;

View File

@@ -119,15 +119,15 @@ class ElectronicFence extends BaseModel {
}
/**
* 定义关联关系
* 定义关联关系(已在 models/index.js 中定义)
*/
static associate(models) {
// 围栏与农场关联(可选)
this.belongsTo(models.Farm, {
foreignKey: 'farm_id',
as: 'farm'
})
}
// static associate(models) {
// // 围栏与农场关联(可选)
// this.belongsTo(models.Farm, {
// foreignKey: 'farm_id',
// as: 'farm'
// })
// }
/**
* 获取围栏类型文本

View File

@@ -303,31 +303,31 @@ const IotCattle = sequelize.define('IotCattle', {
comment: '物联网牛只表'
});
// 定义关联关系
IotCattle.associate = (models) => {
// 关联到农场
IotCattle.belongsTo(models.Farm, {
foreignKey: 'orgId',
as: 'farm'
});
// 关联关系已在 models/index.js 中定义
// IotCattle.associate = (models) => {
// // 关联到农场
// IotCattle.belongsTo(models.Farm, {
// foreignKey: 'orgId',
// as: 'farm'
// });
// 关联到批次
IotCattle.belongsTo(models.CattleBatch, {
foreignKey: 'batchId',
as: 'batch'
});
// // 关联到批次
// IotCattle.belongsTo(models.CattleBatch, {
// foreignKey: 'batchId',
// as: 'batch'
// });
// 关联到栏舍
IotCattle.belongsTo(models.CattlePen, {
foreignKey: 'penId',
as: 'pen'
});
// // 关联到栏舍
// IotCattle.belongsTo(models.CattlePen, {
// foreignKey: 'penId',
// as: 'pen'
// });
// 关联到围栏
IotCattle.belongsTo(models.ElectronicFence, {
foreignKey: 'fenceId',
as: 'fence'
});
};
// // 关联到围栏
// IotCattle.belongsTo(models.ElectronicFence, {
// foreignKey: 'fenceId',
// as: 'fence'
// });
// };
module.exports = IotCattle;

View File

@@ -104,6 +104,8 @@ Role.init({
updatedAt: false
});
// 关联关系已在 models/index.js 中定义
/**
* 导出角色模型
* @exports Role

View File

@@ -197,4 +197,6 @@ User.init({
}
});
// 关联关系已在 models/index.js 中定义
module.exports = User;

View File

@@ -557,9 +557,9 @@ const models = {
OperationLog
};
// 建立关联关系(暂时禁用,避免冲突)
// Object.keys(models).forEach(modelName => {
// if (models[modelName].associate) {
// models[modelName].associate(models);
// }
// });
// 建立关联关系
Object.keys(models).forEach(modelName => {
if (models[modelName].associate) {
models[modelName].associate(models);
}
});