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

284 lines
9.8 KiB

  1. using MoYu.FriendlyException;
  2. using MoYu.RemoteRequest;
  3. using MoYu.RemoteRequest.Extensions;
  4. using Newtonsoft.Json.Linq;
  5. using SafeCampus.Application.Manager.DeepelephManager;
  6. using SafeCampus.Web.Core.Controllers.Application.Business.Dto;
  7. namespace SafeCampus.Web.Core.Controllers.Application.Business;
  8. /// <summary>
  9. /// 服装底库管理接口
  10. /// </summary>
  11. [Route("/business/[controller]")]
  12. [ApiDescriptionSettings(ApiGroupConsts.SYSTEM_Business, Order = 97, Tag = "服装底库管理")]
  13. public class ClothApi
  14. {
  15. private readonly IDeepelephManager _deepelephManager;
  16. public ClothApi(IDeepelephManager deepelephManager)
  17. {
  18. _deepelephManager = deepelephManager;
  19. }
  20. /// <summary>
  21. /// 新增服装底库
  22. /// </summary>
  23. /// <param name="input">人员信息</param>
  24. /// <returns></returns>
  25. public async Task<dynamic> AddClothDataBaseA(ClothDataNameInfo input)
  26. {
  27. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  28. var liststr = await $"{appSettings.SXAPIURL}/dfield-api/ecology/cloth/set/query-list"
  29. .SetBody(new
  30. {
  31. token = _deepelephManager.GetToken(),
  32. tenantCode = appSettings.TenantCode,
  33. poiId = appSettings.PoiId,
  34. })
  35. .SetContentType("application/json")
  36. .PostAsAsync<string>();
  37. var list = JsonConvert.DeserializeObject<JObject>(liststr);
  38. var newlist = new List<string>();
  39. foreach (var item in list["data"])
  40. {
  41. newlist.Add(item.Value<string>("clothSetName"));
  42. }
  43. if (newlist.Any(x=>x==input.ClothSetName))
  44. {
  45. throw Oops.Oh("服装库名称已存在");
  46. }
  47. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/cloth/set/create"
  48. .SetBody(new
  49. {
  50. token = _deepelephManager.GetToken(),
  51. tenantCode = appSettings.TenantCode,
  52. poiId = appSettings.PoiId,
  53. clothSetId = Guid.NewGuid().ToString("N"),
  54. clothSetName = input.ClothSetName,
  55. })
  56. .SetContentType("application/json")
  57. .PostAsAsync<string>();
  58. var model = JsonConvert.DeserializeObject<JObject>(str);
  59. if ((bool)model["success"])
  60. {
  61. return model["data"];
  62. }
  63. throw Oops.Oh(model["message"].ToString());
  64. }
  65. /// <summary>
  66. /// 删除服装底库
  67. /// </summary>
  68. /// <param name="clothSetId"></param>
  69. /// <returns></returns>
  70. public async Task<dynamic> DeleteClothDataBaseD(string clothSetId)
  71. {
  72. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  73. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/cloth/set/delete"
  74. .SetBody(new
  75. {
  76. token = _deepelephManager.GetToken(),
  77. tenantCode = appSettings.TenantCode,
  78. poiId = appSettings.PoiId,
  79. clothSetId = clothSetId,
  80. })
  81. .SetContentType("application/json")
  82. .PostAsAsync<string>();
  83. var model = JsonConvert.DeserializeObject<JObject>(str);
  84. if ((bool)model["success"])
  85. {
  86. return model["data"];
  87. }
  88. throw Oops.Oh(model["message"].ToString());
  89. }
  90. /// <summary>
  91. /// 更新服装底库
  92. /// </summary>
  93. /// <returns></returns>
  94. public async Task<dynamic> UpdateClothU(ClothDataBaseInfo info)
  95. {
  96. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  97. var liststr = await $"{appSettings.SXAPIURL}/dfield-api/ecology/cloth/set/query-list"
  98. .SetBody(new
  99. {
  100. token = _deepelephManager.GetToken(),
  101. tenantCode = appSettings.TenantCode,
  102. poiId = appSettings.PoiId,
  103. })
  104. .SetContentType("application/json")
  105. .PostAsAsync<string>();
  106. var list = JsonConvert.DeserializeObject<JObject>(liststr);
  107. var newlist = new List<string>();
  108. foreach (var item in list["data"])
  109. {
  110. newlist.Add(item.Value<string>("clothSetName"));
  111. }
  112. if (newlist.Any(x => x == info.ClothSetName))
  113. {
  114. throw Oops.Oh("服装库名称已存在");
  115. }
  116. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/cloth/set/update"
  117. .SetBody(new
  118. {
  119. token = _deepelephManager.GetToken(),
  120. tenantCode = appSettings.TenantCode,
  121. poiId = appSettings.PoiId,
  122. clothSetId = info.ClothSetId,
  123. clothSetName = info.ClothSetName,
  124. })
  125. .SetContentType("application/json")
  126. .PostAsAsync<string>();
  127. var model = JsonConvert.DeserializeObject<JObject>(str);
  128. if ((bool)model["success"])
  129. {
  130. return model["data"];
  131. }
  132. throw Oops.Oh(model["message"].ToString());
  133. }
  134. /// <summary>
  135. /// 查询服装底库列表
  136. /// </summary>
  137. /// <returns></returns>
  138. public async Task<dynamic> GetList()
  139. {
  140. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  141. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/cloth/set/query-list"
  142. .SetBody(new
  143. {
  144. token = _deepelephManager.GetToken(),
  145. tenantCode = appSettings.TenantCode,
  146. poiId = appSettings.PoiId,
  147. })
  148. .SetContentType("application/json")
  149. .PostAsAsync<string>();
  150. var model = JsonConvert.DeserializeObject<JObject>(str);
  151. if ((bool)model["success"])
  152. {
  153. return model["data"];
  154. }
  155. throw Oops.Oh(model["message"].ToString());
  156. }
  157. /// <summary>
  158. /// 查询服装底库详情
  159. /// </summary>
  160. /// <param name="clothSetId">服装库Id</param>
  161. /// <returns></returns>
  162. public async Task<dynamic> GetInfo(string clothSetId)
  163. {
  164. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  165. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/cloth/set/query-detail"
  166. .SetBody(new
  167. {
  168. token = _deepelephManager.GetToken(),
  169. tenantCode = appSettings.TenantCode,
  170. poiId = appSettings.PoiId,
  171. clothSetId = clothSetId
  172. })
  173. .SetContentType("application/json")
  174. .PostAsAsync<string>();
  175. var model = JsonConvert.DeserializeObject<JObject>(str);
  176. if ((bool)model["success"])
  177. {
  178. return model["data"];
  179. }
  180. throw Oops.Oh(model["message"].ToString());
  181. }
  182. /// <summary>
  183. /// 服装图片上传
  184. /// </summary>
  185. /// <param name="input"></param>
  186. /// <returns></returns>
  187. public async Task<dynamic> UploadFile([FromForm] BaseFileInput input)
  188. {
  189. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  190. var jsonparam = JsonConvert.SerializeObject(new
  191. {
  192. token = _deepelephManager.GetToken(),
  193. tenantCode = appSettings.TenantCode,
  194. poiId = appSettings.PoiId,
  195. usageScenario = "staff"
  196. });
  197. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/common/upload-file"
  198. .SetFiles(HttpFile.Create("file", input.File.OpenReadStream(), input.File.FileName))
  199. .SetBody(new
  200. {
  201. param = jsonparam
  202. })
  203. .SetContentType("multipart/form-data")
  204. .PostAsAsync<string>();
  205. var model = JsonConvert.DeserializeObject<JObject>(str);
  206. if ((bool)model["success"])
  207. {
  208. return model["data"]["httpUrl"].ToString();
  209. }
  210. throw Oops.Oh(model["message"].ToString());
  211. }
  212. /// <summary>
  213. /// 新增服装
  214. /// </summary>
  215. /// <param name="info"></param>
  216. /// <returns></returns>
  217. public async Task<dynamic> AddClothA(ClothInfos info)
  218. {
  219. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  220. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/cloth/add"
  221. .SetBody(new
  222. {
  223. token = _deepelephManager.GetToken(),
  224. tenantCode = appSettings.TenantCode,
  225. poiId = appSettings.PoiId,
  226. info.clothSetId,
  227. info.clothUrl
  228. })
  229. .SetContentType("application/json")
  230. .PostAsAsync<string>();
  231. var model = JsonConvert.DeserializeObject<JObject>(str);
  232. if ((bool)model["success"])
  233. {
  234. return model["data"];
  235. }
  236. throw Oops.Oh(model["message"].ToString());
  237. }
  238. /// <summary>
  239. /// 删除服装
  240. /// </summary>
  241. /// <returns></returns>
  242. [HttpPost]
  243. public async Task<dynamic> DeleteClothD(ClothInfos info)
  244. {
  245. var list = new List<string>();
  246. if (info.clothId.Contains(","))
  247. {
  248. list = info.clothId.Split(",").ToList();
  249. }
  250. else
  251. {
  252. list.Add(info.clothId);
  253. }
  254. foreach (var ids in list)
  255. {
  256. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  257. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/cloth/delete"
  258. .SetBody(new
  259. {
  260. token = _deepelephManager.GetToken(),
  261. tenantCode = appSettings.TenantCode,
  262. poiId = appSettings.PoiId,
  263. info.clothSetId,
  264. clothId= ids
  265. })
  266. .SetContentType("application/json")
  267. .PostAsAsync<string>();
  268. //var model = JsonConvert.DeserializeObject<JObject>(str);
  269. //if ((bool)model["success"])
  270. //{
  271. // return model["data"];
  272. //}
  273. //throw Oops.Oh(model["message"].ToString());
  274. }
  275. return true;
  276. }
  277. }