This commit is contained in:
2026-02-06 18:34:35 +08:00
commit f7f4c94c00
3285 changed files with 563208 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
/*
*所有关于Sys_QuartzLog类的业务代码应在此处编写
*可使用repository.调用常用方法获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*Sys_QuartzLogService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
using System.Linq;
using iMES.Core.Utilities;
using System.Linq.Expressions;
using iMES.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using iMES.System.IRepositories;
namespace iMES.System.Services
{
public partial class Sys_QuartzLogService
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ISys_QuartzLogRepository _repository;//访问数据库
[ActivatorUtilitiesConstructor]
public Sys_QuartzLogService(
ISys_QuartzLogRepository dbRepository,
IHttpContextAccessor httpContextAccessor
)
: base(dbRepository)
{
_httpContextAccessor = httpContextAccessor;
_repository = dbRepository;
//多租户会用到这init代码其他情况可以不用
//base.Init(dbRepository);
}
}
}

View File

@@ -0,0 +1,123 @@
/*
*所有关于Sys_QuartzOptions类的业务代码应在此处编写
*可使用repository.调用常用方法获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*Sys_QuartzOptionsService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
using System.Linq;
using iMES.Core.Utilities;
using System.Linq.Expressions;
using iMES.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using iMES.System.IRepositories;
using iMES.Core.Quartz;
using Quartz;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace iMES.System.Services
{
public partial class Sys_QuartzOptionsService
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ISys_QuartzOptionsRepository _repository;//访问数据库
private readonly ISchedulerFactory _schedulerFactory;
[ActivatorUtilitiesConstructor]
public Sys_QuartzOptionsService(
ISys_QuartzOptionsRepository dbRepository,
IHttpContextAccessor httpContextAccessor,
ISchedulerFactory schedulerFactory
)
: base(dbRepository)
{
_httpContextAccessor = httpContextAccessor;
_repository = dbRepository;
_schedulerFactory = schedulerFactory;
//多租户会用到这init代码其他情况可以不用
//base.Init(dbRepository);
}
WebResponseContent webResponse = new WebResponseContent();
public override WebResponseContent Add(SaveModel saveDataModel)
{
AddOnExecuting = (Sys_QuartzOptions options, object list) =>
{
options.Status = (int)TriggerState.Paused;
return webResponse.OK();
};
AddOnExecuted = (Sys_QuartzOptions options, object list) =>
{
return webResponse.OK();
};
return base.Add(saveDataModel);
}
public override WebResponseContent Del(object[] keys, bool delList = true)
{
var ids = keys.Select(s => (Guid)(s.GetGuid())).ToArray();
repository.FindAsIQueryable(x => ids.Contains(x.Id)).ToList().ForEach(options =>
{
_schedulerFactory.Remove(options).GetAwaiter().GetResult();
});
return base.Del(keys, delList);
}
public override WebResponseContent Update(SaveModel saveModel)
{
UpdateOnExecuted = (Sys_QuartzOptions options, object addList, object updateList, List<object> delKeys) =>
{
_schedulerFactory.Update(options).GetAwaiter().GetResult();
return webResponse.OK();
};
return base.Update(saveModel);
}
/// <summary>
/// 手动执行一次
/// </summary>
/// <param name="taskOptions"></param>
/// <returns></returns>
public async Task<object> Run(Sys_QuartzOptions taskOptions)
{
return await _schedulerFactory.Run(taskOptions);
}
/// <summary>
/// 开启任务
/// </summary>
/// <param name="schedulerFactory"></param>
/// <param name="taskOptions"></param>
/// <returns></returns>
public async Task<object> Start(Sys_QuartzOptions taskOptions)
{
var result = await _schedulerFactory.Start(taskOptions);
if (taskOptions.Status != (int)TriggerState.Normal)
{
taskOptions.Status = (int)TriggerState.Normal;
_repository.Update(taskOptions, x => new { x.Status }, true);
}
return result;
}
/// <summary>
/// 暂停任务
/// </summary>
/// <param name="schedulerFactory"></param>
/// <param name="taskOptions"></param>
/// <returns></returns>
public async Task<object> Pause(Sys_QuartzOptions taskOptions)
{
var result = await _schedulerFactory.Remove(taskOptions);
taskOptions.Status = (int)TriggerState.Paused;
_repository.Update(taskOptions, x => new { x.Status }, true);
return result;
}
}
}

View File

@@ -0,0 +1,26 @@
/*
*AuthorZMRid
*代码由框架生成,此处任何更改都可能导致被代码生成器覆盖
*所有业务编写全部应在Partial文件夹下Sys_QuartzLogService与ISys_QuartzLogService中编写
*/
using iMES.System.IRepositories;
using iMES.System.IServices;
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
namespace iMES.System.Services
{
public partial class Sys_QuartzLogService : ServiceBase<Sys_QuartzLog, ISys_QuartzLogRepository>
, ISys_QuartzLogService, IDependency
{
public Sys_QuartzLogService(ISys_QuartzLogRepository repository)
: base(repository)
{
Init(repository);
}
public static ISys_QuartzLogService Instance
{
get { return AutofacContainerModule.GetService<ISys_QuartzLogService>(); } }
}
}

View File

@@ -0,0 +1,26 @@
/*
*AuthorZMRid
*代码由框架生成,此处任何更改都可能导致被代码生成器覆盖
*所有业务编写全部应在Partial文件夹下Sys_QuartzOptionsService与ISys_QuartzOptionsService中编写
*/
using iMES.System.IRepositories;
using iMES.System.IServices;
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
namespace iMES.System.Services
{
public partial class Sys_QuartzOptionsService : ServiceBase<Sys_QuartzOptions, ISys_QuartzOptionsRepository>
, ISys_QuartzOptionsService, IDependency
{
public Sys_QuartzOptionsService(ISys_QuartzOptionsRepository repository)
: base(repository)
{
Init(repository);
}
public static ISys_QuartzOptionsService Instance
{
get { return AutofacContainerModule.GetService<ISys_QuartzOptionsService>(); } }
}
}

View File

