liujiandao
2023-11-14 2f32021ab211cd901e36c4cbc5875f0f072385bb
controllers/product_controller.go
@@ -15,7 +15,6 @@
   "wms/models"
   "wms/pkg/logx"
   "wms/request"
   "wms/utils"
)
type ProductController struct {
@@ -34,6 +33,10 @@
      util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
      return
   }
   if params.ID == "" {
      util.ResponseFormat(c, code.RequestParamError, "产品编码不能为空")
      return
   }
   if params.Name == "" {
      util.ResponseFormat(c, code.RequestParamError, "产品名称不能为空")
      return
@@ -46,7 +49,7 @@
      util.ResponseFormat(c, code.RequestParamError, "单位不能为空")
      return
   }
   params.ID = utils.GetUUID()
   //params.ID = utils.GetUUID()
   err := models.NewMaterialSearch().Create(&params)
   if err != nil {
      util.ResponseFormat(c, code.RequestParamError, "产品信息保存失败")
@@ -648,3 +651,38 @@
   util.ResponseFormatListWithPage(c, code.Success, list, int(total), params.Page, params.PageSize)
}
// CancelDisuse
//
//   @Tags      产品
//   @Summary   取消报废
//   @Produce   application/json
//   @Param      id   path      int         true   "id"
//   @Success   200   {object}   util.Response   "成功"
//   @Router      /api-wms/v1/product/cancelDisuse/{id} [put]
func (slf ProductController) CancelDisuse(c *gin.Context) {
   id, err := strconv.Atoi(c.Param("id"))
   if err != nil {
      util.ResponseFormat(c, code.RequestParamError, "错误的id值")
      return
   }
   if id == 0 {
      util.ResponseFormat(c, code.RequestParamError, "id为0")
      return
   }
   operation, err := models.NewOperationSearch().SetID(id).First()
   if err != nil {
      util.ResponseFormat(c, code.RequestParamError, "未找到相关信息:"+err.Error())
      return
   }
   if operation.Status != constvar.OperationStatus_Ready {
      util.ResponseFormat(c, code.RequestError, "该信息无法取消")
      return
   }
   operation.Status = constvar.OperationStatus_Cancel
   if err := models.NewOperationSearch().SetID(operation.Id).Save(operation); err != nil {
      util.ResponseFormat(c, code.SaveFail, err.Error())
      return
   }
   util.ResponseFormat(c, code.Success, "操作成功")
}