From 86530fe51ee65aea39e07e8fa131bf6e3310c4b0 Mon Sep 17 00:00:00 2001
From: lishihai <dslsh@dscom>
Date: 星期五, 14 六月 2024 17:04:13 +0800
Subject: [PATCH] 属性值和对象-AttributeValue-wms_attribute_value-的ID查询和LIST分页查询

---
 request/attribute_value.go     |    6 +++
 controllers/attribute_value.go |   53 ++++++++++++++++++++++++++
 models/attribute_value.go      |   22 ++++++++++
 3 files changed, 79 insertions(+), 2 deletions(-)

diff --git a/controllers/attribute_value.go b/controllers/attribute_value.go
index a641d34..7e5cdf7 100644
--- a/controllers/attribute_value.go
+++ b/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   鏌ヨ灞炴�у�煎拰瀵硅薄 鍒嗛〉鏉′欢绛涢�塚alue 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, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�")
+		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)
+}
diff --git a/models/attribute_value.go b/models/attribute_value.go
index f6bca8b..960685d 100644
--- a/models/attribute_value.go
+++ b/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)
diff --git a/request/attribute_value.go b/request/attribute_value.go
index 0add8f4..7cddbdb 100644
--- a/request/attribute_value.go
+++ b/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%' 妯$硦鏌ヨ
+}

--
Gitblit v1.8.0