@@ -0,0 +1,101 @@
/*
*所有关于Sys_Department类的业务代码应在此处编写
*可使用repository.调用常用方法获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*Sys_DepartmentService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
using System.Linq;
using iMES.Core.Utilities;
using System.Linq.Expressions;
using iMES.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using iMES.System.IRepositories;
using System.Collections.Generic;
using iMES.Core.ManageUser;
using iMES.Core.UserManager;
namespace iMES.System.Services
{
public partial class Sys_DepartmentService
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ISys_DepartmentRepository _repository;//访问数据库
[ActivatorUtilitiesConstructor]
public Sys_DepartmentService(
ISys_DepartmentRepository dbRepository,
IHttpContextAccessor httpContextAccessor
)
: base(dbRepository)
{
_httpContextAccessor = httpContextAccessor;
_repository = dbRepository;
//多租户会用到这init代码其他情况可以不用
//base.Init(dbRepository);
}
public override PageGridData<Sys_Department> GetPageData(PageDataOptions options)
{
FilterData();
return base.GetPageData(options);
}
private void FilterData()
{
//限制 只能看自己部门及下级组织的数据
QueryRelativeExpression = (IQueryable<Sys_Department> queryable) =>
{
if (UserContext.Current.IsSuperAdmin)
{
return queryable;
}
var deptIds = UserContext.Current.GetAllChildrenDeptIds();
return queryable.Where(x => deptIds.Contains(x.DepartmentId));
};
}
public override WebResponseContent Export(PageDataOptions pageData)
{
FilterData();
return base.Export(pageData);
}
WebResponseContent webResponse = new WebResponseContent();
public override WebResponseContent Add(SaveModel saveDataModel)
{
AddOnExecuting = (Sys_Department dept, object list) =>
{
return webResponse.OK();
};
return base.Add(saveDataModel).Reload();
}
public override WebResponseContent Update(SaveModel saveModel)
{
UpdateOnExecuting = (Sys_Department dept, object addList, object updateList, List<object> delKeys) =>
{
if (_repository.Exists(x => x.DepartmentId == dept.ParentId && x.DepartmentId == dept.DepartmentId))
{
return webResponse.Error("上级组织不能选择自己");
}
if (_repository.Exists(x => x.ParentId == dept.DepartmentId) && _repository.Exists(x => x.DepartmentId == dept.ParentId))
{
return webResponse.Error("不能选择此上级组织");
}
return webResponse.OK();
};
return base.Update(saveModel).Reload();
}
public override WebResponseContent Del(object[] keys, bool delList = true)
{
return base.Del(keys, delList).Reload();
}
}
}

View File

@@ -0,0 +1,61 @@
/*
*所有关于Sys_Dept类的业务代码应在此处编写
*可使用repository.调用常用方法获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*Sys_DeptService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
using System.Linq;
using iMES.Core.Utilities;
using System.Linq.Expressions;
using iMES.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using iMES.System.IRepositories;
namespace iMES.System.Services
{
public partial class Sys_DeptService
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ISys_DeptRepository _repository;//访问数据库
[ActivatorUtilitiesConstructor]
public Sys_DeptService(
ISys_DeptRepository dbRepository,
IHttpContextAccessor httpContextAccessor
)
: base(dbRepository)
{
_httpContextAccessor = httpContextAccessor;
_repository = dbRepository;
//多租户会用到这init代码其他情况可以不用
//base.Init(dbRepository);
}
WebResponseContent webResponse = new WebResponseContent();
/// <summary>
/// 新建
/// </summary>
/// <param name="saveDataModel"></param>
/// <returns></returns>
public override WebResponseContent Add(SaveModel saveDataModel)
{
//此处saveModel是从前台提交的原生数据可对数据进修改过滤
AddOnExecuting = (Sys_Dept sysDept, object list) =>
{
//如果返回false,后面代码不会再执行
if (repository.Exists(x => x.DeptCode == sysDept.DeptCode))
{
return webResponse.Error("部门编码已存在");
}
return webResponse.OK();
};
return base.Add(saveDataModel);
}
}
}

View File

@@ -0,0 +1,41 @@
/*
*所有关于Sys_DeptTree类的业务代码应在此处编写
*可使用repository.调用常用方法获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*Sys_DeptTreeService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
using System.Linq;
using iMES.Core.Utilities;
using System.Linq.Expressions;
using iMES.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using iMES.System.IRepositories;
namespace iMES.System.Services
{
public partial class Sys_DeptTreeService
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ISys_DeptTreeRepository _repository;//访问数据库
[ActivatorUtilitiesConstructor]
public Sys_DeptTreeService(
ISys_DeptTreeRepository dbRepository,
IHttpContextAccessor httpContextAccessor
)
: base(dbRepository)
{
_httpContextAccessor = httpContextAccessor;
_repository = dbRepository;
//多租户会用到这init代码其他情况可以不用
//base.Init(dbRepository);
}
}
}

View File

@@ -0,0 +1,63 @@
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
using System.Linq;
using iMES.Core.Extensions;
using System.Collections.Generic;
using iMES.Core.Enums;
using Microsoft.AspNetCore.Http;
using iMES.System.IRepositories;
using iMES.System.IServices;
using Microsoft.Extensions.DependencyInjection;
using iMES.Core.Utilities;
using Microsoft.EntityFrameworkCore;
namespace iMES.System.Services
{
public partial class Sys_DictionaryListService
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ISys_DictionaryRepository _dicRepository;//访问数据库
[ActivatorUtilitiesConstructor]
public Sys_DictionaryListService(
ISys_DictionaryListRepository dbRepository,
ISys_DictionaryRepository dicRepository,
IHttpContextAccessor httpContextAccessor
)
: base(dbRepository)
{
_httpContextAccessor = httpContextAccessor;
_dicRepository = dicRepository;
//多租户会用到这init代码其他情况可以不用
//base.Init(dbRepository);
}
private WebResponseContent webResponse = new WebResponseContent();
public override PageGridData<Sys_DictionaryList> GetPageData(PageDataOptions pageData)
{
if (pageData.Value != null && pageData.Value.ToString() != "")
{
Sys_Dictionary dic = _dicRepository.FindAsIQueryable(x => x.DicNo == pageData.Value.ToString())
.FirstOrDefault();
QueryRelativeExpression = (IQueryable<Sys_DictionaryList> queryable) =>
{
queryable = queryable = queryable.Where(c => c.Dic_ID == dic.Dic_ID);
return queryable;
};
return base.GetPageData(pageData);
}
else
{
base.OrderByExpression = x => new Dictionary<object, QueryOrderBy>() { {
x.OrderNo,QueryOrderBy.Desc
},
{
x.DicList_ID,QueryOrderBy.Asc
}
};
return base.GetPageData(pageData);
}
}
}
}

View File

@@ -0,0 +1,290 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using iMES.Core.BaseProvider;
using iMES.Core.Const;
using iMES.Core.Enums;
using iMES.Core.Extensions;
using iMES.Core.Infrastructure;
using iMES.Core.Utilities;
using iMES.Entity.DomainModels;
namespace iMES.System.Services
{
public partial class Sys_DictionaryService
{
protected override void Init(IRepository<Sys_Dictionary> repository)
{
}
/// <summary>
/// 代码生成器获取所有字典项编号(超级管理权限)
/// </summary>
/// <returns></returns>
public async Task<List<string>> GetBuilderDictionary()
{
//var rows = await repository.FindAsIQueryable(x => 1 == 1, x => new Dictionary<object, QueryOrderBy>() {
// { x.DicNo,QueryOrderBy.Asc }
// })
// .ToListAsync();
//List<string> list = rows.ConvertAll<string>(x => x.DicNo.ToString());
//return list;
return await repository.FindAsync(x => 1 == 1, s => s.DicNo);
}
public List<Sys_Dictionary> Dictionaries
{
get { return DictionaryManager.Dictionaries; }
}
public object GetVueDictionary(string[] dicNos)
{
if (dicNos == null || dicNos.Count() == 0) return new string[] { };
var dicConfig = DictionaryManager.GetDictionaries(dicNos, false).Select(s => new
{
dicNo = s.DicNo,
config = s.Config,
dbSql = s.DbSql,
list = s.Sys_DictionaryList.OrderByDescending(o => o.OrderNo)
.Select(list => new { key = list.DicValue, value = list.DicName })
}).ToList();
object GetSourceData(string dicNo, string dbSql, object data)
{
// 2020.05.01增加根据用户信息加载字典数据源sql
dbSql = DictionaryHandler.GetCustomDBSql(dicNo, dbSql);
if (string.IsNullOrEmpty(dbSql))
{
return data as object;
}
return repository.DapperContext.QueryList<object>(dbSql, null);
}
return dicConfig.Select(item => new
{
item.dicNo,
item.config,
data = GetSourceData(item.dicNo, item.dbSql, item.list)
}).ToList();
}
/// <summary>
/// 通过远程搜索
/// </summary>
/// <param name="dicNo"></param>
/// <param name="value"></param>
/// <returns></returns>
public object GetSearchDictionary(string dicNo, string value)
{
if (string.IsNullOrEmpty(dicNo) || string.IsNullOrEmpty(value))
{
return null;
}
// 2020.05.01增加根据用户信息加载字典数据源sql
string sql = Dictionaries.Where(x => x.DicNo == dicNo).FirstOrDefault()?.DbSql;
sql = DictionaryHandler.GetCustomDBSql(dicNo, sql);
if (string.IsNullOrEmpty(sql))
{
return null;
}
sql = $"SELECT * FROM ({sql}) AS t WHERE value LIKE @value";
return repository.DapperContext.QueryList<object>(sql, new { value = "%" + value + "%" });
}
/// <summary>
/// 表单设置为远程查询重置或第一次添加表单时获取字典的key、value
/// </summary>
/// <param name="dicNo"></param>
/// <param name="value"></param>
/// <returns></returns>
public async Task<object> GetRemoteDefaultKeyValue(string dicNo, string key)
{
return await Task.FromResult(1);
//if (string.IsNullOrEmpty(dicNo) || string.IsNullOrEmpty(key))
//{
// return null;
//}
//string sql = Dictionaries.Where(x => x.DicNo == dicNo).FirstOrDefault()?.DbSql;
//if (string.IsNullOrEmpty(sql))
//{
// return null;
//}
//sql = $"SELECT * FROM ({sql}) AS t WHERE t.key = @key";
//return await Task.FromResult(repository.DapperContext.QueryFirst<object>(sql, new { key }));
}
/// <summary>
/// table加载数据后刷新当前table数据的字典项(适用字典数据量比较大的情况)
/// </summary>
/// <param name="keyData"></param>
/// <returns></returns>
public object GetTableDictionary(Dictionary<string, object[]> keyData)
{
// 2020.08.06增加pgsql获取数据源
if (DBType.Name == DbCurrentType.PgSql.ToString())
{
return GetPgSqlTableDictionary(keyData);
}
var dicInfo = Dictionaries.Where(x => keyData.ContainsKey(x.DicNo) && !string.IsNullOrEmpty(x.DbSql))
.Select(x => new { x.DicNo, x.DbSql })
.ToList();
List<object> list = new List<object>();
string keySql = DBType.Name == DbCurrentType.MySql.ToString() ? "t.key" : "t.[key]";
dicInfo.ForEach(x =>
{
if (keyData.TryGetValue(x.DicNo, out object[] data))
{
// 2020.05.01增加根据用户信息加载字典数据源sql
string sql = DictionaryHandler.GetCustomDBSql(x.DicNo, x.DbSql);
sql = $"SELECT * FROM ({sql}) AS t WHERE " +
$"{keySql}" +
$" in @data";
list.Add(new { key = x.DicNo, data = repository.DapperContext.QueryList<object>(sql, new { data }) });
}
});
return list;
}
/// <summary>
/// 2020.08.06增加pgsql获取数据源
/// </summary>
/// <param name="keyData"></param>
/// <returns></returns>
public object GetPgSqlTableDictionary(Dictionary<string, object[]> keyData)
{
var dicInfo = Dictionaries.Where(x => keyData.ContainsKey(x.DicNo) && !string.IsNullOrEmpty(x.DbSql))
.Select(x => new { x.DicNo, x.DbSql })
.ToList();
List<object> list = new List<object>();
dicInfo.ForEach(x =>
{
if (keyData.TryGetValue(x.DicNo, out object[] data))
{
string sql = DictionaryHandler.GetCustomDBSql(x.DicNo, x.DbSql);
sql = $"SELECT * FROM ({sql}) AS t WHERE t.key=any(@data)";
list.Add(new { key = x.DicNo, data = repository.DapperContext.QueryList<object>(sql, new { data = data.Select(s => s.ToString()).ToList() }) });
}
});
return list;
}
public override PageGridData<Sys_Dictionary> GetPageData(PageDataOptions pageData)
{
//增加查询条件
base.QueryRelativeExpression = (IQueryable<Sys_Dictionary> fun) =>
{
return fun.Where(x => 1 == 1);
};
return base.GetPageData(pageData);
}
public override WebResponseContent Update(SaveModel saveDataModel)
{
if (saveDataModel.MainData.DicKeyIsNullOrEmpty("DicNo")
|| saveDataModel.MainData.DicKeyIsNullOrEmpty("Dic_ID"))
return base.Add(saveDataModel);
//判断修改的字典编号是否在其他ID存在
string dicNo = saveDataModel.MainData["DicNo"].ToString().Trim();
if (base.repository.Exists(x => x.DicNo == dicNo && x.Dic_ID != saveDataModel.MainData["Dic_ID"].GetInt()))
return new WebResponseContent().Error($"字典编号:{ dicNo}已存在。!");
base.UpdateOnExecuting = (Sys_Dictionary dictionary, object addList, object editList, List<object> obj) =>
{
List<Sys_DictionaryList> listObj = new List<Sys_DictionaryList>();
listObj.AddRange(addList as List<Sys_DictionaryList>);
listObj.AddRange(editList as List<Sys_DictionaryList>);
WebResponseContent _responseData = CheckKeyValue(listObj);
if (!_responseData.Status) return _responseData;
dictionary.DbSql = SqlFilters(dictionary.DbSql);
return new WebResponseContent(true);
};
return RemoveCache(base.Update(saveDataModel));
}
private WebResponseContent CheckKeyValue(List<Sys_DictionaryList> dictionaryLists)
{
WebResponseContent webResponse = new WebResponseContent();
if (dictionaryLists == null || dictionaryLists.Count == 0) return webResponse.OK();
if (dictionaryLists.GroupBy(g => g.DicName).Any(x => x.Count() > 1))
return webResponse.Error("【字典项名称】不能有重复的值");
if (dictionaryLists.GroupBy(g => g.DicValue).Any(x => x.Count() > 1))
return webResponse.Error("【字典项Key】不能有重复的值");
return webResponse.OK();
}
private static string SqlFilters(string source)
{
if (string.IsNullOrEmpty(source)) return source;
// source = source.Replace("'", "''");
source = Regex.Replace(source, "-", "", RegexOptions.IgnoreCase);
//去除执行SQL语句的命令关键字
source = Regex.Replace(source, "insert", "", RegexOptions.IgnoreCase);
// source = Regex.Replace(source, "sys.", "", RegexOptions.IgnoreCase);
source = Regex.Replace(source, "update", "", RegexOptions.IgnoreCase);
source = Regex.Replace(source, "delete", "", RegexOptions.IgnoreCase);
source = Regex.Replace(source, "drop", "", RegexOptions.IgnoreCase);
source = Regex.Replace(source, "truncate", "", RegexOptions.IgnoreCase);
source = Regex.Replace(source, "declare", "", RegexOptions.IgnoreCase);
source = Regex.Replace(source, "xp_cmdshell", "", RegexOptions.IgnoreCase);
source = Regex.Replace(source, "/add", "", RegexOptions.IgnoreCase);
source = Regex.Replace(source, "net user", "", RegexOptions.IgnoreCase);
//去除执行存储过程的命令关键字
source = Regex.Replace(source, "exec", "", RegexOptions.IgnoreCase);
source = Regex.Replace(source, "execute", "", RegexOptions.IgnoreCase);
//去除系统存储过程或扩展存储过程关键字
source = Regex.Replace(source, "xp_", "x p_", RegexOptions.IgnoreCase);
source = Regex.Replace(source, "sp_", "s p_", RegexOptions.IgnoreCase);
//防止16进制注入
source = Regex.Replace(source, "0x", "0 x", RegexOptions.IgnoreCase);
return source;
}
public override WebResponseContent Add(SaveModel saveDataModel)
{
if (saveDataModel.MainData.DicKeyIsNullOrEmpty("DicNo")) return base.Add(saveDataModel);
string dicNo = saveDataModel.MainData["DicNo"].ToString();
if (base.repository.Exists(x => x.DicNo == dicNo))
return new WebResponseContent().Error("字典编号:" + dicNo + "已存在");
base.AddOnExecuting = (Sys_Dictionary dic, object obj) =>
{
WebResponseContent _responseData = CheckKeyValue(obj as List<Sys_DictionaryList>);
if (!_responseData.Status) return _responseData;
dic.DbSql = SqlFilters(dic.DbSql);
return new WebResponseContent(true);
};
return RemoveCache(base.Add(saveDataModel));
}
public override WebResponseContent Del(object[] keys, bool delList = false)
{
//delKeys删除的key
base.DelOnExecuting = (object[] delKeys) =>
{
return new WebResponseContent(true);
};
//true将子表数据同时删除
return RemoveCache(base.Del(keys, true));
}
private WebResponseContent RemoveCache(WebResponseContent webResponse)
{
if (webResponse.Status)
{
CacheContext.Remove(DictionaryManager.Key);
}
return webResponse;
}
}
}

View File

@@ -0,0 +1,331 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using iMES.Core.Extensions;
using iMES.Core.ManageUser;
using iMES.Core.Services;
using iMES.Core.Utilities;
using iMES.Entity;
using iMES.Entity.DomainModels;
namespace iMES.System.Services
{
public partial class Sys_MenuService
{
/// <summary>
/// 菜单静态化处理每次获取菜单时先比较菜单是否发生变化如果发生变化从数据库重新获取否则直接获取_menus菜单
/// </summary>
private static List<Sys_Menu> _menus { get; set; }
/// <summary>
/// 从数据库获取菜单时锁定的对象
/// </summary>
private static object _menuObj = new object();
/// <summary>
/// 当前服务器的菜单版本
/// </summary>
private static string _menuVersionn = "";
private const string _menuCacheKey = "inernalMenu";
/// <summary>
/// 编辑修改菜单时,获取所有菜单
/// </summary>
/// <returns></returns>
public async Task<object> GetMenu()
{
// DBServerProvider.SqlDapper.q
return (await repository.FindAsync(x => 1 == 1, a =>
new
{
id = a.Menu_Id,
parentId = a.ParentId,
name = a.MenuName,
a.MenuType,
a.OrderNo
})).OrderByDescending(a => a.OrderNo)
.ThenByDescending(q => q.parentId).ToList();
}
private List<Sys_Menu> GetAllMenu()
{
//每次比较缓存是否更新过,如果更新则重新获取数据
string _cacheVersion = CacheContext.Get(_menuCacheKey);
if (_menuVersionn != "" && _menuVersionn == _cacheVersion)
{
return _menus ?? new List<Sys_Menu>();
}
lock (_menuObj)
{
if (_menuVersionn != "" && _menus != null && _menuVersionn == _cacheVersion) return _menus;
//2020.12.27增加菜单界面上不显示,但可以分配权限
_menus = repository.FindAsIQueryable(x => x.Enable == 1 || x.Enable == 2)
.OrderByDescending(a => a.OrderNo)
.ThenByDescending(q => q.ParentId).ToList();
_menus.ForEach(x =>
{
// 2022.03.26增移动端加菜单类型
x.MenuType ??= 0;
if (!string.IsNullOrEmpty(x.Auth) && x.Auth.Length > 10)
{
try
{
x.Actions = x.Auth.DeserializeObject<List<Sys_Actions>>();
}
catch { }
}
if (x.Actions == null) x.Actions = new List<Sys_Actions>();
});
string cacheVersion = CacheContext.Get(_menuCacheKey);
if (string.IsNullOrEmpty(cacheVersion))
{
cacheVersion = DateTime.Now.ToString("yyyyMMddHHMMssfff");
CacheContext.Add(_menuCacheKey, cacheVersion);
}
else
{
_menuVersionn = cacheVersion;
}
}
return _menus;
}
/// <summary>
/// 获取当前用户有权限查看的菜单
/// </summary>
/// <returns></returns>
public List<Sys_Menu> GetCurrentMenuList()
{
int roleId = UserContext.Current.RoleId;
return GetUserMenuList(roleId);
}
public List<Sys_Menu> GetUserMenuList(int roleId)
{
if (UserContext.IsRoleIdSuperAdmin(roleId))
{
return GetAllMenu();
}
List<int> menuIds = UserContext.Current.GetPermissions(roleId).Select(x => x.Menu_Id).ToList();
return GetAllMenu().Where(x => menuIds.Contains(x.Menu_Id)).ToList();
}
/// <summary>
/// 获取当前用户所有菜单与权限
/// </summary>
/// <returns></returns>
public async Task<object> GetCurrentMenuActionList()
{
return await GetMenuActionList(UserContext.Current.RoleId);
}
/// <summary>
/// 根据角色ID获取菜单与权限
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
public async Task<object> GetMenuActionList(int roleId)
{
//2020.12.27增加菜单界面上不显示,但可以分配权限
if (UserContext.IsRoleIdSuperAdmin(roleId))
{
return await Task.Run(() => GetAllMenu()
.Where(c => c.MenuType == UserContext.MenuType)
.Select(x =>
new
{
id = x.Menu_Id,
name = x.MenuName,
url = x.Url,
parentId = x.ParentId,
icon = x.Icon,
x.Enable,
x.TableName, // 2022.03.26增移动端加菜单类型
permission = x.Actions.Select(s => s.Value).ToArray()
}).ToList());
}
var menu = from a in UserContext.Current.Permissions
join b in GetAllMenu().Where(c => c.MenuType == UserContext.MenuType)
on a.Menu_Id equals b.Menu_Id
orderby b.OrderNo descending
select new
{
id = a.Menu_Id,
name = b.MenuName,
url = b.Url,
parentId = b.ParentId,
icon = b.Icon,
b.Enable,
b.TableName, // 2022.03.26增移动端加菜单类型
permission = a.UserAuthArr
};
return menu.ToList();
}
/// <summary>
/// 新建或编辑菜单
/// </summary>
/// <param name="menu"></param>
/// <returns></returns>
public async Task<WebResponseContent> Save(Sys_Menu menu)
{
WebResponseContent webResponse = new WebResponseContent();
if (menu == null) return webResponse.Error("没有获取到提交的参数");
if (menu.Menu_Id > 0 && menu.Menu_Id == menu.ParentId) return webResponse.Error("父级ID不能是当前菜单的ID");
try
{
webResponse = menu.ValidationEntity(x => new { x.MenuName, x.TableName });
if (!webResponse.Status) return webResponse;
if (menu.TableName != "/" && menu.TableName != ".")
{
// 2022.03.26增移动端加菜单类型判断
Sys_Menu sysMenu = await repository.FindAsyncFirst(x => x.TableName == menu.TableName);
if (sysMenu != null)
{
sysMenu.MenuType ??= 0;
if (sysMenu.MenuType == menu.MenuType)
{
if ((menu.Menu_Id > 0 && sysMenu.Menu_Id != menu.Menu_Id)
|| menu.Menu_Id <= 0)
{
return webResponse.Error($"视图/表名【{menu.TableName}】已被其他菜单使用");
}
}
}
}
bool _changed = false;
if (menu.Menu_Id <= 0)
{
repository.Add(menu.SetCreateDefaultVal());
}
else
{
//2020.05.07新增禁止选择上级角色为自己
if (menu.Menu_Id == menu.ParentId)
{
return webResponse.Error($"父级id不能为自己");
}
if (repository.Exists(x => x.ParentId == menu.Menu_Id && menu.ParentId == x.Menu_Id))
{
return webResponse.Error($"不能选择此父级id选择的父级id与当前菜单形成依赖关系");
}
_changed = repository.FindAsIQueryable(c => c.Menu_Id == menu.Menu_Id).Select(s => s.Auth).FirstOrDefault() != menu.Auth;
repository.Update(menu.SetModifyDefaultVal(), p => new
{
p.ParentId,
p.MenuName,
p.Url,
p.Auth,
p.OrderNo,
p.Icon,
p.Enable,
p.MenuType,// 2022.03.26增移动端加菜单类型
p.TableName,
p.ModifyDate,
p.Modifier
});
}
await repository.SaveChangesAsync();
CacheContext.Add(_menuCacheKey, DateTime.Now.ToString("yyyyMMddHHMMssfff"));
if (_changed)
{
UserContext.Current.RefreshWithMenuActionChange(menu.Menu_Id);
}
_menus = null;
webResponse.OK("保存成功", menu);
}
catch (Exception ex)
{
webResponse.Error(ex.Message);
}
finally
{
Logger.Info($"表:{menu.TableName},菜单:{menu.MenuName},权限{menu.Auth},{(webResponse.Status ? "" : "")}{webResponse.Message}");
}
return webResponse;
}
public async Task<WebResponseContent> DelMenu(int menuId)
{
WebResponseContent webResponse =new WebResponseContent();
if (await repository.ExistsAsync(x => x.ParentId == menuId))
{
return webResponse.Error("当前菜单存在子菜单,请先删除子菜单!");
}
repository.Delete(new Sys_Menu()
{
Menu_Id = menuId
}, true);
CacheContext.Add(_menuCacheKey, DateTime.Now.ToString("yyyyMMddHHMMssfff"));
return webResponse.OK("删除成功");
}
/// <summary>
/// 编辑菜单时,获取菜单信息
/// </summary>
/// <param name="menuId"></param>
/// <returns></returns>
public async Task<object> GetTreeItem(int menuId)
{
var sysMenu = (await base.repository.FindAsync(x => x.Menu_Id == menuId))
.Select(
p => new
{
p.Menu_Id,
p.ParentId,
p.MenuName,
p.Url,
p.Auth,
p.OrderNo,
p.Icon,
p.Enable,
// 2022.03.26增移动端加菜单类型
MenuType = p.MenuType ?? 0,
p.CreateDate,
p.Creator,
p.TableName,
p.ModifyDate
}).FirstOrDefault();
return sysMenu;
}
/// <summary>
/// 根据菜单Url获取菜单信息
/// </summary>
/// <param name="menuId"></param>
/// <returns></returns>
public async Task<object> GetMenuItem(int menuId)
{
var sysMenu = (await base.repository.FindAsync(x => x.Menu_Id == menuId))
.Select(
p => new
{
p.Menu_Id,
p.ParentId,
p.MenuName,
p.Url,
p.Auth,
p.OrderNo,
p.Icon,
p.Enable,
MenuType = p.MenuType ?? 0,
p.CreateDate,
p.Creator,
p.TableName,
p.ModifyDate
}).FirstOrDefault();
return sysMenu;
}
}
}

View File

@@ -0,0 +1,384 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using iMES.Core.Extensions;
using iMES.Core.ManageUser;
using iMES.Core.Services;
using iMES.Core.UserManager;
using iMES.Core.Utilities;
using iMES.Entity;
using iMES.Entity.DomainModels;
namespace iMES.System.Services
{
public partial class Sys_RoleService
{
private WebResponseContent _responseContent = new WebResponseContent();
public override PageGridData<Sys_Role> GetPageData(PageDataOptions pageData)
{
//角色Id=1默认为超级管理员角色界面上不显示此角色
QueryRelativeExpression = (IQueryable<Sys_Role> queryable) =>
{
if (UserContext.Current.IsSuperAdmin)
{
return queryable;
}
List<int> roleIds = GetAllChildrenRoleIdAndSelf();
return queryable.Where(x => roleIds.Contains(x.Role_Id));
};
return base.GetPageData(pageData);
}
/// <summary>
/// 编辑权限时,获取当前用户的所有菜单权限
/// </summary>
/// <returns></returns>
public async Task<WebResponseContent> GetCurrentUserTreePermission()
{
return await GetUserTreePermission(UserContext.Current.RoleId);
}
/// <summary>
/// 编辑权限时,获取指定角色的所有菜单权限
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
public async Task<WebResponseContent> GetUserTreePermission(int roleId)
{
if (!UserContext.IsRoleIdSuperAdmin(roleId) && UserContext.Current.RoleId != roleId)
{
if (!(await GetAllChildrenAsync(UserContext.Current.RoleId)).Exists(x => x.Id == roleId))
{
return _responseContent.Error("没有权限获取此角色的权限信息");
}
}
//获取用户权限
List<Permissions> permissions = UserContext.Current.GetPermissions(roleId);
//权限用户权限查询所有的菜单信息
List<Sys_Menu> menus = await Task.Run(() => Sys_MenuService.Instance.GetUserMenuList(roleId));
//获取当前用户权限如:(Add,Search)对应的显示文本信息如:Add添加Search:查询
var data = menus.Select(x => new
{
Id = x.Menu_Id,
Pid = x.ParentId,
Text = x.MenuName,
IsApp = x.MenuType == 1,
Actions = GetActions(x.Menu_Id, x.Actions, permissions, roleId)
});
return _responseContent.OK(null, data);
}
private List<Sys_Actions> GetActions(int menuId, List<Sys_Actions> menuActions, List<Permissions> permissions, int roleId)
{
if (UserContext.IsRoleIdSuperAdmin(roleId))
{
return menuActions;
}
return menuActions.Where(p => permissions
.Exists(w => menuId == w.Menu_Id
&& w.UserAuthArr.Contains(p.Value)))
.ToList();
}
private List<RoleNodes> rolesChildren = new List<RoleNodes>();
/// <summary>
/// 编辑权限时获取当前用户下的所有角色与当前用户的菜单权限
/// </summary>
/// <returns></returns>
public async Task<WebResponseContent> GetCurrentTreePermission()
{
_responseContent = await GetCurrentUserTreePermission();
int roleId = UserContext.Current.RoleId;
return _responseContent.OK(null, new
{
tree = _responseContent.Data,
roles = await GetAllChildrenAsync(roleId)
});
}
private List<RoleNodes> roles = null;
/// <summary>
/// 获取当前角色下的所有角色包括自己的角色Id
/// </summary>
/// <returns></returns>
public List<int> GetAllChildrenRoleIdAndSelf()
{
int roleId = UserContext.Current.RoleId;
List<int> roleIds = GetAllChildren(roleId).Select(x => x.Id).ToList();
roleIds.Add(roleId);
return roleIds;
}
/// <summary>
/// 获取当前角色下的所有角色
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
public List<RoleNodes> GetAllChildren(int roleId)
{
roles = GetAllRoleQueryable(roleId).ToList();
return GetAllChildrenNodes(roleId);
}
public async Task<List<RoleNodes>> GetAllChildrenAsync(int roleId)
{
roles = await GetAllRoleQueryable(roleId).ToListAsync();
return GetAllChildrenNodes(roleId);
}
private IQueryable<RoleNodes> GetAllRoleQueryable(int roleId)
{
return repository
.FindAsIQueryable(
x => x.Enable == 1 && x.Role_Id > 1)
.Select(
s => new RoleNodes()
{
Id = s.Role_Id,
ParentId = s.ParentId,
RoleName = s.RoleName
});
}
public async Task<List<int>> GetAllChildrenRoleIdAsync(int roleId)
{
return (await GetAllChildrenAsync(roleId)).Select(x => x.Id).ToList();
}
public List<int> GetAllChildrenRoleId(int roleId)
{
return GetAllChildren(roleId).Select(x => x.Id).ToList();
}
private List<RoleNodes> GetAllChildrenNodes(int roleId)
{
if (UserContext.IsRoleIdSuperAdmin(roleId)) return roles;
Dictionary<int, bool> completedRoles = new Dictionary<int, bool>();
rolesChildren = GetChildren(roleId, completedRoles);
//2021.07.11增加无限递归异常数据移除当前节点
if (rolesChildren.Any(x => x.Id == roleId))
{
return rolesChildren.Where(x => x.Id != roleId).ToList();
}
return rolesChildren;
}
/// <summary>
/// 递归获取所有子节点权限
/// </summary>
/// <param name="roleId"></param>
private List<RoleNodes> GetChildren(int roleId, Dictionary<int, bool> completedRoles)
{
roles.ForEach(x =>
{
if (x.ParentId == roleId)
{
if (completedRoles.TryGetValue(x.Id, out bool isWrite))
{
if (!isWrite)
{
roles.Where(x => x.Id == roleId).FirstOrDefault().ParentId = 0;
Logger.Error($"sys_roleservice获取子角色异常RoleContext,角色id:{x.Id}");
Console.WriteLine($"sys_roleservice获取子角色异常RoleContext,角色id:{x.Id}");
completedRoles[x.Id] = true;
}
return;
}
rolesChildren.Add(x);
completedRoles[x.Id] = false;
if (x.Id != x.ParentId)
{
GetChildren(x.Id, completedRoles);
}
}
});
return rolesChildren;
}
/// <summary>
/// 保存角色权限
/// </summary>
/// <param name="userPermissions"></param>
/// <param name="roleId"></param>
/// <returns></returns>
public async Task<WebResponseContent> SavePermission(List<UserPermissions> userPermissions, int roleId)
{
string message = "";
try
{
UserInfo user = UserContext.Current.UserInfo;
if (!(await GetAllChildrenAsync(user.Role_Id)).Exists(x => x.Id == roleId))
return _responseContent.Error("没有权限修改此角色的权限信息");
//当前用户的权限
List<Permissions> permissions = UserContext.Current.Permissions;
List<int> originalMeunIds = new List<int>();
//被分配角色的权限
List<Sys_RoleAuth> roleAuths = await repository.FindAsync<Sys_RoleAuth>(x => x.Role_Id == roleId);
List<Sys_RoleAuth> updateAuths = new List<Sys_RoleAuth>();
foreach (UserPermissions x in userPermissions)
{
Permissions per = permissions.Where(p => p.Menu_Id == x.Id).FirstOrDefault();
//不能分配超过当前用户的权限
if (per == null) continue;
//per.UserAuthArr.Contains(a.Value)校验权限范围
string[] arr = x.Actions == null || x.Actions.Count == 0
? new string[0]
: x.Actions.Where(a => per.UserAuthArr.Contains(a.Value))
.Select(s => s.Value).ToArray();
//如果当前权限没有分配过设置Auth_Id默认为0表示新增的权限
var auth = roleAuths.Where(r => r.Menu_Id == x.Id).Select(s => new { s.Auth_Id, s.AuthValue, s.Menu_Id }).FirstOrDefault();
string newAuthValue = string.Join(",", arr);
//权限没有发生变化则不处理
if (auth == null || auth.AuthValue != newAuthValue)
{
updateAuths.Add(new Sys_RoleAuth()
{
Role_Id = roleId,
Menu_Id = x.Id,
AuthValue = string.Join(",", arr),
Auth_Id = auth == null ? 0 : auth.Auth_Id,
ModifyDate = DateTime.Now,
Modifier = user.UserTrueName,
CreateDate = DateTime.Now,
Creator = user.UserTrueName
});
}
else
{
originalMeunIds.Add(auth.Menu_Id);
}
}
//更新权限
repository.UpdateRange(updateAuths.Where(x => x.Auth_Id > 0), x => new
{
x.Menu_Id,
x.AuthValue,
x.Modifier,
x.ModifyDate
});
//新增的权限
repository.AddRange(updateAuths.Where(x => x.Auth_Id <= 0));
//获取权限取消的权限
int[] authIds = roleAuths.Where(x => userPermissions.Select(u => u.Id)
.ToList().Contains(x.Menu_Id) || originalMeunIds.Contains(x.Menu_Id))
.Select(s => s.Auth_Id)
.ToArray();
List<Sys_RoleAuth> delAuths = roleAuths.Where(x => x.AuthValue != "" && !authIds.Contains(x.Auth_Id)).ToList();
delAuths.ForEach(x =>
{
x.AuthValue = "";
});
//将取消的权限设置为""
repository.UpdateRange(delAuths, x => new
{
x.Menu_Id,
x.AuthValue,
x.Modifier,
x.ModifyDate
});
int addCount = updateAuths.Where(x => x.Auth_Id <= 0).Count();
int updateCount = updateAuths.Where(x => x.Auth_Id > 0).Count();
await repository.SaveChangesAsync();
string _version = DateTime.Now.ToString("yyyyMMddHHMMssfff");
//标识缓存已更新
base.CacheContext.Add(roleId.GetRoleIdKey(), _version);
_responseContent.OK($"保存成功:新增加配菜单权限{addCount}条,更新菜单{updateCount}条,删除权限{delAuths.Count()}条");
}
catch (Exception ex)
{
message = "异常信息:" + ex.Message + ex.StackTrace + ",";
}
finally
{
Logger.Info($"权限分配置:{message}{_responseContent.Message}");
}
return _responseContent;
}
public override WebResponseContent Add(SaveModel saveDataModel)
{
AddOnExecuting = (Sys_Role role, object obj) =>
{
return ValidateRoleName(role, x => x.RoleName == role.RoleName);
};
return RemoveCache(base.Add(saveDataModel));
}
public override WebResponseContent Del(object[] keys, bool delList = true)
{
return RemoveCache(base.Del(keys, delList));
}
private WebResponseContent ValidateRoleName(Sys_Role role, Expression<Func<Sys_Role, bool>> predicate)
{
if (repository.Exists(predicate))
{
return _responseContent.Error($"角色名【{role.RoleName}】已存在,请设置其他角色名");
}
return _responseContent.OK();
}
public override WebResponseContent Update(SaveModel saveModel)
{
UpdateOnExecuting = (Sys_Role role, object obj1, object obj2, List<object> obj3) =>
{
//2020.05.07新增禁止选择上级角色为自己
if (role.Role_Id == role.ParentId)
{
return _responseContent.Error($"上级角色不能选择自己");
}
if (role.Role_Id == UserContext.Current.RoleId)
{
return _responseContent.Error($"不能修改自己的角色");
}
if (repository.Exists(x => x.Role_Id == role.ParentId && x.ParentId == role.Role_Id))
{
return _responseContent.Error($"不能选择此上级角色,选择的上级角色与当前角色形成依赖关系");
}
return ValidateRoleName(role, x => x.RoleName == role.RoleName && x.Role_Id != role.Role_Id);
};
return RemoveCache(base.Update(saveModel));
}
private WebResponseContent RemoveCache(WebResponseContent webResponse)
{
if (webResponse.Status)
{
RoleContext.Refresh();
}
return webResponse;
}
}
public class RoleNodes
{
public int Id { get; set; }
public int ParentId { get; set; }
public string RoleName { get; set; }
}
public class UserPermissions
{
public int Id { get; set; }
public int Pid { get; set; }
public string Text { get; set; }
public bool IsApp { get; set; }
public List<Sys_Actions> Actions { get; set; }
}
}

View File

@@ -0,0 +1,624 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using iMES.Core.Configuration;
using iMES.Core.Enums;
using iMES.Core.Extensions;
using iMES.Core.ManageUser;
using iMES.Core.Services;
using iMES.Core.Utilities;
using iMES.Entity.DomainModels;
using Microsoft.AspNetCore.Http;
using iMES.System.IRepositories;
using Microsoft.Extensions.DependencyInjection;
using iMES.Custom.IRepositories;
using HttpContext = iMES.Core.Utilities.HttpContext;
using iMES.Custom.Services;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using iMES.Custom.IServices;
using iMES.Core.Infrastructure;
using iMES.Core.BaseProvider;
namespace iMES.System.Services
{
public partial class Sys_UserService
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ISys_UserRepository _repository;//访问数据库
private readonly ISys_Table_ExtendRepository _sysTableExtendRepository;//扩展字段访问数据库
private readonly ISys_User_ExtendDataRepository _sysUserExtendDataRepository;//扩展字段访问数据库
private readonly ISys_User_ExtendDataService _userExtendDataService;//访问业务代码
[ActivatorUtilitiesConstructor]
public Sys_UserService(
ISys_UserRepository dbRepository,
ISys_Table_ExtendRepository sysTableExtendRepository,
ISys_User_ExtendDataRepository sysUserExtendDataRepository,
IHttpContextAccessor httpContextAccessor,
ISys_User_ExtendDataService userExtendDataService
)
: base(dbRepository)
{
_httpContextAccessor = httpContextAccessor;
_repository = dbRepository;
_sysTableExtendRepository = sysTableExtendRepository;
_sysUserExtendDataRepository = sysUserExtendDataRepository;
_userExtendDataService = userExtendDataService;
//多租户会用到这init代码其他情况可以不用
//base.Init(dbRepository);
}
//Sys_UserService在类中重写Init方法设置IsMultiTenancy=true开启多租户功能
protected override void Init(IRepository<Sys_User> repository)
{
//开启多租户功能,开启后会对查询、导出、删除、编辑功能同时生效
//如果只需要对某个功能生效,如编辑,则在重写编辑方法中设置 IsMultiTenancy = true;
IsMultiTenancy = true;
}
/// <summary>
/// WebApi登陆
/// </summary>
/// <param name="loginInfo"></param>
/// <param name="verificationCode"></param>
/// <returns></returns>
public async Task<WebResponseContent> Login(LoginInfo loginInfo, bool verificationCode = true)
{
string msg = string.Empty;
WebResponseContent responseContent = new WebResponseContent();
// 2020.06.12增加验证码
IMemoryCache memoryCache = HttpContext.Current.GetService<IMemoryCache>();
string cacheCode = (memoryCache.Get(loginInfo.UUID) ?? "").ToString();
if (string.IsNullOrEmpty(cacheCode))
{
return responseContent.Error("验证码已失效");
}
if (cacheCode.ToLower() != loginInfo.VerificationCode.ToLower())
{
memoryCache.Remove(loginInfo.UUID);
return responseContent.Error("验证码不正确");
}
try
{
Sys_User user = await repository.FindAsIQueryable(x => x.UserName == loginInfo.UserName)
.FirstOrDefaultAsync();
if (user == null || loginInfo.Password.Trim().EncryptDES(AppSetting.Secret.User) != (user.UserPwd ?? ""))
return responseContent.Error(ResponseType.LoginError);
string token = JwtHelper.IssueJwt(new UserInfo()
{
User_Id = user.User_Id,
UserName = user.UserName,
Role_Id = user.Role_Id
});
user.Token = token;
responseContent.Data = new { token, userName = user.UserTrueName, img = user.HeadImageUrl ,userTrueName= user.UserName,roleName=user.RoleName };
repository.Update(user, x => x.Token, true);
UserContext.Current.LogOut(user.User_Id);
loginInfo.Password = string.Empty;
return responseContent.OK(ResponseType.LoginSuccess);
}
catch (Exception ex)
{
msg = ex.Message + ex.StackTrace;
return responseContent.Error(ResponseType.ServerError);
}
finally
{
memoryCache.Remove(loginInfo.UUID);
Logger.Info(LoggerType.Login, loginInfo.Serialize(), responseContent.Message, msg);
}
}
/// <summary>
///当token将要过期时提前置换一个新的token
/// </summary>
/// <returns></returns>
public async Task<WebResponseContent> ReplaceToken()
{
WebResponseContent responseContent = new WebResponseContent();
string error = "";
UserInfo userInfo = null;
try
{
string requestToken = HttpContext.Current.Request.Headers[AppSetting.TokenHeaderName];
requestToken = requestToken?.Replace("Bearer ", "");
if (UserContext.Current.Token != requestToken) return responseContent.Error("Token已失效!");
if (JwtHelper.IsExp(requestToken)) return responseContent.Error("Token已过期!");
int userId = UserContext.Current.UserId;
userInfo = await
repository.FindFirstAsync(x => x.User_Id == userId,
s => new UserInfo()
{
User_Id = userId,
UserName = s.UserName,
UserTrueName = s.UserTrueName,
Role_Id = s.Role_Id,
RoleName = s.RoleName
});
if (userInfo == null) return responseContent.Error("未查到用户信息!");
string token = JwtHelper.IssueJwt(userInfo);
//移除当前缓存
base.CacheContext.Remove(userId.GetUserIdKey());
//只更新的token字段
repository.Update(new Sys_User() { User_Id = userId, Token = token }, x => x.Token, true);
responseContent.OK(null, token);
}
catch (Exception ex)
{
error = ex.Message + ex.StackTrace + ex.Source;
responseContent.Error("token替换出错了..");
}
finally
{
Logger.Info(LoggerType.ReplaceToeken, ($"用户Id:{userInfo?.User_Id},用户{userInfo?.UserTrueName}")
+ (responseContent.Status ? "token替换成功" : "token替换失败"), null, error);
}
return responseContent;
}
/// <summary>
/// 修改密码
/// </summary>
/// <param name="parameters"></param>
/// <returns></returns>
public async Task<WebResponseContent> ModifyPwd(string oldPwd, string newPwd)
{
oldPwd = oldPwd?.Trim();
newPwd = newPwd?.Trim();
string message = "";
WebResponseContent webResponse = new WebResponseContent();
try
{
if (string.IsNullOrEmpty(oldPwd)) return webResponse.Error("旧密码不能为空");
if (string.IsNullOrEmpty(newPwd)) return webResponse.Error("新密码不能为空");
if (newPwd.Length < 6) return webResponse.Error("密码不能少于6位");
int userId = UserContext.Current.UserId;
string userCurrentPwd = await base.repository.FindFirstAsync(x => x.User_Id == userId, s => s.UserPwd);
string _oldPwd = oldPwd.EncryptDES(AppSetting.Secret.User);
if (_oldPwd != userCurrentPwd) return webResponse.Error("旧密码不正确");
string _newPwd = newPwd.EncryptDES(AppSetting.Secret.User);
if (userCurrentPwd == _newPwd) return webResponse.Error("新密码不能与旧密码相同");
repository.Update(new Sys_User
{
User_Id = userId,
UserPwd = _newPwd,
LastModifyPwdDate = DateTime.Now
}, x => new { x.UserPwd, x.LastModifyPwdDate }, true);
webResponse.OK("密码修改成功");
}
catch (Exception ex)
{
message = ex.Message;
webResponse.Error("服务器了点问题,请稍后再试");
}
finally
{
if (message == "")
{
Logger.OK(LoggerType.ApiModifyPwd, "密码修改成功");
}
else
{
Logger.Error(LoggerType.ApiModifyPwd, message);
}
}
return webResponse;
}
/// <summary>
/// 个人中心获取当前用户信息
/// </summary>
/// <returns></returns>
public async Task<WebResponseContent> GetCurrentUserInfo()
{
var data = await base.repository
.FindAsIQueryable(x => x.User_Id == UserContext.Current.UserId)
.Select(s => new
{
s.UserName,
s.UserTrueName,
s.Address,
s.PhoneNo,
s.Email,
s.Remark,
s.Gender,
s.RoleName,
s.HeadImageUrl,
s.CreateDate
})
.FirstOrDefaultAsync();
return new WebResponseContent().OK(null, data);
}
/// <summary>
/// 设置固定排序方式及显示用户过滤
/// </summary>
/// <param name="pageData"></param>
/// <returns></returns>
public override PageGridData<Sys_User> GetPageData(PageDataOptions pageData)
{
int roleId = -1;
//树形菜单传查询角色下所有用户
if (pageData.Value != null)
{
roleId = pageData.Value.ToString().GetInt();
}
QueryRelativeExpression = (IQueryable<Sys_User> queryable) =>
{
if (roleId <= 0)
{
if (UserContext.Current.IsSuperAdmin) return queryable;
roleId = UserContext.Current.RoleId;
}
//查看用户时,只能看下自己角色下的所有用户
List<int> roleIds = Sys_RoleService
.Instance
.GetAllChildrenRoleId(roleId);
roleIds.Add(roleId);
//判断查询的角色是否越权
if (roleId != UserContext.Current.RoleId && !roleIds.Contains(roleId))
{
roleId = -999;
}
return queryable.Where(x => roleIds.Contains(x.Role_Id));
};
base.OrderByExpression = x => new Dictionary<object, Core.Enums.QueryOrderBy>() {
{ x.CreateDate, Core.Enums.QueryOrderBy.Desc },
{ x.User_Id,Core.Enums.QueryOrderBy.Desc}
};
return base.GetPageData(pageData);
}
/// <summary>
/// 新建用户,根据实际情况自行处理
/// </summary>
/// <param name="saveModel"></param>
/// <returns></returns>
public override WebResponseContent Add(SaveModel saveModel)
{
WebResponseContent responseData = new WebResponseContent();
base.AddOnExecute = (SaveModel userModel) =>
{
int roleId = userModel?.MainData?["Role_Id"].GetInt() ?? 0;
if (roleId > 0)
{
string roleName = GetChildrenName(roleId);
if ((!UserContext.Current.IsSuperAdmin && roleId == 1) || string.IsNullOrEmpty(roleName))
return responseData.Error("不能选择此角色");
//选择新建的角色ID手动添加角色ID的名称
userModel.MainData["RoleName"] = roleName;
}
return responseData.OK();
};
///生成6位数随机密码
string pwd = 6.GenerateRandomNumber();
//在AddOnExecuting之前已经对提交的数据做过验证是否为空
base.AddOnExecuting = (Sys_User user, object obj) =>
{
user.UserName = user.UserName.Trim();
user.DeptName = DictionaryManager.GetDictionaryList("dept", user.Dept_Id.ToString());
if (repository.Exists(x => x.UserName == user.UserName))
return responseData.Error("用户名已经被注册");
user.UserPwd = pwd.EncryptDES(AppSetting.Secret.User);
//设置默认头像
return responseData.OK();
};
//扩展字段开始 start
base.AddOnExecuted = (Sys_User user, object list) =>
{
var extra = saveModel.Extra.ToString();
JObject jo = (JObject)JsonConvert.DeserializeObject(extra);
int user_Id = user.User_Id.GetInt();
var userExtend = _sysTableExtendRepository.Find(x => x.TableName == "Sys_User", a => new
{
TableEx_Id = a.TableEx_Id,
FieldName = a.FieldName,
FieldCode = a.FieldCode,
FieldType = a.FieldType
}).ToList();
List<Sys_User_ExtendData> listData = new List<Sys_User_ExtendData>();
for (int i = 0; i < userExtend.Count; i++)
{
Sys_User_ExtendData extendData = new Sys_User_ExtendData();
extendData.User_Id = user_Id;
extendData.TableEx_Id = userExtend[i].TableEx_Id;
extendData.FieldValue = jo[userExtend[i].FieldCode].ToString();
extendData.FieldName = userExtend[i].FieldName;
extendData.FieldCode = userExtend[i].FieldCode;
extendData.CreateDate = user.CreateDate;
extendData.CreateID = user.CreateID;
extendData.Creator = user.Creator;
listData.Add(extendData);
}
_sysUserExtendDataRepository.AddRange(listData, true);
//扩展字段开始 end
int roleId = saveModel.MainData["Role_Id"].GetInt();
return responseData.OK($"用户新建成功.帐号{user.UserName}密码{pwd}");
};
return base.Add(saveModel); ;
}
/// <summary>
/// 删除用户拦截过滤
/// 用户被删除后同时清空对应缓存
/// </summary>
/// <param name="keys"></param>
/// <param name="delList"></param>
/// <returns></returns>
public override WebResponseContent Del(object[] keys, bool delList = false)
{
base.DelOnExecuting = (object[] ids) =>
{
int[] userIds = ids.Select(x => Convert.ToInt32(x)).ToArray();
//校验只能删除当前角色下能看到的用户
var xxx = repository.Find(x => userIds.Contains(x.User_Id));
var delUserIds = repository.Find(x => userIds.Contains(x.User_Id), s => new { s.User_Id, s.Role_Id, s.UserTrueName });
List<int> roleIds = Sys_RoleService
.Instance
.GetAllChildrenRoleId(UserContext.Current.RoleId);
string[] userNames = delUserIds.Where(x => !roleIds.Contains(x.Role_Id))
.Select(s => s.UserTrueName)
.ToArray();
if (userNames.Count() > 0)
{
return new WebResponseContent().Error($"没有权限删除用户:{string.Join(',', userNames)}");
}
return new WebResponseContent().OK();
};
base.DelOnExecuted = (object[] userIds) =>
{
var objKeys = userIds.Select(x => x.GetInt().GetUserIdKey());
base.CacheContext.RemoveAll(objKeys);
for (int i = 0; i < userIds.Length; i++)
{
var userExtend = _sysUserExtendDataRepository.Find(x => x.User_Id == userIds[i].GetInt(), a => new
{
UserExData_Id = a.UserExData_Id,
User_Id = a.User_Id,
TableEx_Id = a.TableEx_Id
}).ToList();
if (userExtend.Count > 0)
{
object[] keys = new object[userExtend.Count];
for (int j = 0; j < userExtend.Count; j++)
{
keys[j] = userExtend[j].UserExData_Id.GetInt();
}
_sysUserExtendDataRepository.DeleteWithKeys(keys, false);
}
};
return new WebResponseContent() { Status = true };
};
return base.Del(keys, delList);
}
private string GetChildrenName(int roleId)
{
//只能修改当前角色能看到的用户
string roleName = Sys_RoleService
.Instance
.GetAllChildren(UserContext.Current.UserInfo.Role_Id).Where(x => x.Id == roleId)
.Select(s => s.RoleName).FirstOrDefault();
return roleName;
}
/// <summary>
/// 修改用户拦截过滤
///
/// </summary>
/// <param name="saveModel"></param>
/// <returns></returns>
public override WebResponseContent Update(SaveModel saveModel)
{
WebResponseContent responseContent = new WebResponseContent();
UserInfo userInfo = UserContext.Current.UserInfo;
//禁止修改用户名
base.UpdateOnExecute = (SaveModel saveInfo) =>
{
int roleId = saveModel.MainData["Role_Id"].GetInt();
string roleName = GetChildrenName(roleId);
saveInfo.MainData.TryAdd("RoleName", roleName);
if (UserContext.IsRoleIdSuperAdmin(userInfo.Role_Id))
{
if (userInfo.Role_Id == roleId)
{
saveInfo.MainData["RoleName"] = userInfo.RoleName;
}
return responseContent.OK();
}
if (string.IsNullOrEmpty(roleName)) return responseContent.Error("不能选择此角色");
return responseContent.OK();
};
base.UpdateOnExecuting = (Sys_User user, object obj1, object obj2, List<object> list) =>
{
if (user.User_Id == userInfo.User_Id && user.Role_Id != userInfo.Role_Id)
return responseContent.Error("不能修改自己的角色");
var _user = repository.Find(x => x.User_Id == user.User_Id,
s => new { s.UserName, s.UserPwd })
.FirstOrDefault();
user.UserName = _user.UserName;
user.DeptName = DictionaryManager.GetDictionaryList("dept", user.Dept_Id.ToString());
//Sys_User实体的UserPwd用户密码字段的属性不是编辑此处不会修改密码。但防止代码生成器将密码字段的修改成了可编辑造成密码被修改
user.UserPwd = _user.UserPwd;
return responseContent.OK();
};
//用户信息被修改后,将用户的缓存信息清除
base.UpdateOnExecuted = (Sys_User user, object obj1, object obj2, List<object> List) =>
{
var extra = saveModel.Extra.ToString();
JObject jo = (JObject)JsonConvert.DeserializeObject(extra);
int user_Id = user.User_Id.GetInt();
var userExtend = _sysTableExtendRepository.Find(x => x.TableName == "Sys_User", a => new
{
TableEx_Id = a.TableEx_Id,
FieldName = a.FieldName,
FieldCode = a.FieldCode,
FieldType = a.FieldType
}).ToList();
for (int i = 0; i < userExtend.Count; i++)
{
Sys_User_ExtendData userExtendData = _sysUserExtendDataRepository.FindAsIQueryable(x => x.User_Id == user_Id && x.TableEx_Id == userExtend[i].TableEx_Id)
.FirstOrDefault();
if (userExtendData == null)
{
Sys_User_ExtendData extendData = new Sys_User_ExtendData();
extendData.User_Id = user_Id;
extendData.TableEx_Id = userExtend[i].TableEx_Id;
extendData.FieldValue = jo[userExtend[i].FieldCode].ToString();
extendData.FieldName = userExtend[i].FieldName;
extendData.FieldCode = userExtend[i].FieldCode;
extendData.CreateDate = user.ModifyDate;
extendData.CreateID = user.ModifyID;
extendData.Creator = user.Modifier;
_sysUserExtendDataRepository.Add(extendData, true);
}
else {
userExtendData.ModifyDate = user.ModifyDate;
userExtendData.ModifyID = user.ModifyID;
userExtendData.Modifier = user.Modifier;
userExtendData.FieldValue = jo[userExtend[i].FieldCode].ToString();
_sysUserExtendDataRepository.Update(userExtendData, true);
};
}
base.CacheContext.Remove(user.User_Id.GetUserIdKey());
return new WebResponseContent(true);
};
return base.Update(saveModel);
}
/// <summary>
/// 导出处理
/// </summary>
/// <param name="pageData"></param>
/// <returns></returns>
public override WebResponseContent Export(PageDataOptions pageData)
{
//限定只能导出当前角色能看到的所有用户
QueryRelativeExpression = (IQueryable<Sys_User> queryable) =>
{
if (UserContext.Current.IsSuperAdmin) return queryable;
List<int> roleIds = Sys_RoleService
.Instance
.GetAllChildrenRoleId(UserContext.Current.RoleId);
return queryable.Where(x => roleIds.Contains(x.Role_Id) || x.User_Id == UserContext.Current.UserId);
};
string path = null;
string fileName = null;
WebResponseContent webResponse = new WebResponseContent();
base.ExportOnExecuting = (List<Sys_User> list, List<string> ignoreColumn) =>
{
if (!ignoreColumn.Contains("Role_Id"))
{
ignoreColumn.Add("Role_Id");
}
if (!ignoreColumn.Contains("RoleName"))
{
ignoreColumn.Remove("RoleName");
}
try
{
List<Dictionary<string, object>> listDic = new List<Dictionary<string, object>>();
foreach (var item in list)
{
var extendDataList = _sysUserExtendDataRepository.Find(x => x.User_Id == item.User_Id, a =>
new
{
UserExData_Id = a.UserExData_Id,
User_Id = a.User_Id,
TableEx_Id = a.TableEx_Id,
FieldCode = a.FieldCode,
FieldName = a.FieldName,
FieldValue = a.FieldValue
}).ToList();
Dictionary<string, object> dic = new Dictionary<string, object>();
dic.Add("账号", item.UserName);
dic.Add("性别", DictionaryManager.GetDictionaryList("gender",item.Gender.ToString()));
dic.Add("真实姓名", item.UserTrueName);
dic.Add("创建时间", item.CreateDate==null ? "":item.CreateDate.ToString("yyyy-MM-dd HH:mm:sss"));
dic.Add("创建人", item.Creator);
dic.Add("是否可用", DictionaryManager.GetDictionaryList("enable", item.Enable.ToString()));
dic.Add("修改时间", item.ModifyDate == null ? "" : item.ModifyDate.ToString("yyyy-MM-dd HH:mm:sss"));
for (int i = 0; i < extendDataList.Count; i++)
{
var tableExtend = _sysTableExtendRepository.Find(x => x.TableName == "Sys_User" && x.FieldCode == extendDataList[i].FieldCode.ToString(), a =>
new
{
TableEx_Id = a.TableEx_Id,
FieldCode = a.FieldCode,
FieldName = a.FieldName,
FieldType = a.FieldType,
DataDic = a.DataDic,
}).OrderByDescending(a => a.TableEx_Id)
.ThenByDescending(q => q.TableEx_Id).ToList();
if (tableExtend.Count > 0)
{
if (!string.IsNullOrEmpty(tableExtend[0].DataDic) && !string.IsNullOrEmpty(extendDataList[i].FieldValue.ToString()))
{
if (extendDataList[i].FieldValue.ToString().Contains(','))
{
string[] str = extendDataList[i].FieldValue.ToString().Split(',');
string changeStrResult = string.Empty;
for (int j = 0; j < str.Length; j++)
{
changeStrResult += (DictionaryManager.GetDictionaryList(tableExtend[0].DataDic, str[j]) + ",");
}
changeStrResult = changeStrResult.Substring(0, changeStrResult.Length-1);
dic.Add(extendDataList[i].FieldName.ToString(), changeStrResult);
}
else
{
dic.Add(extendDataList[i].FieldName.ToString(), DictionaryManager.GetDictionaryList(tableExtend[0].DataDic, extendDataList[i].FieldValue.ToString()));
}
}
else
{
dic.Add(extendDataList[i].FieldName.ToString(), extendDataList[i].FieldValue.ToString());
}
}
}
listDic.Add(dic);
}
fileName = DateTime.Now .ToString("yyyyMMddHHmmsss") + ".xlsx";
path = EPPlusHelper.ExportGeneralExcel(listDic, fileName);
}
catch (Exception ex)
{
Logger.Error($"解析表单出错:{fileName},错误信息{ex.Message}。");
return webResponse.Error("导出用户信息出错");
}
webResponse.Code = "-1";
return webResponse.OK(null, path);
};
return base.Export(pageData);
}
}
}

View File

@@ -0,0 +1,41 @@
/*
*所有关于Sys_VersionInfo类的业务代码应在此处编写
*可使用repository.调用常用方法获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*Sys_VersionInfoService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
using System.Linq;
using iMES.Core.Utilities;
using System.Linq.Expressions;
using iMES.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using iMES.System.IRepositories;
namespace iMES.System.Services
{
public partial class Sys_VersionInfoService
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ISys_VersionInfoRepository _repository;//访问数据库
[ActivatorUtilitiesConstructor]
public Sys_VersionInfoService(
ISys_VersionInfoRepository dbRepository,
IHttpContextAccessor httpContextAccessor
)
: base(dbRepository)
{
_httpContextAccessor = httpContextAccessor;
_repository = dbRepository;
//多租户会用到这init代码其他情况可以不用
//base.Init(dbRepository);
}
}
}

View File

@@ -0,0 +1,27 @@
/*
*Authorjxx
*Contact283591387@qq.com
*代码由框架生成,此处任何更改都可能导致被代码生成器覆盖
*所有业务编写全部应在Partial文件夹下Sys_DepartmentService与ISys_DepartmentService中编写
*/
using iMES.System.IRepositories;
using iMES.System.IServices;
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
namespace iMES.System.Services
{
public partial class Sys_DepartmentService : ServiceBase<Sys_Department, ISys_DepartmentRepository>
, ISys_DepartmentService, IDependency
{
public Sys_DepartmentService(ISys_DepartmentRepository repository)
: base(repository)
{
Init(repository);
}
public static ISys_DepartmentService Instance
{
get { return AutofacContainerModule.GetService<ISys_DepartmentService>(); } }
}
}

