From 2ade7b46bb5b029b674b5731d67f30c0e5d48806 Mon Sep 17 00:00:00 2001 From: hjhan Date: Mon, 13 Jul 2026 13:15:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=97=A5=E7=BB=88=E4=BB=B7=E6=A0=BC?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=94=B9=E5=9B=9E=E6=89=8B=E5=8A=A8=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E6=A0=87=E7=9A=84=E4=BB=A3=E7=A0=81=EF=BC=88=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=85=A8=E9=87=8F=E4=B8=8B=E6=8B=89=E3=80=81=E8=A7=A3?= =?UTF-8?q?=E5=86=B3null=E6=8A=A5=E9=94=99=E4=B8=8E=E5=B8=82=E5=9C=BA?= =?UTF-8?q?=E5=B8=A6=E5=87=BA=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除 BuildUnderlyingOptions/UnderlyingOptionVm(几十万债券全量下拉导致卡死、选不动) - 新增轻量 LookupUnderlyingForEod(code,kind):精确按代码查一条、强制 LaunchState=="1"(与列表查询对齐,杜绝幽灵记录) - 三个编辑页新建时标的代码改为可输入框,onblur 用 main.post 带出市场;期货额外回填 UnderlyingId(按id join) - 隐藏域按新建/编辑分渲染,修复 saveeod_*/on*Picked 读 null 报错 - 删除已废弃的 eodPriceAdd.cshtml --- YLErpWeb/Controllers/EodPriceController.cs | 115 ++++---- .../Views/EodPrice/eodBondPriceEdit.cshtml | 43 +-- .../Views/EodPrice/eodFuturePriceEdit.cshtml | 54 ++-- YLErpWeb/Views/EodPrice/eodPriceAdd.cshtml | 268 ------------------ .../Views/EodPrice/eodStockPriceEdit.cshtml | 40 +-- 5 files changed, 145 insertions(+), 375 deletions(-) delete mode 100644 YLErpWeb/Views/EodPrice/eodPriceAdd.cshtml diff --git a/YLErpWeb/Controllers/EodPriceController.cs b/YLErpWeb/Controllers/EodPriceController.cs index 17a12bcc..91ce6409 100644 --- a/YLErpWeb/Controllers/EodPriceController.cs +++ b/YLErpWeb/Controllers/EodPriceController.cs @@ -4,18 +4,6 @@ using YLErp.Modules.EodModule; namespace YLErp.Web.Controllers { - /// - /// 新建日终价格时,编辑页用来渲染"选择标的"下拉项的轻量视图模型。 - /// 纯服务端渲染,前端不依赖任何自动补全插件。 - /// - public class UnderlyingOptionVm - { - public int Id { get; set; } - public string Code { get; set; } - public string Name { get; set; } - public string Market { get; set; } - } - public class EodPriceController : BaseController { readonly IViewRenderService _viewRenderer; @@ -71,13 +59,8 @@ namespace YLErp.Web.Controllers ViewBag.IsNew = isNew; if (isNew) { - // 新建:提供期货类标的下拉,供前端选择后回填 UnderlyingId/UnderlyingCode/市场 - ViewBag.UnderlyingOptions = BuildUnderlyingOptions( - ConsGlobal.InstrumentType.CommodityFutures, - ConsGlobal.InstrumentType.GoldFutures, - ConsGlobal.InstrumentType.TBFutures, - ConsGlobal.InstrumentType.OtherFutures, - ConsGlobal.InstrumentType.AbroadFutures); + // 新建:手工输入标的代码,失焦时调 LookupUnderlyingForEod 校验并带出市场/UnderlyingId。 + // 默认估值日期=今天:避免未填日期时落库为 0001-01-01、落在列表默认窗口(今天)之外而查不出。 return View(new eod_commodity_future_price { ValueDate = DateTime.Today }); } var intid = DecryptInt(enid); @@ -96,16 +79,7 @@ namespace YLErp.Web.Controllers ViewBag.IsNew = isNew; if (isNew) { - // 新建:提供股票类标的下拉 - ViewBag.UnderlyingOptions = BuildUnderlyingOptions( - ConsGlobal.InstrumentType.Stock, - ConsGlobal.InstrumentType.StockIndex, - ConsGlobal.InstrumentType.StockIF, - ConsGlobal.InstrumentType.HKStock, - ConsGlobal.InstrumentType.HKStockIndex, - ConsGlobal.InstrumentType.NewOtcStock, - ConsGlobal.InstrumentType.AbroadStock, - ConsGlobal.InstrumentType.AbroadStockIndex); + // 新建:手工输入标的代码,失焦时调 LookupUnderlyingForEod 校验并带出市场。 return View(new eod_stock_price { ValueDate = DateTime.Today }); } var intid = DecryptInt(enid); @@ -123,13 +97,8 @@ namespace YLErp.Web.Controllers ViewBag.IsNew = isNew; if (isNew) { - // 新建:提供债券类标的下拉(bond_id 由前端选择后回填)。 - // 默认估值日期=今天:避免未填日期时落库为 0001-01-01,落在列表默认窗口(今天)之外而查不出。 - ViewBag.UnderlyingOptions = BuildUnderlyingOptions( - ConsGlobal.InstrumentType.Bonds, - ConsGlobal.InstrumentType.TBonds, - ConsGlobal.InstrumentType.CreditBonds, - ConsGlobal.InstrumentType.OtherBonds); + // 新建:手工输入债券代码(bond_id),失焦时调 LookupUnderlyingForEod 校验并带出市场。 + // 默认估值日期=今天:避免未填日期时落库为 0001-01-01、落在列表默认窗口(今天)之外而查不出。 return View(new ChinaBondValuation { valuation_date = DateTime.Today }); } var intid = DecryptLong(enid); @@ -143,23 +112,69 @@ namespace YLErp.Web.Controllers } /// - /// 按标的类型取可下拉的标的列表(新建日终价格时供前端选择)。 - /// 返回 Id/Code/Name/Market,纯服务端渲染,不依赖前端自动补全插件。 + /// 新建日终价格时,按用户手工输入的标的代码精确查一条标的,带出名称/市场/Id。 + /// 只返回已上市(LaunchState=="1")且类型匹配的标的——与列表查询 inner join 的过滤对齐, + /// 从源头杜绝"新增能存但查不出"的幽灵记录。前端在输入框失焦时调用,不依赖任何下拉/补全插件。 /// - private List BuildUnderlyingOptions(params string[] instrumentTypes) + /// 标的代码(用户手工输入) + /// bond | future | stock,决定允许的标的类型集合 + [HttpPost] + public JsonResult LookupUnderlyingForEod(string code, string kind) { - var set = new HashSet(instrumentTypes); - return yldb.underlying_manager - .Where(n => n.UnderlyingCode != null && n.LaunchState == "1" && set.Contains(n.UnderlyingInstrumentType)) - .OrderBy(n => n.UnderlyingCode) - .Select(n => new UnderlyingOptionVm + if (string.IsNullOrWhiteSpace(code)) + { + return JsonError("请输入标的代码"); + } + code = code.Trim(); + + string[] types = kind switch + { + "future" => new[] { - Id = n.id, - Code = n.UnderlyingCode, - Name = n.UnderlyingName, - Market = n.MarketName - }) - .ToList(); + ConsGlobal.InstrumentType.CommodityFutures, + ConsGlobal.InstrumentType.GoldFutures, + ConsGlobal.InstrumentType.TBFutures, + ConsGlobal.InstrumentType.OtherFutures, + ConsGlobal.InstrumentType.AbroadFutures, + }, + "stock" => new[] + { + ConsGlobal.InstrumentType.Stock, + ConsGlobal.InstrumentType.StockIndex, + ConsGlobal.InstrumentType.StockIF, + ConsGlobal.InstrumentType.HKStock, + ConsGlobal.InstrumentType.HKStockIndex, + ConsGlobal.InstrumentType.NewOtcStock, + ConsGlobal.InstrumentType.AbroadStock, + ConsGlobal.InstrumentType.AbroadStockIndex, + }, + _ => new[] + { + ConsGlobal.InstrumentType.Bonds, + ConsGlobal.InstrumentType.TBonds, + ConsGlobal.InstrumentType.CreditBonds, + ConsGlobal.InstrumentType.OtherBonds, + }, + }; + var set = new HashSet(types); + + var u = yldb.underlying_manager + .Where(n => n.UnderlyingCode == code && n.LaunchState == "1" && set.Contains(n.UnderlyingInstrumentType)) + .Select(n => new { n.id, n.UnderlyingCode, n.UnderlyingName, n.MarketName }) + .FirstOrDefault(); + + if (u == null) + { + return JsonError("未找到该标的(不存在、未上市或类型不匹配),无法录入"); + } + + return JsonSuccess("", new + { + Id = u.id, + Code = u.UnderlyingCode, + Name = u.UnderlyingName, + Market = u.MarketName, + }); } [HttpPost] public JsonResult EodFuturePriceEditJson(eod_commodity_future_price req) diff --git a/YLErpWeb/Views/EodPrice/eodBondPriceEdit.cshtml b/YLErpWeb/Views/EodPrice/eodBondPriceEdit.cshtml index aeb164ae..7a0a89c9 100644 --- a/YLErpWeb/Views/EodPrice/eodBondPriceEdit.cshtml +++ b/YLErpWeb/Views/EodPrice/eodBondPriceEdit.cshtml @@ -1,7 +1,8 @@ @model ChinaBondValuation @{ - ViewBag.Title = "日终商品期货价格 | 编辑"; + ViewBag.Title = "日终债券价格 | 编辑"; Layout = "~/Views/Shared/_InfoLayout.cshtml"; + bool isNew = ViewBag.IsNew != null && (bool)ViewBag.IsNew; } @section JS { @@ -16,16 +17,23 @@ return pass; } - function onBondPicked() { - var sel = document.getElementById('BondPicker'); - var opt = sel.options[sel.selectedIndex]; - document.getElementById('bond_id').value = opt.value; - document.getElementById('MarketBox').value = opt.getAttribute('data-market') || ''; + // 手工输入债券代码后失焦:校验标的存在且已上市,并带出市场 + function lookupBond() { + var el = document.getElementById('bond_id'); + if (!el) return; + var code = (el.value || '').trim(); + var mk = document.getElementById('MarketBox'); + if (!code) { if (mk) mk.value = ''; return; } + main.post("/eodPrice/LookupUnderlyingForEod", { code: code, kind: 'bond' }).done(function (res) { + el.value = res.obj.Code; + if (mk) mk.value = res.obj.Market || ''; + }); } function saveeod_bond_price() { - if (document.getElementById('BondPicker') && !document.getElementById('bond_id').value) { - main.message('请先选择债券标的'); return false; + var el = document.getElementById('bond_id'); + if (el && !(el.value || '').trim()) { + main.message('请输入债券标的代码'); return false; } if (!checkSubmitData()) return false; var data = $("#form1").serialize(); @@ -41,23 +49,20 @@ - + @if (!isNew) + { + + }

日终债券价格修改

- @if (ViewBag.IsNew != null && (bool)ViewBag.IsNew) + @if (isNew) {
- - + +
@@ -85,4 +90,4 @@
- \ No newline at end of file + diff --git a/YLErpWeb/Views/EodPrice/eodFuturePriceEdit.cshtml b/YLErpWeb/Views/EodPrice/eodFuturePriceEdit.cshtml index 9cddbc82..b4edeb1a 100644 --- a/YLErpWeb/Views/EodPrice/eodFuturePriceEdit.cshtml +++ b/YLErpWeb/Views/EodPrice/eodFuturePriceEdit.cshtml @@ -2,6 +2,7 @@ @{ ViewBag.Title = "日终商品期货价格 | 编辑"; Layout = "~/Views/Shared/_InfoLayout.cshtml"; + bool isNew = ViewBag.IsNew != null && (bool)ViewBag.IsNew; } @section JS { @@ -16,17 +17,29 @@ return pass; } - function onFuturePicked() { - var sel = document.getElementById('FuturePicker'); - var opt = sel.options[sel.selectedIndex]; - document.getElementById('UnderlyingId').value = opt.value; - document.getElementById('UnderlyingCode').value = opt.getAttribute('data-code') || ''; - document.getElementById('MarketBox').value = opt.getAttribute('data-market') || ''; + // 手工输入期货合约代码后失焦:校验标的存在且已上市,带出市场并回填 UnderlyingId(列表查询按此 join) + function lookupFuture() { + var el = document.getElementById('UnderlyingCode'); + if (!el) return; + var code = (el.value || '').trim(); + var mk = document.getElementById('MarketBox'); + var idEl = document.getElementById('UnderlyingId'); + if (!code) { if (mk) mk.value = ''; if (idEl) idEl.value = ''; return; } + main.post("/eodPrice/LookupUnderlyingForEod", { code: code, kind: 'future' }).done(function (res) { + el.value = res.obj.Code; + if (idEl) idEl.value = res.obj.Id; + if (mk) mk.value = res.obj.Market || ''; + }); } function saveeod_commodity_future_price() { - if (document.getElementById('FuturePicker') && !document.getElementById('UnderlyingCode').value) { - main.message('请先选择期货标的'); return false; + var el = document.getElementById('UnderlyingCode'); + var idEl = document.getElementById('UnderlyingId'); + if (el && !(el.value || '').trim()) { + main.message('请输入期货标的代码'); return false; + } + if (el && idEl && !idEl.value) { + main.message('标的未校验通过,请重新输入代码后失焦'); return false; } if (!checkSubmitData()) return false; var data = $("#form1").serialize(); @@ -42,25 +55,26 @@ - - + @if (isNew) + { + + } + else + { + + + }

日终商品期货价格修改

- @if (ViewBag.IsNew != null && (bool)ViewBag.IsNew) + @if (isNew) {
- - + +
@@ -88,4 +102,4 @@
- \ No newline at end of file + diff --git a/YLErpWeb/Views/EodPrice/eodPriceAdd.cshtml b/YLErpWeb/Views/EodPrice/eodPriceAdd.cshtml deleted file mode 100644 index bc216e25..00000000 --- a/YLErpWeb/Views/EodPrice/eodPriceAdd.cshtml +++ /dev/null @@ -1,268 +0,0 @@ -@{ - ViewBag.Title = "日终价格新增"; - Layout = "~/Views/Shared/_InfoLayout.cshtml"; -} -@section CSS -{ - -} -@section JS -{ - -} - -
- - - - - - - - -

日终价格新增

- -
-
- - - -
-
- - -
-
- - -
- - @* 债券字段组 *@ - - - @* 商品期货字段组 *@ - - - @* 股票字段组 *@ - -
- -
- - -
-
diff --git a/YLErpWeb/Views/EodPrice/eodStockPriceEdit.cshtml b/YLErpWeb/Views/EodPrice/eodStockPriceEdit.cshtml index ad7fb36f..08d58bc0 100644 --- a/YLErpWeb/Views/EodPrice/eodStockPriceEdit.cshtml +++ b/YLErpWeb/Views/EodPrice/eodStockPriceEdit.cshtml @@ -2,11 +2,11 @@ @{ ViewBag.Title = "日终股票价格 | 编辑"; Layout = "~/Views/Shared/_InfoLayout.cshtml"; + bool isNew = ViewBag.IsNew != null && (bool)ViewBag.IsNew; } @section JS {