260520 优化历史已解析入库但没有分发成功的问题
新到文件是否仍然正常出现 匹配成功 -> 待解析区 -> 解析成功 -> 正式区 -> 双侧完成 -> 客户报告生成。 历史遗留文件是否出现 已补充分发到正式区 这类新日志,并从源目录消失。 已经真正分发完成的文件,是否仍然保持 已处理且目标区域已存在,跳过,没有重复搬运。
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user