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

143 lines
5.0 KiB
C#

using YLErp.Modules.EodModule;
using YLErp.Modules.EodModule.QueryModule;
namespace YLErp.Web.Controllers
{
/// <summary>
/// 日终持仓
/// </summary>
public class EodPositionController : BaseController
{
/// <summary>
/// 兴证数据中心接口
/// </summary>
public ActionResult XingZheng()
{
FtpSettings settings = null;
var filePath = Server.MapPath("/App_Data/XingZheng/eod_ftp_cfg.json");
if (System.IO.File.Exists(filePath))
{
var json = System.IO.File.ReadAllText(filePath);
settings = JsonHelper.Deserialize<FtpSettings>(json);
}
if (settings != null)
{
var folder = Path.GetDirectoryName(filePath);
filePath = Path.Combine(folder, "eod_ftp_msg.txt");
if (System.IO.File.Exists(filePath))
{
ViewData["LastMsg"] = System.IO.File.ReadAllText(filePath);
}
}
else
{
settings = new FtpSettings();
}
return View(settings);
}
public ActionResult XingZhengExport(DateTime valueDate)
{
try
{
var service = new EodTradePositionExportService(CurUser);
var bytes = service.ExportXingZhengZipFile(valueDate, out var zipFileName);
return File(bytes, "application/zip", zipFileName);
}
catch (Exception ex)
{
return ShowError(ex.Messages());
}
}
public JsonResult XingZhengFtpUpload(DateTime valueDate, FtpSettings settings)
{
if (settings == null)
{
return JsonError("参数错误");
}
if (string.IsNullOrEmpty(settings.FtpHost))
{
return JsonError("FTP主机 必须填写");
}
var dtStr = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
var result = new HandleResult(1);
try
{
XingZhengService.FtpUploadEodPosition(CurUser, valueDate, settings);
var msg = $"操作时间: {dtStr}, 持仓日期: {valueDate:yyyy-MM-dd}, 成功上传到FTP服务器";
result = new HandleResult(0, msg);
LogFactory.GetLogger("eod_ftp").Info(msg);
}
catch (Exception ex)
{
var msg = $"操作时间: {dtStr}, 持仓日期: {valueDate:yyyy-MM-dd}, 上传到FTP服务器失败," + ex.Messages();
result = new HandleResult(msg);
LogFactory.GetLogger("eod_ftp").Error(ex, msg);
}
finally
{
var folder = Server.MapPath("/App_Data/XingZheng");
Task.Run(() =>
{
Directory.CreateDirectory(folder);
System.IO.File.WriteAllText(Path.Combine(folder, "eod_ftp_msg.txt"), result.Message);
if (result.IsSuccess)
{
System.IO.File.WriteAllText(Path.Combine(folder, "eod_ftp_cfg.json"), settings.ToJson());
}
}).ContinueWith(t =>
{
if (t.Exception != null)
{
LogFactory.GetLogger("eod_ftp").Error(t.Exception);
}
});
}
return JsonSuccessData(new { success = result.IsSuccess, msg = result.Message });
}
[ResponseCache(NoStore = true)]
public ActionResult ExportClient(DateTime tradeDate)
{
var result = new EodTradePositionExportService(CurUser).GetClient();
return File(result, "text/comma-separated-values",
$"otc_client{tradeDate:yyyyMMdd}.csv");
}
[ResponseCache(NoStore = true)]
public ActionResult ExportEodPosition(DateTime tradeDate)
{
var req = new Model.EodPositionRisksReq();
req.BookIds = AssetUnitModel.IntersectAssetUnits(req.AssetIdGroupList, req.BookIds).ToList();
req.UserAssets = CurUser.GetAssetUnitIds();
req.UserClients = CurUser.GetClientIdsByCurUser(CurUser.交易管理_查看所有交易);
req.ValueDate = tradeDate;
req.TradeTypes = new string[] {"香草期权","障碍期权","二元期权","亚式期权","合成价差期权","双鲨期权","凤凰期权","雪球期权","累计期权","区间累积期权","气囊结构","收益增强结构","自定义交易","牛市价差","熊市价差","亚式熊市价差",
"跨式组合","宽跨式组合","蝶式组合","远期","掉期","结构化交易","商品现货", "股票","黑箱结构"};
var result = new EodTradePositionExportService(CurUser).GetEodPosition(req);
return File(result, "text/comma-separated-values",
$"otc_position{tradeDate:yyyyMMdd}.csv");
}
}
}