wenjy 1 year ago
commit 1a1e4bffd6

@ -27,5 +27,11 @@ namespace Admin.Core.IRepository
/// <param name="productLineCode"></param>
/// <returns></returns>
Task<List<ProductLineInfoView>> GetProductLineInfo(string productLineCode);
/// <summary>
/// 根据工位查询时间
/// </summary>
/// <param name="stationCode"></param>
/// <returns></returns>
List<dynamic> GetStationHourAmountAsync(string stationCode);
}
}

@ -36,5 +36,11 @@ namespace Admin.Core.IService
/// <param name="productLineCode"></param>
/// <returns></returns>
Task<ProductLineInfoView> GetProductLineInfo(string productLineCode);
/// <summary>
/// 根据工位查询小时
/// </summary>
/// <param name="stationCode"></param>
/// <returns></returns>
List<dynamic> GetStationHourAmountAsync(string stationCode);
}
}

@ -5,6 +5,7 @@ using Admin.Core.Model.ViewModels;
using Admin.Core.Model.Model_New;
using System.Collections.Generic;
using System;
using Microsoft.IdentityModel.Logging;
namespace Admin.Core.Repository
{
@ -54,5 +55,25 @@ namespace Admin.Core.Repository
}
#endregion
/// <summary>
/// 获取班组小时数
/// </summary>
/// <param name="stationCode"></param>
/// <returns></returns>
public List<dynamic> GetStationHourAmountAsync(string stationCode)
{
List<dynamic> result = null;
try
{
result = Db.Queryable<dynamic>().AS("GET_STATION_HOURAMOUNT").Where("PRODUCTLINE_CODE = @stationCode", new { stationCode = stationCode }).ToList();
}
catch (Exception ex)
{
}
return result;
}
}
}

@ -366,6 +366,7 @@ namespace Admin.Core.Service
/// </summary>
/// <param name="whereExpression"></param>
/// <returns></returns>
public List<TEntity> Query(Expression<Func<TEntity, bool>> whereExpression)
{
return BaseDal.Query(whereExpression);

@ -51,7 +51,7 @@ namespace Admin.Core.Service
try
{
spaceInfos = await _baseSpaceInfoRepository.QueryAsync(x => x.StoreCode == store && x.MaterialType == materialType && x.SpaceStatus == 1);
if (spaceInfos.Count == 0) //没有指定该类型物料的货道信息,需获取空白货道信息进行分配
if (spaceInfos==null || spaceInfos.Count == 0) //没有指定该类型物料的货道信息,需获取空白货道信息进行分配
spaceInfos = await GetEmptySpaceInfo(store);
logHelper.Info($"根据仓库{store};物料:{materialType};获取到的货道信息:{spaceInfos.ToJson()}");

@ -67,5 +67,14 @@ namespace Admin.Core.IService
var obj = list.SingleOrDefault(d => d.ProductlineCode == productLineCode);
return obj;
}
/// <summary>
/// 根据工位查询小时
/// </summary>
/// <param name="stationCode"></param>
/// <returns></returns>
public List<dynamic> GetStationHourAmountAsync(string stationCode)
{
return _sysUserInfoRepository.GetStationHourAmountAsync(stationCode);
}
}
}

