Commit e85415d4 by lizefeng

超出moq . 有超出的部分,把补单的(初始建议数为负数)按销量排序,逐个消减

parent 53eae7fa
...@@ -132,6 +132,29 @@ select ...@@ -132,6 +132,29 @@ select
id = max_data.id id = max_data.id
}); });
} }
else if (difference < 0)
{
// 由于上面的补单规则,会导致超出moq . 有超出的部分,把补单的(初始建议数为负数)按销量排序,逐个消减
var abatement = 0 - difference;
foreach (var item in itemGoods.Where(s => s.quantity_init_advise < 0).OrderBy(s => s.goods_history_fourteenday_sales))
{
if (abatement >= item.quantity_final_advise)
{
_connection.Execute(" delete from dc_auto_purchase_advise_detailed where id=@id ", new { id = item.id });
abatement -= item.quantity_final_advise;
}
else
{
_connection.Execute(" update dc_auto_purchase_advise_detailed set quantity_final_advise=@quantity_final_advise where id=@id ", new { id = item.id, quantity_final_advise = item.quantity_final_advise - abatement });
abatement = 0;
}
if (abatement <= 0)
{
break;
}
}
}
} }
} }
......
...@@ -126,68 +126,73 @@ namespace AutoTurnOver.Services ...@@ -126,68 +126,73 @@ namespace AutoTurnOver.Services
purchase_advise.Del(id); purchase_advise.Del(id);
} }
private static object _push_lock = new object();
/// <summary> /// <summary>
/// 把最新一批的采购单推送到采购系统 /// 把最新一批的采购单推送到采购系统
/// </summary> /// </summary>
/// <param name="mainId"></param> /// <param name="mainId"></param>
public static void PushBuySys(List<dc_auto_purchase_advise_detailed_dto> datas,UserData user) public static void PushBuySys(List<dc_auto_purchase_advise_detailed_dto> datas,UserData user)
{ {
MySqlConnection conn = connectionHelper._connection; lock (_push_lock)
conn.Open();
IDbTransaction transaction = conn.BeginTransaction();
try
{ {
//查询最近一个采购建议 MySqlConnection conn = connectionHelper._connection;
// conn.Open();
if (datas == null) IDbTransaction transaction = conn.BeginTransaction();
{ try
return;
}
List<string> planNos = new List<string>();
DateTime now = DateTime.Now;
// 查询未推送成功的采购建议的明细
var detailList = purchase_advise.BuyDetailList(datas.Select(s => s.id).ToList(), false);
foreach (var item in detailList.GroupBy(s => s.warehouse_code))
{ {
//查询最近一个采购建议
mPlanToPurchaseDto data = new mPlanToPurchaseDto //
if (datas == null)
{ {
bp_sendtype = 1, return;
bp_sendfromCode = item.Key,
type = item.Any(s => s.type == 2) ? 2 : item.Any(s => s.type == 1) ? 1 : 3,
bi_buyplandetail = new List<bi_buyplandetail>()
};
data.bi_buyplandetail = item.Select(s => new bi_buyplandetail
{
bd_count = s.quantity_actual > 0 ? s.quantity_actual : s.quantity_final_advise,
bd_price = s.unit_price,
bd_sku = s.bailun_sku
}).ToList();
//把采购数量没有填的都补上 建议采购数
conn.Execute(" update dc_auto_purchase_advise_detailed set quantity_actual=quantity_final_advise where quantity_actual<=0 and id in @ids ", new { ids = datas.Select(s => s.id).ToList() }, transaction);
var result = ApiServices.PushBuyPlan(data);
if (result.IsSuccessed)
{
// 把相关的采购明细都标记成已推送
conn.Execute(" update dc_auto_purchase_advise_detailed set ispush=1,plan_nos=@plan_nos,push_user_name=@push_user_name where id in @ids ", new { ids = item.Select(s => s.id).ToArray(), plan_nos = result.planNo, push_user_name = user.UserName });
} }
planNos.Add(result.planNo); List<string> planNos = new List<string>();
DateTime now = DateTime.Now;
// 查询未推送成功的采购建议的明细
var detailList = purchase_advise.BuyDetailList(datas.Select(s => s.id).ToList(), false);
foreach (var item in detailList.GroupBy(s => s.warehouse_code))
{
} mPlanToPurchaseDto data = new mPlanToPurchaseDto
{
bp_sendtype = 1,
bp_sendfromCode = item.Key,
type = item.Any(s => s.type == 2) ? 2 : item.Any(s => s.type == 1) ? 1 : 3,
bi_buyplandetail = new List<bi_buyplandetail>()
};
data.bi_buyplandetail = item.Select(s => new bi_buyplandetail
{
bd_count = s.quantity_actual > 0 ? s.quantity_actual : s.quantity_final_advise,
bd_price = s.unit_price,
bd_sku = s.bailun_sku
}).ToList();
//把采购数量没有填的都补上 建议采购数
conn.Execute(" update dc_auto_purchase_advise_detailed set quantity_actual=quantity_final_advise where quantity_actual<=0 and id in @ids ", new { ids = datas.Select(s => s.id).ToList() }, transaction);
var result = ApiServices.PushBuyPlan(data);
if (result.IsSuccessed)
{
// 把相关的采购明细都标记成已推送
conn.Execute(" update dc_auto_purchase_advise_detailed set ispush=1,plan_nos=@plan_nos,push_user_name=@push_user_name where id in @ids ", new { ids = item.Select(s => s.id).ToArray(), plan_nos = result.planNo, push_user_name = user.UserName });
}
planNos.Add(result.planNo);
//conn.Execute(" update dc_auto_purchase_advise set buy_sys_plan_no=CONCAT(buy_sys_plan_no,@buy_sys_plan_no),push_time=@push_time where where @detailed_ids ", new { buy_sys_plan_no = string.Join(",", planNos), push_time = now, detailed_ids = item.Select(s => s.id).ToArray() }, transaction); }
transaction.Commit(); //conn.Execute(" update dc_auto_purchase_advise set buy_sys_plan_no=CONCAT(buy_sys_plan_no,@buy_sys_plan_no),push_time=@push_time where where @detailed_ids ", new { buy_sys_plan_no = string.Join(",", planNos), push_time = now, detailed_ids = item.Select(s => s.id).ToArray() }, transaction);
}
catch (Exception)
{
transaction.Rollback(); transaction.Commit();
conn.Close(); }
throw; catch (Exception)
{
transaction.Rollback();
conn.Close();
throw;
}
} }
} }
} }
......
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