注塑空载具出库优化

This commit is contained in:
2024-05-21 09:21:33 +08:00
parent 929b5378bc
commit 8537c29b49
3 changed files with 133 additions and 45 deletions

View File

@@ -2,6 +2,8 @@ using Aop.Api.Domain;
using JNPF; using JNPF;
using JNPF.Common.Core.Manager; using JNPF.Common.Core.Manager;
using JNPF.Common.Enums; using JNPF.Common.Enums;
using JNPF.Common.Extension;
using JNPF.Common.Security;
using JNPF.DependencyInjection; using JNPF.DependencyInjection;
using JNPF.DynamicApiController; using JNPF.DynamicApiController;
using JNPF.Extras.CollectiveOAuth.Models; using JNPF.Extras.CollectiveOAuth.Models;
@@ -51,6 +53,33 @@ namespace Tnb.ProductionMgr
_billRullService = billRullService; _billRullService = billRullService;
_wmsEmptyOutstockService = wmsEmptyOutstockService; _wmsEmptyOutstockService = wmsEmptyOutstockService;
} }
[HttpGet]
[AllowAnonymous]
public async Task<dynamic> 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;
}
/// <summary> /// <summary>
/// 注塑空载具出库 /// 注塑空载具出库
@@ -60,56 +89,83 @@ namespace Tnb.ProductionMgr
[AllowAnonymous] [AllowAnonymous]
public async Task<dynamic> EmptyCarryOutStk() public async Task<dynamic> EmptyCarryOutStk()
{ {
bool cs01 = _redisData.Get<bool>("CallCcuEmptyin_cs01"); bool? cs01 = await _redisData.TryGetValueByKeyField<bool?>("YTCS", "CallCtuEmptyIn_CS01");
bool c503 = _redisData.Get<bool>("CallCtuEmptyin c503"); bool? cs03 = await _redisData.TryGetValueByKeyField<bool?>("YTCS", "CallCtuEmptyIn_CS03");
bool cs01Flag = _redisData.Get<bool>("CallCcuEmptyin_cs01_flag"); bool cs01Flag = _redisData.Get<bool>("YTCS_CallCtuEmptyIn_CS01_flag");
bool c503Flag = _redisData.Get<bool>("CallCtuEmptyin c503_flag"); bool cs03Flag = _redisData.Get<bool>("YTCS_CallCtuEmptyIn_CS03_flag");
if (cs01 && !cs01Flag) if (cs01==true && !cs01Flag)
{ {
MESEmptyCarryOutStkInput input = new MESEmptyCarryOutStkInput(); BasFactoryConfig config = await _repository.AsSugarClient().Queryable<BasFactoryConfig>().FirstAsync(x => x.enabled == 1 && x.key == FactoryConfigConst.DOMAIN);
input.org_id = ""; HttpUtils.RequestGet($"http://localhost:9232/api/production/time-work/empty-carry-out-stk-left");
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));
}
} }
if (c503 && !c503Flag) if (cs03==true && !cs03Flag)
{ {
MESEmptyCarryOutStkInput input = new MESEmptyCarryOutStkInput(); BasFactoryConfig config = await _repository.AsSugarClient().Queryable<BasFactoryConfig>().FirstAsync(x => x.enabled == 1 && x.key == FactoryConfigConst.DOMAIN);
input.org_id = ""; HttpUtils.RequestGet($"http://localhost:9232/api/production/time-work/empty-carry-out-stk-right");
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));
}
} }
return Task.CompletedTask; return Task.CompletedTask;
} }
[HttpGet]
[AllowAnonymous]
public async Task<dynamic> 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<dynamic> 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] [HttpGet]
[AllowAnonymous] [AllowAnonymous]
public async Task<dynamic> FixedPointDelivery() public async Task<dynamic> FixedPointDelivery()
{ {
bool value = _redisData.Get<bool>("DB100.132.0"); bool? value = await _redisData.TryGetValueByKeyField<bool?>("hxjA", "DB100.132.0");
bool valueFlag = _redisData.Get<bool>("DB100.132.0_flag"); bool valueFlag = _redisData.Get<bool>("hxjA_DB100.132.0_flag");
if (value && !valueFlag) if (value==true && !valueFlag)
{ {
bool? cs01 = await _redisData.TryGetValueByKeyField<bool?>("YTCS", "CallCtuEmptyIn_CS01");
bool? cs03 = await _redisData.TryGetValueByKeyField<bool?>("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(); var db = _repository.AsSugarClient();
Dictionary<String, Object> postData = new Dictionary<string, object>(); Dictionary<String, Object> postData = new Dictionary<string, object>();
@@ -125,7 +181,7 @@ namespace Tnb.ProductionMgr
if(authResponse.code == 200 && authResponse.data.ObjToBool()) if(authResponse.code == 200 && authResponse.data.ObjToBool())
{ {
Log.Information("【FixedPointDelivery】注塑定点配送成功"); Log.Information("【FixedPointDelivery】注塑定点配送成功");
_redisData.Set("DB100.132.0_flag", true, TimeSpan.FromMinutes(20)); //_redisData.Set("DB100.132.0_flag", true, TimeSpan.FromMinutes(20));
} }
else else
{ {

View File

@@ -5,11 +5,13 @@ using JNPF.Common.Extension;
using JNPF.Common.Security; using JNPF.Common.Security;
using JNPF.EventBus; using JNPF.EventBus;
using JNPF.FriendlyException; using JNPF.FriendlyException;
using JNPF.Logging;
using JNPF.Systems.Interfaces.System; using JNPF.Systems.Interfaces.System;
using JNPF.VisualDev; using JNPF.VisualDev;
using JNPF.VisualDev.Entitys; using JNPF.VisualDev.Entitys;
using JNPF.VisualDev.Interfaces; using JNPF.VisualDev.Interfaces;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using SqlSugar; using SqlSugar;
using Tnb.BasicData.Entities; using Tnb.BasicData.Entities;
using Tnb.WarehouseMgr.Entities; using Tnb.WarehouseMgr.Entities;
@@ -19,6 +21,7 @@ using Tnb.WarehouseMgr.Entities.Dto;
using Tnb.WarehouseMgr.Entities.Dto.Inputs; using Tnb.WarehouseMgr.Entities.Dto.Inputs;
using Tnb.WarehouseMgr.Entities.Enums; using Tnb.WarehouseMgr.Entities.Enums;
using Tnb.WarehouseMgr.Interfaces; using Tnb.WarehouseMgr.Interfaces;
using Result = Tnb.WarehouseMgr.Entities.Dto.Outputs.Result;
namespace Tnb.WarehouseMgr 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()) // && a.carry_status == ((int)EnumCarryStatus.空闲).ToString() && a.is_lock == 0 && b.is_lock == 0 && b.is_type == ((int)EnumLocationType.存储库位).ToString())
// .ToListAsync(); // .ToListAsync();
// 判断最终目标库位是否可以放置当前载具 // 判断最终目标库位是否可以放置当前载具
WmsEmptyOutstockH wmsEmptyOutstockH = null;
if (carrys?.Count > 0) if (carrys?.Count > 0)
{ {
WmsCarryH curCarry = carrys[^carrys.Count]; WmsCarryH curCarry = carrys[^carrys.Count];
@@ -95,8 +99,12 @@ namespace Tnb.WarehouseMgr
throw new AppFriendlyException("该载具无法放置到目标库位", 500); throw new AppFriendlyException("该载具无法放置到目标库位", 500);
} }
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleConsts.MODULE_WMSEMPTYOUTSTK_ID, true); // VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleConsts.MODULE_WMSEMPTYOUTSTK_ID, true);
await _runService.Create(templateEntity, input); // await _runService.Create(templateEntity, input);
wmsEmptyOutstockH = JsonConvert.DeserializeObject<WmsEmptyOutstockH>(JsonConvert.SerializeObject(input.data));
wmsEmptyOutstockH.id = SnowflakeIdHelper.NextId();
await _db.Insertable(wmsEmptyOutstockH).ExecuteCommandAsync();
} }
@@ -144,7 +152,7 @@ namespace Tnb.WarehouseMgr
WmsPretaskH preTask = new() WmsPretaskH preTask = new()
{ {
org_id = _userManager.User.OrganizeId, org_id = wmsEmptyOutstockH.org_id,
startlocation_id = sPoint?.location_id!, startlocation_id = sPoint?.location_id!,
startlocation_code = sPoint?.location_code!, startlocation_code = sPoint?.location_code!,
endlocation_id = ePoint?.location_id!, endlocation_id = ePoint?.location_id!,
@@ -163,9 +171,10 @@ namespace Tnb.WarehouseMgr
carry_code = carrys![i].carry_code, carry_code = carrys![i].carry_code,
area_id = sPoint?.area_id!, area_id = sPoint?.area_id!,
area_code = it.Key, 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()!, require_code = input.data[nameof(preTask.bill_code)]?.ToString()!,
create_id = _userManager.UserId, create_id = wmsEmptyOutstockH.create_id,
create_time = DateTime.Now create_time = DateTime.Now
}; };
@@ -184,7 +193,7 @@ namespace Tnb.WarehouseMgr
{ {
GenPreTaskUpInput preTaskUpInput = new() GenPreTaskUpInput preTaskUpInput = new()
{ {
RquireId = input.data["ReturnIdentity"].ToString()!, RquireId = wmsEmptyOutstockH.id!,
CarryId = carrys![i].id, CarryId = carrys![i].id,
CarryStartLocationId = points!.FirstOrDefault()!.location_id!, CarryStartLocationId = points!.FirstOrDefault()!.location_id!,
CarryStartLocationCode = points!.FirstOrDefault()!.location_code!, CarryStartLocationCode = points!.FirstOrDefault()!.location_code!,
@@ -201,7 +210,7 @@ namespace Tnb.WarehouseMgr
status = WmsWareHouseConst.BILLSTATUS_ON_ID, status = WmsWareHouseConst.BILLSTATUS_ON_ID,
carry_id = carrys[i].id, carry_id = carrys[i].id,
carry_code = carrys[i].carry_code, carry_code = carrys[i].carry_code,
create_id = _userManager.UserId, create_id = wmsEmptyOutstockH.create_id,
create_time = DateTime.Now create_time = DateTime.Now
}; };
_ = await _db.Insertable(wmsEmptyOutstockD) _ = await _db.Insertable(wmsEmptyOutstockD)
@@ -300,6 +309,7 @@ namespace Tnb.WarehouseMgr
[nameof(WmsEmptyOutstockH.status)] = WmsWareHouseConst.BILLSTATUS_ADD_ID, [nameof(WmsEmptyOutstockH.status)] = WmsWareHouseConst.BILLSTATUS_ADD_ID,
[nameof(WmsEmptyOutstockH.qty)] = input.qty, [nameof(WmsEmptyOutstockH.qty)] = input.qty,
[nameof(WmsEmptyOutstockH.biz_type)] = WmsWareHouseConst.BIZTYPE_WMSEPTYOUTSTK_ID, [nameof(WmsEmptyOutstockH.biz_type)] = WmsWareHouseConst.BIZTYPE_WMSEPTYOUTSTK_ID,
["warehouse_id"] = input.warehouse_id,
[nameof(WmsEmptyOutstockH.create_id)] = input.create_id, [nameof(WmsEmptyOutstockH.create_id)] = input.create_id,
[nameof(WmsEmptyOutstockH.create_time)] = DateTime.Now [nameof(WmsEmptyOutstockH.create_time)] = DateTime.Now
}; };
@@ -312,10 +322,11 @@ namespace Tnb.WarehouseMgr
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.Error(ex.Message,ex);
await _db.Ado.RollbackTranAsync(); await _db.Ado.RollbackTranAsync();
return await ToApiResult(JNPF.Common.Enums.HttpStatusCode.InternalServerError, ex.Message); return await ToApiResult(JNPF.Common.Enums.HttpStatusCode.InternalServerError, ex.Message);
} }
return ToApiResult(); return new Result();
} }
} }
} }

View File

@@ -8,6 +8,7 @@ using JNPF;
using JNPF.Common.Cache; using JNPF.Common.Cache;
using JNPF.DependencyInjection; using JNPF.DependencyInjection;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Newtonsoft.Json;
namespace Tnb.Common.Redis namespace Tnb.Common.Redis
{ {
@@ -243,5 +244,25 @@ namespace Tnb.Common.Redis
{ {
return _instance.HSetAsync(key, field, value); return _instance.HSetAsync(key, field, value);
} }
public async Task<T> TryGetValueByKeyField<T>(string key, string field)
{
if (await _instance.HExistsAsync(key, field))
{
string data = await GetHash(key, field);
Dictionary<String, String> json = JsonConvert.DeserializeObject<Dictionary<String, String>>(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);
}
} }
} }