Commit d08eb7ff by 泽锋 李

fix

parent 58c639f7
...@@ -114,28 +114,28 @@ namespace AutoTurnOver.DB ...@@ -114,28 +114,28 @@ namespace AutoTurnOver.DB
try try
{ {
var parameter_str = $"?LineCodes={data.LineCodes}"; var parameter_str = $"?LineCodes={data.LineCodes}";
parameter_str += $"endCountries={data.endCountries}"; parameter_str += $"&endCountries={data.endCountries}";
parameter_str += $"Long={data.Long}"; parameter_str += $"&Long={data.Long}";
parameter_str += $"width={data.width}"; parameter_str += $"&width={data.width}";
parameter_str += $"high={data.high}"; parameter_str += $"&high={data.high}";
parameter_str += $"weightKg={data.weightKg}"; parameter_str += $"&weightKg={data.weightKg}";
parameter_str += $"startPoint={data.startPoint}"; parameter_str += $"&startPoint={data.startPoint}";
parameter_str += $"warehouseNo={data.warehouseNo}"; //parameter_str += $"&warehouseNo={data.warehouseNo}";
//parameter_str += $"orderPriceCNY={data.orderPriceCNY}"; //parameter_str += $"orderPriceCNY={data.orderPriceCNY}";
parameter_str += $"platform={data.platform}"; parameter_str += $"&platform={data.platform}";
parameter_str += $"Site={data.Site}"; parameter_str += $"&Site={data.Site}";
//查询采购建议明细 //查询采购建议明细
string url = ConfigHelper.GetValue("ApiLogisticsGetFilterLogisticsAssignLine"); string url = ConfigHelper.GetValue("ApiLogisticsGetFilterLogisticsAssignLine");
string resultStr = HttpHelper.Request(url, RequestType.GET, parameter_str, timeout: 1000 * 60 * 60 * 24); string resultStr = HttpHelper.Request(url+ parameter_str, RequestType.GET, timeout: 1000 * 60 * 60 * 24);
var result = resultStr.ToObj<api_logistic_query_result_dto>(); var result = resultStr.ToObj<api_logistic_query_result_dto>();
if (result == null || result.successLines == null || result.successLines.Count <= 0) if (result == null || result.Data == null || result.Data.successLines == null || result.Data.successLines.Count <= 0)
{ {
throw new Exception("未查询到物流费用"); throw new Exception("未查询到物流费用");
} }
else else
{ {
return result.successLines[0]; return result.Data.successLines[0];
} }
} }
catch (Exception ex) catch (Exception ex)
......
...@@ -8,6 +8,7 @@ using System.Linq; ...@@ -8,6 +8,7 @@ using System.Linq;
using AutoTurnOver.Models; using AutoTurnOver.Models;
using AutoTurnOver.Utility; using AutoTurnOver.Utility;
namespace AutoTurnOver.DB namespace AutoTurnOver.DB
{ {
/// <summary> /// <summary>
...@@ -15,13 +16,28 @@ namespace AutoTurnOver.DB ...@@ -15,13 +16,28 @@ namespace AutoTurnOver.DB
/// </summary> /// </summary>
public class report_cash_flow_forecast_dao : connectionHelper public class report_cash_flow_forecast_dao : connectionHelper
{ {
public static void Calculation()
{
var conn = _connection;
var task_datas = conn.Query<dc_report_cash_flow_forecast_task>(" select * from dc_report_cash_flow_forecast_task where `status`=0 order by update_time asc ").ToList();
foreach (var item in task_datas)
{
CalculationSingle(conn, item);
}
}
/// <summary> /// <summary>
/// 计算现金流 /// 计算现金流
/// </summary> /// </summary>
public static void Calculation(MySqlConnection conn, dc_report_cash_flow_forecast_task task_data) public static void CalculationSingle(MySqlConnection conn, dc_report_cash_flow_forecast_task task_data)
{ {
try try
{ {
task_data.status = 1;
task_data.error_message = "";
task_data.error_stack_trace = "";
conn.Update(task_data);
var now = DateTime.Now; var now = DateTime.Now;
conn.Execute(" delete from dc_report_cash_flow_forecast_task_log where task_id=@task_id ", new { task_id = task_data.id }); conn.Execute(" delete from dc_report_cash_flow_forecast_task_log where task_id=@task_id ", new { task_id = task_data.id });
var logisticsList = ApiUtility.RealTimeShipLogisticsList(); var logisticsList = ApiUtility.RealTimeShipLogisticsList();
...@@ -38,10 +54,24 @@ namespace AutoTurnOver.DB ...@@ -38,10 +54,24 @@ namespace AutoTurnOver.DB
List<dc_auto_config_stock_up_days> up_days = conn.Query<dc_auto_config_stock_up_days>(" select * from dc_auto_config_stock_up_days ").ToList(); List<dc_auto_config_stock_up_days> up_days = conn.Query<dc_auto_config_stock_up_days>(" select * from dc_auto_config_stock_up_days ").ToList();
List<dc_auto_config_safe_inventory> safe_inventorys = conn.Query<dc_auto_config_safe_inventory>(" select * from dc_auto_config_safe_inventory ").ToList(); List<dc_auto_config_safe_inventory> safe_inventorys = conn.Query<dc_auto_config_safe_inventory>(" select * from dc_auto_config_safe_inventory ").ToList();
task_data.error_stack_trace = "模拟计算周转数据";
conn.Update(task_data);
// 模拟跑周转模型 // 模拟跑周转模型
List<invented_turnover_model> turnover_list = GetTurnoverModels(task_data, sale_list, MatchingUpDays(up_days, task_data.warehouse_code), MatchingSafeInventorys(safe_inventorys, task_data.warehouse_code)); List<invented_turnover_model> turnover_list = GetTurnoverModels(task_data, sale_list, MatchingUpDays(up_days, task_data.warehouse_code), MatchingSafeInventorys(safe_inventorys, task_data.warehouse_code));
conn.Execute(" delete from dc_report_cash_flow_forecast_turnover where task_id=@task_id ", new { task_id = task_data.id });
if (turnover_list != null)
{
foreach (var item in turnover_list)
{
conn.Insert(new dc_report_cash_flow_forecast_turnover { date = item.date, type = item.type, val = item.val });
}
}
task_data.error_stack_trace = "模拟计算销量";
conn.Update(task_data);
// 模拟销量 // 模拟销量
logs.AddRange(turnover_list.Where(s => s.type == (int)invented_turnover_model.type_enum.销量).Select((s, index) => new dc_report_cash_flow_forecast_task_log() logs.AddRange(turnover_list.Where(s => s.type == (int)invented_turnover_model.type_enum.销量).Select((s, index) => new dc_report_cash_flow_forecast_task_log()
{ {
...@@ -88,8 +118,59 @@ namespace AutoTurnOver.DB ...@@ -88,8 +118,59 @@ namespace AutoTurnOver.DB
pay_time = report_cash_flow_dao.CalculationPayTime(configs, s.date, (int)dc_report_cash_flow_log_data_type_enum.销售数量, task_data.platform_type, task_data.web_site) pay_time = report_cash_flow_dao.CalculationPayTime(configs, s.date, (int)dc_report_cash_flow_log_data_type_enum.销售数量, task_data.platform_type, task_data.web_site)
})); }));
if (task_data.refund_ratio > 0)
{
// 模拟退款
logs.AddRange(turnover_list.Where(s => s.type == (int)invented_turnover_model.type_enum.销量).Select((s, index) => new dc_report_cash_flow_forecast_task_log()
{
warehouse_code = task_data.warehouse_code,
bailun_sku = task_data.bailun_sku,
data_type = (int)dc_report_cash_flow_log_data_type_enum.退款,
is_delete = 0,
item = "",
item_no = $"虚拟退款 - {task_data.id}-{s.date_str}-{index}",
no = $"虚拟退款 - {task_data.id}-{s.date_str}-{index}",
occur_time = s.date.AddDays(7),
pay_type = (int)dc_report_cash_flow_log_pay_type_enum.实时,
remarks = "模拟跑单 - 根据指定退款率,假定付款后7天退款",
task_id = task_data.id,
platform_type = task_data.platform_type,
val = 0 - (s.val * task_data.sale_unit_price_cny * task_data.refund_ratio),
update_time = now,
web_site = task_data.web_site,
pay_time_year_month_no = "",
occur_time_year_month_no = "",
pay_time = s.date.AddDays(7)
}));
}
// 模拟 释放销售成本
logs.AddRange(turnover_list.Where(s => s.type == (int)invented_turnover_model.type_enum.销量).Select((s, index) => new dc_report_cash_flow_forecast_task_log()
{
warehouse_code = task_data.warehouse_code,
bailun_sku = task_data.bailun_sku,
data_type = (int)dc_report_cash_flow_log_data_type_enum.释放销售成本,
is_delete = 0,
item = "",
item_no = $"虚拟销售单 - {task_data.id}-{s.date_str}-{index}",
no = $"虚拟销售单 - {task_data.id}-{s.date_str}-{index}",
occur_time = s.date,
pay_type = (int)dc_report_cash_flow_log_pay_type_enum.实时,
remarks = "模拟跑单",
task_id = task_data.id,
platform_type = task_data.platform_type,
val = s.val * task_data.buy_unit_price_cny,
update_time = now,
web_site = task_data.web_site,
pay_time_year_month_no = "",
occur_time_year_month_no = "",
pay_time = report_cash_flow_dao.CalculationPayTime(configs, s.date, (int)dc_report_cash_flow_log_data_type_enum.销售金额, task_data.platform_type, task_data.web_site)
}));
if (!"FBA仓".Equals(task_data.warehouse_type, StringComparison.OrdinalIgnoreCase)) if (!"FBA仓".Equals(task_data.warehouse_type, StringComparison.OrdinalIgnoreCase))
{ {
task_data.error_stack_trace = "模拟计算尾程费";
conn.Update(task_data);
var index = 0; var index = 0;
// 模拟尾程费 // 模拟尾程费
foreach (var s in turnover_list.Where(s => s.type == (int)invented_turnover_model.type_enum.销量)) foreach (var s in turnover_list.Where(s => s.type == (int)invented_turnover_model.type_enum.销量))
...@@ -108,7 +189,7 @@ namespace AutoTurnOver.DB ...@@ -108,7 +189,7 @@ namespace AutoTurnOver.DB
remarks = "模拟跑单", remarks = "模拟跑单",
task_id = task_data.id, task_id = task_data.id,
platform_type = task_data.platform_type, platform_type = task_data.platform_type,
val = s.val * ApiUtility.GetFilterLogisticsAssignLine(new Models.ApiDto.api_logistic_query_input_dto val = 0 -(s.val * ApiUtility.GetFilterLogisticsAssignLine(new Models.ApiDto.api_logistic_query_input_dto
{ {
endCountries = task_data.web_site, endCountries = task_data.web_site,
high = task_data.high, high = task_data.high,
...@@ -120,10 +201,10 @@ namespace AutoTurnOver.DB ...@@ -120,10 +201,10 @@ namespace AutoTurnOver.DB
warehouseNo = task_data.warehouse_code, warehouseNo = task_data.warehouse_code,
weightKg = task_data.weight_kg, weightKg = task_data.weight_kg,
width = task_data.width width = task_data.width
}).FootFee, }).TotalPrices),
update_time = now, update_time = now,
web_site = task_data.web_site, web_site = task_data.web_site,
pay_time_year_month_no ="", pay_time_year_month_no = "",
occur_time_year_month_no = "" occur_time_year_month_no = ""
}; };
string remarks = null; string remarks = null;
...@@ -135,6 +216,8 @@ namespace AutoTurnOver.DB ...@@ -135,6 +216,8 @@ namespace AutoTurnOver.DB
} }
task_data.error_stack_trace = "模拟采购";
conn.Update(task_data);
// 模拟下采购单 // 模拟下采购单
logs.AddRange(turnover_list.Where(s => s.type == (int)invented_turnover_model.type_enum.最终采购数量).Select((s, index) => new dc_report_cash_flow_forecast_task_log() logs.AddRange(turnover_list.Where(s => s.type == (int)invented_turnover_model.type_enum.最终采购数量).Select((s, index) => new dc_report_cash_flow_forecast_task_log()
{ {
...@@ -150,25 +233,28 @@ namespace AutoTurnOver.DB ...@@ -150,25 +233,28 @@ namespace AutoTurnOver.DB
remarks = "模拟跑单", remarks = "模拟跑单",
task_id = task_data.id, task_id = task_data.id,
platform_type = task_data.platform_type, platform_type = task_data.platform_type,
val = s.val * task_data.buy_unit_price_cny, val =0 -( s.val * task_data.buy_unit_price_cny),
update_time = now, update_time = now,
web_site = task_data.web_site, web_site = task_data.web_site,
pay_time_year_month_no = "", pay_time_year_month_no = "",
occur_time_year_month_no = "", occur_time_year_month_no = "",
pay_time = (task_data.buy_pay_type == 2 ? s.date.AddDays(task_data.buy_pay_days) : s.date) pay_time = (task_data.buy_pay_type == 2 ? s.date.AddDays(task_data.buy_pay_days + task_data.delivery) : s.date)
})); }));
if (!"国内仓".Equals(task_data.warehouse_type, StringComparison.OrdinalIgnoreCase)) if (!"国内仓".Equals(task_data.warehouse_type, StringComparison.OrdinalIgnoreCase))
{ {
task_data.error_stack_trace = "模拟下调拨单";
conn.Update(task_data);
var index = 0; var index = 0;
// 模拟程费 // 模拟程费
foreach (var s in turnover_list.Where(s => s.type == (int)invented_turnover_model.type_enum.调拨下单)) foreach (var s in turnover_list.Where(s => s.type == (int)invented_turnover_model.type_enum.调拨下单))
{ {
var temp_item = new dc_report_cash_flow_forecast_task_log() var temp_item = new dc_report_cash_flow_forecast_task_log()
{ {
warehouse_code = task_data.warehouse_code, warehouse_code = task_data.warehouse_code,
bailun_sku = task_data.bailun_sku, bailun_sku = task_data.bailun_sku,
data_type = (index==0? (int)dc_report_cash_flow_log_data_type_enum.新增头程费用_首单: (int)dc_report_cash_flow_log_data_type_enum.新增头程费用), data_type = (index == 0 ? (int)dc_report_cash_flow_log_data_type_enum.新增头程费用_首单 : (int)dc_report_cash_flow_log_data_type_enum.新增头程费用),
is_delete = 0, is_delete = 0,
item = "", item = "",
item_no = $"虚拟头程费用 - {task_data.id}-{s.date_str}-{index}", item_no = $"虚拟头程费用 - {task_data.id}-{s.date_str}-{index}",
...@@ -178,19 +264,19 @@ namespace AutoTurnOver.DB ...@@ -178,19 +264,19 @@ namespace AutoTurnOver.DB
remarks = "模拟跑单", remarks = "模拟跑单",
task_id = task_data.id, task_id = task_data.id,
platform_type = task_data.platform_type, platform_type = task_data.platform_type,
val = s.val * ApiUtility.GetFilterLogisticsAssignLine(new Models.ApiDto.api_logistic_query_input_dto val = 0 - ( ApiUtility.GetFilterLogisticsAssignLine(new Models.ApiDto.api_logistic_query_input_dto
{ {
endCountries = task_data.web_site, endCountries = task_data.web_site,
high = task_data.high, high = task_data.high,
LineCodes = task_data.tail_logistics_code, LineCodes = task_data.transfer_logistics_code,
Long = task_data.@long, Long = task_data.@long,
platform = task_data.platform_type, platform = task_data.platform_type,
Site = task_data.web_site, Site = task_data.web_site,
startPoint = "3", startPoint = "3",
warehouseNo = task_data.warehouse_code, warehouseNo = task_data.warehouse_code,
weightKg = task_data.weight_kg, weightKg = task_data.weight_kg * s.val,
width = task_data.width width = task_data.width
}).FootFee, }).TotalPrices),
update_time = now, update_time = now,
web_site = task_data.web_site, web_site = task_data.web_site,
pay_time_year_month_no = "", pay_time_year_month_no = "",
...@@ -204,17 +290,24 @@ namespace AutoTurnOver.DB ...@@ -204,17 +290,24 @@ namespace AutoTurnOver.DB
} }
} }
if(logs!=null && logs.Count >= 1) if (logs != null && logs.Count >= 1)
{ {
foreach (var item in logs) foreach (var item in logs)
{ {
conn.Insert(item); conn.Insert(item);
} }
} }
task_data.error_stack_trace = "计算完成";
task_data.status = 2;
task_data.error_message = "";
task_data.error_stack_trace = "";
conn.Update(task_data);
} }
catch (Exception ex) catch (Exception ex)
{ {
task_data.status = 3; task_data.status = 3;
task_data.step = "";
task_data.error_message = ex.Message; task_data.error_message = ex.Message;
task_data.error_stack_trace = ex.StackTrace; task_data.error_stack_trace = ex.StackTrace;
conn.Update(task_data); conn.Update(task_data);
...@@ -339,5 +432,261 @@ namespace AutoTurnOver.DB ...@@ -339,5 +432,261 @@ namespace AutoTurnOver.DB
param = 1 param = 1
}); });
} }
#region 配置页面
public static List<dc_report_cash_flow_forecast_task_dto> Page(dc_report_cash_flow_forecast_task_search_dto m, int offset, int limit, ref int total)
{
var list = new List<dc_report_cash_flow_forecast_task_dto>();
try
{
var sql = @"select t1.* from dc_report_cash_flow_forecast_task as t1 where 1 = 1 ";
if (!string.IsNullOrWhiteSpace(m.bailun_sku))
{
sql += " and t1.bailun_sku=" + $"'{m.bailun_sku}'";
}
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1");
var obj = _connection.Query<dc_report_cash_flow_forecast_task_dto>(sql + " limit " + offset + "," + limit);
return obj.AsList();
}
catch (Exception)
{
return list;
}
}
public static void Save(dc_report_cash_flow_forecast_task_input_dto input_data)
{
var m = input_data.ToJson().ToObj<dc_report_cash_flow_forecast_task>();
using (var conn = _connection)
{
conn.Open();
using (var t = conn.BeginTransaction())
{
m.update_time = DateTime.Now;
if (string.IsNullOrWhiteSpace(m.warehouse_code))
{
throw new Exception("请选择仓库");
}
if (m.refund_ratio > 1)
{
throw new Exception("退款率不可大于1");
}
var warehouse_data = _connection.QuerySingleOrDefault<dc_base_warehouse>(" select * from dc_base_warehouse where warehouse_code=@warehouse_code limit 1 ", new { warehouse_code = m.warehouse_code });
if (warehouse_data == null)
{
throw new Exception(" 数据异常 , 仓库不存在 ");
}
m.warehouse_type = warehouse_data.hq_type;
var logisticsList = ApiUtility.RealTimeShipLogisticsList();
if ((!"国内仓".Equals(warehouse_data.hq_type, StringComparison.OrdinalIgnoreCase)))
{
if (string.IsNullOrWhiteSpace(m.transfer_logistics_code))
{
throw new Exception("请选择物头程物流商");
}
else
{
var logisticsData = logisticsList.SingleOrDefault(s => m.transfer_logistics_code.Equals(s.Line_Code));
if (logisticsData == null)
{
throw new Exception("系统异常 供应商不存在");
}
m.transfer_logistics_name = logisticsData.Line_Name;
}
if (m.transfer_days <= 0)
{
throw new Exception("调拨交期必填");
}
}
else
{
m.transfer_logistics_code = "";
m.transfer_logistics_name = "";
}
if ((!"FBA仓".Equals(warehouse_data.hq_type, StringComparison.OrdinalIgnoreCase)))
{
if (string.IsNullOrWhiteSpace(m.tail_logistics_code))
{
throw new Exception("请选择物尾程物流商");
}
else
{
var logisticsData = logisticsList.SingleOrDefault(s => m.tail_logistics_code.Equals(s.Line_Code));
if (logisticsData == null)
{
throw new Exception("系统异常 供应商不存在");
}
m.tail_logistics_name = logisticsData.Line_Name;
}
}
else
{
m.tail_logistics_name = "";
m.tail_logistics_code = "";
}
m.status = 0;
m.step = "待计算";
m.error_message = "";
m.error_stack_trace = "";
var id = 0;
if (m.id > 0)
{
id = m.id;
var result = conn.Update<dc_report_cash_flow_forecast_task>(m,t);
conn.Execute(" delete from dc_report_cash_flow_forecast_task_sale where task_id=@task_id ", new { task_id = id });
}
else
{
id = conn.Insert<dc_report_cash_flow_forecast_task>(m,t)??0;
}
if (input_data.sales != null)
{
foreach (var item in input_data.sales)
{
conn.Insert(new dc_report_cash_flow_forecast_task_sale {
date =item.date,
task_id = id,
val = item.val
});
}
}
t.Commit();
}
}
}
public static dc_report_cash_flow_forecast_task_input_dto GetById(int id)
{
var data= _connection.QueryFirstOrDefault<dc_report_cash_flow_forecast_task_input_dto>("select * from dc_report_cash_flow_forecast_task where id=" + id);
data.sales = _connection.Query<dc_report_cash_flow_forecast_task_input_dto.sale_dto>(" select `date`,`val` from dc_report_cash_flow_forecast_task_sale where task_id=@task_id ",new { task_id = id }).ToList();
if (data.sales != null && data.sales.Count>=1)
{
data.btime = data.sales.Min(s => s.date).ToString("yyyy-MM-dd");
data.etime = data.sales.Max(s => s.date).ToString("yyyy-MM-dd");
}
return data;
}
#endregion
public static dc_report_cash_flow_forecast_task_info_dto GetInfo(report_cash_flow_view_forecast_task_search_dto search)
{
var info_data = new dc_report_cash_flow_forecast_task_info_dto() { views = new List<report_cash_flow_view_dto>() { },turnovers = new List<dc_report_cash_flow_forecast_task_info_dto.turnover_dto> { } };
info_data.views.Add(new report_cash_flow_view_dto { date_type = new List<int> { 1 }, date_type_str = "销售数量", remarks = "", dates = new List<report_cash_flow_view_dto.date_dto>() });
info_data.views.Add(new report_cash_flow_view_dto { date_type = new List<int> { 2 }, date_type_str = "销售金额", remarks = "过滤掉刷单的订单 ", dates = new List<report_cash_flow_view_dto.date_dto>() });
info_data.views.Add(new report_cash_flow_view_dto { date_type = new List<int> { 3 }, date_type_str = "退款", remarks = "crm 抓取的退款数据,未区分仓库", dates = new List<report_cash_flow_view_dto.date_dto>() });
info_data.views.Add(new report_cash_flow_view_dto { date_type = new List<int> { 4 }, date_type_str = "利润", remarks = "oms 中的订单,分摊到sku的利润,不包含广告费,上架费,退款", dates = new List<report_cash_flow_view_dto.date_dto>() });
info_data.views.Add(new report_cash_flow_view_dto { date_type = new List<int> { 6 }, date_type_str = "释放销售成本", remarks = "采购成本,利润中已经计算了", dates = new List<report_cash_flow_view_dto.date_dto>() });
//info_data.views.Add(new report_cash_flow_view_dto { date_type = new List<int> { 7 }, date_type_str = "释放头程费用", remarks = "", dates = new List<report_cash_flow_view_dto.date_dto>() });
info_data.views.Add(new report_cash_flow_view_dto { date_type = new List<int> { 8 }, date_type_str = "尾程费用", remarks = "oms 订单中海外仓发货的,支付时间 已 读取对应物流商的账期", dates = new List<report_cash_flow_view_dto.date_dto>() });
info_data.views.Add(new report_cash_flow_view_dto { date_type = new List<int> { 9 }, date_type_str = "新增采购费用", remarks = " 1、采购系统的数据,外采订单直接读取订单支付时间。2、向自己工厂采购的(无需付款)的单,支付时间=下单时间 ", dates = new List<report_cash_flow_view_dto.date_dto>() });
info_data.views.Add(new report_cash_flow_view_dto { date_type = new List<int> { 13 }, date_type_str = "新增采购费用_首单", remarks = " 采购首单费用,下单一个月之后如果有出单,讲转移到【新增采购费用】字段", dates = new List<report_cash_flow_view_dto.date_dto>() });
info_data.views.Add(new report_cash_flow_view_dto { date_type = new List<int> { 10 }, date_type_str = "新增头程费用", remarks = " 调拨单的数据,支付时间 已 读取对应物流商的账期,注:调拨单需要付款之后才能获取到金额 ", dates = new List<report_cash_flow_view_dto.date_dto>() });
info_data.views.Add(new report_cash_flow_view_dto { date_type = new List<int> { 14 }, date_type_str = "新增头程费用_首单", remarks = " 调拨首单费用,下单一个月之后如果有出单,讲转移到【新增头程费用】字段 ", dates = new List<report_cash_flow_view_dto.date_dto>() });
info_data.views.Add(new report_cash_flow_view_dto { date_type = new List<int> { 4, 3 }, date_type_str = "汇总利润", remarks = " oms 中的订单,销售额 - 销售成本 - 尾程费 - 头程费 - 退款 (", dates = new List<report_cash_flow_view_dto.date_dto>() });
info_data.views.Add(new report_cash_flow_view_dto { date_type = new List<int> { 2, 3, 5, 8, 9, 10, 11, 12, 13, 14 }, date_type_str = "现金流结余", remarks = " 销售金额 - 新增采购费用 - 新增头程费用 - 平台费用 - 尾程费用 ", dates = new List<report_cash_flow_view_dto.date_dto>() });
info_data.turnovers.Add(new dc_report_cash_flow_forecast_task_info_dto.turnover_dto { types = new List<int> {(int)invented_turnover_model.type_enum.销量 }, item_title = "销量",dates = new List<dc_report_cash_flow_forecast_task_info_dto.turnover_dto.date_dto> { } });
info_data.turnovers.Add(new dc_report_cash_flow_forecast_task_info_dto.turnover_dto { types = new List<int> { (int)invented_turnover_model.type_enum.入库数量 }, item_title = "入库",dates = new List<dc_report_cash_flow_forecast_task_info_dto.turnover_dto.date_dto> { } });
info_data.turnovers.Add(new dc_report_cash_flow_forecast_task_info_dto.turnover_dto { types = new List<int> { (int)invented_turnover_model.type_enum.可用库存 }, item_title = "可用库存",dates = new List<dc_report_cash_flow_forecast_task_info_dto.turnover_dto.date_dto> { } });
info_data.turnovers.Add(new dc_report_cash_flow_forecast_task_info_dto.turnover_dto { types = new List<int> { (int)invented_turnover_model.type_enum.采购数量 }, item_title = "采购数量",dates = new List<dc_report_cash_flow_forecast_task_info_dto.turnover_dto.date_dto> { } });
var conn = _connection;
var occur_sql = " select occur_time as 'date',sum(val) as 'val',data_type,1 as 'type',platform_type,web_site from dc_report_cash_flow_forecast_task_log where task_id=@task_id ";
var pay_sql = " select pay_time as 'date',sum(val) as 'val',data_type,1 as 'type',platform_type,web_site from dc_report_cash_flow_forecast_task_log where task_id=@task_id ";
var turnover_sql = " select * from dc_report_cash_flow_forecast_turnover where task_id=@task_id ";
DynamicParameters parameters = new DynamicParameters();
parameters.Add("task_id",search.task_id);
occur_sql += " GROUP BY data_type,year(occur_time),month(occur_time),day(occur_time) ";
pay_sql += " GROUP BY data_type,year(pay_time),month(pay_time),day(pay_time) ";
var occur_datas = conn.Query<dc_report_cash_flow_group_day>(occur_sql, parameters, commandTimeout: 0).ToList();
var pay_datas = conn.Query<dc_report_cash_flow_group_day>(pay_sql, parameters, commandTimeout: 0).ToList();
var turnover_datas = conn.Query<dc_report_cash_flow_forecast_turnover>(turnover_sql, parameters, commandTimeout: 0).ToList();
var min_o_time = occur_datas.Min(s=>s.date);
var min_p_time = pay_datas.Min(s => s.date);
var max_o_time = occur_datas.Max(s=>s.date);
var max_p_time = pay_datas.Max(s => s.date);
var btime = min_o_time< min_p_time? min_o_time: min_p_time;
var etime = max_o_time > max_p_time ? max_o_time : max_p_time;
foreach (var itemData in info_data.views)
{
itemData.dates.Add(new report_cash_flow_view_dto.date_dto
{
btime = btime,
etime = etime,
date_title = $"汇总",
occur_val = occur_datas.Where(s => itemData.date_type.Contains(s.data_type)).Sum(s => s.val),
pay_val = pay_datas.Where(s => itemData.date_type.Contains(s.data_type)).Sum(s => s.val)
});
}
var thisTime = btime;
while (thisTime <= etime)
{
var bThisTime = thisTime.ToDayHome();
var eThisTime = thisTime.ToDayEnd();
foreach (var itemData in info_data.views)
{
itemData.dates.Add(new report_cash_flow_view_dto.date_dto
{
btime = bThisTime,
etime = eThisTime,
date_title = $"{bThisTime.Month}-{bThisTime.Day}",
occur_val = occur_datas.Where(s => s.date >= bThisTime && s.date <= eThisTime && itemData.date_type.Contains(s.data_type)).Sum(s => s.val),
pay_val = pay_datas.Where(s => s.date >= bThisTime && s.date <= eThisTime && itemData.date_type.Contains(s.data_type)).Sum(s => s.val)
});
}
foreach (var itemData in info_data.turnovers)
{
itemData.dates.Add(new dc_report_cash_flow_forecast_task_info_dto.turnover_dto.date_dto
{
btime = bThisTime,
etime = eThisTime,
date_title = $"{bThisTime.Month}-{bThisTime.Day}",
val = turnover_datas.Where(s => s.date >= bThisTime && s.date <= eThisTime && itemData.types.Contains(s.type)).Sum(s => s.val),
});
}
thisTime = thisTime.AddDays(1);
}
return info_data;
}
public static dc_report_cash_flow_forecast_task_date_dto GetDate(int id)
{
var data1 = _connection.QueryFirstOrDefault<DateTime?>(" select min(occur_time) from dc_report_cash_flow_forecast_task_log where task_id=@task_id ", new { task_id=id});
var data2= _connection.QueryFirstOrDefault<DateTime?>(" select min(pay_time) from dc_report_cash_flow_forecast_task_log where task_id=@task_id ", new { task_id=id});
var data3 = _connection.QueryFirstOrDefault<DateTime?>(" select max(occur_time) from dc_report_cash_flow_forecast_task_log where task_id=@task_id ", new { task_id=id});
var data4 = _connection.QueryFirstOrDefault<DateTime?>(" select max(pay_time) from dc_report_cash_flow_forecast_task_log where task_id=@task_id ", new { task_id=id});
return new dc_report_cash_flow_forecast_task_date_dto {
btime =( (data1 < data2 ? data1 : data2) ?? DateTime.Now.AddDays(-7)).ToString("yyyy-MM-dd"),
etime = ((data3 > data4 ? data3 : data4) ?? DateTime.Now.AddDays(7)).ToString("yyyy-MM-dd")
};
}
} }
} }
...@@ -13,6 +13,11 @@ namespace AutoTurnOver.Models.ApiDto ...@@ -13,6 +13,11 @@ namespace AutoTurnOver.Models.ApiDto
public string Line_Name { get; set; } public string Line_Name { get; set; }
public string Company_Code { get; set; } public string Company_Code { get; set; }
public string Company_Name { get; set; } public string Company_Name { get; set; }
/// <summary>
/// 1-直邮 2-海外 3-头程
/// </summary>
public string Start_Point { get; set; }
} }
public class LmsResultDto<T> public class LmsResultDto<T>
......
...@@ -131,15 +131,20 @@ namespace AutoTurnOver.Models.ApiDto ...@@ -131,15 +131,20 @@ namespace AutoTurnOver.Models.ApiDto
{ {
public bool Success { get; set; } public bool Success { get; set; }
public string ErrorMessage { get; set; } public string ErrorMessage { get; set; }
public string Data { get; set; } public data_dto Data { get; set; }
public class data_dto
{
public List<line_dto> successLines { get; set; } public List<line_dto> successLines { get; set; }
public List<line_dto> failLines { get; set; }
}
public class line_dto public class line_dto
{ {
public string Line_Code { get; set; } public string Line_Code { get; set; }
public string LineName { get; set; } public string LineName { get; set; }
public decimal FootFee { get; set; } public decimal TotalPrices { get; set; }
public decimal HeadFee { get; set; } public decimal HeadFee { get; set; }
public string ErrorMsg { get; set; } public string ErrorMsg { get; set; }
......
using System; using AutoTurnOver.Models.Base;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
...@@ -39,12 +40,14 @@ namespace AutoTurnOver.Models.Report ...@@ -39,12 +40,14 @@ namespace AutoTurnOver.Models.Report
/// 头程物流 /// 头程物流
/// </summary> /// </summary>
public string transfer_logistics_code { get; set; } public string transfer_logistics_code { get; set; }
public string transfer_logistics_name { get; set; }
/// <summary> /// <summary>
/// 尾程物流 /// 尾程物流
/// </summary> /// </summary>
public string tail_logistics_code { get; set; } public string tail_logistics_code { get; set; }
public string tail_logistics_name { get; set; }
/// <summary> /// <summary>
/// 尾程物流 /// 退款率
/// </summary> /// </summary>
public decimal refund_ratio { get; set; } public decimal refund_ratio { get; set; }
/// <summary> /// <summary>
...@@ -74,8 +77,80 @@ namespace AutoTurnOver.Models.Report ...@@ -74,8 +77,80 @@ namespace AutoTurnOver.Models.Report
public decimal @long { get; set; } public decimal @long { get; set; }
public decimal weight_kg { get; set; } public decimal weight_kg { get; set; }
public decimal width { get; set; } public decimal width { get; set; }
public DateTime update_time { get; set; }
}
public class dc_report_cash_flow_forecast_task_info_dto
{
public List<report_cash_flow_view_dto> views { get; set; }
public List<turnover_dto> turnovers { get; set; }
public class turnover_dto
{
public string item_title { get; set; }
public List<int> types { get; set; }
public List<date_dto> dates { get; set; }
public class date_dto
{
public string date_title { get; set; }
public DateTime btime { get; set; }
public DateTime etime { get; set; }
public decimal val { get; set; }
}
}
}
public class report_cash_flow_view_forecast_task_search_dto
{
public int task_id { get; set; }
}
public class dc_report_cash_flow_forecast_task_dto: dc_report_cash_flow_forecast_task
{
public string warehouse_name { get; set; }
public string status_str { get
{
return ((dc_report_cash_flow_forecast_task_status)status).ToString();
} }
}
public class dc_report_cash_flow_forecast_task_date_dto
{
public string btime { get; set; }
public string etime { get; set; }
}
public class dc_report_cash_flow_forecast_task_input_dto: dc_report_cash_flow_forecast_task_dto
{
public string btime { get; set; }
public string etime { get; set; }
public List<sale_dto> sales { get; set; }
public class sale_dto
{
public DateTime date { get; set; }
public decimal val { get; set; }
}
}
public enum dc_report_cash_flow_forecast_task_status
{
已提交=0,
计算中=1,
计算完成=2,
计算异常=3
}
public class dc_report_cash_flow_forecast_task_search_dto
{
public string bailun_sku { get; set; }
} }
public class dc_report_cash_flow_forecast_task_sale public class dc_report_cash_flow_forecast_task_sale
...@@ -145,11 +220,25 @@ namespace AutoTurnOver.Models.Report ...@@ -145,11 +220,25 @@ namespace AutoTurnOver.Models.Report
public string occur_time_year_month_no { get; set; } public string occur_time_year_month_no { get; set; }
} }
public class dc_report_cash_flow_forecast_turnover
{
public int id { get; set; }
public DateTime date { get; set; }
/// <summary>
/// 预测数值
/// </summary>
public decimal val { get; set; }
public int type { get; set; }
}
/// <summary> /// <summary>
/// 虚拟周转模型,用来虚拟下单 /// 虚拟周转模型,用来虚拟下单
/// </summary> /// </summary>
public class invented_turnover_model public class invented_turnover_model
{ {
public int id { get; set; }
public int task_id { get; set; }
public DateTime date { get; set; } public DateTime date { get; set; }
public string date_str { get { return date.ToString("yyyy-MM-dd"); } } public string date_str { get { return date.ToString("yyyy-MM-dd"); } }
......
...@@ -16,6 +16,27 @@ namespace AutoTurnOver.Purchase.AverageTarget ...@@ -16,6 +16,27 @@ namespace AutoTurnOver.Purchase.AverageTarget
protected override Task ExecuteAsync(CancellationToken stoppingToken) protected override Task ExecuteAsync(CancellationToken stoppingToken)
{ {
_timer = new Timer(DoWork, null, TimeSpan.Zero, TimeSpan.FromMinutes(1)); _timer = new Timer(DoWork, null, TimeSpan.Zero, TimeSpan.FromMinutes(1));
Task.Factory.StartNew(() =>
{
while (true)
{
try
{
Console.WriteLine($"开始 计算预测现金流,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
report_cash_flow_forecast_dao.Calculation();
Console.WriteLine($"结束 计算预测现金流,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Thread.Sleep(10 * 1000);
}
});
return Task.CompletedTask; return Task.CompletedTask;
} }
......
...@@ -23,7 +23,7 @@ namespace AutoTurnOver.Purchase.AverageTarget ...@@ -23,7 +23,7 @@ namespace AutoTurnOver.Purchase.AverageTarget
Console.WriteLine("采购平均值计算任务启动..."); Console.WriteLine("采购平均值计算任务启动...");
// 创建采购计划 // 创建采购计划
//Console.WriteLine($"开始同步sku刊登状态,线程Id:{Thread.CurrentThread.ManagedThreadId},{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); //Console.WriteLine($"开始同步sku刊登状态,线程Id:{Thread.CurrentThread.ManagedThreadId},{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
daily.SynchroPPSSkuStatus();
//Console.WriteLine($"结束同步sku刊登状态,线程Id:{Thread.CurrentThread.ManagedThreadId},{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); //Console.WriteLine($"结束同步sku刊登状态,线程Id:{Thread.CurrentThread.ManagedThreadId},{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
var builder = new HostBuilder().ConfigureServices((hostContext, services) => var builder = new HostBuilder().ConfigureServices((hostContext, services) =>
......
...@@ -3,5 +3,6 @@ ...@@ -3,5 +3,6 @@
"Default": "server=gz-cdb-kp7s5i79.sql.tencentcdb.com;port=61691;database=bailun_datacenter;uid=root;password=#7kfnymAM$Y9-Ntf;" "Default": "server=gz-cdb-kp7s5i79.sql.tencentcdb.com;port=61691;database=bailun_datacenter;uid=root;password=#7kfnymAM$Y9-Ntf;"
}, },
"PPSSkuStatus": "http://pps.bailuntec.com/Api/Centre/Publish/External/SkuStatus", "PPSSkuStatus": "http://pps.bailuntec.com/Api/Centre/Publish/External/SkuStatus",
"ApiLogisticsGetFilterLogisticsAssignLine": "http://lms.bailuntec.com/api/Logistics/ApiLogistics/GetFilterLogisticsAssignLine" "ApiLogisticsGetFilterLogisticsAssignLine": "http://lms.bailuntec.com/api/Logistics/ApiLogistics/GetFilterLogisticsAssignLine",
"Lms_GetLogistics": "http://lms.bailuntec.com/api/DataInfo/ApiLogistics/GetLogistics"
} }
...@@ -3,5 +3,6 @@ ...@@ -3,5 +3,6 @@
"Default": "server=10.0.8.15;port=3306;database=bailun_datacenter;uid=root;password=#7kfnymAM$Y9-Ntf;" "Default": "server=10.0.8.15;port=3306;database=bailun_datacenter;uid=root;password=#7kfnymAM$Y9-Ntf;"
}, },
"PPSSkuStatus": "http://pps.bailuntec.com/Api/Centre/Publish/External/SkuStatus", "PPSSkuStatus": "http://pps.bailuntec.com/Api/Centre/Publish/External/SkuStatus",
"ApiLogisticsGetFilterLogisticsAssignLine": "http://lms.bailuntec.com/api/Logistics/ApiLogistics/GetFilterLogisticsAssignLine" "ApiLogisticsGetFilterLogisticsAssignLine": "http://lms.bailuntec.com/api/Logistics/ApiLogistics/GetFilterLogisticsAssignLine",
"Lms_GetLogistics": "http://lms.bailuntec.com/api/DataInfo/ApiLogistics/GetLogistics"
} }
...@@ -3,5 +3,6 @@ ...@@ -3,5 +3,6 @@
"Default": "server=10.0.8.15;port=3306;database=bailun_datacenter;uid=root;password=#7kfnymAM$Y9-Ntf;" "Default": "server=10.0.8.15;port=3306;database=bailun_datacenter;uid=root;password=#7kfnymAM$Y9-Ntf;"
}, },
"PPSSkuStatus": "http://pps.bailuntec.com/Api/Centre/Publish/External/SkuStatus", "PPSSkuStatus": "http://pps.bailuntec.com/Api/Centre/Publish/External/SkuStatus",
"ApiLogisticsGetFilterLogisticsAssignLine": "http://lms.bailuntec.com/api/Logistics/ApiLogistics/GetFilterLogisticsAssignLine" "ApiLogisticsGetFilterLogisticsAssignLine": "http://lms.bailuntec.com/api/Logistics/ApiLogistics/GetFilterLogisticsAssignLine",
"Lms_GetLogistics": "http://lms.bailuntec.com/api/DataInfo/ApiLogistics/GetLogistics"
} }
\ No newline at end of file
using AutoTurnOver.Models;
using AutoTurnOver.Models.Report;
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Text;
namespace AutoTurnOver.Services
{
public class ForecastTaskServices
{
#region 配置页面
public List<dc_report_cash_flow_forecast_task_dto> Page(dc_report_cash_flow_forecast_task_search_dto m, int offset, int limit, ref int total)
{
return DB.report_cash_flow_forecast_dao.Page(m, offset, limit, ref total);
}
public void Save(dc_report_cash_flow_forecast_task_input_dto m)
{
DB.report_cash_flow_forecast_dao.Save(m);
}
public dc_report_cash_flow_forecast_task GetById(int id)
{
return DB.report_cash_flow_forecast_dao.GetById(id);
}
#endregion
public List<dynamic> GetInfo(report_cash_flow_view_forecast_task_search_dto search)
{
var order_list = DB.report_cash_flow_forecast_dao.GetInfo(search).views;
List<dynamic> datas = new List<dynamic>();
foreach (var item in order_list)
{
dynamic o = new ExpandoObject();
o.date_type = string.Join(",", item.date_type);
o.date_type_str = item.date_type_str;
o.remarks = item.remarks;
foreach (var dat_item in item.dates)
{
var dic = (IDictionary<string, object>)o;
dic["occur_" + (dat_item.date_title)] = new { val = Math.Round(dat_item.occur_val, 2), btime = dat_item.btime, etime = dat_item.etime, data_type = item.date_type };
if (
item.date_type.Contains((int)dc_report_cash_flow_log_data_type_enum.销售数量)
//|| item.date_type==(int)dc_report_cash_flow_log_data_type_enum.利润
//|| item.date_type == (int)dc_report_cash_flow_log_data_type_enum.退款
//|| item.date_type == (int)dc_report_cash_flow_log_data_type_enum.平台费用
//|| item.date_type == (int)dc_report_cash_flow_log_data_type_enum.释放销售成本
//|| item.date_type == (int)dc_report_cash_flow_log_data_type_enum.释放头程费用
)
{
}
else
{
dic["pay_" + (dat_item.date_title)] = new { val = Math.Round(dat_item.pay_val, 2), btime = dat_item.btime, etime = dat_item.etime, data_type = item.date_type };
}
}
datas.Add(o);
}
return datas;
} public dc_report_cash_flow_forecast_task_date_dto GetDate(int id)
{
return DB.report_cash_flow_forecast_dao.GetDate(id);
}
}
}
...@@ -31,7 +31,7 @@ namespace AutoTurnOver.Controllers ...@@ -31,7 +31,7 @@ namespace AutoTurnOver.Controllers
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
public JsonResult ListWareHouse(string type,int? areaId) public JsonResult ListWareHouse(string type, int? areaId)
{ {
...@@ -137,7 +137,8 @@ namespace AutoTurnOver.Controllers ...@@ -137,7 +137,8 @@ namespace AutoTurnOver.Controllers
return new JsonResult(list.Select(p => new return new JsonResult(list.Select(p => new
{ {
id = p.Line_Code, id = p.Line_Code,
text = p.Line_Code + " - " + p.Line_Name text = p.Line_Code + " - " + p.Line_Name,
type = p.Start_Point
})); }));
} }
catch (Exception ex) catch (Exception ex)
...@@ -200,7 +201,8 @@ namespace AutoTurnOver.Controllers ...@@ -200,7 +201,8 @@ namespace AutoTurnOver.Controllers
{ {
try try
{ {
var datas = ApiServices.GetCategoryAll().Select(s=> new { var datas = ApiServices.GetCategoryAll().Select(s => new
{
id = s.C_ID, id = s.C_ID,
pId = s.C_PARENTID, pId = s.C_PARENTID,
name = s.C_CNAME, name = s.C_CNAME,
...@@ -227,7 +229,8 @@ namespace AutoTurnOver.Controllers ...@@ -227,7 +229,8 @@ namespace AutoTurnOver.Controllers
{ {
try try
{ {
var datas = ApiServices.GetNewCategoryAll().Select(s => new { var datas = ApiServices.GetNewCategoryAll().Select(s => new
{
id = s.id, id = s.id,
pId = s.parentId, pId = s.parentId,
name = s.name, name = s.name,
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoTurnOver.Models.Report;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace AutoTurnOver.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ForecastTaskController : ControllerBase
{
#region 配置页面
[HttpGet]
public JsonResult Page(int limit, int offset, string order, string sort, string bailun_sku)
{
var m = new dc_report_cash_flow_forecast_task_search_dto
{
bailun_sku = bailun_sku
};
var total = 0;
var service = new Services.ForecastTaskServices();
var list = service.Page(m, offset, limit, ref total);
return new JsonResult(new
{
rows = list,
total = total,
});
}
[HttpPost]
public JsonResult Save([FromBody]dc_report_cash_flow_forecast_task_input_dto m)
{
try
{
new Services.ForecastTaskServices().Save(m);
return new JsonResult(new
{
success =true
});
}
catch (Exception ex)
{
return new JsonResult(new
{
success = false,
message =ex.Message,
stack_trace = ex.StackTrace
});
}
}
[HttpGet]
public JsonResult GetById(int id)
{
var m = new Services.ForecastTaskServices().GetById(id);
return new JsonResult(m);
}
#endregion
[HttpGet]
public JsonResult GetInfo(int id)
{
var list = new Services.ForecastTaskServices().GetInfo(new report_cash_flow_view_forecast_task_search_dto {task_id = id });
return new JsonResult(new
{
rows = list,
total = 0,
});
}
[HttpGet]
public JsonResult GetDate(int id)
{
var m = new Services.ForecastTaskServices().GetDate(id);
return new JsonResult(m);
}
}
}
\ No newline at end of file
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