public ResultModel Update(UserModel user, NFMT.Operate.Model.Apply apply, NFMT.DoPrice.Model.PricingApply pricingApply, List<NFMT.DoPrice.Model.PricingApplyDetail> pricingApplyDetails) { ResultModel result = new ResultModel(); NFMT.Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL(); DAL.PricingApplyDAL pricingApplyDAL = new PricingApplyDAL(); DAL.PricingApplyDetailDAL pricingApplyDetailDAL = new PricingApplyDetailDAL(); NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL(); NFMT.Contract.DAL.ContractDAL contractDAL = new Contract.DAL.ContractDAL(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { result = applyDAL.Get(user, apply.ApplyId); if (result.ResultStatus != 0) return result; NFMT.Operate.Model.Apply getApply = result.ReturnValue as NFMT.Operate.Model.Apply; if (getApply == null || getApply.ApplyId <= 0) { result.ResultStatus = -1; result.Message = "获取申请错误"; return result; } NFMT.User.Model.Department dept = NFMT.User.UserProvider.Departments.FirstOrDefault(temp => temp.DeptId == apply.ApplyDept); if (dept == null || dept.DeptId <= 0) { result.ResultStatus = -1; result.Message = "申请部门不存在"; return result; } getApply.EmpId = user.EmpId; getApply.ApplyTime = DateTime.Now; getApply.ApplyDept = apply.ApplyDept; getApply.ApplyCorp = apply.ApplyCorp; getApply.ApplyDesc = apply.ApplyDesc; result = applyDAL.Update(user, getApply); if (result.ResultStatus != 0) return result; result = pricingApplyDAL.Get(user, pricingApply.PricingApplyId); if (result.ResultStatus != 0) return result; NFMT.DoPrice.Model.PricingApply getPricingApply = result.ReturnValue as NFMT.DoPrice.Model.PricingApply; if (getPricingApply == null || getPricingApply.PricingApplyId <= 0) { result.ResultStatus = -1; result.Message = "获取点价申请错误"; return result; } getPricingApply.StartTime = pricingApply.StartTime; getPricingApply.EndTime = pricingApply.EndTime; getPricingApply.MinPrice = pricingApply.MinPrice; getPricingApply.MaxPrice = pricingApply.MaxPrice; getPricingApply.CurrencyId = pricingApply.CurrencyId; getPricingApply.PricingCorpId = pricingApply.PricingCorpId; getPricingApply.PricingWeight = pricingApply.PricingWeight; getPricingApply.MUId = pricingApply.MUId; getPricingApply.AssertId = pricingApply.AssertId; getPricingApply.PricingPersoinId = pricingApply.PricingPersoinId; //验证子合约 result = subDAL.Get(user, pricingApply.SubContractId); if (result.ResultStatus != 0) return result; NFMT.Contract.Model.ContractSub sub = result.ReturnValue as NFMT.Contract.Model.ContractSub; if (sub == null || sub.SubId <= 0) { result.ResultStatus = -1; result.Message = "子合约不存在"; return result; } if (sub.SubStatus != StatusEnum.已生效) { result.ResultStatus = -1; result.Message = "子合约状态非已生效,不能进行点价申请"; return result; } //获取合约 result = contractDAL.Get(user, sub.ContractId); if (result.ResultStatus != 0) return result; NFMT.Contract.Model.Contract contract = result.ReturnValue as NFMT.Contract.Model.Contract; if (contract == null || contract.ContractId <= 0) { result.ResultStatus = -1; result.Message = "关联合约不存在"; return result; } if (contract.TradeDirection == (int)NFMT.Contract.TradeDirectionEnum.Buy) getPricingApply.PricingDirection = (int)NFMT.DoPrice.PricingDirection.空头; else getPricingApply.PricingDirection = (int)NFMT.DoPrice.PricingDirection.多头; result = pricingApplyDAL.Update(user, getPricingApply); if (result.ResultStatus != 0) return result; //作废明细 result = pricingApplyDetailDAL.InvalidAll(user, getPricingApply.PricingApplyId); if (result.ResultStatus != 0) return result; //写入明细 foreach (Model.PricingApplyDetail detail in pricingApplyDetails) { detail.PricingApplyId = getPricingApply.PricingApplyId; detail.DetailStatus = StatusEnum.已生效; result = pricingApplyDetailDAL.Insert(user, detail); if (result.ResultStatus != 0) return result; } scope.Complete(); } } catch (Exception e) { result.ResultStatus = -1; result.Message = e.Message; } return result; }
public ResultModel Confirm(UserModel user, int pricingApplyId) { ResultModel result = new ResultModel(); try { DAL.PricingApplyDAL pricingApplyDAL = new PricingApplyDAL(); Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL(); DAL.PricingApplyDetailDAL pricingApplyDetailDAL = new PricingApplyDetailDAL(); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { //验证点价申请 result = pricingApplyDAL.Get(user, pricingApplyId); if (result.ResultStatus != 0) return result; Model.PricingApply pricingApply = result.ReturnValue as Model.PricingApply; if (pricingApply == null || pricingApply.PricingApplyId <= 0) { result.ResultStatus = -1; result.Message = "点价申请不存在"; return result; } //验证主申请 result = applyDAL.Get(user, pricingApply.ApplyId); if (result.ResultStatus != 0) return result; Operate.Model.Apply apply = result.ReturnValue as Operate.Model.Apply; if (apply == null || apply.ApplyId <= 0) { result.ResultStatus = -1; result.Message = "主申请不存在"; return result; } //验证是否执行完成 result = pricingApplyDAL.CheckPledgeCanConfirm(user, pricingApplyId); if (result.ResultStatus != 0) return result; Common.StatusEnum status = (Common.StatusEnum)result.ReturnValue; //获取已生效点价申请明细 result = pricingApplyDetailDAL.Load(user, pricingApplyId); if (result.ResultStatus != 0) return result; List<Model.PricingApplyDetail> details = result.ReturnValue as List<Model.PricingApplyDetail>; if (details == null) { result.ResultStatus = -1; result.Message = "获取点价申请明细失败"; return result; } //主申请更新状态至已完成 if (status == StatusEnum.已完成) result = applyDAL.Confirm(user, apply); else if (status == StatusEnum.部分完成) result = applyDAL.PartiallyConfirm(user, apply); else { result.ResultStatus = -1; result.Message = "更新主申请状态失败"; return result; } if (result.ResultStatus != 0) return result; //点价申请明细更新状态至已完成 foreach (Model.PricingApplyDetail detail in details) { //点价申请明细更新状态至已完成 result = pricingApplyDetailDAL.Confirm(user, detail); if (result.ResultStatus != 0) return result; } scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } return result; }
public ResultModel Invalid(UserModel user, int pricingApplyId) { ResultModel result = new ResultModel(); try { DAL.PricingApplyDAL pricingApplyDAL = new PricingApplyDAL(); NFMT.Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL(); DAL.PricingApplyDetailDAL pricingApplyDetailDAL = new PricingApplyDetailDAL(); using (System.Transactions.TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { //获取点价申请 result = pricingApplyDAL.Get(user, pricingApplyId); if (result.ResultStatus != 0) return result; NFMT.DoPrice.Model.PricingApply pricingApply = result.ReturnValue as NFMT.DoPrice.Model.PricingApply; if (pricingApply == null || pricingApply.PricingApplyId <= 0) { result.ResultStatus = -1; result.Message = "点价申请验证失败"; return result; } //获取申请 result = applyDAL.Get(user, pricingApply.ApplyId); if (result.ResultStatus != 0) return result; NFMT.Operate.Model.Apply apply = result.ReturnValue as NFMT.Operate.Model.Apply; if (apply == null || apply.ApplyId <= 0) { result.ResultStatus = -1; result.Message = "申请获取失败"; return result; } //作废申请 result = applyDAL.Invalid(user, apply); if (result.ResultStatus != 0) return result; //作废明细 result = pricingApplyDetailDAL.InvalidAll(user, pricingApplyId); if (result.ResultStatus != 0) return result; scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } return result; }
public ResultModel Create(UserModel user, NFMT.Operate.Model.Apply apply, NFMT.DoPrice.Model.PricingApply pricingApply, List<NFMT.DoPrice.Model.PricingApplyDetail> pricingApplyDetails) { ResultModel result = new ResultModel(); NFMT.Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL(); DAL.PricingApplyDAL pricingApplyDAL = new PricingApplyDAL(); DAL.PricingApplyDetailDAL pricingApplyDetailDAL = new PricingApplyDetailDAL(); NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL(); NFMT.Contract.DAL.ContractDAL contractDAL = new Contract.DAL.ContractDAL(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { NFMT.User.Model.Department dept = NFMT.User.UserProvider.Departments.FirstOrDefault(temp => temp.DeptId == apply.ApplyDept); if (dept == null || dept.DeptId <= 0) { result.ResultStatus = -1; result.Message = "申请部门不存在"; return result; } //新增主申请 apply.EmpId = user.EmpId; apply.ApplyTime = DateTime.Now; apply.ApplyType = NFMT.Operate.ApplyType.PricingApply; apply.ApplyDept = dept.DeptId; result = applyDAL.Insert(user, apply); if (result.ResultStatus != 0) return result; int applyId = (int)result.ReturnValue; pricingApply.ApplyId = applyId; //验证子合约 result = subDAL.Get(user, pricingApply.SubContractId); if (result.ResultStatus != 0) return result; NFMT.Contract.Model.ContractSub sub = result.ReturnValue as NFMT.Contract.Model.ContractSub; if (sub == null || sub.SubId <= 0) { result.ResultStatus = -1; result.Message = "子合约不存在"; return result; } if (sub.SubStatus != StatusEnum.已生效) { result.ResultStatus = -1; result.Message = "子合约状态非已生效,不能进行点价申请"; return result; } //decimal missRate = Convert.ToDecimal(0.05); //if (pricingApply.PricingWeight > sub.SignAmount) //{ // result.ResultStatus = -1; // result.Message = "点价重量超过子合约签订数量"; // return result; //} //获取合约 result = contractDAL.Get(user, sub.ContractId); if (result.ResultStatus != 0) return result; NFMT.Contract.Model.Contract contract = result.ReturnValue as NFMT.Contract.Model.Contract; if (contract == null || contract.ContractId <= 0) { result.ResultStatus = -1; result.Message = "关联合约不存在"; return result; } if (contract.TradeDirection == (int)NFMT.Contract.TradeDirectionEnum.Buy) pricingApply.PricingDirection = (int)NFMT.DoPrice.PricingDirection.空头; else pricingApply.PricingDirection = (int)NFMT.DoPrice.PricingDirection.多头; //新增点价申请 result = pricingApplyDAL.Insert(user, pricingApply); if (result.ResultStatus != 0) return result; int pricingApplyId = (int)result.ReturnValue; foreach (Model.PricingApplyDetail detail in pricingApplyDetails) { detail.PricingApplyId = pricingApplyId; detail.DetailStatus = StatusEnum.已生效; result = pricingApplyDetailDAL.Insert(user, detail); if (result.ResultStatus != 0) return result; } scope.Complete(); } } catch (Exception e) { result.ResultStatus = -1; result.Message = e.Message; } return result; }
public ResultModel ConfirmCancel(UserModel user, int pricingApplyId) { ResultModel result = new ResultModel(); try { DAL.PricingApplyDAL pricingApplyDAL = new PricingApplyDAL(); DAL.PricingApplyDetailDAL pricingApplyDetailDAL = new PricingApplyDetailDAL(); Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL(); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { //验证点价申请 result = pricingApplyDAL.Get(user, pricingApplyId); if (result.ResultStatus != 0) return result; Model.PricingApply pricingApply = result.ReturnValue as Model.PricingApply; if (pricingApply == null || pricingApply.PricingApplyId <= 0) { result.ResultStatus = -1; result.Message = "点价申请不存在"; return result; } //验证主申请 result = applyDAL.Get(user, pricingApply.ApplyId); if (result.ResultStatus != 0) return result; Operate.Model.Apply apply = result.ReturnValue as Operate.Model.Apply; if (apply == null || apply.ApplyId <= 0) { result.ResultStatus = -1; result.Message = "主申请不存在"; return result; } //主申请状态更新至已生效 result = applyDAL.ConfirmCancel(user, apply); if (result.ResultStatus != 0) return result; //点价申请明细,在已完成状态下的更新至已生效 //获取已关闭的明细 result = pricingApplyDetailDAL.Load(user, pricingApply.PricingApplyId, Common.StatusEnum.已完成); if (result.ResultStatus != 0) return result; List<Model.PricingApplyDetail> details = result.ReturnValue as List<Model.PricingApplyDetail>; if (details == null) { result.ResultStatus = -1; result.Message = "获取申请明细失败"; return result; } foreach (Model.PricingApplyDetail detail in details) { result = pricingApplyDetailDAL.ConfirmCancel(user, detail); if (result.ResultStatus != 0) return result; } scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } return result; }
public ResultModel Create(UserModel user, Model.Pricing pricing, List<Model.PricingDetail> pricingDetails) { ResultModel result = new ResultModel(); DAL.PricingDetailDAL pricingDetailDAL = new PricingDetailDAL(); DAL.PricingApplyDAL pricingApplyDAL = new PricingApplyDAL(); DAL.PricingApplyDetailDAL applyDetail = new PricingApplyDetailDAL(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { //获取点价申请 result = pricingApplyDAL.Get(user, pricing.PricingApplyId); if (result.ResultStatus != 0) return result; Model.PricingApply pricingApply = result.ReturnValue as Model.PricingApply; if (pricingApply == null || pricingApply.PricingApplyId <= 0) { result.ResultStatus = -1; result.Message = "对应点价申请不存在"; return result; } if (pricing.AvgPrice < pricingApply.MinPrice || pricing.AvgPrice > pricingApply.MaxPrice) { result.ResultStatus = -1; result.Message = "期货成交价不在点价申请价格范围内"; return result; } result = pricingDAL.IsWeightCanPricing(user, pricing.PricingApplyId, pricing.FuturesCodeId, pricingApply.PricingWeight, pricing.PricingWeight, false, 0); if (result.ResultStatus != 0) return result; pricing.PricingDirection = pricingApply.PricingDirection; pricing.PricingStatus = StatusEnum.已录入; result = pricingDAL.Insert(user, pricing); if (result.ResultStatus != 0) return result; int pricingId = (int)result.ReturnValue; foreach (Model.PricingDetail detail in pricingDetails) { detail.PricingId = pricingId; detail.DetailStatus = StatusEnum.已生效; result = pricingDetailDAL.Insert(user, detail); if (result.ResultStatus != 0) return result; } scope.Complete(); } } catch (Exception ex) { result.Message = ex.Message; } finally { if (result.ResultStatus != 0) this.Log.ErrorFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue); else if (this.Log.IsInfoEnabled) this.Log.InfoFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue); } return result; }