denny 8 months ago
parent
commit
99821cbe85
2 changed files with 51 additions and 0 deletions
  1. 24 0
      src/Service/DatabaseService.cs
  2. 27 0
      src/Service/UserDBService.cs

+ 24 - 0
src/Service/DatabaseService.cs

@@ -59,6 +59,7 @@ namespace WingMongoDBModule.Service
         private string _curCDNHost => EnvironmentConfigManager.GetParammeter<StringParameter>("Storage", "CDNServerUrl").Value;
         private string _domains => EnvironmentConfigManager.GetParammeter<StringParameter>("Gateway", "Domains").Value;
         private string _httpService => EnvironmentConfigManager.GetParammeter<StringParameter>("Services", "JsonRpcHttp").Value;
+        private bool _isResearchEditionService => EnvironmentConfigManager.GetParammeter<BoolParameter>("General", "IsResearchEditionService").Value;
         //是否体检系统本地工作站
         private bool _isLocalHost => GetStringParams("Vital", "CloudServerUrl") != "";
         private int _downloadOriginalLowestValue = 1048576;
@@ -767,6 +768,29 @@ namespace WingMongoDBModule.Service
                     Logger.WriteLineInfo($"mongoDB upgrade failed, now the version is 1.9, error:{ex}");
                 }
             }
+            if (Convert.ToDouble(currentVersion) < 2.0d)//升级DB版本 
+            {
+                try
+                { //以下更新数据库版本号时升级具体内容
+                    Logger.WriteLineInfo($"mongoDB is upgrading from 1.9 to 2.0, please wait.");
+
+                    await DeleteUserFeatureForResearchProjectDBAsync();
+                    //更新版本
+                    var isSuccess = await UpgradeToV11.DoUpgradeAsync();
+                    if (isSuccess)
+                    {
+                        //注:下次正式线上发布需要升级DB版本号
+                        SetNewDBVersion("2.0").Wait();
+                        currentVersion = "2.0";
+                    }
+                    Logger.WriteLineInfo($"mongoDB upgrade successful, now the version is 2.0");
+                }
+                catch (Exception ex)
+                {
+                    Logger.WriteLineInfo($"mongoDB upgrade failed, now the version is 2.0, error:{ex}");
+                }
+            }
+
         }
         /// <summary>
         /// 获取当前DB版本

+ 27 - 0
src/Service/UserDBService.cs

@@ -5421,5 +5421,32 @@ namespace WingMongoDBModule.Service
             }
         }
         #endregion 
+
+        /// <summary>
+        /// 删除科研版权限
+        /// </summary>
+        /// <returns>是否成功</returns>
+        private async Task<bool> DeleteUserFeatureForResearchProjectDBAsync()
+        {
+            using (new Performance(_performanceThreshold, "{0} DeleteUserFeatureForResearchProjectDBAsync execute", $"{this.GetType().Name}"))
+            {
+                var res = await _userFeatureDBRepository.DeleteOneAsync("Code", "URMAuthority");
+                //科研版,清理默认角色的所有权限
+                if (_isResearchEditionService)
+                {
+                    var userRoleDO = await _roleDBRepository.FindOneAsync("Code", "Role_GeneralUser");
+                    if (!string.IsNullOrEmpty(userRoleDO?.Code) && !string.IsNullOrEmpty(userRoleDO?.UserGroupCode))
+                    {
+                        var groupInfo = await _userAuthorityGroupDBRepository.FindOneAsync("Code", userRoleDO.UserGroupCode);
+                        if (!string.IsNullOrEmpty(groupInfo?.Code))
+                        {
+                            groupInfo.Features = new List<string>();
+                            res = await _userAuthorityGroupDBRepository.UpdateOneAsync("Code", groupInfo.Code, groupInfo, "", true);
+                        }
+                    }
+                }
+                return res;
+            }
+        }
     }
 }