WMS_MAIN/app/model/stock_check.js

142 lines
3.9 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';
/**
* 库存盘点主表模型。
* @param {import('egg').Application} app Egg 应用实例。
* @return {import('sequelize').ModelCtor<import('sequelize').Model>} Sequelize 模型。
*/
module.exports = app => {
const { BIGINT, STRING, INTEGER, DATE, JSON: JSON_TYPE } = app.Sequelize;
const StockCheck = app.model.define('wms_stock_check', {
id: {
type: BIGINT(20).UNSIGNED,
primaryKey: true,
autoIncrement: true,
comment: '主键',
},
warehouse_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '仓库ID(数据隔离维度)',
},
check_no: {
type: STRING(50),
allowNull: false,
comment: '盘点单号,唯一,生成规则:PD+YYYYMMDD+6位序号',
},
title: {
type: STRING(200),
allowNull: true,
comment: '盘点名称/主题,非必填',
},
type: {
type: STRING(20),
allowNull: false,
defaultValue: 'all',
comment: '盘点范围类型:all=全盘,store=按货主,goods=按商品,location=按库位',
},
mode: {
type: STRING(20),
allowNull: false,
defaultValue: 'open',
comment: '盘点方式:open=明盘(可见账面数量),blind=盲盘(不可见账面数量)',
},
store_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: '货主ID,按货主盘点时必填(type=store)',
},
scope_snapshot: {
type: JSON_TYPE,
allowNull: true,
comment: '盘点范围条件快照(JSON),如商品ID列表/库位ID列表,供盘点对比与追溯',
},
status: {
type: STRING(20),
allowNull: false,
defaultValue: 'pending',
comment: '盘点状态:pending=待盘点,in_progress=盘点中,checked=已盘待确认,confirmed=已确认,completed=已完成,cancelled=已取消',
},
detail_status: {
type: STRING(30),
allowNull: false,
defaultValue: 'none_checked',
comment: '明细盘点进度:none_checked=未盘,partial_checked=部分已盘,all_checked=全部已盘',
},
check_date: {
type: DATE,
allowNull: false,
comment: '盘点日期',
},
start_time: {
type: DATE,
allowNull: true,
comment: '实际开始时间',
},
end_time: {
type: DATE,
allowNull: true,
comment: '实际结束时间',
},
creator_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '创建人账户ID',
},
creator_name: {
type: STRING(50),
allowNull: true,
comment: '创建人名称快照',
},
total_items: {
type: INTEGER(11),
allowNull: false,
defaultValue: 0,
comment: '明细行数(盘点任务总行数)',
},
checked_items: {
type: INTEGER(11),
allowNull: false,
defaultValue: 0,
comment: '已盘行数',
},
diff_items: {
type: INTEGER(11),
allowNull: false,
defaultValue: 0,
comment: '差异行数(账面与实盘不一致的行数)',
},
remark: {
type: STRING(500),
allowNull: true,
comment: '备注',
},
}, {
tableName: 'wms_stock_check',
comment: '库存盘点主表',
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
paranoid: false,
indexes: [
{ name: 'uk_check_no', unique: true, fields: [ 'check_no' ] },
{ name: 'idx_warehouse_check_date', fields: [ 'warehouse_id', 'check_date' ] },
{ name: 'idx_warehouse_status', fields: [ 'warehouse_id', 'status' ] },
{ name: 'idx_store_id', fields: [ 'store_id' ] },
{ name: 'idx_creator_id', fields: [ 'creator_id' ] },
],
});
StockCheck.associate = function() {
const { StockCheckDetail } = app.model;
// 一个盘点单对应多条盘点明细
StockCheck.hasMany(StockCheckDetail, {
foreignKey: 'check_id',
as: 'details',
});
};
return StockCheck;
};