/// <summary> /// 根据供应商名称获取供应商信息 /// </summary> /// <param name="companyName">供应商名称</param> public Result <Base_Company> GetCompanyByName(string companyName) { Result <Base_Company> result = new Result <Base_Company>(); BasicDataContext baseDB = new BasicDataContext(); try { var model = DataOperateBasic <Base_Company> .Get(baseDB).GetList(t => t.Name == companyName).FirstOrDefault(); result.Data = model; result.Flag = EResultFlag.Success; } catch (Exception ex) { result.Data = null; result.Flag = EResultFlag.Failure; result.Exception = new ExceptionEx(ex, "GetCompanyByName"); } finally { if (baseDB.Database.Connection.State == ConnectionState.Closed) { baseDB.Database.Connection.Dispose(); } } return(result); }
/// <summary> /// 获取企业列表 /// </summary> /// <param name="qc"></param> /// <returns></returns> public Result <List <Base_Company> > GetCompanyListByType(QueryCondition qc) { qc = AddDefault(qc); Result <List <Base_Company> > result = new Result <List <Base_Company> >(); try { using (BasicDataContext baseDataContext = new BasicDataContext()) { result = DataOperate.QueryListSimple <Base_Company>(baseDataContext, qc); if (result.Flag == EResultFlag.Success && result.Data != null && result.Data.Any()) { string[] regionCodes = result.Data.Where(p => !string.IsNullOrWhiteSpace(p.Address)) .Select(p => p.Address.Split(',').LastOrDefault()).Distinct().ToArray(); if (regionCodes.Any()) { var regionModels = baseDataContext.Base_Region.Where(p => regionCodes.Contains(p.RegionCode)) .ToDictionary(p => p.RegionCode, p => p.Fullname); if (regionModels.Any()) { result.Data.ForEach(p => { if (!string.IsNullOrWhiteSpace(p.Address)) { string regeionCode = p.Address.Split(',').LastOrDefault(); if (regionModels.Keys.Contains(regeionCode)) { p.RegionName = regionModels[regeionCode]; } } }); } } } } } catch (Exception ex) { result.Data = null; result.Flag = EResultFlag.Failure; result.Exception = new ExceptionEx(ex, "GetCompanyListByType"); } return(result); }
/// <summary> /// 获取用户列表 /// </summary> /// <param name="qc"></param> /// <returns></returns> public Result <List <Base_User> > GetUserList(QueryCondition qc) { qc = AddDefault(qc); Result <List <Base_User> > result = new Result <List <Base_User> >(); try { using (BasicDataContext baseDataContext = new BasicDataContext()) { result = DataOperate.QueryListSimple <Base_User>(baseDataContext, qc); } } catch (Exception ex) { result.Data = null; result.Flag = EResultFlag.Failure; result.Exception = new ExceptionEx(ex, "GetUserList"); } return(result); }
/// <summary> /// 人脸注册 /// </summary> /// <param name="userId"></param> /// <param name="image"></param> /// <param name="source"></param> /// <returns></returns> public Result <int> AddAIUserFaceInfo(long userId, string image, string source) { Result <int> resultObj = new Result <int>(); resultObj.Data = -1; BasicDataContext basedb = new BasicDataContext(); BusinessDataContext busdb = new BusinessDataContext(); try { var imageType = "BASE64"; var groupId = "group1"; string control = "LOW"; image = image.Substring(image.IndexOf(",") + 1); //将‘,’以前的多余字符串删除 // 如果有可选参数 var options = new Dictionary <string, object> { { "quality_control", control }, { "liveness_control", control } }; Face client = GetFacaClient(); JObject result = new JObject(); //人脸管理 EPM_AIUserFace userFaceAI = new EPM_AIUserFace(); //人脸日志表 EPM_FaceOperateLog faceLog = new EPM_FaceOperateLog(); //查询用户详情 var userResult = DataOperateBasic <Base_User> .Get(basedb).GetModel(userId); //查询该用户是否已经注册的人脸信息 userFaceAI = DataOperateBusiness <EPM_AIUserFace> .Get(busdb).GetList(t => t.UserId == userId).FirstOrDefault(); //已存在人脸更新现有数据 //是否已经存在人脸 bool isExitsUserFace = false; //是否添加人脸 bool isAddFace = false; if (userFaceAI != null && userFaceAI.IsSuccess) { faceLog.APIType = FaceOperate.Update.ToString(); isExitsUserFace = true; } else //不存在添加新数据 { isAddFace = true; faceLog.APIType = FaceOperate.Add.ToString(); if (userFaceAI == null) { userFaceAI = new EPM_AIUserFace(); isExitsUserFace = false; } else { isExitsUserFace = true; } userFaceAI.IsSuccess = true; userFaceAI.UserId = userId; userFaceAI.UserName = userResult.UserName; userFaceAI.UserPhone = userResult.Phone; userFaceAI.ImageBase64 = "data:image/jpeg;base64," + image; userFaceAI.ImageType = imageType; userFaceAI.GroupId = groupId; userFaceAI.LivenessControl = control; userFaceAI.QualityControl = control; userFaceAI.Source = source; } //日志 var requestJson = new { imageType = imageType, groupId = groupId, control = control, userId = userId, options = new { quality_control = control, liveness_control = control } }; faceLog.ModelId = userFaceAI.Id; faceLog.RequestJson = requestJson.ToString(); faceLog = SetCurrentUser(faceLog); try { if (isAddFace) { result = client.UserAdd(image, imageType, groupId, userId.ToString(), options); } else { result = client.UserUpdate(image, imageType, groupId, userId.ToString(), options); } userFaceAI.LogId = result["log_id"].ToString(); if (result["error_code"].ToString() == "0" && result["error_msg"].ToString() == "SUCCESS") { var result_list = Newtonsoft.Json.JsonConvert.DeserializeObject(result["result"].ToString()) as JObject; var result_location = Newtonsoft.Json.JsonConvert.DeserializeObject(result_list["location"].ToString()) as JObject; userFaceAI.FaceToken = result_list["face_token"].ToString(); userFaceAI.Left = Convert.ToDecimal(result_location["left"]); userFaceAI.Top = Convert.ToDecimal(result_location["top"]); userFaceAI.Width = Convert.ToDecimal(result_location["width"]); userFaceAI.Height = Convert.ToDecimal(result_location["height"]); userFaceAI.Rotation = result_location["rotation"].ToString(); userFaceAI.Location = result_list["location"].ToString(); userFaceAI.IsSuccess = true; userFaceAI = SetCurrentUser(userFaceAI); faceLog.IsSuccess = true; resultObj.Data = 1; } else { faceLog.IsSuccess = false; userFaceAI.IsSuccess = false; } } catch (Exception) { faceLog.IsSuccess = false; userFaceAI.IsSuccess = false; } faceLog.ResponseJson = result.ToString(); if (isExitsUserFace) { DataOperateBusiness <EPM_AIUserFace> .Get(busdb).Update(userFaceAI); } else { DataOperateBusiness <EPM_AIUserFace> .Get(busdb).Add(userFaceAI); } DataOperateBusiness <EPM_FaceOperateLog> .Get(busdb).Add(faceLog); resultObj.Flag = EResultFlag.Success; } catch (Exception ex) { resultObj.Data = -1; resultObj.Flag = EResultFlag.Failure; resultObj.Exception = new ExceptionEx(ex, "AddAIUserFaceInfo"); } finally { if (basedb.Database.Connection.State != ConnectionState.Closed) { basedb.Database.Connection.Close(); basedb.Database.Connection.Dispose(); } if (busdb.Database.Connection.State != ConnectionState.Closed) { busdb.Database.Connection.Close(); busdb.Database.Connection.Dispose(); } } return(resultObj); }
/// <summary> /// 人脸搜索 /// </summary> /// <param name="model"></param> /// <returns></returns> public Result <int> SearchUserFace(SignFaceAI model) { BasicDataContext basedb = new BasicDataContext(); BusinessDataContext busdb = new BusinessDataContext(); Result <int> resultObj = new Result <int>(); resultObj.Data = -1; try { //查询用户是否注册人脸信息 var userFaceList = DataOperateBusiness <EPM_AIUserFace> .Get(busdb).GetList(t => t.UserId == model.UserId); if (!userFaceList.Any()) { throw new Exception("您还没有注册人脸识别信息!"); } else { var imageType = "BASE64"; var groupIdList = "group1"; string control = "LOW"; model.Image = model.Image.Substring(model.Image.IndexOf(",") + 1); //将‘,’以前的多余字符串删除 var options = new Dictionary <string, object> { { "quality_control", control }, { "liveness_control", control }, { "user_id", model.UserId.ToString() } }; //签到表 Epm_SignInformation modelSign = new Epm_SignInformation(); //人脸日志表 EPM_FaceOperateLog faceLog = new EPM_FaceOperateLog(); Base_User userModel = DataOperateBasic <Base_User> .Get(basedb).GetModel(model.UserId.Value); List <Epm_ProjectCompany> proComList = DataOperateBusiness <Epm_ProjectCompany> .Get(busdb).GetList(t => t.ProjectId == model.ProjectId && (t.PMId == model.UserId || t.LinkManId == model.UserId || t.SafeManId == model.UserId)).ToList(); string type = ""; if (proComList.Any()) { type = string.Join(",", proComList.Select(t => t.Type)); } modelSign.userId = model.UserId; modelSign.userName = userModel.UserName; modelSign.projectId = model.ProjectId; modelSign.projectName = model.ProjectName; modelSign.Latitude = model.Latitude; modelSign.Longitude = model.Longitude; modelSign.gasstationName = model.OilStationName; modelSign.jobInfo = userModel.Post ?? ""; modelSign.type = type; modelSign.picStrength = model.Image; modelSign.SignTime = DateTime.Now; //日志 var requestJson = new { imageType = imageType, groupId = groupIdList, options = new { quality_control = control, liveness_control = control, user_id = model.UserId } }; faceLog.ModelId = modelSign.Id; faceLog.APIType = FaceOperate.Search.ToString(); faceLog.RequestJson = requestJson.ToString(); JObject result = new JObject(); Face client = GetFacaClient(); try { // 带参数调用人脸识别 result = client.Search(model.Image, imageType, groupIdList, options); } catch (Exception) { modelSign.SignResult = SignRes.Other.ToString(); } if (result["error_code"].ToString() == "0" && result["error_msg"].ToString() == "SUCCESS") { var result_list = Newtonsoft.Json.JsonConvert.DeserializeObject(result["result"].ToString()) as JObject; var user_list = result_list["user_list"]; var Obj = JArray.Parse(user_list.ToString()); foreach (var item in Obj) { //80分以上可以判断为同一人,此分值对应万分之一误识率 var score = Convert.ToInt32(item["score"]); if (score > 80) { modelSign.SignResult = SignRes.Success.ToString(); faceLog.IsSuccess = true; resultObj.Data = 1; resultObj.Flag = EResultFlag.Success; } else { modelSign.SignResult = SignRes.NoFace.ToString(); faceLog.IsSuccess = false; } } } else { modelSign.SignResult = SignRes.Fail.ToString(); } faceLog.ResponseJson = result.ToString(); faceLog = SetCurrentUser(faceLog); DataOperateBusiness <EPM_FaceOperateLog> .Get(busdb).Add(faceLog); var rows = DataOperateBusiness <Epm_SignInformation> .Get(busdb).Add(modelSign); if (rows > 0) { resultObj.Flag = EResultFlag.Success; } } } catch (Exception ex) { resultObj.Data = -1; resultObj.Flag = EResultFlag.Failure; resultObj.Exception = new ExceptionEx(ex, "SearchUserFace"); } finally { if (basedb.Database.Connection.State != ConnectionState.Closed) { basedb.Database.Connection.Close(); basedb.Database.Connection.Dispose(); } if (busdb.Database.Connection.State != ConnectionState.Closed) { busdb.Database.Connection.Close(); busdb.Database.Connection.Dispose(); } } return(resultObj); }
/// <summary> /// 发送短信 /// </summary> /// <param name="receiveId"></param> /// <param name="step"></param> /// <param name="parameters"></param> /// <returns></returns> public Result <int> AddSMS(long sendId, long sendCompanyId, long receiveId, long receiveCompanyId, MessageStep step, Dictionary <string, string> parameters) { Result <int> result = new Result <int>(); try { using (MsgDataContext db = new MsgDataContext()) { //查找模板 var templete = db.Msg_SMSTemplete.FirstOrDefault(i => i.Step == step.ToString() && i.IsConfirm && i.IsEnable); if (templete != null) { Msg_SMS model = new Msg_SMS(); string con = templete.TemplateCon; if (parameters != null && parameters.Any()) { //替换内容参数 foreach (var item in parameters) { con = con.Replace("{" + item.Key + "}", item.Value); } } BasicDataContext basicData = new BasicDataContext(); var receive = basicData.Base_User.FirstOrDefault(i => i.Id == receiveId); model.ReceivePhone = receive.Phone; model.ReceiveId = receiveId; model.SenderId = sendId; model.SendeCompanyId = sendCompanyId; model.ReceiveCompanyId = receiveCompanyId; model.SenderPhone = ""; model.SenderTime = null; model.SmsCon = con; model.State = false; model.SubmissionTime = DateTime.Now; model.Step = step.ToString(); model.TemplateId = templete.Id; model.ServerNo = templete.ServerNo; model.Params = UtilitySendMessage.CreateSmsParam(parameters).Data; model.SignName = templete.SignName; db.Msg_SMS.Add(model); var rows = db.SaveChanges(); result.Data = rows; result.Flag = EResultFlag.Success; //WriteLog(AdminModule.SMSHistory.GetText(), SystemRight.Add.GetText(), "新增短信:" + model.Id + ":" + model.SmsCon); } else { throw new Exception("未查找到短信模板"); } } } catch (Exception ex) { result.Data = -1; result.Flag = EResultFlag.Failure; result.Exception = new ExceptionEx(ex, "AddSMS"); } return(result); }
/// <summary> /// 发送邮件,TODO:扩展附件方法 /// </summary> /// <param name="receiveId"></param> /// <param name="step"></param> /// <param name="parameters"></param> /// <returns></returns> public Result <int> AddEmail(long sendId, long sendCompanyId, long receiveId, long receiveCompanyId, MessageStep step, Dictionary <string, string> parameters) { Result <int> result = new Result <int>(); try { using (MsgDataContext db = new MsgDataContext()) { //查找模板 var templete = db.Msg_EmailTemplete.FirstOrDefault(i => i.Step == step.ToString() && i.IsConfirm && i.IsEnable); if (templete != null) { Msg_Email model = new Msg_Email(); string con = templete.TemplateCon; string title = templete.TitleCon; if (parameters != null && parameters.Any()) { //替换标题和内容参数 foreach (var item in parameters) { con = con.Replace("{" + item.Key + "}", item.Value); title = title.Replace("{" + item.Key + "}", item.Value); } } BasicDataContext basicData = new BasicDataContext(); model.EmailCon = con; model.ReceiveId = receiveId; model.ReceiveEmaile = basicData.Base_User.FirstOrDefault(i => i.Id == model.ReceiveId).Email; model.SenderId = sendId; model.SenderEmail = db.Msg_EmailSetting.FirstOrDefault(i => i.IsConfirm && i.IsEnable).UserName; model.SendeCompanyId = sendCompanyId; model.ReceiveCompanyId = receiveCompanyId; model.State = false; model.Step = step.ToString(); model.TemplateId = templete.Id; model.Title = title; model.SenderTime = null; model.SubmissionTime = DateTime.Now; model.SendCount = 0; db.Msg_Email.Add(model); var rows = db.SaveChanges(); result.Data = rows; result.Flag = EResultFlag.Success; //WriteLog(AdminModule.EmailHistory.GetText(), SystemRight.Add.GetText(), "新增邮件:" + model.Id + ":" + model.Title); } else { throw new Exception("未查找到对应邮件模板"); } } } catch (Exception ex) { result.Data = -1; result.Flag = EResultFlag.Failure; result.Exception = new ExceptionEx(ex, "AddEmail"); } return(result); }
/// <summary> /// 根据企业 ID 获取企业详情 /// </summary> /// <param name="id">企业 ID</param> public Result <CompanyView> GetCompanyModel(long id) { Result <CompanyView> result = new Result <CompanyView>(); BasicDataContext baseDB = new BasicDataContext(); try { var viewModel = new CompanyView(); var model = DataOperateBasic <Base_Company> .Get(baseDB).GetModel(id); if (model != null) { viewModel.Id = model.Id; viewModel.PId = model.PId; viewModel.PreCode = model.PreCode; viewModel.PreName = model.PreName; viewModel.Type = model.Type; viewModel.Code = model.Code; viewModel.Name = model.Name; viewModel.ShortName = model.ShortName; viewModel.FaxPhone = model.FaxPhone; viewModel.Email = model.Email; viewModel.Address = model.Address; viewModel.AddressInfo = model.AddressInfo; viewModel.Remark = model.Remark; viewModel.Phone = model.Phone; viewModel.LinkManId = model.LinkManId; viewModel.LinkMan = model.LinkMan; viewModel.LinkPhone = model.LinkPhone; viewModel.OrgType = model.OrgType; viewModel.AddressName = model.AddressName; viewModel.IsBlacklist = model.IsBlacklist; viewModel.CompanyType = model.CompanyType; viewModel.CompanyRank = model.CompanyRank; viewModel.CompanyTypeName = model.CompanyTypeName; viewModel.CompanyRankName = model.CompanyRankName; if (!string.IsNullOrWhiteSpace(model.Address)) { string[] codes = model.Address.Split(','); string code = codes[codes.Length - 1]; var regionModel = DataOperateBasic <Base_Region> .Get(baseDB).Single(i => i.RegionCode == code); if (regionModel != null) { viewModel.RegionName = regionModel.Fullname; } var file = DataOperateBasic <Base_Files> .Get(baseDB).Single(p => p.TableName == "Base_Company" && p.TableId == model.Id); if (file != null) { viewModel.Logo = file.Url; } } var attachsList = GetFilesByTable("Base_Company", model.Id).Data;//根据表名和id获取附件信息 if (attachsList != null && attachsList.Any()) { List <Base_Files> fileList = new List <Base_Files>(); foreach (var item in attachsList) { //转换 var noToName = DataOperateBasic <Base_TypeDictionary> .Get().Single(p => p.No == item.TableColumn).Name; item.TypeName = noToName; fileList.Add(item); } viewModel.baseFiles = fileList; } } result.Data = viewModel; result.Flag = EResultFlag.Success; } catch (Exception ex) { result.Data = null; result.Flag = EResultFlag.Failure; result.Exception = new ExceptionEx(ex, "GetCompanyModel"); } finally { if (baseDB.Database.Connection.State == ConnectionState.Closed) { baseDB.Database.Connection.Dispose(); } } return(result); }