Explorar o código

增加“查询省市信息(不包括区)”接口

zhou.xiaoning %!s(int64=5) %!d(string=hai) anos
pai
achega
d7a1e309a3
Modificáronse 8 ficheiros con 402 adicións e 11 borrados
  1. 78 0
      controllers/common/common.go
  2. 104 2
      docs/docs.go
  3. 104 2
      docs/swagger.json
  4. 73 2
      docs/swagger.yaml
  5. 0 3
      go.mod
  6. 39 0
      models/common.go
  7. 2 2
      models/hsby.go
  8. 2 0
      routers/router.go

+ 78 - 0
controllers/common/common.go

@@ -0,0 +1,78 @@
+package common
+
+import (
+	"mtp2_if/global/app"
+	"mtp2_if/global/e"
+	"mtp2_if/logger"
+	"mtp2_if/models"
+	"net/http"
+
+	"github.com/gin-gonic/gin"
+)
+
+// QueryProvincesAndCitiesReq 查询省市信息请求参数
+type QueryProvincesAndCitiesReq struct {
+	ProvinceID int `form:"provinceID"` // 省ID
+}
+
+// QueryProvincesAndCitiesRsp 查询省市信息返回模型
+type QueryProvincesAndCitiesRsp struct {
+	Province models.Division   // 省
+	Cities   []models.Division // 市
+}
+
+// QueryProvincesAndCities 查询省市信息(不包括区)
+// @Summary 查询省市信息(不包括区)
+// @Produce json
+// @Param provinceID query int false "省ID"
+// @Success 200 {object} QueryProvincesAndCitiesRsp
+// @Failure 500 {object} app.Response
+// @Router /Common/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.GetProvincesAndCities(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)
+}

+ 104 - 2
docs/docs.go

@@ -477,6 +477,39 @@ var doc = `{
                 }
             }
         },
+        "/Common/QueryProvincesAndCities": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "通用服务"
+                ],
+                "summary": "查询省市信息(不包括区)",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "省ID",
+                        "name": "provinceID",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/common.QueryProvincesAndCitiesRsp"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Common/QueryTableDefine": {
             "get": {
                 "produces": [
@@ -1929,6 +1962,22 @@ var doc = `{
                 }
             }
         },
