增加生产数据保存在本地功能
This commit is contained in:
@@ -116,7 +116,32 @@ namespace Cowain.Preheat.Common.Core
|
||||
|
||||
return filePath;
|
||||
}
|
||||
public static void WriteMap<T, TMap>(IEnumerable<T> list, string filePath) where TMap : ClassMap
|
||||
{
|
||||
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
|
||||
{
|
||||
// 设置列头编码为UTF8以支持中文
|
||||
Delimiter = ",",
|
||||
HasHeaderRecord = true,
|
||||
Encoding = System.Text.Encoding.UTF8
|
||||
};
|
||||
|
||||
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
config.HasHeaderRecord = false; // 获取字段描述作为列头
|
||||
}
|
||||
|
||||
using (var writer = new StreamWriter(filePath, true, System.Text.Encoding.UTF8))
|
||||
using (var csv = new CsvWriter(writer, config))
|
||||
{
|
||||
// 注册自定义映射
|
||||
//csv.Context.RegisterClassMap<BatteryInfoMap>();
|
||||
csv.Context.RegisterClassMap<TMap>();
|
||||
// 写入记录
|
||||
csv.WriteRecords(list);
|
||||
}
|
||||
}
|
||||
public static void WriteMap<T, TMap>(IEnumerable<T> list ) where TMap : ClassMap //where TMap : ClassMap<T> // 约束:必须是 ClassMap<T> 或其子类
|
||||
{
|
||||
string filePath = GetFilePath();
|
||||
|
||||
@@ -40,6 +40,7 @@ namespace Cowain.Preheat.Main.Common
|
||||
{
|
||||
List<TBatteryInfo> batteries = new List<TBatteryInfo>();
|
||||
batteries.Add(batteryInfo);
|
||||
_unityContainer.Resolve<UnLoadingStation>().BuildRecordFile(batteries);
|
||||
MESReturnOutputModel mesResult = _unityContainer.Resolve<MESProcess>().CellOutput(batteries, "OK", "", "", new List<MaterialInfoModel>(), true);
|
||||
if (null == mesResult)
|
||||
{
|
||||
|
||||
@@ -51,5 +51,5 @@ using System.Windows;
|
||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
|
||||
//通过使用 "*",如下所示:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.1.5")]
|
||||
[assembly: AssemblyFileVersion("1.0.1.5")]
|
||||
[assembly: AssemblyVersion("1.0.1.6")]
|
||||
[assembly: AssemblyFileVersion("1.0.1.6")]
|
||||
|
||||
@@ -208,12 +208,12 @@ namespace Cowain.Preheat.Main.Station
|
||||
LogHelper.Instance.Error($"重复扫码:-{scanResult.Content},{_queueBatterys.Count}");
|
||||
replyResult = (Int16)EResult.RepeatScann;
|
||||
}
|
||||
else if (!IsCharFlag(scanResult.Content))
|
||||
{
|
||||
msg = "A\\B面扫码异常";
|
||||
LogHelper.Instance.Error($"{msg}:-{scanResult.Content}");
|
||||
replyResult = (Int16)EResult.ErrorAB;
|
||||
}
|
||||
//else if (!IsCharFlag(scanResult.Content))
|
||||
//{
|
||||
// msg = "A\\B扫码异常";
|
||||
// LogHelper.Instance.Error($"{msg}:-{scanResult.Content}");
|
||||
// replyResult = (Int16)EResult.ErrorAB;
|
||||
//}
|
||||
else
|
||||
{
|
||||
////扫码OK入库
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Cowain.Preheat.BLL;
|
||||
using Cowain.Preheat.Common.Core;
|
||||
using Cowain.Preheat.Common.CsvMap;
|
||||
using Cowain.Preheat.Common.Enums;
|
||||
using Cowain.Preheat.Common.Interface;
|
||||
using Cowain.Preheat.Communication.Interface;
|
||||
@@ -26,7 +27,7 @@ namespace Cowain.Preheat.Main.Station
|
||||
public string Name { get; set; }
|
||||
public IUnityContainer _unityContainer { get; set; }
|
||||
IPLCDevice PLC { get; set; }
|
||||
|
||||
public readonly object _lockObj = new object();
|
||||
public List<BtnInfoModel> WindowBtnInfo = new List<BtnInfoModel>();
|
||||
public UnLoadingStation(IUnityContainer unityContainer)
|
||||
{
|
||||
@@ -213,45 +214,7 @@ namespace Cowain.Preheat.Main.Station
|
||||
return $"{(int)(diff.TotalSeconds / 60)}分钟{(int)(diff.TotalSeconds % 60) }秒";
|
||||
}
|
||||
}
|
||||
void BuildRecordFile(List<TBatteryInfo> batteryList)
|
||||
{
|
||||
string dateFile = "";
|
||||
string filePath = "";
|
||||
string path = _unityContainer.Resolve<SysSetupService>().GetValueByParaID(ESysSetup.DataFilePath.ToString());//
|
||||
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
dateFile = DateTime.Now.ToString("yyyyMMdd");
|
||||
filePath = path + $"\\{dateFile}.csv";
|
||||
if (null == batteryList)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
CSVHelper.WriteDataTableToCsv(batteryList, new List<string> { "Id","BatteryCode",
|
||||
"PositionX", "PositionY", "Layer", "ScanTime","LoadingTime", "UnLoadingTime", "LodingTemperature",
|
||||
"PreheatTemperature","UnLoadingTemperature","PreheatTime"}, new List<string>
|
||||
{ "序号", "电芯条码", "行号", "列号", "层号","扫码时间", "上料时间", "下料时间"
|
||||
,"上料温度","预热温度","下料温度","预热时长" }, filePath);
|
||||
|
||||
foreach (var item in batteryList)
|
||||
{
|
||||
if (0 == _unityContainer.Resolve<BatteryInfoService>().UpdateStatus(item.Id, (int)EBatteryStatus.OutBoundRecord))
|
||||
{
|
||||
LogHelper.Instance.Fatal("修改记录出站状态失败!");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Instance.GetCurrentClassFatal($"{ex.Message},{ex.StackTrace}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//public void GetSuccessBattery(ref int[] batteryIds)
|
||||
//{
|
||||
@@ -303,7 +266,7 @@ namespace Cowain.Preheat.Main.Station
|
||||
LogHelper.Instance.Fatal($"出站数据大于11,电芯ID:{string.Join(",", batteryIds)}");
|
||||
}
|
||||
|
||||
//BuildRecordFile(batteryList); //记录出站
|
||||
BuildRecordFile(batteryList); //记录出站
|
||||
|
||||
//真实上传MOM
|
||||
if (int.Parse(_unityContainer.Resolve<SysSetupService>().GetValueByParaID(ESysSetup.MOMEnable.ToString())) == (int)EMOMEnable.Enable)
|
||||
@@ -323,8 +286,50 @@ namespace Cowain.Preheat.Main.Station
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void BuildRecordFile(List<TBatteryInfo> batterys)
|
||||
{
|
||||
string dateFile = "";
|
||||
string filePath = "";
|
||||
string path = _unityContainer.Resolve<SysSetupService>().GetValueByParaID(ESysSetup.DataFilePath.ToString());//
|
||||
if (null == batterys
|
||||
|| batterys.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
dateFile = DateTime.Now.ToString("yyyyMMdd");
|
||||
filePath = path + $"\\{dateFile}.csv";
|
||||
|
||||
try
|
||||
{
|
||||
// CSVHelper.WriteDataTableToCsv(batteryList, new List<string> { "Id","BatteryCode",
|
||||
//"PositionX", "PositionY", "Layer", "ScanTime","LoadingTime", "UnLoadingTime", "LodingTemperature",
|
||||
// "PreheatTemperature","UnLoadingTemperature","PreheatTime"}, new List<string>
|
||||
//{ "序号", "电芯条码", "行号", "列号", "层号","扫码时间", "上料时间", "下料时间"
|
||||
//,"上料温度","预热温度","下料温度","预热时长" }, filePath);
|
||||
|
||||
//foreach (var item in batteryList)
|
||||
//{
|
||||
// if (0 == _unityContainer.Resolve<BatteryInfoService>().UpdateStatus(item.Id, (int)EBatteryStatus.OutBoundRecord))
|
||||
// {
|
||||
// LogHelper.Instance.Fatal("修改记录出站状态失败!");
|
||||
// }
|
||||
//}
|
||||
lock (_lockObj)
|
||||
{
|
||||
CSVHelper.WriteMap<TBatteryInfo, BatteryInfoMap>(batterys, filePath);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Instance.GetCurrentClassFatal($"{ex.Message},{ex.StackTrace}");
|
||||
}
|
||||
}
|
||||
public void Stop()
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user