diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpBdCustomer.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpBdCustomer.cs
new file mode 100644
index 00000000..09154f69
--- /dev/null
+++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpBdCustomer.cs
@@ -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; }
+ }
+}
\ No newline at end of file
diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpExtendField.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpExtendField.cs
index d470d568..941a75d3 100644
--- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpExtendField.cs
+++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpExtendField.cs
@@ -85,5 +85,10 @@ namespace Tnb.ProductionMgr.Entities.Entity
/// 单位id
///
public string cunitid { get; set; }
+
+ ///
+ /// 客户id
+ ///
+ public string customer_id { get; set; }
}
}
\ No newline at end of file
diff --git a/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs b/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs
index 566f371c..ceee511b 100644
--- a/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs
+++ b/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs
@@ -125,6 +125,8 @@ namespace Tnb.ProductionMgr
bool wbzxx1Flag = await _db.Queryable().AnyAsync(x => x.endlocation_code == "ZZ-01-01" && statusList.Contains(x.status) );
bool wbzxx2Flag = await _db.Queryable().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 SyncBaseData()
+ {
+ string result = "";
+ BasFactoryConfig config = await _repository.AsSugarClient().Queryable().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(response1);
+ result += authResponse1.data.ToString();
+
+ string response2 = HttpUtils.RequestGet($"{config.value}/api/production/time-work/sync-material");
+ AuthResponse authResponse2 = JsonConvert.DeserializeObject(response2);
+ result += ","+authResponse2.data.ToString();
+ return result;
+ }
+
+ ///
+ /// 同步物料
+ ///
+ ///
+ [HttpGet]
+ [AllowAnonymous]
+ public async Task 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 SyncUnit()
{
+ string msg = "";
var mysqlDb = _db.AsTenant().GetConnection("erpdb");
List list = await mysqlDb.Queryable().ToListAsync();
- List erpExtendFields = await _db.Queryable().ToListAsync();
+ List erpExtendFields = await _db.Queryable().Where(x=>x.table_name=="base_dictionarydata").ToListAsync();
List insertUnit = new List();
List insertExtendFields = new List();
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;
+ }
+
+ ///
+ /// 同步客户
+ ///
+ ///
+ [HttpGet]
+ [AllowAnonymous]
+ public async Task SyncCustomer()
+ {
+ string msg = "";
+ try
+ {
+ int editCount = 0;
+ var mysqlDb = _db.AsTenant().GetConnection("erpdb");
+ List list = await mysqlDb.Queryable().ToListAsync();
+ List erpExtendFields = await _db.Queryable().Where(x=>x.table_name=="bas_customer").ToListAsync();
+ List insertCustomers = new List();
+ List insertExtendFields = new List();
+
+ 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()
+ .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;
}
}
diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsMaterialTransferService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsMaterialTransferService.cs
index f6369ef8..00eccc4c 100644
--- a/WarehouseMgr/Tnb.WarehouseMgr/WmsMaterialTransferService.cs
+++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsMaterialTransferService.cs
@@ -1011,21 +1011,18 @@ namespace Tnb.WarehouseMgr
Logger.LogInformation("【WmsMaterialTransferService ModifyAsync】同步其它出库单到erp...");
List dList = await _db.Queryable().Where(x => x.bill_id == wmsMaterialTransferd.bill_id).OrderBy(x => x.id).ToListAsync();
- DictionaryDataEntity unitData = await _db.Queryable()
- .LeftJoin((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()
+ // .LeftJoin((x, y) => x.Id == y.DictionaryTypeId)
+ // .Where((x, y) => x.EnCode == DictConst.MeasurementUnit && y.EnCode == wmsMaterialTransferd.unit_id)
+ // .Select((x, y) => y)
+ // .FirstAsync();
List ids = new List();
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 erpExtendFields = await _db.Queryable().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,