|
|
@@ -2,6 +2,7 @@
|
|
|
using FreeRedis;
|
|
|
using MessagePack;
|
|
|
using MessagePack.Resolvers;
|
|
|
+using SqlSugar;
|
|
|
using System;
|
|
|
using System.Collections.Concurrent;
|
|
|
using System.Collections.Generic;
|
|
|
@@ -13,7 +14,7 @@ using WCS.Core;
|
|
|
using WCS.Core.DataTrans;
|
|
|
using WCS.Entity;
|
|
|
using WCS.Entity.Protocol;
|
|
|
-using DbContext = Microsoft.EntityFrameworkCore.DbContext;
|
|
|
+using WCS.Service.Extensions;
|
|
|
|
|
|
namespace WCS.Service
|
|
|
{
|
|
|
@@ -23,7 +24,7 @@ namespace WCS.Service
|
|
|
|
|
|
public ProtocolProxy(string id, WCS_DATABLOCK db, ushort start, WCS_DEVICEPROTOCOL protocol) : base(id, db, start, protocol)
|
|
|
{
|
|
|
- _setMethod = typeof(DbContext).GetMethod("Set", new Type[] { })?.MakeGenericMethod(this.ProtocolDataType);
|
|
|
+ _setMethod = typeof(SqlSugarScope).GetMethod("Queryable", new Type[] { })?.MakeGenericMethod(this.ProtocolDataType);
|
|
|
}
|
|
|
|
|
|
private static readonly ConcurrentDictionary<Type, object[]> LastDatas = new();
|
|
|
@@ -32,19 +33,14 @@ namespace WCS.Service
|
|
|
{
|
|
|
if (!LastDatas.ContainsKey(this.ProtocolDataType))
|
|
|
{
|
|
|
- dynamic q = _setMethod.Invoke(db.Default, null);
|
|
|
- q = DynamicQueryableExtensions.Where(q, "ISLAST==@0", true);
|
|
|
- q = DynamicQueryableExtensions.OrderBy(q, "ID");
|
|
|
- q = DynamicQueryableExtensions.Select(q, "new(it.DEVICE.CODE as Code,it as Data)");
|
|
|
- var arr = Enumerable.ToArray(q);
|
|
|
- LastDatas[this.ProtocolDataType] = arr;
|
|
|
+ LastDatas[this.ProtocolDataType] = db.Default.Queryable<dynamic>().AS($"{this.ProtocolDataType.Name}", "it").Where("ISLAST=0").OrderBy("ID").ToArray();
|
|
|
}
|
|
|
dynamic datas = LastDatas[this.ProtocolDataType];
|
|
|
var list = new List<WCS_PROTOCOLDATA>();
|
|
|
foreach (var data in datas)
|
|
|
{
|
|
|
- if (data.Code == Protocol.DEVICE.CODE)
|
|
|
- list.Add(data.Data);
|
|
|
+ if (data.DEVICECOD == Protocol.DEVICE.CODE)
|
|
|
+ list.Add(data);
|
|
|
}
|
|
|
|
|
|
if (list.Count > 1)
|
|
|
@@ -68,18 +64,25 @@ namespace WCS.Service
|
|
|
|
|
|
if (last != null)
|
|
|
{
|
|
|
- db.Default.Insertable((object)last).ExecuteCommand();
|
|
|
+ var dc = TypeExtension.EntityClassToDictionary((object)last);
|
|
|
+ db.Default.Insertable(dc).AS($"{last.GetType().Name}").ExecuteCommand();
|
|
|
last.ISLAST = false;
|
|
|
}
|
|
|
|
|
|
- db.Default.Storageable(Protocol.DEVICE).ExecuteCommand();
|
|
|
-
|
|
|
- newobj.DEVICE = Protocol.DEVICE;
|
|
|
+ var a = db.Default.Storageable(Protocol.DEVICE).ExecuteCommand();
|
|
|
+ newobj.DEVICECOD = Protocol.DEVICE.CODE;
|
|
|
newobj.ISLAST = true;
|
|
|
newobj.UPDATETIME = DateTime.Now;
|
|
|
newobj.UPDATEUSER = user;
|
|
|
newobj.FRAME = LogicHandler.Frame;
|
|
|
- db.Default.Insertable((object)newobj).ExecuteCommand();
|
|
|
+ var typeName = newobj.GetType().Name;
|
|
|
+ if (!typeName.Contains("SRM") && !typeName.Contains("RGV"))
|
|
|
+ {
|
|
|
+ var f = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ var dc1 = TypeExtension.EntityClassToDictionary((object)newobj);
|
|
|
+ db.Default.Insertable(dc1).AS($"{typeName}").ExecuteCommand();
|
|
|
return newobj;
|
|
|
}
|
|
|
|
|
|
@@ -91,7 +94,7 @@ namespace WCS.Service
|
|
|
static ProtocolProxy()
|
|
|
{
|
|
|
MessagePackSerializer.DefaultOptions = StandardResolver.Options.WithCompression(MessagePackCompression.Lz4Block);
|
|
|
- Redis = new RedisClient("212.64.66.35,database=10");
|
|
|
+ Redis = new RedisClient("127.0.0.1,database=2");
|
|
|
Redis.Serialize = obj =>
|
|
|
{
|
|
|
var bytes = MessagePackSerializer.Serialize(obj);
|
|
|
@@ -103,9 +106,9 @@ namespace WCS.Service
|
|
|
return obj;
|
|
|
};
|
|
|
|
|
|
- Yg150Redis = new RedisClient("192.168.249.150,password=123456,database=1");
|
|
|
- Ygwms150Redis = new RedisClient("192.168.249.150,password=123456,database=0");
|
|
|
- Ygwcs150Redis = new RedisClient("192.168.249.150,password=123456,database=10");
|
|
|
+ Yg150Redis = new RedisClient("127.0.0.1,database=1");
|
|
|
+ Ygwms150Redis = new RedisClient("127.0.0.1,database=0");
|
|
|
+ Ygwcs150Redis = new RedisClient("127.0.0.1,database=3");
|
|
|
Ygwcs150Redis.Serialize = obj =>
|
|
|
{
|
|
|
var bytes = MessagePackSerializer.Serialize(obj);
|