30 lines
1.3 KiB
Go
30 lines
1.3 KiB
Go
package repository
|
|
|
|
import (
|
|
"github.com/wmms/wmms/internal/model"
|
|
"github.com/wmms/wmms/pkg/database"
|
|
)
|
|
|
|
// MaterialImportLogRepo 负责 material_import_logs 的写入,表里存的是文件级批次汇总
|
|
// (操作人、文件名、总行数、成功数)。
|
|
//
|
|
// 目前只写不读:没有查询接口也没有页面——逐条物料的溯源走日志页,成功导入的每件物料
|
|
// 都有一条带操作人和「批量导入创建」详情的 CREATE 记录。这张表留作将来做「导入历史」
|
|
// 入口时的数据源,暂时没有使用方。
|
|
type MaterialImportLogRepo struct{}
|
|
|
|
func NewMaterialImportLogRepo() *MaterialImportLogRepo { return &MaterialImportLogRepo{} }
|
|
|
|
// Create 写一条成功导入汇总,由服务在事务提交成功后调用。
|
|
// 失败导入不写记录,逐行错误明细只随接口响应返回,不落库。
|
|
func (r *MaterialImportLogRepo) Create(log *model.MaterialImportLog) error {
|
|
result, err := database.DB.Exec(
|
|
`INSERT INTO material_import_logs (organization_id, operator, file_name, total_rows, success_rows, failed_rows, status, failure_reason) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
log.OrganizationID, log.Operator, log.FileName, log.TotalRows, log.SuccessRows, log.FailedRows, log.Status, log.FailureReason)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
log.ID, err = result.LastInsertId()
|
|
return err
|
|
}
|