Commit f5e55f33 by lizefeng

修改商品moq下单的算法

parent d61c8c8f
......@@ -13,7 +13,6 @@ namespace AutoGeneratePurchaseAdvise
Console.WriteLine("采购建议计算任务启动...");
// 创建采购计划
//PurchaseAdviseServices.Generate();
var builder = new HostBuilder().ConfigureServices((hostContext, services) =>
{
services.AddHostedService<GeneratePurchaseAdviseBackgroundService>();
......
{
"ConnectionStrings": {
"Default": "server=gz-cdb-kp7s5i79.sql.tencentcdb.com;port=61691;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;"
}
}
......@@ -31,11 +31,12 @@ GROUP BY t1.bailun_sku,t1.warehouse_code,t1.supplier_id ");
//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 IEnumerable<dc_average_purchase> GetList(string sku)
public static IEnumerable<dc_average_purchase> GetListByWCode(string sku, string warehouse_code)
{
DynamicParameters parameters = new DynamicParameters();
parameters.Add("bailun_sku", sku);
return _connection.Query<dc_average_purchase>("select * from dc_average_purchase where bailun_sku=@bailun_sku ", parameters);
parameters.Add("warehouse_code", warehouse_code);
return _connection.Query<dc_average_purchase>("select * from dc_average_purchase where bailun_sku=@bailun_sku and warehouse_code=@warehouse_code ", parameters);
}
public static IEnumerable<dc_average_purchase> GetList(string supplier_ids,string bailun_skus)
......
......@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Text;
using Dapper;
using AutoTurnOver.Models;
using AutoTurnOver.Models.Common;
namespace AutoTurnOver.DB
{
......@@ -64,5 +65,41 @@ namespace AutoTurnOver.DB
return _connection.Query<mwarehouseArea>(sql).AsList();
}
/// <summary>
/// 查询供应商
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static List<supplier_dto> SearchSupplier(string name)
{
if (string.IsNullOrWhiteSpace(name))
{
return new List<supplier_dto>();
}
else
{
var sql = " select suppliers_name as 'name' from dc_base_sku where suppliers_name like @suppliers_name GROUP BY suppliers_name ";
return _connection.Query<supplier_dto>(sql,new { suppliers_name = $"%{name}%" }).AsList();
}
}
/// <summary>
/// 查询采购员
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static List<purchase_user_dto> SearchPurchaseUser(string name)
{
if (string.IsNullOrWhiteSpace(name))
{
return new List<purchase_user_dto>();
}
else
{
var sql = " select buyer_name as 'name' from dc_base_sku where buyer_name like @buyer_name GROUP BY buyer_name ";
return _connection.Query<purchase_user_dto>(sql, new { buyer_name = $"%{name}%" }).AsList();
}
}
}
}
......@@ -182,11 +182,11 @@ where 1=1 ";
var obj = _connection.Query<Models.dc_auto_turnover_Extend>(sql);
var obj = _connection.Query<Models.dc_auto_turnover_Extend>(sql,commandTimeout:0);
return obj.AsList();
}
catch (Exception)
catch (Exception ex)
{
return new List<Models.dc_auto_turnover_Extend>();
......
......@@ -2,6 +2,7 @@
using Dapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AutoTurnOver.DB
......@@ -38,9 +39,10 @@ namespace AutoTurnOver.DB
INSERT into dc_auto_purchase_advise_detailed(`bailun_sku`,`warehouse_code`,`quantity_init_advise`,`quantity_final_advise`,
`product_inner_code`,`goods_quantity_init_advise`,`goods_moq`,`good_sku_codes`,`goods_history_fourteenday_sales`,`history_fourteenday_sales`,
`quantity_actual`,`main_id`,
`forecast_formula`,`fit_forecast_formula`,`turnover_days`,`supplier_delivery`,`inspection_delivery`,`transfer_delivery`,`sales_upper_limit`,`ispush`,`type`)
`forecast_formula`,`fit_forecast_formula`,`turnover_days`,`supplier_delivery`,`inspection_delivery`,`transfer_delivery`,`sales_upper_limit`,`ispush`,`type`,`suppliers_id`)
(
select
select * from (
select
t1.bailun_sku,
t1.warehouse_code,
t1.quantity_init_advise as 'quantity_init_advise', -- 原始采购建议数量 new
......@@ -49,10 +51,10 @@ INSERT into dc_auto_purchase_advise_detailed(`bailun_sku`,`warehouse_code`,`quan
when t7.sum_quantity_init_advise>=t7.max_moq then t1.quantity_init_advise -- 如果商品的下单总量达到moq了,就直接下单
when t7.sku_count=1 then t7.max_moq -- 如果该商品只有一个sku需要下单,则直接下一个moq
else
CEILING(
t1.quantity_init_advise +
FLOOR(
GREATEST(t1.quantity_init_advise,0) +
(
(t7.max_moq-t7.sum_quantity_init_advise)
(t7.max_moq-GREATEST(t7.sum_quantity_init_advise,0))
*
(t1.history_fourteenday_sales / t7.sum_history_fourteenday_sales )
)
......@@ -75,16 +77,40 @@ INSERT into dc_auto_purchase_advise_detailed(`bailun_sku`,`warehouse_code`,`quan
t1.transfer_delivery,
t1.sales_upper_limit,
0 as 'ispush',
(case when t1.quantity_out_stock>0 then 2 when t1.`status` then 1 else 3 end) as 'type'
(case when t1.quantity_out_stock>0 then 2 when t1.`status` then 1 else 3 end) as 'type',
t6.suppliers_id
from dc_auto_turnover as t1
left join dc_auto_sales as t2 on t1.bailun_sku = t2.bailun_sku and t1.warehouse_code = t2.warehouse_code
left join dc_auto_config_sku_warehouse as t5 on t1.bailun_sku = t5.bailun_sku and t1.warehouse_code = t5.warehouse_code
left join dc_base_sku as t6 on t1.bailun_sku = t6.bailun_sku
left join view_goods_moq as t7 on t6.product_inner_code = t7.product_inner_code and t1.warehouse_code = t7.warehouse_code and t6.suppliers_id = t7.suppliers_id
where (t1.history_fourteenday_sales>0 or t1.quantity_out_stock>0 ) and t1.quantity_init_advise>0 and ( t5.`status`=0 or t5.`status` is null )
where (t1.history_fourteenday_sales>0 or t1.quantity_out_stock>0 ) and ( t5.`status`=0 or t5.`status` is null ) and t7.sum_quantity_init_advise>0
) as t1 where t1.quantity_final_advise>0
)
", new { main_id = mainID });
", new { main_id = mainID }, commandTimeout: 0);
// 调整因为舍弃小数导致的moq不足
var datas = _connection.Query<dc_auto_purchase_advise_detailed>(" select * from dc_auto_purchase_advise_detailed where main_id=@main_id ", new { main_id = mainID }).AsList();
if (datas != null && datas.Count > 0)
{
foreach (var itemGoods in datas.GroupBy(s => new { s.suppliers_id, s.product_inner_code, s.warehouse_code }))
{
// 判断总建议采购数是否达到了moq
var difference = itemGoods.Max(s => s.goods_moq) - itemGoods.Sum(s => s.quantity_final_advise);
if (difference > 0)
{
// 把最大的那条记录找出来,加给他
var max_data = itemGoods.OrderByDescending(s => s.quantity_final_advise).FirstOrDefault();
_connection.Execute(" update dc_auto_purchase_advise_detailed set quantity_final_advise=@quantity_final_advise where id=@id ", new
{
quantity_final_advise = max_data.quantity_final_advise + difference,
id = max_data.id
});
}
}
}
}
/// <summary>
......@@ -170,6 +196,10 @@ left join dc_base_sku as t3 on t1.bailun_sku = t3.bailun_sku
left join dc_auto_purchase_advise as t4 on t1.main_id = t4.id
where 1=1 ";
if (!string.IsNullOrWhiteSpace(m.product_inner_code))
{
sql += " and t3.product_inner_code=" + m.product_inner_code;
}
if (m.type != null)
{
sql += " and t1.`type`= " + m.type;
......@@ -212,7 +242,17 @@ where 1=1 ";
sql += $" and t1.warehouse_code=@warehouse_code ";
parameters.Add("warehouse_code", m.warehouse_code);
}
if (!string.IsNullOrWhiteSpace(m.supplier_name))
{
sql += " and t3.suppliers_name =@suppliers_name ";
parameters.Add("suppliers_name", m.supplier_name);
}
if (!string.IsNullOrWhiteSpace(m.purchase_user))
{
sql += " and t3.buyer_name =@buyer_name ";
parameters.Add("buyer_name", m.purchase_user);
}
sql += " order by t1.quantity_final_advise desc ";
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1", parameters);
......
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Models.Common
{
public class supplier_dto
{
public int? id { get; set; }
public string name { get; set; }
}
public class purchase_user_dto
{
public int? id { get; set; }
public string name { get; set; }
}
}
......@@ -134,6 +134,8 @@ namespace AutoTurnOver.Models
/// 产品的最近14日日均
/// </summary>
public decimal history_fourteenday_sales { get; set; }
public int suppliers_id { get; set; }
}
public class dc_auto_purchase_advise_detailed_buy_dto: dc_auto_purchase_advise_detailed
......@@ -201,6 +203,18 @@ namespace AutoTurnOver.Models
public bool? ispush { get; set; }
public int? type { get; set; }
/// <summary>
/// 采购员
/// </summary>
public string purchase_user { get; set; }
/// <summary>
/// 供应商
/// </summary>
public string supplier_name { get; set; }
public string product_inner_code { get; set; }
}
}
{
"ConnectionStrings": {
"Default": "server=gz-cdb-kp7s5i79.sql.tencentcdb.com;port=61691;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;"
}
}
......@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Text;
using AutoTurnOver.Models;
using AutoTurnOver.DB;
using AutoTurnOver.Models.Common;
namespace AutoTurnOver.Services
{
......@@ -22,5 +23,17 @@ namespace AutoTurnOver.Services
{
return DB.common.ListWareHouseArea();
}
public List<supplier_dto> SearchSupplier(string name)
{
return DB.common.SearchSupplier(name);
}
public List<purchase_user_dto> SearchPurchaseUser(string name)
{
return DB.common.SearchPurchaseUser(name);
}
}
}
......@@ -156,9 +156,9 @@ namespace AutoTurnOver.Services
conn.Update(task_log);
}
public static IEnumerable<dc_average_purchase> GetList(string sku)
public static IEnumerable<dc_average_purchase> GetListByWCode(string sku,string warehouse_code)
{
return AveragePurchase.GetList(sku);
return AveragePurchase.GetListByWCode(sku, warehouse_code);
}
public static IEnumerable<dc_average_purchase> GetList(string supplier_ids, string bailun_skus)
......
......@@ -67,6 +67,30 @@ namespace AutoTurnOver.Controllers
return new JsonResult(datas);
}
public JsonResult SearchSupplier(string name)
{
var list = new CommonServices().SearchSupplier(name);
return new JsonResult(list.Select(p => new
{
id = p.name,
text = p.name
}));
}
public JsonResult SearchPurchaseUser(string name)
{
var list = new CommonServices().SearchPurchaseUser(name);
return new JsonResult(list.Select(p => new
{
id = p.name,
text = p.name
}));
}
/// <summary>
/// 获取一二级的百伦数据
/// </summary>
......
......@@ -59,7 +59,9 @@ namespace AutoTurnOver.Controllers
/// <param name="start_date"></param>
/// <returns></returns>
[HttpGet]
public string DetailList(int limit, int offset, int main_id, string sort, string sku, string warehousecode, DateTime? end_date, DateTime? start_date, string warehousetype, int? warehousearea, bool? ispush = null,int? type = null)
public string DetailList(int limit, int offset, int main_id, string sort, string sku, string warehousecode,
DateTime? end_date, DateTime? start_date, string warehousetype, int? warehousearea,
bool? ispush = null,int? type = null,string supplier_name = null,string purchase_user = null,string product_inner_code= null)
{
var m = new dc_auto_purchase_advise_detailed_search_dto
{
......@@ -71,7 +73,10 @@ namespace AutoTurnOver.Controllers
warehousearea = warehousearea,
warehousetype = warehousetype,
ispush = ispush,
type = type
type = type,
supplier_name = supplier_name,
purchase_user = purchase_user,
product_inner_code = product_inner_code
};
var total = 0;
......
......@@ -47,7 +47,7 @@ namespace AutoTurnOver.Controllers
var names = new List<string>() { "销量","计算规则", "预计入库", "可用库存", "预计缺货数量", "特殊销量", "市场因素", "建议下单数量", "人工下单数量" };
var turnoverData = new Services.SkuAutoTurnServices().GetModel(sku, warehousecode);
var saleVolumeData = new Services.SaleVolumeServices().GetBySkuWarehouseCode(sku, warehousecode);
var averageTargets = PurchaseAverageTargetServices.GetList(sku);
var averageTargets = PurchaseAverageTargetServices.GetListByWCode(sku, warehousecode);
var averageTargetWarehouse = PurchaseAverageTargetServices.GetWarehouse(sku, warehousecode);
DateTime turnoverDate = DateTime.Now.AddDays(turnoverData.turnover_days);
......
......@@ -8,7 +8,6 @@
}
},
"AllowedHosts": "*",
"cnstr": "server=gz-cdb-kp7s5i79.sql.tencentcdb.com;port=61691;database=bailun_datacenter;uid=root;password=#7kfnymAM$Y9-Ntf;",
"PushBuyPlan": "http://192.168.6.229/api/CreatePlanToPurchase",
"WebHost_GetUser": "http://www.bailuntec.com/Login/GetUserByBLUserAcct?webcode=aims",
"WebHost_LoginOut": "http://www.bailuntec.com/Login/LoginOut"
......
......@@ -8,7 +8,6 @@
}
},
"AllowedHosts": "*",
"cnstr": "server=gz-cdb-kp7s5i79.sql.tencentcdb.com;port=61691;database=bailun_datacenter;uid=root;password=#7kfnymAM$Y9-Ntf;",
"PushBuyPlan": "http://192.168.6.229/api/CreatePlanToPurchase",
"WebHost_GetUser": "http://www.bailuntec.com/Login/GetUserByBLUserAcct?webcode=aims",
"WebHost_LoginOut": "http://www.bailuntec.com/Login/LoginOut"
......
{
"ConnectionStrings": {
"Default": "server=gz-cdb-kp7s5i79.sql.tencentcdb.com;port=61691;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;"
},
"Logging": {
"LogLevel": {
......@@ -8,7 +8,6 @@
}
},
"AllowedHosts": "*",
"cnstr": "server=gz-cdb-kp7s5i79.sql.tencentcdb.com;port=61691;database=bailun_datacenter;uid=root;password=#7kfnymAM$Y9-Ntf;",
"PushBuyPlan": "http://192.168.6.229/api/CreatePlanToPurchase",
"WebHost_GetUser": "http://www.bailuntec.com/Login/GetUserByBLUserAcct?webcode=aims",
"WebHost_LoginOut": "http://www.bailuntec.com/Login/LoginOut"
......
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