Files
cmautobuy/admin/service/inner_code_delete.go
T

39 lines
1.1 KiB
Go

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) > InnerCodeDeleteBatchLimit {
return 0, fmt.Errorf("一次最多删除当前页 %d 条记录", InnerCodeDeleteBatchLimit)
}
return repository.SoftDeleteInnerCodeRecords(db, unique, actorUserID, now.UTC().Format(model.TimeLayout))
}