Exemplo n.º 1
0
        public async Task <CommonResponse <string> > RenewBorrow([FromBody] RenewBorrowRequest request)
        {
            request.SerializeToLog("RenewBorrow");
            var response = await _borrowRegisterService.RenewBorrow(request);

            response.SerializeToLog("RenewBorrow");
            return(response);
        }
Exemplo n.º 2
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);
        }