using MoYu.FriendlyException;
using MoYu.RemoteRequest;
using MoYu.RemoteRequest.Extensions;
using Newtonsoft.Json.Linq;
using SafeCampus.Application.Manager.DeepelephManager;
using SafeCampus.Application.Services.Business.PersonFacesService;
using SafeCampus.Application.Services.Business.PersonInfoService;
using SafeCampus.Web.Core.Controllers.Application.Business.Dto.Person;
namespace SafeCampus.Web.Core.Controllers.Application.Business;
///
/// 重点人员库接口
///
[ApiDescriptionSettings(ApiGroupConsts.SYSTEM_Business, Order = 88, Tag = "重点人员库")]
[Route("/business/keyPersonnel")]
[RolePermission]
public class KeyPersonnelController
{
private readonly IDeepelephManager _deepelephManager;
private readonly IPersonInfoService _personInfoService;
private readonly IPersonFacesService _personFacesService;
public KeyPersonnelController(IDeepelephManager deepelephManager, IPersonInfoService personInfoService, IPersonFacesService personFacesService)
{
_deepelephManager = deepelephManager;
_personInfoService = personInfoService;
_personFacesService = personFacesService;
}
///
/// 新增人员
///
/// 人员信息
///
public async Task CreatePersonA(PersonModel info)
{
var appSettings = App.GetOptionsMonitor();
var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/create"
.SetBody(new
{
token = _deepelephManager.GetToken(),
tenantCode = appSettings.TenantCode,
poiId = appSettings.PoiId,
personId = Guid.NewGuid().ToString("N"),
age = info.Age,
name = info.Name,
gender = info.Gender,
phone = info.Phone,
exData = info.ExData,
faces = info.Faces
})
.SetContentType("application/json")
.PostAsAsync();
var model = JsonConvert.DeserializeObject(str);
if ((bool)model["success"])
{
await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/set/bind"
.SetBody(new
{
token = _deepelephManager.GetToken(),
tenantCode = appSettings.TenantCode,
poiId = appSettings.PoiId,
personSetId = SafeCampusConst.ZDRY,
personIds = new List { model["data"].ToString() }
})
.SetContentType("application/json")
.PostAsAsync();
//var model1 = JsonConvert.DeserializeObject(str);
//if ((bool)model1["success"])
//{
// return model["data"];
//}
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 = "personSet"
});
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"])
{
var strCheck = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/faceQuality/check"
.SetBody(new
{
token = _deepelephManager.GetToken(),
tenantCode = appSettings.TenantCode,
poiId = appSettings.PoiId,
faceSizeLimit = 60,
qualityScore = 30,
faceUrl = model["data"]["httpUrl"].ToString()
})
.SetContentType("application/json")
.PostAsAsync();
var modelCheck = JsonConvert.DeserializeObject(strCheck);
if ((bool)modelCheck["success"])
{
if ((bool)modelCheck["data"]["pass"])
{
return model["data"]["httpUrl"].ToString();
}
throw Oops.Oh(modelCheck["data"]["message"].ToString());
}
else
{
throw Oops.Oh("人脸效验失败!");
}
}
throw Oops.Oh(model["message"].ToString());
}
///
/// 删除人员
///
///
///
public async Task DeletePersonD(string id)
{
var list = new List();
if (id.Contains(","))
{
list = id.Split(",").ToList();
}
else
{
list.Add(id);
}
foreach (var ids in list)
{
var appSettings = App.GetOptionsMonitor();
var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/delete"
.SetBody(new
{
token = _deepelephManager.GetToken(),
tenantCode = appSettings.TenantCode,
poiId = appSettings.PoiId,
personId = ids,
})
.SetContentType("application/json")
.PostAsAsync();
//var model = JsonConvert.DeserializeObject(str);
//if ((bool)model["success"])
//{
// var isOk = model["data"].ToString() == ids;
// if (isOk)
// {
// await _personInfoService.Delete(ids);
// }
// //return model["data"].ToString() == id;
//}
//throw Oops.Oh(model["message"].ToString());
}
return true;
}
///
/// 更新人员信息,如果人员不存在,则创建人员;如果人员存在,则覆盖信息。
///
///
///
public async Task UpdatePersionU(PersonModel info)
{
var appSettings = App.GetOptionsMonitor();
var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/createOrOverride"
.SetBody(new
{
token = _deepelephManager.GetToken(),
tenantCode = appSettings.TenantCode,
poiId = appSettings.PoiId,
personId = info.PersonId,
age = info.Age,
name = info.Name,
gender = info.Gender,
phone = info.Phone,
exData = info.ExData,
faces = info.Faces
})
.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 PageQuery(PersonSearch search)
{
var appSettings = App.GetOptionsMonitor();
var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/pageQuery"
.SetBody(new
{
token = _deepelephManager.GetToken(),
tenantCode = appSettings.TenantCode,
poiId = appSettings.PoiId,
personSetId =SafeCampusConst.ZDRY,
personId = search.PersonId,
personName = search.PersonName,
pageIndex = search.PageNum,
pageSize = search.PageSize,
})
.SetContentType("application/json")
.PostAsAsync();
var model = JsonConvert.DeserializeObject(str);
if (!(bool)model["success"]) throw Oops.Oh(model["message"].ToString());
if (model["data"] != null)
{
return new
{
pageNum = search.PageNum,
pageSize = model["pageSize"],
total = model["totalCount"],
pages = model["pageIndex"],
list = model["data"]
};
}
return new
{
pageNum = search.PageNum,
pageSize = 0,
total = 0,
pages = 0,
list = new List()
};
}
///
/// 查看人员详情
///
/// 人员id
///
public async Task GetPersionById(ControllersIdInput input)
{
var appSettings = App.GetOptionsMonitor();
var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/query"
.SetBody(new
{
token = _deepelephManager.GetToken(),
tenantCode = appSettings.TenantCode,
poiId = appSettings.PoiId,
personId = input.Id,
})
.SetContentType("application/json")
.PostAsAsync();
var model = JsonConvert.DeserializeObject(str);
if ((bool)model["success"])
{
if (model["data"]["personSets"].Count() > 0)
{
model["data"]["personSetId"] = model["data"]["personSets"][0]["personSetId"];
model["data"]["personSetName"] = model["data"]["personSets"][0]["personSetName"];
}
else
{
model["data"]["personSetId"] = null;
model["data"]["personSetName"] = null;
}
return model["data"];
}
throw Oops.Oh(model["message"].ToString());
}
///
/// 添加人脸
///
/// 人脸信息
///
public async Task AddFaceA(PersonFaceInfo info)
{
var appSettings = App.GetOptionsMonitor();
var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/addFace"
.SetBody(new
{
token = _deepelephManager.GetToken(),
tenantCode = appSettings.TenantCode,
poiId = appSettings.PoiId,
personId = info.PersonId,
info.faceSizeLimit,
info.qualityScore,
faces = new List
{
new Faces
{
faceUrl = info.faceUrl,
faceId=Guid.NewGuid().ToString("N"),
}
}
})
.SetContentType("application/json")
.PostAsAsync();
var model = JsonConvert.DeserializeObject(str);
if ((bool)model["success"])
{
return true;
}
throw Oops.Oh(model["message"].ToString());
}
///
/// 删除人脸
///
/// 删除信息
///
[HttpPost]
public async Task DeleteFaceD(PersonFaceDel info)
{
var appSettings = App.GetOptionsMonitor();
var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/person/removeFace"
.SetBody(new
{
token = _deepelephManager.GetToken(),
tenantCode = appSettings.TenantCode,
poiId = appSettings.PoiId,
info.personId,
info.faceIds
})
.SetContentType("application/json")
.PostAsAsync();
var model = JsonConvert.DeserializeObject(str);
if ((bool)model["success"])
{
return true;
}
throw Oops.Oh(model["message"].ToString());
}
}