Exemplo n.º 1
0
        public ActionResult ShareFile(string name)
        {
            List <FileInfo>      f = new List <FileInfo>();
            List <DirectoryInfo> d = new List <DirectoryInfo>();

            try
            {
                var dirs  = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "\\Share\\" + name + "\\").GetDirectories();
                var files = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "\\Share\\" + name + "\\").GetFiles();

                foreach (var file in files)
                {
                    f.Add(file);
                }

                foreach (var dir in dirs)
                {
                    d.Add(dir);
                }

                ApplicationLog.Debug(name);

                ViewData.Add("name", name.ToUpper());
            }
            catch (Exception ee)
            {
                ApplicationLog.Error(ee.ToString());
            }

            ViewData.Add("file", f);
            ViewData.Add("dir", d);

            return(View());
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取借阅详情
        /// </summary>
        public async Task <CommonResponse <GetBorrowDetailResult> > GetBorrowDetail(GetBorrowDetailRequest request)
        {
            var response = new CommonResponse <GetBorrowDetailResult>();

            try
            {
                if (request == null)
                {
                    throw new BizException("参数不能为空");
                }
                var borrowRegister = await _db.BorrowRegister.AsNoTracking().FirstOrDefaultAsync(c => c.Id == request.BorrowRegisterId && !c.Deleted);

                if (borrowRegister == null)
                {
                    throw new BizException("借阅登记不存在");
                }

                var archivesList = await _db.ArchivesInfo.AsNoTracking().Join(_db.BorrowRegisterDetail.AsNoTracking(), a => a.Id, b => b.ArchivesId, (a, b) => new { a, b })
                                   .Where(j => j.b.BorrowRegisterId == borrowRegister.Id).Select(c => new ArchivesSearchResult
                {
                    Id             = c.a.Id,
                    ArchivesNumber = c.a.ArchivesNumber,
                    CategoryId     = c.a.CategoryId,
                    FileNumber     = c.a.FileNumber,
                    ProjectName    = c.a.ProjectName,
                    Title          = c.a.Title,
                    OrderNumber    = c.a.OrderNumber,
                }).ToListAsync();

                response.Data = new GetBorrowDetailResult
                {
                    BorrowRegister = new BorrowRegisterSimple
                    {
                        Id            = borrowRegister.Id,
                        Borrower      = borrowRegister.Borrower,
                        Company       = borrowRegister.Company,
                        Phone         = borrowRegister.Phone,
                        ReturnDate    = borrowRegister.ReturnDate,
                        ReturnDateStr = borrowRegister.ReturnDate.ToString("yyyy-MM-dd"),
                        Department    = borrowRegister.Department,
                        SignPhoto     = borrowRegister.SignPhoto,
                        CreateTime    = borrowRegister.CreateTime,
                        CreateTimeStr = borrowRegister.CreateTime.ToString("yyyy-MM-dd"),
                        Status        = borrowRegister.Status
                    },
                    ArchivesList = archivesList
                };
                response.Success = true;
            }
            catch (BizException ex)
            {
                response.Message = ex.Message;
            }
            catch (Exception ex)
            {
                response.Message = "获取借阅详情发生异常";
                ApplicationLog.Error("GetBorrowDetail", ex);
            }
            return(response);
        }
Exemplo n.º 3
0
        public async Task <CommonResponse <ArchivesInfo> > GetArchives(int id)
        {
            var response = new CommonResponse <ArchivesInfo>();

            try
            {
                var archives = await _db.ArchivesInfo.AsNoTracking().FirstOrDefaultAsync(c => c.Id == id && !c.Deleted);

                if (archives == null)
                {
                    throw new BizException("档案不存在或已删除");
                }
                //var archivesDetails = await _db.ArchivesDetails.Where(c => c.ArchivesId == archivesId && !c.Deleted).ToListAsync();
                response.Data    = archives;
                response.Success = true;
            }
            catch (BizException ex)
            {
                response.Message = ex.Message;
            }
            catch (Exception ex)
            {
                response.Message = "获取档案详情失败";
                ApplicationLog.Error("GetArchives", ex);
                //写日志可以用log4netcore
            }
            return(response);
        }
