fix: 批量改进 (#2/#23/#38/#39/#40/#47)

- Web: 隐藏 ICP 备案号(条件渲染),联系入口改为微信咨询(条件渲染,配置 wechat 字段后生效)
- backend: 拼音回填抽取为独立 cmd/backfill-pinyin 工具,不再在启动时运行
- backend: DB 连接池参数(max_idle_conns/max_open_conns)改为配置可控,默认 10/100
- backend: Inventory 反范式字段添加注释说明快照语义
- backend: 全量 handler 采用 util.RespondSuccess/RespondCreated 统一响应格式(51 处)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-06-11 09:33:43 +08:00
parent d28aba863e
commit e0bee00ff4
21 changed files with 144 additions and 89 deletions
+13 -12
View File
@@ -8,6 +8,7 @@ import (
"github.com/wangjia/jiu/backend/internal/middleware"
"github.com/wangjia/jiu/backend/internal/model"
"github.com/wangjia/jiu/backend/internal/util"
)
// ProductAttrHandler 处理商品属性字典(产地/保质期/储存方式/描述文档)
@@ -25,7 +26,7 @@ func (h *ProductAttrHandler) ListOrigins(c *gin.Context) {
shopID := middleware.GetShopID(c)
items := make([]model.ProductOriginOption, 0)
h.db.Where("shop_id = ?", shopID).Order("id ASC").Find(&items)
c.JSON(http.StatusOK, gin.H{"data": items})
util.RespondSuccess(c, items)
}
func (h *ProductAttrHandler) CreateOrigin(c *gin.Context) {
@@ -49,7 +50,7 @@ func (h *ProductAttrHandler) CreateOrigin(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusCreated, gin.H{"data": item})
util.RespondCreated(c, item)
}
func (h *ProductAttrHandler) UpdateOrigin(c *gin.Context) {
@@ -71,7 +72,7 @@ func (h *ProductAttrHandler) UpdateOrigin(c *gin.Context) {
h.db.Model(&item).Where("shop_id = ?", shopID).Updates(map[string]interface{}{
"code": req.Code, "name": req.Name, "remark": req.Remark,
})
c.JSON(http.StatusOK, gin.H{"data": item})
util.RespondSuccess(c, item)
}
func (h *ProductAttrHandler) DeleteOrigin(c *gin.Context) {
@@ -86,7 +87,7 @@ func (h *ProductAttrHandler) ListShelfLives(c *gin.Context) {
shopID := middleware.GetShopID(c)
items := make([]model.ProductShelfLifeOption, 0)
h.db.Where("shop_id = ?", shopID).Order("id ASC").Find(&items)
c.JSON(http.StatusOK, gin.H{"data": items})
util.RespondSuccess(c, items)
}
func (h *ProductAttrHandler) CreateShelfLife(c *gin.Context) {
@@ -110,7 +111,7 @@ func (h *ProductAttrHandler) CreateShelfLife(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusCreated, gin.H{"data": item})
util.RespondCreated(c, item)
}
func (h *ProductAttrHandler) UpdateShelfLife(c *gin.Context) {
@@ -132,7 +133,7 @@ func (h *ProductAttrHandler) UpdateShelfLife(c *gin.Context) {
h.db.Model(&item).Where("shop_id = ?", shopID).Updates(map[string]interface{}{
"code": req.Code, "name": req.Name, "remark": req.Remark,
})
c.JSON(http.StatusOK, gin.H{"data": item})
util.RespondSuccess(c, item)
}
func (h *ProductAttrHandler) DeleteShelfLife(c *gin.Context) {
@@ -147,7 +148,7 @@ func (h *ProductAttrHandler) ListStorages(c *gin.Context) {
shopID := middleware.GetShopID(c)
items := make([]model.ProductStorageOption, 0)
h.db.Where("shop_id = ?", shopID).Order("id ASC").Find(&items)
c.JSON(http.StatusOK, gin.H{"data": items})
util.RespondSuccess(c, items)
}
func (h *ProductAttrHandler) CreateStorage(c *gin.Context) {
@@ -171,7 +172,7 @@ func (h *ProductAttrHandler) CreateStorage(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusCreated, gin.H{"data": item})
util.RespondCreated(c, item)
}
func (h *ProductAttrHandler) UpdateStorage(c *gin.Context) {
@@ -193,7 +194,7 @@ func (h *ProductAttrHandler) UpdateStorage(c *gin.Context) {
h.db.Model(&item).Where("shop_id = ?", shopID).Updates(map[string]interface{}{
"code": req.Code, "name": req.Name, "remark": req.Remark,
})
c.JSON(http.StatusOK, gin.H{"data": item})
util.RespondSuccess(c, item)
}
func (h *ProductAttrHandler) DeleteStorage(c *gin.Context) {
@@ -208,7 +209,7 @@ func (h *ProductAttrHandler) ListDescriptionDocs(c *gin.Context) {
shopID := middleware.GetShopID(c)
items := make([]model.ProductDescriptionDoc, 0)
h.db.Where("shop_id = ?", shopID).Order("id ASC").Find(&items)
c.JSON(http.StatusOK, gin.H{"data": items})
util.RespondSuccess(c, items)
}
func (h *ProductAttrHandler) CreateDescriptionDoc(c *gin.Context) {
@@ -232,7 +233,7 @@ func (h *ProductAttrHandler) CreateDescriptionDoc(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusCreated, gin.H{"data": item})
util.RespondCreated(c, item)
}
func (h *ProductAttrHandler) UpdateDescriptionDoc(c *gin.Context) {
@@ -254,7 +255,7 @@ func (h *ProductAttrHandler) UpdateDescriptionDoc(c *gin.Context) {
h.db.Model(&item).Where("shop_id = ?", shopID).Updates(map[string]interface{}{
"title": req.Title, "content": req.Content, "remark": req.Remark,
})
c.JSON(http.StatusOK, gin.H{"data": item})
util.RespondSuccess(c, item)
}
func (h *ProductAttrHandler) DeleteDescriptionDoc(c *gin.Context) {