2019-05-09 13:16:14 +08:00
|
|
|
|
using Bootstrap.Security;
|
2018-10-28 15:03:59 +08:00
|
|
|
|
using Longbow.Cache;
|
2018-10-19 23:09:52 +08:00
|
|
|
|
using Longbow.Data;
|
2019-04-08 16:01:40 +08:00
|
|
|
|
using Longbow.Web;
|
|
|
|
|
using System;
|
2018-10-19 23:09:52 +08:00
|
|
|
|
using System.Collections.Generic;
|
2019-03-26 17:12:18 +08:00
|
|
|
|
using System.Linq;
|
2018-10-19 23:09:52 +08:00
|
|
|
|
|
|
|
|
|
namespace Bootstrap.DataAccess
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class DictHelper
|
|
|
|
|
{
|
2018-10-28 15:42:06 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 缓存索引,BootstrapAdmin后台清理缓存时使用
|
|
|
|
|
/// </summary>
|
|
|
|
|
public const string RetrieveDictsDataKey = "BootstrapDict-RetrieveDicts";
|
2019-01-11 23:20:28 +08:00
|
|
|
|
|
2018-10-28 15:42:06 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
2018-10-28 15:03:59 +08:00
|
|
|
|
public const string RetrieveCategoryDataKey = "DictHelper-RetrieveDictsCategory";
|
2019-01-11 23:20:28 +08:00
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2019-01-11 23:20:28 +08:00
|
|
|
|
public static IEnumerable<BootstrapDict> RetrieveDicts() => CacheManager.GetOrAdd(RetrieveDictsDataKey, key => DbContextManager.Create<Dict>().RetrieveDicts());
|
|
|
|
|
|
2019-05-09 13:16:14 +08:00
|
|
|
|
private static IEnumerable<BootstrapDict> RetrieveProtectedDicts() => RetrieveDicts().Where(d => d.Define == 0 || d.Category == "测试平台");
|
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除字典中的数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value">需要删除的IDs</param>
|
|
|
|
|
/// <returns></returns>
|
2019-01-11 23:20:28 +08:00
|
|
|
|
public static bool Delete(IEnumerable<string> value)
|
2018-10-30 23:01:36 +08:00
|
|
|
|
{
|
2019-03-26 17:12:18 +08:00
|
|
|
|
if (RetrieveSystemModel())
|
|
|
|
|
{
|
2019-05-09 13:16:14 +08:00
|
|
|
|
// 禁止删除系统数据与测试平台数据
|
|
|
|
|
var systemDicts = RetrieveProtectedDicts();
|
2019-03-26 17:12:18 +08:00
|
|
|
|
value = value.Where(v => !systemDicts.Any(d => d.Id == v));
|
|
|
|
|
if (!value.Any()) return true;
|
|
|
|
|
}
|
2019-05-18 16:15:44 +08:00
|
|
|
|
if (!value.Any()) return true;
|
2019-01-11 23:20:28 +08:00
|
|
|
|
var ret = DbContextManager.Create<Dict>().Delete(value);
|
2018-10-30 23:01:36 +08:00
|
|
|
|
CacheCleanUtility.ClearCache(dictIds: value);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2019-01-11 23:20:28 +08:00
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存新建/更新的字典信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="p"></param>
|
|
|
|
|
/// <returns></returns>
|
2019-01-11 23:20:28 +08:00
|
|
|
|
public static bool Save(BootstrapDict p)
|
2018-10-30 23:01:36 +08:00
|
|
|
|
{
|
2019-05-09 13:16:14 +08:00
|
|
|
|
if (RetrieveSystemModel() && RetrieveProtectedDicts().Any(m => m.Id == p.Id)) return true;
|
|
|
|
|
|
2019-01-11 23:20:28 +08:00
|
|
|
|
var ret = DbContextManager.Create<Dict>().Save(p);
|
2019-02-01 14:09:13 +08:00
|
|
|
|
if (ret) CacheCleanUtility.ClearCache(dictIds: new List<string>());
|
2018-10-30 23:01:36 +08:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
2019-01-11 23:20:28 +08:00
|
|
|
|
|
2019-04-08 16:01:40 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="op"></param>
|
|
|
|
|
public static void ConfigIPLocator(IPLocatorOption op)
|
|
|
|
|
{
|
|
|
|
|
var name = RetrieveLocaleIPSvr();
|
|
|
|
|
if (!string.IsNullOrEmpty(name) && !name.Equals("None", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
var url = RetrieveLocaleIPSvrUrl(name);
|
|
|
|
|
op.Locator = string.IsNullOrEmpty(url) ? null : DefaultIPLocatorProvider.CreateLocator(name);
|
|
|
|
|
op.Url = string.IsNullOrEmpty(url) ? string.Empty : $"{url}{op.IP}";
|
2019-05-17 16:14:20 +08:00
|
|
|
|
if (int.TryParse(RetrieveLocaleIPSvrCachePeriod(), out var period) && period > 0) op.Period = period * 60 * 1000;
|
2019-04-08 16:01:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存网站个性化设置
|
|
|
|
|
/// </summary>
|
2019-03-22 15:46:32 +08:00
|
|
|
|
/// <param name="dict"></param>
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <returns></returns>
|
2018-10-30 23:01:36 +08:00
|
|
|
|
public static bool SaveSettings(BootstrapDict dict)
|
|
|
|
|
{
|
2019-01-11 23:20:28 +08:00
|
|
|
|
var ret = DbContextManager.Create<Dict>().SaveSettings(dict);
|
2018-10-30 23:01:36 +08:00
|
|
|
|
if (ret) CacheCleanUtility.ClearCache(dictIds: new List<string>());
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2019-01-11 23:20:28 +08:00
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取字典分类名称
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2019-01-11 23:20:28 +08:00
|
|
|
|
public static IEnumerable<string> RetrieveCategories() => CacheManager.GetOrAdd(RetrieveCategoryDataKey, key => DbContextManager.Create<Dict>().RetrieveCategories());
|
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2019-01-11 23:20:28 +08:00
|
|
|
|
public static string RetrieveWebTitle() => DbContextManager.Create<Dict>().RetrieveWebTitle();
|
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2019-01-11 23:20:28 +08:00
|
|
|
|
public static string RetrieveWebFooter() => DbContextManager.Create<Dict>().RetrieveWebFooter();
|
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获得系统中配置的可以使用的网站样式
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2019-01-11 23:20:28 +08:00
|
|
|
|
public static IEnumerable<BootstrapDict> RetrieveThemes() => DbContextManager.Create<Dict>().RetrieveThemes();
|
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获得网站设置中的当前样式
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2019-01-11 23:20:28 +08:00
|
|
|
|
public static string RetrieveActiveTheme() => DbContextManager.Create<Dict>().RetrieveActiveTheme();
|
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取头像路径
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2019-01-11 23:20:28 +08:00
|
|
|
|
public static string RetrieveIconFolderPath() => DbContextManager.Create<Dict>().RetrieveIconFolderPath();
|
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获得默认的前台首页地址,默认为~/Home/Index
|
|
|
|
|
/// </summary>
|
2019-02-27 16:48:19 +08:00
|
|
|
|
/// <param name="appCode">应用程序编码</param>
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <returns></returns>
|
2019-02-27 16:48:19 +08:00
|
|
|
|
public static string RetrieveHomeUrl(string appCode) => DbContextManager.Create<Dict>().RetrieveHomeUrl(appCode);
|
2019-01-11 23:20:28 +08:00
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2019-01-11 23:20:28 +08:00
|
|
|
|
public static IEnumerable<KeyValuePair<string, string>> RetrieveApps() => DbContextManager.Create<Dict>().RetrieveApps();
|
2019-03-08 15:33:00 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-03-18 17:49:28 +08:00
|
|
|
|
/// 程序异常时长 默认1月
|
2019-03-08 15:33:00 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static int RetrieveExceptionsLogPeriod() => DbContextManager.Create<Dict>().RetrieveExceptionsLogPeriod();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static int RetrieveLogsPeriod() => DbContextManager.Create<Dict>().RetrieveLogsPeriod();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static int RetrieveLoginLogsPeriod() => DbContextManager.Create<Dict>().RetrieveLoginLogsPeriod();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static int RetrieveCookieExpiresPeriod() => DbContextManager.Create<Dict>().RetrieveCookieExpiresPeriod();
|
2019-03-08 16:21:31 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2019-03-29 18:18:56 +08:00
|
|
|
|
public static string RetrieveLocaleIPSvr() => DbContextManager.Create<Dict>().RetrieveLocaleIPSvr();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
2019-05-17 15:57:46 +08:00
|
|
|
|
/// <param name="ipSvr">ip地址请求服务名称</param>
|
2019-03-29 18:18:56 +08:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static string RetrieveLocaleIPSvrUrl(string ipSvr) => DbContextManager.Create<Dict>().RetrieveLocaleIPSvrUrl(ipSvr);
|
2019-03-18 17:26:12 +08:00
|
|
|
|
|
2019-05-17 15:57:46 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static string RetrieveLocaleIPSvrCachePeriod() => DbContextManager.Create<Dict>().RetrieveLocaleIPSvrCachePeriod();
|
|
|
|
|
|
2019-03-18 17:26:12 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 访问日志保留时长 默认一个月
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static int RetrieveAccessLogPeriod() => DbContextManager.Create<Dict>().RetrieveAccessLogPeriod();
|
2019-03-26 17:12:18 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获得 是否为演示系统 默认为 false 不是演示系统
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool RetrieveSystemModel() => DbContextManager.Create<Dict>().RetrieveSystemModel();
|
2019-04-13 16:01:06 +08:00
|
|
|
|
|
2019-05-01 16:46:24 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获得验证码图床地址
|
|
|
|
|
/// </summary>
|
2019-04-13 16:01:06 +08:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static string RetrieveImagesLibUrl() => DbContextManager.Create<Dict>().RetrieveImagesLibUrl();
|
2018-10-19 23:09:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|