同步客户
This commit is contained in:
@@ -125,6 +125,8 @@ namespace Tnb.ProductionMgr
|
||||
bool wbzxx1Flag = await _db.Queryable<WmsPretaskH>().AnyAsync(x => x.endlocation_code == "ZZ-01-01" && statusList.Contains(x.status) );
|
||||
bool wbzxx2Flag = await _db.Queryable<WmsPretaskH>().AnyAsync(x => x.endlocation_code == "ZZ-02-01" && statusList.Contains(x.status) );
|
||||
|
||||
Log.Information($"空箱入呼叫cs01值{(cs01==null ? "null" : cs01.ToString())},cs03值{(cs03==null ? "null" : cs03.ToString())},cs06值{(cs06==null ? "null" : cs06.ToString())}");
|
||||
|
||||
if (cs01Flag)
|
||||
{
|
||||
Log.Information($"【EmptyCarryOutStk】ctu1空箱入呼叫存在未完成的预任务,跳过此次自动呼叫");
|
||||
@@ -772,6 +774,27 @@ namespace Tnb.ProductionMgr
|
||||
[HttpGet]
|
||||
[AllowAnonymous]
|
||||
public async Task<String> SyncBaseData()
|
||||
{
|
||||
string result = "";
|
||||
BasFactoryConfig config = await _repository.AsSugarClient().Queryable<BasFactoryConfig>().FirstAsync(x => x.enabled == 1 && x.key == FactoryConfigConst.DOMAIN);
|
||||
|
||||
string response1 = HttpUtils.RequestGet($"{config.value}/api/production/time-work/sync-unit");
|
||||
AuthResponse authResponse1 = JsonConvert.DeserializeObject<AuthResponse>(response1);
|
||||
result += authResponse1.data.ToString();
|
||||
|
||||
string response2 = HttpUtils.RequestGet($"{config.value}/api/production/time-work/sync-material");
|
||||
AuthResponse authResponse2 = JsonConvert.DeserializeObject<AuthResponse>(response2);
|
||||
result += ","+authResponse2.data.ToString();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步物料
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[AllowAnonymous]
|
||||
public async Task<String> SyncMaterial()
|
||||
{
|
||||
string msg = "";
|
||||
try
|
||||
@@ -1028,6 +1051,7 @@ namespace Tnb.ProductionMgr
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
msg = e.Message;
|
||||
Log.Error(e.Message, e);
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
throw Oops.Bah(e.Message);
|
||||
@@ -1044,9 +1068,10 @@ namespace Tnb.ProductionMgr
|
||||
[AllowAnonymous]
|
||||
public async Task<String> SyncUnit()
|
||||
{
|
||||
string msg = "";
|
||||
var mysqlDb = _db.AsTenant().GetConnection("erpdb");
|
||||
List<ErpBdMeasdoc> list = await mysqlDb.Queryable<ErpBdMeasdoc>().ToListAsync();
|
||||
List<ErpExtendField> erpExtendFields = await _db.Queryable<ErpExtendField>().ToListAsync();
|
||||
List<ErpExtendField> erpExtendFields = await _db.Queryable<ErpExtendField>().Where(x=>x.table_name=="base_dictionarydata").ToListAsync();
|
||||
List<DictionaryDataEntity> insertUnit = new List<DictionaryDataEntity>();
|
||||
List<ErpExtendField> insertExtendFields = new List<ErpExtendField>();
|
||||
foreach (ErpBdMeasdoc erpBdMeasdoc in list)
|
||||
@@ -1084,10 +1109,85 @@ namespace Tnb.ProductionMgr
|
||||
await _db.Insertable(insertUnit).ExecuteCommandAsync();
|
||||
await _db.Insertable(insertExtendFields).ExecuteCommandAsync();
|
||||
});
|
||||
return result.IsSuccess ? "成功" : result.ErrorMessage;
|
||||
return result.IsSuccess ? $"新增单位{insertUnit.Count}条" : result.ErrorMessage;
|
||||
}
|
||||
|
||||
return "true";
|
||||
return msg;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步客户
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[AllowAnonymous]
|
||||
public async Task<String> SyncCustomer()
|
||||
{
|
||||
string msg = "";
|
||||
try
|
||||
{
|
||||
int editCount = 0;
|
||||
var mysqlDb = _db.AsTenant().GetConnection("erpdb");
|
||||
List<ErpBdCustomer> list = await mysqlDb.Queryable<ErpBdCustomer>().ToListAsync();
|
||||
List<ErpExtendField> erpExtendFields = await _db.Queryable<ErpExtendField>().Where(x=>x.table_name=="bas_customer").ToListAsync();
|
||||
List<BasCustomer> insertCustomers = new List<BasCustomer>();
|
||||
List<ErpExtendField> insertExtendFields = new List<ErpExtendField>();
|
||||
|
||||
await _db.Ado.BeginTranAsync();
|
||||
|
||||
foreach (ErpBdCustomer erpBdCustomer in list)
|
||||
{
|
||||
if (erpExtendFields.All(x => x.customer_id != erpBdCustomer.ID))
|
||||
{
|
||||
BasCustomer basCustomer = new BasCustomer()
|
||||
{
|
||||
id = SnowflakeIdHelper.NextId(),
|
||||
customer_code = erpBdCustomer.CODE,
|
||||
customer_name = erpBdCustomer.NAME
|
||||
};
|
||||
ErpExtendField erpExtendField = new ErpExtendField()
|
||||
{
|
||||
table_id = basCustomer.id,
|
||||
table_name = "bas_customer",
|
||||
cunitid = erpBdCustomer.ID,
|
||||
create_time = DateTime.Now
|
||||
};
|
||||
|
||||
insertCustomers.Add(basCustomer);
|
||||
insertExtendFields.Add(erpExtendField);
|
||||
}
|
||||
else
|
||||
{
|
||||
ErpExtendField erpExtendField = erpExtendFields.Find(x => x.customer_id == erpBdCustomer.ID);
|
||||
|
||||
int updateRow = await _db.Updateable<BasCustomer>()
|
||||
.SetColumns(x => x.customer_code == erpBdCustomer.CODE)
|
||||
.SetColumns(x => x.customer_name == erpBdCustomer.NAME)
|
||||
.Where(x => x.id == erpExtendField.customer_id)
|
||||
.ExecuteCommandAsync();
|
||||
if (updateRow <= 0)
|
||||
{
|
||||
Log.Error($"未找到客户{erpExtendField.customer_id},跳过此条数据");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await _db.Insertable(insertCustomers).ExecuteCommandAsync();
|
||||
await _db.Insertable(insertExtendFields).ExecuteCommandAsync();
|
||||
|
||||
await _db.Ado.CommitTranAsync();
|
||||
|
||||
msg = $"新增客户${insertCustomers.Count}条,修改客户{editCount}条";
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e.Message, e);
|
||||
msg = e.Message;
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
throw Oops.Bah(e.Message);
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user