You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

570 lines
21 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using MaterialTraceability.Common;
using MaterialTraceability.Entity.DAO;
using MaterialTraceability.Entity.DTO;
using MaterialTraceability.Entity.UpLoad;
using MaterialTraceability.SqlSugar;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
namespace MaterialTraceability.Business
{
/// <summary>
/// 数据上传逻辑
/// </summary>
public sealed class UpLoadBusiness
{
#region 单例模式
private static readonly Lazy<UpLoadBusiness> lazy = new Lazy<UpLoadBusiness>(() => new UpLoadBusiness());
public static UpLoadBusiness Instance
{
get
{
return lazy.Value;
}
}
private UpLoadBusiness() { }
#endregion
private SqlSugarClient _db = SqlGenerator.GetMySqlInstance();
private AppConfigDto appConfig = AppConfigDto.Instance;
/// <summary>
/// 放卷记录
/// </summary>
/// <param name="upRecord"></param>
public void SaveUpRecord(ProUpRecord upRecord)
{
try
{
UpRecord info = new UpRecord()
{
clientId = upRecord.Id,
machineId = upRecord.MachineId,
resource = appConfig.resource,
positionId = upRecord.PositionId,
rfidStr = upRecord.Rfid,
sfcStr = upRecord.Sfc,
eaValue = upRecord.eaValue,
isProduction = upRecord.IsProduction,
isFinish = upRecord.isFinish,
recordTime = upRecord.RecordTime,
beginTime = upRecord.beginTime,
endTime = upRecord.endTime,
upMaterialId = upRecord.UpMaterialId,
};
LogHelper.Info("上传放卷记录:" + JsonChange.ModeToJson(info));
int result = _db.Insertable<UpRecord>(info).ExecuteCommand();
if (result > 0)
{
LogHelper.Info("放卷记录上传成功");
}
else
{
LogHelper.Info("放卷记录上传失败");
}
}catch(Exception ex)
{
LogHelper.Error("UpRecord数据上传异常", ex);
}
}
/// <summary>
/// 修改上料记录
/// </summary>
/// <param name="upRecord"></param>
public void UpdateUpRecord(ProUpRecord upRecord)
{
try
{
UpRecord info = new UpRecord()
{
clientId = upRecord.Id,
machineId = upRecord.MachineId,
resource = appConfig.resource,
positionId = upRecord.PositionId,
rfidStr = upRecord.Rfid,
sfcStr = upRecord.Sfc,
eaValue = upRecord.eaValue,
isProduction = upRecord.IsProduction,
isFinish = upRecord.isFinish,
recordTime = upRecord.RecordTime,
beginTime = upRecord.beginTime,
endTime = upRecord.endTime,
upMaterialId = upRecord.UpMaterialId,
};
LogHelper.Info("修改放卷记录:" + JsonChange.ModeToJson(info));
int result = _db.Updateable<UpRecord>()
.Where(it => it.clientId == upRecord.Id && it.positionId == upRecord.PositionId && it.resource == appConfig.resource)
.SetColumns(it=>it.rfidStr == upRecord.Rfid)
.SetColumns(it => it.sfcStr == upRecord.Sfc)
.SetColumns(it => it.eaValue == upRecord.eaValue)
.SetColumns(it => it.isProduction == upRecord.IsProduction)
.SetColumns(it => it.isFinish == upRecord.isFinish)
.SetColumns(it => it.recordTime == upRecord.RecordTime)
.SetColumns(it => it.beginTime == upRecord.beginTime)
.SetColumns(it => it.endTime == upRecord.endTime)
.SetColumns(it => it.upMaterialId == upRecord.UpMaterialId)
.ExecuteCommand();
if (result > 0)
{
LogHelper.Info("放卷记录修改成功");
}
else
{
LogHelper.Info("放卷记录修改失败");
}
}
catch (Exception ex)
{
LogHelper.Error("UpdateUpRecord处理异常", ex);
}
}
/// <summary>
/// 收卷记录
/// </summary>
/// <param name="downRecord"></param>
public void SaveDownRecord(ProDownRecord downRecord)
{
try
{
DownRecord info = new DownRecord()
{
clientId = downRecord.Id,
machineId = downRecord.MachineId,
resource = appConfig.resource,
positionId = downRecord.PositionId,
rfidStr = downRecord.Rfid,
sfcStr = downRecord.Sfc,
eaValue = downRecord.eaValue,
isProduction = downRecord.IsProduction,
isFinish = downRecord.isFinish,
recordTime = downRecord.RecordTime,
beginTime = downRecord.beginTime,
endTime = downRecord.endTime,
downMaterialId = downRecord.DownMaterialId,
productUser = ConfigHelper.GetConfig("userName"),
};
LogHelper.Info("上传收卷记录:" + JsonChange.ModeToJson(info));
int result = _db.Insertable<DownRecord>(info).ExecuteCommand();
if (result > 0)
{
LogHelper.Info("收卷记录上传成功");
}
else
{
LogHelper.Info("收卷记录上传失败");
}
}
catch (Exception ex)
{
LogHelper.Error("DownRecord数据上传异常", ex);
}
}
/// <summary>
/// 修改收卷记录
/// </summary>
/// <param name="upRecord"></param>
public void UpdateDownRecord(ProDownRecord downRecord)
{
try
{
DownRecord info = new DownRecord()
{
clientId = downRecord.Id,
machineId = downRecord.MachineId,
resource = appConfig.resource,
positionId = downRecord.PositionId,
rfidStr = downRecord.Rfid,
sfcStr = downRecord.Sfc,
eaValue = downRecord.eaValue,
isProduction = downRecord.IsProduction,
isFinish = downRecord.isFinish,
recordTime = downRecord.RecordTime,
beginTime = downRecord.beginTime,
endTime = downRecord.endTime,
downMaterialId = downRecord.DownMaterialId,
productUser = ConfigHelper.GetConfig("userName"),
};
LogHelper.Info("修改收卷记录:" + JsonChange.ModeToJson(info));
int result = _db.Updateable<DownRecord>()
.Where(it => it.clientId == downRecord.Id && it.positionId == downRecord.PositionId && it.resource == appConfig.resource)
.SetColumns(it => it.rfidStr == downRecord.Rfid)
.SetColumns(it => it.sfcStr == downRecord.Sfc)
.SetColumns(it => it.eaValue == downRecord.eaValue)
.SetColumns(it => it.isProduction == downRecord.IsProduction)
.SetColumns(it => it.isFinish == downRecord.isFinish)
.SetColumns(it => it.recordTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
.SetColumns(it => it.beginTime == downRecord.beginTime)
.SetColumns(it => it.endTime == downRecord.endTime)
.SetColumns(it => it.downMaterialId == downRecord.DownMaterialId)
.ExecuteCommand();
if (result > 0)
{
LogHelper.Info("收卷记录修改成功");
}
else
{
LogHelper.Info("收卷记录修改失败");
}
}
catch (Exception ex)
{
LogHelper.Error("UpdateDownRecord处理异常", ex);
}
}
/// <summary>
/// 模切特征数据上传
/// </summary>
/// <param name="downRecord"></param>
public void SaveMqUpLoad(MqUpLoad mqUpLoad)
{
try
{
LogHelper.Info("上传模切重量特征数据:" + JsonChange.ModeToJson(mqUpLoad));
int result = _db.Insertable<MqUpLoad>(mqUpLoad).ExecuteCommand();
if (result > 0)
{
LogHelper.Info("模切重量特征数据上传成功");
}
else
{
LogHelper.Info("模切重量特征数据上传失败");
}
}
catch (Exception ex)
{
LogHelper.Error("SaveMqUpLoad数据上传异常", ex);
}
}
/// <summary>
/// 模切特征数据修改
/// </summary>
/// <param name="upRecord"></param>
public void UpdateMqUpLoad(MqUpLoad mqUpLoad)
{
try
{
LogHelper.Info("修改模切重量特征数据:" + JsonChange.ModeToJson(mqUpLoad));
int result = _db.Updateable<MqUpLoad>()
.Where(it => it.clientId == mqUpLoad.clientId && it.sfcStr == mqUpLoad.sfcStr)
.SetColumns(it => it.is_success == mqUpLoad.is_success)
.SetColumns(it => it.recordTime == mqUpLoad.recordTime)
.ExecuteCommand();
if (result > 0)
{
LogHelper.Info("模切重量特征数据修改成功");
}
else
{
LogHelper.Info("模切重量特征数据修改失败");
}
}
catch (Exception ex)
{
LogHelper.Error("UpdateMqUpLoad处理异常", ex);
}
}
/// <summary>
/// 冷压重量特征数据上传
/// </summary>
/// <param name="mqUpLoad"></param>
public void SaveLyUpLoad(LyUpLoad lyUpLoad)
{
try
{
LogHelper.Info("上传模切重量特征数据:" + JsonChange.ModeToJson(lyUpLoad));
int result = _db.Insertable<LyUpLoad>(lyUpLoad).ExecuteCommand();
if (result > 0)
{
LogHelper.Info("冷压重量特征数据上传成功");
}
else
{
LogHelper.Info("冷压重量特征数据上传失败");
}
}
catch (Exception ex)
{
LogHelper.Error("SaveLyUpLoad数据上传异常", ex);
}
}
/// <summary>
/// 读取记录
/// </summary>
/// <param name="readRecord"></param>
public void SaveReadRecord(ProReadRecord readRecord)
{
try
{
ReadRecord info = new ReadRecord()
{
machineId = readRecord.MachineID,
resource = appConfig.resource,
equipId = readRecord.EquipID,
positionId = readRecord.PositionID,
ant = readRecord.Ant,
rfidStr = readRecord.ReadEPC,
is_success = StringChange.ParseToInt(readRecord.Result),
recordTime = readRecord.ReadTime
};
LogHelper.Info("上传读取记录:" + JsonChange.ModeToJson(info));
int result = _db.Insertable<ReadRecord>(info).ExecuteCommand();
if (result > 0)
{
LogHelper.Info("读取记录上传成功");
}
else
{
LogHelper.Info("读取记录上传失败");
}
}
catch (Exception ex)
{
LogHelper.Error("ReadRecord数据上传异常", ex);
}
}
/// <summary>
/// 通过Card获取用户登录信息
/// </summary>
/// <param name="card"></param>
/// <returns></returns>
public SysUser GetSysUserInfoByCard(string card)
{
SysUser sysUser = new SysUser();
if (StringExtension.IsNotBlank(card))
{
DataTable info = _db.Queryable<SysUser>().Where(x => x.clientKey == card).ToDataTable();
if (info.Rows.Count > 0)
{
DataRow dataRow = info.Rows[0];
sysUser.id = Convert.ToInt32(dataRow["user_id"]);
sysUser.loginName = dataRow["login_name"].ToString();
sysUser.userName = dataRow["user_name"].ToString();
sysUser.clientKey = dataRow["client_key"].ToString();
sysUser.clientRole = dataRow["client_role"].ToString();
}
}
return sysUser;
}
/// <summary>
/// 判断当前机台是否为190品种190品种上传重量特征数据
/// </summary>
/// <returns></returns>
public bool JudgeResourceIsUplpadData()
{
try
{
DeviceInfo deviceInfo = new DeviceInfo();
string resource = appConfig.resource;
DataTable info = _db.Queryable<DeviceInfo>().Where(x => x.resource == resource).ToDataTable();
if (info.Rows.Count > 0)
{
DataRow dataRow = info.Rows[0];
deviceInfo.deviceId = Convert.ToInt32(dataRow["device_id"]);
deviceInfo.deviceName = dataRow["device_name"].ToString();
deviceInfo.resource = dataRow["resource"].ToString();
deviceInfo.materialType = Convert.ToInt32(dataRow["material_type"]);
deviceInfo.deviceId = Convert.ToInt32(dataRow["parent_id"]);
}
LogHelper.Info(String.Format("{0}设备信息:{1}", resource, JsonChange.ModeToJson(deviceInfo)));
if (deviceInfo.materialType == 1)
{
return false;
}
else
{
return false;
}
}catch(Exception ex)
{
LogHelper.Error("JudgeResourceIsUplpadData异常", ex);
return false;
}
}
/// <summary>
/// 通过设备资源号获取dc数据组
/// </summary>
/// <returns></returns>
public string GerDcGroupByResource()
{
try
{
DeviceInfo deviceInfo = new DeviceInfo();
string resource = appConfig.resource;
DataTable info = _db.Queryable<DeviceInfo>().Where(x => x.resource == resource).ToDataTable();
if (info.Rows.Count > 0)
{
DataRow dataRow = info.Rows[0];
deviceInfo.deviceId = Convert.ToInt32(dataRow["device_id"]);
deviceInfo.deviceName = dataRow["device_name"].ToString();
deviceInfo.resource = dataRow["resource"].ToString();
deviceInfo.materialType = Convert.ToInt32(dataRow["material_type"]);
deviceInfo.parentId = Convert.ToInt32(dataRow["parent_id"]);
}
LogHelper.Info(String.Format("{0}设备信息:{1}", resource, JsonChange.ModeToJson(deviceInfo)));
if (deviceInfo.parentId == 158)
{
return "1ANEFS1SI00089";
}else if(deviceInfo.parentId == 159)
{
return "1CAEFS1SI00089";
}else if (deviceInfo.parentId == 132)
{
return "1ANCAP1SI00089";
}else if (deviceInfo.parentId == 133)
{
return "1CACAP1SI0089";
}
else
{
return "";
}
}
catch (Exception ex)
{
LogHelper.Error("GerDcGroupByResource()异常", ex);
return "";
}
}
/// <summary>
/// 日志记录
/// </summary>
/// <param name="logRecord"></param>
public void SaveLogRecord(int position,string msg)
{
try
{
LogRecord logRecord = new LogRecord()
{
resource = appConfig.resource,
positionId = position,
message = msg
};
int result = _db.Insertable<LogRecord>(logRecord).ExecuteCommand();
}
catch (Exception ex)
{
LogHelper.Error("LogRecord数据上传异常", ex);
}
}
/// <summary>
/// 获取冷压纵向膜区根据L2膜卷号获取拆分数量前三卷为1其余为2
/// </summary>
/// <param name="upMaterialSfc"></param>
/// <returns></returns>
public int GetLengthwaysArea(string upMaterialSfc)
{
LogHelper.Info(String.Format("进入GetLengthwaysArea()函数,获取冷压纵向膜区"));
int splitCount = 0;
// 通过L2在冷压下达的L3膜卷号
DataTable upRecordDataTable = _db.Queryable<UpRecord>().Where(x => x.upMaterialId == upMaterialSfc && x.machineId == 11).ToDataTable();
foreach(DataRow item in upRecordDataTable.Rows)
{
DataTable downRecordDataTable = _db.Queryable<DownRecord>().Where(x => x.sfcStr.Contains(item["sfcStr"].ToString()) && x.machineId == 11).ToDataTable();
splitCount = splitCount + downRecordDataTable.Rows.Count;
}
if(splitCount < 3)
{
return 1;
}
else
{
return 2;
}
}
/// <summary>
/// 通过MES返回编号获取返回信息
/// </summary>
/// <param name="code"></param>
/// <param name="message"></param>
/// <returns></returns>
public string GetMesMessage(int code,string message)
{
try
{
AlarmInfo alarmInfo = new AlarmInfo();
DataTable info = _db.Queryable<AlarmInfo>().Where(x => x.alarmCode == code.ToString()).ToDataTable();
if (info.Rows.Count > 0)
{
DataRow dataRow = info.Rows[0];
//alarmInfo.objId = Convert.ToInt32(dataRow["objId"]);
//alarmInfo.alarmCode = dataRow["alarmCode"].ToString();
//alarmInfo.alarmMessage = dataRow["alarmMessage"].ToString();
//alarmInfo.alarmPropose = dataRow["alarmPropose"].ToString();
//alarmInfo.remark = dataRow["remark"].ToString();
// message = dataRow["alarmMessage"].ToString();
message = dataRow["alarmMessage"].ToString() + "解决建议:" + dataRow["alarmPropose"].ToString();
}
}
catch (Exception ex)
{
LogHelper.Error("GetMesMessage()异常", ex);
}
return message;
}
public void RefreshDeviceTime(object sender, ElapsedEventArgs e)
{
try
{
int result = _db.Updateable<DeviceInfo>()
.Where(it => it.resource == appConfig.resource)
.SetColumns(it => it.statusTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
.ExecuteCommand();
if (result < 1)
{
//LogHelper.Info("设备当前时间失败!!!");
}
}
catch (Exception ex)
{
LogHelper.Error("RefreshDeviceTime处理异常", ex);
}
}
}
}