zhou.xiaoning 5 anni fa
parent
commit
ec5ba3ad71
7 ha cambiato i file con 267 aggiunte e 8 eliminazioni
  1. 2 1
      config/cfg.json
  2. 76 5
      controllers/hsby/hsby.go
  3. 62 0
      docs/docs.go
  4. 62 0
      docs/swagger.json
  5. 40 0
      docs/swagger.yaml
  6. 23 2
      models/hsby.go
  7. 2 0
      routers/router.go

+ 2 - 1
config/cfg.json

@@ -11,6 +11,7 @@
         "quoteHost": "192.168.31.109",
         "quotePort": "5002",
         "tradeHost": "192.168.31.109",
-        "tradePort": "5001"
+        "tradePort": "5001",
+        "newsUrl": "http://www.baidu.com"
     }
 }

+ 76 - 5
controllers/hsby/hsby.go

@@ -131,10 +131,11 @@ func QueryHsbyListingGoodsDetail(c *gin.Context) {
 
 // QueryHsbyGoodsOrderDetailsReq 查询二级市场(挂牌点选)商品对应的挂牌委托单信息请求参数
 type QueryHsbyGoodsOrderDetailsReq struct {
-	GoodsID   int     `form:"goodsID" binding:"required"`
-	BuyOrSell int     `form:"buyOrSell"`
-	Price     float64 `form:"price"`
-	Speed     int     `form:"speed"`
+	GoodsID    int     `form:"goodsID" binding:"required"`
+	AccountIDs string  `form:"accountIDs" binding:"required"`
+	BuyOrSell  int     `form:"buyOrSell"`
+	Price      float64 `form:"price"`
+	Speed      int     `form:"speed"`
 }
 
 // QueryHsbyGoodsOrderDetails 查询二级市场(挂牌点选)商品对应的挂牌委托单信息
@@ -143,6 +144,7 @@ type QueryHsbyGoodsOrderDetailsReq struct {
 // @Produce json
 // @Security ApiKeyAuth
 // @Param goodsID query int true "商品ID"
+// @Param accountIDs query string true "摘牌方资金账户列表,格式:1,2,3。主要用于过滤自己的挂牌单"
 // @Param buyOrSell query int false "委托单方向。0:买 1:卖。不传则默认为买"
 // @Param price query number false " 参考价格。买方向委托单则价格小于等于(站在摘牌人的角度);卖方向委托单则价格大于等于"
 // @Param speed query int false "档位,不传则默认为3档"
@@ -162,7 +164,7 @@ func QueryHsbyGoodsOrderDetails(c *gin.Context) {
 	}
 
 	// 获取数据
-	orderDetails, err := models.GetHsbyGoodsOrderDetails(req.GoodsID, req.BuyOrSell, req.Price)
+	orderDetails, err := models.GetHsbyGoodsOrderDetails(req.GoodsID, req.BuyOrSell, req.Price, req.AccountIDs)
 	if err != nil {
 		// 查询失败
 		logger.GetLogger().Errorf("QueryHsbyGoodsOrderDetails failed: %s", err.Error())
@@ -597,3 +599,72 @@ func SetHsbyMyPackagesStatus(c *gin.Context) {
 	logger.GetLogger().Debugln("SetHsbyMyPackagesStatus successed: %v", "ok")
 	appG.Response(http.StatusOK, e.SUCCESS, "")
 }
+
+// QueryProvincesAndCitiesReq 查询省市信息请求参数
+type QueryProvincesAndCitiesReq struct {
+	ProvinceID int `form:"provinceID"` // 省ID
+}
+
+// QueryProvincesAndCitiesRsp 查询省市信息返回模型
+type QueryProvincesAndCitiesRsp struct {
+	Province models.Division   // 省
+	Cities   []models.Division // 市
+}
+
+// QueryProvincesAndCities 查询省市信息(不包括区)
+// @Summary 查询省市信息(不包括区)
+// @Description 查询结果只包括二级市场商品已关连的省市信息。
+// @Produce json
+// @Security ApiKeyAuth
+// @Param provinceID query int false "省ID"
+// @Success 200 {object} QueryProvincesAndCitiesRsp
+// @Failure 500 {object} app.Response
+// @Router /HSBY/QueryProvincesAndCities [get]
+// @Tags 定制【海商报业】
+func QueryProvincesAndCities(c *gin.Context) {
+	appG := app.Gin{C: c}
+
+	// 获取请求参数
+	var req QueryProvincesAndCitiesReq
+	if err := appG.C.ShouldBindQuery(&req); err != nil {
+		logger.GetLogger().Errorf("QueryProvincesAndCities failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	// 获取省市信息
+	provinces, err := models.GetHsbyProvincesAndCities(req.ProvinceID)
+	if err != nil {
+		// 查询失败
+		logger.GetLogger().Errorf("QueryProvincesAndCities failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+		return
+	}
+
+	// 分解省市数据
+	// Golang Map元素取址问题: cannot assign to struct field XXXX in map
+	// https://blog.csdn.net/makenothing/article/details/105037977
+	pMap := make(map[string]*QueryProvincesAndCitiesRsp)
+	// 构建省节点
+	for _, v := range provinces {
+		if v.Divisionlevel == "province" {
+			pMap[v.Divisioncode] = &QueryProvincesAndCitiesRsp{Province: v, Cities: make([]models.Division, 0)}
+		}
+	}
+	// 为省节点增加市信息
+	for _, v := range provinces {
+		if v.Divisionlevel == "city" {
+			pMap[v.Parentcode].Cities = append(pMap[v.Parentcode].Cities, v)
+		}
+	}
+
+	// map to slice
+	rst := make([]QueryProvincesAndCitiesRsp, 0)
+	for _, v := range pMap {
+		rst = append(rst, *v)
+	}
+
+	// 查询成功
+	logger.GetLogger().Debugln("QueryProvincesAndCities successed: %v", rst)
+	appG.Response(http.StatusOK, e.SUCCESS, rst)
+}

+ 62 - 0
docs/docs.go

@@ -813,6 +813,13 @@ var doc = `{
                         "required": true
                     },
                     {
+                        "type": "string",
+                        "description": "摘牌方资金账户列表,格式:1,2,3。主要用于过滤自己的挂牌单",
+                        "name": "accountIDs",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
                         "type": "integer",
                         "description": "委托单方向。0:买 1:卖。不传则默认为买",
                         "name": "buyOrSell",
@@ -1241,6 +1248,45 @@ var doc = `{
                 }
             }
         },
+        "/HSBY/QueryProvincesAndCities": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "description": "查询结果只包括二级市场商品已关连的省市信息。",
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "定制【海商报业】"
+                ],
+                "summary": "查询省市信息(不包括区)",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "省ID",
+                        "name": "provinceID",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/hsby.QueryProvincesAndCitiesRsp"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/HSBY/SetHsbyMyPackagesStatus": {
             "post": {
                 "security": [
@@ -4166,6 +4212,22 @@ var doc = `{
                 }
             }
         },
+        "hsby.QueryProvincesAndCitiesRsp": {
+            "type": "object",
+            "properties": {
+                "cities": {
+                    "description": "市",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/models.Division"
+                    }
+                },
+                "province": {
+                    "description": "省",
+                    "$ref": "#/definitions/models.Division"
+                }
+            }
+        },
         "models.Division": {
             "type": "object",
             "required": [

+ 62 - 0
docs/swagger.json

@@ -797,6 +797,13 @@
                         "required": true
                     },
                     {
+                        "type": "string",
+                        "description": "摘牌方资金账户列表,格式:1,2,3。主要用于过滤自己的挂牌单",
+                        "name": "accountIDs",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
                         "type": "integer",
                         "description": "委托单方向。0:买 1:卖。不传则默认为买",
                         "name": "buyOrSell",
@@ -1225,6 +1232,45 @@
                 }
             }
         },
+        "/HSBY/QueryProvincesAndCities": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "description": "查询结果只包括二级市场商品已关连的省市信息。",
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "定制【海商报业】"
+                ],
+                "summary": "查询省市信息(不包括区)",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "省ID",
+                        "name": "provinceID",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/hsby.QueryProvincesAndCitiesRsp"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/HSBY/SetHsbyMyPackagesStatus": {
             "post": {
                 "security": [
@@ -4150,6 +4196,22 @@
                 }
             }
         },
+        "hsby.QueryProvincesAndCitiesRsp": {
+            "type": "object",
+            "properties": {
+                "cities": {
+                    "description": "市",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/models.Division"
+                    }
+                },
+                "province": {
+                    "description": "省",
+                    "$ref": "#/definitions/models.Division"
+                }
+            }
+        },
         "models.Division": {
             "type": "object",
             "required": [

+ 40 - 0
docs/swagger.yaml

@@ -1200,6 +1200,17 @@ definitions:
     required:
     - spotcontractid
     type: object
+  hsby.QueryProvincesAndCitiesRsp:
+    properties:
+      cities:
+        description: 市
+        items:
+          $ref: '#/definitions/models.Division'
+        type: array
+      province:
+        $ref: '#/definitions/models.Division'
+        description: 省
+    type: object
   models.Division:
     properties:
       autoid:
@@ -4119,6 +4130,11 @@ paths:
         name: goodsID
         required: true
         type: integer
+      - description: 摘牌方资金账户列表,格式:1,2,3。主要用于过滤自己的挂牌单
+        in: query
+        name: accountIDs
+        required: true
+        type: string
       - description: 委托单方向。0:买 1:卖。不传则默认为买
         in: query
         name: buyOrSell
@@ -4395,6 +4411,30 @@ paths:
       summary: 查询热卖商品列表(二级市场挂牌点选)
       tags:
       - 定制【海商报业】
+  /HSBY/QueryProvincesAndCities:
+    get:
+      description: 查询结果只包括二级市场商品已关连的省市信息。
+      parameters:
+      - description: 省ID
+        in: query
+        name: provinceID
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/hsby.QueryProvincesAndCitiesRsp'
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 查询省市信息(不包括区)
+      tags:
+      - 定制【海商报业】
   /HSBY/SetHsbyMyPackagesStatus:
     post:
       parameters:

+ 23 - 2
models/hsby.go

@@ -256,7 +256,7 @@ type HsbyGoodsOrderDetail struct {
 // 输入 price float64 参考价格。买方向委托单则价格小于等于(站在摘牌人的角度);卖方向委托单则价格大于等于
 // 输出 []HsbyGoodsOrderDetail 商品对应的挂牌委托单信息
 // 输出 error error
-func GetHsbyGoodsOrderDetails(goodsID, buyOrSell int, price float64) ([]HsbyGoodsOrderDetail, error) {
+func GetHsbyGoodsOrderDetails(goodsID, buyOrSell int, price float64, accountIDs string) ([]HsbyGoodsOrderDetail, error) {
 	engine := db.GetEngine()
 
 	// 获取与目标商品相关的挂牌委托单信息(ListingSelectType = 1 or 3; OrderStatus =3 or 7)
@@ -268,7 +268,8 @@ func GetHsbyGoodsOrderDetails(goodsID, buyOrSell int, price float64) ([]HsbyGood
 		Join("LEFT", "USERINFO", "USERINFO.USERID = TAACCOUNT.RELATEDUSERID").
 		Where("(TRADE_ORDERDETAIL.LISTINGSELECTTYPE = 1 or TRADE_ORDERDETAIL.LISTINGSELECTTYPE = 3) and (TRADE_ORDERDETAIL.ORDERSTATUS = 3 or TRADE_ORDERDETAIL.ORDERSTATUS = 7)").
 		And("TRADE_ORDERDETAIL.GOODSID = ?", goodsID).
-		And("TRADE_ORDERDETAIL.BUYORSELL = ?", buyOrSell)
+		And("TRADE_ORDERDETAIL.BUYORSELL = ?", buyOrSell).
+		And(fmt.Sprintf("TRADE_ORDERDETAIL.ACCOUNTID not in (%s)", accountIDs))
 	if price > 0 {
 		if buyOrSell == 0 {
 			// 买方向委托单则价格小于等于(站在摘牌人的角度)
@@ -913,3 +914,23 @@ func SetHsbyMyPackagesStatus(takeOrderID string, accountID, status int) error {
 
 	return err
 }
+
+// GetHsbyProvincesAndCities 获取省市信息数组
+// 参数 provinceID int 省ID,选填
+// 返回 []Division 枚举信息数组
+// 返回 error error
+func GetHsbyProvincesAndCities(provinceID int) ([]Division, error) {
+	engine := db.GetEngine()
+
+	divisions := make([]Division, 0)
+	session := engine.Where("DIVISIONLEVEL = 'province' or DIVISIONLEVEL = 'city'").
+		And("AUTOID in ((select DESCPROVINCEID AUTOID from HSBY_GOODSEX) union all (select DESCCITYID AUTOID from HSBY_GOODSEX))")
+	if provinceID > 0 {
+		session = session.And("AUTOID = ?", provinceID)
+	}
+	if err := session.Find(&divisions); err != nil {
+		return nil, err
+	}
+
+	return divisions, nil
+}

+ 2 - 0
routers/router.go

@@ -211,6 +211,8 @@ func InitRouter() *gin.Engine {
 		hsbyR.GET("/QueryHsbyMyPackages", hsby.QueryHsbyMyPackages)
 		// 设置我的包裹已收货状态
 		hsbyR.POST("/SetHsbyMyPackagesStatus", hsby.SetHsbyMyPackagesStatus)
+		// 查询省市信息(不包括区)
+		hsbyR.GET("/QueryProvincesAndCities", hsby.QueryProvincesAndCities)
 	}
 
 	return r