Merge branch 'dev' of https://git.tuotong-tech.com/tnb/tnb.server into dev
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -824,14 +840,13 @@ namespace Tnb.ProductionMgr
|
||||
|
||||
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 ?? "";
|
||||
auxiliaryUnitId = unitDic.ContainsKey(auxiliaryUnitId) ? unitDic[auxiliaryUnitId].ToString() : "";
|
||||
string[] unitArr = erpBdMaterial.MEASRATE.Split("/");
|
||||
if (erpExtendFields.All(x => x.cmaterialoid != erpBdMaterial.ID))
|
||||
{
|
||||
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 ?? "";
|
||||
auxiliaryUnitId = unitDic.ContainsKey(auxiliaryUnitId) ? unitDic[auxiliaryUnitId].ToString() : "";
|
||||
string[] unitArr = erpBdMaterial.MEASRATE.Split("/");
|
||||
BasMaterial basMaterial = null;
|
||||
ErpExtendField tempExtendField = insertExtendFields.Find(x => x.cmaterialoid == erpBdMaterial.ID);
|
||||
if (tempExtendField!=null)
|
||||
@@ -883,8 +898,14 @@ 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)
|
||||
{
|
||||
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 ?? "";
|
||||
auxiliaryUnitId = unitDic.ContainsKey(auxiliaryUnitId) ? unitDic[auxiliaryUnitId].ToString() : "";
|
||||
string[] unitArr = erpBdMaterial.MEASRATE.Split("/");
|
||||
|
||||
int updateRow = await _db.Updateable<BasMaterial>()
|
||||
.SetColumns(x => x.name == erpBdMaterial.NAME)
|
||||
.SetColumns(x => x.code == erpBdMaterial.CODE)
|
||||
@@ -892,9 +913,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)
|
||||
{
|
||||
@@ -1046,7 +1072,7 @@ namespace Tnb.ProductionMgr
|
||||
await _db.Insertable(insertBasEbomDs).ExecuteCommandAsync();
|
||||
|
||||
await _db.Ado.CommitTranAsync();
|
||||
msg = $"新增物料${insertMaterial.Count}条,修改物料{editCount}条";
|
||||
msg = $"新增物料{insertMaterial.Count}条,修改物料{editCount}条";
|
||||
Log.Information(msg);
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -1127,8 +1153,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,13 +1169,14 @@ 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()
|
||||
{
|
||||
table_id = basCustomer.id,
|
||||
table_name = "bas_customer",
|
||||
cunitid = erpBdCustomer.ID,
|
||||
customer_id = erpBdCustomer.ID,
|
||||
create_time = DateTime.Now
|
||||
};
|
||||
|
||||
@@ -1159,15 +1186,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;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1177,7 +1210,173 @@ namespace Tnb.ProductionMgr
|
||||
|
||||
await _db.Ado.CommitTranAsync();
|
||||
|
||||
msg = $"新增客户${insertCustomers.Count}条,修改客户{editCount}条";
|
||||
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;
|
||||
}
|
||||
|
||||
/// <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",
|
||||
supplier_id = 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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user