lishihai
2024-06-14 86530fe51ee65aea39e07e8fa131bf6e3310c4b0
属性值和对象-AttributeValue-wms_attribute_value-的ID查询和LIST分页查询
3个文件已修改
81 ■■■■■ 已修改文件
controllers/attribute_value.go 53 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/attribute_value.go 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
request/attribute_value.go 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/attribute_value.go
@@ -95,7 +95,6 @@
// DeleteAttributeValue
// @Tags      属性值和对象
// @Summary   删除属性值和对象
// @Produce   application/json
// @Param        id    path        unit            true    "id"
// @Success   200 {object} util.Response "成功"
// @Router    /api-wms/v1/attributeValue/delete/{id} [delete]
@@ -113,3 +112,55 @@
    }
    util.ResponseFormat(c, code.Success, "删除成功")
}
// ListAttributeValue
// @Tags      属性值和对象
// @Summary   查询属性值和对象 分页条件筛选Value like '%v%' 模糊查询
// @Produce   application/json
// object  body  request.OperationList true  "查询参数"
// @Success   200 {object} util.Response "成功"
// @Router    /api-wms/v1/attributeValue/list [post]
func (slf *AttributeValueController) ListAttributeValue(c *gin.Context) {
    var params request.AttributeValueList
    if err := c.BindJSON(&params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
    search := models.NewAttributeValueSearch()
    search.SetPage(params.Page, params.PageSize)
    if params.EntityID != "" {
        search.SetEntityID(params.EntityID)
    }
    if params.AttributeID != 0 {
        search.SetAttributeID(params.AttributeID)
    }
    if params.Value != "" {
        search.SetValue(params.Value)
    }
    list, total, err := search.Find()
    if err != nil {
        util.ResponseFormat(c, code.RequestError, "查找失败:"+err.Error())
        return
    }
    util.ResponseFormatListWithPage(c, code.Success, list, int(total), params.Page, params.PageSize)
}
// PrimaryAttributeValue
// @Tags      属性值和对象
// @Summary   查询属性值和对象 通过主键ID查询
// object  body  request.OperationList true  "查询参数"
// @Success   200 {object} util.Response "成功"
// @Router    /api-wms/v1/attributeValue/primary/{id}  [get]
func (slf *AttributeValueController) PrimaryAttributeValue(c *gin.Context) {
    id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
    if id == 0 {
        util.ResponseFormat(c, code.RequestParamError, "无效id")
        return
    }
    attributeValue, err := models.NewAttributeValueSearch().SetID(uint(id)).First()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查询失败")
        return
    }
    util.ResponseFormat(c, code.Success, attributeValue)
}
models/attribute_value.go
@@ -51,13 +51,33 @@
    slf.ID = id
    return slf
}
func (slf *AttributeValueSearch) SetEntityID(entityId string) *AttributeValueSearch {
    slf.EntityID = entityId
    return slf
}
func (slf *AttributeValueSearch) SetAttributeID(attributeId uint) *AttributeValueSearch {
    slf.AttributeID = attributeId
    return slf
}
func (slf *AttributeValueSearch) SetValue(value string) *AttributeValueSearch {
    slf.Value = value
    return slf
}
func (slf *AttributeValueSearch) build() *gorm.DB {
    var db = slf.Orm.Table(slf.TableName())
    if slf.ID != 0 {
        db = db.Where("id = ?", slf.ID)
    }
    if slf.EntityID != "" {
        db = db.Where("entity_id = ?", slf.EntityID)
    }
    if slf.AttributeID != 0 {
        db = db.Where("attribute_id = ?", slf.AttributeID)
    }
    if slf.Value != "" {
        db = db.Where("value like ?", "%"+slf.Value+"%")
    }
    if slf.Order != "" {
        db = db.Order(slf.Order)
request/attribute_value.go
@@ -11,3 +11,9 @@
    AttributeID uint   `json:"attributeId"`
    Value       string `json:"value"`
}
type AttributeValueList struct {
    PageInfo
    EntityID    string `json:"entityId"`
    AttributeID uint   `json:"attributeId"`
    Value       string `json:"value"` //like '%v%' 模糊查询
}