Exemplo n.º 4
0
        internal static FieldInfo GetEntityField(Object gameEntity, string fieldName)
        {
            try
            {
                FieldInfo field = gameEntity.GetType( ).GetField(fieldName);
                if (field == null)
                {
                    //Recurse up through the class heirarchy to try to find the field
                    Type type = gameEntity.GetType( );
                    while (type != typeof(Object))
                    {
                        field = type.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);
                        if (field != null)
                        {
                            break;
                        }

                        type = type.BaseType;
                    }
                }
                return(field);
            }
            catch (Exception ex)
            {
                ApplicationLog.Error(string.Format("Failed to get entity field '{0}'", fieldName));
                return(null);
            }
        }
        public async Task <CommonResponse <ArchivesEditResult> > Edit(ArchivesEditRequest request)
        {
            var response = new CommonResponse <ArchivesEditResult>();

            try
            {
                if (request == null)
                {
                    throw new BizException("参数不能为空");
                }

                var entity = await _db.ArchivesInfo.FirstOrDefaultAsync(c => c.Id == request.Id);

                if (entity == null)
                {
                    throw new BizException("档案不存在");
                }

                if (entity.Deleted)
                {
                    throw new BizException("档案已删除,无法修改");//此条件需要放在where条件中么?
                }
                //if (entity.Status != ArchivesStatus.Init)
                //    throw new BizException("档案已借阅过,无法再编辑");

                //entity.ArchivesNumber = request.ArchivesNumber;
                entity.UpdateTime        = DateTime.Now;
                entity.Title             = request.Title;
                entity.WrittenDate       = request.WrittenDate;
                entity.Summary           = request.Summary;
                entity.SecretLevel       = request.SecretLevel;
                entity.ResponsibleObject = request.ResponsibleObject;
                entity.Remark            = request.Remark;
                entity.ProjectName       = request.ProjectName;
                entity.Pages             = request.Pages;
                //entity.OrderNumber = request.OrderNumber;
                entity.IsPermanent = request.IsPermanent;
                //entity.FileNumber = request.FileNumber;
                //entity.CategoryId = request.CategoryId;
                entity.CatalogNumber       = request.CatalogNumber;
                entity.ArchivingDepartment = request.ArchivingDepartment;
                entity.ArchivingDate       = request.ArchivingDate;

                await _db.SaveChangesAsync();

                response.Data    = new ArchivesEditResult();
                response.Success = true;
            }
            catch (BizException ex)
            {
                response.Message = ex.Message;
            }
            catch (Exception ex)
            {
                response.Message = "操作发生异常";
                ApplicationLog.Error("Edit", ex);
            }
            return(response);
        }
Exemplo n.º 6
0
        public async Task <CommonResponse <string> > BorrowRegisterNotify(int dayLimit)
        {
            var response = new CommonResponse <string>();

            try
            {
                var list = await _db.BorrowRegister.Where(c => !c.Deleted && c.ReturnDate <= DateTime.Now.AddDays(dayLimit) && (!c.ReturnNotified.HasValue || c.ReturnNotified.Value == false) &&
                                                          (c.Status == BorrowRegisterStatus.Borrowed || c.Status == BorrowRegisterStatus.Overdue || c.Status == BorrowRegisterStatus.Renewed))
                           .OrderBy(c => c.Id).Take(50).ToListAsync();

                var archivesList = await _db.ArchivesInfo.Join(_db.BorrowRegisterDetail, a => a.Id, b => b.ArchivesId, (a, b) => new { a, b })
                                   .Where(j => list.Select(l => l.Id).Contains(j.b.BorrowRegisterId))
                                   .Select(c => new
                {
                    c.a.ProjectName,
                    c.b.Id,
                    c.b.BorrowRegisterId
                }).ToListAsync();

                if (list.Any())
                {
                    list.ForEach(c =>
                    {
                        var projectName = archivesList.FirstOrDefault(a => a.BorrowRegisterId == c.Id);

                        ApplicationLog.Info("task.SMS_171116662." + c.Phone + "." + c.Id);
                        var msgRes = OssHelper.SendSms("SMS_171116662", c.Phone, $"{{\"name\":\"{c.Borrower}\", \"PtName\":\"{(projectName != null ? projectName.ProjectName : string.Empty)}\", \"RDate\":\"{c.ReturnDate.ToString("yyyy-MM-dd")}\" }}");
                        //循环发送短信
                        if (msgRes.Code == "OK")
                        {
                            c.ReturnNotified = true;
                            c.NotifyCount    = c.NotifyCount.GetValueOrDefault() + 1;
                            c.UpdateTime     = DateTime.Now;
                        }
                    });
                    var data = list.Select(c => c.Id).Serialize();
                    await _db.OperationLog.AddAsync(new OperationLog
                    {
                        Action     = OperationAction.Create,
                        Name       = "催还短信",
                        CreateTime = DateTime.Now,
                        BeforeData = data
                    });

                    await _db.SaveChangesAsync();

                    response.Data = data;
                }
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                ApplicationLog.Error("BorrowRegisterNotify", ex);
            }

            return(response);
        }
