Commit 30e1a7db by 泽锋 李

新增供应商数据同步服务

parent 00638f53
...@@ -262,5 +262,33 @@ namespace AutoTurnOver.DB ...@@ -262,5 +262,33 @@ namespace AutoTurnOver.DB
throw new Exception("pps 供应商节假日接口异常: " + ex.StackTrace); throw new Exception("pps 供应商节假日接口异常: " + ex.StackTrace);
} }
} }
/// <summary>
/// 抓取供应商列表
/// </summary>
/// <returns></returns>
public static List<api_supplier_dto.data_dto> getSupplierList(int page,DateTime start,DateTime end)
{
try
{
//查询采购建议明细
string url = ConfigHelper.GetValue("supplier_sys:list");
string resultStr = HttpHelper.Request(url+ $"?page={page}&start={start}&end={end}", RequestType.POST);
var result = resultStr.ToObj<api_supplier_dto>();
if (result == null)
{
return new List<api_supplier_dto.data_dto>();
}
else
{
return result.data;
}
}
catch (Exception ex)
{
throw new Exception("供应商 list 接口异常: " + ex.Message);
throw new Exception("供应商 list 接口异常: " + ex.StackTrace);
}
}
} }
} }
...@@ -127,5 +127,7 @@ left join dc_auto_sales as t2 on t1.bailun_sku = t2.bailun_sku and t1.warehouse_ ...@@ -127,5 +127,7 @@ left join dc_auto_sales as t2 on t1.bailun_sku = t2.bailun_sku and t1.warehouse_
} }
return _connection.Page<api_sku_tort_dto>(sql, search, parameters); return _connection.Page<api_sku_tort_dto>(sql, search, parameters);
} }
} }
} }
...@@ -1777,5 +1777,102 @@ and start_date<=@end_date and end_date>=@start_date ...@@ -1777,5 +1777,102 @@ and start_date<=@end_date and end_date>=@start_date
#endregion #endregion
#region 退货规则配置
public static List<dc_auto_return_goods_config_dto> ReturnGoodsConfigPage(dc_auto_return_goods_config_search_dto m, int offset, int limit, ref int total)
{
var list = new List<dc_auto_return_goods_config_dto>();
try
{
var sql = @"select t1.*,t2.warehouse_name from dc_auto_return_goods_config as t1
left join dc_base_warehouse as t2 on t1.warehouse_code = t2.warehouse_code
where 1 = 1 ";
DynamicParameters parameters = new DynamicParameters();
if (!string.IsNullOrWhiteSpace(m.warehousetype))
{
sql += " and t2.hq_type=@warehousetype";
parameters.Add("warehousetype", m.warehousetype);
}
if (m.warehousearea > 0)
{
sql += " and t2.area_id=" + m.warehousearea;
}
if (m.warehouse_code != null)
{
sql += $" and t1.warehouse_code=@warehouse_code ";
parameters.Add("warehouse_code", m.warehouse_code);
}
if (!string.IsNullOrWhiteSpace(m.supplier_name))
{
sql += " and t3.suppliers_name =@suppliers_name ";
parameters.Add("suppliers_name", m.supplier_name);
}
if (m.has_no_library != null)
{
sql += " and t1.has_no_library=" + m.has_no_library;
}
if (m.has_return > 0)
{
sql += " and t1.has_return=" + m.has_return;
}
if (m.status > 0)
{
sql += " and t1.status=" + m.status;
}
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1", parameters);
var obj = _connection.Query<dc_auto_return_goods_config_dto>(sql + " limit " + offset + "," + limit, parameters);
return obj.AsList();
}
catch (Exception)
{
return list;
}
}
//public static string SaveReturnGoodsConfig(dc_auto_return_goods_config m)
//{
// try
// {
// var commData = companyList.SingleOrDefault(s => m.company_code.Equals(s.Company_Code));
// if (commData == null)
// {
// throw new Exception("系统异常 供应商不存在");
// }
// m.company_name = commData.Company_Name;
// if (m.id > 0)
// {
// var result = _connection.Update<dc_report_logistics_company_config>(m);
// return result > 0 ? "" : "保存异常,请重试!";
// }
// else
// {
// var result = _connection.Insert<dc_report_logistics_company_config>(m);
// return result.HasValue && result.Value > 0 ? "" : "提交异常,请重试!";
// }
// }
// catch (Exception ex)
// {
// return ex.Message;
// }
//}
//public static dc_report_logistics_company_config GetLogisticsCompanyConfigById(int id)
//{
// return _connection.QueryFirstOrDefault<dc_report_logistics_company_config>("select * from dc_report_logistics_company_config where id=" + id);
//}
#endregion
} }
} }
using AutoTurnOver.Models;
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.DB
{
public class dc_base_supplier_dao : connectionHelper
{
public static void SynchroBailunSupplier()
{
var task_name = "SynchroBailunSupplier";
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;
while (true)
{
var datas = ApiUtility.getSupplierList(page, new_task_synchro_log.start_time, new_task_synchro_log.end_time);
if (datas == null || datas.Count <= 0)
{
break;
}
page++;
foreach (var item in datas)
{
var db_data = new dc_base_supplier()
{
isaccept_refund = item.isaccept_refund??0,
isdaytakeinstore =item.isdaytakeinstore??0,
name = item.name,
nostock =item.nostock??0,
sup_id = item.id,
sup_value =item.value
};
db_data.id = conn.QueryFirstOrDefault<int?>(" select id from dc_base_supplier where `sup_id`=@sup_id ", new { sup_id = db_data.sup_id }) ?? 0;
if (db_data.id > 0)
{
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_supplier_dto
{
public bool success { get; set; }
public string msg { get; set; }
public List<data_dto> data { get; set; }
public class data_dto
{
public int id { get; set; }
public string name { get; set; }
public int value { get; set; }
/// <summary>
/// 是否无库
/// </summary>
public int? nostock { get; set; }
/// <summary>
/// 是否支持退货
/// </summary>
public int? isaccept_refund { get; set; }
/// <summary>
/// 是否自提
/// </summary>
public int? isdaytakeinstore { get; set; }
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Models
{
/// <summary>
/// 退货规则
/// </summary>
public class dc_auto_return_goods_config
{
public int id { get; set; }
public string title { get; set; }
public string warehouse_code { get; set; }
public int suppliers_id { get; set; }
public string suppliers_name { get; set; }
public int has_return { get; set; }
public int has_no_library { get; set; }
public decimal first_inbound_days_min { get; set; }
public decimal first_inbound_days_max { get; set; }
public int sales_days_1 { get; set; }
public decimal sales_weight_1 { get; set; }
public decimal sales_days_2 { get; set; }
public decimal sales_weight_2 { get; set; }
public decimal sales_average_upper_limit { get; set; }
public DateTime create_date { get; set; }
public string create_user { get; set; }
public DateTime delete_date { get; set; }
public string delete_user { get; set; }
/// <summary>
/// 0 =正常 -1= 删除 1 =审核通过 -2 = 驳回 3= 已推送
/// </summary>
public int status { get; set; }
}
public class dc_auto_return_goods_config_dto: dc_auto_return_goods_config
{
public string status_str
{ get
{
return ((dc_auto_return_goods_config_status_enum)status).ToString();
} }
/// <summary>
/// 仓库名称
/// </summary>
public string warehouse_name { get; set; }
/// <summary>
/// 供应商
/// </summary>
public string suppliers_name { get; set; }
public string rule_str { get
{
return $" 过去 {sales_days_1} 天销量 * {sales_weight_1} +过去 {sales_days_2} 天销量 * {sales_weight_2} < {sales_average_upper_limit} ";
} }
}
public class dc_auto_return_goods_config_search_dto
{
public string warehouse_code { get; set; }
public string warehousetype { get; set; }
public int? warehousearea { get; set; }
/// <summary>
/// 供应商
/// </summary>
public string supplier_name { get; set; }
public int? has_return { get; set; }
public int? has_no_library { get; set; }
public int? status { get; set; }
}
public enum dc_auto_return_goods_config_status_enum
{
正常 = 0,
删除 = -1,
审核通过 = 1,
驳回 = -2,
已推送 = 2
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Models
{
public class dc_base_supplier
{
public int id { get; set; }
public string name { get; set; }
public int sup_id { get; set; }
public int sup_value { get; set; }
/// <summary>
/// 是否无库
/// </summary>
public int nostock { get; set; }
/// <summary>
/// 是否支持退货
/// </summary>
public int isaccept_refund { get; set; }
/// <summary>
/// 是否自提
/// </summary>
public int isdaytakeinstore { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Models
{
public class task_synchro_log
{
public int id { get; set; }
public string task_name { get; set; }
public DateTime start_time { get; set; }
public DateTime end_time { get; set; }
/// <summary>
/// 0 = 抓取中 1 = 已完成
/// </summary>
public int status { get; set; }
public int count { get; set; }
public DateTime create_date { get; set; }
}
}
...@@ -17,6 +17,7 @@ namespace ResetOutofstock ...@@ -17,6 +17,7 @@ namespace ResetOutofstock
{ {
var now = DateTime.Now; var now = DateTime.Now;
//base_supplier_holiday_time_dao.SynchroData(); //base_supplier_holiday_time_dao.SynchroData();
//report.ResetCashFlowData(); //report.ResetCashFlowData();
//report.StockWeekBackUp(); //report.StockWeekBackUp();
......
...@@ -75,6 +75,26 @@ namespace ResetOutofstock ...@@ -75,6 +75,26 @@ namespace ResetOutofstock
{ {
try try
{ {
Console.WriteLine($"开始 同步供应商数据,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
dc_base_supplier_dao.SynchroBailunSupplier();
Console.WriteLine($"结束 同步供应商数据,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Thread.Sleep(60 * 60 * 1000);
}
});
Task.Factory.StartNew(() =>
{
while (true)
{
try
{
Console.WriteLine($"开始 同步半成品库存数据,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); Console.WriteLine($"开始 同步半成品库存数据,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
wip_stock_dao.Synchronization(); wip_stock_dao.Synchronization();
Console.WriteLine($"结束 同步半成品库存数据,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); Console.WriteLine($"结束 同步半成品库存数据,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
......
...@@ -20,5 +20,8 @@ ...@@ -20,5 +20,8 @@
}, },
"distribution_sys": { "distribution_sys": {
"getSupplierHolidayTimes": "http://pps.bailuntec.com/distributionapi/Manager/SupplierAssessmentData/getSupplierHolidayTimes" "getSupplierHolidayTimes": "http://pps.bailuntec.com/distributionapi/Manager/SupplierAssessmentData/getSupplierHolidayTimes"
},
"supplier_sys": {
"list": "http://supplier.bailuntec.com/Api/ListSupplierAllByTime"
} }
} }
...@@ -21,5 +21,8 @@ ...@@ -21,5 +21,8 @@
}, },
"distribution_sys": { "distribution_sys": {
"getSupplierHolidayTimes": "http://pps.bailuntec.com/distributionapi/Manager/SupplierAssessmentData/getSupplierHolidayTimes" "getSupplierHolidayTimes": "http://pps.bailuntec.com/distributionapi/Manager/SupplierAssessmentData/getSupplierHolidayTimes"
},
"supplier_sys": {
"list": "http://supplier.bailuntec.com/Api/ListSupplierAllByTime"
} }
} }
...@@ -20,5 +20,8 @@ ...@@ -20,5 +20,8 @@
}, },
"distribution_sys": { "distribution_sys": {
"getSupplierHolidayTimes": "http://pps.bailuntec.com/distributionapi/Manager/SupplierAssessmentData/getSupplierHolidayTimes" "getSupplierHolidayTimes": "http://pps.bailuntec.com/distributionapi/Manager/SupplierAssessmentData/getSupplierHolidayTimes"
},
"supplier_sys": {
"list": "http://supplier.bailuntec.com/Api/ListSupplierAllByTime"
} }
} }
\ 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