feat: 新增物料导入记录表与模型
This commit is contained in:
parent
616a4a3b1d
commit
84e7f4d7d0
File diff suppressed because it is too large
Load Diff
60
internal/model/material_import.go
Normal file
60
internal/model/material_import.go
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
package model
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
// MaterialImportRow 是解析后的一行原始数据。Row 保留 Excel 真实行号(从 1
|
||||||
|
// 开始、含表头行),校验失败时用它定位,用户可直接对着 Excel 找。
|
||||||
|
type MaterialImportRow struct {
|
||||||
|
Row int
|
||||||
|
Name string
|
||||||
|
Spec string
|
||||||
|
Unit string
|
||||||
|
MajorName string
|
||||||
|
MinorName string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Data 返回该行的原始内容,用于错误明细里的"原始数据"。
|
||||||
|
func (r MaterialImportRow) Data() map[string]string {
|
||||||
|
return map[string]string{
|
||||||
|
"name": r.Name,
|
||||||
|
"spec": r.Spec,
|
||||||
|
"unit": r.Unit,
|
||||||
|
"major": r.MajorName,
|
||||||
|
"minor": r.MinorName,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MaterialImportError 是一行的失败原因,Reason 可能包含多条,用中文分号连接。
|
||||||
|
type MaterialImportError struct {
|
||||||
|
Row int `json:"row"`
|
||||||
|
Data map[string]string `json:"data"`
|
||||||
|
Reason string `json:"reason"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MaterialImportResult 是一次导入的返回值。校验失败时 SuccessRows 为 0、
|
||||||
|
// Errors 非空;成功时 Errors 为空数组(不是 null)。
|
||||||
|
type MaterialImportResult struct {
|
||||||
|
TotalRows int `json:"total_rows"`
|
||||||
|
SuccessRows int `json:"success_rows"`
|
||||||
|
FailedRows int `json:"failed_rows"`
|
||||||
|
Errors []MaterialImportError `json:"errors"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MaterialImportLog 是一次导入的持久化记录,成功或失败都会写一条。
|
||||||
|
type MaterialImportLog struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
OrganizationID int64 `json:"organization_id"`
|
||||||
|
Operator string `json:"operator"`
|
||||||
|
FileName string `json:"file_name"`
|
||||||
|
TotalRows int `json:"total_rows"`
|
||||||
|
SuccessRows int `json:"success_rows"`
|
||||||
|
FailedRows int `json:"failed_rows"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
FailureReason string `json:"failure_reason"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
MaterialImportStatusSuccess = "success"
|
||||||
|
MaterialImportStatusFailed = "failed"
|
||||||
|
)
|
||||||
4
scripts/upgrades/2026-10-10-material-bulk-import.sql
Normal file
4
scripts/upgrades/2026-10-10-material-bulk-import.sql
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
-- 物料批量导入:新增导入记录表。仅在已部署的库上执行一次;本地开发库走 init.sql 重建。
|
||||||
|
SET NAMES utf8mb4;
|
||||||
|
CREATE TABLE material_import_logs (id BIGINT AUTO_INCREMENT PRIMARY KEY, organization_id BIGINT NOT NULL, operator VARCHAR(100) NOT NULL, file_name VARCHAR(255) NOT NULL, total_rows INT NOT NULL DEFAULT 0, success_rows INT NOT NULL DEFAULT 0, failed_rows INT NOT NULL DEFAULT 0, status VARCHAR(20) NOT NULL, failure_reason VARCHAR(1000) NOT NULL DEFAULT '', created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, KEY idx_material_import_logs_org_created(organization_id,created_at), FOREIGN KEY(organization_id) REFERENCES organizations(id)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
INSERT INTO schema_migrations(version,status,completed_at,details) VALUES('2026-10-10-material-bulk-import','completed',NOW(),JSON_OBJECT('version','2026-10-10-material-bulk-import','source','upgrade'));
|
||||||
Loading…
Reference in New Issue
Block a user