Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="_Res"></param>
        public static void ModAuthLog(this string _ResJson, int _RowId, List <ImageInfo> _Images, string _AuthId)
        {
            var _Res = _ResJson.ToEntity <XAIResBase>();

            using (var dbContext = new DbContextContainer(DbKind.MySql, DbName.FACEDb)._DataAccess)
            {
                try
                {
                    var dbAuthLog = dbContext.Set <Db_AuthLog>().Where(w => w.Id == _RowId).ToList().FirstOrDefault();
                    if (dbAuthLog == null)
                    {
                        throw new Exception("The authlog that needs to be modified does not exist! id=" + _RowId);
                    }
                    dbAuthLog.PaperworkImageId  = _Images.Where(w => w.Kind == "IDCARD").FirstOrDefault()?.ImageId;
                    dbAuthLog.PageworkImageType = "BASE64";
                    dbAuthLog.FaceImageId       = _Images.Where(w => w.Kind == "LIVE").FirstOrDefault()?.ImageId;
                    dbAuthLog.FaceImageType     = "BASE64";
                    dbAuthLog.MessageOut        = _Res.ToJson();
                    dbAuthLog.ReturnCode        = _Res.Code.ToInt();
                    dbAuthLog.ReturnDesc        = _Res.Desc;
                    dbAuthLog.OutTime           = DateTime.Now;
                    dbAuthLog.ModDate           = DateTime.Now;
                    dbContext.SaveChanges();
                }
                catch (Exception ex)
                {
                    LogModule.Error("Db Fail:" + ex.Message + (ex.InnerException == null ? "" : ex.InnerException.Message));
                }
            }
        }
Example #2
0
 /// <summary>
 ///
 /// </summary>
 public static void AddAuthLog(this XAIReqBase req)
 {
     //TODO AUTH和Find记入参日志
     using (var dbContext = new DbContextContainer(DbKind.MySql, DbName.FACEDb)._DataAccess)
     {
         try
         {
             var args      = req.Args.ToEntity <XAIReqAuth>();
             var dbAuthLog = new Db_AuthLog
             {
                 AuthID        = "".CreateKey(),
                 AppCode       = req.AppCode,
                 PaperworkType = "IDCARD",
                 PaperworkNo   = args.UserInfo.PaperWorkNo,
                 PhoneNo       = args.UserInfo.PhoneNo,
                 MessageIn     = req.ToJson(),
                 InTime        = Convert.ToDateTime(req.ReqTime),
                 AddDate       = DateTime.Now,
                 IsDelete      = 0
             };
             dbContext.Entry(dbAuthLog).State = EntityState.Added;
             dbContext.SaveChanges();
             req.RowId = dbAuthLog.Id;
         }
         catch (Exception ex)
         {
             LogModule.Error("Db Fail:" + ex.Message + (ex.InnerException == null ? "" : ex.InnerException.Message) + "\r\n参数:" + req.EntityToKeyValue(false));
         }
     }
 }
Example #3
0
 public virtual K OnExecu <T, K>(T o, BConfig x)
     where T : ExternalReqBase
     where K : ExternalResBase
 {
     try
     {
         using (var dbContext = new DbContextContainer(DbName.HCDb)._DataAccess)
         {
             var dynamicSql = @"SELECT * 
                                  FROM AT_RegDev
                                 WHERE AuthorizeHospitalCode = '" + x.HCode + "' " +
                              "AND RegDevCode = 'Conlin'";
             var dbRegDev = dbContext.Database.Connection.QueryFirstOrDefault <Db_RegDev>(dynamicSql);
             o.ReqHeader = new ReqHeader(dbRegDev, x.BCode, x.TCode, x.OCode);
             var s = String.Empty;
             var v = _ESBClient.ReqBusiness(o.ReqHeader.ReqHospitalCode, o.ReqHeader.ReqCompanyCode, x.TKind, OnEntry(o, x).ToJson(), ref s);
             return(OnExits(s, x).ToEntity <K>());
         }
     }
     catch (Exception ex)
     {
         LogModule.Info("执行ESB请求异常:", ex);
         throw ex;
     }
 }