Exemplo n.º 7
0
        public async Task <CommonResponse <ArchivesAddResult> > Add(ArchivesAddRequest request)
        {
            var response = new CommonResponse <ArchivesAddResult>();

            try
            {
                if (request == null)
                {
                    throw new BizException("参数不能为空");
                }
                //var exists = await _db.ArchivesInfo.AnyAsync(c => c.ArchivesNumber == request.ArchivesNumber && c.CatalogNumber == request.CatalogNumber && c.FileNumber == request.FileNumber && c.CategoryId == request.CategoryId);
                //if (exists)
                //    throw new BizException("当前提交的档号、目录号、分类号、案卷号在数据库中已存在,无法重复添加,请查询是否已添加");

                var entity = new ArchivesInfo
                {
                    ArchivesNumber      = request.ArchivesNumber,
                    Deleted             = false,
                    FileNumber          = request.FileNumber,
                    IsPermanent         = request.IsPermanent,
                    OrderNumber         = request.OrderNumber,
                    Pages               = request.Pages,
                    CategoryId          = request.CategoryId,
                    ArchivingDate       = request.ArchivingDate,
                    ArchivingDepartment = request.ArchivingDepartment,
                    CatalogNumber       = request.CatalogNumber,
                    CreateTime          = DateTime.Now,
                    ProjectName         = request.ProjectName,
                    Remark              = request.Remark,
                    ResponsibleObject   = request.ResponsibleObject,
                    SecretLevel         = request.SecretLevel,
                    Status              = ArchivesStatus.Init,
                    Summary             = request.Summary,
                    Title               = request.Title,
                    UpdateTime          = DateTime.Now,
                    WrittenDate         = request.WrittenDate
                };
                await _db.ArchivesInfo.AddAsync(entity);

                await _db.SaveChangesAsync();

                response.Data = new ArchivesAddResult
                {
                    Id = entity.Id
                };
                response.Success = true;
            }
            catch (BizException ex)
            {
                response.Message = ex.Message;
            }
            catch (Exception ex)
            {
                response.Message = "添加档案发生异常";
                ApplicationLog.Error("Add", ex);
            }
            return(response);
        }
Exemplo n.º 8
0
 public void Error(string message, Exception exception = null)
 {
     if (string.IsNullOrWhiteSpace(message))
     {
         return;
     }
     message = string.Concat(LogPrefix, message);
     ApplicationLog.Error(message, exception);
 }
Exemplo n.º 9
0
        public async Task <CommonResponse <string> > ReturnWarn(ReturnWarnRequest request)
        {
            var response = new CommonResponse <string>();

            try
            {
                if (request == null)
                {
                    throw new BizException("参数不能为空");
                }

                var borrowRegister = await _db.BorrowRegister.FirstAsync(c => c.Id == request.BorrowRegisterId);

                if (borrowRegister == null)
                {
                    throw new BizException("借阅记录不存在");
                }

                if (!(borrowRegister.Status == BorrowRegisterStatus.Borrowed || borrowRegister.Status == BorrowRegisterStatus.Overdue || borrowRegister.Status == BorrowRegisterStatus.Renewed))
                {
                    throw new BizException("借阅登记状态为:已借出、延期、逾期 才能催还");
                }

                //var archives = await _db.ArchivesInfo.Join(_db.BorrowRegisterDetail.Where(j => j.BorrowRegisterId == borrowRegister.Id).Take(1), a => a.Id, b => b.ArchivesId, (a, b) => new { a, b })
                //    .Select(c => new
                //    {
                //        c.a.ProjectName,
                //        c.b.Id
                //    }).FirstOrDefaultAsync();
                var projects = await _db.BorrowRegisterDetail.AsNoTracking().FirstOrDefaultAsync(c => c.BorrowRegisterId == borrowRegister.Id);

                ApplicationLog.Info("SMS_171116662." + borrowRegister.Phone + "." + borrowRegister.Id);
                var msgRes = OssHelper.SendSms("SMS_171116662", borrowRegister.Phone, $"{{\"name\":\"{borrowRegister.Borrower}\", \"PtName\":\"{(projects?.ProjectName)}\", \"RDate\":\"{borrowRegister.ReturnDate.ToString("yyyy-MM-dd")}\" }}");

                if (msgRes.Code == "OK")
                {
                    borrowRegister.ReturnNotified = true;
                    borrowRegister.NotifyCount    = borrowRegister.NotifyCount.GetValueOrDefault() + 1;
                    borrowRegister.UpdateTime     = DateTime.Now;
                    await _db.SaveChangesAsync();

                    response.Data = borrowRegister.NotifyCount.ToString();
                }
                response.Success = true;
            }
            catch (BizException ex)
            {
                response.Message = ex.Message;
            }
            catch (Exception ex)
            {
                response.Message = "催还发生异常";
                ApplicationLog.Error("ReturnWarn", ex);
            }

            return(response);
        }
