Commit e67052d9 by 泽锋 李

新增生产订单抓取的服务

parent 8f2d3b9a
...@@ -619,5 +619,34 @@ namespace AutoTurnOver.DB ...@@ -619,5 +619,34 @@ namespace AutoTurnOver.DB
//throw new Exception("平台费 接口异常: " + ex.StackTrace); //throw new Exception("平台费 接口异常: " + ex.StackTrace);
} }
} }
/// <summary>
/// 抓取生产系统订单
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static List<api_prod_order_response_dto.data_dto> GetProdOrder(api_prod_order_request_dto data)
{
try
{
//查询采购建议明细
string url = ConfigHelper.GetValue("prod-sys:order");
string resultStr = HttpHelper.Request(url+$"?page={data.page}&rows={data.rows}&btime={data.btime}&etime={data.etime}", RequestType.GET, "application/json", timeout: 1000 * 60 * 60 * 24);
var result = resultStr.ToObj<api_prod_order_response_dto>();
if (result == null)
{
return new List<api_prod_order_response_dto.data_dto>() { };
}
else
{
return result.data;
}
}
catch (Exception ex)
{
throw new Exception("pps sku 刊登状态接口异常: " + ex.Message);
throw new Exception("pps sku 刊登状态接口异常: " + ex.StackTrace);
}
}
} }
} }
using AutoTurnOver.Models;
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.DB
{
public class dc_base_prod_order_dao : connectionHelper
{
public static void SynchroData()
{
var task_name = "SynchroProdData_v1";
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(2015, 05, 14);
}
new_task_synchro_log.id = conn.Insert(new_task_synchro_log) ?? 0;
int count = 0;
var page = 1;
var rows = 1000;
while (true)
{
var datas = ApiUtility.GetProdOrder(new Models.ApiDto.api_prod_order_request_dto { btime = new_task_synchro_log.start_time, etime = new_task_synchro_log.end_time, page = page, rows = rows });
if (datas == null || datas.Count <= 0)
{
break;
}
page++;
foreach (var item in datas)
{
var db_data = new dc_base_prod_order()
{
gmt_modified_date = DateTime.Now,
is_delete = item.order_status == 1 ? 1 : 0,
prod_sys_id = item.sys_id,
purchase_no = item.purchase_no,
prod_sys_no = item.prod_order_no,
prod_last_update_date = item.last_update_date,
gmt_create_date = DateTime.Now
};
if (!string.IsNullOrWhiteSpace(item.pack_code) && item.pack_product_quantity > 0)
{
db_data.order_quantity = (item.product_quantity ?? 0) / item.pack_product_quantity.Value;
db_data.distribution_quantity = (item.product_distribution_quantity ?? 0) / item.pack_product_quantity.Value;
db_data.prod_quantity = (item.product_prod_quantity ?? 0) / item.pack_product_quantity.Value;
// 编码要看这俩编码哪一个能匹配上采购单的编码了
db_data.bailun_sku = item.pack_code;
// 如果通过订单编码查到了数据,则用订单编码
var pu_count = _connection.QueryFirstOrDefault<int?>(" select id from dc_base_purchase_details where purchase_id=@purchase_id and bailun_sku=@bailun_sku ",new {
purchase_id = db_data.purchase_no,
bailun_sku = item.pack_order_code
}) ??0;
if (pu_count > 0)
{
db_data.bailun_sku = item.pack_order_code;
}
}
else
{
db_data.order_quantity = item.product_quantity ?? 0;
db_data.distribution_quantity = item.product_distribution_quantity ?? 0;
db_data.prod_quantity = item.product_prod_quantity ?? 0;
db_data.bailun_sku = item.product_sku_code;
// 如果通过订单编码查到了数据,则用订单编码
var pu_count = _connection.QueryFirstOrDefault<int?>(" select id from dc_base_purchase_details where purchase_id=@purchase_id and bailun_sku=@bailun_sku ", new
{
purchase_id = db_data.purchase_no,
bailun_sku = item.product_order_code
}) ?? 0;
if (pu_count > 0)
{
db_data.bailun_sku = item.product_order_code;
}
}
if (db_data.order_quantity <= db_data.prod_quantity)
{
db_data.status = "生产完成";
}
else
{
var status = "";
if (db_data.order_quantity <= db_data.distribution_quantity)
{
status += " 完全分配 ";
}
else if (db_data.distribution_quantity > 0)
{
status += " 部分分配 ";
}
else
{
status += " 未分配 ";
}
if (db_data.prod_quantity > 0)
{
status += " 部分生产 ";
}
db_data.status = status;
}
var old_data = conn.QueryFirstOrDefault<dc_base_prod_order>(" select * from dc_base_prod_order where `purchase_no`=@purchase_no and bailun_sku=@bailun_sku ", new
{
purchase_no = db_data.purchase_no,
bailun_sku = db_data.bailun_sku,
});
if (old_data != null)
{
db_data.distribution_quantity = Math.Min(db_data.distribution_quantity, old_data.distribution_quantity);
db_data.prod_quantity = Math.Min(db_data.prod_quantity, old_data.prod_quantity);
conn.Update(db_data);
}
else
{
conn.Insert(db_data);
}
count++;
}
}
new_task_synchro_log.count = count;
new_task_synchro_log.status = 1;
conn.Update(new_task_synchro_log);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Models.ApiDto
{
public class api_prod_order_request_dto
{
public int page { get; set; }
public int rows { get; set; }
public DateTime btime { get; set; }
public DateTime etime { get; set; }
}
public class api_prod_order_response_dto
{
public bool success { get; set; }
public List<data_dto> data { get; set; }
public class data_dto
{
/// <summary>
/// 系统id
/// </summary>
public long sys_id { get; set; }
public DateTime last_update_date { get; set; }
public string purchase_no { get; set; }
public string prod_order_no { get; set; }
public decimal? product_prod_quantity { get; set; }
public decimal? product_distribution_quantity { get; set; }
public decimal? product_quantity { get; set; }
public decimal? pack_quantity { get; set; }
public decimal? pack_product_quantity { get; set; }
public string product_sku_code { get; set; }
public string product_order_code { get; set; }
public string pack_code { get; set; }
public string pack_order_code { get; set; }
/// <summary>
/// 1 = 删除
/// </summary>
public int order_status { get; set; }
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Models
{
/// <summary>
/// 生产系统订单
/// </summary>
public class dc_base_prod_order
{
public int id { get; set; }
public long prod_sys_id { get; set; }
public string bailun_sku { get; set; }
public decimal order_quantity { get; set; }
public string purchase_no { get; set; }
public string prod_sys_no { get; set; }
public decimal distribution_quantity { get; set; }
public decimal prod_quantity { get; set; }
public DateTime prod_last_update_date { get; set; }
public string status { get; set; }
public int is_delete { get; set; }
public DateTime gmt_create_date { get; set; }
public DateTime gmt_modified_date { get; set; }
}
}
...@@ -31,7 +31,7 @@ namespace ResetOutofstock ...@@ -31,7 +31,7 @@ namespace ResetOutofstock
//daily.ResetFbaExtendSales(DateTime.Now); //daily.ResetFbaExtendSales(DateTime.Now);
//dc_aims_transfer_warehouse_dao.TransferWarehouseTask(); //dc_aims_transfer_warehouse_dao.TransferWarehouseTask();
//daily.ResetFbaExtendReview(DateTime.Now); //daily.ResetFbaExtendReview(DateTime.Now);
} }
catch (Exception ex) catch (Exception ex)
......
...@@ -42,7 +42,7 @@ namespace ResetOutofstock ...@@ -42,7 +42,7 @@ namespace ResetOutofstock
Task.Factory.StartNew(() => Task.Factory.StartNew(() =>
{ {
Console.WriteLine($"开始 init ,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); Console.WriteLine($"开始 init ,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
//daily.ResetFbaExtendReview(DateTime.Now); //dc_base_prod_order_dao.SynchroData();
Console.WriteLine($"结束 init ,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); Console.WriteLine($"结束 init ,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
}); });
...@@ -65,6 +65,26 @@ namespace ResetOutofstock ...@@ -65,6 +65,26 @@ namespace ResetOutofstock
Thread.Sleep(10 * 60 * 1000); Thread.Sleep(10 * 60 * 1000);
} }
});
Task.Factory.StartNew(() =>
{
while (true)
{
try
{
Console.WriteLine($"开始 同步生产订单数据 ,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
dc_base_prod_order_dao.SynchroData();
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);
}
}); });
......
...@@ -29,5 +29,8 @@ ...@@ -29,5 +29,8 @@
"api_trans_temp_schedule": "http://api.wms.bailuntec.com/api/services/app/AllotScheduleService/GetTempSchedulePageList", "api_trans_temp_schedule": "http://api.wms.bailuntec.com/api/services/app/AllotScheduleService/GetTempSchedulePageList",
"pps-sys": { "pps-sys": {
"review": "https://pps.bailuntec.com/Api/amazon/analyze/Download/GetReviewInfoBy" "review": "https://pps.bailuntec.com/Api/amazon/analyze/Download/GetReviewInfoBy"
},
"prod-sys": {
"order": "http://mjzz.bailuntec.com/api/ApiOrderList"
} }
} }
...@@ -30,5 +30,8 @@ ...@@ -30,5 +30,8 @@
"api_trans_temp_schedule": "http://api.wms.bailuntec.com/api/services/app/AllotScheduleService/GetTempSchedulePageList", "api_trans_temp_schedule": "http://api.wms.bailuntec.com/api/services/app/AllotScheduleService/GetTempSchedulePageList",
"pps-sys": { "pps-sys": {
"review": "https://pps.bailuntec.com/Api/amazon/analyze/Download/GetReviewInfoBy" "review": "https://pps.bailuntec.com/Api/amazon/analyze/Download/GetReviewInfoBy"
},
"prod-sys": {
"order": "http://mjzz.bailuntec.com/api/ApiOrderList"
} }
} }
...@@ -29,5 +29,8 @@ ...@@ -29,5 +29,8 @@
"api_trans_temp_schedule": "http://api.wms.bailuntec.com/api/services/app/AllotScheduleService/GetTempSchedulePageList", "api_trans_temp_schedule": "http://api.wms.bailuntec.com/api/services/app/AllotScheduleService/GetTempSchedulePageList",
"pps-sys": { "pps-sys": {
"review": "https://pps.bailuntec.com/Api/amazon/analyze/Download/GetReviewInfoBy" "review": "https://pps.bailuntec.com/Api/amazon/analyze/Download/GetReviewInfoBy"
},
"prod-sys": {
"order": "http://mjzz.bailuntec.com/api/ApiOrderList"
} }
} }
\ 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