平安校园
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

210 lines
7.3 KiB

  1. using MoYu.FriendlyException;
  2. using MoYu.RemoteRequest.Extensions;
  3. using Newtonsoft.Json.Linq;
  4. using SafeCampus.Application.Manager.DeepelephManager;
  5. using SafeCampus.Application.Services.Business.ClassTeacherService;
  6. using SafeCampus.Application.Services.Business.PersonSetInfoService;
  7. namespace SafeCampus.Web.Core.Controllers.Application.Business;
  8. /// <summary>
  9. /// 人员班级管理接口
  10. /// </summary>
  11. [Route("/business/[controller]")]
  12. [ApiDescriptionSettings(ApiGroupConsts.SYSTEM_Business, Order = 99,Tag = "人员班级管理")]
  13. public class DfieldApi : IDynamicApiController
  14. {
  15. private readonly IDeepelephManager _deepelephManager;
  16. private readonly IClassTeacherService _classTeacherService;
  17. private readonly IPersonSetInfoService _personSetInfoService;
  18. public DfieldApi(IDeepelephManager deepelephManager, IClassTeacherService classTeacherService, IPersonSetInfoService personSetInfoService)
  19. {
  20. _deepelephManager = deepelephManager;
  21. _classTeacherService = classTeacherService;
  22. _personSetInfoService = personSetInfoService;
  23. }
  24. /// <summary>
  25. /// 创建底库
  26. /// </summary>
  27. /// <returns></returns>
  28. public async Task<dynamic> CreateDfieldA(ControllersNameInput input)
  29. {
  30. var personSetId = Guid.NewGuid().ToString("N");
  31. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  32. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/set/create"
  33. .SetBody(new
  34. {
  35. token = _deepelephManager.GetToken(),
  36. tenantCode = appSettings.TenantCode,
  37. poiId = appSettings.PoiId,
  38. personSetId,
  39. personSetName = input.Name,
  40. })
  41. .SetContentType("application/json")
  42. .PostAsAsync<string>();
  43. var model = JsonConvert.DeserializeObject<JObject>(str);
  44. if ((bool)model["success"])
  45. {
  46. await _personSetInfoService.Add(new PersonSetInfoDto{PersonSetId = personSetId ,PersonSetName = input.Name,MajorId = input.MajorId});
  47. return model["data"];
  48. }
  49. throw Oops.Oh(model["message"].ToString());
  50. }
  51. /// <summary>
  52. /// 查询底库列表
  53. /// </summary>
  54. /// <returns></returns>
  55. public async Task<dynamic> QueryAll(long? majorId,string personSetName)
  56. {
  57. return await _personSetInfoService.GetPageList(majorId, personSetName);
  58. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  59. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/set/queryAll"
  60. .SetBody(new
  61. {
  62. token = _deepelephManager.GetToken(),
  63. tenantCode = appSettings.TenantCode,
  64. poiId = appSettings.PoiId,
  65. })
  66. .SetContentType("application/json")
  67. .PostAsAsync<string>();
  68. var model = JsonConvert.DeserializeObject<JObject>(str);
  69. if ((bool)model["success"])
  70. {
  71. var list = model["data"];
  72. for (int i = 0; i < list.Count(); i++)
  73. {
  74. var models = await _classTeacherService.GetInfo(list[i]["personSetId"].ToString());
  75. if (models!=null)
  76. {
  77. list[i]["userId"]= models.UserId;
  78. list[i]["userName"]= models.Name;
  79. list[i]["id"]= models.Id;
  80. }
  81. else
  82. {
  83. list[i]["userId"] = null;
  84. list[i]["userName"] =null;
  85. }
  86. }
  87. return list;
  88. }
  89. throw Oops.Oh(model["message"].ToString());
  90. }
  91. /// <summary>
  92. /// 删除底库
  93. /// </summary>
  94. /// <param name="id">底库id</param>
  95. /// <returns></returns>
  96. public async Task<dynamic> DeleteDfieldD(string id)
  97. {
  98. var list = new List<string>();
  99. if (id.Contains(","))
  100. {
  101. list = id.Split(",").ToList();
  102. }
  103. else
  104. {
  105. list.Add(id);
  106. }
  107. foreach (var ids in list)
  108. {
  109. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  110. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/set/delete"
  111. .SetBody(new
  112. {
  113. token = _deepelephManager.GetToken(),
  114. tenantCode = appSettings.TenantCode,
  115. poiId = appSettings.PoiId,
  116. personSetId = ids
  117. })
  118. .SetContentType("application/json")
  119. .PostAsAsync<string>();
  120. var model = JsonConvert.DeserializeObject<JObject>(str);
  121. if ((bool)model["success"])
  122. {
  123. var isOk = model["data"].ToString() == ids;
  124. if (isOk)
  125. {
  126. await _personSetInfoService.Delete(ids);
  127. }
  128. return isOk;
  129. }
  130. throw Oops.Oh(model["message"].ToString());
  131. }
  132. return false;
  133. }
  134. /// <summary>
  135. /// 更新底库
  136. /// </summary>
  137. /// <param name="input"></param>
  138. /// <returns></returns>
  139. public async Task<dynamic> UpdateDfieldU(DfieldInput input)
  140. {
  141. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  142. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/set/update"
  143. .SetBody(new
  144. {
  145. token = _deepelephManager.GetToken(),
  146. tenantCode = appSettings.TenantCode,
  147. poiId = appSettings.PoiId,
  148. personSetId=input.Id,
  149. personSetName=input.Name
  150. })
  151. .SetContentType("application/json")
  152. .PostAsAsync<string>();
  153. var model = JsonConvert.DeserializeObject<JObject>(str);
  154. if ((bool)model["success"])
  155. {
  156. var isOk = model["data"].ToString() == input.Id;
  157. if (isOk)
  158. {
  159. await _personSetInfoService.Update(new PersonSetInfoDto
  160. {
  161. PersonSetId = input.Id,
  162. PersonSetName = input.Name,
  163. MajorId = input.MajorId
  164. });
  165. }
  166. return isOk;
  167. }
  168. throw Oops.Oh(model["message"].ToString());
  169. }
  170. /// <summary>
  171. /// 同步班级数据
  172. /// </summary>
  173. /// <returns></returns>
  174. public async Task<bool> SyncData()
  175. {
  176. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  177. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/set/queryAll"
  178. .SetBody(new
  179. {
  180. token = _deepelephManager.GetToken(),
  181. tenantCode = appSettings.TenantCode,
  182. poiId = appSettings.PoiId,
  183. })
  184. .SetContentType("application/json")
  185. .PostAsAsync<string>();
  186. var model = JsonConvert.DeserializeObject<JObject>(str);
  187. if ((bool)model["success"])
  188. {
  189. var list = model["data"];
  190. foreach (var item in list)
  191. {
  192. await _personSetInfoService.Add(new PersonSetInfoDto
  193. {
  194. PersonSetId = item["personSetId"].ToString(),
  195. PersonSetName = item["personSetName"].ToString(),
  196. });
  197. }
  198. }
  199. return true;
  200. }
  201. }