Exemplo n.º 10
0
        public async Task <CommonSearchResponse <List <ArchivesSearchResult> > > SearchArchives(ArchivesSearchRequest request)
        {
            var response = new CommonSearchResponse <List <ArchivesSearchResult> >();

            try
            {
                var query = _db.ArchivesInfo.AsNoTracking().Where(c => !c.Deleted);
                if (!string.IsNullOrEmpty(request.Keyword))
                {
                    query = query.Where(c => c.Title.Contains(request.Keyword.Trim()) || c.ProjectName.Contains(request.Keyword.Trim()));
                }
                if (!string.IsNullOrEmpty(request.Label))
                {
                    var projectNames = request.Label.Split(',', StringSplitOptions.RemoveEmptyEntries);
                    query = query.Where(c => projectNames.Contains(c.ProjectName));
                }
                if (request.ShowBorrowed.HasValue)
                {
                    if (!request.ShowBorrowed.Value)
                    {
                        query = query.Where(c => c.Status != ArchivesStatus.Borrowed);
                    }
                }
                var list = await query.OrderBy(c => c.ArchivesNumber)
                           .Skip(request.PageNumber * request.PageSize)
                           .Take(request.PageSize)
                           .Select(c => new ArchivesSearchResult
                {
                    Id             = c.Id,
                    ArchivesNumber = c.ArchivesNumber,
                    CategoryId     = c.CategoryId,
                    FileNumber     = c.FileNumber,
                    ProjectName    = c.ProjectName,
                    Title          = c.Title,
                    OrderNumber    = c.OrderNumber,
                    Status         = c.Status,
                }).ToListAsync();

                var total = await query.CountAsync();

                response.Data       = list;
                response.TotalPage  = total.GetPages(request.PageSize);
                response.TotalCount = total;
                response.Success    = true;
                response.SEcho      = request.SEcho;
            }
            catch (Exception ex)
            {
                response.Message = "获取案档列表发生异常";
                ApplicationLog.Error("SearchArchives", ex);
            }

            return(response);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 归还
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <CommonResponse <string> > ReturnArchives(ReturnBorrowRequest request)
        {
            var response = new CommonResponse <string>();

            try
            {
                if (request == null)
                {
                    throw new BizException("参数不能为空");
                }

                var borrowRegister = await _db.BorrowRegister.FirstOrDefaultAsync(c => c.Id == request.BorrowRegisterId && !c.Deleted);

                if (borrowRegister == null)
                {
                    throw new BizException("借阅登记不存在");
                }

                if (borrowRegister.Status == BorrowRegisterStatus.Returned)
                {
                    response.Message   = "当前状态已经归还";
                    response.ErrorCode = 1;
                    response.Success   = true;
                    return(response);
                }

                if (borrowRegister.Status != BorrowRegisterStatus.Borrowed && borrowRegister.Status != BorrowRegisterStatus.Overdue && borrowRegister.Status != BorrowRegisterStatus.Renewed)
                {
                    throw new BizException("借阅登记状态为:已借出、延期、逾期 才需要归还");
                }
                borrowRegister.UpdateTime = DateTime.Now;
                borrowRegister.Status     = BorrowRegisterStatus.Returned;
                borrowRegister.UpdateTime = DateTime.Now;

                var archivesList = await _db.ArchivesInfo.Join(_db.BorrowRegisterDetail, a => a.Id, b => b.ArchivesId, (a, b) => new { a, b }).Where(j => j.b.BorrowRegisterId == borrowRegister.Id).Select(c => c.a).ToListAsync();

                archivesList.ForEach(a => a.Status = ArchivesStatus.Normal);
                await _db.SaveChangesAsync();

                response.Success = true;
            }
            catch (BizException ex)
            {
                response.Message = ex.Message;
            }
            catch (Exception ex)
            {
                response.Message = "提交续借发生异常";
                ApplicationLog.Error("ReturnArchives", ex);
            }
            return(response);
        }
Exemplo n.º 12
0
 internal static FieldInfo GetStaticField(Type objectType, string fieldName)
 {
     try
     {
         FieldInfo field = objectType.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.FlattenHierarchy) ??
                           objectType.BaseType.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.FlattenHierarchy);
         return(field);
     }
     catch (Exception ex)
     {
         ApplicationLog.Error(string.Format("Failed to get static field '{0}'", fieldName), ex);
         return(null);
     }
 }
Exemplo n.º 13
0
        public async Task <CommonResponse <List <AddFileResult> > > BatchAddFile(List <IFormFile> files)
        {
            var response = new CommonResponse <List <AddFileResult> >();

            try
            {
                var listFile = new List <dal.Entity.FileStorage>();
                foreach (var file in files)
                {
                    var id       = Guid.NewGuid().ToString("N");
                    var suffix   = file.FileName.Substring(file.FileName.LastIndexOf(".") + 1);
                    var filePath = $"{_localPath}{id}.{suffix}";//注意formFile.FileName包含上传文件的文件路径,所以要进行Substring只取出最后的文件名

                    using (var stream = new FileStream(filePath, FileMode.Create))
                    {
                        await file.CopyToAsync(stream);
                    }

                    listFile.Add(new dal.Entity.FileStorage
                    {
                        Id               = id,
                        ContentType      = file.ContentType,
                        CreateTime       = DateTime.Now,
                        StoragePath      = filePath,
                        StorageType      = dal.Entity.FileStorageType.Local,
                        Size             = file.Length,
                        AccessUrl        = $"{_gatewayFilePath}?f={id}",
                        BizType          = dal.Entity.FileStorageBizType.ArchivesExcel,
                        OriginalFileName = file.FileName
                    });
                }
                var list = await _fileStorageService.AddRangeFile(listFile);

                response.Data = listFile.Select(c => new AddFileResult
                {
                    Id          = c.Id,
                    Size        = c.Size,
                    ContentType = c.ContentType,
                    AccessUrl   = c.AccessUrl,
                    FileName    = c.OriginalFileName
                }).ToList();
                response.Success = true;
            }
            catch (Exception ex)
            {
                ApplicationLog.Error("BatchAddFile", ex);
                response.Message = "上传发生异常";
            }
            return(response);
        }
