Files
zszq-trs/YLErpDAL/Helpers/BondCalcHepler.cs
T

77 lines
2.6 KiB
C#

using Org.BouncyCastle.Asn1.Ocsp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YLErp.Model;
namespace YLErp.Helpers
{
/// <summary>
/// 计算器帮助类
/// </summary>
public class BondCalcHepler
{
/// <summary>
/// 计算器
/// </summary>
/// <returns></returns>
public static CalBondResult BondCalc(string underlyingCode,decimal price,string priceType="DP")
{
var baseUrl = Environment.GetEnvironmentVariable("BondOmsInterface_BaseUrl");
var calculateUrl = "/calc/cal_bond_value";
CalcBondRequest request = new CalcBondRequest() {
bondId= underlyingCode,
price = price.ToString(),
priceType = priceType,
};
if (!string.IsNullOrEmpty(baseUrl))
{
var httpHelper = new HttpHelper(baseUrl, null);
// http 请求 Web项目接口
var result = httpHelper.PostRequestNoAuth<CalcBondRequest, CalcBondReponse>(calculateUrl, request).Result;
if (result != null && !result.success)
{
LogFactory.GetLogger("BondCalcHepler").Info("计算器计算失败:" + result.message);
}
else
{
return result.data;
}
}
return null;
}
public static CalBondResult BondCalcByDate(string underlyingCode, decimal price, String targetDate, string priceType = "DP")
{
var baseUrl = Environment.GetEnvironmentVariable("BondOmsInterface_BaseUrl");
var calculateUrl = "/calc/cal_bond_value";
CalcBondRequest request = new CalcBondRequest()
{
bondId = underlyingCode,
price = price.ToString(),
priceType = priceType,
targetDate = targetDate,
};
if (!string.IsNullOrEmpty(baseUrl))
{
var httpHelper = new HttpHelper(baseUrl, null);
try
{
// http 请求 Web项目接口
var result = httpHelper.PostRequestNoAuth<CalcBondRequest, CalcBondReponse>(calculateUrl, request).Result;
return result.data;
}
catch (Exception ex)
{
LogFactory.GetLogger("BondCalcHelper").Error("请求计算器时发生异常", ex);
}
}
return null;
}
}
}