@ -18,7 +18,7 @@ namespace Aucam.Core.PerfusionService.Business
/// <summary>
/// 采集灌注数据
/// </summary>
public class Collection
public class PerfusionCollection
{
Semaphore semaphore = new Semaphore(1, 1);
protected readonly IPerfusionRecordServices? _perfusionRecordServices ;
@ -32,7 +32,7 @@ namespace Aucam.Core.PerfusionService.Business
private Perfusion_DeviceStatus perfusion_DeviceStatus = new Perfusion_DeviceStatus();
private Perfusion_Alarm perfusion_Alarm = new Perfusion_Alarm();
public Collection(PerfusionRecordServices perfusionRecordServices, IPerfusionAlarmServices perfusionAlarmServices, IPerfusionDeviceStatusServices perfusionDeviceStatusServices)
public PerfusionCollection(PerfusionRecordServices perfusionRecordServices, IPerfusionAlarmServices perfusionAlarmServices, IPerfusionDeviceStatusServices perfusionDeviceStatusServices)
{
_perfusionRecordServices = perfusionRecordServices;
_perfusionAlarmServices = perfusionAlarmServices;
@ -105,12 +105,12 @@ namespace Aucam.Core.PerfusionService.Business
/// <returns></returns>
static void ReadEquipSystem(Aucma.Core.HwPLc.PlcModel obj, Perfusion_Record record, Perfusion_DeviceStatus deviceStatus, Perfusion_Alarm alarmInfo)
{
byte[] info = obj.plc.Read("DB55.0", 50);
byte[] info = obj.plc.Read("DB55.0", 84);
if (info == null) return;
#region 灌注记录赋值
record.PerfusionActualVolume=byteToDouble(info.Skip(0).Take(8).ToArray()).ToString();
record.PerfusionR = byteToDouble(info.Skip(8).Take(4).ToArray()).ToString().ToString();
record.PerfusionL = byteToFloat(info.Skip(50).Take(4).ToArray()).ToString();
record.PerfusionL = byteToFloat(info.Skip(55).Take(4).ToArray()).ToString();
record.PerfusionDuration = int.Parse(StringChange.bytesToHexStr(info.Skip(12).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber).ToString();
record.Yield = int.Parse(StringChange.bytesToHexStr(info.Skip(16).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber).ToString();
record.PerfusionBoxCode = asciiEncoding.GetString(info.Skip(20).Take(24).ToArray()).Replace("\0", "").Trim('\n');
@ -119,8 +119,8 @@ namespace Aucam.Core.PerfusionService.Business
record.PerfusionSetVolume = byteToFloat(info.Skip(78).Take(4).ToArray()).ToString();
record.PerfusionSystem =short.Parse(StringChange.bytesToHexStr(info.Skip(82).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString();
///灌注完成状态字
record.PerfusionFinishStatus = short.Parse(StringChange.bytesToHexStr(info.Skip(42).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString();
record.PerfusionResult = short.Parse(StringChange.bytesToHexStr(info.Skip(44).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
record.PerfusionFinishStatus = short.Parse(StringChange.bytesToHexStr(info.Skip(46).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString();
record.PerfusionResult = short.Parse(StringChange.bytesToHexStr(info.Skip(48).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
record.CreatedBy = "equip";
record.CreatedTime = DateTime.Now;
record.UpdatedBy = "equip";
@ -129,7 +129,7 @@ namespace Aucam.Core.PerfusionService.Business
#region 设备状态赋值
deviceStatus.PerfusionDevicetype = "灌注";
deviceStatus.PerfusionStatus = short.Parse(StringChange.bytesToHexStr(info.Skip(46).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
deviceStatus.PerfusionStatus = short.Parse(StringChange.bytesToHexStr(info.Skip(50).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
deviceStatus.CreatedBy = "equip";
deviceStatus.CreatedTime = DateTime.Now;
deviceStatus.UpdatedBy = "equip";
@ -138,7 +138,7 @@ namespace Aucam.Core.PerfusionService.Business
#region 设备报警赋值
alarmInfo.PerfusionBoxcode = record.PerfusionBoxCode;
alarmInfo.PerfusionStatus = short.Parse(StringChange.bytesToHexStr(info.Skip(48).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
alarmInfo.PerfusionStatus = short.Parse(StringChange.bytesToHexStr(info.Skip(52).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
alarmInfo.PerfusionAlarm = AlarmTrans(alarmInfo.PerfusionStatus);
alarmInfo.PerfusionCompleted = "1";
alarmInfo.CreatedBy = "equip";

@ -3,6 +3,7 @@ using Admin.Core.Extensions;
using Admin.Core.IService.ISys;
using Admin.Core.Tasks;
using Aucma.Core.RunPlc;
using Aucma.Core.Tasks;
using Autofac;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
@ -60,6 +61,8 @@ namespace Aucam.Core.PerfusionService
services.AddJobSetup();
//PLC
services.AddPlcSetup();
services.AddAucmaTaskSetup();
//支持编码大全 例如:支持 System.Text.Encoding.GetEncoding("GB2312") System.Text.Encoding.GetEncoding("GB18030")
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
}
@ -80,7 +83,9 @@ namespace Aucam.Core.PerfusionService
/// </summary>
/// <param name="app"></param>
/// <param name="env"></param>
public void Configure(IApplicationBuilder app, ISysTasksQzService tasksQzService, ISchedulerCenter schedulerCenter, IRunPlcService runPlcService)
public void Configure(IApplicationBuilder app, ISysTasksQzService tasksQzService,
ISchedulerCenter schedulerCenter, IRunPlcService runPlcService,
IAucamTaskService aucamTaskService)
{
// 使用静态文件
app.UseStaticFiles();
@ -91,6 +96,7 @@ namespace Aucam.Core.PerfusionService
//PLC
app.UsePlcMildd(runPlcService);
app.AucmaTaskMildds(aucamTaskService);
}
#region 注册服务
@ -101,7 +107,7 @@ namespace Aucam.Core.PerfusionService
private static void AddServices(IServiceCollection services)
{
#region 注册服务
//services.AddScoped<IProductPlanInfoServices, ProductPlanInfoServices>();
//services.AddScoped<Collection>();
//services.AddScoped<IEEquipmentCategoryRepository, EEquipmentCategoryRepository>();
//services.AddScoped<IBaseRepository<EEquipmentCategory>, BaseRepository<EEquipmentCategory>>();
//services.AddSingleton<IBaseService<EEquipmentCategory>, BaseService<EEquipmentCategory>>();

@ -167,6 +167,9 @@
"QuartzNetJob": {
"Enabled": true
},
"AucamTask": {
"Enabled": true
}
},
"PLCServer": [

@ -34,6 +34,7 @@ namespace Aucma.Core.BoxFoam.Business
public static List<float> MoldTemperatureList = new List<float>();
public static List<float> ProductionCycleList = new List<float>();
Semaphore semaphore = new Semaphore(1, 1);
public CollectionFoamLine()
{
startCollect();
@ -49,8 +50,6 @@ namespace Aucma.Core.BoxFoam.Business
try
{
Thread.Sleep(3000);
var obj = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("foamLine1Plc"));
if (obj != null)

@ -69,6 +69,7 @@ namespace Aucma.Core.BoxFoam
services.AddJobSetup();
//PLC
services.AddPlcSetup();
//支持编码大全 例如:支持 System.Text.Encoding.GetEncoding("GB2312") System.Text.Encoding.GetEncoding("GB18030")
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
}
@ -89,7 +90,8 @@ namespace Aucma.Core.BoxFoam
/// </summary>
/// <param name="app"></param>
/// <param name="env"></param>
public void Configure(IApplicationBuilder app, ISysTasksQzService tasksQzService, ISchedulerCenter schedulerCenter, IRunPlcService runPlcService,IScannerService scannerService)//
public void Configure(IApplicationBuilder app, ISysTasksQzService tasksQzService,
ISchedulerCenter schedulerCenter, IRunPlcService runPlcService,IScannerService scannerService)//
{
// 使用静态文件
app.UseStaticFiles();
@ -102,6 +104,7 @@ namespace Aucma.Core.BoxFoam
app.UsePlcMildd(runPlcService);
//开启扫码服务
app.UseScannerMildd(scannerService);
}
#region 注册服务

@ -24,7 +24,7 @@ namespace Aucma.Core.BoxFoam.ViewModels
{
Job_BoxFoamLastData_Quartz.RefreshLastShotDataDelegateEvent += RefreshData;
_boxLastShotRecordServices = App.ServiceProvider.GetService<IBoxLastShotRecordServices>();
// LoadData();
//Task.WaitAll(LoadData());
}
@ -95,8 +95,8 @@ namespace Aucma.Core.BoxFoam.ViewModels
});
i++;
};
//Datalist.Insert(0, Datalist[Datalist.Count - 1]);
//Datalist.RemoveAt(Datalist.Count - 1);
// Datalist.Insert(0, Datalist[Datalist.Count - 1]);
// Datalist.RemoveAt(Datalist.Count - 1);
}));
}

@ -326,20 +326,23 @@ namespace Aucma.Core.BoxFoam.ViewModels
public async void RealTimeFoamingTask(object? sender, ElapsedEventArgs e)
{
semaphore.WaitOne();
try
{
string productLineCode = Appsettings.app("StationInfo", "ProductLineCode");
DateTime now = DateTime.Now;
List<CurrentTeamTime> timeList = await _currentTeamTimeServices.QueryAsync(d => d.StartTime <= now && d.EndTime >= now);
CurrentTeamTime currentTeamTime = await _currentTeamTimeServices.FirstAsync(d => d.StartTime <= now && d.EndTime >= now);
if (timeList.Count>0)
if (currentTeamTime!=null)
{
//比较计划更新数据
ExecHourDataAsync(productLineCode);
}
else
else
{
ShiftChangeAsync(productLineCode);
// 白夜班切换
ShiftChangeAsync(productLineCode, currentTeamTime);
}
}
@ -370,8 +373,7 @@ namespace Aucma.Core.BoxFoam.ViewModels
int complateAmount = 0;
BoxFoamDataRealTime bfd = bfds.SingleOrDefault(d => d.FixtureBoxtype == bLis[j].FixtureBoxType && d.SerialNumber == bLis[j].ObjId);
if (bfd != null)
{
{
//更新计划数量
complateAmount = bLis[j].Yield - bfd.FixtureProductioncapacity;
UpdateClampData(bLis[j], bfd);
@ -420,30 +422,30 @@ namespace Aucma.Core.BoxFoam.ViewModels
}
}
private async void ShiftChangeAsync(string productLineCode)
private async void ShiftChangeAsync(string productLineCode, CurrentTeamTime currentTeamTime)
{
try
{
//切换班组计划
var currentTeamTimeList = await _sysUserInfoServices.GetTeamData();
if (currentTeamTimeList.Count == 0) return;
// 夹具
var list = await _boxFoamDataRealTimeServices.QueryAsync(d => d.ProductlineCode == productLineCode);
//更新计划表操作
CurrentTeamTime currentTeamTime = await _currentTeamTimeServices.FirstAsync();
//CurrentTeamTime currentTeamTime = await _currentTeamTimeServices.FirstAsync();
// 更新当班时间
currentTeamTime.TeamName = currentTeamTimeList.FirstOrDefault().TeamName;
currentTeamTime.StartTime = currentTeamTimeList.Min(d => d.StartTime);
currentTeamTime.EndTime = currentTeamTimeList.Max(d => d.EndTime);
bool result = await _currentTeamTimeServices.UpdateAsync(currentTeamTime);
if (result)
{
var obj2 = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("foamLine1Plc"));
if (obj2 == null) { return; }
//清空 当班计划
var realTimeList = await _boxFoamDataRealTimeHistoryServices.QueryAsync(d => d.ProductlineCode == productLineCode);
await _boxFoamDataRealTimeHistoryServices.DeletesAsync(realTimeList);
// var realTimeList = await _boxFoamDataRealTimeHistoryServices.QueryAsync(d => d.ProductlineCode == productLineCode);
var plan = await _boxFoamPlanServices.QueryAsync(d => d.ProductLineCode == productLineCode);
await _boxFoamPlanServices.DeletesAsync(plan);
}
@ -458,7 +460,6 @@ namespace Aucma.Core.BoxFoam.ViewModels
/// </summary>
public async void UpdateClampData(FixtureStatus fixtureStatus, BoxFoamDataRealTime bfd)
{
try
{
bfd.FixtureBoxtype = fixtureStatus.FixtureBoxType;

@ -76,7 +76,7 @@ namespace Aucma.Core.HwPLc
/// <returns></returns>
public bool Connect(string iP, int port)
{
//melsecMcNet.IpAddress = iP;//正式环境开启
melsecMcNet.IpAddress = iP;//正式环境开启
melsecMcNet.Port = port;
// 如果网络不太理想,配置了两个端口,一个有问题,立即切换另一个的话,可以配置如下的代码

@ -2,6 +2,7 @@
using Admin.Core.IService;
using Aucma.Core.HwPLc;
using Aucma.Core.OldBoxFoam.Models;
using Consul;
using Microsoft.Extensions.DependencyInjection;
using NetTaste;
using System;
@ -20,8 +21,8 @@ namespace Aucma.Core.OldBoxFoam.Business
public HwPLc.PlcModel plc2 = null;
public HwPLc.PlcModel plc3 = null;
public HwPLc.PlcModel plc4 = null;
public List<FixtureStatus> listFixtureStatus = new List<FixtureStatus>();
public List<SpaceDetailModel> spaceDetailModel = new List<SpaceDetailModel>();
public static List<FixtureStatus> listFixtureStatus = new List<FixtureStatus>();
public static List<SpaceDetailModel> spaceDetailModel = new List<SpaceDetailModel>();
public static List<int> BoxTypeList = new List<int>();
public static List<int> HolderStatusList = new List<int>();
@ -29,15 +30,16 @@ namespace Aucma.Core.OldBoxFoam.Business
public static List<int> SolidifyTimeList = new List<int>();
public static List<string> StoreTypeList = new List<string>();
public static List<string> StoreAmountList = new List<string>();
System.Threading.Semaphore semaphore = new System.Threading.Semaphore(1, 1);
public Collection() {
startCollect();
}
public async void startCollect()
{
try
{
//await ExecTaskMethod();
await ExecTaskMethod();
return;
}
catch (Exception ex)
@ -52,94 +54,107 @@ namespace Aucma.Core.OldBoxFoam.Business
{
while (true)
{
Thread.Sleep(3000);
plc1 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc1"));
plc2 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc2"));
plc3 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc3"));
plc4 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc4"));
BoxTypeList.Clear();
HolderStatusList.Clear();
HolderOutPutList.Clear();
SolidifyTimeList.Clear();
listFixtureStatus.Clear();//夹具集合
spaceDetailModel.Clear();//货道集合
//夹具箱型
ReadBoxType(plc1, BoxTypeList);
ReadBoxType(plc2, BoxTypeList);
ReadBoxType(plc3, BoxTypeList);
ReadBoxType(plc4, BoxTypeList);
ReadHolderStatus(plc1, HolderStatusList);
ReadHolderStatus(plc2, HolderStatusList);
ReadHolderStatus(plc3, HolderStatusList);
ReadHolderStatus(plc4, HolderStatusList);
ReadHolderOutPut(plc1, HolderOutPutList);
ReadHolderOutPut(plc2, HolderOutPutList);
ReadHolderOutPut(plc3, HolderOutPutList);
ReadHolderOutPut(plc4, HolderOutPutList);
ReadSolidifyTime(plc1, SolidifyTimeList);
ReadSolidifyTime(plc2, SolidifyTimeList);
ReadSolidifyTime(plc3, SolidifyTimeList);
ReadSolidifyTime(plc4, SolidifyTimeList);
ReadStoreType(plc1, StoreTypeList);
ReadStoreType(plc2, StoreTypeList);
ReadStoreType(plc3, StoreTypeList);
ReadStoreType(plc4, StoreTypeList);
ReadStoreAmount(plc1, StoreAmountList);
ReadStoreAmount(plc2, StoreAmountList);
ReadStoreAmount(plc3, StoreAmountList);
ReadStoreAmount(plc4, StoreAmountList);
for (int i = 0; i < 24; i++)
semaphore.WaitOne();
try
{
FixtureStatus model = new FixtureStatus();
model.ObjId = i + 1;
if (BoxTypeList.Count > 0 && BoxTypeList != null)
Thread.Sleep(3000);
plc1 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc1"));
plc2 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc2"));
plc3 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc3"));
plc4 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc4"));
BoxTypeList.Clear();
HolderStatusList.Clear();
HolderOutPutList.Clear();
SolidifyTimeList.Clear();
listFixtureStatus.Clear();//夹具集合
spaceDetailModel.Clear();//货道集合
//夹具箱型
ReadBoxType(plc1, BoxTypeList);
ReadBoxType(plc2, BoxTypeList);
ReadBoxType(plc3, BoxTypeList);
ReadBoxType(plc4, BoxTypeList);
ReadHolderStatus(plc1, HolderStatusList);
ReadHolderStatus(plc2, HolderStatusList);
ReadHolderStatus(plc3, HolderStatusList);
ReadHolderStatus(plc4, HolderStatusList);
ReadHolderOutPut(plc1, HolderOutPutList);
ReadHolderOutPut(plc2, HolderOutPutList);
ReadHolderOutPut(plc3, HolderOutPutList);
ReadHolderOutPut(plc4, HolderOutPutList);
ReadSolidifyTime(plc1, SolidifyTimeList);
ReadSolidifyTime(plc2, SolidifyTimeList);
ReadSolidifyTime(plc3, SolidifyTimeList);
ReadSolidifyTime(plc4, SolidifyTimeList);
ReadStoreType(plc1, StoreTypeList);
ReadStoreType(plc2, StoreTypeList);
ReadStoreType(plc3, StoreTypeList);
ReadStoreType(plc4, StoreTypeList);
ReadStoreAmount(plc1, StoreAmountList);
ReadStoreAmount(plc2, StoreAmountList);
ReadStoreAmount(plc3, StoreAmountList);
ReadStoreAmount(plc4, StoreAmountList);
for (int i = 0; i < 24; i++)
{
model.FixtureBoxType = BoxTypeList[i].ToString();
FixtureStatus model = new FixtureStatus();
model.ObjId = i + 1;
if (BoxTypeList.Count > 0 && BoxTypeList != null)
{
model.FixtureBoxType = BoxTypeList[i].ToString();
}
else
{
model.FixtureBoxType = "";
}
if (HolderStatusList.Count > 0 && HolderStatusList != null)
{
model.Status = HolderStatusList[i];
}
else
{
model.Status = 0;
}
if (HolderOutPutList.Count > 0 && HolderOutPutList != null)
{
model.Yield = HolderOutPutList[i];
}
else
{
model.Yield = 0;
}
if (SolidifyTimeList.Count > 0 && HolderOutPutList != null)
{
model.PlanCuringTime = SolidifyTimeList[i];
}
else
{
model.PlanCuringTime = 0;
}
listFixtureStatus.Add(model);
}
else
for (int i = 0; i < 8; i++)
{
model.FixtureBoxType = "";
SpaceDetailModel model = new SpaceDetailModel();
model.ObjId = i + 1;
if (StoreTypeList.Count > 0) model.StoreType = StoreTypeList[i].ToString();
if (StoreAmountList.Count > 0) model.StoreAmount = Convert.ToInt32(StoreAmountList[i]);
spaceDetailModel.Add(model);
}
if (HolderStatusList.Count > 0 && HolderStatusList != null)
{
model.Status = HolderStatusList[i];
}
else
{
model.Status = 0;
}
if (HolderOutPutList.Count > 0 && HolderOutPutList != null)
{
model.Yield = HolderOutPutList[i];
}
else
{
model.Yield = 0;
}
if (SolidifyTimeList.Count > 0 && HolderOutPutList != null)
{
model.PlanCuringTime = SolidifyTimeList[i];
}
else
{
model.PlanCuringTime = 0;
}
listFixtureStatus.Add(model);
}
for (int i = 0; i < 8; i++)
catch (Exception)
{
throw;
}
finally
{
SpaceDetailModel model = new SpaceDetailModel();
model.ObjId = i + 1;
if (StoreTypeList.Count > 0) model.StoreType = StoreTypeList[i].ToString();
if (StoreAmountList.Count > 0) model.StoreAmount = Convert.ToInt32(StoreAmountList[i]);
spaceDetailModel.Add(model);
semaphore.Release();
}
}
});

@ -37,6 +37,9 @@ namespace Aucma.Core.OldBoxFoam.ViewModels
private readonly ISysUserInfoServices _sysUserInfoServices;
private readonly ICurrentTeamTimeServices _currentTeamTimeServices;
private readonly IBoxFoamDataRecordServices _boxFoamDataRecordServices;
private readonly IBoxFoamDataRealTimeServices? _boxFoamDataRealTimeServices;
private readonly IBoxFoamDataRealTimeHistoryServices _boxFoamDataRealTimeHistoryServices;
private static readonly log4net.ILog log = LogManager.GetLogger(typeof(OldBoxFoamPageViewModel));
Collection collection = new Collection();
System.Timers.Timer timer2 = new System.Timers.Timer(3000);
@ -49,8 +52,9 @@ namespace Aucma.Core.OldBoxFoam.ViewModels
_boxFoamPlanServices = App.ServiceProvider.GetService<IBoxFoamPlanServices>();
_sysUserInfoServices = App.ServiceProvider.GetService<ISysUserInfoServices>();
_currentTeamTimeServices = App.ServiceProvider.GetService<ICurrentTeamTimeServices>();
// _currentTeamTimeServices = App.ServiceProvider.GetService<ICurrentTeamTimeServices>();
_boxFoamDataRealTimeServices = App.ServiceProvider.GetService<IBoxFoamDataRealTimeServices>();
_boxFoamDataRecordServices = App.ServiceProvider.GetService<IBoxFoamDataRecordServices>();
_boxFoamDataRealTimeHistoryServices = App.ServiceProvider.GetService<IBoxFoamDataRealTimeHistoryServices>();
//AucamTaskService.RefreshOldBoxFoamDataDelegateEvent += OldBoxFoamOnLoad3;
//timer2.Elapsed += new System.Timers.ElapsedEventHandler(RealTimeFoamingTask); //到达时间的时候执行事件;
@ -102,9 +106,9 @@ namespace Aucma.Core.OldBoxFoam.ViewModels
{
try
{
collection.startCollect();
if (collection.listFixtureStatus == null) return;
var prderList = collection.listFixtureStatus;
//Collection.startCollect();
if (Collection.listFixtureStatus == null) return;
var prderList = Collection.listFixtureStatus;
int num = prderList.Sum(d => d.Yield);
if (prderList.Count==0) return;
totalAmount = 0;
@ -238,298 +242,496 @@ namespace Aucma.Core.OldBoxFoam.ViewModels
}
#endregion
Semaphore semaphore = new Semaphore(1, 1);
#region 将采集到的数据保存
/// <summary>
/// 将采集到的数据保存
/// </summary>
/// <param name="mode"></param>
public async void RealTimeFoamingTask(object? sender, ElapsedEventArgs e)
{
semaphore.WaitOne();
try
{
string productLineCode = Appsettings.app("StationInfo", "ProductLineCode");
if (collection.listFixtureStatus == null) return;
DateTime now = DateTime.Now;
CurrentTeamTime time = await _currentTeamTimeServices.FirstAsync(d => d.StartTime <= now && d.EndTime >= now);
if (time != null)
List<CurrentTeamTime> timeList = await _currentTeamTimeServices.QueryAsync(d => d.StartTime <= now && d.EndTime >= now);
if (timeList.Count > 0)
{
ExecHourData(productLineCode);
ExecHourDataAsync(productLineCode);
}
else
{
ShiftChange(productLineCode);
ShiftChangeAsync(productLineCode);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message.ToString());
Console.WriteLine(ex.Message);
}
finally
{
semaphore.Release();
}
}
private async void ShiftChange(string productLineCode)
{
//切换班组计划
var list = await _oldBoxFoamDataServices.QueryAsync(d => d.ProductLineCode == productLineCode);
List<BoxFoamDataRecord> recordList = new List<BoxFoamDataRecord>();
var currentTeamTimeList = await _sysUserInfoServices.GetTeamData();
if (currentTeamTimeList.Count == 0) return;
//更新计划表操作
CurrentTeamTime currentTeamTime = await _currentTeamTimeServices.FirstAsync();
currentTeamTime.TeamName = currentTeamTimeList.FirstOrDefault().TeamName;
currentTeamTime.StartTime = currentTeamTimeList.Min(d => d.StartTime);
currentTeamTime.EndTime = currentTeamTimeList.Max(d => d.EndTime);
await _currentTeamTimeServices.UpdateAsync(currentTeamTime);
//可以使用Mapping 映射
list.ForEach(d =>
{
BoxFoamDataRecord record = new BoxFoamDataRecord();
record.OrderCode = d.OrderCode;
record.ProductLineCode = d.ProductLineCode;
record.Fixturestatus = d.Production;
record.CuringTimeSettingValue = d.CuringTimeSettingValue;
record.ActualValue = d.ActualValue;
record.AnHour = d.AnHour;
record.TwoHour = d.TwoHour;
record.ThreeHour = d.ThreeHour;
record.FourHour = d.FourHour;
record.FiveHour = d.FiveHour;
record.SixHour = d.SixHour;
record.SevenHour = d.SevenHour;
record.EightHour = d.EightHour;
record.NineHour = d.NineHour;
record.TenHour = d.TenHour;
record.ElevenHour = d.ElevenHour;
record.TwelveHour = d.TwelveHour;
record.BoxFixturesideplate = d.BoxFixturesideplate;
record.BoxClosebetatemperature = d.BoxClosebetatemperature;
record.BoxBeat = d.BoxBeat;
record.CreateTime = DateTime.Now;
});
int result = await _boxFoamDataRecordServices.AddAsync(recordList);
if (result > 0)
{
var obj2 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc1"));
if (obj2 == null) { return; }
obj2.plc.WriteInt16("M216", "1");//换班 数据清空
//清空 当班计划
await _oldBoxFoamDataServices.DeletesAsync(list);
}
}
Semaphore semaphore = new Semaphore(1, 1);
}
#endregion
private async void ExecHourData(string productLineCode)
#region 获取小时数据
public async void ExecHourDataAsync(string productLineCode)
{
try
List<FixtureStatus> bLis = Collection.listFixtureStatus;
if (bLis.Count == 0) return;
List<BoxFoamPlan> planList = await _boxFoamPlanServices.QueryAsync();
List<BoxFoamDataRealTime> bfds = await _boxFoamDataRealTimeServices.QueryAsync();
for (int j = 0; j < bLis.Count; j++)
{
List<FixtureStatus> bList = new List<FixtureStatus>();
var collectionList = collection.listFixtureStatus;
if (collectionList.Count == 0) return;
bList.AddRange(collectionList);
List<BoxFoamData> bfds = await _oldBoxFoamDataServices.QueryAsync();
List<OldBoxFoamType> spaceList = await _oldBoxFoamTypeServices.QueryAsync();
List<BoxFoamPlan> planList = await _boxFoamPlanServices.QueryAsync();
for (int j = 0; j < bList.Count; j++)
try
{
try
if (string.IsNullOrEmpty(bLis[j].FixtureBoxType)) continue;
BoxFoamPlan plan = planList.FirstOrDefault(d => d.MaterialCode == bLis[j].FixtureBoxType && d.PlanAmount > d.CompleteAmount);
if (plan != null)
{
OldBoxFoamType space = spaceList.FirstOrDefault(d => d.Boxtype == bList[j].FixtureBoxType);
//根据夹具找货道,根据货道找物料
if (spaceList != null)
int complateAmount = 0;
BoxFoamDataRealTime bfd = bfds.SingleOrDefault(d => d.FixtureBoxtype == bLis[j].FixtureBoxType && d.SerialNumber == bLis[j].ObjId);
if (bfd != null)
{
BoxFoamPlan plan = planList.FirstOrDefault(d => d.MaterialCode == space.MaterialCode && d.PlanAmount > d.CompleteAmount);
if (plan != null)
{
int complateAmount = 0;
//更新小时数据
BoxFoamData bfd = bfds.FirstOrDefault(d => d.Fixtureboxtype == bList[j].FixtureBoxType && d.MainId == bList[j].ObjId);
if (bfd != null)
{
//更新计划数量
complateAmount = bList[j].Yield - bfd.Production;
UpdateBoxData(bList[j], bfd);
}
else
{
SaveBoxData(productLineCode, bList[j]);
}
plan.CompleteAmount = plan.CompleteAmount + complateAmount;
await _boxFoamPlanServices.UpdateAsync(plan);
}
else
{
//更新小时数据
BoxFoamData bfd = bfds.FirstOrDefault(d => d.Fixtureboxtype == bList[j].FixtureBoxType && d.MainId == bList[j].ObjId);
if (bfd != null)
{
UpdateBoxData(bList[j], bfd);
}
else
{
SaveBoxData(productLineCode, bList[j]);
}
}
//更新计划数量
complateAmount = bLis[j].Yield - bfd.FixtureProductioncapacity;
UpdateClampData(bLis[j], bfd);
}
else
{
//更新小时数据
BoxFoamData bfd = bfds.FirstOrDefault(d => d.Fixtureboxtype == bList[j].FixtureBoxType && d.MainId == bList[j].ObjId);
if (bfd != null)
{
UpdateBoxData(bList[j], bfd);
}
else
{
SaveBoxData(productLineCode, bList[j]);
}
FixtureStatus fixtureStatus = bLis[j];
SaveClampData(productLineCode, fixtureStatus);
}
}
catch { }
plan.CompleteAmount = plan.CompleteAmount + complateAmount;
if (complateAmount > 0)
{
//保存历史记录
BoxFoamDataRealTimeHistory history = new BoxFoamDataRealTimeHistory();
history.PlantCode = bfd.PlantCode;
history.ProductlineCode = bfd.ProductlineCode;
history.ProcessCode = bfd.ProcessCode;
history.StationCode = bfd.StationCode;
history.FixtureProductioncapacity = bLis[j].Yield;
history.FixtureCuringtimesettingvalue = bLis[j].PlanCuringTime.ToString();
history.FixtureActualtime = bLis[j].RealCuringTime.ToString();
history.UpdatedTime = DateTime.Now;
//事务合并
await _boxFoamDataRealTimeHistoryServices.AddAsync(history);
await _boxFoamPlanServices.UpdateAsync(plan);
}
}
else
{
//更新小时数据
BoxFoamDataRealTime bfd = bfds.SingleOrDefault(d => d.FixtureBoxtype == bLis[j].FixtureBoxType && d.SerialNumber == bLis[j].ObjId);
if (bfd != null)
{
UpdateClampData(bLis[j], bfd);
}
else
{
SaveClampData(productLineCode, bLis[j]);
}
}
}
OldBoxFoamOnLoad(bList);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
catch { }
}
}
}
#endregion
private async void UpdateBoxData(FixtureStatus item, BoxFoamData bfd)
#region 切换班组
private async void ShiftChangeAsync(string productLineCode)
{
int hour = GetTeamHour(DateTime.Now).Seq;
switch (hour)
try
{
case 1:
bfd.AnHour = item.Yield - bfd.Production;
break;
case 2:
bfd.TwoHour = item.Yield - bfd.Production;
break;
case 3:
bfd.ThreeHour = item.Yield - bfd.Production;
break;
case 4:
bfd.FourHour = item.Yield - bfd.Production;
break;
case 5:
bfd.FiveHour = item.Yield - bfd.Production;
break;
case 6:
bfd.SixHour = item.Yield - bfd.Production;
break;
case 7:
bfd.SevenHour = item.Yield - bfd.Production;
break;
case 8:
bfd.EightHour = item.Yield - bfd.Production;
break;
case 9:
bfd.NineHour = item.Yield - bfd.Production;
break;
case 10:
bfd.TenHour = item.Yield - bfd.Production;
break;
case 11:
bfd.ElevenHour = item.Yield - bfd.Production;
break;
case 12:
bfd.TwelveHour = item.Yield - bfd.Production;
break;
default:
break;
}
//切换班组计划
var currentTeamTimeList = await _sysUserInfoServices.GetTeamData();
if (currentTeamTimeList.Count == 0) return;
var list = await _boxFoamDataRealTimeServices.QueryAsync(d => d.ProductlineCode == productLineCode);
//更新计划表操作
CurrentTeamTime currentTeamTime = await _currentTeamTimeServices.FirstAsync();
currentTeamTime.TeamName = currentTeamTimeList.FirstOrDefault().TeamName;
currentTeamTime.StartTime = currentTeamTimeList.Min(d => d.StartTime);
currentTeamTime.EndTime = currentTeamTimeList.Max(d => d.EndTime);
bfd.Production = item.Yield;
bool result = await _currentTeamTimeServices.UpdateAsync(currentTeamTime);
if (result)
{
var obj2 = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("foamLine1Plc"));
if (obj2 == null) { return; }
await _oldBoxFoamDataServices.UpdateAsync(bfd);
}
//清空 当班计划
var realTimeList = await _boxFoamDataRealTimeHistoryServices.QueryAsync(d => d.ProductlineCode == productLineCode);
await _boxFoamDataRealTimeHistoryServices.DeletesAsync(realTimeList);
private async void SaveBoxData(string productLineCode, FixtureStatus item)
{
BoxFoamData bfdata = new BoxFoamData();
bfdata.MainId = item.ObjId;
bfdata.ProductLineCode = productLineCode;
bfdata.Fixtureboxtype = item.FixtureBoxType;
bfdata.Fixturestatus = item.Status;
bfdata.Production = item.Yield;
bfdata.CuringTimeSettingValue = item.PlanCuringTime.ToString();
bfdata.ActualValue = item.RealCuringTime.ToString();
int hour = GetTeamHour(DateTime.Now).Seq;
switch (hour)
{
case 1:
bfdata.AnHour = item.Yield = bfdata.Production;
break;
case 2:
bfdata.TwoHour = item.Yield = bfdata.Production;
break;
case 3:
bfdata.ThreeHour = item.Yield = bfdata.Production;
break;
case 4:
bfdata.FourHour = item.Yield = bfdata.Production;
break;
case 5:
bfdata.FiveHour = item.Yield = bfdata.Production;
break;
case 6:
bfdata.SixHour = item.Yield = bfdata.Production;
break;
case 7:
bfdata.SevenHour = item.Yield = bfdata.Production;
break;
case 8:
bfdata.EightHour = item.Yield = bfdata.Production;
break;
case 9:
bfdata.NineHour = item.Yield = bfdata.Production;
break;
case 10:
bfdata.TenHour = item.Yield = bfdata.Production;
break;
case 11:
bfdata.ElevenHour = item.Yield = bfdata.Production;
break;
case 12:
bfdata.TwelveHour = item.Yield = bfdata.Production;
break;
default:
break;
var plan = await _boxFoamPlanServices.QueryAsync(d => d.ProductLineCode == productLineCode);
await _boxFoamPlanServices.DeletesAsync(plan);
}
}
bfdata.MainId = item.ObjId;
await _oldBoxFoamDataServices.AddAsync(bfdata);
catch { }
}
public CurrentTeamTimeView GetTeamHour()
#endregion
#region 更新夹具型号
/// <summary>
/// 更新夹具型号
/// </summary>
public async void UpdateClampData(FixtureStatus fixtureStatus, BoxFoamDataRealTime bfd)
{
DateTime now = DateTime.Now;
var list = _sysUserInfoServices.GetTeamData().Result;
if (list != null)
try
{
//var obj = list.FirstOrDefault().EndTime.ToString("HH:mm");
var view = list.FirstOrDefault();
return view;
bfd.FixtureBoxtype = fixtureStatus.FixtureBoxType;
bfd.FixtureStatus = fixtureStatus.Status.ToString();
bfd.FixtureProductioncapacity = fixtureStatus.Yield;
bfd.FixtureCuringtimesettingvalue = fixtureStatus.PlanCuringTime.ToString();
bfd.FixtureActualtime = fixtureStatus.RealCuringTime.ToString();
bfd.UpdatedTime = DateTime.Now;
await _boxFoamDataRealTimeServices.UpdateAsync(bfd);
}
return null;
catch { }
}
#endregion
public CurrentTeamTimeView GetTeamHour(DateTime now)
#region 新增夹具型号
/// <summary>
/// 更新夹具型号
/// </summary>
public async void SaveClampData(string productLineCode, FixtureStatus fixtureStatus)
{
var obj = _sysUserInfoServices.GetTeamData(now).Result;
var obj = await _sysUserInfoServices.GetProductLineInfo(productLineCode);
if (obj != null)
{
return obj;
BoxFoamDataRealTime bfd = new BoxFoamDataRealTime();
bfd.PlantCode = obj.PlantCode;
bfd.ProductlineCode = productLineCode;
bfd.ProcessCode = obj.ProcessCode;
bfd.StationCode = obj.StationCode;
bfd.SerialNumber = fixtureStatus.ObjId;
bfd.FixtureBoxtype = fixtureStatus.FixtureBoxType;
bfd.FixtureStatus = fixtureStatus.Status.ToString();
bfd.FixtureProductioncapacity = fixtureStatus.Yield;
bfd.FixtureCuringtimesettingvalue = fixtureStatus.PlanCuringTime.ToString();
bfd.FixtureActualtime = fixtureStatus.RealCuringTime.ToString();
bfd.CreatedTime = DateTime.Now;
bfd.UpdatedTime = DateTime.Now;
await _boxFoamDataRealTimeServices.AddAsync(bfd);
}
return null;
}
#endregion
#region 原数据采集方法
/// <summary>
/// 将采集到的数据保存
/// </summary>
/// <param name="mode"></param>
//public async void RealTimeFoamingTask(object? sender, ElapsedEventArgs e)
//{
// semaphore.WaitOne();
// try
// {
// string productLineCode = Appsettings.app("StationInfo", "ProductLineCode");
// if (Collection.listFixtureStatus == null|| Collection.listFixtureStatus.Count==0) return;
// DateTime now = DateTime.Now;
// CurrentTeamTime time = await _currentTeamTimeServices.FirstAsync(d => d.StartTime <= now && d.EndTime >= now);
// if (time != null)
// {
// ExecHourData(productLineCode);
// }
// else
// {
// ShiftChange(productLineCode);
// }
// }
// catch (Exception ex)
// {
// Console.WriteLine(ex.Message.ToString());
// }
// finally
// {
// semaphore.Release();
// }
//}
//private async void ShiftChange(string productLineCode)
//{
// //切换班组计划
// var list = await _oldBoxFoamDataServices.QueryAsync(d => d.ProductLineCode == productLineCode);
// List<BoxFoamDataRecord> recordList = new List<BoxFoamDataRecord>();
// var currentTeamTimeList = await _sysUserInfoServices.GetTeamData();
// if (currentTeamTimeList.Count == 0) return;
// //更新计划表操作
// CurrentTeamTime currentTeamTime = await _currentTeamTimeServices.FirstAsync();
// currentTeamTime.TeamName = currentTeamTimeList.FirstOrDefault().TeamName;
// currentTeamTime.StartTime = currentTeamTimeList.Min(d => d.StartTime);
// currentTeamTime.EndTime = currentTeamTimeList.Max(d => d.EndTime);
// await _currentTeamTimeServices.UpdateAsync(currentTeamTime);
// //可以使用Mapping 映射
// list.ForEach(d =>
// {
// BoxFoamDataRecord record = new BoxFoamDataRecord();
// record.OrderCode = d.OrderCode;
// record.ProductLineCode = d.ProductLineCode;
// record.Fixturestatus = d.Production;
// record.CuringTimeSettingValue = d.CuringTimeSettingValue;
// record.ActualValue = d.ActualValue;
// record.AnHour = d.AnHour;
// record.TwoHour = d.TwoHour;
// record.ThreeHour = d.ThreeHour;
// record.FourHour = d.FourHour;
// record.FiveHour = d.FiveHour;
// record.SixHour = d.SixHour;
// record.SevenHour = d.SevenHour;
// record.EightHour = d.EightHour;
// record.NineHour = d.NineHour;
// record.TenHour = d.TenHour;
// record.ElevenHour = d.ElevenHour;
// record.TwelveHour = d.TwelveHour;
// record.BoxFixturesideplate = d.BoxFixturesideplate;
// record.BoxClosebetatemperature = d.BoxClosebetatemperature;
// record.BoxBeat = d.BoxBeat;
// record.CreateTime = DateTime.Now;
// });
// int result = await _boxFoamDataRecordServices.AddAsync(recordList);
// if (result > 0)
// {
// var obj2 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc1"));
// if (obj2 == null) { return; }
// obj2.plc.WriteInt16("M216", "1");//换班 数据清空
// //清空 当班计划
// await _oldBoxFoamDataServices.DeletesAsync(list);
// }
//}
//Semaphore semaphore = new Semaphore(1, 1);
//private async void ExecHourData(string productLineCode)
//{
// try
// {
// List<FixtureStatus> bList = new List<FixtureStatus>();
// var collectionList = collection.listFixtureStatus;
// if (collectionList.Count == 0) return;
// bList.AddRange(collectionList);
// List<BoxFoamData> bfds = await _oldBoxFoamDataServices.QueryAsync();
// List<OldBoxFoamType> spaceList = await _oldBoxFoamTypeServices.QueryAsync();
// List<BoxFoamPlan> planList = await _boxFoamPlanServices.QueryAsync();
// for (int j = 0; j < bList.Count; j++)
// {
// try
// {
// OldBoxFoamType space = spaceList.FirstOrDefault(d => d.Boxtype == bList[j].FixtureBoxType);
// //根据夹具找货道,根据货道找物料
// if (spaceList != null)
// {
// BoxFoamPlan plan = planList.FirstOrDefault(d => d.MaterialCode == space.MaterialCode && d.PlanAmount > d.CompleteAmount);
// if (plan != null)
// {
// int complateAmount = 0;
// //更新小时数据
// BoxFoamData bfd = bfds.FirstOrDefault(d => d.Fixtureboxtype == bList[j].FixtureBoxType && d.MainId == bList[j].ObjId);
// if (bfd != null)
// {
// //更新计划数量
// complateAmount = bList[j].Yield - bfd.Production;
// UpdateBoxData(bList[j], bfd);
// }
// else
// {
// SaveBoxData(productLineCode, bList[j]);
// }
// plan.CompleteAmount = plan.CompleteAmount + complateAmount;
// await _boxFoamPlanServices.UpdateAsync(plan);
// }
// else
// {
// //更新小时数据
// BoxFoamData bfd = bfds.FirstOrDefault(d => d.Fixtureboxtype == bList[j].FixtureBoxType && d.MainId == bList[j].ObjId);
// if (bfd != null)
// {
// UpdateBoxData(bList[j], bfd);
// }
// else
// {
// SaveBoxData(productLineCode, bList[j]);
// }
// }
// }
// else
// {
// //更新小时数据
// BoxFoamData bfd = bfds.FirstOrDefault(d => d.Fixtureboxtype == bList[j].FixtureBoxType && d.MainId == bList[j].ObjId);
// if (bfd != null)
// {
// UpdateBoxData(bList[j], bfd);
// }
// else
// {
// SaveBoxData(productLineCode, bList[j]);
// }
// }
// }
// catch { }
// }
// OldBoxFoamOnLoad(bList);
// }
// catch (Exception ex)
// {
// Console.WriteLine(ex.Message);
// }
//}
//private async void UpdateBoxData(FixtureStatus item, BoxFoamData bfd)
//{
// int hour = GetTeamHour(DateTime.Now).Seq;
// switch (hour)
// {
// case 1:
// bfd.AnHour = item.Yield - bfd.Production;
// break;
// case 2:
// bfd.TwoHour = item.Yield - bfd.Production;
// break;
// case 3:
// bfd.ThreeHour = item.Yield - bfd.Production;
// break;
// case 4:
// bfd.FourHour = item.Yield - bfd.Production;
// break;
// case 5:
// bfd.FiveHour = item.Yield - bfd.Production;
// break;
// case 6:
// bfd.SixHour = item.Yield - bfd.Production;
// break;
// case 7:
// bfd.SevenHour = item.Yield - bfd.Production;
// break;
// case 8:
// bfd.EightHour = item.Yield - bfd.Production;
// break;
// case 9:
// bfd.NineHour = item.Yield - bfd.Production;
// break;
// case 10:
// bfd.TenHour = item.Yield - bfd.Production;
// break;
// case 11:
// bfd.ElevenHour = item.Yield - bfd.Production;
// break;
// case 12:
// bfd.TwelveHour = item.Yield - bfd.Production;
// break;
// default:
// break;
// }
// bfd.Production = item.Yield;
// await _oldBoxFoamDataServices.UpdateAsync(bfd);
//}
//private async void SaveBoxData(string productLineCode, FixtureStatus item)
//{
// BoxFoamData bfdata = new BoxFoamData();
// bfdata.MainId = item.ObjId;
// bfdata.ProductLineCode = productLineCode;
// bfdata.Fixtureboxtype = item.FixtureBoxType;
// bfdata.Fixturestatus = item.Status;
// bfdata.Production = item.Yield;
// bfdata.CuringTimeSettingValue = item.PlanCuringTime.ToString();
// bfdata.ActualValue = item.RealCuringTime.ToString();
// int hour = GetTeamHour(DateTime.Now).Seq;
// switch (hour)
// {
// case 1:
// bfdata.AnHour = item.Yield = bfdata.Production;
// break;
// case 2:
// bfdata.TwoHour = item.Yield = bfdata.Production;
// break;
// case 3:
// bfdata.ThreeHour = item.Yield = bfdata.Production;
// break;
// case 4:
// bfdata.FourHour = item.Yield = bfdata.Production;
// break;
// case 5:
// bfdata.FiveHour = item.Yield = bfdata.Production;
// break;
// case 6:
// bfdata.SixHour = item.Yield = bfdata.Production;
// break;
// case 7:
// bfdata.SevenHour = item.Yield = bfdata.Production;
// break;
// case 8:
// bfdata.EightHour = item.Yield = bfdata.Production;
// break;
// case 9:
// bfdata.NineHour = item.Yield = bfdata.Production;
// break;
// case 10:
// bfdata.TenHour = item.Yield = bfdata.Production;
// break;
// case 11:
// bfdata.ElevenHour = item.Yield = bfdata.Production;
// break;
// case 12:
// bfdata.TwelveHour = item.Yield = bfdata.Production;
// break;
// default:
// break;
// }
// bfdata.MainId = item.ObjId;
// await _oldBoxFoamDataServices.AddAsync(bfdata);
//}
//public CurrentTeamTimeView GetTeamHour()
//{
// DateTime now = DateTime.Now;
// var list = _sysUserInfoServices.GetTeamData().Result;
// if (list != null)
// {
// //var obj = list.FirstOrDefault().EndTime.ToString("HH:mm");
// var view = list.FirstOrDefault();
// return view;
// }
// return null;
//}
//public CurrentTeamTimeView GetTeamHour(DateTime now)
//{
// var obj = _sysUserInfoServices.GetTeamData(now).Result;
// if (obj != null)
// {
// return obj;
// }
// return null;
//}
#endregion
}
}

@ -13,6 +13,7 @@ using Admin.Core.Model;
using Aucma.Core.HwPLc;
using Microsoft.Extensions.DependencyInjection;
using NetTaste;
using SqlSugar;
namespace Aucma.Core.SheetMetal.Business;
@ -21,12 +22,24 @@ namespace Aucma.Core.SheetMetal.Business;
/// </summary>
public class SheetMetalPlanTaskHandle
{
#region 刷新当前正在执行的计划
/// <summary>
/// 刷新当前正在执行的计划
/// </summary>
public delegate void RefreshCurrentPlanInfo(ExecutePlanInfo planInfo);
public event RefreshCurrentPlanInfo RefreshCurrentPlanInfoEvent;
public static event RefreshCurrentPlanInfo RefreshCurrentPlanInfoEvent;
#endregion
#region 给设备监控模块显示
/// <summary>
/// 刷新当前正在执行的计划
/// </summary>
public delegate void RefreshExecInfo(string message);
public static event RefreshExecInfo RefreshExecInfoEvent;
#endregion
protected readonly IExecutePlanInfoServices? _executePlanInfoServices;
protected readonly IRecordSidePanelComplateServices _sidePanelComplateServices;
@ -52,13 +65,14 @@ public class SheetMetalPlanTaskHandle
while (true)
{
var planInfos = _executePlanInfoServices.Query(d => d.ProductLineCode.Equals("1001") && d.ExecuteStatus == 1);
var planInfos = _executePlanInfoServices.QueryAsync(d => d.ProductLineCode.Equals("1001") && d.ExecuteStatus == 1).Result;
if (planInfos != null)
{
if (planInfos.Count > 0)
{
ExecutePlanInfo planInfo = planInfos.First();
//planInfo.PlanAmount = planInfo.PlanAmount - planInfo.CompleteAmount;
if (planInfo.PlanType == 1) //联合下发
{
SendPlanTask(planInfo, obj_sidePanel, obj_backPanel);
@ -83,6 +97,7 @@ public class SheetMetalPlanTaskHandle
else
{
Console.WriteLine("未获取到需要下发的任务");
RefreshExecInfoEvent?.Invoke("未获取到需要下发的任务");
}
}
@ -105,14 +120,14 @@ public class SheetMetalPlanTaskHandle
do
{
//等待计划执行完成
List<RecordSidePanelComplate> sidePanelComplates = _sidePanelComplateServices.Query(x => x.ProductlineCode == "1001" && x.PlanCode == planInfo.TaskCode);
List<RecordSidePanelComplate> sidePanelComplates = _sidePanelComplateServices.QueryAsync(x => x.ProductlineCode == "1001" && x.PlanCode == planInfo.TaskCode).Result;
int sumSidePanelAmount = sidePanelComplates.Sum(x => x.OutPutAmount);
List<RecordBackPanelComplate> backPanelComplates = _backPanelComplateServices.Query(x => x.ProductlineCode == "1001" && x.PlanCode == planInfo.TaskCode);
List<RecordBackPanelComplate> backPanelComplates = _backPanelComplateServices.QueryAsync(x => x.ProductlineCode == "1001" && x.PlanCode == planInfo.TaskCode).Result;
int sumBackPanelAmount = backPanelComplates.Sum(x => x.OutPutAmount);
Console.WriteLine($"当前计划:{planInfo.TaskCode};计划产量:{planInfo.PlanAmount};围板完成:{sumSidePanelAmount};背板完成:{sumBackPanelAmount}");
RefreshExecInfoEvent?.Invoke($"当前计划:{planInfo.TaskCode};计划产量:{planInfo.PlanAmount};围板完成:{sumSidePanelAmount};背板完成:{sumBackPanelAmount}");
int sumAmount = 0;
if (planInfo.PlanType == 1)
@ -153,6 +168,7 @@ public class SheetMetalPlanTaskHandle
catch (Exception ex)
{
Console.WriteLine($"计划任务信息更新异常:{ex.Message}");
RefreshExecInfoEvent?.Invoke($"计划任务信息更新异常:{ex.Message}");
}
}
@ -171,13 +187,16 @@ public class SheetMetalPlanTaskHandle
if (obj_sidePanel != null)
{
//计划编号10个字D6000-D6009、物料编号10个字D6010-D6019、计划数量1个字D6020、应答字1个字D6021
obj_sidePanel.plc.WriteString("D6030", planInfo.TaskCode);
obj_sidePanel.plc.WriteString("D6000", planInfo.TaskCode);
string processNumber = GetProcessNumberBy(planInfo.MaterialCode);
obj_sidePanel.plc.WriteString("D6010", "BCD/310NF");
obj_sidePanel.plc.WriteInt32("D6020", planInfo.PlanAmount);
obj_sidePanel.plc.WriteInt32("D6021", 1);
Console.WriteLine($"{DateTime.Now.ToString("HH:m:s")}===>等待围板设备应答。。。。。。");
RefreshExecInfoEvent?.Invoke("等待围板设备应答");
//下发完成后读取PLC应答应答后复位应答信号
#region PLC反馈信号逻辑处理
@ -189,6 +208,7 @@ public class SheetMetalPlanTaskHandle
{
obj_sidePanel.plc.WriteInt32("D6021", 0);
Console.WriteLine($"{DateTime.Now.ToString("HH:m:s")}===>收到围板设备应答信号,复位应答地址");
RefreshExecInfoEvent?.Invoke("收到围板设备应答信号,复位应答地址");
isFlag = false;
}
Thread.Sleep(2000);
@ -210,13 +230,14 @@ public class SheetMetalPlanTaskHandle
if (obj_backPanel != null)
{
//计划编号10个字D6000-D6009、物料编号10个字D6010-D6019、计划数量1个字D6020、应答字1个字D6021
obj_backPanel.plc.WriteString("D6030", planInfo.TaskCode);
obj_backPanel.plc.WriteString("D4000", planInfo.TaskCode);
string processNumber = GetProcessNumberBy(planInfo.MaterialCode);
obj_backPanel.plc.WriteString("D6010", "BCD/310NF");
obj_backPanel.plc.WriteInt32("D6020", planInfo.PlanAmount);
obj_backPanel.plc.WriteInt32("D6021", 1);
obj_backPanel.plc.WriteString("D4010", "BCD/310NF");
obj_backPanel.plc.WriteInt32("D4020", planInfo.PlanAmount);
obj_backPanel.plc.WriteInt32("D4021", 1);
Console.WriteLine($"{DateTime.Now.ToString("HH:m:s")}===>等待背板设备应答。。。。。。");
RefreshExecInfoEvent?.Invoke("等待背板设备应答......");
#region PLC反馈信号逻辑处理
//循环读取PLC应答信号PLC应答后复位应答信号、更新计划状态为执行中
@ -224,10 +245,11 @@ public class SheetMetalPlanTaskHandle
do
{
if (obj_backPanel.plc.ReadInt32("D6021") == 2)
if (obj_backPanel.plc.ReadInt32("D4021") == 2)
{
obj_backPanel.plc.WriteInt32("D6021", 0);
obj_backPanel.plc.WriteInt32("D4021", 0);
Console.WriteLine($"{DateTime.Now.ToString("HH:m:s")}===>收到背板板设备应答信号,复位应答地址");
RefreshExecInfoEvent?.Invoke("收到背板板设备应答信号,复位应答地址");
isFlag = false;
}
Thread.Sleep(2000);
@ -265,13 +287,14 @@ public class SheetMetalPlanTaskHandle
if (obj_sidePanel != null)
{
//计划编号10个字D6000-D6009、物料编号10个字D6010-D6019、计划数量1个字D6020、应答字1个字D6021
obj_sidePanel.plc.WriteString("D6030", planInfo.TaskCode);
obj_sidePanel.plc.WriteString("D6000", planInfo.TaskCode);
string processNumber = GetProcessNumberBy(planInfo.MaterialCode);
obj_sidePanel.plc.WriteString("D6010", "BCD/310NF");
obj_sidePanel.plc.WriteInt32("D6020", planInfo.PlanAmount);
obj_sidePanel.plc.WriteInt32("D6021", 1);
Console.WriteLine($"{DateTime.Now.ToString("HH:m:s")}===>等待围板设备应答。。。。。。");
RefreshExecInfoEvent?.Invoke("等待围板设备应答......");
//下发完成后读取PLC应答应答后复位应答信号
#region PLC反馈信号逻辑处理
@ -283,6 +306,7 @@ public class SheetMetalPlanTaskHandle
{
obj_sidePanel.plc.WriteInt32("D6021", 0);
Console.WriteLine($"{DateTime.Now.ToString("HH:m:s")}===>收到围板设备应答信号,复位应答地址");
RefreshExecInfoEvent?.Invoke("收到围板设备应答信号......");
isFlag = false;
}
Thread.Sleep(2000);
@ -303,6 +327,7 @@ public class SheetMetalPlanTaskHandle
{
MessageBox.Show($"围板⽣产计划下发异常:{ex.Message}", "提示", MessageBoxButton.OK, MessageBoxImage.Error,
MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly);
RefreshExecInfoEvent?.Invoke("产计划下发异常");
}
}
@ -342,7 +367,9 @@ public class SheetMetalPlanTaskHandle
int productionBeat = short.Parse(bytesToHexStr(info.Skip(51).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
Console.WriteLine($"围板设备数据读取====>>>>当前计划:{planCode},物料编号:{materialCode},完成数量:{complateAmount},下线数量:{offLineAmount},设备状态:{deviceStatus},生产节拍:{productionBeat}");
Console.WriteLine($"===>收到围板设备应答信号,复位应答地址");
RefreshExecInfoEvent?.Invoke($"围板设备数据读取====>>>>当前计划:{planCode},物料编号:{materialCode},完成数量:{complateAmount},下线数量:{offLineAmount},设备状态:{deviceStatus},生产节拍:{productionBeat}");
RefreshExecInfoEvent?.Invoke($"收到围板设备应答信号,复位应答地址");
//添加完工记录
RecordSidePanelComplate sidePanelComplate = new RecordSidePanelComplate()
{
@ -385,7 +412,7 @@ public class SheetMetalPlanTaskHandle
}
else
{
List<ExecutePlanInfo> planInfos = _executePlanInfoServices.Query(x => x.TaskCode.Equals(planCode.Substring(0, 16)) && x.ExecuteStatus == 2);
List<ExecutePlanInfo> planInfos = _executePlanInfoServices.QueryAsync(x => x.TaskCode.Equals(planCode.Substring(0, 16)) && x.ExecuteStatus == 2).Result;
if (planInfos != null)
{
if (planInfos.Count > 0)
@ -397,6 +424,7 @@ public class SheetMetalPlanTaskHandle
{
isFlag = false;
Console.WriteLine($"围板计划执行完成,计划数量:{planInfo.PlanAmount};实际产量:{sumComplateAmount};差异值:{planInfo.PlanAmount - sumComplateAmount}");
RefreshExecInfoEvent?.Invoke($"围板计划执行完成,计划数量:{planInfo.PlanAmount};实际产量:{sumComplateAmount};差异值:{planInfo.PlanAmount - sumComplateAmount}");
}
}
}
@ -414,6 +442,7 @@ public class SheetMetalPlanTaskHandle
catch (Exception e)
{
Console.WriteLine($"读取围板设备完成数据异常:{e.Message}");
RefreshExecInfoEvent?.Invoke($"读取围板设备完成数据异常:{e.Message}");
}
}
@ -433,24 +462,25 @@ public class SheetMetalPlanTaskHandle
if (obj_backPanel != null)
{
//计划编号10个字D6000-D6009、物料编号10个字D6010-D6019、计划数量1个字D6020、应答字1个字D6021
obj_backPanel.plc.WriteString("D6030", planInfo.TaskCode);
obj_backPanel.plc.WriteString("D4000", planInfo.TaskCode);
string processNumber = GetProcessNumberBy(planInfo.MaterialCode);
obj_backPanel.plc.WriteString("D6010", "BCD/310NF");
obj_backPanel.plc.WriteInt32("D6020", planInfo.PlanAmount);
obj_backPanel.plc.WriteInt32("D6021", 1);
obj_backPanel.plc.WriteString("D4010", "BCD/310NF");
obj_backPanel.plc.WriteInt32("D4020", planInfo.PlanAmount);
obj_backPanel.plc.WriteInt32("D4021", 1);
Console.WriteLine($"{DateTime.Now.ToString("HH:m:s")}===>等待背板设备应答。。。。。。");
RefreshExecInfoEvent?.Invoke($"等待背板设备应答.....");
#region PLC反馈信号逻辑处理
//循环读取PLC应答信号PLC应答后复位应答信号、更新计划状态为执行中
bool isFlag = true;
do
{
if (obj_backPanel.plc.ReadInt32("D6021") == 2)
if (obj_backPanel.plc.ReadInt32("D4021") == 2)
{
obj_backPanel.plc.WriteInt32("D6021", 0);
obj_backPanel.plc.WriteInt32("D4021", 0);
Console.WriteLine($"{DateTime.Now.ToString("HH:m:s")}===>收到背板板设备应答信号,复位应答地址");
RefreshExecInfoEvent?.Invoke($"收到背板板设备应答信号,复位应答地址");
isFlag = false;
}
Thread.Sleep(2000);
@ -471,6 +501,7 @@ public class SheetMetalPlanTaskHandle
{
MessageBox.Show($"背板⽣产计划下发异常:{ex.Message}", "提示", MessageBoxButton.OK, MessageBoxImage.Error,
MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly);
RefreshExecInfoEvent?.Invoke($"背板⽣产计划下发异常:{ex.Message}");
}
}
@ -487,7 +518,7 @@ public class SheetMetalPlanTaskHandle
do
{
//计划编号D6030-D6039物料编号D6040-D6049计划完成数D6050计划下线数D6051设备状态D6052-D6056,生产节拍D6057-D6058
byte[] info = obj.plc.Read("D6030", 59);
byte[] info = obj.plc.Read("D4030", 59);
if (info == null)
{
@ -509,7 +540,7 @@ public class SheetMetalPlanTaskHandle
int productionBeat = short.Parse(bytesToHexStr(info.Skip(51).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
Console.WriteLine($"背板设备数据读取====>>>>当前计划:{planCode},物料编号:{materialCode},完成数量:{complateAmount},下线数量:{offLineAmount},设备状态:{deviceStatus},生产节拍:{productionBeat}");
RefreshExecInfoEvent?.Invoke($"当前计划:{planCode},物料编号:{materialCode},完成数量:{complateAmount},下线数量:{offLineAmount},设备状态:{deviceStatus},生产节拍:{productionBeat}");
//添加完工记录
RecordBackPanelComplate backPanelComplate = new RecordBackPanelComplate()
{
@ -563,6 +594,7 @@ public class SheetMetalPlanTaskHandle
{
isFlag = false;
Console.WriteLine($"背板计划执行完成,计划数量:{planInfo.PlanAmount};实际产量:{sumComplateAmount};差异值:{planInfo.PlanAmount - sumComplateAmount}");
RefreshExecInfoEvent?.Invoke($"背板计划执行完成,计划数量:{planInfo.PlanAmount};实际产量:{sumComplateAmount};差异值:{planInfo.PlanAmount - sumComplateAmount}");
}
}
}
@ -579,11 +611,10 @@ public class SheetMetalPlanTaskHandle
catch (Exception e)
{
Console.WriteLine($"读取背板设备完成数据异常:{e.Message}");
RefreshExecInfoEvent?.Invoke($"读取背板设备完成数据异常:{e.Message}");
}
}
/// <summary>
/// 通过物料编号获取工艺编号
/// </summary>

@ -33,7 +33,19 @@ namespace Aucma.Core.SheetMetal.Models
/// </summary>
public int CompleteAmount { get; set; }
/// <summary>
///
/// 前板完成数量
/// </summary>
public int SidePanelComplete { get; set; }
/// <summary>
/// 后板完成数量
/// </summary>
public int BackPanelComplete { get; set; }
/// <summary>
/// 状态
/// </summary>
public string Status { get; set; }
/// <summary>
/// 完成时间
/// </summary>
public string BeginTime { get; set; }
/// <summary>

@ -61,9 +61,10 @@ namespace Aucma.Core.SheetMetal
//注册业务服务
AddServices(services);
//任务调度
services.AddJobSetup();
//services.AddJobSetup();
//PLC
services.AddPlcSetup();
// services.AddAucmaTaskSetup();
//支持编码大全 例如:支持 System.Text.Encoding.GetEncoding("GB2312") System.Text.Encoding.GetEncoding("GB18030")
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
}
@ -84,13 +85,12 @@ namespace Aucma.Core.SheetMetal
/// </summary>
/// <param name="app"></param>
/// <param name="env"></param>
public void Configure(IApplicationBuilder app, ISysTasksQzService tasksQzService,
ISchedulerCenter schedulerCenter, IRunPlcService runPlcService)
public void Configure(IApplicationBuilder app, IRunPlcService runPlcService)
{
// 使用静态文件
app.UseStaticFiles();
// 开启QuartzNetJob调度服务
app.UseQuartzJobMildd(tasksQzService, schedulerCenter);
//app.UseQuartzJobMildd(tasksQzService, schedulerCenter);
//PLC
app.UsePlcMildd(runPlcService);
}

@ -25,6 +25,7 @@ using static Aucma.Core.SheetMetal.Business.SheetMetalPlanTaskHandle;
using System.Threading;
using NetTaste;
using Aucma.Core.HwPLc;
using Admin.Core.Model.ViewModels;
/*
*
*/
@ -33,7 +34,8 @@ namespace Aucma.Core.SheetMetal.ViewModels
public partial class IndexPageViewModel : ObservableObject
{
protected readonly IExecutePlanInfoServices? _taskExecutionPlanInfoServices;
private SheetMetalPlanTaskHandle _taskHandle = new SheetMetalPlanTaskHandle();
protected readonly ISysUserInfoServices? _sysUserInfoServices;
//private SheetMetalPlanTaskHandle _taskHandle = new SheetMetalPlanTaskHandle();
private AppConfigHelper appConfig = new AppConfigHelper();
List<SelectModel> list = new List<SelectModel>() { new SelectModel()
@ -51,22 +53,31 @@ namespace Aucma.Core.SheetMetal.ViewModels
#region 构造函数
public IndexPageViewModel()
{
_stationName = Appsettings.app("StationInfo", "StationName");//工位名称
_taskExecutionPlanInfoServices = App.ServiceProvider.GetService<IExecutePlanInfoServices>();
_stationName = Appsettings.app("StationInfo", "StationName");
Job_SheetMetalTask_Quartz.SmEverDayDelegateEvent += InitEveryDayMethod;
Job_SheetMetalTask_Quartz.SmTaskDelegateEvent += UpdatePlanSHow;//计划内容展示
WeakReferenceMessenger.Default.Register<string>(this, Recive);
Task.WaitAll(LoadData(), InitExecMethod());
InitEveryDayMethod();
_sysUserInfoServices = App.ServiceProvider.GetService<ISysUserInfoServices>();
//Job_SheetMetalTask_Quartz.SmEverDayDelegateEvent += InitEveryDayMethod;
//Job_SheetMetalTask_Quartz.SmTaskDelegateEvent += UpdatePlanSHow;//计划内容展示
//WeakReferenceMessenger.Default.Register<string>(this, Recive);
Task.WaitAll(LoadData());
//InitEveryDayMethod();
AddSelectData();//添加下拉菜单
//RefreshHourAmount();//小时产量
SheetMetalPlanTaskHandle.RefreshCurrentPlanInfoEvent += RefreshCurrentPlanInfo;
}
#endregion
#region 下拉
public void AddSelectData()
{
foreach (var item in list)
{
LocationSource.Add(item);
}
SelectLocation = ReadFile();
_taskHandle.RefreshCurrentPlanInfoEvent += RefreshCurrentPlanInfo;
}
#endregion
#region 订单统计
@ -125,7 +136,7 @@ namespace Aucma.Core.SheetMetal.ViewModels
ProductionHourList = new List<string>()
{
"7:30", "8:80", "9:30", "10:30", "11:30", "12:30", "13:30", "14:30", "15:30", "16:30", "17:30", "18:30"
"8:00", "9:00", "9:30", "10:30", "11:30", "12:30", "13:30", "14:30", "15:30", "16:30", "17:30", "18:30"
};
//Formatter = value => value.ToString("N");
Achievement.Add(column);
@ -135,10 +146,10 @@ namespace Aucma.Core.SheetMetal.ViewModels
DataLabels = true,
Title = "后板",
Values = achievement,
Fill = new SolidColorBrush(Color.FromRgb(15,209,226)),
Fill = new SolidColorBrush(Color.FromRgb(15, 209, 226)),
Foreground = Brushes.CadetBlue,
FontSize = 18
});
});
#endregion
@ -182,15 +193,12 @@ namespace Aucma.Core.SheetMetal.ViewModels
#region 计划列表
#region 加载DataGrid数据
private async Task LoadData()
private Task LoadData()
{
string productLineCode = Appsettings.app("StationInfo", "ProductLineCode");
string stationCode = Appsettings.app("StationInfo", "StationCode");
//stationCode = "1001";
//var list = await _taskExecutionPlanInfoServices.QueryAsync(d => d.ProductLineCode.Contains(stationCode));
var list = _taskExecutionPlanInfoServices.Query(x => x.ProductLineCode == stationCode);
if (list == null) return;
var execList = list.OrderBy(d => d.ExecuteOrder);
var list = _taskExecutionPlanInfoServices.QueryAsync(x => x.ProductLineCode == stationCode).Result;
if (list == null) return Task.CompletedTask;
var execList = list.OrderByDescending(d => d.ExecuteOrder);
int i = 1;
string planType = string.Empty;
foreach (var item in execList)
@ -224,6 +232,23 @@ namespace Aucma.Core.SheetMetal.ViewModels
PlanInfoDataGrid.Add(task);
i++;
}
//更新首页显示信息
ExecutePlanInfo execPlan = execList.SingleOrDefault(d => d.ExecuteStatus == 2);
if (execPlan!=null)
{
_orderCode = execPlan.OrderCode;
_mesMOrderCode = execPlan.ProductPlanCode;
_productModel = execPlan.MaterialName;
_beginTime = execPlan.BeginTime.ToString();
_planMaxNum= _planNum = execPlan.PlanAmount;
_realQuantity = execPlan.CompleteAmount;
_diffQuantity =_planMaxNum- _realQuantity;
_completionRate = _realQuantity / _planMaxNum;
}
return Task.CompletedTask;
}
#endregion
@ -619,17 +644,52 @@ namespace Aucma.Core.SheetMetal.ViewModels
}
#endregion
#region 刷新当前执行的计划进度
/// <summary>
/// 刷新当前执行的计划进度
/// </summary>
/// <param name="planInfo"></param>
private void RefreshCurrentPlanInfo(ExecutePlanInfo planInfo)
{
_ = App.Current.Dispatcher.BeginInvoke((Action)(() =>
App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
PlanInfoDataGrid.Clear();
LoadData();
}));
}
#endregion
#region 刷新小时产量统计
/// <summary>
/// 刷新小时产量统计
/// </summary>
private void RefreshHourAmount()
{
App.Current.Dispatcher.Invoke((Action)(() =>
{
//获取小时产量
string stationCode = Appsettings.app("StoreInfo", "StationCode");
List<dynamic> hourAmount = _sysUserInfoServices.GetStationHourAmountAsync(stationCode);
if (hourAmount != null)
{
Achievement.Clear();
ProductionHourList = new List<string>();
ChartValues<double> hourAchievement = new ChartValues<double>();
foreach (var item in hourAmount)
{
ProductionHourList.Add(item.PRODUCT_HOUR);
hourAchievement.Add(Convert.ToDouble(item.PRODUCT_AMOUNT));
}
var houeColumn = new ColumnSeries();
houeColumn.DataLabels = true;
houeColumn.Title = "小时产量";
houeColumn.Values = hourAchievement;
houeColumn.Foreground = Brushes.White;
Achievement.Add(houeColumn);
}
}));
}
#endregion
}
}

@ -11,6 +11,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Documents;
using Admin.Core.Tasks;
using Aucma.Core.SheetMetal.Business;
namespace Aucma.Core.SheetMetal.ViewModels
{
@ -21,9 +22,9 @@ namespace Aucma.Core.SheetMetal.ViewModels
public LogPageViewModel()
{
//Job_Admin_Quartz.LogDelegateEvent += PrintMessageToListBox;
SheetMetalPlanTaskHandle.RefreshExecInfoEvent += PrintMessageToListBox;
}
/// <summary>
/// LisBox数据模板
/// </summary>

@ -79,7 +79,7 @@ namespace Aucma.Core.SheetMetal.ViewModels
public void RefreshPlc()
{
// 后板plc
var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("后板Plc"));
var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("BackPanelPLC"));
if (obj != null)
{
if (obj.plc.IsConnected)
@ -96,7 +96,7 @@ namespace Aucma.Core.SheetMetal.ViewModels
PlcState(false);
}
// u壳plc
var obj2 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("U壳PLC"));
var obj2 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("SidePanelPlc"));
if (obj2 != null)
{
if (obj2.plc.IsConnected)
@ -116,6 +116,7 @@ namespace Aucma.Core.SheetMetal.ViewModels
}
#endregion
#region 更换界面
public System.Windows.Controls.UserControl _content;
@ -222,6 +223,7 @@ namespace Aucma.Core.SheetMetal.ViewModels
}
}
#endregion
#region MES数据库状态
/// <summary>
/// MES数据库-文字
@ -261,13 +263,13 @@ namespace Aucma.Core.SheetMetal.ViewModels
{
if (type)
{
MesDbUIStatusWb = "MES数据库连接成功";
MesDbUIStatusWb = "MES数据库";
MesDbUIColor = "Green";
MesUIIcon = "Assets/Images/Green.png";
}
else
{
MesDbUIStatusWb = "MES数据库异常";
MesDbUIStatusWb = "MES数据库";
MesDbUIColor = "Red";
MesUIIcon = "Assets/Images/Red.png";
}
@ -314,13 +316,13 @@ namespace Aucma.Core.SheetMetal.ViewModels
{
if (type)
{
PlcUIStatusWb = "后板PLC连接成功";
PlcUIStatusWb = "后板PLC";
PlcUIColor = "Green";
PlcUIIcon = "Assets/Images/Green.png";
}
else
{
PlcUIStatusWb = "后板PLC状态异常";
PlcUIStatusWb = "后板PLC";
PlcUIColor = "Red";
PlcUIIcon = "Assets/Images/Red.png";
}
@ -328,7 +330,6 @@ namespace Aucma.Core.SheetMetal.ViewModels
}
#endregion
#region U壳PLC状态
/// <summary>
/// UI plc 展示状态-文字
@ -368,13 +369,13 @@ namespace Aucma.Core.SheetMetal.ViewModels
{
if (type)
{
Plc2UIStatusWb = "U壳PLC连接成功";
Plc2UIStatusWb = "U壳PLC";
Plc2UIColor = "Green";
Plc2UIIcon = "Assets/Images/Green.png";
}
else
{
Plc2UIStatusWb = "U壳PLC状态异常";
Plc2UIStatusWb = "U壳PLC";
Plc2UIColor = "Red";
Plc2UIIcon = "Assets/Images/Red.png";
}

@ -49,7 +49,7 @@ namespace Aucma.Core.SheetMetal.ViewModels
MaterialDataGrid.Clear();
int i = 1;
string station = Appsettings.app("StationInfo", "StationCode");
var planlist = _productPlanInfoServices.Query(d => d.ProductLineCode.Equals(station));
var planlist = _productPlanInfoServices.QueryAsync(d => d.ProductLineCode.Equals(station)).Result;
if (planlist == null) return ;
var execList = await _executePlanInfoServices.QueryAsync(d => d.ProductLineCode.Equals(station));
if (execList == null) return;

@ -11,6 +11,9 @@ using System.Windows;
using Admin.Core.IService;
using Admin.Core.Service;
using Microsoft.Extensions.DependencyInjection;
using Admin.Core.Model;
using StackExchange.Profiling.Internal;
using Admin.Core.Common;
namespace Aucma.Core.SheetMetal.ViewModels
{
@ -18,23 +21,30 @@ namespace Aucma.Core.SheetMetal.ViewModels
{
List<MaterialComplateInfo> materialComplateInfos = new List<MaterialComplateInfo>();
protected readonly IProductPlanInfoServices? _productPlanInfoServices;
protected readonly IRecordSidePanelComplateServices _sidePanelComplateServices;
protected readonly IRecordBackPanelComplateServices _backPanelComplateServices;
protected readonly IExecutePlanInfoServices? _executePlanInfoServices;
public StatisticsPageViewModel()
{
_productPlanInfoServices = App.ServiceProvider.GetService<IProductPlanInfoServices>();
Task.Run(async () =>
{
await LoadData();
});
_sidePanelComplateServices = App.ServiceProvider.GetService<IRecordSidePanelComplateServices>();
_backPanelComplateServices = App.ServiceProvider.GetService<IRecordBackPanelComplateServices>();
_executePlanInfoServices = App.ServiceProvider.GetService<IExecutePlanInfoServices>();
Task.WaitAll(LoadData());
}
#region 加载DataGrid数据
private async Task LoadData()
{
var list = (await _productPlanInfoServices.QueryAsync(d=>d.ProductLineCode=="1001")).Take(1000);
string station = Appsettings.app("StationInfo", "StationCode");
var list = _productPlanInfoServices.QueryAsync(d => d.ProductLineCode.Equals(station)).Result;
var sidePanelComplateList = _sidePanelComplateServices.QueryAsync(d => d.ProductlineCode == "1001").Result;
int i = 1;
foreach (var item in list)
{
int sidePanelComplete = GetSidePanelCompleteData(sidePanelComplateList, item.OrderCode, "1001");
int backPanelComplete = GetBackPanelCompleteData(sidePanelComplateList, item.OrderCode, "1001");
MaterialDataGrid.Add(new MaterialComplateInfo() {
No = i,
ProductPlanCode = item.PlanCode,
@ -42,9 +52,12 @@ namespace Aucma.Core.SheetMetal.ViewModels
MaterialName = item.MaterialName,
PlanAmount = item.PlanAmount,
CompleteAmount = item.CompleteAmount,
SidePanelComplete = sidePanelComplete,
BackPanelComplete = backPanelComplete,
BeginTime = item.BeginTime.ToString(),
EndTime = item.EndTime.ToString(),
});
Status= item.CompleteAmount== item.PlanAmount?"完成":"未完成"
});
i++;
}
}
@ -90,7 +103,8 @@ namespace Aucma.Core.SheetMetal.ViewModels
var beginTime =DateTime.Parse(result.BeginTime);
var endTime = DateTime.Parse(result.EndTime);
MaterialDataGrid.Clear();
var list = await _productPlanInfoServices.QueryAsync(d => d.ProductLineCode == "1001");
string station = Appsettings.app("StationInfo", "StationCode");
var list = _productPlanInfoServices.QueryAsync(d => d.ProductLineCode.Equals(station)).Result;
foreach (var item in list.Where(d=>d.BeginTime> beginTime&& d.EndTime < endTime))
{
MaterialDataGrid.Add(new MaterialComplateInfo()
@ -111,6 +125,44 @@ namespace Aucma.Core.SheetMetal.ViewModels
LoadData();
}
}
#endregion
#endregion
/// <summary>
/// 围板完成数量
/// </summary>
/// <param name="sidePanelComplate"></param>
/// <param name="orderCode">订单</param>
/// <param name="productLineCode">工位</param>
/// <returns></returns>
public int GetSidePanelCompleteData(List<RecordSidePanelComplate> sidePanelComplate, string orderCode, string productLineCode)
{
try
{
var execList = _executePlanInfoServices.QueryAsync(d => d.OrderCode == orderCode && d.ProductPlanCode == productLineCode).Result;
List<string> taskCodeList = execList.Select(x => x.TaskCode).ToList();
var list = _sidePanelComplateServices.QueryAsync(d => taskCodeList.Contains(d.PlanCode)).Result;
return list.Count;
}
catch (Exception)
{
return 0;
}
}
public int GetBackPanelCompleteData(List<RecordSidePanelComplate> sidePanelComplate, string orderCode, string productLineCode)
{
try
{
var execList = _executePlanInfoServices.QueryAsync(d => d.OrderCode == orderCode && d.ProductPlanCode == productLineCode).Result;
List<string> taskCodeList = execList.Select(x => x.TaskCode).ToList();
var list = _backPanelComplateServices.QueryAsync(d => taskCodeList.Contains(d.PlanCode)).Result;
return list.Count;
}
catch (Exception)
{
return 0;
}
}
}
}

@ -18,7 +18,7 @@
</Border>
<Border Grid.Row="1" BorderBrush="#0288d1" BorderThickness="0" CornerRadius="5" Background="Transparent" Margin="1,1,5,5">
<Grid Margin="10,10">
<ListBox Grid.Row="1" x:Name="listBox" ItemsSource="{Binding LogInfoListBox}" Foreground="White" Background="Transparent" BorderBrush="Transparent" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden"/>
<ListBox Grid.Row="1" x:Name="listBox" FontSize="18" ItemsSource="{Binding LogInfoListBox}" Foreground="White" Background="Transparent" BorderBrush="Transparent" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden"/>
</Grid>
</Border>
</Grid>

@ -121,7 +121,7 @@
</DatePicker.SelectedDate>
</DatePicker>
<Button Margin="10 0"
Content="查询" Command="{Binding ExecQueryCommand}" FontSize="50"
Content="查询" Command="{Binding ExecQueryCommand}" FontSize="18"
Style="{StaticResource MaterialDesignRaisedSecondaryDarkButton}">
<Button.CommandParameter>
<MultiBinding Converter="{StaticResource QueryConvert}">
@ -146,9 +146,9 @@
<DataGridTextColumn Binding="{Binding MaterialName}" Header="物料名称" Width="3*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" Visibility="Collapsed"/>
<DataGridTextColumn Binding="{Binding MaterialCode}" Header="物料编号" Width="1*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" Visibility="Collapsed"/>
<DataGridTextColumn Binding="{Binding PlanAmount}" Header="计划数量" Width="*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding PlanAmount}" Header="前板数量" Width="*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding PlanAmount}" Header="后板数量" Width="*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding ProductPlanCode}" Header="状态" Width="1*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding SidePanelComplete}" Header="前板数量" Width="*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding BackPanelComplete}" Header="后板数量" Width="*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding Status}" Header="状态" Width="1*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
</DataGrid.Columns>
</DataGrid>

@ -135,8 +135,8 @@
"EquipName": "BackPanelPLC",
"PlcType": "Melsec",
"Enabled": true,
"IP": "127.0.0.1",
"Port": 6001
"IP": "10.10.91.6",
"Port": 5552
}
]
}

@ -14,13 +14,15 @@ namespace Aucma.Core.Tasks
/// </summary>
public class AucamTaskService : IAucamTaskService
{
/// <summary>
/// 老发泡线更新事件
/// </summary>
/// <returns></returns>
private static readonly log4net.ILog logHelper = LogManager.GetLogger(typeof(AucamTaskService));
public AucamTaskService()
IPerfusionRecordServices _perfusionRecordServices;
public AucamTaskService(IPerfusionRecordServices perfusionRecordServices, IPerfusionAlarmServices perfusionAlarmServices, IPerfusionDeviceStatusServices perfusionDeviceStatusServices)
{
// _perfusionRecordServices = perfusionRecordServices;
PerfusionCollection coll = new PerfusionCollection(perfusionRecordServices, perfusionAlarmServices, perfusionDeviceStatusServices);
}
System.Timers.Timer timer1 = new System.Timers.Timer(5000);

@ -0,0 +1,249 @@
using Admin.Core.Common.Helper;
using Admin.Core.IRepository;
using Admin.Core.IService;
using Admin.Core.Model;
using Admin.Core.Model.Model_New;
using Aucma.Core.HwPLc;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Aucma.Core.Tasks.Business
{
/// <summary>
/// 采集灌注数据
/// </summary>
public class PerfusionCollection
{
Semaphore semaphore = new Semaphore(1, 1);
protected readonly IPerfusionRecordServices? _perfusionRecordServices ;
protected readonly IPerfusionAlarmServices ?_perfusionAlarmServices;
protected readonly IPerfusionDeviceStatusServices? _perfusionDeviceStatusServices;
private static System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
private Perfusion_Record record = new Perfusion_Record();
private Perfusion_Record temprRecord;
private Perfusion_DeviceStatus perfusion_DeviceStatus = new Perfusion_DeviceStatus();
private Perfusion_Alarm perfusion_Alarm = new Perfusion_Alarm();
public PerfusionCollection(IPerfusionRecordServices perfusionRecordServices, IPerfusionAlarmServices perfusionAlarmServices, IPerfusionDeviceStatusServices perfusionDeviceStatusServices)
{
_perfusionRecordServices = perfusionRecordServices;
_perfusionAlarmServices = perfusionAlarmServices;
_perfusionDeviceStatusServices = perfusionDeviceStatusServices;
startCollect();
}
public void startCollect()
{
Task.Run(() =>
{
while (true)
{
semaphore.WaitOne();
try
{
Thread.Sleep(3000);
var obj = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("PerfusionPlc"));
if (obj != null && obj.plc.IsConnected)
{
//采集数据
ReadEquipSystem(obj,record, perfusion_DeviceStatus, perfusion_Alarm);
//更新设备状态
// _perfusionDeviceStatusServices.UpdateAsync;
// 更新报警信息
//充注结束
if (record.PerfusionFinishStatus == "1")
{
//缓存没数据查数据库
if(temprRecord == null)
{
Perfusion_Record lastRecord = _perfusionRecordServices.Query(d => d.PerfusionBoxCode.Equals(record.PerfusionBoxCode)).FirstOrDefault();
// 数据库没有数据
if (lastRecord == null)
{
_= _perfusionRecordServices.AddAsync(record).Result;
return;
}
}
// 箱体码和上次不一样,或者箱体码一样但是充铸结果不一样
else if(temprRecord.PerfusionBoxCode!=record.PerfusionBoxCode || (temprRecord.PerfusionBoxCode == record.PerfusionBoxCode && temprRecord.PerfusionResult!=record.PerfusionResult) )
{
_ = _perfusionRecordServices.AddAsync(record).Result;
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
finally
{
temprRecord = record;
semaphore.Release();
}
}
});
}
/// <summary>
/// 采集灌注参数
/// </summary>
/// <returns></returns>
static void ReadEquipSystem(Aucma.Core.HwPLc.PlcModel obj, Perfusion_Record record, Perfusion_DeviceStatus deviceStatus, Perfusion_Alarm alarmInfo)
{
byte[] info = obj.plc.Read("DB55.0", 54);
if (info == null) return;
#region 灌注记录赋值
record.PerfusionActualVolume=byteToDouble(info.Skip(0).Take(8).ToArray()).ToString().Replace("\0", "");
record.PerfusionR = byteToFloat(info.Skip(8).Take(4).ToArray()).ToString().ToString().Replace("\0", "");
record.PerfusionL = byteToFloat(info.Skip(50).Take(4).ToArray()).ToString().Replace("\0", "");
record.PerfusionDuration = int.Parse(StringChange.bytesToHexStr(info.Skip(12).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber).ToString().Replace("\0", "");
record.Yield = int.Parse(StringChange.bytesToHexStr(info.Skip(16).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber).ToString().Replace("\0", "");
record.PerfusionBoxCode = asciiEncoding.GetString(info.Skip(20).Take(24).ToArray()).Trim('\n').Replace("\0", "");
// record.PerfusionRefrigerantTypeLeft = asciiEncoding.GetString(info.Skip(58).Take(7).ToArray()).Trim('\n').Replace("\0", "");
// record.PerfusionRefrigerantTypeRight = asciiEncoding.GetString(info.Skip(68).Take(7).ToArray()).Trim('\n').Replace("\0", "");
// record.PerfusionSetVolume = byteToFloat(info.Skip(78).Take(4).ToArray()).ToString().Replace("\0", "");
// record.PerfusionSystem =short.Parse(StringChange.bytesToHexStr(info.Skip(82).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString().Replace("\0", "");
///灌注完成状态字
record.PerfusionFinishStatus = short.Parse(StringChange.bytesToHexStr(info.Skip(42).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString().Replace("\0", "");
record.PerfusionResult = short.Parse(StringChange.bytesToHexStr(info.Skip(44).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
record.CreatedBy = "equip";
record.CreatedTime = DateTime.Now;
record.UpdatedBy = "equip";
record.UpdatedTime = DateTime.Now;
#endregion
#region 设备状态赋值
deviceStatus.PerfusionDevicetype = "灌注";
deviceStatus.PerfusionStatus = short.Parse(StringChange.bytesToHexStr(info.Skip(46).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
deviceStatus.CreatedBy = "equip";
deviceStatus.CreatedTime = DateTime.Now;
deviceStatus.UpdatedBy = "equip";
deviceStatus.UpdatedTime = DateTime.Now;
#endregion
#region 设备报警赋值
alarmInfo.PerfusionBoxcode = record.PerfusionBoxCode;
alarmInfo.PerfusionStatus = short.Parse(StringChange.bytesToHexStr(info.Skip(48).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
alarmInfo.PerfusionAlarm = AlarmTrans(alarmInfo.PerfusionStatus);
alarmInfo.PerfusionCompleted = "1";
alarmInfo.CreatedBy = "equip";
alarmInfo.CreatedTime = DateTime.Now;
alarmInfo.UpdatedBy = "equip";
alarmInfo.UpdatedTime = DateTime.Now;
#endregion
}
static string AlarmTrans(short code)
{
string result = "";
switch (code)
{
case 2: result = "充注枪真空不合格"; break;
case 4: result = "充注故障"; break;
case 8: result = "充注时真空度超限定"; break;
case 16: result = "回升检测不合格"; break;
case 32: result = "工件真空不合格"; break;
case 64: result = "平衡缸接近开关异常"; break;
case 128: result = "增压超时"; break;
case 256: result = "风压不足"; break;
}
return result;
}
#region 字符工具转换方法
/// byte[]转十进制ascii码
/// </summary>
/// <param name="bytes"></param>
static string ByteArrayToString(byte[] bytes)
{
string result = string.Empty;
foreach (byte b in bytes)
{
int decimalValue = Convert.ToInt32(b); // 将字节转换为十进制值
result += decimalValue;
}
return result;
}
/// <summary>
/// byte[]转二进制
/// </summary>
/// <param name="bytes"></param>
static string ByteArrayToBinary(byte[] bytes)
{
StringBuilder binaryString = new StringBuilder();
foreach (byte b in bytes)
{
binaryString.Append(Convert.ToString(b, 2).PadLeft(8, '0'));
}
// Console.WriteLine(binaryString);
string reversedStr = new string(binaryString.ToString().Reverse().ToArray());
// Console.WriteLine(reversedStr);
return reversedStr;
}
/// <summary>
/// 根据二进制字符串确定夹具状态 1正常生产 2暂停生产
/// </summary>
static int judgeStatus(string str1)
{
int item1 = 0;
if (str1.Substring(0, 1) == "1")
{
item1 = 1; //
}
else if (str1.Substring(1, 1) == "1")
{
item1 = 2; //
}
return item1;
}
/// <summary>
/// byte数组转换为float
/// </summary>
static float byteToFloat(byte[] list)
{
float result = 0.00f;
Array.Reverse(list);
result = BitConverter.ToSingle(list, 0);
// 只保留两位小数
// string str = result.ToString("0.00");
return result;
}
/// <summary>
/// byte数组转换为double
/// </summary>
static double byteToDouble(byte[] list)
{
double result = 0;
Array.Reverse(list);
result = BitConverter.ToDouble(list, 0);
return result;
}
#endregion
}
}
Loading…
Cancel
Save