This commit is contained in:
SunYF
2026-10-26 16:32:35 +08:00
parent 4b14f9540a
commit f86feb2271
99 changed files with 1652 additions and 521 deletions
@@ -2,6 +2,7 @@ package production
import (
"net/http"
"strconv"
"bj_power_mes/common/httpx"
"bj_power_mes/internal/logic"
@@ -26,6 +27,7 @@ func CreateAlertRuleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
httpx.Fail(w, 3301, err.Error())
return
}
svcCtx.EventLog.Write(r.Context(), "alert.rule.create", "", operator(r, ""), "alert_rule", req.Name, "新增预警规则 "+req.Name, nil)
httpx.OkMessage(w, "保存成功", nil)
}
}
@@ -49,6 +51,7 @@ func UpdateAlertRuleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
httpx.Fail(w, 3302, err.Error())
return
}
svcCtx.EventLog.Write(r.Context(), "alert.rule.update", "", operator(r, ""), "alert_rule", strconv.Itoa(req.Id), "修改预警规则 "+req.Name, nil)
httpx.OkMessage(w, "保存成功", nil)
}
}
@@ -65,6 +68,7 @@ func DeleteAlertRuleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
httpx.Fail(w, 3303, err.Error())
return
}
svcCtx.EventLog.Write(r.Context(), "alert.rule.delete", "", operator(r, ""), "alert_rule", strconv.Itoa(id), "删除预警规则 id="+strconv.Itoa(id), nil)
httpx.OkMessage(w, "删除成功", nil)
}
}
@@ -23,6 +23,7 @@ func UpsertMaterialInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
httpx.Fail(w, 3120, err.Error())
return
}
svcCtx.EventLog.Write(r.Context(), "material.upsert", "", operator(r, ""), "material", req.Code, "物料档案 upsert "+req.Code, nil)
httpx.Ok(w, map[string]any{"created": created})
}
}
@@ -96,6 +96,17 @@ func DeleteProductTypeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
}
// RetryProductTypeSyncHandler POST /product-types/:id/sync-retry 手动重推单行物料到 WMS(替代原列表自动重推)
func RetryProductTypeSyncHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if err := logic.New(svcCtx).RetryProductTypeSync(r.Context(), pathID(r)); err != nil {
httpx.Fail(w, 3015, "重推失败:"+err.Error())
return
}
httpx.OkMessage(w, "重推成功", nil)
}
}
// SetProductTypeStatusHandler POST /product-types/status 物料档案启用/停用专用通道(body {id,isActive})
func SetProductTypeStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
@@ -154,8 +154,21 @@ func ListEventLogsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
isAdmin := false
if me != nil {
candidates = []string{me.Username, me.Name}
if rl, err := svcCtx.EntClient.Role.Get(context.Background(), me.RoleId); err == nil && rl.Code == "SUPER_ADMIN" {
isAdmin = true
}
// B3.3 isAdmin 优先取 JWT 中的 roleCode(上下文注入 / 解析 token),缺失时回退 DB Role 查 code,避免每次查库
if rc, ok := r.Context().Value("roleCode").(string); ok && rc != "" {
isAdmin = rc == "SUPER_ADMIN"
} else {
auth := strings.TrimPrefix(r.Header.Get("Authorization"), "Bearer ")
if auth != "" {
if claims, err := tokenx.Parse(svcCtx.Config.Auth.AccessSecret, auth); err == nil && claims.RoleCode == "SUPER_ADMIN" {
isAdmin = true
}
}
if !isAdmin && me != nil {
if rl, err := svcCtx.EntClient.Role.Get(context.Background(), me.RoleId); err == nil && rl.Code == "SUPER_ADMIN" {
isAdmin = true
}
}
}
explicitFilter := q.Get("operator")
@@ -165,7 +178,7 @@ func ListEventLogsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
list, total, err := logic.New(svcCtx).ListEventLogs(r.Context(),
q.Get("orderNo"), operatorCandidates(explicitFilter, candidates), q.Get("eventType"), fromMs, toMs, page, pageSize)
q.Get("orderNo"), operatorCandidates(explicitFilter, candidates), q.Get("eventType"), q.Get("entityType"), fromMs, toMs, page, pageSize)
if err != nil {
httpx.Fail(w, 3308, err.Error())
return