diff --git a/DOAN.Admin.WebApi/Controllers/huate_group/CloudMonitor/ZiyuanDevice01Controller.cs b/DOAN.Admin.WebApi/Controllers/huate_group/CloudMonitor/ZiyuanDevice01Controller.cs
index 2b9c9a7..28409e3 100644
--- a/DOAN.Admin.WebApi/Controllers/huate_group/CloudMonitor/ZiyuanDevice01Controller.cs
+++ b/DOAN.Admin.WebApi/Controllers/huate_group/CloudMonitor/ZiyuanDevice01Controller.cs
@@ -59,7 +59,7 @@ namespace DOAN.Admin.WebApi.Controllers.Business
///
[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(ids);
+ var idArr = Tools.SplitAndConvert(ids);
return ToResponse(_ZiyuanDevice01Service.Delete(idArr));
}
diff --git a/DOAN.Model/System/Model/SysTasks.cs b/DOAN.Model/System/Model/SysTasks.cs
index 50b49b8..6d41035 100644
--- a/DOAN.Model/System/Model/SysTasks.cs
+++ b/DOAN.Model/System/Model/SysTasks.cs
@@ -4,7 +4,7 @@
///计划任务
///
[SugarTable("sys_tasks", "计划任务表")]
- [Tenant(0)]
+ [Tenant(1)]
public class SysTasks : SysBase
{
public SysTasks()
diff --git a/DOAN.Model/huate_group/CloudMonitor/ZiyuanDevice01.cs b/DOAN.Model/huate_group/CloudMonitor/ZiyuanDevice01.cs
index aa6cac6..1a1bcc6 100644
--- a/DOAN.Model/huate_group/CloudMonitor/ZiyuanDevice01.cs
+++ b/DOAN.Model/huate_group/CloudMonitor/ZiyuanDevice01.cs
@@ -11,8 +11,16 @@ namespace DOAN.Model.huate_group.CloudMonitor
/// Id
///
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
- public int Id { get; set; }
+ public string Id { get; set; }
+
+
+ ///
+ /// 配方id
+ ///
+ [SugarColumn(ColumnName = "fk_recipe_id")]
+ public int FkRecipeId { get; set; }
+
///
/// 地点
///
diff --git a/DOAN.Service/huate_group/CloudMonitor/IServcie/IZiyuanDevice01Service.cs b/DOAN.Service/huate_group/CloudMonitor/IServcie/IZiyuanDevice01Service.cs
index 0f700ce..7363e0c 100644
--- a/DOAN.Service/huate_group/CloudMonitor/IServcie/IZiyuanDevice01Service.cs
+++ b/DOAN.Service/huate_group/CloudMonitor/IServcie/IZiyuanDevice01Service.cs
@@ -10,7 +10,7 @@ namespace DOAN.Service.huate_group.CloudMonitor.IService
{
PagedInfo GetList(ZiyuanDevice01QueryDto parm);
- ZiyuanDevice01 GetInfo(int Id);
+ ZiyuanDevice01 GetInfo(string Id);
ZiyuanDevice01 AddZiyuanDevice01(ZiyuanDevice01 parm);
diff --git a/DOAN.Service/huate_group/CloudMonitor/ZiyuanDevice01Service.cs b/DOAN.Service/huate_group/CloudMonitor/ZiyuanDevice01Service.cs
index 4eb37a8..c229653 100644
--- a/DOAN.Service/huate_group/CloudMonitor/ZiyuanDevice01Service.cs
+++ b/DOAN.Service/huate_group/CloudMonitor/ZiyuanDevice01Service.cs
@@ -19,10 +19,7 @@ namespace DOAN.Service.huate_group.CloudMonitor
{
return Context.AsTenant().QueryableWithAttr().ToList();
}
- //TODO 获取车型
-
- //TODO 获取零件号
///
/// 查询小房间热熔焊接列表
///
@@ -65,7 +62,7 @@ namespace DOAN.Service.huate_group.CloudMonitor
///
///
///
- public ZiyuanDevice01 GetInfo(int Id)
+ public ZiyuanDevice01 GetInfo(string Id)
{
var response = Queryable()
.Where(x => x.Id == Id)
diff --git a/DOAN.Tasks/TaskScheduler/YIDA_dataUpload_Task.cs b/DOAN.Tasks/TaskScheduler/YIDA_dataUpload_Task.cs
index 5ea593c..386118a 100644
--- a/DOAN.Tasks/TaskScheduler/YIDA_dataUpload_Task.cs
+++ b/DOAN.Tasks/TaskScheduler/YIDA_dataUpload_Task.cs
@@ -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 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()
+ .AsTenant().QueryableWithAttr()
.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().TableName;
+ if (!string.IsNullOrEmpty(tablecode))
+ {
+ ReflexAccount reflexAccount = DbScoped.SugarScope.CopyNew().AsTenant()
+ .QueryableWithAttr().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().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
/// 异步任务 数据上传
///
///
- public Task dataUpLoad() where T : ZiyuanDevice01, new()
+ public Task dataUpLoad() where T : ZiyuanDevice01, new()
{
- return Task.Run(() =>
+ return Task.Run(() =>
{
int flag = 0;
//1.读取设备数据
- List device01s = DbScoped.SugarScope.Queryable().Where(it => it.IsUpload == 0).Take(600).ToList();
+ List device01s = DbScoped.SugarScope.AsTenant().QueryableWithAttr().Where(it => it.IsUpload == 0).Take(60).ToList();
List yidas = new List();
//2.上传到宜搭
@@ -120,18 +134,22 @@ namespace DOAN.Tasks.TaskScheduler
//2.2 上传数据
if (device01s != null && device01s.Count > 0)
{
- var query = DbScoped.SugarScope.Queryable().ToList();
+ var query = DbScoped.SugarScope.AsTenant().QueryableWithAttr().ToList();
+
+ List itemsToRemove = new List();
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(device01s).ExecuteCommand();
+
+ flag = DbScoped.SugarScope.AsTenant().UpdateableWithAttr(device01s).ExecuteCommand();
}