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
+7
View File
@@ -0,0 +1,7 @@
package order
type ApiGroup struct {
OrderApi
RefundApi
StockApi
}
+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)
}
+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 RefundApi struct{}
var refundService = service.ServiceGroupApp.OrderServiceGroup.RefundService
// Save
// @Tags 管理
// @Summary 新增
// @Security BasicAuth
// @accept json
// @Produce json
// @Param data body req.SaveRefundReq true "新增参数"
// @Success 200 {object} response.Response "新增成功"
// @Router /order/refund/save [post]
func (a *RefundApi) Save(c *gin.Context) {
var r req.SaveRefundReq
if err := c.ShouldBindJSON(&r); err != nil {
response.FailWithMsg("参数错误:"+err.Error(), c)
return
}
if err := refundService.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.UpdateRefundReq true "更新参数"
// @Success 200 {object} response.Response "更新成功"
// @Router /order/refund/update [post]
func (a *RefundApi) Update(c *gin.Context) {
var r req.UpdateRefundReq
if err := c.ShouldBindJSON(&r); err != nil {
response.FailWithMsg("参数错误:"+err.Error(), c)
return
}
if err := refundService.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/refund/delete [post]
func (a *RefundApi) 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 := refundService.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/refund/detail [get]
func (a *RefundApi) Detail(c *gin.Context) {
id := c.Query("id")
data, err := refundService.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.ListRefundReq true "分页参数"
// @Success 200 {object} response.Response{data=response.PageResult} "获取列表成功"
// @Router /order/refund/list [post]
func (a *RefundApi) List(c *gin.Context) {
var r req.ListRefundReq
if err := c.ShouldBindJSON(&r); err != nil {
response.FailWithMsg("参数错误:"+err.Error(), c)
return
}
list, total, err := refundService.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)
}
+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 StockApi struct{}
var stockService = service.ServiceGroupApp.OrderServiceGroup.StockService
// Save
// @Tags 管理
// @Summary 新增
// @Security BasicAuth
// @accept json
// @Produce json
// @Param data body req.SaveStockReq true "新增参数"
// @Success 200 {object} response.Response "新增成功"
// @Router /order/stock/save [post]
func (a *StockApi) Save(c *gin.Context) {
var r req.SaveStockReq
if err := c.ShouldBindJSON(&r); err != nil {
response.FailWithMsg("参数错误:"+err.Error(), c)
return
}
if err := stockService.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.UpdateStockReq true "更新参数"
// @Success 200 {object} response.Response "更新成功"
// @Router /order/stock/update [post]
func (a *StockApi) Update(c *gin.Context) {
var r req.UpdateStockReq
if err := c.ShouldBindJSON(&r); err != nil {
response.FailWithMsg("参数错误:"+err.Error(), c)
return
}
if err := stockService.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/stock/delete [post]
func (a *StockApi) 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 := stockService.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/stock/detail [get]
func (a *StockApi) Detail(c *gin.Context) {
id := c.Query("id")
data, err := stockService.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.ListStockReq true "分页参数"
// @Success 200 {object} response.Response{data=response.PageResult} "获取列表成功"
// @Router /order/stock/list [post]
func (a *StockApi) List(c *gin.Context) {
var r req.ListStockReq
if err := c.ShouldBindJSON(&r); err != nil {
response.FailWithMsg("参数错误:"+err.Error(), c)
return
}
list, total, err := stockService.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)
}