Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 续借
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <CommonResponse <string> > RenewBorrow(RenewBorrowRequest request)
        {
            var response = new CommonResponse <string>();

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

                if (request.RenewDate < DateTime.Now)
                {
                    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.Renewed || borrowRegister.Status == BorrowRegisterStatus.Overdue || borrowRegister.Status == BorrowRegisterStatus.Borrowed))
                {
                    throw new BizException("借阅登记状态为:已借出、延期、逾期 才能续借");
                }

                borrowRegister.ReturnDate     = request.RenewDate;
                borrowRegister.Status         = BorrowRegisterStatus.Renewed;
                borrowRegister.UpdateTime     = DateTime.Now;
                borrowRegister.ReturnNotified = false;
                await _db.SaveChangesAsync();

                response.Success = true;

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

                try
                {
                    //var archivesFirst = await _db.ArchivesInfo.AsNoTracking().Join(_db.BorrowRegisterDetail.AsNoTracking().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
                    //    }).FirstOrDefaultAsync();
                    ApplicationLog.Info("SMS_171116665." + borrowRegister.Phone + "." + borrowRegister.Id);
                    var msgRes = OssHelper.SendSms("SMS_171116665", borrowRegister.Phone, $"{{\"name\":\"{borrowRegister.Borrower}\", \"PtName\":\"{(projects?.ProjectName)}\", \"RDate\":\"{borrowRegister.ReturnDate.ToString("yyyy-MM-dd")}\" }}");
                }
                catch (Exception ex1)
                {
                    ApplicationLog.Error("RenewBorrow notice exception", ex1);
                }
            }
            catch (BizException ex)
            {
                response.Message = ex.Message;
            }
            catch (Exception ex)
            {
                response.Message = "提交续借发生异常";
                ApplicationLog.Error("RenewBorrow", ex);
            }
            return(response);
        }