using System;
using System.Collections.Generic;
using System.Text;
using Ys.Core.Common;
using djy.Paas.Model;
using djy.Paas.IService;
using System.Threading.Tasks;
using System.Linq;
using FreeSql;
using System.Diagnostics;
using System.Threading;
using AutoMapper;
using DotNetCore.CAP;
using System.Text.Json;
using System.Linq.Expressions;
using System.Reflection;
namespace djy.Paas.Service
{
///
/// 服务基类
///
public class ServBase : DbContext, ICapSubscribe
{
///
/// 获取登录者账户详情信息
///
///
///
public djy.Model.User GetUserInfo(string UserId)
{
if (UserId.IsNull())
{
return null;
}
return DbBus.Get(DbList.djyolddb).Select().Where(w => w.GID == UserId.ToString()).ToOne();
}
///
/// 创建日志
///
/// 消息
/// 触发数据对象或分组
/// 触发数据
///
public static bool _LogsAdd(string Message, string ObjName, object DataJson = null)
{
return _LogsAdd(Message, ObjName, DataJson, null, null);
}
///
/// 创建日志
///
/// 消息
/// 触发数据对象或分组
/// 触发数据
/// 触发数据guid
/// 返回的数据
/// true 属性原型 false 小驼峰模式
///
public static bool _LogsAdd(string Message, string ObjName = null, object DataJson = null, string ObjGid = null, object ResultJson = null, bool JsonNotWebOption = true)
{
try
{
if (DataJson == null)
{ DataJson = ""; }
if (ResultJson == null) {
ResultJson = "";
}
var _datajson = "";
var _resulitjson = "";
if (JsonNotWebOption)
{
_datajson = DataJson.GetType() == typeof(string) ? DataJson.ToString() : JsonSerializer.Serialize(DataJson);
_resulitjson = ResultJson.GetType() == typeof(string) ? ResultJson.ToString() : JsonSerializer.Serialize(ResultJson);
}
else
{
var _option = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
_datajson = DataJson.GetType() == typeof(string) ? DataJson.ToString() : JsonSerializer.Serialize(DataJson, _option);
_resulitjson = ResultJson.GetType() == typeof(string) ? ResultJson.ToString() : JsonSerializer.Serialize(ResultJson, _option);
}
return _LogsAdd(new tb_sys_Logs
{
Message = Message,
ObjName = ObjName,
ObjGid = ObjGid,
DataJson = _datajson,
ResultJson = _resulitjson
});
}
catch { return false; }
}
///
/// 创建日志
///
///
///
public static bool _LogsAdd(tb_sys_Logs Logs)
{
return _LogsAdd(new List() { Logs });
}
///
/// 创建日志
///
///
///
public static bool _LogsAdd(List LogsList)
{
var count = 0;
try
{
LogsList.ForEach(x=> { x.Init();x.SysCode = "djypaas"; });
count = DbBus.Get(DbList.Logsdb).Insert(LogsList).ExecuteAffrows();
}
catch { }
return count > 0 ? true : false;
}
}
///
/// 服务基类
///
/// 表名
/// Dto 名称
public class ServBase:ServBase where T:class,new()
{
///
///设置 数据库连接池KeyName
///
/// 数据库连接池KeyName
public ServBase(string DbconnName)
{
DbKeyName = DbconnName;
}
///
/// 数据库链接池KeyName
///
public string DbKeyName { get; set; }
public virtual ReturnResult