瀏覽代碼

增加查询商品详情接口

zhou.xiaoning 3 年之前
父節點
當前提交
95b3184a40
共有 6 個文件被更改,包括 236 次插入0 次删除
  1. 28 0
      controllers/ferroalloy/quote.go
  2. 58 0
      docs/docs.go
  3. 58 0
      docs/swagger.json
  4. 37 0
      docs/swagger.yaml
  5. 54 0
      models/ferroalloy.go
  6. 1 0
      routers/router.go

+ 28 - 0
controllers/ferroalloy/quote.go

@@ -2,7 +2,10 @@ package ferroalloy
 
 import (
 	"mtp2_if/global/app"
+	"mtp2_if/global/e"
+	"mtp2_if/logger"
 	"mtp2_if/models"
+	"net/http"
 
 	"github.com/gin-gonic/gin"
 )
@@ -42,3 +45,28 @@ func QueryTHJProduct(c *gin.Context) {
 	a.DoBindReq(&m)
 	a.DoGetDataByPage(&m)
 }
+
+// QueryTHJGoodsDetail
+// @Summary  查询商品详情
+// @Produce  json
+// @Security ApiKeyAuth
+// @Param    wrstandardid query    int true "现货商品ID"
+// @Success  200          {array}  models.THJGoodsDetailRsp
+// @Failure  500          {object} app.Response
+// @Router   /Ferroalloy/QueryTHJGoodsDetail [get]
+// @Tags     铁合金
+func QueryTHJGoodsDetail(c *gin.Context) {
+	a := app.GinUtils{Gin: app.Gin{C: c}}
+	m := models.THJGoodsDetailReq{}
+	if err := a.C.ShouldBind(&m); err != nil {
+		a.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	if rsp, err := m.GetTHJGoodsDetail(); err == nil {
+		a.Gin.Response(http.StatusOK, e.SUCCESS, rsp)
+	} else {
+		logger.GetLogger().Errorf("query fail, %v", err)
+		a.Gin.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+	}
+}

+ 58 - 0
docs/docs.go

@@ -7687,6 +7687,48 @@ const docTemplate = `{
                 }
             }
         },
+        "/Ferroalloy/QueryTHJGoodsDetail": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "铁合金"
+                ],
+                "summary": "查询商品详情",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "现货商品ID",
+                        "name": "wrstandardid",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "type": "array",
+                            "items": {
+                                "$ref": "#/definitions/models.THJGoodsDetailRsp"
+                            }
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Ferroalloy/QueryTHJProduct": {
             "get": {
                 "security": [
@@ -39953,6 +39995,22 @@ const docTemplate = `{
                 }
             }
         },
+        "models.THJGoodsDetailRsp": {
+            "type": "object",
+            "properties": {
+                "goodsinfo": {
+                    "description": "商品信息",
+                    "$ref": "#/definitions/models.THJWrstandardDetail_GoodsInfo"
+                },
+                "spotgoodspricelogs": {
+                    "description": "历史价格走势",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/models.THJSpotGoodsPriceLog"
+                    }
+                }
+            }
+        },
         "models.THJPresaleApplyDeposit": {
             "type": "object",
             "properties": {

+ 58 - 0
docs/swagger.json

@@ -7678,6 +7678,48 @@
                 }
             }
         },
+        "/Ferroalloy/QueryTHJGoodsDetail": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "铁合金"
+                ],
+                "summary": "查询商品详情",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "现货商品ID",
+                        "name": "wrstandardid",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "type": "array",
+                            "items": {
+                                "$ref": "#/definitions/models.THJGoodsDetailRsp"
+                            }
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Ferroalloy/QueryTHJProduct": {
             "get": {
                 "security": [
@@ -39944,6 +39986,22 @@
                 }
             }
         },