Exemplo n.º 14
0
        internal static PropertyInfo GetEntityProperty(Object gameEntity, string propertyName)
        {
            try
            {
                PropertyInfo property = gameEntity.GetType( ).GetProperty(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy) ??
                                        gameEntity.GetType( ).BaseType.GetProperty(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);

                return(property);
            }
            catch (Exception ex)
            {
                ApplicationLog.Error("Failed to get entity property '" + propertyName + "'");
                return(null);
            }
        }
Exemplo n.º 15
0
 internal static void SetEntityFieldValue(Object gameEntity, string fieldName, Object value)
 {
     try
     {
         FieldInfo field = GetEntityField(gameEntity, fieldName);
         if (field == null)
         {
             return;
         }
         field.SetValue(gameEntity, value);
     }
     catch (Exception ex)
     {
         ApplicationLog.Error(ex.Message, ex);
     }
 }
Exemplo n.º 16
0
 internal static void SetStaticFieldValue(Type objectType, string fieldName, Object value)
 {
     try
     {
         FieldInfo field = GetStaticField(objectType, fieldName);
         if (field == null)
         {
             return;
         }
         field.SetValue(null, value);
     }
     catch (Exception ex)
     {
         ApplicationLog.Error(ex.Message, ex);
     }
 }
Exemplo n.º 17
0
        public async Task <ActionResult> Export()
        {
            try
            {
                var list = await _archivesService.QueryAllArchives();

                System.IO.MemoryStream output = new System.IO.MemoryStream();

                System.IO.StreamWriter writer = new System.IO.StreamWriter(output, System.Text.Encoding.UTF8);
                writer.Write("档号,分类号,案卷号,卷内序号,题名,项目名称,责任者,成文日期,页数,保管期限,密级,归档部门,归档日期,备注,目录号,提要");

                writer.WriteLine();

                //输出内容
                list.ForEach(a => {
                    writer.Write($"\"{a.ArchivesNumber}\",\"");//第一列
                    writer.Write($"{a.CategoryId}\",\"");
                    writer.Write($"{a.FileNumber}\",\"");
                    writer.Write($"{a.OrderNumber}\",\"");
                    writer.Write($"{a.Title}\",\"");
                    writer.Write($"{a.ProjectName}\",\"");
                    writer.Write($"{a.ResponsibleObject}\",\"");
                    writer.Write($"{a.WrittenDate.ToString("yyyy-MM-dd")}\",\"");
                    writer.Write($"{a.Pages}\",\"");
                    writer.Write($"{a.IsPermanent}\",\"");
                    writer.Write($"{a.SecretLevel}\",\"");
                    writer.Write($"{a.ArchivingDepartment}\",\"");
                    writer.Write($"{a.ArchivingDate.ToString("yyyy-MM-dd")}\",\"");
                    writer.Write($"{a.Remark}\",\"");
                    writer.Write($"{a.CatalogNumber}\",\"");
                    writer.Write($"{a.Summary}\",");
                    writer.WriteLine();
                });

                writer.Flush();

                output.Position = 0;

                return(File(output, "application/ms-excel", "卷盒内文件.csv"));
            }
            catch (Exception ex)
            {
                ApplicationLog.Error("Export Excetpion", ex);
                return(Ok(ex.Message));
            }
        }
Exemplo n.º 18
0
        internal static MethodInfo GetEntityMethod(Object gameEntity, string methodName, Type[] argTypes)
        {
            try
            {
                if (argTypes == null || argTypes.Length == 0)
                {
                    return(GetEntityMethod(gameEntity, methodName));
                }

                if (gameEntity == null)
                {
                    throw new Exception("Game entity was null");
                }
                if (string.IsNullOrEmpty(methodName))
                {
                    throw new Exception("Method name was empty");
                }
                MethodInfo method = gameEntity.GetType( ).GetMethod(methodName, argTypes);
                if (method == null)
                {
                    //Recurse up through the class heirarchy to try to find the method
                    Type type = gameEntity.GetType( );
                    while (type != typeof(Object))
                    {
                        method = type.GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy, Type.DefaultBinder, argTypes, null);
                        if (method != null)
                        {
                            break;
                        }

                        type = type.BaseType;
                    }
                }
                if (method == null)
                {
                    throw new Exception("Method not found");
                }
                return(method);
            }
            catch (Exception ex)
            {
                ApplicationLog.Error("Failed to get entity method '" + methodName + "': " + ex.Message);
                return(null);
            }
        }
