This commit is contained in:
2024-07-18 23:54:54 +08:00
2 changed files with 48 additions and 20 deletions

View File

@@ -17,6 +17,7 @@ using JNPF.Systems.Interfaces.System;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using SQLitePCL;
using SqlSugar;
using SqlSugar.Extensions;
using Tnb.BasicData.Entities;
@@ -703,26 +704,48 @@ namespace Tnb.ProductionMgr
[AllowAnonymous]
public async Task<String> SyncUnit()
{
// var mysqlDb = _db.AsTenant().GetConnection("erpdb");
// List<ErpBdMeasdoc> list = await mysqlDb.Queryable<ErpBdMeasdoc>().ToListAsync();
// List<ErpExtendField> erpExtendFields = await _db.Queryable<ErpExtendField>().ToListAsync();
// List<DictionaryDataEntity> insertMaterial = new List<DictionaryDataEntity>();
// List<ErpExtendField> insertExtendFields = new List<ErpExtendField>();
// foreach (ErpBdMaterial erpBdMaterial in list)
// {
// if (erpExtendFields.All(x => x.cmaterialoid != erpBdMaterial.ID))
// {
// insertMaterial.Add(new BasMaterial()
// {
// id = SnowflakeIdHelper.NextId(),
// name = erpBdMaterial.NAME,
// code = erpBdMaterial.CODE,
// org_id = WmsWareHouseConst.AdministratorOrgId,
// material_specification = erpBdMaterial.MATERIALSPEC,
// material_standard = erpBdMaterial.MATERIALTYPE
// });
// }
// }
var mysqlDb = _db.AsTenant().GetConnection("erpdb");
List<ErpBdMeasdoc> list = await mysqlDb.Queryable<ErpBdMeasdoc>().ToListAsync();
List<ErpExtendField> erpExtendFields = await _db.Queryable<ErpExtendField>().ToListAsync();
List<DictionaryDataEntity> insertUnit = new List<DictionaryDataEntity>();
List<ErpExtendField> insertExtendFields = new List<ErpExtendField>();
foreach (ErpBdMeasdoc erpBdMeasdoc in list)
{
if (erpExtendFields.All(x => x.cunitid != erpBdMeasdoc.ID))
{
DictionaryDataEntity dictionaryDataEntity = new DictionaryDataEntity()
{
Id = SnowflakeIdHelper.NextId(),
FullName = erpBdMeasdoc.NAME,
EnCode = erpBdMeasdoc.CODE,
ParentId = "0",
SortCode = 0,
EnabledMark = 1,
CreatorTime = DateTime.Now,
DictionaryTypeId = WmsWareHouseConst.UNITTYPEID,
};
ErpExtendField erpExtendField = new ErpExtendField()
{
table_id = dictionaryDataEntity.Id,
table_name = "base_dictionarydata",
cunitid = erpBdMeasdoc.ID,
create_time = DateTime.Now
};
insertUnit.Add(dictionaryDataEntity);
insertExtendFields.Add(erpExtendField);
}
}
if (!insertUnit.IsEmpty() && !insertExtendFields.IsEmpty())
{
DbResult<bool> result = await _db.Ado.UseTranAsync(async () =>
{
await _db.Insertable(insertUnit).ExecuteCommandAsync();
await _db.Insertable(insertExtendFields).ExecuteCommandAsync();
});
}
return "true";
}

View File

@@ -485,5 +485,10 @@
/// 第三方 bip
/// </summary>
public const string BIP_DOMAIN = "http://192.168.1.11:8087/";
/// <summary>
/// 单位类型id
/// </summary>
public const string UNITTYPEID = "24906054811669";
}
}