+        "models.THJGoodsDetailRsp": {
+            "type": "object",
+            "properties": {
+                "goodsinfo": {
+                    "description": "商品信息",
+                    "$ref": "#/definitions/models.THJWrstandardDetail_GoodsInfo"
+                },
+                "spotgoodspricelogs": {
+                    "description": "历史价格走势",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/models.THJSpotGoodsPriceLog"
+                    }
+                }
+            }
+        },
         "models.THJPresaleApplyDeposit": {
             "type": "object",
             "properties": {

+ 37 - 0
docs/swagger.yaml

@@ -16768,6 +16768,17 @@ definitions:
         description: 成交数量
         type: integer
     type: object
+  models.THJGoodsDetailRsp:
+    properties:
+      goodsinfo:
+        $ref: '#/definitions/models.THJWrstandardDetail_GoodsInfo'
+        description: 商品信息
+      spotgoodspricelogs:
+        description: 历史价格走势
+        items:
+          $ref: '#/definitions/models.THJSpotGoodsPriceLog'
+        type: array
+    type: object
   models.THJPresaleApplyDeposit:
     properties:
       depositid:
@@ -28659,6 +28670,32 @@ paths:
       summary: 查询我的注册红包
       tags:
       - 铁合金
+  /Ferroalloy/QueryTHJGoodsDetail:
+    get:
+      parameters:
+      - description: 现货商品ID
+        in: query
+        name: wrstandardid
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            items:
+              $ref: '#/definitions/models.THJGoodsDetailRsp'
+            type: array
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 查询商品详情
+      tags:
+      - 铁合金
   /Ferroalloy/QueryTHJProduct:
     get:
       parameters:

+ 54 - 0
models/ferroalloy.go

@@ -960,3 +960,57 @@ func (r *THJTradeData) GetDataByPage() (interface{}, error, int, int, int) {
 	}
 	return sData, err, r.Page, r.PageSize, total
 }
+
+// THJGoodsDetailReq 商品详情
+type THJGoodsDetailReq struct {
+	WRSTANDARDID int64 `form:"wrstandardid" binding:"required"` // 现货商品ID
+}
+
+// THJGoodsDetailRsp 商品详情
+type THJGoodsDetailRsp struct {
+	GoodsInfo          THJWrstandardDetail_GoodsInfo `json:"goodsinfo"`          // 商品信息
+	SpotGoodsPriceLogs []THJSpotGoodsPriceLog        `json:"spotgoodspricelogs"` // 历史价格走势
+}
+
+func (r *THJGoodsDetailReq) GetTHJGoodsDetail() (rsp *THJGoodsDetailRsp, err error) {
+	engine := db.GetEngine()
+
+	rsp = new(THJGoodsDetailRsp)
+
+	// 采购商品信息
+	var goodsInfo THJWrstandardDetail_GoodsInfo
+	sql := fmt.Sprintf(`
+		select
+			t.WRSTANDARDID,
+			t.WRSTANDARDCODE,
+			t.WRSTANDARDNAME,
+			t.PICTUREURLS,
+			p.SPOTGOODSPRICE
+		from wrstandard t
+		left join ERMCP_SpotGoodsPrice p on t.WRSTANDARDID = p.WRSTANDARDID and p.spotgoodsbrandid=0 and p.currencyid = 1 
+		where t.WRSTANDARDID = %v
+	`, r.WRSTANDARDID)
+	if _, err = engine.SQL(sql).Get(&goodsInfo); err != nil {
+		return
+	}
+	rsp.GoodsInfo = goodsInfo
+
+	// 历史价格走势
+	spotGoodsPriceLogs := make([]THJSpotGoodsPriceLog, 0)
+	sql = fmt.Sprintf(`
+		select 
+			t.SPOTGOODSPRICE, 
+			t.TRADEDATE 
+		from ERMCP_SpotGoodsPriceLog t
+		where t.wrstandardid = %v 
+			and t.SPOTGOODSBRANDID = 0 
+			and t.CURRENCYID = 1
+		order by t.LogID
+	`, r.WRSTANDARDID)
+	if err = engine.SQL(sql).Find(&spotGoodsPriceLogs); err != nil {
+		return
+	}
+	rsp.SpotGoodsPriceLogs = spotGoodsPriceLogs
+
+	return
+}

+ 1 - 0
routers/router.go

@@ -700,6 +700,7 @@ func InitRouter() *gin.Engine {
 		ferroalloyR.Use(token.Auth()).GET("QueryTHJScoreConfig", ferroalloy.QueryTHJScoreConfig)
 		ferroalloyR.Use(token.Auth()).GET("QueryTHJProduct", ferroalloy.QueryTHJProduct)
 		ferroalloyR.Use(token.Auth()).GET("QueryTHJTradeData", ferroalloy.QueryTHJTradeData)
+		ferroalloyR.Use(token.Auth()).GET("QueryTHJGoodsDetail", ferroalloy.QueryTHJGoodsDetail)
 	}
 
 	return r