zhangqian
2024-07-04 c950586b718ae6fc198bedf424609a4ac94cb5d1
controllers/attribute.go
@@ -6,6 +6,7 @@
   "github.com/gin-gonic/gin"
   "github.com/spf13/cast"
   "gorm.io/gorm"
   "strconv"
   "wms/extend/code"
   "wms/extend/util"
   "wms/models"
@@ -23,7 +24,7 @@
// @Param     Authorization   header string true "token"
// @Success   200 {object} util.Response "成功"
// @Router    /api-wms/v1/attribute/attribute [post]
func (slf *AttributeController) Add(c *gin.Context) {
func (slf AttributeController) Add(c *gin.Context) {
   var reqParams request.AddAttribute
   var params models.Attribute
   if err := c.BindJSON(&reqParams); err != nil {
@@ -141,21 +142,20 @@
   util.ResponseFormat(c, code.UpdateSuccess, "删除成功")
}
// List
// @Tags      属性
// @Summary   查询属性列表
// ListAttribute
// @Tags      属性值和对象
// @Summary   添加属性值和对象
// @Produce   application/json
// @Param     object  query    request.GetAttributeList true  "查询参数"
// @Param     Authorization   header string true "token"
// @Success   200   {object}  util.ResponseList{data=[]models.Attribute}  "成功"
// @Param     object  body  request.AttributeList true  "属性值和对象信息"
// @Success   200 {object} util.Response "成功"
// @Router    /api-wms/v1/attribute/attribute [get]
func (slf AttributeController) List(c *gin.Context) {
   var params request.GetAttributeList
   if err := c.ShouldBindQuery(&params); err != nil {
func (slf AttributeController) ListAttribute(c *gin.Context) {
   var params request.AttributeList
   if err := c.ShouldBind(&params); err != nil {
      util.ResponseFormat(c, code.RequestParamError, err.Error())
      return
   }
   list, count, err := models.NewAttributeSearch().SetPage(params.Page, params.PageSize).SetOrder("id desc").Find()
   list, count, err := models.NewAttributeSearch().SetEntityType(params.EntityType).SetPage(params.Page, params.PageSize).SetOrder("id desc").Find()
   if err != nil {
      util.ResponseFormat(c, code.RequestParamError, "查询失败")
      return
@@ -184,3 +184,23 @@
//
//   util.ResponseFormat(c, code.UpdateSuccess, first)
//}
// PrimaryAttribute
// @Tags      属性值和对象
// @Summary   查询属性值和对象 通过主键ID查询
// object  body  request.OperationList true  "查询参数"
// @Success   200 {object} util.Response "成功"
// @Router    /api-wms/v1/attribute/primary/{id}  [get]
func (slf AttributeController) PrimaryAttribute(c *gin.Context) {
   id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
   if id == 0 {
      util.ResponseFormat(c, code.RequestParamError, "无效id")
      return
   }
   attribute, err := models.NewAttributeSearch().SetID(uint(id)).First()
   if err != nil {
      util.ResponseFormat(c, code.RequestParamError, "查询失败")
      return
   }
   util.ResponseFormat(c, code.Success, attribute)
}