View File

@@ -0,0 +1,26 @@
/*
*AuthorCOCO
*代码由框架生成,此处任何更改都可能导致被代码生成器覆盖
*所有业务编写全部应在Partial文件夹下Sys_DeptService与ISys_DeptService中编写
*/
using iMES.System.IRepositories;
using iMES.System.IServices;
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
namespace iMES.System.Services
{
public partial class Sys_DeptService : ServiceBase<Sys_Dept, ISys_DeptRepository>
, ISys_DeptService, IDependency
{
public Sys_DeptService(ISys_DeptRepository repository)
: base(repository)
{
Init(repository);
}
public static ISys_DeptService Instance
{
get { return AutofacContainerModule.GetService<ISys_DeptService>(); } }
}
}

View File

@@ -0,0 +1,26 @@
/*
*AuthorCOCO
*代码由框架生成,此处任何更改都可能导致被代码生成器覆盖
*所有业务编写全部应在Partial文件夹下Sys_DeptTreeService与ISys_DeptTreeService中编写
*/
using iMES.System.IRepositories;
using iMES.System.IServices;
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
namespace iMES.System.Services
{
public partial class Sys_DeptTreeService : ServiceBase<Sys_DeptTree, ISys_DeptTreeRepository>
, ISys_DeptTreeService, IDependency
{
public Sys_DeptTreeService(ISys_DeptTreeRepository repository)
: base(repository)
{
Init(repository);
}
public static ISys_DeptTreeService Instance
{
get { return AutofacContainerModule.GetService<ISys_DeptTreeService>(); } }
}
}

