public async Task <CommonResponse <string> > ConfirmBorrowed([FromBody] ConfirmBorrowedRequest request) { request.SerializeToLog("ConfirmBorrowed"); var response = await _borrowRegisterService.ConfirmBorrowed(request); response.SerializeToLog("ConfirmBorrowed"); return(response); }
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); }