同步基础数据

This commit is contained in:
2024-07-24 17:50:20 +08:00
parent dd0ef3c8e2
commit 5cb371d4bd
8 changed files with 359 additions and 18 deletions

View File

@@ -279,8 +279,4 @@ public partial class BasMaterial : BaseEntity<string>
/// </summary>
public string? material_standard { get; set; }
/// <summary>
/// erp修改时间
/// </summary>
public string erp_modify_time { get; set; }
}

View File

@@ -8,5 +8,9 @@ namespace Tnb.ProductionMgr.Entities.Entity.ErpEntity
public string ID { get; set; }
public string CODE { get; set; }
public string NAME { get; set; }
/// <summary>
/// 修改时间
/// </summary>
public string MODIFIEDTIME { get; set; }
}
}

View File

@@ -0,0 +1,12 @@
using SqlSugar;
namespace Tnb.ProductionMgr.Entities.Entity.ErpEntity
{
[SugarTable("ERP_BD_PSNDOC")]
public class ErpBdPsndoc
{
public string ID { get; set; }
public string CODE { get; set; }
public string NAME { get; set; }
}
}

View File

@@ -0,0 +1,16 @@
using SqlSugar;
namespace Tnb.ProductionMgr.Entities.Entity.ErpEntity
{
[SugarTable("ERP_BD_SUPPLIER")]
public class ErpBdSupplier
{
public string ID { get; set; }
public string CODE { get; set; }
public string NAME { get; set; }
/// <summary>
/// 修改时间
/// </summary>
public string MODIFIEDTIME { get; set; }
}
}

View File

@@ -90,5 +90,15 @@ namespace Tnb.ProductionMgr.Entities.Entity
/// 客户id
/// </summary>
public string customer_id { get; set; }
/// <summary>
/// 供应商id
/// </summary>
public string supplier_id { get; set; }
/// <summary>
/// 修改时间
/// </summary>
public string erp_modify_time { get; set; }
}
}

View File

@@ -256,5 +256,11 @@ public partial class PrdMo : BaseEntity<string>
/// </summary>
public string erp_mo_pk { get; set; }
/// <summary>
/// 工单类别
/// </summary>
/// <returns></returns>
public string mo_category { get; set; }
}

View File