View File

@@ -0,0 +1,26 @@
/*
*AuthorCOCO
*代码由框架生成,此处任何更改都可能导致被代码生成器覆盖
*所有业务编写全部应在Partial文件夹下Sys_DictionaryListService与ISys_DictionaryListService中编写
*/
using iMES.System.IRepositories;
using iMES.System.IServices;
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
namespace iMES.System.Services
{
public partial class Sys_DictionaryListService : ServiceBase<Sys_DictionaryList, ISys_DictionaryListRepository>
, ISys_DictionaryListService, IDependency
{
public Sys_DictionaryListService(ISys_DictionaryListRepository repository)
: base(repository)
{
Init(repository);
}
public static ISys_DictionaryListService Instance
{
get { return AutofacContainerModule.GetService<ISys_DictionaryListService>(); } }
}
}

View File

@@ -0,0 +1,26 @@
/*
*AuthorCOCO
* 此代码由框架生成,请勿随意更改
*/
using iMES.System.IRepositories;
using iMES.System.IServices;
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
namespace iMES.System.Services
{
public partial class Sys_DictionaryService : ServiceBase<Sys_Dictionary, ISys_DictionaryRepository>, ISys_DictionaryService, IDependency
{
public Sys_DictionaryService(ISys_DictionaryRepository repository)
: base(repository)
{
Init(repository);
}
public static ISys_DictionaryService Instance
{
get { return AutofacContainerModule.GetService<ISys_DictionaryService>(); }
}
}
}

