微调

parent 241f5a3f
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.Infrastructure
{
public static partial class UtilExtensions
{
/// <summary>
/// 时间戳计时开始时间
/// </summary>
private static DateTime timeStampStartTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
/// <summary>
/// DateTime转换为10位时间戳(单位:秒)
/// </summary>
/// <param name="dateTime"></param>
/// <returns></returns>
public static long ToTimeStamp(this DateTime dateTime)
{
return (long)(dateTime.ToUniversalTime() - timeStampStartTime).TotalSeconds;
}
/// <summary>
/// DateTime转换为13位时间戳(单位:毫秒)
/// </summary>
/// <param name="dateTime"> DateTime</param>
/// <returns>13位时间戳(单位:毫秒)</returns>
public static long ToLongTimeStamp(this DateTime dateTime)
{
return (long)(dateTime.ToUniversalTime() - timeStampStartTime).TotalMilliseconds;
}
/// <summary>
/// 10位时间戳(单位:秒)转换为DateTime
/// </summary>
/// <param name="timeStamp">10位时间戳(单位:秒)</param>
/// <returns>DateTime</returns>
public static DateTime ToDateTime(this long timeStamp)
{
return timeStampStartTime.AddSeconds(timeStamp).ToLocalTime();
}
/// <summary>
/// 13位时间戳(单位:毫秒)转换为DateTime
/// </summary>
/// <param name="longTimeStamp">13位时间戳(单位:毫秒)</param>
/// <returns>DateTime</returns>
public static DateTime ToDateTimeLongTimeStamp(this long longTimeStamp)
{
return timeStampStartTime.AddMilliseconds(longTimeStamp).ToLocalTime();
}
}
}
...@@ -26,6 +26,7 @@ public class OperationRecord ...@@ -26,6 +26,7 @@ public class OperationRecord
public class EpChanage public class EpChanage
{ {
public string SheetName { get; set; } public string SheetName { get; set; }
public string Version { get; set; }
public OperationRecord[] OperationRecord { get; set; } public OperationRecord[] OperationRecord { get; set; }
public List<dynamic> Data { get; set; } public List<dynamic> Data { get; set; }
} }
......
namespace Performance.Services.OnlineExcel
{
public partial class OnlineExcelService
{
public class ExcelSheetInfo
{
public string Name { get; set; }
public int Row { get; set; }
public int Column { get; set; }
public string Version { get; set; }
public string Message
{
get
{
if (Row * Column > 500 * 50)
return "数据量很大,加载需要较长时间";
else if (Row * Column > 100 * 50)
return "数据较多,可能需要较长加载时间";
return "";
}
}
}
}
}
\ No newline at end of file
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using OfficeOpenXml; using OfficeOpenXml;
using OfficeOpenXml.Style; using OfficeOpenXml.Style;
using Performance.DtoModels;
using Performance.EntityModels; using Performance.EntityModels;
using Performance.Infrastructure;
using Polly; using Polly;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
...@@ -38,24 +40,6 @@ public OnlineExcelService(IMemoryCache cache) ...@@ -38,24 +40,6 @@ public OnlineExcelService(IMemoryCache cache)
{ {
_cache = cache; _cache = cache;
} }
public class ExcelSheetInfo
{
public string Name { get; set; }
public int Row { get; set; }
public int Column { get; set; }
public string Message
{
get
{
if (Row * Column > 500 * 50)
return "数据量很大,加载需要较长时间";
else if (Row * Column > 100 * 50)
return "数据较多,可能需要较长加载时间";
return "";
}
}
}
/// <summary> /// <summary>
/// 读取Sheet名称 /// 读取Sheet名称
/// </summary> /// </summary>
...@@ -70,6 +54,9 @@ public List<ExcelSheetInfo> GetExcelSheetName(per_allot allot) ...@@ -70,6 +54,9 @@ public List<ExcelSheetInfo> GetExcelSheetName(per_allot allot)
sheetNames = sheetNames ?? new List<ExcelSheetInfo>(); sheetNames = sheetNames ?? new List<ExcelSheetInfo>();
FileInfo file = new FileInfo(allot.Path); FileInfo file = new FileInfo(allot.Path);
var version = file.LastWriteTimeUtc.ToTimeStamp();
using (ExcelPackage package = new ExcelPackage(file)) using (ExcelPackage package = new ExcelPackage(file))
{ {
foreach (var sheet in package.Workbook.Worksheets) foreach (var sheet in package.Workbook.Worksheets)
...@@ -79,6 +66,7 @@ public List<ExcelSheetInfo> GetExcelSheetName(per_allot allot) ...@@ -79,6 +66,7 @@ public List<ExcelSheetInfo> GetExcelSheetName(per_allot allot)
Name = sheet.Name, Name = sheet.Name,
Row = sheet.Dimension.End.Row, Row = sheet.Dimension.End.Row,
Column = sheet.Dimension.End.Column, Column = sheet.Dimension.End.Column,
Version = version.ToString(),
}); });
} }
} }
...@@ -100,6 +88,7 @@ public EpSheet ReadSheet(per_allot allot, string sheetName) ...@@ -100,6 +88,7 @@ public EpSheet ReadSheet(per_allot allot, string sheetName)
return cacheSheet; return cacheSheet;
FileInfo file = new FileInfo(allot.Path); FileInfo file = new FileInfo(allot.Path);
using (ExcelPackage package = new ExcelPackage(file)) using (ExcelPackage package = new ExcelPackage(file))
{ {
foreach (var sheet in package.Workbook.Worksheets) foreach (var sheet in package.Workbook.Worksheets)
......
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OfficeOpenXml; using OfficeOpenXml;
using Performance.DtoModels;
using Performance.EntityModels; using Performance.EntityModels;
using Performance.Infrastructure;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
...@@ -36,6 +37,9 @@ public void WriteSheet(per_allot allot, EpChanage chanage) ...@@ -36,6 +37,9 @@ public void WriteSheet(per_allot allot, EpChanage chanage)
{ {
FileInfo file = new FileInfo(allot.Path); FileInfo file = new FileInfo(allot.Path);
if (file.LastWriteTimeUtc.ToTimeStamp().ToString() != chanage.Version)
throw new PerformanceException("您读取的文件已被其他人更改");
using (ExcelPackage package = new ExcelPackage(file)) using (ExcelPackage package = new ExcelPackage(file))
{ {
foreach (var sheet in package.Workbook.Worksheets) foreach (var sheet in package.Workbook.Worksheets)
......
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