+        "common.QueryProvincesAndCitiesRsp": {
+            "type": "object",
+            "properties": {
+                "cities": {
+                    "description": "市",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/models.Division"
+                    }
+                },
+                "province": {
+                    "description": "省",
+                    "$ref": "#/definitions/models.Division"
+                }
+            }
+        },
         "common.QueryTableDefineRsp": {
             "type": "object",
             "required": [
@@ -3414,6 +3463,59 @@ var doc = `{
                 }
             }
         },
+        "models.Division": {
+            "type": "object",
+            "required": [
+                "autoid",
+                "divisioncode"
+            ],
+            "properties": {
+                "autoid": {
+                    "description": "自增ID",
+                    "type": "integer"
+                },
+                "divisioncode": {
+                    "description": "行政代码",
+                    "type": "string"
+                },
+                "divisionlevel": {
+                    "description": "行政级别",
+                    "type": "string"
+                },
+                "divisionname": {
+                    "description": "行政名称",
+                    "type": "string"
+                },
+                "modifierid": {
+                    "description": "修改人",
+                    "type": "integer"
+                },
+                "modifytime": {
+                    "description": "修改时间",
+                    "type": "string"
+                },
+                "parentcode": {
+                    "description": "上级行政代码",
+                    "type": "string"
+                },
+                "pathname": {
+                    "description": "路径名称",
+                    "type": "string"
+                },
+                "postcode": {
+                    "description": "邮政编码",
+                    "type": "string"
+                },
+                "separablename": {
+                    "description": "可拆分的全称",
+                    "type": "string"
+                },
+                "shortcode": {
+                    "description": "地区简码",
+                    "type": "string"
+                }
+            }
+        },
         "models.HsbyGoodsOrderDetail": {
             "type": "object",
             "required": [
@@ -3518,7 +3620,7 @@ var doc = `{
                     "type": "string"
                 },
                 "vendorattr": {
-                    "description": "附件(多张,逗号分隔)",
+                    "description": "供应商附件(多张,逗号分隔)",
                     "type": "string"
                 },
                 "vendorname": {
@@ -3526,7 +3628,7 @@ var doc = `{
                     "type": "string"
                 },
                 "vendorphone": {
-                    "description": "客服电话",
+                    "description": "供应商客服电话",
                     "type": "string"
                 },
                 "videourls": {

+ 104 - 2
docs/swagger.json

@@ -461,6 +461,39 @@
                 }
             }
         },
+        "/Common/QueryProvincesAndCities": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "通用服务"
+                ],
+                "summary": "查询省市信息(不包括区)",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "省ID",
+                        "name": "provinceID",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/common.QueryProvincesAndCitiesRsp"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Common/QueryTableDefine": {
             "get": {
                 "produces": [
@@ -1913,6 +1946,22 @@
                 }
             }
         },
+        "common.QueryProvincesAndCitiesRsp": {
+            "type": "object",
+            "properties": {
+                "cities": {
+                    "description": "市",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/models.Division"
+                    }
+                },
+                "province": {
+                    "description": "省",
+                    "$ref": "#/definitions/models.Division"
+                }
+            }
+        },
         "common.QueryTableDefineRsp": {
             "type": "object",
             "required": [
@@ -3398,6 +3447,59 @@
                 }
             }
         },
+        "models.Division": {
+            "type": "object",
+            "required": [
+                "autoid",
+                "divisioncode"
+            ],
+            "properties": {
+                "autoid": {
+                    "description": "自增ID",
+                    "type": "integer"
+                },
+                "divisioncode": {
+                    "description": "行政代码",
+                    "type": "string"
+                },
+                "divisionlevel": {
+                    "description": "行政级别",
+                    "type": "string"
+                },
+                "divisionname": {
+                    "description": "行政名称",
+                    "type": "string"
+                },
+                "modifierid": {
+                    "description": "修改人",
+                    "type": "integer"
+                },
+                "modifytime": {
+                    "description": "修改时间",
+                    "type": "string"
+                },
+                "parentcode": {
+                    "description": "上级行政代码",
+                    "type": "string"
+                },
+                "pathname": {
+                    "description": "路径名称",
+                    "type": "string"
+                },
+                "postcode": {
+                    "description": "邮政编码",
+                    "type": "string"
+                },
+                "separablename": {
+                    "description": "可拆分的全称",
+                    "type": "string"
+                },
+                "shortcode": {
+                    "description": "地区简码",
+                    "type": "string"
+                }
+            }
+        },
         "models.HsbyGoodsOrderDetail": {
             "type": "object",
             "required": [
@@ -3502,7 +3604,7 @@
                     "type": "string"
                 },
                 "vendorattr": {
-                    "description": "附件(多张,逗号分隔)",
+                    "description": "供应商附件(多张,逗号分隔)",
                     "type": "string"
                 },
                 "vendorname": {
@@ -3510,7 +3612,7 @@
                     "type": "string"
                 },
                 "vendorphone": {
-                    "description": "客服电话",
+                    "description": "供应商客服电话",
                     "type": "string"
                 },
                 "videourls": {

+ 73 - 2
docs/swagger.yaml

@@ -74,6 +74,17 @@ definitions:
     required:
     - autoid
     type: object
+  common.QueryProvincesAndCitiesRsp:
+    properties:
+      cities:
+        description: 市
+        items:
+          $ref: '#/definitions/models.Division'
+        type: array
+      province:
+        $ref: '#/definitions/models.Division'
+        description: 省
+    type: object
   common.QueryTableDefineRsp:
     properties:
       columns:
@@ -1189,6 +1200,45 @@ definitions:
     required:
     - spotcontractid
     type: object
+  models.Division:
+    properties:
+      autoid:
+        description: 自增ID
+        type: integer
+      divisioncode:
+        description: 行政代码
+        type: string
+      divisionlevel:
+        description: 行政级别
+        type: string
+      divisionname:
+        description: 行政名称
+        type: string
+      modifierid:
+        description: 修改人
+        type: integer
+      modifytime:
+        description: 修改时间
+        type: string
+      parentcode:
+        description: 上级行政代码
+        type: string
+      pathname:
+        description: 路径名称
+        type: string
+      postcode:
+        description: 邮政编码
+        type: string
+      separablename:
+        description: 可拆分的全称
+        type: string
+      shortcode:
+        description: 地区简码
+        type: string
+    required:
+    - autoid
+    - divisioncode
+    type: object
   models.HsbyGoodsOrderDetail:
     properties:
       buyorsell:
@@ -1262,13 +1312,13 @@ definitions:
         description: 介绍图片[多张用逗号分隔]
         type: string
       vendorattr:
-        description: 附件(多张,逗号分隔)
+        description: 供应商附件(多张,逗号分隔)
         type: string
       vendorname:
         description: 供应商名称
         type: string
       vendorphone:
-        description: 客服电话
+        description: 供应商客服电话
         type: string
       videourls:
         description: 介绍视频[多张用逗号分隔]
@@ -3300,6 +3350,27 @@ paths:
       summary: 通知公告系统消息查询
       tags:
       - 通用服务
+  /Common/QueryProvincesAndCities:
+    get:
+      parameters:
+      - description: 省ID
+        in: query
+        name: provinceID
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/common.QueryProvincesAndCitiesRsp'
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      summary: 查询省市信息(不包括区)
+      tags:
+      - 通用服务
   /Common/QueryTableDefine:
     get:
       parameters:

+ 0 - 3
go.mod

@@ -12,7 +12,6 @@ require (
 	github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
 	github.com/beevik/etree v1.1.0
 	github.com/bndr/gotabulate v1.1.2 // indirect
-	github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
 	github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
 	github.com/fatih/structs v1.1.0 // indirect
 	github.com/gin-gonic/gin v1.6.3
@@ -39,12 +38,10 @@ require (
 	github.com/syndtr/goleveldb v1.0.0 // indirect
 	github.com/tealeg/xlsx v1.0.5 // indirect
 	github.com/tebeka/strftime v0.1.3 // indirect
-	github.com/urfave/cli/v2 v2.2.0 // indirect
 	github.com/xormplus/builder v0.0.0-20200331055651-240ff40009be // indirect
 	github.com/xormplus/core v0.0.0-20200308074340-f3bce19d5f31
 	github.com/xormplus/xorm v0.0.0-20200912034818-5d90dcd4e3d6
 	golang.org/x/net v0.0.0-20200927032502-5d4f70055728 // indirect
-	golang.org/x/text v0.3.3 // indirect
 	golang.org/x/tools v0.0.0-20200928201943-a0ef9b62deab // indirect
 	gopkg.in/flosch/pongo2.v3 v3.0.0-20141028000813-5e81b817a0c4 // indirect
 	gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22

+ 39 - 0
models/common.go

@@ -145,6 +145,26 @@ func (Msgreceiver) TableName() string {
 	return "MSGRECEIVER"
 }
 
+// Division 行政区域表
+type Division struct {
+	Autoid        int64     `json:"autoid"  xorm:"'AUTOID'" binding:"required"`             // 自增ID
+	Divisioncode  string    `json:"divisioncode"  xorm:"'DIVISIONCODE'" binding:"required"` // 行政代码
+	Shortcode     string    `json:"shortcode"  xorm:"'SHORTCODE'"`                          // 地区简码
+	Parentcode    string    `json:"parentcode"  xorm:"'PARENTCODE'"`                        // 上级行政代码
+	Divisionlevel string    `json:"divisionlevel"  xorm:"'DIVISIONLEVEL'"`                  // 行政级别
+	Divisionname  string    `json:"divisionname"  xorm:"'DIVISIONNAME'"`                    // 行政名称
+	Pathname      string    `json:"pathname"  xorm:"'PATHNAME'"`                            // 路径名称
+	Separablename string    `json:"separablename"  xorm:"'SEPARABLENAME'"`                  // 可拆分的全称
+	Postcode      string    `json:"postcode"  xorm:"'POSTCODE'"`                            // 邮政编码
+	Modifytime    time.Time `json:"modifytime"  xorm:"'MODIFYTIME'"`                        // 修改时间
+	Modifierid    int64     `json:"modifierid"  xorm:"'MODIFIERID'"`                        // 修改人
+}
+
+// TableName is DIVISION
+func (Division) TableName() string {
+	return "DIVISION"
+}
+
 // QuotePrimaryMenu 报价牌一级分类菜单
 type QuotePrimaryMenu struct {
 	Index        int                  `json:"Index"`        // 序号
@@ -532,3 +552,22 @@ func GetEnumDicItem(enumDicCode string, enumItemName int) ([]Enumdicitem, error)
 
 	return enumDicItems, nil
 }
+
+// GetProvincesAndCities 获取省市信息数组
+// 参数 provinceID int 省ID,选填
+// 返回 []Division 枚举信息数组
+// 返回 error error
+func GetProvincesAndCities(provinceID int) ([]Division, error) {
+	engine := db.GetEngine()
+
+	divisions := make([]Division, 0)
+	session := engine.Where("DIVISIONLEVEL = 'province' or DIVISIONLEVEL = 'city'")
+	if provinceID > 0 {
+		session = session.And("AUTOID = ?", provinceID)
+	}
+	if err := session.Find(&divisions); err != nil {
+		return nil, err
+	}
+
+	return divisions, nil
+}

+ 2 - 2
models/hsby.go

@@ -147,8 +147,8 @@ type HsbyListingGoodsDetail struct {
 	Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号
 
 	Vendorname  string `json:"vendorname"  xorm:"'VENDORNAME'"`   // 供应商名称
-	Vendorphone string `json:"vendorphone"  xorm:"'VENDORPHONE'"` // 客服电话
-	Vendorattr  string `json:"vendorattr"  xorm:"'VENDORATTR'"`   // 附件(多张,逗号分隔)
+	Vendorphone string `json:"vendorphone"  xorm:"'VENDORPHONE'"` // 供应商客服电话
+	Vendorattr  string `json:"vendorattr"  xorm:"'VENDORATTR'"`   // 供应商附件(多张,逗号分隔)
 
 	Last float64 `json:"last" xorm:"-"` // 现价
 }

+ 2 - 0
routers/router.go

@@ -76,6 +76,8 @@ func InitRouter() *gin.Engine {
 		commonR.GET("/QueryTraderMenu", common.QueryTraderMenu)
 		// 查询交易端列表头信息
 		commonR.GET("/QueryTableDefine", common.QueryTableDefine)
+		// 查询省市信息(不包括区)
+		commonR.GET("/QueryProvincesAndCities", common.QueryProvincesAndCities)
 		// 通知公告系统消息查询
 		commonR.Use(token.Auth()).GET("/QueryNotice", common.QueryNotice)
 		// 通知公告设置已读请求