This commit is contained in:
qianjiawei
2023-12-18 17:17:48 +08:00
parent dc784077f0
commit 296c618bf5
5 changed files with 111 additions and 125 deletions

View File

@@ -4,6 +4,7 @@ using System.Security.Policy;
using Aop.Api.Domain;
using JNPF;
using JNPF.Common.Cache;
using JNPF.Common.Dtos.VisualDev;
using JNPF.FriendlyException;
using Microsoft.Extensions.Hosting;
using NetTaste;
@@ -19,32 +20,36 @@ using Tnb.ProductionMgr.Entities.Enums;
using Tnb.ProductionMgr.Interfaces;
using Tnb.WarehouseMgr.Entities;
using Tnb.WarehouseMgr.Entities.Consts;
using Tnb.WarehouseMgr.Interfaces;
namespace Tnb.ProductionMgr
{
//redis定时获取数采数据
public class RedisBackGround : IHostedService, IDisposable
{
private Timer? Readtimer;
private Timer? Readtimer;
private Timer? CheckGettimer;
private Timer? Scantimer;
private readonly RedisData _redisData;
private readonly IPrdInstockService _prdInstockService;
private readonly ISqlSugarRepository<RedisReadConfig> _repository;
public RedisBackGround(RedisData redisData, IPrdInstockService prdInstockService, ISqlSugarRepository<RedisReadConfig> repository)
private readonly IWmsPDAScanInStockService _wmsPDAScanInStock;
public RedisBackGround(RedisData redisData, IPrdInstockService prdInstockService, ISqlSugarRepository<RedisReadConfig> repository, IWmsPDAScanInStockService wmsPDAScanInStock)
{
_redisData = redisData;
_prdInstockService = prdInstockService;
_repository = repository;
_repository = repository;
_wmsPDAScanInStock = wmsPDAScanInStock;
}
//获取redis数据
private void GetRedisData(object state)
{
var _redisReadConfigs = _repository.AsQueryable().Where(p => p.enabled == 1).ToList();
var _redisReadConfigs = _repository.AsQueryable().Where(p => p.enabled == 1).ToList();
foreach (var config in _redisReadConfigs)
{
try
{
var json= _redisData.GetHash(config.dev_name!, config.tag_name!).Result;
var json = _redisData.GetHash(config.dev_name!, config.tag_name!).Result;
JObject? res = JsonConvert.DeserializeObject<JObject>(json);
if (config.data_type == (int)DataType.INT)
{
@@ -62,7 +67,7 @@ namespace Tnb.ProductionMgr
}
else if (config.check_type == (int)CheckType.)
{
int[] ints= Array.ConvertAll(config.data!.Replace("[","").Replace("]","").Split(",",StringSplitOptions.RemoveEmptyEntries),int.Parse);
int[] ints = Array.ConvertAll(config.data!.Replace("[", "").Replace("]", "").Split(",", StringSplitOptions.RemoveEmptyEntries), int.Parse);
if (ints.Contains(res.Value<int>("Value")))
{
InstockInput instockInput = new()
@@ -132,14 +137,14 @@ namespace Tnb.ProductionMgr
string codedata = _redisData.GetHash(strs[0], strs[2]).Result;
JObject? coderes = JsonConvert.DeserializeObject<JObject>(codedata);
string coderesult = coderes != null && coderes["Value"] != null ? coderes.Value<string>("Value")! : "";
var DistaskH= _repository.AsSugarClient().Queryable<WmsDistaskH>().Where(p => p.carry_code == coderesult && p.status == WmsWareHouseConst.TASK_BILL_STATUS_RUNING_ID).First();
var DistaskH = _repository.AsSugarClient().Queryable<WmsDistaskH>().Where(p => p.carry_code == coderesult && p.status == WmsWareHouseConst.TASK_BILL_STATUS_RUNING_ID).First();
dynamic reqBody = new ExpandoObject();
reqBody.taskCode = DistaskH.bill_code;
reqBody.slotCode = key;
reqBody.containerCode = coderesult;
CancellationTokenSource Ctu = new();
//{"code":500,"msg":"成功!"}
dynamic respBody = HttpClientHelper.PostStreamAsync("http://192.168.11.104:1880/wcs/notify/cargo", reqBody, Ctu.Token).Result;
dynamic respBody = HttpClientHelper.PostStreamAsync("http://192.168.11.104:1880/wcs/notify/cargo", reqBody, Ctu.Token).Result;
Ctu.Dispose();
}
}
@@ -149,120 +154,34 @@ namespace Tnb.ProductionMgr
}
}
}
//扫码入库
private void ScanInStock(object state)
{
var carry_code = "carry_code";
WmsCarryH? carry = _repository.AsSugarClient().Queryable<WmsCarryH>().Single(it => it.carry_code == carry_code);
if (carry != null)
{
var WmsCarryCode = _repository.AsSugarClient().Queryable<WmsCarryCode>().Single(it => it.carry_id == carry.id);
//获取注塑装箱状态
private void GetZSPackStatus(object state)
{
try
{
string[] strs = new string[1] { "TY4C-ZHUSU1" };
string sign = "agvMode";
foreach (string s in strs)
{
Dictionary<string, string> dic = _redisData.HGetAll(s).Result;
foreach (KeyValuePair<string, string> kv in dic)
{
if (!kv.Key.Contains(sign))
{
continue;
}
JObject? res = JsonConvert.DeserializeObject<JObject>(kv.Value);
if (res != null && res["Value"] != null)
{
if (int.Parse(res["Value"]!.ToString()) is not ((int)Eagvmode.) and not ((int)Eagvmode.))
{
InstockInput instockInput = new()
{
equip_code = res["DevName"]!.ToString(),
label_code = res["TagName"]!.ToString()
};
_prdInstockService.InstockTypeOne(instockInput);
}
}
}
}
}
catch (Exception)
{
}
}
//获取挤出装箱状态
private void GetJCPackStatus(object state)
{
try
{
string[] strs = new string[1] { "TY4C-SHUSONG-JC" };
string sign = "AGVFullCall";
foreach (string s in strs)
{
Dictionary<string, string> dic = _redisData.HGetAll(s).Result;
foreach (KeyValuePair<string, string> kv in dic)
{
if (!kv.Key.Contains(sign))
{
continue;
}
JObject? res = JsonConvert.DeserializeObject<JObject>(kv.Value);
if (res != null && res["Value"] != null)
{
if (res.Value<bool>("Value"))
{
InstockInput instockInput = new()
{
equip_code = res["DevName"]!.ToString(),
label_code = res["TagName"]!.ToString()
};
_prdInstockService.InstockTypeOne(instockInput);
}
}
}
}
}
catch (Exception)
{
}
}
//获取限位状态
private void GetLimitStatus(object state)
{
/*
Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss}");
Console.WriteLine($"获取挤出装箱状态");
string data = _redisData.GetHash("TY4C-SHUSONG-JC", "AGVFullCall").Result;
Console.WriteLine(data);*/
try
{
string[] strs = new string[1] { "TY4C-WAIBAO" };
string sign = "AGVCall";
foreach (string s in strs)
{
Dictionary<string, string> dic = _redisData.HGetAll(s).Result;
foreach (KeyValuePair<string, string> kv in dic)
{
if (!kv.Key.Contains(sign))
{
continue;
}
JObject? res = JsonConvert.DeserializeObject<JObject>(kv.Value);
if (res != null && res["Value"] != null)
{
if (res.Value<bool>("Value"))
{
InstockInput instockInput = new()
{
equip_code = res["DevName"]!.ToString(),
label_code = res["TagName"]!.ToString()
};
_prdInstockService.InstockOutPack(instockInput);
}
}
}
}
}
catch (Exception)
{
VisualDevModelDataCrInput input = new VisualDevModelDataCrInput();
input.data = new Dictionary<string, object>();
input.data.Add("barcode", carry_code);
input.data.Add("codeqty", WmsCarryCode.codeqty);//条码数量
input.data.Add("material_code", WmsCarryCode.material_code);
input.data.Add("extras", WmsCarryCode.location_code);//location_code
input.data.Add("warehouse_id", WmsCarryCode.warehouse_id!);
input.data.Add("bill_code", "");//采购收货单号
input.data.Add("code_batch", WmsCarryCode.code_batch!);//批次
input.data.Add("material_specification", WmsCarryCode.material_specification!);//规格型号
input.data.Add("container_no", WmsCarryCode.container_no!);//箱号
input.data.Add("material_id", WmsCarryCode.material_id);
input.data.Add("id", null);
_wmsPDAScanInStock.ScanInStock(input);
}
}
public void Dispose()
{
Readtimer?.Dispose();
@@ -270,8 +189,9 @@ namespace Tnb.ProductionMgr
}
public Task StartAsync(CancellationToken cancellationToken)
{
// Readtimer = new Timer(GetRedisData, null, TimeSpan.Zero, TimeSpan.FromSeconds(300));
CheckGettimer = new Timer(CheckGet, null, TimeSpan.Zero, TimeSpan.FromSeconds(300));
// Readtimer = new Timer(GetRedisData, null, TimeSpan.Zero, TimeSpan.FromSeconds(300));
// CheckGettimer = new Timer(CheckGet, null, TimeSpan.Zero, TimeSpan.FromSeconds(300));
// Scantimer = new Timer(ScanInStock, null, TimeSpan.Zero, TimeSpan.FromSeconds(300));
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)

View File

@@ -16,7 +16,7 @@
<ProjectReference Include="..\..\QcMgr\Tnb.QcMgr.Interfaces\Tnb.QcMgr.Interfaces.csproj" />
<ProjectReference Include="..\..\taskschedule\Tnb.TaskScheduler\Tnb.TaskScheduler.csproj" />
<ProjectReference Include="..\..\visualdev\Tnb.VisualDev.Engine\Tnb.VisualDev.Engine.csproj" />
<ProjectReference Include="..\..\WarehouseMgr\Tnb.WarehouseMgr.Entities\Tnb.WarehouseMgr.Entities.csproj" />
<ProjectReference Include="..\..\WarehouseMgr\Tnb.WarehouseMgr.Interfaces\Tnb.WarehouseMgr.Interfaces.csproj" />
<ProjectReference Include="..\Tnb.ProductionMgr.Interfaces\Tnb.ProductionMgr.Interfaces.csproj" />
</ItemGroup>

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tnb.WarehouseMgr.Entities.Dto.Inputs
{
public class CarryMaterialBindInput
{
public string? carrycode { get; set; }
public List<CarryMaterialDetail> details { get; set; }
}
public class CarryMaterialDetail
{
public string? material_id { get; set; }
public string? material_code { get; set; }
public string? barcode { get; set; }
public string? code_batch { get; set; }
public string? codeqty { get; set; }
public int is_out { get; set; }
public string? unit_id { get; set; }
}
}

View File

@@ -1,4 +1,5 @@
using JNPF.Common.Core.Manager;
using System.Dynamic;
using JNPF.Common.Core.Manager;
using JNPF.Common.Dtos.VisualDev;
using JNPF.Common.Enums;
using JNPF.Common.Extension;
@@ -8,9 +9,14 @@ using JNPF.Systems.Interfaces.System;
using JNPF.VisualDev;
using JNPF.VisualDev.Entitys;
using JNPF.VisualDev.Interfaces;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Senparc.Weixin.MP.AdvancedAPIs.Card;
using SqlSugar;
using Tnb.WarehouseMgr.Entities;
using Tnb.WarehouseMgr.Entities.Dto;
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
using Tnb.WarehouseMgr.Entities.Enums;
using Tnb.WarehouseMgr.Interfaces;
@@ -41,6 +47,7 @@ namespace Tnb.WarehouseMgr
_userManager = userManager;
_billRullService = billRullService;
OverideFuncs.CreateAsync = CarryBind;
}
[NonAction]
public async Task<dynamic> CarryBind(VisualDevModelDataCrInput input)
@@ -129,8 +136,42 @@ namespace Tnb.WarehouseMgr
return Task.FromResult(true);
}
[HttpPost]
public async Task<dynamic> GetInfoByCode(string code)
{
var data = await _db.Queryable<WmsTempCode>().Where(p => p.barcode == code).FirstAsync();
if(data==null)
throw new AppFriendlyException("没有条码信息", 500);
var result = data.Adapt<CarryMaterialDetail>();
return result;
}
[HttpPost]
public async Task CarryMaterialBind(CarryMaterialBindInput input)
{
try
{
WmsCarryH? carry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.carry_code == input.carrycode);
List<WmsCarryCode> WmsCarryCodes = new List<WmsCarryCode>();
foreach (var detail in input.details)
{
var WmsCarryCode = detail.Adapt<WmsCarryCode>();
WmsCarryCode.id = SnowflakeIdHelper.NextId();
WmsCarryCode.carry_id = carry.id;
WmsCarryCode.is_out = 0;
WmsCarryCodes.Add(WmsCarryCode);
}
if (WmsCarryCodes.Count > 0)
await _db.Insertable(WmsCarryCodes).ExecuteCommandAsync();
}
catch (Exception)
{
throw new AppFriendlyException("绑定失败", 500);
}
}
/* public override async Task ModifyAsync(WareHouseUpInput input)
{

View File

@@ -595,13 +595,13 @@ namespace Tnb.WarehouseMgr
public class CustomEqualityComparer : EqualityComparer<WmsTempCode>
{
public bool Equals(WmsTempCode? x, WmsTempCode? y)
public override bool Equals(WmsTempCode? x, WmsTempCode? y)
{
// 判断两个对象是否相等的逻辑
return x?.barcode == y?.barcode && x?.require_id == y?.require_id;
}
public int GetHashCode([DisallowNull] WmsTempCode obj)
public override int GetHashCode([DisallowNull] WmsTempCode obj)
{
// 使用多个属性来计算哈希码
int hashCode = obj.barcode?.GetHashCode() ?? 0;