Commit 9ce50fd1 by 泽锋 李

sku 停止监控之后,要从母sku移除

parent 4d9d4267
...@@ -673,6 +673,15 @@ GROUP BY t1.bailun_sku,t3.hq_type ...@@ -673,6 +673,15 @@ GROUP BY t1.bailun_sku,t3.hq_type
bailun_sku_warehouse_codes = datas.Select(s => $"{s.bailun_sku}{s.warehouse_code}").ToList() bailun_sku_warehouse_codes = datas.Select(s => $"{s.bailun_sku}{s.warehouse_code}").ToList()
}); });
} }
//停止监控之后,从母sku移除
if (monitor_status == 1)
{
dc_base_mother_sku_dao.RemoveMap(new remove_map_input_dto
{
map_ids = conn.Query<int>(" select t1.id from dc_base_mother_sku_map as t1 where t1.bailun_sku_warehouse_code=@bailun_sku_warehouse_codes ", new { bailun_sku_warehouse_codes = datas.Select(s => s.bailun_sku_warehouse_code).ToList() }).ToList()
}, new UserData { UserName = "system" });
}
return ""; return "";
......
...@@ -121,8 +121,9 @@ where t1.mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new ...@@ -121,8 +121,9 @@ where t1.mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new
/// <summary> /// <summary>
/// 保存数据 /// 保存数据
/// </summary> /// </summary>
public static void Save(dc_base_mother_sku data, UserData user) public static int Save(dc_base_mother_sku data, UserData user)
{ {
var id = 0;
data.sku = ("M-" + data.sku); data.sku = ("M-" + data.sku);
data.sku_warehouse_code = $"{data.sku}{data.warehouse_code}"; data.sku_warehouse_code = $"{data.sku}{data.warehouse_code}";
if (data.id <= 0) if (data.id <= 0)
...@@ -131,9 +132,9 @@ where t1.mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new ...@@ -131,9 +132,9 @@ where t1.mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new
var oldData = _connection.QueryFirstOrDefault(" select * from dc_base_mother_sku where sku=@sku ", new { sku = data.sku }); var oldData = _connection.QueryFirstOrDefault(" select * from dc_base_mother_sku where sku=@sku ", new { sku = data.sku });
if (oldData != null) if (oldData != null)
{ {
throw new Exception("该sku已存在,请勿重复添加"); return oldData.id;
} }
_connection.Insert(data); id = _connection.Insert(data) ?? 0;
_connection.Insert(new dc_base_mother_sku_log _connection.Insert(new dc_base_mother_sku_log
{ {
...@@ -157,10 +158,12 @@ where t1.mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new ...@@ -157,10 +158,12 @@ where t1.mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new
} }
else else
{ {
throw new Exception("不支持修改"); throw new Exception("不支持修改");
//_connection.Update(data); //_connection.Update(data);
} }
return id;
} }
...@@ -204,7 +207,10 @@ where t1.mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new ...@@ -204,7 +207,10 @@ where t1.mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new
/// <param name="input_data"></param> /// <param name="input_data"></param>
public static void RemoveMap(remove_map_input_dto input_data, UserData user) public static void RemoveMap(remove_map_input_dto input_data, UserData user)
{ {
if(input_data.map_ids==null || input_data.map_ids.Count <= 0)
{
return;
}
var conn = MyMySqlConnection._connection; var conn = MyMySqlConnection._connection;
conn.Open(); conn.Open();
using (var t = conn.BeginTransaction()) using (var t = conn.BeginTransaction())
...@@ -311,21 +317,22 @@ where t1.mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new ...@@ -311,21 +317,22 @@ where t1.mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new
}); });
if (oldLog != null) if (oldLog != null)
{ {
// 跳过
//// 先移除
//conn.Insert(new dc_base_mother_sku_log
//{
// action = $"移除子sku 【{oldLog.bailun_sku}】【{oldLog.warehouse_code}】,设置到新的sku 【{mother_data.sku}】",
// sku_warehouse_code = oldLog.mother_sku_warehouse_code,
// create_date = DateTime.Now,
// create_user = user.UserName,
// sku = oldLog.mother_sku,
// warehouse_code = oldLog.mother_warehouse_code
//});
// 先移除 //conn.Execute(" delete from dc_base_mother_sku_map where id=@id ", new { id = oldLog.id });
conn.Insert(new dc_base_mother_sku_log
{
action = $"移除子sku 【{oldLog.bailun_sku}】【{oldLog.warehouse_code}】,设置到新的sku 【{mother_data.sku}】",
sku_warehouse_code = oldLog.mother_sku_warehouse_code,
create_date = DateTime.Now,
create_user = user.UserName,
sku = oldLog.mother_sku,
warehouse_code = oldLog.mother_warehouse_code
});
conn.Execute(" delete from dc_base_mother_sku_map where id=@id ", new { id = oldLog.id });
} }
else
{
// 添加日志 // 添加日志
conn.Insert(new dc_base_mother_sku_log conn.Insert(new dc_base_mother_sku_log
{ {
...@@ -346,6 +353,10 @@ where t1.mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new ...@@ -346,6 +353,10 @@ where t1.mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new
bailun_sku_warehouse_code = $"{trunData.bailun_sku}{trunData.warehouse_code}", bailun_sku_warehouse_code = $"{trunData.bailun_sku}{trunData.warehouse_code}",
is_main = input_data.is_main is_main = input_data.is_main
}); });
ResetTurnOver(mother_data.sku, mother_data.warehouse_code);
}
} }
t.Commit(); t.Commit();
...@@ -564,15 +575,17 @@ where t1.mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new ...@@ -564,15 +575,17 @@ where t1.mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new
var dc_auto_sales_list = new List<dc_auto_sales>(); var dc_auto_sales_list = new List<dc_auto_sales>();
foreach (var item in turn_datas) foreach (var item in turn_datas)
{ {
var item_dc_auto_sales = conn.QuerySingleOrDefault<dc_auto_sales>(" select * from dc_auto_sales where bailun_sku=@bailun_sku and warehouse_code=@warehouse_code ",new { var item_dc_auto_sales = conn.QuerySingleOrDefault<dc_auto_sales>(" select * from dc_auto_sales where bailun_sku=@bailun_sku and warehouse_code=@warehouse_code ", new
bailun_sku= item.bailun_sku, {
bailun_sku = item.bailun_sku,
warehouse_code = item.warehouse_code warehouse_code = item.warehouse_code
}); });
dc_auto_sales_list.Add(item_dc_auto_sales); dc_auto_sales_list.Add(item_dc_auto_sales);
} }
var first_auto_sales_data = dc_auto_sales_list.FirstOrDefault(); var first_auto_sales_data = dc_auto_sales_list.FirstOrDefault();
var mother_dc_auto_sales = new dc_auto_sales { var mother_dc_auto_sales = new dc_auto_sales
average_sales = dc_auto_sales_list.Sum(s=>s.average_sales), {
average_sales = dc_auto_sales_list.Sum(s => s.average_sales),
bailun_sku = mother_turn_data.bailun_sku, bailun_sku = mother_turn_data.bailun_sku,
b_variable = first_auto_sales_data.b_variable, b_variable = first_auto_sales_data.b_variable,
category_id = first_auto_sales_data.category_id, category_id = first_auto_sales_data.category_id,
...@@ -616,13 +629,13 @@ where t1.mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new ...@@ -616,13 +629,13 @@ where t1.mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new
forecast_twoday_sales = dc_auto_sales_list.Sum(s => s.forecast_twoday_sales), forecast_twoday_sales = dc_auto_sales_list.Sum(s => s.forecast_twoday_sales),
fourteenday_sales = dc_auto_sales_list.Sum(s => s.fourteenday_sales), fourteenday_sales = dc_auto_sales_list.Sum(s => s.fourteenday_sales),
fourthday_sales = dc_auto_sales_list.Sum(s => s.fourthday_sales), fourthday_sales = dc_auto_sales_list.Sum(s => s.fourthday_sales),
gmt_create =DateTime.Now, gmt_create = DateTime.Now,
gmt_modified =DateTime.Now, gmt_modified = DateTime.Now,
k_variable = first_auto_sales_data.k_variable, k_variable = first_auto_sales_data.k_variable,
nineday_sales = dc_auto_sales_list.Sum(s => s.nineday_sales), nineday_sales = dc_auto_sales_list.Sum(s => s.nineday_sales),
nineteenday_sales = dc_auto_sales_list.Sum(s => s.nineteenday_sales), nineteenday_sales = dc_auto_sales_list.Sum(s => s.nineteenday_sales),
oneday_sales = dc_auto_sales_list.Sum(s => s.oneday_sales), oneday_sales = dc_auto_sales_list.Sum(s => s.oneday_sales),
sevenday_sales= dc_auto_sales_list.Sum(s => s.sevenday_sales), sevenday_sales = dc_auto_sales_list.Sum(s => s.sevenday_sales),
sixday_sales = dc_auto_sales_list.Sum(s => s.sixday_sales), sixday_sales = dc_auto_sales_list.Sum(s => s.sixday_sales),
sixteenday_sales = dc_auto_sales_list.Sum(s => s.sixteenday_sales), sixteenday_sales = dc_auto_sales_list.Sum(s => s.sixteenday_sales),
seventeenday_sales = dc_auto_sales_list.Sum(s => s.seventeenday_sales), seventeenday_sales = dc_auto_sales_list.Sum(s => s.seventeenday_sales),
...@@ -649,8 +662,9 @@ where t1.mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new ...@@ -649,8 +662,9 @@ where t1.mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new
}; };
mother_dc_auto_sales.id = conn.QueryFirstOrDefault<int?>(" select id from dc_auto_sales where bailun_sku=@bailun_sku and warehouse_code=@warehouse_code ", new { mother_dc_auto_sales.id = conn.QueryFirstOrDefault<int?>(" select id from dc_auto_sales where bailun_sku=@bailun_sku and warehouse_code=@warehouse_code ", new
bailun_sku= mother_dc_auto_sales.bailun_sku, {
bailun_sku = mother_dc_auto_sales.bailun_sku,
warehouse_code = mother_dc_auto_sales.warehouse_code warehouse_code = mother_dc_auto_sales.warehouse_code
}) ?? 0; }) ?? 0;
if (mother_dc_auto_sales.id > 0) if (mother_dc_auto_sales.id > 0)
...@@ -673,7 +687,7 @@ where t1.mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new ...@@ -673,7 +687,7 @@ where t1.mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new
{ {
warehouse_code = mother_dc_auto_sales.warehouse_code, warehouse_code = mother_dc_auto_sales.warehouse_code,
bailun_sku = mother_dc_auto_sales.bailun_sku, bailun_sku = mother_dc_auto_sales.bailun_sku,
actual_inventory = dc_auto_inbound_list.Sum(s=>s.actual_inventory), actual_inventory = dc_auto_inbound_list.Sum(s => s.actual_inventory),
forecast_eightday_inbound = dc_auto_inbound_list.Sum(s => s.forecast_eightday_inbound), forecast_eightday_inbound = dc_auto_inbound_list.Sum(s => s.forecast_eightday_inbound),
forecast_eighteenday_inbound = dc_auto_inbound_list.Sum(s => s.forecast_eighteenday_inbound), forecast_eighteenday_inbound = dc_auto_inbound_list.Sum(s => s.forecast_eighteenday_inbound),
forecast_elevenday_inbound = dc_auto_inbound_list.Sum(s => s.forecast_elevenday_inbound), forecast_elevenday_inbound = dc_auto_inbound_list.Sum(s => s.forecast_elevenday_inbound),
...@@ -707,7 +721,7 @@ where t1.mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new ...@@ -707,7 +721,7 @@ where t1.mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new
forecast_twoday_inbound = dc_auto_inbound_list.Sum(s => s.forecast_twoday_inbound), forecast_twoday_inbound = dc_auto_inbound_list.Sum(s => s.forecast_twoday_inbound),
gmt_create = DateTime.Now, gmt_create = DateTime.Now,
gmt_modified = DateTime.Now, gmt_modified = DateTime.Now,
relation = $"[{(string.Join(",", MergeStringList(dc_auto_inbound_list.Select(s => s.relation.Replace("[", "").Replace("]", "").Split(',').ToList()).ToList())))}]" , relation = $"[{(string.Join(",", MergeStringList(dc_auto_inbound_list.Select(s => s.relation.Replace("[", "").Replace("]", "").Split(',').ToList()).ToList())))}]",
details = MergeList(dc_auto_inbound_list.Select(s => s.details.ToObj<List<decimal>>()).ToList()).ToJson() details = MergeList(dc_auto_inbound_list.Select(s => s.details.ToObj<List<decimal>>()).ToList()).ToJson()
}; };
...@@ -756,7 +770,7 @@ where t1.mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new ...@@ -756,7 +770,7 @@ where t1.mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new
{ {
if (item.Count - 1 >= i) if (item.Count - 1 >= i)
{ {
val.AddRange(item[i].Split('*')) ; val.AddRange(item[i].Split('*'));
} }
} }
r.Add(string.Join("*", val)); r.Add(string.Join("*", val));
...@@ -771,7 +785,8 @@ where t1.mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new ...@@ -771,7 +785,8 @@ where t1.mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new
/// <returns></returns> /// <returns></returns>
public static List<dc_base_mother_sku_map> GetMapSkus(string mother_sku, string monther_warehouse_code) public static List<dc_base_mother_sku_map> GetMapSkus(string mother_sku, string monther_warehouse_code)
{ {
return _connection.Query<dc_base_mother_sku_map>(" select * dc_base_mother_sku where mother_sku_warehouse_code=@mother_sku_warehouse_code ",new { return _connection.Query<dc_base_mother_sku_map>(" select * dc_base_mother_sku where mother_sku_warehouse_code=@mother_sku_warehouse_code ", new
{
mother_sku_warehouse_code = $"{mother_sku}{monther_warehouse_code}" mother_sku_warehouse_code = $"{mother_sku}{monther_warehouse_code}"
}).ToList(); }).ToList();
} }
...@@ -840,5 +855,61 @@ order by t1.gmt_modified asc ...@@ -840,5 +855,61 @@ order by t1.gmt_modified asc
new_task_synchro_log.status = 1; new_task_synchro_log.status = 1;
conn.Update(new_task_synchro_log); conn.Update(new_task_synchro_log);
} }
/// <summary>
/// 自动生成数据
/// 用一个sku 在监控中 都是fba仓
/// </summary>
public static void GenerateData()
{
var group_list = _connection.Query<temp_turnover_dto>(@"select t1.bailun_sku,GROUP_CONCAT(CONCAT(t1.warehouse_code,'_',t1.daily_weighted_sales,'_',t1.id)) as 'warehouse_codes' from dc_auto_turnover as t1
left join dc_base_warehouse as t2 on t1.warehouse_code =t2.warehouse_code
left join dc_auto_config_sku_warehouse as t3 on t1.bailun_sku = t3.bailun_sku and t1.warehouse_code = t3.warehouse_code
where t2.hq_type in ('fba仓') and ifnull(t3.`status`,0)=0 GROUP BY t1.bailun_sku HAVING count(1)>1
").ToList();
foreach (var item in group_list)
{
var mainData = item.warehouse_datas.OrderByDescending(s => s.daily_weighted_sales).FirstOrDefault();
var mother_id = 0;
mother_id = Save(new dc_base_mother_sku { sku = item.bailun_sku, warehouse_code = mainData.warehouse_code }, new UserData() { UserName = "system" });
// 销量最高的做主sku
BatchSet(new batch_set_input_dto { mother_id = mother_id, ids = item.warehouse_datas.Where(s => s.id != mainData.id).Select(s => s.id).ToList() }, new UserData() { UserName = "system" });
BatchSet(new batch_set_input_dto { mother_id = mother_id, ids = new List<int> { mainData.id }, is_main = 1 }, new UserData() { UserName = "system" });
}
}
public class temp_turnover_dto
{
public int id { get; set; }
public string bailun_sku { get; set; }
public string warehouse_codes { get; set; }
public List<warehouse_data_dto> warehouse_datas
{
get
{
List<warehouse_data_dto> datas = new List<warehouse_data_dto>();
datas.AddRange(warehouse_codes.Split(',').Select(s =>
{
var temp_datas = s.Split('_');
return new warehouse_data_dto()
{
warehouse_code = temp_datas[0],
daily_weighted_sales = decimal.Parse(temp_datas[1]),
id = int.Parse(temp_datas[2]),
};
}).ToList());
return datas;
}
}
public class warehouse_data_dto
{
public decimal daily_weighted_sales { get; set; }
public string warehouse_code { get; set; }
public int id { get; set; }
}
}
} }
} }
...@@ -34,6 +34,7 @@ namespace ResetOutofstock ...@@ -34,6 +34,7 @@ namespace ResetOutofstock
//dc_base_mother_sku_dao.ResetTurnOver("M-test123", "MMDUSFBA"); //dc_base_mother_sku_dao.ResetTurnOver("M-test123", "MMDUSFBA");
//dc_base_transfer_extend_dao.SynchroLmsTransferOrder(); //dc_base_transfer_extend_dao.SynchroLmsTransferOrder();
//dc_base_full_link_wait_order_dao.ResetDatas(); //dc_base_full_link_wait_order_dao.ResetDatas();
dc_base_mother_sku_dao.GenerateData();
} }
catch (Exception ex) catch (Exception ex)
{ {
......
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