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

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