Exemplo n.º 19
0
        internal static Object GetEntityPropertyValue(Object gameEntity, string propertyName)
        {
            try
            {
                PropertyInfo property = GetEntityProperty(gameEntity, propertyName);
                if (property == null)
                {
                    return(null);
                }

                Object result = property.GetValue(gameEntity, null);
                return(result);
            }
            catch (Exception ex)
            {
                ApplicationLog.Error("Failed to get entity property value '" + propertyName + "'");
                return(null);
            }
        }
Exemplo n.º 20
0
        internal static Object InvokeStaticMethod(Type objectType, string methodName, Object[] parameters)
        {
            try
            {
                MethodInfo method = GetStaticMethod(objectType, methodName);
                if (method == null)
                {
                    throw new Exception("Method is empty");
                }
                Object result = method.Invoke(null, parameters);

                return(result);
            }
            catch (Exception ex)
            {
                ApplicationLog.Error("Failed to invoke static method '" + methodName + "': " + ex.Message);
                return(null);
            }
        }
Exemplo n.º 21
0
        public async Task <IActionResult> DownLoad(string f)
        {
            try
            {
                var fileStorage = await _fileStorageService.Get(f);

                var stream = System.IO.File.OpenRead(fileStorage.StoragePath);
                return(File(stream, fileStorage.ContentType, string.IsNullOrEmpty(fileStorage.OriginalFileName) ? f: fileStorage.OriginalFileName));
            }
            catch (BizException ex)
            {
                return(Json(ex.Message));//两个catch先暂时这么写吧,
            }
            catch (Exception ex)
            {
                ApplicationLog.Error($"DownLoad:{f}", ex);
                return(Json("系统异常"));
            }
        }
Exemplo n.º 22
0
        internal static Object InvokeEntityMethod(Object gameEntity, string methodName, Object[] parameters, Type[] argTypes)
        {
            try
            {
                MethodInfo method = GetEntityMethod(gameEntity, methodName, argTypes);
                if (method == null)
                {
                    throw new Exception("Method is empty");
                }
                Object result = method.Invoke(gameEntity, parameters);

                return(result);
            }
            catch (Exception ex)
            {
                ApplicationLog.Error("Failed to invoke entity method '" + methodName + "' on type '" + gameEntity.GetType( ).FullName + "': " + ex.Message);
                return(null);
            }
        }
Exemplo n.º 23
0
        public async Task <CommonResponse <ArchivesDeleteResult> > Delete(ArchivesDeleteRequest request)
        {
            var response = new CommonResponse <ArchivesDeleteResult>();

            try
            {
                if (request == null)
                {
                    throw new BizException("参数不能为空");
                }
                var archives = await _db.ArchivesInfo.FirstOrDefaultAsync(c => c.Id == request.ArchivesId);

                if (archives == null)
                {
                    throw new BizException("档案不存在,无法删除");
                }
                if (archives.Status != ArchivesStatus.Init)
                {
                    throw new BizException("档案已借阅过,无法删除");
                }
                _db.ArchivesInfo.Remove(archives);
                await _db.SaveChangesAsync();

                //if (!archives.Deleted)
                //{
                //    archives.Deleted = true;
                //    await _db.SaveChangesAsync();
                //}
                response.Data    = new ArchivesDeleteResult();
                response.Success = true;
            }
            catch (BizException ex)
            {
                response.Message = ex.Message;
            }
            catch (Exception ex)
            {
                response.Message = "删除发生异常";
                ApplicationLog.Error("Delete", ex);
            }
            return(response);
        }
Exemplo n.º 24
0
        internal static void SetEntityPropertyValue(Object gameEntity, string propertyName, Object value)
        {
            try
            {
                PropertyInfo property = GetEntityProperty(gameEntity, propertyName);
                if (property == null)
                {
                    return;
                }

                property.SetValue(gameEntity, value, null);
            }
            catch (Exception ex)
            {
                ApplicationLog.Error("Failed to set entity property value '" + propertyName + "'");
                if (SandboxGameAssemblyWrapper.IsDebugging)
                {
                    return;
                }
            }
        }
Exemplo n.º 25
0
        public async Task <CommonResponse <string> > CloseBorrow(CloseBorrowRequest request)
        {
            var response = new CommonResponse <string>();

            try
            {
                if (request == null)
                {
                    throw new BizException("参数不能为空");
                }

                var borrowRegister = await _db.BorrowRegister.FirstOrDefaultAsync(c => c.Id == request.BorrowRegisterId && !c.Deleted);

                if (borrowRegister == null)
                {
                    throw new BizException("借阅登记不存在");
                }

                if (borrowRegister.Status != BorrowRegisterStatus.Registered)
                {
                    throw new BizException("借阅登记状态为:已登记 才能关闭");
                }

                borrowRegister.Status     = BorrowRegisterStatus.Closed;
                borrowRegister.UpdateTime = DateTime.Now;
                await _db.SaveChangesAsync();

                response.Success = true;
            }
            catch (BizException ex)
            {
                response.Message = ex.Message;
            }
            catch (Exception ex)
            {
                response.Message = "关闭借阅发生异常";
                ApplicationLog.Error("RenewBorrow", ex);
            }
            return(response);
        }
