diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpBdPsndoc.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpBdPsndoc.cs index 766bff23..ca0ce2b3 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpBdPsndoc.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpBdPsndoc.cs @@ -11,5 +11,10 @@ namespace Tnb.ProductionMgr.Entities.Entity.ErpEntity public string ID { get; set; } public string CODE { get; set; } public string NAME { get; set; } + + /// + /// 1 未启用,2已启用,3已停用 + /// + public int ENABLESTATE { get; set; } } } \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpSmUser.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpSmUser.cs index 06d65f52..d21261f3 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpSmUser.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpSmUser.cs @@ -12,5 +12,10 @@ namespace Tnb.ProductionMgr.Entities.Entity.ErpEntity public string PK_PSNDOC { get; set; } public string CODE { get; set; } public string NAME { get; set; } + + /// + /// 1 未启用,2已启用,3已停用 + /// + public int ENABLESTATE { get; set; } } } \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpUserDto.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpUserDto.cs index ffd8091e..7ae86e79 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpUserDto.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpUserDto.cs @@ -13,5 +13,10 @@ namespace Tnb.ProductionMgr.Entities.Entity.ErpEntity /// 1 erp人员 2 erp用户 /// public string TYPE { get; set; } + + /// + /// 1 未启用,2已启用,3已停用 + /// + public int ENABLESTATE { get; set; } } } \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs b/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs index b86cdf65..f12a6733 100644 --- a/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs @@ -493,21 +493,31 @@ namespace Tnb.ProductionMgr return "YTCS没开机"; } string stateHxja = await _redisData.TryGetValueByKeyField("hxjA", "State"); + string stateHxjb = await _redisData.TryGetValueByKeyField("hxjB", "State"); string stateHxjc = await _redisData.TryGetValueByKeyField("hxjC", "State"); + string stateHxjd = await _redisData.TryGetValueByKeyField("hxjD", "State"); List hxjList = new List(); if ("OK" == stateHxja) { hxjList.Add("hxjA"); } + if ("OK" == stateHxjb) + { + hxjList.Add("hxjB"); + } if ("OK" == stateHxjc) { hxjList.Add("hxjC"); } + if ("OK" == stateHxjd) + { + hxjList.Add("hxjD"); + } if (hxjList.IsEmpty()) { - Log.Error($"hxjA,hxjC不正常"); - return "hxjA,hxjC不正常"; + Log.Error($"hxjA,hxjB,hxjC,hxjD不正常"); + return "hxjA,hxjB,hxjC,hxjD不正常"; } string msg = ""; List equipments = await _db.Queryable() @@ -732,7 +742,9 @@ namespace Tnb.ProductionMgr return "true"; } - + + #region 同步基础数据 + /// /// 同步基础数据 /// @@ -1500,15 +1512,18 @@ namespace Tnb.ProductionMgr { var erpdb = _db.AsTenant().GetConnection("erpdb"); List persons = await erpdb.Queryable() + .Where(x=>x.ENABLESTATE!=1) .Select(x=>new ErpUserDto { PERSON_ID = x.ID, CODE = x.CODE, NAME = x.NAME, TYPE = "1", + ENABLESTATE = x.ENABLESTATE }) .ToListAsync(); List users = await erpdb.Queryable() + .Where(x=>x.ENABLESTATE!=1) .Select(x=>new ErpUserDto { PERSON_ID = x.PK_PSNDOC, @@ -1516,86 +1531,197 @@ namespace Tnb.ProductionMgr CODE = x.CODE, NAME = x.NAME, TYPE = "2", + ENABLESTATE = x.ENABLESTATE }) .ToListAsync(); - persons.AddRange(users); + // persons.AddRange(users); List erpExtendFields = await _db.Queryable().Where(x=>x.table_name=="base_user").ToListAsync(); - List insertUsers = new List(); List existsUsers = await _db.Queryable().ToListAsync(); + List insertUsers = new List(); List insertUserRelations = new List(); List insertErpExtendFields = new List(); - await _db.Ado.BeginTranAsync(); + List insertUsers2 = new List(); + List insertUserRelations2 = new List(); + List insertErpExtendFields2 = new List(); - foreach (var person in persons) - { - if ((person.TYPE=="1" && erpExtendFields.All(x => x.person_id != person.PERSON_ID)) || (person.TYPE=="2" && erpExtendFields.All(x => x.user_id != person.USER_ID))) - { - if (person.TYPE == "2" && insertErpExtendFields.FindIndex(x=>x.person_id==person.PERSON_ID)!=-1 && person.PERSON_ID!="~") - { - ErpExtendField eef = insertErpExtendFields.Find(x => x.person_id == person.PERSON_ID); - eef.user_id = person.USER_ID; - } - else - { - UserEntity userEntity = new UserEntity(); - if (existsUsers.Exists(x => x.Account == person.CODE)) - { - userEntity = existsUsers.Find(x => x.Account == person.CODE); - } - else - { - userEntity.Id = SnowflakeIdHelper.NextId(); - userEntity.Account = person.CODE; - userEntity.RealName = person.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); - } + await _db.Ado.BeginTranAsync(); - ErpExtendField extendField = new ErpExtendField(); - extendField.org_id = WmsWareHouseConst.AdministratorOrgId; - extendField.table_name = "base_user"; - extendField.table_id = userEntity.Id; - extendField.person_id = person.PERSON_ID; - extendField.user_id = person.USER_ID; - insertErpExtendFields.Add(extendField); + foreach (var user in users) + { + List userErpExtendFields = erpExtendFields.Where(x => x.user_id == user.USER_ID).ToList(); + if (userErpExtendFields == null || userErpExtendFields.IsEmpty() || userErpExtendFields.Count == 1) + { + + UserEntity userEntity = new UserEntity(); + if (userErpExtendFields.Count == 1) + { + userEntity = existsUsers.Find(x => x.Id == erpExtendFields[0].table_id); + int state = user.ENABLESTATE == 2 ? 1 : 0; + if (userEntity != null) + { + if (userEntity.EnabledMark != state) + { + await _db.Updateable() + .SetColumns(x => x.EnabledMark == state) + .Where(x => x.Id == userEntity.Id) + .ExecuteCommandAsync(); + } + continue; + } } + + + 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 = user.ENABLESTATE == 2 ? 1 : 0; + 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 erpExtendField = new ErpExtendField(); + erpExtendField.org_id = WmsWareHouseConst.AdministratorOrgId; + erpExtendField.table_name = "base_user"; + erpExtendField.table_id = userEntity.Id; + erpExtendField.person_id = user.PERSON_ID; + erpExtendField.user_id = user.USER_ID; + insertErpExtendFields.Add(erpExtendField); + } + else + { } } - await _db.Insertable(insertUsers).ExecuteCommandAsync(); - await _db.Insertable(insertUserRelations).ExecuteCommandAsync(); - await _db.Insertable(insertErpExtendFields).ExecuteCommandAsync(); + if (!insertUsers.IsEmpty()) + { + existsUsers.AddRange(insertUsers); + await _db.Insertable(insertUsers).ExecuteCommandAsync(); + + } + if (!insertUserRelations.IsEmpty()) + { + await _db.Insertable(insertUserRelations).ExecuteCommandAsync(); + } + + if (!insertErpExtendFields.IsEmpty()) + { + erpExtendFields.AddRange(insertErpExtendFields); + await _db.Insertable(insertErpExtendFields).ExecuteCommandAsync(); + } + + foreach (var person in persons) + { + List userErpExtendFields = erpExtendFields.Where(x => x.person_id == person.PERSON_ID).ToList(); + if (userErpExtendFields == null || userErpExtendFields.IsEmpty() || userErpExtendFields.Count == 1) + { + + UserEntity userEntity = new UserEntity(); + if (userErpExtendFields.Count == 1) + { + userEntity = existsUsers.Find(x => x.Id == erpExtendFields[0].table_id); + int state = person.ENABLESTATE == 2 ? 1 : 0; + if (userEntity != null) + { + if (userEntity.EnabledMark != state) + { + await _db.Updateable() + .SetColumns(x => x.EnabledMark == state) + .Where(x => x.Id == userEntity.Id) + .ExecuteCommandAsync(); + } + continue; + } + } + + + userEntity.Id = SnowflakeIdHelper.NextId(); + userEntity.Account = person.CODE; + userEntity.RealName = person.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 = person.ENABLESTATE == 2 ? 1 : 0; + userEntity.CreatorTime = DateTime.Now; + insertUsers2.Add(userEntity); + + UserRelationEntity userRelationEntity = new UserRelationEntity(); + userRelationEntity.Id = SnowflakeIdHelper.NextId(); + userRelationEntity.UserId = userEntity.Id; + userRelationEntity.ObjectType = "Role"; + userRelationEntity.ObjectId = "30327535942933"; + userRelationEntity.CreatorTime = DateTime.Now; + insertUserRelations2.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; + insertUserRelations2.Add(userRelationEntity2); + + ErpExtendField erpExtendField = new ErpExtendField(); + erpExtendField.org_id = WmsWareHouseConst.AdministratorOrgId; + erpExtendField.table_name = "base_user"; + erpExtendField.table_id = userEntity.Id; + erpExtendField.person_id = person.PERSON_ID; + erpExtendField.user_id = person.USER_ID; + insertErpExtendFields2.Add(erpExtendField); + } + else + { + + } + } + + if (!insertUsers2.IsEmpty()) + { + await _db.Insertable(insertUsers2).ExecuteCommandAsync(); + + } + if (!insertUserRelations2.IsEmpty()) + { + await _db.Insertable(insertUserRelations2).ExecuteCommandAsync(); + } + + if (!insertErpExtendFields2.IsEmpty()) + { + await _db.Insertable(insertErpExtendFields2).ExecuteCommandAsync(); + } await _db.Ado.CommitTranAsync(); - msg = $"新增用户{insertUsers.Count}条"; + msg = $"新增用户{insertUsers.Count+insertUsers2.Count}条"; } catch (Exception e) { @@ -1607,6 +1733,8 @@ namespace Tnb.ProductionMgr return msg; } + + #endregion /// /// 监测工艺 diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsMaterialTransferService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsMaterialTransferService.cs index f2eead51..4157687b 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsMaterialTransferService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsMaterialTransferService.cs @@ -539,7 +539,7 @@ namespace Tnb.WarehouseMgr } InStockStrategyQuery inStockStrategyInput = new() { warehouse_id = WmsWareHouseConst.WAREHOUSE_CP_ID, Size = items_pretask.Count, Region_id = WmsWareHouseConst.REGION_CPOutstock_ID }; - List endLocations = await _wareHouseService.InStockStrategy(inStockStrategyInput); + List endLocations = await _wareHouseService.InStockStrategy(inStockStrategyInput, _db); int instockLocIndex = 0; foreach (Tuple item in items_pretask) diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAScanInStockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAScanInStockService.cs index aaff4c2c..2d499131 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAScanInStockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAScanInStockService.cs @@ -489,7 +489,7 @@ namespace Tnb.WarehouseMgr code_batch = r.Key.code_batch, material_specification = item.material_specification, container_no = item.container_no, - warehouse_id = WmsWareHouseConst.WAREHOUSE_CP_ID, + warehouse_id = WmsWareHouseConst.WAREHOUSE_YCL_ID, print_qty = qty, scan_qty = qty, print_id = "",