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

---
 models/restriction.go      |   27 +++++++++++++
 controllers/restriction.go |   40 +++++++++++++++++++
 models/db.go               |    2 
 service/userService.go     |    2 
 4 files changed, 68 insertions(+), 3 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()
 	}
 }
 
diff --git a/models/db.go b/models/db.go
index 72258a9..8821eeb 100644
--- a/models/db.go
+++ b/models/db.go
@@ -13,6 +13,6 @@
 	dbPath := rootPath +"/"+ dbUrl
 	orm.RegisterDriver("sqlite", orm.DRSqlite)
 	_ = orm.RegisterDataBase("default", "sqlite3", dbPath)
-	orm.RegisterModel(new(User), new(UserCar), new(SysUpgrade), new(UserClient))
+	orm.RegisterModel(new(User), new(UserCar), new(SysUpgrade), new(UserClient), new(Restriction))
 	_ = orm.RunSyncdb("default", false, true)
 }
diff --git a/models/restriction.go b/models/restriction.go
index 2640e7f..8a29351 100644
--- a/models/restriction.go
+++ b/models/restriction.go
@@ -1 +1,28 @@
 package models
+
+import (
+	"github.com/astaxie/beego/orm"
+)
+
+type Restriction struct {
+	Date 		string 		`orm:"pk;size(50);column(date)" json:"date"`
+	Week 		string 		`orm:"size(50);column(week)" json:"week"`
+	CityName 	string  	`orm:"size(50);column(cityName)" json:"cityName"`
+	IsXianXing	int 		`orm:"size(8);column(isXianXing)" json:"isXianXing"`
+	WeiHao 		string 		`orm:"size(50);column(weiHao)" json:"weiHao"`
+}
+
+func (r *Restriction) TableName() string {
+	return "sys_restriction"
+}
+
+func (r *Restriction) Insert() (int64,error) {
+	o := orm.NewOrm()
+	return o.Insert(r)
+}
+
+func (r *Restriction) SelectByDate(date string) error {
+	o := orm.NewOrm()
+	err := o.QueryTable(r.TableName()).Filter("date", date).One(r)
+	return err
+}
\ No newline at end of file
diff --git a/service/userService.go b/service/userService.go
index dc2f08b..a468dca 100644
--- a/service/userService.go
+++ b/service/userService.go
@@ -89,7 +89,7 @@
 			}
 		} else { //鐢ㄦ埛宸插瓨鍦�
 			if phoneNum != tmpUser.PhoneNum {
-				tmpUser.UpdatePhoneNum(tmpUser.PhoneNum, hikPersonId)
+				tmpUser.UpdatePhoneNum(phoneNum, hikPersonId)
 			}
 			var plateNos = make([]string, 0)
 			hikVehicles := carSv.GetVehicleListByPerson(hikPersonId)

--
Gitblit v1.8.0