提报获取重量

This commit is contained in:
2024-05-22 16:37:56 +08:00
parent a53623823c
commit 90b567f653
6 changed files with 130 additions and 61 deletions

View File

@@ -1,18 +1,24 @@
using System.Reflection;
using JNPF;
using JNPF.Common.Cache;
using JNPF.Common.Dtos.VisualDev;
using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.FriendlyException;
using JNPF.Logging;
using JNPF.VisualDev;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SqlSugar;
using Tnb.Common.Extension;
using Tnb.Common.Redis;
using Tnb.ProductionMgr.Entities;
using Tnb.ProductionMgr.Interfaces;
using Tnb.WarehouseMgr.Entities.Configs;
using Tnb.Common.Utils;
using Tnb.EquipMgr.Entities;
namespace Tnb.ProductionMgr
{
@@ -27,6 +33,7 @@ namespace Tnb.ProductionMgr
private const string ModuleId = "30062789830933";
private readonly RedisData _redisData;
private readonly ISqlSugarRepository<RedisReadConfig> _repository;
private readonly ElevatorControlConfiguration _eleCtlCfg = App.Configuration.Build<ElevatorControlConfiguration>();
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
public RedisDataService(RedisData redisData, ISqlSugarRepository<RedisReadConfig> repository)
{
@@ -54,14 +61,60 @@ namespace Tnb.ProductionMgr
[HttpPost]
public async Task<dynamic> GetWeight(string device, string jihao)
{
bool flag = await _redisData.HashExist(device, jihao);
EqpDaq eqpDaq1 = await _repository.AsSugarClient().Queryable<EqpDaq>().Where(x => x.equip_code == device && x.label_name.Contains("允许称重")).FirstAsync();
if (eqpDaq1 == null)
{
throw Oops.Bah("未在数据采集中设置允许称重标签点");
}
Dictionary<string, string> dicCommand = new(StringComparer.OrdinalIgnoreCase)
{
["DevName"] = device,
["token"] = _eleCtlCfg.token,
["TagName"] = eqpDaq1.label_point,
["Value"] = "true",
};
Log.Information($"确认称重参数:{JsonConvert.SerializeObject(dicCommand)}");
var str = await HttpClientHelper.GetRequestAsync(_eleCtlCfg.WriteTagUrl, dicCommand);
EqpDaq eqpDaq2 = await _repository.AsSugarClient().Queryable<EqpDaq>().Where(x => x.equip_code == device && x.label_name.Contains("当前重量")).FirstAsync();
if (eqpDaq2 == null)
{
throw Oops.Bah("未在数据采集中设置当前重量标签点");
}
bool flag = await _redisData.HashExist(device, eqpDaq2.label_point);
if (!flag)
{
throw Oops.Bah("没有找到" + device + "----" + jihao + "的数据");
throw Oops.Bah("没有找到" + device + "----" + eqpDaq2.label_point + "的数据");
}
string data = await _redisData.GetHash(device, jihao);
string data = await _redisData.GetHash(device, eqpDaq2.label_point);
JObject? res = JsonConvert.DeserializeObject<JObject>(data);
decimal result = res != null && res["Value"] != null ? decimal.Parse(res["Value"]!.ToString()) : throw Oops.Bah("数据格式错误");
if (result > 0)
{
EqpDaq eqpDaq3 = await _repository.AsSugarClient().Queryable<EqpDaq>().Where(x => x.equip_code == device && x.label_name.Contains("称重完成")).FirstAsync();
if (eqpDaq3 == null)
{
throw Oops.Bah("未在数据采集中设置称重完成标签点");
}
Dictionary<string, string> dicCommand2 = new(StringComparer.OrdinalIgnoreCase)
{
["DevName"] = device,
["token"] = _eleCtlCfg.token,
["TagName"] = eqpDaq3.label_point,
["Value"] = "false",
};
Log.Information($"称重完成参数:{JsonConvert.SerializeObject(dicCommand)}");
for (int i = 0; i < 5; i++)
{
await HttpClientHelper.GetRequestAsync(_eleCtlCfg.WriteTagUrl, dicCommand);
}
}
return result;
}
}