Merge branch 'master' of http://47.104.102.122:3000/gaofei/HJGL_DS
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -95,6 +95,7 @@
|
||||
<Reference Include="System.DirectoryServices" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Management" />
|
||||
<Reference Include="System.Runtime.Caching" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.ServiceModel" />
|
||||
<Reference Include="System.Web" />
|
||||
@@ -114,7 +115,6 @@
|
||||
<Compile Include="API\APIUnitInfoService.cs" />
|
||||
<Compile Include="API\APIWeldServices.cs" />
|
||||
<Compile Include="AttachFile\AttachFileService.cs" />
|
||||
<Compile Include="CacheHelper.cs" />
|
||||
<Compile Include="Common\ADomainService.cs" />
|
||||
<Compile Include="Common\BaseInfo\AudiFlowService.cs" />
|
||||
<Compile Include="Common\BaseInfo\AuditFlowApproveService.cs.cs" />
|
||||
@@ -125,6 +125,7 @@
|
||||
<Compile Include="Common\BaseInfo\Base_TeamGroupService.cs" />
|
||||
<Compile Include="Common\BaseInfo\Base_UnitService.cs" />
|
||||
<Compile Include="Common\BaseInfo\ProjectPlanService.cs" />
|
||||
<Compile Include="Common\CacheHelper.cs" />
|
||||
<Compile Include="Common\ChartControlService.cs" />
|
||||
<Compile Include="Common\ConstValue.cs" />
|
||||
<Compile Include="Common\FastReportService.cs" />
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Collections;
|
||||
|
||||
public class CacheHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取数据缓存
|
||||
/// </summary>
|
||||
/// <param name="CacheKey">键</param>
|
||||
/// <returns></returns>
|
||||
public static object GetCache(string CacheKey)
|
||||
{
|
||||
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
|
||||
return objCache[CacheKey];
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置数据缓存
|
||||
/// </summary>
|
||||
/// <param name="CacheKey"></param>
|
||||
/// <param name="objObject"></param>
|
||||
public static void SetCache(string CacheKey, object objObject)
|
||||
{
|
||||
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
|
||||
objCache.Insert(CacheKey, objObject);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置数据缓存
|
||||
/// </summary>
|
||||
/// <param name="CacheKey"></param>
|
||||
/// <param name="objObject"></param>
|
||||
/// <param name="Timeout"></param>
|
||||
public static void SetCache(string CacheKey, object objObject, TimeSpan Timeout)
|
||||
{
|
||||
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
|
||||
objCache.Insert(CacheKey, objObject, null, DateTime.MaxValue, Timeout, System.Web.Caching.CacheItemPriority.NotRemovable, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置数据缓存
|
||||
/// </summary>
|
||||
/// <param name="CacheKey"></param>
|
||||
/// <param name="objObject"></param>
|
||||
/// <param name="absoluteExpiration"></param>
|
||||
/// <param name="slidingExpiration"></param>
|
||||
public static void SetCache(string CacheKey, object objObject, DateTime absoluteExpiration, TimeSpan slidingExpiration)
|
||||
{
|
||||
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
|
||||
objCache.Insert(CacheKey, objObject, null, absoluteExpiration, slidingExpiration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除指定数据缓存
|
||||
/// </summary>
|
||||
/// <param name="CacheKey"></param>
|
||||
public static void RemoveAllCache(string CacheKey)
|
||||
{
|
||||
|
||||
System.Web.Caching.Cache _cache = HttpRuntime.Cache;
|
||||
_cache.Remove(CacheKey);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除全部缓存
|
||||
/// </summary>
|
||||
public static void RemoveAllCache()
|
||||
{
|
||||
System.Web.Caching.Cache _cache = HttpRuntime.Cache;
|
||||
IDictionaryEnumerator CacheEnum = _cache.GetEnumerator();
|
||||
while (CacheEnum.MoveNext())
|
||||
{
|
||||
_cache.Remove(CacheEnum.Key.ToString());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓存
|
||||
/// </summary>
|
||||
private static object GetPrivate(string key)
|
||||
{
|
||||
return string.IsNullOrEmpty(key) ? null : HttpRuntime.Cache.Get(key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Runtime.Caching;
|
||||
|
||||
namespace BLL
|
||||
{
|
||||
public static class CacheHelper
|
||||
{
|
||||
private static readonly ObjectCache Cache = MemoryCache.Default;
|
||||
|
||||
/// <summary>
|
||||
/// 添加缓存项
|
||||
/// </summary>
|
||||
/// <param name="key">缓存键</param>
|
||||
/// <param name="value">缓存值</param>
|
||||
/// <param name="absoluteExpiration">绝对过期时间</param>
|
||||
public static void Add(string key, object value, DateTimeOffset absoluteExpiration)
|
||||
{
|
||||
if (string.IsNullOrEmpty(key))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(key));
|
||||
}
|
||||
|
||||
Cache.Set(key, value, absoluteExpiration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓存项(泛型)
|
||||
/// </summary>
|
||||
/// <typeparam name="T">返回类型</typeparam>
|
||||
/// <param name="key">缓存键</param>
|
||||
/// <returns>缓存值</returns>
|
||||
public static T Get<T>(string key)
|
||||
{
|
||||
if (string.IsNullOrEmpty(key))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(key));
|
||||
}
|
||||
|
||||
object value = Cache[key];
|
||||
if (value is T tValue)
|
||||
{
|
||||
return tValue;
|
||||
}
|
||||
return default(T);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓存项
|
||||
/// </summary>
|
||||
/// <param name="key">缓存键</param>
|
||||
/// <returns>缓存值</returns>
|
||||
public static object Get(string key)
|
||||
{
|
||||
if (string.IsNullOrEmpty(key))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(key));
|
||||
}
|
||||
|
||||
return Cache[key];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除缓存项
|
||||
/// </summary>
|
||||
/// <param name="key">缓存键</param>
|
||||
public static void Remove(string key)
|
||||
{
|
||||
if (string.IsNullOrEmpty(key))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(key));
|
||||
}
|
||||
|
||||
Cache.Remove(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空所有缓存
|
||||
/// </summary>
|
||||
public static void Clear()
|
||||
{
|
||||
foreach (var item in Cache)
|
||||
{
|
||||
Cache.Remove(item.Key);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查缓存项是否存在
|
||||
/// </summary>
|
||||
/// <param name="key">缓存键</param>
|
||||
/// <returns>是否存在</returns>
|
||||
public static bool Exists(string key)
|
||||
{
|
||||
if (string.IsNullOrEmpty(key))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(key));
|
||||
}
|
||||
|
||||
return Cache.Contains(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +1,85 @@
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using FastReport;
|
||||
using NPOI.POIFS.Crypt;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Data;
|
||||
using FastReport;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
|
||||
namespace BLL.Common
|
||||
{
|
||||
public static class FastReportService
|
||||
{
|
||||
|
||||
// 缓存过期时间:30分钟
|
||||
private static readonly int CacheExpirationMinutes = 5;
|
||||
|
||||
/// <summary>
|
||||
/// 重置数据
|
||||
/// 重置数据 - 清理缓存和Session
|
||||
/// </summary>
|
||||
public static void ResetData()
|
||||
{
|
||||
HttpContext.Current.Session["ReportDataTables"] = null;
|
||||
HttpContext.Current.Session["ReportParameterValues"] = null;
|
||||
if (HttpContext.Current?.Session == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 清理Session中的缓存键引用
|
||||
var cacheKeys = HttpContext.Current.Session["ReportDataCacheKeys"] as List<string>;
|
||||
if (cacheKeys != null)
|
||||
{
|
||||
foreach (var key in cacheKeys)
|
||||
{
|
||||
try
|
||||
{
|
||||
CacheHelper.Remove(key);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 忽略缓存删除异常
|
||||
}
|
||||
}
|
||||
}
|
||||
HttpContext.Current.Session["ReportDataCacheKeys"] = null;
|
||||
HttpContext.Current.Session["ReportParameterCacheKey"] = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加报表数据表到缓存
|
||||
/// </summary>
|
||||
public static void AddFastreportTable(DataTable dataTable)
|
||||
{
|
||||
List<DataTable> dataTables = (List<DataTable>)HttpContext.Current.Session["ReportDataTables"];
|
||||
if (dataTables == null)
|
||||
|
||||
// 生成唯一缓存键
|
||||
string cacheKey = $"ReportData_{Guid.NewGuid()}_{DateTime.Now.Ticks}";
|
||||
|
||||
// 将数据表存储到缓存中,设置5分钟过期
|
||||
CacheHelper.Add(cacheKey, dataTable, DateTimeOffset.Now.AddMinutes(CacheExpirationMinutes));
|
||||
|
||||
List<string> cacheKeys = HttpContext.Current.Session["ReportDataCacheKeys"] as List<string>;
|
||||
if (cacheKeys==null)
|
||||
{
|
||||
dataTables = new List<DataTable>();
|
||||
cacheKeys = new List<string>();
|
||||
}
|
||||
dataTables.Add(dataTable);
|
||||
|
||||
HttpContext.Current.Session["ReportDataTables"] = dataTables;
|
||||
cacheKeys.Add(cacheKey);
|
||||
HttpContext.Current.Session["ReportDataCacheKeys"] = cacheKeys;
|
||||
}
|
||||
public static void AddFastreportParameter(Dictionary<string, string> Dicparames)
|
||||
{
|
||||
HttpContext.Current.Session["ReportParameterValues"] = Dicparames;
|
||||
|
||||
/// <summary>
|
||||
/// 添加报表参数到缓存
|
||||
/// </summary>
|
||||
public static void AddFastreportParameter(Dictionary<string, string> Dicparames)
|
||||
{
|
||||
// 生成唯一缓存键
|
||||
string cacheKey = $"ReportParam_{Guid.NewGuid()}_{DateTime.Now.Ticks}";
|
||||
|
||||
// 将参数存储到缓存中,设置5分钟过期
|
||||
CacheHelper.Add(cacheKey, Dicparames, DateTimeOffset.Now.AddMinutes(CacheExpirationMinutes));
|
||||
|
||||
// Session只存储缓存键的引用(轻量级)
|
||||
HttpContext.Current.Session["ReportParameterCacheKey"] = cacheKey;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -82,16 +127,8 @@ namespace BLL.Common
|
||||
|
||||
}
|
||||
}
|
||||
if (printType == "1")
|
||||
{
|
||||
FastReport.Export.Pdf.PDFExport exp = new FastReport.Export.Pdf.PDFExport();
|
||||
report.Export(exp, path);
|
||||
}
|
||||
else if (printType == "2")
|
||||
{
|
||||
FastReport.Export.OoXML.Word2007Export exportBase = new FastReport.Export.OoXML.Word2007Export();
|
||||
report.Export(export: exportBase, fileName: path.Replace(oldValue: "pdf", newValue: "docx"));
|
||||
}
|
||||
FastReport.Export.Pdf.PDFExport exp = new FastReport.Export.Pdf.PDFExport();
|
||||
report.Export(exp, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0"/>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/></startup></configuration>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /></startup></configuration>
|
||||
|
||||
@@ -4,4 +4,5 @@
|
||||
<package id="NPOI" version="2.5.5" targetFramework="net461" />
|
||||
<package id="Portable.BouncyCastle" version="1.8.9" targetFramework="net461" />
|
||||
<package id="SharpZipLib" version="1.3.2" targetFramework="net461" />
|
||||
<package id="System.Runtime.Caching" version="4.7.0" targetFramework="net461" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user