View File

@@ -0,0 +1,22 @@
using iMES.System.IRepositories;
using iMES.System.IServices;
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
namespace iMES.System.Services
{
public partial class Sys_LogService : ServiceBase<Sys_Log, ISys_LogRepository>, ISys_LogService, IDependency
{
public Sys_LogService(ISys_LogRepository repository)
: base(repository)
{
Init(repository);
}
public static ISys_LogService Instance
{
get { return AutofacContainerModule.GetService<ISys_LogService>(); }
}
}
}

View File

@@ -0,0 +1,22 @@
using iMES.System.IRepositories;
using iMES.System.IServices;
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
namespace iMES.System.Services
{
public partial class Sys_MenuService : ServiceBase<Sys_Menu, ISys_MenuRepository>, ISys_MenuService, IDependency
{
public Sys_MenuService(ISys_MenuRepository repository)
: base(repository)
{
Init(repository);
}
public static ISys_MenuService Instance
{
get { return AutofacContainerModule.GetService<ISys_MenuService>(); }
}
}
}

View File

@@ -0,0 +1,26 @@
/*
*AuthorCOCO
* 此代码由框架生成,请勿随意更改
*/
using iMES.System.IRepositories;
using iMES.System.IServices;
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
namespace iMES.System.Services
{
public partial class Sys_RoleService : ServiceBase<Sys_Role, ISys_RoleRepository>, ISys_RoleService, IDependency
{
public Sys_RoleService(ISys_RoleRepository repository)
: base(repository)
{
Init(repository);
}
public static ISys_RoleService Instance
{
get { return AutofacContainerModule.GetService<ISys_RoleService>(); }
}
}
}

