平安校园
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.
 
 
 
 
 
 

228 lines
8.0 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. if (await _personSetInfoService.CheckName(input.Name,null))
  31. {
  32. throw Oops.Oh("【"+input.Name+"】班级名称已存在");
  33. }
  34. var personSetId = Guid.NewGuid().ToString("N");
  35. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  36. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/set/create"
  37. .SetBody(new
  38. {
  39. token = _deepelephManager.GetToken(),
  40. tenantCode = appSettings.TenantCode,
  41. poiId = appSettings.PoiId,
  42. personSetId,
  43. personSetName = input.Name,
  44. })
  45. .SetContentType("application/json")
  46. .PostAsAsync<string>();
  47. var model = JsonConvert.DeserializeObject<JObject>(str);
  48. if ((bool)model["success"])
  49. {
  50. await _personSetInfoService.Add(new PersonSetInfoDto{PersonSetId = personSetId ,PersonSetName = input.Name,MajorId = input.MajorId});
  51. return model["data"];
  52. }
  53. throw Oops.Oh(model["message"].ToString());
  54. }
  55. /// <summary>
  56. /// 查询底库列表
  57. /// </summary>
  58. /// <returns></returns>
  59. public async Task<dynamic> QueryAll(long? majorId,string personSetName)
  60. {
  61. return await _personSetInfoService.GetPageList(majorId, personSetName);
  62. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  63. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/set/queryAll"
  64. .SetBody(new
  65. {
  66. token = _deepelephManager.GetToken(),
  67. tenantCode = appSettings.TenantCode,
  68. poiId = appSettings.PoiId,
  69. })
  70. .SetContentType("application/json")
  71. .PostAsAsync<string>();
  72. var model = JsonConvert.DeserializeObject<JObject>(str);
  73. if ((bool)model["success"])
  74. {
  75. var list = model["data"];
  76. for (int i = 0; i < list.Count(); i++)
  77. {
  78. var models = await _classTeacherService.GetInfo(list[i]["personSetId"].ToString());
  79. if (models!=null)
  80. {
  81. list[i]["userId"]= models.UserId;
  82. list[i]["userName"]= models.Name;
  83. list[i]["id"]= models.Id;
  84. }
  85. else
  86. {
  87. list[i]["userId"] = null;
  88. list[i]["userName"] =null;
  89. }
  90. }
  91. return list;
  92. }
  93. throw Oops.Oh(model["message"].ToString());
  94. }
  95. /// <summary>
  96. /// 分页获取班级列表
  97. /// </summary>
  98. /// <param name="search"></param>
  99. /// <returns></returns>
  100. public async Task<dynamic> GetPageList(PersonSetInfoSearch search)
  101. {
  102. return await _personSetInfoService.GetList(search);
  103. }
  104. /// <summary>
  105. /// 删除底库
  106. /// </summary>
  107. /// <param name="id">底库id</param>
  108. /// <returns></returns>
  109. public async Task<dynamic> DeleteDfieldD(string id)
  110. {
  111. var list = new List<string>();
  112. if (id.Contains(","))
  113. {
  114. list = id.Split(",").ToList();
  115. }
  116. else
  117. {
  118. list.Add(id);
  119. }
  120. foreach (var ids in list)
  121. {
  122. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  123. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/set/delete"
  124. .SetBody(new
  125. {
  126. token = _deepelephManager.GetToken(),
  127. tenantCode = appSettings.TenantCode,
  128. poiId = appSettings.PoiId,
  129. personSetId = ids
  130. })
  131. .SetContentType("application/json")
  132. .PostAsAsync<string>();
  133. var model = JsonConvert.DeserializeObject<JObject>(str);
  134. if ((bool)model["success"])
  135. {
  136. var isOk = model["data"].ToString() == ids;
  137. await _personSetInfoService.Delete(ids);
  138. }
  139. else if (model["message"].ToString().Contains("不存在"))
  140. {
  141. await _personSetInfoService.Delete(ids);
  142. }
  143. else
  144. {
  145. throw Oops.Oh(model["message"].ToString());
  146. }
  147. }
  148. return true;
  149. }
  150. /// <summary>
  151. /// 更新底库
  152. /// </summary>
  153. /// <param name="input"></param>
  154. /// <returns></returns>
  155. public async Task<dynamic> UpdateDfieldU(DfieldInput input)
  156. {
  157. if (await _personSetInfoService.CheckName(input.Name, input.Id))
  158. {
  159. throw Oops.Oh("【" + input.Name + "】班级名称已存在");
  160. }
  161. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  162. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/set/update"
  163. .SetBody(new
  164. {
  165. token = _deepelephManager.GetToken(),
  166. tenantCode = appSettings.TenantCode,
  167. poiId = appSettings.PoiId,
  168. personSetId=input.Id,
  169. personSetName=input.Name
  170. })
  171. .SetContentType("application/json")
  172. .PostAsAsync<string>();
  173. var model = JsonConvert.DeserializeObject<JObject>(str);
  174. if ((bool)model["success"])
  175. {
  176. var isOk = model["data"].ToString() == input.Id;
  177. if (isOk)
  178. {
  179. await _personSetInfoService.Update(new PersonSetInfoDto
  180. {
  181. PersonSetId = input.Id,
  182. PersonSetName = input.Name,
  183. MajorId = input.MajorId
  184. });
  185. }
  186. return isOk;
  187. }
  188. throw Oops.Oh(model["message"].ToString());
  189. }
  190. /// <summary>
  191. /// 同步班级数据
  192. /// </summary>
  193. /// <returns></returns>
  194. public async Task<bool> SyncData()
  195. {
  196. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  197. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/set/queryAll"
  198. .SetBody(new
  199. {
  200. token = _deepelephManager.GetToken(),
  201. tenantCode = appSettings.TenantCode,
  202. poiId = appSettings.PoiId,
  203. })
  204. .SetContentType("application/json")
  205. .PostAsAsync<string>();
  206. var model = JsonConvert.DeserializeObject<JObject>(str);
  207. if ((bool)model["success"])
  208. {
  209. var list = model["data"];
  210. foreach (var item in list)
  211. {
  212. await _personSetInfoService.Add(new PersonSetInfoDto
  213. {
  214. PersonSetId = item["personSetId"].ToString(),
  215. PersonSetName = item["personSetName"].ToString(),
  216. });
  217. }
  218. }
  219. return true;
  220. }
  221. }