ThirdService.cs 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using Azure.Cosmos;
  2. using HTEXLib.COMM.Helpers;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Text.Json;
  8. using System.Threading.Tasks;
  9. using TEAMModelOS.SDK.DI;
  10. using TEAMModelOS.SDK.Extension;
  11. using static TEAMModelOS.SDK.Models.Teacher;
  12. namespace TEAMModelOS.SDK.Models
  13. {
  14. public static class ThirdService
  15. {
  16. public static async Task<(string accessConfig, Area area, AreaSetting setting)> GetAccessConfig(CosmosClient client,string standard) {
  17. Area area = null;
  18. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Normal").
  19. GetItemQueryIterator<Area>($"select value(c) from c where c.standard='{standard}'", requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base-Area") }))
  20. {
  21. area = item;
  22. break;
  23. }
  24. AreaSetting setting = null;
  25. if (area != null)
  26. {
  27. try
  28. {
  29. setting = await client.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<AreaSetting>(area.id, new PartitionKey("AreaSetting"));
  30. }
  31. catch (CosmosException)
  32. {
  33. setting = null;
  34. }
  35. }
  36. if (setting == null|| string.IsNullOrEmpty(setting.accessConfig))
  37. {
  38. return (null,null,null);
  39. }
  40. else {
  41. return (setting.accessConfig,area,setting);
  42. }
  43. }
  44. public static async Task<List<Ability>> GetDiagnosisList(CosmosClient client, string standard,DingDing dingDing, AreaSetting setting, HttpTrigger httpTrigger, Teacher teacher, TEAMModelOS.Models.Option _option) {
  45. List<string> abilityNos = new List<string>() ;
  46. var config= setting.accessConfig.ToObject<JsonElement>();
  47. config.TryGetProperty("config", out JsonElement _config);
  48. if ($"{_config}".Equals("scsyxpt"))
  49. {
  50. var binds = teacher.binds.FindAll(x => x.type.Equals("scsyxpt"));
  51. var datas = binds.SelectMany(x => x.data).Where(y=>y.Contains("scsyxpt"));
  52. HashSet<string> pxids = new HashSet<string> ();
  53. if (datas != null) {
  54. datas.ToList().ForEach(x => {
  55. var data = x.ToObject<ScBindData>();
  56. if (!string.IsNullOrEmpty(data?.pxid)) {
  57. pxids.Add(data.pxid);
  58. }
  59. });
  60. }
  61. foreach (var pxid in pxids) {
  62. Dictionary<string, object> dict = new Dictionary<string, object>() { { "accessConfig", setting.accessConfig },{ "pxid",pxid } };
  63. (int status, string json) = await httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetDiagnosisListByProject_V2");
  64. if (status == 200)
  65. {
  66. List<string> nos = json.ToObject<List<string>>();
  67. if (nos.IsNotEmpty()) {
  68. abilityNos.AddRange(nos);
  69. }
  70. }
  71. }
  72. }
  73. //获取能力点
  74. List<Ability> abilities = null;
  75. if (abilityNos.IsNotEmpty()) {
  76. abilities = new List<Ability>();
  77. StringBuilder sql = new StringBuilder($"select value(c) from c where c.no in ({string.Join(",", abilityNos.Select(x => $"'{x}'"))})");
  78. await foreach (var item in client.GetContainer("TEAMModelOS", "Normal")
  79. .GetItemQueryIterator<Ability>(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Ability-{standard}") }))
  80. {
  81. abilities.Add(item);
  82. }
  83. }
  84. return abilities;
  85. }
  86. }
  87. }