列表页新增"新增"按钮(结算管理-日终价格修改 权限),打开统一新增页;选标的后按 UnderlyingInstrumentType 自动显示对应字段组,保存时路由到正确的 Save 方法落到对应表;字段与上传 Excel 对齐,避免冗余字段。
216 lines
7.8 KiB
C#
216 lines
7.8 KiB
C#
using YLErp.DBModels;
|
|
using YLErp.Modules.EodModule;
|
|
|
|
namespace YLErp.Web.Controllers
|
|
{
|
|
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)
|
|
{
|
|
if (string.IsNullOrEmpty(enid) || enid == "0")
|
|
{
|
|
return View(new eod_commodity_future_price());
|
|
}
|
|
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)
|
|
{
|
|
if (string.IsNullOrEmpty(enid) || enid == "0")
|
|
{
|
|
return View(new eod_stock_price());
|
|
}
|
|
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)
|
|
{
|
|
if (string.IsNullOrEmpty(enid) || enid == "0")
|
|
{
|
|
return View(new ChinaBondValuation());
|
|
}
|
|
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);
|
|
}
|
|
[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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 日终价格新增:统一入口,按所选标的的类型自动落到对应表
|
|
/// (债券→china_bond_valuation / 商品期货→eod_commodity_future_price / 股票→eod_stock_price)。
|
|
/// 与编辑页同级权限(结算管理-日终价格修改)。
|
|
/// </summary>
|
|
[MyAuthorize("结算管理-日终价格修改")]
|
|
public ActionResult EodPriceAdd()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
/// <summary>00
|
|
/// 新增时选择标的的补全接口:返回代码/名称/品种类型/市场/标的ID,
|
|
/// 供前端按 UnderlyingInstrumentType 自动判断落入哪张日终价格表。
|
|
/// </summary>
|
|
[HttpPost]
|
|
public JsonResult UnderlyingSuggestForEod(string q)
|
|
{
|
|
q = (q ?? "").Trim();
|
|
var list = yldb.underlying_manager
|
|
.Where(n => string.IsNullOrEmpty(q) || n.UnderlyingCode.Contains(q) || n.UnderlyingName.Contains(q))
|
|
.OrderBy(n => n.UnderlyingCode)
|
|
.Take(30)
|
|
.Select(n => new
|
|
{
|
|
Id = n.id,
|
|
Code = n.UnderlyingCode,
|
|
Name = n.UnderlyingName,
|
|
InstrumentType = n.UnderlyingInstrumentType,
|
|
Market = n.MarketName
|
|
})
|
|
.ToList();
|
|
return JsonSuccess("", list);
|
|
}
|
|
|
|
[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);
|
|
}
|
|
}
|
|
}
|
|
}
|