Example #1
0
func ExportAPTrace() {
	session := db.GetDBSession()
	defer db.ReleaseDBSession(session)
	detectorArr := make([]DetectorDBInfo, 0)
	err := session.DB("detector").C("detector_info").Find(bson.M{"company": "02"}).All(&detectorArr)
	if err != nil {
		log.Println(err)
		return
	}

	outArr := make([]TraceInfo, 0)
	for _, e := range detectorArr {
		if len(e.Mac) < 12 {
			continue
		}
		service := protocol.ServiceInfo{}
		err := session.DB("platform").C("service").Find(bson.M{"id": e.OrgCode + "_" + e.NetbarWacode}).One(&service)
		if err != nil {
			continue
		}

		no, _ := strconv.Atoi(service.NO)
		service.SERVICE_CODE = service.NETBAR_WACODE[:8] + fmt.Sprintf("%06d", no)
		traceArr := make([]TraceDBInfo, 0)
		err = session.DB("detector").C("detector_report").Find(bson.M{"ap_mac": e.Mac}).Sort("-time").Limit(1).All(&traceArr)
		if err != nil {
			log.Println(err)
			return
		}

		for _, e := range traceArr {
			detectorDBInfo := DetectorDBInfo{}
			session.DB("detector").C("detector_info").FindId(e.ApMac).One(&detectorDBInfo)
			ApMac := strings.ToUpper(e.ApMac[len(e.ApMac)-12:])
			var trace TraceInfo
			trace.MAC = FormatMac(e.DeviceMac)
			trace.TYPE = 2
			trace.START_TIME = e.Time
			trace.BSSID = FormatMac(ApMac)
			trace.XPOINT = strconv.FormatFloat(e.Longitude, 'f', 6, 64)
			trace.YPOINT = strconv.FormatFloat(e.Latitude, 'f', 6, 64)
			trace.DEVMAC = FormatMac(ApMac)
			trace.DEVICENUM = OrgCode + ApMac
			trace.SERVICECODE = service.SERVICE_CODE
			outArr = append(outArr, trace)
		}
	}

	jsonString, err := json.Marshal(outArr)
	if err != nil {
		return
	}
	log.Print(string(jsonString))
	SaveFile(string(jsonString), "001")
}
Example #2
0
func ExportAPInfo() {
	session := db.GetDBSession()
	defer db.ReleaseDBSession(session)
	detectorArr := make([]DetectorDBInfo, 0)
	err := session.DB("detector").C("detector_info").Find(bson.M{"company": "02"}).All(&detectorArr)
	if err != nil {
		log.Println(err)
		return
	}

	outArr := make([]DetectorInfo, 0)
	for _, e := range detectorArr {
		if len(e.Mac) < 12 {
			continue
		}
		service := protocol.ServiceInfo{}
		err := session.DB("platform").C("service").Find(bson.M{"id": e.OrgCode + "_" + e.NetbarWacode}).One(&service)
		if err != nil {
			continue
		}
		no, _ := strconv.Atoi(service.NO)
		service.SERVICE_CODE = service.NETBAR_WACODE[:8] + fmt.Sprintf("%06d", no)
		Mac := strings.ToUpper(e.Mac[len(e.Mac)-12:])
		var detector DetectorInfo
		detector.MAC = FormatMac(Mac)
		detector.EQUIPMENT_NUM = OrgCode + Mac
		detector.EQUIPMENT_NAME = service.SERVICE_NAME + Mac[6:]
		detector.SECURITY_FACTORY_ORGCODE = OrgCode
		detector.SERVICE_CODE = service.SERVICE_CODE
		detector.PROVINCE_CODE = service.PROVINCE_CODE
		detector.CITY_CODE = service.CITY_CODE
		detector.AREA_CODE = service.AREA_CODE
		detector.EQUIPMENT_TYPE = "00"
		detector.LATITUDE = strconv.FormatFloat(e.Latitude, 'f', 6, 64)
		detector.LONGITUDE = strconv.FormatFloat(e.Longitude, 'f', 6, 64)
		detector.CREATE_TIME = "2016-07-03 12:32:00"
		detector.LAST_CONNECT_TIME = time.Now().Format("2006-01-02 15:04:05")
		detector.WDA_VERSION = "1.10"
		detector.FIRMWARE_VERSION = "1.0"
		detector.COLLECTION_RADIUS = 150
		detector.UPLOAD_TIME_INTERVAL = 60
		detector.CREATER = service.PERSON_NAME
		outArr = append(outArr, detector)
	}

	jsonString, err := json.Marshal(outArr)
	if err != nil {
		return
	}
	log.Print(string(jsonString))
	SaveFile(string(jsonString), "010")
}
Example #3
0
func ExportDeviceInfo() {
	rawData := make([]RawData, 0)
	session := db.GetDBSession()
	defer db.ReleaseDBSession(session)
	err := session.DB("3rd_data").C("raw_data").Find(bson.M{"org_code": "555400905", "type": "WA_SOURCE_FJ_0001"}).Sort("-_id").Limit(10).All(&rawData)
	if err != nil {
		log.Println(err)
		return
	}

	outArr := make([]protocol.DeviceInfo, 0)
	for _, data := range rawData {
		fields := make(map[string]string)
		for _, e := range data.Fields {
			fields[e.Key] = e.Value
		}
		wc := fields["G020004"]
		service := protocol.ServiceInfo{}
		err := session.DB("platform").C("service").Find(bson.M{"id": data.OrgCode + "_" + wc}).One(&service)
		if err != nil {
			continue
		}

		no, _ := strconv.Atoi(service.NO)
		service.SERVICE_CODE = service.NETBAR_WACODE[:8] + fmt.Sprintf("%06d", no)

		deviceInfo := protocol.DeviceInfo{}
		deviceInfo.SERVICE_CODE = service.SERVICE_CODE
		tmp, _ := strconv.ParseUint(fields["H010015"], 10, 32)
		deviceInfo.ONLINE_TIME = uint32(tmp)
		deviceInfo.NET_ENDING_NAME = ""
		tmp, _ = strconv.ParseUint(fields["F020001"], 10, 32)
		deviceInfo.NET_ENDING_IP = uint32(tmp)
		deviceInfo.NET_ENDING_MAC = fields["C040002"]
		deviceInfo.SESSION_ID = fields["H010013"]
		deviceInfo.AP_MAC = fields["F030011"]
		deviceInfo.AP_NUM = data.OrgCode + filterMac(deviceInfo.AP_MAC)
		deviceInfo.COMPANY_ID = data.OrgCode
		outArr = append(outArr, deviceInfo)
	}

	jsonString, err := json.Marshal(outArr)
	if err != nil {
		return
	}
	log.Print(string(jsonString))
	SaveFile(string(jsonString), "005")
}