View File

@@ -0,0 +1,26 @@
/*
*AuthorCOCO
* 此代码由框架生成,请勿随意更改
*/
using iMES.System.IRepositories;
using iMES.System.IServices;
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
namespace iMES.System.Services
{
public partial class Sys_UserService : ServiceBase<Sys_User, ISys_UserRepository>, ISys_UserService, IDependency
{
public Sys_UserService(ISys_UserRepository repository)
: base(repository)
{
Init(repository);
}
public static ISys_UserService Instance
{
get { return AutofacContainerModule.GetService<ISys_UserService>(); }
}
}
}

View File

@@ -0,0 +1,26 @@
/*
*AuthorCOCO
*代码由框架生成,此处任何更改都可能导致被代码生成器覆盖
*所有业务编写全部应在Partial文件夹下Sys_VersionInfoService与ISys_VersionInfoService中编写
*/
using iMES.System.IRepositories;
using iMES.System.IServices;
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
namespace iMES.System.Services
{
public partial class Sys_VersionInfoService : ServiceBase<Sys_VersionInfo, ISys_VersionInfoRepository>
, ISys_VersionInfoService, IDependency
{
public Sys_VersionInfoService(ISys_VersionInfoRepository repository)
: base(repository)
{
Init(repository);
}
public static ISys_VersionInfoService Instance
{
get { return AutofacContainerModule.GetService<ISys_VersionInfoService>(); } }
}
}

