From 83414efff580cd4168e7cbc2e1e3288895444fff Mon Sep 17 00:00:00 2001
From: liuxiaolong <liuxiaolong@aiotlink.com>
Date: 星期四, 13 八月 2020 11:31:30 +0800
Subject: [PATCH] save restriction in db

---
 controllers/restriction.go |   40 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 39 insertions(+), 1 deletions(-)

diff --git a/controllers/restriction.go b/controllers/restriction.go
index 37ede7b..45a819c 100644
--- a/controllers/restriction.go
+++ b/controllers/restriction.go
@@ -3,11 +3,15 @@
 import (
 	"car-service/extend/code"
 	"car-service/extend/util"
+	"car-service/models"
 	"encoding/json"
 	"fmt"
 	"github.com/astaxie/beego"
 	"net/http"
 	"github.com/robfig/cron"
+	"strconv"
+	"strings"
+	"time"
 )
 
 type RestrictionController struct {
@@ -15,7 +19,29 @@
 }
 
 func init() {
-	getRestrictionInfo()
+	date := time.Now().Format("2006-01-02")
+	var r models.Restriction
+	err := r.SelectByDate(date)
+	if err == nil {
+		//浠婃棩宸茶幏鍙栬繃闄愯淇℃伅
+		todayRes = &RestrictionResult{
+			Date: date,
+			Week: r.Week,
+			CityName: r.CityName,
+			IsXianXing: r.IsXianXing,
+		}
+		arr := strings.Split(r.WeiHao, ",")
+		if len(arr) >0 {
+			for _,s := range arr {
+				n, e := strconv.Atoi(s)
+				if e ==nil {
+					todayRes.XxWeiHao = append(todayRes.XxWeiHao,n)
+				}
+			}
+		}
+	} else {
+		getRestrictionInfo()
+	}
 }
 
 // @Title 鏌ヨ闄愯灏惧彿
@@ -99,6 +125,18 @@
 			IsXianXing: result.Result.IsXianXing,
 			XxWeiHao: result.Result.XXWeiHao,
 		}
+		rc := models.Restriction{
+			Date: result.Result.Date,
+			Week: result.Result.Week,
+			CityName: result.Result.CityName,
+			IsXianXing: result.Result.IsXianXing,
+		}
+		var arr []string
+		for _,n := range result.Result.XXWeiHao {
+			arr=append(arr, strconv.Itoa(n))
+		}
+		rc.WeiHao = strings.Join(arr, ",")
+		rc.Insert()
 	}
 }
 

--
Gitblit v1.8.0