internal ResponseModel BatchBaseModelFile(IEnumerable <HttpFile> files, string userName) { var responseModel = new ResponseModel(); foreach (var file in files) { try { var tempFileName = DateTime.Now.ToString($"yyyyMMddHHmmssffff{Path.GetExtension(file.Name)}"); var zipPath = Path.Combine(ConstFile.TempPath, tempFileName); SaveFile(file, zipPath); #region 对基文件不进行删除操作 //if (Directory.Exists(ConstFile.BaseModelFilePath)) //{ // Directory.Delete(ConstFile.BaseModelFilePath, true); //} #endregion if (!ZipHelper.UnZip(zipPath, ConstFile.BaseModelFilePath)) { responseModel.Success = false; responseModel.Msg = string.Format("上传失败:解压失败"); break; } var newestAlldllVersionDictionary = new Dictionary <string, string>(); var newestFileDirectoryInfo = new DirectoryInfo(ConstFile.BaseModelFilePath); GetFileNameDictionary(newestFileDirectoryInfo, newestAlldllVersionDictionary, ConstFile.BASEVERSION, ConstFile.BASEMODELID.ToString()); var baseVersion = new VersionModel { AllDllVersion = JsonConvert.SerializeObject(newestAlldllVersionDictionary), User = userName, UpLoadTime = DateTime.Now, HospitalId = -1, Number = ConstFile.BASEVERSION, }; var model = VersionBll.GetModelById(ConstFile.BASEMODELID); if (model == null) { VersionBll.Insert(baseVersion); } else { VersionBll.UpdateBaseModel(baseVersion); } responseModel.Success = true; } catch (Exception ex) { responseModel.Success = false; responseModel.Msg = $"上传失败:{ex.Message}"; break; } } DeleteTempFileOrDirectory(); return(responseModel); }
private static void CompareAction(string oldFilesDirectoryPath, string newestFileDirectoryPath, string user, UpLoadFileRequestModel upLoadFileRequestModel) { //1.获取当前医院最新版本设置版本号 //2.对比,管理文件 //3.修改本地配置 var hospitalID = upLoadFileRequestModel.HospitalId; var lastVersionModel = new VersionModel(); var number = ConstFile.BASEVERSION; var newestAllDLLVersionDictionary = new Dictionary <string, string>(); var newestFileDirectoryInfo = new DirectoryInfo(newestFileDirectoryPath); GetFileNameDictionary(newestFileDirectoryInfo, newestAllDLLVersionDictionary, ConstFile.BASEVERSION, hospitalID.ToString()); var newesterVsionModel = new VersionModel { //Id = DateTime.Now.ToString("yyyyMMddHHmmssffff"), HospitalId = hospitalID, UpLoadTime = DateTime.Now, User = user, BlackList = upLoadFileRequestModel.BlackList, ExistSoIgnoreList = upLoadFileRequestModel.ExistSoIgnoreList, DynamicCode = upLoadFileRequestModel.DynamicCode, DynamicCodeVersion = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Description = upLoadFileRequestModel.Description }; var versionModels = VersionBll.GetModelsByHospitalId(hospitalID); //对比逻辑: //1.第一次上传的时候或者当前没有出新文件的时候。和模板文件匹配. //2.第二次开始: // A【修改】.上传文件和本地文件都存在,对比不同,则把最新的文件复制到work目录和仓库目录,并且设置上传文件version为最新version(存入数据库时) // B【不变】.上传文件和本地文件都存在,对比相同,不复制文件,设置上传文件version为老版本文件的version(存入数据库时) // C【新增】.上传文件存在,本地文件不存在,则把最新的文件复制到work目录和仓库目录,并且设置上传文件version为最新version(存入数据库时) // D【删除】.上传文件不存在,本地文件存在。暂时不操作。 var oldAllDLLVersionDictionary = new Dictionary <string, string>(); var workPath = Path.Combine(ConstFile.WorkPath, hospitalID.ToString()); if (versionModels.Count != 0) { lastVersionModel = versionModels.FirstOrDefault(p => p.Id == versionModels.Max(t => t.Id)); number = AddVersion(lastVersionModel.Number); oldAllDLLVersionDictionary = JsonConvert.DeserializeObject <Dictionary <string, string> >(lastVersionModel.AllDllVersion); } else { var baseModel = VersionBll.GetModelById(ConstFile.BASEMODELID); oldAllDLLVersionDictionary = JsonConvert.DeserializeObject <Dictionary <string, string> >(baseModel.AllDllVersion); number = AddVersion(baseModel.Number); } var tempdllVersionDictionary = new Dictionary <string, string>(); foreach (var item in newestAllDLLVersionDictionary) { var newestFilePath = Path.Combine(newestFileDirectoryPath, item.Key); var newestFileInfo = new FileInfo(newestFilePath); if (oldAllDLLVersionDictionary.Keys.Contains(item.Key) && oldAllDLLVersionDictionary[item.Key] == ConstFile.BASEVERSION) { oldFilesDirectoryPath = ConstFile.BaseModelFilePath; } var localFilePath = Path.Combine(oldFilesDirectoryPath, item.Key); if (File.Exists(localFilePath)) { var localFileInfo = new FileInfo(localFilePath); if (!IsTheSame(newestFileInfo, localFileInfo)) { FileCopy(newestFileInfo, hospitalID.ToString(), number, workPath, item.Key); tempdllVersionDictionary.Add(item.Key, number); } else { tempdllVersionDictionary.Add(item.Key, oldAllDLLVersionDictionary[item.Key]); } oldAllDLLVersionDictionary.Remove(item.Key); } else { FileCopy(newestFileInfo, hospitalID.ToString(), number, workPath, item.Key); tempdllVersionDictionary.Add(item.Key, number); } } // 向前兼容.保护配置 //(删除功能暂时删除) //var deleteKey = new List<string>(); //foreach (var item in oldAllDLLVersionDictionary) //{ // if (item.Value != ConstFile.BASEVERSION) // { // deleteKey.Add(item.Key); // } //} //deleteKey.ForEach((p) => //{ // oldAllDLLVersionDictionary.Remove(p); // //var deleteFilePath = Path.Combine(workPath, p); // //MaintainWorkDic(deleteFilePath); //}); foreach (var key in tempdllVersionDictionary.Keys) { if (oldAllDLLVersionDictionary.Keys.Contains(key)) { oldAllDLLVersionDictionary[key] = tempdllVersionDictionary[key]; continue; } oldAllDLLVersionDictionary.Add(key, tempdllVersionDictionary[key]); } newesterVsionModel.Number = number; newesterVsionModel.AllDllVersion = JsonConvert.SerializeObject(oldAllDLLVersionDictionary); VersionBll.Insert(newesterVsionModel); VersionBll.UpdateHospitalNewestNumber(number, hospitalID); if (MemoryCenter.Instance.NewestHospitalVersionDic.ContainsKey(hospitalID)) { MemoryCenter.Instance.NewestHospitalVersionDic[hospitalID] = number; } else { MemoryCenter.Instance.NewestHospitalVersionDic.Add(hospitalID, number); } }