/// <summary> /// 排队 微信接口使用 /// </summary> /// <param name="selectBusy"></param> /// <param name="selectUnit"></param> /// <param name="ticketStart"></param> /// <param name="idCard"></param> /// <param name="name"></param> /// <param name="app"></param> /// <returns></returns> public TQueueModel QueueLine(string unitSeq, string unitName, string busiSeq, string busiName, string ticketStart, string idCard, string name, string wxId, TAppointmentModel app) { TQueueModel qModel = null; try { LockAction.Run(LockKey.Queue, () => { var maxNo = new TLineUpMaxNoDAL(this.db).GetModelList().Where(l => l.unitSeq == unitSeq && l.busiSeq == busiSeq).FirstOrDefault(); int ticketNo = maxNo == null ? 1 : maxNo.lineDate.Date != DateTime.Now.Date ? 1 : maxNo.maxNo + 1; TQueueModel line = new TQueueModel(); line.busTypeName = busiName; line.busTypeSeq = busiSeq; line.qNumber = ticketNo.ToString(); line.state = 0; line.ticketNumber = ticketStart + ticketNo.ToString("000"); line.ticketTime = DateTime.Now; line.unitName = unitName; line.unitSeq = unitSeq; line.vipLever = ""; line.windowName = ""; line.windowNumber = ""; line.idCard = idCard; line.qNmae = name; line.sysFlag = 0; line.wxId = wxId; line.qType = 1; if (app != null) { line.appType = app.appType; line.reserveSeq = app.reserveSeq; line.reserveStartTime = app.reserveStartTime; line.reserveEndTime = app.reserveEndTime; line.type = app.type; } line = this.Insert(line); if (maxNo == null) { maxNo = new TLineUpMaxNoModel(); maxNo.areaSeq = ""; maxNo.busiSeq = busiSeq; maxNo.lineDate = DateTime.Now; maxNo.maxNo = 1; maxNo.unitSeq = unitSeq; maxNo.sysFlag = 0; new TLineUpMaxNoDAL(this.db).Insert(maxNo); } else { if (maxNo.lineDate.Date != DateTime.Now.Date) { maxNo.maxNo = 1; } else { maxNo.maxNo = maxNo.maxNo + 1; } maxNo.lineDate = DateTime.Now; maxNo.sysFlag = 1; new TLineUpMaxNoDAL(this.db).Update(maxNo); } qModel = line; }); } catch { return(null); } return(qModel); }
/// <summary> /// 排队 ** 已弃用 /// </summary> /// <param name="selectBusy"></param> /// <param name="selectUnit"></param> /// <param name="ticketStart"></param> /// <param name="idCard"></param> /// <param name="name"></param> /// <param name="reserveSeq"></param> /// <returns></returns> public TQueueModel QueueLine(TBusinessModel selectBusy, TUnitModel selectUnit, string ticketStart, string idCard, string name, string reserveSeq) { try { this.db.Session.BeginTransaction(); var maxNo = new TLineUpMaxNoDAL(this.db).GetModelList().Where(l => l.unitSeq == selectUnit.unitSeq && l.busiSeq == selectBusy.busiSeq).FirstOrDefault(); //按照主键对该记录进行行锁确保数据一致性 maxNo = this.db.SqlQuery <TLineUpMaxNoModel>( "select * from T_LineUpMaxNo a where a.id = @id FOR UPDATE;", new DbParam[] { new DbParam("id", maxNo == null ? -1 : maxNo.id) } ).FirstOrDefault(); int ticketNo = maxNo == null ? 1 : maxNo.lineDate.Date != DateTime.Now.Date ? 1 : maxNo.maxNo + 1; TQueueModel line = new TQueueModel(); line.busTypeName = selectBusy.busiName; line.busTypeSeq = selectBusy.busiSeq; line.qNumber = ticketNo.ToString(); line.state = 0; line.ticketNumber = ticketStart + ticketNo.ToString("000"); line.ticketTime = DateTime.Now; line.unitName = selectUnit.unitName; line.unitSeq = selectUnit.unitSeq; line.vipLever = ""; line.windowName = ""; line.windowNumber = ""; line.idCard = idCard; line.qNmae = name; line.reserveSeq = reserveSeq; line = this.Insert(line); if (maxNo == null) { maxNo = new TLineUpMaxNoModel(); maxNo.areaSeq = ""; maxNo.busiSeq = selectBusy.busiSeq; maxNo.lineDate = DateTime.Now; maxNo.maxNo = 1; maxNo.unitSeq = selectUnit.unitSeq; new TLineUpMaxNoDAL(this.db).Insert(maxNo); } else { if (maxNo.lineDate.Date != DateTime.Now.Date) { maxNo.maxNo = 1; } else { maxNo.maxNo = maxNo.maxNo + 1; } maxNo.lineDate = DateTime.Now; new TLineUpMaxNoDAL(this.db).Update(maxNo); } this.db.Session.CommitTransaction(); return(line); } catch { this.db.Session.RollbackTransaction(); return(null); } finally { this.db.Dispose(); } }