handleConflict 处理偏好冲突
(existing, new *Preference)
| 156 | |
| 157 | // handleConflict 处理偏好冲突 |
| 158 | func (pm *PreferenceManager) handleConflict(existing, new *Preference) error { |
| 159 | switch pm.config.ConflictStrategy { |
| 160 | case ConflictKeepLatest: |
| 161 | // 用新偏好替换旧偏好 |
| 162 | existing.Value = new.Value |
| 163 | existing.Strength = new.Strength |
| 164 | existing.Confidence = new.Confidence |
| 165 | existing.UpdatedAt = time.Now() |
| 166 | |
| 167 | case ConflictKeepStronger: |
| 168 | // 保留强度更高的 |
| 169 | if new.Strength > existing.Strength { |
| 170 | existing.Value = new.Value |
| 171 | existing.Strength = new.Strength |
| 172 | existing.Confidence = new.Confidence |
| 173 | existing.UpdatedAt = time.Now() |
| 174 | } |
| 175 | |
| 176 | case ConflictMerge: |
| 177 | // 合并:增加强度 |
| 178 | existing.Strength = (existing.Strength + new.Strength) / 2 |
| 179 | if existing.Strength > 1.0 { |
| 180 | existing.Strength = 1.0 |
| 181 | } |
| 182 | existing.Confidence = (existing.Confidence + new.Confidence) / 2 |
| 183 | existing.UpdatedAt = time.Now() |
| 184 | } |
| 185 | |
| 186 | return nil |
| 187 | } |
| 188 | |
| 189 | // GetPreference 获取偏好 |
| 190 | func (pm *PreferenceManager) GetPreference( |