Commit 38a3bf2e by guanzhenshan

增加物流费用基础信息的汇率和人民币金额

parent 11b3e035
...@@ -12,28 +12,28 @@ namespace Bailun.DC.DailyLogisticSupplierTransaction ...@@ -12,28 +12,28 @@ namespace Bailun.DC.DailyLogisticSupplierTransaction
/// </summary> /// </summary>
/// <param name="args"></param> /// <param name="args"></param>
/// <returns></returns> /// <returns></returns>
static async Task Main(string[] args) //static async Task Main(string[] args)
{
Console.WriteLine("启动服务 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
var builder = new HostBuilder().ConfigureServices((hostContext, services) =>
{
services.AddHostedService<Services>();
});
await builder.RunConsoleAsync();
}
//static void Main(string[] args)
//{ //{
// var _services = new Services(); // Console.WriteLine("启动服务 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
// var builder = new HostBuilder().ConfigureServices((hostContext, services) =>
// var start = DateTime.Parse("2020-06-01");
// while (start.AddDays(1) < DateTime.Now)
// { // {
// Console.WriteLine(start); // services.AddHostedService<Services>();
// _services.Init(start); // });
// start = start.AddDays(1);
// } // await builder.RunConsoleAsync();
//} //}
static void Main(string[] args)
{
var _services = new Services();
var start = DateTime.Parse("2020-09-01");
while (start.AddDays(1) < DateTime.Now)
{
Console.WriteLine(start);
_services.Init(start);
start = start.AddDays(1);
}
}
} }
} }
...@@ -61,5 +61,9 @@ namespace Bailun.DC.SyncLogisticInfo.Models ...@@ -61,5 +61,9 @@ namespace Bailun.DC.SyncLogisticInfo.Models
public DateTime gmt_modify_time { get; set; } public DateTime gmt_modify_time { get; set; }
public string currencytype { get; set; } public string currencytype { get; set; }
public decimal? exchangerate { get; set; }
public decimal? amount_rmb { get; set; }
} }
} }
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.DC.SyncLogisticInfo.Models
{
public class response_Exchange
{
public decimal rate { get; set; }
public string toCurName { get; set; }
public string createTime { get; set; }
}
}
...@@ -29,8 +29,9 @@ namespace Bailun.DC.SyncLogisticInfo ...@@ -29,8 +29,9 @@ namespace Bailun.DC.SyncLogisticInfo
// Console.WriteLine("Hello World!"); // Console.WriteLine("Hello World!");
// var _service = new Services(); // var _service = new Services();
// _service.Init(); // //_service.Init();
// _service.UpdateRMBAmount();
//} //}
......
...@@ -8,6 +8,7 @@ using Dapper; ...@@ -8,6 +8,7 @@ using Dapper;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Linq;
namespace Bailun.DC.SyncLogisticInfo namespace Bailun.DC.SyncLogisticInfo
{ {
...@@ -15,6 +16,7 @@ namespace Bailun.DC.SyncLogisticInfo ...@@ -15,6 +16,7 @@ namespace Bailun.DC.SyncLogisticInfo
{ {
private static bool isRuning = false; private static bool isRuning = false;
private Timer _timer; private Timer _timer;
private static List<Tuple<DateTime, string, decimal>> listMonthExchange = new List<Tuple<DateTime, string, decimal>>();
protected override Task ExecuteAsync(CancellationToken stoppingToken) protected override Task ExecuteAsync(CancellationToken stoppingToken)
{ {
...@@ -32,6 +34,11 @@ namespace Bailun.DC.SyncLogisticInfo ...@@ -32,6 +34,11 @@ namespace Bailun.DC.SyncLogisticInfo
{ {
Console.WriteLine("开始启动 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Console.WriteLine("开始启动 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
Init(); Init();
//更新汇率
Console.WriteLine("开始更新汇率 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
UpdateRMBAmount();
Console.WriteLine("任务运行完成 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Console.WriteLine("任务运行完成 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
} }
...@@ -144,6 +151,7 @@ namespace Bailun.DC.SyncLogisticInfo ...@@ -144,6 +151,7 @@ namespace Bailun.DC.SyncLogisticInfo
private void Save(List<DataInfo> list) private void Save(List<DataInfo> list)
{ {
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString)) using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
{ {
if (cn.State == System.Data.ConnectionState.Closed) if (cn.State == System.Data.ConnectionState.Closed)
...@@ -192,6 +200,50 @@ namespace Bailun.DC.SyncLogisticInfo ...@@ -192,6 +200,50 @@ namespace Bailun.DC.SyncLogisticInfo
currencytype = item.currencyType, currencytype = item.currencyType,
}; };
//获取相应汇率 取当月顺延第一日的汇率
if(m.currencytype.ToLower()=="cny")
{
m.amount_rmb = m.merchant_shipment_cost_cny;
m.exchangerate = 1;
}
else if(m.merchant_reconciliation_time.HasValue)
{
var objRate = listMonthExchange.Where(a => a.Item1.Year == m.merchant_reconciliation_time.Value.Year && a.Item1.Month == m.merchant_reconciliation_time.Value.Month && a.Item2==m.currencytype.ToUpper()).FirstOrDefault();
if(objRate!=null)
{
m.exchangerate = objRate.Item3;
m.amount_rmb = m.merchant_shipment_cost_cny * objRate.Item3;
}
else
{
//获取当月汇率
try
{
var _url_exchange = $"http://oa.bailuntec.com/Api/ExchangeRate/GetMonthlyExchangeRateByDate?date={m.merchant_reconciliation_time.Value.ToString("yyyy-MM")}&toCur=CNY&fromCur="+m.currencytype.ToUpper();
var result_Exchange = Common.HttpHelper.NetHelper.Request(_url_exchange);
if (!string.IsNullOrEmpty(result_Exchange))
{
var json = Newtonsoft.Json.JsonConvert.DeserializeObject<Models.response_Exchange>(result_Exchange);
objRate = new Tuple<DateTime, string, decimal>(DateTime.Parse(m.merchant_reconciliation_time.Value.ToString("yyyy-MM")+"-01"),m.currencytype.ToUpper(),json.rate);
listMonthExchange.Add(objRate);
m.exchangerate = objRate.Item3;
m.amount_rmb = objRate.Item3 * m.merchant_shipment_cost_cny;
}
}
catch (Exception ex)
{
}
}
}
cn.Insert<dc_base_logistics>(m); cn.Insert<dc_base_logistics>(m);
} }
catch (Exception ex) catch (Exception ex)
...@@ -205,5 +257,94 @@ namespace Bailun.DC.SyncLogisticInfo ...@@ -205,5 +257,94 @@ namespace Bailun.DC.SyncLogisticInfo
} }
public void UpdateRMBAmount()
{
var list = new List<dc_base_logistics>();
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString_read))
{
if(cn.State== System.Data.ConnectionState.Closed)
{
cn.Open();
}
list = cn.Query<dc_base_logistics>("select * from dc_base_logistics where merchant_reconciliation_time>='2020-09-01' and amount_rmb is null",null,null,true,6*60).ToList();
}
if(list.Count>0)
{
//
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
{
foreach (var item in list)
{
if (item.currencytype.ToLower() == "cny")
{
item.amount_rmb = item.merchant_shipment_cost_cny;
item.exchangerate = 1;
if (cn.State == System.Data.ConnectionState.Closed)
{
cn.Open();
}
cn.Execute($"update dc_base_logistics set exchangerate={item.exchangerate},amount_rmb={item.amount_rmb} where id={item.id}");
}
else
{
var objRate = listMonthExchange.Where(a => a.Item1.Year == item.merchant_reconciliation_time.Value.Year && a.Item1.Month == item.merchant_reconciliation_time.Value.Month && a.Item2 == item.currencytype.ToUpper()).FirstOrDefault();
if (objRate != null)
{
item.exchangerate = objRate.Item3;
item.amount_rmb = item.merchant_shipment_cost_cny * objRate.Item3;
if (cn.State == System.Data.ConnectionState.Closed)
{
cn.Open();
}
cn.Execute($"update dc_base_logistics set exchangerate={item.exchangerate},amount_rmb={item.amount_rmb} where id={item.id}");
}
else
{
//获取当月汇率
try
{
var _url_exchange = $"http://oa.bailuntec.com/Api/ExchangeRate/GetMonthlyExchangeRateByDate?date={item.merchant_reconciliation_time.Value.ToString("yyyy-MM")}&toCur=CNY&fromCur=" + item.currencytype.ToUpper();
var result_Exchange = Common.HttpHelper.NetHelper.Request(_url_exchange);
if (!string.IsNullOrEmpty(result_Exchange))
{
var json = Newtonsoft.Json.JsonConvert.DeserializeObject<Models.response_Exchange>(result_Exchange);
objRate = new Tuple<DateTime, string, decimal>(DateTime.Parse(item.merchant_reconciliation_time.Value.ToString("yyyy-MM") + "-01"), item.currencytype.ToUpper(), json.rate);
listMonthExchange.Add(objRate);
item.exchangerate = objRate.Item3;
item.amount_rmb = objRate.Item3 * item.merchant_shipment_cost_cny;
if (cn.State == System.Data.ConnectionState.Closed)
{
cn.Open();
}
cn.Execute($"update dc_base_logistics set exchangerate={item.exchangerate},amount_rmb={item.amount_rmb} where id={item.id}");
}
}
catch (Exception ex)
{
}
}
}
}
}
Console.WriteLine("本次更新" + list.Count + "条记录");
}
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment