From 85f9175b3064094a09dbe9f71ba37b2f11f38e5f Mon Sep 17 00:00:00 2001 From: liuxiaolong <liuxiaolong@aiotlink.com> Date: 星期三, 29 七月 2020 14:21:16 +0800 Subject: [PATCH] use sqlite, spaceNo add isMine --- conf/app.conf | 2 +- models/car.go | 1 + models/db.go | 6 ++++-- service/carService.go | 18 ++++++++++++++++-- controllers/car.go | 3 ++- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/conf/app.conf b/conf/app.conf index d73f536..504730a 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -16,7 +16,7 @@ pushMasterSecret = vFiErCTBqqAcufPzB0Tl45 pushPackageName = uni.UNIEDF0B5C pushBaseUrl = https://restapi.getui.com/v2/ -dbUrl = root:c++java123@tcp(192.168.20.173:3306)/car_yuying?charset=utf8 +dbUrl = ./conf/app.db redisIp = 192.168.20.10 redisPort = 6379 hikUrl = https://111.205.161.131:1443 \ No newline at end of file diff --git a/controllers/car.go b/controllers/car.go index 47980b8..2093f1a 100644 --- a/controllers/car.go +++ b/controllers/car.go @@ -101,8 +101,9 @@ // @Failure 403 {string} json "" // @router /spaceNo [get] func (c *CarController) SpaceNo() { + userId := c.GetString("userId") sv := service.NewCarService() - spaceNos := sv.FindSpaceNo() + spaceNos := sv.FindSpaceNo(userId) sort.Sort(spaceNos) resp := code.Code{ Success: true, diff --git a/models/car.go b/models/car.go index 91caf63..1e7eca2 100644 --- a/models/car.go +++ b/models/car.go @@ -34,6 +34,7 @@ PosNo string `json:"posNo"` State int `json:"state"` //0锛氱┖闂诧紝1锛氭湁杞� PlateNo string `json:"plateNo"` + IsMine bool `json:"isMine"` } type PosResult []PosInfo diff --git a/models/db.go b/models/db.go index 3ca978d..48345c6 100644 --- a/models/db.go +++ b/models/db.go @@ -3,12 +3,14 @@ import ( "github.com/astaxie/beego" "github.com/astaxie/beego/orm" - _ "github.com/go-sql-driver/mysql" //瀵煎叆鏁版嵁搴撻┍鍔� + _ "github.com/mattn/go-sqlite3" ) func InitDb() { dbUrl := beego.AppConfig.String("dbUrl") - _ = orm.RegisterDataBase("default", "mysql", dbUrl) + + orm.RegisterDriver("sqlite", orm.DRSqlite) + _ = orm.RegisterDataBase("default", "sqlite3", dbUrl) orm.RegisterModel(new(User), new(UserCar), new(SysUpgrade)) _ = orm.RunSyncdb("default", false, true) } diff --git a/service/carService.go b/service/carService.go index 028e015..edddb6b 100644 --- a/service/carService.go +++ b/service/carService.go @@ -150,9 +150,17 @@ SpaceType string `json:"spaceType"` } -func (sv *CarService) FindSpaceNo() models.PosResult { +func (sv *CarService) FindSpaceNo(userId string) models.PosResult { resultList := make(models.PosResult,0) - + var myPlateNosMap = make(map[string]string) + vehicles := sv.GetVehicleListByPerson(userId) + if vehicles != nil { + for _,veh := range vehicles { + myPlateNosMap[veh.PlateNo] = veh.PlateNo + //myPlateNos = append(myPlateNos, veh.PlateNo) + } + } + //bindCars := strings.Join(myPlateNos, ",") //鍏堟煡杞﹀簱鍞竴鏍囪瘑 //parkList := sv.getHikParkList() //鍏堟煡鏈夊嚑涓仠杞﹀満 //if parkList != nil { @@ -161,6 +169,7 @@ reqBody := map[string]interface{} { //"parkSyscode": p.ParkIndexCode,//鍋滆溅搴撳敮涓�鏍囪瘑 //"state": 1, //杞︿綅鐘舵�侊紝0锛氱┖闂诧紝1锛氬仠杞� + //"bindCars": bindCars, "pageNo": 1, "pageSize": 1000, } @@ -179,11 +188,16 @@ return nil } for _,s := range spaceList { + isMine := false + if _,exist := myPlateNosMap[s.PlateNos]; exist { + isMine = true + } pi := models.PosInfo { SpaceNo: s.SpaceNo, PosNo: "", State: s.State, PlateNo: s.PlateNos, + IsMine: isMine, } if v,ok := models.SpaceNo2Pos[s.SpaceNo];ok { pi.PosNo = v -- Gitblit v1.8.0