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

---
 service/userService.go |   40 +++++++++++++++++++++++++++++++++-------
 1 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/service/userService.go b/service/userService.go
index b93ba6c..a3e643f 100644
--- a/service/userService.go
+++ b/service/userService.go
@@ -18,31 +18,57 @@
 
 func (sv *UserService) Login(phoneNum, code string) (bool,*vo.UserInfo,error) {
 	if verifyCode(phoneNum, code) {
+		carSv := NewCarService()
+
 		var tmpUser models.User
 		err := tmpUser.SelectByPhoneNum(phoneNum)
 		fmt.Println("login err:", err)
 		if err != nil { //鐢ㄦ埛涓嶅瓨鍦�,鍒欐柊澧�
+			//鍏堝垽鏂鎵嬫満鍙锋槸鍚﹀湪娴峰悍骞冲彴涓�
+			hikPersons := carSv.GetHikPersonList()
+			found := false
+			hikPersonId := ""
+			if hikPersons != nil {
+				for _,hikP := range hikPersons {
+					if hikP.PhoneNo == phoneNum {
+						found = true
+						hikPersonId = hikP.PersonId
+					}
+				}
+			}
+			if !found {
+				return false, nil, errors.New("璇疯仈绯诲仠杞﹀満绠$悊鍛�")
+			}
+
 			u := models.User{
-				Id: uuid.NewV4().String(),
+				Id: hikPersonId,
 				PhoneNum: phoneNum,
 				IsDelete: false,
 			}
 			if _, e := u.Insert();e ==nil {
+				var plateNos = make([]string, 0)
+				hikVehicles := carSv.GetVehicleListByPerson(u.Id)
+
+				if hikVehicles != nil {
+					for _,up := range hikVehicles {
+						plateNos = append(plateNos, up.PlateNo)
+					}
+				}
 				return true, &vo.UserInfo{
 					UserId: u.Id,
 					PhoneNum: phoneNum,
-					PlateNos: []string{},
+					PlateNos: plateNos,
 				}, nil
 			} else {
 				fmt.Println("u.Insert err:", e)
 				return false, nil, errors.New("娉ㄥ唽澶辫触")
 			}
 		} else { //鐢ㄦ埛宸插瓨鍦�
-			var userCar models.UserCar
-			var plateNos []string
-			all, e := userCar.GetByUserId(tmpUser.Id)
-			if e == nil && all != nil {
-				for _,up := range all {
+			var plateNos = make([]string, 0)
+			hikVehicles := carSv.GetVehicleListByPerson(tmpUser.Id)
+
+			if hikVehicles != nil {
+				for _,up := range hikVehicles {
 					plateNos = append(plateNos, up.PlateNo)
 				}
 			}

--
Gitblit v1.8.0