同步基础数据
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user