Files
zszq-trs/YLErpWeb/Controllers/EodPriceController.cs
T
2024-05-09 14:06:26 +08:00

181 lines
6.4 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);
}
[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);
}
}
}
}