sync user from hik manual,ret syncCount
| | |
| | | } |
| | | |
| | | |
| | | // @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() |
| | | } |
| | |
| | | return all,nil |
| | | } |
| | | |
| | | func (u *User) GetAllMapByPhone() map[string]User { |
| | | func (u *User) GetAllMapByPhone() (map[string]User, map[string]User) { |
| | | m := make(map[string]User) |
| | | idM := make(map[string]User) |
| | | all, _ := u.GetAllUsers() |
| | | if all !=nil { |
| | | for _,p := range all { |
| | | m[p.PhoneNum] = p |
| | | idM[p.Id] = p |
| | | } |
| | | } |
| | | return m |
| | | return m, idM |
| | | } |
| | | |
| | | func (u *User) Update() (int64, error) { |
| | |
| | | o := orm.NewOrm() |
| | | return o.Update(u, "isDelete") |
| | | } |
| | | |
| | | func (u *User) Delete(id string) (int64, error) { |
| | | o := orm.NewOrm() |
| | | res, err := o.Raw("delete from sys_user where id=?", id).Exec() |
| | | if err != nil { |
| | | return 0, err |
| | | } |
| | | return res.RowsAffected() |
| | | } |
| | |
| | | beego.Router(preApi+"/user/delPlateNo", &controllers.UserController{}, "*:DelPlateNo") |
| | | |
| | | beego.Router(preApi+"/user/all", &controllers.UserController{}, "*:GetUserAll") |
| | | beego.Router(preApi+"/user/sync", &controllers.UserController{}, "*:Sync") |
| | | |
| | | beego.Router(preApi+"/car/crossRecord", &controllers.CarController{}, "*:CrossRecord") |
| | | } |
| | |
| | | return list |
| | | } |
| | | |
| | | func SyncHikPerson() { |
| | | func SyncHikPerson() int { |
| | | syncCount := 0 |
| | | sv := NewCarService() |
| | | hikPersons := sv.GetHikPersonList() |
| | | if hikPersons != nil { |
| | | if hikPersons != nil && len(hikPersons) >0 { |
| | | var u models.User |
| | | uMap := u.GetAllMapByPhone() |
| | | uMap,idMap := u.GetAllMapByPhone() |
| | | hikPM := make(map[string]string) |
| | | for _,hp := range hikPersons { |
| | | hikPM[hp.PersonId] = hp.PersonId |
| | | if sp,ok := uMap[hp.PhoneNo];ok { |
| | | if sp.Id != hp.PersonId { |
| | | u.SyncHikPersonId(hp.PhoneNo, hp.PersonId) |
| | | syncCount++ |
| | | } |
| | | } |
| | | } |
| | | for k,_ := range idMap { |
| | | if _,in := hikPM[k];!in { |
| | | u.Delete(k) |
| | | syncCount++ |
| | | } |
| | | } |
| | | |
| | | } |
| | | return syncCount |
| | | } |
| | | |
| | | func (sv *CarService) getHikPageResult(url string, reqBody map[string]interface{}) *vo.HikPageResult { |