lishihai
2024-06-20 924d4245c26934dfcb069a25a4911a6289389097
查询属性值和对象 通过主键ID查询
2个文件已修改
25 ■■■■■ 已修改文件
controllers/attribute.go 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/attribute.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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"
@@ -184,3 +185,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 *AttributeValueController) 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)
}
models/attribute.go
@@ -25,6 +25,7 @@
        PageNum  int
        PageSize int
        Orm      *gorm.DB
        Keyword  string
    }
)
@@ -130,6 +131,9 @@
    if slf.Name != "" {
        db = db.Where("name = ?", slf.Name)
    }
    if slf.Keyword != "" {
        db = db.Where("id like ? or data_type like ? or entity_type like ?", fmt.Sprintf("%%%v%%", slf.Keyword), fmt.Sprintf("%%%v%%", slf.Keyword), fmt.Sprintf("%%%v%%", slf.Keyword))
    }
    return db
}