ScsApisHttpTrigger.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using System;
  2. using System.IO;
  3. using System.Threading.Tasks;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.Azure.WebJobs;
  6. using Microsoft.Azure.WebJobs.Extensions.Http;
  7. using Microsoft.AspNetCore.Http;
  8. using Microsoft.Extensions.Logging;
  9. using TEAMModelOS.SDK.DI;
  10. using Azure.Cosmos;
  11. using System.Text.Json;
  12. using System.Collections.Generic;
  13. using TEAMModelOS.SDK.Models;
  14. using TEAMModelOS.SDK.Extension;
  15. using TEAMModelOS.SDK;
  16. using TEAMModelOS.SDK.Models.Cosmos;
  17. using TEAMModelOS.SDK.Models.Cosmos.Common;
  18. using System.Linq;
  19. using TEAMModelOS.Services.Common;
  20. using TEAMModelOS.SDK.Models.Service;
  21. using HTEXLib.COMM.Helpers;
  22. namespace TEAMModelFunction
  23. {
  24. public class ScsApisHttpTrigger
  25. {
  26. private readonly AzureCosmosFactory _azureCosmos;
  27. private readonly DingDing _dingDing;
  28. private readonly AzureStorageFactory _azureStorage;
  29. private readonly AzureRedisFactory _azureRedis;
  30. private readonly ThirdApisService _thirdApisService;
  31. public static string Code { get; set; }
  32. public static Dictionary<string, object> parameterMap = null;
  33. public ScsApisHttpTrigger(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, ThirdApisService thirdApisService
  34. , AzureRedisFactory azureRedis)
  35. {
  36. _azureCosmos = azureCosmos;
  37. _dingDing = dingDing;
  38. _azureStorage = azureStorage;
  39. _azureRedis = azureRedis;
  40. _thirdApisService = thirdApisService;
  41. }
  42. /// <summary>
  43. ///
  44. /// </summary>
  45. /// <param name="req"></param>
  46. /// <param name="log"></param>
  47. /// <returns></returns>
  48. [FunctionName("GetDiagnosisListByProject_V2")]
  49. public async Task<IActionResult> GetDiagnosisListByProject_V2([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req, ILogger log) {
  50. List<string> abilityNos = null;
  51. string data = await new StreamReader(req.Body).ReadToEndAsync();
  52. JsonElement accessConfig= data.ToObject<JsonElement>().GetProperty("accessConfig");
  53. JsonElement pxid = data.ToObject<JsonElement>().GetProperty("pxid");
  54. ScAccessConfig config = $"{accessConfig}".ToObject<ScAccessConfig>();
  55. Code = "GetDiagnosisListByProject_V2";
  56. parameterMap = new Dictionary<string, object>();
  57. parameterMap.Add("TrainComID", config.trainComID);
  58. //parameterMap.Add("ProjectID", "22");
  59. //parameterMap.Add("ProjectItemID", "22");
  60. parameterMap.Add("PXID", pxid);
  61. ScsResult result = new ScsResult { code = Code, title = "5.3.1.3通过项目编号获取学员测评能力项V2" };
  62. try
  63. {
  64. result = await _thirdApisService.Post(config.url, Code, config.passKey, config.privateKey, parameterMap);
  65. if (result.result)
  66. {
  67. List<ScDiagnosis> diagnoses = result.content.ToObject<List<ScDiagnosis>>();
  68. if (diagnoses != null)
  69. {
  70. abilityNos = diagnoses.Select(x => x.DiagnosisDicNum).ToList();
  71. }
  72. }
  73. return new OkObjectResult(new { data= abilityNos .ToJsonString()});
  74. }
  75. catch (Exception ex)
  76. {
  77. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")},IES5.ScApisService:getDiagnosisListByProject_V2\n{ex.Message}{ex.StackTrace}\n{result.ToJsonString()}", GroupNames.成都开发測試群組);
  78. return new OkObjectResult(abilityNos);
  79. }
  80. }
  81. /// <summary>
  82. /// 5.3.1.11获取跳转学员信息,用于sso单点,后端验证。
  83. /// </summary>
  84. /// <param name="req"></param>
  85. /// <param name="log"></param>
  86. /// <returns></returns>
  87. [FunctionName("GetSingleTeacherByProject")]
  88. public async Task<IActionResult> GetSingleTeacherByProject([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req, ILogger log)
  89. {
  90. string teacher=null;
  91. string data = await new StreamReader(req.Body).ReadToEndAsync();
  92. JsonElement accessConfig = data.ToObject<JsonElement>().GetProperty("accessConfig");
  93. JsonElement pxid = data.ToObject<JsonElement>().GetProperty("pxid");
  94. JsonElement tid = data.ToObject<JsonElement>().GetProperty("tid");
  95. ScAccessConfig config = $"{accessConfig}".ToObject<ScAccessConfig>();
  96. Code = "GetSingleTeacherByProject";
  97. parameterMap = new Dictionary<string, object>();
  98. parameterMap.Add("TrainComID", config.trainComID);
  99. parameterMap.Add("Pxid", $"{pxid}");
  100. parameterMap.Add("Tid", $"{tid}");
  101. ScsResult result = new ScsResult { code = Code, title = "5.3.1.11获取跳转学员信息,用于sso单点,后端验证。" };
  102. try
  103. {
  104. ///{“result”:true,”reason”:null,”content”:”{“PXID”:””,”TID”:””,”TeacherName”:””,”ProjectTitle”:””,”ProjectItemTitle”:””,”CityName”:””,
  105. ///”DisName”:””,”SchoolName”:””,”Sex”:””,”PXXK”:””,”PXXD”:””,”TeacherXK”:””,”TeacherXD”:””,”Email”:””}”,”pagecount”:1}
  106. result = await _thirdApisService.Post(config.url, Code, config.passKey, config.privateKey, parameterMap);
  107. if (result.result)
  108. {
  109. teacher = result.content;
  110. }
  111. return new OkObjectResult(new {data= teacher });
  112. }
  113. catch (Exception ex)
  114. {
  115. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")},IES5.ScApisService:GetSingleTeacherByProject\n{ex.Message}{ex.StackTrace}\n{result.ToJsonString()}", GroupNames.成都开发測試群組);
  116. return new OkObjectResult(teacher);
  117. }
  118. }
  119. }
  120. }