func SaveVirtualID(orgcode string, data []map[string]string) { log.Println("SaveVirtualID") var waitgroup sync.WaitGroup for _, fields := range data { authType := fields["B040021"] authAccount := fields["B040022"] virtualID := fields["B040003"] virtualType := fields["B040001"] mac := fields["C040002"] mac = filterMac(mac) time, err := strconv.Atoi(fields["H010015"]) if err != nil { continue } fAuth := data_import.Feature{} fVirtual := data_import.Feature{} fMac := data_import.Feature{} if authType == "1029999" { if isPhoneNo(authAccount) { fAuth.Type = "1020004" } else { continue } } else if authType == "1020002" { fAuth.Type = "1020002" fAuth.Value = filterMac(authAccount) } else { fAuth.Type = authType fAuth.Value = authAccount fAuth.OrgCode = orgcode fAuth.Time = uint32(time) } fVirtual.Type = virtualType fVirtual.OrgCode = orgcode fVirtual.Time = uint32(time) fVirtual.Value = virtualID fMac.Value = mac fMac.OrgCode = orgcode fMac.Time = uint32(time) fMac.Type = "1020002" if authType == "1020002" { waitgroup.Add(1) go data_import.SaveFeature(&waitgroup, fMac, fVirtual) } else { waitgroup.Add(1) go data_import.SaveFeature(&waitgroup, fMac, fVirtual) waitgroup.Add(1) go data_import.SaveFeature(&waitgroup, fMac, fAuth) waitgroup.Add(1) go data_import.SaveFeature(&waitgroup, fAuth, fVirtual) } } waitgroup.Wait() }
func SaveDeviceInfo(orgcode string, data []map[string]string) { session := db.GetDBSession() defer db.ReleaseDBSession(session) c := session.DB("person_info").C("mac") bulk := c.Bulk() var waitgroup sync.WaitGroup for i, fields := range data { mac := fields["MAC"] mac = filterMac(mac) ap_mac := fields["AP_MAC"] ap_mac = filterMac(ap_mac) authType := fields["AUTH_TYPE"] authAccount := fields["AUTH_ACCOUNT"] time, err3 := strconv.Atoi(fields["START_TIME"]) if err3 != nil { continue } log.Println(i, ": mac", mac, "ap_mac", ap_mac, "auth_type", authType, "account", authAccount, "time", time) if saveToDB { f1 := data_import.Feature{} f2 := data_import.Feature{} f1.Type = "1020002" f1.Value = mac f1.OrgCode = orgcode f1.Time = uint32(time) if authType == "1020004" { bulk.Upsert(bson.M{"mac": mac, "phone": authAccount}, bson.M{"mac": mac, "phone": authAccount, "org_code": orgcode, "time": uint32(time)}) } else if authType == "1029999" { if isPhoneNo(authAccount) { bulk.Upsert(bson.M{"mac": mac, "phone": authAccount}, bson.M{"mac": mac, "phone": authAccount, "org_code": orgcode, "time": uint32(time)}) } } if authType == "1029999" { if isPhoneNo(authAccount) { f2.Type = "1020004" f2.Value = authAccount f2.OrgCode = orgcode f2.Time = uint32(time) } else { continue } } else { f2.Type = authType if f2.Type == "1020002" { f2.Value = filterMac(authAccount) } else { f2.Value = authAccount } f2.OrgCode = orgcode f2.Time = uint32(time) } waitgroup.Add(1) go data_import.SaveFeature(&waitgroup, f1, f2) } } bulk.Run() waitgroup.Wait() }