xyxie hai 1 día
pai
achega
89818a0e35

+ 7 - 1
controllers/kpler.go

@@ -81,7 +81,13 @@ func (this *KplerController) GetProductData() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
-	data, err := kpler.GetProducts()
+	var params models.KplerProductLibReq
+	if e := json.Unmarshal(this.Ctx.Input.RequestBody, &params); e != nil {
+		br.Msg = "参数解析异常"
+		br.ErrMsg = fmt.Sprintf("参数解析失败, %v", e)
+		return
+	}
+	data, err := kpler.GetProducts(params)
 	if err != nil {
 		br.Msg = "获取数据失败"
 		br.ErrMsg = fmt.Sprintf("获取数据失败, %v", err)

+ 15 - 1
models/base_from_kpler.go

@@ -109,4 +109,18 @@ type HandleKplerExcelData struct {
 type HandleKplerExcelDataReq struct {
 	List         []*HandleKplerExcelData
 	TerminalCode string `description:"编码"`
-}
+}
+
+type KplerProductLibReq struct {
+	AncestorFamilyIds string `description:"祖先家族ID"`
+	AncestorFamilyNames string `description:"祖先家族名称"`
+	AncestorGroupIds string `description:"祖先组ID"`
+	AncestorGroupNames string `description:"祖先组名称"`
+	AncestorProductIds string `description:"祖先产品ID"`
+	AncestorProductNames string `description:"祖先产品名称"`
+	AncestorGradeIds string `description:"祖先等级ID"`
+	AncestorGradeNames string `description:"祖先等级名称"`
+	Products string `description:"产品"`
+	ProductIds string `description:"产品ID"`
+}
+	

+ 6 - 0
services/base_from_kpler.go

@@ -88,13 +88,18 @@ func GetKplerDataByExcel(filePath string) (err error) {
 			indexName := fmt.Sprintf("%s_%s", index.Title, index.Name)
 			unit := flowsRequestItem.Unit
 			sort := k
+			classifyName := ""
 			productNameSlice := flowsRequestItem.Products
 			productNames := ""
 			if len(productNameSlice) > 0 {
 				for _, productName := range productNameSlice {
+					if classifyName == "" {
+						classifyName = productName.Name
+					}
 					productNames += productName.Name + ","
 				}
 			}
+			
 			productNames = strings.TrimSuffix(productNames, ",")
 			fromZoneNameSlice := flowsRequestItem.Origins
 			fromZoneNames := ""
@@ -125,6 +130,7 @@ func GetKplerDataByExcel(filePath string) (err error) {
 				IndexName: indexName,
 				Unit: unit,
 				Sort: sort,
+				ClassifyName: classifyName,
 				ProductNames: productNames,
 				FromZoneNames: fromZoneNames,
 				ToZoneNames: toZoneNames,

+ 3 - 3
services/kpler/kpler.go

@@ -10,19 +10,19 @@ import (
 	"github.com/patrickmn/go-cache"
 )
 
-func GetProducts() (products []models.KplerProduct, err error) {
+func GetProducts(req models.KplerProductLibReq) (products []models.KplerProduct, err error) {
 	token, err := GetKplerAccessToken(false)
 	if err != nil {
 		return nil, err
 	}
-	products, err = GetProductsByApi(token)
+	products, err = GetProductsByApi(req, token)
 	if err != nil {
 		if err.Error() == "Unauthorized" {
 			token, err = GetKplerAccessToken(true)
 			if err != nil {
 				return 
 			}
-			products, err = GetProductsByApi(token)
+			products, err = GetProductsByApi(req, token)
 			if err != nil {
 				return 
 			}

+ 15 - 15
services/kpler/liquid.go

@@ -58,24 +58,24 @@ func login()(token string, err error){
 }
 
 // 分别获取group为:Clean Products;Crude/Co; DPP)的产品
-func GetProductsByApi(token string) (data []models.KplerProduct, err error) {
-  url := "https://api.kpler.com/v1/products"
-  ancestorFamilyIds := ""
-  ancestorFamilyNames := ""
-  ancestorGroupIds := ""
-  ancestorGroupNames := ""
-  ancestorProductIds := ""
-  ancestorProductNames := ""
-  ancestorGradeIds := ""
-  ancestorGradeNames := ""
-  products := ""
-  productIds := ""
-  url = fmt.Sprintf("%s?ancestorFamilyIds=%s&ancestorFamilyNames=%s&ancestorGroupIds=%s&ancestorGroupNames=%s&ancestorProductIds=%s&ancestorProductNames=%s&ancestorGradeIds=%s&ancestorGradeNames=%s&products=%s&productIds=%s", url, ancestorFamilyIds, ancestorFamilyNames, ancestorGroupIds, ancestorGroupNames, ancestorProductIds, ancestorProductNames, ancestorGradeIds, ancestorGradeNames, products, productIds)
-  method := "GET"
+func GetProductsByApi(params models.KplerProductLibReq, token string) (data []models.KplerProduct, err error) {
+  uri := "https://api.kpler.com/v1/products"
+  ancestorFamilyIds := url.QueryEscape(params.AncestorFamilyIds)
+  ancestorFamilyNames := url.QueryEscape(params.AncestorFamilyNames)
+  ancestorGroupIds := url.QueryEscape(params.AncestorGroupIds)
+  ancestorGroupNames := url.QueryEscape(params.AncestorGroupNames)
+  ancestorProductIds := url.QueryEscape(params.AncestorProductIds)
+  ancestorProductNames := url.QueryEscape(params.AncestorProductNames)
+  ancestorGradeIds := url.QueryEscape(params.AncestorGradeIds)
+  ancestorGradeNames := url.QueryEscape(params.AncestorGradeNames)
+  products := params.Products
+  productIds := params.ProductIds
+  uri = fmt.Sprintf("%s?ancestorFamilyIds=%s&ancestorFamilyNames=%s&ancestorGroupIds=%s&ancestorGroupNames=%s&ancestorProductIds=%s&ancestorProductNames=%s&ancestorGradeIds=%s&ancestorGradeNames=%s&products=%s&productIds=%s", uri, ancestorFamilyIds, ancestorFamilyNames, ancestorGroupIds, ancestorGroupNames, ancestorProductIds, ancestorProductNames, ancestorGradeIds, ancestorGradeNames, products, productIds)
+    method := "GET"
 
   client := &http.Client {
   }
-  req, err := http.NewRequest(method, url, nil)
+  req, err := http.NewRequest(method, uri, nil)
 
   if err != nil {
     fmt.Println(err)