func log(i int) { logger.Debug("Debug>>>>>>>>>>>>>>>>>>>>>>" + strconv.Itoa(i)) logger.Info("Info>>>>>>>>>>>>>>>>>>>>>>>>>" + strconv.Itoa(i)) logger.Warn("Warn>>>>>>>>>>>>>>>>>>>>>>>>>" + strconv.Itoa(i)) logger.Error("Error>>>>>>>>>>>>>>>>>>>>>>>>>" + strconv.Itoa(i)) logger.Fatal("Fatal>>>>>>>>>>>>>>>>>>>>>>>>>" + strconv.Itoa(i)) }
/**复制所有ini文件*/ func copyIniFiles_local() error { if len(goldCfg) <= 0 { return nil } defer func() { if err := recover(); err != nil { logger.Fatal("捕获到异常:", err) } }() var rootName string = "plugins/java.rpt.datapost/WebRoot/xmlConf/" var desRootName string = "xml_bak" var suffix string = ".ini" var rootPath string = "xml_ini//xml_ini.ini" var fileFilter string = "/" s := []string{goldCfg, rootName} var path = strings.Join(s, "/") results := make(map[string]string) err := filepath.Walk(path, func(path string, f os.FileInfo, err error) error { if f == nil { return err } if f.IsDir() { iniFile := path + fileFilter + f.Name() + suffix desIniFile := strings.Replace("xml_bak/"+f.Name(), rootName, desRootName, -1) + fileFilter + f.Name() + suffix if !strings.EqualFold(iniFile, rootPath) && strings.HasSuffix(iniFile, suffix) { results[desIniFile] = iniFile copyFile(iniFile, desIniFile) } } return nil }) if err != nil { panic(err) logger.Error("filepath.Walk() returned %v\n", err) } return err }
func NoSqlSync(dbIni *DBini, xmlInfo *XmlInfo) { if !StartFlag { return } defer func() { if err := recover(); err != nil { logger.Error(err) } }() if strings.EqualFold(xmlInfo.FileName, "network_control") { connString := fmt.Sprintf("%s:%s", dbIni.F_Ip, dbIni.F_Port) dbName := dbIni.F_Dbname yearMonth := GetYearMonth(TimeUtcToStr(time.Now())) firstDay := StrToTime(GetMonthFirstDay(TimeUtcToStr(time.Now()))) siteMap := make(map[int32]Site) session, err := mgo.Dial(connString) defer session.Close() t_pwd, _ := Base64Dec(dbIni.T_Password) dbIni.T_Db.Db_open(dbIni.T_DbType, dbIni.T_User, t_pwd, dbIni.T_Ip, dbIni.T_Port, dbIni.T_Dbname) //关闭数据库 defer dbIni.T_Db.db.Close() if dbIni.T_Db.db == nil { logger.Error("无法链接中间数据库") return } if err != nil { logger.Error("无法链接mongodb数据库,请检查配置信息及服务是否正常") return } session.SetMode(mgo.Monotonic, true) siteChartTable_c := session.DB(dbName).C("siteChartTable") alarmprint_c := session.DB(dbName).C("alarmprint") site_c := session.DB(dbName).C("site") var siteChartDatas []SiteChartTable ///////////////////////测试数据 赋值 //yearMonth = "201406" //firstDay = StrToTime(GetMonthFirstDay("2014-06-30 11:13:57")) siteChartTable_c.Find(bson.M{"month": yearMonth}).All(&siteChartDatas) var alarmDatas []Alarmprint alarmprint_c.Find(bson.M{"time": bson.M{"$gte": firstDay}}).All(&alarmDatas) var siteDatas []Site site_c.Find(nil).All(&siteDatas) for i := range siteDatas { site := siteDatas[i] siteMap[site.Siteurlhash] = site } fmt.Println("siteChartDatas:", len(siteChartDatas)) fmt.Println("alarmDatas:", len(alarmDatas)) fmt.Println("siteDatas:", len(siteDatas)) //写入中间库 stmt, err := dbIni.T_Db.db.Prepare(xmlInfo.InsertSQL) defer stmt.Close() if err != nil { panic(err) logger.Fatal(err) return } impDate := TimeUtcToStr(time.Now()) for i := range siteChartDatas { siteChart := siteChartDatas[i] scans := make([]interface{}, 15) month := Substr(siteChart.Month, 4, 2) year_month_info := strings.Join([]string{siteChart.Year, month}, "-") siteInfo, ok := siteMap[siteChart.Siteurlhash] var siteName, siteUrl string if ok { siteName = siteInfo.Sitename siteUrl = siteInfo.Siteurl } scans[0] = siteInfo.Id.Hex() scans[1] = siteName scans[2] = siteUrl scans[3] = siteChart.Year scans[4] = month scans[5] = year_month_info scans[6] = siteChart.Numwarning scans[7] = siteChart.Numsuspicion scans[8] = siteChart.Numattention scans[9] = 0 scans[10] = Substr(impDate, 0, 10) scans[11] = impDate scans[12] = dbIni.SysType scans[13] = dbIni.SysId scans[14] = dbIni.SysName if len(siteInfo.Id.Hex()) > 0 { stmt.Exec(scans...) } } for i := range alarmDatas { alarm := alarmDatas[i] scans := make([]interface{}, 15) dateTime := TimeUtcToStr(alarm.Time) year := strconv.Itoa(alarm.Time.Year()) month := Substr(dateTime, 5, 2) year_month_info := strings.Join([]string{year, month}, "-") siteInfo, ok := siteMap[alarm.Siteurlhash] var siteName, siteUrl string if ok { siteName = siteInfo.Sitename siteUrl = siteInfo.Siteurl } else { siteName = "已删除站点" } scans[0] = alarm.Id.Hex() scans[1] = siteName scans[2] = siteUrl scans[3] = year scans[4] = month scans[5] = year_month_info scans[6] = 0 scans[7] = 0 scans[8] = 0 scans[9] = 1 scans[10] = Substr(dateTime, 0, 10) scans[11] = impDate scans[12] = dbIni.SysType scans[13] = dbIni.SysId scans[14] = dbIni.SysName if len(alarm.Id.Hex()) > 0 { stmt.Exec(scans...) } } logger.Info("exec sysnc yearMonth end ......................", yearMonth, firstDay) } }