package worker import ( "enterprise/common/config" "enterprise/common/dao" "enterprise/common/model" "enterprise/common/weixin" log "github.com/sirupsen/logrus" "github.com/spf13/cast" ) func SyncStaffInfo() { cfg := config.GetConfig() hrAssiant := weixin.NewQyWeixinHR(cfg.QyWeixin.Corpid, cfg.QyWeixin.HrSecret, cfg.QyWeixin.HrSecret) userConfigs, err := dao.NewUserConfigDao().Query(model.UserConfigStatusNormal) if err != nil { log.Errorf("query staff db error :%s", err.Error()) return } for _, user := range userConfigs { staffInfo, err := hrAssiant.GetStaffInfo(user.Username) if err != nil { log.Errorf("getstaff info username[%s] error :%s", user.Username, err.Error()) continue } staff, err := dao.NewStaffInfoDao().GetByUsername(user.Username) if err != nil { log.Errorf("db error :%s", err.Error()) continue } if staff == nil { staff = new(model.StaffInfo) } staff.Username = staffInfo.UserName staff.Realname = staffInfo.RealName staff.Phone = staffInfo.Phone staff.Idno = staffInfo.Idno staff.Salary = cast.ToString(staffInfo.Salary) staff.EntryDate = staffInfo.EntryDate staff.OfficialDate = staffInfo.OfficialDate staff.BirthDate = staffInfo.BirthDate staff.BankName = staffInfo.BankName staff.BankCard = staffInfo.BankCard if staff.Id == 0 { _, err = dao.NewStaffInfoDao().Create(staff) } else { err = dao.NewStaffInfoDao().Update(staff) } if err != nil { log.Errorf("db error :%s", err.Error()) } } }