Merge branch 'dev' of https://git.tuotong-tech.com/tnb/tnb.server into dev
Conflicts: WarehouseMgr/Tnb.WarehouseMgr/WmsMaterialTransferService.cs
This commit is contained in:
@@ -7,6 +7,7 @@ using JNPF.DynamicApiController;
|
||||
using JNPF.FriendlyException;
|
||||
using JNPF.Logging;
|
||||
using JNPF.Message.Service;
|
||||
using JNPF.Systems.Entitys.System;
|
||||
using JNPF.Systems.Interfaces.System;
|
||||
using JNPF.TaskScheduler;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@@ -92,8 +93,10 @@ namespace Tnb.ProductionMgr
|
||||
throw Oops.Bah($"系统中无法找到物料清单{item.ebom_version}版本");
|
||||
}
|
||||
|
||||
|
||||
DictionaryDataEntity unitDic = await _db.Queryable<DictionaryDataEntity>().Where(x=>x.DictionaryTypeId==WmsWareHouseConst.UNITTYPEID && x.EnCode==item.unit_id).FirstAsync();
|
||||
|
||||
item.id = SnowflakeIdHelper.NextId();
|
||||
item.material_id = basMaterial.id;
|
||||
item.mo_source = "1";
|
||||
item.mo_type = moTypeDic[item.mo_type];
|
||||
item.mo_code = item.mo_code;
|
||||
@@ -103,6 +106,7 @@ namespace Tnb.ProductionMgr
|
||||
item.erp_mo_pk = item.erp_mo_pk;
|
||||
item.erp_line_pk = item.erp_line_pk;
|
||||
item.erp_lineno = item.erp_lineno;
|
||||
item.unit_id = unitDic?.Id ?? item.unit_id;
|
||||
|
||||
moList.Add(item);
|
||||
}
|
||||
|
||||
@@ -758,7 +758,7 @@ namespace Tnb.ProductionMgr
|
||||
foreach (BasEbomD item in basEbomDs)
|
||||
{
|
||||
// decimal? num1 = beforeReportNum / basEbomH.quantity * item.quantity;
|
||||
decimal? num1 = beforeReportNum / basEbomH.quantity * (item.molecule/item.denominator);
|
||||
decimal? num1 = beforeReportNum / (item.molecule/item.denominator);
|
||||
List<PrdFeedingD> prdFeedingDs = await _db.Queryable<PrdFeedingD>()
|
||||
.LeftJoin<PrdFeedingH>((a, b) => a.feeding_id == b.id)
|
||||
.Where((a, b) => a.material_id == item.material_id && b.mo_task_id == mo_task_id)
|
||||
@@ -775,7 +775,7 @@ namespace Tnb.ProductionMgr
|
||||
else
|
||||
{
|
||||
// decimal? num2 = prdReport.reported_qty / basEbomH.quantity * item.quantity;
|
||||
decimal? num2 = prdReport.reported_qty / basEbomH.quantity * (item.molecule/item.denominator);
|
||||
decimal? num2 = prdReport.reported_qty / (item.molecule/item.denominator);
|
||||
if (sum2 <= num2)
|
||||
{
|
||||
prdFeedingIds.Add(item.id);
|
||||
@@ -1094,7 +1094,7 @@ namespace Tnb.ProductionMgr
|
||||
foreach (PrdReport prdReport in prdReports)
|
||||
{
|
||||
// decimal needNum = (prdReport.reported_qty ?? 0) / basEbomH.quantity * basEbomD.quantity;
|
||||
decimal needNum = (prdReport.reported_qty ?? 0) / basEbomH.quantity * (basEbomD.molecule/basEbomD.denominator);
|
||||
decimal needNum = (prdReport.reported_qty ?? 0) / (basEbomD.molecule/basEbomD.denominator);
|
||||
if (beforeIn - needNum >= 0)
|
||||
{
|
||||
beforeIn -= needNum;
|
||||
|
||||
@@ -773,47 +773,241 @@ namespace Tnb.ProductionMgr
|
||||
[AllowAnonymous]
|
||||
public async Task<String> SyncBaseData()
|
||||
{
|
||||
var mysqlDb = _db.AsTenant().GetConnection("erpdb");
|
||||
List<ErpBdMaterial> list = await mysqlDb.Queryable<ErpBdMaterial>().ToListAsync();
|
||||
List<ErpExtendField> erpExtendFields = await _db.Queryable<ErpExtendField>().Where(x=>x.table_name=="base_dictionarydata").ToListAsync();
|
||||
Dictionary<string,object> unitDic = await _db.Queryable<DictionaryDataEntity>().Where(x=>x.DictionaryTypeId==WmsWareHouseConst.UNITTYPEID).ToDictionaryAsync(x=>x.Id,y=>y.EnCode);
|
||||
List<BasMaterial> materials = await _db.Queryable<BasMaterial>().ToListAsync();
|
||||
List<BasMaterial> insertMaterial = new List<BasMaterial>();
|
||||
List<BasMaterialUnit> insertMaterialUnits = new List<BasMaterialUnit>();
|
||||
List<ErpExtendField> insertExtendFields = new List<ErpExtendField>();
|
||||
foreach (ErpBdMaterial erpBdMaterial in list)
|
||||
try
|
||||
{
|
||||
if (erpExtendFields.All(x => x.cmaterialoid != erpBdMaterial.ID))
|
||||
string[] tables = new[] { "base_dictionarydata", "bas_material" };
|
||||
var erpdb = _db.AsTenant().GetConnection("erpdb");
|
||||
List<ErpBdMaterial> list = await erpdb.Queryable<ErpBdMaterial>().ToListAsync();
|
||||
List<BomList> bomList = erpdb.Queryable<BomList>().ToList();
|
||||
List<ErpExtendField> erpExtendFields = await _db.Queryable<ErpExtendField>()
|
||||
.Where(x => tables.Contains(x.table_name)).ToListAsync();
|
||||
Dictionary<string, object> unitDic = await _db.Queryable<DictionaryDataEntity>()
|
||||
.Where(x => x.DictionaryTypeId == WmsWareHouseConst.UNITTYPEID)
|
||||
.ToDictionaryAsync(x => x.Id, y => y.EnCode);
|
||||
Dictionary<string, object> unitDic2 = await _db.Queryable<DictionaryDataEntity>()
|
||||
.Where(x => x.DictionaryTypeId == WmsWareHouseConst.UNITTYPEID)
|
||||
.ToDictionaryAsync(x => x.FullName, y => y.EnCode);
|
||||
List<BasMaterial> materials = await _db.Queryable<BasMaterial>().ToListAsync();
|
||||
List<BasEbomH> basEbomHs = await _db.Queryable<BasEbomH>().ToListAsync();
|
||||
List<BasMaterial> insertMaterial = new List<BasMaterial>();
|
||||
List<BasMaterialUnit> insertMaterialUnits = new List<BasMaterialUnit>();
|
||||
List<BasEbomH> insertBasEbomHs = new List<BasEbomH>();
|
||||
List<BasEbomD> insertBasEbomDs = new List<BasEbomD>();
|
||||
List<ErpExtendField> insertExtendFields = new List<ErpExtendField>();
|
||||
|
||||
await _db.Ado.BeginTranAsync();
|
||||
|
||||
foreach (ErpBdMaterial erpBdMaterial in list)
|
||||
{
|
||||
string unitId = erpExtendFields.Find(x => x.cunitid == erpBdMaterial.PK_MEASDOC)?.table_id ?? "";
|
||||
unitId = unitDic.ContainsKey(unitId) ? unitDic[unitId].ToString() : "";
|
||||
string auxiliaryUnitId = erpExtendFields.Find(x => x.cunitid == erpBdMaterial.FMEASDOC)?.table_id ?? "";
|
||||
string auxiliaryUnitId =
|
||||
erpExtendFields.Find(x => x.cunitid == erpBdMaterial.FMEASDOC)?.table_id ?? "";
|
||||
auxiliaryUnitId = unitDic.ContainsKey(auxiliaryUnitId) ? unitDic[auxiliaryUnitId].ToString() : "";
|
||||
BasMaterial basMaterial = new BasMaterial()
|
||||
{
|
||||
id = SnowflakeIdHelper.NextId(),
|
||||
name = erpBdMaterial.NAME,
|
||||
code = erpBdMaterial.CODE,
|
||||
org_id = WmsWareHouseConst.AdministratorOrgId,
|
||||
material_specification = erpBdMaterial.MATERIALSPEC,
|
||||
material_standard = erpBdMaterial.MATERIALTYPE,
|
||||
category_id = "[\"CGJCJ\"]",
|
||||
unit_id = unitId,
|
||||
};
|
||||
insertMaterial.Add(basMaterial);
|
||||
|
||||
string[] unitArr = erpBdMaterial.MEASRATE.Split("/");
|
||||
insertMaterialUnits.Add(new BasMaterialUnit()
|
||||
if (erpExtendFields.All(x => x.cmaterialoid != erpBdMaterial.ID))
|
||||
{
|
||||
id = SnowflakeIdHelper.NextId(),
|
||||
material_id = basMaterial.id,
|
||||
number_of_primary_unit = unitArr[0],
|
||||
number_of_auxiliary_unit = unitArr[1],
|
||||
auxiliary_unit_id = auxiliaryUnitId
|
||||
});
|
||||
BasMaterial basMaterial = new BasMaterial()
|
||||
{
|
||||
id = SnowflakeIdHelper.NextId(),
|
||||
name = erpBdMaterial.NAME,
|
||||
code = erpBdMaterial.CODE,
|
||||
org_id = WmsWareHouseConst.AdministratorOrgId,
|
||||
material_specification = erpBdMaterial.MATERIALSPEC,
|
||||
material_standard = erpBdMaterial.MATERIALTYPE,
|
||||
category_id = "[\"CGJCJ\"]",
|
||||
unit_id = unitId,
|
||||
create_time = DateTime.Now
|
||||
};
|
||||
insertMaterial.Add(basMaterial);
|
||||
|
||||
if (unitId != auxiliaryUnitId)
|
||||
{
|
||||
insertMaterialUnits.Add(new BasMaterialUnit()
|
||||
{
|
||||
id = SnowflakeIdHelper.NextId(),
|
||||
material_id = basMaterial.id,
|
||||
number_of_primary_unit = unitArr[0],
|
||||
number_of_auxiliary_unit = unitArr[1],
|
||||
auxiliary_unit_id = auxiliaryUnitId
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ErpExtendField extendField = erpExtendFields.Find(x => x.cmaterialoid == erpBdMaterial.ID);
|
||||
string materialId = extendField?.table_id ?? "";
|
||||
BasMaterial basMaterial = await _db.Queryable<BasMaterial>().SingleAsync(x => x.id == materialId);
|
||||
if (erpBdMaterial.MODIFIEDTIME != basMaterial.erp_modify_time)
|
||||
{
|
||||
int updateRow = await _db.Updateable<BasMaterial>()
|
||||
.SetColumns(x => x.name == erpBdMaterial.NAME)
|
||||
.SetColumns(x => x.code == erpBdMaterial.CODE)
|
||||
.SetColumns(x => x.material_specification == erpBdMaterial.MATERIALSPEC)
|
||||
.SetColumns(x => x.material_standard == erpBdMaterial.MATERIALTYPE)
|
||||
.SetColumns(x => x.unit_id == unitId)
|
||||
.SetColumns(x => x.name == erpBdMaterial.NAME)
|
||||
.SetColumns(x => x.erp_modify_time == erpBdMaterial.MODIFIEDTIME)
|
||||
.Where(x => x.id == materialId)
|
||||
.ExecuteCommandAsync();
|
||||
if (updateRow <= 0)
|
||||
{
|
||||
Log.Error($"未找到物料{erpBdMaterial.ID},跳过此条数据");
|
||||
continue;
|
||||
}
|
||||
|
||||
BasMaterialUnit basMaterialUnit = await _db.Queryable<BasMaterialUnit>()
|
||||
.Where(x => x.material_id == materialId && x.auxiliary_unit_id == auxiliaryUnitId)
|
||||
.FirstAsync();
|
||||
if (basMaterialUnit == null)
|
||||
{
|
||||
if (unitId != auxiliaryUnitId)
|
||||
{
|
||||
insertMaterialUnits.Add(new BasMaterialUnit()
|
||||
{
|
||||
id = SnowflakeIdHelper.NextId(),
|
||||
material_id = materialId,
|
||||
number_of_primary_unit = unitArr[0],
|
||||
number_of_auxiliary_unit = unitArr[1],
|
||||
auxiliary_unit_id = auxiliaryUnitId
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (unitId != auxiliaryUnitId)
|
||||
{
|
||||
await _db.Updateable<BasMaterialUnit>()
|
||||
.SetColumns(x => x.number_of_primary_unit == unitArr[0])
|
||||
.SetColumns(x => x.number_of_auxiliary_unit == unitArr[1])
|
||||
.Where(x => x.id == basMaterialUnit.id)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await _db.Insertable(insertMaterial).ExecuteCommandAsync();
|
||||
await _db.Insertable(insertMaterialUnits).ExecuteCommandAsync();
|
||||
|
||||
//物料清单开始同步
|
||||
materials = await _db.Queryable<BasMaterial>().ToListAsync();
|
||||
var groupList = bomList.GroupBy(x => x.BOMID);
|
||||
foreach (var item in groupList)
|
||||
{
|
||||
string key = item.Key;
|
||||
List<BomList> itemList = item.ToList();
|
||||
BomList firstItemInList = itemList[0];
|
||||
BasMaterial material = materials.Find(x => x.code==firstItemInList.MPRODID);
|
||||
if (material == null) continue;
|
||||
string unitId = unitDic.ContainsKey(firstItemInList.UNIT) ? unitDic[firstItemInList.UNIT].ToString() : "";
|
||||
if (basEbomHs.All(x => x.material_id != material.id && x.version != firstItemInList.HVERSION))
|
||||
{
|
||||
BasEbomH basEbomH = new BasEbomH()
|
||||
{
|
||||
id = SnowflakeIdHelper.NextId(),
|
||||
org_id = WmsWareHouseConst.AdministratorOrgId,
|
||||
material_id = material.id,
|
||||
unit_id = unitId,
|
||||
version = firstItemInList.HVERSION,
|
||||
create_time = DateTime.Now,
|
||||
};
|
||||
|
||||
|
||||
bool flag = false;
|
||||
List<BasEbomD> tempList = new List<BasEbomD>();
|
||||
foreach (var children in itemList)
|
||||
{
|
||||
BasMaterial childrenMaterial = materials.Find(x => x.code==children.SUBPRODID);
|
||||
if (childrenMaterial == null)
|
||||
{
|
||||
flag = true;
|
||||
tempList = new List<BasEbomD>();
|
||||
break;
|
||||
}
|
||||
|
||||
BasEbomD basEbomD = new BasEbomD()
|
||||
{
|
||||
id = SnowflakeIdHelper.NextId(),
|
||||
ebom_id = basEbomH.id,
|
||||
material_id = childrenMaterial.id,
|
||||
denominator = children.DISHU,
|
||||
molecule = children.BATCHAMOUNT,
|
||||
};
|
||||
tempList.Add(basEbomD);
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
insertBasEbomHs.Add(basEbomH);
|
||||
insertBasEbomDs.AddRange(tempList);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
BasEbomH basEbomH = await _db.Queryable<BasEbomH>().Where(x=>x.material_id==material.id && x.version==firstItemInList.HVERSION).FirstAsync();
|
||||
if (basEbomH == null) continue;
|
||||
|
||||
if (basEbomH.erp_modify_time != firstItemInList.MODIFIEDTIME)
|
||||
{
|
||||
bool flag = false;
|
||||
List<BasEbomD> tempList = new List<BasEbomD>();
|
||||
foreach (var children in itemList)
|
||||
{
|
||||
BasMaterial childrenMaterial = materials.Find(x => x.code==children.SUBPRODID);
|
||||
if (childrenMaterial == null)
|
||||
{
|
||||
flag = true;
|
||||
tempList = new List<BasEbomD>();
|
||||
break;
|
||||
}
|
||||
|
||||
BasEbomD basEbomD = new BasEbomD()
|
||||
{
|
||||
id = SnowflakeIdHelper.NextId(),
|
||||
ebom_id = basEbomH.id,
|
||||
material_id = childrenMaterial.id,
|
||||
denominator = children.DISHU,
|
||||
molecule = children.BATCHAMOUNT,
|
||||
};
|
||||
tempList.Add(basEbomD);
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
insertBasEbomDs.AddRange(tempList);
|
||||
await _db.Updateable<BasEbomH>()
|
||||
.SetColumns(x => x.unit_id == unitId)
|
||||
.Where(x => x.id == basEbomH.id)
|
||||
.ExecuteCommandAsync();
|
||||
await _db.Deleteable<BasEbomD>().Where(x => x.ebom_id == basEbomH.id).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
await _db.Insertable(insertBasEbomHs).ExecuteCommandAsync();
|
||||
await _db.Insertable(insertBasEbomDs).ExecuteCommandAsync();
|
||||
|
||||
await _db.Ado.CommitTranAsync();
|
||||
}
|
||||
return "true";
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e.Message, e);
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
throw Oops.Bah(e.Message);
|
||||
}
|
||||
|
||||
return "成功";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user