2019-03-06 15:28:30 +08:00
|
|
|
|
using Bootstrap.Security;
|
2018-10-28 23:35:23 +08:00
|
|
|
|
using Bootstrap.Security.DataAccess;
|
2019-03-08 15:33:00 +08:00
|
|
|
|
using Longbow;
|
2018-10-19 23:09:52 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2018-10-21 10:02:59 +08:00
|
|
|
|
using System.Linq;
|
2018-10-19 23:09:52 +08:00
|
|
|
|
|
|
|
|
|
namespace Bootstrap.DataAccess
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class Dict : BootstrapDict
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除字典中的数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value">需要删除的IDs</param>
|
|
|
|
|
/// <returns></returns>
|
2019-01-11 23:20:28 +08:00
|
|
|
|
public virtual bool Delete(IEnumerable<string> value)
|
2018-10-21 10:02:59 +08:00
|
|
|
|
{
|
2019-01-16 16:36:44 +08:00
|
|
|
|
if (!value.Any()) return true;
|
2018-10-21 10:02:59 +08:00
|
|
|
|
var ids = string.Join(",", value);
|
2019-01-11 23:20:28 +08:00
|
|
|
|
string sql = $"where ID in ({ids})";
|
2019-01-14 12:33:09 +08:00
|
|
|
|
DbManager.Create().Delete<BootstrapDict>(sql);
|
2019-01-11 23:20:28 +08:00
|
|
|
|
return true;
|
2018-10-21 10:02:59 +08:00
|
|
|
|
}
|
2019-01-11 23:20:28 +08:00
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存新建/更新的字典信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dict"></param>
|
|
|
|
|
/// <returns></returns>
|
2019-01-11 23:20:28 +08:00
|
|
|
|
public virtual bool Save(BootstrapDict dict)
|
2018-10-21 10:02:59 +08:00
|
|
|
|
{
|
|
|
|
|
if (dict.Category.Length > 50) dict.Category = dict.Category.Substring(0, 50);
|
|
|
|
|
if (dict.Name.Length > 50) dict.Name = dict.Name.Substring(0, 50);
|
|
|
|
|
if (dict.Code.Length > 50) dict.Code = dict.Code.Substring(0, 50);
|
2019-01-11 23:20:28 +08:00
|
|
|
|
|
2019-01-14 12:33:09 +08:00
|
|
|
|
DbManager.Create().Save(dict);
|
2019-01-11 23:20:28 +08:00
|
|
|
|
return true;
|
2018-10-21 10:02:59 +08:00
|
|
|
|
}
|
2019-01-11 23:20:28 +08:00
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存网站个性化设置
|
|
|
|
|
/// </summary>
|
2019-03-06 15:28:30 +08:00
|
|
|
|
/// <param name="dict"></param>
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <returns></returns>
|
2018-10-21 10:02:59 +08:00
|
|
|
|
public virtual bool SaveSettings(BootstrapDict dict)
|
|
|
|
|
{
|
2019-01-14 12:33:09 +08:00
|
|
|
|
DbManager.Create().Update<BootstrapDict>("set Code = @Code where Category = @Category and Name = @Name", dict);
|
2019-01-11 23:20:28 +08:00
|
|
|
|
return true;
|
2018-10-21 10:02:59 +08:00
|
|
|
|
}
|
2019-01-11 23:20:28 +08:00
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取字典分类名称
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2019-03-11 14:21:48 +08:00
|
|
|
|
public virtual IEnumerable<string> RetrieveCategories() => DictHelper.RetrieveDicts().OrderBy(d => d.Category).Select(d => d.Category).Distinct();
|
2019-01-11 23:20:28 +08:00
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2018-10-30 13:07:29 +08:00
|
|
|
|
public virtual string RetrieveWebTitle() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "网站标题" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "后台管理系统" }).Code;
|
2019-01-11 23:20:28 +08:00
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2018-10-30 13:07:29 +08:00
|
|
|
|
public virtual string RetrieveWebFooter() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "网站页脚" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "2016 © 通用后台管理系统" }).Code;
|
2019-01-11 23:20:28 +08:00
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获得系统中配置的可以使用的网站样式
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2018-10-30 13:07:29 +08:00
|
|
|
|
public virtual IEnumerable<BootstrapDict> RetrieveThemes() => DictHelper.RetrieveDicts().Where(d => d.Category == "网站样式");
|
2019-01-11 23:20:28 +08:00
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获得网站设置中的当前样式
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2018-10-21 10:02:59 +08:00
|
|
|
|
public virtual string RetrieveActiveTheme()
|
|
|
|
|
{
|
2019-03-06 15:28:30 +08:00
|
|
|
|
var theme = DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "使用样式" && d.Category == "当前样式" && d.Define == 0);
|
2018-10-21 10:02:59 +08:00
|
|
|
|
return theme == null ? string.Empty : (theme.Code.Equals("site.css", StringComparison.OrdinalIgnoreCase) ? string.Empty : theme.Code);
|
|
|
|
|
}
|
2019-01-11 23:20:28 +08:00
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取头像路径
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2019-03-08 15:33:00 +08:00
|
|
|
|
public virtual string RetrieveIconFolderPath() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "头像路径" && d.Category == "头像地址" && d.Define == 0) ?? new BootstrapDict { Code = "~/images/uploader/" }).Code;
|
2019-01-11 23:20:28 +08:00
|
|
|
|
|
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 virtual string RetrieveHomeUrl(string appCode)
|
|
|
|
|
{
|
|
|
|
|
// https://gitee.com/LongbowEnterprise/dashboard/issues?id=IS0WK
|
|
|
|
|
var url = "~/Home/Index";
|
|
|
|
|
var dicts = DictHelper.RetrieveDicts();
|
|
|
|
|
if (appCode != "0")
|
|
|
|
|
{
|
|
|
|
|
var appUrl = dicts.FirstOrDefault(d => d.Name.Equals(appCode, StringComparison.OrdinalIgnoreCase) && d.Category == "应用首页" && d.Define == 0)?.Code;
|
|
|
|
|
if (!string.IsNullOrEmpty(appUrl))
|
|
|
|
|
{
|
|
|
|
|
url = appUrl;
|
|
|
|
|
return url;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var defaultUrl = dicts.FirstOrDefault(d => d.Name == "前台首页" && d.Category == "网站设置" && d.Define == 0)?.Code;
|
|
|
|
|
if (!string.IsNullOrEmpty(defaultUrl)) url = defaultUrl;
|
|
|
|
|
return url;
|
|
|
|
|
}
|
2019-01-11 23:20:28 +08:00
|
|
|
|
|
2018-10-21 10:02:59 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2018-10-30 13:07:29 +08:00
|
|
|
|
public virtual IEnumerable<KeyValuePair<string, string>> RetrieveApps() => DictHelper.RetrieveDicts().Where(d => d.Category == "应用程序" && d.Define == 0).Select(d => new KeyValuePair<string, string>(d.Code, d.Name)).OrderBy(d => d.Key);
|
2019-01-11 23:20:28 +08:00
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 通过数据库获得所有字典表配置信息,缓存Key=DictHelper-RetrieveDicts
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2018-10-28 23:35:23 +08:00
|
|
|
|
public virtual IEnumerable<BootstrapDict> RetrieveDicts() => DbHelper.RetrieveDicts();
|
2019-03-08 15:33:00 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 程序异常时长 默认1月
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int RetrieveExceptionsLogPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().Where(d => d.Category == "系统设置" && d.Name == "程序异常保留时长" && d.Define == 0).FirstOrDefault()?.Code, 1);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 操作日志时长 默认12月
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int RetrieveLogsPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().Where(d => d.Category == "系统设置" && d.Name == "操作日志保留时长" && d.Define == 0).FirstOrDefault()?.Code, 12);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 登录日志时长 默认12月
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int RetrieveLoginLogsPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().Where(d => d.Category == "系统设置" && d.Name == "登录日志保留时长" && d.Define == 0).FirstOrDefault()?.Code, 12);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Cookie保存时长 默认7天
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2019-03-08 16:21:31 +08:00
|
|
|
|
public int RetrieveCookieExpiresPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().Where(d => d.Category == "系统设置" && d.Name == "Cookie保留时长" && d.Define == 0).FirstOrDefault()?.Code, 7);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获得 项目是否获取登录地点 默认为false
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int RetrieveLocaleIP() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().Where(d => d.Category == "系统设置" && d.Name == "获取IP地点" && d.Define == 0).FirstOrDefault()?.Code, 0);
|
2018-10-19 23:09:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|