Commit 45e4a4b0 by lizefeng

fix

parent 2be956a6
...@@ -831,18 +831,28 @@ namespace AutoTurnOver.Services ...@@ -831,18 +831,28 @@ namespace AutoTurnOver.Services
try try
{ {
var pamsAccount = ApiServices.GetAmazonAccountList().FirstOrDefault(s => s.Id == ana_task.pams_account_id); var pamsAccount = ApiServices.GetAmazonAccountList().FirstOrDefault(s => s.Id == ana_task.pams_account_id);
var filePath = DownloadReportData(pamsAccount, ana_task.report_id); DataTable table = null;
StringBuilder response_str = new StringBuilder() { }; if (!string.IsNullOrWhiteSpace(ana_task.content))
using (StreamReader sr = new StreamReader(filePath.ReportDocumentId))
{ {
response_str.AppendLine(sr.ReadToEnd()); table = CsvFileHelper.StringReadFromCSV(ana_task.content, true, '\t');
sr.Close();
} }
else
{
var filePath = DownloadReportData(pamsAccount, ana_task.report_id);
StringBuilder response_str = new StringBuilder() { };
using (StreamReader sr = new StreamReader(filePath.ReportDocumentId))
{
response_str.AppendLine(sr.ReadToEnd());
sr.Close();
}
string jsonText = response_str.ToString(); string jsonText = response_str.ToString();
ana_task.content = jsonText; ana_task.content = jsonText;
var table = CsvFileHelper.ReadFromCSV(filePath.ReportDocumentId, true, '\t'); table = CsvFileHelper.ReadFromCSV(filePath.ReportDocumentId, true, '\t');
}
foreach (DataRow row in table.Rows) foreach (DataRow row in table.Rows)
{ {
try try
...@@ -855,7 +865,7 @@ namespace AutoTurnOver.Services ...@@ -855,7 +865,7 @@ namespace AutoTurnOver.Services
fee_type = "月度仓储费", fee_type = "月度仓储费",
account = pamsAccount.Account, account = pamsAccount.Account,
asin = row.DataRowToString("asin"), asin = row.DataRowToString("asin"),
report_end_date = filePath.DataEndTime ?? new DateTime(1991, 1, 1) report_end_date = ana_task.etime.Value
}; };
storageFee.fee = row.DataRowToNumber("estimated_monthly_storage_fee") ?? 0; storageFee.fee = row.DataRowToNumber("estimated_monthly_storage_fee") ?? 0;
storageFee._date = DateTime.Parse(row.DataRowToString("month_of_charge")); storageFee._date = DateTime.Parse(row.DataRowToString("month_of_charge"));
......
...@@ -65,6 +65,62 @@ namespace AutoTurnOver.Utility ...@@ -65,6 +65,62 @@ namespace AutoTurnOver.Utility
return dt; return dt;
} }
/// <summary>
/// 将CSV文件中内容读取到DataTable中
/// </summary>
/// <param name="path">CSV文件路径</param>
/// <param name="hasTitle">是否将CSV文件的第一行读取为DataTable的列名</param>
/// <returns></returns>
public static DataTable StringReadFromCSV(string content, bool hasTitle = false,char separator = ',')
{
DataTable dt = new DataTable(); //要输出的数据表
StringReader sr = new StringReader(content); //文件读入流
bool bFirst = true; //指示是否第一次读取数据
//逐行读取
string line;
while ((line = sr.ReadLine()) != null)
{
string[] elements = line.Replace("\"", "").Split(separator);
//第一次读取数据时,要创建数据列
if (bFirst)
{
for (int i = 0; i < elements.Length; i++)
{
dt.Columns.Add();
}
bFirst = false;
}
//有标题行时,第一行当做标题行处理
if (hasTitle)
{
for (int i = 0; i < dt.Columns.Count && i < elements.Length; i++)
{
dt.Columns[i].ColumnName = elements[i];
}
hasTitle = false;
}
else //读取一行数据
{
if (elements.Length == dt.Columns.Count)
{
dt.Rows.Add(elements);
}
else
{
//throw new Exception("CSV格式错误:表格各行列数不一致");
}
}
}
sr.Close();
return dt;
}
/// <summary> /// <summary>
/// 将DataTable中数据写入到CSV文件中 /// 将DataTable中数据写入到CSV文件中
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment