Files
zszq-trs/YLErpWeb/Controllers/EodPriceController.cs
T
hjhan 8cade8ae53 fix: 修复日终价格新增后查不出(picker过滤LaunchState、新记录日期默认今天、列表新增改三选一)
- EodPriceController.BuildUnderlyingOptions 增加 LaunchState=="1" 过滤,与列表查询对齐,避免新增非激活标的被 inner join 永久过滤

- 三个编辑页新建分支将 valuation_date/ValueDate 默认设为今天,落在列表默认查询窗口内

- eodStockPriceEdit 补全 StockPicker 下拉(此前股票无picker,UnderlyingCode为空hidden导致查不出),删除上传无用的状态字段

- eodPriceList.js openEodPriceAdd 改为三选一(债券/期货/股票)打开各自编辑页空enid,替代已废弃的 EodPriceAdd 搜索页
2026-07-13 12:34:39 +08:00

244 lines
9.5 KiB
C#

using YLErp.Core;
using YLErp.DBModels;
using YLErp.Modules.EodModule;
namespace YLErp.Web.Controllers
{
/// <summary>
/// 新建日终价格时,编辑页用来渲染"选择标的"下拉项的轻量视图模型。
/// 纯服务端渲染,前端不依赖任何自动补全插件。
/// </summary>
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;
public EodPriceController(IViewRenderService viewRenderer)
{
_viewRenderer = viewRenderer;
}
[MyAuthorize("结算管理-日终价格查看")]
public ActionResult EodPriceList()
{
return View();
}
[HttpPost]
public JsonResult EodPriceQuery(EodCommodityFuturePriceReq req)
{
var sList = new EodPriceService(CurUser).SearchUnderlyingList(req);
return Json(sList);
}
public ActionResult EodPriceView(string enid, string UnderlyingInstrumentType)
{
var eodUnderlying = new EodPriceViewModel() { UnderlyingInstrumentType = UnderlyingInstrumentType };
var intid = DecryptLong(enid);
if ("Stock".Equals(UnderlyingInstrumentType))
{
var id = Convert.ToInt32(intid);
var r = yldb.eod_stock_price.Find(id);
eodUnderlying.eod_Stock_Price = r;
eodUnderlying.underlying = DataCacheProvider.GetUnderlyingDataSource().GetData(r.UnderlyingCode);
}
else if ("CommodityFutures".Equals(UnderlyingInstrumentType))
{
var id = Convert.ToInt32(intid);
var r = yldb.eod_commodity_future_price.Find(id);
eodUnderlying.eod_commodity_future_price = r;
eodUnderlying.underlying = yldb.underlying_manager.Find(r.UnderlyingId);
}
else
{
var r = yldb.china_bond_valuation.Find(intid);
eodUnderlying.ChinaBondValuation = r;
eodUnderlying.underlying = yldb.underlying_manager.FirstOrDefault(x => x.UnderlyingCode == r.bond_id);
}
return View(eodUnderlying);
}
public ActionResult EodFuturePriceEdit(string enid)
{
bool isNew = string.IsNullOrEmpty(enid) || enid == "0";
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);
return View(new eod_commodity_future_price { ValueDate = DateTime.Today });
}
var intid = DecryptInt(enid);
var dbmodel = yldb.eod_commodity_future_price.Find(intid);
if (dbmodel == null)
{
return ShowError("找不到数据");
}
ViewData["市场"] = DataCacheProvider.GetUnderlyingDataSource().GetData(dbmodel.UnderlyingCode)?.MarketName;
return View(dbmodel);
}
public ActionResult EodStockPriceEdit(string enid)
{
bool isNew = string.IsNullOrEmpty(enid) || enid == "0";
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);
return View(new eod_stock_price { ValueDate = DateTime.Today });
}
var intid = DecryptInt(enid);
var dbmodel = yldb.eod_stock_price.Find(intid);
if (dbmodel == null)
{
return ShowError("找不到数据");
}
ViewData["市场"] = DataCacheProvider.GetUnderlyingDataSource().GetData(dbmodel.UnderlyingCode)?.MarketName;
return View(dbmodel);
}
public ActionResult EodBondPriceEdit(string enid)
{
bool isNew = string.IsNullOrEmpty(enid) || enid == "0";
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);
return View(new ChinaBondValuation { valuation_date = DateTime.Today });
}
var intid = DecryptLong(enid);
var dbmodel = yldb.china_bond_valuation.Find(intid);
if (dbmodel == null)
{
return ShowError("找不到数据");
}
ViewData["市场"] = DataCacheProvider.GetUnderlyingDataSource().GetData(dbmodel.bond_id)?.MarketName;
return View(dbmodel);
}
/// <summary>
/// 按标的类型取可下拉的标的列表(新建日终价格时供前端选择)。
/// 返回 Id/Code/Name/Market,纯服务端渲染,不依赖前端自动补全插件。
/// </summary>
private List<UnderlyingOptionVm> BuildUnderlyingOptions(params string[] instrumentTypes)
{
var set = new HashSet<string>(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
{
Id = n.id,
Code = n.UnderlyingCode,
Name = n.UnderlyingName,
Market = n.MarketName
})
.ToList();
}
[HttpPost]
public JsonResult EodFuturePriceEditJson(eod_commodity_future_price req)
{
if (!string.IsNullOrEmpty(req.EncryptId))
{
req.id = DecryptInt(req.EncryptId);
}
var r = new EodPriceService(CurUser).SaveEodFuturePrice(req);
return JsonSuccess("更新成功", r);
}
public JsonResult EodBondPriceEditJson(ChinaBondValuation req)
{
if (!string.IsNullOrEmpty(req.EncryptId))
{
req.id = DecryptLong(req.EncryptId);
}
var r = new EodPriceService(CurUser).SaveBondPrice(req);
return JsonSuccess("更新成功", r);
}
[HttpPost]
public JsonResult EodStockPriceEditJson(eod_stock_price req)
{
if (!string.IsNullOrEmpty(req.EncryptId))
{
req.id = DecryptInt(req.EncryptId);
}
var r = new EodPriceService(CurUser).SaveEodStockPrice(req);
return JsonSuccess("更新成功", r);
}
[HttpPost]
public JsonResult DeletEodPrice(string id)
{
var intid = DecryptInt(id);
var r = yldb.eod_commodity_future_price.Find(intid);
if (r == null)
{
return JsonError("找不到日终商品期货价格");
}
yldb.eod_commodity_future_price.Remove(r);
yldb.SaveChanges();
return JsonSuccess("删除成功");
}
/// <summary>
/// 导入结算价
/// </summary>
public async Task<ActionResult> UploadSettlementBill(IFormFile file)
{
try
{
if (file == null || string.IsNullOrWhiteSpace(file.FileName))
{
return JsonError("未获取上传文件");
}
var fileExtension = Path.GetExtension(file.FileName);
if (fileExtension.ToLowerInvariant() != ".xlsx")
{
return JsonError("请上传xlsx格式的文件");
}
using var openStream = file.OpenReadStream();
var result = new SettlementPriceImportService(CurUser).ImportxlsxDatas(openStream);
var html = await _viewRenderer.RenderToStringAsync("Common/ImportResult", result);
return JsonSuccess(null, html);
}
catch (Exception ex)
{
LogFactory.GetLogger("导入结算价").Error("导入结算价出错", ex);
return JsonError(ex.Message);
}
}
}
}