Example #1
0
func SaveTraceInfo(orgcode string, data []map[string]string) {
	log.Println("SaveTraceInfo")
	session := db.GetDBSession()
	defer db.ReleaseDBSession(session)
	c := session.DB("detector").C("detector_report")
	bulk := c.Bulk()
	for i, fields := range data {
		//log.Println(fields)
		mac := fields["MAC"]
		mac = filterMac(mac)
		ap_mac := fields["ACCESS_AP_MAC"]
		ap_mac = filterMac(ap_mac)
		lng, err1 := strconv.ParseFloat(fields["COLLECTION_EQUIPMENT_LONGITUDE"], 64)
		lat, err2 := strconv.ParseFloat(fields["COLLECTION_EQUIPMENT_LATITUDE"], 64)
		time, err3 := strconv.Atoi(fields["CAPTURE_TIME"])
		if err1 != nil || err2 != nil || err3 != nil {
			continue
		}
		lng, lat = data_file.Bd09towgs84(lng, lat)
		log.Println(i, ": mac", mac, "ap_mac", ap_mac, "lng", lng, "lat", lat, "time", time)

		if saveToDB {
			bulk.Insert(bson.M{"ap_mac": ap_mac, "device_mac": mac, "longitude": lng, "latitude": lat, "org_code": orgcode, "time": uint32(time)})
		}
	}
	bulk.Run()
}
Example #2
0
func SaveBehaviorLog(orgcode string, data []map[string]string) {
	log.Println("SaveLog")
	session := db.GetDBSession()
	defer db.ReleaseDBSession(session)
	c := session.DB("person_info").C("behavior_log")
	bulk := c.Bulk()
	for i, fields := range data {
		log.Println(i, fields)
		mac := fields["MAC"]
		mac = filterMac(mac)
		IpInt, err4 := strconv.ParseInt(fields["DST_IP"], 10, 64)
		Ip := inet_ntoa(IpInt)
		port := fields["DST_PORT"]
		lng, err1 := strconv.ParseFloat(fields["LONGITUDE"], 64)
		lat, err2 := strconv.ParseFloat(fields["LATITUDE"], 64)
		if orgcode == "779852855" && err2 != nil {
			lat, err2 = strconv.ParseFloat(fields["LAITTUDE"], 64)
		}
		time, err3 := strconv.Atoi(fields["CAPTURE_TIME"])
		if err1 != nil || err2 != nil || err3 != nil || err4 != nil {
			log.Println("error:", err1, err2, err3, err4)
			continue
		}
		lng, lat = data_file.Bd09towgs84(lng, lat)
		if saveToDB {
			//c.Insert(fields)
			bulk.Insert(bson.M{"mac": mac, "dst_ip": Ip, "dst_port": port, "longitude": lng, "latitude": lat, "org_code": orgcode, "time": uint32(time)})
		}
	}
	bulk.Run()
}
Example #3
0
func ConvertGeo() {
	c := db.GetDBSession().DB("detector").C("detector_report")
	c2 := db.GetDBSession().Copy().DB("detector").C("detector_report")
	query := c.Find(bson.M{"org_code": "555400905"})
	iter := query.Iter()
	e := bson.M{}
	for iter.Next(&e) {
		id, _ := e["_id"]
		idStr := id.(bson.ObjectId)
		log.Println(idStr)
		lng := GetNumber(e, "longitude")
		lat := GetNumber(e, "latitude")
		lng, lat = data_file.Bd09towgs84(lng, lat)
		c2.UpdateId(e["_id"], bson.M{"$set": bson.M{"longitude": lng, "latitude": lat}})
	}
}
Example #4
0
func SaveServiceInfo(data *data_file.BCPFile) {
	session := db.GetDBSession()
	defer db.ReleaseDBSession(session)
	orgCode := data.Meta.OrgCode
	for _, fields := range data.KeyFields {
		serviceInfo := protocol.ServiceInfo{}
		serviceInfo.NETBAR_WACODE = fields["G020004"]
		serviceInfo.ID = orgCode + "_" + serviceInfo.NETBAR_WACODE
		serviceInfo.SERVICE_NAME = fields["F040002"]
		serviceInfo.PRINCIPAL = fields["E020001"]
		serviceInfo.PERSON_NAME = fields["E020001"]
		serviceInfo.PERSON_TEL = fields["B070003"]
		serviceInfo.BUSINESS_NATURE = fields["E010007"]
		serviceInfo.STATUS = 1
		serviceInfo.SERVICE_TYPE = 9
		serviceInfo.PROVINCE_CODE = serviceInfo.NETBAR_WACODE[:2] + "0000"
		serviceInfo.CITY_CODE = serviceInfo.NETBAR_WACODE[:4] + "00"
		serviceInfo.AREA_CODE = serviceInfo.NETBAR_WACODE[:6]
		serviceInfo.ADDRESS = fields["G020017"]
		serviceInfo.ORG_CODE = orgCode
		lng, _ := strconv.ParseFloat(fields["F010016"], 64)
		lat, _ := strconv.ParseFloat(fields["F010017"], 64)
		lng, lat = data_file.Bd09towgs84(lng, lat)
		serviceInfo.XPOINT = fmt.Sprintf("%.6f", lng)
		serviceInfo.YPOINT = fmt.Sprintf("%.6f", lat)
		serviceInfo.CREATE_TIME = "2016-07-02 00:00:00"
		serviceInfo.CAP_TYPE = "2"

		serviceInfoOld := protocol.ServiceInfo{}
		err := session.DB("platform").C("service").Find(bson.M{"id": serviceInfo.ID}).One(&serviceInfoOld)
		if err != nil {
			no, err := CreateServiceNo()
			serviceInfo.NO = strconv.Itoa(no)
			if err != nil {
				continue
			}
			session.DB("platform").C("service").Insert(serviceInfo)
		} else {
			serviceInfo.NO = serviceInfoOld.NO
			session.DB("platform").C("service").Update(bson.M{"id": serviceInfo.ID}, serviceInfo)
		}
	}
}
Example #5
0
func UpdateApData(orgcode string, data []map[string]string) {
	session := db.GetDBSession()
	defer db.ReleaseDBSession(session)
	c := session.DB("detector").C("detector_info")
	for i, fields := range data {
		mac := fields["AP_MAC"]
		mac = filterMac(mac)
		netbar_wacode := fields["NETBAR_WACODE"]
		lng, err1 := strconv.ParseFloat(fields["LONGITUDE"], 64)
		lat, err2 := strconv.ParseFloat(fields["LATITUDE"], 64)
		if orgcode == "779852855" && err2 != nil {
			lat, err2 = strconv.ParseFloat(fields["LAITTUDE"], 64)
		}
		if err1 != nil || err2 != nil {
			continue
		}
		lng, lat = data_file.Bd09towgs84(lng, lat)
		log.Println(i, ": mac", mac, "lng", lng, "lat", lat)
		if saveToDB {
			c.UpsertId(mac, bson.M{"_id": mac, "longitude": lng, "latitude": lat, "last_active_time": uint32(time.Now().Unix()), "company": "02", "org_code": orgcode, "netbar_wacode": netbar_wacode})
		}
	}
}