宜搭完工

This commit is contained in:
qianhao.xu 2024-08-28 09:32:48 +08:00
parent 30fc6e963e
commit fb9498452b
6 changed files with 63 additions and 34 deletions

View File

@ -59,7 +59,7 @@ namespace DOAN.Admin.WebApi.Controllers.Business
/// <returns></returns>
[HttpGet("{Id}")]
[ActionPermissionFilter(Permission = "ziyuandevice01:query")]
public IActionResult GetZiyuanDevice01(int Id)
public IActionResult GetZiyuanDevice01(string Id)
{
var response = _ZiyuanDevice01Service.GetInfo(Id);
@ -107,7 +107,7 @@ namespace DOAN.Admin.WebApi.Controllers.Business
[Log(Title = "小房间热熔焊接", BusinessType = BusinessType.DELETE)]
public IActionResult DeleteZiyuanDevice01([FromRoute]string ids)
{
var idArr = Tools.SplitAndConvert<int>(ids);
var idArr = Tools.SplitAndConvert<string>(ids);
return ToResponse(_ZiyuanDevice01Service.Delete(idArr));
}

View File

@ -4,7 +4,7 @@
///计划任务
///</summary>
[SugarTable("sys_tasks", "计划任务表")]
[Tenant(0)]
[Tenant(1)]
public class SysTasks : SysBase
{
public SysTasks()

View File

@ -11,8 +11,16 @@ namespace DOAN.Model.huate_group.CloudMonitor
/// Id
/// </summary>
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
public string Id { get; set; }
/// <summary>
/// 配方id
/// </summary>
[SugarColumn(ColumnName = "fk_recipe_id")]
public int FkRecipeId { get; set; }
/// <summary>
/// 地点
/// </summary>

View File

@ -10,7 +10,7 @@ namespace DOAN.Service.huate_group.CloudMonitor.IService
{
PagedInfo<ZiyuanDevice01Dto> GetList(ZiyuanDevice01QueryDto parm);
ZiyuanDevice01 GetInfo(int Id);
ZiyuanDevice01 GetInfo(string Id);
ZiyuanDevice01 AddZiyuanDevice01(ZiyuanDevice01 parm);

View File

@ -19,10 +19,7 @@ namespace DOAN.Service.huate_group.CloudMonitor
{
return Context.AsTenant().QueryableWithAttr<ReflexAccount>().ToList();
}
//TODO 获取车型
//TODO 获取零件号
/// <summary>
/// 查询小房间热熔焊接列表
/// </summary>
@ -65,7 +62,7 @@ namespace DOAN.Service.huate_group.CloudMonitor
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
public ZiyuanDevice01 GetInfo(int Id)
public ZiyuanDevice01 GetInfo(string Id)
{
var response = Queryable()
.Where(x => x.Id == Id)

View File

@ -30,20 +30,22 @@ using Infrastructure.Model;
using Microsoft.Extensions.Options;
using DOAN.Model;
using System.Net;
using System.Reflection;
using SqlSugar;
namespace DOAN.Tasks.TaskScheduler
{
[AppService(ServiceType = typeof(YIDA_dataUpload_Task), ServiceLifetime = LifeTime.Scoped)]
public class YIDA_dataUpload_Task : JobBase, IJob
public class YIDA_dataUpload_Task : JobBase, IJob
{
private readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
private readonly MqttPublisher publisher = null;
private readonly MqttPublicConfig mqttPublicConfig;
public YIDA_dataUpload_Task(IOptions<OptionsSetting> options)
{
OptionsSetting OptionsSetting = options.Value;
OptionsSetting OptionsSetting = options.Value;
mqttPublicConfig = OptionsSetting.mqttPublicConfig;
//init MQTT
publisher = new MqttPublisher(mqttPublicConfig.BrokerIp, mqttPublicConfig.ClientId, mqttPublicConfig.Port);
@ -53,11 +55,11 @@ namespace DOAN.Tasks.TaskScheduler
try
{
await publisher.ConnectAsync();
Console.WriteLine("---------------------------------上传开始");
AbstractTrigger trigger = (context as JobExecutionContextImpl).Trigger as AbstractTrigger;
var infoTask = await DbScoped.SugarScope.CopyNew()
.Queryable<SysTasks>()
.AsTenant().QueryableWithAttr<SysTasks>()
.FirstAsync(f => f.ID == trigger.JobName) ?? throw new CustomException($"任务{trigger?.JobName}宜搭数据上传任务执行失败,任务不存在");
if (infoTask != null)
@ -77,16 +79,28 @@ namespace DOAN.Tasks.TaskScheduler
await Task.WhenAll(t1);
if (t1.Result > 0)
{
//获取上传设备id
string tablecode = typeof(ZiyuanDevice01).GetCustomAttribute<SugarTable>().TableName;
if (!string.IsNullOrEmpty(tablecode))
{
ReflexAccount reflexAccount = DbScoped.SugarScope.CopyNew().AsTenant()
.QueryableWithAttr<ReflexAccount>().Where(it => it.TableCode == tablecode).First();
if (reflexAccount != null)
{
string jsonString = "{\"num\": " + t1.Result + ", \"datetime\": \"" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\"}";
await publisher.PublishAsync(mqttPublicConfig.Topic + $"/{reflexAccount.FkDeviceId}", jsonString)
;
}
//获取上传设备id
string tablecode = typeof(ZiyuanDevice01).Name;
ReflexAccount reflexAccount= DbScoped.SugarScope.CopyNew().AsTenant()
.QueryableWithAttr<ReflexAccount>().Where(it=>it.TableName== tablecode).First();
}
await publisher.PublishAsync(mqttPublicConfig.Topic+$"/{reflexAccount.FkDeviceId}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
;
}
Console.WriteLine("---------------------------------上传结束");
Console.WriteLine("---------------------------------上传结束" + t1.Result);
}
}
@ -97,7 +111,7 @@ namespace DOAN.Tasks.TaskScheduler
finally
{
await publisher.DisconnectAsync();
}
}
@ -105,13 +119,13 @@ namespace DOAN.Tasks.TaskScheduler
/// 异步任务 数据上传
/// </summary>
/// <returns></returns>
public Task<int> dataUpLoad<T>() where T : ZiyuanDevice01, new()
public Task<int> dataUpLoad<T>() where T : ZiyuanDevice01, new()
{
return Task.Run(() =>
return Task.Run(() =>
{
int flag = 0;
//1.读取设备数据
List<T> device01s = DbScoped.SugarScope.Queryable<T>().Where(it => it.IsUpload == 0).Take(600).ToList();
List<T> device01s = DbScoped.SugarScope.AsTenant().QueryableWithAttr<T>().Where(it => it.IsUpload == 0).Take(60).ToList();
List<string> yidas = new List<string>();
//2.上传到宜搭
@ -120,18 +134,22 @@ namespace DOAN.Tasks.TaskScheduler
//2.2 上传数据
if (device01s != null && device01s.Count > 0)
{
var query = DbScoped.SugarScope.Queryable<Recipee>().ToList();
var query = DbScoped.SugarScope.AsTenant().QueryableWithAttr<Recipee>().ToList();
List<T> itemsToRemove = new List<T>();
foreach (T item in device01s)
{
//1.1 判断设备配置情况
Recipee options = query.Where(it => it.DeviceName == item.Workstation && it.ParamterName == item.Paramter).First();
Recipee options = query
.Where(it => it.Id == item.FkRecipeId).FirstOrDefault();
if (options != null)
{ //不可上传
if (!(bool)options.IsUpload)
{
Console.WriteLine("设备名为" + typeof(T).Name + "不可上传,禁止上传");
device01s.Remove(item);
// device01s.Remove(item);
itemsToRemove.Add(item);
continue;
}
@ -141,7 +159,8 @@ namespace DOAN.Tasks.TaskScheduler
if (item.Value > item.UpValue || item.Value < item.LowValue)
{
Console.WriteLine("设备名为" + typeof(T).Name + "不合格数据,禁止上传");
device01s.Remove(item);
//device01s.Remove(item);
itemsToRemove.Add(item);
continue;
}
@ -151,9 +170,14 @@ namespace DOAN.Tasks.TaskScheduler
}
}
foreach (T item in itemsToRemove)
{
device01s.Remove(item);
}
if (device01s.Count > 0)
{
foreach (T item in device01s)
{
ZiyuanDevice_YIDA ziyuan = new ZiyuanDevice_YIDA();
@ -179,14 +203,14 @@ namespace DOAN.Tasks.TaskScheduler
yidas.Add(JsonConvert.SerializeObject(ziyuan));
}
}
}
BatchSaveFormDataResponse response = UploadYIDABatch(tokenResponse.Body.AccessToken.ToString(), yidas);
if (response != null && response.StatusCode == 200)
{
flag = DbScoped.SugarScope.Updateable<T>(device01s).ExecuteCommand();
flag = DbScoped.SugarScope.AsTenant().UpdateableWithAttr<T>(device01s).ExecuteCommand();
}