Exemplo n.º 26
0
        public async Task <CommonResponse <string> > ChangPassword(ChangePsdRequest request)
        {
            var response = new CommonResponse <string>();

            try
            {
                if (request == null)
                {
                    throw new BizException("参数不能为空");
                }
                var entity = await _db.AdminUser.FirstOrDefaultAsync(c => c.UserName == request.UserName);

                if (entity.Password != Md5.MD5Hash(request.OldPassword).ToLower())
                {
                    throw new BizException("原密码错误");
                }

                if (entity == null)
                {
                    throw new BizException("用户不存在");
                }

                entity.Password = Md5.MD5Hash(request.NewPassword).ToLower();

                await _db.SaveChangesAsync();

                response.Data    = "ok";
                response.Success = true;
            }
            catch (BizException ex)
            {
                response.Message = ex.Message;
            }
            catch (Exception ex)
            {
                response.Message = "修改密码发生异常";
                ApplicationLog.Error("ChangPassword", ex);
            }
            return(response);
        }
Exemplo n.º 27
0
        public async Task <ActionResult> Export(SearchBorrowRegisterRequest request)
        {
            try
            {
                var list = await _borrowRegisterService.QueryAllBorrowRegisters(request);

                System.IO.MemoryStream output = new System.IO.MemoryStream();

                System.IO.StreamWriter writer = new System.IO.StreamWriter(output, System.Text.Encoding.UTF8);
                writer.Write("借阅时间,借阅单位,借阅人,工程名称,借阅条目,归还日期,接收人,备注");

                writer.WriteLine();

                //输出内容
                list.ForEach(a => {
                    writer.Write($"\"{a.CreateTimeStr}\",\"");//第一列
                    writer.Write($"{a.Department}\",\"");
                    writer.Write($"{a.Borrower}\",\"");
                    writer.Write($"{a.ProjectName}\",\"");
                    writer.Write($"{a.ArchivesStr}\",\"");
                    writer.Write($"{a.ReturnDateStr}\",\"");
                    writer.Write($"{a.Receiver}\",\"");
                    writer.Write($"{a.StatusDesc}\",");
                    writer.WriteLine();
                });

                writer.Flush();

                output.Position = 0;

                return(File(output, "application/ms-excel", "借阅记录.csv"));
            }
            catch (Exception ex)
            {
                ApplicationLog.Error("Export Excetpion", ex);
                return(Ok(ex.Message));
            }
        }