@@ -1,16 +1,19 @@
using System.Diagnostics;
using Aop.Api.Domain;
using JNPF;
using JNPF.Common.Const;
using JNPF.Common.Core.Manager;
using JNPF.Common.Enums;
using JNPF.Common.Extension;
using JNPF.Common.Security;
using JNPF.DataEncryption;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.Extras.CollectiveOAuth.Models;
using JNPF.Extras.CollectiveOAuth.Utils;
using JNPF.FriendlyException;
using JNPF.Logging;
using JNPF.Systems.Entitys.Permission;
using JNPF.Systems.Entitys.System;
using JNPF.Systems.Interfaces.Permission;
using JNPF.Systems.Interfaces.System;
@@ -785,6 +788,19 @@ namespace Tnb.ProductionMgr
string response2 = HttpUtils.RequestGet($"{config.value}/api/production/time-work/sync-material");
AuthResponse authResponse2 = JsonConvert.DeserializeObject<AuthResponse>(response2);
result += ","+authResponse2.data.ToString();
string response3 = HttpUtils.RequestGet($"{config.value}/api/production/time-work/sync-customer");
AuthResponse authResponse3 = JsonConvert.DeserializeObject<AuthResponse>(response3);
result += ","+authResponse3.data.ToString();
string response4 = HttpUtils.RequestGet($"{config.value}/api/production/time-work/sync-supplier");
AuthResponse authResponse4 = JsonConvert.DeserializeObject<AuthResponse>(response4);
result += ","+authResponse4.data.ToString();
string response5 = HttpUtils.RequestGet($"{config.value}/api/production/time-work/sync-user");
AuthResponse authResponse5 = JsonConvert.DeserializeObject<AuthResponse>(response5);
result += ","+authResponse5.data.ToString();
return result;
}
@@ -883,7 +899,7 @@ namespace Tnb.ProductionMgr
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)
if (erpBdMaterial.MODIFIEDTIME != extendField.erp_modify_time)
{
int updateRow = await _db.Updateable<BasMaterial>()
.SetColumns(x => x.name == erpBdMaterial.NAME)
@@ -892,9 +908,14 @@ namespace Tnb.ProductionMgr
.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();
await _db.Updateable<ErpExtendField>()
.SetColumns(x => x.erp_modify_time == erpBdMaterial.MODIFIEDTIME)
.Where(x => x.table_id == extendField.table_id)
.ExecuteCommandAsync();
editCount += updateRow;
if (updateRow <= 0)
{
@@ -1127,8 +1148,8 @@ namespace Tnb.ProductionMgr
try
{
int editCount = 0;
var mysqlDb = _db.AsTenant().GetConnection("erpdb");
List<ErpBdCustomer> list = await mysqlDb.Queryable<ErpBdCustomer>().ToListAsync();
var erpdb = _db.AsTenant().GetConnection("erpdb");
List<ErpBdCustomer> list = await erpdb.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>();
@@ -1143,7 +1164,8 @@ namespace Tnb.ProductionMgr
{
id = SnowflakeIdHelper.NextId(),
customer_code = erpBdCustomer.CODE,
customer_name = erpBdCustomer.NAME
customer_name = erpBdCustomer.NAME,
create_time = DateTime.Now
};
ErpExtendField erpExtendField = new ErpExtendField()
{
@@ -1159,15 +1181,21 @@ namespace Tnb.ProductionMgr
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)
if (erpBdCustomer.MODIFIEDTIME != erpExtendField.erp_modify_time)
{
Log.Error($"未找到客户{erpExtendField.customer_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.table_id)
.ExecuteCommandAsync();
await _db.Updateable<ErpExtendField>()
.SetColumns(x => x.erp_modify_time == erpBdCustomer.MODIFIEDTIME)
.Where(x => x.table_id == erpExtendField.table_id)
.ExecuteCommandAsync();
editCount += updateRow;
}
}
}
@@ -1189,6 +1217,172 @@ namespace Tnb.ProductionMgr
return msg;
}
/// <summary>
/// 同步供应商
/// </summary>
/// <returns></returns>
[HttpGet]
[AllowAnonymous]
public async Task<String> SyncSupplier()
{
string msg = "";
try
{
int editCount = 0;
var erpdb = _db.AsTenant().GetConnection("erpdb");
List<ErpBdSupplier> list = await erpdb.Queryable<ErpBdSupplier>().ToListAsync();
List<ErpExtendField> erpExtendFields = await _db.Queryable<ErpExtendField>().Where(x=>x.table_name=="bas_supplier").ToListAsync();
List<BasSupplier> insertSuppliers = new List<BasSupplier>();
List<ErpExtendField> insertExtendFields = new List<ErpExtendField>();
await _db.Ado.BeginTranAsync();
foreach (ErpBdSupplier erpBdSupplier in list)
{
if (erpExtendFields.All(x => x.supplier_id != erpBdSupplier.ID))
{
BasSupplier basSupplier = new BasSupplier()
{
id = SnowflakeIdHelper.NextId(),
supplier_code = erpBdSupplier.CODE,
supplier_name = erpBdSupplier.NAME,
create_time = DateTime.Now
};
ErpExtendField erpExtendField = new ErpExtendField()
{
table_id = basSupplier.id,
table_name = "bas_supplier",
cunitid = erpBdSupplier.ID,
create_time = DateTime.Now
};
insertSuppliers.Add(basSupplier);
insertExtendFields.Add(erpExtendField);
}
else
{
ErpExtendField erpExtendField = erpExtendFields.Find(x => x.supplier_id == erpBdSupplier.ID);
if (erpBdSupplier.MODIFIEDTIME != erpExtendField.erp_modify_time)
{
int updateRow = await _db.Updateable<BasSupplier>()
.SetColumns(x => x.supplier_code == erpBdSupplier.CODE)
.SetColumns(x => x.supplier_name == erpBdSupplier.NAME)
.Where(x => x.id == erpExtendField.table_id)
.ExecuteCommandAsync();
await _db.Updateable<ErpExtendField>()
.SetColumns(x => x.erp_modify_time == erpBdSupplier.MODIFIEDTIME)
.Where(x => x.table_id == erpExtendField.table_id)
.ExecuteCommandAsync();
editCount += updateRow;
}
}
}
await _db.Insertable(insertSuppliers).ExecuteCommandAsync();
await _db.Insertable(insertExtendFields).ExecuteCommandAsync();
await _db.Ado.CommitTranAsync();
msg = $"新增供应商${insertSuppliers.Count}条,修改供应商{editCount}条";
}
catch (Exception e)
{
Log.Error(e.Message, e);
msg = e.Message;
await _db.Ado.RollbackTranAsync();
throw Oops.Bah(e.Message);
}
return msg;
}
/// <summary>
/// 同步用户
/// </summary>
/// <returns></returns>
[HttpGet]
[AllowAnonymous]
public async Task<String> SyncUser()
{
string msg = "";
try
{
var erpdb = _db.AsTenant().GetConnection("erpdb");
List<ErpBdPsndoc> users = await erpdb.Queryable<ErpBdPsndoc>().ToListAsync();
List<ErpExtendField> erpExtendFields = await _db.Queryable<ErpExtendField>().Where(x=>x.table_name=="base_user").ToListAsync();
List<UserEntity> insertUsers = new List<UserEntity>();
List<UserRelationEntity> insertUserRelations = new List<UserRelationEntity>();
List<ErpExtendField> insertErpExtendFields = new List<ErpExtendField>();
await _db.Ado.BeginTranAsync();
foreach (var user in users)
{
if (erpExtendFields.All(x => x.user_id != user.ID))
{
UserEntity userEntity = new UserEntity();
userEntity.Id = SnowflakeIdHelper.NextId();
userEntity.Account = user.CODE;
userEntity.RealName = user.NAME;
userEntity.Gender = 1;
userEntity.OrganizeId = WmsWareHouseConst.AdministratorOrgId;
userEntity.RoleId = "30327535942933";
userEntity.Secretkey = Guid.NewGuid().ToString();
userEntity.Password = MD5Encryption.Encrypt(MD5Encryption.Encrypt(CommonConst.DEFAULTPASSWORD) + userEntity.Secretkey);
userEntity.EntryDate = DateTime.Now;
userEntity.EnabledMark = 1;
userEntity.CreatorTime = DateTime.Now;
insertUsers.Add(userEntity);
UserRelationEntity userRelationEntity = new UserRelationEntity();
userRelationEntity.Id = SnowflakeIdHelper.NextId();
userRelationEntity.UserId = userEntity.Id;
userRelationEntity.ObjectType = "Role";
userRelationEntity.ObjectId = "30327535942933";
userRelationEntity.CreatorTime = DateTime.Now;
insertUserRelations.Add(userRelationEntity);
UserRelationEntity userRelationEntity2 = new UserRelationEntity();
userRelationEntity2.Id = SnowflakeIdHelper.NextId();
userRelationEntity2.UserId = userEntity.Id;
userRelationEntity2.ObjectType = "Organize";
userRelationEntity2.ObjectId = WmsWareHouseConst.AdministratorOrgId;
userRelationEntity2.CreatorTime = DateTime.Now;
insertUserRelations.Add(userRelationEntity2);
ErpExtendField extendField = new ErpExtendField();
extendField.org_id = WmsWareHouseConst.AdministratorOrgId;
extendField.table_name = "base_user";
extendField.table_id = userEntity.Id;
extendField.user_id = user.ID;
insertErpExtendFields.Add(extendField);
}
}
await _db.Insertable(insertUsers).ExecuteCommandAsync();
await _db.Insertable(insertUserRelations).ExecuteCommandAsync();
await _db.Insertable(insertErpExtendFields).ExecuteCommandAsync();
await _db.Ado.CommitTranAsync();
msg = $"新增用户${insertUsers.Count}条";
}
catch (Exception e)
{
Log.Error(e.Message, e);
msg = e.Message;
await _db.Ado.RollbackTranAsync();
throw Oops.Bah(e.Message);
}
return msg;
}
}
}

