using Learun.DataBase.Repository;
using Learun.Util;
using System;
using System.Collections.Generic;
using System.Text;
namespace Learun.Application.Base.SystemModule
{
///
/// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
/// Copyright (c) 2013-2018 北京泉江科技有限公司
/// 创建人:陈彬彬
/// 日 期:2017.03.08
/// 描 述:数据字典管理服务类
///
public class DataItemService : RepositoryFactory
{
#region 属性 构造函数
private string fieldSql;
private string detailFieldSql;
public DataItemService()
{
fieldSql = @"
t.F_ItemId,
t.F_ParentId,
t.F_ItemCode,
t.F_ItemCodeGB,
t.F_ItemName,
t.F_IsTree,
t.F_IsNav,
t.F_SortCode,
t.F_DeleteMark,
t.F_EnabledMark,
t.F_Description,
t.F_CreateDate,
t.F_CreateUserId,
t.F_CreateUserName,
t.F_ModifyDate,
t.F_ModifyUserId,
t.F_ModifyUserName
";
detailFieldSql = @"
t.F_ItemDetailId,
t.F_ItemId,
t.F_ParentId,
t.F_ItemCode,
t.F_ItemCodeGB,
t.F_ItemName,
t.F_ItemValue,
t.F_QuickQuery,
t.F_SimpleSpelling,
t.F_IsDefault,
t.F_SortCode,
t.F_DeleteMark,
t.F_EnabledMark,
t.F_Description,
t.F_CreateDate,
t.F_CreateUserId,
t.F_CreateUserName,
t.F_ModifyDate,
t.F_ModifyUserId,
t.F_ModifyUserName
";
}
#endregion
#region 数据字典分类管理
///
/// 分类列表
///
///
public IEnumerable GetClassifyList()
{
try
{
StringBuilder strSql = new StringBuilder();
strSql.Append("SELECT " + fieldSql + " FROM LR_Base_DataItem t WHERE t.F_DeleteMark = 0 and t.F_EnabledMark=1 Order By t.F_ParentId,t.F_SortCode ");
return this.BaseRepository().FindList(strSql.ToString());
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 虚拟删除分类数据
///
/// 主键
public void VirtualDeleteClassify(string keyValue)
{
try
{
DataItemEntity entity = new DataItemEntity()
{
F_ItemId = keyValue,
F_DeleteMark = 1
};
this.BaseRepository().Update(entity);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 保存分类数据实体
///
/// 主键
/// 实体
public void SaveClassifyEntity(string keyValue, DataItemEntity entity) {
try
{
if (string.IsNullOrEmpty(keyValue))
{
entity.Create();
this.BaseRepository().Insert(entity);
}
else {
entity.Modify(keyValue);
this.BaseRepository().Update(entity);
}
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
#region 数据字典明细
///
/// 获取数据字典明细
///
///
public IEnumerable GetAllDetailList()
{
try
{
StringBuilder strSql = new StringBuilder();
strSql.Append("SELECT " + @"t.F_ItemId,
t.F_ParentId,
t2.F_ItemCode,
t.F_ItemName,
t.F_ItemValue " + @" FROM LR_Base_DataItemDetail t
INNER JOIN LR_Base_DataItem t2 ON t.F_ItemId = t2.F_ItemId
WHERE t.F_DeleteMark = 0 and t.F_EnabledMark=1 Order By t.F_SortCode
");
return this.BaseRepository().FindList(strSql.ToString());
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 获取数据字典明显根据分类编号
///
/// 分类编号
///
public IEnumerable GetDetailList(string itemCode)
{
try
{
StringBuilder strSql = new StringBuilder();
strSql.Append("SELECT " + detailFieldSql + @" FROM LR_Base_DataItemDetail t
INNER JOIN LR_Base_DataItem t2 ON t.F_ItemId = t2.F_ItemId
WHERE t2.F_ItemCode = @itemCode AND t.F_DeleteMark = 0 and t.F_EnabledMark=1 Order By t.F_SortCode
");
return this.BaseRepository().FindList(strSql.ToString(), new { itemCode = itemCode });
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 获取数据字典明细实体类
///
/// 主键
///
public DataItemDetailEntity GetDetailEntity(string keyValue) {
try
{
return this.BaseRepository().FindEntity(keyValue);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 虚拟删除明细数据
///
/// 主键
public void VirtualDeleteDetail(string keyValue)
{
try
{
DataItemDetailEntity entity = new DataItemDetailEntity()
{
F_ItemDetailId = keyValue,
F_DeleteMark = 1
};
this.BaseRepository().Update(entity);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 保存明细数据实体
///
/// 主键
/// 实体
public void SaveDetailEntity(string keyValue, DataItemDetailEntity entity)
{
try
{
if (string.IsNullOrEmpty(keyValue))
{
entity.Create();
this.BaseRepository().Insert(entity);
}
else
{
entity.Modify(keyValue);
this.BaseRepository().Update(entity);
}
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
}
}