采集数据

1023
nodyang@aliyun.com 2 weeks ago
parent 37f97831a1
commit 026228a02e

@ -113,6 +113,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Service\PointLogService.cs" />
<Compile Include="Service\PointService.cs" />
<Compile Include="Service\UpdateLogService.cs" />
<Compile Include="Service\UserService.cs" />
<Compile Include="SystemEntityTypeBuilder.cs" />
</ItemGroup>

@ -15,7 +15,7 @@
/// <summary>
/// 页面的Id
/// </summary>
public long FunctionId { get; set; }
public string PointName { get; set; }
}

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Windows.Forms.VisualStyles;
using DB.Dto;
using DB.Entity;
using Tool;
namespace DB.Service
{
public class UpdateLogService
{
public bool AddOrUpdateLog(UserDto user,string address,uint value)
{
UpdateLog log = new UpdateLog
{
ID = SnowflakeFactory.NewId,
PointName = address,
CreateDate = DateTime.Now,
CreateUserId = user.Id.ToString(),
CreateUserName = user.UserName,
LastModifyUserId = "",
LastModifyUserName = "",
LastModifyDate = DateTime.Now
};
using (var dbContext = DbFactory.GetContext)
{
var firstOrDefault = dbContext.Query<UpdateLog>()
.Where(x=>x.PointName==address)
.OrderByDesc(x=>x.ID).FirstOrDefault();
if (firstOrDefault != null)
{
if (firstOrDefault.NewValue != value.ToString())
{
log.OldValue = firstOrDefault.NewValue;
log.NewValue = value.ToString();
dbContext.Insert(log);
}
}
else
{
log.OldValue = "";
log.NewValue = value.ToString();
dbContext.Insert(log);
}
}
return true;
}
}
}

@ -17,16 +17,22 @@ using Tool;
using System.Security.Principal;
using DB.Entity;
using DB;
using System.Threading;
using DB.Service;
using NewLife.Caching;
using Tool.Model;
namespace RfidWeb
{
public partial class FormMain : Form
{
private ILogNet logNet = ILogNetFactory.GetLogNet;
private ICache cache;
TimerX _timer;
public FormMain()
{
cache=Cache.Default;
DbInfo.Init(typeof(UserInfo).Assembly);
var rfidSetting = RfidSetting.Current;
@ -59,6 +65,8 @@ namespace RfidWeb
this.panContent.Controls.Clear();
this.panContent.Controls.Add(new UserMain());
}
@ -73,6 +81,36 @@ namespace RfidWeb
label1.Text = dataTime.ToString("yyyy'/'MM'/'dd");
label2.Text = dataTime.ToString("HH:mm:ss");
});
ThreadPoolX.QueueUserWorkItem(UpdateLog);
}
private UpdateLogService updateLogService = new UpdateLogService();
private void UpdateLog()
{
if(cache.ContainsKey("UpdateLog")) return;
cache.Set("UpdateLog", "d", TimeSpan.FromSeconds(10));
var plc = PlcConnect.Instance;
var userDto = TestFactory.TestUser();
var strings = HmiPoint.GetValue();
foreach (var se in strings)
{
var res = plc.ReadUInt32(se);
if (res.IsSuccess)
{
updateLogService.AddOrUpdateLog(userDto, se, res.Content);
}
}
cache.Remove("UpdateLog");
}
private void btnExit_Click(object sender, EventArgs e)

