43 lines
1.4 KiB
C#
43 lines
1.4 KiB
C#
using JNPF.Common.Cache;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.FriendlyException;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using Tnb.Common.Redis;
|
|
using Tnb.ProductionMgr.Interfaces;
|
|
|
|
namespace Tnb.ProductionMgr
|
|
{
|
|
/// <summary>
|
|
/// 数据采集
|
|
/// </summary>
|
|
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 700)]
|
|
[Route("api/[area]/[controller]/[action]")]
|
|
public class RedisDataService : IRedisDataService, IDynamicApiController, ITransient
|
|
{
|
|
private readonly RedisData _redisData;
|
|
public RedisDataService(RedisData redisData)
|
|
{
|
|
_redisData = redisData;
|
|
}
|
|
/// <summary>
|
|
/// 根据机号获取重量
|
|
/// </summary>
|
|
[HttpPost]
|
|
public async Task<dynamic> GetWeight(string device, string jihao)
|
|
{
|
|
bool flag = await _redisData.HashExist(device, jihao);
|
|
if (!flag)
|
|
{
|
|
throw Oops.Bah("没有找到" + device + "----" + jihao + "的数据");
|
|
}
|
|
string data = await _redisData.GetHash(device, jihao);
|
|
JObject? res = JsonConvert.DeserializeObject<JObject>(data);
|
|
decimal result = res != null && res["Value"] != null ? decimal.Parse(res["Value"]!.ToString()) : throw Oops.Bah("数据格式错误");
|
|
return result;
|
|
}
|
|
}
|
|
}
|