using Microsoft.VisualBasic;
using Model.ModelDto.LogDto;
using Model.ModelDto.SysDto;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using WMS.Entity.Context;
using WMS.Entity.LogEntity;
using WMS.Entity.SysEntity;
using WMS.IDAL.ILogInterface;
namespace WMS.DAL.LogInterface
{
///
/// 系统操作日志仓储实践
///
public class OperationSysRepository : BaseRepository, IOperationSysRepository
{
private static readonly SqlSugarScope Db = DataContext.Db;
public OperationSysRepository() : base(Db)
{
}
///
/// 获取系统操作日志数据列表
///
/// 菜单名称
/// 操作类型
/// 操作内容
/// 菜单号
/// 模块号
///
public List GetSysOperationList(string menuName, string type, string msg, string menuNo, string parentNo)
{
string str = "select logsys.*,user1.RealName CreateUserName,dic.DictName TypeName from LogOperationSys logsys left join SysUserInfor user1 on logsys.CreateUser = user1.Id left join SysFunctionMenu menu on logsys.ParentNo = menu.MenuNo left join SysDictionary dic on logsys.type = dic.Id where logsys.IsDel = @isdel and logsys.ParentNo = (select MenuNo from SysFunctionMenu where IsDel = @isdel and MenuName = @menuname)";
//判断菜单名称是否为空
if (!string.IsNullOrEmpty(menuName))
{
str += " and logsys.MenuName like @mname";
}
//判断操作类型是否为空
if (!string.IsNullOrEmpty(type))
{
str += " and logsys.Type = @type";
}
//判断操作内容是否为空
if (!string.IsNullOrEmpty(msg))
{
str += " and logsys.Msg like @msg";
}
//判断菜单号是否为空
if (!string.IsNullOrEmpty(menuNo))
{
str += " and logsys.MenuNo = @menuno";
}
str += " order by logsys.CreateTime desc";
List operationlist = Db.Ado.SqlQuery(str, new
{
isdel = "0", //是否删除
menuname = parentNo, //模块名称获取模块号
mname = "%" + menuName + "%", //菜单名称
type, //操作类型
msg = "%" + msg + "%", //操作内容
menuno = menuNo //菜单号
});
return operationlist;
}
///
/// 新增系统操作日志
///
/// 模块号
/// 菜单号
/// 菜单名称
/// 数据编号
/// 操作类型
/// 操作内容
/// 创建人
///
public async Task InsertOperation(string parentNo, string menuNo, string menuName, string fkNo, string type, string msg, int createUser)
{
type = Db.Ado.SqlQuerySingle("select * from SysDictionary where IsDel = @isdel and DictName = @dictname", new
{
isdel = "0", //是否删除
dictname = type == "修改" ? "编辑" : type //字典名称
}).Id.ToString();
string str = "insert into LogOperationSys values(@parentno, @menuno, @menuname, @fkno, @type, @msg, @isdel, @createtime, @createuser, null,null)";
int i = await Db.Ado.ExecuteCommandAsync(str, new
{
parentno = parentNo, //模块号
menuno = menuNo, //菜单号
menuname = menuName, //菜单名称
fkno = fkNo, //数据编号
type, //操作类型
msg, //操作内容
isdel = "0", //是否删除
createtime = Db.GetDate(), //创建时间
createuser = createUser //创建人
});
return i;
}
///
/// 根据菜单名称获取菜单号
///
///
///
public SysFunctionMenu GetMenuList(string menuName)
{
string str = "select MenuNo from SysFunctionMenu where MenuName = @menuname and IsDel = @isdel";
SysFunctionMenu menu = Db.Ado.SqlQuerySingle(str, new
{
menuname = menuName, //菜单名称
isdel = "0" //是否删除
});
return menu;
}
///
/// 获取类型菜单
///
/// 字典名称
///
public List GetDicTypeList(string dicName)
{
string str = "select * from SysDictionary where IsDel = @isdel and ParentNo = (select DictNo from SysDictionary where DictName = @dictname)";
List diclist = Db.Ado.SqlQuery(str, new
{
isdel = "0", //是否删除
dictname = dicName //字典名称
});
return diclist;
}
}
}