feat: 代码生成
This commit is contained in:
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user