using FreeSql;
using OfficeOpenXml.Drawing.Chart;
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Comm;
using WIDESEA_Comm.ItemDB;
using WIDESEA_Comm.LogInfo;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Core.Extensions;
using WIDESEA_Entity.DomainModels;
using WIDESEA_WCS.IRepositories;
using WIDESEA_WCS.IServices;
using WIDESEA_WCS.Jobs;
using WIDESEA_WCS.Repositories;
using WIDESEA_WCS.Services;
using WIDESEA_WCS.WCSClient;
using static System.Collections.Specialized.BitVector32;
namespace WIDESEA_WCS
{
///
/// 一二单元调度
///
[DisallowConcurrentExecution]
public class One_two_unitJob : JobBase, IJob
{
public Task Execute(IJobExecutionContext context)
{
try
{
AddDB();
//ExecuteJob(context, DoAction);
}
catch (Exception ex)
{
}
return Task.CompletedTask;
}
private void DoAction(IJobExecutionContext context)
{
var client = context.JobDetail.JobDataMap.Get("JobParams") as PLCClient;
//自动重连
if (!client.IsConnected)
{
client.Connect();
return;
}
StackerReadDBItem.StackerReadDBItems = new List();
PropertyInfo[] propertyInfos = typeof(StackerReadDBItem).GetProperties();
var groups = client.itemGroups.OrderBy(x => x.Methods).ThenBy(x => x.name).GroupBy(x => x.Methods).ToList();
foreach (var key in groups)
{
StackerReadDBItem StackerDBItem = new StackerReadDBItem();
foreach (var propertyInfo in propertyInfos)
{
if (propertyInfo.Name == "StackerNo")
{
StackerDBItem.StackerNo = key.Key;
}
else
{
DBItemGroup group = key.FirstOrDefault(x => x.name == propertyInfo.Name);
if (group != null)
{
var readData = DBExtension.Read(group, client);
switch (propertyInfo.Name)
{
case "R_wheel_SN":
StackerDBItem.R_wheel_SN = readData.ToString();
break;
case "R_wheel_type":
StackerDBItem.R_wheel_type = Convert.ToInt16(readData);
break;
case "R_part_status":
StackerDBItem.R_part_status = Convert.ToByte(readData);
break;
case "R_part_process":
StackerDBItem.R_part_process = Convert.ToByte(readData);
break;
case "R_machine_nr":
StackerDBItem.R_machine_nr = Convert.ToBoolean(readData);
break;
case "R_direction":
StackerDBItem.R_direction = Convert.ToByte(readData);
break;
}
}
}
}
StackerReadDBItem.StackerReadDBItems.Add(StackerDBItem);
}
}
///
/// 添加DB地址信息
///
public void AddDB()
{
VOLContext context = new VOLContext();
Idt_plcinfodetailRepository repository = new dt_plcinfodetailRepository(context);
List plcinfodetail = new List();
string name = "Pipeline";
for (int i = 1; i <= 3; i++)
{
dt_plcinfodetail dt_Plcinfodetail1 = new dt_plcinfodetail()
{
plcdetail_id = Guid.NewGuid(),
plcdetail_iotype = name,
plcdetail_db = "DB29",
plcdetail_value = (21 + (i - 1) * 80).ToString(),
plcdetail_valtype = "string",
plcdetail_len = 20,
plcdetail_name = "R_Wheel_SN",
plcdetail_opratortype = "oiler",
plcdetail_remark = "Wheel_SN",
plcdetail_number = i + "单元",
};
plcinfodetail.Add(dt_Plcinfodetail1);
dt_plcinfodetail dt_Plcinfodetail2 = new dt_plcinfodetail()
{
plcdetail_id = Guid.NewGuid(),
plcdetail_iotype = name,
plcdetail_db = "DB29",
plcdetail_value = (22 + (i - 1) * 80).ToString(),
plcdetail_valtype = "int16",
plcdetail_name = "R_Wheel_Type",
plcdetail_opratortype = "oiler",
plcdetail_remark = "Wheel_Type",
plcdetail_number = i + "单元",
};
plcinfodetail.Add(dt_Plcinfodetail2);
dt_plcinfodetail dt_Plcinfodetail3 = new dt_plcinfodetail()
{
plcdetail_id = Guid.NewGuid(),
plcdetail_iotype = name,
plcdetail_db = "DB29",
plcdetail_value = (24 + (i - 1) * 80).ToString(),
plcdetail_valtype = "byte",
plcdetail_name = "R_Part_Status",
plcdetail_opratortype = "oiler",
plcdetail_remark = "Part_Status",
plcdetail_number = i + "单元",
};
plcinfodetail.Add(dt_Plcinfodetail3);
dt_plcinfodetail dt_Plcinfodetail4 = new dt_plcinfodetail()
{
plcdetail_id = Guid.NewGuid(),
plcdetail_iotype = name,
plcdetail_db = "DB29",
plcdetail_value = (25 + (i - 1) * 80).ToString(),
plcdetail_valtype = "byte",
plcdetail_name = "R_Part_Process",
plcdetail_opratortype = "oiler",
plcdetail_remark = "Part_Process",
plcdetail_number = i + "单元",
};
plcinfodetail.Add(dt_Plcinfodetail4);
}
repository.AddRange(plcinfodetail, true);
}
}
}