View File

@@ -0,0 +1,26 @@
/*
*AuthorCOCO
* 此代码由框架生成,请勿随意更改
*/
using iMES.System.IRepositories;
using iMES.System.IServices;
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
namespace iMES.System.Services
{
public partial class vSys_DictionaryService : ServiceBase<vSys_Dictionary, IvSys_DictionaryRepository>, IvSys_DictionaryService, IDependency
{
public vSys_DictionaryService(IvSys_DictionaryRepository repository)
: base(repository)
{
Init(repository);
}
public static IvSys_DictionaryService Instance
{
get { return AutofacContainerModule.GetService<IvSys_DictionaryService>(); }
}
}
}

View File

@@ -0,0 +1,142 @@
/*
*所有关于Sys_WorkFlow类的业务代码应在此处编写
*可使用repository.调用常用方法获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*Sys_WorkFlowService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
using System.Linq;
using iMES.Core.Utilities;
using System.Linq.Expressions;
using iMES.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using iMES.System.IRepositories;
using System.Collections.Generic;
using iMES.Core.WorkFlow;
using System;
using iMES.System.Repositories;
namespace iMES.System.Services
{
public partial class Sys_WorkFlowService
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ISys_WorkFlowRepository _repository;//访问数据库
private readonly ISys_WorkFlowStepRepository _stepRepository;
[ActivatorUtilitiesConstructor]
public Sys_WorkFlowService(
ISys_WorkFlowRepository dbRepository,
IHttpContextAccessor httpContextAccessor,
ISys_WorkFlowStepRepository stepRepository
)
: base(dbRepository)
{
_httpContextAccessor = httpContextAccessor;
_repository = dbRepository;
_stepRepository = stepRepository;
//多租户会用到这init代码其他情况可以不用
//base.Init(dbRepository);
}
WebResponseContent webResponse = new WebResponseContent();
public override WebResponseContent Add(SaveModel saveDataModel)
{
saveDataModel.MainData["Enable"] = 1;
AddOnExecuting = (Sys_WorkFlow workFlow, object list) =>
{
workFlow.WorkFlow_Id = Guid.NewGuid();
webResponse= WorkFlowContainer.Instance.AddTable(workFlow, list as List<Sys_WorkFlowStep>);
if (!webResponse.Status)
{
return webResponse;
}
return webResponse.OK();
};
AddOnExecuted = (Sys_WorkFlow workFlow, object list) =>
{
return webResponse.OK();
};
return base.Add(saveDataModel);
}
public override WebResponseContent Update(SaveModel saveModel)
{
Sys_WorkFlow flow = null;
UpdateOnExecuting = (Sys_WorkFlow workFlow, object addList, object updateList, List<object> delKeys) =>
{
flow = workFlow;
if ((flow.AuditingEdit ?? 0) == 0)
{
if (Sys_WorkFlowTableRepository.Instance.Exists(x=>x.WorkFlow_Id==flow.WorkFlow_Id&&(x.AuditStatus == (int)AuditStatus.)))
{
return webResponse.Error("当前流程有审核中的数据,不能修改,可以修改,流程中的【审核中数据是否可以编辑】属性");
}
}
//新增的明细
List<Sys_WorkFlowStep> add = addList as List<Sys_WorkFlowStep>;
var stepsClone = add.Serialize().DeserializeObject<List<Sys_WorkFlowStep>>();
add.Clear();
var steps = _stepRepository.FindAsIQueryable(x => x.WorkFlow_Id == workFlow.WorkFlow_Id)
.Select(s => new { s.WorkStepFlow_Id, s.StepId })
.ToList();
//删除的节点
var delIds = steps.Where(x => !stepsClone.Any(c => c.StepId == x.StepId))
.Select(s => s.WorkStepFlow_Id).ToList();
delKeys.AddRange(delKeys);
//新增的节点
var newSteps = stepsClone.Where(x => !steps.Any(c => c.StepId == x.StepId))
.ToList();
add.AddRange(newSteps);
List<Sys_WorkFlowStep> update = updateList as List<Sys_WorkFlowStep>;
//修改的节点
var updateSteps = stepsClone.Where(x => steps.Any(c => c.StepId == x.StepId))
.ToList();
update.AddRange(updateSteps);
updateSteps.ForEach(x =>
{
x.WorkStepFlow_Id = steps.Where(c => c.StepId == x.StepId).Select(s => s.WorkStepFlow_Id).FirstOrDefault();
foreach (var item in saveModel.DetailData)
{
if (item["StepId"].ToString()==x.StepId)
{
item["WorkFlow_Id"] = workFlow.WorkFlow_Id;
item["WorkStepFlow_Id"] = x.WorkStepFlow_Id;
}
}
});
return webResponse.OK();
};
webResponse= base.Update(saveModel);
if (webResponse.Status)
{
flow= repository.FindAsIQueryable(x => x.WorkFlow_Id == flow.WorkFlow_Id).Include(x=>x.Sys_WorkFlowStep).FirstOrDefault();
webResponse = WorkFlowContainer.Instance.AddTable(flow,flow.Sys_WorkFlowStep);
}
return webResponse;
}
public override WebResponseContent Del(object[] keys, bool delList = true)
{
webResponse= base.Del(keys, delList);
if (webResponse.Status)
{
WorkFlowContainer.DelRange(keys.Select(s=>(Guid)s.GetGuid()).ToArray());
}
return webResponse;
}
}
}

View File

@@ -0,0 +1,43 @@
/*
*所有关于Sys_WorkFlowStep类的业务代码应在此处编写
*可使用repository.调用常用方法获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*Sys_WorkFlowStepService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
using System.Linq;
using iMES.Core.Utilities;
using System.Linq.Expressions;
using iMES.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using iMES.System.IRepositories;
namespace iMES.System.Services
{
public partial class Sys_WorkFlowStepService
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ISys_WorkFlowStepRepository _repository;//访问数据库
[ActivatorUtilitiesConstructor]
public Sys_WorkFlowStepService(
ISys_WorkFlowStepRepository dbRepository,
IHttpContextAccessor httpContextAccessor
)
: base(dbRepository)
{
_httpContextAccessor = httpContextAccessor;
_repository = dbRepository;
//多租户会用到这init代码其他情况可以不用
//base.Init(dbRepository);
}
}
}

View File

@@ -0,0 +1,41 @@
/*
*所有关于Sys_WorkFlowTableAuditLog类的业务代码应在此处编写
*可使用repository.调用常用方法获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*Sys_WorkFlowTableAuditLogService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
using System.Linq;
using iMES.Core.Utilities;
using System.Linq.Expressions;
using iMES.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using iMES.System.IRepositories;
namespace iMES.System.Services
{
public partial class Sys_WorkFlowTableAuditLogService
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ISys_WorkFlowTableAuditLogRepository _repository;//访问数据库
[ActivatorUtilitiesConstructor]
public Sys_WorkFlowTableAuditLogService(
ISys_WorkFlowTableAuditLogRepository dbRepository,
IHttpContextAccessor httpContextAccessor
)
: base(dbRepository)
{
_httpContextAccessor = httpContextAccessor;
_repository = dbRepository;
//多租户会用到这init代码其他情况可以不用
//base.Init(dbRepository);
}
}
}

View File

@@ -0,0 +1,64 @@
/*
*所有关于Sys_WorkFlowTable类的业务代码应在此处编写
*可使用repository.调用常用方法获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*Sys_WorkFlowTableService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
using System.Linq;
using iMES.Core.Utilities;
using System.Linq.Expressions;
using iMES.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using iMES.System.IRepositories;
using iMES.Core.ManageUser;
using iMES.Core.WorkFlow;
namespace iMES.System.Services
{
public partial class Sys_WorkFlowTableService
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ISys_WorkFlowTableRepository _repository;//访问数据库
private readonly ISys_WorkFlowTableStepRepository _stepRepository;//访问数据库
[ActivatorUtilitiesConstructor]
public Sys_WorkFlowTableService(
ISys_WorkFlowTableRepository dbRepository,
IHttpContextAccessor httpContextAccessor,
ISys_WorkFlowTableStepRepository stepRepository
)
: base(dbRepository)
{
_httpContextAccessor = httpContextAccessor;
_repository = dbRepository;
_stepRepository = stepRepository;
//多租户会用到这init代码其他情况可以不用
//base.Init(dbRepository);
}
public override PageGridData<Sys_WorkFlowTable> GetPageData(PageDataOptions options)
{
if (!UserContext.Current.IsSuperAdmin)
{
var user = UserContext.Current.UserInfo;
//显示当前用户需要审批的数据
var deptIds = user.DeptIds.Select(s => s.ToString());
var stepQuery = _stepRepository.FindAsIQueryable(x => (x.StepType == (int)AuditType. && x.StepValue == user.User_Id.ToString())
|| (x.StepType == (int)AuditType. && x.StepValue == user.Role_Id.ToString())
|| (x.StepType == (int)AuditType. && deptIds.Contains(x.StepValue))
);
QueryRelativeExpression = (IQueryable<Sys_WorkFlowTable> queryable) =>
{
return queryable.Where(x => stepQuery.Any(c => x.WorkFlowTable_Id == c.WorkFlowTable_Id));
};
}
return base.GetPageData(options);
}
}
}

View File

@@ -0,0 +1,41 @@
/*
*所有关于Sys_WorkFlowTableStep类的业务代码应在此处编写
*可使用repository.调用常用方法获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*Sys_WorkFlowTableStepService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
using System.Linq;
using iMES.Core.Utilities;
using System.Linq.Expressions;
using iMES.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using iMES.System.IRepositories;
namespace iMES.System.Services
{
public partial class Sys_WorkFlowTableStepService
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ISys_WorkFlowTableStepRepository _repository;//访问数据库
[ActivatorUtilitiesConstructor]
public Sys_WorkFlowTableStepService(
ISys_WorkFlowTableStepRepository dbRepository,
IHttpContextAccessor httpContextAccessor
)
: base(dbRepository)
{
_httpContextAccessor = httpContextAccessor;
_repository = dbRepository;
//多租户会用到这init代码其他情况可以不用
//base.Init(dbRepository);
}
}
}

View File

@@ -0,0 +1,26 @@
/*
*AuthorCOCO
*代码由框架生成,此处任何更改都可能导致被代码生成器覆盖
*所有业务编写全部应在Partial文件夹下Sys_WorkFlowService与ISys_WorkFlowService中编写
*/
using iMES.System.IRepositories;
using iMES.System.IServices;
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
namespace iMES.System.Services
{
public partial class Sys_WorkFlowService : ServiceBase<Sys_WorkFlow, ISys_WorkFlowRepository>
, ISys_WorkFlowService, IDependency
{
public Sys_WorkFlowService(ISys_WorkFlowRepository repository)
: base(repository)
{
Init(repository);
}
public static ISys_WorkFlowService Instance
{
get { return AutofacContainerModule.GetService<ISys_WorkFlowService>(); } }
}
}

