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") }
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") }
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") }
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) } } }