package SyncService import ( "dsAutoCode/Dao/SyncDao" "dsAutoCode/Utils/CommonUtil" "dsAutoCode/Utils/FileUtil" ) var lastUpdateTimeLog = CommonUtil.GetCurrentPath()+"/lastupdate.log" //记录最后的修改时间 func WriteLastUpdateTimeLog() { //读取最后一次修改时间 lastUpdateTime := ReadLastUpdate() FileUtil.WriteFileContent(lastUpdateTimeLog,CommonUtil.ConvertInt64ToString(lastUpdateTime)) } func SwaggerTableClear() { SyncDao.SwaggerTableClear() } func ProtoTableClear() { SyncDao.ProtoTableClear() } //2、初始化 func SwaggerTableToDb() { SyncDao.SwaggerTableToDb() } func ProtoTableToDb() { SyncDao.ProtoTableToDb() } /** 功能:获取最后的文件修改时间 作者:黄海 时间:2020-04-27 */ func ReadLastUpdate() int64 { swaggerFile := CommonUtil.GetCurrentParentPath()+"/dsBaseWeb/docs/swagger.json" lastUpdateTime := CommonUtil.GetFileModTime(swaggerFile) //遍历所有proto文件 pathname := CommonUtil.GetCurrentParentPath()+"/dsBaseRpc/RpcService" files, _ := FileUtil.WalkDir(pathname, ".pb.go") for m := 0; m < len(files); m++ { thisUpdateTime := CommonUtil.GetFileModTime(files[m]) if thisUpdateTime > lastUpdateTime { lastUpdateTime = thisUpdateTime } } return lastUpdateTime } func CheckNew() bool { //读取最后一次修改时间 lastUpdateTime := ReadLastUpdate() //提取本地日志文件的提取时间 exists, _ := CommonUtil.PathExists(lastUpdateTimeLog) //文件不存在,肯定需要更新 if exists { logLastUpdateTime := CommonUtil.ConvertStringToInt64(FileUtil.ReadFileContent(lastUpdateTimeLog)) if logLastUpdateTime < lastUpdateTime { return true } else { return false } } else { return true } }