260520 优化历史已解析入库但没有分发成功的问题

新到文件是否仍然正常出现 匹配成功 -> 待解析区 -> 解析成功 -> 正式区 -> 双侧完成 -> 客户报告生成。
历史遗留文件是否出现 已补充分发到正式区 这类新日志,并从源目录消失。
已经真正分发完成的文件,是否仍然保持 已处理且目标区域已存在,跳过,没有重复搬运。
This commit is contained in:
zhengxuan.zhang
2026-05-20 16:06:37 +08:00
parent 4d5449f186
commit 08e623410f
8 changed files with 95 additions and 35 deletions
+4 -4
View File
@@ -79,7 +79,7 @@ namespace NSAnalysis
return;
}
// 对于分发配置,strReadType 进行转换 ,文件内容 对应1 文件名称对应2
// 对于分发配置,strReadType 进行转换,文件内容对应1文件名称对应2
if (string.IsNullOrEmpty(strReadType) || (strReadType != "文件内容" && strReadType != "文件名称"))
{
MessageBox.Show("请选择正确的读取类型! ", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
@@ -107,11 +107,11 @@ namespace NSAnalysis
//数据转换
if (strPosition.Equals("左侧"))
{
strPosition = "R"; // 左侧
strPosition = "L";
}
else if (strPosition.Equals("右侧"))
{
strPosition = "L"; // 右侧
strPosition = "R";
}
if (strStatus.Equals("启动"))
@@ -199,4 +199,4 @@ namespace NSAnalysis
}
}
}
}
}
+3 -3
View File
@@ -199,8 +199,8 @@ namespace NSAnalysis
{
switch (e.Value.ToString())
{
case "1": e.Value = "文件名称"; break;
case "2": e.Value = "文件内容"; break;
case "1": e.Value = "文件内容"; break;
case "2": e.Value = "文件名称"; break;
}
}
@@ -217,4 +217,4 @@ namespace NSAnalysis
}
}
}
}
}
+6 -6
View File
@@ -49,7 +49,7 @@ namespace NSAnalysis
string strReadTyple = gFTS.dgvTolList.Rows[gFTS.idgvSelectRowNumber].Cells["readType"].Value.ToString();
if (strReadTyple.Equals("1"))
if (strReadTyple.Equals("1") || strReadTyple.Equals("2"))
{
rddl_ReadType.Text = "文件内容";
}
@@ -120,7 +120,7 @@ namespace NSAnalysis
return;
}
// 对于分发配置,strReadType 进行转换 ,文件内容 对应1 文件名称对应2
// 对于分发配置,strReadType 进行转换,文件内容对应1文件名称对应2
if (string.IsNullOrEmpty(strReadType) || (strReadType != "文件内容" && strReadType != "文件名称"))
{
MessageBox.Show("请选择正确的读取类型! ", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
@@ -129,11 +129,11 @@ namespace NSAnalysis
if (strReadType.Equals("文件名称"))
{
strReadType = "1"; // 文件名称
strReadType = "2";
}
else if (strReadType.Equals("文件内容"))
{
strReadType = "2"; // 文件内容
strReadType = "1";
}
#endregion
@@ -151,7 +151,7 @@ namespace NSAnalysis
Status = strStatus.Equals("启动") ? "start" : "stop",
CreateDate = DateTime.Now,
IsDelete = 1, //未删除
ReadType = strReadType.Equals("文件内容") ? 2 : 1 // 文件内容对应1,文件名称对应2
ReadType = int.Parse(strReadType)
};
tmdal.UpdateTaskRelease(cjlrTaskRelease);
@@ -212,4 +212,4 @@ namespace NSAnalysis
}
}
}
}
}
+78 -18
View File
@@ -35,6 +35,13 @@ namespace NSAnalysis
public string MatchToken { get; set; }
}
private sealed class StagingPaths
{
public string FinalDir { get; set; }
public string PendingDir { get; set; }
public string ErrorDir { get; set; }
}
public CjlrDAL _dal = new CjlrDAL();
//定义读取的位置
@@ -136,13 +143,6 @@ namespace NSAnalysis
return;
}
if (_dal.IsFileProcessed(file))
{
Trace($"文件已处理过,跳过后续匹配和解析: {file}");
emitProcessStep($"---> 2、文件已处理过,跳过后续匹配和解析: {file}");
continue;
}
string rawMatchValue;
string normalizedMatchValue;
if (!TryReadMatchToken(file, readRowIndex, readColIndex, out rawMatchValue, out normalizedMatchValue))
@@ -169,16 +169,54 @@ namespace NSAnalysis
continue;
}
EnsureTargetDirectory(matchedRule.TargetDir);
Trace($"匹配成功,准备移动文件: {file} -> {matchedRule.TargetDir},原始特征符: {rawMatchValue},标准化后: {normalizedMatchValue}");
StagingPaths staging = EnsureStagingDirectories(matchedRule.TargetDir);
string destFile = MoveMatchedFile(file, matchedRule.TargetDir);
Trace($"移动完成,: {file} -> {destFile}");
emitProcessStep($"---> 5、文件移动完成: -> {destFile}");
if (_dal.IsFileProcessed(file))
{
if (IsFileAlreadyInTargetArea(file, staging))
{
Trace($"文件已处理且目标区域已存在,跳过后续匹配和解析: {file}");
emitProcessStep($"---> 2、文件已处理且目标区域已存在,跳过: {file}");
continue;
}
InsertTaskDetail(matchedRule, file, destFile, 1, "文件移动成功");
string finalFile = MoveMatchedFile(file, staging.FinalDir);
Trace($"文件已有历史解析记录,但仍停留在源目录,已补充分发到正式区: {file} -> {finalFile}");
emitProcessStep($"---> 5、检测到历史已解析未分发文件,已补充分发: -> {finalFile}");
InsertTaskDetail(matchedRule, file, finalFile, 1, "历史已解析文件补充分发到正式区");
continue;
}
AnalysisNxsCSV(destFile);
Trace($"匹配成功,准备移入待解析区: {file} -> {staging.PendingDir},原始特征符: {rawMatchValue},标准化后: {normalizedMatchValue}");
string pendingFile = MoveMatchedFile(file, staging.PendingDir);
Trace($"已移入待解析区: {file} -> {pendingFile}");
emitProcessStep($"---> 5、文件已移入待解析区: -> {pendingFile}");
InsertTaskDetail(matchedRule, file, pendingFile, 1, "文件已移入待解析区");
CsvParseResult parseResult = AnalysisNxsCSV(pendingFile);
if (parseResult.Success)
{
string finalFile = MoveMatchedFile(pendingFile, staging.FinalDir);
Trace($"解析成功,已转入正式区: {pendingFile} -> {finalFile}");
emitProcessStep($"---> 6、解析成功,已转入正式区: -> {finalFile}");
InsertTaskDetail(matchedRule, pendingFile, finalFile, 1, "解析成功并转入正式区");
}
else
{
if (File.Exists(pendingFile))
{
string errorFile = MoveMatchedFile(pendingFile, staging.ErrorDir);
Trace($"解析失败,已转入错误区: {pendingFile} -> {errorFile}");
emitProcessStep($"---> 6、解析失败,已转入错误区: -> {errorFile}");
InsertTaskDetail(matchedRule, pendingFile, errorFile, 2, "解析失败并转入错误区");
}
else
{
Trace($"解析失败后文件已不存在,无法转入错误区: {pendingFile}");
emitProcessStep($"---> 6、解析失败后文件已不存在,无法转入错误区: {pendingFile}");
}
}
}
}
@@ -278,15 +316,37 @@ namespace NSAnalysis
return side == 'L' || side == 'R';
}
private static void EnsureTargetDirectory(string targetDir)
private static StagingPaths EnsureStagingDirectories(string targetDir)
{
if (!Directory.Exists(targetDir))
var paths = new StagingPaths
{
Directory.CreateDirectory(targetDir);
MyBase.TraceWriteLine($"创建目标文件夹: {targetDir}");
FinalDir = targetDir,
PendingDir = Path.Combine(targetDir, "_pending"),
ErrorDir = Path.Combine(targetDir, "_error")
};
EnsureDirectory(paths.FinalDir);
EnsureDirectory(paths.PendingDir);
EnsureDirectory(paths.ErrorDir);
return paths;
}
private static void EnsureDirectory(string dir)
{
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
MyBase.TraceWriteLine($"创建目标文件夹: {dir}");
}
}
private static bool IsFileAlreadyInTargetArea(string sourceFile, StagingPaths staging)
{
string fileName = Path.GetFileName(sourceFile);
return File.Exists(Path.Combine(staging.FinalDir, fileName))
|| File.Exists(Path.Combine(staging.PendingDir, fileName))
|| File.Exists(Path.Combine(staging.ErrorDir, fileName));
}
private static string MoveMatchedFile(string sourceFile, string targetDir)
{
string destFile = Path.Combine(targetDir, Path.GetFileName(sourceFile));
+2 -2
View File
@@ -48,7 +48,7 @@ namespace NSAnalysis.DAL
sourceFile, targetFile, status, create_date,
readType
FROM CJLR.dbo.CJLR_TASK_RELEASE
WHERE is_delete = 1 AND readType = 1 "); // 默认只查询未删除记录
WHERE is_delete = 1 "); // 默认只查询未删除记录,避免历史 readType 数据导致任务被遗漏
List<SqlParameter> paras = new List<SqlParameter>();
@@ -630,4 +630,4 @@ NULLIF(
#endregion
}
}
}
+2 -2
View File
@@ -25,8 +25,8 @@ using System.Runtime.InteropServices;
//
// You can specify all the values or you can default the Build and Revision Numbers by using the '*'
// as shown below: [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2025.09.01.2")]
[assembly: AssemblyFileVersion("2025.09.01.2")]
[assembly: AssemblyVersion("2026.05.20.2")]
[assembly: AssemblyFileVersion("2026.05.20.2")]
//奇瑞总装软件
//2024.09.27.1 该版本增加读取编码器数值功能
//2024.10.08.1 该版本修改了EHY和EH3的测点图片 以及增加了上传IOT时,在1.5倍公差内,都是OK的结果,传给IOT
Binary file not shown.
Binary file not shown.