From f2cdd37d118b4c1f55c21ccdd511c0e6ccec9208 Mon Sep 17 00:00:00 2001 From: jiangshuai <291802688@qq.com> Date: 星期二, 19 九月 2023 19:56:06 +0800 Subject: [PATCH] 1.获取入库列表、修改入库信息接口服务。 --- controllers/operation.go | 128 +++++++++++++++++++++++++++++++++++++++++- 1 files changed, 123 insertions(+), 5 deletions(-) diff --git a/controllers/operation.go b/controllers/operation.go index bbe2288..581f085 100644 --- a/controllers/operation.go +++ b/controllers/operation.go @@ -2,8 +2,10 @@ import ( "errors" - "fmt" "github.com/gin-gonic/gin" + "github.com/spf13/cast" + "gorm.io/gorm" + "strconv" "wms/extend/code" "wms/extend/util" "wms/models" @@ -26,11 +28,11 @@ var reqParams request.AddOperation var params models.Operation if err := c.BindJSON(&reqParams); err != nil { - util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�"+err.Error()) + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�") return } - if err := structx.AssignTo(reqParams, params); err != nil { - util.ResponseFormat(c, code.RequestParamError, "鏁版嵁杞崲閿欒") + if err := structx.AssignTo(reqParams, ¶ms); err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏁版嵁杞崲閿欒"+err.Error()) return } if err := slf.CheckParams(params); err != nil { @@ -85,7 +87,123 @@ return errors.New("浜у搧鏁伴噺鍑洪敊") } } - fmt.Println(111111) return nil } + +// List +// @Tags 鍏ュ簱/鍑哄簱 +// @Summary 鍏ュ簱/鍑哄簱鍒楄〃 +// @Produce application/json +// @Accept json +// @Param object query request.OperationList true "鍙傛暟" +// @Success 200 {object} util.Response "鎴愬姛" +// @Router /api-wms/v1/operation/operation [get] +func (slf OperationController) List(c *gin.Context) { + var params request.OperationList + if err := c.ShouldBindQuery(¶ms); err != nil { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�:"+err.Error()) + return + } + if err := slf.CheckListParams(¶ms); err != nil { + util.ResponseFormat(c, code.RequestParamError, err.Error()) + return + } + search := models.NewOperationSearch() + search.SetPage(params.Page, params.PageSize) + list, total, err := search.SetOperationTypeId(params.OperationTypeId).SetPreload(true).SetOrder("created_at desc").Find() + if err != nil { + util.ResponseFormat(c, code.RequestError, "鏌ユ壘澶辫触:"+err.Error()) + return + } + + util.ResponseFormatList(c, code.Success, list, int(total)) + +} + +func (slf OperationController) CheckListParams(params *request.OperationList) error { + if !params.PageInfo.Check() { + return errors.New("鏁版嵁鍒嗛〉淇℃伅閿欒") + } + if params.OperationTypeId == 0 { + return errors.New("operationTypeId涓�0") + } + return nil +} + +// Update +// @Tags 鍏ュ簱/鍑哄簱 +// @Summary 淇敼鍏ュ簱/鍑哄簱淇℃伅 +// @Produce application/json +// @Param object body request.UpdateOperation true "鍏ュ簱淇℃伅" +// @Param id path int true "鍏ュ簱淇℃伅id" +// @Success 200 {object} util.Response "鎴愬姛" +// @Router /api-wms/v1/operation/operation/{id} [put] +func (slf OperationController) Update(c *gin.Context) { + id := cast.ToUint(c.Param("id")) + if id == 0 { + util.ResponseFormat(c, code.RequestParamError, "绌虹殑璁板綍id") + return + } + var reqParams request.UpdateOperation + var params models.Operation + if err := c.BindJSON(&reqParams); err != nil { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇細"+err.Error()) + return + } + if err := structx.AssignTo(reqParams, ¶ms); err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏁版嵁杞崲閿欒"+err.Error()) + return + } + if err := slf.CheckParams(params); err != nil { + util.ResponseFormat(c, code.RequestParamError, err.Error()) + return + } + if err := models.WithTransaction(func(tx *gorm.DB) error { + if err := models.NewOperationDetailsSearch().SetOrm(tx).SetOperationId(params.Id).Delete(); err != nil { + return err + } + if err := models.NewOperationSearch().SetOrm(tx).SetID(params.Id).Save(¶ms); err != nil { + return err + } + return nil + }); err != nil { + util.ResponseFormat(c, code.RequestParamError, "淇敼澶辫触锛�"+err.Error()) + return + } + + util.ResponseFormat(c, code.Success, "淇敼鎴愬姛") +} + +// DeleteDevice +// +// @Tags 鍏ュ簱/鍑哄簱 +// @Summary 鍒犻櫎鍏ュ簱/鍑哄簱淇℃伅 +// @Produce application/json +// @Param id path int true "id" +// @Success 200 {object} util.Response "鎴愬姛" +// @Router /api-wms/v1/operation/operation/{id} [delete] +func (slf OperationController) Delete(c *gin.Context) { + id, err := strconv.Atoi(c.Param("id")) + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "閿欒鐨刬d鍊�") + return + } + if id == 0 { + util.ResponseFormat(c, code.RequestParamError, "绌虹殑璁板綍id") + return + } + if err := models.WithTransaction(func(tx *gorm.DB) error { + if err := models.NewOperationDetailsSearch().SetOrm(tx).SetOperationId(id).Delete(); err != nil { + return err + } + if err := models.NewOperationSearch().SetOrm(tx).SetID(id).Delete(); err != nil { + return err + } + return nil + }); err != nil { + util.ResponseFormat(c, code.RequestParamError, "淇敼澶辫触锛�"+err.Error()) + return + } + util.ResponseFormat(c, code.Success, "鍒犻櫎鎴愬姛") +} -- Gitblit v1.8.0