material_manage_system/internal/model/material_import.go
2026-10-10 14:56:42 +08:00

61 lines
1.9 KiB
Go
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.

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"
)