WMS_MAIN/app/model/stock_check_record.js
liufumingren 190d3cf9e5 feat(stock.check): 盘点模块功能扩展并同步接口文档(0.3.227)
- 盘点明细/记录支持未知商品(stock_id 可空)与库位范围,模式/状态口径修正
- 新增静态盘点任务、公告相关模型与迁移,stock_warehouse 增加预警数量
- methods/system.json 同步盘点接口文档;headers platform 微信端取值 wx 修正为 miniprogram
2026-10-02 15:43:49 +08:00

126 lines
4.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
/**
* 库存盘点作业记录表模型(存储盘点的库位、数量信息)。
* 一个盘点明细(商品行或库位行)可在多个库位/商品维度多次上报,每次上报一条记录;
* 覆盖式语义为「同明细 + 同商品 + 同库位」(uk_detail_stock_location 唯一索引);
* 支持未知商品(仿收货明细口径):stock_id 为空(NULL)+ barcode + item_name,
* 唯一索引中 NULL 不参与唯一约束,未知商品查重由应用层保证。
* @param {import('egg').Application} app Egg 应用实例。
* @return {import('sequelize').ModelCtor<import('sequelize').Model>} Sequelize 模型。
*/
module.exports = app => {
const { BIGINT, STRING, INTEGER, DATE } = app.Sequelize;
const StockCheckRecord = app.model.define('wms_stock_check_record', {
id: {
type: BIGINT(20).UNSIGNED,
primaryKey: true,
autoIncrement: true,
comment: '主键',
},
check_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '关联盘点主表 wms_stock_check.id(冗余,便于按任务查记录)',
},
warehouse_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '仓库ID(冗余,隔离查询)',
},
detail_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '关联盘点明细 wms_stock_check_detail.id',
},
stock_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: '库存商品ID(冗余,商品维度查询),关联 wms_stock_warehouse.id;NULL=未知商品',
},
barcode: {
type: STRING(100),
allowNull: true,
comment: '扫描到的条码/编码(未知商品上报使用;已知商品可为空)',
},
item_name: {
type: STRING(255),
allowNull: true,
comment: '未知商品名称快照(缺省为条码);已知商品为空',
},
location_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: '库位ID,关联 wms_location_space.id;库位编码匹配时回填,未匹配为空',
},
location_code: {
type: STRING(50),
allowNull: false,
defaultValue: '',
comment: '库位编码(盘点上报的库位,空串表示无库位分组)',
},
quantity: {
type: INTEGER(12),
allowNull: false,
defaultValue: 0,
comment: '实盘数量(不小于0的整数)',
},
checker_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: '盘点人账户ID',
},
checker_name: {
type: STRING(50),
allowNull: true,
comment: '盘点人名称快照',
},
checked_at: {
type: DATE,
allowNull: true,
comment: '上报时间',
},
remark: {
type: STRING(500),
allowNull: true,
comment: '备注',
},
}, {
tableName: 'wms_stock_check_record',
comment: '库存盘点作业记录表(库位+数量)',
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
paranoid: false,
indexes: [
{ name: 'idx_check_id', fields: [ 'check_id' ] },
{ name: 'idx_detail_id', fields: [ 'detail_id' ] },
{ name: 'idx_stock_id', fields: [ 'stock_id' ] },
{ name: 'idx_warehouse_location', fields: [ 'warehouse_id', 'location_code' ] },
{ name: 'uk_detail_stock_location', unique: true, fields: [ 'detail_id', 'stock_id', 'location_code' ] },
],
});
StockCheckRecord.associate = function() {
const { StockCheck, StockCheckDetail, StockWarehouse } = app.model;
// 关联盘点主表
StockCheckRecord.belongsTo(StockCheck, {
foreignKey: 'check_id',
as: 'check',
});
// 关联盘点明细
StockCheckRecord.belongsTo(StockCheckDetail, {
foreignKey: 'detail_id',
as: 'detail',
});
// 关联库存商品
StockCheckRecord.belongsTo(StockWarehouse, {
foreignKey: 'stock_id',
as: 'stockWarehouse',
});
};
return StockCheckRecord;
};