@ -7,6 +7,7 @@ using System.Windows.Forms;
using Chloe.PostgreSQL.DDL;
using Chloe.RDBMS.DDL;
using Tool;
using DB.Service;
namespace RfidWeb
{
@ -145,48 +146,9 @@ namespace RfidWeb
private void ucBtnExt2_BtnClick(object sender, EventArgs e)
{
var dbContext = DbFactory.GetContext;
var dic = new Dictionary<string, string>();
dic["HMI_button_LP_ON[0].0"] = "右料盘横移电缸";
for (int i = 1; i < 31; i++)
{
string key = "HMI_button_LP_ON[0]." + i;
dic[key] = "";
}
for (int i = 0; i < 31; i++)
{
string key = "HMI_button_LP_ON[1]." + i;
dic[key] = "";
}
foreach (var eti in dic)
{
Point p = new Point()
{
ID = GetId,
FromType = "料盘页手动界面",
DataType = "bool",
CreateDate = DateTime.Now,
LastModifyDate = DateTime.Now,
CreateUserId = "",
CreateUserName = "",
LastModifyUserId = "",
LastModifyUserName = "",
PointName = eti.Value,
PointAddress = eti.Key
};
dbContext.Insert(p);
}
DbInfo.Init(typeof(UserInfo).Assembly);
UpdateLogService service = new UpdateLogService();
service.AddOrUpdateLog(TestFactory.TestUser(), "test", 1);

@ -19,8 +19,8 @@ namespace RfidWeb
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FromSQl());
//Application.Run(new FormMain());
//Application.Run(new FromSQl());
Application.Run(new FormMain());
}
}
}

@ -168,6 +168,7 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestFactory.cs" />
<Compile Include="UserManager.cs" />
<EmbeddedResource Include="FormLogin.resx">
<DependentUpon>FormLogin.cs</DependentUpon>

@ -0,0 +1,39 @@
using DB.Dto;
using DB.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualBasic.ApplicationServices;
namespace RfidWeb
{
public class TestFactory
{
public static UserDto dto;
public static UserDto TestUser()
{
if (dto != null)
{
return dto;
}
long id = 7254397083167133696;
var userInfo = new UserService().Query(id);
UserDto user = new UserDto
{
Id = userInfo.ID,
UserName = userInfo.UserName,
RoleId = userInfo.RoleId,
RoleName ="管理员",
RoleLevel =1
};
dto = user;
return user;
}
}
}

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Tool.Model
{
public class HmiPoint
{
/// <summary>
/// DInt 供料电机速度
/// </summary>
public static readonly string feeding_motor_speed = "feeding_motor_speed";
/// <summary>
/// DInt 层合电机速度
/// </summary>
public static readonly string Laminated_motor_speed = "Laminated_motor_speed";
/// <summary>
/// DInt 毛毡带电机速度
/// </summary>
public static readonly string Felt_belt_motor_speed = "Felt_belt_motor_speed";
/// <summary>
/// DInt 收料电机1速度
/// </summary>
public static readonly string Receiving_Electric_motor_speed_1 = "Receiving_Electric_motor_speed_1";
/// <summary>
/// DInt 收料电机2速度
/// </summary>
public static readonly string Receiving_Electric_motor_speed_2 = "Receiving_Electric_motor_speed_2";
public static string[] GetValue()
{
List<string> ls = new List<string>
{
feeding_motor_speed,
Laminated_motor_speed,
Felt_belt_motor_speed,
Receiving_Electric_motor_speed_1,
Receiving_Electric_motor_speed_2
};
return ls.ToArray();
}
}
}

@ -106,10 +106,10 @@ namespace Tool
public static OperateResult WriteTag(string address, UInt32 num)
{
OperateResult operate = Instance.WriteTag(address, 0xC4, num.GetBytes());
OperateResult result = Instance.WriteTag(address, 0xC4, num.GetBytes());
logNet.WriteInfo("打印日志", $"write 地址[{address}] value:[{num.ToString()}] type:[Tag] result:[{result.ToJsonString()}]");
return operate;
return result;
}
}

@ -16,7 +16,7 @@ namespace Tool
public string Db { get; set; } = "server=127.0.0.1;database=gaosu;uid=postgres;pwd=123456";
public string PlcIp { get; set; } = "192.168.1.140";
public string PlcIp { get; set; } = "192.168.1.180";
public int Port { get; set; }=44818;

@ -68,6 +68,7 @@
<Compile Include="ILogNetFactory.cs" />
<Compile Include="Model\BoolModelFactory.cs" />
<Compile Include="Model\HmiChModel.cs" />
<Compile Include="Model\HmiPoint.cs" />
<Compile Include="Model\PlcBoolModel.cs" />
<Compile Include="PagedList.cs" />
<Compile Include="Result.cs" />

Loading…
Cancel
Save