示例#1
0
        /// <summary>
        /// 更新用户级别(0-普通用户、10 以上 Vip等级)
        /// </summary>
        public void UpdateUserLevel()
        {
            using (var db = new DBEntities())
            {
                var users = (from ua in db.Users
                             where !ua.IsDeleted && ua.UserLevel == -1
                             select ua.UserID).ToList();

                if (users != null && users.Count > 0)
                {
                    db.Database.ExecuteSqlCommand(@"update Users set UserLevel=isnull(aa.UserLevel,0)
                    from users left join (
                    select isnull(users.UserID,UserRoleMaps.UserID) UserID,max(UserLevelRules.UserLevel) UserLevel from UserLevelRules left join users on UserLevelRules.OrgCode=users.OrgCode
                    left join UserRoleMaps on UserLevelRules.RoleID=UserRoleMaps.RoleID
                    where UserLevelRules.IsDeleted=0 and ((UserLevelRules.RuleDimension=0 and users.UserID is not null)
                    or (UserLevelRules.RuleDimension=1 and UserRoleMaps.UserID is not null))
                    group by users.UserID,UserRoleMaps.UserID)aa on  users.UserID = aa.UserID
                    where Users.UserLevel=-1");

                    foreach (var item in users)
                    {
                        var User_CacheKey = new XuHos.Common.Cache.Keys.EntityCacheKey <ResponseUserDTO>(StringCacheKeyType.User, item);
                        User_CacheKey.RemoveCache();
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// 更新用户信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ApiResult UpdateUserInfo([FromBody] UserDTO model)
        {
            userService  = new BLL.User.Implements.UserService();
            model.UserID = CurrentOperatorUserID;
            if (userService.UpdateUserInfo(model))
            {
                var GetUserIDByMobile_CacheKey = new XuHos.Common.Cache.Keys.EntityCacheKey <ResponseUserDTO>(StringCacheKeyType.User, model.UserID);
                GetUserIDByMobile_CacheKey.RemoveCache();
                return(true.ToApiResultForBoolean());
            }

            return(EnumApiStatus.BizError.ToApiResultForApiStatus());
        }
示例#3
0
        public ApiResult GetAccessSignatureUrl(
            string ResourceID         = "",
            string AccessKey          = "",
            DateTime?AccessStartTime  = null,
            DateTime?AccessExpiryTime = null)
        {
            var fileService = new SysFileIndexService("");

            #region 从缓存中获取,如果不存在则重建缓存

            var fileIndexCacheKey = new XuHos.Common.Cache.Keys.EntityCacheKey <SysFileIndex>(StringCacheKeyType.SysFileIndex, ResourceID);

            //获取缓存中的数据
            var fileIndex = fileIndexCacheKey.FromCache();

            //从数据库中重建索引
            if (fileIndex == null)
            {
                if (ResourceID.Length == 32)
                {
                    fileIndex = fileService.Single <SysFileIndex>(a => a.MD5 == ResourceID);
                }
                else
                {
                    fileIndex = fileService.Single <SysFileIndex>(a => a.FileUrl == ResourceID);
                }

                if (fileIndex != null)
                {
                    fileIndex.ToCache(fileIndexCacheKey, TimeSpan.FromHours(2));
                }
            }
            #endregion

            //验证访问权限
            if (fileIndex != null && (fileIndex.AccessKey == AccessKey || string.IsNullOrEmpty(fileIndex.AccessKey)))
            {
                var signUrl = XuHos.Common.Storage.Manager.Instance.GetReadAccessSignature(
                    fileIndex.FileType,
                    fileIndex.FileUrl,
                    AccessStartTime,
                    AccessExpiryTime);

                return(signUrl.ToApiResultForObject());
                //return EnumApiStatus.BizOK.ToApiResultForApiStatus(signUrl);
            }
            else
            {
                return(EnumApiStatus.ApiUserUnauthorized.ToApiResultForApiStatus("", "AccessKey 与 ResourceID 不匹配"));
            }
        }
示例#4
0
 /// <summary>
 /// 找回密码
 /// </summary>
 /// <param name="userID"></param>
 /// <param name="userPwd"></param>
 /// <returns></returns>
 public bool ResetPassword(string userID, string userPwd)
 {
     if (base.Update(userID, i => new Entity.User {
         Password = StringEncrypt.EncryptWithMD5(userPwd)
     }))
     {
         //采用缓存淘汰策略
         var cacheKey_User = new XuHos.Common.Cache.Keys.EntityCacheKey <ResponseUserDTO>(StringCacheKeyType.User, userID);
         cacheKey_User.RemoveCache();
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#5
0
        /// <summary>
        /// 修改密码信息
        /// </summary>
        /// <param name="userModel"></param>
        public ApiResult ChangePassword(RequestUserChangePasswordDTO passwordModel)
        {
            try
            {
                using (DBEntities db = new DBEntities())
                {
                    if (passwordModel.NewPassword != passwordModel.ConfirmPassword.Trim())
                    {
                        return(EnumApiStatus.BizChangePasswordConfirmPasswordError.ToApiResultForApiStatus());
                    }

                    if (passwordModel.NewPassword == passwordModel.OldPassword)
                    {
                        return(EnumApiStatus.BizChangePasswordNewPasswordEqualOld.ToApiResultForApiStatus());
                    }

                    string oldMD5 = StringEncrypt.EncryptWithMD5(passwordModel.OldPassword);
                    string oldSHA = StringEncrypt.EncryptWithSHA(passwordModel.OldPassword);

                    var user = db.Users.Where(t => t.UserID == passwordModel.UserID && (t.Password == oldMD5 || t.Password == oldSHA)).FirstOrDefault();

                    if (user == null)
                    {
                        return(EnumApiStatus.BizChangePasswordOldPasswordError.ToApiResultForApiStatus());
                    }
                    user.Password = StringEncrypt.EncryptWithMD5(passwordModel.NewPassword);
                    if (db.SaveChanges() > 0)
                    {
                        var GetUserIDByMobile_CacheKey = new XuHos.Common.Cache.Keys.EntityCacheKey <ResponseUserDTO>(StringCacheKeyType.User, passwordModel.UserID);
                        GetUserIDByMobile_CacheKey.RemoveCache();

                        return(EnumApiStatus.BizOK.ToApiResultForApiStatus("密码修改成功"));
                    }
                    else
                    {
                        return(EnumApiStatus.BizChangePasswordOldPasswordError.ToApiResultForApiStatus());
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteError(ex);
                return(EnumApiStatus.BizError.ToApiResultForApiStatus("修改密码失败"));
            }
        }
示例#6
0
        /// <summary>
        /// 医生 依据 MemberID查询 成员信息
        /// </summary>
        /// <param name="MemberID"></param>
        /// <returns></returns>
        public ResponseUserMemberDTO GetMemberInfo(string MemberID)
        {
            var userMemberCacheKey = new XuHos.Common.Cache.Keys.EntityCacheKey <ResponseUserMemberDTO>
                                         (XuHos.Common.Cache.Keys.StringCacheKeyType.User_Member, MemberID);
            var member = userMemberCacheKey.FromCache();

            if (member == null)
            {
                using (DBEntities db = new DBEntities())
                {
                    member = (from members in db.UserMembers
                              where members.MemberID == MemberID && !members.IsDeleted
                              select members).FirstOrDefault().Map <Entity.UserMember, ResponseUserMemberDTO>();
                    member.ToCache(userMemberCacheKey);
                }
            }
            return(member);
        }
示例#7
0
        /// <summary>
        /// 获取医生排版预约总数
        /// </summary>
        /// <param name="ScheduleID"></param>
        /// <returns></returns>
        int getDoctorScheduleRegNum(string ScheduleID)
        {
            var cacheKey = new XuHos.Common.Cache.Keys.EntityCacheKey <int?>(StringCacheKeyType.Doctor_ScheduleRegNum, ScheduleID);

            var count = cacheKey.FromCache();

            if (count == null)
            {
                using (DBEntities db = new DBEntities())
                {
                    //查询医生排版和对应预约数量
                    count = (from opd in db.Set <UserOPDRegister>().Where(c => c.IsDeleted == false && c.ScheduleID == ScheduleID)
                             //目前没有库管管理(通过订单来判断)
                             join order in db.Orders.Where(a => a.OrderState != EnumOrderState.Canceled) on opd.OPDRegisterID equals order.OrderOutID
                             select opd.ScheduleID).Count();

                    //TODO:这里还没有做库存更新的处理
                    count.ToCache(cacheKey, TimeSpan.FromMinutes(5));
                }
            }

            return(count.Value);
        }
示例#8
0
        /// <summary>
        /// 更新发送频率

        /// 日期:2017年8月29日
        /// </summary>
        /// <param name="Mobile"></param>
        public void UpdateSendRate(string Mobile, Dictionary <string, int> rates)
        {
            var smsDuplicateCacheKey = new XuHos.Common.Cache.Keys.EntityCacheKey <int?>(XuHos.Common.Cache.Keys.StringCacheKeyType.SMS_Duplicate, Mobile);
            var now = DateTime.Now;

            foreach (var point in new Dictionary <string, int>
            {
                { "1M", 1 },
                { "30M", 30 },
                { "24H", 1440 }
            })
            {
                var key  = $"{smsDuplicateCacheKey.KeyName}:{point.Key}";
                var list = XuHos.Common.Cache.Manager.Instance.StringGet <List <DateTime> >(key) ?? new List <DateTime>();
                list.RemoveAll(x => x.AddMinutes(point.Value) <= now);
                list.Add(now);
                Manager.Instance.StringSet(key, list);
                //if (!rates.ContainsKey(point.Key))
                //{
                XuHos.Common.Cache.Manager.Instance.ExpireEntryAt(key, TimeSpan.FromMinutes(point.Value));
                //}
            }
        }
示例#9
0
        /// <summary>
        /// 更新会员信息

        /// 日期:2017年4月15日
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public EnumApiStatus UpdateMemberInfo(BLL.User.DTOs.Request.RequestUserMemberDTO request)
        {
            using (DBEntities db = new DBEntities())
            {
                using (db.BeginTransaction())
                {
                    var model = db.UserMembers.Where(q => q.UserID == request.MemberID && q.MemberID == request.MemberID && q.IsDeleted == false).FirstOrDefault();
                    if (model == null)
                    {
                        return(EnumApiStatus.BizError);
                    }

                    // 当前用户不能有相同身份证的就诊人 add by lrj 2017-7-20
                    if (!string.IsNullOrEmpty(request.IDNumber))
                    {
                        var mid = db.UserMembers.Where(q => q.IDNumber == request.IDNumber && q.MemberID != model.MemberID &&
                                                       q.IsDeleted == false).Select(q => q.MemberID).FirstOrDefault();
                    }

                    #region 必填参数
                    model.MemberName = request.MemberName;
                    // model.Relation = request.Relation;
                    model.Gender     = request.Gender;
                    model.Marriage   = request.Marriage;
                    model.IDType     = request.IDType;
                    model.MemberName = request.MemberName;
                    #endregion

                    #region 可选参数(有值才修改)
                    if (request.Birthday != null)
                    {
                        model.Birthday = request.Birthday;
                    }

                    if (request.Mobile != null)
                    {
                        model.Mobile = request.Mobile;
                    }

                    if (request.IDNumber != null)
                    {
                        model.IDNumber = request.IDNumber;
                    }

                    if (request.Nationality != null)
                    {
                        model.Nationality = request.Nationality;
                    }
                    if (request.Province != null)
                    {
                        model.Province = request.Province;
                    }

                    if (request.ProvinceRegionID != null)
                    {
                        model.ProvinceRegionID = request.ProvinceRegionID;
                    }

                    if (request.City != null)
                    {
                        model.City = request.City;
                    }

                    if (request.CityRegionID != null)
                    {
                        model.CityRegionID = request.CityRegionID;
                    }

                    if (request.District != null)
                    {
                        model.District = request.District;
                    }

                    if (request.DistrictRegionID != null)
                    {
                        model.DistrictRegionID = request.DistrictRegionID;
                    }

                    if (request.Town != null)
                    {
                        model.Town = request.Town;
                    }

                    if (request.TownRegionID != null)
                    {
                        model.TownRegionID = request.TownRegionID;
                    }

                    if (request.Village != null)
                    {
                        model.Village = request.Village;
                    }

                    if (request.VillageRegionID != null)
                    {
                        model.VillageRegionID = request.VillageRegionID;
                    }

                    if (request.Address != null)
                    {
                        model.Address = request.Address;
                    }

                    if (request.Email != null)
                    {
                        model.Email = request.Email;
                    }

                    if (request.PostCode != null)
                    {
                        model.PostCode = request.PostCode;
                    }

                    #endregion

                    #region 是否已经存在本人关系的就诊人
                    if (request.Relation == EnumUserRelation.MySelf)
                    {
                        var members = GetMemberList(request.UserID);

                        //本人关系已经存在
                        if (members.Any(a => a.Relation == EnumUserRelation.MySelf && a.MemberID != model.MemberID))
                        {
                            return(EnumApiStatus.BizUserMemberRejectUpdateMySelfExists);
                        }
                    }
                    #endregion

                    #region 通过身份证号码获取性别和身份证号码
                    if (model.IDType == EnumUserCardType.IDCard && !string.IsNullOrEmpty(model.IDNumber))
                    {
                        string birthday, sex;
                        var    res = ToolHelper.GetBirthdaySexFromIdCard(model.IDNumber, out birthday, out sex);

                        //身份证号码正确
                        if (res)
                        {
                            model.Birthday = birthday;
                            model.Gender   = sex == "0" ? EnumUserGender.Male : EnumUserGender.Female;
                        }
                        else
                        {
                            //身份证号码格式错误
                            return(EnumApiStatus.BizUserMemberRejectInsertUpdateIDNumberFormatError);
                        }
                    }
                    #endregion

                    model.Relation = request.Relation;
                    if (request.IsDefault.HasValue && request.IsDefault == true)
                    {
                        model.IsDefault = true;
                    }
                    else if (request.IsDefault.HasValue && request.IsDefault == false)
                    {
                        model.IsDefault = false;
                    }

                    if (request.Relation == EnumUserRelation.MySelf)
                    {
                        var user = db.Users.Where(a => a.UserID == request.UserID).FirstOrDefault();
                        user.UserCNName = model.MemberName;
                        user.UserENName = model.MemberName;
                    }


                    if (db.SaveChanges() > 0)
                    {
                        db.Commit();
                        var userMemberCacheKey = new XuHos.Common.Cache.Keys.EntityCacheKey <ResponseUserMemberDTO>(XuHos.Common.Cache.Keys.StringCacheKeyType.User_Member, model.MemberID);
                        userMemberCacheKey.RemoveCache();

                        var User_CacheKey = new XuHos.Common.Cache.Keys.EntityCacheKey <ResponseUserDTO>(XuHos.Common.Cache.Keys.StringCacheKeyType.User, request.UserID);
                        User_CacheKey.RemoveCache();
                    }
                }
                //设置默认
                if (request.IsDefault.HasValue && request.IsDefault.Value)
                {
                    SetDefaultMember(request.MemberID, request.UserID);
                }
                return(EnumApiStatus.BizOK);
            }
        }
示例#10
0
        /// <summary>
        /// 新增成员

        /// 日期:2017年4月15日
        /// </summary>
        /// <param name="userMemberEntity"></param>
        /// <returns></returns>
        public ApiResult InsertMemberInfo(BLL.User.DTOs.Request.RequestUserMemberDTO request)
        {
            ApiResult result = new ApiResult();

            string memberid = string.Empty;

            #region 身份证号码格式校验
            if (!string.IsNullOrEmpty(request.IDNumber) && request.IDType == EnumUserCardType.IDCard)
            {
                string birthday, sex;
                var    res = ToolHelper.GetBirthdaySexFromIdCard(request.IDNumber, out birthday, out sex);

                //身份证号码正确
                if (res)
                {
                    request.Birthday = birthday;
                    request.Gender   = sex == "0" ? EnumUserGender.Male : EnumUserGender.Female;
                }
                else
                {
                    result.Status = EnumApiStatus.BizUserMemberRejectInsertUpdateIDNumberFormatError;
                    result.Msg    = result.Status.GetEnumDescript();
                    return(result);
                }
            }
            #endregion

            using (DBEntities db = new DBEntities())
            {
                using (db.BeginTransaction())
                {
                    db.Configuration.AutoDetectChangesEnabled = true;
                    bool       isAdd            = false;
                    UserMember userMemberEntity = null;
                    if (!string.IsNullOrEmpty(request.IDNumber))
                    {
                        userMemberEntity = (from q in db.UserMembers
                                            where q.IDNumber == request.IDNumber && q.MemberName == request.MemberName && q.IsDeleted == false
                                            orderby q.ModifyTime descending, q.CreateTime descending, q.MemberID
                                            select q).FirstOrDefault();
                    }

                    if (userMemberEntity == null)
                    {
                        isAdd = true;
                        #region 可选参数(默认值)
                        if (request.Birthday == null)
                        {
                            request.Birthday = "";
                        }

                        if (request.Mobile == null)
                        {
                            request.Mobile = "";
                        }

                        if (request.IDNumber == null)
                        {
                            request.IDNumber = "";
                        }

                        if (request.Nationality == null)
                        {
                            request.Nationality = "";
                        }

                        if (request.Province == null)
                        {
                            request.Province = "";
                        }
                        if (request.ProvinceRegionID == null)
                        {
                            request.ProvinceRegionID = "";
                        }

                        if (request.City == null)
                        {
                            request.City = "";
                        }
                        if (request.CityRegionID == null)
                        {
                            request.CityRegionID = "";
                        }

                        if (request.District == null)
                        {
                            request.District = "";
                        }
                        if (request.DistrictRegionID == null)
                        {
                            request.DistrictRegionID = "";
                        }

                        if (request.Town == null)
                        {
                            request.Town = "";
                        }
                        if (request.TownRegionID == null)
                        {
                            request.TownRegionID = "";
                        }

                        if (request.Village == null)
                        {
                            request.Village = "";
                        }
                        if (request.VillageRegionID == null)
                        {
                            request.VillageRegionID = "";
                        }

                        if (request.Address == null)
                        {
                            request.Address = "";
                        }

                        if (request.Email == null)
                        {
                            request.Email = "";
                        }

                        if (request.PostCode == null)
                        {
                            request.PostCode = "";
                        }

                        if (request.IsDefault == null || !request.IsDefault.HasValue)
                        {
                            request.IsDefault = false;
                        }
                        #endregion
                        userMemberEntity              = request.Map <RequestUserMemberDTO, Entity.UserMember>();
                        userMemberEntity.MemberID     = Guid.NewGuid().ToString("N");
                        userMemberEntity.CreateTime   = DateTime.Now;
                        userMemberEntity.CreateUserID = request.UserID;
                    }


                    //默认成员
                    var defaultMemberEntity = GetDefaultMemberInfo(request.UserID).Map <ResponseUserMemberDTO, Entity.UserMember>();

                    memberid = userMemberEntity.MemberID;

                    //默认成员不存在
                    if (defaultMemberEntity == null)
                    {
                        //当前成员为默认
                        userMemberEntity.IsDefault = true;
                    }

                    if (request.Relation == EnumUserRelation.MySelf)
                    {
                        var userEntity = db.Users.Where(a => a.UserID == request.UserID).FirstOrDefault();
                        userEntity.UserCNName = request.MemberName;
                        userEntity.UserENName = request.MemberName;
                        var mySelfMember = (from m in db.UserMembers
                                            where m.UserID == request.UserID && m.Relation == EnumUserRelation.MySelf &&
                                            m.IsDeleted == false && m.IsDeleted == false
                                            select m).FirstOrDefault();

                        //如果默认成员已经存在则更新默认成员
                        if (mySelfMember != null)
                        {
                            //兼容bat 服务站,新增自己关系是,要是原来的自己关系信息不完整(身份证号为空),则覆盖
                            //身份证不为空,且操作机构不为网络医院
                            var webapiConfig = SysConfigService.Get <XuHos.Common.Config.Sections.Api>();
                            if (string.IsNullOrEmpty(mySelfMember.IDNumber) && request.OrgID != webapiConfig.OrgID)
                            {
                                mySelfMember.Gender     = request.Gender;
                                mySelfMember.Marriage   = request.Marriage;
                                mySelfMember.MemberName = request.MemberName;

                                #region 可选参数(有值才修改)
                                if (request.Birthday != null)
                                {
                                    mySelfMember.Birthday = request.Birthday;
                                }

                                if (request.Mobile != null)
                                {
                                    mySelfMember.Mobile = request.Mobile;
                                }

                                if (request.IDNumber != null)
                                {
                                    mySelfMember.IDNumber = request.IDNumber;
                                }

                                if (request.Nationality != null)
                                {
                                    mySelfMember.Nationality = request.Nationality;
                                }
                                if (request.Province != null)
                                {
                                    mySelfMember.Province = request.Province;
                                }

                                if (request.ProvinceRegionID != null)
                                {
                                    mySelfMember.ProvinceRegionID = request.ProvinceRegionID;
                                }

                                if (request.City != null)
                                {
                                    mySelfMember.City = request.City;
                                }

                                if (request.CityRegionID != null)
                                {
                                    mySelfMember.CityRegionID = request.CityRegionID;
                                }

                                if (request.District != null)
                                {
                                    mySelfMember.District = request.District;
                                }

                                if (request.DistrictRegionID != null)
                                {
                                    mySelfMember.DistrictRegionID = request.DistrictRegionID;
                                }

                                if (request.Town != null)
                                {
                                    mySelfMember.Town = request.Town;
                                }

                                if (request.TownRegionID != null)
                                {
                                    mySelfMember.TownRegionID = request.TownRegionID;
                                }

                                if (request.Village != null)
                                {
                                    mySelfMember.Village = request.Village;
                                }

                                if (request.VillageRegionID != null)
                                {
                                    mySelfMember.VillageRegionID = request.VillageRegionID;
                                }

                                if (request.Address != null)
                                {
                                    mySelfMember.Address = request.Address;
                                }

                                if (request.Email != null)
                                {
                                    mySelfMember.Email = request.Email;
                                }

                                if (request.PostCode != null)
                                {
                                    mySelfMember.PostCode = request.PostCode;
                                }

                                #endregion
                                memberid = mySelfMember.MemberID;
                                db.Update(mySelfMember);
                            }
                            else
                            {
                                result.Status = EnumApiStatus.BizUserMemberRejectUpdateMySelfExists;
                                result.Msg    = result.Status.GetEnumDescript();
                                return(result);
                            }
                        }
                    }

                    if (isAdd)
                    {
                        db.UserMembers.Add(userMemberEntity);
                    }
                    //db.Update(userEntity);
                    var count = db.SaveChanges();
                    db.Commit();
                    if (count > 0)
                    {
                        var userMemberCacheKey = new XuHos.Common.Cache.Keys.EntityCacheKey <ResponseUserMemberDTO>(XuHos.Common.Cache.Keys.StringCacheKeyType.User_Member, userMemberEntity.MemberID);
                        userMemberCacheKey.RemoveCache();

                        var User_CacheKey = new XuHos.Common.Cache.Keys.EntityCacheKey <ResponseUserDTO>(XuHos.Common.Cache.Keys.StringCacheKeyType.User, request.UserID);
                        User_CacheKey.RemoveCache();
                        result.Status = EnumApiStatus.BizOK;
                    }
                    else
                    {
                        result.Status = EnumApiStatus.BizError;
                    }
                }
                //设置默认
                if (request.IsDefault.HasValue && request.IsDefault.Value)
                {
                    SetDefaultMember(memberid, request.UserID);
                }
                result.Data = memberid;
                result.Msg  = result.Status.GetEnumDescript();
                return(result);
            }
        }
示例#11
0
        public async Task <HttpResponseMessage> Download(
            string FileType,
            string ResourceID,
            string ResizeCMD = "")
        {
            return(await Task.Run <HttpResponseMessage>(async() =>
            {
                HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);

                SysFileIndexService fileService = new SysFileIndexService(CurrentOperatorUserID);

                SysFileIndex fileIndex = null;

                #region 修正命令
                if (!string.IsNullOrEmpty(ResizeCMD) && !ResizeCMD.ToUpper().Contains("X"))
                {
                    ResourceID = ResourceID + "." + ResizeCMD;
                    ResizeCMD = "";
                }
                #endregion

                ResourceID = ResourceID.ToUpper();

                #region 从缓存中获取,如果不存在则重建缓存

                var fileIndexCacheKey = new XuHos.Common.Cache.Keys.EntityCacheKey <SysFileIndex>(StringCacheKeyType.SysFileIndex, ResourceID);

                //获取缓存中的数据
                fileIndex = fileIndexCacheKey.FromCache();

                //从数据库中重建索引
                if (fileIndex == null)
                {
                    if (ResourceID.Length == 32)
                    {
                        fileIndex = fileService.Single <SysFileIndex>(a => a.MD5 == ResourceID && a.FileType == FileType);
                    }
                    else
                    {
                        fileIndex = fileService.Single <SysFileIndex>(a => a.FileUrl == ResourceID && a.FileType == FileType);
                    }

                    if (fileIndex != null)
                    {
                        fileIndex.ToCache(fileIndexCacheKey, TimeSpan.FromHours(2));
                    }
                }
                #endregion

                if (fileIndex != null)
                {
                    string etag = string.Format("\"{0}\"", fileIndex.MD5);
                    var tag = Request.Headers.IfNoneMatch.FirstOrDefault();
                    if (Request.Headers.IfModifiedSince.HasValue && tag != null && tag.Tag == etag)
                    {
                        result.StatusCode = HttpStatusCode.NotModified;
                    }
                    else
                    {
                        #region 重新读取文件

                        if (XuHos.Common.Storage.Manager.Instance.Exists(FileType, fileIndex.FileUrl))
                        {
                            #region 文件存在

                            //不需要缩放
                            if (!string.IsNullOrEmpty(ResizeCMD) && FileType.ToLower() == "images")
                            {
                                //80X80 统一成小写  Exists 的时候 不区分大小,但是OpenFile确区分大小写
                                ResizeCMD = ResizeCMD.ToLower();
                                //E:\XXX\XXX.80X80.jpg
                                var resizeImgOtputPath = string.Format("{0}.{1}", fileIndex.FileUrl, ResizeCMD);

                                if (XuHos.Common.Storage.Manager.Instance.Exists(FileType, resizeImgOtputPath))
                                {
                                    var stream = await XuHos.Common.Storage.Manager.Instance.OpenFile(FileType, resizeImgOtputPath);
                                    result.Content = new StreamContent(stream);
                                }
                                else
                                {
                                    var stream = await XuHos.Common.Storage.Manager.Instance.OpenFile(FileType, fileIndex.FileUrl);

                                    using (ImageMagick.MagickImage image = new ImageMagick.MagickImage(stream))
                                    {
                                        ImageMagick.MagickGeometry size = new ImageMagick.MagickGeometry(ResizeCMD);

                                        image.Resize(size);

                                        var resizeStream = new System.IO.MemoryStream();

                                        image.Write(resizeStream);

                                        await XuHos.Common.Storage.Manager.Instance.WriteFile(FileType, resizeImgOtputPath, resizeStream);

                                        result.Content = new ByteArrayContent(image.ToByteArray());
                                    }
                                }
                            }
                            else
                            {
                                var stream = await XuHos.Common.Storage.Manager.Instance.OpenFile(FileType, fileIndex.FileUrl);
                                result.Content = new StreamContent(stream);
                            }

                            #endregion

                            result.Content.Headers.ContentType = new MediaTypeHeaderValue("Store/octet-stream");
                            result.Content.Headers.Add("Content-Disposition", "attachment;filename=\"" + HttpUtility.UrlEncode(fileIndex.Remark) + "\"");
                            result.Headers.ETag = new EntityTagHeaderValue(etag);
                            result.Headers.CacheControl = new CacheControlHeaderValue();
                            result.Headers.CacheControl.Public = true;
                            result.Headers.CacheControl.MaxAge = TimeSpan.FromHours(480);
                            result.Content.Headers.Expires = DateTimeOffset.Now.AddDays(20);
                            result.Content.Headers.LastModified = fileIndex.CreateTime;
                        }
                        else
                        {
                            result.StatusCode = HttpStatusCode.NotFound;
                        }
                        #endregion
                    }
                }
                else
                {
                    result.StatusCode = HttpStatusCode.NotFound;
                }

                return result;
            }));
        }
示例#12
0
        /// <summary>
        /// 上传文件

        /// 日期:2016年9月28日
        /// </summary>
        /// <param name="FileType">文件类型</param>
        /// <param name="Directory">文件保存路径</param>
        /// <param name="PreMD5">预处理Md5哈希值</param>
        /// <returns></returns>
        public async Task <ApiResult> Upload(
            string FileType  = "images",
            string Directory = null,
            string PreMD5    = "",
            string AccessKey = "",
            string Name      = "")
        {
            // 检查是否是 multipart/form-data
            if (!Request.Content.IsMimeMultipartContent("form-data"))
            {
                return(EnumApiStatus.BizError.ToApiResultForApiStatus("UnsupportedMediaType"));
            }

            try
            {
                //文件存储配置
                var config = SysConfigService.Get <XuHos.Common.Config.Sections.IMGStore>();

                SysFileIndex fileIndex = null;

                //通过缓存来判断文件是否已经上传了
                XuHos.Common.Cache.Keys.EntityCacheKey <SysFileIndex> CacheKey;

                //预处理文件Hash,客户端进行哈希值计算
                if (PreMD5 != "")
                {
                    CacheKey = new XuHos.Common.Cache.Keys.EntityCacheKey <SysFileIndex>(StringCacheKeyType.SysFileIndex, PreMD5);
                    //缓存中获取文件索引
                    fileIndex = CacheKey.FromCache();
                }

                //文件已经存在,则使用妙传(不需要保存直接返回之前已经上传的问题)
                if (fileIndex != null)
                {
                    //返回上传结果
                    return(new ResponseUploadFileDTO
                    {
                        UrlPrefix = config.UrlPrefix,
                        FileName = string.IsNullOrEmpty(Name) ? string.Format("{0}/{1}", FileType, fileIndex.FileUrl) : Name,
                        MD5 = fileIndex.MD5,
                        FileSize = fileIndex.FileSize,
                        FileSeq = fileIndex.MD5,
                        AccessKey = fileIndex.AccessKey
                    }.ToApiResultForObject());
                }
                else
                {
                    var httpPostFile = HttpContext.Current.Request.Files[0];

                    var FileStream = httpPostFile.InputStream;

                    var RequestFileName = httpPostFile.FileName;

                    FileStream.Seek(0, SeekOrigin.Begin);

                    var FileMD5 = XuHos.Common.Utility.HashHelper.ComputeMD5(FileStream);

                    //扩展名
                    var FileUrl = FileMD5 + Path.GetExtension(RequestFileName);

                    var FileSize = FileStream.Length;

                    //通过缓存来判断文件是否已经上传了
                    CacheKey = new XuHos.Common.Cache.Keys.EntityCacheKey <SysFileIndex>(StringCacheKeyType.SysFileIndex, FileMD5);

                    //缓存中获取文件索引
                    fileIndex = CacheKey.FromCache();

                    //文件已经存在
                    if (fileIndex != null)
                    {
                        //返回上传结果
                        return(new ResponseUploadFileDTO
                        {
                            UrlPrefix = config.UrlPrefix,
                            FileName = string.IsNullOrEmpty(Name) ? string.Format("{0}/{1}", fileIndex.FileType, fileIndex.FileUrl) : Name,
                            MD5 = fileIndex.MD5,
                            FileSize = fileIndex.FileSize,
                            FileSeq = fileIndex.MD5,
                            AccessKey = fileIndex.AccessKey
                        }.ToApiResultForObject());
                    }
                    //文件不存在的才保存到服务器
                    else
                    {
                        await XuHos.Common.Storage.Manager.Instance.WriteFile(FileType, FileUrl, FileStream);

                        SysFileIndexService fileService = new SysFileIndexService(CurrentOperatorUserID);
                        fileIndex = new SysFileIndex()
                        {
                            MD5       = FileMD5,
                            FileType  = FileType,
                            FileUrl   = FileUrl,
                            FileSize  = FileSize,
                            Remark    = string.IsNullOrEmpty(Name) ? FileUrl : Name,
                            AccessKey = AccessKey
                        };

                        var result = new ResponseUploadFileDTO
                        {
                            UrlPrefix = config.UrlPrefix,
                            FileName  = string.IsNullOrEmpty(Name) ? string.Format("{0}/{1}", FileType, FileUrl) : Name,
                            MD5       = FileMD5,
                            FileSize  = FileSize,
                            FileSeq   = fileIndex.MD5,
                            AccessKey = fileIndex.AccessKey
                        };

                        var SaveFlag = false;

                        //文件不存在
                        if (!fileService.Exists(a => a.MD5 == FileMD5))
                        {
                            try
                            {
                                //添加记录
                                SaveFlag = fileService.Insert(fileIndex);
                            }
                            //主键冲突异常
                            catch (ConstraintException ex)
                            {
                                SaveFlag = true;
                            }
                        }
                        else
                        {
                            fileService.Update(fileIndex);
                            SaveFlag = true;
                        }

                        //保存成功
                        if (SaveFlag)
                        {
                            //设置缓存
                            fileIndex.ToCache(CacheKey, TimeSpan.FromHours(2));

                            return(result.ToApiResultForObject());
                        }
                        else
                        {
                            return(EnumApiStatus.BizError.ToApiResultForApiStatus());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
                if (ex.InnerException != null)
                {
                    msg += System.Environment.NewLine + ex.InnerException.Message;

                    if (ex.InnerException.InnerException != null)
                    {
                        msg += System.Environment.NewLine + ex.InnerException.InnerException.Message;
                    }
                }
                LogHelper.WriteError(ex);

                return(EnumApiStatus.BizError.ToApiResultForApiStatus("上传失败,错误:" + msg));
            }
        }
示例#13
0
        public async Task <ApiResult> UploadDCM(string Md5 = "", string AccessKey = "")
        {
            var res = await Upload("dcm", "", PreMD5 : Md5, AccessKey : AccessKey);

            if (res.Status != 0)
            {
                return(res);
            }

            var data   = res.Data as ResponseUploadFileDTO;
            var result = data.Map <ResponseUploadFileDTO, DcmDTO>();

            #region //获取文件路径
            string filePath = "";
            //缓存中获取文件索引
            var CacheKey = new XuHos.Common.Cache.Keys.EntityCacheKey <SysFileIndex>(StringCacheKeyType.SysFileIndex, result.MD5);

            SysFileIndex fileIndex = CacheKey.FromCache();

            if (fileIndex != null)
            {
                filePath = fileIndex.FileUrl;
            }
            else
            {
                //从数据库中获取文件索引
                var file = new SysFileIndexService(CurrentOperatorUserID).Single <SysFileIndex>(a => a.MD5 == result.MD5);
                if (file == null)
                {
                    filePath = file.FileUrl;
                }
            }
            if (string.IsNullOrEmpty(filePath))
            {
                return(EnumApiStatus.BizError.ToApiResultForApiStatus());
            }
            #endregion

            #region//解析DCM文件参数
            var config       = SysConfigService.Get <IMGStore>();
            var fileFullPath = Path.Combine(config.DirectorRootPath, filePath);
            Dictionary <string, string> tags = DCMHelper.TagRead(fileFullPath);
            string caseId  = null; //病例号
            string studyId = null; //检查号
            string stuUid  = null;
            if (tags != null)
            {
                tags.TryGetValue("0010,0020", out caseId);
                tags.TryGetValue("0008,0050", out studyId);
                tags.TryGetValue("0020,000d", out stuUid);
            }
            result.CaseID = caseId != null?caseId.Trim() : "";

            result.StudyID = studyId != null?studyId.Trim() : "";

            result.StuUID = stuUid != null?stuUid.TrimEnd('\0').Trim() : "";

            #endregion

            return(result.ToApiResultForObject());
        }
示例#14
0
        public async Task <ApiResult> UploadImageByBase64([FromBody] BLL.Sys.DTOs.Request.RequestUploadImageByBase64DTO request)
        {
            byte[] byteData = Convert.FromBase64String(request.Content.Replace("data:image/png;base64", ""));

            var FileType = "Images";

            try
            {
                //文件存储配置
                var config = SysConfigService.Get <XuHos.Common.Config.Sections.IMGStore>();

                SysFileIndex fileIndex = null;

                var FileStream = new System.IO.MemoryStream(byteData);

                var FileMD5 = XuHos.Common.Utility.HashHelper.ComputeMD5(FileStream);

                //通过缓存来判断文件是否已经上传了
                var CacheKey = new XuHos.Common.Cache.Keys.EntityCacheKey <SysFileIndex>(StringCacheKeyType.SysFileIndex, FileMD5);

                //缓存中获取文件索引
                fileIndex = CacheKey.FromCache();

                //文件已经存在
                if (fileIndex != null)
                {
                    //返回上传结果
                    return(new ResponseUploadFileDTO
                    {
                        UrlPrefix = config.UrlPrefix,
                        FileName = string.Format("{0}/{1}", fileIndex.FileType, fileIndex.FileUrl),
                        MD5 = fileIndex.MD5,
                        FileSize = fileIndex.FileSize,
                        FileSeq = request.FileSeq
                    }.ToApiResultForObject());
                }
                //文件不存在的才保存到服务器
                else
                {
                    SysFileIndexService fileService = new SysFileIndexService(CurrentOperatorUserID);

                    //文件不存在
                    if (fileService.Exists(a => a.MD5 == FileMD5))
                    {
                        fileIndex = fileService.Single <SysFileIndex>(a => a.MD5 == FileMD5);

                        if (fileIndex != null)
                        {
                            //设置缓存
                            fileIndex.ToCache(CacheKey, TimeSpan.FromHours(2));

                            var result = new ResponseUploadFileDTO
                            {
                                UrlPrefix = config.UrlPrefix,
                                FileName  = string.Format("{0}/{1}", fileIndex.FileType, fileIndex.FileUrl),
                                MD5       = fileIndex.MD5,
                                FileSize  = fileIndex.FileSize,
                                FileSeq   = request.FileSeq
                            };

                            return(result.ToApiResultForObject());
                        }
                        else
                        {
                            return(EnumApiStatus.BizError.ToApiResultForApiStatus());
                        }
                    }
                    else
                    {
                        //文件名
                        var FileUrl = Guid.NewGuid().ToString("N") + ".jpg";

                        var FileSize = FileStream.Length;

                        await XuHos.Common.Storage.Manager.Instance.WriteFile(FileType, FileUrl, FileStream);

                        fileIndex = new SysFileIndex()
                        {
                            MD5       = FileMD5,
                            FileType  = FileType,
                            FileUrl   = FileUrl,
                            FileSize  = FileSize,
                            Remark    = "",
                            AccessKey = string.IsNullOrEmpty(request.AccessKey) ? "" : request.AccessKey
                        };

                        var result = new ResponseUploadFileDTO
                        {
                            UrlPrefix = config.UrlPrefix,
                            FileName  = string.Format("{0}/{1}", FileType, FileUrl),
                            MD5       = FileMD5,
                            FileSize  = FileSize,
                            FileSeq   = request.FileSeq,
                            AccessKey = request.AccessKey
                        };

                        var SaveFlag = false;

                        //文件不存在
                        if (!fileService.Exists(a => a.MD5 == FileMD5))
                        {
                            try
                            {
                                //添加记录
                                SaveFlag = fileService.Insert(fileIndex);
                            }
                            //主键冲突异常
                            catch (ConstraintException ex)
                            {
                                SaveFlag = true;
                            }
                        }
                        else
                        {
                            SaveFlag = true;
                        }

                        //保存成功
                        if (SaveFlag)
                        {
                            //设置缓存
                            fileIndex.ToCache(CacheKey, TimeSpan.FromHours(2));

                            return(result.ToApiResultForObject());
                        }
                        else
                        {
                            return(EnumApiStatus.BizError.ToApiResultForApiStatus());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
                if (ex.InnerException != null)
                {
                    msg += System.Environment.NewLine + ex.InnerException.Message;

                    if (ex.InnerException.InnerException != null)
                    {
                        msg += System.Environment.NewLine + ex.InnerException.InnerException.Message;
                    }
                }
                LogHelper.WriteError(ex);

                return(EnumApiStatus.BizError.ToApiResultForApiStatus("上传失败,错误:" + msg));
            }
        }
示例#15
0
        /// <summary>
        /// 根据用户编号获取用户信息
        /// </summary>
        /// <param name="userId"></param>
        public ResponseUserDTO GetUserInfoByUserId(string userId)
        {
            if (string.IsNullOrEmpty(userId))
            {
                return(default(ResponseUserDTO));
            }

            var User_CacheKey = new XuHos.Common.Cache.Keys.EntityCacheKey <ResponseUserDTO>(StringCacheKeyType.User, userId);
            var userModel     = User_CacheKey.FromCache();

            if (userModel == null)
            {
                using (DBEntities db = new DBEntities())
                {
                    var query = from user in db.Users.Where(a => a.UserID == userId && a.IsDeleted == false)
                                join userUid in db.ConversationIMUids on user.UserID equals userUid.UserID
                                select new ResponseUserDTO()
                    {
                        CancelTime   = user.CancelTime,
                        Email        = user.Email,
                        Identifier   = userUid.Identifier,
                        UserID       = user.UserID,
                        Mobile       = user.Mobile,
                        Password     = user.Password,
                        PhotoUrl     = user.PhotoUrl,
                        RegTime      = user.RegTime,
                        UserType     = user.UserType,
                        UserState    = user.UserState,
                        UserLevel    = user.UserLevel,
                        UserAccount  = user.UserAccount,
                        OrgID        = user.OrgCode,
                        UserCNName   = user.UserCNName,
                        UserENName   = user.UserENName,
                        CreateUserID = user.CreateUserID
                    };

                    userModel = query.FirstOrDefault();

                    if (userModel != null)
                    {
                        XuHos.BLL.User.Implements.UserMemberService service = new UserMemberService();
                        var MemberIsEmpty = service.GetMemberList(userModel.UserID).Find(a => a.Relation == EnumUserRelation.MySelf);

                        //取 usercnname, 先取自己关系membername, 为空则取users.usercname,还为空则取手机号
                        var UserCNName = userModel.UserCNName;
                        if (MemberIsEmpty != null && !string.IsNullOrWhiteSpace(MemberIsEmpty.MemberName))
                        {
                            UserCNName = MemberIsEmpty.MemberName;
                        }

                        if (string.IsNullOrEmpty(UserCNName))
                        {
                            UserCNName = userModel.Mobile;
                        }
                        userModel.UserCNName = UserCNName;
                        userModel.UserENName = MemberIsEmpty != null ? MemberIsEmpty.MemberName : userModel.UserENName;
                        userModel.MemberID   = MemberIsEmpty != null ? MemberIsEmpty.MemberID : "";
                        userModel.IDType     = MemberIsEmpty != null ? MemberIsEmpty.IDType : EnumUserCardType.IDCard;
                        userModel.IDNumber   = MemberIsEmpty != null ? MemberIsEmpty.IDNumber : "";
                        userModel.Gender     = MemberIsEmpty != null ? MemberIsEmpty.Gender : EnumUserGender.Other;
                    }

                    userModel.ToCache(User_CacheKey, TimeSpan.FromMinutes(_GetUserInfoExpireMinutes()));
                }
            }

            return(userModel);
        }