diff --git a/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs b/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs index 54e5bcd7..71833489 100644 --- a/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs @@ -2,6 +2,8 @@ using Aop.Api.Domain; using JNPF; using JNPF.Common.Core.Manager; using JNPF.Common.Enums; +using JNPF.Common.Extension; +using JNPF.Common.Security; using JNPF.DependencyInjection; using JNPF.DynamicApiController; using JNPF.Extras.CollectiveOAuth.Models; @@ -51,6 +53,33 @@ namespace Tnb.ProductionMgr _billRullService = billRullService; _wmsEmptyOutstockService = wmsEmptyOutstockService; } + + [HttpGet] + [AllowAnonymous] + public async Task test() + { + var db = _repository.AsSugarClient(); + + await db.Ado.BeginTranAsync(); + BasUnit basUnit = new BasUnit(); + basUnit.id = SnowflakeIdHelper.NextId(); + basUnit.unit_name = "aaa"; + basUnit.unit_code = "bbb"; + await db.Insertable(basUnit).ExecuteCommandAsync(); + + await db.Ado.CommitTranAsync(); + + await db.Ado.BeginTranAsync(); + BasUnit basUnit2 = new BasUnit(); + basUnit2.id = SnowflakeIdHelper.NextId(); + basUnit2.unit_name = "ccc"; + basUnit2.unit_code = "ddd"; + await db.Insertable(basUnit2).ExecuteCommandAsync(); + + await db.Ado.CommitTranAsync(); + + return Task.CompletedTask; + } /// /// 注塑空载具出库 @@ -60,56 +89,83 @@ namespace Tnb.ProductionMgr [AllowAnonymous] public async Task EmptyCarryOutStk() { - bool cs01 = _redisData.Get("CallCcuEmptyin_cs01"); - bool c503 = _redisData.Get("CallCtuEmptyin c503"); - bool cs01Flag = _redisData.Get("CallCcuEmptyin_cs01_flag"); - bool c503Flag = _redisData.Get("CallCtuEmptyin c503_flag"); - if (cs01 && !cs01Flag) + bool? cs01 = await _redisData.TryGetValueByKeyField("YTCS", "CallCtuEmptyIn_CS01"); + bool? cs03 = await _redisData.TryGetValueByKeyField("YTCS", "CallCtuEmptyIn_CS03"); + bool cs01Flag = _redisData.Get("YTCS_CallCtuEmptyIn_CS01_flag"); + bool cs03Flag = _redisData.Get("YTCS_CallCtuEmptyIn_CS03_flag"); + if (cs01==true && !cs01Flag) { - MESEmptyCarryOutStkInput input = new MESEmptyCarryOutStkInput(); - input.org_id = ""; - input.location_code = "SSX-021-001"; - input.warehouse_id = WmsWareHouseConst.WAREHOUSE_ZC_ID; - input.carrystd_id = WmsWareHouseConst.LIAOXIANGID; - input.qty = 5; - Log.Information($"【EmptyCarryOutStk】左输送线空箱入呼叫开始,参数:{JsonConvert.SerializeObject(input)}"); - Result result = await _wmsEmptyOutstockService.MESEmptyCarryOutStk(input); - if (result.code == HttpStatusCode.OK) - { - Log.Information("【EmptyCarryOutStk】左输送线空箱入呼叫成功"); - _redisData.Set("CallCcuEmptyin_cs01_flag", true, TimeSpan.FromMinutes(20)); - } + BasFactoryConfig config = await _repository.AsSugarClient().Queryable().FirstAsync(x => x.enabled == 1 && x.key == FactoryConfigConst.DOMAIN); + HttpUtils.RequestGet($"http://localhost:9232/api/production/time-work/empty-carry-out-stk-left"); } - if (c503 && !c503Flag) + if (cs03==true && !cs03Flag) { - MESEmptyCarryOutStkInput input = new MESEmptyCarryOutStkInput(); - input.org_id = ""; - input.location_code = "SSX-021-003"; - input.warehouse_id = WmsWareHouseConst.WAREHOUSE_ZC_ID; - input.carrystd_id = WmsWareHouseConst.LIAOXIANGID; - input.qty = 5; - Log.Information($"【EmptyCarryOutStk】右输送线空箱入呼叫开始,参数:{JsonConvert.SerializeObject(input)}"); - Result result = await _wmsEmptyOutstockService.MESEmptyCarryOutStk(input); - if (result.code == HttpStatusCode.OK) - { - Log.Information("【EmptyCarryOutStk】右输送线空箱入呼叫成功"); - _redisData.Set("CallCtuEmptyin c503_flag", true, TimeSpan.FromMinutes(20)); - } + BasFactoryConfig config = await _repository.AsSugarClient().Queryable().FirstAsync(x => x.enabled == 1 && x.key == FactoryConfigConst.DOMAIN); + HttpUtils.RequestGet($"http://localhost:9232/api/production/time-work/empty-carry-out-stk-right"); } - return Task.CompletedTask; } + [HttpGet] + [AllowAnonymous] + public async Task EmptyCarryOutStkLeft() + { + MESEmptyCarryOutStkInput input = new MESEmptyCarryOutStkInput(); + input.org_id = WmsWareHouseConst.AdministratorOrgId; + input.location_code = "SSX-021-001"; + input.warehouse_id = WmsWareHouseConst.WAREHOUSE_ZC_ID; + input.carrystd_id = WmsWareHouseConst.LIAOXIANGID; + input.qty = 1; + input.create_id = WmsWareHouseConst.AdministratorUserId; + Log.Information($"【EmptyCarryOutStk】左输送线空箱入呼叫开始,参数:{JsonConvert.SerializeObject(input)}"); + Result result = await _wmsEmptyOutstockService.MESEmptyCarryOutStk(input); + if (result.code == HttpStatusCode.OK) + { + Log.Information("【EmptyCarryOutStk】左输送线空箱入呼叫成功"); + //_redisData.Set("YTCS_CallCtuEmptyIn_CS01_flag", true, TimeSpan.FromMinutes(20)); + } + return Task.CompletedTask; + } + + [HttpGet] + [AllowAnonymous] + public async Task EmptyCarryOutStkRight() + { + MESEmptyCarryOutStkInput input = new MESEmptyCarryOutStkInput(); + input.org_id = WmsWareHouseConst.AdministratorOrgId; + input.location_code = "SSX-021-003"; + input.warehouse_id = WmsWareHouseConst.WAREHOUSE_ZC_ID; + input.carrystd_id = WmsWareHouseConst.LIAOXIANGID; + input.qty = 1; + input.create_id = WmsWareHouseConst.AdministratorUserId; + Log.Information($"【EmptyCarryOutStk】右输送线空箱入呼叫开始,参数:{JsonConvert.SerializeObject(input)}"); + Result result = await _wmsEmptyOutstockService.MESEmptyCarryOutStk(input); + if (result.code == HttpStatusCode.OK) + { + Log.Information("【EmptyCarryOutStk】右输送线空箱入呼叫成功"); + //_redisData.Set("YTCS_CallCtuEmptyIn_CS03_flag", true, TimeSpan.FromMinutes(20)); + } + return Task.CompletedTask; + } + [HttpGet] [AllowAnonymous] public async Task FixedPointDelivery() { - bool value = _redisData.Get("DB100.132.0"); - bool valueFlag = _redisData.Get("DB100.132.0_flag"); - if (value && !valueFlag) + bool? value = await _redisData.TryGetValueByKeyField("hxjA", "DB100.132.0"); + bool valueFlag = _redisData.Get("hxjA_DB100.132.0_flag"); + if (value==true && !valueFlag) { + bool? cs01 = await _redisData.TryGetValueByKeyField("YTCS", "CallCtuEmptyIn_CS01"); + bool? cs03 = await _redisData.TryGetValueByKeyField("YTCS", "CallCtuEmptyIn_CS03"); + string startLocationCode = cs01==false ? "SSX-021-001" : cs03==false ? "SSX-021-003" : ""; + if (startLocationCode.IsEmpty()) + { + return Task.CompletedTask; + } + var db = _repository.AsSugarClient(); Dictionary postData = new Dictionary(); @@ -125,7 +181,7 @@ namespace Tnb.ProductionMgr if(authResponse.code == 200 && authResponse.data.ObjToBool()) { Log.Information("【FixedPointDelivery】注塑定点配送成功"); - _redisData.Set("DB100.132.0_flag", true, TimeSpan.FromMinutes(20)); + //_redisData.Set("DB100.132.0_flag", true, TimeSpan.FromMinutes(20)); } else { diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsEmptyOutstockService .cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsEmptyOutstockService .cs index a2754ae6..20344846 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsEmptyOutstockService .cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsEmptyOutstockService .cs @@ -5,11 +5,13 @@ using JNPF.Common.Extension; using JNPF.Common.Security; using JNPF.EventBus; using JNPF.FriendlyException; +using JNPF.Logging; using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; using JNPF.VisualDev.Entitys; using JNPF.VisualDev.Interfaces; using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; using SqlSugar; using Tnb.BasicData.Entities; using Tnb.WarehouseMgr.Entities; @@ -19,6 +21,7 @@ using Tnb.WarehouseMgr.Entities.Dto; using Tnb.WarehouseMgr.Entities.Dto.Inputs; using Tnb.WarehouseMgr.Entities.Enums; using Tnb.WarehouseMgr.Interfaces; +using Result = Tnb.WarehouseMgr.Entities.Dto.Outputs.Result; namespace Tnb.WarehouseMgr @@ -86,6 +89,7 @@ namespace Tnb.WarehouseMgr // && a.carry_status == ((int)EnumCarryStatus.空闲).ToString() && a.is_lock == 0 && b.is_lock == 0 && b.is_type == ((int)EnumLocationType.存储库位).ToString()) // .ToListAsync(); // 判断最终目标库位是否可以放置当前载具 + WmsEmptyOutstockH wmsEmptyOutstockH = null; if (carrys?.Count > 0) { WmsCarryH curCarry = carrys[^carrys.Count]; @@ -95,8 +99,12 @@ namespace Tnb.WarehouseMgr throw new AppFriendlyException("该载具无法放置到目标库位", 500); } - VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleConsts.MODULE_WMSEMPTYOUTSTK_ID, true); - await _runService.Create(templateEntity, input); + // VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleConsts.MODULE_WMSEMPTYOUTSTK_ID, true); + // await _runService.Create(templateEntity, input); + + wmsEmptyOutstockH = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(input.data)); + wmsEmptyOutstockH.id = SnowflakeIdHelper.NextId(); + await _db.Insertable(wmsEmptyOutstockH).ExecuteCommandAsync(); } @@ -144,7 +152,7 @@ namespace Tnb.WarehouseMgr WmsPretaskH preTask = new() { - org_id = _userManager.User.OrganizeId, + org_id = wmsEmptyOutstockH.org_id, startlocation_id = sPoint?.location_id!, startlocation_code = sPoint?.location_code!, endlocation_id = ePoint?.location_id!, @@ -163,9 +171,10 @@ namespace Tnb.WarehouseMgr carry_code = carrys![i].carry_code, area_id = sPoint?.area_id!, area_code = it.Key, - require_id = input.data["ReturnIdentity"].ToString(), + // require_id = input.data["ReturnIdentity"].ToString(), + require_id = wmsEmptyOutstockH.id, require_code = input.data[nameof(preTask.bill_code)]?.ToString()!, - create_id = _userManager.UserId, + create_id = wmsEmptyOutstockH.create_id, create_time = DateTime.Now }; @@ -184,7 +193,7 @@ namespace Tnb.WarehouseMgr { GenPreTaskUpInput preTaskUpInput = new() { - RquireId = input.data["ReturnIdentity"].ToString()!, + RquireId = wmsEmptyOutstockH.id!, CarryId = carrys![i].id, CarryStartLocationId = points!.FirstOrDefault()!.location_id!, CarryStartLocationCode = points!.FirstOrDefault()!.location_code!, @@ -201,7 +210,7 @@ namespace Tnb.WarehouseMgr status = WmsWareHouseConst.BILLSTATUS_ON_ID, carry_id = carrys[i].id, carry_code = carrys[i].carry_code, - create_id = _userManager.UserId, + create_id = wmsEmptyOutstockH.create_id, create_time = DateTime.Now }; _ = await _db.Insertable(wmsEmptyOutstockD) @@ -300,6 +309,7 @@ namespace Tnb.WarehouseMgr [nameof(WmsEmptyOutstockH.status)] = WmsWareHouseConst.BILLSTATUS_ADD_ID, [nameof(WmsEmptyOutstockH.qty)] = input.qty, [nameof(WmsEmptyOutstockH.biz_type)] = WmsWareHouseConst.BIZTYPE_WMSEPTYOUTSTK_ID, + ["warehouse_id"] = input.warehouse_id, [nameof(WmsEmptyOutstockH.create_id)] = input.create_id, [nameof(WmsEmptyOutstockH.create_time)] = DateTime.Now }; @@ -312,10 +322,11 @@ namespace Tnb.WarehouseMgr } catch (Exception ex) { + Log.Error(ex.Message,ex); await _db.Ado.RollbackTranAsync(); return await ToApiResult(JNPF.Common.Enums.HttpStatusCode.InternalServerError, ex.Message); } - return ToApiResult(); + return new Result(); } } } diff --git a/common/Tnb.Common/Redis/RedisData.cs b/common/Tnb.Common/Redis/RedisData.cs index 3c296f5c..8b06a2b8 100644 --- a/common/Tnb.Common/Redis/RedisData.cs +++ b/common/Tnb.Common/Redis/RedisData.cs @@ -8,6 +8,7 @@ using JNPF; using JNPF.Common.Cache; using JNPF.DependencyInjection; using Microsoft.Extensions.Options; +using Newtonsoft.Json; namespace Tnb.Common.Redis { @@ -243,5 +244,25 @@ namespace Tnb.Common.Redis { return _instance.HSetAsync(key, field, value); } + + public async Task TryGetValueByKeyField(string key, string field) + { + if (await _instance.HExistsAsync(key, field)) + { + string data = await GetHash(key, field); + Dictionary json = JsonConvert.DeserializeObject>(data); + Type type = typeof(T); + if (!type.IsValueType || (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))) + { + return (T)Convert.ChangeType(json["Value"],type.GetGenericArguments()[0]); + } + else + { + return (T)Convert.ChangeType(json["Value"],type); + } + // return ; + } + return default(T); + } } } \ No newline at end of file