All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 9m23s
新增 000225 迁移:运营弹窗配置表 tb_h5_popup_configuration(页面/范围/优先级/频率/受控动作/启停/有效期/版本) 与 tb_notification 可空 JSONB 列 popup_snapshot。 新增通知直建窄接口 DirectWriter.CreateOrGetPersonal:与 Outbox 消费共用 prepareDelivery 的渲染、 展示期与 CreateIdempotent 规则,冲突时回查返回既有行;同步扩展个人通知查询与已读两处类型白名单, 并按个人客户入口补齐投递审计来源。 新增 H5 候选与风险换卡:GET /api/c/v1/popup-candidates 先判风险资格(广电卡 + 风险停机 + 无活动物流换货单),命中只返回风险候选;未命中再按时间/启停/页面/店铺/设备类型/卡类型范围/频率 匹配运营配置。POST /api/c/v1/risk-exchanges/:asset_id/address 锁资产行后幂等创建待发货物流换货单, 首次地址锁定,不沿用资产级群发通知。 新增后台运营弹窗配置 CRUD 与启停(仅超级管理员与平台账号),更新递增版本并刷新最近更新时间, 标题与正文统一拒绝 URL 与前端路由,全部写操作记录操作者、前后值、版本与时间。 同步 OpenAPI(cmd/gendocs、cmd/api/docs.go、pkg/openapi/handlers.go)与参数校验中文提示共用实现。
179 lines
6.1 KiB
Go
179 lines
6.1 KiB
Go
package admin
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"github.com/go-playground/validator/v10"
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
h5popupapp "github.com/break/junhong_cmp_fiber/internal/application/h5popup"
|
|
"github.com/break/junhong_cmp_fiber/internal/handler/validation"
|
|
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
|
h5popupquery "github.com/break/junhong_cmp_fiber/internal/query/h5popup"
|
|
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
|
"github.com/break/junhong_cmp_fiber/pkg/response"
|
|
)
|
|
|
|
// H5PopupConfigurationHandler H5 运营弹窗配置后台 Handler。
|
|
// 全部接口仅超级管理员与平台账号可用,代理与企业统一返回 403。
|
|
type H5PopupConfigurationHandler struct {
|
|
service *h5popupapp.ConfigurationService
|
|
query *h5popupquery.Query
|
|
validator *validator.Validate
|
|
}
|
|
|
|
// NewH5PopupConfigurationHandler 创建 H5 运营弹窗配置后台 Handler。
|
|
func NewH5PopupConfigurationHandler(service *h5popupapp.ConfigurationService, query *h5popupquery.Query, validate *validator.Validate) *H5PopupConfigurationHandler {
|
|
return &H5PopupConfigurationHandler{service: service, query: query, validator: validate}
|
|
}
|
|
|
|
// ListH5PopupConfigurations 查询运营弹窗配置列表。
|
|
// GET /api/admin/h5-popup-configurations
|
|
func (h *H5PopupConfigurationHandler) ListH5PopupConfigurations(c *fiber.Ctx) error {
|
|
if err := requirePlatformManagement(c); err != nil {
|
|
return err
|
|
}
|
|
var request dto.H5PopupConfigurationListRequest
|
|
if err := c.QueryParser(&request); err != nil {
|
|
return errors.New(errors.CodeInvalidParam)
|
|
}
|
|
if h.validator != nil {
|
|
if err := h.validator.Struct(&request); err != nil {
|
|
return errors.New(errors.CodeInvalidParam, validation.Message("运营弹窗配置列表参数不合法", &request, err))
|
|
}
|
|
}
|
|
if h.query == nil {
|
|
return errors.New(errors.CodeServiceUnavailable, "运营弹窗配置维护能力尚未配置")
|
|
}
|
|
result, err := h.query.List(c.UserContext(), request)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return response.SuccessWithPagination(c, result.Items, result.Total, result.Page, result.Size)
|
|
}
|
|
|
|
// GetH5PopupConfiguration 查询运营弹窗配置详情。
|
|
// GET /api/admin/h5-popup-configurations/:id
|
|
func (h *H5PopupConfigurationHandler) GetH5PopupConfiguration(c *fiber.Ctx) error {
|
|
if err := requirePlatformManagement(c); err != nil {
|
|
return err
|
|
}
|
|
id, err := h.parseID(c)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if h.query == nil {
|
|
return errors.New(errors.CodeServiceUnavailable, "运营弹窗配置维护能力尚未配置")
|
|
}
|
|
result, err := h.query.Get(c.UserContext(), id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return response.Success(c, result)
|
|
}
|
|
|
|
// CreateH5PopupConfiguration 创建运营弹窗配置,初始版本为 1。
|
|
// POST /api/admin/h5-popup-configurations
|
|
func (h *H5PopupConfigurationHandler) CreateH5PopupConfiguration(c *fiber.Ctx) error {
|
|
if err := requirePlatformManagement(c); err != nil {
|
|
return err
|
|
}
|
|
var request dto.CreateH5PopupConfigurationRequest
|
|
if err := c.BodyParser(&request); err != nil {
|
|
return errors.New(errors.CodeInvalidParam)
|
|
}
|
|
if h.validator != nil {
|
|
if err := h.validator.Struct(&request); err != nil {
|
|
return errors.New(errors.CodeInvalidParam, validation.Message("创建运营弹窗配置参数不合法", &request, err))
|
|
}
|
|
}
|
|
if h.service == nil || h.query == nil {
|
|
return errors.New(errors.CodeServiceUnavailable, "运营弹窗配置维护能力尚未配置")
|
|
}
|
|
id, err := h.service.Create(c.UserContext(), request)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
result, err := h.query.Get(c.UserContext(), id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return response.Success(c, result)
|
|
}
|
|
|
|
// UpdateH5PopupConfiguration 更新运营弹窗配置并递增版本。
|
|
// PUT /api/admin/h5-popup-configurations/:id
|
|
func (h *H5PopupConfigurationHandler) UpdateH5PopupConfiguration(c *fiber.Ctx) error {
|
|
if err := requirePlatformManagement(c); err != nil {
|
|
return err
|
|
}
|
|
id, err := h.parseID(c)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
var request dto.UpdateH5PopupConfigurationParams
|
|
if err := c.BodyParser(&request); err != nil {
|
|
return errors.New(errors.CodeInvalidParam)
|
|
}
|
|
// 路径来源字段必须由 Handler 回填后再校验,避免被请求体覆盖,也避免 required 恒失败。
|
|
request.ID = id
|
|
if h.validator != nil {
|
|
if err := h.validator.Struct(&request); err != nil {
|
|
return errors.New(errors.CodeInvalidParam, validation.Message("更新运营弹窗配置参数不合法", &request, err))
|
|
}
|
|
}
|
|
if h.service == nil || h.query == nil {
|
|
return errors.New(errors.CodeServiceUnavailable, "运营弹窗配置维护能力尚未配置")
|
|
}
|
|
if err := h.service.Update(c.UserContext(), id, request.UpdateH5PopupConfigurationRequest); err != nil {
|
|
return err
|
|
}
|
|
result, err := h.query.Get(c.UserContext(), id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return response.Success(c, result)
|
|
}
|
|
|
|
// EnableH5PopupConfiguration 启用运营弹窗配置,仅影响后续候选并刷新最近更新时间。
|
|
// POST /api/admin/h5-popup-configurations/:id/enable
|
|
func (h *H5PopupConfigurationHandler) EnableH5PopupConfiguration(c *fiber.Ctx) error {
|
|
return h.setEnabled(c, true)
|
|
}
|
|
|
|
// DisableH5PopupConfiguration 停用运营弹窗配置,仅影响后续候选并刷新最近更新时间。
|
|
// POST /api/admin/h5-popup-configurations/:id/disable
|
|
func (h *H5PopupConfigurationHandler) DisableH5PopupConfiguration(c *fiber.Ctx) error {
|
|
return h.setEnabled(c, false)
|
|
}
|
|
|
|
func (h *H5PopupConfigurationHandler) setEnabled(c *fiber.Ctx, enabled bool) error {
|
|
if err := requirePlatformManagement(c); err != nil {
|
|
return err
|
|
}
|
|
id, err := h.parseID(c)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if h.service == nil || h.query == nil {
|
|
return errors.New(errors.CodeServiceUnavailable, "运营弹窗配置维护能力尚未配置")
|
|
}
|
|
if err := h.service.SetEnabled(c.UserContext(), id, enabled); err != nil {
|
|
return err
|
|
}
|
|
result, err := h.query.Get(c.UserContext(), id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return response.Success(c, result)
|
|
}
|
|
|
|
// parseID 从路径解析运营弹窗配置 ID。
|
|
func (h *H5PopupConfigurationHandler) parseID(c *fiber.Ctx) (uint, error) {
|
|
id, err := strconv.ParseUint(c.Params("id"), 10, 64)
|
|
if err != nil || id == 0 {
|
|
return 0, errors.New(errors.CodeInvalidParam, "运营弹窗配置ID不合法")
|
|
}
|
|
return uint(id), nil
|
|
}
|