62 lines
2.0 KiB
Go
62 lines
2.0 KiB
Go
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 是一次成功导入的持久化汇总;失败不写记录。
|
||
// 保留失败字段以兼容已有表结构和历史数据,新记录失败数为 0、失败原因为空。
|
||
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"
|
||
)
|