Commit 78704e11 by 泽锋 李

新增同步采购临时数据的服务

parent 84658090
...@@ -138,7 +138,7 @@ namespace AutoTurnOver.DB ...@@ -138,7 +138,7 @@ namespace AutoTurnOver.DB
var result = resultStr.ToObj<api_platform_fee_result_dto>(); var result = resultStr.ToObj<api_platform_fee_result_dto>();
if (result == null) if (result == null)
{ {
return new api_platform_fee_result_dto.result_dto() {}; return new api_platform_fee_result_dto.result_dto() { };
} }
else else
{ {
...@@ -163,11 +163,11 @@ namespace AutoTurnOver.DB ...@@ -163,11 +163,11 @@ namespace AutoTurnOver.DB
{ {
//查询采购建议明细 //查询采购建议明细
string url = ConfigHelper.GetValue("api_plat_category"); string url = ConfigHelper.GetValue("api_plat_category");
string resultStr = HttpHelper.Request(url+ $"?plat={data.plat}&site={data.site}", RequestType.GET, timeout: 1000 * 60 * 60 * 24); string resultStr = HttpHelper.Request(url + $"?plat={data.plat}&site={data.site}", RequestType.GET, timeout: 1000 * 60 * 60 * 24);
var result = resultStr.ToObj<api_platform_category_result_dto>(); var result = resultStr.ToObj<api_platform_category_result_dto>();
if (result == null) if (result == null)
{ {
return new List<api_plat_category_dto>(){ } ; return new List<api_plat_category_dto>() { };
} }
else else
{ {
...@@ -204,7 +204,7 @@ namespace AutoTurnOver.DB ...@@ -204,7 +204,7 @@ namespace AutoTurnOver.DB
//查询采购建议明细 //查询采购建议明细
string url = ConfigHelper.GetValue("ApiLogisticsGetFilterLogisticsAssignLine"); string url = ConfigHelper.GetValue("ApiLogisticsGetFilterLogisticsAssignLine");
string resultStr = HttpHelper.Request(url+ parameter_str, RequestType.GET, timeout: 1000 * 60 * 60 * 24); string resultStr = HttpHelper.Request(url + parameter_str, RequestType.GET, timeout: 1000 * 60 * 60 * 24);
var result = resultStr.ToObj<api_logistic_query_result_dto>(); var result = resultStr.ToObj<api_logistic_query_result_dto>();
if (result == null || result.Data == null || result.Data.successLines == null || result.Data.successLines.Count <= 0) if (result == null || result.Data == null || result.Data.successLines == null || result.Data.successLines.Count <= 0)
{ {
...@@ -295,13 +295,13 @@ namespace AutoTurnOver.DB ...@@ -295,13 +295,13 @@ namespace AutoTurnOver.DB
/// 抓取供应商列表 /// 抓取供应商列表
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public static List<api_supplier_dto.data_dto> getSupplierList(int page,DateTime start,DateTime end) public static List<api_supplier_dto.data_dto> getSupplierList(int page, DateTime start, DateTime end)
{ {
try try
{ {
//查询采购建议明细 //查询采购建议明细
string url = ConfigHelper.GetValue("supplier_sys:list"); string url = ConfigHelper.GetValue("supplier_sys:list");
string resultStr = HttpHelper.Request(url+ $"?page={page}&start={start}&end={end}", RequestType.POST); string resultStr = HttpHelper.Request(url + $"?page={page}&start={start}&end={end}", RequestType.POST);
var result = resultStr.ToObj<api_supplier_dto>(); var result = resultStr.ToObj<api_supplier_dto>();
if (result == null) if (result == null)
{ {
...@@ -462,7 +462,7 @@ namespace AutoTurnOver.DB ...@@ -462,7 +462,7 @@ namespace AutoTurnOver.DB
{ {
//查询采购建议明细 //查询采购建议明细
string url = ConfigHelper.GetValue("api_lms_order_transfer_sku"); string url = ConfigHelper.GetValue("api_lms_order_transfer_sku");
string resultStr = HttpHelper.Request(url , RequestType.POST, data.ToJson(),entype: "application/json; charset=utf-8", timeout: 1000 * 60 * 60 * 24); string resultStr = HttpHelper.Request(url, RequestType.POST, data.ToJson(), entype: "application/json; charset=utf-8", timeout: 1000 * 60 * 60 * 24);
var result = resultStr.ToObj<List<api_lms_order_transfer_sku_dto>>(); var result = resultStr.ToObj<List<api_lms_order_transfer_sku_dto>>();
if (result == null) if (result == null)
{ {
...@@ -490,7 +490,7 @@ namespace AutoTurnOver.DB ...@@ -490,7 +490,7 @@ namespace AutoTurnOver.DB
{ {
//查询采购建议明细 //查询采购建议明细
string url = ConfigHelper.GetValue("api_lms_order_transfer_sku_avg"); string url = ConfigHelper.GetValue("api_lms_order_transfer_sku_avg");
string resultStr = HttpHelper.Request(url , RequestType.POST, data.ToJson(),entype: "application/json; charset=utf-8", timeout: 1000 * 60 * 60 * 24); string resultStr = HttpHelper.Request(url, RequestType.POST, data.ToJson(), entype: "application/json; charset=utf-8", timeout: 1000 * 60 * 60 * 24);
var result = resultStr.ToObj<List<api_avg_days_dto>>(); var result = resultStr.ToObj<List<api_avg_days_dto>>();
if (result == null) if (result == null)
{ {
...@@ -520,14 +520,15 @@ namespace AutoTurnOver.DB ...@@ -520,14 +520,15 @@ namespace AutoTurnOver.DB
{ {
//查询采购建议明细 //查询采购建议明细
string url = ConfigHelper.GetValue("api_finance_body"); string url = ConfigHelper.GetValue("api_finance_body");
string resultStr = HttpHelper.Request(url , RequestType.POST, new { modify_time_start = new DateTime(2001,1,1), modify_time_end = DateTime.Now.AddDays(1)}.ToJson(),entype: "application/json; charset=utf-8", timeout: 1000 * 60 * 60 * 24); string resultStr = HttpHelper.Request(url, RequestType.POST, new { modify_time_start = new DateTime(2001, 1, 1), modify_time_end = DateTime.Now.AddDays(1) }.ToJson(), entype: "application/json; charset=utf-8", timeout: 1000 * 60 * 60 * 24);
var result = resultStr.ToObj<api_finance_body_dto>(); var result = resultStr.ToObj<api_finance_body_dto>();
if (result == null) if (result == null)
{ {
throw new Exception("付款主体抓取异常"); throw new Exception("付款主体抓取异常");
}else if (result.Success==false) }
else if (result.Success == false)
{ {
throw new Exception("付款主体抓取异常:"+result.Message); throw new Exception("付款主体抓取异常:" + result.Message);
} }
else else
{ {
...@@ -540,5 +541,47 @@ namespace AutoTurnOver.DB ...@@ -540,5 +541,47 @@ namespace AutoTurnOver.DB
throw new Exception("财务系统 付款主体抓取异常 接口异常: " + ex.StackTrace); throw new Exception("财务系统 付款主体抓取异常 接口异常: " + ex.StackTrace);
} }
} }
/// <summary>
/// 获取调拨单临时数据
/// </summary>
/// <returns></returns>
public static List<api_temp_schedule_response_dto.item_dto> GetTransOrderTempSchedule(DateTime btime, DateTime etime, int page)
{
try
{
//查询采购建议明细
string url = ConfigHelper.GetValue("api_trans_temp_schedule");
string resultStr = HttpHelper.Request(url, RequestType.POST, new
{
Data = new
{
Code = "",
StartTime = btime.ToString("yyyy-MM-dd HH:mm:ss"),
EndTime = etime.ToString("yyyy-MM-dd HH:mm:ss"),
Page = new
{
page = page,
rows = 100
}
}
}.ToJson(), entype: "application/json; charset=utf-8", timeout: 1000 * 60 * 60 * 24);
var result = resultStr.ToObj<api_temp_schedule_response_dto>();
if (result == null)
{
return new List<api_temp_schedule_response_dto.item_dto> { };
}
else
{
return result.data.items;
}
}
catch (Exception ex)
{
return new List<api_temp_schedule_response_dto.item_dto>();
//throw new Exception("lms 调拨单时效 接口异常: " + ex.Message);
//throw new Exception("lms 调拨单时效 接口异常: " + ex.StackTrace);
}
}
} }
} }
using AutoTurnOver.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AutoTurnOver.DB
{
public class dc_base_trans_temp_schedule_dao : connectionHelper
{
/// <summary>
/// 从调拨系统同步数据
/// </summary>
public static void SynchroTransTempScheduleData()
{
var task_name = "SynchroTransTempScheduleData";
var conn = _connection;
// 查询最后一次成功抓取的记录
var last_task_synchro_log = conn.QuerySingleOrDefault<task_synchro_log>(" select * from task_synchro_log where task_name=@task_name and status=1 order by end_time desc limit 1 ", new { task_name = task_name });
var new_task_synchro_log = new task_synchro_log
{
create_date = DateTime.Now,
end_time = DateTime.Now,
status = 0,
task_name = task_name
};
if (last_task_synchro_log != null)
{
new_task_synchro_log.start_time = last_task_synchro_log.end_time.AddMinutes(-1);
}
else
{
new_task_synchro_log.start_time = new DateTime(2001, 05, 14);
}
new_task_synchro_log.id = conn.Insert(new_task_synchro_log) ?? 0;
int count = 0;
var page = 1;
var data_skus = new List<dc_base_trans_temp_schedule>();
while (true)
{
var datas = ApiUtility.GetTransOrderTempSchedule(new_task_synchro_log.start_time, new_task_synchro_log.end_time, page);
if (datas == null || datas.Count <= 0)
{
break;
}
page++;
foreach (var item in datas)
{
foreach (var itemSku in item.allotScheduleProducts)
{
var db_data = new dc_base_trans_temp_schedule()
{
code = item.code ?? "",
creater_name = item.createrName,
data_id = item.purchaseCode + "-" + itemSku.sku,
create_time = item.createTime,
sku = itemSku.sku,
gmt_create_date = DateTime.Now,
gmt_update_date = DateTime.Now,
is_aims = item.isAims == true ? 1 : 0,
is_delete = item.isDeleted == true ? 1 : 0,
is_temp_data = item.isTempData == true ? 1 : 0,
is_exception = item.IsException == true ? 1 : 0,
product_name = itemSku.productName,
product_num = itemSku.productNum,
purchase_code = item.purchaseCode,
sku_ware_no = $"{itemSku.sku}{item.targetWareNo}",
source_ware_name = item.sourceWareName,
source_ware_no = item.sourceWareNo,
status = 0,
target_ware_name = item.targetWareName,
target_ware_no = item.targetWareNo,
time_stamp = DateTime.Now
};
data_skus.Add(db_data);
db_data.id = conn.QueryFirstOrDefault<int?>(" select id from dc_base_trans_temp_schedule where `purchase_code`=@purchase_code and `sku`=@sku ", new { sku = db_data.sku, purchase_code = db_data.purchase_code }) ?? 0;
if (db_data.id > 0)
{
conn.Update(db_data);
}
else
{
conn.Insert(db_data);
}
count++;
}
}
}
if (data_skus != null && data_skus.Count >= 1)
{
// 计算相关sku的总在途
var temp_datas = _connection.Query<temp_sum_dto>(@"select sku_ware_no,sku as 'bailun_sku',target_ware_no as 'warehouse_code',sum(product_num) as 'count' from dc_base_trans_temp_schedule
where is_delete=0 and is_temp_data=1 and is_exception=0
and sku_ware_no in @sku_ware_nos
GROUP BY sku_ware_no", new { sku_ware_nos = data_skus.Select(s=>s.sku_ware_no).Distinct().ToList() });
foreach (var item in temp_datas)
{
_connection.Execute("update dc_mid_transit set quantity_transfer_temp_schedule=@quantity_transfer_temp_schedule where bailun_sku=@bailun_sku and warehouse_code=@warehouse_code ", new
{
bailun_sku = item.bailun_sku,
warehouse_code = item.warehouse_code,
quantity_transfer_temp_schedule = item.count
});
}
var data_0 = data_skus.Where(s => !temp_datas.Any(v => v.sku_ware_no == s.sku_ware_no)).ToList();
if (data_0 != null && data_0.Count>=1)
{
foreach (var item in data_0.Select(s=>new { s.sku,s.target_ware_no}).Distinct())
{
_connection.Execute("update dc_mid_transit set quantity_transfer_temp_schedule=0 where bailun_sku=@bailun_sku and warehouse_code=@warehouse_code ", new
{
bailun_sku = item.sku,
warehouse_code = item.target_ware_no
});
}
}
}
new_task_synchro_log.count = count;
new_task_synchro_log.status = 1;
conn.Update(new_task_synchro_log);
}
public class temp_sum_dto
{
public string sku_ware_no { get; set; }
public string bailun_sku { get; set; }
public string warehouse_code { get; set; }
public int count { get; set; }
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Models.ApiDto
{
public class api_temp_schedule_response_dto
{
public bool isSuccess { get; set; }
public string message { get; set; }
public data_dto data { get; set; }
public class data_dto
{
public List<item_dto> items { get; set; }
}
public class item_dto
{
public string code { get; set; }
public string purchaseCode { get; set; }
public string sourceWareName { get; set; }
public string sourceWareNo { get; set; }
public string targetWareName { get; set; }
public string targetWareNo { get; set; }
public bool? isLockedPosition { get; set; }
public string isLockedPocreaterNamesition { get; set; }
public DateTime createTime { get; set; }
public string createrName { get; set; }
/// <summary>
/// 是否临时数据
/// </summary>
public bool isTempData { get; set; }
/// <summary>
/// 是否合并单
/// </summary>
public bool isMerge { get; set; }
/// <summary>
/// 是否删除
/// </summary>
public bool isDeleted { get; set; }
/// <summary>
/// 是否异常
/// </summary>
public bool? IsException { get; set; }
/// <summary>
/// 是否aims
/// </summary>
public bool isAims { get; set; }
public DateTime timeStamp { get; set; }
public string remarks { get; set; }
public List<sku_dto> allotScheduleProducts { get; set; }
public class sku_dto
{
public string sku { get; set; }
public string productName { get; set; }
public int productNum { get; set; }
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Models
{
public class dc_base_trans_temp_schedule
{
public int id { get; set; }
public string code { get; set; }
public string purchase_code { get; set; }
/// <summary>
/// sku+仓库
/// </summary>
public string sku_ware_no { get; set; }
public string source_ware_name { get; set; }
public string source_ware_no { get; set; }
public string target_ware_name { get; set; }
public string target_ware_no { get; set; }
public int is_exception { get; set; }
public string creater_name { get; set; }
public DateTime create_time { get; set; }
public int is_aims { get; set; }
public int is_temp_data { get; set; }
public int is_delete { get; set; }
public DateTime time_stamp { get; set; }
public string sku { get; set; }
public string product_name { get; set; }
public int product_num { get; set; }
public string data_id { get; set; }
public int status { get; set; }
public DateTime gmt_create_date { get; set; }
public DateTime gmt_update_date { get; set; }
}
}
...@@ -25,6 +25,7 @@ namespace ResetOutofstock ...@@ -25,6 +25,7 @@ namespace ResetOutofstock
//report.ResetLastweekData(); //report.ResetLastweekData();
//report.ResetOmsOutofstock(); //report.ResetOmsOutofstock();
//report.PurchaseWeekBackUp(); //report.PurchaseWeekBackUp();
} }
catch (Exception ex) catch (Exception ex)
{ {
......
...@@ -49,6 +49,23 @@ namespace ResetOutofstock ...@@ -49,6 +49,23 @@ namespace ResetOutofstock
Task.Factory.StartNew(() => Task.Factory.StartNew(() =>
{ {
try
{
Console.WriteLine($"开始 同步调拨 采购临时数据 ,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
dc_base_trans_temp_schedule_dao.SynchroTransTempScheduleData();
Console.WriteLine($"结束 同步调拨 采购临时数据 ,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
Thread.Sleep(10 * 60 * 1000);
});
Task.Factory.StartNew(() =>
{
while (true) while (true)
{ {
try try
......
...@@ -25,5 +25,6 @@ ...@@ -25,5 +25,6 @@
"supplier_sys": { "supplier_sys": {
"list": "http://supplier.bailuntec.com/Api/ListSupplierAllByTime" "list": "http://supplier.bailuntec.com/Api/ListSupplierAllByTime"
}, },
"api_finance_body": "http://cw.bailuntec.com/API/API/GetCompanyMainBody" "api_finance_body": "http://cw.bailuntec.com/API/API/GetCompanyMainBody",
"api_trans_temp_schedule": "http://api.wms.bailuntec.com/api/services/app/AllotScheduleService/GetTempSchedulePageList"
} }
...@@ -26,5 +26,6 @@ ...@@ -26,5 +26,6 @@
"supplier_sys": { "supplier_sys": {
"list": "http://supplier.bailuntec.com/Api/ListSupplierAllByTime" "list": "http://supplier.bailuntec.com/Api/ListSupplierAllByTime"
}, },
"api_finance_body": "http://cw.bailuntec.com/API/API/GetCompanyMainBody" "api_finance_body": "http://cw.bailuntec.com/API/API/GetCompanyMainBody",
"api_trans_temp_schedule": "http://api.wms.bailuntec.com/api/services/app/AllotScheduleService/GetTempSchedulePageList"
} }
...@@ -25,5 +25,6 @@ ...@@ -25,5 +25,6 @@
"supplier_sys": { "supplier_sys": {
"list": "http://supplier.bailuntec.com/Api/ListSupplierAllByTime" "list": "http://supplier.bailuntec.com/Api/ListSupplierAllByTime"
}, },
"api_finance_body": "http://cw.bailuntec.com/API/API/GetCompanyMainBody" "api_finance_body": "http://cw.bailuntec.com/API/API/GetCompanyMainBody",
"api_trans_temp_schedule": "http://api.wms.bailuntec.com/api/services/app/AllotScheduleService/GetTempSchedulePageList"
} }
\ No newline at end of file
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