CrazyIter_Bin 3 年之前
父節點
當前提交
ee161994f1

+ 2 - 0
TEAMModelOS.SDK/Models/Cosmos/Teacher/Teacher.cs

@@ -44,6 +44,7 @@ namespace TEAMModelOS.SDK.Models
 
             public string userid { get; set; }
             public string username { get; set; }
+            public string account { get; set; }
             // public HashSet<string> pxid { get; set; } = new HashSet<string>();
             public List<string> data { get; set; }= new List<string>();
         }
@@ -73,6 +74,7 @@ namespace TEAMModelOS.SDK.Models
             public string pxid { get; set; }
             public string userid { get; set; }
             public string username { get; set; }
+            public string account { get; set; }
         }
 
 

+ 99 - 7
TEAMModelOS/Controllers/Third/ScController.cs

@@ -202,12 +202,13 @@ namespace TEAMModelOS.Controllers.Third
                             var bind = teacher.binds.Find(x => x.userid.Equals($"{scsso.tid}"));
                             if (bind == null)
                             {
-                                teacher.binds = new List<Teacher.ThirdBind> { new Teacher.ThirdBind { data = new List<string> { scsso.data }, userid = $"{scsso.tid}",username=scsso.username, type = type } };
+                                teacher.binds = new List<Teacher.ThirdBind> { new Teacher.ThirdBind { data = new List<string> { scsso.data }, userid = $"{scsso.tid}",account=scsso.account,username=scsso.username, type = type } };
                                 await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
                             }
                             else
                             {
                                 bind.username=scsso.username;
+                                bind.account=scsso.account;
                                 var bindData = scsso.data.ToObject<ScBindData>();
                                 bool isnew = true;
                                 for (int index = 0; index < bind.data.Count; index++)
@@ -226,6 +227,51 @@ namespace TEAMModelOS.Controllers.Third
                                 if (bindData != null) {
                                     bindData.userid = scsso.tid;
                                     bindData.username=scsso.username;
+                                    bindData.account = scsso.account;
+                                }
+                                if (teacher.schools.IsNotEmpty())
+                                {
+                                    foreach (var school in teacher.schools)
+                                    {
+                                        if (!string.IsNullOrEmpty(school.schoolId))
+                                        {
+                                            StringBuilder queryText = new StringBuilder($"SELECT distinct value(c) FROM c where c.type='yxtrain'");
+                                            List<GroupList> yxtrain = new List<GroupList>();
+                                            await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<GroupList>(queryText: queryText.ToString(),
+                                            requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList-{school.schoolId}") }))
+                                            {
+                                                yxtrain.Add(item);
+                                            }
+                                            if (yxtrain.IsNotEmpty())
+                                            {
+                                                var meber = yxtrain.SelectMany(x => x.members).Where(y => y.id.Equals(teacher.id));
+                                                //不在研修名单
+                                                if (meber == null || meber.Count() <= 0)
+                                                {
+                                                    yxtrain[0].members.Add(new Member { id = teacher.id, type = 1 });
+                                                    await GroupListService.UpsertList(yxtrain[0], _azureCosmos, _configuration, _serviceBus);
+                                                }
+                                            }
+                                            else
+                                            {
+                                                GroupList groupList = new GroupList()
+                                                {
+                                                    id = Guid.NewGuid().ToString(),
+                                                    code = $"GroupList-{school.schoolId}",
+                                                    creatorId = teacher.id,
+                                                    type = "yxtrain",
+                                                    year = DateTimeOffset.UtcNow.Year,
+                                                    members = new List<Member> { new Member { id = teacher.id, type = 1 } },
+                                                    scope = "school",
+                                                    school = school.schoolId,
+                                                    name = "研修名单",
+                                                    pk = "GroupList",
+                                                    ttl = -1
+                                                };
+                                                await GroupListService.UpsertList(groupList, _azureCosmos, _configuration, _serviceBus);
+                                            }
+                                        }
+                                    }
                                 }
                                 await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
                                 await _azureStorage.UploadFileByContainer("teammodelos", bindData.ToJsonString(), $"yxpt/{scsso.path}/scbind", $"{teacher.id}.json");
@@ -250,7 +296,7 @@ namespace TEAMModelOS.Controllers.Third
                     teacher = new Teacher
                     {
                         id = id,
-                        pk = "Base",
+                        pk = "Teacher",
                         code = "Base",
                         name = name?.ToString(),
                         picture = picture?.ToString(),
@@ -269,6 +315,7 @@ namespace TEAMModelOS.Controllers.Third
                     {
                         bindData.userid = scsso.tid;
                         bindData.username = scsso.username;
+                        bindData.account = scsso.account;
                         await _azureStorage.UploadFileByContainer("teammodelos", bindData.ToJsonString(), $"yxpt/{scsso.path}/scbind", $"{teacher.id}.json");
                     }
                     else {
@@ -354,7 +401,7 @@ namespace TEAMModelOS.Controllers.Third
                 }
                 string accessConfig = setting.accessConfig;
                 Dictionary<string, object> dict = new Dictionary<string, object> { { "accessConfig", accessConfig }, { "pxid", scsso.Pxid }, { "tid", scsso.tid } };
-                string SchoolName = "", SchoolID = "", ProjectID = "", ProjectItemID = "", TeacherName = "" ; 
+                string SchoolName = "", SchoolID = "", ProjectID = "", ProjectItemID = "", TeacherName = "" , Account=""; 
 
                 (int status, string json) = await _httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetSingleTeacherByProject");
                 if (status == 200)
@@ -368,6 +415,7 @@ namespace TEAMModelOS.Controllers.Third
                         ProjectID =$"{ scTeacher.ProjectID}";
                         ProjectItemID =$"{ scTeacher.ProjectItemID}";
                         TeacherName = $"{ scTeacher.TeacherName}";
+                        Account = $"{ scTeacher.Account}";
                     }
                 }
                 ScBindData bindData = new ScBindData
@@ -378,12 +426,14 @@ namespace TEAMModelOS.Controllers.Third
                     pid = ProjectItemID,
                     pxid = scsso.Pxid,
                     userid=scsso.tid,
-                    username=TeacherName
-                    
-                };
+                    username=TeacherName,
+                    account = Account
+
+            };
                 var data = bindData.ToJsonString();
                 ScSSOData sso = new ScSSOData {
                     username = TeacherName,
+                    account=Account,
                     path = path,
                     Pxid = scsso.Pxid,
                     Encrypt = scsso.Encrypt,
@@ -426,7 +476,7 @@ namespace TEAMModelOS.Controllers.Third
                     {
                         implicit_token = content.ToObject<TmdidImplicit>();
                         if (string.IsNullOrEmpty(implicit_token.id_token)) {
-                            await _dingDing.SendBotMsg($"OS,隐式登录获得信息空:{_option.Location}-\n{scsso.ToJsonString()} \npath:{path}\n{content}", GroupNames.成都开发測試群組);
+                            await _dingDing.SendBotMsg($"OS,隐式登录获得信息空:{_option.Location}-\n{scsso.ToJsonString()} \npath:{path}\n{content}", GroupNames.成都开发測試群組);
                             return Redirect(rurl.Append($"?status=1").ToString());
                         }
                         var bind = teacher.binds.Find(x => x.userid.Equals(sso.tid));
@@ -447,6 +497,47 @@ namespace TEAMModelOS.Controllers.Third
                                 bind.data.Add(bindData.ToJsonString());
                             }
                             bind.username = TeacherName;
+                            bind.account = Account;
+                            if (teacher.schools.IsNotEmpty()) {
+                                foreach (var school in teacher.schools) {
+                                    if (!string.IsNullOrEmpty(school.schoolId)) {
+                                        StringBuilder queryText = new StringBuilder($"SELECT distinct value(c) FROM c where c.type='yxtrain'");
+                                        List<GroupList> yxtrain = new List<GroupList>();
+                                        await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<GroupList>(queryText: queryText.ToString(),
+                                        requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList-{school.schoolId}") }))
+                                        {
+                                            yxtrain.Add(item);
+                                        }
+                                        if (yxtrain.IsNotEmpty())
+                                        {
+                                            var meber= yxtrain.SelectMany(x=>x.members).Where(y => y.id.Equals(teacher.id));
+                                            //不在研修名单
+                                            if ( meber== null || meber.Count() <= 0) {
+                                                yxtrain[0].members.Add(new Member { id = teacher.id, type = 1 });
+                                                await GroupListService.UpsertList(yxtrain[0], _azureCosmos, _configuration, _serviceBus);
+                                            }
+                                        }
+                                        else
+                                        {
+                                            GroupList groupList = new GroupList()
+                                            {
+                                                id = Guid.NewGuid().ToString(),
+                                                code = $"GroupList-{school.schoolId}",
+                                                creatorId = teacher.id,
+                                                type = "yxtrain",
+                                                year = DateTimeOffset.UtcNow.Year,
+                                                members = new List<Member> { new Member { id = teacher.id, type = 1 } },
+                                                scope = "school",
+                                                school = school.schoolId,
+                                                name = "研修名单",
+                                                pk = "GroupList",
+                                                ttl = -1
+                                            };
+                                            await  GroupListService.UpsertList(groupList, _azureCosmos, _configuration, _serviceBus);
+                                        }
+                                    }
+                                }
+                            }
                             await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
                         }
                         await _azureStorage.UploadFileByContainer("teammodelos", bindData.ToJsonString(), $"yxpt/{sso.path}/scbind", $"{teacher.id}.json");
@@ -1046,6 +1137,7 @@ namespace TEAMModelOS.Controllers.Third
             public string Encrypt { get; set; }
             public string data { get; set; }
             public string username { get; set; }
+            public string account { get; set; }
         }
         public record SSO
         {

+ 199 - 1
TEAMModelOS/Controllers/XTest/FixDataController.cs

@@ -25,6 +25,9 @@ using Azure.Storage.Blobs.Models;
 using Azure.Storage.Blobs;
 using System.Security.Cryptography;
 using Azure;
+using Microsoft.Extensions.Options;
+using Microsoft.Extensions.Configuration;
+using TEAMModelOS.Models;
 
 namespace TEAMModelOS.Controllers
 {
@@ -32,16 +35,211 @@ namespace TEAMModelOS.Controllers
     [ApiController]
     public class FixDataController : ControllerBase
     {
+        private readonly IConfiguration _configuration;
         private readonly AzureStorageFactory _azureStorage;
         private readonly AzureRedisFactory _azureRedis;
         private readonly AzureCosmosFactory _azureCosmos;
         private readonly DingDing _dingDing;
-        public FixDataController(AzureCosmosFactory azureCosmos, AzureRedisFactory azureRedis, AzureStorageFactory azureStorage, DingDing dingDing)
+        private readonly Option _option;
+        public FixDataController(AzureCosmosFactory azureCosmos, AzureRedisFactory azureRedis, AzureStorageFactory azureStorage, DingDing dingDing, IOptionsSnapshot<Option> option, IConfiguration configuration)
         {
             _azureCosmos = azureCosmos;
             _azureRedis = azureRedis;
             _azureStorage = azureStorage;
             _dingDing = dingDing;
+            _option = option?.Value;
+            _configuration = configuration;
+        }
+
+        /// <summary>
+        /// 测试blob多线程写入同一个文件
+        /// </summary>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("fix-joinschool")]
+        public async Task<IActionResult> GenerateSchoolCodes(JsonElement json)
+        {
+            JsonElement _teachers =json.GetProperty("teachers");
+            
+            List<JoinSchool> joins= _teachers.ToObject<List<JoinSchool>>();
+            string url = _configuration.GetValue<string>("HaBookAuth:CoreId:userinfo");
+            HttpClient client = new HttpClient();
+            var tmdids= joins.Select(x => x.tmdid).ToList();
+            var content = new StringContent(tmdids.ToJsonString(), Encoding.UTF8, "application/json");
+            HttpResponseMessage responseMessage = await client.PostAsync(url, content);
+            List<Teacher> ids = null;
+            if (responseMessage.StatusCode == HttpStatusCode.OK)
+            {
+                string responseBody = responseMessage.Content.ReadAsStringAsync().Result;
+                ids= responseBody.ToObject<List<Teacher>>();
+            }
+            if (ids.IsNotEmpty()) {
+                var school = joins.Select(x => x.schoolId);
+                HashSet<string> scho= new HashSet<string>(school);
+                string sql = $"select value(c) from c where c.id in ({string.Join(",", scho.Select(x => $"'{x}'"))})";
+                List<School> schools = new List<School>();
+                await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").
+                    GetItemQueryIterator<School>(sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Base") }))
+                {
+                    schools.Add(item);
+                }
+                var noexist =  tmdids.Except( ids.Select(x=>x.id));
+                  sql = $"select value(c) from c where c.id in ({string.Join(",", ids.Select(x => $"'{x.id}'"))})";
+                List<Teacher> teachers = new List<Teacher>();
+                List<Teacher> updTeachers = new List<Teacher>();
+                await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").
+                    GetItemQueryIterator<Teacher>(sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Base") }))
+                {
+                    teachers.Add(item);
+                }
+                long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                var nobinds = ids.Select(x => x.id).Except(teachers.Select(t => t.id)).ToList();
+                foreach (var tch in teachers) {
+                    var join =  joins.Find(x => x.tmdid.Equals(tch.id));
+                    if (join != null) {
+                        var joinschool= tch.schools.Find(x => x.schoolId.Equals(join.schoolId));
+                     
+                        if (joinschool == null) {
+                            var schoolInfo= schools.Find(x => x.id.Equals(join.schoolId));
+                            if (schoolInfo != null) {
+                                tch.defaultSchool = join.schoolId;
+                                tch.schools.Add(new Teacher.TeacherSchool { schoolId = join.schoolId, areaId = schoolInfo.areaId, name = schoolInfo?.name, picture = schoolInfo?.picture, status = "join", time = now });
+
+                                SchoolTeacher schoolTeacher = null;
+                                List<string> roles = new List<string> { "teacher" };
+                                if (!string.IsNullOrEmpty(join.role) && join.role.Equals("admin"))
+                                {
+                                    roles.Add("admin");
+                                }
+                                try
+                                {
+                                    schoolTeacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<SchoolTeacher>(tch.id, new PartitionKey($"Teacher-{join.schoolId}"));
+                                    if (roles.Contains("admin") && !schoolTeacher.roles.Contains("admin"))
+                                    {
+                                        schoolTeacher.roles.Add("admin");
+                                    }
+                                    if (roles.Contains("teacher") && !schoolTeacher.roles.Contains("teacher"))
+                                    {
+                                        schoolTeacher.roles.Add("teacher");
+                                    }
+                                }
+                                catch (CosmosException)
+                                {
+                                    schoolTeacher = new SchoolTeacher
+                                    {
+                                        id = tch.id,
+                                        name = tch.name,
+                                        picture = tch.picture,
+                                        code = $"Teacher-{schoolInfo.id}",
+                                        pk = "SchoolTeacher",
+                                        ttl = -1,
+                                        size = 0,
+                                        roles = roles,
+                                        status = "join",
+                                        createTime = now,
+                                    };
+
+                                }
+                                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").UpsertItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey(schoolTeacher.code));
+                                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(tch, tch.id, new PartitionKey("Base"));
+                                updTeachers.Add(tch);
+                            }
+                        }
+                        
+                    }
+                }
+                List<Teacher> addTeachers = new List<Teacher>();
+                if (nobinds != null) {
+                    foreach (var tch in nobinds)
+                    {
+                        var teacher = ids.Find(x => x.id.Equals(tch));
+                        var join = joins.Find(x => x.tmdid.Equals(tch));
+                        var schoolInfo = schools.Find(x => x.id.Equals(join.schoolId));
+                        if (schoolInfo!=null && teacher != null)
+                        {
+                            teacher.ttl = -1;
+                            teacher.pk = "Teacher";
+                            teacher.code = "Base";
+                            teacher.size = 2;
+                            teacher.schools = new List<Teacher.TeacherSchool> { new Teacher.TeacherSchool { schoolId = join.schoolId, areaId = schoolInfo.areaId, name = schoolInfo?.name, picture = schoolInfo?.picture, status = "join", time = now } };
+                            teacher.defaultSchool = schoolInfo?.id;
+                            List<string> roles = new List<string> { "teacher" };
+                            if (!string.IsNullOrEmpty(join.role) && join.role.Equals("admin"))
+                            {
+                                roles.Add("admin");
+                            }
+                            var container = _azureStorage.GetBlobContainerClient(teacher.id);
+                            await container.CreateIfNotExistsAsync(PublicAccessType.None); //嘗試創建Teacher私有容器,如存在則不做任何事,保障容器一定存在
+                            teacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
+                            addTeachers.Add(teacher);
+                            SchoolTeacher schoolTeacher = new SchoolTeacher
+                            {
+                                id = teacher.id,
+                                name = teacher.name,
+                                picture = teacher.picture,
+                                code = $"Teacher-{schoolInfo?.id}",
+                                pk = "SchoolTeacher",
+                                ttl = -1,
+                                size = 0,
+                                roles = roles,
+                                status = "join",
+                                createTime = now,
+                            };
+                            await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").UpsertItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey(schoolTeacher.code));
+                        }
+                    }
+                }
+
+                //foreach (var sch in schools) {
+                //    StringBuilder queryText = new StringBuilder($"SELECT distinct value(c) FROM c where c.type='yxtrain'");
+                //    List<GroupList> yxtrain = new List<GroupList>();
+                //    await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<GroupList>(queryText: queryText.ToString(),
+                //    requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList-{sch.id}") }))
+                //    {
+                //        yxtrain.Add(item);
+                //    }
+                //    if (yxtrain.IsNotEmpty())
+                //    {
+                //        var meber = yxtrain.SelectMany(x => x.members).Where(y => y.id.Equals(teacher.id));
+                //        //不在研修名单
+                //        if (meber == null || meber.Count() <= 0)
+                //        {
+                //            yxtrain[0].members.Add(new Member { id = teacher.id, type = 1 });
+                //            await GroupListService.UpsertList(yxtrain[0], _azureCosmos, _configuration, _serviceBus);
+                //        }
+                //    }
+                //    else
+                //    {
+                //        var schjoin =  joins.FindAll(x => x.schoolId.Equals(sch.id));
+                //        schjoin.r
+                //        GroupList groupList = new GroupList()
+                //        {
+                //            id = Guid.NewGuid().ToString(),
+                //            code = $"GroupList-{sch.id}",
+                //            creatorId = teacher.id,
+                //            type = "yxtrain",
+                //            year = DateTimeOffset.UtcNow.Year,
+                //            members = new List<Member> { new Member { id = teacher.id, type = 1 } },
+                //            scope = "school",
+                //            school = sch.id,
+                //            name = "研修名单",
+                //            pk = "GroupList",
+                //            ttl = -1
+                //        };
+                //        await GroupListService.UpsertList(groupList, _azureCosmos, _configuration, _serviceBus);
+                //    }
+                //}
+                return Ok(new { noexist ,update= updTeachers,add= addTeachers });
+            }
+            return Ok(new { status=404 });
+        }
+        public class JoinSchool{
+            public string name { get; set; }
+            public string schoolId { get; set; }
+            public string mobile { get; set; }
+            public string tmdid { get; set; }
+            public string role { get; set; }
+
         }
         [ProducesDefaultResponseType]
         [HttpPost("fix-md5-duration")]

+ 2 - 523
TEAMModelOS/Controllers/XTest/TestController.cs

@@ -53,227 +53,7 @@ namespace TEAMModelOS.Controllers
             _environment = environment;
             _httpClient= httpClient;
         }
-
-        public static List<string> comeRemoveStr = new List<string>() { "省", "市", "区", "州", "县", "旗", "盟", "自治" };
-        public static List<string> prvcRemoveStr = new List<string>() { "回族", "维吾尔", "壮族", };
-        public static List<string> cityRemoveStr = new List<string>() { "蒙古族", "地区", "壮族", "朝鲜族", "直辖" };
-        public static List<string> nationRemoveStr = new List<string> {
-            "维吾尔","回族", "自治", "满族", "蒙古", "壮族", "苗族" , "侗族", "瑶族",
-            "达斡尔","鄂温克","朝鲜","畲族","土家","各族","仫佬","毛南","羌族","彝族","仡佬","布依","水族",
-            "傣族","纳西","哈尼","拉祜","佤族","傈僳","独龙","怒族","白族","普米","固族","哈萨克","土族","撒拉","景颇","族"
-        };
-        public static List<string> schemoveStr = new List<string> { "第", "校区", "部", "楼", "与", "学校", "校园", };
-        public static List<string> schooRemoveStr = new List<string>() {"省", "市",  "区", "州", "县", "旗", "盟","办事处","街道", "自治",
-           "镇","村","乡","街","路","站","馆"
-        };
-        public static List<string> afterSchoolRm = new List<string>() {"校","园","院", "湾","峡","沟","山","庄",
-            "堡","江","屯","岭","溪","河","桥","营","铺","坡","寨","场","湖","巷","集","关","庙","寺","矿","塘"};
-        public static List<KeyValuePair<string, string>> areaRemoveStr = new List<KeyValuePair<string, string>>{
-            new KeyValuePair<string, string>("高新技术产业开发区", "高") ,
-             new KeyValuePair<string, string>("经济技术开发区", "经") ,
-            new KeyValuePair<string, string>("国际", "际") ,
-            new KeyValuePair<string, string>("中国", ""),
-            new KeyValuePair<string, string>("国家", ""),
-            new KeyValuePair<string, string>("新区", ""),
-            new KeyValuePair<string, string>("高新", "高"),
-            new KeyValuePair<string, string>("园区", ""),
-            new KeyValuePair<string, string>("产业", "产"),
-            new KeyValuePair<string, string>("经济", "经"),
-            new KeyValuePair<string, string>("开发", "开"),
-            new KeyValuePair<string, string>("中心", "") ,
-            new KeyValuePair<string, string>("集团", "") ,
-            new KeyValuePair<string, string>("公司", "") ,
-            new KeyValuePair<string, string>("有限", "") ,
-            new KeyValuePair<string, string>("股份", "") ,
-            new KeyValuePair<string, string>("服务", "") ,
-            new KeyValuePair<string, string>("基地", "") ,
-            new KeyValuePair<string, string>("社区", "社") ,
-            new KeyValuePair<string, string>("职工", "") ,
-            new KeyValuePair<string, string>("专修", ""),
-            new KeyValuePair<string, string>("实验", "验"),
-            new KeyValuePair<string, string>("完全", ""),
-            new KeyValuePair<string, string>("一贯制", "") ,
-            new KeyValuePair<string, string>("联办", ""),
-            new KeyValuePair<string, string>("联合", ""),
-            new KeyValuePair<string, string>("完小", "小"),
-            new KeyValuePair<string, string>("义务", ""),
-            new KeyValuePair<string, string>("基础", ""),
-            new KeyValuePair<string, string>("制造", "")
-        };
-        public static List<KeyValuePair<string, string>> schooReplaceStr = new List<KeyValuePair<string, string>> {
-            new KeyValuePair<string, string>("分校", "分") ,
-            new KeyValuePair<string, string>("分园", "分") ,
-            new KeyValuePair<string, string>("分院", "分") ,
-            new KeyValuePair<string, string>("藏文", "藏"),
-            new KeyValuePair<string, string>("职业技术学院", "职") ,
-            new KeyValuePair<string, string>("创新创业", "创") ,
-            new KeyValuePair<string, string>("就业创业", "就") ,
-            new KeyValuePair<string, string>("应用核技术", "核") ,
-            new KeyValuePair<string, string>("职业学院", "职") ,
-            new KeyValuePair<string, string>("幼儿园", "幼") ,
-            new KeyValuePair<string, string>("幼儿", "幼") ,
-            new KeyValuePair<string, string>("小学", "小") ,
-            new KeyValuePair<string, string>("中学", "中") ,
-            new KeyValuePair<string, string>("中等", "中") ,
-            new KeyValuePair<string, string>("双语", "双") ,
-            new KeyValuePair<string, string>("初中", "初") ,
-            new KeyValuePair<string, string>("初级", "初") ,
-            new KeyValuePair<string, string>("广播", "广"),
-            new KeyValuePair<string, string>("高中", "高") ,
-            new KeyValuePair<string, string>("高级", "高") ,
-            new KeyValuePair<string, string>("大学", "大") ,
-            new KeyValuePair<string, string>("学院", "院") ,
-            new KeyValuePair<string, string>("综合", "综") ,
-            new KeyValuePair<string, string>("职业", "职") ,
-            new KeyValuePair<string, string>("技术", "技") ,
-            new KeyValuePair<string, string>("专科", "专") ,
-            new KeyValuePair<string, string>("外国语", "外") ,
-           
-            new KeyValuePair<string, string>("九年", "九") ,
-            new KeyValuePair<string, string>("五年", "五") ,
-            new KeyValuePair<string, string>("年制", "制") ,
-            new KeyValuePair<string, string>("高等", "高") ,
-    
-            new KeyValuePair<string, string>("院校", "院") ,
-            new KeyValuePair<string, string>("初等", "小") ,
-            new KeyValuePair<string, string>("附属", "附"),
-            new KeyValuePair<string, string>("寄宿制", "寄") ,
-            new KeyValuePair<string, string>("寄宿", "寄") ,
-            new KeyValuePair<string, string>("卫生", "卫") ,
-            new KeyValuePair<string, string>("创业", "创") ,
-            new KeyValuePair<string, string>("继续", "继") ,
-            new KeyValuePair<string, string>("开放", "开") ,
-            new KeyValuePair<string, string>("技师", "技") ,
-            new KeyValuePair<string, string>("成人", "成") ,
-            new KeyValuePair<string, string>("教育", "教") ,
-            new KeyValuePair<string, string>("科技", "科") ,
-            new KeyValuePair<string, string>("行政", "政") ,
-            new KeyValuePair<string, string>("生物", "生") ,
-            new KeyValuePair<string, string>("美术", "美") ,
-            new KeyValuePair<string, string>("设计", "设") ,
-            new KeyValuePair<string, string>("传播", "传") ,
-            new KeyValuePair<string, string>("计算机", "算") ,
-            new KeyValuePair<string, string>("土木", "土") ,
-            new KeyValuePair<string, string>("石油", "油") ,
-            new KeyValuePair<string, string>("科普", "普") ,
-            new KeyValuePair<string, string>("电信", "信") ,
-            new KeyValuePair<string, string>("联合", "联") ,
-            new KeyValuePair<string, string>("电商", "商") ,
-            new KeyValuePair<string, string>("纺织", "织") ,
-            new KeyValuePair<string, string>("服装", "服") ,
-            new KeyValuePair<string, string>("新闻", "新") ,
-            new KeyValuePair<string, string>("网络", "网") ,
-            new KeyValuePair<string, string>("应用", "应") ,
-            new KeyValuePair<string, string>("畜牧", "畜") ,
-            new KeyValuePair<string, string>("兽医", "兽") ,
-            new KeyValuePair<string, string>("师范", "师") ,
-            new KeyValuePair<string, string>("人文", "文") ,
-            new KeyValuePair<string, string>("创新", "创") ,
-            new KeyValuePair<string, string>("法官", "法") ,
-            new KeyValuePair<string, string>("邮电", "邮") ,
-            new KeyValuePair<string, string>("文化", "文") ,
-            new KeyValuePair<string, string>("函授", "函") ,
-            new KeyValuePair<string, string>("科学", "科") ,
-            new KeyValuePair<string, string>("信息", "息") ,
-            new KeyValuePair<string, string>("水利", "利") ,
-            new KeyValuePair<string, string>("水电", "电") ,
-            new KeyValuePair<string, string>("电力", "力") ,
-            new KeyValuePair<string, string>("环境", "环") ,
-            new KeyValuePair<string, string>("建材", "材") ,
-            new KeyValuePair<string, string>("机电", "机") ,
-            new KeyValuePair<string, string>("航空", "空") ,
-            new KeyValuePair<string, string>("航天", "天") ,
-            new KeyValuePair<string, string>("警察", "警") ,
-            new KeyValuePair<string, string>("警官", "警") ,
-            new KeyValuePair<string, string>("财贸", "财") ,
-            new KeyValuePair<string, string>("电子", "电") ,
-            new KeyValuePair<string, string>("建筑", "筑") ,
-            new KeyValuePair<string, string>("艺术", "艺") ,
-            new KeyValuePair<string, string>("体育", "体") ,
-            new KeyValuePair<string, string>("城市", "城") ,
-            new KeyValuePair<string, string>("地质", "地") ,
-            new KeyValuePair<string, string>("医药", "药") ,
-            new KeyValuePair<string, string>("政法", "法") ,
-            new KeyValuePair<string, string>("铁路", "铁") ,
-            new KeyValuePair<string, string>("铁道", "道") ,
-            new KeyValuePair<string, string>("轨道", "轨") ,
-            new KeyValuePair<string, string>("交通", "通") ,
-            new KeyValuePair<string, string>("医学院", "医") ,
-            new KeyValuePair<string, string>("医学", "医") ,
-            new KeyValuePair<string, string>("传媒", "媒") ,
-            new KeyValuePair<string, string>("工程", "程") ,
-            new KeyValuePair<string, string>("临床", "临") ,
-            new KeyValuePair<string, string>("化工", "化") ,
-            new KeyValuePair<string, string>("林业", "林") ,
-            new KeyValuePair<string, string>("老年", "老") ,
-            new KeyValuePair<string, string>("旅游", "游") ,
-            new KeyValuePair<string, string>("护理", "护") ,
-            new KeyValuePair<string, string>("贸易", "贸") ,
-            new KeyValuePair<string, string>("中医药", "中医") ,
-            new KeyValuePair<string, string>("资源", "源") ,
-            new KeyValuePair<string, string>("冶金", "冶") ,
-            new KeyValuePair<string, string>("能源", "能") ,
-            new KeyValuePair<string, string>("汽车", "车") ,
-            new KeyValuePair<string, string>("医科", "医") ,
-            new KeyValuePair<string, string>("机械", "械") ,
-            new KeyValuePair<string, string>("应用", "应") ,
-            new KeyValuePair<string, string>("电气", "电") ,
-            new KeyValuePair<string, string>("材料", "材") ,
-            new KeyValuePair<string, string>("劳动", "劳") ,
-            new KeyValuePair<string, string>("轻工", "轻") ,
-            new KeyValuePair<string, string>("农业", "农") ,
-            new KeyValuePair<string, string>("委员会", "委") ,
-             new KeyValuePair<string, string>("专业", "专") ,
-            new KeyValuePair<string, string>("广播", "广"),
-            new KeyValuePair<string, string>("电视", "电") ,
-            new KeyValuePair<string, string>("工商", "商") ,
-            new KeyValuePair<string, string>("工业", "工") ,
-            new KeyValuePair<string, string>("管理", "管") ,
-            new KeyValuePair<string, string>("社会主义", "社") ,
-            new KeyValuePair<string, string>("社会", "社") ,
-            new KeyValuePair<string, string>("自动化", "自") ,
-
-                    
-
-        };
-        public static List<KeyValuePair<string, string>> proReplaceStr = new List<KeyValuePair<string, string>> {
-            new KeyValuePair<string, string>("北京","京") ,
-            new KeyValuePair<string, string>("天津","津") ,
-            new KeyValuePair<string, string>("河北","冀") ,
-            new KeyValuePair<string, string>("山西","晋") ,
-            new KeyValuePair<string, string>("内蒙古","蒙") ,
-            new KeyValuePair<string, string>("辽宁","辽") ,
-            new KeyValuePair<string, string>("吉林","吉") ,
-            new KeyValuePair<string, string>("黑龙江","黑") ,
-            new KeyValuePair<string, string>("上海","沪") ,
-            new KeyValuePair<string, string>("江苏","苏") ,
-            new KeyValuePair<string, string>("浙江","浙") ,
-            new KeyValuePair<string, string>("安徽","皖") ,
-            new KeyValuePair<string, string>("福建","闽") ,
-            new KeyValuePair<string, string>("江西","赣") ,
-            new KeyValuePair<string, string>("山东","鲁") ,
-            new KeyValuePair<string, string>("河南","豫") ,
-            new KeyValuePair<string, string>("湖北","鄂") ,
-            new KeyValuePair<string, string>("湖南","湘") ,
-            new KeyValuePair<string, string>("广东","粤") ,
-            new KeyValuePair<string, string>("广西","桂") ,
-            new KeyValuePair<string, string>("海南","琼") ,
-            new KeyValuePair<string, string>("四川","川") ,
-            new KeyValuePair<string, string>("贵州","贵") ,
-            new KeyValuePair<string, string>("云南","云") ,
-            new KeyValuePair<string, string>("重庆","渝") ,
-            new KeyValuePair<string, string>("西藏","藏") ,
-            new KeyValuePair<string, string>("陕西","陕") ,
-            new KeyValuePair<string, string>("甘肃","甘") ,
-            new KeyValuePair<string, string>("青海","青") ,
-            new KeyValuePair<string, string>("宁夏","宁") ,
-            new KeyValuePair<string, string>("新疆","新") ,
-            new KeyValuePair<string, string>("香港","港") ,
-            new KeyValuePair<string, string>("澳门","澳") ,
-            new KeyValuePair<string, string>("台湾","台")
-        };
-        // new List<string>() {"省", "市", "校区", "区", "州", "县", "旗", "盟", "自治","小学","第","学校","中学","大学","初中","高中", "学院", "职业","技术","幼儿园","(",")", "(",")","分校","分园","附属","校园","镇","村","乡","街","路","部"
-
+         
         public class SchoolData{
             public string province { get; set; }
             public string id { get; set; }
@@ -435,308 +215,7 @@ namespace TEAMModelOS.Controllers
             dynamic data = await  SchoolService.GenerateSchoolCode(json, _dingDing, _environment);
             return Ok(data);
         }
-
-        /// <summary>
-        /// 测试blob多线程写入同一个文件
-        /// </summary>
-        /// <returns></returns>
-        [ProducesDefaultResponseType]
-        [HttpPost("generate-school-code")]
-        public async Task<IActionResult> GenerateSchoolCode(JsonElement json)
-        {
-            string path = $"{_environment.ContentRootPath}/JsonFile/Core/region.json";
-            var schools = json.GetProperty("schools").ToObject<List<SchoolData>>();
-            schools= schools.Where((x, i) => schools.FindIndex(n => n.name.Equals(x.name)) == i).ToList();
-            StreamReader streamReader = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8);
-            StringBuilder stringBuilder = new StringBuilder();
-            string text;
-            while ((text = streamReader.ReadLine()) != null)
-            {
-                stringBuilder.Append(text.ToString());
-            }
-
-            streamReader.Close();
-            string input = stringBuilder.ToString();
-            List<Region> region = input.ToObject<List<Region>>(); 
-            try
-            {
-                schools.ForEach(x =>
-                {
-                    x.province=  ChineseConverter.Convert(x.province, ChineseConversionDirection.TraditionalToSimplified);
-                    if (String.IsNullOrEmpty(x.city))
-                    {
-                        x.city = x.province;
-                    }
-                    else {
-                        x.city = ChineseConverter.Convert(x.city, ChineseConversionDirection.TraditionalToSimplified);
-                    }
-                   
-                    x.name = ChineseConverter.Convert(x.name, ChineseConversionDirection.TraditionalToSimplified);
-                    //处理英文名字的学校
-                    if (!string.IsNullOrEmpty(x.address)) {
-                        x.address = ChineseConverter.Convert(x.address, ChineseConversionDirection.TraditionalToSimplified);
-                    }
-                 
-                    comeRemoveStr.ForEach(c => { x.province = x.province.Replace(c, ""); });
-                    prvcRemoveStr.ForEach(c => { x.province = x.province.Replace(c, ""); });
-                    var province = region.Find(r => r.name.Contains(x.province));
-                    string tmpprovince = x.province;
-                    string tmpcity = x.city;
-                    if (province != null)
-                    {
-                        x.province = province.name;
-                        comeRemoveStr.ForEach(c => { x.city = x.city.Replace(c, ""); });
-                        cityRemoveStr.ForEach(c => { x.city = x.city.Replace(c, ""); });
-                        nationRemoveStr.ForEach(c => { x.city = x.city.Replace(c, ""); });
-                        tmpcity = x.city;
-                        var city = province.children.Find(r => r.name.Contains(x.city));
-
-                        if (city == null)
-                        {
-                            city = province.children.Find(r => r.name.Contains(x.city));
-                            if (city == null)
-                            {
-                                city = province.children.SelectMany(x => x.children).ToList().Find(r => r.name.Contains(x.city));
-                            }
-                        }
-                        if (city != null)
-                        {
-                            x.city = city.name;
-                        }
-                    }
-
-                    string name = x.name;
-                    //去除冗余的学校信息,只保留地名和校名关键信息
-                    schemoveStr.ForEach(str =>
-                    {
-                        name = name.Replace(str, "");
-                    });
-                    string[] names = name.Split("(");
-                    if (names.Length > 1)
-                    {
-                        name = $"{names[0]}";
-                        for (int index = 1; index< names.Length; index++) 
-                        {
-                            name = $"{name}{names[index].Substring(0, 1)}";
-                            var afnames= names[index].Split(")");
-                            if (afnames.Length > 1) {
-                                for (int i = 1; i < afnames.Length; i++) {
-                                    name = $"{name}{afnames[i]}";
-                                }
-                            }
-                        }
-                    }
-                    names = name.Split("(");
-                    if (names.Length > 1)
-                    {
-                        name = $"{names[0]}";
-                        for (int index = 1; index  < names.Length; index++)
-                        {
-                            name = $"{name}{names[index].Substring(0, 1)}";
-                            var afnames = names[index].Split(")");
-                            if (afnames.Length > 1)
-                            {
-                                for (int i = 1; i < afnames.Length; i++)
-                                {
-                                    name = $"{name}{afnames[i]}";
-                                }
-                            }
-                        }
-                    }
-                    name = Regex.Replace(name, "[ \\[ \\] \\^ \\-|()【】/' {}_*×――(^)$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", " ");
-                    //检查是否有英文
-                    if (Regex.Matches(name, "[a-zA-Z]").Count > 0)
-                    {
-                        var array = Regex.Split(name, "\\s+", RegexOptions.IgnoreCase);
-                        StringBuilder tmpname = new StringBuilder();
-                        if (array.Length > 1)
-                        {
-                            foreach (var item in array)
-                            {
-                                var arr = item.Select(x => $"{x}");
-                                int index = 0;
-                                foreach (var stra in arr)
-                                {
-                                    if (Regex.Matches(stra, "[a-zA-Z]").Count > 0)
-                                    {
-                                        if (index == 0)
-                                        {
-                                            tmpname.Append(stra);
-                                        }
-                                        else
-                                        {
-
-                                        }
-                                    }
-                                    else
-                                    {
-                                        tmpname.Append(stra);
-                                    }
-                                    index++;
-                                }
-                            }
-                        }
-                        else
-                        {
-                            var arr = name.Select(x => $"{x}");
-                            int index = 0;
-                            foreach (var stra in arr)
-                            {
-                                if (Regex.Matches(stra, "[A-Z]").Count > 0)
-                                {
-                                    tmpname.Append(stra);
-                                }
-                                else if (Regex.Matches(stra, "[a-z]").Count > 0)
-                                {
-                                }
-                                else
-                                {
-                                    tmpname.Append(stra);
-                                }
-                                index++;
-                            }
-
-                        }
-                        name = tmpname.ToString();
-                    }
-                    name = Regex.Replace(name, @"\s", "");
-                    name = name.Replace("\\", "");
-                    if (name.Length > 6)
-                    {
-                        //新区,高新,产业等非新政单位
-                        areaRemoveStr.ForEach(str =>
-                        {
-                            name = name.Replace(str.Key, str.Value);
-                        });
-                        //去除冗余的学校信息,只保留地名和校名关键信息
-                        schooRemoveStr.ForEach(str =>
-                        {
-                            name = name.Replace(str, "");
-                        });
-                       
-                        //替换民族信息词
-                        if (name.Length > 6)
-                        {
-                            nationRemoveStr.ForEach(str =>
-                            {
-                                name = name.Replace(str, "");
-                            });
-                        }
-                        //替换学校信息的副词
-                        if (name.Length > 6)
-                        {
-                            foreach (var str in schooReplaceStr) {
-                                if (name.Length <= 6)
-                                {
-                                    break;
-                                }
-                                name = name.Replace(str.Key, str.Value);
-                                
-                            }
-                        }
-                        //替换省简称信息词
-                        string tmpname = name;
-                        if (name.Length > 6)
-                        {
-                            proReplaceStr.ForEach(str =>
-                            {
-                                name = name.Replace(str.Key, str.Value);
-                            });
-                            //如果替换后仍然大于6位,则取消,直接替换省份完整的词
-                            if (name.Length > 6)
-                            {
-                                name = tmpname.Replace(tmpprovince, "");
-                            }
-                        }
-                        //替换城市信息词
-                        if (name.Length > 6)
-                        {
-                            name = name.Replace(tmpcity, "");
-                        }
-
-                    }
-                    int len = name.Length;
-                    if (len > 6) {
-                        foreach (var str in afterSchoolRm)
-                        {
-                            if (name.Length <= 6)
-                            {
-                                break;
-                            }
-                            name = name.Replace(str, "");
-                        }
-                    }
-
-                    len = name.Length;
-                    if (len >= 6)
-                    {
-                        name = $"{name.Substring(0, 1)}{name.Substring(len-5, 3)}{name.Substring(len - 2, 2)}";
-                    }
-                    //if (len <= 7 && len > 6)
-                    //{
-                    //    name = name.Substring(len - 6);
-                    //}
-                    if (len <= 4)
-                    {
-                        name = $"{x.city.Substring(0, 2)}{name}";
-                    }
-                    if (len == 5)
-                    {
-                        name = $"{x.city.Substring(0, 1)}{name}";
-                    }
-                    string code = PingYinHelper.GetFirstSpell(name);
-                    x.address = name;
-                    x.id = code;
-                    
-                });
-            }
-            catch (Exception ex)
-            {
-                await _dingDing.SendBotMsg($"{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
-            }
-            string a_z = "abcdefghijklmnopqrstuvwxyz";
-            var data= schools.GroupBy(x=>x.id).Select(x=>new {key= x.Key,more=x.ToList().Count>2, count = x.ToList().Count, list= x.ToList()}).ToList();
-            data.ForEach(x =>
-            {
-                if (x.count > 1)
-                {
-                    var first = x.list.First();
-                    var same = x.list.Skip(1).Take(x.count - 1).ToList();
-                    var fs = first.name.Select(x => x).ToArray();
-                    same.ForEach(z =>
-                    {
-                        var sp = z.name.Select(x => x).ToArray();
-                        int len = sp.Length;
-                        if (sp.Length >= fs.Length)
-                        {
-                            len = fs.Count();
-                        }
-                        for (int index = 0; index < len; index++)
-                        {
-                            if (!$"{sp[index]}".Equals($"{fs[index]}"))
-                            {
-                                short st = ChineseChar.GetStrokeNumber(sp[index]);
-                                if (st > 0)
-                                {
-                                    var ins = st % 27;
-                                    var insch = a_z[ins];
-                                    if (z.name.EndsWith($"{insch}"))
-                                    {
-                                        ins = (st + 1) % 27;
-                                        insch = a_z[ins];
-                                    }
-                                    z.id = $"{z.id.Substring(0, z.id.Length - 1)}{insch}";
-                                    break;
-                                }
-                            }
-                        }
-                    });
-                }
-            });
-            var rdata = data.Where(x => x.count > 1);
-            return Ok(rdata);
-        }
-      
+         
         /// <summary>
         /// 测试blob多线程写入同一个文件
         /// </summary>

+ 3 - 3
TEAMModelOS/TEAMModelOS.csproj

@@ -40,9 +40,9 @@
     <SpaRoot>ClientApp\</SpaRoot>
     <DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
     <UserSecretsId>078b5d89-7d90-4f6a-88fc-7d96025990a8</UserSecretsId>
-    <Version>5.2112.9</Version>
-    <AssemblyVersion>5.2112.9.1</AssemblyVersion>
-    <FileVersion>5.2112.9.1</FileVersion>
+    <Version>5.2112.13</Version>
+    <AssemblyVersion>5.2112.13.2</AssemblyVersion>
+    <FileVersion>5.2112.13.2</FileVersion>
     <Description>TEAMModelOS(IES5)版本更新。</Description>
     <PackageReleaseNotes>版本说明</PackageReleaseNotes>
   </PropertyGroup>