同步客户
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
using SqlSugar;
|
||||
|
||||
namespace Tnb.ProductionMgr.Entities.Entity.ErpEntity
|
||||
{
|
||||
[SugarTable("ERP_BD_CUSTOMER")]
|
||||
public class ErpBdCustomer
|
||||
{
|
||||
public string ID { get; set; }
|
||||
public string CODE { get; set; }
|
||||
public string NAME { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -85,5 +85,10 @@ namespace Tnb.ProductionMgr.Entities.Entity
|
||||
/// 单位id
|
||||
/// </summary>
|
||||
public string cunitid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 客户id
|
||||
/// </summary>
|
||||
public string customer_id { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1011,21 +1011,18 @@ namespace Tnb.WarehouseMgr
|
||||
Logger.LogInformation("【WmsMaterialTransferService ModifyAsync】同步其它出库单到erp...");
|
||||
|
||||
List<WmsMaterialTransferD> dList = await _db.Queryable<WmsMaterialTransferD>().Where(x => x.bill_id == wmsMaterialTransferd.bill_id).OrderBy(x => x.id).ToListAsync();
|
||||
DictionaryDataEntity unitData = await _db.Queryable<DictionaryTypeEntity>()
|
||||
.LeftJoin<DictionaryDataEntity>((x, y) => x.Id == y.DictionaryTypeId)
|
||||
.Where((x, y) => x.EnCode == DictConst.MeasurementUnit && y.EnCode == wmsMaterialTransferd.unit_id)
|
||||
.Select((x, y) => y)
|
||||
.FirstAsync();
|
||||
// DictionaryDataEntity unitData = await _db.Queryable<DictionaryTypeEntity>()
|
||||
// .LeftJoin<DictionaryDataEntity>((x, y) => x.Id == y.DictionaryTypeId)
|
||||
// .Where((x, y) => x.EnCode == DictConst.MeasurementUnit && y.EnCode == wmsMaterialTransferd.unit_id)
|
||||
// .Select((x, y) => y)
|
||||
// .FirstAsync();
|
||||
List<string> ids = new List<string>();
|
||||
ids.Add(wmsMaterialTransfer.create_id);
|
||||
ids.Add(WmsWareHouseConst.AdministratorOrgId);
|
||||
ids.Add(wmsMaterialTransfer.warehouse_outstock);
|
||||
ids.Add(wmsMaterialTransfer.warehouse_instock);
|
||||
ids.Add(wmsMaterialTransferd.material_id);
|
||||
if (unitData != null)
|
||||
{
|
||||
ids.Add(unitData.Id);
|
||||
}
|
||||
ids.Add(wmsMaterialTransferd.unit_id);
|
||||
List<ErpExtendField> erpExtendFields = await _db.Queryable<ErpExtendField>().Where(x => ids.Contains(x.table_id)).ToListAsync();
|
||||
|
||||
ErpExtendField erpOrg = erpExtendFields.Find(x => x.table_id == (wmsMaterialTransfer.org_id ?? WmsWareHouseConst.AdministratorOrgId));
|
||||
@@ -1065,7 +1062,7 @@ namespace Tnb.WarehouseMgr
|
||||
["crowno"] = wmsMaterialTransferd.lineno,
|
||||
["csourcebillbid"] = wmsMaterialTransferd.erp_line_pk,
|
||||
["csourcebillhid"] = wmsMaterialTransfer.erp_pk,
|
||||
["cunitid"] = erpExtendFields.Find(x => x.table_id == unitData?.Id)?.cunitid ?? "",
|
||||
["cunitid"] = erpExtendFields.Find(x => x.table_id == wmsMaterialTransferd.unit_id)?.cunitid ?? "",
|
||||
["cvendorid"] = "",
|
||||
["cvendorvid"] = "",
|
||||
["dbizdate"] = nowStr,
|
||||
|
||||
Reference in New Issue
Block a user