private void CODE_OPERTAE() { string EntityName = g_Context.Request["EntityName"]; string FormData = g_Context.Request["data"]; JObject tokens = JObject.Parse(FormData); IARES_ENTITY a = AresEntityFactory.MakeAresEntity(EntityName, tokens); string CODE = tokens["CODE"].ToString(); string sql = ""; if (CODE == "") { CODE = Snowflake.Instance().GetId().ToString(); tokens["CODE"] = CODE; sql = GetCodeInsertSql(EntityName, tokens); } else { sql = GetCodeUpdateSql(EntityName, tokens); } try { DbHelperSQL.ExecuteSql(sql); SendError sendError = new SendError("200", "数据操作成功", "auth_code"); Send(sendError); return; } catch (Exception e) { SendError sendError = new SendError("100", e.ToString(), "auth_code"); Send(sendError); return; } }
//[Authorize] public IActionResult AddRole([FromBody] RoleDto role) { var resultData = new ResultData(); if (!ModelState.IsValid) { return(BadRequest(role)); } try { var roleModel = _mapper.Map <Role>(role); roleModel.ID = Snowflake.Instance().GetId(); roleModel.CreateTime = DateTime.Now; roleModel.LastUpdateTime = DateTime.Now; _roleService.Insert(roleModel); log.Info($"添加成功"); resultData.Data = null; } catch (Exception ex) { resultData.State = Status.Fail.ToString(); resultData.Msg = "添加角色失败!"; log.Error($"添加菜单错误信息:{ex}"); } return(Ok(resultData)); }
public void Test() { for (int i = 0; i < 1000; i++) { var id = Snowflake.Instance().GetId(); Console.WriteLine( $"开始执行 {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffffff")} NO: {id} HashCode: {id.GetHashCode()}"); } }
protected override void OnModelCreating(ModelBuilder modelBuilder) { var gender = new EnumToNumberConverter <Gender, int>(); modelBuilder.Entity <Users>(a => { a.HasKey(b => b.ID); a.Property(b => b.UserName).HasMaxLength(50).IsRequired(); a.Property(b => b.Password).HasMaxLength(50).IsRequired(); a.Property(b => b.Genders).HasConversion(gender).IsRequired(); a.Property(b => b.LoginCount).HasDefaultValue(0).IsRequired(); a.Property(b => b.CreateTime); a.Property(b => b.LastUpdateTime).IsRequired(); a.Property(b => b.LoginCount).HasDefaultValue(0); a.Property(b => b.LookTime); }); var target = new EnumToNumberConverter <Target, int>(); modelBuilder.Entity <Menu>(a => { a.HasKey(b => b.ID); a.Property(b => b.Name).HasMaxLength(50).IsRequired(); a.Property(b => b.Iocn).HasMaxLength(50).IsRequired(); a.Property(b => b.Targets).HasConversion(target).IsRequired(); a.Property(b => b.ParentID).HasDefaultValue(0).IsRequired(); a.Property(b => b.IsDelete).HasDefaultValue(0).IsRequired(); a.Property(b => b.IsShow).HasDefaultValue(0).IsRequired(); a.Property(b => b.CreateTime); a.Property(b => b.LastUpdateTime).IsRequired(); }); modelBuilder.Entity <Role>(a => { a.HasKey(b => b.ID); a.Property(b => b.Name).HasMaxLength(50).IsRequired(); a.Property(b => b.MenuPermissionID).IsRequired(); a.Property(b => b.IsDelete).HasDefaultValue(0).IsRequired(); a.Property(b => b.CreateTime).IsRequired(); a.Property(b => b.LastUpdateTime).IsRequired(); }); modelBuilder.Entity <Users>().HasData( new Users { ID = Snowflake.Instance().GetId(), UserName = "******", Password = "******", Genders = Gender.Male, CreateTime = DateTime.Now, LastUpdateTime = DateTime.Now, Age = 31, LoginCount = 0 }, new Users { ID = Snowflake.Instance().GetId(), UserName = "******", Password = "******", Genders = Gender.Female, CreateTime = DateTime.Now, LastUpdateTime = DateTime.Now, Age = 21, LoginCount = 0 }, new Users { ID = Snowflake.Instance().GetId(), UserName = "******", Password = "******", Genders = Gender.Male, CreateTime = DateTime.Now, LastUpdateTime = DateTime.Now, Age = 18, LoginCount = 0 }, new Users { ID = Snowflake.Instance().GetId(), UserName = "******", Password = "******", Genders = Gender.Male, CreateTime = DateTime.Now, LastUpdateTime = DateTime.Now, Age = 25, LoginCount = 0 }, new Users { ID = Snowflake.Instance().GetId(), UserName = "******", Password = "******", Genders = Gender.Female, CreateTime = DateTime.Now, LastUpdateTime = DateTime.Now, Age = 25, LoginCount = 0 }); }
public void Set(IServiceCollection services, IConfiguration config) { services.AddTransient <IFirstDI, FirstDI>(); services.AddTransient <IMiddleObject, MiddleObject>(); services.AddTransient <ISecondDI, SecondDI>(); services.AddSingleton <IRegexRule, RegexRuleModel>(); services.AddSingleton <IAuthService, AuthService>(); services.AddSingleton <IUserRepository>(new UserRepository(config)); services.AddSingleton <ISnowflake>(Snowflake.Instance(long.Parse(config["MachineId:Default"]))); services.AddSingleton <IIdService, IdService>(); }
private void ParallelTest() { // 并行的for循环 Parallel.For(0, 500, i => { long iid = Snowflake.Instance().GetId(); DbHelperSQL.ExecuteSql("insert into ARES_CODE_FEED(F_TYPE,F_CODE) values(@F_TYPE,@F_CODE)", new SqlParameter[] { new SqlParameter("@F_TYPE", "ABCD"), new SqlParameter("@F_CODE", iid.ToString()) }); }); }
public void SnowflakeTestMethod1() { var ids = new List <long>(); for (int i = 0; i < 1000000; i++)//测试同时100W有序ID { ids.Add(Snowflake.Instance().GetId()); } for (int i = 0; i < ids.Count - 1; i++) { Assert.IsTrue(ids[i] < ids[i + 1]); } }
public long CreateUser(UserEntity user) { using (var context = new IzumiContext("CodeFirstDb")) { Func <long> func = () => { long UserID = Snowflake.Instance().GetId(); user.UserID = UserID; context.User.Add(user); context.SaveChanges(); return(UserID); }; return(ExcuteTransaction(context, func)); } }
public long CreateStudent(StudentEntity student) { using (var context = new IzumiContext("CodeFirstDb")) { Func <long> func = () => { long studentID = Snowflake.Instance().GetId(); student.StudentID = studentID; context.Student.Add(student); context.SaveChanges(); return(studentID); }; return(ExcuteTransaction(context, func)); } }
public IActionResult AddMenu([FromBody] Menu menu) { var resultData = new ResultData(); try { menu.ID = Snowflake.Instance().GetId(); menu.CreateTime = DateTime.Now; menu.LastUpdateTime = DateTime.Now; _authorityManagementService.Insert(menu); log.Info($"添加信息:,成功"); resultData.Data = menu.ID; } catch (Exception ex) { resultData.State = Status.Fail.ToString(); resultData.Msg = "添加菜单失败!"; log.Error($"添加菜单错误信息:{ex}"); throw; } return(Ok(resultData)); }
public IActionResult Register([FromBody] RegisterViewModel viewmodel) { if (viewmodel == null) { return(Json(new { state = "401", Message = "参数错误" })); } if (string.IsNullOrEmpty(viewmodel.username) || string.IsNullOrEmpty(viewmodel.password) || string.IsNullOrEmpty(viewmodel.code)) { return(Json(new { state = "401", Message = "参数错误" })); } if (_user.isExist(viewmodel.username)) { return(Json(new { state = "403", Message = "手机号已被注册" })); } User user = new User() { ID = Snowflake.Instance().GetId().ToString(), Nickname = viewmodel.username, PassWord = MD5Helper.GetMD5(viewmodel.password), Phone = viewmodel.username, HeadAddress = "images/dadultHead.jpg", Register_Time = DateTime.Now, }; try { _user.RegisterUser(user); } catch (Exception ex) { return(Json(new { state = "500", Message = "出现错误,请重新刷新页面" })); } return(Json(new { state = "200", Message = "注册成功" })); }
public EntityBase() { ID = Snowflake.Instance().GetId(); }
public static long CreateNewId() { return(Snowflake.Instance().GetId()); }
/// <summary> /// 生成新的ID /// </summary> /// <returns></returns> public static long GenerateId() { return(Snowflake.Instance().GetId()); }
public XAIModule() : base("/API") { Init(); Before += RequestFilter; After += ResponseFilter; //PDF文档 Get["/"] = o => { return(Response.AsFile("XAI_交互协议.pdf")); }; Post["/Auth"] = o => { try { _Req.AddAuthLog(); var biz = _Req.Args.ToEntity <XAIReqAuth>(); var groupId = "G_" + _App.AppCode + "_01"; biz.UserId = groupId + "_" + biz.UserInfo.PaperWorkNo; #region 参数判断 if (biz.Images.Count() != 2 || biz.Images.Where(w => w.Kind == "LIVE" || w.Kind == "1").Count() == 0 || biz.Images.Where(w => w.Kind == "IDCARD" || w.Kind == "2").Count() == 0) { throw new ArgumentNullException("Images对比图片必须为两张,且一张为生活照,一张为证件照"); } biz.Images.ForEach(f => { if (!f.Image.Replace("\r\n", "").IsBase64()) { throw new ArgumentNullException("Images必须是BASE64编码"); } if (!Regex.IsMatch(f.Image, @"^data:image/.{3,5};base64,")) { throw new ArgumentNullException("Images必须包含头如【data:image/.jpg;base64, 】的BASE64编码"); } f.Kind.IsNullOrEmptyOfVar("Kind"); }); if (biz.UserInfo == null) { throw new ArgumentNullException("UserInfo用户信息不可为空!"); } biz.UserInfo.PaperWorkNo.IsNullOrEmptyOfVar("UserInfo.PaperWorkNo"); #endregion using (var dbContext = new DbContextContainer(DbKind.MySql, DbName.FACEDb)._DataAccess) { var patientList = dbContext.Set <Db_Patient>().Where(w => w.PaperworkNo == biz.UserInfo.PaperWorkNo && w.IsDetele == 0).AsNoTracking().FirstOrDefault(); if (patientList != null) { return(ResCode.业务错误.XAIAckOfErr("该用户已认证,请勿重复认证!")); } var authlog = dbContext.Set <Db_AuthLog>().Where(w => w.Id == _Req.RowId).FirstOrDefault(); if (authlog == null) { return(ResCode.业务错误.XAIAckOfErr("not found authlog,id=" + _Req.RowId)); } //人脸对比 var resAuth = _Business.Auth(biz); //插一条人员表 var dbPatient = new Db_Patient() { AuthId = resAuth.AuthId, UserId = biz.UserId, Name = biz.UserInfo.Name, PhoneNo = biz.UserInfo.PhoneNo, Sex = biz.UserInfo.Sex, Natrue = biz.UserInfo.Nature, Adress = biz.UserInfo.Address, Birthday = biz.UserInfo.Birthday, PaperworkType = "IDCARD", PaperworkNo = biz.UserInfo.PaperWorkNo, IsDetele = 0, AddDate = DateTime.Now }; dbContext.Entry(dbPatient).State = EntityState.Added; try { var IDCARDImage = biz.Images.Where(w => w.Kind == "IDCARD" || w.Kind == "2").FirstOrDefault(); //循环图片插入图片和人脸表 var dbImage = new Db_Image() { ImageId = Snowflake.Instance().GetId().ToString(), Image = IDCARDImage.Image }; dbContext.Entry(dbImage).State = EntityState.Added; var reqFAdd = new XAIReqFAdd() { UserId = biz.UserId, UserInfo = biz.UserInfo, Image = IDCARDImage.Image, GroupId = groupId }; //人脸新增 var resFAdd = _Business.FAdd(reqFAdd); var dbface = new Db_Face() { AuthId = resFAdd.AuthId, AppCode = _App.AppCode, ImageId = dbImage.ImageId, //暂写死BASE64 ImageType = "BASE64", FaceType = IDCARDImage.Kind, FaceToken = resFAdd.FaceToken, GroupId = groupId, UserId = biz.UserId, UserInfo = biz.UserInfo.ToJson(), LocationLeft = resFAdd.LocationLeft, LocationTop = resFAdd.LocationTop, LocationHeight = resFAdd.LocationHeight, LocationWidth = resFAdd.LocationWidth, LocationRotaion = resFAdd.LocationRotaion, IsDelete = 0, AddDate = DateTime.Now, }; dbContext.Entry(dbface).State = EntityState.Added; resAuth.UserInfo = biz.UserInfo; resAuth.UserInfo.PhoneNo = biz.UserInfo.PhoneNo.IsNullOrEmptyOfVar() ? "" : biz.UserInfo.PhoneNo; var res = ResCode.交易成功.XAIAckOfBiz(resAuth); //补充authlog res.ModAuthLog(_Req.RowId, biz.Images, resAuth.AuthId); dbContext.SaveChanges(); return(res); } catch (Exception ex) { var reqFDel = new XAIReqFDel() { GroupId = groupId, UserId = biz.UserId }; //删除用户 var resFAdd = _Business.FDel(reqFDel); throw ex; } } } catch (Exception ex) { LogModule.Info(ex); return(ResCode.业务错误.XAIAckOfErr(ex.Message)); } }; Post["/Find"] = o => { try { _Req.AddFindLog(); var biz = _Req.Args.ToEntity <XAIReqFind>(); biz.HospitalId = biz.HospitalId.IsNullOrEmptySetVar("0000"); #region 参数判断 var xxx = this.Request.Body; if (!biz.Image.Replace("\r\n", "").IsBase64()) { throw new ArgumentNullException("Image必须是BASE64编码"); } if (!Regex.IsMatch(biz.Image, @"^^data:image/.{3,5};base64,")) { throw new ArgumentNullException("Image必须包含头如【data:image/.jpg;base64, 】的BASE64编码"); } #endregion var groupId = "G_" + _App.AppCode + "_01"; using (var dbContext = new DbContextContainer(DbKind.MySql, DbName.FACEDb)._DataAccess) { var dbImage = new Db_Image() { ImageId = Snowflake.Instance().GetId().ToString(), Image = biz.Image }; dbContext.Entry(dbImage).State = EntityState.Added; dbContext.SaveChanges(); biz.GroupId = groupId; var resFind = _Business.Find(biz); var dbPatient = dbContext.Set <Db_Patient>().Where(w => w.UserId == resFind.UserId && w.IsDetele == 0).AsNoTracking().FirstOrDefault(); if (dbPatient == null) { return(ResCode.业务错误.XAIAckOfErr("未查找到用户:" + resFind.UserId)); } resFind.UserInfo = new UserInfo { PhoneNo = dbPatient.PhoneNo.IsNullOrEmptyOfVar() ? "" : dbPatient.PhoneNo, PaperWorkNo = dbPatient.PaperworkNo, Name = dbPatient.Name, Sex = dbPatient.Sex, Nature = dbPatient.Natrue, Address = dbPatient.Adress, Birthday = dbPatient.Birthday }; var dbUserIndexList = dbContext.Set <Db_UserIndex>().Where(w => w.HospitalId == biz.HospitalId && w.UserId == resFind.UserId && w.IsDelete == 0).ToList(); resFind.Indexs = dbUserIndexList.Select(s => new UserIndexInfo { Index = s.Index, IndexType = s.IndexType }).ToList(); var res = ResCode.交易成功.XAIAckOfBiz(resFind); //补充identlog res.ModFindLog(_Req.RowId, dbImage); return(res); } } catch (Exception ex) { LogModule.Info(ex); if (ex.HResult == 7101) { return(ResCode.刷脸业务错误.XAIAckOfErr(ex.Message)); } return(ResCode.业务错误.XAIAckOfErr(ex.Message)); } }; Post["/FAdd"] = o => { try { var biz = _Req.Args.ToEntity <XAIReqFAdd>(); #region 参数判断 if (!biz.Image.Replace("\r\n", "").IsBase64()) { throw new ArgumentNullException("Image必须是BASE64编码"); } if (!Regex.IsMatch(biz.Image, @"^^data:image/.{3,5};base64,")) { throw new ArgumentNullException("Image必须包含头如【data:image/.jpg;base64, 】的BASE64编码"); } if (biz.UserInfo == null) { throw new ArgumentNullException("UserInfo用户信息不可为空!"); } biz.UserInfo.PhoneNo.IsNullOrEmptyOfVar("UserInfo.PhoneNo"); biz.UserInfo.PaperWorkNo.IsNullOrEmptyOfVar("UserInfo.PaperWorkNo"); #endregion biz.GroupId = "G_" + _App.AppCode + "_01"; biz.UserId = biz.GroupId + "_" + biz.UserInfo.PaperWorkNo; //插入成功标志 var FaceToken = ""; using (var dbContext = new DbContextContainer(DbKind.MySql, DbName.FACEDb)._DataAccess) { var dbPatient = dbContext.Set <Db_Patient>().Where(w => w.UserId == biz.UserId && w.IsDetele == 0).AsNoTracking().FirstOrDefault(); var IsDeleteUser = (dbPatient != null && dbPatient.IsDetele == 0) ? false : true; var dbImage = new Db_Image() { ImageId = Snowflake.Instance().GetId().ToString(), Image = biz.Image }; dbContext.Entry(dbImage).State = EntityState.Added; try { var resFAdd = _Business.FAdd(biz); FaceToken = resFAdd.FaceToken; if (dbPatient == null) { //插一条人员表 var newDbPatient = new Db_Patient() { AuthId = resFAdd.AuthId, UserId = biz.UserId, Name = biz.UserInfo.Name, PhoneNo = biz.UserInfo.PhoneNo, Sex = biz.UserInfo.Sex, Natrue = biz.UserInfo.Nature, Adress = biz.UserInfo.Address, Birthday = biz.UserInfo.Birthday, PaperworkType = "IDCARD", PaperworkNo = biz.UserInfo.PaperWorkNo, IsDetele = 0, AddDate = DateTime.Now }; dbContext.Entry(newDbPatient).State = EntityState.Added; } else if (dbPatient != null && dbPatient.IsDetele != 0) { //更新人员表 dbPatient = new Db_Patient() { AuthId = resFAdd.AuthId, UserId = biz.UserId, Empi = null, Name = biz.UserInfo.Name, PhoneNo = biz.UserInfo.PhoneNo, Sex = biz.UserInfo.Sex, Natrue = biz.UserInfo.Nature, Adress = biz.UserInfo.Address, Birthday = biz.UserInfo.Birthday, PaperworkType = "IDCARD", PaperworkNo = biz.UserInfo.PaperWorkNo, IsDetele = 0, AddDate = DateTime.Now }; dbContext.Entry(dbPatient).State = EntityState.Modified; } //插入人脸表 var dbface = new Db_Face() { AuthId = resFAdd.AuthId, AppCode = _App.AppCode, ImageId = dbImage.ImageId, ImageType = "BASE64", FaceType = "LIVE", FaceToken = resFAdd.FaceToken, GroupId = biz.GroupId, UserId = biz.UserId, UserInfo = biz.UserInfo.ToJson(), LocationLeft = resFAdd.LocationLeft, LocationTop = resFAdd.LocationTop, LocationHeight = resFAdd.LocationHeight, LocationWidth = resFAdd.LocationWidth, LocationRotaion = resFAdd.LocationRotaion, IsDelete = 0, AddDate = DateTime.Now, }; dbContext.Entry(dbface).State = EntityState.Added; dbContext.SaveChanges(); return(ResCode.交易成功.XAIAckOfBiz(new XAIResFAdd() { UserId = biz.UserId })); } catch (Exception ex) { if (IsDeleteUser) { var reqFDel = new XAIReqFDel() { GroupId = biz.GroupId, UserId = biz.UserId }; //删除用户 var resFAdd = _Business.FDel(reqFDel); } else { if (!FaceToken.IsNullOrEmptyOfVar()) { var reqDeleteFace = new XAIReqDeleteFace() { GroupId = biz.GroupId, UserId = biz.UserId, FaceToken = FaceToken }; //删除用户 var resDeleteFace = _Business.DeleteFace(reqDeleteFace); } } throw ex; } } } catch (Exception ex) { LogModule.Info(ex); return(ResCode.业务错误.XAIAckOfErr(ex.Message)); } }; Post["/FMod"] = o => { try { var biz = _Req.Args.ToEntity <XAIReqFMod>(); #region 参数判断 biz.UserId.IsNullOrEmptyOfVar("UserId"); #endregion using (var dbContext = new DbContextContainer(DbKind.MySql, DbName.FACEDb)._DataAccess) { var dbPatient = dbContext.Set <Db_Patient>().Where(w => w.UserId == biz.UserId && w.IsDetele == 0).FirstOrDefault(); if (dbPatient == null) { return(ResCode.业务错误.XAIAckOfErr("未查询到用户:" + biz.UserId)); } var dbface = dbContext.Set <Db_Face>().Where(w => w.UserId == biz.UserId && w.FaceType == "LIVE" && w.IsDelete == 0).FirstOrDefault(); if (dbface == null) { return(ResCode.业务错误.XAIAckOfErr("未查询到用户的人脸库:" + biz.UserId)); } biz.GroupId = dbface.GroupId; if (!biz.Image.IsNullOrEmptyOfVar()) { if (!biz.Image.Replace("\r\n", "").IsBase64()) { throw new ArgumentNullException("Image必须是BASE64编码"); } if (!Regex.IsMatch(biz.Image, @"^^data:image/.{3,5};base64,")) { throw new ArgumentNullException("Image必须包含头如【data:image/.jpg;base64, 】的BASE64编码"); } var dbImage = new Db_Image() { ImageId = Snowflake.Instance().GetId().ToString(), Image = biz.Image }; dbContext.Entry(dbImage).State = EntityState.Added; var resFMod = _Business.FMod(biz); dbface.ImageId = dbImage.ImageId; dbface.LocationLeft = resFMod.LocationLeft; dbface.LocationTop = resFMod.LocationTop; dbface.LocationHeight = resFMod.LocationHeight; dbface.LocationWidth = resFMod.LocationWidth; dbface.LocationRotaion = resFMod.LocationRotaion; dbface.ModDate = DateTime.Now; dbface.ModUser = "******"; } if (biz.UserInfo != null) { if (!biz.UserInfo.PhoneNo.IsNullOrEmptyOfVar()) { dbPatient.PhoneNo = biz.UserInfo.PhoneNo; } if (!biz.UserInfo.PaperWorkNo.IsNullOrEmptyOfVar()) { dbPatient.PaperworkNo = biz.UserInfo.PaperWorkNo; } if (!biz.UserInfo.Name.IsNullOrEmptyOfVar()) { dbPatient.Name = biz.UserInfo.Name; } if (!biz.UserInfo.Nature.IsNullOrEmptyOfVar()) { dbPatient.Natrue = biz.UserInfo.Nature; } if (!biz.UserInfo.Address.IsNullOrEmptyOfVar()) { dbPatient.Adress = biz.UserInfo.Address; } if (!biz.UserInfo.Birthday.IsNullOrEmptyOfVar()) { dbPatient.Birthday = biz.UserInfo.Birthday; } } dbContext.SaveChanges(); } return(ResCode.交易成功.XAIAckOfBiz(new XAIResFMod())); } catch (Exception ex) { LogModule.Info(ex); return(ResCode.业务错误.XAIAckOfErr(ex.Message)); } }; Post["/FDel"] = o => { try { var biz = _Req.Args.ToEntity <XAIReqFDel>(); #region 参数判断 biz.UserId.IsNullOrEmptyOfVar("UserId"); #endregion using (var dbContext = new DbContextContainer(DbKind.MySql, DbName.FACEDb)._DataAccess) { var dbPatient = dbContext.Set <Db_Patient>().Where(w => w.UserId == biz.UserId && w.IsDetele == 0).FirstOrDefault(); if (dbPatient == null) { return(ResCode.业务错误.XAIAckOfErr("未查询到用户:" + biz.UserId)); } var reqFDel = new XAIReqFDel() { GroupId = "G_" + _App.AppCode + "_01", UserId = biz.UserId }; var resFDel = _Business.FDel(reqFDel); dbPatient.IsDetele = 1; var dbFaceList = dbContext.Set <Db_Face>().Where(w => w.UserId == biz.UserId).ToList(); dbFaceList.ForEach(f => { f.IsDelete = 1; }); dbContext.SaveChanges(); return(ResCode.交易成功.XAIAckOfBiz(new XAIResFDel())); } } catch (Exception ex) { LogModule.Info(ex); return(ResCode.业务错误.XAIAckOfErr(ex.Message)); } }; Post["/FGet"] = o => { try { var biz = _Req.Args.ToEntity <XAIReqFGet>(); #region 参数判断 biz.UserId.IsNullOrEmptyOfVar("UserId"); #endregion using (var dbContext = new DbContextContainer(DbKind.MySql, DbName.FACEDb)._DataAccess) { var dbPatient = dbContext.Set <Db_Patient>().Where(w => w.UserId == biz.UserId && w.IsDetele == 0).FirstOrDefault(); if (dbPatient == null) { return(ResCode.业务错误.XAIAckOfErr("未查询到用户:" + biz.UserId)); } var dbFaceList = dbContext.Set <Db_Face>().Where(w => w.UserId == biz.UserId && w.IsDelete == 0).ToList(); var dbUserIndexList = dbContext.Set <Db_UserIndex>().Where(w => w.UserId == biz.UserId && w.IsDelete == 0).ToList(); var res = new XAIResFGet() { UserInfo = new UserInfo { PhoneNo = dbPatient.PhoneNo, PaperWorkNo = dbPatient.PaperworkNo, Name = dbPatient.Name, Sex = dbPatient.Sex, Nature = dbPatient.Natrue, Address = dbPatient.Adress, Birthday = dbPatient.Birthday, }, Images = dbFaceList.Select(s => new ImageInfo { ImageId = s.ImageId, Kind = s.FaceType }).ToList(), Indexs = dbUserIndexList.Select(s => new UserIndexInfo { Index = s.Index, IndexType = s.IndexType }).ToList() }; //var resGet = _Business.FGet(biz); return(ResCode.交易成功.XAIAckOfBiz(res)); } } catch (Exception ex) { LogModule.Info(ex); return(ResCode.业务错误.XAIAckOfErr(ex.Message)); } }; Post["/IAdd"] = o => { try { var biz = _Req.Args.ToEntity <XAIReqIAdd>(); biz.HospitalId = biz.HospitalId.IsNullOrEmptySetVar("0000"); #region 参数判断 biz.UserId.IsNullOrEmptyOfVar("UserId"); if (biz.Indexs == null) { throw new ArgumentNullException("Indexs用户索引信息不可为空!"); } biz.Indexs.ForEach(f => { f.Index.IsNullOrEmptyOfVar("Index"); f.IndexType.IsNullOrEmptyOfVar("IndexType"); }); #endregion using (var dbContext = new DbContextContainer(DbKind.MySql, DbName.FACEDb)._DataAccess) { var dbIndexList = dbContext.Set <Db_UserIndex>().Where(w => w.HospitalId == biz.HospitalId && w.UserId == biz.UserId).ToList(); var IndexCount = "IndexCount".ConfigValue("2").ToInt(); if (biz.Indexs.Count() > IndexCount || (dbIndexList.Count() + biz.Indexs.Count()) > IndexCount) { throw new XAIException("无法添加,用户索引添加索引超过最大限:" + IndexCount.ToString()); } biz.Indexs.ForEach(f => { var dbIndex = dbIndexList.Where(w => w.IndexType == f.IndexType).FirstOrDefault(); if (dbIndex != null) { if (dbIndex.IsDelete == 0 && dbIndex.Index == f.Index) { throw new XAIException("用户索引已存在,请勿重复添加:" + f.Index); } dbIndex.IsDelete = 0; dbIndex.ModDate = DateTime.Now; dbIndex.ModUser = "******"; } else { dbIndex = new Db_UserIndex() { HospitalId = biz.HospitalId, UserId = biz.UserId, Index = f.Index, IndexType = f.IndexType, IsDelete = 0, AddDate = DateTime.Now, }; dbContext.Entry(dbIndex).State = EntityState.Added; } }); dbContext.SaveChanges(); return(ResCode.交易成功.XAIAckOfBiz(new XAIResIAdd())); } } catch (Exception ex) { LogModule.Info(ex); return(ResCode.业务错误.XAIAckOfErr(ex.Message)); } }; Post["/IDel"] = o => { try { var biz = _Req.Args.ToEntity <XAIReqIDel>(); biz.HospitalId = biz.HospitalId.IsNullOrEmptySetVar("0000"); #region 参数判断 biz.UserId.IsNullOrEmptyOfVar("UserId"); if (biz.Indexs == null) { throw new ArgumentNullException("Indexs用户索引信息不可为空!"); } biz.Indexs.ForEach(f => { f.Index.IsNullOrEmptyOfVar("Index"); f.IndexType.IsNullOrEmptyOfVar("IndexType"); }); #endregion using (var dbContext = new DbContextContainer(DbKind.MySql, DbName.FACEDb)._DataAccess) { var dbIndexList = dbContext.Set <Db_UserIndex>().Where(w => w.HospitalId == biz.HospitalId && w.UserId == biz.UserId).ToList(); biz.Indexs.ForEach(f => { var dbIndex = dbContext.Set <Db_UserIndex>().Where(w => w.Index == f.Index && w.IndexType == f.IndexType).FirstOrDefault(); if (dbIndex == null) { throw new XAIException("未查询到用户索引:" + f.Index); } dbIndex.IsDelete = 1; dbIndex.ModDate = DateTime.Now; dbIndex.ModUser = "******"; }); dbContext.SaveChanges(); return(ResCode.交易成功.XAIAckOfBiz(new XAIResIDel())); } } catch (Exception ex) { LogModule.Info(ex); return(ResCode.业务错误.XAIAckOfErr(ex.Message)); } }; }
public User() { this.Id = Snowflake.Instance().GetString(); this.CreationTime = DateTime.Now; }