using MoYu.FriendlyException; using MoYu.RemoteRequest; using MoYu.RemoteRequest.Extensions; using Newtonsoft.Json.Linq; using SafeCampus.Application.Manager.DeepelephManager; using SafeCampus.Web.Core.Controllers.Application.Business.Dto; namespace SafeCampus.Web.Core.Controllers.Application.Business; /// /// 服装底库管理接口 /// [Route("/business/[controller]")] [ApiDescriptionSettings(ApiGroupConsts.SYSTEM_Business, Order = 97, Tag = "服装底库管理")] public class ClothApi { private readonly IDeepelephManager _deepelephManager; public ClothApi(IDeepelephManager deepelephManager) { _deepelephManager = deepelephManager; } /// /// 新增服装底库 /// /// 人员信息 /// public async Task AddClothDataBaseA(ClothDataNameInfo input) { var appSettings = App.GetOptionsMonitor(); var liststr = await $"{appSettings.SXAPIURL}/dfield-api/ecology/cloth/set/query-list" .SetBody(new { token = _deepelephManager.GetToken(), tenantCode = appSettings.TenantCode, poiId = appSettings.PoiId, }) .SetContentType("application/json") .PostAsAsync(); var list = JsonConvert.DeserializeObject(liststr); var newlist = new List(); foreach (var item in list["data"]) { newlist.Add(item.Value("clothSetName")); } if (newlist.Any(x=>x==input.ClothSetName)) { throw Oops.Oh("服装库名称已存在"); } var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/cloth/set/create" .SetBody(new { token = _deepelephManager.GetToken(), tenantCode = appSettings.TenantCode, poiId = appSettings.PoiId, clothSetId = Guid.NewGuid().ToString("N"), clothSetName = input.ClothSetName, }) .SetContentType("application/json") .PostAsAsync(); var model = JsonConvert.DeserializeObject(str); if ((bool)model["success"]) { return model["data"]; } throw Oops.Oh(model["message"].ToString()); } /// /// 删除服装底库 /// /// /// public async Task DeleteClothDataBaseD(string clothSetId) { var appSettings = App.GetOptionsMonitor(); var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/cloth/set/delete" .SetBody(new { token = _deepelephManager.GetToken(), tenantCode = appSettings.TenantCode, poiId = appSettings.PoiId, clothSetId = clothSetId, }) .SetContentType("application/json") .PostAsAsync(); var model = JsonConvert.DeserializeObject(str); if ((bool)model["success"]) { return model["data"]; } throw Oops.Oh(model["message"].ToString()); } /// /// 更新服装底库 /// /// public async Task UpdateClothU(ClothDataBaseInfo info) { var appSettings = App.GetOptionsMonitor(); var liststr = await $"{appSettings.SXAPIURL}/dfield-api/ecology/cloth/set/query-list" .SetBody(new { token = _deepelephManager.GetToken(), tenantCode = appSettings.TenantCode, poiId = appSettings.PoiId, }) .SetContentType("application/json") .PostAsAsync(); var list = JsonConvert.DeserializeObject(liststr); var newlist = new List(); foreach (var item in list["data"]) { newlist.Add(item.Value("clothSetName")); } if (newlist.Any(x => x == info.ClothSetName)) { throw Oops.Oh("服装库名称已存在"); } var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/cloth/set/update" .SetBody(new { token = _deepelephManager.GetToken(), tenantCode = appSettings.TenantCode, poiId = appSettings.PoiId, clothSetId = info.ClothSetId, clothSetName = info.ClothSetName, }) .SetContentType("application/json") .PostAsAsync(); var model = JsonConvert.DeserializeObject(str); if ((bool)model["success"]) { return model["data"]; } throw Oops.Oh(model["message"].ToString()); } /// /// 查询服装底库列表 /// /// public async Task GetList() { var appSettings = App.GetOptionsMonitor(); var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/cloth/set/query-list" .SetBody(new { token = _deepelephManager.GetToken(), tenantCode = appSettings.TenantCode, poiId = appSettings.PoiId, }) .SetContentType("application/json") .PostAsAsync(); var model = JsonConvert.DeserializeObject(str); if ((bool)model["success"]) { return model["data"]; } throw Oops.Oh(model["message"].ToString()); } /// /// 查询服装底库详情 /// /// 服装库Id /// public async Task GetInfo(string clothSetId) { var appSettings = App.GetOptionsMonitor(); var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/cloth/set/query-detail" .SetBody(new { token = _deepelephManager.GetToken(), tenantCode = appSettings.TenantCode, poiId = appSettings.PoiId, clothSetId = clothSetId }) .SetContentType("application/json") .PostAsAsync(); var model = JsonConvert.DeserializeObject(str); if ((bool)model["success"]) { return model["data"]; } throw Oops.Oh(model["message"].ToString()); } /// /// 服装图片上传 /// /// /// public async Task UploadFile([FromForm] BaseFileInput input) { var appSettings = App.GetOptionsMonitor(); var jsonparam = JsonConvert.SerializeObject(new { token = _deepelephManager.GetToken(), tenantCode = appSettings.TenantCode, poiId = appSettings.PoiId, usageScenario = "staff" }); var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/common/upload-file" .SetFiles(HttpFile.Create("file", input.File.OpenReadStream(), input.File.FileName)) .SetBody(new { param = jsonparam }) .SetContentType("multipart/form-data") .PostAsAsync(); var model = JsonConvert.DeserializeObject(str); if ((bool)model["success"]) { return model["data"]["httpUrl"].ToString(); } throw Oops.Oh(model["message"].ToString()); } /// /// 新增服装 /// /// /// public async Task AddClothA(ClothInfos info) { var appSettings = App.GetOptionsMonitor(); var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/cloth/add" .SetBody(new { token = _deepelephManager.GetToken(), tenantCode = appSettings.TenantCode, poiId = appSettings.PoiId, info.clothSetId, info.clothUrl }) .SetContentType("application/json") .PostAsAsync(); var model = JsonConvert.DeserializeObject(str); if ((bool)model["success"]) { return model["data"]; } throw Oops.Oh(model["message"].ToString()); } /// /// 删除服装 /// /// [HttpPost] public async Task DeleteClothD(ClothInfos info) { var list = new List(); if (info.clothId.Contains(",")) { list = info.clothId.Split(",").ToList(); } else { list.Add(info.clothId); } foreach (var ids in list) { var appSettings = App.GetOptionsMonitor(); var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/cloth/delete" .SetBody(new { token = _deepelephManager.GetToken(), tenantCode = appSettings.TenantCode, poiId = appSettings.PoiId, info.clothSetId, clothId= ids }) .SetContentType("application/json") .PostAsAsync(); //var model = JsonConvert.DeserializeObject(str); //if ((bool)model["success"]) //{ // return model["data"]; //} //throw Oops.Oh(model["message"].ToString()); } return true; } }