package services import ( "fmt" "hongze/hongqi_watch/cache" "path/filepath" "time" ) // HandleFileUpdate // @Description: 处理文件变化 // @author: Roc // @datetime2023-10-31 09:52:23 func HandleFileUpdate() { defer func() { if err := recover(); err != nil { fmt.Println("[AutoHandle]", err) } }() for { el := cache.HandleExcelList.Front() // 如果没取到,那么就睡眠1s if el == nil { time.Sleep(1 * time.Second) continue } filePath := el.Value.(string) fileExt := filepath.Ext(filePath) if fileExt != ".xlsx" && fileExt != ".xls" { //fmt.Println("不是excel文件") return } // 读取excel内容并操作入库 ReadHqExcel(filePath) // 处理完后就移除该list cache.HandleExcelList.Remove(el) cache.HandleExcelFilePathMutex.Lock() delete(cache.HandleExcelFilePathMap, filePath) cache.HandleExcelFilePathMutex.Unlock() } }