Commit faca4f00 by lizefeng

采购单推送,失败重试

parent 8a64c340
...@@ -506,7 +506,9 @@ and not EXISTS ( ...@@ -506,7 +506,9 @@ and not EXISTS (
)>0 )>0
) )
) -- 同属性仓库 (是否国内) 有库存,就不算 0库存 ) -- 同属性仓库 (是否国内) 有库存,就不算 0库存
and not exists ( select * from dc_auto_shortage_push where dc_auto_shortage_push.warehouse_code = t1.warehouse_code and dc_auto_shortage_push.bailun_sku = t1.bailun_sku and dc_auto_shortage_push.`type`=2 )"; and not exists ( select * from dc_auto_shortage_push where dc_auto_shortage_push.warehouse_code = t1.warehouse_code and dc_auto_shortage_push.bailun_sku = t1.bailun_sku and dc_auto_shortage_push.`type`=2 )
and not exists ( select * from dc_auto_shortage_push_not_config where dc_auto_shortage_push_not_config.warehouse_code=t1.warehouse_code and dc_auto_shortage_push_not_config.bailun_sku=t1.bailun_sku )
";
shortage_list.AddRange(conn.Query<dc_auto_shortage_push>(no_library_sql, commandTimeout: 0)); shortage_list.AddRange(conn.Query<dc_auto_shortage_push>(no_library_sql, commandTimeout: 0));
return shortage_list; return shortage_list;
...@@ -522,6 +524,15 @@ and not exists ( select * from dc_auto_shortage_push where dc_auto_shortage_push ...@@ -522,6 +524,15 @@ and not exists ( select * from dc_auto_shortage_push where dc_auto_shortage_push
} }
} }
public static void removeShortagePush(IEnumerable<int> datas)
{
var conn = _connection;
foreach (var item in datas)
{
conn.Delete<dc_auto_shortage_push>(item);
}
}
/// <summary> /// <summary>
...@@ -690,6 +701,7 @@ end ...@@ -690,6 +701,7 @@ end
var shortage_list = new List<dc_return_goods_push>(); var shortage_list = new List<dc_return_goods_push>();
// 回货速改推送 // 回货速改推送
string sql = @"select string sql = @"select
t1.id as 'shortage_push_id',
t1.bailun_sku, t1.bailun_sku,
t1.warehouse_code, t1.warehouse_code,
now() as 'push_time', now() as 'push_time',
......
...@@ -29,5 +29,10 @@ namespace AutoTurnOver.Models.ApiDto ...@@ -29,5 +29,10 @@ namespace AutoTurnOver.Models.ApiDto
/// 总页数 /// 总页数
/// </summary> /// </summary>
public int TotalPages { get; set; } public int TotalPages { get; set; }
/// <summary>
/// 失败sku
/// </summary>
public List<string> fail_skus { get; set; }
} }
} }
...@@ -8,6 +8,8 @@ namespace AutoTurnOver.Models ...@@ -8,6 +8,8 @@ namespace AutoTurnOver.Models
{ {
public int id { get; set; } public int id { get; set; }
public int shortage_push_id { get; set; }
public string bailun_sku { get; set; } public string bailun_sku { get; set; }
public string warehouse_code { get; set; } public string warehouse_code { get; set; }
......
...@@ -8,6 +8,7 @@ using System.Text; ...@@ -8,6 +8,7 @@ using System.Text;
using System.Linq; using System.Linq;
using AutoTurnOver.Models; using AutoTurnOver.Models;
using AutoTurnOver.DB; using AutoTurnOver.DB;
using System.Text.RegularExpressions;
namespace AutoTurnOver.Services namespace AutoTurnOver.Services
{ {
...@@ -137,16 +138,76 @@ namespace AutoTurnOver.Services ...@@ -137,16 +138,76 @@ namespace AutoTurnOver.Services
var result = resultStr.ToObj<BuyOutputResult>(); var result = resultStr.ToObj<BuyOutputResult>();
if (result == null) if (result == null)
{ {
throw new Exception("采购系统异常: 推送失败"); throw new Exception("采购系统异常: 推送失败,采购系统无响应");
} }
if (!result.IsSuccessed) if (!result.IsSuccessed)
{ {
// 提取异常sku
var skus = ExtractSku(result.Message);
if(skus!=null && skus.Count >= 1)
{
// 判断提取出来的sku 是否是我们想推送的sku ,但凡有一个不是我们想推送的,就抛异常
if(skus.Any(s=> !data.bi_buyplandetail.Any(sku => sku.bd_sku.Equals(s, StringComparison.OrdinalIgnoreCase))))
{
throw new Exception("采购系统异常:-------------采购系统抛出来的异常sku在源推送sku中未找到-------源异常消息: " + result.Message);
}
else
{
// 移除该sku,尝试重新推送
data.bi_buyplandetail = data.bi_buyplandetail.Where(s => !skus.Any(sku => sku.Equals(s.bd_sku))).ToList();
var re = PushBuyPlan(data);
if (re.fail_skus == null)
{
re.fail_skus = new List<string>();
}
re.fail_skus.AddRange(skus);
return re;
}
}
throw new Exception("采购系统异常: " + result.Message); throw new Exception("采购系统异常: " + result.Message);
} }
return result; return result;
} }
/// <summary> /// <summary>
/// 提取sku
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public static List<string> ExtractSku(string message)
{
if (!message.Contains("SKU") && !message.Contains("sku"))
{
return null;
}
else
{
Regex skuRegex = new Regex(@"【[\s\S]+】");
var skus = skuRegex.Matches(message);
if (skus != null && skus.Count == 1)
{
return skus[0].Value.Split(',').ToList();
}
else if (skus.Count > 1)
{
report.AddError(new dc_task_error_log
{
date = DateTime.Now,
message = "异常中包含多个【】,识别异常",
stack_trace = message,
task_name = "AutoPushBuySys_ExtractSku"
});
return null;
}
else
{
return null;
}
}
}
/// <summary>
/// 账号列表 /// 账号列表
/// </summary> /// </summary>
public static List<AccountDto> AccountList() public static List<AccountDto> AccountList()
......
using AutoTurnOver.DB; using AutoTurnOver.DB;
using AutoTurnOver.Models; using AutoTurnOver.Models;
using AutoTurnOver.Models.ApiDto; using AutoTurnOver.Models.ApiDto;
using Bailun.ServiceFabric.Core;
using Dapper; using Dapper;
using MySql.Data.MySqlClient; using MySql.Data.MySqlClient;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions;
namespace AutoTurnOver.Services namespace AutoTurnOver.Services
{ {
...@@ -144,10 +146,28 @@ namespace AutoTurnOver.Services ...@@ -144,10 +146,28 @@ namespace AutoTurnOver.Services
if (result.IsSuccessed) if (result.IsSuccessed)
{ {
//把采购数量没有填的都补上 建议采购数 //把采购数量没有填的都补上 建议采购数
connectionHelper._connection.Execute(" update dc_auto_purchase_advise_detailed set quantity_actual=quantity_final_advise where quantity_actual<=0 and id in @ids ", new { ids = item.Select(s => s.id).ToList() }); var sql = " update dc_auto_purchase_advise_detailed set quantity_actual=quantity_final_advise where quantity_actual<=0 and id in @ids ";
DynamicParameters parameters = new DynamicParameters();
parameters.Add("ids", item.Select(s => s.id).ToList());
if(result.fail_skus!=null && result.fail_skus.Count >= 1)
{
sql += " and bailun_sku not in @bailunSku ";
parameters.Add("bailunSku", result.fail_skus.ToList());
}
connectionHelper._connection.Execute(sql, parameters);
// 把相关的采购明细都标记成已推送 // 把相关的采购明细都标记成已推送
connectionHelper._connection.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 }); var sql2 = " update dc_auto_purchase_advise_detailed set ispush=1,plan_nos=@plan_nos,push_user_name=@push_user_name where id in @ids ";
DynamicParameters parameters2 = new DynamicParameters();
parameters2.Add("ids", item.Select(s => s.id).ToArray());
parameters2.Add("plan_nos", result.planNo);
parameters2.Add("push_user_name", user.UserName);
if (result.fail_skus != null && result.fail_skus.Count >= 1)
{
sql2 += " and bailun_sku not in @bailunSku ";
parameters2.Add("bailunSku", result.fail_skus.ToList());
}
connectionHelper._connection.Execute(sql2, parameters2);
} }
planNos.Add(result.planNo); planNos.Add(result.planNo);
...@@ -169,27 +189,67 @@ namespace AutoTurnOver.Services ...@@ -169,27 +189,67 @@ namespace AutoTurnOver.Services
{ {
// 生产jit采购建议 // 生产jit采购建议
var mainID = purchase_advise.ImportJITShortageDetailed(0); var mainID = purchase_advise.ImportJITShortageDetailed(0);
List<dc_auto_purchase_advise_detailed_dto> datas = new List<dc_auto_purchase_advise_detailed_dto>();
try try
{ {
List<dc_auto_purchase_advise_detailed_dto> datas = new List<dc_auto_purchase_advise_detailed_dto>();
// 推送 张莹霞 广州01 仓的数据 // 推送 张莹霞 广州01 仓的数据
var total = 0; var total = 0;
datas.AddRange(PurchaseAdviseServices.DetailList(new dc_auto_purchase_advise_detailed_search_dto { main_id = mainID, end_date = DateTime.Now,start_date = DateTime.Now, ispush = false,purchase_user="张莹霞",warehouse_code= "GZBLWH" }, 0, int.MaxValue, ref total)); datas.AddRange(PurchaseAdviseServices.DetailList(new dc_auto_purchase_advise_detailed_search_dto { main_id = mainID, end_date = DateTime.Now, start_date = DateTime.Now, ispush = false, purchase_user = "张莹霞", warehouse_code = "GZBLWH" }, 0, int.MaxValue, ref total));
datas.AddRange(PurchaseAdviseServices.DetailList(new dc_auto_purchase_advise_detailed_search_dto { main_id = mainID, end_date = DateTime.Now, start_date = DateTime.Now, ispush = false, purchase_user = "张莹霞1", warehouse_code = "GZBLWH" }, 0, int.MaxValue, ref total)); datas.AddRange(PurchaseAdviseServices.DetailList(new dc_auto_purchase_advise_detailed_search_dto { main_id = mainID, end_date = DateTime.Now, start_date = DateTime.Now, ispush = false, purchase_user = "张莹霞1", warehouse_code = "GZBLWH" }, 0, int.MaxValue, ref total));
PurchaseAdviseServices.PushBuySys(datas, new UserData { UserName = "admin" }); PurchaseAdviseServices.PushBuySys(datas, new UserData { UserName = "admin" });
} }
catch (Exception ex) catch (Exception ex)
{ {
report.AddError(new dc_task_error_log { report.AddError(new dc_task_error_log
date =DateTime.Now, {
date = DateTime.Now,
message = ex.Message, message = ex.Message,
stack_trace = ex.StackTrace, stack_trace = datas.ToJson(),
task_name = "AutoPushBuySys" task_name = "AutoPushBuySys"
}); });
Console.WriteLine(ex.Message); Console.WriteLine(ex.Message);
}
} }
/// <summary>
/// 提取sku
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public static List<string> ExtractSku(string message)
{
if (!message.Contains("SKU") && !message.Contains("sku"))
{
return null;
}
else
{
Regex skuRegex = new Regex(@"【[\s\S]+】");
var skus = skuRegex.Matches(message);
if (skus != null && skus.Count == 1)
{
return skus[0].Value.Split(',').ToList();
}
else if (skus.Count > 1)
{
report.AddError(new dc_task_error_log
{
date = DateTime.Now,
message = "异常中包含多个【】,识别异常",
stack_trace = message,
task_name = "AutoPushBuySys_ExtractSku"
});
return null;
}
else
{
return null;
}
}
} }
} }
} }
...@@ -461,6 +461,8 @@ namespace AutoTurnOver.Services ...@@ -461,6 +461,8 @@ namespace AutoTurnOver.Services
// 记录推送状态 // 记录推送状态
report.AddReturnGoodsPush(datas.Where(s => !err_datas.Any(e => e.warehouseCode == s.warehouse_code && s.bailun_sku == e.sku))); report.AddReturnGoodsPush(datas.Where(s => !err_datas.Any(e => e.warehouseCode == s.warehouse_code && s.bailun_sku == e.sku)));
// 移除缺货改零记录 (如果以后再没有库存,继续改零)
report.removeShortagePush(datas.Where(s => !err_datas.Any(e => e.warehouseCode == s.warehouse_code && s.bailun_sku == e.sku)).Select(s=>s.shortage_push_id));
} }
......
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