using Learun.Application.Base.SystemModule;
using Learun.Util;
using Learun.Util.SqlSugar;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
using DbType = System.Data.DbType;
namespace Learun.Application.Report
{
///
/// 版 本 PIT-ADMS V7.0.3 敏捷开发框架
/// Copyright (c) 2013-2018 Hexagon PPM
/// 创 建:超级管理员
/// 日 期:2019-03-26 18:29
/// 描 述:报表菜单关联设置
///
public class RptRelationService
{
#region 仓储
Repository _relationRepository => new Repository();
Repository _moduleRepository => new Repository();
#endregion
private ModuleIBLL moduleIBLL = new ModuleBLL();
#region 获取数据
///
/// 获取页面显示列表数据
///
/// 查询参数
///
public IEnumerable GetPageList(Pagination pagination, string queryJson)
{
try
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(@"
t.F_Id,
t.F_EnCode,
t.F_FullName,
t.F_ParentId,
t.F_Icon,
t.F_SortCode,
t.F_RptFileId,
t.F_Description
");
strSql.Append(" FROM LR_RptRelation t ");
strSql.Append(" WHERE 1=1 ");
var queryParam = queryJson.ToJObject();
// 虚拟参数
//var dp = new DynamicParameters(new { });
var dp = new List();
if (!queryParam["F_FullName"].IsEmpty())
{
dp.Add(new SugarParameter("F_FullName", "%" + queryParam["F_FullName"].ToString() + "%", DbType.String));
strSql.Append(" AND t.F_FullName Like @F_FullName ");
}
if (!queryParam["F_ModifyUserName"].IsEmpty())
{
dp.Add(new SugarParameter("F_ModifyUserName", queryParam["F_ModifyUserName"].ToString(), DbType.String));
strSql.Append(" AND t.F_ModifyUserName = @F_ModifyUserName ");
}
//return this.BaseRepository().FindList(strSql.ToString(), dp, pagination);
return SqlSugarHelper.Db.SqlQueryable(strSql.ToString()).AddParameters(dp).ToPageList(pagination.page, pagination.rows);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 获取LR_RptRelation表实体数据
/// 主键
///
///
public LR_RPT_RelationEntity GetLR_RptRelationEntity(string keyValue)
{
try
{
return _relationRepository.GetById(keyValue);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
#region 提交数据
///
/// 删除实体数据
/// 主键
///
///
public void DeleteEntity(string keyValue)
{
try
{
//删除报表关系同时把菜单也删除
LR_RPT_RelationEntity relation = _relationRepository.GetById(keyValue);
string moduleCode = relation.F_EnCode;
var module = _moduleRepository.GetList(t => t.F_EnCode == moduleCode);
_moduleRepository.Delete(module);
_relationRepository.Delete(relation);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 保存实体数据(新增、修改)
/// 主键
///
///
public void SaveEntity(string keyValue, LR_RPT_RelationEntity entity)
{
try
{
if (!string.IsNullOrEmpty(keyValue))
{
entity.Modify(keyValue);
_relationRepository.Update(entity);
}
else
{
entity.Create();
ModuleEntity moduleEntity = new ModuleEntity();
moduleEntity.F_IsMenu = 1;
moduleEntity.F_EnabledMark = 1;
moduleEntity.F_EnCode = entity.F_EnCode;
moduleEntity.F_FullName = entity.F_FullName;
moduleEntity.F_ParentId = entity.F_ParentId;
moduleEntity.F_Icon = entity.F_Icon;
moduleEntity.F_Description = entity.F_Description;
moduleEntity.F_Target = "iframe";
moduleEntity.F_UrlAddress = "/LR_ReportModule/RptManage/Report?reportId=" + entity.F_RptUrl;
List moduleButtonList = new List();
List moduleColumnList = new List();
List moduleFormEntitys = new List();
moduleIBLL.SaveEntity(null, moduleEntity, moduleButtonList, moduleColumnList, moduleFormEntitys);
_relationRepository.Insert(entity);
}
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
}
}