添加项目文件。
This commit is contained in:
11
WaterCloud.Service/AutoJob/IJobTask.cs
Normal file
11
WaterCloud.Service/AutoJob/IJobTask.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
|
||||
namespace WaterCloud.Service.AutoJob
|
||||
{
|
||||
public interface IJobTask
|
||||
{
|
||||
//执行方法
|
||||
Task<AlwaysResult> Start();
|
||||
}
|
||||
}
|
||||
32
WaterCloud.Service/AutoJob/IOCJobFactory.cs
Normal file
32
WaterCloud.Service/AutoJob/IOCJobFactory.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Quartz;
|
||||
using Quartz.Spi;
|
||||
using System;
|
||||
|
||||
namespace WaterCloud.Service.AutoJob
|
||||
{
|
||||
/// <summary>
|
||||
/// 依赖注入必须,代替原本的SimpleJobFactory
|
||||
/// </summary>
|
||||
public class IOCJobFactory : IJobFactory
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public IOCJobFactory(IServiceProvider serviceProvider)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
|
||||
{
|
||||
var serviceScope = _serviceProvider.CreateScope(); // 获得一个ioc对象,指定创建scope级别的实例(在job里面需要依赖注入ef,但是startup里面配置的ef是scope级别的,必须指定为scope,不然报错)。不写的话,默认是单例。
|
||||
return serviceScope.ServiceProvider.GetService(bundle.JobDetail.JobType) as IJob; // 依赖注入一个 job 然后返回
|
||||
}
|
||||
|
||||
public void ReturnJob(IJob job)
|
||||
{
|
||||
var disposable = job as IDisposable;
|
||||
disposable?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
46
WaterCloud.Service/AutoJob/Job/SaveServerStateJob.cs
Normal file
46
WaterCloud.Service/AutoJob/Job/SaveServerStateJob.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.Domain.SystemSecurity;
|
||||
using WaterCloud.Service.SystemSecurity;
|
||||
|
||||
namespace WaterCloud.Service.AutoJob
|
||||
{
|
||||
[ServiceDescription("服务器监控")]
|
||||
public class SaveServerStateJob : IJobTask
|
||||
{
|
||||
private IWebHostEnvironment _hostingEnvironment;
|
||||
private ServerStateService _server;
|
||||
|
||||
public SaveServerStateJob(ISqlSugarClient context)
|
||||
{
|
||||
_hostingEnvironment = GlobalContext.HostingEnvironment;
|
||||
_server = new ServerStateService(context);
|
||||
}
|
||||
|
||||
public async Task<AlwaysResult> Start()
|
||||
{
|
||||
AlwaysResult obj = new AlwaysResult();
|
||||
try
|
||||
{
|
||||
ServerStateEntity entity = new ServerStateEntity();
|
||||
var computer = ComputerHelper.GetComputerInfo();
|
||||
entity.F_ARM = computer.RAMRate;
|
||||
entity.F_CPU = computer.CPURate;
|
||||
entity.F_IIS = "0";
|
||||
entity.F_WebSite = _hostingEnvironment.ContentRootPath;
|
||||
await _server.SubmitForm(entity);
|
||||
obj.state = ResultType.success.ToString();
|
||||
obj.message = "服务器状态更新成功!";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
obj.state = ResultType.error.ToString();
|
||||
obj.message = "服务器状态更新失败!" + ex.Message;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
146
WaterCloud.Service/AutoJob/JobCenter.cs
Normal file
146
WaterCloud.Service/AutoJob/JobCenter.cs
Normal file
@@ -0,0 +1,146 @@
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Quartz;
|
||||
using Quartz.Impl.Triggers;
|
||||
using Quartz.Spi;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.Domain.SystemSecurity;
|
||||
using WaterCloud.Service.SystemSecurity;
|
||||
|
||||
namespace WaterCloud.Service.AutoJob
|
||||
{
|
||||
/// <summary>
|
||||
/// quartz 主机服务
|
||||
/// </summary>
|
||||
[DisallowConcurrentExecution]
|
||||
public class JobCenter : IHostedService
|
||||
{
|
||||
/// <summary>
|
||||
/// 定时作业计划生成工厂,这一项在startup有配置集群模式
|
||||
/// </summary>
|
||||
private readonly ISchedulerFactory _schedulerFactory;
|
||||
|
||||
/// <summary>
|
||||
/// 定时作业工厂
|
||||
/// </summary>
|
||||
private readonly IJobFactory _jobFactory;
|
||||
|
||||
private OpenJobsService _service;
|
||||
private IScheduler _scheduler;
|
||||
|
||||
/// <summary>
|
||||
/// 构造注入
|
||||
/// </summary>
|
||||
public JobCenter(OpenJobsService service, ISchedulerFactory schedulerFactory, IJobFactory jobFactory)
|
||||
{
|
||||
_service = service;
|
||||
_jobFactory = jobFactory;
|
||||
_schedulerFactory = schedulerFactory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量启动定时任务
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_scheduler = await _schedulerFactory.GetScheduler(cancellationToken);
|
||||
_scheduler.JobFactory = _jobFactory;
|
||||
if (GlobalContext.SystemConfig.IsCluster == false || GlobalContext.SystemConfig.NeedClear == true)
|
||||
{
|
||||
await _scheduler.Clear();
|
||||
}
|
||||
List<OpenJobEntity> obj = await _service.GetAllList(null);
|
||||
obj = obj.Where(a => a.F_EnabledMark == true).ToList();
|
||||
if (obj.Count > 0)
|
||||
{
|
||||
await AddScheduleJob(obj, cancellationToken);
|
||||
}
|
||||
await _scheduler.Start();
|
||||
//if (!GlobalContext.SystemConfig.Debug)
|
||||
//{
|
||||
// List<OpenJobEntity> obj = await new OpenJobService().GetList(null);
|
||||
// if (obj.Count>0)
|
||||
// {
|
||||
// AddScheduleJob(obj);
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
public async Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await ClearScheduleJob();
|
||||
}
|
||||
|
||||
#region 添加任务计划
|
||||
|
||||
/// <summary>
|
||||
/// 添加任务计划
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task AddScheduleJob(List<OpenJobEntity> entityList, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (OpenJobEntity entity in entityList)
|
||||
{
|
||||
entity.F_StarRunTime = DateTime.Now;
|
||||
entity.F_EndRunTime = DateTime.Now.AddSeconds(-1);
|
||||
DateTimeOffset starRunTime = DateBuilder.NextGivenSecondDate(entity.F_StarRunTime, 1);
|
||||
DateTimeOffset endRunTime = DateBuilder.NextGivenSecondDate(DateTime.MaxValue.AddDays(-1), 1);
|
||||
await _service.SubmitForm(entity, entity.F_Id);
|
||||
|
||||
ICronTrigger trigger = (ICronTrigger)TriggerBuilder.Create()
|
||||
.StartAt(starRunTime)
|
||||
.EndAt(endRunTime)
|
||||
.WithIdentity(entity.F_JobName, entity.F_JobGroup)
|
||||
.WithCronSchedule(entity.F_CronExpress)
|
||||
.Build();
|
||||
((CronTriggerImpl)trigger).MisfireInstruction = MisfireInstruction.CronTrigger.DoNothing;
|
||||
// 判断数据库中有没有记录过,有的话,quartz会自动从数据库中提取信息创建 schedule
|
||||
if (!await _scheduler.CheckExists(new JobKey(entity.F_JobName, entity.F_JobGroup)))
|
||||
{
|
||||
IJobDetail job = JobBuilder.Create<JobExecute>().WithIdentity(entity.F_JobName, entity.F_JobGroup).Build();
|
||||
job.JobDataMap.Add("F_Id", entity.F_Id);
|
||||
await _scheduler.ScheduleJob(job, trigger, cancellationToken);
|
||||
//存在相同名字的Job或Trigger,更新调度任务
|
||||
//IList<ICronTrigger> triggers = new List<ICronTrigger> { trigger };
|
||||
//await _scheduler.ScheduleJob(job, new ReadOnlyCollection<ICronTrigger>(triggers), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteWithTime(ex);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion 添加任务计划
|
||||
|
||||
#region 清除任务计划
|
||||
|
||||
/// <summary>
|
||||
/// 清除任务计划
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task ClearScheduleJob()
|
||||
{
|
||||
try
|
||||
{
|
||||
await _scheduler.Clear();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteWithTime(ex);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion 清除任务计划
|
||||
}
|
||||
}
|
||||
218
WaterCloud.Service/AutoJob/JobExecute.cs
Normal file
218
WaterCloud.Service/AutoJob/JobExecute.cs
Normal file
@@ -0,0 +1,218 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Quartz;
|
||||
using Quartz.Impl.Triggers;
|
||||
using Quartz.Spi;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.DataBase;
|
||||
using WaterCloud.Domain.SystemSecurity;
|
||||
using WaterCloud.Service.SystemSecurity;
|
||||
|
||||
namespace WaterCloud.Service.AutoJob
|
||||
{
|
||||
public class JobExecute : IJob
|
||||
{
|
||||
private IScheduler _scheduler;
|
||||
private ISchedulerFactory _schedulerFactory;
|
||||
private IJobFactory _iocJobfactory;
|
||||
private readonly IHttpClientFactory _httpClient;
|
||||
public JobExecute(ISchedulerFactory schedulerFactory, IJobFactory iocJobfactory, IHttpClientFactory httpClient)
|
||||
{
|
||||
_scheduler = schedulerFactory.GetScheduler().GetAwaiter().GetResult();
|
||||
_scheduler.JobFactory = iocJobfactory;
|
||||
_schedulerFactory = schedulerFactory;
|
||||
_iocJobfactory = iocJobfactory;
|
||||
_httpClient = httpClient;
|
||||
}
|
||||
|
||||
public Task Execute(IJobExecutionContext context)
|
||||
{
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
using var dbContext = new SqlSugarClient(DBInitialize.GetConnectionConfigs(true),
|
||||
//全局上下文生效
|
||||
db =>
|
||||
{
|
||||
foreach (var item in DBInitialize.GetConnectionConfigs(false))
|
||||
{
|
||||
db.GetConnection(item.ConfigId).DefaultConfig();
|
||||
}
|
||||
});
|
||||
string jobId = "";
|
||||
JobDataMap jobData = null;
|
||||
OpenJobEntity dbJobEntity = null;
|
||||
DateTime now = DateTime.Now;
|
||||
try
|
||||
{
|
||||
jobData = context.JobDetail.JobDataMap;
|
||||
jobId = jobData.GetString("F_Id");
|
||||
// 获取数据库中的任务
|
||||
dbJobEntity = await dbContext.Queryable<OpenJobEntity>().Where(a=>a.F_Id== jobId).FirstAsync();
|
||||
if (dbJobEntity != null)
|
||||
{
|
||||
if (dbJobEntity.F_EnabledMark == true)
|
||||
{
|
||||
CronTriggerImpl trigger = context.Trigger as CronTriggerImpl;
|
||||
if (trigger != null)
|
||||
{
|
||||
if (trigger.CronExpressionString != dbJobEntity.F_CronExpress)
|
||||
{
|
||||
// 更新任务周期
|
||||
trigger.CronExpressionString = dbJobEntity.F_CronExpress;
|
||||
await _scheduler.RescheduleJob(trigger.Key, trigger);
|
||||
return;
|
||||
}
|
||||
|
||||
#region 执行任务
|
||||
|
||||
OpenJobLogEntity log = new OpenJobLogEntity();
|
||||
log.F_Id = Utils.GuId();
|
||||
log.F_JobId = jobId;
|
||||
log.F_JobName = dbJobEntity.F_JobName;
|
||||
log.F_CreatorTime = now;
|
||||
AlwaysResult result = new AlwaysResult();
|
||||
if (dbJobEntity.F_JobType == 0)
|
||||
{
|
||||
//反射执行就行
|
||||
var path = AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory;
|
||||
//反射取指定前后缀的dll
|
||||
var referencedAssemblies = Directory.GetFiles(path, "WaterCloud.*.dll").Select(Assembly.LoadFrom).ToArray();
|
||||
var types = referencedAssemblies
|
||||
.SelectMany(a => a.GetTypes().Where(t => t.GetInterfaces()
|
||||
.Contains(typeof(IJobTask)))).ToArray();
|
||||
string filename = dbJobEntity.F_FileName;
|
||||
var implementType = types.Where(x => x.IsClass && x.FullName == filename).FirstOrDefault();
|
||||
var obj = System.Activator.CreateInstance(implementType, dbContext); // 创建实例(带参数)
|
||||
MethodInfo method = implementType.GetMethod("Start", new Type[] { }); // 获取方法信息
|
||||
object[] parameters = null;
|
||||
result = ((Task<AlwaysResult>)method.Invoke(obj, parameters)).GetAwaiter().GetResult(); // 调用方法,参数为空
|
||||
if (result.state.ToString() == ResultType.success.ToString())
|
||||
{
|
||||
log.F_EnabledMark = true;
|
||||
log.F_Description = "执行成功," + result.message.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
log.F_EnabledMark = false;
|
||||
log.F_Description = "执行失败," + result.message.ToString();
|
||||
}
|
||||
}
|
||||
else if (dbJobEntity.F_JobType == 5)
|
||||
{
|
||||
var dbContextTemp = dbContext.AsTenant().GetConnectionScope(dbJobEntity.F_JobDBProvider);
|
||||
try
|
||||
{
|
||||
dbContextTemp.Ado.BeginTran();
|
||||
if (!string.IsNullOrEmpty(dbJobEntity.F_JobSqlParm))
|
||||
{
|
||||
var dic = dbJobEntity.F_JobSqlParm.ToObject<Dictionary<string, object>>();
|
||||
List<SugarParameter> list = new List<SugarParameter>();
|
||||
foreach (var item in dic)
|
||||
{
|
||||
list.Add(new SugarParameter(item.Key, item.Value));
|
||||
}
|
||||
var dbResult = await dbContextTemp.Ado.SqlQueryAsync<dynamic>(dbJobEntity.F_JobSql, list);
|
||||
log.F_EnabledMark = true;
|
||||
log.F_Description = "执行成功," + dbResult.ToJson();
|
||||
}
|
||||
else
|
||||
{
|
||||
var dbResult = await dbContextTemp.Ado.SqlQueryAsync<dynamic>(dbJobEntity.F_JobSql);
|
||||
log.F_EnabledMark = true;
|
||||
log.F_Description = "执行成功," + dbResult.ToJson();
|
||||
}
|
||||
dbContextTemp.Ado.CommitTran();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.F_EnabledMark = false;
|
||||
log.F_Description = "执行失败," + ex.Message;
|
||||
dbContextTemp.Ado.RollbackTran();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
HttpMethod method = HttpMethod.Get;
|
||||
switch (dbJobEntity.F_JobType)
|
||||
{
|
||||
case 1:
|
||||
method = HttpMethod.Get;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
method = HttpMethod.Post;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
method = HttpMethod.Put;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
method = HttpMethod.Delete;
|
||||
break;
|
||||
}
|
||||
var dic = dbJobEntity.F_RequestHeaders.ToObject<Dictionary<string, string>>();
|
||||
if (dic == null)
|
||||
{
|
||||
dic = new Dictionary<string, string>();
|
||||
}
|
||||
//请求头添加租户号
|
||||
dic.Add("dbNumber", dbJobEntity.F_DbNumber);
|
||||
try
|
||||
{
|
||||
var temp = await new HttpWebClient(_httpClient).ExecuteAsync(dbJobEntity.F_RequestUrl, method, dbJobEntity.F_RequestString, dic);
|
||||
log.F_EnabledMark = true;
|
||||
log.F_Description = $"执行成功。{temp}";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.F_EnabledMark = false;
|
||||
log.F_Description = "执行失败," + ex.Message.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion 执行任务
|
||||
|
||||
dbContext.Ado.BeginTran();
|
||||
if (log.F_EnabledMark == true)
|
||||
{
|
||||
await dbContext.Updateable<OpenJobEntity>(a => new OpenJobEntity
|
||||
{
|
||||
F_LastRunMark = true,
|
||||
F_LastRunTime = now,
|
||||
}).Where(a => a.F_Id == jobId).ExecuteCommandAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
await dbContext.Updateable<OpenJobEntity>(a => new OpenJobEntity
|
||||
{
|
||||
F_LastRunMark = false,
|
||||
F_LastRunTime = now,
|
||||
F_LastRunErrTime = now,
|
||||
F_LastRunErrMsg = log.F_Description
|
||||
}).Where(a => a.F_Id == jobId).ExecuteCommandAsync();
|
||||
}
|
||||
if (dbJobEntity.F_IsLog == "是")
|
||||
{
|
||||
dbContext.Insertable(log).ExecuteCommand();
|
||||
}
|
||||
dbContext.Ado.CommitTran();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteWithTime(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
104
WaterCloud.Service/ContentManage/ArticleCategoryService.cs
Normal file
104
WaterCloud.Service/ContentManage/ArticleCategoryService.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.DataBase;
|
||||
using WaterCloud.Domain.ContentManage;
|
||||
|
||||
namespace WaterCloud.Service.ContentManage
|
||||
{
|
||||
/// <summary>
|
||||
/// 创 建:超级管理员
|
||||
/// 日 期:2020-06-09 19:42
|
||||
/// 描 述:新闻类别服务类
|
||||
/// </summary>
|
||||
public class ArticleCategoryService : BaseService<ArticleCategoryEntity>, IDenpendency
|
||||
{
|
||||
public ArticleCategoryService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
#region 获取数据
|
||||
|
||||
public async Task<List<ArticleCategoryEntity>> GetList(string keyword = "")
|
||||
{
|
||||
var query = repository.IQueryable();
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
//此处需修改
|
||||
query = query.Where(a => a.F_FullName.Contains(keyword) || a.F_Description.Contains(keyword));
|
||||
}
|
||||
return await query.Where(a => a.F_DeleteMark == false).OrderBy(a => a.F_Id, OrderByType.Desc).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<ArticleCategoryEntity>> GetLookList(string keyword = "")
|
||||
{
|
||||
var query = repository.IQueryable().Where(a => a.F_DeleteMark == false);
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_FullName.Contains(keyword) || a.F_Description.Contains(keyword));
|
||||
}
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
return await query.OrderBy(a => a.F_Id, OrderByType.Desc).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<ArticleCategoryEntity>> GetLookList(Pagination pagination, string keyword = "")
|
||||
{
|
||||
var query = repository.IQueryable().Where(a => a.F_DeleteMark == false);
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_FullName.Contains(keyword) || a.F_Description.Contains(keyword));
|
||||
}
|
||||
//权限过滤
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
return await query.ToPageListAsync(pagination);
|
||||
}
|
||||
|
||||
public async Task<ArticleCategoryEntity> GetForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<ArticleCategoryEntity> GetLookForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return GetFieldsFilterData(data);
|
||||
}
|
||||
|
||||
#endregion 获取数据
|
||||
|
||||
#region 提交数据
|
||||
|
||||
public async Task SubmitForm(ArticleCategoryEntity entity, string keyValue)
|
||||
{
|
||||
if (string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
entity.F_DeleteMark = false;
|
||||
//此处需修改
|
||||
entity.Create();
|
||||
await repository.Insert(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
//此处需修改
|
||||
entity.Modify(keyValue);
|
||||
await repository.Update(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteForm(string keyValue)
|
||||
{
|
||||
var ids = keyValue.Split(',');
|
||||
if (await repository.Db.Queryable<ArticleNewsEntity>().Where(a => ids.Contains(a.F_CategoryId)).AnyAsync())
|
||||
{
|
||||
throw new Exception("新闻类别使用中,无法删除");
|
||||
}
|
||||
await repository.Delete(t => ids.Contains(t.F_Id));
|
||||
}
|
||||
|
||||
#endregion 提交数据
|
||||
}
|
||||
}
|
||||
142
WaterCloud.Service/ContentManage/ArticleNewsService.cs
Normal file
142
WaterCloud.Service/ContentManage/ArticleNewsService.cs
Normal file
@@ -0,0 +1,142 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.DataBase;
|
||||
using WaterCloud.Domain.ContentManage;
|
||||
|
||||
namespace WaterCloud.Service.ContentManage
|
||||
{
|
||||
/// <summary>
|
||||
/// 创 建:超级管理员
|
||||
/// 日 期:2020-06-09 19:42
|
||||
/// 描 述:新闻管理服务类
|
||||
/// </summary>
|
||||
public class ArticleNewsService : BaseService<ArticleNewsEntity>, IDenpendency
|
||||
{
|
||||
public ArticleNewsService(ISqlSugarClient context) : base(context)
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
#region 获取数据
|
||||
|
||||
public async Task<List<ArticleNewsEntity>> GetList(string keyword = "")
|
||||
{
|
||||
var query = repository.IQueryable();
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_Title.Contains(keyword) || a.F_Tags.Contains(keyword));
|
||||
}
|
||||
return await query.Where(a => a.F_DeleteMark == false).OrderBy(a => a.F_Id, OrderByType.Desc).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<ArticleNewsEntity>> GetLookList(SoulPage<ArticleNewsEntity> pagination, string keyword = "", string CategoryId = "")
|
||||
{
|
||||
//反格式化显示只能用"等于",其他不支持
|
||||
Dictionary<string, Dictionary<string, string>> dic = new Dictionary<string, Dictionary<string, string>>();
|
||||
Dictionary<string, string> enabledTemp = new Dictionary<string, string>();
|
||||
enabledTemp.Add("1", "有效");
|
||||
enabledTemp.Add("0", "无效");
|
||||
dic.Add("F_EnabledMark", enabledTemp);
|
||||
Dictionary<string, string> isTrue = new Dictionary<string, string>();
|
||||
isTrue.Add("1", "是");
|
||||
isTrue.Add("0", "否");
|
||||
dic.Add("F_IsTop", isTrue);
|
||||
dic.Add("F_IsHot", isTrue);
|
||||
pagination = ChangeSoulData(dic, pagination);
|
||||
//获取新闻列表
|
||||
var query = repository.Db.Queryable<ArticleNewsEntity, ArticleCategoryEntity>((a, b) => new JoinQueryInfos(
|
||||
JoinType.Left, a.F_CategoryId == b.F_Id && b.F_EnabledMark == true
|
||||
))
|
||||
.Select((a, b) => new ArticleNewsEntity
|
||||
{
|
||||
F_Id = a.F_Id.SelectAll(),
|
||||
F_CategoryName = b.F_FullName,
|
||||
}).MergeTable();
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_Title.Contains(keyword));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(CategoryId))
|
||||
{
|
||||
query = query.Where(a => a.F_CategoryId.Contains(CategoryId));
|
||||
}
|
||||
query = query.Where(a => a.F_DeleteMark == false);
|
||||
//权限过滤
|
||||
query = GetDataPrivilege<ArticleNewsEntity>("a", "", query);
|
||||
return await query.ToPageListAsync(pagination);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取新闻详情
|
||||
/// </summary>
|
||||
/// <param name="keyValue">主键值</param>
|
||||
/// <returns></returns>
|
||||
public async Task<ArticleNewsEntity> GetForm(string keyValue)
|
||||
{
|
||||
var query = repository.Db.Queryable<ArticleNewsEntity, ArticleCategoryEntity>((a, b) => new JoinQueryInfos(
|
||||
JoinType.Left, a.F_CategoryId == b.F_Id && b.F_EnabledMark == true
|
||||
))
|
||||
.Select((a, b) => new ArticleNewsEntity
|
||||
{
|
||||
F_Id = a.F_Id.SelectAll(),
|
||||
F_CategoryName = b.F_FullName,
|
||||
}).MergeTable();
|
||||
if (!string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
query = query.Where(a => a.F_Id == keyValue);
|
||||
}
|
||||
//字段权限处理
|
||||
return GetFieldsFilterData(await query.FirstAsync());
|
||||
}
|
||||
|
||||
#endregion 获取数据
|
||||
|
||||
#region 提交数据
|
||||
|
||||
public async Task SubmitForm(ArticleNewsEntity entity, string keyValue)
|
||||
{
|
||||
if (string.IsNullOrEmpty(entity.F_Zhaiyao))
|
||||
{
|
||||
entity.F_Zhaiyao = TextHelper.GetSubString(WebHelper.NoHtml(entity.F_Description), 255);
|
||||
}
|
||||
if (string.IsNullOrEmpty(entity.F_SeoTitle))
|
||||
{
|
||||
entity.F_SeoTitle = entity.F_Title;
|
||||
}
|
||||
if (string.IsNullOrEmpty(entity.F_SeoKeywords))
|
||||
{
|
||||
entity.F_SeoKeywords = entity.F_Zhaiyao;
|
||||
}
|
||||
if (string.IsNullOrEmpty(entity.F_SeoDescription))
|
||||
{
|
||||
entity.F_SeoDescription = entity.F_Zhaiyao;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
entity.F_DeleteMark = false;
|
||||
//此处需修改
|
||||
entity.Create();
|
||||
await repository.Insert(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
//此处需修改
|
||||
entity.Modify(keyValue);
|
||||
await repository.Update(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteForm(string keyValue)
|
||||
{
|
||||
var ids = keyValue.Split(',');
|
||||
await repository.Delete(a => ids.Contains(a.F_Id));
|
||||
}
|
||||
|
||||
#endregion 提交数据
|
||||
}
|
||||
}
|
||||
47
WaterCloud.Service/Event/BaseEventSource.cs
Normal file
47
WaterCloud.Service/Event/BaseEventSource.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using Jaina;
|
||||
using System.Threading;
|
||||
using System;
|
||||
using WaterCloud.Code;
|
||||
|
||||
namespace WaterCloud.Service.Event
|
||||
{
|
||||
public class BaseEventSource : IEventSource
|
||||
{
|
||||
public BaseEventSource()
|
||||
{
|
||||
}
|
||||
public BaseEventSource(string eventId, object payload, OperatorModel user = null)
|
||||
{
|
||||
EventId = eventId;
|
||||
Payload = payload;
|
||||
User = user;
|
||||
}
|
||||
// 自定义属性
|
||||
public string ToDoName { get; set; }
|
||||
/// <summary>
|
||||
/// 事件 Id
|
||||
/// </summary>
|
||||
public string EventId { get; set; }
|
||||
/// <summary>
|
||||
/// 事件承载(携带)数据
|
||||
/// </summary>
|
||||
public object Payload { get; set; }
|
||||
/// <summary>
|
||||
/// 事件创建时间
|
||||
/// </summary>
|
||||
public DateTime CreatedTime { get; set; } = DateTime.Now;
|
||||
/// <summary>
|
||||
/// 当前用户信息
|
||||
/// </summary>
|
||||
public OperatorModel User { get; set; }
|
||||
/// <summary>
|
||||
/// 取消任务 Token
|
||||
/// </summary>
|
||||
/// <remarks>用于取消本次消息处理</remarks>
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public CancellationToken CancellationToken { get; set; }
|
||||
|
||||
public bool IsConsumOnce => true;
|
||||
}
|
||||
}
|
||||
38
WaterCloud.Service/Event/LogEventSubscriber.cs
Normal file
38
WaterCloud.Service/Event/LogEventSubscriber.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Jaina;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SqlSugar;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.Domain.SystemSecurity;
|
||||
using WaterCloud.Service.SystemSecurity;
|
||||
|
||||
namespace WaterCloud.Service.Event
|
||||
{
|
||||
// 实现 IEventSubscriber 接口
|
||||
public class LogEventSubscriber : IEventSubscriber
|
||||
{
|
||||
|
||||
public LogEventSubscriber()
|
||||
{
|
||||
}
|
||||
|
||||
[EventSubscribe("Log:create")]
|
||||
public async Task SendMessages(EventHandlerExecutingContext context)
|
||||
{
|
||||
var todo = (BaseEventSource)context.Source;
|
||||
var input = (LogEntity)todo.Payload;
|
||||
var user = todo.User;
|
||||
using var dbContext = new SqlSugarClient(DBInitialize.GetConnectionConfigs(true),
|
||||
//全局上下文生效
|
||||
db =>
|
||||
{
|
||||
foreach (var item in DBInitialize.GetConnectionConfigs(false))
|
||||
{
|
||||
db.GetConnection(item.ConfigId).DefaultConfig();
|
||||
}
|
||||
});
|
||||
await new LogService(dbContext).WriteDbLog(input, user);
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
58
WaterCloud.Service/Event/MessageEventSubscriber.cs
Normal file
58
WaterCloud.Service/Event/MessageEventSubscriber.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using Jaina;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.Domain.InfoManage;
|
||||
|
||||
namespace WaterCloud.Service.Event
|
||||
{
|
||||
// 实现 IEventSubscriber 接口
|
||||
public class MessageEventSubscriber : IEventSubscriber
|
||||
{
|
||||
private readonly IHubContext<MessageHub> _messageHub;
|
||||
private string cacheHubKey = GlobalContext.SystemConfig.ProjectPrefix + "_hubuserinfo_";
|
||||
|
||||
public MessageEventSubscriber(IHubContext<MessageHub> messageHub)
|
||||
{
|
||||
_messageHub = messageHub;
|
||||
}
|
||||
|
||||
[EventSubscribe("Message:send")] // 支持多个
|
||||
public async Task SendMessage(EventHandlerExecutingContext context)
|
||||
{
|
||||
var todo = (BaseEventSource)context.Source;
|
||||
var input = (MessageEntity)todo.Payload;
|
||||
if (!string.IsNullOrEmpty(input.companyId) && input.F_ToUserId.Length == 0)
|
||||
{
|
||||
await _messageHub.Clients.Group(input.companyId).SendAsync("ReceiveMessage", input.ToJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
var users = input.F_ToUserId.Split(',');
|
||||
foreach (var item in users)
|
||||
{
|
||||
//存在就私信
|
||||
var connectionIDs = await CacheHelper.GetAsync<List<string>>(cacheHubKey + item);
|
||||
if (connectionIDs == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
foreach (var connectionID in connectionIDs)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _messageHub.Clients.Client(connectionID).SendAsync("ReceiveMessage", input.ToJson());
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
117
WaterCloud.Service/Event/RabbitMQEventSourceStorer.cs
Normal file
117
WaterCloud.Service/Event/RabbitMQEventSourceStorer.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using Jaina;
|
||||
using RabbitMQ.Client;
|
||||
using RabbitMQ.Client.Events;
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Channels;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WaterCloud.Service.Event
|
||||
{
|
||||
public sealed class RabbitMQEventSourceStorer : IEventSourceStorer, IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// 内存通道事件源存储器
|
||||
/// </summary>
|
||||
private readonly Channel<IEventSource> _channel;
|
||||
/// <summary>
|
||||
/// 通道对象
|
||||
/// </summary>
|
||||
private readonly IModel _model;
|
||||
/// <summary>
|
||||
/// 连接对象
|
||||
/// </summary>
|
||||
private readonly IConnection _connection;
|
||||
/// <summary>
|
||||
/// 路由键
|
||||
/// </summary>
|
||||
private readonly string _routeKey;
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="factory">连接工厂</param>
|
||||
/// <param name="routeKey">路由键</param>
|
||||
/// <param name="capacity">存储器最多能够处理多少消息,超过该容量进入等待写入</param>
|
||||
public RabbitMQEventSourceStorer(ConnectionFactory factory, string routeKey, int capacity)
|
||||
{
|
||||
// 配置通道,设置超出默认容量后进入等待
|
||||
var boundedChannelOptions = new BoundedChannelOptions(capacity)
|
||||
{
|
||||
FullMode = BoundedChannelFullMode.Wait
|
||||
};
|
||||
// 创建有限容量通道
|
||||
_channel = Channel.CreateBounded<IEventSource>(boundedChannelOptions);
|
||||
// 创建连接
|
||||
_connection = factory.CreateConnection();
|
||||
_routeKey = routeKey;
|
||||
// 创建通道
|
||||
_model = _connection.CreateModel();
|
||||
// 声明路由队列
|
||||
_model.QueueDeclare(routeKey, false, false, false, null);
|
||||
// 创建消息订阅者
|
||||
var consumer = new EventingBasicConsumer(_model);
|
||||
// 订阅消息并写入内存 Channel
|
||||
consumer.Received += (ch, ea) =>
|
||||
{
|
||||
// 读取原始消息
|
||||
var stringEventSource = Encoding.UTF8.GetString(ea.Body.ToArray());
|
||||
// 转换为 IEventSource,这里可以选择自己喜欢的序列化工具,如果自定义了 EventSource,注意属性是可读可写
|
||||
var eventSource = JsonSerializer.Deserialize<BaseEventSource>(stringEventSource);
|
||||
// 写入内存管道存储器
|
||||
_channel.Writer.WriteAsync(eventSource);
|
||||
// 确认该消息已被消费
|
||||
_model.BasicAck(ea.DeliveryTag, false);
|
||||
};
|
||||
// 启动消费者 设置为手动应答消息
|
||||
_model.BasicConsume(routeKey, false, consumer);
|
||||
}
|
||||
/// <summary>
|
||||
/// 将事件源写入存储器
|
||||
/// </summary>
|
||||
/// <param name="eventSource">事件源对象</param>
|
||||
/// <param name="cancellationToken">取消任务 Token</param>
|
||||
/// <returns><see cref="ValueTask"/></returns>
|
||||
public async ValueTask WriteAsync(IEventSource eventSource, CancellationToken cancellationToken)
|
||||
{
|
||||
// 空检查
|
||||
if (eventSource == default)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(eventSource));
|
||||
}
|
||||
// 这里判断是否是 ChannelEventSource 或者 自定义的 EventSource
|
||||
if (eventSource is ChannelEventSource source)
|
||||
{
|
||||
// 序列化,这里可以选择自己喜欢的序列化工具
|
||||
var data = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(source));
|
||||
// 发布
|
||||
_model.BasicPublish("", _routeKey, null, data);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 这里处理动态订阅问题
|
||||
await _channel.Writer.WriteAsync(eventSource, cancellationToken);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 从存储器中读取一条事件源
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">取消任务 Token</param>
|
||||
/// <returns>事件源对象</returns>
|
||||
public async ValueTask<IEventSource> ReadAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
// 读取一条事件源
|
||||
var eventSource = await _channel.Reader.ReadAsync(cancellationToken);
|
||||
return eventSource;
|
||||
}
|
||||
/// <summary>
|
||||
/// 释放非托管资源
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
_model.Dispose();
|
||||
_connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
147
WaterCloud.Service/FileManage/UploadfileService.cs
Normal file
147
WaterCloud.Service/FileManage/UploadfileService.cs
Normal file
@@ -0,0 +1,147 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.DataBase;
|
||||
using WaterCloud.Domain.FileManage;
|
||||
using WaterCloud.Domain.SystemOrganize;
|
||||
|
||||
namespace WaterCloud.Service.FileManage
|
||||
{
|
||||
/// <summary>
|
||||
/// 创 建:超级管理员
|
||||
/// 日 期:2020-07-22 12:04
|
||||
/// 描 述:文件管理服务类
|
||||
/// </summary>
|
||||
public class UploadfileService : BaseService<UploadfileEntity>, IDenpendency
|
||||
{
|
||||
public UploadfileService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
#region 获取数据
|
||||
|
||||
public async Task<List<UploadfileEntity>> GetList(string keyword = "")
|
||||
{
|
||||
var query = repository.IQueryable();
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_FileName.Contains(keyword) || a.F_Description.Contains(keyword));
|
||||
}
|
||||
return await query.OrderBy(a => a.F_Id, OrderByType.Desc).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<UploadfileEntity>> GetLookList(string keyword = "")
|
||||
{
|
||||
var query = GetQuery();
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_FileName.Contains(keyword) || a.F_Description.Contains(keyword));
|
||||
}
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
var data = await query.OrderBy(a => a.F_Id, OrderByType.Desc).ToListAsync();
|
||||
foreach (var item in data)
|
||||
{
|
||||
string[] departments = item.F_OrganizeId.Split(',');
|
||||
item.F_OrganizeName = string.Join(',', repository.Db.Queryable<OrganizeEntity>().Where(a => departments.Contains(a.F_Id)).Select(a => a.F_FullName).ToList());
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<List<UploadfileEntity>> GetLookList(SoulPage<UploadfileEntity> pagination, string keyword = "")
|
||||
{
|
||||
//反格式化显示只能用"等于",其他不支持
|
||||
Dictionary<string, Dictionary<string, string>> dic = new Dictionary<string, Dictionary<string, string>>();
|
||||
Dictionary<string, string> enabledTemp = new Dictionary<string, string>();
|
||||
enabledTemp.Add("1", "有效");
|
||||
enabledTemp.Add("0", "无效");
|
||||
dic.Add("F_EnabledMark", enabledTemp);
|
||||
Dictionary<string, string> fileTypeTemp = new Dictionary<string, string>();
|
||||
fileTypeTemp.Add("1", "图片");
|
||||
fileTypeTemp.Add("0", "文件");
|
||||
dic.Add("F_FileType", fileTypeTemp);
|
||||
pagination = ChangeSoulData(dic, pagination);
|
||||
var query = GetQuery();
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
//此处需修改
|
||||
query = query.Where(a => a.F_FileName.Contains(keyword) || a.F_Description.Contains(keyword));
|
||||
}
|
||||
//权限过滤
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
var data = await query.ToPageListAsync(pagination); ;
|
||||
var orgs = repository.Db.Queryable<OrganizeEntity>().ToList();
|
||||
foreach (var item in data)
|
||||
{
|
||||
string[] departments = item.F_OrganizeId.Split(',');
|
||||
item.F_OrganizeName = string.Join(',', orgs.Where(a => departments.Contains(a.F_Id)).Select(a => a.F_FullName).ToList());
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private ISugarQueryable<UploadfileEntity> GetQuery()
|
||||
{
|
||||
var query = repository.Db.Queryable<UploadfileEntity, UserEntity>((a, b) => new JoinQueryInfos(
|
||||
JoinType.Left, a.F_CreatorUserId == b.F_Id))
|
||||
.Select((a, b) => new UploadfileEntity
|
||||
{
|
||||
F_Id = a.F_Id,
|
||||
F_CreatorUserName = b.F_RealName,
|
||||
F_CreatorTime = a.F_CreatorTime,
|
||||
F_CreatorUserId = a.F_CreatorUserId,
|
||||
F_Description = a.F_Description,
|
||||
F_EnabledMark = a.F_EnabledMark,
|
||||
F_FileExtension = a.F_FileExtension,
|
||||
F_FileBy = a.F_FileBy,
|
||||
F_FileName = a.F_FileName,
|
||||
F_FilePath = a.F_FilePath,
|
||||
F_FileSize = a.F_FileSize,
|
||||
F_FileType = a.F_FileType,
|
||||
F_OrganizeId = a.F_OrganizeId,
|
||||
}).MergeTable();
|
||||
return query;
|
||||
}
|
||||
|
||||
public async Task<UploadfileEntity> GetForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<UploadfileEntity> GetLookForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return GetFieldsFilterData(data);
|
||||
}
|
||||
|
||||
#endregion 获取数据
|
||||
|
||||
#region 提交数据
|
||||
|
||||
public async Task SubmitForm(UploadfileEntity entity, string keyValue)
|
||||
{
|
||||
if (string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
//此处需修改
|
||||
entity.Create();
|
||||
await repository.Insert(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
//此处需修改
|
||||
entity.Modify(keyValue);
|
||||
await repository.Update(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteForm(string keyValue)
|
||||
{
|
||||
var ids = keyValue.Split(',');
|
||||
await repository.Delete(a => ids.Contains(a.F_Id));
|
||||
}
|
||||
|
||||
#endregion 提交数据
|
||||
}
|
||||
}
|
||||
1250
WaterCloud.Service/FlowManage/FlowinstanceService.cs
Normal file
1250
WaterCloud.Service/FlowManage/FlowinstanceService.cs
Normal file
File diff suppressed because it is too large
Load Diff
47
WaterCloud.Service/FlowManage/FormTestService.cs
Normal file
47
WaterCloud.Service/FlowManage/FormTestService.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
/*******************************************************************************
|
||||
* Copyright © 2020 WaterCloud.Framework 版权所有
|
||||
* Author: WaterCloud
|
||||
* Description: WaterCloud快速开发平台
|
||||
* Website:
|
||||
*********************************************************************************/
|
||||
|
||||
using SqlSugar;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.Domain.FlowManage;
|
||||
|
||||
namespace WaterCloud.Service.FlowManage
|
||||
{
|
||||
public class FormTestService : BaseService<FormTestEntity>, IDenpendency, ICustomerForm
|
||||
{
|
||||
public FormTestService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task Add(string flowInstanceId, string frmData)
|
||||
{
|
||||
currentuser = OperatorProvider.Provider.GetCurrent();
|
||||
var req = frmData.ToObject<FormTestEntity>();
|
||||
req.F_FlowInstanceId = flowInstanceId;
|
||||
req.Create();
|
||||
req.F_CreatorUserName = currentuser.UserName;
|
||||
await repository.Insert(req);
|
||||
}
|
||||
|
||||
public async Task Edit(string flowInstanceId, string frmData)
|
||||
{
|
||||
currentuser = OperatorProvider.Provider.GetCurrent();
|
||||
var req = frmData.ToObject<FormTestEntity>();
|
||||
req.F_FlowInstanceId = flowInstanceId;
|
||||
await repository.Update(a => a.F_FlowInstanceId == req.F_FlowInstanceId, a => new FormTestEntity
|
||||
{
|
||||
F_Attachment = req.F_Attachment,
|
||||
F_EndTime = req.F_EndTime,
|
||||
F_StartTime = a.F_StartTime,
|
||||
F_RequestComment = a.F_RequestComment,
|
||||
F_RequestType = a.F_RequestType,
|
||||
F_UserName = a.F_UserName
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
117
WaterCloud.Service/Hubs/MessageHub.cs
Normal file
117
WaterCloud.Service/Hubs/MessageHub.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.Domain.InfoManage;
|
||||
using WaterCloud.Service.InfoManage;
|
||||
using WaterCloud.Service.SystemOrganize;
|
||||
|
||||
namespace WaterCloud.Service
|
||||
{
|
||||
public class MessageHub : Hub
|
||||
{
|
||||
private string cacheKey = GlobalContext.SystemConfig.ProjectPrefix + "_hubuserinfo_";
|
||||
private readonly UserService _service;
|
||||
private readonly MessageService _msgService;
|
||||
private string cacheKeyOperator = GlobalContext.SystemConfig.ProjectPrefix + "_operator_";// +登录者tokens
|
||||
|
||||
public MessageHub(UserService service, MessageService msgService)
|
||||
{
|
||||
_service = service;
|
||||
_msgService = msgService;
|
||||
}
|
||||
|
||||
// <summary>
|
||||
/// 客户端登录到服务器
|
||||
/// </summary>
|
||||
/// <param name="token"></param>
|
||||
public async Task SendLogin(string token)
|
||||
{
|
||||
var user = _service.currentuser;
|
||||
if (user == null || user.UserId == null)
|
||||
{
|
||||
user = CacheHelper.Get<OperatorModel>(cacheKeyOperator + token);
|
||||
}
|
||||
if (user != null && user.CompanyId != null)
|
||||
{
|
||||
//一个公司一个分组
|
||||
await Groups.AddToGroupAsync(Context.ConnectionId, user.CompanyId);
|
||||
//将用户信息存进缓存
|
||||
var list = await CacheHelper.GetAsync<List<string>>(cacheKey + user.UserId) ?? new List<string>();
|
||||
//登录计数
|
||||
var onlinelist = await CacheHelper.GetAsync<List<string>>(cacheKey + "list_" + user.CompanyId) ?? new List<string>();
|
||||
list.Add(Context.ConnectionId);
|
||||
onlinelist.Add(Context.ConnectionId);
|
||||
await CacheHelper.SetAsync(cacheKey + Context.ConnectionId, user.UserId);
|
||||
await CacheHelper.SetAsync(cacheKey + user.UserId, list);
|
||||
await CacheHelper.SetAsync(cacheKey + "list_" + user.CompanyId, onlinelist);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送消息
|
||||
/// </summary>
|
||||
/// <param name="reUserId">收消息的人员Id</param>
|
||||
/// <param name="message">消息内容</param>
|
||||
/// <returns></returns>
|
||||
public async Task SendMessage(string reUserId, string message)
|
||||
{
|
||||
if (string.IsNullOrEmpty(reUserId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageEntity msg = new MessageEntity();
|
||||
msg.F_EnabledMark = true;
|
||||
msg.F_MessageType = 1;
|
||||
msg.F_CreatorUserName = _service.currentuser.UserName;
|
||||
msg.F_MessageInfo = message;
|
||||
msg.F_ToUserId = reUserId;
|
||||
msg.F_ClickRead = true;
|
||||
await _msgService.SubmitForm(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public override async Task OnDisconnectedAsync(Exception exception)
|
||||
{
|
||||
var user = _service.currentuser;
|
||||
//删除缓存连接
|
||||
var userId = await CacheHelper.GetAsync<string>(cacheKey + Context.ConnectionId);
|
||||
if (!string.IsNullOrEmpty(userId))
|
||||
{
|
||||
//将用户信息存进缓存
|
||||
var list = await CacheHelper.GetAsync<List<string>>(cacheKey + userId);
|
||||
//登录计数
|
||||
var onlinelist = await CacheHelper.GetAsync<List<string>>(cacheKey + "list_" + user.CompanyId);
|
||||
if (list != null)
|
||||
{
|
||||
list.Remove(Context.ConnectionId);
|
||||
if (list.Count == 0)
|
||||
{
|
||||
await CacheHelper.RemoveAsync(cacheKey + userId);
|
||||
}
|
||||
else
|
||||
{
|
||||
await CacheHelper.SetAsync(cacheKey + userId, list);
|
||||
}
|
||||
}
|
||||
if (onlinelist != null)
|
||||
{
|
||||
onlinelist.Remove(Context.ConnectionId);
|
||||
if (list.Count == 0)
|
||||
{
|
||||
await CacheHelper.RemoveAsync(cacheKey + "list_" + user.CompanyId);
|
||||
}
|
||||
else
|
||||
{
|
||||
await CacheHelper.SetAsync(cacheKey + "list_" + user.CompanyId, onlinelist);
|
||||
}
|
||||
}
|
||||
await CacheHelper.RemoveAsync(cacheKey + Context.ConnectionId);
|
||||
}
|
||||
await base.OnDisconnectedAsync(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
179
WaterCloud.Service/InfoManage/MessageService.cs
Normal file
179
WaterCloud.Service/InfoManage/MessageService.cs
Normal file
@@ -0,0 +1,179 @@
|
||||
using Jaina;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.DataBase;
|
||||
using WaterCloud.Domain.InfoManage;
|
||||
using WaterCloud.Domain.SystemOrganize;
|
||||
using WaterCloud.Service.Event;
|
||||
using WaterCloud.Service.SystemManage;
|
||||
|
||||
namespace WaterCloud.Service.InfoManage
|
||||
{
|
||||
/// <summary>
|
||||
/// 创 建:超级管理员
|
||||
/// 日 期:2020-07-29 16:41
|
||||
/// 描 述:通知管理服务类
|
||||
/// </summary>
|
||||
public class MessageService : BaseService<MessageEntity>, IDenpendency
|
||||
{
|
||||
public ItemsDataService itemsApp { get; set; }
|
||||
|
||||
public MessageService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
#region 获取数据
|
||||
|
||||
public async Task<List<MessageEntity>> GetList(string keyword = "")
|
||||
{
|
||||
var query = repository.IQueryable();
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_MessageInfo.Contains(keyword) || a.F_CreatorUserName.Contains(keyword));
|
||||
}
|
||||
return await query.Where(a => a.F_EnabledMark == true).OrderBy(a => a.F_CreatorTime, OrderByType.Desc).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<MessageEntity>> GetLookList(string keyword = "")
|
||||
{
|
||||
var query = repository.IQueryable().Where(a => a.F_EnabledMark == true);
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_MessageInfo.Contains(keyword) || a.F_CreatorUserName.Contains(keyword));
|
||||
}
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
return await query.OrderBy(a => a.F_CreatorTime, OrderByType.Desc).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<MessageEntity>> GetUnReadListJson()
|
||||
{
|
||||
var hisquery = repository.Db.Queryable<MessageHistoryEntity>().Where(a => a.F_CreatorUserId == currentuser.UserId).Select(a => a.F_MessageId).ToList();
|
||||
var tempList = repository.Db.Queryable<MessageEntity, MessageHistoryEntity>((a, b) => new JoinQueryInfos(
|
||||
JoinType.Inner, a.F_Id == b.F_MessageId && a.F_MessageType == 2
|
||||
)).Select(a => a.F_Id).ToList();
|
||||
hisquery.AddRange(tempList);
|
||||
var query = repository.IQueryable(a => (a.F_ToUserId.Contains(currentuser.UserId) || a.F_ToUserId == "") && a.F_EnabledMark == true).Where(a => !hisquery.Contains(a.F_Id));
|
||||
return await GetFieldsFilterDataNew("a", query.OrderBy(a => a.F_CreatorTime, OrderByType.Desc)).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<MessageEntity>> GetLookList(SoulPage<MessageEntity> pagination, string keyword = "")
|
||||
{
|
||||
//反格式化显示只能用"等于",其他不支持
|
||||
Dictionary<string, Dictionary<string, string>> dic = new Dictionary<string, Dictionary<string, string>>();
|
||||
var setList = await itemsApp.GetItemList("MessageType");
|
||||
Dictionary<string, string> messageTypeTemp = new Dictionary<string, string>();
|
||||
foreach (var item in setList)
|
||||
{
|
||||
messageTypeTemp.Add(item.F_ItemCode, item.F_ItemName);
|
||||
}
|
||||
dic.Add("F_MessageType", messageTypeTemp);
|
||||
pagination = ChangeSoulData(dic, pagination);
|
||||
//获取数据权限
|
||||
var query = repository.IQueryable().Where(a => a.F_EnabledMark == true);
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
//此处需修改
|
||||
query = query.Where(a => a.F_MessageInfo.Contains(keyword) || a.F_CreatorUserName.Contains(keyword));
|
||||
}
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
return await query.ToPageListAsync(pagination);
|
||||
}
|
||||
|
||||
public async Task<MessageEntity> GetForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return data;
|
||||
}
|
||||
|
||||
#endregion 获取数据
|
||||
|
||||
public async Task<MessageEntity> GetLookForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return GetFieldsFilterData(data);
|
||||
}
|
||||
|
||||
#region 提交数据
|
||||
|
||||
public async Task SubmitForm(MessageEntity entity)
|
||||
{
|
||||
entity.Create();
|
||||
entity.F_EnabledMark = true;
|
||||
entity.F_CreatorUserName = currentuser.UserName;
|
||||
MessageEntity messageEntity = new MessageEntity();
|
||||
if (string.IsNullOrEmpty(entity.F_ToUserId))
|
||||
{
|
||||
string msg = entity.ToJson();
|
||||
entity.F_ToUserName = "所有人";
|
||||
entity.F_ToUserId = "";
|
||||
messageEntity = await repository.Insert(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
var users = entity.F_ToUserId.Split(",");
|
||||
entity.F_ToUserName = string.Join(",", repository.Db.Queryable<UserEntity>().Where(a => users.Contains(a.F_Id)).Select(a => a.F_RealName).ToList());
|
||||
messageEntity = await repository.Insert(entity);
|
||||
}
|
||||
//通过http发送消息
|
||||
messageEntity.companyId = currentuser.CompanyId;
|
||||
await GlobalContext.GetService<IEventPublisher>().PublishAsync(new BaseEventSource("Message:send", messageEntity,currentuser));
|
||||
}
|
||||
|
||||
public async Task ReadAllMsgForm(int type)
|
||||
{
|
||||
var unList = await GetUnReadListJson();
|
||||
var strList = unList.Where(a => a.F_MessageType == type && a.F_ClickRead == true).Select(a => a.F_Id).ToList();
|
||||
repository.Db.Ado.BeginTran();
|
||||
foreach (var item in strList)
|
||||
{
|
||||
await ReadMsgForm(item);
|
||||
}
|
||||
repository.Db.Ado.CommitTran();
|
||||
}
|
||||
|
||||
public async Task ReadMsgForm(string keyValue)
|
||||
{
|
||||
MessageHistoryEntity msghis = new MessageHistoryEntity();
|
||||
msghis.Create();
|
||||
msghis.F_CreatorUserName = currentuser.UserName;
|
||||
msghis.F_MessageId = keyValue;
|
||||
await repository.Db.Insertable(msghis).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> CheckMsg(string keyValue)
|
||||
{
|
||||
var msg = await repository.FindEntity(keyValue);
|
||||
if (msg == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (msg.F_ClickRead == false)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (await repository.Db.Queryable<MessageHistoryEntity>().Where(a => a.F_MessageId == keyValue && a.F_CreatorUserId == currentuser.UserId).AnyAsync())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteForm(string keyValue)
|
||||
{
|
||||
var ids = keyValue.Split(',');
|
||||
await repository.Update(a => ids.Contains(a.F_Id), a => new MessageEntity
|
||||
{
|
||||
F_EnabledMark = false
|
||||
});
|
||||
}
|
||||
|
||||
#endregion 提交数据
|
||||
}
|
||||
}
|
||||
325
WaterCloud.Service/Infrastructure/BaseService.cs
Normal file
325
WaterCloud.Service/Infrastructure/BaseService.cs
Normal file
@@ -0,0 +1,325 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.DataBase;
|
||||
using WaterCloud.Domain.SystemManage;
|
||||
using WaterCloud.Domain.SystemOrganize;
|
||||
|
||||
namespace WaterCloud.Service
|
||||
{
|
||||
public class BaseService<T> : RepositoryBase<T> where T : class, new()
|
||||
{
|
||||
// 用户信息
|
||||
public OperatorModel currentuser;
|
||||
|
||||
// 用于当前表操作
|
||||
protected RepositoryBase<T> repository;
|
||||
|
||||
// 用于其他表操作
|
||||
protected ISqlSugarClient _context;
|
||||
|
||||
public BaseService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
currentuser = OperatorProvider.Provider.GetCurrent();
|
||||
_context = context;
|
||||
repository = this;
|
||||
if (currentuser == null)
|
||||
{
|
||||
currentuser = new OperatorModel();
|
||||
}
|
||||
else
|
||||
{
|
||||
var entityType = typeof(T);
|
||||
if (entityType.IsDefined(typeof(TenantAttribute), false))
|
||||
{
|
||||
var tenantAttribute = entityType.GetCustomAttribute<TenantAttribute>(false)!;
|
||||
repository.ChangeEntityDb(tenantAttribute.configId);
|
||||
}
|
||||
else if (_context.AsTenant().IsAnyConnection(currentuser.DbNumber))
|
||||
{
|
||||
repository.ChangeEntityDb(currentuser.DbNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
var dblist = DBInitialize.GetConnectionConfigs(false);
|
||||
_context.AsTenant().AddConnection(dblist.FirstOrDefault(a => a.ConfigId.ToString() == currentuser.DbNumber));
|
||||
repository.ChangeEntityDb(currentuser.DbNumber);
|
||||
repository.Db.DefaultConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前登录用户的数据访问权限(单表)
|
||||
/// </summary>
|
||||
/// <param name=""parameterName>linq表达式参数的名称,如u=>u.name中的"u"</param>
|
||||
/// <param name=""moduleName>菜单名称</param>
|
||||
/// <param name=""query>查询</param>
|
||||
/// <returns></returns>
|
||||
protected ISugarQueryable<T> GetDataPrivilege(string parametername, string moduleName = "", ISugarQueryable<T> query = null)
|
||||
{
|
||||
moduleName = string.IsNullOrEmpty(moduleName) ? ReflectionHelper.GetModuleName() : moduleName;
|
||||
if (query == null)
|
||||
{
|
||||
query = repository.IQueryable();
|
||||
}
|
||||
if (!CheckDataPrivilege(moduleName))
|
||||
{
|
||||
return GetFieldsFilterDataNew(parametername, query, moduleName);
|
||||
}
|
||||
var rule = repository.Db.Queryable<DataPrivilegeRuleEntity>().WithCache().First(u => u.F_ModuleCode == moduleName && u.F_EnabledMark == true && u.F_DeleteMark == false);
|
||||
if (rule.F_PrivilegeRules.Contains(Define.DATAPRIVILEGE_LOGINUSER) ||
|
||||
rule.F_PrivilegeRules.Contains(Define.DATAPRIVILEGE_LOGINROLE) ||
|
||||
rule.F_PrivilegeRules.Contains(Define.DATAPRIVILEGE_LOGINORG))
|
||||
{
|
||||
//即把{loginUser} =='xxxxxxx'换为 loginUser.User.Id =='xxxxxxx',从而把当前登录的用户名与当时设计规则时选定的用户id对比
|
||||
rule.F_PrivilegeRules = rule.F_PrivilegeRules.Replace(Define.DATAPRIVILEGE_LOGINUSER, currentuser.UserId);
|
||||
var roles = currentuser.RoleId;
|
||||
//var roles = loginUser.Roles.Select(u => u.Id).ToList();//多角色
|
||||
//roles.Sort();
|
||||
rule.F_PrivilegeRules = rule.F_PrivilegeRules.Replace(Define.DATAPRIVILEGE_LOGINROLE,
|
||||
roles);
|
||||
var orgs = currentuser.OrganizeId;
|
||||
//var orgs = loginUser.Orgs.Select(u => u.Id).ToList();//多部门
|
||||
//orgs.Sort();
|
||||
rule.F_PrivilegeRules = rule.F_PrivilegeRules.Replace(Define.DATAPRIVILEGE_LOGINORG,
|
||||
orgs);
|
||||
}
|
||||
query = query.GenerateFilter(parametername,
|
||||
JsonHelper.ToObject<List<FilterList>>(rule.F_PrivilegeRules));
|
||||
return GetFieldsFilterDataNew(parametername, query, moduleName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前登录用户的数据访问权限(复杂查询)
|
||||
/// </summary>
|
||||
/// <param name=""parameterName>linq表达式参数的名称,如u=>u.name中的"u"</param>
|
||||
/// <param name=""moduleName>菜单名称</param>
|
||||
/// <param name=""query>查询</param>
|
||||
/// <returns></returns>
|
||||
protected ISugarQueryable<TEntity> GetDataPrivilege<TEntity>(string parametername, string moduleName = "", ISugarQueryable<TEntity> query = null)
|
||||
{
|
||||
moduleName = string.IsNullOrEmpty(moduleName) ? ReflectionHelper.GetModuleName() : moduleName;
|
||||
if (!CheckDataPrivilege(moduleName))
|
||||
{
|
||||
return GetFieldsFilterDataNew(parametername, query, moduleName);
|
||||
}
|
||||
var rule = repository.Db.Queryable<DataPrivilegeRuleEntity>().WithCache().First(u => u.F_ModuleCode == moduleName && u.F_EnabledMark == true && u.F_DeleteMark == false);
|
||||
if (rule.F_PrivilegeRules.Contains(Define.DATAPRIVILEGE_LOGINUSER) ||
|
||||
rule.F_PrivilegeRules.Contains(Define.DATAPRIVILEGE_LOGINROLE) ||
|
||||
rule.F_PrivilegeRules.Contains(Define.DATAPRIVILEGE_LOGINORG))
|
||||
{
|
||||
//即把{loginUser} =='xxxxxxx'换为 loginUser.User.Id =='xxxxxxx',从而把当前登录的用户名与当时设计规则时选定的用户id对比
|
||||
rule.F_PrivilegeRules = rule.F_PrivilegeRules.Replace(Define.DATAPRIVILEGE_LOGINUSER, currentuser.UserId);
|
||||
var roles = currentuser.RoleId;
|
||||
rule.F_PrivilegeRules = rule.F_PrivilegeRules.Replace(Define.DATAPRIVILEGE_LOGINROLE,
|
||||
roles);
|
||||
var orgs = currentuser.OrganizeId;
|
||||
rule.F_PrivilegeRules = rule.F_PrivilegeRules.Replace(Define.DATAPRIVILEGE_LOGINORG,
|
||||
orgs);
|
||||
}
|
||||
query = query.GenerateFilter(parametername,
|
||||
JsonHelper.ToObject<List<FilterList>>(rule.F_PrivilegeRules));
|
||||
return GetFieldsFilterDataNew(parametername, query, moduleName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前登录用户是否需要数据控制
|
||||
/// </summary>
|
||||
/// <param name=""moduleName>菜单名称</param>
|
||||
/// <returns></returns>
|
||||
protected bool CheckDataPrivilege(string moduleName = "")
|
||||
{
|
||||
moduleName = string.IsNullOrEmpty(moduleName) ? ReflectionHelper.GetModuleName() : moduleName;
|
||||
if (currentuser.IsAdmin) return false; //超级管理员特权
|
||||
var rule = repository.Db.Queryable<DataPrivilegeRuleEntity>().WithCache().First(u => u.F_ModuleCode == moduleName && u.F_EnabledMark == true && u.F_DeleteMark == false);
|
||||
////系统菜单也不需要数据权限 跟字段重合取消这样处理
|
||||
//var module = UnitWork.FindEntity<ModuleEntity>(u => u.F_EnCode == moduleName).GetAwaiter().GetResult();
|
||||
if (rule == null)
|
||||
{
|
||||
return false; //没有设置数据规则,那么视为该资源允许被任何主体查看
|
||||
}
|
||||
//if (rule == null|| module.F_IsPublic==true)
|
||||
//{
|
||||
// return false; //没有设置数据规则,那么视为该资源允许被任何主体查看
|
||||
//}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// soul数据反向模板化
|
||||
/// </summary>
|
||||
/// <param name=""dic>集合</param>
|
||||
/// <param name=""pagination>分页</param>
|
||||
/// <returns></returns>
|
||||
protected SoulPage<TEntity> ChangeSoulData<TEntity>(Dictionary<string, Dictionary<string, string>> dic, SoulPage<TEntity> pagination)
|
||||
{
|
||||
List<FilterSo> filterSos = pagination.getFilterSos();
|
||||
filterSos = FormatData(dic, filterSos);
|
||||
pagination.filterSos = filterSos.ToJson();
|
||||
return pagination;
|
||||
}
|
||||
|
||||
protected List<FilterSo> FormatData(Dictionary<string, Dictionary<string, string>> dic, List<FilterSo> filterSos)
|
||||
{
|
||||
foreach (var item in filterSos)
|
||||
{
|
||||
if (item.mode == "condition" && dic.ContainsKey(item.field) && dic[item.field].Values.Contains(item.value))
|
||||
{
|
||||
item.value = dic[item.field].FirstOrDefault(a => a.Value == item.value).Key;
|
||||
}
|
||||
if (item.children != null && item.children.Count > 0)
|
||||
{
|
||||
item.children = FormatData(dic, item.children);
|
||||
}
|
||||
}
|
||||
return filterSos;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字段权限处理
|
||||
/// </summary>
|
||||
///<param name=""list>数据列表</param>
|
||||
/// <param name=""moduleName>菜单名称</param>
|
||||
/// <returns></returns>
|
||||
protected List<TEntity> GetFieldsFilterData<TEntity>(List<TEntity> list, string moduleName = "")
|
||||
{
|
||||
moduleName = string.IsNullOrEmpty(moduleName) ? ReflectionHelper.GetModuleName() : moduleName;
|
||||
//管理员跳过
|
||||
if (currentuser.IsAdmin)
|
||||
{
|
||||
return list;
|
||||
}
|
||||
//系统菜单跳过
|
||||
var module = repository.Db.Queryable<ModuleEntity>().First(u => u.F_EnCode == moduleName);
|
||||
//判断是否需要字段权限
|
||||
if (module == null || module.F_IsFields == false)
|
||||
{
|
||||
return list;
|
||||
}
|
||||
//空list直接返回
|
||||
if (list.Count == 0)
|
||||
{
|
||||
return list;
|
||||
}
|
||||
var rolelist = currentuser.RoleId.Split(',');
|
||||
var rule = repository.Db.Queryable<RoleAuthorizeEntity>().Where(u => rolelist.Contains(u.F_ObjectId) && u.F_ItemType == 3).Select(a => a.F_ItemId).Distinct().ToList();
|
||||
var fieldsList = repository.Db.Queryable<ModuleFieldsEntity>().Where(u => (rule.Contains(u.F_Id) || u.F_IsPublic == true) && u.F_EnabledMark == true && u.F_ModuleId == module.F_Id).Select(u => u.F_EnCode).ToList();
|
||||
//反射获取主键
|
||||
PropertyInfo pkProp = typeof(TEntity).GetProperties().Where(p => p.GetCustomAttributes(typeof(SugarColumn), false).Length > 0).First();
|
||||
var idName = "F_Id";
|
||||
if (pkProp != null)
|
||||
{
|
||||
idName = pkProp.Name;
|
||||
}
|
||||
fieldsList.Add(idName);
|
||||
fieldsList = fieldsList.Distinct().ToList();
|
||||
return DataTableHelper.ListFilter(list, fieldsList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字段权限处理
|
||||
/// </summary>
|
||||
///<param name=""entity>数据</param>
|
||||
/// <param name=""moduleName>菜单名称</param>
|
||||
/// <returns></returns>
|
||||
protected TEntity GetFieldsFilterData<TEntity>(TEntity entity, string moduleName = "")
|
||||
{
|
||||
moduleName = string.IsNullOrEmpty(moduleName) ? ReflectionHelper.GetModuleName() : moduleName;
|
||||
//管理员跳过
|
||||
if (currentuser.IsAdmin)
|
||||
{
|
||||
return entity;
|
||||
}
|
||||
//系统菜单跳过
|
||||
var module = repository.Db.Queryable<ModuleEntity>().First(u => u.F_EnCode == moduleName);
|
||||
//判断是否需要字段权限
|
||||
if (module == null || module.F_IsFields == false)
|
||||
{
|
||||
return entity;
|
||||
}
|
||||
//空对象直接返回
|
||||
if (entity == null)
|
||||
{
|
||||
return entity;
|
||||
}
|
||||
var rolelist = currentuser.RoleId.Split(',');
|
||||
var rule = repository.Db.Queryable<RoleAuthorizeEntity>().Where(u => rolelist.Contains(u.F_ObjectId) && u.F_ItemType == 3).Select(a => a.F_ItemId).Distinct().ToList();
|
||||
var fieldsList = repository.Db.Queryable<ModuleFieldsEntity>().Where(u => (rule.Contains(u.F_Id) || u.F_IsPublic == true) && u.F_EnabledMark == true && u.F_ModuleId == module.F_Id).Select(u => u.F_EnCode).ToList();
|
||||
//反射获取主键
|
||||
PropertyInfo pkProp = typeof(TEntity).GetProperties().Where(p => p.GetCustomAttributes(typeof(SugarColumn), false).Length > 0).First();
|
||||
var idName = "F_Id";
|
||||
if (pkProp != null)
|
||||
{
|
||||
idName = pkProp.Name;
|
||||
}
|
||||
fieldsList.Add(idName);
|
||||
fieldsList = fieldsList.Distinct().ToList();
|
||||
List<TEntity> list = new List<TEntity>();
|
||||
list.Add(entity);
|
||||
return DataTableHelper.ListFilter(list, fieldsList)[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字段权限处理
|
||||
/// </summary>
|
||||
///<param name=""query>数据列表</param>
|
||||
/// <param name=""moduleName>菜单名称</param>
|
||||
/// <returns></returns>
|
||||
protected ISugarQueryable<TEntity> GetFieldsFilterDataNew<TEntity>(string parametername, ISugarQueryable<TEntity> query, string moduleName = "")
|
||||
{
|
||||
moduleName = string.IsNullOrEmpty(moduleName) ? ReflectionHelper.GetModuleName() : moduleName;
|
||||
//管理员跳过
|
||||
if (currentuser.IsAdmin)
|
||||
{
|
||||
return query;
|
||||
}
|
||||
//系统菜单跳过
|
||||
var module = repository.Db.Queryable<ModuleEntity>().First(u => u.F_EnCode == moduleName);
|
||||
//判断是否需要字段权限
|
||||
if (module == null || module.F_IsFields == false)
|
||||
{
|
||||
return query;
|
||||
}
|
||||
var rolelist = currentuser.RoleId.Split(',');
|
||||
var rule = repository.Db.Queryable<RoleAuthorizeEntity>().Where(u => rolelist.Contains(u.F_ObjectId) && u.F_ItemType == 3).Select(a => a.F_ItemId).Distinct().ToList();
|
||||
var fieldsList = repository.Db.Queryable<ModuleFieldsEntity>().Where(u => (rule.Contains(u.F_Id) || u.F_IsPublic == true) && u.F_EnabledMark == true && u.F_ModuleId == module.F_Id).Select(u => u.F_EnCode).ToList();
|
||||
//反射获取主键
|
||||
PropertyInfo pkProp = typeof(TEntity).GetProperties().Where(p => p.GetCustomAttributes(typeof(SugarColumn), false).Length > 0).First();
|
||||
var idName = "F_Id";
|
||||
if (pkProp != null)
|
||||
{
|
||||
idName = pkProp.Name;
|
||||
}
|
||||
fieldsList.Add(idName);
|
||||
fieldsList = fieldsList.Distinct().ToList();
|
||||
//可以构建lambda
|
||||
var parameter = Expression.Parameter(typeof(TEntity), parametername);
|
||||
var bindings = fieldsList
|
||||
.Select(name => name.Trim())
|
||||
.Select(name => Expression.Bind(
|
||||
typeof(TEntity).GetProperty(name),
|
||||
Expression.Property(parameter, name)
|
||||
));
|
||||
var newT = Expression.MemberInit(Expression.New(typeof(TEntity)), bindings);
|
||||
var lambda = Expression.Lambda<Func<TEntity, TEntity>>(newT, parameter);
|
||||
query = query.Select(lambda);
|
||||
//chloe扩展方法
|
||||
//List<string> ignoreList = new List<string>();
|
||||
// foreach (var item in typeof(TEntity).GetProperties())
|
||||
// {
|
||||
// if (!fieldsList.Contains(item.Name))
|
||||
// {
|
||||
// ignoreList.Add(item.Name);
|
||||
// }
|
||||
// }
|
||||
// query = query.Ignore(ignoreList.ToArray());
|
||||
return query;
|
||||
}
|
||||
}
|
||||
}
|
||||
74
WaterCloud.Service/Infrastructure/DBInitialize.cs
Normal file
74
WaterCloud.Service/Infrastructure/DBInitialize.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.Code.Model;
|
||||
using WaterCloud.DataBase;
|
||||
using WaterCloud.Domain.SystemOrganize;
|
||||
|
||||
namespace WaterCloud.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始数据库操作类
|
||||
/// </summary>
|
||||
public class DBInitialize
|
||||
{
|
||||
private static string cacheKey = GlobalContext.SystemConfig.ProjectPrefix + "_dblist";// 数据库键
|
||||
|
||||
/// <summary>
|
||||
/// 获取注册数据库list
|
||||
/// </summary>
|
||||
/// <param name="readDb">重置数据库list</param>
|
||||
/// <returns></returns>
|
||||
public static List<ConnectionConfig> GetConnectionConfigs(bool readDb = false)
|
||||
{
|
||||
List<ConnectionConfig> list = CacheHelper.Get<List<ConnectionConfig>>(cacheKey);
|
||||
if (list == null || !list.Any() || readDb)
|
||||
{
|
||||
list = new List<ConnectionConfig>();
|
||||
var data = GlobalContext.SystemConfig;
|
||||
var defaultConfig = DBContexHelper.Contex(data.DBConnectionString, data.DBProvider);
|
||||
defaultConfig.ConfigId = "0";
|
||||
list.Add(defaultConfig);
|
||||
try
|
||||
{
|
||||
//租户数据库
|
||||
if (data.SqlMode == Define.SQL_TENANT)
|
||||
{
|
||||
using (var context = new SqlSugarClient(defaultConfig))
|
||||
{
|
||||
var sqls = context.Queryable<SystemSetEntity>().ToList();
|
||||
foreach (var item in sqls.Where(a => a.F_EnabledMark == true && a.F_EndTime > DateTime.Now.Date && a.F_DbNumber != "0"))
|
||||
{
|
||||
var config = DBContexHelper.Contex(item.F_DbString, item.F_DBProvider);
|
||||
config.ConfigId = item.F_DbNumber;
|
||||
list.Add(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (data.SqlConfig == null)
|
||||
data.SqlConfig = new List<DBConfig>();
|
||||
|
||||
//扩展数据库
|
||||
foreach (var item in data.SqlConfig)
|
||||
{
|
||||
var config = DBContexHelper.Contex(item.DBConnectionString, item.DBProvider);
|
||||
config.ConfigId = item.DBNumber;
|
||||
if (list.Any(a => a.ConfigId == config.ConfigId))
|
||||
{
|
||||
throw new Exception($"数据库编号重复,请检查{config.ConfigId}");
|
||||
}
|
||||
list.Add(config);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteWithTime(ex);
|
||||
}
|
||||
CacheHelper.SetBySecond(cacheKey, list);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
64
WaterCloud.Service/Infrastructure/DatabaseTableService.cs
Normal file
64
WaterCloud.Service/Infrastructure/DatabaseTableService.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.DataBase;
|
||||
using WaterCloud.Domain.SystemSecurity;
|
||||
|
||||
namespace WaterCloud.Service
|
||||
{
|
||||
public class DatabaseTableService : IDenpendency
|
||||
{
|
||||
public RepositoryBase<LogEntity> repository;
|
||||
private static string cacheKey = GlobalContext.SystemConfig.ProjectPrefix + "_dblist";// 数据库键
|
||||
|
||||
public DatabaseTableService(ISqlSugarClient context)
|
||||
{
|
||||
repository = new RepositoryBase<LogEntity>(context);
|
||||
}
|
||||
|
||||
public List<DbTableInfo> GetTableList(string tableName, string dbNumber)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dbNumber))
|
||||
{
|
||||
dbNumber = GlobalContext.SystemConfig.MainDbNumber;
|
||||
}
|
||||
repository.ChangeEntityDb(dbNumber);
|
||||
var data = repository.Db.DbMaintenance.GetTableInfoList(false);
|
||||
if (!string.IsNullOrEmpty(tableName))
|
||||
data = data.Where(a => a.Name.Contains(tableName)).ToList();
|
||||
return data;
|
||||
}
|
||||
|
||||
public List<DbTableInfo> GetTablePageList(string tableName, string dbNumber, Pagination pagination)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dbNumber))
|
||||
{
|
||||
dbNumber = GlobalContext.SystemConfig.MainDbNumber;
|
||||
}
|
||||
repository.ChangeEntityDb(dbNumber);
|
||||
var data = repository.Db.DbMaintenance.GetTableInfoList(false);
|
||||
if (!string.IsNullOrEmpty(tableName))
|
||||
data = data.Where(a => a.Name.Contains(tableName)).ToList();
|
||||
pagination.records = data.Count();
|
||||
return data.Skip((pagination.page - 1) * pagination.rows).Take(pagination.rows).ToList();
|
||||
}
|
||||
|
||||
public List<dynamic> GetDbNumberListJson()
|
||||
{
|
||||
var data = DBInitialize.GetConnectionConfigs();
|
||||
return data.Select(a => a.ConfigId).ToList();
|
||||
}
|
||||
|
||||
public List<DbColumnInfo> GetTableFieldList(string tableName, string dbNumber)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dbNumber))
|
||||
{
|
||||
dbNumber = GlobalContext.SystemConfig.MainDbNumber;
|
||||
}
|
||||
repository.ChangeEntityDb(dbNumber);
|
||||
var data = repository.Db.DbMaintenance.GetColumnInfosByTableName(tableName, false);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
WaterCloud.Service/Infrastructure/ICustomerForm.cs
Normal file
11
WaterCloud.Service/Infrastructure/ICustomerForm.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WaterCloud.Service
|
||||
{
|
||||
public interface ICustomerForm
|
||||
{
|
||||
Task Add(string flowInstanceId, string frmData);
|
||||
|
||||
Task Edit(string flowInstanceId, string frmData);
|
||||
}
|
||||
}
|
||||
5
WaterCloud.Service/Infrastructure/IDenpendency.cs
Normal file
5
WaterCloud.Service/Infrastructure/IDenpendency.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
namespace WaterCloud.Service
|
||||
{
|
||||
public interface IDenpendency
|
||||
{ }
|
||||
}
|
||||
431
WaterCloud.Service/Infrastructure/ServiceSetup.cs
Normal file
431
WaterCloud.Service/Infrastructure/ServiceSetup.cs
Normal file
@@ -0,0 +1,431 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using MySqlConnector;
|
||||
using Quartz;
|
||||
using Quartz.Impl;
|
||||
using Quartz.Impl.AdoJobStore.Common;
|
||||
using Quartz.Spi;
|
||||
using RabbitMQ.Client;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.DataBase;
|
||||
using WaterCloud.Domain.SystemOrganize;
|
||||
using WaterCloud.Service.AutoJob;
|
||||
using WaterCloud.Service.Event;
|
||||
|
||||
namespace WaterCloud.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 服务设置
|
||||
/// </summary>
|
||||
public static class ServiceSetup
|
||||
{
|
||||
/// <summary>
|
||||
/// SqlSugar设置
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
public static IServiceCollection AddSqlSugar(this IServiceCollection services)
|
||||
{
|
||||
var configList = DBInitialize.GetConnectionConfigs(true);
|
||||
SqlSugarScope sqlSugarScope = new SqlSugarScope(configList,
|
||||
//全局上下文生效
|
||||
db =>
|
||||
{
|
||||
foreach (var item in configList)
|
||||
{
|
||||
db.GetConnection(item.ConfigId).DefaultConfig();
|
||||
}
|
||||
});
|
||||
//初始化数据库
|
||||
foreach (var item in configList)
|
||||
{
|
||||
var db = sqlSugarScope.GetConnection(item.ConfigId);
|
||||
if (GlobalContext.SystemConfig.IsInitDb)
|
||||
{
|
||||
InitDb(item, db);
|
||||
}
|
||||
if (GlobalContext.SystemConfig.IsSeedData)
|
||||
{
|
||||
InitSeedData(item, db);
|
||||
}
|
||||
}
|
||||
//注入数据库连接
|
||||
// 注册 SqlSugar
|
||||
services.AddSingleton<ISqlSugarClient>(sqlSugarScope);
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// sqlsugar配置
|
||||
/// </summary>
|
||||
/// <param name="db"></param>
|
||||
public static void DefaultConfig(this ISqlSugarClient db)
|
||||
{
|
||||
db.Ado.CommandTimeOut = GlobalContext.SystemConfig.DBCommandTimeout;
|
||||
db.CurrentConnectionConfig.ConfigureExternalServices = new ConfigureExternalServices()
|
||||
{
|
||||
DataInfoCacheService = new SqlSugarCache(), //配置我们创建的缓存类
|
||||
EntityNameService = (type, entity) =>
|
||||
{
|
||||
var attributes = type.GetCustomAttributes(true);
|
||||
if (attributes.Any(it => it is TableAttribute))
|
||||
{
|
||||
entity.DbTableName = (attributes.First(it => it is TableAttribute) as TableAttribute).Name;
|
||||
}
|
||||
},
|
||||
EntityService = (property, column) =>
|
||||
{
|
||||
var attributes = property.GetCustomAttributes(true);//get all attributes
|
||||
if (attributes.Any(it => it is KeyAttribute))// by attribute set primarykey
|
||||
{
|
||||
column.IsPrimarykey = true; //有哪些特性可以看 1.2 特性明细
|
||||
}
|
||||
if (attributes.Any(it => it is ColumnAttribute))
|
||||
{
|
||||
column.DbColumnName = (attributes.First(it => it is ColumnAttribute) as ColumnAttribute).Name;
|
||||
}
|
||||
if (attributes.Any(it => it is SugarColumn) && column.DataType == "longtext" && db.CurrentConnectionConfig.DbType == SqlSugar.DbType.SqlServer)
|
||||
{
|
||||
column.DataType = "nvarchar(4000)";
|
||||
}
|
||||
}
|
||||
};
|
||||
db.Aop.OnLogExecuted = (sql, pars) => //SQL执行完
|
||||
{
|
||||
if (sql.StartsWith("SELECT"))
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.WriteLine("[SELECT]-" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
|
||||
}
|
||||
if (sql.StartsWith("INSERT"))
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Console.WriteLine("[INSERT]-" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
|
||||
}
|
||||
if (sql.StartsWith("UPDATE"))
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine("[UPDATE]-" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
|
||||
}
|
||||
if (sql.StartsWith("DELETE"))
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("[DELETE]-" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
|
||||
}
|
||||
Console.WriteLine($"执行库{db.CurrentConnectionConfig.ConfigId}");
|
||||
Console.WriteLine("NeedTime-" + db.Ado.SqlExecutionTime.ToString());
|
||||
//App.PrintToMiniProfiler("SqlSugar", "Info", sql + "\r\n" + db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
|
||||
Console.WriteLine("Content:" + UtilMethods.GetSqlString(db.CurrentConnectionConfig.DbType, sql, pars));
|
||||
Console.WriteLine("---------------------------------");
|
||||
Console.WriteLine("");
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private static void InitSeedData(ConnectionConfig config, SqlSugarProvider db)
|
||||
{
|
||||
var entityTypes = GlobalContext.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.IsDefined(typeof(SugarTable), false));
|
||||
if (!entityTypes.Any()) return;//没有就退出
|
||||
|
||||
// 获取所有种子配置-初始化数据
|
||||
var seedDataTypes = GlobalContext.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass
|
||||
&& u.GetInterfaces().Any(i => i.HasImplementedRawGeneric(typeof(ISqlSugarEntitySeedData<>))));
|
||||
if (!seedDataTypes.Any()) return;
|
||||
foreach (var seedType in seedDataTypes)//遍历种子类
|
||||
{
|
||||
//使用与指定参数匹配程度最高的构造函数来创建指定类型的实例。
|
||||
var instance = Activator.CreateInstance(seedType);
|
||||
//获取SeedData方法
|
||||
var hasDataMethod = seedType.GetMethod("SeedData");
|
||||
//判断是否有种子数据
|
||||
var seedData = ((IEnumerable)hasDataMethod?.Invoke(instance, null))?.Cast<object>();
|
||||
if (seedData == null) continue;//没有种子数据就下一个
|
||||
var entityType = seedType.GetInterfaces().First().GetGenericArguments().First();//获取实体类型
|
||||
var tenantAtt = entityType.GetCustomAttribute<TenantAttribute>();//获取sqlsugar租户特性
|
||||
if (tenantAtt != null && tenantAtt.configId.ToString() != config.ConfigId.ToString()) continue;//如果不是当前租户的就下一个
|
||||
var seedDataTable = seedData.ToList().ToDataTable();//获取种子数据
|
||||
seedDataTable.TableName = db.EntityMaintenance.GetEntityInfo(entityType).DbTableName;//获取表名
|
||||
|
||||
if (seedDataTable.Columns.Contains("F_Id"))//判断种子数据是否有主键
|
||||
{
|
||||
var storage = db.Storageable(seedDataTable).WhereColumns("F_Id").ToStorage();
|
||||
|
||||
//codefirst暂时全部新增,根据主键更新,用户表暂不更新
|
||||
storage.AsInsertable.ExecuteCommand();
|
||||
|
||||
var ignoreUpdate = hasDataMethod.GetCustomAttribute<IgnoreSeedDataUpdateAttribute>();//读取忽略更新特性
|
||||
if (ignoreUpdate == null)
|
||||
storage.AsUpdateable.ExecuteCommand();//只有没有忽略更新的特性才执行更新
|
||||
}
|
||||
else // 没有主键或者不是预定义的主键(有重复的可能)
|
||||
{
|
||||
//全量插入
|
||||
var storage = db.Storageable(seedDataTable).ToStorage();
|
||||
storage.AsInsertable.ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化数据库表结构
|
||||
/// </summary>
|
||||
/// <param name="config">数据库配置</param>
|
||||
private static void InitDb(ConnectionConfig config, SqlSugarProvider db)
|
||||
{
|
||||
try
|
||||
{
|
||||
db.DbMaintenance.CreateDatabase();//创建数据库
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"创建数据库失败,开始尝试操作表! ex:{ex.Message}");
|
||||
}
|
||||
|
||||
var entityTypes = GlobalContext.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.IsDefined(typeof(SugarTable), false));
|
||||
if (!entityTypes.Any()) return;//没有就退出
|
||||
foreach (var entityType in entityTypes)
|
||||
{
|
||||
var tenantAtt = entityType.GetCustomAttribute<TenantAttribute>();//获取Sqlsugar多租户特性
|
||||
var ignoreInit = entityType.GetCustomAttribute<IgnoreInitTableAttribute>();//获取忽略初始化特性
|
||||
if (ignoreInit != null) continue;//如果有忽略初始化特性
|
||||
if (tenantAtt != null && tenantAtt.configId.ToString() != config.ConfigId.ToString()) continue;//如果特性存在并且租户ID不是当前数据库ID
|
||||
var splitTable = entityType.GetCustomAttribute<SplitTableAttribute>();//获取自动分表特性
|
||||
|
||||
if (splitTable == null)//如果特性是空
|
||||
{
|
||||
db.CodeFirst.SetStringDefaultLength(50).InitTables(entityType);//普通创建
|
||||
|
||||
}
|
||||
else
|
||||
db.CodeFirst.SetStringDefaultLength(50).SplitTables().InitTables(entityType);//自动分表创建
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断类型是否实现某个泛型
|
||||
/// </summary>
|
||||
/// <param name="type">类型</param>
|
||||
/// <param name="generic">泛型类型</param>
|
||||
/// <returns>bool</returns>
|
||||
public static bool HasImplementedRawGeneric(this System.Type type, System.Type generic)
|
||||
{
|
||||
// 检查接口类型
|
||||
var isTheRawGenericType = type.GetInterfaces().Any(IsTheRawGenericType);
|
||||
if (isTheRawGenericType) return true;
|
||||
|
||||
// 检查类型
|
||||
while (type != null && type != typeof(object))
|
||||
{
|
||||
isTheRawGenericType = IsTheRawGenericType(type);
|
||||
if (isTheRawGenericType) return true;
|
||||
type = type.BaseType;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
// 判断逻辑
|
||||
bool IsTheRawGenericType(System.Type type) => generic == (type.IsGenericType ? type.GetGenericTypeDefinition() : type);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List转DataTable
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="list"></param>
|
||||
/// <returns></returns>
|
||||
public static DataTable ToDataTable<T>(this List<T> list)
|
||||
{
|
||||
DataTable result = new();
|
||||
if (list.Count > 0)
|
||||
{
|
||||
// result.TableName = list[0].GetType().Name; // 表名赋值
|
||||
PropertyInfo[] propertys = list[0].GetType().GetProperties();
|
||||
foreach (PropertyInfo pi in propertys)
|
||||
{
|
||||
System.Type colType = pi.PropertyType;
|
||||
if (colType.IsGenericType && colType.GetGenericTypeDefinition() == typeof(Nullable<>))
|
||||
{
|
||||
colType = colType.GetGenericArguments()[0];
|
||||
}
|
||||
if (IsIgnoreColumn(pi))
|
||||
continue;
|
||||
if (IsJsonColumn(pi))//如果是json特性就是sting类型
|
||||
colType = typeof(string);
|
||||
result.Columns.Add(pi.Name, colType);
|
||||
}
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
ArrayList tempList = new();
|
||||
foreach (PropertyInfo pi in propertys)
|
||||
{
|
||||
if (IsIgnoreColumn(pi))
|
||||
continue;
|
||||
object obj = pi.GetValue(list[i], null);
|
||||
if (IsJsonColumn(pi))//如果是json特性就是转化为json格式
|
||||
obj = obj?.ToJson();//如果json字符串是空就传null
|
||||
tempList.Add(obj);
|
||||
}
|
||||
object[] array = tempList.ToArray();
|
||||
result.LoadDataRow(array, true);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 排除SqlSugar忽略的列
|
||||
/// </summary>
|
||||
/// <param name="pi"></param>
|
||||
/// <returns></returns>
|
||||
private static bool IsIgnoreColumn(PropertyInfo pi)
|
||||
{
|
||||
var sc = pi.GetCustomAttributes<SugarColumn>(false).FirstOrDefault(u => u.IsIgnore == true);
|
||||
return sc != null;
|
||||
}
|
||||
|
||||
private static bool IsJsonColumn(PropertyInfo pi)
|
||||
{
|
||||
var sc = pi.GetCustomAttributes<SugarColumn>(false).FirstOrDefault(u => u.IsJson == true);
|
||||
return sc != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Quartz设置
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
public static IServiceCollection AddQuartz(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<JobExecute>();
|
||||
//注册ISchedulerFactory的实例。
|
||||
services.AddSingleton<IJobFactory, IOCJobFactory>();
|
||||
if (GlobalContext.SystemConfig.IsCluster != true)
|
||||
{
|
||||
services.AddSingleton<ISchedulerFactory, StdSchedulerFactory>();
|
||||
}
|
||||
else
|
||||
{
|
||||
//开启集群模式,具体数据库从官方github下载
|
||||
//https://github.com/quartznet/quartznet/blob/main/database/tables/
|
||||
services.AddSingleton<ISchedulerFactory>(u =>
|
||||
{
|
||||
//当前是mysql的例子,其他数据库做相应更改
|
||||
DbProvider.RegisterDbMetadata("mysql-custom", new DbMetadata()
|
||||
{
|
||||
AssemblyName = typeof(MySqlConnection).Assembly.GetName().Name,
|
||||
ConnectionType = typeof(MySqlConnection),
|
||||
CommandType = typeof(MySqlCommand),
|
||||
ParameterType = typeof(MySqlParameter),
|
||||
ParameterDbType = typeof(System.Data.DbType),
|
||||
ParameterDbTypePropertyName = "DbType",
|
||||
ParameterNamePrefix = "@",
|
||||
ExceptionType = typeof(MySqlException),
|
||||
BindByName = true
|
||||
});
|
||||
var properties = new NameValueCollection
|
||||
{
|
||||
["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz", // 配置Quartz以使用JobStoreTx
|
||||
//["quartz.jobStore.useProperties"] = "true", // 配置AdoJobStore以将字符串用作JobDataMap值
|
||||
["quartz.jobStore.dataSource"] = "myDS", // 配置数据源名称
|
||||
["quartz.jobStore.tablePrefix"] = "QRTZ_", // quartz所使用的表,在当前数据库中的表前缀
|
||||
["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.MySQLDelegate, Quartz", // 配置AdoJobStore使用的DriverDelegate
|
||||
["quartz.dataSource.myDS.connectionString"] = GlobalContext.SystemConfig.DBConnectionString, // 配置数据库连接字符串,自己处理好连接字符串,我这里就直接这么写了
|
||||
["quartz.dataSource.myDS.provider"] = "mysql-custom", // 配置数据库提供程序(这里是自定义的,定义的代码在上面)
|
||||
["quartz.jobStore.lockHandler.type"] = "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz",
|
||||
["quartz.serializer.type"] = "json",
|
||||
["quartz.jobStore.clustered"] = "true", // 指示Quartz.net的JobStore是应对 集群模式
|
||||
["quartz.scheduler.instanceId"] = "AUTO"
|
||||
};
|
||||
return new StdSchedulerFactory(properties);
|
||||
});
|
||||
}
|
||||
//是否开启后台任务
|
||||
if (GlobalContext.SystemConfig.OpenQuartz == true)
|
||||
{
|
||||
services.AddHostedService<JobCenter>();
|
||||
}
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置超管密码
|
||||
/// </summary>
|
||||
public static IServiceCollection ReviseSuperSysem(this IServiceCollection services)
|
||||
{
|
||||
var data = GlobalContext.SystemConfig;
|
||||
try
|
||||
{
|
||||
if (data.ReviseSystem == true)
|
||||
{
|
||||
using (var context = new SqlSugarClient(DBContexHelper.Contex()))
|
||||
{
|
||||
context.Ado.BeginTran();
|
||||
var systemSet = context.Queryable<SystemSetEntity>().First(a => a.F_DbNumber == data.MainDbNumber);
|
||||
var user = context.Queryable<UserEntity>().First(a => a.F_CompanyId == systemSet.F_Id && a.F_IsAdmin == true);
|
||||
var userinfo = context.Queryable<UserLogOnEntity>().Where(a => a.F_UserId == user.F_Id).First();
|
||||
userinfo.F_UserSecretkey = Md5.md5(Utils.CreateNo(), 16).ToLower();
|
||||
userinfo.F_UserPassword = Md5.md5(DESEncrypt.Encrypt(Md5.md5(systemSet.F_AdminPassword, 32).ToLower(), userinfo.F_UserSecretkey).ToLower(), 32).ToLower();
|
||||
context.Updateable<UserEntity>(a => new UserEntity
|
||||
{
|
||||
F_Account = systemSet.F_AdminAccount
|
||||
}).Where(a => a.F_Id == userinfo.F_Id).ExecuteCommand();
|
||||
context.Updateable<UserLogOnEntity>(a => new UserLogOnEntity
|
||||
{
|
||||
F_UserPassword = userinfo.F_UserPassword,
|
||||
F_UserSecretkey = userinfo.F_UserSecretkey
|
||||
}).Where(a => a.F_Id == userinfo.F_Id).ExecuteCommand();
|
||||
context.Ado.CommitTran();
|
||||
CacheHelper.Remove(GlobalContext.SystemConfig.ProjectPrefix + "_operator_" + "info_" + user.F_Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Write(ex);
|
||||
}
|
||||
return services;
|
||||
}
|
||||
/// <summary>
|
||||
/// 注册事件总线
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <returns></returns>
|
||||
public static IServiceCollection AddEventBus(this IServiceCollection services)
|
||||
{
|
||||
// 注册 EventBus 服务
|
||||
return services.AddEventBus(builder =>
|
||||
{
|
||||
if (GlobalContext.SystemConfig.RabbitMq.Enabled)
|
||||
{
|
||||
// 创建连接工厂
|
||||
var factory = new ConnectionFactory
|
||||
{
|
||||
HostName= GlobalContext.SystemConfig.RabbitMq.HostName,
|
||||
VirtualHost= GlobalContext.SystemConfig.RabbitMq.VirtualHost,
|
||||
Port= GlobalContext.SystemConfig.RabbitMq.Port,
|
||||
UserName = GlobalContext.SystemConfig.RabbitMq.UserName,
|
||||
Password = GlobalContext.SystemConfig.RabbitMq.Password
|
||||
};
|
||||
// 创建默认内存通道事件源对象,可自定义队列路由key,比如这里是 eventbus
|
||||
var rbmqEventSourceStorer = new RabbitMQEventSourceStorer(factory, GlobalContext.SystemConfig.ProjectPrefix
|
||||
+ "_eventbus", 3000);
|
||||
// 替换默认事件总线存储器
|
||||
builder.ReplaceStorer(serviceProvider =>
|
||||
{
|
||||
return rbmqEventSourceStorer;
|
||||
});
|
||||
}
|
||||
// 注册 ToDo 事件订阅者
|
||||
builder.AddSubscriber<LogEventSubscriber>();
|
||||
builder.AddSubscriber<MessageEventSubscriber>();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
186
WaterCloud.Service/OrderManagement/OrderService.cs
Normal file
186
WaterCloud.Service/OrderManagement/OrderService.cs
Normal file
@@ -0,0 +1,186 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.DataBase;
|
||||
using WaterCloud.Domain.OrderManagement;
|
||||
|
||||
namespace WaterCloud.Service.OrderManagement
|
||||
{
|
||||
/// <summary>
|
||||
/// 创 建:超级管理员
|
||||
/// 日 期:2021-07-12 20:41
|
||||
/// 描 述:订单管理服务类
|
||||
/// </summary>
|
||||
public class OrderService : BaseService<OrderEntity>, IDenpendency
|
||||
{
|
||||
public OrderService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
#region 获取数据
|
||||
|
||||
public async Task<List<OrderEntity>> GetList(string keyword = "")
|
||||
{
|
||||
var data = repository.IQueryable();
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
data = data.Where(a => a.F_OrderCode.Contains(keyword)
|
||||
|| a.F_Description.Contains(keyword));
|
||||
}
|
||||
return await data.Where(a => a.F_DeleteMark == false).OrderBy(a => a.F_NeedTime).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<OrderEntity>> GetLookList(string keyword = "")
|
||||
{
|
||||
var query = repository.IQueryable().Where(a => a.F_DeleteMark == false);
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
//此处需修改
|
||||
query = query.Where(a => a.F_OrderCode.Contains(keyword)
|
||||
|| a.F_Description.Contains(keyword));
|
||||
}
|
||||
//权限过滤
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
return await query.OrderBy(a => a.F_NeedTime).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<OrderEntity>> GetLookList(SoulPage<OrderEntity> pagination, string keyword = "", string id = "")
|
||||
{
|
||||
var query = IQuery().Where(a => a.F_DeleteMark == false);
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_OrderCode.Contains(keyword)
|
||||
|| a.F_Description.Contains(keyword));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(id))
|
||||
{
|
||||
query = query.Where(a => a.F_Id == id);
|
||||
}
|
||||
//权限过滤
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
return await query.ToPageListAsync(pagination);
|
||||
}
|
||||
|
||||
private ISugarQueryable<OrderEntity> IQuery()
|
||||
{
|
||||
var details = repository.Db.Queryable<OrderDetailEntity>().GroupBy(a => a.F_OrderId).Select<Object>(a => new
|
||||
{
|
||||
a.F_OrderId,
|
||||
F_NeedNum = SqlFunc.AggregateSum(a.F_NeedNum),
|
||||
F_ActualNum = SqlFunc.AggregateSum(a.F_ActualNum),
|
||||
});
|
||||
var order = repository.Db.Queryable<OrderEntity>();
|
||||
var query = repository.Db.Queryable(order, details, JoinType.Inner, (a, b) => a.F_Id == SqlFunc.MappingColumn(default(string), "b.F_OrderId")).Select((a, b) => new OrderEntity
|
||||
{
|
||||
F_Id = a.F_Id,
|
||||
F_ActualTime = a.F_ActualTime,
|
||||
F_CreatorTime = a.F_CreatorTime,
|
||||
F_CreatorUserId = a.F_CreatorUserId,
|
||||
F_CreatorUserName = a.F_CreatorUserName,
|
||||
F_DeleteMark = a.F_DeleteMark,
|
||||
F_DeleteTime = a.F_DeleteTime,
|
||||
F_DeleteUserId = a.F_DeleteUserId,
|
||||
F_Description = a.F_Description,
|
||||
F_EnabledMark = a.F_EnabledMark,
|
||||
F_LastModifyTime = a.F_LastModifyTime,
|
||||
F_LastModifyUserId = a.F_LastModifyUserId,
|
||||
F_NeedTime = a.F_NeedTime,
|
||||
F_OrderCode = a.F_OrderCode,
|
||||
F_OrderState = a.F_OrderState,
|
||||
F_NeedNum = SqlFunc.MappingColumn(default(int), "b.F_NeedNum"),
|
||||
F_ActualNum = SqlFunc.MappingColumn(default(int), "b.F_ActualNum"),
|
||||
}).MergeTable();
|
||||
return query;
|
||||
}
|
||||
|
||||
public async Task<OrderEntity> GetForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
data.list = await repository.Db.Queryable<OrderDetailEntity>().Where(a => a.F_OrderId == keyValue).ToListAsync();
|
||||
return data;
|
||||
}
|
||||
|
||||
#endregion 获取数据
|
||||
|
||||
public async Task<OrderEntity> GetLookForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
data.list = await repository.Db.Queryable<OrderDetailEntity>().Where(a => a.F_OrderId == keyValue).ToListAsync();
|
||||
return GetFieldsFilterData(data);
|
||||
}
|
||||
|
||||
#region 提交数据
|
||||
|
||||
public async Task SubmitForm(OrderEntity entity, string keyValue)
|
||||
{
|
||||
if (string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
entity.Create();
|
||||
entity.F_DeleteMark = false;
|
||||
entity.F_CreatorUserName = currentuser.UserName;
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.Modify(keyValue);
|
||||
}
|
||||
bool isdone = true;
|
||||
var dataList = new List<OrderDetailEntity>();
|
||||
if (entity.list == null || entity.list.Count == 0)
|
||||
{
|
||||
throw new Exception("产品明细不能为空!");
|
||||
}
|
||||
foreach (var item in entity.list)
|
||||
{
|
||||
item.Create();
|
||||
item.F_CreatorUserName = currentuser.UserName;
|
||||
item.F_CreatorTime = entity.F_CreatorTime;
|
||||
item.F_NeedTime = entity.F_NeedTime;
|
||||
item.F_OrderId = entity.F_Id;
|
||||
item.F_OrderState = item.F_OrderState == null ? 0 : item.F_OrderState;
|
||||
if (item.F_OrderState == 0)
|
||||
{
|
||||
isdone = false;
|
||||
}
|
||||
else if (item.F_ActualTime == null)
|
||||
{
|
||||
item.F_ActualTime = entity.F_NeedTime;
|
||||
}
|
||||
if (string.IsNullOrEmpty(item.F_ProductName))
|
||||
{
|
||||
throw new Exception("请输入明细的产品名称");
|
||||
}
|
||||
dataList.Add(item);
|
||||
}
|
||||
entity.F_OrderState = isdone ? 1 : 0;
|
||||
entity.F_ActualTime = isdone ? dataList.Max(a => a.F_ActualTime) : null;
|
||||
repository.Db.Ado.BeginTran();
|
||||
if (string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
await repository.Insert(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
await repository.Update(entity);
|
||||
}
|
||||
await repository.Db.Deleteable<OrderDetailEntity>().Where(a => a.F_OrderId == entity.F_Id).ExecuteCommandAsync();
|
||||
await repository.Db.Insertable(dataList).ExecuteCommandAsync();
|
||||
repository.Db.Ado.CommitTran();
|
||||
}
|
||||
|
||||
public async Task DeleteForm(string keyValue)
|
||||
{
|
||||
var ids = keyValue.Split(',');
|
||||
await repository.Update(a => ids.Contains(a.F_Id), a => new OrderEntity
|
||||
{
|
||||
F_DeleteMark = true,
|
||||
F_DeleteTime = DateTime.Now,
|
||||
F_DeleteUserId = currentuser.UserId
|
||||
});
|
||||
}
|
||||
|
||||
#endregion 提交数据
|
||||
}
|
||||
}
|
||||
8
WaterCloud.Service/Properties/launchSettings.json
Normal file
8
WaterCloud.Service/Properties/launchSettings.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"profiles": {
|
||||
"WaterCloud.Service": {
|
||||
"commandName": "Project",
|
||||
"nativeDebugging": true
|
||||
}
|
||||
}
|
||||
}
|
||||
82
WaterCloud.Service/SystemManage/AreaService.cs
Normal file
82
WaterCloud.Service/SystemManage/AreaService.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
/*******************************************************************************
|
||||
* Copyright © 2020 WaterCloud.Framework 版权所有
|
||||
* Author: WaterCloud
|
||||
* Description: WaterCloud快速开发平台
|
||||
* Website:
|
||||
*********************************************************************************/
|
||||
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Domain.SystemManage;
|
||||
|
||||
namespace WaterCloud.Service.SystemManage
|
||||
{
|
||||
public class AreaService : BaseService<AreaEntity>, IDenpendency
|
||||
{
|
||||
public AreaService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<List<AreaEntity>> GetList(int layers = 0)
|
||||
{
|
||||
var query = repository.IQueryable();
|
||||
if (layers != 0)
|
||||
{
|
||||
query = query.Where(a => a.F_Layers == layers);
|
||||
}
|
||||
return await query.Where(a => a.F_DeleteMark == false && a.F_EnabledMark == true).OrderBy(a => a.F_SortCode).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<AreaEntity>> GetLookList(int layers = 0)
|
||||
{
|
||||
var query = repository.IQueryable().Where(a => a.F_DeleteMark == false && a.F_EnabledMark == true);
|
||||
if (layers != 0)
|
||||
{
|
||||
query = query.Where(a => a.F_Layers == layers);
|
||||
}
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
return await query.OrderBy(a => a.F_SortCode).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<AreaEntity> GetLookForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return GetFieldsFilterData(data);
|
||||
}
|
||||
|
||||
public async Task<AreaEntity> GetForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task DeleteForm(string keyValue)
|
||||
{
|
||||
if (await repository.IQueryable(a => a.F_ParentId.Equals(keyValue)).AnyAsync())
|
||||
{
|
||||
throw new Exception("删除失败!操作的对象包含了下级数据。");
|
||||
}
|
||||
else
|
||||
{
|
||||
await repository.Delete(a => a.F_Id == keyValue);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SubmitForm(AreaEntity mEntity, string keyValue)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
mEntity.Modify(keyValue);
|
||||
await repository.Update(mEntity);
|
||||
}
|
||||
else
|
||||
{
|
||||
mEntity.F_DeleteMark = false;
|
||||
mEntity.Create();
|
||||
await repository.Insert(mEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
130
WaterCloud.Service/SystemManage/CodegeneratelogService.cs
Normal file
130
WaterCloud.Service/SystemManage/CodegeneratelogService.cs
Normal file
@@ -0,0 +1,130 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using WaterCloud.Code;
|
||||
using SqlSugar;
|
||||
using WaterCloud.DataBase;
|
||||
using WaterCloud.Domain.SystemManage;
|
||||
using WaterCloud.Code.Model;
|
||||
|
||||
namespace WaterCloud.Service.SystemManage
|
||||
{
|
||||
/// <summary>
|
||||
/// 创 建:超级管理员
|
||||
/// 日 期:2022-10-06 14:18
|
||||
/// 描 述:条码生成记录服务类
|
||||
/// </summary>
|
||||
public class CodegeneratelogService : BaseService<CodegeneratelogEntity>, IDenpendency
|
||||
{
|
||||
public CodegeneratelogService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
#region 获取数据
|
||||
public async Task<List<CodegeneratelogEntity>> GetList(string keyword = "")
|
||||
{
|
||||
var data = repository.IQueryable();
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
data = data.Where(a => a.F_Code.Contains(keyword)
|
||||
|| a.F_RuleName.Contains(keyword));
|
||||
}
|
||||
return await data.Where(a => a.F_DeleteMark == false).OrderBy(a => a.F_Id , OrderByType.Desc).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<CodegeneratelogEntity>> GetLookList(string keyword = "")
|
||||
{
|
||||
var query = repository.IQueryable().Where(a => a.F_DeleteMark == false);
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
//此处需修改
|
||||
query = query.Where(a => a.F_Code.Contains(keyword)
|
||||
|| a.F_RuleName.Contains(keyword));
|
||||
}
|
||||
//权限过滤
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
return await query.OrderBy(a => a.F_Id , OrderByType.Desc).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<CodegeneratelogEntity>> GetLookList(SoulPage<CodegeneratelogEntity> pagination,string keyword = "",string id="")
|
||||
{
|
||||
var query = repository.IQueryable().Where(a => a.F_DeleteMark == false);
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_Code.Contains(keyword)
|
||||
|| a.F_RuleName.Contains(keyword));
|
||||
}
|
||||
if(!string.IsNullOrEmpty(id))
|
||||
{
|
||||
query= query.Where(a=>a.F_Id==id);
|
||||
}
|
||||
//权限过滤
|
||||
query = GetDataPrivilege("a","",query);
|
||||
return await query.ToPageListAsync(pagination);
|
||||
}
|
||||
|
||||
public async Task<CodegeneratelogEntity> GetForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return data;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public async Task<CodegeneratelogEntity> GetLookForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return GetFieldsFilterData(data);
|
||||
}
|
||||
|
||||
#region 提交数据
|
||||
public async Task<List<PrintEntity>> Reprint(string keyValue, int count = 1)
|
||||
{
|
||||
var list = new List<PrintEntity>();
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
var rule = await repository.Db.Queryable<CoderuleEntity>().FirstAsync(a => a.F_Id == data.F_RuleId);
|
||||
var template = await repository.Db.Queryable<TemplateEntity>().FirstAsync(a => a.F_Id == rule.F_TemplateId);
|
||||
if (template.F_Batch == true)
|
||||
{
|
||||
PrintEntity entity = new PrintEntity();
|
||||
entity.data = new PrintDetail();
|
||||
entity.data.printIniInfo = new PrintInitInfo();
|
||||
entity.data.printIniInfo.printType = template.F_PrintType;
|
||||
entity.data.printIniInfo.isBatch = template.F_Batch;
|
||||
entity.data.printIniInfo.realName = template.F_TemplateName;
|
||||
entity.data.printIniInfo.filePath = (GlobalContext.HttpContext.Request.IsHttps ? "https://" : "http://") + GlobalContext.HttpContext.Request.Host + template.F_TemplateFile;
|
||||
entity.requestId = Utils.GetGuid();
|
||||
var listJson = new List<Dictionary<string, string>>();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
listJson.Add(data.F_PrintJson.ToObject<Dictionary<string, string>>());
|
||||
}
|
||||
entity.data.data = listJson;
|
||||
list.Add(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
PrintEntity entity = new PrintEntity();
|
||||
entity.data = new PrintDetail();
|
||||
entity.data.printIniInfo = new PrintInitInfo();
|
||||
entity.data.printIniInfo.printType = template.F_PrintType;
|
||||
entity.data.printIniInfo.isBatch = template.F_Batch;
|
||||
entity.data.printIniInfo.realName = template.F_TemplateName;
|
||||
entity.data.printIniInfo.filePath = (GlobalContext.HttpContext.Request.IsHttps ? "https://" : "http://") + GlobalContext.HttpContext.Request.Host + template.F_TemplateFile;
|
||||
entity.requestId = Utils.GetGuid();
|
||||
entity.data.data = data.F_PrintJson.ToObject<Dictionary<string, string>>();
|
||||
list.Add(entity);
|
||||
}
|
||||
}
|
||||
//更新打印次数
|
||||
await repository.Update(a => a.F_Id == keyValue, a => new CodegeneratelogEntity
|
||||
{
|
||||
F_PrintCount = a.F_PrintCount + count
|
||||
});
|
||||
return list;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
492
WaterCloud.Service/SystemManage/CoderuleService.cs
Normal file
492
WaterCloud.Service/SystemManage/CoderuleService.cs
Normal file
@@ -0,0 +1,492 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using WaterCloud.Code;
|
||||
using SqlSugar;
|
||||
using WaterCloud.DataBase;
|
||||
using WaterCloud.Domain.SystemManage;
|
||||
using WaterCloud.Code.Model;
|
||||
using System.Globalization;
|
||||
using NetTaste;
|
||||
|
||||
namespace WaterCloud.Service.SystemManage
|
||||
{
|
||||
/// <summary>
|
||||
/// 创 建:超级管理员
|
||||
/// 日 期:2022-10-06 11:25
|
||||
/// 描 述:条码规则服务类
|
||||
/// </summary>
|
||||
public class CoderuleService : BaseService<CoderuleEntity>, IDenpendency
|
||||
{
|
||||
public CoderuleService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
#region 获取数据
|
||||
public async Task<List<CoderuleEntity>> GetList(string keyword = "")
|
||||
{
|
||||
var data = GetQuery();
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
data = data.Where(a => a.F_RuleName.Contains(keyword));
|
||||
}
|
||||
return await data.OrderBy(a => a.F_Id , OrderByType.Desc).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<CoderuleEntity>> GetLookList(string keyword = "")
|
||||
{
|
||||
var query = GetQuery();
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
//此处需修改
|
||||
query = query.Where(a => a.F_RuleName.Contains(keyword));
|
||||
}
|
||||
//权限过滤
|
||||
query = GetDataPrivilege("a", query: query);
|
||||
return await query.OrderBy(a => a.F_Id , OrderByType.Desc).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<CoderuleEntity>> GetLookList(SoulPage<CoderuleEntity> pagination,string keyword = "",string id="")
|
||||
{
|
||||
//反格式化显示只能用"等于",其他不支持
|
||||
Dictionary<string, Dictionary<string, string>> dic = new Dictionary<string, Dictionary<string, string>>();
|
||||
Dictionary<string, string> enabledTemp = new Dictionary<string, string>();
|
||||
enabledTemp.Add("1", "有效");
|
||||
enabledTemp.Add("0", "无效");
|
||||
dic.Add("F_EnabledMark", enabledTemp);
|
||||
var setList = await GlobalContext.GetService<ItemsDataService>().GetItemList("RuleReset");
|
||||
Dictionary<string, string> resetTemp = new Dictionary<string, string>();
|
||||
foreach (var item in setList)
|
||||
{
|
||||
resetTemp.Add(item.F_ItemCode, item.F_ItemName);
|
||||
}
|
||||
dic.Add("F_Reset", resetTemp);
|
||||
var printList = await GlobalContext.GetService<ItemsDataService>().GetItemList("PrintType");
|
||||
Dictionary<string, string> printTemp = new Dictionary<string, string>();
|
||||
foreach (var item in printList)
|
||||
{
|
||||
printTemp.Add(item.F_ItemCode, item.F_ItemName);
|
||||
}
|
||||
dic.Add("F_PrintType", printTemp);
|
||||
pagination = ChangeSoulData(dic, pagination);
|
||||
var query = GetQuery();
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_RuleName.Contains(keyword));
|
||||
}
|
||||
if(!string.IsNullOrEmpty(id))
|
||||
{
|
||||
query = query.Where(a => a.F_Id == id);
|
||||
}
|
||||
//权限过滤
|
||||
query = GetDataPrivilege("a", query: query);
|
||||
return await query.ToPageListAsync(pagination);
|
||||
}
|
||||
|
||||
public async Task<CoderuleEntity> GetForm(string keyValue)
|
||||
{
|
||||
var data = await GetQuery().FirstAsync(a => a.F_Id == keyValue);
|
||||
return data;
|
||||
}
|
||||
private ISugarQueryable<CoderuleEntity> GetQuery()
|
||||
{
|
||||
var query = repository.IQueryable()
|
||||
.InnerJoin<TemplateEntity>((a,b)=>a.F_TemplateId == b.F_Id)
|
||||
.Select((a, b) => new CoderuleEntity
|
||||
{
|
||||
F_Id=a.F_Id.SelectAll(),
|
||||
F_TemplateName = b.F_TemplateName,
|
||||
F_PrintType = b.F_PrintType,
|
||||
F_Batch=b.F_Batch
|
||||
}).MergeTable().Where(a => a.F_DeleteMark == false);
|
||||
return query;
|
||||
}
|
||||
public async Task<CoderuleEntity> GetLookForm(string keyValue)
|
||||
{
|
||||
var data = await GetQuery().FirstAsync(a => a.F_Id == keyValue);
|
||||
return GetFieldsFilterData(data);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 提交数据
|
||||
public async Task SubmitForm(CoderuleEntity entity, string keyValue)
|
||||
{
|
||||
if(string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
entity.F_DeleteMark = false;
|
||||
entity.Create();
|
||||
await repository.Insert(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.Modify(keyValue);
|
||||
await repository.Update(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteForm(string keyValue)
|
||||
{
|
||||
var ids = keyValue.Split(',');
|
||||
await repository.Delete(a => ids.Contains(a.F_Id.ToString()));
|
||||
}
|
||||
/// <summary>
|
||||
/// 计算编码规则生成流水号<para>注意:此编码规则只支持单个流水号</para>
|
||||
/// </summary>
|
||||
/// <param name="ruleName">规则名称</param>
|
||||
/// <param name="count">生成数量</param>
|
||||
/// <param name="preview">是否预览,预览不新增条码不操作Redis zincr</param>
|
||||
/// <param name="replaceList">通配符替换列表</param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<string>> GetBillNumber(
|
||||
string ruleName,
|
||||
int count,
|
||||
bool preview = false,
|
||||
List<string> replaceList = null)
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
var rule = await repository.Db.Queryable<CoderuleEntity>().FirstAsync(a => a.F_RuleName == ruleName);
|
||||
var resetRule = "NoReset";
|
||||
switch (rule.F_Reset)
|
||||
{
|
||||
//By 年 月 日
|
||||
case "yyyy":
|
||||
case "yyyy-MM":
|
||||
case "yyyy-MM-dd":
|
||||
resetRule = DateTime.Now.ToString(rule.F_Reset); break;
|
||||
//By 周
|
||||
case "yyyy-MM-WW":
|
||||
var gc = new GregorianCalendar();
|
||||
var thisWeek = gc.GetWeekOfYear(now, CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
|
||||
resetRule = DateTime.Now.ToString("yyyy") + "W" + thisWeek; break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
var codeRuleFormatList = rule.F_RuleJson.ToObject<List<CodeRuleFormatEntity>>();
|
||||
//格式化
|
||||
var format = string.Empty;
|
||||
var reset = string.Empty;
|
||||
//流水号长度
|
||||
int flowNumberLength = 5;
|
||||
//流水号初始值
|
||||
int initVal = 0;
|
||||
//流水号最大值
|
||||
int? maxVal = null;
|
||||
//默认10进制
|
||||
int toBase = 10;
|
||||
//步长
|
||||
decimal increment = 1;
|
||||
|
||||
string diyCode = string.Empty;
|
||||
|
||||
char replaceChar = '*';
|
||||
|
||||
List<string> list = new List<string>();
|
||||
|
||||
codeRuleFormatList.ForEach(item =>
|
||||
{
|
||||
//编码前缀类型 1 - 固定参数 2 - 日期 3 - 年 4 - 月 5 - 日 6 - 周别 7 - 周几 8 - 小时 9 - 上午下午 10 - 班别 11 - 流水号 12 - 自定义
|
||||
switch (item.FormatType)
|
||||
{
|
||||
//固定参数
|
||||
case 1:
|
||||
format += item.FormatString;
|
||||
break;
|
||||
//日期
|
||||
case 2:
|
||||
format += now.ToString(item.FormatString);
|
||||
break;
|
||||
//年
|
||||
case 3:
|
||||
var ye = now.ToString("yyyy");
|
||||
//判断是否有自定义
|
||||
if (!string.IsNullOrEmpty(item.FormatString))
|
||||
{
|
||||
var yl = item.FormatString.Length;//yyyy 还是yy 还是y
|
||||
if (yl <= 4)
|
||||
ye = ye.Substring(4 - yl, yl);
|
||||
}
|
||||
format += ye;
|
||||
break;
|
||||
//月
|
||||
case 4:
|
||||
var m = item.DiyDate[now.Month - 1];
|
||||
format += m;
|
||||
break;
|
||||
//日
|
||||
case 5:
|
||||
var d = item.DiyDate[now.Day - 1];
|
||||
format += d;
|
||||
break;
|
||||
//周别 (本年的第几周)
|
||||
case 6:
|
||||
var gc = new GregorianCalendar();
|
||||
var thisWeek = gc.GetWeekOfYear(now, CalendarWeekRule.FirstDay,DayOfWeek.Sunday);
|
||||
var y = item.DiyDate[thisWeek - 1];
|
||||
format += y;
|
||||
break;
|
||||
//周几 (按照周一是第一天算)
|
||||
case 7:
|
||||
var wk = now.DayOfWeek.ToInt();
|
||||
if (wk == 0)
|
||||
wk = 6;
|
||||
else
|
||||
wk -= 1;
|
||||
var w = item.DiyDate[wk];
|
||||
format += w;
|
||||
break;
|
||||
case 8:
|
||||
var h = now.ToString(item.FormatString);
|
||||
format += h;
|
||||
break;
|
||||
case 9:
|
||||
var ch = now.Hour;
|
||||
format += ch < 12? item.DiyDate[0] : item.DiyDate[1];
|
||||
break;
|
||||
//班别
|
||||
case 10:
|
||||
string csstr = "";
|
||||
foreach (var cs in item.DiyDate)
|
||||
{
|
||||
var strs = cs.Split(".");
|
||||
var times = strs[1].Split("-");
|
||||
if (int.Parse(times[0].Split(":")[0]) < int.Parse(times[1].Split(":")[0]))
|
||||
{
|
||||
//开始时间
|
||||
var startTime = DateTime.Parse($"{now:yyyy/MM/dd} {times[0]}");
|
||||
//结束时间
|
||||
var endTime = DateTime.Parse($"{now:yyyy/MM/dd} {times[1]}");
|
||||
if (DateTime.Now>=startTime && DateTime.Now < endTime)
|
||||
{
|
||||
csstr = strs[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//开始时间
|
||||
var startTime = DateTime.Parse($"{now:yyyy/MM/dd} {times[0]}");
|
||||
//结束时间
|
||||
var endTime = DateTime.Parse($"{now:yyyy/MM/dd} {times[1]}").AddDays(1);
|
||||
if (DateTime.Now >= startTime && DateTime.Now < endTime)
|
||||
{
|
||||
csstr = strs[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
format += csstr;
|
||||
break;
|
||||
//流水
|
||||
case 11:
|
||||
initVal = item.InitValue.Value;
|
||||
maxVal = item.MaxValue;
|
||||
flowNumberLength = item.FormatString.Length;
|
||||
toBase = item.ToBase;
|
||||
format += "^_^";
|
||||
increment = item.Increment.Value;
|
||||
break;
|
||||
//自定义方法
|
||||
case 12:
|
||||
//反射执行方法获取参数
|
||||
var udf =((Task<string>)this.GetType().GetMethod(item.FormatString, new Type[] { }).Invoke(this, new object[] { ruleName })).GetAwaiter().GetResult();
|
||||
format += udf;
|
||||
break;
|
||||
//通配符
|
||||
case 13:
|
||||
//如果作为检查流水号的长度的条件,则最后一个通配符是00,2位,那么流水号是4位,就会有问题 2 != 4
|
||||
replaceChar = item.FormatString.FirstOrDefault();
|
||||
var tempstr = "".PadLeft(item.FormatString.Length, replaceChar);
|
||||
format += tempstr;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
//判断编码格式是否有效
|
||||
if (!string.IsNullOrEmpty(format))
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var score = 0M;
|
||||
var scoreString = string.Empty;
|
||||
//预览
|
||||
if (!preview)
|
||||
{
|
||||
if (GlobalContext.SystemConfig.CacheProvider == Define.CACHEPROVIDER_REDIS)
|
||||
{
|
||||
score = await BaseHelper.ZIncrByAsync(GlobalContext.SystemConfig.ProjectPrefix + $"_BillNumber:{ruleName}", resetRule, increment);
|
||||
}
|
||||
else
|
||||
{
|
||||
var rulelog = await repository.Db.Queryable<CoderulelogEntity>().FirstAsync(a => a.F_Key == GlobalContext.SystemConfig.ProjectPrefix + $"_BillNumber:{ruleName}" && a.F_Value == resetRule);
|
||||
if (rulelog == null)
|
||||
{
|
||||
rulelog = new CoderulelogEntity();
|
||||
rulelog.F_Id = Utils.GetGuid();
|
||||
rulelog.F_Key = GlobalContext.SystemConfig.ProjectPrefix + $"_BillNumber:{ruleName}";
|
||||
rulelog.F_Value = resetRule;
|
||||
rulelog.F_Score = (int)increment;
|
||||
rulelog.F_RuleId = rule.F_Id;
|
||||
await repository.Db.Insertable(rulelog).ExecuteCommandAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
await repository.Db.Updateable<CoderulelogEntity>(a => new CoderulelogEntity
|
||||
{
|
||||
F_Score = a.F_Score + (int)increment
|
||||
}).Where(a => a.F_Id == rulelog.F_Id).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GlobalContext.SystemConfig.CacheProvider == Define.CACHEPROVIDER_REDIS)
|
||||
{
|
||||
score = await BaseHelper.ZScoreAsync(GlobalContext.SystemConfig.ProjectPrefix + $"_BillNumber:{ruleName}", resetRule)??0;
|
||||
score += increment;
|
||||
}
|
||||
else
|
||||
{
|
||||
var rulelog = await repository.Db.Queryable<CoderulelogEntity>().FirstAsync(a => a.F_Key == GlobalContext.SystemConfig.ProjectPrefix + $"_BillNumber:{ruleName}" && a.F_Value == resetRule);
|
||||
if (rulelog == null)
|
||||
{
|
||||
score += increment;
|
||||
}
|
||||
else
|
||||
{
|
||||
score = (rulelog.F_Score??0) + increment;
|
||||
}
|
||||
}
|
||||
}
|
||||
//10进制流水号
|
||||
var flowNumber = score + initVal;
|
||||
|
||||
//判断流水号是否超过流水号设定的最大值
|
||||
if (maxVal > 0 && flowNumber > maxVal)
|
||||
throw new Exception($"Morethan the flownumber settinged max value:{maxVal} and now value:{flowNumber}");
|
||||
|
||||
//默认10进制
|
||||
scoreString = flowNumber.ToString();
|
||||
|
||||
if (toBase != 10)
|
||||
scoreString = scoreString.ToLong().ToBase(toBase);
|
||||
|
||||
//^_^是代表可以任意位置流水号
|
||||
var flow = scoreString.PadLeft(flowNumberLength, '0');
|
||||
if (flow.Length != flowNumberLength)
|
||||
{
|
||||
throw new Exception($"bill encode ({ruleName})settinged error,FlowLength,current:[{flow.Length}],setting:[{flowNumberLength}]");
|
||||
}
|
||||
var v = format.Replace("^_^", flow);
|
||||
if (replaceList!=null&&replaceList.Count>0)
|
||||
foreach (var item in replaceList)
|
||||
{
|
||||
var temp = "".PadLeft(item.Length, replaceChar);
|
||||
v = v.ReplaceFrist(temp, item);
|
||||
}
|
||||
list.Add(v);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
public async Task<Dictionary<string,string>> GetPrintJson(string code,string templateId)
|
||||
{
|
||||
var template = await repository.Db.Queryable<TemplateEntity>().FirstAsync(a => a.F_Id == templateId);
|
||||
List<SugarParameter> list = new List<SugarParameter>();
|
||||
list.Add(new SugarParameter("rulecode", code));
|
||||
if (!string.IsNullOrEmpty(template.F_TemplateSqlParm))
|
||||
{
|
||||
var dic = template.F_TemplateSqlParm.ToObject<Dictionary<string, object>>();
|
||||
foreach (var item in dic)
|
||||
{
|
||||
list.Add(new SugarParameter(item.Key, item.Value));
|
||||
}
|
||||
}
|
||||
var printResult = string.IsNullOrEmpty(template.F_TemplateSql) ? null : await repository.Db.Ado.SqlQueryAsync<dynamic>(template.F_TemplateSql, list);
|
||||
if (printResult!=null && printResult.Count>0)
|
||||
{
|
||||
var printData = (printResult[0] as IDictionary<string, object>)?.ToDictionary(k => k.Key.ToLower(), v => v.Value?.ToString());
|
||||
printData.Add("rulecode", code);
|
||||
return printData;
|
||||
}
|
||||
else
|
||||
{
|
||||
var printData = new Dictionary<string, string>();
|
||||
printData.Add("rulecode", code);
|
||||
return printData;
|
||||
}
|
||||
}
|
||||
public async Task<List<PrintEntity>> CreateForm(string keyValue, int count = 1, bool needPrint = false)
|
||||
{
|
||||
var list = new List<PrintEntity>();
|
||||
var rule = await repository.Db.Queryable<CoderuleEntity>().FirstAsync(a => a.F_Id == keyValue);
|
||||
var template = await repository.Db.Queryable<TemplateEntity>().FirstAsync(a => a.F_Id == rule.F_TemplateId);
|
||||
var logs = new List<CodegeneratelogEntity>();
|
||||
var codes = await GetBillNumber(rule.F_RuleName, count);
|
||||
if (template.F_Batch == true)
|
||||
{
|
||||
PrintEntity entity = new PrintEntity();
|
||||
entity.data = new PrintDetail();
|
||||
entity.data.printIniInfo = new PrintInitInfo();
|
||||
entity.data.printIniInfo.printType = template.F_PrintType;
|
||||
entity.data.printIniInfo.isBatch = template.F_Batch;
|
||||
entity.data.printIniInfo.realName = template.F_TemplateName;
|
||||
entity.data.printIniInfo.filePath = (GlobalContext.HttpContext.Request.IsHttps ? "https://" : "http://") + GlobalContext.HttpContext.Request.Host + template.F_TemplateFile;
|
||||
entity.requestId = Utils.GetGuid();
|
||||
var listJson = new List<Dictionary<string, string>>();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var log = new CodegeneratelogEntity();
|
||||
log.Create();
|
||||
log.F_Code = codes[i];
|
||||
log.F_PrintCount = needPrint ? 1 : 0;
|
||||
log.F_RuleId = rule.F_Id;
|
||||
log.F_RuleName = rule.F_RuleName;
|
||||
log.F_EnabledMark = true;
|
||||
log.F_DeleteMark = false;
|
||||
var printJson = await GetPrintJson(log.F_Code, template.F_Id);
|
||||
log.F_PrintJson = printJson.ToJson();
|
||||
logs.Add(log);
|
||||
listJson.Add(printJson);
|
||||
}
|
||||
entity.data.data = listJson;
|
||||
list.Add(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var log = new CodegeneratelogEntity();
|
||||
log.Create();
|
||||
log.F_Code = codes[i];
|
||||
log.F_PrintCount = needPrint ? 1 : 0;
|
||||
log.F_RuleId = rule.F_Id;
|
||||
log.F_RuleName = rule.F_RuleName;
|
||||
log.F_EnabledMark = true;
|
||||
log.F_DeleteMark = false;
|
||||
var printJson = await GetPrintJson(log.F_Code, template.F_Id);
|
||||
log.F_PrintJson = printJson.ToJson();
|
||||
logs.Add(log);
|
||||
PrintEntity entity = new PrintEntity();
|
||||
entity.data = new PrintDetail();
|
||||
entity.data.printIniInfo = new PrintInitInfo();
|
||||
entity.data.printIniInfo.printType = template.F_PrintType;
|
||||
entity.data.printIniInfo.isBatch = template.F_Batch;
|
||||
entity.data.printIniInfo.realName = template.F_TemplateName;
|
||||
entity.data.printIniInfo.filePath = (GlobalContext.HttpContext.Request.IsHttps ? "https://" : "http://") + GlobalContext.HttpContext.Request.Host + template.F_TemplateFile;
|
||||
entity.requestId = Utils.GetGuid();
|
||||
entity.data.data = printJson;
|
||||
list.Add(entity);
|
||||
}
|
||||
}
|
||||
//新增log
|
||||
await repository.Db.Insertable(logs).ExecuteCommandAsync();
|
||||
return list;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
187
WaterCloud.Service/SystemManage/FlowschemeService.cs
Normal file
187
WaterCloud.Service/SystemManage/FlowschemeService.cs
Normal file
@@ -0,0 +1,187 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.DataBase;
|
||||
using WaterCloud.Domain.FlowManage;
|
||||
using WaterCloud.Domain.SystemManage;
|
||||
using WaterCloud.Domain.SystemOrganize;
|
||||
|
||||
namespace WaterCloud.Service.SystemManage
|
||||
{
|
||||
/// <summary>
|
||||
/// 创 建:超级管理员
|
||||
/// 日 期:2020-07-10 08:49
|
||||
/// 描 述:流程设计服务类
|
||||
/// </summary>
|
||||
public class FlowschemeService : BaseService<FlowschemeEntity>, IDenpendency
|
||||
{
|
||||
public FlowschemeService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
#region 获取数据
|
||||
|
||||
public async Task<List<FlowschemeEntity>> GetList(string keyword = "")
|
||||
{
|
||||
var query = repository.IQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_SchemeCode.Contains(keyword) || a.F_SchemeName.Contains(keyword));
|
||||
}
|
||||
var list = currentuser.OrganizeId?.Split(',');
|
||||
if (list.Any())
|
||||
{
|
||||
return await query.Where(a => a.F_DeleteMark == false && (a.F_OrganizeId == "" || a.F_OrganizeId == null || list.Contains(a.F_OrganizeId))).OrderBy(a => a.F_Id, OrderByType.Desc).ToListAsync();
|
||||
}
|
||||
return await query.Where(a => a.F_DeleteMark == false && a.F_OrganizeId == "" || a.F_OrganizeId == null).OrderBy(a => a.F_Id, OrderByType.Desc).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<FlowschemeEntity>> GetLookList(string ItemId = "", string keyword = "")
|
||||
{
|
||||
var query = repository.IQueryable().Where(a => a.F_DeleteMark == false);
|
||||
if (!string.IsNullOrEmpty(ItemId))
|
||||
{
|
||||
query = query.Where(a => a.F_OrganizeId == ItemId || a.F_OrganizeId == null || a.F_OrganizeId == "");
|
||||
}
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_SchemeCode.Contains(keyword) || a.F_SchemeName.Contains(keyword));
|
||||
}
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
return await query.OrderBy(a => a.F_CreatorTime, OrderByType.Desc).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<FlowschemeEntity>> GetLookList(Pagination pagination, string keyword = "")
|
||||
{
|
||||
var query = repository.IQueryable().Where(a => a.F_DeleteMark == false);
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_SchemeCode.Contains(keyword) || a.F_SchemeName.Contains(keyword));
|
||||
}
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
return await query.ToPageListAsync(pagination);
|
||||
}
|
||||
|
||||
public async Task<FlowschemeEntity> GetForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return data;
|
||||
}
|
||||
|
||||
#endregion 获取数据
|
||||
|
||||
public async Task<FlowschemeEntity> GetLookForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return GetFieldsFilterData(data);
|
||||
}
|
||||
|
||||
public async Task<FlowschemeExtend> GetFormExtend(string keyValue)
|
||||
{
|
||||
var cachedata = await repository.FindEntity(keyValue);
|
||||
var temp = cachedata.MapTo<FlowschemeExtend>();
|
||||
var form = await repository.Db.Queryable<FormEntity>().InSingleAsync(cachedata.F_FrmId);
|
||||
temp.F_WebId = form.F_WebId;
|
||||
if (form.F_FrmType == 0)
|
||||
temp.F_WebId = form.F_DbName;
|
||||
temp.F_FrmContentData = form.F_ContentData;
|
||||
temp.F_FrmContent = form.F_Content;
|
||||
//创建运行实例
|
||||
var flowinstance = new FlowinstanceEntity();
|
||||
flowinstance.F_SchemeContent = temp.F_SchemeContent;
|
||||
var runtime = new FlowRuntime(flowinstance);
|
||||
if (runtime.nextNodeType != -1 && runtime.nextNode != null && runtime.nextNode.setInfo != null && runtime.nextNodeType != 4)
|
||||
{
|
||||
temp.NextNodeDesignateType = runtime.nextNode.setInfo.NodeDesignate;
|
||||
if (temp.NextNodeDesignateType == Setinfo.SPECIAL_USER)
|
||||
{
|
||||
temp.NextNodeDesignates = runtime.nextNode.setInfo.NodeDesignateData.users;
|
||||
temp.NextMakerName = string.Join(',', repository.Db.Queryable<UserEntity>().Where(a => temp.NextNodeDesignates.Contains(a.F_Id)).Select(a => a.F_RealName).ToList());
|
||||
}
|
||||
else if (temp.NextNodeDesignateType == Setinfo.SPECIAL_ROLE)
|
||||
{
|
||||
temp.NextNodeDesignates = runtime.nextNode.setInfo.NodeDesignateData.roles;
|
||||
List<UserEntity> list = new List<UserEntity>();
|
||||
List<string> users = new List<string>();
|
||||
foreach (var item in temp.NextNodeDesignates)
|
||||
{
|
||||
var usertemp = repository.Db.Queryable<UserEntity>().Where(a => a.F_RoleId.Contains(item)).ToList();
|
||||
var tempList = new List<UserEntity>();
|
||||
if (runtime.nextNode.setInfo.NodeDesignateData.currentDepart)
|
||||
{
|
||||
var currentDepartment = repository.Db.Queryable<UserEntity>().InSingle(currentuser.UserId).F_OrganizeId.Split(',').ToList();
|
||||
foreach (var user in usertemp)
|
||||
{
|
||||
var nextCurrentDepartment = user.F_OrganizeId.Split(',').ToList();
|
||||
if (TextHelper.IsArrayIntersection(currentDepartment, nextCurrentDepartment))
|
||||
{
|
||||
tempList.Add(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tempList = usertemp;
|
||||
}
|
||||
var tempFinal = tempList.Select(a => a.F_Id).ToList();
|
||||
users.AddRange(tempFinal);
|
||||
}
|
||||
users = users.Distinct().ToList();
|
||||
temp.NextMakerName = string.Join(',', repository.Db.Queryable<UserEntity>().Where(a => users.Contains(a.F_Id)).Select(a => a.F_RealName).ToList());
|
||||
}
|
||||
else if (temp.NextNodeDesignateType == Setinfo.DEPARTMENT_MANAGER)//部门负责人
|
||||
{
|
||||
var orgs = runtime.nextNode.setInfo.NodeDesignateData.orgs;
|
||||
if (runtime.nextNode.setInfo.NodeDesignateData.currentDepart)
|
||||
{
|
||||
orgs = currentuser.OrganizeId.Split(',');
|
||||
}
|
||||
var departments = repository.Db.Queryable<OrganizeEntity>().Where(a => orgs.Contains(a.F_Id) && !string.IsNullOrEmpty(a.F_ManagerId)).Select(a => a.F_ManagerId).ToList();
|
||||
var departmentNames = repository.Db.Queryable<UserEntity>().Where(a => departments.Contains(a.F_Id)).Select(a => a.F_RealName).ToList();
|
||||
temp.NextMakerName = string.Join(',', departmentNames);
|
||||
}
|
||||
else if (temp.NextNodeDesignateType == Setinfo.USER_MANAGER || temp.NextNodeDesignateType == Setinfo.MORE_USER_MANAGER)//直属上级、直属上级多级负责人
|
||||
{
|
||||
var userEntity = repository.Db.Queryable<UserEntity>().InSingle(currentuser.UserId);
|
||||
if (userEntity != null)
|
||||
{
|
||||
var manager = repository.Db.Queryable<UserEntity>().InSingle(userEntity.F_ManagerId);
|
||||
temp.NextMakerName = manager?.F_RealName;
|
||||
}
|
||||
}
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
#region 提交数据
|
||||
|
||||
public async Task SubmitForm(FlowschemeEntity entity, string keyValue)
|
||||
{
|
||||
if (string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
//此处需修改
|
||||
entity.Create();
|
||||
await repository.Insert(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
//此处需修改
|
||||
entity.Modify(keyValue);
|
||||
await repository.Update(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteForm(string keyValue)
|
||||
{
|
||||
var ids = keyValue.Split(',');
|
||||
await repository.Delete(a => ids.Contains(a.F_Id));
|
||||
}
|
||||
|
||||
#endregion 提交数据
|
||||
}
|
||||
}
|
||||
129
WaterCloud.Service/SystemManage/FormService.cs
Normal file
129
WaterCloud.Service/SystemManage/FormService.cs
Normal file
@@ -0,0 +1,129 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.DataBase;
|
||||
using WaterCloud.Domain.SystemManage;
|
||||
using WaterCloud.Domain.SystemOrganize;
|
||||
|
||||
namespace WaterCloud.Service.SystemManage
|
||||
{
|
||||
/// <summary>
|
||||
/// 创 建:超级管理员
|
||||
/// 日 期:2020-07-08 14:33
|
||||
/// 描 述:表单设计服务类
|
||||
/// </summary>
|
||||
public class FormService : BaseService<FormEntity>, IDenpendency
|
||||
{
|
||||
public FormService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
#region 获取数据
|
||||
|
||||
public async Task<List<FormEntity>> GetList(string keyword = "")
|
||||
{
|
||||
var query = repository.IQueryable();
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_Name.Contains(keyword) || a.F_Description.Contains(keyword));
|
||||
}
|
||||
return await query.Where(a => a.F_DeleteMark == false).OrderBy(a => a.F_Id, OrderByType.Desc).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<FormEntity>> GetLookList(string ItemId = "", string keyword = "")
|
||||
{
|
||||
var query = GetQuery().Where(a => a.F_DeleteMark == false);
|
||||
if (!string.IsNullOrEmpty(ItemId))
|
||||
{
|
||||
query = query.Where(a => a.F_OrganizeId == ItemId || a.F_OrganizeId == null || a.F_OrganizeId == "");
|
||||
}
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_Name.Contains(keyword) || a.F_Description.Contains(keyword));
|
||||
}
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
return await query.Where(a => a.F_DeleteMark == false).OrderBy(a => a.F_Id, OrderByType.Desc).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<FormEntity>> GetLookList(Pagination pagination, string keyword = "")
|
||||
{
|
||||
//获取数据权限
|
||||
var query = GetQuery().Where(a => a.F_DeleteMark == false);
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_Name.Contains(keyword) || a.F_Description.Contains(keyword));
|
||||
}
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
return await query.ToPageListAsync(pagination);
|
||||
}
|
||||
|
||||
private ISugarQueryable<FormEntity> GetQuery()
|
||||
{
|
||||
var query = repository.Db.Queryable<FormEntity, OrganizeEntity>((a, b) => new JoinQueryInfos(
|
||||
JoinType.Left, a.F_OrganizeId == b.F_Id
|
||||
))
|
||||
.Select((a, b) => new FormEntity
|
||||
{
|
||||
F_Id = a.F_Id.SelectAll(),
|
||||
F_OrganizeName = b.F_FullName,
|
||||
}).MergeTable();
|
||||
return query;
|
||||
}
|
||||
|
||||
public async Task<FormEntity> GetForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<FormEntity> GetLookForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return GetFieldsFilterData(data);
|
||||
}
|
||||
|
||||
#endregion 获取数据
|
||||
|
||||
#region 提交数据
|
||||
|
||||
public async Task SubmitForm(FormEntity entity, string keyValue)
|
||||
{
|
||||
if (entity.F_FrmType != 1)
|
||||
{
|
||||
var temp = FormUtil.SetValue(entity.F_Content);
|
||||
entity.F_ContentData = string.Join(',', temp.ToArray());
|
||||
entity.F_Fields = temp.Count();
|
||||
}
|
||||
else
|
||||
{
|
||||
var temp = FormUtil.SetValueByWeb(entity.F_WebId);
|
||||
entity.F_ContentData = string.Join(',', temp.ToArray());
|
||||
entity.F_Fields = temp.Count();
|
||||
}
|
||||
if (string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
//此处需修改
|
||||
entity.F_DeleteMark = false;
|
||||
entity.Create();
|
||||
await repository.Insert(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
//此处需修改
|
||||
entity.Modify(keyValue);
|
||||
await repository.Update(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteForm(string keyValue)
|
||||
{
|
||||
var ids = keyValue.Split(',');
|
||||
await repository.Delete(a => ids.Contains(a.F_Id));
|
||||
}
|
||||
|
||||
#endregion 提交数据
|
||||
}
|
||||
}
|
||||
97
WaterCloud.Service/SystemManage/ItemsDataService.cs
Normal file
97
WaterCloud.Service/SystemManage/ItemsDataService.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
/*******************************************************************************
|
||||
* Copyright © 2020 WaterCloud.Framework 版权所有
|
||||
* Author: WaterCloud
|
||||
* Description: WaterCloud快速开发平台
|
||||
* Website:
|
||||
*********************************************************************************/
|
||||
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Domain.SystemManage;
|
||||
|
||||
namespace WaterCloud.Service.SystemManage
|
||||
{
|
||||
public class ItemsDataService : BaseService<ItemsDetailEntity>, IDenpendency
|
||||
{
|
||||
public ItemsTypeService itemApp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 缓存操作类
|
||||
/// </summary>
|
||||
public ItemsDataService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
//获取类名
|
||||
|
||||
public async Task<List<ItemsDetailEntity>> GetList(string itemId = "", string keyword = "")
|
||||
{
|
||||
var list = repository.IQueryable();
|
||||
if (!string.IsNullOrEmpty(itemId))
|
||||
{
|
||||
list = list.Where(a => a.F_ItemId == itemId);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
list = list.Where(a => a.F_ItemName.Contains(keyword) || a.F_ItemCode.Contains(keyword));
|
||||
}
|
||||
return await list.Where(a => a.F_DeleteMark == false).OrderBy(a => a.F_SortCode).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<ItemsDetailEntity>> GetLookList(string itemId = "", string keyword = "")
|
||||
{
|
||||
var query = repository.IQueryable().Where(a => a.F_DeleteMark == false);
|
||||
if (!string.IsNullOrEmpty(itemId))
|
||||
{
|
||||
query = query.Where(a => a.F_ItemId == itemId);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_ItemName.Contains(keyword) || a.F_ItemCode.Contains(keyword));
|
||||
}
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
return await query.OrderBy(a => a.F_SortCode).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<ItemsDetailEntity>> GetItemList(string enCode)
|
||||
{
|
||||
var itemcachedata = await itemApp.GetList();
|
||||
var item = itemcachedata.Find(a => a.F_EnCode == enCode);
|
||||
var data = repository.IQueryable();
|
||||
return data.Where(a => a.F_DeleteMark == false && a.F_EnabledMark == true && a.F_ItemId == item.F_Id).OrderBy(a => a.F_SortCode).ToList();
|
||||
}
|
||||
|
||||
public async Task<ItemsDetailEntity> GetLookForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return GetFieldsFilterData(data);
|
||||
}
|
||||
|
||||
public async Task<ItemsDetailEntity> GetForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task DeleteForm(string keyValue)
|
||||
{
|
||||
await repository.Delete(a => a.F_Id == keyValue);
|
||||
}
|
||||
|
||||
public async Task SubmitForm(ItemsDetailEntity itemsDetailEntity, string keyValue)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
itemsDetailEntity.Modify(keyValue);
|
||||
await repository.Update(itemsDetailEntity);
|
||||
}
|
||||
else
|
||||
{
|
||||
itemsDetailEntity.F_DeleteMark = false;
|
||||
itemsDetailEntity.Create();
|
||||
await repository.Insert(itemsDetailEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
75
WaterCloud.Service/SystemManage/ItemsTypeService.cs
Normal file
75
WaterCloud.Service/SystemManage/ItemsTypeService.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
/*******************************************************************************
|
||||
* Copyright © 2020 WaterCloud.Framework 版权所有
|
||||
* Author: WaterCloud
|
||||
* Description: WaterCloud快速开发平台
|
||||
* Website:
|
||||
*********************************************************************************/
|
||||
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Domain.SystemManage;
|
||||
|
||||
namespace WaterCloud.Service.SystemManage
|
||||
{
|
||||
public class ItemsTypeService : BaseService<ItemsEntity>, IDenpendency
|
||||
{
|
||||
public ItemsTypeService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<List<ItemsEntity>> GetList()
|
||||
{
|
||||
var query = repository.IQueryable();
|
||||
return await query.Where(a => a.F_DeleteMark == false).OrderBy(a => a.F_SortCode).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<ItemsEntity>> GetLookList()
|
||||
{
|
||||
var query = repository.IQueryable().Where(a => a.F_DeleteMark == false);
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
return await query.OrderBy(a => a.F_SortCode).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<ItemsEntity> GetLookForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return GetFieldsFilterData(data);
|
||||
}
|
||||
|
||||
public async Task<ItemsEntity> GetForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task DeleteForm(string keyValue)
|
||||
{
|
||||
if (await repository.IQueryable(a => a.F_ParentId.Equals(keyValue)).AnyAsync())
|
||||
{
|
||||
throw new Exception("删除失败!操作的对象包含了下级数据。");
|
||||
}
|
||||
else
|
||||
{
|
||||
await repository.Delete(a => a.F_Id == keyValue);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SubmitForm(ItemsEntity itemsEntity, string keyValue)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
itemsEntity.Modify(keyValue);
|
||||
await repository.Update(itemsEntity);
|
||||
}
|
||||
else
|
||||
{
|
||||
itemsEntity.F_DeleteMark = false;
|
||||
itemsEntity.F_IsTree = false;
|
||||
itemsEntity.Create();
|
||||
await repository.Insert(itemsEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
172
WaterCloud.Service/SystemManage/ModuleButtonService.cs
Normal file
172
WaterCloud.Service/SystemManage/ModuleButtonService.cs
Normal file
@@ -0,0 +1,172 @@
|
||||
/*******************************************************************************
|
||||
* Copyright © 2020 WaterCloud.Framework 版权所有
|
||||
* Author: WaterCloud
|
||||
* Description: WaterCloud快速开发平台
|
||||
* Website:
|
||||
*********************************************************************************/
|
||||
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.Domain.SystemManage;
|
||||
using WaterCloud.Domain.SystemOrganize;
|
||||
|
||||
namespace WaterCloud.Service.SystemManage
|
||||
{
|
||||
public class ModuleButtonService : BaseService<ModuleButtonEntity>, IDenpendency
|
||||
{
|
||||
private string authorizecacheKey = GlobalContext.SystemConfig.ProjectPrefix + "_authorizeurldata_";// +权限
|
||||
|
||||
public ModuleButtonService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<List<ModuleButtonEntity>> GetList(string moduleId = "")
|
||||
{
|
||||
var list = repository.IQueryable();
|
||||
if (!string.IsNullOrEmpty(moduleId))
|
||||
{
|
||||
list = list.Where(a => a.F_ModuleId == moduleId);
|
||||
}
|
||||
return await list.Where(a => a.F_DeleteMark == false).OrderBy(a => a.F_SortCode).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<ModuleButtonEntity>> GetLookList(string moduleId = "", string keyword = "")
|
||||
{
|
||||
var query = repository.IQueryable().Where(a => a.F_DeleteMark == false);
|
||||
if (!string.IsNullOrEmpty(moduleId))
|
||||
{
|
||||
query = query.Where(a => a.F_ModuleId == moduleId);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
//此处需修改
|
||||
query = query.Where(a => a.F_FullName.Contains(keyword) || a.F_EnCode.Contains(keyword));
|
||||
}
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
return await query.OrderBy(a => a.F_SortCode).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<ModuleButtonEntity> GetLookForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return GetFieldsFilterData(data);
|
||||
}
|
||||
|
||||
public async Task<ModuleButtonEntity> GetForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task DeleteForm(string keyValue)
|
||||
{
|
||||
if (await repository.IQueryable(a => a.F_ParentId.Equals(keyValue)).AnyAsync())
|
||||
{
|
||||
throw new Exception("删除失败!操作的对象包含了下级数据。");
|
||||
}
|
||||
else
|
||||
{
|
||||
await repository.Delete(a => a.F_Id == keyValue);
|
||||
}
|
||||
await CacheHelper.RemoveAsync(authorizecacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list");
|
||||
}
|
||||
|
||||
public async Task<List<ModuleButtonEntity>> GetListByRole(string roleid)
|
||||
{
|
||||
var moduleList = repository.Db.Queryable<RoleAuthorizeEntity>().Where(a => a.F_ObjectId == roleid && a.F_ItemType == 2).Select(a => a.F_ItemId).ToList();
|
||||
var query = repository.IQueryable().Where(a => (moduleList.Contains(a.F_Id) || a.F_IsPublic == true) && a.F_DeleteMark == false && a.F_EnabledMark == true);
|
||||
return await query.OrderBy(a => a.F_SortCode).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task SubmitForm(ModuleButtonEntity moduleButtonEntity, string keyValue)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(moduleButtonEntity.F_Authorize))
|
||||
{
|
||||
moduleButtonEntity.F_Authorize = moduleButtonEntity.F_Authorize.ToLower();
|
||||
}
|
||||
if (!string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
moduleButtonEntity.Modify(keyValue);
|
||||
await repository.Update(moduleButtonEntity);
|
||||
}
|
||||
else
|
||||
{
|
||||
moduleButtonEntity.F_DeleteMark = false;
|
||||
moduleButtonEntity.F_AllowEdit = false;
|
||||
moduleButtonEntity.F_AllowDelete = false;
|
||||
var module = await repository.Db.Queryable<ModuleEntity>().Where(a => a.F_Id == moduleButtonEntity.F_ModuleId).FirstAsync();
|
||||
if (module.F_Target != "iframe" && module.F_Target != "expand")
|
||||
{
|
||||
throw new Exception("菜单不能创建按钮");
|
||||
}
|
||||
moduleButtonEntity.Create();
|
||||
await repository.Insert(moduleButtonEntity);
|
||||
}
|
||||
await CacheHelper.RemoveAsync(authorizecacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list");
|
||||
}
|
||||
|
||||
public async Task SubmitCloneButton(string moduleId, string Ids)
|
||||
{
|
||||
string[] ArrayId = Ids.Split(',');
|
||||
var data = await this.GetList();
|
||||
List<ModuleButtonEntity> entitys = new List<ModuleButtonEntity>();
|
||||
var module = await repository.Db.Queryable<ModuleEntity>().Where(a => a.F_Id == moduleId).FirstAsync();
|
||||
if (module.F_Target != "iframe" && module.F_Target != "expand")
|
||||
{
|
||||
throw new Exception("菜单不能创建按钮");
|
||||
}
|
||||
foreach (string item in ArrayId)
|
||||
{
|
||||
ModuleButtonEntity moduleButtonEntity = data.Find(a => a.F_Id == item);
|
||||
moduleButtonEntity.Create();
|
||||
moduleButtonEntity.F_ModuleId = moduleId;
|
||||
entitys.Add(moduleButtonEntity);
|
||||
}
|
||||
await repository.Insert(entitys);
|
||||
await CacheHelper.RemoveAsync(authorizecacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list");
|
||||
}
|
||||
|
||||
public async Task<List<ModuleButtonEntity>> GetListNew(string moduleId = "")
|
||||
{
|
||||
var query = repository.Db.Queryable<ModuleButtonEntity, ModuleEntity>((a, b) => new JoinQueryInfos(
|
||||
JoinType.Inner, a.F_ModuleId == b.F_Id && b.F_EnabledMark == true && b.F_DeleteMark == false
|
||||
|
||||
)).Where(a => a.F_EnabledMark == true && a.F_DeleteMark == false)
|
||||
.Select((a, b) => new ModuleButtonEntity
|
||||
{
|
||||
F_Id = a.F_Id,
|
||||
F_AllowDelete = a.F_AllowDelete,
|
||||
F_AllowEdit = a.F_AllowEdit,
|
||||
F_UrlAddress = a.F_UrlAddress,
|
||||
F_CreatorTime = a.F_CreatorTime,
|
||||
F_CreatorUserId = a.F_CreatorUserId,
|
||||
F_DeleteMark = a.F_DeleteMark,
|
||||
F_DeleteTime = a.F_DeleteTime,
|
||||
F_DeleteUserId = a.F_DeleteUserId,
|
||||
F_Description = a.F_Description,
|
||||
F_EnabledMark = a.F_EnabledMark,
|
||||
F_EnCode = a.F_EnCode,
|
||||
F_FullName = a.F_FullName,
|
||||
F_Icon = a.F_Icon,
|
||||
F_IsPublic = a.F_IsPublic,
|
||||
F_JsEvent = a.F_JsEvent,
|
||||
F_LastModifyTime = a.F_LastModifyTime,
|
||||
F_LastModifyUserId = a.F_LastModifyUserId,
|
||||
F_Layers = a.F_Layers,
|
||||
F_Location = a.F_Location,
|
||||
F_ModuleId = b.F_UrlAddress,
|
||||
F_ParentId = a.F_ParentId,
|
||||
F_SortCode = a.F_SortCode,
|
||||
F_Split = a.F_Split,
|
||||
}).MergeTable();
|
||||
if (!string.IsNullOrEmpty(moduleId))
|
||||
{
|
||||
query = query.Where(a => a.F_ModuleId == moduleId);
|
||||
}
|
||||
return await query.OrderBy(a => a.F_SortCode).ToListAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
142
WaterCloud.Service/SystemManage/ModuleFieldsService.cs
Normal file
142
WaterCloud.Service/SystemManage/ModuleFieldsService.cs
Normal file
@@ -0,0 +1,142 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.DataBase;
|
||||
using WaterCloud.Domain.SystemManage;
|
||||
using WaterCloud.Domain.SystemOrganize;
|
||||
|
||||
namespace WaterCloud.Service.SystemManage
|
||||
{
|
||||
/// <summary>
|
||||
/// 创 建:超级管理员
|
||||
/// 日 期:2020-05-21 14:38
|
||||
/// 描 述:字段管理服务类
|
||||
/// </summary>
|
||||
public class ModuleFieldsService : BaseService<ModuleFieldsEntity>, IDenpendency
|
||||
{
|
||||
public ModuleFieldsService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
#region 获取数据
|
||||
|
||||
public async Task<List<ModuleFieldsEntity>> GetList(string keyword = "")
|
||||
{
|
||||
var query = repository.IQueryable();
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
//此处需修改
|
||||
query = query.Where(a => a.F_FullName.Contains(keyword) || a.F_EnCode.Contains(keyword));
|
||||
}
|
||||
return await query.Where(a => a.F_DeleteMark == false).OrderBy(a => a.F_Id, OrderByType.Desc).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<ModuleFieldsEntity>> GetLookList(Pagination pagination, string moduleId, string keyword = "")
|
||||
{
|
||||
//获取数据权限
|
||||
var query = repository.IQueryable().Where(a => a.F_DeleteMark == false && a.F_ModuleId == moduleId);
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_FullName.Contains(keyword) || a.F_EnCode.Contains(keyword));
|
||||
}
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
return await query.ToPageListAsync(pagination);
|
||||
}
|
||||
|
||||
public async Task<ModuleFieldsEntity> GetLookForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return GetFieldsFilterData(data);
|
||||
}
|
||||
|
||||
public async Task<ModuleFieldsEntity> GetForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return data;
|
||||
}
|
||||
|
||||
#endregion 获取数据
|
||||
|
||||
#region 提交数据
|
||||
|
||||
public async Task SubmitForm(ModuleFieldsEntity entity, string keyValue)
|
||||
{
|
||||
if (string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
entity.F_DeleteMark = false;
|
||||
entity.Create();
|
||||
await repository.Insert(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.Modify(keyValue);
|
||||
await repository.Update(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteForm(string keyValue)
|
||||
{
|
||||
await repository.Delete(a => a.F_Id == keyValue);
|
||||
}
|
||||
|
||||
public async Task SubmitCloneFields(string moduleId, string ids)
|
||||
{
|
||||
string[] ArrayId = ids.Split(',');
|
||||
var data = await this.GetList();
|
||||
List<ModuleFieldsEntity> entitys = new List<ModuleFieldsEntity>();
|
||||
var module = await repository.Db.Queryable<ModuleEntity>().Where(a => a.F_Id == moduleId).FirstAsync();
|
||||
if (string.IsNullOrEmpty(module.F_UrlAddress) || module.F_Target != "iframe")
|
||||
{
|
||||
throw new Exception("框架页才能创建字段");
|
||||
}
|
||||
foreach (string item in ArrayId)
|
||||
{
|
||||
ModuleFieldsEntity moduleFieldsEntity = data.Find(a => a.F_Id == item);
|
||||
moduleFieldsEntity.Create();
|
||||
moduleFieldsEntity.F_ModuleId = moduleId;
|
||||
entitys.Add(moduleFieldsEntity);
|
||||
}
|
||||
await repository.Insert(entitys);
|
||||
}
|
||||
|
||||
public async Task<List<ModuleFieldsEntity>> GetListByRole(string roleid)
|
||||
{
|
||||
var moduleList = repository.Db.Queryable<RoleAuthorizeEntity>().Where(a => a.F_ObjectId == roleid && a.F_ItemType == 3).Select(a => a.F_ItemId).ToList();
|
||||
var query = repository.IQueryable().Where(a => (moduleList.Contains(a.F_Id) || a.F_IsPublic == true) && a.F_DeleteMark == false && a.F_EnabledMark == true);
|
||||
return await query.OrderBy(a => a.F_CreatorTime, OrderByType.Desc).ToListAsync();
|
||||
}
|
||||
|
||||
internal async Task<List<ModuleFieldsEntity>> GetListNew(string moduleId = "")
|
||||
{
|
||||
var query = repository.Db.Queryable<ModuleFieldsEntity, ModuleEntity>((a, b) => new JoinQueryInfos(
|
||||
JoinType.Inner, a.F_ModuleId == b.F_Id && b.F_EnabledMark == true
|
||||
))
|
||||
.Select((a, b) => new ModuleFieldsEntity
|
||||
{
|
||||
F_Id = a.F_Id,
|
||||
F_CreatorTime = a.F_CreatorTime,
|
||||
F_CreatorUserId = a.F_CreatorUserId,
|
||||
F_DeleteMark = a.F_DeleteMark,
|
||||
F_DeleteTime = a.F_DeleteTime,
|
||||
F_DeleteUserId = a.F_DeleteUserId,
|
||||
F_Description = a.F_Description,
|
||||
F_EnabledMark = a.F_EnabledMark,
|
||||
F_EnCode = a.F_EnCode,
|
||||
F_FullName = a.F_FullName,
|
||||
F_LastModifyTime = a.F_LastModifyTime,
|
||||
F_LastModifyUserId = a.F_LastModifyUserId,
|
||||
F_ModuleId = b.F_UrlAddress,
|
||||
F_IsPublic = a.F_IsPublic
|
||||
}).MergeTable();
|
||||
if (!string.IsNullOrEmpty(moduleId))
|
||||
{
|
||||
query = query.Where(a => a.F_ModuleId == moduleId);
|
||||
}
|
||||
return await query.OrderBy(a => a.F_CreatorTime, OrderByType.Desc).ToListAsync();
|
||||
}
|
||||
|
||||
#endregion 提交数据
|
||||
}
|
||||
}
|
||||
135
WaterCloud.Service/SystemManage/ModuleService.cs
Normal file
135
WaterCloud.Service/SystemManage/ModuleService.cs
Normal file
@@ -0,0 +1,135 @@
|
||||
/*******************************************************************************
|
||||
* Copyright © 2020 WaterCloud.Framework 版权所有
|
||||
* Author: WaterCloud
|
||||
* Description: WaterCloud快速开发平台
|
||||
* Website:
|
||||
*********************************************************************************/
|
||||
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.Domain.SystemManage;
|
||||
using WaterCloud.Domain.SystemOrganize;
|
||||
|
||||
namespace WaterCloud.Service.SystemManage
|
||||
{
|
||||
public class ModuleService : BaseService<ModuleEntity>, IDenpendency
|
||||
{
|
||||
/// <summary>
|
||||
/// 缓存操作类
|
||||
/// </summary>
|
||||
private string authorizecacheKey = GlobalContext.SystemConfig.ProjectPrefix + "_authorizeurldata_";// +权限
|
||||
|
||||
//获取类名
|
||||
|
||||
public ModuleService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<List<ModuleEntity>> GetList()
|
||||
{
|
||||
var query = repository.IQueryable();
|
||||
return await query.Where(a => a.F_DeleteMark == false).OrderBy(a => a.F_SortCode).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<ModuleEntity>> GetBesidesList()
|
||||
{
|
||||
var moduleList = repository.Db.Queryable<DataPrivilegeRuleEntity>().Select(a => a.F_ModuleId).ToList();
|
||||
var query = repository.IQueryable().Where(a => !moduleList.Contains(a.F_Id) && a.F_EnabledMark == true && a.F_Target == "iframe");
|
||||
return await query.OrderBy(a => a.F_SortCode).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<ModuleEntity>> GetLookList()
|
||||
{
|
||||
var query = repository.IQueryable().Where(a => a.F_DeleteMark == false);
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
return await query.OrderBy(a => a.F_SortCode).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<ModuleEntity> GetLookForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return GetFieldsFilterData(data);
|
||||
}
|
||||
|
||||
public async Task<ModuleEntity> GetForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<string> GetMaxSortCode(string F_ParentId)
|
||||
{
|
||||
try
|
||||
{
|
||||
int F_SortCode = (int)await repository.Db.Queryable<ModuleEntity>().Where(t => t.F_ParentId == F_ParentId).MaxAsync(a => a.F_SortCode);
|
||||
|
||||
return (F_SortCode + 1).ToString();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteForm(string keyValue)
|
||||
{
|
||||
if (await repository.IQueryable(a => a.F_ParentId.Equals(keyValue)).AnyAsync())
|
||||
{
|
||||
throw new Exception("删除失败!操作的对象包含了下级数据。");
|
||||
}
|
||||
else
|
||||
{
|
||||
repository.Db.Ado.BeginTran();
|
||||
await repository.Delete(a => a.F_Id == keyValue);
|
||||
await repository.Db.Deleteable<ModuleButtonEntity>().Where(a => a.F_ModuleId == keyValue).ExecuteCommandAsync();
|
||||
await repository.Db.Deleteable<ModuleFieldsEntity>().Where(a => a.F_ModuleId == keyValue).ExecuteCommandAsync();
|
||||
repository.Db.Ado.CommitTran();
|
||||
await CacheHelper.RemoveAsync(authorizecacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<ModuleEntity>> GetListByRole(string roleid)
|
||||
{
|
||||
var moduleList = repository.Db.Queryable<RoleAuthorizeEntity>().Where(a => a.F_ObjectId == roleid && a.F_ItemType == 1).Select(a => a.F_ItemId).ToList();
|
||||
var query = repository.IQueryable().Where(a => (moduleList.Contains(a.F_Id) || a.F_IsPublic == true) && a.F_DeleteMark == false && a.F_EnabledMark == true);
|
||||
return await query.OrderBy(a => a.F_SortCode).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task SubmitForm(ModuleEntity moduleEntity, string keyValue)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(moduleEntity.F_Authorize))
|
||||
{
|
||||
moduleEntity.F_Authorize = moduleEntity.F_Authorize.ToLower();
|
||||
}
|
||||
if (!string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
moduleEntity.Modify(keyValue);
|
||||
await repository.Update(moduleEntity);
|
||||
}
|
||||
else
|
||||
{
|
||||
moduleEntity.Create();
|
||||
await repository.Insert(moduleEntity);
|
||||
}
|
||||
await CacheHelper.RemoveAsync(authorizecacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新菜单排序
|
||||
/// </summary>
|
||||
/// <param name="F_Id">内码</param>
|
||||
/// <param name="SortCode">排序数字</param>
|
||||
/// <returns></returns>
|
||||
public async Task SubmitUpdateForm(string F_Id, int SortCode)
|
||||
{
|
||||
//更新
|
||||
await repository.Update(a => a.F_Id == F_Id, a => new ModuleEntity()
|
||||
{
|
||||
F_SortCode = SortCode
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
161
WaterCloud.Service/SystemManage/QuickModuleService.cs
Normal file
161
WaterCloud.Service/SystemManage/QuickModuleService.cs
Normal file
@@ -0,0 +1,161 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file=" QuickModule.cs" company="JR">
|
||||
// * Copyright (C) WaterCloud.Framework All Rights Reserved
|
||||
// * version : 1.0
|
||||
// * author : WaterCloud.Framework
|
||||
// * FileName: QuickModule.cs
|
||||
// * history : Created by T4 04/13/2020 16:51:13
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.Domain.SystemManage;
|
||||
using WaterCloud.Domain.SystemOrganize;
|
||||
|
||||
namespace WaterCloud.Service.SystemManage
|
||||
{
|
||||
public class QuickModuleService : BaseService<QuickModuleEntity>, IDenpendency
|
||||
{
|
||||
public QuickModuleService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<object> GetTransferList(string userId)
|
||||
{
|
||||
var quicklist = repository.IQueryable(a => a.F_CreatorUserId == userId && a.F_EnabledMark == true).ToList();
|
||||
List<ModuleEntity> quicks = new List<ModuleEntity>();
|
||||
var user = await repository.Db.Queryable<UserEntity>().InSingleAsync(userId);
|
||||
var roleId = user.F_RoleId;
|
||||
if (user.F_IsAdmin == true)
|
||||
{
|
||||
roleId = "admin";
|
||||
}
|
||||
var rolelist = roleId.Split(',');
|
||||
var modulelist = repository.Db.Queryable<RoleAuthorizeEntity, ModuleEntity>((a, b) => new JoinQueryInfos(
|
||||
JoinType.Inner, a.F_ItemId == b.F_Id && b.F_IsMenu == true
|
||||
|
||||
)).Where(a => roleId.Contains(a.F_ObjectId) && a.F_ItemType == 1).Select(a => a.F_ItemId).ToList();
|
||||
if (roleId == "admin")
|
||||
{
|
||||
modulelist = repository.Db.Queryable<ModuleEntity>().Where(a => a.F_EnabledMark == true && a.F_IsMenu == true && a.F_DeleteMark == false).Select(a => a.F_Id).ToList();
|
||||
}
|
||||
modulelist = modulelist.Distinct().ToList();
|
||||
quicks = repository.Db.Queryable<ModuleEntity>().Where(a => (modulelist.Contains(a.F_Id) || a.F_IsPublic == true) && a.F_IsMenu == true && a.F_EnabledMark == true && a.F_UrlAddress != null)
|
||||
.Select(a => new ModuleEntity
|
||||
{
|
||||
F_Id = a.F_Id,
|
||||
F_EnabledMark = false,
|
||||
F_FullName = a.F_FullName
|
||||
}).ToList();
|
||||
foreach (var item in quicklist)
|
||||
{
|
||||
var temp = quicks.Find(a => a.F_Id == item.F_ModuleId);
|
||||
if (temp != null)
|
||||
{
|
||||
temp.F_EnabledMark = true;
|
||||
}
|
||||
}
|
||||
return quicks;
|
||||
}
|
||||
|
||||
public async Task<List<QuickModuleExtend>> GetQuickModuleList(string userId)
|
||||
{
|
||||
var quicklist = repository.IQueryable(a => a.F_CreatorUserId == userId && a.F_EnabledMark == true);
|
||||
List<QuickModuleExtend> list = new List<QuickModuleExtend>();
|
||||
List<QuickModuleEntity> quicks = new List<QuickModuleEntity>();
|
||||
repository.Db.Ado.BeginTran();
|
||||
if (!await quicklist.AnyAsync())
|
||||
{
|
||||
var user = await repository.Db.Queryable<UserEntity>().InSingleAsync(userId);
|
||||
var roleId = user.F_RoleId;
|
||||
if (user.F_IsAdmin == true)
|
||||
{
|
||||
roleId = "admin";
|
||||
}
|
||||
var rolelist = roleId.Split(',');
|
||||
var modulelist = repository.Db.Queryable<RoleAuthorizeEntity, ModuleEntity>((a, b) => new JoinQueryInfos(
|
||||
JoinType.Inner, a.F_ItemId == b.F_Id && b.F_IsMenu == true
|
||||
|
||||
)).Where(a => roleId.Contains(a.F_ObjectId) && a.F_ItemType == 1).Select(a => a.F_ItemId).ToList();
|
||||
if (roleId == "admin")
|
||||
{
|
||||
modulelist = repository.Db.Queryable<ModuleEntity>().Where(a => a.F_EnabledMark == true && a.F_IsMenu == true && a.F_DeleteMark == false).Select(a => a.F_Id).ToList();
|
||||
}
|
||||
var temp = repository.Db.Queryable<ModuleEntity>().Where(a => a.F_IsPublic == true && a.F_IsMenu == true && a.F_EnabledMark == true && a.F_DeleteMark == false).Select(a => a.F_Id).ToList();
|
||||
modulelist.AddRange(temp);
|
||||
modulelist = modulelist.Distinct().ToList();
|
||||
foreach (var item in modulelist)
|
||||
{
|
||||
var module = await repository.Db.Queryable<ModuleEntity>().Where(a => a.F_Id == item && a.F_EnabledMark == true).FirstAsync();
|
||||
if (module != null && module.F_UrlAddress != null && list.Count < 8)
|
||||
{
|
||||
list.Add(new QuickModuleExtend
|
||||
{
|
||||
id = module.F_Id,
|
||||
title = module.F_FullName,
|
||||
href = module.F_UrlAddress,
|
||||
icon = module.F_Icon
|
||||
});
|
||||
QuickModuleEntity quick = new QuickModuleEntity();
|
||||
quick.Create();
|
||||
quick.F_DeleteMark = false;
|
||||
quick.F_EnabledMark = true;
|
||||
quick.F_ModuleId = module.F_Id;
|
||||
quicks.Add(quick);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var item in quicklist.ToList())
|
||||
{
|
||||
var module = await repository.Db.Queryable<ModuleEntity>().Where(a => a.F_Id == item.F_ModuleId && a.F_EnabledMark == true).FirstAsync();
|
||||
if (module != null)
|
||||
{
|
||||
list.Add(new QuickModuleExtend
|
||||
{
|
||||
id = module.F_Id,
|
||||
title = module.F_FullName,
|
||||
href = module.F_UrlAddress,
|
||||
icon = module.F_Icon
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
await repository.Delete(a => a.F_Id == item.F_Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (quicks.Count > 0)
|
||||
{
|
||||
await repository.Db.Insertable(quicks).ExecuteCommandAsync();
|
||||
}
|
||||
repository.Db.Ado.CommitTran();
|
||||
return list;
|
||||
}
|
||||
|
||||
public async Task SubmitForm(string[] permissionIds)
|
||||
{
|
||||
List<QuickModuleEntity> list = new List<QuickModuleEntity>();
|
||||
if (permissionIds != null)
|
||||
{
|
||||
foreach (var itemId in permissionIds)
|
||||
{
|
||||
QuickModuleEntity entity = new QuickModuleEntity();
|
||||
entity.Create();
|
||||
entity.F_ModuleId = itemId;
|
||||
entity.F_EnabledMark = true;
|
||||
entity.F_DeleteMark = false;
|
||||
list.Add(entity);
|
||||
}
|
||||
}
|
||||
repository.Db.Ado.BeginTran();
|
||||
await repository.Delete(a => a.F_CreatorUserId == currentuser.UserId);
|
||||
await repository.Insert(list);
|
||||
repository.Db.Ado.CommitTran();
|
||||
}
|
||||
}
|
||||
}
|
||||
101
WaterCloud.Service/SystemManage/TemplateService.cs
Normal file
101
WaterCloud.Service/SystemManage/TemplateService.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using WaterCloud.Code;
|
||||
using SqlSugar;
|
||||
using WaterCloud.DataBase;
|
||||
using WaterCloud.Domain.SystemManage;
|
||||
|
||||
namespace WaterCloud.Service.SystemManage
|
||||
{
|
||||
/// <summary>
|
||||
/// 创 建:超级管理员
|
||||
/// 日 期:2022-10-06 14:11
|
||||
/// 描 述:打印模板服务类
|
||||
/// </summary>
|
||||
public class TemplateService : BaseService<TemplateEntity>, IDenpendency
|
||||
{
|
||||
public TemplateService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
#region 获取数据
|
||||
public async Task<List<TemplateEntity>> GetList(string keyword = "")
|
||||
{
|
||||
var data = repository.IQueryable();
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
data = data.Where(a => a.F_TemplateName.Contains(keyword));
|
||||
}
|
||||
return await data.Where(a => a.F_DeleteMark == false).OrderBy(a => a.F_Id , OrderByType.Desc).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<TemplateEntity>> GetLookList(string keyword = "")
|
||||
{
|
||||
var query = repository.IQueryable().Where(a => a.F_DeleteMark == false);
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
//此处需修改
|
||||
query = query.Where(a => a.F_TemplateName.Contains(keyword));
|
||||
}
|
||||
//权限过滤
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
return await query.OrderBy(a => a.F_Id , OrderByType.Desc).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<TemplateEntity>> GetLookList(SoulPage<TemplateEntity> pagination,string keyword = "",string id="")
|
||||
{
|
||||
var query = repository.IQueryable().Where(a => a.F_DeleteMark == false);
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_TemplateName.Contains(keyword));
|
||||
}
|
||||
if(!string.IsNullOrEmpty(id))
|
||||
{
|
||||
query= query.Where(a=>a.F_Id==id);
|
||||
}
|
||||
//权限过滤
|
||||
query = GetDataPrivilege("a","",query);
|
||||
return await query.ToPageListAsync(pagination);
|
||||
}
|
||||
|
||||
public async Task<TemplateEntity> GetForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return data;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public async Task<TemplateEntity> GetLookForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return GetFieldsFilterData(data);
|
||||
}
|
||||
|
||||
#region 提交数据
|
||||
public async Task SubmitForm(TemplateEntity entity, string keyValue)
|
||||
{
|
||||
if(string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
//初始值添加
|
||||
entity.F_DeleteMark = false;
|
||||
entity.Create();
|
||||
await repository.Insert(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
//此处需修改
|
||||
entity.Modify(keyValue);
|
||||
await repository.Update(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteForm(string keyValue)
|
||||
{
|
||||
var ids = keyValue.Split(',');
|
||||
await repository.Delete(a => ids.Contains(a.F_Id.ToString()));
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.DataBase;
|
||||
using WaterCloud.Domain.SystemManage;
|
||||
using WaterCloud.Domain.SystemOrganize;
|
||||
|
||||
namespace WaterCloud.Service.SystemOrganize
|
||||
{
|
||||
/// <summary>
|
||||
/// 创 建:超级管理员
|
||||
/// 日 期:2020-06-01 09:44
|
||||
/// 描 述:数据权限服务类
|
||||
/// </summary>
|
||||
public class DataPrivilegeRuleService : BaseService<DataPrivilegeRuleEntity>, IDenpendency
|
||||
{
|
||||
public DataPrivilegeRuleService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
//获取类名
|
||||
|
||||
#region 获取数据
|
||||
|
||||
public async Task<List<DataPrivilegeRuleEntity>> GetList(string keyword = "")
|
||||
{
|
||||
var list = repository.IQueryable();
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
list = list.Where(a => a.F_ModuleCode.Contains(keyword) || a.F_Description.Contains(keyword));
|
||||
}
|
||||
return await list.Where(a => a.F_DeleteMark == false).OrderBy(a => a.F_Id, OrderByType.Desc).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<DataPrivilegeRuleEntity>> GetLookList(SoulPage<DataPrivilegeRuleEntity> pagination, string keyword = "")
|
||||
{
|
||||
//反格式化显示只能用"等于",其他不支持
|
||||
Dictionary<string, Dictionary<string, string>> dic = new Dictionary<string, Dictionary<string, string>>();
|
||||
Dictionary<string, string> enabledTemp = new Dictionary<string, string>();
|
||||
enabledTemp.Add("1", "有效");
|
||||
enabledTemp.Add("0", "无效");
|
||||
dic.Add("F_EnabledMark", enabledTemp);
|
||||
pagination = ChangeSoulData(dic, pagination);
|
||||
var query = repository.IQueryable().Where(a => a.F_DeleteMark == false);
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_ModuleCode.Contains(keyword) || a.F_Description.Contains(keyword));
|
||||
}
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
return await query.ToPageListAsync(pagination);
|
||||
}
|
||||
|
||||
public async Task<DataPrivilegeRuleEntity> GetLookForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return GetFieldsFilterData(data);
|
||||
}
|
||||
|
||||
public async Task<DataPrivilegeRuleEntity> GetForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return data;
|
||||
}
|
||||
|
||||
#endregion 获取数据
|
||||
|
||||
#region 提交数据
|
||||
|
||||
public async Task SubmitForm(DataPrivilegeRuleEntity entity, string keyValue)
|
||||
{
|
||||
entity.F_ModuleCode = repository.Db.Queryable<ModuleEntity>().InSingle(entity.F_ModuleId).F_EnCode;
|
||||
if (string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
entity.F_DeleteMark = false;
|
||||
entity.Create();
|
||||
await repository.Insert(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.Modify(keyValue);
|
||||
await repository.Update(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteForm(string keyValue)
|
||||
{
|
||||
await repository.Delete(a => a.F_Id == keyValue);
|
||||
}
|
||||
|
||||
#endregion 提交数据
|
||||
}
|
||||
}
|
||||
173
WaterCloud.Service/SystemOrganize/DutyService.cs
Normal file
173
WaterCloud.Service/SystemOrganize/DutyService.cs
Normal file
@@ -0,0 +1,173 @@
|
||||
/*******************************************************************************
|
||||
* Copyright © 2020 WaterCloud.Framework 版权所有
|
||||
* Author: WaterCloud
|
||||
* Description: WaterCloud快速开发平台
|
||||
* Website:
|
||||
*********************************************************************************/
|
||||
|
||||
using MiniExcelLibs;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.DataBase;
|
||||
using WaterCloud.Domain.SystemOrganize;
|
||||
|
||||
namespace WaterCloud.Service.SystemOrganize
|
||||
{
|
||||
public class DutyService : BaseService<RoleEntity>, IDenpendency
|
||||
{
|
||||
public SystemSetService setApp { get; set; }
|
||||
|
||||
public DutyService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<List<RoleEntity>> GetList(string keyword = "")
|
||||
{
|
||||
var query = repository.IQueryable();
|
||||
query = query.Where(a => a.F_Category == 2 && a.F_DeleteMark == false);
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_FullName.Contains(keyword) || a.F_EnCode.Contains(keyword));
|
||||
}
|
||||
return await query.OrderBy(a => a.F_SortCode).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<RoleExtend>> GetLookList(SoulPage<RoleExtend> pagination, string keyword = "")
|
||||
{
|
||||
//反格式化显示只能用"等于",其他不支持
|
||||
Dictionary<string, Dictionary<string, string>> dic = new Dictionary<string, Dictionary<string, string>>();
|
||||
Dictionary<string, string> enabledTemp = new Dictionary<string, string>();
|
||||
enabledTemp.Add("1", "有效");
|
||||
enabledTemp.Add("0", "无效");
|
||||
dic.Add("F_EnabledMark", enabledTemp);
|
||||
var setList = await setApp.GetList();
|
||||
Dictionary<string, string> orgizeTemp = new Dictionary<string, string>();
|
||||
foreach (var item in setList)
|
||||
{
|
||||
orgizeTemp.Add(item.F_Id, item.F_CompanyName);
|
||||
}
|
||||
dic.Add("F_CompanyId", orgizeTemp);
|
||||
pagination = ChangeSoulData(dic, pagination);
|
||||
var query = GetQuery();
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_FullName.Contains(keyword) || a.F_EnCode.Contains(keyword));
|
||||
}
|
||||
query = query.Where(a => a.F_DeleteMark == false && a.F_Category == 2);
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
return await query.ToPageListAsync(pagination);
|
||||
}
|
||||
|
||||
public async Task<RoleEntity> GetLookForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return GetFieldsFilterData(data);
|
||||
}
|
||||
|
||||
public async Task<RoleEntity> GetForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return data;
|
||||
}
|
||||
|
||||
private ISugarQueryable<RoleExtend> GetQuery()
|
||||
{
|
||||
var query = repository.Db.Queryable<RoleEntity, SystemSetEntity>((a, b) => new JoinQueryInfos(
|
||||
JoinType.Left, a.F_CompanyId == b.F_Id
|
||||
|
||||
)).Where(a => a.F_DeleteMark == false && a.F_Category == 2)
|
||||
.Select((a, b) => new RoleExtend
|
||||
{
|
||||
F_Id = a.F_Id.SelectAll(),
|
||||
F_CompanyName = b.F_CompanyName,
|
||||
}).MergeTable();
|
||||
return query;
|
||||
}
|
||||
|
||||
public async Task DeleteForm(string keyValue)
|
||||
{
|
||||
if (await repository.Db.Queryable<UserEntity>().Where(a => a.F_DutyId == keyValue).AnyAsync())
|
||||
{
|
||||
throw new Exception("岗位使用中,无法删除");
|
||||
}
|
||||
await repository.Delete(a => a.F_Id == keyValue);
|
||||
}
|
||||
|
||||
public async Task SubmitForm(RoleEntity roleEntity, string keyValue)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
roleEntity.Modify(keyValue);
|
||||
await repository.Update(roleEntity);
|
||||
}
|
||||
else
|
||||
{
|
||||
roleEntity.F_DeleteMark = false;
|
||||
roleEntity.F_AllowEdit = false;
|
||||
roleEntity.F_AllowDelete = false;
|
||||
roleEntity.Create();
|
||||
roleEntity.F_Category = 2;
|
||||
await repository.Insert(roleEntity);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<RoleExtend>> CheckFile(string fileFullName)
|
||||
{
|
||||
if (!FileHelper.IsExcel(fileFullName))
|
||||
{
|
||||
throw new Exception("文件不是有效的Excel文件!");
|
||||
}
|
||||
//文件解析
|
||||
var list = MiniExcel.Query<RoleExtend>(fileFullName).ToList(); ;
|
||||
//删除文件
|
||||
File.Delete(fileFullName);
|
||||
foreach (var item in list)
|
||||
{
|
||||
item.F_Id = Utils.GuId();
|
||||
item.F_EnabledMark = true;
|
||||
item.F_DeleteMark = false;
|
||||
item.F_CompanyId = currentuser.CompanyId;
|
||||
item.F_SortCode = 1;
|
||||
item.F_Category = 2;
|
||||
item.F_AllowEdit = false;
|
||||
item.F_AllowDelete = false;
|
||||
List<string> str = new List<string>();
|
||||
if (string.IsNullOrEmpty(item.F_EnCode))
|
||||
{
|
||||
item.F_EnabledMark = false;
|
||||
item.ErrorMsg = "编号不存在";
|
||||
continue;
|
||||
}
|
||||
else if (await repository.IQueryable(a => a.F_EnCode == item.F_EnCode).AnyAsync() || list.Where(a => a.F_EnCode == item.F_EnCode).Count() > 1)
|
||||
{
|
||||
str.Add("编号重复");
|
||||
item.F_EnabledMark = false;
|
||||
}
|
||||
if (string.IsNullOrEmpty(item.F_FullName))
|
||||
{
|
||||
str.Add("名称不存在");
|
||||
item.F_EnabledMark = false;
|
||||
}
|
||||
if (item.F_EnabledMark == false)
|
||||
{
|
||||
item.ErrorMsg = string.Join(',', str.ToArray());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public async Task ImportForm(List<RoleEntity> filterList)
|
||||
{
|
||||
foreach (var item in filterList)
|
||||
{
|
||||
item.Create();
|
||||
}
|
||||
await repository.Db.Insertable(filterList).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
89
WaterCloud.Service/SystemOrganize/NoticeService.cs
Normal file
89
WaterCloud.Service/SystemOrganize/NoticeService.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file=" Notice.cs" company="JR">
|
||||
// * Copyright (C) WaterCloud.Framework All Rights Reserved
|
||||
// * version : 1.0
|
||||
// * author : WaterCloud.Framework
|
||||
// * FileName: Notice.cs
|
||||
// * history : Created by T4 04/13/2020 16:51:21
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.DataBase;
|
||||
using WaterCloud.Domain.SystemOrganize;
|
||||
|
||||
namespace WaterCloud.Service.SystemOrganize
|
||||
{
|
||||
public class NoticeService : BaseService<NoticeEntity>, IDenpendency
|
||||
{
|
||||
public NoticeService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<List<NoticeEntity>> GetList(string keyword)
|
||||
{
|
||||
var query = repository.IQueryable();
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_Title.Contains(keyword) || a.F_Content.Contains(keyword));
|
||||
}
|
||||
return await query.Where(a => a.F_DeleteMark == false).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<NoticeEntity>> GetLookList(SoulPage<NoticeEntity> pagination, string keyword = "")
|
||||
{
|
||||
//反格式化显示只能用"等于",其他不支持
|
||||
Dictionary<string, Dictionary<string, string>> dic = new Dictionary<string, Dictionary<string, string>>();
|
||||
Dictionary<string, string> enabledDic = new Dictionary<string, string>();
|
||||
enabledDic.Add("1", "有效");
|
||||
enabledDic.Add("0", "无效");
|
||||
dic.Add("F_EnabledMark", enabledDic);
|
||||
pagination = ChangeSoulData(dic, pagination);
|
||||
var query = repository.IQueryable().Where(a => a.F_DeleteMark == false);
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_Title.Contains(keyword) || a.F_Content.Contains(keyword));
|
||||
}
|
||||
//权限过滤(保证分页参数存在)
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
return await query.ToPageListAsync(pagination);
|
||||
}
|
||||
|
||||
public async Task<NoticeEntity> GetLookForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return GetFieldsFilterData(data);
|
||||
}
|
||||
|
||||
public async Task<NoticeEntity> GetForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task SubmitForm(NoticeEntity entity, string keyValue)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
entity.Modify(keyValue);
|
||||
await repository.Update(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.F_CreatorUserName = currentuser.UserName;
|
||||
entity.F_DeleteMark = false;
|
||||
entity.Create();
|
||||
await repository.Insert(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteForm(string keyValue)
|
||||
{
|
||||
var ids = keyValue.Split(',');
|
||||
await repository.Delete(a => ids.Contains(a.F_Id));
|
||||
}
|
||||
}
|
||||
}
|
||||
94
WaterCloud.Service/SystemOrganize/OrganizeService.cs
Normal file
94
WaterCloud.Service/SystemOrganize/OrganizeService.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
/*******************************************************************************
|
||||
* Copyright © 2020 WaterCloud.Framework 版权所有
|
||||
* Author: WaterCloud
|
||||
* Description: WaterCloud快速开发平台
|
||||
* Website:
|
||||
*********************************************************************************/
|
||||
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Domain.SystemOrganize;
|
||||
|
||||
namespace WaterCloud.Service.SystemOrganize
|
||||
{
|
||||
public class OrganizeService : BaseService<OrganizeEntity>, IDenpendency
|
||||
{
|
||||
public OrganizeService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<List<OrganizeExtend>> GetList()
|
||||
{
|
||||
var query = GetQuery();
|
||||
return await query.Where(a => a.F_DeleteMark == false).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<OrganizeExtend>> GetLookList()
|
||||
{
|
||||
var query = GetQuery().Where(a => a.F_DeleteMark == false);
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
return await query.OrderBy(a => a.F_SortCode).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<OrganizeExtend> GetLookForm(string keyValue)
|
||||
{
|
||||
var data = await GetQuery().FirstAsync(a => a.F_Id == keyValue);
|
||||
return GetFieldsFilterData(data);
|
||||
}
|
||||
|
||||
public async Task<OrganizeExtend> GetForm(string keyValue)
|
||||
{
|
||||
var data = await GetQuery().FirstAsync(a => a.F_Id == keyValue);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
private ISugarQueryable<OrganizeExtend> GetQuery()
|
||||
{
|
||||
var query = repository.Db.Queryable<OrganizeEntity, UserEntity>((a, b) => new JoinQueryInfos(
|
||||
JoinType.Left, a.F_ManagerId == b.F_Id
|
||||
)).Where(a => a.F_DeleteMark == false)
|
||||
.Select((a, b) => new OrganizeExtend
|
||||
{
|
||||
F_Id = a.F_Id.SelectAll(),
|
||||
F_ManagerName = b.F_RealName
|
||||
}).MergeTable();
|
||||
return query;
|
||||
}
|
||||
|
||||
public async Task DeleteForm(string keyValue)
|
||||
{
|
||||
if (await repository.IQueryable(a => a.F_ParentId.Equals(keyValue)).AnyAsync())
|
||||
{
|
||||
throw new Exception("删除失败!操作的对象包含了下级数据。");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (await repository.Db.Queryable<UserEntity>().Where(a => a.F_CompanyId == keyValue).AnyAsync() || await repository.Db.Queryable<UserEntity>().Where(a => a.F_OrganizeId == keyValue).AnyAsync())
|
||||
{
|
||||
throw new Exception("组织使用中,无法删除");
|
||||
}
|
||||
await repository.Delete(a => a.F_Id == keyValue);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SubmitForm(OrganizeEntity organizeEntity, string keyValue)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
organizeEntity.Modify(keyValue);
|
||||
await repository.Update(organizeEntity);
|
||||
}
|
||||
else
|
||||
{
|
||||
organizeEntity.F_AllowDelete = false;
|
||||
organizeEntity.F_AllowEdit = false;
|
||||
organizeEntity.F_DeleteMark = false;
|
||||
organizeEntity.Create();
|
||||
await repository.Insert(organizeEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
392
WaterCloud.Service/SystemOrganize/RoleAuthorizeService.cs
Normal file
392
WaterCloud.Service/SystemOrganize/RoleAuthorizeService.cs
Normal file
@@ -0,0 +1,392 @@
|
||||
/*******************************************************************************
|
||||
* Copyright © 2020 WaterCloud.Framework 版权所有
|
||||
* Author: WaterCloud
|
||||
* Description: WaterCloud快速开发平台
|
||||
* Website:
|
||||
*********************************************************************************/
|
||||
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.Domain.SystemManage;
|
||||
using WaterCloud.Domain.SystemOrganize;
|
||||
using WaterCloud.Domain.ViewModel;
|
||||
using WaterCloud.Service.SystemManage;
|
||||
|
||||
namespace WaterCloud.Service.SystemOrganize
|
||||
{
|
||||
public class RoleAuthorizeService : BaseService<RoleAuthorizeEntity>, IDenpendency
|
||||
{
|
||||
public ModuleService moduleApp { get; set; }
|
||||
public ModuleButtonService moduleButtonApp { get; set; }
|
||||
public ModuleFieldsService moduleFieldsApp { get; set; }
|
||||
public UserService userApp { get; set; }
|
||||
public RoleService roleApp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 缓存操作类
|
||||
/// </summary>
|
||||
private string cacheKey = GlobalContext.SystemConfig.ProjectPrefix + "_authorizeurldata_";// +权限
|
||||
|
||||
public RoleAuthorizeService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<List<RoleAuthorizeEntity>> GetList(string ObjectId)
|
||||
{
|
||||
var query = repository.IQueryable();
|
||||
query = query.Where(a => a.F_ObjectId == ObjectId);
|
||||
return await query.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<ModuleEntity>> GetMenuList(string roleId)
|
||||
{
|
||||
var data = new List<ModuleEntity>();
|
||||
if (currentuser.IsAdmin)
|
||||
{
|
||||
data = await moduleApp.GetList();
|
||||
data = data.Where(a => a.F_IsMenu == true && a.F_EnabledMark == true).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
var rolelist = roleId.Split(',');
|
||||
var moduledata = await moduleApp.GetList();
|
||||
moduledata = moduledata.Where(a => a.F_IsMenu == true && a.F_EnabledMark == true).ToList();
|
||||
var role = repository.Db.Queryable<RoleEntity>().Where(a => rolelist.Contains(a.F_Id) && a.F_EnabledMark == true).ToList();
|
||||
if (role.Count == 0)
|
||||
{
|
||||
return data;
|
||||
}
|
||||
var authorizedata = repository.IQueryable().Where(a => rolelist.Contains(a.F_ObjectId) && a.F_ItemType == 1).Distinct().ToList();
|
||||
foreach (var item in authorizedata)
|
||||
{
|
||||
ModuleEntity moduleEntity = moduledata.Find(a => a.F_Id == item.F_ItemId && a.F_IsPublic == false);
|
||||
if (moduleEntity != null && data.Find(a => a.F_Id == moduleEntity.F_Id) == null)
|
||||
{
|
||||
data.Add(moduleEntity);
|
||||
}
|
||||
}
|
||||
data.AddRange(moduledata.Where(a => a.F_IsPublic == true));
|
||||
}
|
||||
return data.OrderBy(a => a.F_SortCode).ToList();
|
||||
}
|
||||
|
||||
public async Task<List<ModuleButtonEntity>> GetButtonList(string roleId)
|
||||
{
|
||||
var data = new List<ModuleButtonEntity>();
|
||||
if (currentuser.IsAdmin)
|
||||
{
|
||||
data = await moduleButtonApp.GetListNew();
|
||||
}
|
||||
else
|
||||
{
|
||||
var buttondata = await moduleButtonApp.GetListNew();
|
||||
var role = await roleApp.GetForm(roleId);
|
||||
if (role == null || role.F_EnabledMark == false)
|
||||
{
|
||||
return data;
|
||||
}
|
||||
var authorizedata = repository.IQueryable().Where(a => a.F_ObjectId == roleId && a.F_ItemType == 2).ToList();
|
||||
foreach (var item in authorizedata)
|
||||
{
|
||||
ModuleButtonEntity moduleButtonEntity = buttondata.Find(a => a.F_Id == item.F_ItemId && a.F_IsPublic == false);
|
||||
if (moduleButtonEntity != null)
|
||||
{
|
||||
data.Add(moduleButtonEntity);
|
||||
}
|
||||
}
|
||||
data.AddRange(buttondata.Where(a => a.F_IsPublic == true));
|
||||
}
|
||||
return data.OrderBy(a => a.F_SortCode).ToList();
|
||||
}
|
||||
|
||||
public async Task<List<ModuleFieldsEntity>> GetFieldsList(string roleId)
|
||||
{
|
||||
var data = new List<ModuleFieldsEntity>();
|
||||
if (currentuser.IsAdmin)
|
||||
{
|
||||
data = await moduleFieldsApp.GetListNew();
|
||||
}
|
||||
else
|
||||
{
|
||||
var fieldsdata = await moduleFieldsApp.GetListNew();
|
||||
var role = await roleApp.GetForm(roleId);
|
||||
if (role == null || role.F_EnabledMark == false)
|
||||
{
|
||||
return data;
|
||||
}
|
||||
var authorizedata = repository.IQueryable().Where(a => a.F_ObjectId == roleId && a.F_ItemType == 3).ToList();
|
||||
foreach (var item in authorizedata)
|
||||
{
|
||||
ModuleFieldsEntity moduleFieldsEntity = fieldsdata.Where(a => a.F_Id == item.F_ItemId && a.F_IsPublic == false).FirstOrDefault();
|
||||
if (moduleFieldsEntity != null)
|
||||
{
|
||||
data.Add(moduleFieldsEntity);
|
||||
}
|
||||
}
|
||||
data.AddRange(fieldsdata.Where(a => a.F_IsPublic == true));
|
||||
}
|
||||
return data.OrderByDescending(a => a.F_CreatorTime).ToList();
|
||||
}
|
||||
|
||||
public async Task<bool> ActionValidate(string action, bool isAuthorize = false)
|
||||
{
|
||||
var user = await userApp.GetForm(currentuser.UserId);
|
||||
var temps = isAuthorize ? action.Split(',') : new string[0];
|
||||
if (user == null || user.F_EnabledMark == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var authorizeurldata = new List<AuthorizeActionModel>();
|
||||
var cachedata = await CacheHelper.GetAsync<Dictionary<string, List<AuthorizeActionModel>>>(cacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list");
|
||||
if (cachedata == null)
|
||||
{
|
||||
cachedata = new Dictionary<string, List<AuthorizeActionModel>>();
|
||||
}
|
||||
if (user.F_IsAdmin == true)
|
||||
{
|
||||
if (await repository.Db.Queryable<ModuleEntity>().Where(a => a.F_UrlAddress == action || temps.Contains(a.F_Authorize)).AnyAsync()
|
||||
|| await repository.Db.Queryable<ModuleButtonEntity>().Where(a => a.F_UrlAddress == action || temps.Contains(a.F_Authorize)).AnyAsync())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
var rolelist = user.F_RoleId.Split(',');
|
||||
foreach (var roles in rolelist)
|
||||
{
|
||||
if (!cachedata.ContainsKey(roles))
|
||||
{
|
||||
var moduledata = await moduleApp.GetList();
|
||||
moduledata = moduledata.Where(a => a.F_EnabledMark == true).ToList();
|
||||
var buttondata = await moduleButtonApp.GetList();
|
||||
buttondata = buttondata.Where(a => a.F_EnabledMark == true).ToList();
|
||||
var role = await roleApp.GetForm(roles);
|
||||
if (role != null && role.F_EnabledMark == true)
|
||||
{
|
||||
var authdata = new List<AuthorizeActionModel>();
|
||||
var authorizedata = await GetList(roles);
|
||||
foreach (var item in authorizedata)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (item.F_ItemType == 1)
|
||||
{
|
||||
ModuleEntity moduleEntity = moduledata.Where(a => a.F_Id == item.F_ItemId && a.F_IsPublic == false).FirstOrDefault();
|
||||
if (moduleEntity != null)
|
||||
{
|
||||
authdata.Add(new AuthorizeActionModel { F_Id = moduleEntity.F_Id, F_UrlAddress = moduleEntity.F_UrlAddress, F_Authorize = moduleEntity.F_Authorize });
|
||||
}
|
||||
}
|
||||
else if (item.F_ItemType == 2)
|
||||
{
|
||||
ModuleButtonEntity moduleButtonEntity = buttondata.Where(a => a.F_Id == item.F_ItemId && a.F_IsPublic == false).FirstOrDefault();
|
||||
if (moduleButtonEntity != null)
|
||||
{
|
||||
authdata.Add(new AuthorizeActionModel { F_Id = moduleButtonEntity.F_ModuleId, F_UrlAddress = moduleButtonEntity.F_UrlAddress, F_Authorize = moduleButtonEntity.F_Authorize });
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string e = ex.Message;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
authdata.AddRange(moduledata.Where(a => a.F_IsPublic == true).Select(a => new AuthorizeActionModel { F_Id = a.F_Id, F_UrlAddress = a.F_UrlAddress, F_Authorize = a.F_Authorize }).ToList());
|
||||
authdata.AddRange(buttondata.Where(a => a.F_IsPublic == true).Select(a => new AuthorizeActionModel { F_Id = a.F_ModuleId, F_UrlAddress = a.F_UrlAddress, F_Authorize = a.F_Authorize }).ToList());
|
||||
cachedata.Add(roles, authdata);
|
||||
authorizeurldata.AddRange(authdata);
|
||||
await CacheHelper.RemoveAsync(cacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list");
|
||||
await CacheHelper.SetAsync(cacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list", cachedata);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
authorizeurldata.AddRange(cachedata[roles]);
|
||||
}
|
||||
}
|
||||
}
|
||||
var module = authorizeurldata.Find(a => a.F_UrlAddress == action || temps.Contains(a.F_Authorize));
|
||||
if (module != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task<bool> CheckReturnUrl(string userId, string url, bool isAll = false)
|
||||
{
|
||||
var user = await userApp.GetForm(userId);
|
||||
if (isAll == false && (user == null || user.F_EnabledMark == false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (isAll == true || user.F_IsAdmin == true)
|
||||
{
|
||||
if (repository.Db.Queryable<ModuleEntity>().Where(a => a.F_UrlAddress == url).Any() || repository.Db.Queryable<ModuleButtonEntity>().Where(a => a.F_UrlAddress == url).Any())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
var authorizeurldata = new List<AuthorizeActionModel>();
|
||||
var rolelist = user.F_RoleId.Split(',');
|
||||
var cachedata = await CacheHelper.GetAsync<Dictionary<string, List<AuthorizeActionModel>>>(cacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list");
|
||||
if (cachedata == null)
|
||||
{
|
||||
cachedata = new Dictionary<string, List<AuthorizeActionModel>>();
|
||||
}
|
||||
foreach (var roles in rolelist)
|
||||
{
|
||||
if (!cachedata.ContainsKey(roles))
|
||||
{
|
||||
var moduledata = await moduleApp.GetList();
|
||||
moduledata = moduledata.Where(a => a.F_EnabledMark == true).ToList();
|
||||
var buttondata = await moduleButtonApp.GetList();
|
||||
buttondata = buttondata.Where(a => a.F_EnabledMark == true).ToList();
|
||||
var role = await roleApp.GetForm(roles);
|
||||
if (role != null && role.F_EnabledMark == true)
|
||||
{
|
||||
var authdata = new List<AuthorizeActionModel>();
|
||||
var authorizedata = await GetList(roles);
|
||||
foreach (var item in authorizedata)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (item.F_ItemType == 1)
|
||||
{
|
||||
ModuleEntity moduleEntity = moduledata.Where(a => a.F_Id == item.F_ItemId && a.F_IsPublic == false).FirstOrDefault();
|
||||
if (moduleEntity != null)
|
||||
{
|
||||
authdata.Add(new AuthorizeActionModel { F_Id = moduleEntity.F_Id, F_UrlAddress = moduleEntity.F_UrlAddress, F_Authorize = moduleEntity.F_Authorize });
|
||||
}
|
||||
}
|
||||
else if (item.F_ItemType == 2)
|
||||
{
|
||||
ModuleButtonEntity moduleButtonEntity = buttondata.Where(a => a.F_Id == item.F_ItemId && a.F_IsPublic == false).FirstOrDefault();
|
||||
if (moduleButtonEntity != null)
|
||||
{
|
||||
authdata.Add(new AuthorizeActionModel { F_Id = moduleButtonEntity.F_ModuleId, F_UrlAddress = moduleButtonEntity.F_UrlAddress, F_Authorize = moduleButtonEntity.F_Authorize });
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string e = ex.Message;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
authdata.AddRange(moduledata.Where(a => a.F_IsPublic == true).Select(a => new AuthorizeActionModel { F_Id = a.F_Id, F_UrlAddress = a.F_UrlAddress, F_Authorize = a.F_Authorize }).ToList());
|
||||
authdata.AddRange(buttondata.Where(a => a.F_IsPublic == true).Select(a => new AuthorizeActionModel { F_Id = a.F_ModuleId, F_UrlAddress = a.F_UrlAddress, F_Authorize = a.F_Authorize }).ToList());
|
||||
cachedata.Add(roles, authdata);
|
||||
authorizeurldata.AddRange(authdata);
|
||||
await CacheHelper.RemoveAsync(cacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list");
|
||||
await CacheHelper.SetAsync(cacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list", cachedata);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
authorizeurldata.AddRange(cachedata[roles]);
|
||||
}
|
||||
}
|
||||
var module = authorizeurldata.Find(a => a.F_UrlAddress == url);
|
||||
if (module != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> RoleValidate()
|
||||
{
|
||||
var current = OperatorProvider.Provider.GetCurrent();
|
||||
if (current == null || string.IsNullOrEmpty(current.UserId))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var user = await userApp.GetForm(current.UserId);
|
||||
if (user == null || user.F_EnabledMark == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (user.F_IsAdmin == true)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
var authorizeurldata = new List<AuthorizeActionModel>();
|
||||
var rolelist = user.F_RoleId.Split(',');
|
||||
var cachedata = await CacheHelper.GetAsync<Dictionary<string, List<AuthorizeActionModel>>>(cacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list");
|
||||
if (cachedata == null)
|
||||
{
|
||||
cachedata = new Dictionary<string, List<AuthorizeActionModel>>();
|
||||
}
|
||||
foreach (var roles in rolelist)
|
||||
{
|
||||
if (!cachedata.ContainsKey(roles))
|
||||
{
|
||||
var moduledata = await moduleApp.GetList();
|
||||
moduledata = moduledata.Where(a => a.F_EnabledMark == true).ToList();
|
||||
var buttondata = await moduleButtonApp.GetList();
|
||||
buttondata = buttondata.Where(a => a.F_EnabledMark == true).ToList();
|
||||
var role = await roleApp.GetForm(roles);
|
||||
if (role != null && role.F_EnabledMark == true)
|
||||
{
|
||||
var authdata = new List<AuthorizeActionModel>();
|
||||
var authorizedata = await GetList(roles);
|
||||
foreach (var item in authorizedata)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (item.F_ItemType == 1)
|
||||
{
|
||||
ModuleEntity moduleEntity = moduledata.Where(a => a.F_Id == item.F_ItemId && a.F_IsPublic == false).FirstOrDefault();
|
||||
if (moduleEntity != null)
|
||||
{
|
||||
authdata.Add(new AuthorizeActionModel { F_Id = moduleEntity.F_Id, F_UrlAddress = moduleEntity.F_UrlAddress, F_Authorize = moduleEntity.F_Authorize });
|
||||
}
|
||||
}
|
||||
else if (item.F_ItemType == 2)
|
||||
{
|
||||
ModuleButtonEntity moduleButtonEntity = buttondata.Where(a => a.F_Id == item.F_ItemId && a.F_IsPublic == false).FirstOrDefault();
|
||||
if (moduleButtonEntity != null)
|
||||
{
|
||||
authdata.Add(new AuthorizeActionModel { F_Id = moduleButtonEntity.F_ModuleId, F_UrlAddress = moduleButtonEntity.F_UrlAddress, F_Authorize = moduleButtonEntity.F_Authorize });
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string e = ex.Message;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
authdata.AddRange(moduledata.Where(a => a.F_IsPublic == true).Select(a => new AuthorizeActionModel { F_Id = a.F_Id, F_UrlAddress = a.F_UrlAddress, F_Authorize = a.F_Authorize }).ToList());
|
||||
authdata.AddRange(buttondata.Where(a => a.F_IsPublic == true).Select(a => new AuthorizeActionModel { F_Id = a.F_ModuleId, F_UrlAddress = a.F_UrlAddress, F_Authorize = a.F_Authorize }).ToList());
|
||||
cachedata.Add(roles, authdata);
|
||||
authorizeurldata.AddRange(authdata);
|
||||
await CacheHelper.RemoveAsync(cacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list");
|
||||
await CacheHelper.SetAsync(cacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list", cachedata);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
authorizeurldata.AddRange(cachedata[roles]);
|
||||
}
|
||||
}
|
||||
if (authorizeurldata.Count > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
188
WaterCloud.Service/SystemOrganize/RoleService.cs
Normal file
188
WaterCloud.Service/SystemOrganize/RoleService.cs
Normal file
@@ -0,0 +1,188 @@
|
||||
/*******************************************************************************
|
||||
* Copyright © 2020 WaterCloud.Framework 版权所有
|
||||
* Author: WaterCloud
|
||||
* Description: WaterCloud快速开发平台
|
||||
* Website:
|
||||
*********************************************************************************/
|
||||
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.DataBase;
|
||||
using WaterCloud.Domain.SystemOrganize;
|
||||
using WaterCloud.Service.SystemManage;
|
||||
|
||||
namespace WaterCloud.Service.SystemOrganize
|
||||
{
|
||||
public class RoleService : BaseService<RoleEntity>, IDenpendency
|
||||
{
|
||||
public ModuleService moduleApp { get; set; }
|
||||
public ModuleButtonService moduleButtonApp { get; set; }
|
||||
public ModuleFieldsService moduleFieldsApp { get; set; }
|
||||
public ItemsDataService itemsApp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 缓存操作类
|
||||
/// </summary>
|
||||
private string authorizecacheKey = GlobalContext.SystemConfig.ProjectPrefix + "_authorizeurldata_";// +权限
|
||||
|
||||
//获取类名
|
||||
|
||||
public RoleService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<List<RoleExtend>> GetList(string keyword = "")
|
||||
{
|
||||
var query = GetQuery();
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_FullName.Contains(keyword) || a.F_EnCode.Contains(keyword));
|
||||
}
|
||||
return await query.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<RoleExtend>> GetLookList(SoulPage<RoleExtend> pagination, string keyword = "")
|
||||
{
|
||||
//反格式化显示只能用"等于",其他不支持
|
||||
Dictionary<string, Dictionary<string, string>> dic = new Dictionary<string, Dictionary<string, string>>();
|
||||
Dictionary<string, string> enabledTemp = new Dictionary<string, string>();
|
||||
enabledTemp.Add("1", "有效");
|
||||
enabledTemp.Add("0", "无效");
|
||||
dic.Add("F_EnabledMark", enabledTemp);
|
||||
var setList = await itemsApp.GetItemList("RoleType");
|
||||
Dictionary<string, string> messageTypeTemp = new Dictionary<string, string>();
|
||||
foreach (var item in setList)
|
||||
{
|
||||
messageTypeTemp.Add(item.F_ItemCode, item.F_ItemName);
|
||||
}
|
||||
dic.Add("F_Type", messageTypeTemp);
|
||||
pagination = ChangeSoulData(dic, pagination);
|
||||
//获取数据权限
|
||||
var query = GetQuery();
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_FullName.Contains(keyword) || a.F_EnCode.Contains(keyword));
|
||||
}
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
return await query.ToPageListAsync(pagination);
|
||||
}
|
||||
|
||||
public async Task<RoleEntity> GetForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<RoleEntity> GetLookForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return GetFieldsFilterData(data);
|
||||
}
|
||||
|
||||
private ISugarQueryable<RoleExtend> GetQuery()
|
||||
{
|
||||
var query = repository.Db.Queryable<RoleEntity, SystemSetEntity>((a, b) => new JoinQueryInfos(
|
||||
JoinType.Left, a.F_CompanyId == b.F_Id
|
||||
)).Where(a => a.F_DeleteMark == false && a.F_Category == 1)
|
||||
.Select((a, b) => new RoleExtend
|
||||
{
|
||||
F_Id = a.F_Id,
|
||||
F_AllowDelete = a.F_AllowDelete,
|
||||
F_AllowEdit = a.F_AllowEdit,
|
||||
F_Category = a.F_Category,
|
||||
F_CreatorTime = a.F_CreatorTime,
|
||||
F_CreatorUserId = a.F_CreatorUserId,
|
||||
F_Description = a.F_Description,
|
||||
F_DeleteMark = a.F_DeleteMark,
|
||||
F_EnabledMark = a.F_EnabledMark,
|
||||
F_EnCode = a.F_EnCode,
|
||||
F_FullName = a.F_FullName,
|
||||
F_CompanyId = a.F_CompanyId,
|
||||
F_SortCode = a.F_SortCode,
|
||||
F_Type = a.F_Type,
|
||||
F_CompanyName = b.F_CompanyName,
|
||||
}).MergeTable();
|
||||
return query;
|
||||
}
|
||||
|
||||
public async Task DeleteForm(string keyValue)
|
||||
{
|
||||
if (await repository.Db.Queryable<UserEntity>().Where(a => a.F_RoleId.Contains(keyValue)).AnyAsync())
|
||||
{
|
||||
throw new Exception("角色使用中,无法删除");
|
||||
}
|
||||
repository.Db.Ado.BeginTran();
|
||||
await repository.Delete(a => a.F_Id == keyValue);
|
||||
await repository.Db.Deleteable<RoleAuthorizeEntity>(a => a.F_ObjectId == keyValue).ExecuteCommandAsync();
|
||||
repository.Db.Ado.CommitTran();
|
||||
await CacheHelper.RemoveAsync(authorizecacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list");
|
||||
}
|
||||
|
||||
public async Task SubmitForm(RoleEntity roleEntity, string[] permissionIds, string[] permissionfieldsIds, string keyValue)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
roleEntity.F_Id = keyValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
roleEntity.F_DeleteMark = false;
|
||||
roleEntity.F_AllowEdit = false;
|
||||
roleEntity.F_AllowDelete = false;
|
||||
roleEntity.Create();
|
||||
}
|
||||
var moduledata = await moduleApp.GetList();
|
||||
var buttondata = await moduleButtonApp.GetList();
|
||||
var fieldsdata = await moduleFieldsApp.GetList();
|
||||
List<RoleAuthorizeEntity> roleAuthorizeEntitys = new List<RoleAuthorizeEntity>();
|
||||
foreach (var itemId in permissionIds)
|
||||
{
|
||||
RoleAuthorizeEntity roleAuthorizeEntity = new RoleAuthorizeEntity();
|
||||
roleAuthorizeEntity.F_Id = Utils.GuId();
|
||||
roleAuthorizeEntity.F_ObjectType = 1;
|
||||
roleAuthorizeEntity.F_ObjectId = roleEntity.F_Id;
|
||||
roleAuthorizeEntity.F_ItemId = itemId;
|
||||
if (moduledata.Find(a => a.F_Id == itemId) != null)
|
||||
{
|
||||
roleAuthorizeEntity.F_ItemType = 1;
|
||||
roleAuthorizeEntitys.Add(roleAuthorizeEntity);
|
||||
}
|
||||
if (buttondata.Find(a => a.F_Id == itemId) != null)
|
||||
{
|
||||
roleAuthorizeEntity.F_ItemType = 2;
|
||||
roleAuthorizeEntitys.Add(roleAuthorizeEntity);
|
||||
}
|
||||
}
|
||||
foreach (var itemId in permissionfieldsIds)
|
||||
{
|
||||
RoleAuthorizeEntity roleAuthorizeEntity = new RoleAuthorizeEntity();
|
||||
roleAuthorizeEntity.F_Id = Utils.GuId();
|
||||
roleAuthorizeEntity.F_ObjectType = 1;
|
||||
roleAuthorizeEntity.F_ObjectId = roleEntity.F_Id;
|
||||
roleAuthorizeEntity.F_ItemId = itemId;
|
||||
if (fieldsdata.Find(a => a.F_Id == itemId) != null)
|
||||
{
|
||||
roleAuthorizeEntity.F_ItemType = 3;
|
||||
roleAuthorizeEntitys.Add(roleAuthorizeEntity);
|
||||
}
|
||||
}
|
||||
repository.Db.Ado.BeginTran();
|
||||
if (!string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
await repository.Update(roleEntity);
|
||||
}
|
||||
else
|
||||
{
|
||||
roleEntity.F_Category = 1;
|
||||
await repository.Insert(roleEntity);
|
||||
}
|
||||
await repository.Db.Deleteable<RoleAuthorizeEntity>(a => a.F_ObjectId == roleEntity.F_Id).ExecuteCommandAsync();
|
||||
await repository.Db.Insertable(roleAuthorizeEntitys).ExecuteCommandAsync();
|
||||
repository.Db.Ado.CommitTran();
|
||||
await CacheHelper.RemoveAsync(authorizecacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list");
|
||||
}
|
||||
}
|
||||
}
|
||||
371
WaterCloud.Service/SystemOrganize/SystemSetService.cs
Normal file
371
WaterCloud.Service/SystemOrganize/SystemSetService.cs
Normal file
@@ -0,0 +1,371 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.DataBase;
|
||||
using WaterCloud.Domain.SystemManage;
|
||||
using WaterCloud.Domain.SystemOrganize;
|
||||
using WaterCloud.Service.SystemManage;
|
||||
|
||||
namespace WaterCloud.Service.SystemOrganize
|
||||
{
|
||||
/// <summary>
|
||||
/// 创 建:超级管理员
|
||||
/// 日 期:2020-06-12 13:50
|
||||
/// 描 述:系统设置服务类
|
||||
/// </summary>
|
||||
public class SystemSetService : BaseService<SystemSetEntity>, IDenpendency
|
||||
{
|
||||
private string cacheKeyOperator = GlobalContext.SystemConfig.ProjectPrefix + "_operator_";// +登录者token
|
||||
private static string cacheKey = GlobalContext.SystemConfig.ProjectPrefix + "_dblist";// 数据库键
|
||||
public ModuleService moduleApp { get; set; }
|
||||
public ModuleButtonService moduleButtonApp { get; set; }
|
||||
public ModuleFieldsService moduleFieldsApp { get; set; }
|
||||
|
||||
public SystemSetService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
#region 获取数据
|
||||
|
||||
public async Task<List<SystemSetEntity>> GetList(string keyword = "")
|
||||
{
|
||||
var query = repository.IQueryable();
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_CompanyName.Contains(keyword) || a.F_ProjectName.Contains(keyword));
|
||||
}
|
||||
return await query.Where(a => a.F_DeleteMark == false).OrderBy(a => a.F_Id, OrderByType.Desc).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<SystemSetEntity>> GetLookList(string keyword = "")
|
||||
{
|
||||
var query = repository.IQueryable().Where(a => a.F_DeleteMark == false);
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_CompanyName.Contains(keyword) || a.F_ProjectName.Contains(keyword));
|
||||
}
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
return await query.OrderBy(a => a.F_Id, OrderByType.Desc).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<SystemSetEntity> GetFormByHost(string host)
|
||||
{
|
||||
repository.ChangeEntityDb(GlobalContext.SystemConfig.MainDbNumber);
|
||||
var query = repository.IQueryable();
|
||||
if (!string.IsNullOrEmpty(host))
|
||||
{
|
||||
//此处需修改
|
||||
query = query.Where(a => a.F_HostUrl.Contains(host));
|
||||
}
|
||||
else
|
||||
{
|
||||
query = query.Where(a => a.F_DbNumber == "0");
|
||||
}
|
||||
if (!await query.Clone().AnyAsync())
|
||||
{
|
||||
query = repository.IQueryable();
|
||||
query = query.Where(a => a.F_DbNumber == "0");
|
||||
}
|
||||
var data = await query.Where(a => a.F_DeleteMark == false).FirstAsync();
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<List<SystemSetEntity>> GetLookList(Pagination pagination, string keyword = "")
|
||||
{
|
||||
var query = repository.IQueryable().Where(a => a.F_DeleteMark == false && a.F_DbNumber != "0");
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
//此处需修改
|
||||
query = query.Where(a => a.F_CompanyName.Contains(keyword) || a.F_ProjectName.Contains(keyword));
|
||||
}
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
return await query.ToPageListAsync(pagination);
|
||||
}
|
||||
|
||||
public async Task<SystemSetEntity> GetForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return data;
|
||||
}
|
||||
|
||||
#endregion 获取数据
|
||||
|
||||
public async Task<SystemSetEntity> GetLookForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return GetFieldsFilterData(data);
|
||||
}
|
||||
|
||||
#region 提交数据
|
||||
|
||||
public async Task SubmitForm(SystemSetEntity entity, string keyValue, string[] permissionIds = null, string[] permissionfieldsIds = null)
|
||||
{
|
||||
repository.ChangeEntityDb(GlobalContext.SystemConfig.MainDbNumber);
|
||||
List<RoleAuthorizeEntity> roleAuthorizeEntitys = new List<RoleAuthorizeEntity>();
|
||||
List<ModuleEntity> modules = new List<ModuleEntity>();
|
||||
List<ModuleButtonEntity> modulebtns = new List<ModuleButtonEntity>();
|
||||
List<ModuleFieldsEntity> modulefileds = new List<ModuleFieldsEntity>();
|
||||
//字典数据
|
||||
var itemsTypes = await repository.Db.Queryable<ItemsEntity>().ToListAsync();
|
||||
var itemsDetails = await repository.Db.Queryable<ItemsDetailEntity>().ToListAsync();
|
||||
repository.Tenant.BeginTran();
|
||||
if (string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
entity.F_DeleteMark = false;
|
||||
entity.Create();
|
||||
await repository.Insert(entity);
|
||||
if (permissionIds != null)
|
||||
{
|
||||
var moduledata = await moduleApp.GetList();
|
||||
var buttondata = await moduleButtonApp.GetList();
|
||||
foreach (var itemId in permissionIds.Distinct())
|
||||
{
|
||||
RoleAuthorizeEntity roleAuthorizeEntity = new RoleAuthorizeEntity();
|
||||
roleAuthorizeEntity.F_Id = Utils.GuId();
|
||||
roleAuthorizeEntity.F_ObjectType = 2;
|
||||
roleAuthorizeEntity.F_ObjectId = entity.F_Id;
|
||||
roleAuthorizeEntity.F_ItemId = itemId;
|
||||
if (moduledata.Find(a => a.F_Id == itemId) != null)
|
||||
{
|
||||
roleAuthorizeEntity.F_ItemType = 1;
|
||||
roleAuthorizeEntitys.Add(roleAuthorizeEntity);
|
||||
modules.Add(moduledata.Find(a => a.F_Id == itemId));
|
||||
}
|
||||
if (buttondata.Find(a => a.F_Id == itemId) != null)
|
||||
{
|
||||
roleAuthorizeEntity.F_ItemType = 2;
|
||||
roleAuthorizeEntitys.Add(roleAuthorizeEntity);
|
||||
modulebtns.Add(buttondata.Find(a => a.F_Id == itemId));
|
||||
}
|
||||
}
|
||||
//排除租户
|
||||
modules.AddRange(moduledata.Where(a => a.F_IsPublic == true && a.F_EnabledMark == true && a.F_DeleteMark == false && a.F_EnCode != "SystemSet"));
|
||||
modulebtns.AddRange(buttondata.Where(a => a.F_IsPublic == true && a.F_EnabledMark == true && a.F_DeleteMark == false));
|
||||
}
|
||||
if (permissionfieldsIds != null)
|
||||
{
|
||||
var fieldsdata = await moduleFieldsApp.GetList();
|
||||
foreach (var itemId in permissionfieldsIds.Distinct())
|
||||
{
|
||||
RoleAuthorizeEntity roleAuthorizeEntity = new RoleAuthorizeEntity();
|
||||
roleAuthorizeEntity.F_Id = Utils.GuId();
|
||||
roleAuthorizeEntity.F_ObjectType = 2;
|
||||
roleAuthorizeEntity.F_ObjectId = entity.F_Id;
|
||||
roleAuthorizeEntity.F_ItemId = itemId;
|
||||
if (fieldsdata.Find(a => a.F_Id == itemId) != null)
|
||||
{
|
||||
roleAuthorizeEntity.F_ItemType = 3;
|
||||
roleAuthorizeEntitys.Add(roleAuthorizeEntity);
|
||||
modulefileds.Add(fieldsdata.Find(a => a.F_Id == itemId));
|
||||
}
|
||||
}
|
||||
modulefileds.AddRange(fieldsdata.Where(a => a.F_IsPublic == true && a.F_EnabledMark == true && a.F_DeleteMark == false));
|
||||
}
|
||||
//新建租户权限
|
||||
if (roleAuthorizeEntitys.Count > 0)
|
||||
{
|
||||
await repository.Db.Insertable(roleAuthorizeEntitys).ExecuteCommandAsync();
|
||||
}
|
||||
//新建数据库和表
|
||||
using (var db = new SqlSugarClient(DBContexHelper.Contex(entity.F_DbString, entity.F_DBProvider)))
|
||||
{
|
||||
//判断数据库有没有被使用
|
||||
db.DbMaintenance.CreateDatabase();
|
||||
if (db.DbMaintenance.GetTableInfoList(false).Where(a => a.Name.ToLower() == "sys_module").Any())
|
||||
throw new Exception("数据库已存在,请重新设置数据库");
|
||||
var path = AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory;
|
||||
//反射取指定前后缀的dll
|
||||
var referencedAssemblies = Directory.GetFiles(path, "WaterCloud.Domain.dll").Select(Assembly.LoadFrom).ToArray();
|
||||
var types = referencedAssemblies.SelectMany(a => a.GetTypes().ToArray());
|
||||
var implementType = types.Where(x => x.IsClass);
|
||||
//忽视类列表
|
||||
var ignoreTables = new List<string> { "RoleExtend", "UserExtend" };
|
||||
foreach (var item in implementType)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (item.GetCustomAttributes(typeof(SugarTable), true).FirstOrDefault((x => x.GetType() == typeof(SugarTable))) is SugarTable sugarTable && !ignoreTables.Any(a => a == item.Name))
|
||||
{
|
||||
db.CodeFirst.SetStringDefaultLength(50).InitTables(item);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
//新建账户,密码
|
||||
UserEntity user = new UserEntity();
|
||||
user.Create();
|
||||
user.F_Account = entity.F_AdminAccount;
|
||||
user.F_RealName = entity.F_CompanyName;
|
||||
user.F_Gender = true;
|
||||
user.F_CompanyId = entity.F_Id;
|
||||
user.F_IsAdmin = true;
|
||||
user.F_DeleteMark = false;
|
||||
user.F_EnabledMark = true;
|
||||
user.F_IsBoss = false;
|
||||
user.F_IsLeaderInDepts = false;
|
||||
user.F_SortCode = 0;
|
||||
user.F_IsSenior = false;
|
||||
UserLogOnEntity logon = new UserLogOnEntity();
|
||||
logon.F_Id = user.F_Id;
|
||||
logon.F_UserId = user.F_Id;
|
||||
logon.F_UserSecretkey = Md5.md5(Utils.CreateNo(), 16).ToLower();
|
||||
logon.F_UserPassword = Md5.md5(DESEncrypt.Encrypt(Md5.md5(entity.F_AdminPassword, 32).ToLower(), logon.F_UserSecretkey).ToLower(), 32).ToLower();
|
||||
db.Insertable(user).ExecuteCommand();
|
||||
db.Insertable(logon).ExecuteCommand();
|
||||
await db.Insertable(roleAuthorizeEntitys).ExecuteCommandAsync();
|
||||
await db.Insertable(entity).ExecuteCommandAsync();
|
||||
//新建菜单
|
||||
await db.Insertable(modules).ExecuteCommandAsync();
|
||||
await db.Insertable(modulebtns).ExecuteCommandAsync();
|
||||
await db.Insertable(modulefileds).ExecuteCommandAsync();
|
||||
//同步字典
|
||||
await db.Deleteable<ItemsEntity>().ExecuteCommandAsync();
|
||||
await db.Deleteable<ItemsDetailEntity>().ExecuteCommandAsync();
|
||||
await db.Insertable(itemsTypes).ExecuteCommandAsync();
|
||||
await db.Insertable(itemsDetails).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.Modify(keyValue);
|
||||
if (permissionIds != null)
|
||||
{
|
||||
var moduledata = await moduleApp.GetList();
|
||||
var buttondata = await moduleButtonApp.GetList();
|
||||
foreach (var itemId in permissionIds.Distinct())
|
||||
{
|
||||
RoleAuthorizeEntity roleAuthorizeEntity = new RoleAuthorizeEntity();
|
||||
roleAuthorizeEntity.F_Id = Utils.GuId();
|
||||
roleAuthorizeEntity.F_ObjectType = 2;
|
||||
roleAuthorizeEntity.F_ObjectId = entity.F_Id;
|
||||
roleAuthorizeEntity.F_ItemId = itemId;
|
||||
if (moduledata.Find(a => a.F_Id == itemId) != null)
|
||||
{
|
||||
roleAuthorizeEntity.F_ItemType = 1;
|
||||
roleAuthorizeEntitys.Add(roleAuthorizeEntity);
|
||||
modules.Add(moduledata.Find(a => a.F_Id == itemId));
|
||||
}
|
||||
if (buttondata.Find(a => a.F_Id == itemId) != null)
|
||||
{
|
||||
roleAuthorizeEntity.F_ItemType = 2;
|
||||
roleAuthorizeEntitys.Add(roleAuthorizeEntity);
|
||||
modulebtns.Add(buttondata.Find(a => a.F_Id == itemId));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (permissionfieldsIds != null)
|
||||
{
|
||||
var fieldsdata = await moduleFieldsApp.GetList();
|
||||
foreach (var itemId in permissionfieldsIds.Distinct())
|
||||
{
|
||||
RoleAuthorizeEntity roleAuthorizeEntity = new RoleAuthorizeEntity();
|
||||
roleAuthorizeEntity.F_Id = Utils.GuId();
|
||||
roleAuthorizeEntity.F_ObjectType = 2;
|
||||
roleAuthorizeEntity.F_ObjectId = entity.F_Id;
|
||||
roleAuthorizeEntity.F_ItemId = itemId;
|
||||
if (fieldsdata.Find(a => a.F_Id == itemId) != null)
|
||||
{
|
||||
roleAuthorizeEntity.F_ItemType = 3;
|
||||
roleAuthorizeEntitys.Add(roleAuthorizeEntity);
|
||||
modulefileds.Add(fieldsdata.Find(a => a.F_Id == itemId));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (roleAuthorizeEntitys.Count > 0)
|
||||
{
|
||||
await repository.Db.Deleteable<RoleAuthorizeEntity>(a => a.F_ObjectId == entity.F_Id).ExecuteCommandAsync();
|
||||
await repository.Db.Insertable(roleAuthorizeEntitys).ExecuteCommandAsync();
|
||||
}
|
||||
//更新主库
|
||||
if (currentuser.IsSuperAdmin == true)
|
||||
{
|
||||
await repository.Db.Updateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.F_AdminAccount = null;
|
||||
entity.F_AdminPassword = null;
|
||||
await repository.Db.Updateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
||||
}
|
||||
//更新租户库
|
||||
if (GlobalContext.SystemConfig.SqlMode == Define.SQL_TENANT)
|
||||
{
|
||||
var tenant = await repository.Db.Queryable<SystemSetEntity>().InSingleAsync(entity.F_Id);
|
||||
repository.ChangeEntityDb(tenant.F_DbNumber);
|
||||
var user = repository.Db.Queryable<UserEntity>().First(a => a.F_CompanyId == entity.F_Id && a.F_IsAdmin == true);
|
||||
var userinfo = repository.Db.Queryable<UserLogOnEntity>().First(a => a.F_UserId == user.F_Id);
|
||||
userinfo.F_UserSecretkey = Md5.md5(Utils.CreateNo(), 16).ToLower();
|
||||
userinfo.F_UserPassword = Md5.md5(DESEncrypt.Encrypt(Md5.md5(entity.F_AdminPassword, 32).ToLower(), userinfo.F_UserSecretkey).ToLower(), 32).ToLower();
|
||||
await repository.Db.Updateable<UserEntity>(a => new UserEntity
|
||||
{
|
||||
F_Account = entity.F_AdminAccount
|
||||
}).Where(a => a.F_Id == user.F_Id).ExecuteCommandAsync();
|
||||
await repository.Db.Updateable<UserLogOnEntity>(a => new UserLogOnEntity
|
||||
{
|
||||
F_UserPassword = userinfo.F_UserPassword,
|
||||
F_UserSecretkey = userinfo.F_UserSecretkey
|
||||
}).Where(a => a.F_Id == userinfo.F_Id).ExecuteCommandAsync();
|
||||
await repository.Db.Updateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
||||
//更新菜单
|
||||
if (roleAuthorizeEntitys.Count > 0)
|
||||
{
|
||||
await repository.Db.Deleteable<ModuleEntity>().ExecuteCommandAsync();
|
||||
await repository.Db.Deleteable<ModuleButtonEntity>().ExecuteCommandAsync();
|
||||
await repository.Db.Deleteable<ModuleFieldsEntity>().ExecuteCommandAsync();
|
||||
await repository.Db.Insertable(modules).ExecuteCommandAsync();
|
||||
await repository.Db.Insertable(modulebtns).ExecuteCommandAsync();
|
||||
await repository.Db.Insertable(modulefileds).ExecuteCommandAsync();
|
||||
}
|
||||
//同步字典
|
||||
await repository.Db.Deleteable<ItemsEntity>().ExecuteCommandAsync();
|
||||
await repository.Db.Deleteable<ItemsDetailEntity>().ExecuteCommandAsync();
|
||||
await repository.Db.Insertable(itemsTypes).ExecuteCommandAsync();
|
||||
await repository.Db.Insertable(itemsDetails).ExecuteCommandAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
var user = repository.Db.Queryable<UserEntity>().First(a => a.F_CompanyId == entity.F_Id && a.F_IsAdmin == true);
|
||||
var userinfo = repository.Db.Queryable<UserLogOnEntity>().First(a => a.F_UserId == user.F_Id);
|
||||
userinfo.F_UserSecretkey = Md5.md5(Utils.CreateNo(), 16).ToLower();
|
||||
userinfo.F_UserPassword = Md5.md5(DESEncrypt.Encrypt(Md5.md5(entity.F_AdminPassword, 32).ToLower(), userinfo.F_UserSecretkey).ToLower(), 32).ToLower();
|
||||
await repository.Db.Updateable<UserEntity>(a => new UserEntity
|
||||
{
|
||||
F_Account = entity.F_AdminAccount
|
||||
}).Where(a => a.F_Id == user.F_Id).ExecuteCommandAsync();
|
||||
await repository.Db.Updateable<UserLogOnEntity>(a => new UserLogOnEntity
|
||||
{
|
||||
F_UserPassword = userinfo.F_UserPassword,
|
||||
F_UserSecretkey = userinfo.F_UserSecretkey
|
||||
}).Where(a => a.F_Id == userinfo.F_Id).ExecuteCommandAsync();
|
||||
}
|
||||
var set = await repository.Db.Queryable<SystemSetEntity>().InSingleAsync(entity.F_Id);
|
||||
var tempkey = repository.ChangeEntityDb(GlobalContext.SystemConfig.MainDbNumber).Queryable<UserEntity>().First(a => a.F_IsAdmin == true).F_Id;
|
||||
await CacheHelper.RemoveAsync(cacheKeyOperator + "info_" + tempkey);
|
||||
}
|
||||
repository.Tenant.CommitTran();
|
||||
//清空缓存,重新拉数据
|
||||
DBInitialize.GetConnectionConfigs(true);
|
||||
}
|
||||
|
||||
public async Task DeleteForm(string keyValue)
|
||||
{
|
||||
await repository.Update(a => a.F_Id == keyValue, a => new SystemSetEntity
|
||||
{
|
||||
F_DeleteMark = true,
|
||||
F_EnabledMark = false,
|
||||
F_DeleteUserId = currentuser.UserId
|
||||
});
|
||||
}
|
||||
|
||||
#endregion 提交数据
|
||||
}
|
||||
}
|
||||
93
WaterCloud.Service/SystemOrganize/UserLogOnService.cs
Normal file
93
WaterCloud.Service/SystemOrganize/UserLogOnService.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
/*******************************************************************************
|
||||
* Copyright © 2020 WaterCloud.Framework 版权所有
|
||||
* Author: WaterCloud
|
||||
* Description: WaterCloud快速开发平台
|
||||
* Website:
|
||||
*********************************************************************************/
|
||||
|
||||
using SqlSugar;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.Domain.SystemOrganize;
|
||||
|
||||
namespace WaterCloud.Service.SystemOrganize
|
||||
{
|
||||
public class UserLogOnService : BaseService<UserLogOnEntity>, IDenpendency
|
||||
{
|
||||
/// <summary>
|
||||
/// 缓存操作类
|
||||
/// </summary>
|
||||
private string cacheKeyOperator = GlobalContext.SystemConfig.ProjectPrefix + "_operator_";// +登录者token
|
||||
|
||||
public UserLogOnService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<UserLogOnEntity> GetForm(string keyValue)
|
||||
{
|
||||
return await repository.FindEntity(keyValue);
|
||||
}
|
||||
|
||||
public async Task RevisePassword(string userPassword, string keyValue)
|
||||
{
|
||||
UserLogOnEntity entity = new UserLogOnEntity();
|
||||
entity = repository.IQueryable().InSingle(keyValue);
|
||||
if (entity == null)
|
||||
{
|
||||
entity = new UserLogOnEntity();
|
||||
entity.F_Id = keyValue;
|
||||
entity.F_UserId = keyValue;
|
||||
entity.F_LogOnCount = 0;
|
||||
entity.F_UserOnLine = false;
|
||||
entity.F_UserSecretkey = Md5.md5(Utils.CreateNo(), 16).ToLower();
|
||||
entity.F_UserPassword = Md5.md5(DESEncrypt.Encrypt(Md5.md5(userPassword, 32).ToLower(), entity.F_UserSecretkey).ToLower(), 32).ToLower();
|
||||
await repository.Insert(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
//userLogOnEntity = new UserLogOnEntity();
|
||||
//userLogOnEntity.F_Id = keyValue;
|
||||
entity.F_UserSecretkey = Md5.md5(Utils.CreateNo(), 16).ToLower();
|
||||
entity.F_UserPassword = Md5.md5(DESEncrypt.Encrypt(Md5.md5(userPassword, 32).ToLower(), entity.F_UserSecretkey).ToLower(), 32).ToLower();
|
||||
await repository.Update(entity);
|
||||
}
|
||||
//缓存用户账户信息
|
||||
var userLogOnEntity = await CacheHelper.GetAsync<OperatorUserInfo>(cacheKeyOperator + "info_" + keyValue);
|
||||
if (userLogOnEntity == null)
|
||||
{
|
||||
userLogOnEntity = new OperatorUserInfo();
|
||||
userLogOnEntity.F_UserPassword = entity.F_UserPassword;
|
||||
userLogOnEntity.F_UserSecretkey = entity.F_UserSecretkey;
|
||||
userLogOnEntity.F_AllowEndTime = entity.F_AllowEndTime;
|
||||
userLogOnEntity.F_AllowStartTime = entity.F_AllowStartTime;
|
||||
userLogOnEntity.F_AnswerQuestion = entity.F_AnswerQuestion;
|
||||
userLogOnEntity.F_ChangePasswordDate = entity.F_ChangePasswordDate;
|
||||
userLogOnEntity.F_FirstVisitTime = entity.F_FirstVisitTime;
|
||||
userLogOnEntity.F_LastVisitTime = entity.F_LastVisitTime;
|
||||
userLogOnEntity.F_LockEndDate = entity.F_LockEndDate;
|
||||
userLogOnEntity.F_LockStartDate = entity.F_LockStartDate;
|
||||
userLogOnEntity.F_LogOnCount = entity.F_LogOnCount;
|
||||
userLogOnEntity.F_PreviousVisitTime = entity.F_PreviousVisitTime;
|
||||
userLogOnEntity.F_Question = entity.F_Question;
|
||||
userLogOnEntity.F_Theme = entity.F_Theme;
|
||||
}
|
||||
userLogOnEntity.F_UserPassword = entity.F_UserPassword;
|
||||
userLogOnEntity.F_UserSecretkey = entity.F_UserSecretkey;
|
||||
await CacheHelper.RemoveAsync(cacheKeyOperator + "info_" + keyValue);
|
||||
await CacheHelper.SetAsync(cacheKeyOperator + "info_" + keyValue, userLogOnEntity);
|
||||
}
|
||||
|
||||
public async Task ReviseSelfPassword(string userPassword, string keyValue)
|
||||
{
|
||||
UserLogOnEntity entity = new UserLogOnEntity();
|
||||
entity = repository.IQueryable().InSingle(keyValue);
|
||||
entity.F_UserSecretkey = Md5.md5(Utils.CreateNo(), 16).ToLower();
|
||||
entity.F_UserPassword = Md5.md5(DESEncrypt.Encrypt(Md5.md5(userPassword, 32).ToLower(), entity.F_UserSecretkey).ToLower(), 32).ToLower();
|
||||
await repository.Update(entity);
|
||||
var userLogOnEntity = await CacheHelper.GetAsync<OperatorUserInfo>(cacheKeyOperator + "info_" + keyValue);
|
||||
userLogOnEntity.F_UserPassword = entity.F_UserPassword;
|
||||
userLogOnEntity.F_UserSecretkey = entity.F_UserSecretkey;
|
||||
await CacheHelper.SetAsync(cacheKeyOperator + "info_" + keyValue, userLogOnEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
394
WaterCloud.Service/SystemOrganize/UserService.cs
Normal file
394
WaterCloud.Service/SystemOrganize/UserService.cs
Normal file
@@ -0,0 +1,394 @@
|
||||
/*******************************************************************************
|
||||
* Copyright © 2020 WaterCloud.Framework 版权所有
|
||||
* Author: WaterCloud
|
||||
* Description: WaterCloud快速开发平台
|
||||
* Website:
|
||||
*********************************************************************************/
|
||||
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.DataBase;
|
||||
using WaterCloud.Domain.SystemOrganize;
|
||||
using WaterCloud.Domain.SystemSecurity;
|
||||
using WaterCloud.Service.SystemManage;
|
||||
using WaterCloud.Service.SystemSecurity;
|
||||
|
||||
namespace WaterCloud.Service.SystemOrganize
|
||||
{
|
||||
public class UserService : BaseService<UserEntity>, IDenpendency
|
||||
{
|
||||
public SystemSetService syssetApp { get; set; }
|
||||
public FilterIPService ipApp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 缓存操作类
|
||||
/// </summary>
|
||||
private string cacheKeyOperator = GlobalContext.SystemConfig.ProjectPrefix + "_operator_";// +登录者token
|
||||
|
||||
//获取类名
|
||||
|
||||
public UserService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<List<UserExtend>> GetLookList(SoulPage<UserExtend> pagination, string keyword)
|
||||
{
|
||||
//反格式化显示只能用"等于",其他不支持
|
||||
Dictionary<string, Dictionary<string, string>> dic = new Dictionary<string, Dictionary<string, string>>();
|
||||
Dictionary<string, string> enabledTemp = new Dictionary<string, string>();
|
||||
enabledTemp.Add("1", "有效");
|
||||
enabledTemp.Add("0", "无效");
|
||||
dic.Add("F_EnabledMark", enabledTemp);
|
||||
Dictionary<string, string> sexTemp = new Dictionary<string, string>();
|
||||
var sexList = await GlobalContext.GetService<ItemsDataService>().GetItemList("104");
|
||||
foreach (var item in sexList)
|
||||
{
|
||||
sexTemp.Add(item.F_ItemCode, item.F_ItemName);
|
||||
}
|
||||
dic.Add("F_Gender", sexTemp);
|
||||
pagination = ChangeSoulData(dic, pagination);
|
||||
//获取数据权限
|
||||
var query = GetQuery().Where(a => a.F_IsAdmin == false);
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_Account.Contains(keyword) || a.F_RealName.Contains(keyword) || a.F_MobilePhone.Contains(keyword));
|
||||
}
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
var data = await query.ToPageListAsync(pagination);
|
||||
var roles = repository.Db.Queryable<RoleEntity>().ToList();
|
||||
var orgs = repository.Db.Queryable<OrganizeEntity>().ToList();
|
||||
foreach (var item in data)
|
||||
{
|
||||
string[] roleIds = item.F_RoleId.Split(',');
|
||||
string[] departmentIds = item.F_OrganizeId.Split(',');
|
||||
item.F_OrganizeName = string.Join(',', orgs.Where(a => departmentIds.Contains(a.F_Id)).Select(a => a.F_FullName).ToList());
|
||||
item.F_RoleName = string.Join(',', roles.Where(a => roleIds.Contains(a.F_Id)).Select(a => a.F_FullName).ToList());
|
||||
item.F_IsLeaderInDepts = orgs.Any(a => departmentIds.Contains(a.F_Id) && a.F_ManagerId == item.F_Id);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<List<UserExtend>> GetList(string keyword)
|
||||
{
|
||||
var cachedata = GetQuery().Where(a => a.F_IsAdmin == false);
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
cachedata = cachedata.Where(a => a.F_Account.Contains(keyword) || a.F_RealName.Contains(keyword) || a.F_MobilePhone.Contains(keyword));
|
||||
}
|
||||
var data = await cachedata.OrderBy(a => a.F_Account).ToListAsync();
|
||||
var roles = await repository.Db.Queryable<RoleEntity>().ToListAsync();
|
||||
var orgs = await repository.Db.Queryable<OrganizeEntity>().ToListAsync();
|
||||
foreach (var item in data)
|
||||
{
|
||||
string[] roleIds = item.F_RoleId.Split(',');
|
||||
string[] departmentIds = item.F_OrganizeId.Split(',');
|
||||
item.F_OrganizeName = string.Join(',', orgs.Where(a => departmentIds.Contains(a.F_Id)).Select(a => a.F_FullName).ToList());
|
||||
item.F_RoleName = string.Join(',', roles.Where(a => roleIds.Contains(a.F_Id)).Select(a => a.F_FullName).ToList());
|
||||
item.F_IsLeaderInDepts = orgs.Any(a => departmentIds.Contains(a.F_Id) && a.F_ManagerId == item.F_Id);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private ISugarQueryable<UserExtend> GetQuery()
|
||||
{
|
||||
var query = repository.Db.Queryable<UserEntity, RoleEntity, SystemSetEntity,UserEntity>((a, b, c,d) => new JoinQueryInfos(
|
||||
JoinType.Left, a.F_DutyId == b.F_Id,
|
||||
JoinType.Left, a.F_CompanyId == c.F_Id,
|
||||
JoinType.Left, a.F_ManagerId == d.F_Id
|
||||
)).Where(a => a.F_DeleteMark == false)
|
||||
.Select((a, b, c, d) => new UserExtend
|
||||
{
|
||||
F_Id = a.F_Id,
|
||||
F_IsSenior = a.F_IsSenior,
|
||||
F_SecurityLevel = a.F_SecurityLevel,
|
||||
F_Account = a.F_Account,
|
||||
F_DingTalkAvatar = a.F_DingTalkAvatar,
|
||||
F_IsAdmin = a.F_IsAdmin,
|
||||
F_Birthday = a.F_Birthday,
|
||||
F_CompanyName = c.F_CompanyName,
|
||||
F_CreatorTime = a.F_CreatorTime,
|
||||
F_CreatorUserId = a.F_CreatorUserId,
|
||||
F_OrganizeId = a.F_OrganizeId,
|
||||
F_Description = a.F_Description,
|
||||
F_DingTalkUserId = a.F_DingTalkUserId,
|
||||
F_DingTalkUserName = a.F_DingTalkUserName,
|
||||
F_DutyId = a.F_DutyId,
|
||||
F_DutyName = b.F_FullName,
|
||||
F_Email = a.F_Email,
|
||||
F_EnabledMark = a.F_EnabledMark,
|
||||
F_Gender = a.F_Gender,
|
||||
F_HeadIcon = a.F_HeadIcon,
|
||||
F_HeadImgUrl = a.F_HeadImgUrl,
|
||||
F_IsBoss = a.F_IsBoss,
|
||||
F_ManagerId = a.F_ManagerId,
|
||||
F_ManagerName = d.F_RealName,
|
||||
F_MobilePhone = a.F_MobilePhone,
|
||||
F_NickName = a.F_NickName,
|
||||
F_CompanyId = a.F_CompanyId,
|
||||
F_RealName = a.F_RealName,
|
||||
F_Remark = a.F_RealName,
|
||||
F_RoleId = a.F_RoleId,
|
||||
F_Signature = a.F_Signature,
|
||||
F_SortCode = a.F_SortCode,
|
||||
F_WeChat = a.F_WeChat,
|
||||
F_WxNickName = a.F_WxNickName,
|
||||
F_WxOpenId = a.F_WxOpenId,
|
||||
F_OrganizeName = "",
|
||||
F_RoleName = ""
|
||||
}).MergeTable();
|
||||
return query;
|
||||
}
|
||||
|
||||
public async Task SubmitUserForm(UserEntity userEntity)
|
||||
{
|
||||
await repository.Update(userEntity);
|
||||
}
|
||||
|
||||
public async Task<List<UserEntity>> GetUserList(string keyword)
|
||||
{
|
||||
var query = repository.IQueryable();
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_Account.Contains(keyword) || a.F_RealName.Contains(keyword) || a.F_MobilePhone.Contains(keyword));
|
||||
}
|
||||
return await query.Where(a => a.F_EnabledMark == true && a.F_DeleteMark == false).OrderBy(a => a.F_Account).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<UserExtend> GetForm(string keyValue)
|
||||
{
|
||||
var data = await GetQuery().FirstAsync(a => a.F_Id == keyValue);
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<UserExtend> GetFormExtend(string keyValue)
|
||||
{
|
||||
var data = await GetQuery().FirstAsync(a => a.F_Id == keyValue);
|
||||
string[] temp;
|
||||
if (data.F_RoleId != null)
|
||||
{
|
||||
temp = data.F_RoleId.Split(',');
|
||||
data.F_RoleName = string.Join(",", repository.Db.Queryable<RoleEntity>().Where(a => temp.Contains(a.F_Id)).Select(a => a.F_FullName).ToList().ToArray());
|
||||
}
|
||||
if (data.F_OrganizeId != null)
|
||||
{
|
||||
temp = data.F_OrganizeId.Split(',');
|
||||
data.F_OrganizeName = string.Join(",", repository.Db.Queryable<OrganizeEntity>().Where(a => temp.Contains(a.F_Id)).Select(a => a.F_FullName).ToList().ToArray());
|
||||
data.F_IsLeaderInDepts = repository.Db.Queryable<OrganizeEntity>().Any(a => temp.Contains(a.F_Id) && a.F_ManagerId == data.F_Id);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<UserExtend> GetLookForm(string keyValue)
|
||||
{
|
||||
var data = await GetQuery().FirstAsync(a => a.F_Id == keyValue);
|
||||
string[] temp;
|
||||
if (data.F_RoleId != null)
|
||||
{
|
||||
temp = data.F_RoleId.Split(',');
|
||||
data.F_RoleName = string.Join(",", repository.Db.Queryable<RoleEntity>().Where(a => temp.Contains(a.F_Id)).Select(a => a.F_FullName).ToList().ToArray());
|
||||
}
|
||||
if (data.F_OrganizeId != null)
|
||||
{
|
||||
temp = data.F_OrganizeId.Split(',');
|
||||
data.F_OrganizeName = string.Join(",", repository.Db.Queryable<OrganizeEntity>().Where(a => temp.Contains(a.F_Id)).Select(a => a.F_FullName).ToList().ToArray());
|
||||
data.F_IsLeaderInDepts = repository.Db.Queryable<OrganizeEntity>().Any(a => temp.Contains(a.F_Id) && a.F_ManagerId == data.F_Id);
|
||||
}
|
||||
return GetFieldsFilterData(data);
|
||||
}
|
||||
|
||||
public async Task DeleteForm(string keyValue)
|
||||
{
|
||||
repository.Db.Ado.BeginTran();
|
||||
await repository.Delete(a => a.F_Id == keyValue);
|
||||
await repository.Db.Deleteable<UserLogOnEntity>(a => a.F_UserId == keyValue).ExecuteCommandAsync();
|
||||
repository.Db.Ado.CommitTran();
|
||||
}
|
||||
|
||||
public async Task SubmitForm(UserEntity userEntity, UserLogOnEntity userLogOnEntity, string keyValue)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
//自己不能作为自己的直属上级
|
||||
if (keyValue == userEntity.F_ManagerId)
|
||||
{
|
||||
userEntity.F_ManagerId = null;
|
||||
}
|
||||
if (userEntity.F_ManagerId.Contains(","))
|
||||
{
|
||||
throw new Exception("只能选择一个直属上级");
|
||||
}
|
||||
userEntity.Modify(keyValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
userEntity.Create();
|
||||
userLogOnEntity.F_Id = Utils.GuId();
|
||||
userLogOnEntity.F_UserId = userEntity.F_Id;
|
||||
userLogOnEntity.F_ErrorNum = 0;
|
||||
userLogOnEntity.F_UserOnLine = false;
|
||||
userLogOnEntity.F_LogOnCount = 0;
|
||||
}
|
||||
repository.Db.Ado.BeginTran();
|
||||
if (!string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
await repository.Update(userEntity);
|
||||
}
|
||||
else
|
||||
{
|
||||
userLogOnEntity.F_Id = userEntity.F_Id;
|
||||
userLogOnEntity.F_UserId = userEntity.F_Id;
|
||||
userLogOnEntity.F_UserSecretkey = Md5.md5(Utils.CreateNo(), 16).ToLower();
|
||||
userLogOnEntity.F_UserPassword = Md5.md5(DESEncrypt.Encrypt(Md5.md5(userLogOnEntity.F_UserPassword, 32).ToLower(), userLogOnEntity.F_UserSecretkey).ToLower(), 32).ToLower();
|
||||
await repository.Insert(userEntity);
|
||||
await repository.Db.Insertable(userLogOnEntity).ExecuteCommandAsync();
|
||||
}
|
||||
repository.Db.Ado.CommitTran();
|
||||
}
|
||||
|
||||
public async Task UpdateForm(UserEntity userEntity)
|
||||
{
|
||||
await repository.Update(userEntity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 登录判断
|
||||
/// </summary>
|
||||
/// <param name="username"></param>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<UserEntity> CheckLogin(string username, string password, string localurl)
|
||||
{
|
||||
//根据登录公司查找公司
|
||||
if (GlobalContext.SystemConfig.SqlMode == Define.SQL_TENANT)
|
||||
{
|
||||
repository.ChangeEntityDb(GlobalContext.SystemConfig.MainDbNumber);
|
||||
var setTemp = (await syssetApp.GetList()).Where(a => localurl.Contains(a.F_HostUrl)).FirstOrDefault();
|
||||
if (setTemp != null)
|
||||
{
|
||||
if (setTemp.F_EndTime < DateTime.Now.Date)
|
||||
{
|
||||
throw new Exception("租户已到期,请联系供应商");
|
||||
}
|
||||
if (!_context.AsTenant().IsAnyConnection(setTemp.F_DbNumber))
|
||||
{
|
||||
var dblist = DBInitialize.GetConnectionConfigs(true);
|
||||
_context.AsTenant().AddConnection(dblist.FirstOrDefault(a => a.ConfigId.ToString() == setTemp.F_DbNumber));
|
||||
repository.ChangeEntityDb(setTemp.F_DbNumber);
|
||||
repository.Db.DefaultConfig();
|
||||
}
|
||||
else
|
||||
{
|
||||
repository.ChangeEntityDb(setTemp.F_DbNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!(await CheckIP()))
|
||||
{
|
||||
throw new Exception("IP受限");
|
||||
}
|
||||
UserEntity userEntity = await repository.IQueryable().SingleAsync(a => a.F_Account == username);
|
||||
if (userEntity != null)
|
||||
{
|
||||
if (userEntity.F_EnabledMark == true)
|
||||
{
|
||||
//缓存用户账户信息
|
||||
var userLogOnEntity = await CacheHelper.GetAsync<OperatorUserInfo>(cacheKeyOperator + "info_" + userEntity.F_Id);
|
||||
if (userLogOnEntity == null)
|
||||
{
|
||||
userLogOnEntity = new OperatorUserInfo();
|
||||
UserLogOnEntity entity = await repository.Db.Queryable<UserLogOnEntity>().InSingleAsync(userEntity.F_Id);
|
||||
userLogOnEntity.F_UserPassword = entity.F_UserPassword;
|
||||
userLogOnEntity.F_UserSecretkey = entity.F_UserSecretkey;
|
||||
userLogOnEntity.F_AllowEndTime = entity.F_AllowEndTime;
|
||||
userLogOnEntity.F_AllowStartTime = entity.F_AllowStartTime;
|
||||
userLogOnEntity.F_AnswerQuestion = entity.F_AnswerQuestion;
|
||||
userLogOnEntity.F_ChangePasswordDate = entity.F_ChangePasswordDate;
|
||||
userLogOnEntity.F_FirstVisitTime = entity.F_FirstVisitTime;
|
||||
userLogOnEntity.F_LastVisitTime = entity.F_LastVisitTime;
|
||||
userLogOnEntity.F_LockEndDate = entity.F_LockEndDate;
|
||||
userLogOnEntity.F_LockStartDate = entity.F_LockStartDate;
|
||||
userLogOnEntity.F_LogOnCount = entity.F_LogOnCount;
|
||||
userLogOnEntity.F_PreviousVisitTime = entity.F_PreviousVisitTime;
|
||||
userLogOnEntity.F_Question = entity.F_Question;
|
||||
userLogOnEntity.F_Theme = entity.F_Theme;
|
||||
await CacheHelper.SetAsync(cacheKeyOperator + "info_" + userEntity.F_Id, userLogOnEntity);
|
||||
}
|
||||
if (userLogOnEntity == null)
|
||||
{
|
||||
throw new Exception("账户未初始化设置密码,请联系管理员");
|
||||
}
|
||||
string dbPassword = Md5.md5(DESEncrypt.Encrypt(password.ToLower(), userLogOnEntity.F_UserSecretkey).ToLower(), 32).ToLower();
|
||||
if (dbPassword == userLogOnEntity.F_UserPassword)
|
||||
{
|
||||
if (userEntity.F_IsAdmin != true)
|
||||
{
|
||||
var list = userEntity.F_RoleId.Split(',');
|
||||
var rolelist = repository.Db.Queryable<RoleEntity>().Where(a => list.Contains(a.F_Id) && a.F_EnabledMark == true).ToList();
|
||||
if (!rolelist.Any())
|
||||
{
|
||||
throw new Exception("账户未设置权限,请联系管理员");
|
||||
}
|
||||
}
|
||||
DateTime lastVisitTime = DateTime.Now;
|
||||
int LogOnCount = (userLogOnEntity.F_LogOnCount).ToInt() + 1;
|
||||
if (userLogOnEntity.F_LastVisitTime != null)
|
||||
{
|
||||
userLogOnEntity.F_PreviousVisitTime = userLogOnEntity.F_LastVisitTime.ToDate();
|
||||
}
|
||||
userLogOnEntity.F_LastVisitTime = lastVisitTime;
|
||||
userLogOnEntity.F_LogOnCount = LogOnCount;
|
||||
userLogOnEntity.F_UserOnLine = true;
|
||||
await CacheHelper.RemoveAsync(cacheKeyOperator + "info_" + userEntity.F_Id);
|
||||
await CacheHelper.SetAsync(cacheKeyOperator + "info_" + userEntity.F_Id, userLogOnEntity);
|
||||
await OperatorProvider.Provider.ClearCurrentErrorNum();
|
||||
return userEntity;
|
||||
}
|
||||
else
|
||||
{
|
||||
//登录错误不超过指定次数
|
||||
int num = await OperatorProvider.Provider.AddCurrentErrorNum();
|
||||
int errorcount = GlobalContext.SystemConfig.LoginErrorCount ?? 4;
|
||||
string erornum = (errorcount - num).ToString();
|
||||
if (num == errorcount)
|
||||
{
|
||||
FilterIPEntity ipentity = new FilterIPEntity();
|
||||
ipentity.F_Id = Utils.GuId();
|
||||
ipentity.F_StartIP = WebHelper.Ip;
|
||||
ipentity.F_CreatorTime = DateTime.Now;
|
||||
ipentity.F_DeleteMark = false;
|
||||
ipentity.F_EnabledMark = true;
|
||||
ipentity.F_Type = false;
|
||||
//默认封禁12小时
|
||||
ipentity.F_EndTime = DateTime.Now.AddHours(12);
|
||||
await ipApp.SubmitForm(ipentity, null);
|
||||
await OperatorProvider.Provider.ClearCurrentErrorNum();
|
||||
throw new Exception("密码不正确,IP被锁定");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("密码不正确,请重新输入,还有" + erornum + "次机会");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("账户被系统锁定,请联系管理员");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("账户不存在,请重新输入");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<bool> CheckIP()
|
||||
{
|
||||
string ip = WebHelper.Ip;
|
||||
return await ipApp.CheckIP(ip);
|
||||
}
|
||||
}
|
||||
}
|
||||
125
WaterCloud.Service/SystemSecurity/FilterIPService.cs
Normal file
125
WaterCloud.Service/SystemSecurity/FilterIPService.cs
Normal file
@@ -0,0 +1,125 @@
|
||||
/*******************************************************************************
|
||||
* Copyright © 2020 WaterCloud.Framework 版权所有
|
||||
* Author: WaterCloud
|
||||
* Description: WaterCloud快速开发平台
|
||||
* Website:
|
||||
*********************************************************************************/
|
||||
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Domain.SystemSecurity;
|
||||
|
||||
namespace WaterCloud.Service.SystemSecurity
|
||||
{
|
||||
public class FilterIPService : BaseService<FilterIPEntity>, IDenpendency
|
||||
{
|
||||
public FilterIPService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<List<FilterIPEntity>> GetList(string keyword)
|
||||
{
|
||||
var list = repository.IQueryable();
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
list = list.Where(a => a.F_StartIP.Contains(keyword) || a.F_EndIP.Contains(keyword));
|
||||
}
|
||||
return await list.Where(a => a.F_DeleteMark == false).OrderBy(a => a.F_Id).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<FilterIPEntity>> GetLookList(string keyword)
|
||||
{
|
||||
var query = repository.IQueryable().Where(a => a.F_DeleteMark == false);
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
//此处需修改
|
||||
query = query.Where(a => a.F_StartIP.Contains(keyword) || a.F_EndIP.Contains(keyword));
|
||||
}
|
||||
query = GetDataPrivilege("a", "", query);
|
||||
return await query.OrderBy(a => a.F_Id).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<FilterIPEntity> GetLookForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return GetFieldsFilterData(data);
|
||||
}
|
||||
|
||||
public async Task<FilterIPEntity> GetForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task DeleteForm(string keyValue)
|
||||
{
|
||||
var ids = keyValue.Split(",");
|
||||
await repository.Delete(a => ids.Contains(a.F_Id));
|
||||
}
|
||||
|
||||
public async Task<bool> CheckIP(string ip)
|
||||
{
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
var list = repository.IQueryable().Where(a => a.F_EnabledMark == true && a.F_DeleteMark == false && a.F_Type == false && a.F_EndTime > DateTime.Now).ToList();
|
||||
long ipAddress = IP2Long(ip);
|
||||
foreach (var item in list)
|
||||
{
|
||||
if (string.IsNullOrEmpty(item.F_EndIP))
|
||||
{
|
||||
long start = IP2Long(item.F_StartIP);
|
||||
bool inRange = ipAddress == start;
|
||||
if (inRange)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
long start = IP2Long(item.F_StartIP);
|
||||
long end = IP2Long(item.F_EndIP);
|
||||
bool inRange = (ipAddress >= start && ipAddress <= end);
|
||||
if (inRange)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public static long IP2Long(string ip)
|
||||
{
|
||||
string[] ipBytes;
|
||||
double num = 0;
|
||||
if (!string.IsNullOrEmpty(ip))
|
||||
{
|
||||
ipBytes = ip.Split('.');
|
||||
for (int i = ipBytes.Length - 1; i >= 0; i--)
|
||||
{
|
||||
num += ((int.Parse(ipBytes[i]) % 256) * Math.Pow(256, (3 - i)));
|
||||
}
|
||||
}
|
||||
return (long)num;
|
||||
}
|
||||
|
||||
public async Task SubmitForm(FilterIPEntity filterIPEntity, string keyValue)
|
||||
{
|
||||
filterIPEntity.F_Type = false;
|
||||
if (!string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
filterIPEntity.Modify(keyValue);
|
||||
await repository.Update(filterIPEntity);
|
||||
}
|
||||
else
|
||||
{
|
||||
filterIPEntity.Create();
|
||||
await repository.Insert(filterIPEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
245
WaterCloud.Service/SystemSecurity/LogService.cs
Normal file
245
WaterCloud.Service/SystemSecurity/LogService.cs
Normal file
@@ -0,0 +1,245 @@
|
||||
/*******************************************************************************
|
||||
* Copyright © 2020 WaterCloud.Framework 版权所有
|
||||
* Author: WaterCloud
|
||||
* Description: WaterCloud快速开发平台
|
||||
* Website:
|
||||
*********************************************************************************/
|
||||
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.DataBase;
|
||||
using WaterCloud.Domain.SystemManage;
|
||||
using WaterCloud.Domain.SystemOrganize;
|
||||
using WaterCloud.Domain.SystemSecurity;
|
||||
using WaterCloud.Service.SystemManage;
|
||||
|
||||
namespace WaterCloud.Service.SystemSecurity
|
||||
{
|
||||
public class LogService : BaseService<LogEntity>, IDenpendency
|
||||
{
|
||||
public ModuleService moduleservice { get; set; }
|
||||
//获取类名
|
||||
|
||||
public LogService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<List<LogEntity>> GetList(Pagination pagination, int timetype, string keyword = "")
|
||||
{
|
||||
//获取数据权限
|
||||
var result = new List<LogEntity>();
|
||||
DateTime startTime = DateTime.Now.ToString("yyyy-MM-dd").ToDate();
|
||||
DateTime endTime = DateTime.Now.ToString("yyyy-MM-dd").ToDate().AddDays(1);
|
||||
switch (timetype)
|
||||
{
|
||||
case 1:
|
||||
break;
|
||||
|
||||
case 2:
|
||||
startTime = startTime.AddDays(-7);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
startTime = startTime.AddMonths(-1);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
startTime = startTime.AddMonths(-3);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
var query = repository.IQueryable();
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_Account.Contains(keyword) || a.F_Description.Contains(keyword) || a.F_ModuleName.Contains(keyword));
|
||||
}
|
||||
|
||||
query = query.Where(a => a.F_Date >= startTime && a.F_Date <= endTime);
|
||||
|
||||
return GetFieldsFilterData(await query.ToPageListAsync(pagination));
|
||||
}
|
||||
|
||||
public async Task<List<LogEntity>> GetList()
|
||||
{
|
||||
return await repository.IQueryable().ToListAsync();
|
||||
}
|
||||
|
||||
public async Task RemoveLog(string keepTime)
|
||||
{
|
||||
DateTime operateTime = DateTime.Now;
|
||||
if (keepTime == "7") //保留近一周
|
||||
{
|
||||
operateTime = DateTime.Now.AddDays(-7);
|
||||
}
|
||||
else if (keepTime == "1") //保留近一个月
|
||||
{
|
||||
operateTime = DateTime.Now.AddMonths(-1);
|
||||
}
|
||||
else if (keepTime == "3") //保留近三个月
|
||||
{
|
||||
operateTime = DateTime.Now.AddMonths(-3);
|
||||
}
|
||||
var expression = ExtLinq.True<LogEntity>();
|
||||
expression = expression.AndAlso(a => a.F_Date <= operateTime);
|
||||
await repository.Delete(expression);
|
||||
}
|
||||
|
||||
public async Task WriteDbLog(LogEntity logEntity, OperatorModel user = null)
|
||||
{
|
||||
logEntity.F_Id = Utils.GuId();
|
||||
logEntity.F_Date = DateTime.Now;
|
||||
currentuser = OperatorProvider.Provider.GetCurrent();
|
||||
if (user == null || string.IsNullOrEmpty(user.UserId))
|
||||
{
|
||||
user = currentuser;
|
||||
}
|
||||
var dbNumber = GlobalContext.SystemConfig.MainDbNumber;
|
||||
if (user != null)
|
||||
{
|
||||
dbNumber = user.DbNumber;
|
||||
}
|
||||
repository.ChangeEntityDb(GlobalContext.SystemConfig.MainDbNumber);
|
||||
var systemSet = await repository.Db.Queryable<SystemSetEntity>().Where(a => a.F_DbNumber == GlobalContext.SystemConfig.MainDbNumber).FirstAsync();
|
||||
repository.ChangeEntityDb(dbNumber);
|
||||
try
|
||||
{
|
||||
if (user == null || string.IsNullOrEmpty(user.UserId))
|
||||
{
|
||||
logEntity.F_IPAddress = WebHelper.Ip;
|
||||
if (GlobalContext.SystemConfig.LocalLAN != false)
|
||||
{
|
||||
logEntity.F_IPAddressName = "本地局域网";
|
||||
}
|
||||
else
|
||||
{
|
||||
logEntity.F_IPAddressName = WebHelper.GetIpLocation(logEntity.F_IPAddress);
|
||||
}
|
||||
logEntity.F_CompanyId = systemSet.F_Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
logEntity.F_IPAddress = user.LoginIPAddress;
|
||||
logEntity.F_IPAddressName = user.LoginIPAddressName;
|
||||
logEntity.F_CompanyId = user.CompanyId;
|
||||
}
|
||||
logEntity.Create();
|
||||
if (!string.IsNullOrEmpty(logEntity.F_KeyValue))
|
||||
{
|
||||
//批量删除时,循环拆分F_KeyValue,以免截断二进制错误
|
||||
//方便以后根据F_KeyValue查询;
|
||||
var keylist = logEntity.F_KeyValue.Split(",").ToList();
|
||||
var loglist = new List<LogEntity>();
|
||||
foreach (var key in keylist)
|
||||
{
|
||||
var log = new LogEntity();
|
||||
log = logEntity.ToJson().ToObject<LogEntity>();
|
||||
log.F_KeyValue = key;
|
||||
log.F_Id = Utils.GuId();
|
||||
loglist.Add(log);
|
||||
}
|
||||
await repository.Insert(loglist);
|
||||
}
|
||||
else
|
||||
{
|
||||
await repository.Insert(logEntity);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
logEntity.F_IPAddress = WebHelper.Ip;
|
||||
if (GlobalContext.SystemConfig.LocalLAN != false)
|
||||
{
|
||||
logEntity.F_IPAddressName = "本地局域网";
|
||||
}
|
||||
else
|
||||
{
|
||||
logEntity.F_IPAddressName = WebHelper.GetIpLocation(logEntity.F_IPAddress);
|
||||
}
|
||||
logEntity.F_CompanyId = systemSet.F_Id;
|
||||
logEntity.Create();
|
||||
await repository.Insert(logEntity);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<LogEntity> CreateLog(string className, DbLogType type)
|
||||
{
|
||||
try
|
||||
{
|
||||
var moduleitem = (await moduleservice.GetList()).Where(a => a.F_IsExpand == false && a.F_EnCode == className.Substring(0, className.Length - 10)).FirstOrDefault();
|
||||
if (moduleitem == null)
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
var module = (await moduleservice.GetList()).Where(a => a.F_Id == moduleitem.F_ParentId).First();
|
||||
return new LogEntity(await CreateModule(module), moduleitem == null ? "" : moduleitem.F_FullName, type.ToString());
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return new LogEntity(className, "", type.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<string> CreateModule(ModuleEntity module, string str = "")
|
||||
{
|
||||
if (module == null)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
str = module.F_FullName + "-" + str;
|
||||
if (module.F_ParentId == "0")
|
||||
{
|
||||
return str;
|
||||
}
|
||||
else
|
||||
{
|
||||
var temp = (await moduleservice.GetList()).Where(a => a.F_Id == module.F_ParentId).First();
|
||||
return await CreateModule(temp, str);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<LogEntity> CreateLog(string message, string className, string keyValue = "", DbLogType? logType = null, bool isError = false)
|
||||
{
|
||||
LogEntity logEntity;
|
||||
if (logType != null)
|
||||
{
|
||||
logEntity = await CreateLog(className, (DbLogType)logType);
|
||||
logEntity.F_Description += logType.ToDescription();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
logEntity = await CreateLog(className, DbLogType.Create);
|
||||
logEntity.F_Description += DbLogType.Create.ToDescription();
|
||||
}
|
||||
else
|
||||
{
|
||||
logEntity = await CreateLog(className, DbLogType.Update);
|
||||
logEntity.F_Description += DbLogType.Update.ToDescription();
|
||||
}
|
||||
}
|
||||
logEntity.F_KeyValue = keyValue;
|
||||
if (isError)
|
||||
{
|
||||
logEntity.F_Result = false;
|
||||
logEntity.F_Description += "操作失败," + message;
|
||||
}
|
||||
else
|
||||
{
|
||||
logEntity.F_Description += message;
|
||||
}
|
||||
if (currentuser != null && currentuser.UserId != null)
|
||||
{
|
||||
logEntity.F_Account = currentuser.UserCode;
|
||||
logEntity.F_NickName = currentuser.UserName;
|
||||
}
|
||||
return logEntity;
|
||||
}
|
||||
}
|
||||
}
|
||||
381
WaterCloud.Service/SystemSecurity/OpenJobsService.cs
Normal file
381
WaterCloud.Service/SystemSecurity/OpenJobsService.cs
Normal file
@@ -0,0 +1,381 @@
|
||||
/*******************************************************************************
|
||||
* Copyright © 2020 WaterCloud.Framework 版权所有
|
||||
* Author: WaterCloud
|
||||
* Description: WaterCloud快速开发平台
|
||||
* Website:
|
||||
*********************************************************************************/
|
||||
|
||||
using Quartz;
|
||||
using Quartz.Impl.Triggers;
|
||||
using Quartz.Spi;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.DataBase;
|
||||
using WaterCloud.Domain.SystemSecurity;
|
||||
using WaterCloud.Service.AutoJob;
|
||||
|
||||
namespace WaterCloud.Service.SystemSecurity
|
||||
{
|
||||
public class OpenJobsService : IDenpendency
|
||||
{
|
||||
private RepositoryBase<OpenJobEntity> repository;
|
||||
private IScheduler _scheduler;
|
||||
private HttpWebClient _httpClient;
|
||||
|
||||
public OpenJobsService(ISqlSugarClient context, ISchedulerFactory schedulerFactory, IJobFactory iocJobfactory, IHttpClientFactory httpClient)
|
||||
{
|
||||
repository = new RepositoryBase<OpenJobEntity>(context);
|
||||
_scheduler = schedulerFactory.GetScheduler().GetAwaiter().GetResult();
|
||||
_scheduler.JobFactory = iocJobfactory;
|
||||
_httpClient = new HttpWebClient(httpClient);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载列表
|
||||
/// </summary>
|
||||
public async Task<List<OpenJobEntity>> GetLookList(Pagination pagination, string keyword = "")
|
||||
{
|
||||
var DbNumber = OperatorProvider.Provider.GetCurrent().DbNumber;
|
||||
var query = repository.IQueryable().Where(a => a.F_DbNumber == DbNumber);
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_JobName.Contains(keyword) || a.F_Description.Contains(keyword));
|
||||
}
|
||||
query = query.Where(a => a.F_DeleteMark == false);
|
||||
return await query.ToPageListAsync(pagination);
|
||||
}
|
||||
|
||||
public async Task<List<OpenJobLogEntity>> GetLogList(string keyValue)
|
||||
{
|
||||
return await repository.Db.Queryable<OpenJobLogEntity>().Where(a => a.F_JobId == keyValue).OrderBy(a => a.F_CreatorTime, OrderByType.Desc).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<OpenJobEntity>> GetList(string keyword = "")
|
||||
{
|
||||
var DbNumber = OperatorProvider.Provider.GetCurrent().DbNumber;
|
||||
var query = repository.IQueryable().Where(a => a.F_DbNumber == DbNumber);
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_JobName.Contains(keyword));
|
||||
}
|
||||
return await query.Where(a => a.F_DeleteMark == false).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<OpenJobEntity>> GetAllList(string keyword = "")
|
||||
{
|
||||
var query = repository.IQueryable();
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
query = query.Where(a => a.F_JobName.Contains(keyword));
|
||||
}
|
||||
return await query.Where(a => a.F_DeleteMark == false).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<OpenJobEntity> GetForm(string keyValue)
|
||||
{
|
||||
var data = await repository.FindEntity(keyValue);
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task SubmitForm(OpenJobEntity entity, string keyValue)
|
||||
{
|
||||
bool IsTrue = CronExpression.IsValidExpression(entity.F_CronExpress);
|
||||
if (IsTrue == false)
|
||||
{
|
||||
throw new Exception("定时任务的Cron表达式不正确!");
|
||||
}
|
||||
repository.Db.Ado.BeginTran();
|
||||
if (!string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
entity.Modify(keyValue);
|
||||
await repository.Update(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.Create();
|
||||
entity.F_DbNumber = OperatorProvider.Provider.GetCurrent().DbNumber;
|
||||
await repository.Insert(entity);
|
||||
}
|
||||
//启动任务
|
||||
if (entity.F_DoItNow == true)
|
||||
{
|
||||
await ChangeJobStatus(entity.F_Id, 1);
|
||||
}
|
||||
repository.Db.Ado.CommitTran();
|
||||
//执行任务
|
||||
if (entity.F_DoItNow == true)
|
||||
{
|
||||
await DoNow(entity.F_Id, false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清除任务计划
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task ClearScheduleJob()
|
||||
{
|
||||
try
|
||||
{
|
||||
await _scheduler.Clear();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteWithTime(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteForm(string keyValue)
|
||||
{
|
||||
var job = await repository.FindEntity(keyValue);
|
||||
TriggerKey triggerKey = new TriggerKey(job.F_JobName, job.F_JobGroup);
|
||||
await _scheduler.PauseTrigger(triggerKey);
|
||||
await _scheduler.UnscheduleJob(triggerKey);
|
||||
await _scheduler.DeleteJob(new JobKey(job.F_JobName, job.F_JobGroup));
|
||||
await repository.Delete(a => a.F_Id == keyValue);
|
||||
}
|
||||
|
||||
#region 定时任务运行相关操作
|
||||
|
||||
/// <summary>
|
||||
/// 返回系统的job接口
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<KeyValue> QueryLocalHandlers()
|
||||
{
|
||||
var types = AppDomain.CurrentDomain.GetAssemblies()
|
||||
.SelectMany(a => a.GetTypes().Where(a => a.GetInterfaces()
|
||||
.Contains(typeof(IJobTask))))
|
||||
.ToArray();
|
||||
var list = new List<KeyValue>();
|
||||
foreach (var item in types)
|
||||
{
|
||||
list.Add(new KeyValue
|
||||
{
|
||||
Key = item.FullName,
|
||||
Description = item.GetCustomAttribute<ServiceDescriptionAttribute>(false)!.ClassDescription
|
||||
});
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public async Task ChangeJobStatus(string keyValue, int status)
|
||||
{
|
||||
var job = await repository.FindEntity(a => a.F_Id == keyValue);
|
||||
if (job == null)
|
||||
{
|
||||
throw new Exception("任务不存在");
|
||||
}
|
||||
if (status == 0) //停止
|
||||
{
|
||||
TriggerKey triggerKey = new TriggerKey(job.F_JobName, job.F_JobGroup);
|
||||
// 停止触发器
|
||||
await _scheduler.PauseTrigger(triggerKey);
|
||||
// 移除触发器
|
||||
await _scheduler.UnscheduleJob(triggerKey);
|
||||
// 删除任务
|
||||
await _scheduler.DeleteJob(new JobKey(job.F_JobName, job.F_JobGroup));
|
||||
job.F_EnabledMark = false;
|
||||
job.F_EndRunTime = DateTime.Now;
|
||||
}
|
||||
else //启动
|
||||
{
|
||||
DateTimeOffset starRunTime = DateBuilder.NextGivenSecondDate(job.F_StarRunTime, 1);
|
||||
DateTimeOffset endRunTime = DateBuilder.NextGivenSecondDate(DateTime.MaxValue.AddDays(-1), 1);
|
||||
|
||||
ITrigger trigger = TriggerBuilder.Create()
|
||||
.StartAt(starRunTime)
|
||||
.EndAt(endRunTime)
|
||||
.WithIdentity(job.F_JobName, job.F_JobGroup)
|
||||
.WithCronSchedule(job.F_CronExpress)
|
||||
.Build();
|
||||
((CronTriggerImpl)trigger).MisfireInstruction = MisfireInstruction.CronTrigger.DoNothing;
|
||||
// 判断数据库中有没有记录过,有的话,quartz会自动从数据库中提取信息创建 schedule
|
||||
if (!await _scheduler.CheckExists(new JobKey(job.F_JobName, job.F_JobGroup)))
|
||||
{
|
||||
IJobDetail jobdetail = JobBuilder.Create<JobExecute>().WithIdentity(job.F_JobName, job.F_JobGroup).Build();
|
||||
jobdetail.JobDataMap.Add("F_Id", job.F_Id);
|
||||
|
||||
await _scheduler.ScheduleJob(jobdetail, trigger);
|
||||
}
|
||||
|
||||
job.F_EnabledMark = true;
|
||||
job.F_StarRunTime = DateTime.Now;
|
||||
}
|
||||
job.Modify(job.F_Id);
|
||||
await repository.Update(job);
|
||||
}
|
||||
|
||||
public async Task DoNow(string keyValue, bool returnEx = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 获取数据库中的任务
|
||||
var dbJobEntity = await GetForm(keyValue);
|
||||
if (dbJobEntity != null)
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
|
||||
#region 执行任务
|
||||
|
||||
OpenJobLogEntity log = new OpenJobLogEntity();
|
||||
log.F_Id = Utils.GuId();
|
||||
log.F_JobId = keyValue;
|
||||
log.F_JobName = dbJobEntity.F_JobName;
|
||||
log.F_CreatorTime = now;
|
||||
AlwaysResult result = new AlwaysResult();
|
||||
if (dbJobEntity.F_JobType == 0)
|
||||
{
|
||||
//反射执行就行
|
||||
var path = AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory;
|
||||
//反射取指定前后缀的dll
|
||||
var referencedAssemblies = Directory.GetFiles(path, "WaterCloud.*.dll").Select(Assembly.LoadFrom).ToArray();
|
||||
var types = referencedAssemblies
|
||||
.SelectMany(a => a.GetTypes().Where(t => t.GetInterfaces()
|
||||
.Contains(typeof(IJobTask)))).ToArray();
|
||||
string filename = dbJobEntity.F_FileName;
|
||||
var implementType = types.Where(x => x.IsClass && x.FullName == filename).FirstOrDefault();
|
||||
var obj = System.Activator.CreateInstance(implementType, repository.Tenant); // 创建实例(带参数)
|
||||
MethodInfo method = implementType.GetMethod("Start", new Type[] { }); // 获取方法信息
|
||||
object[] parameters = null;
|
||||
result = ((Task<AlwaysResult>)method.Invoke(obj, parameters)).GetAwaiter().GetResult(); // 调用方法,参数为空
|
||||
if (result.state.ToString() == ResultType.success.ToString())
|
||||
{
|
||||
log.F_EnabledMark = true;
|
||||
log.F_Description = "执行成功," + result.message.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
log.F_EnabledMark = false;
|
||||
log.F_Description = "执行失败," + result.message.ToString();
|
||||
}
|
||||
}
|
||||
else if (dbJobEntity.F_JobType == 5)
|
||||
{
|
||||
try
|
||||
{
|
||||
repository.ChangeEntityDb(dbJobEntity.F_JobDBProvider).Ado.BeginTran();
|
||||
if (!string.IsNullOrEmpty(dbJobEntity.F_JobSqlParm))
|
||||
{
|
||||
var dic = dbJobEntity.F_JobSqlParm.ToObject<Dictionary<string, object>>();
|
||||
List<SugarParameter> list = new List<SugarParameter>();
|
||||
foreach (var item in dic)
|
||||
{
|
||||
list.Add(new SugarParameter(item.Key, item.Value));
|
||||
}
|
||||
var dbResult = await repository.Db.Ado.SqlQueryAsync<dynamic>(dbJobEntity.F_JobSql, list);
|
||||
log.F_EnabledMark = true;
|
||||
log.F_Description = "执行成功," + dbResult.ToJson();
|
||||
}
|
||||
else
|
||||
{
|
||||
var dbResult = await repository.Db.Ado.SqlQueryAsync<dynamic>(dbJobEntity.F_JobSql);
|
||||
log.F_EnabledMark = true;
|
||||
log.F_Description = "执行成功," + dbResult.ToJson();
|
||||
}
|
||||
repository.Db.Ado.CommitTran();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.F_EnabledMark = false;
|
||||
log.F_Description = "执行失败," + ex.Message;
|
||||
repository.Db.Ado.RollbackTran();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
HttpMethod method = HttpMethod.Get;
|
||||
switch (dbJobEntity.F_JobType)
|
||||
{
|
||||
case 1:
|
||||
method = HttpMethod.Get;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
method = HttpMethod.Post;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
method = HttpMethod.Put;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
method = HttpMethod.Delete;
|
||||
break;
|
||||
}
|
||||
var dic = dbJobEntity.F_RequestHeaders.ToObject<Dictionary<string, string>>();
|
||||
if (dic == null)
|
||||
{
|
||||
dic = new Dictionary<string, string>();
|
||||
}
|
||||
//请求头添加租户号
|
||||
dic.Add("dbNumber", dbJobEntity.F_DbNumber);
|
||||
try
|
||||
{
|
||||
var temp = await _httpClient.ExecuteAsync(dbJobEntity.F_RequestUrl, method, dbJobEntity.F_RequestString, dic);
|
||||
log.F_EnabledMark = true;
|
||||
log.F_Description = $"执行成功。{temp}";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.F_EnabledMark = false;
|
||||
log.F_Description = "执行失败," + ex.Message.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion 执行任务
|
||||
|
||||
repository.ChangeEntityDb(GlobalContext.SystemConfig.MainDbNumber);
|
||||
|
||||
repository.Db.Ado.BeginTran();
|
||||
//记录执行日志
|
||||
if (log.F_EnabledMark == true)
|
||||
{
|
||||
await repository.Update(a => a.F_Id == keyValue, a => new OpenJobEntity
|
||||
{
|
||||
F_LastRunMark = true,
|
||||
F_LastRunTime = now
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
await repository.Update(a => a.F_Id == keyValue, a => new OpenJobEntity
|
||||
{
|
||||
F_LastRunMark = false,
|
||||
F_LastRunTime = now,
|
||||
F_LastRunErrTime = now,
|
||||
F_LastRunErrMsg = log.F_Description
|
||||
});
|
||||
}
|
||||
if (dbJobEntity.F_IsLog == "是")
|
||||
{
|
||||
await repository.Db.Insertable(log).ExecuteCommandAsync();
|
||||
}
|
||||
repository.Db.Ado.CommitTran();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteWithTime(ex);
|
||||
if (returnEx)
|
||||
{
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteLogForm(string keyValue)
|
||||
{
|
||||
await repository.Db.Deleteable<OpenJobLogEntity>(a => a.F_JobId == keyValue).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
#endregion 定时任务运行相关操作
|
||||
}
|
||||
}
|
||||
76
WaterCloud.Service/SystemSecurity/ServerStateService.cs
Normal file
76
WaterCloud.Service/SystemSecurity/ServerStateService.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file=" ServerState.cs" company="JR">
|
||||
// * Copyright (C) WaterCloud.Framework All Rights Reserved
|
||||
// * version : 1.0
|
||||
// * author : WaterCloud.Framework
|
||||
// * FileName: ServerState.cs
|
||||
// * history : Created by T4 04/13/2020 11:54:48
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using WaterCloud.Code;
|
||||
using WaterCloud.Domain.SystemSecurity;
|
||||
|
||||
namespace WaterCloud.Service.SystemSecurity
|
||||
{
|
||||
public class ServerStateService : BaseService<ServerStateEntity>, IDenpendency
|
||||
{
|
||||
public ServerStateService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<List<ServerStateEntity>> GetList(int timetype)
|
||||
{
|
||||
var expression = ExtLinq.True<ServerStateEntity>();
|
||||
DateTime startTime = DateTime.Now.ToString("yyyy-MM-dd").ToDate();
|
||||
DateTime endTime = DateTime.Now.ToString("yyyy-MM-dd").ToDate().AddDays(1);
|
||||
switch (timetype)
|
||||
{
|
||||
case 1:
|
||||
break;
|
||||
|
||||
case 2:
|
||||
startTime = startTime.AddDays(-7);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
startTime = startTime.AddMonths(-1);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
startTime = startTime.AddMonths(-3);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
expression = expression.AndAlso(a => a.F_Date >= startTime && a.F_Date <= endTime);
|
||||
return await repository.IQueryable(expression).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task SubmitForm(ServerStateEntity entity)
|
||||
{
|
||||
var old = repository.IQueryable().First(a => a.F_WebSite == entity.F_WebSite && a.F_Date == DateTime.Now.Date);
|
||||
if (old != null)
|
||||
{
|
||||
entity.F_Id = old.F_Id;
|
||||
entity.F_Date = old.F_Date;
|
||||
entity.F_Cout = old.F_Cout + 1;
|
||||
entity.F_ARM = Math.Round(((old.F_ARM).ToDouble() * old.F_Cout + entity.F_ARM.ToDouble()) / entity.F_Cout, 2).ToString();
|
||||
entity.F_CPU = Math.Round(((old.F_CPU).ToDouble() * old.F_Cout + entity.F_CPU.ToDouble()) / entity.F_Cout, 2).ToString();
|
||||
entity.F_IIS = Math.Round(((old.F_IIS).ToDouble() * old.F_Cout + entity.F_IIS.ToDouble()) / entity.F_Cout, 0).ToString();
|
||||
await repository.Update(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.F_Id = Utils.GuId();
|
||||
entity.F_Cout = 1;
|
||||
entity.F_Date = DateTime.Now.Date;
|
||||
await repository.Insert(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
24
WaterCloud.Service/WaterCloud.Service.csproj
Normal file
24
WaterCloud.Service/WaterCloud.Service.csproj
Normal file
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<Optimize>false</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Autofac" Version="8.0.0" />
|
||||
<PackageReference Include="Jaina" Version="4.3.0" />
|
||||
<PackageReference Include="Quartz" Version="3.11.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WaterCloud.CodeGenerator\WaterCloud.CodeGenerator.csproj" />
|
||||
<ProjectReference Include="..\WaterCloud.Code\WaterCloud.Code.csproj" />
|
||||
<ProjectReference Include="..\WaterCloud.Data\WaterCloud.DataBase.csproj" />
|
||||
<ProjectReference Include="..\WaterCloud.Domain\WaterCloud.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
5
WaterCloud.Service/libman.json
Normal file
5
WaterCloud.Service/libman.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"version": "1.0",
|
||||
"defaultProvider": "cdnjs",
|
||||
"libraries": []
|
||||
}
|
||||
Reference in New Issue
Block a user