|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- using MoYu.FriendlyException;
- using MoYu.RemoteRequest.Extensions;
- using Newtonsoft.Json.Linq;
- using SafeCampus.Application.Manager.DeepelephManager;
- using SafeCampus.Application.Services.Business.ClassTeacherService;
- using SafeCampus.Application.Services.Business.PersonSetInfoService;
-
- namespace SafeCampus.Web.Core.Controllers.Application.Business;
- /// <summary>
- /// 人员班级管理接口
- /// </summary>
- [Route("/business/[controller]")]
- [ApiDescriptionSettings(ApiGroupConsts.SYSTEM_Business, Order = 99,Tag = "人员班级管理")]
- public class DfieldApi : IDynamicApiController
- {
- private readonly IDeepelephManager _deepelephManager;
- private readonly IClassTeacherService _classTeacherService;
- private readonly IPersonSetInfoService _personSetInfoService;
-
- public DfieldApi(IDeepelephManager deepelephManager, IClassTeacherService classTeacherService, IPersonSetInfoService personSetInfoService)
- {
- _deepelephManager = deepelephManager;
- _classTeacherService = classTeacherService;
- _personSetInfoService = personSetInfoService;
- }
- /// <summary>
- /// 创建底库
- /// </summary>
- /// <returns></returns>
- public async Task<dynamic> CreateDfieldA(ControllersNameInput input)
- {
- if (await _personSetInfoService.CheckName(input.Name,null))
- {
- throw Oops.Oh("【"+input.Name+"】班级名称已存在");
- }
- var personSetId = Guid.NewGuid().ToString("N");
- var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
- var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/set/create"
- .SetBody(new
- {
- token = _deepelephManager.GetToken(),
- tenantCode = appSettings.TenantCode,
- poiId = appSettings.PoiId,
- personSetId,
- personSetName = input.Name,
- })
- .SetContentType("application/json")
- .PostAsAsync<string>();
- var model = JsonConvert.DeserializeObject<JObject>(str);
- if ((bool)model["success"])
- {
- await _personSetInfoService.Add(new PersonSetInfoDto{PersonSetId = personSetId ,PersonSetName = input.Name,MajorId = input.MajorId});
- return model["data"];
- }
-
- throw Oops.Oh(model["message"].ToString());
- }
- /// <summary>
- /// 查询底库列表
- /// </summary>
- /// <returns></returns>
- public async Task<dynamic> QueryAll(long? majorId,string personSetName)
- {
- return await _personSetInfoService.GetPageList(majorId, personSetName);
- var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
- var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/set/queryAll"
- .SetBody(new
- {
- token = _deepelephManager.GetToken(),
- tenantCode = appSettings.TenantCode,
- poiId = appSettings.PoiId,
- })
- .SetContentType("application/json")
- .PostAsAsync<string>();
- var model = JsonConvert.DeserializeObject<JObject>(str);
- if ((bool)model["success"])
- {
- var list = model["data"];
- for (int i = 0; i < list.Count(); i++)
- {
- var models = await _classTeacherService.GetInfo(list[i]["personSetId"].ToString());
- if (models!=null)
- {
- list[i]["userId"]= models.UserId;
- list[i]["userName"]= models.Name;
- list[i]["id"]= models.Id;
- }
- else
- {
- list[i]["userId"] = null;
- list[i]["userName"] =null;
- }
- }
- return list;
- }
-
- throw Oops.Oh(model["message"].ToString());
- }
- /// <summary>
- /// 分页获取班级列表
- /// </summary>
- /// <param name="search"></param>
- /// <returns></returns>
- public async Task<dynamic> GetPageList(PersonSetInfoSearch search)
- {
- return await _personSetInfoService.GetList(search);
- }
- /// <summary>
- /// 删除底库
- /// </summary>
- /// <param name="id">底库id</param>
- /// <returns></returns>
- public async Task<dynamic> DeleteDfieldD(string id)
- {
- var list = new List<string>();
- if (id.Contains(","))
- {
- list = id.Split(",").ToList();
- }
- else
- {
- list.Add(id);
- }
-
- foreach (var ids in list)
- {
- var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
- var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/set/delete"
- .SetBody(new
- {
- token = _deepelephManager.GetToken(),
- tenantCode = appSettings.TenantCode,
- poiId = appSettings.PoiId,
- personSetId = ids
- })
- .SetContentType("application/json")
- .PostAsAsync<string>();
- var model = JsonConvert.DeserializeObject<JObject>(str);
- if ((bool)model["success"])
- {
- var isOk = model["data"].ToString() == ids;
- await _personSetInfoService.Delete(ids);
- }
- else if (model["message"].ToString().Contains("不存在"))
- {
- await _personSetInfoService.Delete(ids);
- }
- else
- {
- throw Oops.Oh(model["message"].ToString());
- }
- }
- return true;
- }
- /// <summary>
- /// 更新底库
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- public async Task<dynamic> UpdateDfieldU(DfieldInput input)
- {
- if (await _personSetInfoService.CheckName(input.Name, input.Id))
- {
- throw Oops.Oh("【" + input.Name + "】班级名称已存在");
- }
- var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
- var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/set/update"
- .SetBody(new
- {
- token = _deepelephManager.GetToken(),
- tenantCode = appSettings.TenantCode,
- poiId = appSettings.PoiId,
- personSetId=input.Id,
- personSetName=input.Name
- })
- .SetContentType("application/json")
- .PostAsAsync<string>();
- var model = JsonConvert.DeserializeObject<JObject>(str);
- if ((bool)model["success"])
- {
- var isOk = model["data"].ToString() == input.Id;
- if (isOk)
- {
- await _personSetInfoService.Update(new PersonSetInfoDto
- {
- PersonSetId = input.Id,
- PersonSetName = input.Name,
- MajorId = input.MajorId
- });
- }
- return isOk;
- }
-
- throw Oops.Oh(model["message"].ToString());
- }
- /// <summary>
- /// 同步班级数据
- /// </summary>
- /// <returns></returns>
- public async Task<bool> SyncData()
- {
- var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
- var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/set/queryAll"
- .SetBody(new
- {
- token = _deepelephManager.GetToken(),
- tenantCode = appSettings.TenantCode,
- poiId = appSettings.PoiId,
- })
- .SetContentType("application/json")
- .PostAsAsync<string>();
- var model = JsonConvert.DeserializeObject<JObject>(str);
- if ((bool)model["success"])
- {
- var list = model["data"];
- foreach (var item in list)
- {
- await _personSetInfoService.Add(new PersonSetInfoDto
- {
- PersonSetId = item["personSetId"].ToString(),
- PersonSetName = item["personSetName"].ToString(),
- });
- }
-
- }
- return true;
- }
- }
|