| | |
| | | func (u *UserController) Login() { |
| | | phoneNum := u.GetString("phoneNum") |
| | | cod := u.GetString("code") |
| | | cid := u.GetString("cid") //unipush clientid |
| | | resp := code.Code{} |
| | | fmt.Println("phoneNum:", phoneNum, "code:", cod) |
| | | if phoneNum == "" || cod == "" { |
| | | fmt.Println("phoneNum:", phoneNum, "code:", cod, "clientId:", cid) |
| | | if phoneNum == "" || cod == ""{ |
| | | resp.Success= false |
| | | resp.Status= http.StatusBadRequest |
| | | resp.Data= "参数有误" |
| | | } else { |
| | | var sv service.UserService |
| | | b, info, e := sv.Login(phoneNum, cod) |
| | | b, info, e := sv.Login(phoneNum, cod, cid) |
| | | |
| | | if b { |
| | | resp.Success= true |
| | |
| | | // @Success 200 {string} logout success |
| | | // @router /logout [get] |
| | | func (u *UserController) Logout() { |
| | | cid := u.GetString("cid") //unipush clientid |
| | | fmt.Println("clientId:", cid) |
| | | |
| | | if cid != "" { |
| | | go func() { |
| | | unbindB, unE := service.UnbindAlias(cid) |
| | | fmt.Println("unbind result:", unbindB, "err:", unE) |
| | | var uc models.UserClient |
| | | uc.DeleteByCid(cid) |
| | | }() |
| | | } |
| | | resp := code.Code{} |
| | | resp.Success = true |
| | | resp.Status = http.StatusOK |
| | |
| | | resp.Status = http.StatusBadRequest |
| | | resp.Data = "参数有误" |
| | | } else { |
| | | |
| | | var sv service.UserService |
| | | if sv.AddPlateNo(reqBody.UserId, reqBody.PlateNo) { |
| | | resp.Success = true |
| | | resp.Status = http.StatusOK |
| | | resp.Data = "添加成功" |
| | | } else { |
| | | resp.Success = false |
| | | resp.Status = http.StatusBadRequest |
| | | resp.Data = "添加失败" |
| | | } |
| | | } |
| | | u.Data["json"] = resp |
| | | u.ServeJSON() |
| | | } |
| | | |
| | | // @router /myPlateNos [get] |
| | | func (u *UserController) MyPlateNos() { |
| | | userId := u.GetString("userId") |
| | | fmt.Println("MyPlateNos userId", userId) |
| | | sv := service.NewCarService() |
| | | vehicleList := sv.GetVehicleListByPerson(userId) |
| | | var nos = make([]string, 0) |
| | | if vehicleList != nil { |
| | | for _,p := range vehicleList { |
| | | nos = append(nos, p.PlateNo) |
| | | } |
| | | } |
| | | resp := code.Code{ |
| | | Success: true, |
| | | Status: http.StatusOK, |
| | | Data: nos, |
| | | } |
| | | u.Data["json"] = resp |
| | | u.ServeJSON() |
| | | } |
| | | |
| | | // @router /delPlateNo [delete] |
| | | func (u *UserController) DelPlateNo() { |
| | | userId := u.GetString("userId") |
| | | plateNo := u.GetString("plateNo") |
| | | resp := code.Code{} |
| | | var uc models.UserCar |
| | | i,e := uc.Delete(userId, plateNo) |
| | | fmt.Println("delPlateNo i:",i, "e:", e) |
| | | if e ==nil && i >0 { |
| | | resp.Success = true |
| | | resp.Status = http.StatusOK |
| | | resp.Data = "删除成功" |
| | | } else { |
| | | resp.Success = false |
| | | resp.Status = http.StatusInternalServerError |
| | | resp.Data = "删除失败" |
| | | } |
| | | u.Data["json"] = resp |
| | | u.ServeJSON() |
| | | } |
| | | |
| | | // @router /all [get] |
| | | func (u *UserController) GetUserAll() { |
| | | resp := code.Code{} |
| | | sv := service.NewCarService() |
| | | personAll := sv.GetHikPersonList() |
| | | if personAll != nil { |
| | | resp.Success = true |
| | | resp.Status = http.StatusOK |
| | | resp.Data = personAll |
| | | } |
| | | u.Data["json"] = resp |
| | | u.ServeJSON() |
| | | } |
| | | |
| | | |
| | | // @router /sync [get] |
| | | func (u *UserController) Sync() { |
| | | resp := code.Code{} |
| | | syncCount := service.SyncHikPerson() |
| | | |
| | | resp.Success = true |
| | | resp.Status = http.StatusOK |
| | | resp.Data = map[string]interface{}{ |
| | | "syncCount": syncCount, |
| | | } |
| | | |
| | | u.Data["json"] = resp |
| | | u.ServeJSON() |
| | | } |