View File

@@ -0,0 +1,26 @@
/*
*AuthorCOCO
*代码由框架生成,此处任何更改都可能导致被代码生成器覆盖
*所有业务编写全部应在Partial文件夹下Sys_WorkFlowStepService与ISys_WorkFlowStepService中编写
*/
using iMES.System.IRepositories;
using iMES.System.IServices;
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
namespace iMES.System.Services
{
public partial class Sys_WorkFlowStepService : ServiceBase<Sys_WorkFlowStep, ISys_WorkFlowStepRepository>
, ISys_WorkFlowStepService, IDependency
{
public Sys_WorkFlowStepService(ISys_WorkFlowStepRepository repository)
: base(repository)
{
Init(repository);
}
public static ISys_WorkFlowStepService Instance
{
get { return AutofacContainerModule.GetService<ISys_WorkFlowStepService>(); } }
}
}

View File

@@ -0,0 +1,25 @@
/*
*代码由框架生成,此处任何更改都可能导致被代码生成器覆盖
*所有业务编写全部应在Partial文件夹下Sys_WorkFlowTableAuditLogService与ISys_WorkFlowTableAuditLogService中编写
*/
using iMES.System.IRepositories;
using iMES.System.IServices;
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
namespace iMES.System.Services
{
public partial class Sys_WorkFlowTableAuditLogService : ServiceBase<Sys_WorkFlowTableAuditLog, ISys_WorkFlowTableAuditLogRepository>
, ISys_WorkFlowTableAuditLogService, IDependency
{
public Sys_WorkFlowTableAuditLogService(ISys_WorkFlowTableAuditLogRepository repository)
: base(repository)
{
Init(repository);
}
public static ISys_WorkFlowTableAuditLogService Instance
{
get { return AutofacContainerModule.GetService<ISys_WorkFlowTableAuditLogService>(); } }
}
}

View File

@@ -0,0 +1,26 @@
/*
*AuthorCOCO
*代码由框架生成,此处任何更改都可能导致被代码生成器覆盖
*所有业务编写全部应在Partial文件夹下Sys_WorkFlowTableService与ISys_WorkFlowTableService中编写
*/
using iMES.System.IRepositories;
using iMES.System.IServices;
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
namespace iMES.System.Services
{
public partial class Sys_WorkFlowTableService : ServiceBase<Sys_WorkFlowTable, ISys_WorkFlowTableRepository>
, ISys_WorkFlowTableService, IDependency
{
public Sys_WorkFlowTableService(ISys_WorkFlowTableRepository repository)
: base(repository)
{
Init(repository);
}
public static ISys_WorkFlowTableService Instance
{
get { return AutofacContainerModule.GetService<ISys_WorkFlowTableService>(); } }
}
}

View File

@@ -0,0 +1,26 @@
/*
*AuthorCOCO
*代码由框架生成,此处任何更改都可能导致被代码生成器覆盖
*所有业务编写全部应在Partial文件夹下Sys_WorkFlowTableStepService与ISys_WorkFlowTableStepService中编写
*/
using iMES.System.IRepositories;
using iMES.System.IServices;
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
namespace iMES.System.Services
{
public partial class Sys_WorkFlowTableStepService : ServiceBase<Sys_WorkFlowTableStep, ISys_WorkFlowTableStepRepository>
, ISys_WorkFlowTableStepService, IDependency
{
public Sys_WorkFlowTableStepService(ISys_WorkFlowTableStepRepository repository)
: base(repository)
{
Init(repository);
}
public static ISys_WorkFlowTableStepService Instance
{
get { return AutofacContainerModule.GetService<ISys_WorkFlowTableStepService>(); } }
}
}

View File

@@ -0,0 +1,26 @@
/*
*AuthorCOCO
*代码由框架生成,此处任何更改都可能导致被代码生成器覆盖
*所有业务编写全部应在Partial文件夹下FormCollectionObjectService与IFormCollectionObjectService中编写
*/
using iMES.System.IRepositories;
using iMES.System.IServices;
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
namespace iMES.System.Services
{
public partial class FormCollectionObjectService : ServiceBase<FormCollectionObject, IFormCollectionObjectRepository>
, IFormCollectionObjectService, IDependency
{
public FormCollectionObjectService(IFormCollectionObjectRepository repository)
: base(repository)
{
Init(repository);
}
public static IFormCollectionObjectService Instance
{
get { return AutofacContainerModule.GetService<IFormCollectionObjectService>(); } }
}
}

View File

@@ -0,0 +1,26 @@
/*
*AuthorCOCO
*代码由框架生成,此处任何更改都可能导致被代码生成器覆盖
*所有业务编写全部应在Partial文件夹下FormDesignOptionsService与IFormDesignOptionsService中编写
*/
using iMES.System.IRepositories;
using iMES.System.IServices;
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
namespace iMES.System.Services
{
public partial class FormDesignOptionsService : ServiceBase<FormDesignOptions, IFormDesignOptionsRepository>
, IFormDesignOptionsService, IDependency
{
public FormDesignOptionsService(IFormDesignOptionsRepository repository)
: base(repository)
{
Init(repository);
}
public static IFormDesignOptionsService Instance
{
get { return AutofacContainerModule.GetService<IFormDesignOptionsService>(); } }
}
}

View File

@@ -0,0 +1,100 @@
/*
*所有关于FormCollectionObject类的业务代码应在此处编写
*可使用repository.调用常用方法获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*FormCollectionObjectService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
using System.Linq;
using iMES.Core.Utilities;
using System.Linq.Expressions;
using iMES.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using iMES.System.IRepositories;
using System.Collections.Generic;
using iMES.Core.Configuration;
using iMES.Core.Services;
using System;
using OfficeOpenXml;
using System.IO;
using OfficeOpenXml.Style;
using System.Drawing;
namespace iMES.System.Services
{
public partial class FormCollectionObjectService
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IFormCollectionObjectRepository _repository;//访问数据库
private readonly IFormDesignOptionsRepository _designOptionsRepository;
[ActivatorUtilitiesConstructor]
public FormCollectionObjectService(
IFormCollectionObjectRepository dbRepository,
IHttpContextAccessor httpContextAccessor,
IFormDesignOptionsRepository designOptionsRepository
)
: base(dbRepository)
{
_httpContextAccessor = httpContextAccessor;
_repository = dbRepository;
_designOptionsRepository = designOptionsRepository;
}
public override WebResponseContent Export(PageDataOptions pageData)
{
string path = null;
string fileName = null;
WebResponseContent webResponse = new WebResponseContent();
ExportOnExecuting = (List<FormCollectionObject> list, List<string> columns) =>
{
var formId = list[0].FormId;
var data = _designOptionsRepository.FindAsIQueryable(x => x.FormId == formId)
.Select(s => new { s.Title, s.FormConfig }).FirstOrDefault();
try
{
List<FormOptions> formObj = data.FormConfig.DeserializeObject<List<FormOptions>>();
List<Dictionary<string, object>> listDic = new List<Dictionary<string, object>>();
foreach (var item in list)
{
Dictionary<string, object> dic = new Dictionary<string, object>();
var formData = item.FormData.DeserializeObject<Dictionary<string, string>>();
dic.Add("标题", data.Title);
dic.Add("提交人", item.Creator);
dic.Add("提交时间", item.CreateDate.ToString("yyyy-MM-dd HH:mm:sss"));
foreach (var obj in formObj)
{
dic.Add(obj.Title, formData.Where(x => x.Key == obj.Field).Select(s => s.Value).FirstOrDefault());
}
listDic.Add(dic);
}
fileName = data.Title + ".xlsx";
path = EPPlusHelper.ExportGeneralExcel(listDic, fileName);
}
catch (Exception ex)
{
Logger.Error($"解析表单出错:{data.Title},表单配置:{data.FormConfig},{ex.Message}");
return webResponse.Error("获取表单出错");
}
webResponse.Code = "-1";
return webResponse.OK(null, path.EncryptDES(AppSetting.Secret.ExportFile));
};
return base.Export(pageData);
}
}
public class FormOptions
{
public string Field { get; set; }
public string Title { get; set; }
public string Type { get; set; }
}
}

View File

@@ -0,0 +1,46 @@
/*
*所有关于FormDesignOptions类的业务代码应在此处编写
*可使用repository.调用常用方法获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*FormDesignOptionsService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
using System.Linq;
using iMES.Core.Utilities;
using System.Linq.Expressions;
using iMES.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using iMES.System.IRepositories;
namespace iMES.System.Services
{
public partial class FormDesignOptionsService
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IFormDesignOptionsRepository _repository;//访问数据库
[ActivatorUtilitiesConstructor]
public FormDesignOptionsService(
IFormDesignOptionsRepository dbRepository,
IHttpContextAccessor httpContextAccessor
)
: base(dbRepository)
{
_httpContextAccessor = httpContextAccessor;
_repository = dbRepository;
//多租户会用到这init代码其他情况可以不用
//base.Init(dbRepository);
}
public override PageGridData<FormDesignOptions> GetPageData(PageDataOptions options)
{
return base.GetPageData(options);
}
}
}