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

KeyPersonnelController.cs 12 KiB

4 months ago
4 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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.Person;
  7. namespace SafeCampus.Web.Core.Controllers.Application.Business;
  8. /// <summary>
  9. /// 重点人员库接口
  10. /// </summary>
  11. [ApiDescriptionSettings(ApiGroupConsts.SYSTEM_Business, Order = 88, Tag = "重点人员库")]
  12. [Route("/business/keyPersonnel")]
  13. [RolePermission]
  14. public class KeyPersonnelController
  15. {
  16. private readonly IDeepelephManager _deepelephManager;
  17. public KeyPersonnelController(IDeepelephManager deepelephManager)
  18. {
  19. _deepelephManager = deepelephManager;
  20. }
  21. /// <summary>
  22. /// 新增人员
  23. /// </summary>
  24. /// <param name="info">人员信息</param>
  25. /// <returns></returns>
  26. public async Task<dynamic> CreatePersonA(PersonModel info)
  27. {
  28. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  29. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/create"
  30. .SetBody(new
  31. {
  32. token = _deepelephManager.GetToken(),
  33. tenantCode = appSettings.TenantCode,
  34. poiId = appSettings.PoiId,
  35. personId = Guid.NewGuid().ToString("N"),
  36. age = info.Age,
  37. name = info.Name,
  38. gender = info.Gender,
  39. phone = info.Phone,
  40. exData = info.ExData,
  41. faces = info.Faces
  42. })
  43. .SetContentType("application/json")
  44. .PostAsAsync<string>();
  45. var model = JsonConvert.DeserializeObject<JObject>(str);
  46. if ((bool)model["success"])
  47. {
  48. await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/set/bind"
  49. .SetBody(new
  50. {
  51. token = _deepelephManager.GetToken(),
  52. tenantCode = appSettings.TenantCode,
  53. poiId = appSettings.PoiId,
  54. personSetId = SafeCampusConst.ZDRY,
  55. personIds = new List<string> { model["data"].ToString() }
  56. })
  57. .SetContentType("application/json")
  58. .PostAsAsync<string>();
  59. //var model1 = JsonConvert.DeserializeObject<JObject>(str);
  60. //if ((bool)model1["success"])
  61. //{
  62. // return model["data"];
  63. //}
  64. return model["data"];
  65. }
  66. throw Oops.Oh(model["message"].ToString());
  67. }
  68. /// <summary>
  69. /// 人脸图片上传
  70. /// </summary>
  71. /// <param name="input"></param>
  72. /// <returns></returns>
  73. public async Task<dynamic> UploadFile([FromForm] BaseFileInput input)
  74. {
  75. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  76. var jsonparam = JsonConvert.SerializeObject(new
  77. {
  78. token = _deepelephManager.GetToken(),
  79. tenantCode = appSettings.TenantCode,
  80. poiId = appSettings.PoiId,
  81. usageScenario = "personSet"
  82. });
  83. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/common/upload-file"
  84. .SetFiles(HttpFile.Create("file", input.File.OpenReadStream(), input.File.FileName))
  85. .SetBody(new
  86. {
  87. param = jsonparam
  88. })
  89. .SetContentType("multipart/form-data")
  90. .PostAsAsync<string>();
  91. var model = JsonConvert.DeserializeObject<JObject>(str);
  92. if ((bool)model["success"])
  93. {
  94. var strCheck = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/faceQuality/check"
  95. .SetBody(new
  96. {
  97. token = _deepelephManager.GetToken(),
  98. tenantCode = appSettings.TenantCode,
  99. poiId = appSettings.PoiId,
  100. faceSizeLimit = 60,
  101. qualityScore = 30,
  102. faceUrl = model["data"]["httpUrl"].ToString()
  103. })
  104. .SetContentType("application/json")
  105. .PostAsAsync<string>();
  106. var modelCheck = JsonConvert.DeserializeObject<JObject>(strCheck);
  107. if ((bool)modelCheck["success"])
  108. {
  109. if ((bool)modelCheck["data"]["pass"])
  110. {
  111. return model["data"]["httpUrl"].ToString();
  112. }
  113. throw Oops.Oh(modelCheck["data"]["message"].ToString());
  114. }
  115. else
  116. {
  117. throw Oops.Oh("人脸效验失败!");
  118. }
  119. }
  120. throw Oops.Oh(model["message"].ToString());
  121. }
  122. /// <summary>
  123. /// 删除人员
  124. /// </summary>
  125. /// <param name="personId"></param>
  126. /// <returns></returns>
  127. public async Task<dynamic> DeletePersonD(string id)
  128. {
  129. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  130. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/delete"
  131. .SetBody(new
  132. {
  133. token = _deepelephManager.GetToken(),
  134. tenantCode = appSettings.TenantCode,
  135. poiId = appSettings.PoiId,
  136. personId = id,
  137. })
  138. .SetContentType("application/json")
  139. .PostAsAsync<string>();
  140. var model = JsonConvert.DeserializeObject<JObject>(str);
  141. if ((bool)model["success"])
  142. {
  143. return model["data"].ToString() == id;
  144. }
  145. throw Oops.Oh(model["message"].ToString());
  146. }
  147. /// <summary>
  148. /// 更新人员信息,如果人员不存在,则创建人员;如果人员存在,则覆盖信息。
  149. /// </summary>
  150. /// <param name="info"></param>
  151. /// <returns></returns>
  152. public async Task<dynamic> UpdatePersionU(PersonModel info)
  153. {
  154. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  155. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/createOrOverride"
  156. .SetBody(new
  157. {
  158. token = _deepelephManager.GetToken(),
  159. tenantCode = appSettings.TenantCode,
  160. poiId = appSettings.PoiId,
  161. personId = info.PersonId,
  162. age = info.Age,
  163. name = info.Name,
  164. gender = info.Gender,
  165. phone = info.Phone,
  166. exData = info.ExData,
  167. faces = info.Faces
  168. })
  169. .SetContentType("application/json")
  170. .PostAsAsync<string>();
  171. var model = JsonConvert.DeserializeObject<JObject>(str);
  172. if ((bool)model["success"])
  173. {
  174. return model["data"];
  175. }
  176. throw Oops.Oh(model["message"].ToString());
  177. }
  178. /// <summary>
  179. /// 分页查询人员信息
  180. /// </summary>
  181. /// <param name="search">查询条件</param>
  182. /// <returns></returns>
  183. public async Task<dynamic> PageQuery(PersonSearch search)
  184. {
  185. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  186. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/pageQuery"
  187. .SetBody(new
  188. {
  189. token = _deepelephManager.GetToken(),
  190. tenantCode = appSettings.TenantCode,
  191. poiId = appSettings.PoiId,
  192. personSetId =SafeCampusConst.ZDRY,
  193. personId = search.PersonId,
  194. personName = search.PersonName,
  195. pageIndex = search.PageNum,
  196. pageSize = search.PageSize,
  197. })
  198. .SetContentType("application/json")
  199. .PostAsAsync<string>();
  200. var model = JsonConvert.DeserializeObject<JObject>(str);
  201. if (!(bool)model["success"]) throw Oops.Oh(model["message"].ToString());
  202. if (model["data"] != null)
  203. {
  204. return new
  205. {
  206. pageNum = search.PageNum,
  207. pageSize = model["pageSize"],
  208. total = model["totalCount"],
  209. pages = model["pageIndex"],
  210. list = model["data"]
  211. };
  212. }
  213. return new
  214. {
  215. pageNum = search.PageNum,
  216. pageSize = 0,
  217. total = 0,
  218. pages = 0,
  219. list = new List<string>()
  220. };
  221. }
  222. /// <summary>
  223. /// 查看人员详情
  224. /// </summary>
  225. /// <param name="personId">人员id</param>
  226. /// <returns></returns>
  227. public async Task<dynamic> GetPersionById(ControllersIdInput input)
  228. {
  229. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  230. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/query"
  231. .SetBody(new
  232. {
  233. token = _deepelephManager.GetToken(),
  234. tenantCode = appSettings.TenantCode,
  235. poiId = appSettings.PoiId,
  236. personId = input.Id,
  237. })
  238. .SetContentType("application/json")
  239. .PostAsAsync<string>();
  240. var model = JsonConvert.DeserializeObject<JObject>(str);
  241. if ((bool)model["success"])
  242. {
  243. if (model["data"]["personSets"].Count() > 0)
  244. {
  245. model["data"]["personSetId"] = model["data"]["personSets"][0]["personSetId"];
  246. model["data"]["personSetName"] = model["data"]["personSets"][0]["personSetName"];
  247. }
  248. else
  249. {
  250. model["data"]["personSetId"] = null;
  251. model["data"]["personSetName"] = null;
  252. }
  253. return model["data"];
  254. }
  255. throw Oops.Oh(model["message"].ToString());
  256. }
  257. /// <summary>
  258. /// 添加人脸
  259. /// </summary>
  260. /// <param name="info">人脸信息</param>
  261. /// <returns></returns>
  262. public async Task<dynamic> AddFaceA(PersonFaceInfo info)
  263. {
  264. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  265. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/addFace"
  266. .SetBody(new
  267. {
  268. token = _deepelephManager.GetToken(),
  269. tenantCode = appSettings.TenantCode,
  270. poiId = appSettings.PoiId,
  271. personId = info.PersonId,
  272. info.faceSizeLimit,
  273. info.qualityScore,
  274. faces = new List<Faces>
  275. {
  276. new Faces
  277. {
  278. faceUrl = info.faceUrl,
  279. faceId=Guid.NewGuid().ToString("N"),
  280. }
  281. }
  282. })
  283. .SetContentType("application/json")
  284. .PostAsAsync<string>();
  285. var model = JsonConvert.DeserializeObject<JObject>(str);
  286. if ((bool)model["success"])
  287. {
  288. return true;
  289. }
  290. throw Oops.Oh(model["message"].ToString());
  291. }
  292. /// <summary>
  293. /// 删除人脸
  294. /// </summary>
  295. /// <param name="info">删除信息</param>
  296. /// <returns></returns>
  297. [HttpPost]
  298. public async Task<dynamic> DeleteFaceD(PersonFaceDel info)
  299. {
  300. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  301. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/removeFace"
  302. .SetBody(new
  303. {
  304. token = _deepelephManager.GetToken(),
  305. tenantCode = appSettings.TenantCode,
  306. poiId = appSettings.PoiId,
  307. info.personId,
  308. info.faceIds
  309. })
  310. .SetContentType("application/json")
  311. .PostAsAsync<string>();
  312. var model = JsonConvert.DeserializeObject<JObject>(str);
  313. if ((bool)model["success"])
  314. {
  315. return true;
  316. }
  317. throw Oops.Oh(model["message"].ToString());
  318. }
  319. }