From 49f07b0ce7a6a9e0893a9a01199130f2fa0e619c Mon Sep 17 00:00:00 2001
From: liuxiaolong <liuxiaolong@aiotlink.com>
Date: 星期三, 17 六月 2020 18:03:23 +0800
Subject: [PATCH] add restriction
---
go.sum | 2 +
routers/router.go | 1
controllers/restriction.go | 95 +++++++++++++++++++++++++++++++++++++++++++++++
go.mod | 1
4 files changed, 99 insertions(+), 0 deletions(-)
diff --git a/controllers/restriction.go b/controllers/restriction.go
new file mode 100644
index 0000000..8ce48ce
--- /dev/null
+++ b/controllers/restriction.go
@@ -0,0 +1,95 @@
+package controllers
+
+import (
+ "car-service/extend/code"
+ "car-service/extend/util"
+ "encoding/json"
+ "github.com/astaxie/beego"
+ "net/http"
+ "github.com/robfig/cron"
+)
+
+type RestrictionController struct {
+ beego.Controller
+}
+
+// @Title 鏌ヨ闄愯灏惧彿
+// @Description 鏌ヨ闄愯灏惧彿
+// @Success 200 {object} controllers.RestrictionResult
+// @Failure 403 {string} json ""
+// @router /spaceNo [get]
+func (c *RestrictionController) Restriction() {
+ resp := code.Code{}
+ if todayRes !=nil {
+ resp.Success= true
+ resp.Status= http.StatusOK
+ resp.Data= *todayRes
+ } else {
+ resp.Success= false
+ resp.Status= http.StatusBadRequest
+ resp.Data= nil
+ }
+ c.Data["json"] = resp
+ c.ServeJSON()
+}
+
+var todayRes *RestrictionResult
+
+func Schedule() {
+ c := cron.New()
+ //姣忓皬鏃剁洃娴嬩竴娆℃槸鍚﹁繃鏈�
+ c.AddFunc("0 0 * * * ?", func() {
+ todayRes = nil
+ getRestrictionInfo()
+ })
+ c.Start()
+}
+
+type RestrictionResult struct {
+ Date string `json:"date"`
+ Week string `json:"week"`
+ CityName string `json:"cityName"`
+ XxWeiHao []int `json:"xxWeiHao"`
+}
+
+type JuHeResult struct {
+ Reason string `json:"reason"`
+ Result CityRestriction `json:"result"`
+ ErrorCode int `json:"error_code"`
+}
+
+type CityRestriction struct {
+ Date string `json:"date"`
+ Week string `json:"week"`
+ City string `json:"city"`
+ CityName string `json:"cityname"`
+ Des []interface{} `json:"des"`
+ Fine string `json:"fine"`
+ Remarks string `json:"remarks"`
+ IsXianXing int `json:"isxianxing"`
+ XXWeiHao []int `json:"xxweihao"`
+ Holiday string `json:"holiday"`
+}
+
+func getRestrictionInfo() {
+ juHeAppKey := ""
+ url := "http://v.juhe.cn/xianxing/index?key="+ juHeAppKey +"&city=beijing&type=1"
+ b, err := util.DoPostRequest(url, util.CONTENT_TYPE_JSON, nil, nil, nil)
+ if err != nil {
+ return
+ }
+ var result JuHeResult
+ err = json.Unmarshal(b, &result)
+ if err != nil {
+ return
+ }
+ if result.ErrorCode == 0 {
+ todayRes = &RestrictionResult{
+ Date: result.Result.Date,
+ Week: result.Result.Week,
+ CityName: result.Result.CityName,
+ XxWeiHao: result.Result.XXWeiHao,
+ }
+ }
+}
+
diff --git a/go.mod b/go.mod
index 5b133dc..a9742c0 100644
--- a/go.mod
+++ b/go.mod
@@ -9,4 +9,5 @@
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/swaggo/swag v1.6.7
+ github.com/robfig/cron v1.2.0
)
diff --git a/go.sum b/go.sum
index f022e5e..1751cd9 100644
--- a/go.sum
+++ b/go.sum
@@ -14,6 +14,8 @@
github.com/astaxie/beego v1.12.1/go.mod h1:kPBWpSANNbSdIqOc8SUL9h+1oyBMZhROeYsXQDbidWQ=
github.com/beego/goyaml2 v0.0.0-20130207012346-5545475820dd/go.mod h1:1b+Y/CofkYwXMUU0OhQqGvsY2Bvgr4j6jfT699wyZKQ=
github.com/beego/x2j v0.0.0-20131220205130-a0352aadc542/go.mod h1:kSeGC/p1AbBiEp5kat81+DSQrZenVBZXklMLaELspWU=
+github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ=
+github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
github.com/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737/go.mod h1:PmM6Mmwb0LSuEubjR8N7PtNe1KxZLtOUHtbeikc5h60=
github.com/casbin/casbin v1.7.0/go.mod h1:c67qKN6Oum3UF5Q1+BByfFxkwKvhwW57ITjqwtzR1KE=
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80=
diff --git a/routers/router.go b/routers/router.go
index b191f5f..5a9a84c 100644
--- a/routers/router.go
+++ b/routers/router.go
@@ -42,4 +42,5 @@
beego.Router("/basic/api/car/statistic", &controllers.CarController{}, "*:Statistic")
beego.Router("/basic/api/car/spaceNo", &controllers.CarController{}, "*:SpaceNo")
beego.Router("/basic/api/car/app/version", &controllers.AppController{}, "*:Version")
+ beego.Router("/basic/api/car/restriction", &controllers.RestrictionController{}, "*:Restriction")
}
--
Gitblit v1.8.0