liuxiaolong
2020-08-11 eef11eeadc679b1ad7bd23c983a67318d7cd3705
sync user from hik manual,ret syncCount
4个文件已修改
47 ■■■■ 已修改文件
controllers/user.go 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/user.go 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
routers/router.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/carService.go 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/user.go
@@ -186,4 +186,17 @@
}
// @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()
}
models/user.go
@@ -55,15 +55,17 @@
    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) {
@@ -89,3 +91,12 @@
    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()
}
routers/router.go
@@ -56,6 +56,7 @@
    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")
}
service/carService.go
@@ -303,20 +303,32 @@
    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 {