Exemplo n.º 28
0
        internal static MethodInfo GetStaticMethod(Type objectType, string methodName)
        {
            try
            {
                if (string.IsNullOrEmpty(methodName))
                {
                    throw new Exception("Method name was empty");
                }
                MethodInfo method = objectType.GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.FlattenHierarchy);
                if (method == null)
                {
                    //Recurse up through the class heirarchy to try to find the method
                    Type type = objectType;
                    while (type != typeof(Object))
                    {
                        method = type.GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.FlattenHierarchy);
                        if (method != null)
                        {
                            break;
                        }

                        type = type.BaseType;
                    }
                }
                if (method == null)
                {
                    throw new Exception("Method not found");
                }
                return(method);
            }
            catch (Exception ex)
            {
                ApplicationLog.Error("Failed to get static method '" + methodName + "'");
                return(null);
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// 申报借阅
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <CommonResponse <BorrowRegisterResult> > BorrowRegister(BorrowRegisterRequest request)
        {
            var response = new CommonResponse <BorrowRegisterResult>();

            if (request == null)
            {
                response.Message = "参数不能为空";
                return(response);
            }
            if (string.IsNullOrEmpty(request.Phone))
            {
                response.Message = "手机不能为空";
                return(response);
            }
            if (string.IsNullOrEmpty(request.Borrower))
            {
                response.Message = "借阅人不能为空";
                return(response);
            }
            if (request.ReturnDate < DateTime.Now)
            {
                response.Message = "归还日期不能早于今天";
                return(response);
            }

            var regEntity = new dal.Entity.BorrowRegister
            {
                Borrower       = request.Borrower,
                Phone          = request.Phone,
                ReturnDate     = request.ReturnDate,
                SignPhoto      = request.SignPhoto,
                Status         = BorrowRegisterStatus.Registered,
                Company        = request.Company,
                Department     = request.Department,
                CreateTime     = DateTime.Now,
                Deleted        = false,
                UpdateTime     = DateTime.Now,
                ReturnNotified = false,
                Remark         = request.Remark
            };

            using (var trans = await _db.Database.BeginTransactionAsync())
            {
                try
                {
                    //var archives = await _db.ArchivesInfo.AsNoTracking().Where(c => request.ArchivesId.Contains(c.Id) && !c.Deleted).ToListAsync();
                    //if (archives.Count != request.ArchivesId.Count)
                    //{
                    //    throw new BizException("请求档案数目与数据库可用档案不一致,可能是数据已删除,请重新查询后再提交");
                    //}

                    //var borrowedArchives = archives.Where(c => c.Status == ArchivesStatus.Borrowed);
                    //if (borrowedArchives.Any())
                    //{
                    //    throw new BizException($"请求档案:{string.Join(",", borrowedArchives.Select(c => c.ArchivesNumber))} 当前状态为已借阅");
                    //}

                    await _db.BorrowRegister.AddAsync(regEntity);

                    await _db.SaveChangesAsync();

                    response.Data = new BorrowRegisterResult {
                        BorrowRegisterId = regEntity.Id
                    };

                    await _db.BorrowRegisterDetail.AddRangeAsync(request.Details.Select(c => new dal.Entity.BorrowRegisterDetail
                    {
                        ArchivesId       = 0,
                        BorrowRegisterId = regEntity.Id,
                        CreateTime       = DateTime.Now,
                        ArchivesNumber   = c.ArchivesNumber,
                        CategoryId1      = c.CategoryId1,
                        CategoryName1    = c.CategoryName1,
                        CategoryId2      = c.CategoryId2,
                        CategoryName2    = c.CategoryName2,
                        CategoryId3      = c.CategoryId3,
                        CategoryName3    = c.CategoryName3,
                        FileNumber       = c.FileNumber,
                        CategoryNumber   = c.CategoryId,
                        OrderNumber      = c.OrderNumber,
                        ProjectId        = c.ProjectId,
                        ProjectName      = c.ProjectName,
                        Title            = c.Title
                    }));

                    await _db.SaveChangesAsync();

                    trans.Commit();
                    response.Success = true;
                }
                catch (BizException ex)
                {
                    trans.Rollback();
                    response.Message = ex.Message;
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    response.Message = "提交申请借阅发生异常";
                    ApplicationLog.Error("BorrowRegister", ex);
                }
            }

            return(response);
        }
Exemplo n.º 30
0
        public async Task <CommonResponse <string> > ConfirmBorrowed(ConfirmBorrowedRequest request)
        {
            var response = new CommonResponse <string>();

            using (var trans = await _db.Database.BeginTransactionAsync())
            {
                try
                {
                    if (request == null)
                    {
                        throw new BizException("参数不能为空");
                    }

                    var borrowRegister = await _db.BorrowRegister.FirstOrDefaultAsync(c => c.Id == request.BorrowRegisterId && !c.Deleted);

                    if (borrowRegister == null)
                    {
                        throw new BizException("借阅登记不存在");
                    }

                    if (borrowRegister.Status == BorrowRegisterStatus.Borrowed)
                    {
                        //response.Message = "当前状态已经借出";
                        //response.ErrorCode = 1;
                        //response.Success = true;
                        //return response;
                        throw new BizException("当前借阅的状态为已借出");
                    }

                    if (borrowRegister.Status != BorrowRegisterStatus.Registered)
                    {
                        throw new BizException("借阅登记状态为:已登记 才能确认借出");
                    }

                    /*
                     * var archives = await _db.ArchivesInfo.Join(_db.BorrowRegisterDetail, a => a.Id, b => b.ArchivesId, (a, b) => new { a, b })
                     *  .Where(j => j.b.BorrowRegisterId == borrowRegister.Id)
                     *  .Select(c => c.a).ToListAsync();
                     * //如果当前状态为init,将档案改为
                     * archives.ForEach(c =>
                     * {
                     *  switch (c.Status)
                     *  {
                     *      case ArchivesStatus.Init:
                     *      case ArchivesStatus.Normal:
                     *          c.Status = ArchivesStatus.Borrowed;
                     *          break;
                     *      case ArchivesStatus.Borrowed:
                     *          throw new BizException("您选择的档案可能已借出,无法再次借阅");
                     *      default:
                     *          throw new BizException("您选择的档案档案当前状态出错,无法确认借出");
                     *  }
                     * });
                     */
                    borrowRegister.UpdateTime = DateTime.Now;
                    borrowRegister.Status     = BorrowRegisterStatus.Borrowed;
                    borrowRegister.UpdateTime = DateTime.Now;

                    await _db.SaveChangesAsync();

                    trans.Commit();
                    response.Success = true;

                    var projects = await _db.BorrowRegisterDetail.AsNoTracking().FirstOrDefaultAsync(c => c.BorrowRegisterId == borrowRegister.Id);

                    ApplicationLog.Info("SMS_171116670." + borrowRegister.Phone + "." + borrowRegister.Id);
                    var msgRes = OssHelper.SendSms("SMS_171116670", borrowRegister.Phone, $"{{\"name\":\"{borrowRegister.Borrower}\", \"PtName\":\"{(projects?.ProjectName)}\", \"RDate\":\"{borrowRegister.ReturnDate.ToString("yyyy-MM-dd")}\" }}");
                }
                catch (BizException ex)
                {
                    trans.Rollback();
                    response.Message = ex.Message;
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    response.Message = "提交续借发生异常";
                    ApplicationLog.Error("ConfirmBorrowed", ex);
                }
            }

            return(response);
        }