Преглед изворни кода

增加查询区域信息接口

zhou.xiaoning пре 4 година
родитељ
комит
8055c7c7bc
8 измењених фајлова са 109 додато и 0 уклоњено
  1. 23 0
      controllers/common/common.go
  2. 25 0
      docs/docs.go
  3. 25 0
      docs/swagger.json
  4. 16 0
      docs/swagger.yaml
  5. 2 0
      go.mod
  6. 4 0
      go.sum
  7. 12 0
      models/common.go
  8. 2 0
      routers/router.go

+ 23 - 0
controllers/common/common.go

@@ -77,6 +77,29 @@ func QueryProvincesAndCities(c *gin.Context) {
 	appG.Response(http.StatusOK, e.SUCCESS, rst)
 }
 
+// GetDivisions 查询区域信息
+// @Summary 查询区域信息
+// @Produce json
+// @Success 200 {object} models.Division
+// @Failure 500 {object} app.Response
+// @Router /Common/GetDivisions [get]
+// @Tags 通用服务
+func GetDivisions(c *gin.Context) {
+	appG := app.Gin{C: c}
+
+	divisions, err := models.GetDivisions()
+	if err != nil {
+		// 查询失败
+		logger.GetLogger().Errorf("GetDivisions failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+		return
+	}
+
+	// 查询成功
+	logger.GetLogger().Debugln("GetDivisions successed: %v", divisions)
+	appG.Response(http.StatusOK, e.SUCCESS, divisions)
+}
+
 // QueryImageConfigsReq 查询轮播图配置信息请求参数
 type QueryImageConfigsReq struct {
 	ImageType int `form:"imageType"`

+ 25 - 0
docs/docs.go

@@ -402,6 +402,31 @@ var doc = `{
                 }
             }
         },
+        "/Common/GetDivisions": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "通用服务"
+                ],
+                "summary": "查询区域信息",
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/models.Division"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Common/GetServerTime": {
             "get": {
                 "produces": [

+ 25 - 0
docs/swagger.json

@@ -386,6 +386,31 @@
                 }
             }
         },
+        "/Common/GetDivisions": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "通用服务"
+                ],
+                "summary": "查询区域信息",
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/models.Division"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Common/GetServerTime": {
             "get": {
                 "produces": [

+ 16 - 0
docs/swagger.yaml

@@ -8322,6 +8322,22 @@ paths:
       summary: 获取所有枚举信息
       tags:
       - 通用服务
+  /Common/GetDivisions:
+    get:
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/models.Division'
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      summary: 查询区域信息
+      tags:
+      - 通用服务
   /Common/GetServerTime:
     get:
       produces:

+ 2 - 0
go.mod

@@ -12,6 +12,7 @@ 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/clbanning/mxj v1.8.4 // 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
@@ -27,6 +28,7 @@ require (
 	github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042 // indirect
 	github.com/mailru/easyjson v0.7.6 // indirect
 	github.com/mattn/go-oci8 v0.0.8
+	github.com/mattn/go-sqlite3 v1.14.6 // indirect
 	github.com/onsi/ginkgo v1.12.0 // indirect
 	github.com/onsi/gomega v1.9.0 // indirect
 	github.com/pkg/errors v0.9.1 // indirect

+ 4 - 0
go.sum

@@ -35,6 +35,8 @@ github.com/bndr/gotabulate v1.1.2 h1:yC9izuZEphojb9r+KYL4W9IJKO/ceIO8HDwxMA24U4c
 github.com/bndr/gotabulate v1.1.2/go.mod h1:0+8yUgaPTtLRTjf49E8oju7ojpU11YmXyvq1LbPAb3U=
 github.com/boombuler/barcode v1.0.1-0.20180315051053-3c06908149f7/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
 github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
+github.com/clbanning/mxj v1.8.4 h1:HuhwZtbyvyOw+3Z1AowPkU87JkJUSv751ELWaiTpj8I=
+github.com/clbanning/mxj v1.8.4/go.mod h1:BVjHeAH+rl9rs6f+QIpeRl0tfu10SXn1pUSa5PVGJng=
 github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
 github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
 github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
@@ -207,6 +209,8 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
 github.com/mattn/go-oci8 v0.0.8 h1:D0lVs4vwDEsZ1uPKsE6v26OS6FfHeAI43yf3l8h3X48=
 github.com/mattn/go-oci8 v0.0.8/go.mod h1:wjDx6Xm9q7dFtHJvIlrI99JytznLw5wQ4R+9mNXJwGI=
 github.com/mattn/go-sqlite3 v1.11.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
+github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg=
+github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
 github.com/mattn/go-sqlite3 v2.0.1+incompatible h1:xQ15muvnzGBHpIpdrNi1DA5x0+TcBZzsIDwmw9uTHzw=
 github.com/mattn/go-sqlite3 v2.0.1+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
 github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=

+ 12 - 0
models/common.go

@@ -625,6 +625,18 @@ func GetProvincesAndCities(provinceID int) ([]Division, error) {
 	return divisions, nil
 }
 
+// GetDivisions 获取所有区域信息
+func GetDivisions() ([]Division, error) {
+	engine := db.GetEngine()
+
+	divisions := make([]Division, 0)
+	if err := engine.Find(&divisions); err != nil {
+		return nil, err
+	}
+
+	return divisions, nil
+}
+
 // GetImageConfigs 获取轮播图配置信息
 func GetImageConfigs(imageType int) ([]Szdz2imageconfig, error) {
 	engine := db.GetEngine()

+ 2 - 0
routers/router.go

@@ -99,6 +99,8 @@ func InitRouter() *gin.Engine {
 		commonR.GET("/QueryTableDefine", common.QueryTableDefine)
 		// 查询省市信息(不包括区)
 		commonR.GET("/QueryProvincesAndCities", common.QueryProvincesAndCities)
+		// 查询区域信息
+		commonR.GET("/GetDivisions", common.GetDivisions)
 		// 查询轮播图配置信息
 		commonR.GET("/QueryImageConfigs", common.QueryImageConfigs)
 		// 获取所有枚举信息