feat(耗材管理): 添加扫码功能及SN查询接口
实现耗材SN扫码功能,包括扫码添加、入库和出库操作 添加后端API接口根据SN查询耗材信息 优化耗材表单UI,分步骤展示不同信息区块 同步数据库模型确保耗材相关表结构正确
This commit is contained in:
@@ -179,6 +179,23 @@ router.post('/import', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/by-sn/:sn', async (req, res) => {
|
||||
try {
|
||||
const sn = req.params.sn;
|
||||
const consumables = await Consumable.findAll();
|
||||
const consumable = consumables.find(c => {
|
||||
const snList = c.snList || [];
|
||||
return snList.includes(sn);
|
||||
});
|
||||
res.json({
|
||||
found: !!consumable,
|
||||
consumable
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/categories/list', async (req, res) => {
|
||||
try {
|
||||
const categories = await Consumable.findAll({
|
||||
|
||||
@@ -9,6 +9,19 @@
|
||||
|
||||
const { sequelize } = require('../db');
|
||||
const SystemSetting = require('../models/SystemSetting');
|
||||
const Consumable = require('../models/Consumable');
|
||||
const ConsumableLog = require('../models/ConsumableLog');
|
||||
const ConsumableCategory = require('../models/ConsumableCategory');
|
||||
const ConsumableRecord = require('../models/ConsumableRecord');
|
||||
const ConsumableLogArchive = require('../models/ConsumableLogArchive');
|
||||
const Device = require('../models/Device');
|
||||
const Rack = require('../models/Rack');
|
||||
const Room = require('../models/Room');
|
||||
const User = require('../models/User');
|
||||
const FaultCategory = require('../models/FaultCategory');
|
||||
const InventoryPlan = require('../models/InventoryPlan');
|
||||
const InventoryTask = require('../models/InventoryTask');
|
||||
const InventoryRecord = require('../models/InventoryRecord');
|
||||
|
||||
// 默认系统设置(包含中文描述)
|
||||
const defaultSettings = [
|
||||
@@ -50,8 +63,31 @@ async function initDatabase() {
|
||||
await sequelize.authenticate();
|
||||
console.log('数据库连接成功');
|
||||
|
||||
// 同步所有模型
|
||||
await sequelize.sync({ force: false, alter: true });
|
||||
// 同步所有模型(按依赖顺序)
|
||||
console.log('开始同步模型...');
|
||||
|
||||
// 基础模型
|
||||
await User.sync({ alter: true });
|
||||
await Room.sync({ alter: true });
|
||||
await Rack.sync({ alter: true });
|
||||
await Device.sync({ alter: true });
|
||||
await FaultCategory.sync({ alter: true });
|
||||
|
||||
// 耗材相关模型
|
||||
await ConsumableCategory.sync({ alter: true });
|
||||
await Consumable.sync({ alter: true });
|
||||
await ConsumableLog.sync({ alter: true });
|
||||
await ConsumableRecord.sync({ alter: true });
|
||||
await ConsumableLogArchive.sync({ alter: true });
|
||||
|
||||
// 盘点相关模型
|
||||
await InventoryPlan.sync({ alter: true });
|
||||
await InventoryTask.sync({ alter: true });
|
||||
await InventoryRecord.sync({ alter: true });
|
||||
|
||||
// 系统设置
|
||||
await SystemSetting.sync({ alter: true });
|
||||
|
||||
console.log('数据库表结构同步完成');
|
||||
|
||||
// 初始化或更新系统设置
|
||||
|
||||
@@ -43,6 +43,24 @@ sequelize.authenticate()
|
||||
const SystemSetting = require('./models/SystemSetting');
|
||||
return SystemSetting.sync();
|
||||
})
|
||||
.then(() => {
|
||||
// 同步耗材模型
|
||||
const Consumable = require('./models/Consumable');
|
||||
const ConsumableLog = require('./models/ConsumableLog');
|
||||
const ConsumableCategory = require('./models/ConsumableCategory');
|
||||
const ConsumableRecord = require('./models/ConsumableRecord');
|
||||
const ConsumableLogArchive = require('./models/ConsumableLogArchive');
|
||||
return Promise.all([
|
||||
Consumable.sync({ alter: true }),
|
||||
ConsumableLog.sync(),
|
||||
ConsumableCategory.sync(),
|
||||
ConsumableRecord.sync(),
|
||||
ConsumableLogArchive.sync()
|
||||
]);
|
||||
})
|
||||
.then(() => {
|
||||
console.log('耗材模型同步完成');
|
||||
})
|
||||
.then(() => {
|
||||
// 同步盘点模型
|
||||
const InventoryPlan = require('./models/InventoryPlan');
|
||||
@@ -57,6 +75,24 @@ sequelize.authenticate()
|
||||
.then(() => {
|
||||
console.log('盘点模型同步完成');
|
||||
})
|
||||
.then(() => {
|
||||
// 同步耗材相关模型
|
||||
const Consumable = require('./models/Consumable');
|
||||
const ConsumableLog = require('./models/ConsumableLog');
|
||||
const ConsumableCategory = require('./models/ConsumableCategory');
|
||||
const ConsumableRecord = require('./models/ConsumableRecord');
|
||||
const ConsumableLogArchive = require('./models/ConsumableLogArchive');
|
||||
return Promise.all([
|
||||
Consumable.sync({ alter: true }),
|
||||
ConsumableLog.sync(),
|
||||
ConsumableCategory.sync(),
|
||||
ConsumableRecord.sync(),
|
||||
ConsumableLogArchive.sync()
|
||||
]);
|
||||
})
|
||||
.then(() => {
|
||||
console.log('耗材模型同步完成');
|
||||
})
|
||||
.then(() => {
|
||||
// 初始化系统设置默认值(关键:确保部署时数据正确初始化)
|
||||
console.log('开始初始化系统设置默认值...');
|
||||
|
||||
@@ -253,6 +253,7 @@ export const consumableAPI = {
|
||||
quickInOut: data => cachedAPI.post('/consumables/quick-inout', data),
|
||||
getStatistics: () => cachedAPI.get('/consumables/statistics/summary'),
|
||||
getLowStock: () => cachedAPI.get('/consumables/low-stock'),
|
||||
getBySn: sn => cachedAPI.get(`/consumables/by-sn/${encodeURIComponent(sn)}`),
|
||||
};
|
||||
|
||||
export const consumableCategoryAPI = {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user