Example #4
0
 /// <summary>
 ///
 /// </summary>
 public static void AddSingleRow(this UPPReqBase req)
 {
     using (var dbContext = new DbContextContainer(DbKind.MySql, DbName.UPPDb)._DataAccess)
     {
         try
         {
             var dbReq = new Db_AppLog
             {
                 AppId     = req.AppId,
                 Channel   = req.Channel,
                 Class     = req.Class,
                 Kind      = req.Kind,
                 Mode      = req.Mode,
                 OperCode  = req.OperCode,
                 ReqTime   = Convert.ToDateTime(req.ReqTime),
                 TermCode  = req.TermCode,
                 ReqArgs   = req.Args,
                 ReqRandom = req.Random,
                 ReqSign   = req.Sign,
                 AddDate   = DateTime.Now
             };
             dbContext.Entry(dbReq).State = EntityState.Added;
             dbContext.SaveChanges();
             req.RowId = dbReq.Id;
         }
         catch (Exception ex)
         {
             LogModule.Error("Db Fail:" + ex.Message + (ex.InnerException == null ? "" : ex.InnerException.Message) + "\r\n参数:" + req.EntityToKeyValue(false));
         }
     }
 }
Example #5
0
 /// <summary>
 /// 构造
 /// </summary>
 /// <param name="_Req"></param>
 public BusinessBIDU(XAIReqBase _Req)
 {
     if (BIDUClientCache.Where(w => w.Key == _Req.AppCode).Count() == 0)
     {
         lock (BIDUClientCache)
         {
             using (var dbContext = new DbContextContainer(DbKind.MySql, DbName.FACEDb)._DataAccess)
             {
                 var dbApp = dbContext.DbApp(_Req.AppCode);
                 if (dbApp != null)
                 {
                     client = new Baidu.Aip.Face.Face(dbApp.AppKey.ToString(), dbApp.AppSecret.ToString())
                     {
                         Timeout = 60000  // 修改超时时间
                     };
                     BIDUClientCache.AddOrUpdate(_Req.AppCode, client, (key, value) => value);
                 }
                 else
                 {
                     throw new Exception("Missing app config or not activated!");
                 }
             }
         }
     }
     else
     {
         client = BIDUClientCache.Where(w => w.Key == _Req.AppCode).FirstOrDefault().Value;
     }
 }
Example #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="res"></param>
 public static void ModSingleRow(this UPPResBase res, UPPReqBase req)
 {
     using (var dbContext = new DbContextContainer(DbKind.MySql, DbName.UPPDb)._DataAccess)
     {
         try
         {
             var dbRow = dbContext.Set <Db_AppLog>().Where(w => w.Id == req.RowId).ToList().FirstOrDefault();
             if (dbRow == null)
             {
                 throw new Exception("The line that needs to be modified does not exist!");
             }
             dbRow.Code      = res.ResCode;
             dbRow.Msg       = res.ResMsg;
             dbRow.ResTime   = Convert.ToDateTime(res.ResTime);
             dbRow.ResArgs   = res.Args;
             dbRow.ResRandom = res.Random;
             dbRow.ResSign   = res.Sign;
             dbRow.ModDate   = DateTime.Now;
             dbContext.SaveChanges();
         }
         catch (Exception ex)
         {
             LogModule.Error("Db Fail:" + ex.Message + (ex.InnerException == null ? "" : ex.InnerException.Message));
         }
     }
 }