View File

@@ -8,14 +8,20 @@ using JNPF.DynamicApiController;
using JNPF.JsonSerialization;
using JNPF.Logging.Attributes;
using JNPF.Systems.Entitys.Permission;
using JNPF.Systems.Entitys.System;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Npgsql.TypeHandlers;
using SqlSugar;
using Tnb.BasicData.Entities;
using Tnb.ProductionMgr.Entities.Entity;
using Tnb.ProductionMgr.Entities.Entity.ErpEntity;
using Tnb.WarehouseMgr.Entities.Entity;
using Tnb.WarehouseMgr.Entities.Consts;
using Tnb.BasicData;
using Tnb.WarehouseMgr.Entities;
namespace JNPF.Systems.Common;
@@ -96,10 +102,99 @@ public class TestService : IDynamicApiController, ITransient
public string test1()
{
var mysqlDb = _sugar.GetConnection("erpdb");
List<ErpBdMaterial> list = mysqlDb.Queryable<ErpBdMaterial>().ToList();
List<BasFactoryConfig2> list = mysqlDb.Queryable<BasFactoryConfig2>().ToList();
List<BasMaterial> list2 = _sugar.Queryable<BasMaterial>().ToList();
return JsonConvert.SerializeObject(list);
}
[HttpGet]
[AllowAnonymous]
public async Task<string> test2()
{
WmsMaterialTransferD wmsMaterialTransferd = await _sugar.Queryable<WmsMaterialTransferD>().Where(r => r.id == "35610026468885").SingleAsync();
WmsMaterialTransfer wmsMaterialTransfer = await _sugar.Queryable<WmsMaterialTransfer>().SingleAsync(x => x.id == wmsMaterialTransferd.bill_id);
List<WmsMaterialTransferD> dList = await _sugar.Queryable<WmsMaterialTransferD>().Where(x => x.bill_id == wmsMaterialTransferd.bill_id).OrderBy(x=>x.id).ToListAsync();
DictionaryDataEntity unitData = await _sugar.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);
}
List<ErpExtendField> erpExtendFields = await _sugar.Queryable<ErpExtendField>().Where(x=>ids.Contains(x.table_id)).ToListAsync();
ErpExtendField erpOrg = erpExtendFields.Find(x => x.table_id == (wmsMaterialTransfer.org_id ?? WmsWareHouseConst.AdministratorOrgId));
string erpCreateId = erpExtendFields.Find(x=>x.table_id==wmsMaterialTransfer.create_id)?.user_id ?? "";
List<Dictionary<string, object>> requestData = new List<Dictionary<string, object>>();
Dictionary<string, object> erpRequestData = new Dictionary<string, object>();
string nowStr = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
erpRequestData.Add("billmaker",erpCreateId);
erpRequestData.Add("cdptid","1001A1100000000JRLI1");// 先写死
erpRequestData.Add("cdptvid","0001A11000000007GGO8");// 先写死
erpRequestData.Add("corpoid",erpOrg.corpoid);
erpRequestData.Add("corpvid",erpOrg.corpoid);
erpRequestData.Add("cothercalbodyoid",erpOrg.pk_org);
erpRequestData.Add("cotherwhid",erpExtendFields.Find(x=>x.table_id==wmsMaterialTransfer.warehouse_instock)?.cotherwhid ?? "");
erpRequestData.Add("creationtime",nowStr);
erpRequestData.Add("creator",erpCreateId);
erpRequestData.Add("ctrantypeid","0001H11000000000D31W");
erpRequestData.Add("cwarehouseid",erpExtendFields.Find(x=>x.table_id==wmsMaterialTransfer.warehouse_outstock)?.cotherwhid ?? "");
erpRequestData.Add("dbilldate",nowStr);
erpRequestData.Add("dmakedate",nowStr);
erpRequestData.Add("ntotalnum",20);
erpRequestData.Add("pk_group",erpOrg.pk_group);
erpRequestData.Add("pk_org",erpOrg.pk_org);
erpRequestData.Add("pk_org_v",erpOrg.pk_org_v);
erpRequestData.Add("vbillcode",wmsMaterialTransfer.bill_code);
erpRequestData.Add("vtrantypecode","4I-01");//其他出库 先写死
List<Dictionary<string, object>> erpRequestDataDetails = new List<Dictionary<string, object>>();
erpRequestDataDetails.Add(new Dictionary<string, object>()
{
["cbodytranstypecode"] = "4I-01",
["cbodywarehouseid"] = erpExtendFields.Find(x=>x.table_id==wmsMaterialTransfer.warehouse_outstock)?.cotherwhid ?? "",
["cmaterialoid"] = erpExtendFields.Find(x=>x.table_id==wmsMaterialTransferd.material_id)?.cmaterialoid ?? "",
["cmaterialvid"] = erpExtendFields.Find(x=>x.table_id==wmsMaterialTransferd.material_id)?.cmaterialvid ?? "",
["corpoid"] = erpOrg.corpoid,
["corpvid"] = erpOrg.corpvid,
["crowno"] = wmsMaterialTransferd.lineno,
["csourcebillbid"] = wmsMaterialTransferd.erp_line_pk,
["csourcebillhid"] = wmsMaterialTransfer.erp_pk,
["cunitid"] = erpExtendFields.Find(x=>x.table_id==unitData.Id)?.cunitid ?? "",
["cvendorid"] = "",
["cvendorvid"] = "",
["dbizdate"] = nowStr,
["nnum"] = 20,
["nshouldnum"] = wmsMaterialTransferd.qty,
["pk_group"] = erpOrg.pk_group,
["pk_org"] = erpOrg.pk_org,
["pk_org_v"] = erpOrg.pk_org_v,
["vbatchcode"] = wmsMaterialTransferd.code_batch,
});
erpRequestData.Add("dtls",erpRequestDataDetails);
requestData.Add(erpRequestData);
ThirdWebapiRecord thirdWebapiRecord = new ThirdWebapiRecord();
thirdWebapiRecord.id = SnowflakeIdHelper.NextId();
thirdWebapiRecord.third_name = WmsWareHouseConst.BIP;
thirdWebapiRecord.name = "其它出库";
thirdWebapiRecord.method = "POST";
thirdWebapiRecord.url = WmsWareHouseConst.BIP_DOMAIN+"uapws/rest/generalout/save";
thirdWebapiRecord.request_data = JsonConvert.SerializeObject(requestData);
thirdWebapiRecord.create_time = DateTime.Now;
await _sugar.Insertable(thirdWebapiRecord).ExecuteCommandAsync();
return "123";
}
[HttpGet]
[AllowAnonymous]
public async Task<string> insertUser()
@@ -131,6 +226,14 @@ public class TestService : IDynamicApiController, ITransient
userRelationEntity.ObjectId = "30327535942933";
userRelationEntity.CreatorTime = DateTime.Now;
insertUserRelations.Add(userRelationEntity);
UserRelationEntity userRelationEntity2 = new UserRelationEntity();
userRelationEntity2.Id = SnowflakeIdHelper.NextId();
userRelationEntity2.UserId = userEntity.Id;
userRelationEntity2.ObjectType = "Organize";
userRelationEntity2.ObjectId = "25193668006933";
userRelationEntity2.CreatorTime = DateTime.Now;
insertUserRelations.Add(userRelationEntity2);
ErpExtendField extendField = new ErpExtendField();
extendField.org_id = "25193668006933";