feat: 代码生成

This commit is contained in:
Blizzard
2026-04-28 10:29:02 +08:00
parent 7e282b36d7
commit b343856b58
38 changed files with 2199 additions and 51 deletions
+134
View File
@@ -0,0 +1,134 @@
package order
import (
"sundynix-go/global"
"sundynix-go/model/commom/response"
req "sundynix-go/model/order/request"
"sundynix-go/service"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
type OrderApi struct{}
var orderService = service.ServiceGroupApp.OrderServiceGroup.OrderService
// Save
// @Tags 管理
// @Summary 新增
// @Security BasicAuth
// @accept json
// @Produce json
// @Param data body req.SaveOrderReq true "新增参数"
// @Success 200 {object} response.Response "新增成功"
// @Router /order/order/save [post]
func (a *OrderApi) Save(c *gin.Context) {
var r req.SaveOrderReq
if err := c.ShouldBindJSON(&r); err != nil {
response.FailWithMsg("参数错误:"+err.Error(), c)
return
}
if err := orderService.Save(r); err != nil {
global.Logger.Error("新增失败!", zap.Error(err))
response.FailWithMsg(err.Error(), c)
return
}
response.OkWithMsg("新增成功", c)
}
// Update
// @Tags 管理
// @Summary 更新
// @Security BasicAuth
// @accept json
// @Produce json
// @Param data body req.UpdateOrderReq true "更新参数"
// @Success 200 {object} response.Response "更新成功"
// @Router /order/order/update [post]
func (a *OrderApi) Update(c *gin.Context) {
var r req.UpdateOrderReq
if err := c.ShouldBindJSON(&r); err != nil {
response.FailWithMsg("参数错误:"+err.Error(), c)
return
}
if err := orderService.Update(r); err != nil {
global.Logger.Error("更新失败!", zap.Error(err))
response.FailWithMsg(err.Error(), c)
return
}
response.OkWithMsg("更新成功", c)
}
// Delete
// @Tags 管理
// @Summary 删除(支持批量)
// @Security BasicAuth
// @accept json
// @Produce json
// @Param data body object{ids=[]string} true "id列表"
// @Success 200 {object} response.Response "删除成功"
// @Router /order/order/delete [post]
func (a *OrderApi) Delete(c *gin.Context) {
var req struct {
Ids []string `json:"ids" binding:"required,min=1"`
}
if err := c.ShouldBindJSON(&req); err != nil {
response.FailWithMsg("参数错误:"+err.Error(), c)
return
}
if err := orderService.Delete(req.Ids); err != nil {
global.Logger.Error("删除失败!", zap.Error(err))
response.FailWithMsg(err.Error(), c)
return
}
response.OkWithMsg("删除成功", c)
}
// Detail
// @Tags 管理
// @Summary 获取详情
// @Security BasicAuth
// @Produce json
// @Param id query string true "ID"
// @Success 200 {object} response.Response "获取详情成功"
// @Router /order/order/detail [get]
func (a *OrderApi) Detail(c *gin.Context) {
id := c.Query("id")
data, err := orderService.Detail(id)
if err != nil {
global.Logger.Error("获取详情失败!", zap.Error(err))
response.FailWithMsg(err.Error(), c)
return
}
response.OkWithData(data, c)
}
// List
// @Tags 管理
// @Summary 分页获取列表
// @Security BasicAuth
// @accept json
// @Produce json
// @Param data body req.ListOrderReq true "分页参数"
// @Success 200 {object} response.Response{data=response.PageResult} "获取列表成功"
// @Router /order/order/list [post]
func (a *OrderApi) List(c *gin.Context) {
var r req.ListOrderReq
if err := c.ShouldBindJSON(&r); err != nil {
response.FailWithMsg("参数错误:"+err.Error(), c)
return
}
list, total, err := orderService.List(r)
if err != nil {
global.Logger.Error("获取列表失败!", zap.Error(err))
response.FailWithMsg(err.Error(), c)
return
}
response.OkWithData(response.PageResult{
List: list,
Total: total,
Page: r.Current,
PageSize: r.PageSize,
}, c)
}