fix: 简化真实采购创建并恢复客户端选择 (#112)
This commit is contained in:
@@ -205,20 +205,25 @@ func ListAssignableClients(db *sql.DB, actor *model.User, threshold time.Duratio
|
||||
return ListClientViewsForUser(db, actor, "", threshold)
|
||||
}
|
||||
|
||||
// ListLivePurchaseClients 返回当前用户能分配真实采购任务的在线客户端。
|
||||
//
|
||||
// 页面过滤只用于减少误选;创建任务时仍会在事务内重新校验可见范围和 live 能力。
|
||||
func ListLivePurchaseClients(db *sql.DB, actor *model.User, threshold time.Duration) ([]ClientView, error) {
|
||||
// PurchaseClientOptions 是采购弹窗的客户端候选和可选数量。
|
||||
// 非 live Client 也返回给页面显示禁用原因;创建时仍会在事务内复核能力。
|
||||
type PurchaseClientOptions struct {
|
||||
Rows []ClientView
|
||||
SelectableCount int
|
||||
}
|
||||
|
||||
// ListPurchaseClientOptions 返回当前用户可见的采购客户端。
|
||||
// live Client 即使暂时离线也可提前指派,等它上线后再领取任务。
|
||||
func ListPurchaseClientOptions(db *sql.DB, actor *model.User, threshold time.Duration) (*PurchaseClientOptions, error) {
|
||||
clients, err := ListClientViewsForUser(db, actor, "", threshold)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := make([]ClientView, 0, len(clients))
|
||||
result := &PurchaseClientOptions{Rows: clients}
|
||||
for _, client := range clients {
|
||||
if client.Status != "在线" || client.PurchaseMode != string(model.TaskExecutionLive) {
|
||||
continue
|
||||
if client.PurchaseMode == string(model.TaskExecutionLive) {
|
||||
result.SelectableCount++
|
||||
}
|
||||
result = append(result, client)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user