Go refactoring: - Split handlers/pricing.go (2446→291 lines) into 5 focused files - Split services/stock_import.go (1334→~400 lines) into stock_mappings.go + stock_parse.go - Split services/sync/service.go (1290→~250 lines) into 3 files JS extraction: - Move all inline <script> blocks to web/static/js/ (6 files) - Templates reduced: admin_pricing 2873→521, lot 1531→304, vendor_mappings 1063→169, etc. Competitor pricelists (migrations 033-039): - qt_competitors + partnumber_log_competitors tables - Excel import with column mapping, dedup, bulk insert - p/n→lot resolution via weighted_median, discount applied - Unmapped p/ns written to qt_vendor_partnumber_seen - Quote counts (unique/total) shown on /admin/competitors - price_method="weighted_median", price_period_days=0 stored explicitly Fix price_method/price_period_days for warehouse items: - warehouse: weighted_avg, period=0 - competitor: weighted_median, period=0 - Removes misleading DB defaults (was: median/90) Update bible: architecture.md, pricelist.md, history.md Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
120 lines
3.0 KiB
Go
120 lines
3.0 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"git.mchus.pro/mchus/priceforge/internal/models"
|
|
"git.mchus.pro/mchus/priceforge/internal/repository"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func (h *PricingHandler) ListAlerts(c *gin.Context) {
|
|
// Check if we're in offline mode
|
|
if h.db == nil {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"alerts": []interface{}{},
|
|
"total": 0,
|
|
"page": 1,
|
|
"per_page": 20,
|
|
"offline": true,
|
|
})
|
|
return
|
|
}
|
|
|
|
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
|
perPage, _ := strconv.Atoi(c.DefaultQuery("per_page", "20"))
|
|
|
|
filter := repository.AlertFilter{
|
|
Status: models.AlertStatus(c.Query("status")),
|
|
Severity: models.AlertSeverity(c.Query("severity")),
|
|
Type: models.AlertType(c.Query("type")),
|
|
LotName: c.Query("lot_name"),
|
|
}
|
|
|
|
alertsList, total, err := h.alertService.List(filter, page, perPage)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"alerts": alertsList,
|
|
"total": total,
|
|
"page": page,
|
|
"per_page": perPage,
|
|
})
|
|
}
|
|
|
|
func (h *PricingHandler) AcknowledgeAlert(c *gin.Context) {
|
|
// Check if we're in offline mode
|
|
if h.db == nil {
|
|
c.JSON(http.StatusServiceUnavailable, gin.H{
|
|
"error": "Управление алертами доступно только в онлайн режиме",
|
|
"offline": true,
|
|
})
|
|
return
|
|
}
|
|
|
|
id, err := strconv.ParseUint(c.Param("id"), 10, 32)
|
|
if err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid alert id"})
|
|
return
|
|
}
|
|
|
|
if err := h.alertService.Acknowledge(uint(id)); err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{"message": "acknowledged"})
|
|
}
|
|
|
|
func (h *PricingHandler) ResolveAlert(c *gin.Context) {
|
|
// Check if we're in offline mode
|
|
if h.db == nil {
|
|
c.JSON(http.StatusServiceUnavailable, gin.H{
|
|
"error": "Управление алертами доступно только в онлайн режиме",
|
|
"offline": true,
|
|
})
|
|
return
|
|
}
|
|
|
|
id, err := strconv.ParseUint(c.Param("id"), 10, 32)
|
|
if err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid alert id"})
|
|
return
|
|
}
|
|
|
|
if err := h.alertService.Resolve(uint(id)); err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{"message": "resolved"})
|
|
}
|
|
|
|
func (h *PricingHandler) IgnoreAlert(c *gin.Context) {
|
|
// Check if we're in offline mode
|
|
if h.db == nil {
|
|
c.JSON(http.StatusServiceUnavailable, gin.H{
|
|
"error": "Управление алертами доступно только в онлайн режиме",
|
|
"offline": true,
|
|
})
|
|
return
|
|
}
|
|
|
|
id, err := strconv.ParseUint(c.Param("id"), 10, 32)
|
|
if err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid alert id"})
|
|
return
|
|
}
|
|
|
|
if err := h.alertService.Ignore(uint(id)); err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{"message": "ignored"})
|
|
}
|