using Learun.DataBase.Repository;
using Learun.Util;
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace Learun.Application.Organization
{
///
/// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
/// Copyright (c) 2013-2018 北京泉江科技有限公司
/// 创建人:陈彬彬
/// 日 期:2017.04.17
/// 描 述:部门管理
///
public class DepartmentService : RepositoryFactory
{
#region 构造函数和属性
private string fieldSql;
public DepartmentService()
{
fieldSql = "*";
}
#endregion
#region 获取数据
///
/// 获取部门列表信息(根据公司Id)
///
/// 公司主键
///
public IEnumerable GetList(string companyId)
{
try
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(fieldSql);
strSql.Append(" FROM LR_Base_Department t WHERE t.F_EnabledMark = 1 AND t.F_DeleteMark = 0 AND F_CompanyId = @companyId ORDER BY t.F_ParentId,t.F_FullName ");
return this.BaseRepository().FindList(strSql.ToString(), new { companyId = companyId });
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 获取部门列表信息(根据公司Id)
///
///
public IEnumerable GetAllList()
{
try
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(fieldSql);
strSql.Append(" FROM LR_Base_Department t WHERE t.F_EnabledMark = 1 AND t.F_DeleteMark = 0 order by F_Order");
return this.BaseRepository().FindList(strSql.ToString());
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 获取部门数据实体
///
/// 主键
///
public DepartmentEntity GetEntity(string keyValue)
{
try
{
return this.BaseRepository().FindEntity(keyValue);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 获取部门名称列表
///
/// 部门idList
///
public string GetDepartmentList(string keyValue)
{
try
{
var idList = keyValue.Split(',').ToList();
var data=this.BaseRepository().FindList(a=>idList.Contains(a.F_DepartmentId));
var result =new StringBuilder();
foreach (var item in data)
{
result.Append(item.F_FullName+",");
}
return result.ToString().TrimEnd(',');
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 获取部门数据实体
///
/// 部门编号
///
public DepartmentEntity GetEntityByCode(string code)
{
try
{
return this.BaseRepository().FindEntity(x => x.F_EnCode == code);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
#region 提交数据
///
/// 虚拟删除部门
///
/// 主键
public void VirtualDelete(string keyValue)
{
try
{
DepartmentEntity entity = new DepartmentEntity()
{
F_DepartmentId = keyValue,
F_DeleteMark = 1
};
this.BaseRepository().Update(entity);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 保存部门表单(新增、修改)
///
/// 主键值
/// 部门实体
///
public void SaveEntity(string keyValue, DepartmentEntity departmentEntity)
{
try
{
if (!string.IsNullOrEmpty(keyValue))
{
departmentEntity.Modify(keyValue);
this.BaseRepository().Update(departmentEntity);
}
else
{
departmentEntity.Create();
this.BaseRepository().Insert(departmentEntity);
}
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
internal bool GetAny()
{
try
{
return this.BaseRepository().FindList().ToList().Count() > 0 ? true : false;
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
}
}