Commit 4327f6bb by lizefeng

新增采购指标计算(独立 netCore 服务)

parent e7ccc377
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework> <TargetFramework>netcoreapp2.1</TargetFramework>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Dapper" Version="1.50.5" /> <PackageReference Include="Dapper" Version="1.50.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.4" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.4" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
<PackageReference Include="MySql.Data" Version="8.0.13" /> <PackageReference Include="MySql.Data" Version="8.0.13" />
<PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.13" /> <PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.13" />
</ItemGroup> </ItemGroup>
...@@ -15,4 +18,5 @@ ...@@ -15,4 +18,5 @@
<ProjectReference Include="..\AutoTurnOver.Models\AutoTurnOver.Models.csproj" /> <ProjectReference Include="..\AutoTurnOver.Models\AutoTurnOver.Models.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>
using System;
using System.Collections.Generic;
using System.Text;
using AutoTurnOver.Models.dc_base_purchase;
using Dapper;
using System.Linq;
using AutoTurnOver.Models;
using MySql.Data.MySqlClient;
namespace AutoTurnOver.DB
{
public class AveragePurchase : connectionHelper
{
/// <summary>
/// 取最近2天有发生采购记录的SKU
/// 采购记录
/// 到货记录
/// 入库记录
/// </summary>
/// <param name="day">最近几天</param>
/// <returns></returns>
public static IEnumerable<temp_sku_dto> GetChangeSku(int day)
{
DynamicParameters parameters = new DynamicParameters();
parameters.Add("time", DateTime.Now.AddDays(0 - day).ToString("yyyy-MM-dd 00:00:00"));
return _connection.Query<temp_sku_dto>("select t1.bailun_sku,t1.warehouse_code,t1.supplier_id from dc_base_purchase as t1 where t1.update_time>=@time group by t1.bailun_sku,t1.warehouse_code,t1.supplier_id ", parameters);
}
public static dc_average_purchase GetModel(string sku, string warehousecode)
{
DynamicParameters parameters = new DynamicParameters();
parameters.Add("bailun_sku", sku);
parameters.Add("warehouse_code", warehousecode);
return _connection.QueryFirstOrDefault<dc_average_purchase>("select * from dc_average_purchase where warehouse_code=@warehouse_code and bailun_sku=@bailun_sku ", parameters);
}
/// <summary>
/// 获取SKU 的最近5条采购完成的采购单
/// </summary>
/// <param name="skuData">sku 信息</param>
/// <param name="seed_count">取数天数</param>
/// <returns></returns>
public static IEnumerable<dc_base_purchase_dto> GetPurchaseList(temp_sku_dto skuData, int seed_count)
{
DynamicParameters parameters = new DynamicParameters();
parameters.Add("bailun_sku", skuData.bailun_sku);
parameters.Add("warehouse_code", skuData.warehouse_code);
parameters.Add("supplier_id", skuData.supplier_id);
parameters.Add("seed_count", seed_count);
return _connection.Query<dc_base_purchase_dto>(@"select t1.price,t1.bailun_sku,t1.warehouse_code,t1.purchase_id,t1.warehouse_name,t1.count,t1.sku_name,t1.supplier_id,t1.supplier_name,t1.confirm_time,t1.pay_time,t1.pay_type from dc_base_purchase as t1
where t1.buy_status=4 and t1.bailun_sku=@bailun_sku and t1.warehouse_code=@warehouse_code and t1.supplier_id=@supplier_id
ORDER BY t1.update_time desc LIMIT @seed_count
", parameters);
}
/// <summary>
/// 获取指定采购单的到货数据
/// </summary>
/// <param name="skuData">sku 信息</param>
/// <param name="purchase_ids">采购单号</param>
/// <returns></returns>
public static IEnumerable<dc_base_purchase_arrival_dto> GetArrivalList(IEnumerable<string> purchase_ids)
{
DynamicParameters parameters = new DynamicParameters();
parameters.Add("purchase_ids", purchase_ids.ToArray());
return _connection.Query<dc_base_purchase_arrival_dto>(@"select * from dc_base_purchase_arrival where purchase_id in @purchase_ids
", parameters);
}
/// <summary>
/// 获取指定采购单的入库数据
/// </summary>
/// <param name="skuData">sku 信息</param>
/// <param name="purchase_ids">采购单号</param>
/// <returns></returns>
public static IEnumerable<dc_base_purchase_inbound_dto> GetInboundList(IEnumerable<string> purchase_ids)
{
DynamicParameters parameters = new DynamicParameters();
parameters.Add("purchase_ids", purchase_ids.ToArray());
return _connection.Query<dc_base_purchase_inbound_dto>(@"select * from dc_base_purchase_inbound where purchase_id in @purchase_ids
", parameters);
}
/// <summary>
/// 保存数据
/// </summary>
/// <param name="data"></param>
public static void Save(dc_average_purchase data, MySqlConnection conn)
{
if (conn == null)
{
conn = _connection;
}
data.update_time = DateTime.Now;
DynamicParameters parameters = new DynamicParameters();
parameters.Add("bailun_sku", data.bailun_sku);
parameters.Add("warehouse_code", data.warehouse_code);
parameters.Add("supplier_id", data.supplier_id);
var oldData = conn.QueryFirstOrDefault(" select * from dc_average_purchase where bailun_sku=@bailun_sku and warehouse_code=@warehouse_code and supplier_id=@supplier_id ", parameters);
if (oldData == null)
{
conn.Insert(data);
}
else
{
data.ID = oldData.ID;
conn.Update(data);
}
}
}
public class temp_sku_dto
{
public string bailun_sku { get; set; }
public string warehouse_code { get; set; }
public int? supplier_id { get; set; }
}
}
...@@ -3,6 +3,8 @@ using System; ...@@ -3,6 +3,8 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using Dapper; using Dapper;
using System.IO;
using Microsoft.Extensions.Configuration;
namespace AutoTurnOver.DB namespace AutoTurnOver.DB
{ {
...@@ -10,15 +12,36 @@ namespace AutoTurnOver.DB ...@@ -10,15 +12,36 @@ namespace AutoTurnOver.DB
{ {
//private static MySqlConnection connection = new MySqlConnection("server=gz-cdb-hqmznu0w.sql.tencentcdb.com;database=bailun_datacenter;uid=root;password=#7kfnymAM$Y9-Ntf;port=63523;Convert Zero Datetime=True;Allow User Variables=True"); //private static MySqlConnection connection = new MySqlConnection("server=gz-cdb-hqmznu0w.sql.tencentcdb.com;database=bailun_datacenter;uid=root;password=#7kfnymAM$Y9-Ntf;port=63523;Convert Zero Datetime=True;Allow User Variables=True");
public static string _connStr = null;
public static MySqlConnection _connection public static MySqlConnection _connection
{ {
get { get
{
//if (connection.State == System.Data.ConnectionState.Closed) //if (connection.State == System.Data.ConnectionState.Closed)
//{ //{
// connection.Open(); // connection.Open();
//} //}
//return connection; //return connection;
return new MySqlConnection("server=gz-cdb-hqmznu0w.sql.tencentcdb.com;database=bailun_datacenter;uid=root;password=#7kfnymAM$Y9-Ntf;port=63523;Convert Zero Datetime=True;Allow User Variables=True"); //return new MySqlConnection("server=gz-cdb-hqmznu0w.sql.tencentcdb.com;database=bailun_datacenter;uid=root;password=#7kfnymAM$Y9-Ntf;port=63523;Convert Zero Datetime=True;Allow User Variables=True");
return new MySqlConnection(connStr);
}
}
public static string connStr
{
get
{
if (!string.IsNullOrWhiteSpace(_connStr))
{
return _connStr;
}
else
{
var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json");
var configurationRoot = builder.Build();
return configurationRoot.GetSection("cnstr").Value;
}
} }
} }
} }
......
...@@ -93,5 +93,6 @@ where 1=1 ...@@ -93,5 +93,6 @@ where 1=1
total = _connection.QueryFirst<int>(countSql, parameters); total = _connection.QueryFirst<int>(countSql, parameters);
return obj.AsList(); return obj.AsList();
} }
} }
} }
......
...@@ -135,14 +135,14 @@ where 1=1 "; ...@@ -135,14 +135,14 @@ where 1=1 ";
/// <param name="warehousecode"></param> /// <param name="warehousecode"></param>
/// <param name="days"></param> /// <param name="days"></param>
/// <returns></returns> /// <returns></returns>
public static IEnumerable<dc_auto_config_promotion> ListConfigPromotion(string sku, string warehousecode, int days) public static IEnumerable<dc_auto_config_promotion> ListConfigPromotion(string sku, string warehousecode,DateTime btime, DateTime etime)
{ {
DynamicParameters parameters = new DynamicParameters(); DynamicParameters parameters = new DynamicParameters();
parameters.Add("bailun_sku", sku); parameters.Add("bailun_sku", sku);
parameters.Add("warehouse_code", warehousecode); parameters.Add("warehouse_code", warehousecode);
parameters.Add("b_promotion_time",DateTime.Now.ToString("yyyy-MM-dd 00:00:00")); parameters.Add("b_promotion_time", btime.ToString("yyyy-MM-dd 00:00:00"));
parameters.Add("e_promotion_time", DateTime.Now.AddDays(days).ToString("yyyy-MM-dd 23:59:59")); parameters.Add("e_promotion_time", etime.ToString("yyyy-MM-dd 23:59:59"));
return _connection.Query<Models.dc_auto_config_promotion>(@"select * from dc_auto_config_promotion where bailun_sku=@bailun_sku and warehouse_code=@warehouse_code and promotion_time>=@b_promotion_time and promotion_time=@e_promotion_time ", parameters); return _connection.Query<Models.dc_auto_config_promotion>(@"select * from dc_auto_config_promotion where bailun_sku=@bailun_sku and warehouse_code=@warehouse_code and promotion_time>=@b_promotion_time and promotion_time<=@e_promotion_time ", parameters);
} }
/// <summary> /// <summary>
......
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework> <TargetFramework>netcoreapp2.1</TargetFramework>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
</PropertyGroup> </PropertyGroup>
</Project> </Project>
...@@ -142,6 +142,11 @@ namespace AutoTurnOver.Models ...@@ -142,6 +142,11 @@ namespace AutoTurnOver.Models
/// </summary> /// </summary>
public int forecast_fourteenday_sales { get; set; } public int forecast_fourteenday_sales { get; set; }
/// <summary>
/// 七天实际销量+预测销量
/// </summary>
public string sales_details { get; set; }
} }
public class Condition_AutoTurnOver public class Condition_AutoTurnOver
......
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Models
{
/// <summary>
/// 平均采购指标
/// </summary>
public class dc_average_purchase
{
public int ID { get; set; }
public string bailun_sku { get; set; }
/// <summary>
/// 仓库编码
/// </summary>
public string warehouse_code { get; set; }
/// <summary>
/// 供应商ID
/// </summary>
public int supplier_id { get; set; }
/// <summary>
/// 供应商名称
/// </summary>
public string supplier_name { get; set; }
/// <summary>
/// 平均采购价格
/// </summary>
public decimal price { get; set; }
/// <summary>
/// 平均交期
/// </summary>
public int delivery_days { get; set; }
/// <summary>
/// 平均入库天数
/// </summary>
public int inbound_days { get; set; }
/// <summary>
/// 更新时间
/// </summary>
public DateTime update_time { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Models.dc_base_purchase
{
/// <summary>
/// 到货
/// </summary>
public class dc_base_purchase_arrival_dto
{
public string bailun_sku { get; set; }
/// <summary>
/// 采购单号
/// </summary>
public string purchase_id { get; set; }
/// <summary>
/// 仓库编码
/// </summary>
public string warehouse_code { get; set; }
/// <summary>
/// 更新时间
/// </summary>
public DateTime update_time { get; set; }
/// <summary>
/// 到货数量
/// </summary>
public int count { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Models.dc_base_purchase
{
public class dc_base_purchase_dto
{
public string bailun_sku { get; set; }
/// <summary>
/// 采购单号
/// </summary>
public string purchase_id { get; set; }
/// <summary>
/// 仓编编码
/// </summary>
public string warehouse_code { get; set; }
/// <summary>
/// 仓库名称
/// </summary>
public string warehouse_name { get; set; }
/// <summary>
/// 数量
/// </summary>
public int count { get; set; }
/// <summary>
/// sku 名称
/// </summary>
public string sku_name { get; set; }
/// <summary>
/// 供应商ID
/// </summary>
public int? supplier_id { get; set; }
/// <summary>
/// 供应商名称
/// </summary>
public string supplier_name { get; set; }
/// <summary>
/// 确认时间
/// </summary>
public DateTime? confirm_time { get; set; }
/// <summary>
/// 付款时间
/// </summary>
public DateTime? pay_time { get; set; }
/// <summary>
/// 付款类型
/// </summary>
public int? pay_type { get; set; }
public decimal? price { get; set; }
/// <summary>
/// 采购单状态
/// </summary>
public int? buy_status { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Models.dc_base_purchase
{
public class dc_base_purchase_inbound_dto
{
public string bailun_sku { get; set; }
public string purchase_id { get; set; }
public string warehouse_code { get; set; }
public DateTime update_time { get; set; }
public int count { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Models
{
public class dc_task_log
{
public int ID { get; set; }
/// <summary>
/// 1 = 采购计划平均指标计算
/// </summary>
public int Type { get; set; }
public DateTime StartTime { get; set; }
/// <summary>
/// 完成时间
/// </summary>
public DateTime? CompleteTime { get; set; }
public int Count { get; set; }
public string ErrorMsg { get; set; }
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\AutoTurnOver.Services\AutoTurnOver.Services.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
using AutoTurnOver.Services;
using System;
namespace AutoTurnOver.Purchase.AverageTarget
{
/// <summary>
/// 计算采购历史平均指标
/// 最近5次平均交期
/// 最近5次平均入库天数
/// 最近5次平均(空运)调拨天数
/// 最近5次平均(海运)调拨天数
/// 最近5次平均采购价
/// </summary>
class Program
{
static void Main(string[] args)
{
PurchaseAverageTargetServices.Calculation();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishProtocol>FileSystem</PublishProtocol>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<TargetFramework>netcoreapp2.1</TargetFramework>
<PublishDir>bin\Release\netcoreapp2.1\publish\</PublishDir>
<SelfContained>true</SelfContained>
<_IsPortable>false</_IsPortable>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
</PropertyGroup>
</Project>
\ No newline at end of file
{
"cnstr": "server=gz-cdb-hqmznu0w.sql.tencentcdb.com;port=63523;database=bailun_datacenter;uid=root;password=#7kfnymAM$Y9-Ntf;"
}
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework> <TargetFramework>netcoreapp2.1</TargetFramework>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
......
...@@ -25,5 +25,7 @@ namespace AutoTurnOver.Services ...@@ -25,5 +25,7 @@ namespace AutoTurnOver.Services
{ {
return DB.daily.RealtimeList(sku, warehouse_code,offset, limit, ref total); return DB.daily.RealtimeList(sku, warehouse_code,offset, limit, ref total);
} }
} }
} }
using AutoTurnOver.DB;
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using MySql.Data.MySqlClient;
using AutoTurnOver.Models;
using Dapper;
namespace AutoTurnOver.Services
{
/// <summary>
/// 采购平均指标计算
/// </summary>
public class PurchaseAverageTargetServices
{
/// <summary>
/// 取数基数
/// </summary>
public static int _seed_count = 5;
public static void Calculation()
{
MySqlConnection conn = connectionHelper._connection;
var task_log = new dc_task_log
{
StartTime = DateTime.Now,
Type = 1,
Count = 0
};
var taskID = conn.Insert(task_log);
task_log.ID = taskID.Value;
try
{
// 获取最近2天发送变化的SKU 用于计算
var chageSkuList = AveragePurchase.GetChangeSku(2);
foreach (var skuItem in chageSkuList)
{
dc_average_purchase data = new dc_average_purchase()
{
bailun_sku = skuItem.bailun_sku,
warehouse_code = skuItem.warehouse_code,
supplier_id = skuItem.supplier_id ?? 0
};
// 查询相关采购单
var purchaseList = AveragePurchase.GetPurchaseList(skuItem, _seed_count).ToList();
//有相关采购单
if (purchaseList != null && purchaseList.Count() >= 1)
{
data.supplier_name = purchaseList[0].supplier_name;
//计算平均价格
data.price = purchaseList.Sum(s => s.price ?? 0) / purchaseList.Count;
// 计算平均到货天数
// 计算总交期
int delivery_days = 0;
// 查询相关的到货记录
var arrivalList = AveragePurchase.GetArrivalList(purchaseList.Select(s => s.purchase_id));
foreach (var itemArrivalList in arrivalList.GroupBy(s => s.purchase_id))
{
var tempPurchase = purchaseList.SingleOrDefault(s => s.purchase_id == itemArrivalList.Key);
if (tempPurchase.pay_type == 1)
{
delivery_days += (int)(itemArrivalList.Max(s => s.update_time) - tempPurchase.pay_time).Value.TotalDays;
}
else
{
delivery_days += (int)(itemArrivalList.Max(s => s.update_time) - tempPurchase.confirm_time).Value.TotalDays;
}
}
// 平均采购交期
data.delivery_days = delivery_days / purchaseList.Count;
// 计算平均入库天数
// 查询相关的入库记录
var inbound_days = 0;
var inboundList = AveragePurchase.GetInboundList(purchaseList.Select(s => s.purchase_id));
foreach (var itemInboundList in inboundList.GroupBy(s => s.purchase_id))
{
var tempPurchase = purchaseList.SingleOrDefault(s => s.purchase_id == itemInboundList.Key);
if (tempPurchase.pay_type == 1)
{
inbound_days += (int)(itemInboundList.Max(s => s.update_time) - tempPurchase.pay_time).Value.TotalDays;
}
else
{
inbound_days += (int)(itemInboundList.Max(s => s.update_time) - tempPurchase.confirm_time).Value.TotalDays;
}
}
// 平均入库天数
data.inbound_days = inbound_days / purchaseList.Count;
//写入数据库
AveragePurchase.Save(data, conn);
task_log.Count++;
}
}
task_log.CompleteTime = DateTime.Now;
}
catch (Exception ex)
{
task_log.ErrorMsg = ex.Message;
}
conn.Update(task_log);
}
public static dc_average_purchase GetModel(string sku, string warehouse_code)
{
return AveragePurchase.GetModel(sku, warehouse_code);
}
}
}
...@@ -21,7 +21,9 @@ namespace AutoTurnOver.Services ...@@ -21,7 +21,9 @@ namespace AutoTurnOver.Services
var list = new List<string>(); var list = new List<string>();
//获取预测销量 //获取预测销量
var sales = DB.SaleVolume.GetBySkuWarehouseCode(sku, warehousecode); //var sales = DB.SaleVolume.GetBySkuWarehouseCode(sku, warehousecode);
var sales = DB.dc_auto_turnover.GetModel(sku, warehousecode);
//获取预计采购入库 //获取预计采购入库
//var buyputin = DB.dc_auto_turnover.GetAutoInboundBySkuWH(sku, warehousecode,1); //var buyputin = DB.dc_auto_turnover.GetAutoInboundBySkuWH(sku, warehousecode,1);
...@@ -39,7 +41,7 @@ namespace AutoTurnOver.Services ...@@ -39,7 +41,7 @@ namespace AutoTurnOver.Services
var shortsupply = DB.dc_auto_turnover.GetAutoShortSupplyBySkuWH(sku, warehousecode); var shortsupply = DB.dc_auto_turnover.GetAutoShortSupplyBySkuWH(sku, warehousecode);
list.Add(sales != null ? sales.details : "[]"); list.Add(sales != null ? sales.sales_details : "[]");
//list.Add(buyputin != null ? buyputin.details : "[]"); //list.Add(buyputin != null ? buyputin.details : "[]");
//list.Add(allotputin != null ? allotputin.details : "[]"); //list.Add(allotputin != null ? allotputin.details : "[]");
list.Add(putin != null ? putin.details : "[]"); list.Add(putin != null ? putin.details : "[]");
...@@ -49,9 +51,11 @@ namespace AutoTurnOver.Services ...@@ -49,9 +51,11 @@ namespace AutoTurnOver.Services
// 计算涉及的总天数 // 计算涉及的总天数
int count = list.Max(s => s.Split(',').Length); int count = list.Max(s => s.Split(',').Length);
DateTime today = DateTime.Now.AddDays(-7);
DateTime endDay = today.AddDays(count);
// 查询这些时间范围的 特殊销量情况 // 查询这些时间范围的 特殊销量情况
var configPromotionList = DB.dc_auto_turnover.ListConfigPromotion(sku, warehousecode, count); var configPromotionList = DB.dc_auto_turnover.ListConfigPromotion(sku, warehousecode, today, endDay);
DateTime today = DateTime.Now;
List<int> tempStrList = new List<int>(); List<int> tempStrList = new List<int>();
for (var i = 0; i < count; i++) for (var i = 0; i < count; i++)
{ {
...@@ -68,7 +72,7 @@ namespace AutoTurnOver.Services ...@@ -68,7 +72,7 @@ namespace AutoTurnOver.Services
tempStrList.Add(tempData.count); tempStrList.Add(tempData.count);
} }
} }
list.Add(tempStrList!=null ? tempStrList.ToJson(): "[]"); list.Add(tempStrList != null ? tempStrList.ToJson() : "[]");
////添加预测销量 ////添加预测销量
//list.Add(new mforecast { //list.Add(new mforecast {
......
...@@ -45,7 +45,8 @@ namespace AutoTurnOver.Services ...@@ -45,7 +45,8 @@ namespace AutoTurnOver.Services
/// <returns></returns> /// <returns></returns>
public IEnumerable<dc_auto_config_promotion> List(string sku,string warehousecode,int days) public IEnumerable<dc_auto_config_promotion> List(string sku,string warehousecode,int days)
{ {
return DB.dc_auto_turnover.ListConfigPromotion(sku, warehousecode, days); var now = DateTime.Now;
return DB.dc_auto_turnover.ListConfigPromotion(sku, warehousecode, now, now.AddDays(days));
} }
......
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
......
...@@ -13,6 +13,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoTurnOver.DB", "AutoTurn ...@@ -13,6 +13,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoTurnOver.DB", "AutoTurn
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoTurnOver.Utility", "AutoTurnOver.Utility\AutoTurnOver.Utility.csproj", "{DDD8D47F-A607-4D28-ADAB-77F21794939A}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoTurnOver.Utility", "AutoTurnOver.Utility\AutoTurnOver.Utility.csproj", "{DDD8D47F-A607-4D28-ADAB-77F21794939A}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AutoTurnOver.Console", "AutoTurnOver.Console", "{C1F6DDE1-217D-43D6-81B5-91A7E78A7876}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoTurnOver.Purchase.AverageTarget", "AutoTurnOver.Purchase.AverageTarget\AutoTurnOver.Purchase.AverageTarget.csproj", "{DD5C8D24-7098-4708-A1AC-ACFBB5EBBD6C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test", "test\test.csproj", "{9B3FE8C3-061C-4E94-AF23-11727A3B70A8}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
...@@ -39,10 +45,21 @@ Global ...@@ -39,10 +45,21 @@ Global
{DDD8D47F-A607-4D28-ADAB-77F21794939A}.Debug|Any CPU.Build.0 = Debug|Any CPU {DDD8D47F-A607-4D28-ADAB-77F21794939A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DDD8D47F-A607-4D28-ADAB-77F21794939A}.Release|Any CPU.ActiveCfg = Release|Any CPU {DDD8D47F-A607-4D28-ADAB-77F21794939A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DDD8D47F-A607-4D28-ADAB-77F21794939A}.Release|Any CPU.Build.0 = Release|Any CPU {DDD8D47F-A607-4D28-ADAB-77F21794939A}.Release|Any CPU.Build.0 = Release|Any CPU
{DD5C8D24-7098-4708-A1AC-ACFBB5EBBD6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DD5C8D24-7098-4708-A1AC-ACFBB5EBBD6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DD5C8D24-7098-4708-A1AC-ACFBB5EBBD6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DD5C8D24-7098-4708-A1AC-ACFBB5EBBD6C}.Release|Any CPU.Build.0 = Release|Any CPU
{9B3FE8C3-061C-4E94-AF23-11727A3B70A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9B3FE8C3-061C-4E94-AF23-11727A3B70A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B3FE8C3-061C-4E94-AF23-11727A3B70A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B3FE8C3-061C-4E94-AF23-11727A3B70A8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
EndGlobalSection EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{DD5C8D24-7098-4708-A1AC-ACFBB5EBBD6C} = {C1F6DDE1-217D-43D6-81B5-91A7E78A7876}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {09B3C433-2F6E-498C-AB7C-2931F260C5CE} SolutionGuid = {09B3C433-2F6E-498C-AB7C-2931F260C5CE}
EndGlobalSection EndGlobalSection
......
...@@ -86,7 +86,6 @@ namespace AutoTurnOver.Controllers ...@@ -86,7 +86,6 @@ namespace AutoTurnOver.Controllers
table.Rows.Add(row); table.Rows.Add(row);
} }
var vName = @"Result/RealtimeStock/实时库存.csv";
var fileName = AppContext.BaseDirectory+ @"Result\RealtimeStock\实时库存.csv"; var fileName = AppContext.BaseDirectory+ @"Result\RealtimeStock\实时库存.csv";
DataTableHelper.SaveCSV(table, fileName); DataTableHelper.SaveCSV(table, fileName);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using AutoTurnOver.Services;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
...@@ -35,17 +36,18 @@ namespace AutoTurnOver.Controllers ...@@ -35,17 +36,18 @@ namespace AutoTurnOver.Controllers
} }
//[0.13, 0.12, 0.11, 0.11, 0.1, 0.09, 0.09, 0.08, 0.08, 0.07, 0.06, 0.06, 0.05, 0.04, 0.04, 0.03, 0.02, 0.02, 0.01, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] //[0.13, 0.12, 0.11, 0.11, 0.1, 0.09, 0.09, 0.08, 0.08, 0.07, 0.06, 0.06, 0.05, 0.04, 0.04, 0.03, 0.02, 0.02, 0.01, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
var date = new List<string>(); var date = new List<string>();
var today = DateTime.Now; var today = DateTime.Now.AddDays(-7);
for (var i = 0; i < count; i++) for (var i = 0; i < count; i++)
{ {
date.Add(today.AddDays(i).ToString("MM/dd")); date.Add(today.AddDays(i).ToString("MM/dd"));
} }
var names = new List<string>() { "预测销量", "预计入库", "可用库存", "预计缺货数量","特殊销量" }; var names = new List<string>() { "销量", "预计入库", "可用库存", "预计缺货数量", "特殊销量" };
var turnoverData = new Services.SkuAutoTurnServices().GetModel(sku, warehousecode); var turnoverData = new Services.SkuAutoTurnServices().GetModel(sku, warehousecode);
var saleVolumeData = new Services.SaleVolumeServices().GetBySkuWarehouseCode(sku, warehousecode); var saleVolumeData = new Services.SaleVolumeServices().GetBySkuWarehouseCode(sku, warehousecode);
return new JsonResult(new { data = result, turnoverData, saleVolumeData, days = date, names }); var averageTarget = PurchaseAverageTargetServices.GetModel(sku, warehousecode);
return new JsonResult(new { data = result, turnoverData, saleVolumeData, days = date, names, averageTarget });
} }
} }
......
using System;
using System.Collections.Generic;
using System.Linq;
namespace test
{
class Program
{
static void Main(string[] args)
{
var datas = new List<testDto>() {
new testDto{name="A",count=100 },
new testDto{name="B",count=50 }
};
for (int i = 0; i < 5; i++)
{
var tempData = datas.Where(s => s.name == "A").FirstOrDefault();
tempData.count -= 1;
Console.WriteLine(tempData.count);
}
Console.WriteLine("--------------");
foreach (var item in datas)
{
Console.WriteLine("name:" + item.name + ",count:" + item.count);
}
Console.ReadKey();
}
}
public class testDto
{
public int count { get; set; }
public string name { get; set; }
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
</Project>
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