Example #7
0
        public Db_TradeLogMapper()
        {
            var _TableName = "SubTable".ConfigValue("NO") == "YES" ? "AT_TradeLog_" + DateTime.Now.Year + DateTime.Now.Month.ToString("00") : "AT_TradeLog";

            if ("SubTable".ConfigValue("NO") == "YES")
            {
                using (var dbContext = new DbContextContainer(DbKind.MySql, DbName.HPDb)._DataAccess)
                {
                    var x = dbContext.Database.Connection.Query("SELECT TABLE_NAME FROM information_schema.TABLES WHERE table_name = '" + _TableName + "'");
                    if (x.Count() == 0)
                    {
                        dbContext.Database.Connection.Execute(String.Format(@"CREATE TABLE `{0}` (
                                                            `Id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增主键',
                                                            `Guid` varchar(50) NOT NULL COMMENT '消息Id',
                                                            `HospitalId` varchar(5) NOT NULL COMMENT '医院Id',
                                                            `CompanyCode` varchar(45) NOT NULL COMMENT '厂商代码',
                                                            `TradeType` varchar(60) NOT NULL COMMENT '交易类型',
                                                            `ReqMsg` longtext NOT NULL COMMENT '请求串',
                                                            `ResMsg` longtext COMMENT '返回串',
                                                            `RetCode` varchar(10) DEFAULT NULL COMMENT '交易返回码',
                                                            `ReqTime` datetime NOT NULL COMMENT '请求时间',
                                                            `ResTime` datetime DEFAULT NULL COMMENT '响应时间',
                                                            `TradeState` int(11) NOT NULL DEFAULT '0' COMMENT '0->交易正在请求中 1->交易请求完成 -99->非法或异常请求',
                                                            `UploadState` int(11) NOT NULL DEFAULT '0' COMMENT '0->未提取 1->已提取 2->已上传',
                                                            PRIMARY KEY (`Id`),
                                                            UNIQUE KEY `Id_UNIQUE` (`Id`),
                                                            UNIQUE KEY `Guid_UNIQUE` (`Guid`),
                                                            KEY `idx_{0}_ReqTime` (`ReqTime`)
                                                        ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;", _TableName));
                    }
                }
            }
            ToTable(_TableName);
            HasKey(o => o.Id);
        }
Example #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="res"></param>
        public static void ModFindLog(this string _ResJson, int _RowId, Db_Image _Image)
        {
            var _Res = _ResJson.ToEntity <XAIResBase>();

            using (var dbContext = new DbContextContainer(DbKind.MySql, DbName.FACEDb)._DataAccess)
            {
                try
                {
                    var dbIdentLog = dbContext.Set <Db_IdentLog>().Where(w => w.Id == _RowId).ToList().FirstOrDefault();
                    if (dbIdentLog == null)
                    {
                        throw new Exception("The identlog that needs to be modified does not exist! id=" + _RowId);
                    }
                    dbIdentLog.ImageId    = _Image.ImageId;
                    dbIdentLog.ImageType  = "BASE64";
                    dbIdentLog.UserId     = _Res.UserId;
                    dbIdentLog.ReturnCode = _Res.Code.ToInt();
                    dbIdentLog.ReturnDesc = _Res.Desc;
                    dbIdentLog.TimeOut    = DateTime.Now;
                    dbIdentLog.ModDate    = DateTime.Now;
                    dbContext.SaveChanges();
                }
                catch (Exception ex)
                {
                    LogModule.Error("Db Fail:" + ex.Message + (ex.InnerException == null ? "" : ex.InnerException.Message));
                }
            }
        }
Example #9
0
        public virtual CheckMode GetCheckMode(string deptCode)
        {
            try
            {
                if (deptCode.IsNullOrEmptyOfVar())
                {
                    throw new Exception("TCPCommon.参数deptCode为空");
                }

                using (var cDbContext = new DbContextContainer(DbKind.MySql, DbName.HCDb)._DataAccess)
                {
                    var deptInfo = cDbContext.Set <Db_Dept>().Where(w => w.DeptCode == deptCode).FirstOrDefault();
                    if (deptInfo == null)
                    {
                        throw new Exception("TCPCommon.未找到科室信息");
                    }

                    return((CheckMode)Enum.ToObject(typeof(CheckMode), deptInfo.CheckMode));
                }
            }
            catch (Exception e)
            {
                LogModule.Error("TCPCommon.GetCheckMode()异常,异常信息:" + e.Message);
                throw e;
            }
        }
Example #10
0
 private void Init(string _Key)
 {
     _UPPCONFIG = _UPPCONFIGCACHE.Where(w => w.Key == _Key).FirstOrDefault().Value;
     if (_UPPCONFIG == null)
     {
         using (var dbContext = new DbContextContainer(DbName.UPPDb)._DataAccess)
         {
             List <Db_App> dbAppList = null;
             if (_Key.Contains("#"))
             {
                 var _HCode  = _Key.Split('#')[0];
                 var _HBCode = _Key.Split('#')[1] == _HCode ? "" : _Key.Split('#')[1];
                 var appId   = "AppId".ConfigValue();
                 //AppId为空则为App根据HosCode查询
                 if (appId.IsNullOrEmptyOfVar())
                 {
                     _HBCode   = _HCode == "00030" ? "" : _HBCode;
                     dbAppList = dbContext.Set <Db_App>().Where(w => w.HosCode == _HCode && w.Active == 0).AsNoTracking().ToList();
                 }
                 else
                 {
                     dbAppList = dbContext.Set <Db_App>().Where(w => w.HosCode == _HCode && w.Active == 0 && w.AppCode == appId).AsNoTracking().ToList();
                 }
                 if (!_HBCode.IsNullOrEmptyOfVar())
                 {
                     dbAppList = dbAppList.Where(w => w.BranchCode == _HBCode).ToList();
                 }
             }
             else
             {
                 dbAppList = dbContext.Set <Db_App>().Where(w => w.AppCode == _Key && w.Active == 0).AsNoTracking().ToList();
                 if (dbAppList.Count == 0)
                 {
                     dbAppList = dbContext.Database.Connection.Query <Db_App>("SELECT A.* FROM UT_APP A,UT_APPLINK B WHERE A.APPCODE = B.APPCODE AND A.ACTIVE = 0 AND B.ACTIVE = 0 AND B.APPID = " + _Key).ToList();
                 }
             }
             if (dbAppList.Count == 0)
             {
                 throw new Exception("UPPClient未找到相关配置");
             }
             if (dbAppList.FirstOrDefault().Url.IsNullOrEmptyOfVar())
             {
                 throw new Exception("UPPClient未找到URL配置");
             }
             _UPPCONFIG = new UPPConfig()
             {
                 AppId = dbAppList.FirstOrDefault().AppCode,
                 Key   = dbAppList.FirstOrDefault().DevKey,
                 Url   = dbAppList.FirstOrDefault().Url.ToLower().Contains("api") ? dbAppList.FirstOrDefault().Url : dbAppList.FirstOrDefault().Url + "api"
             };
             _UPPCONFIGCACHE.AddOrUpdate(_Key, _UPPCONFIG, (key, value) => value);
         }
     }
 }
Example #11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="_DbAppCache"></param>
 public static void DbAppConfig(this ConcurrentDictionary <String, Db_App> _DbAppCache)
 {
     lock (_DbAppCache)
     {
         using (var dbContext = new DbContextContainer(DbKind.MySql, DbName.UPPDb)._DataAccess)
         {
             dbContext.Database.Connection.Query <Db_App>("SELECT * FROM UT_App WHERE Active = 0").ToList().ForEach(o =>
             {
                 _DbAppCache.AddOrUpdate(o.AppCode, o, (key, value) => value);
             });
         }
     }
 }
Example #12
0
 /// <summary>
 ///
 /// </summary>
 public static void AddFindLog(this XAIReqBase req)
 {
     using (var dbContext = new DbContextContainer(DbKind.MySql, DbName.FACEDb)._DataAccess)
     {
         try
         {
             var args       = req.Args.ToEntity <XAIReqFind>();
             var dbIdentLog = new Db_IdentLog
             {
                 TimeIn   = Convert.ToDateTime(req.ReqTime),
                 AddDate  = DateTime.Now,
                 IsDelete = 0
             };
             dbContext.Entry(dbIdentLog).State = EntityState.Added;
             dbContext.SaveChanges();
             req.RowId = dbIdentLog.Id;
         }
         catch (Exception ex)
         {
             LogModule.Error("Db Fail:" + ex.Message + (ex.InnerException == null ? "" : ex.InnerException.Message) + "\r\n参数:" + req.EntityToKeyValue(false));
         }
     }
 }
Example #13
0
        public static Db_Param GetParamByName(this string paramName, string hopitalId)
        {
            Db_Param dbParam = new Db_Param();

            try
            {
                if (!String.IsNullOrEmpty(paramName))
                {
                    using (var dbContext = new DbContextContainer(DbKind.MySql, DbName.HCDb)._DataAccess)
                    {
                        if (!String.IsNullOrEmpty(hopitalId))
                        {
                            dbParam = dbContext.Set <Db_Param>().AsNoTracking()
                                      .Where(p => p.PARAM_NAME == paramName && p.HOSPITAL_ID == hopitalId).FirstOrDefault();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogModule.Error("ESBToolBox->GetParamByName():" + ex.Message);
            }
            return(dbParam);
        }
Example #14
0
        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));
                }
            };
        }
Example #15
0
 public PhotoRepository()
 {
     dbContext = new DbContextContainer();
 }
Example #16
0
 public PersonRepository()
 {
     dbContext = new DbContextContainer();
 }
Example #17
0
        /// <summary>
        /// 获取病人列表
        /// </summary>
        /// <param name="deptCode"></param>
        /// <param name="whereQueueStateStr">类似" queuestate in(0,1,2)"</param>
        /// <param name="isFrontCount">是否统计当前报到模式前面排队人数</param>
        /// <param name="roomId"></param>
        /// <param name="patientId"></param>
        /// <param name="docCode"></param>
        /// <returns></returns>
        public virtual List <Db_RegPatientList> GetPatientList(string deptCode, string docCode, string typeCode)
        {
            try
            {
                docCode.IsNullOrEmptyOfVar("docCode");
                deptCode.IsNullOrEmptyOfVar("deptCode");
                typeCode.IsNullOrEmptyOfVar("typeCode");
                using (var dbContext = new DbContextContainer(DbName.HPDb)._DataAccess)
                {
                    var docLoginInfo = dbContext.Set <Db_DoctorLoginInfo>().Where(w => w.DoctorCode == docCode && w.LoginState == "1" && w.DeptCode == deptCode && w.TypeCode == typeCode).FirstOrDefault();
                    if (docLoginInfo == null)
                    {
                        throw new Exception("未查询到医生登录信息");
                    }
                    CheckMode cm  = GetCheckMode(docLoginInfo.DeptCode);
                    var       sql = "";
                    if (cm == CheckMode.首诊报到到医生)
                    {
                        return(dbContext.Set <Db_RegPatientList>().Where(w => w.RoomId == docLoginInfo.RoomId && w.CheckDoctorCode == docLoginInfo.DoctorCode && w.IsCancel == 0).AsNoTracking().ToList());
                    }
                    if (cm == CheckMode.首诊不报到直接呼叫)
                    {
                        if (docLoginInfo.TypeCode == "1")
                        {
                            sql = string.Format(@"select * from at_regpatientlist 
                                          where RegDeptCode='{0}' and CheckDoctorCode is null and RegTypeCode='1' 
                                          AND IsCancel='0'
                                          UNION ALL
                                          SELECT * from at_regpatientlist where
                                          checkdoctorcode='{1}' and roomid='{2}' and IsCancel=0 ", docLoginInfo, deptCode, docLoginInfo.DoctorCode, docLoginInfo.RoomId);
                        }
                        else
                        {
                            sql = string.Format(@"SELECT * from at_regpatientlist 
                                          WHERE checkdoctorcode='{0}'
                                          AND roomid='{1}'
                                          and iscancel=0", docLoginInfo.DoctorCode, docLoginInfo.RoomId);
                        }
                    }

                    if (cm == CheckMode.首诊报到到科室)
                    {
                        if (docLoginInfo.TypeCode == "1")
                        {
                            sql = string.Format(@" select * from at_regpatientlist
                                                 WHERE CheckDeptCode='{0}'
                                                 and (CheckDoctorCode is null or CheckDoctorCode ='')
                                                 and RegTypeCode = '1'
                                                 and IsCancel = 0
                                                 UNION ALL
                                                 select * from at_regpatientlist
                                                 WHERE CheckDoctorCode='{1}'
                                                 AND RoomId='{2}'
                                                 AND IsCancel=0", docLoginInfo.DeptCode, docLoginInfo.DoctorCode, docLoginInfo.RoomId);
                        }
                        else
                        {
                            sql = string.Format(@"select * from at_regpatientlist 
                                                        where CheckDoctorCode='{0}'
                                                        AND roomid='{1}'
                                                        and IsCancel=0", docLoginInfo.DoctorCode, docLoginInfo.RoomId);
                        }
                    }

                    return(dbContext.Database.SqlQuery <Db_RegPatientList>(sql).ToList());
                }
            }
            catch (Exception e)
            {
                LogModule.Error("TCPCommon.GetPatientList()异常,异常信息:" + e.Message);
                throw e;
            }
        }