Example #1
0
// 将通道里面的所有内容写入到文件中
func SaveToFile() {
	logUtil.Log(fmt.Sprintf("通道中尚未被处理的数据量为:%d", len(dataChannel)), logUtil.Debug, true)

	// 组装数据到dataSlice中,并保存到日志文件
	dataSlice := make([]string, 0, 1024)

	logUtil.Log("开始取通道中的数据", logUtil.Debug, true)
	if len(dataChannel) > 0 {
	Outer:
		for {
			select {
			case data := <-dataChannel:
				dataSlice = append(dataSlice, data)
				dataSlice = append(dataSlice, stringUtil.GetNewLineString())
			default:
				break Outer
			}
		}
	}
	logUtil.Log("取通道中的数据结束", logUtil.Debug, true)

	logUtil.Log("开始保存数据到文件", logUtil.Debug, true)
	if len(dataSlice) > 0 {
		fileUtil.WriteFile(config.SAVE_DATA_PATH, fmt.Sprintf("%s.sql", timeUtil.Format(time.Now(), "yyyy-MM-dd")), true, dataSlice...)
	}
	logUtil.Log("保存数据到文件结束", logUtil.Debug, true)
}
// 保存世界历史消息
func saveWorldHistoryMessage() {
	logUtil.Log("开始保存世界历史消息...", logUtil.Info, true)

	worldHistoryMessageMutex.RLock()
	defer worldHistoryMessageMutex.RUnlock()

	if bytes, err := json.Marshal(worldHistoryMessageList); err == nil {
		fileUtil.WriteFile(con_HistoryPath, getWorldHistoryMessageFileName(), false, string(bytes))
	}

	logUtil.Log("保存世界历史消息完成...", logUtil.Info, true)
}
// 保存公会历史消息
func saveUnionHistoryMessage() {
	logUtil.Log("开始保存公会历史消息...", logUtil.Info, true)

	unionHistoryMessageMutex.RLock()
	defer unionHistoryMessageMutex.RUnlock()

	// 遍历所有的历史消息,每个公会保存为一个文件
	for unionId, messageList := range unionHistoryMessageList {
		if bytes, err := json.Marshal(messageList); err == nil {
			fileUtil.WriteFile(con_HistoryPath, getUnionHistoryMessageFileName(unionId), false, string(bytes))
		}
	}

	logUtil.Log("保存公会历史消息完成...", logUtil.Info, true)
}
Example #4
0
// 执行sql语句
// sql:sql语句
// 返回值:无
func ExecuteSql(sql string) (errorList []error) {
	sqlSlice := strings.Split(sql, ";")

	for _, item := range sqlSlice {
		// 由于sql语句的长度不可能小于10,所以据此进行过滤
		if len(item) < 10 {
			continue
		}

		err := executeSql(item)
		if err != nil {
			fileUtil.WriteFile(config.FAIL_DATA_PATH, timeUtil.Format(time.Now(), "yyyy-MM-dd"), true, item, ";", stringUtil.GetNewLineString())
			errorList = append(errorList, err)
		}
	}

	// 如果整个过程当中出现过错误,则将整句sql记录下来
	if len(errorList) > 0 {
		logUtil.Log(fmt.Sprintf("出现Error的sql语句为:%s", sql), logUtil.Error, true)
	}

	return
}