Koleksi settings menyimpan konfigurasi per store — termasuk CS distribution (GlobalAssignation) yang dipakai rotator, dan pixel tracking.
Model
models/mongo_settings.go:17 — SettingsStruct:
| Field | BSON key | Tipe | Catatan |
|---|---|---|---|
ID | id | string | Primary key |
StoreId | store_id | string | Tenant scope |
GlobalAssignation | globalAssignation | GlobalAssignationStruct | Konfigurasi CS rotator |
Pixel | pixel | SettingPixelStruct | Access token pixel |
Sub-struct: GlobalAssignationStruct
mongo_settings.go:5:
| Field | BSON key | Tipe | Catatan |
|---|---|---|---|
Role | role | string | Role default CS |
Team | team | []string | Daftar CS ID yang eligible |
Distribution | distribution | []Distribution | Bobot per CS (untuk percentage) |
TypeDistribution | type_distribution | string | "percentage" atau lainnya → selectBySame |
Sub-struct: Distribution
mongo_product.go:20:
| Field | BSON key | Tipe | Catatan |
|---|---|---|---|
Name | — | string | Nama CS |
ID | — | string | CS ID (match dengan Team entry) |
Total | — | int | Bobot |
Sub-struct: SettingPixelStruct
mongo_settings.go:12:
| Field | BSON key | Tipe |
|---|---|---|
AccessToken | access_token | string |
Cara akses di handler
CS rotator
internal/service/chat_service.go:83-84:
col := mongo.MongoClient.Database(config.Env.DbName).Collection("settings")
var settings models.SettingsStruct
err := col.FindOne(ctx, bson.M{"store_id": storeID}).Decode(&settings)Strategi rotator
TypeDistribution menentukan strategi (lihat CS Rotator):
TypeDistribution | Strategi | Fungsi |
|---|---|---|
"percentage" | Weighted | selectByPercentage (chat_service.go:190) |
| (lainnya) | Least-loaded | selectBySame (chat_service.go:167) |
Percentage — contoh
{
"globalAssignation": {
"role": "Customer service",
"team": ["cs-001", "cs-002", "cs-003"],
"distribution": [
{"name": "CS Andi", "id": "cs-001", "total": 50},
{"name": "CS Budi", "id": "cs-002", "total": 30},
{"name": "CS Citra", "id": "cs-003", "total": 20}
],
"type_distribution": "percentage"
}
}- Total bobot: 100
- CS Andi dapat alokasi 50%, Budi 30%, Citra 20%
- Rotator pilih CS dengan rasio
activeCount / normalizedWeightterendah
Least-loaded — contoh
{
"globalAssignation": {
"role": "Customer service",
"team": ["cs-001", "cs-002", "cs-003"],
"distribution": [],
"type_distribution": "same"
}
}Distributionboleh kosong (tidak dipakai)- Rotator pilih CS dengan
activeCountpaling sedikit
Catatan
- Hanya satu dokumen settings per store (query by
store_id,FindOne) Distributionbisa kosong untuk strategi least-loaded- Jika
Teamkosong →ErrEmptyTeam(chat_service.go:28) - Jika
TypeDistribution="percentage"tapitotalBobot=0→ fall back keselectBySame(bukan error)
Kembali ke
- Schema Index — daftar semua koleksi
- CS Rotator — detail algoritma assignment