feat: 档口入库码支持软删除与重导恢复 (#238)
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"cmautobuy/admin/model"
|
||||
"cmautobuy/admin/repository"
|
||||
)
|
||||
|
||||
// DeleteInnerCodes 软删除当前页选中的档口入库码记录。
|
||||
// 删除只隐藏本地记录,不取消在途请求,也不撤销顺运宝远端值。
|
||||
func DeleteInnerCodes(db *sql.DB, ids []int64, actorUserID string, now time.Time) (int, error) {
|
||||
if len(ids) == 0 {
|
||||
return 0, fmt.Errorf("请先选择要删除的记录")
|
||||
}
|
||||
if strings.TrimSpace(actorUserID) == "" {
|
||||
return 0, fmt.Errorf("删除账号不能为空")
|
||||
}
|
||||
seen := make(map[int64]bool, len(ids))
|
||||
unique := make([]int64, 0, len(ids))
|
||||
for _, id := range ids {
|
||||
if id <= 0 || seen[id] {
|
||||
continue
|
||||
}
|
||||
seen[id] = true
|
||||
unique = append(unique, id)
|
||||
}
|
||||
if len(unique) == 0 {
|
||||
return 0, fmt.Errorf("没有有效的档口入库码记录")
|
||||
}
|
||||
if len(unique) > PageSize {
|
||||
return 0, fmt.Errorf("一次最多删除当前页 %d 条记录", PageSize)
|
||||
}
|
||||
return repository.SoftDeleteInnerCodeRecords(db, unique, actorUserID, now.UTC().Format(model.TimeLayout))
|
||||
}
|
||||
@@ -45,6 +45,7 @@ type InnerCodeImportResult struct {
|
||||
TotalRows int
|
||||
CreatedCount int
|
||||
UpdatedCount int
|
||||
RestoredCount int
|
||||
DuplicateRows int
|
||||
}
|
||||
|
||||
@@ -130,10 +131,16 @@ func ImportInnerCodeExcel(db *sql.DB, path, originalFilename, actorUserID string
|
||||
return nil, fmt.Errorf("%w:Excel 第 %d 行的入库码 %q 在该业务日期已属于另一条记录",
|
||||
ErrInvalidInnerCodeImport, row.SourceRow, row.InnerCode)
|
||||
}
|
||||
if errors.Is(err, repository.ErrInnerCodeRestoreConflict) {
|
||||
return nil, fmt.Errorf("%w:Excel 第 %d 行对应的已删除记录已有远端结果,且入库码发生变化;请人工核对后处理",
|
||||
ErrInvalidInnerCodeImport, row.SourceRow)
|
||||
}
|
||||
return nil, fmt.Errorf("导入 Excel 第 %d 行失败: %w", row.SourceRow, err)
|
||||
}
|
||||
if outcome == repository.InnerCodeImportCreated {
|
||||
result.CreatedCount++
|
||||
} else if outcome == repository.InnerCodeImportRestored {
|
||||
result.RestoredCount++
|
||||
} else {
|
||||
result.UpdatedCount++
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user