public override string CreateTable() { DBExtend helper = DBExtend; Transaction obj1 = new Transaction(); //IAccountRecord obj2 = new IAccountRecord(); string msg = obj1.CreateTable(helper); //msg += obj2.CreateTable(helper); LockRecord rec = new LockRecord(); msg += rec.CreateTable(helper); return(msg); }
/// <summary> /// 锁定金额 /// </summary> /// <param name="record"></param> /// <param name="error"></param> /// <param name="useTrans">是否使用事务,默认为true</param> /// <returns></returns> public bool LockAmount(LockRecord record, out string error, bool useTrans = true) { error = ""; if (useTrans) { return(PackageTrans((out string ex) => { return LockAmountNoTrans(record, out ex); }, out error)); } else { return(LockAmountNoTrans(record, out error)); } }
/// <summary> /// 锁定,不带事务 /// </summary> /// <param name="record"></param> /// <param name="error"></param> /// <returns></returns> bool LockAmountNoTrans(LockRecord record, out string error) { error = ""; var helper = DBExtend; if (record.Amount <= 0) { error = "amount格式不正确"; return(false); } string key = string.Format("LockAmount_{0}_{1}_{2}_{3}", record.AccountId, 0, record.Remark, 0); if (!CoreHelper.ConcurrentControl.Check(key, 3)) { error = "同时提交了多次相同的参数" + key; return(false); //throw new Exception("同时提交了多次相同的参数" + key); } var account = AccountBusiness <TType> .Instance.QueryItem(record.AccountId); if (account.AvailableBalance < record.Amount) { CoreHelper.ConcurrentControl.Remove(key); error = "余额不足"; return(false); } helper.InsertFromObj(record); var accountDetail = new AccountDetail() { Id = record.AccountId }; accountDetail.Cumulation(b => b.LockedAmount, Math.Abs(record.Amount)); helper.Update(accountDetail); return(true); }