200 lines
6.1 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Learun.Util;
using Learun.Util.SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Learun.Application.Organization
{
/// <summary>
/// 版 本 PIT-ADMS V7.0.3 敏捷开发框架
/// Copyright (c) 2013-2018 Hexagon PPM
/// 创建人:研发部
/// 日 期2017.04.17
/// 描 述:部门管理
/// </summary>
public class DepartmentService
{
#region
Repository<DepartmentEntity> _departmentRepository => new Repository<DepartmentEntity>();
#endregion
#region
private string fieldSql;
public DepartmentService()
{
fieldSql = @"
t.F_DepartmentId,
t.F_CompanyId,
t.F_ParentId,
t.F_EnCode,
t.F_FullName,
t.F_ShortName,
t.F_Nature,
t.F_Manager,
t.F_OuterPhone,
t.F_InnerPhone,
t.F_Email,
t.F_Fax,
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
/// <summary>
/// 获取部门列表信息(根据公司Id)
/// </summary>
/// <param name="companyId">公司主键</param>
/// <returns></returns>
public List<DepartmentEntity> 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<DepartmentEntity>(strSql.ToString(), new { companyId = companyId });
var res= _departmentRepository.GetList().Where(X => X.F_EnabledMark == 1 && X.F_DeleteMark == 0 && X.F_CompanyId == companyId).
OrderBy(x => x.F_ParentId).OrderBy(x => x.F_FullName);
return res.ToList();
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
/// <summary>
/// 获取部门列表信息
/// </summary>
/// <returns></returns>
public List<DepartmentEntity> GetAllList()
{
try
{
return _departmentRepository.GetList().Where(t => t.F_EnabledMark == 1 && t.F_DeleteMark == 0).ToList();
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
/// <summary>
/// 获取部门数据实体
/// </summary>
/// <param name="keyValue">主键</param>
/// <returns></returns>
public DepartmentEntity GetEntity(string keyValue)
{
try
{
return _departmentRepository.GetById(keyValue);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
#region
/// <summary>
/// 虚拟删除部门
/// </summary>
/// <param name="keyValue">主键</param>
public void VirtualDelete(string keyValue)
{
try
{
DepartmentEntity entity = new DepartmentEntity()
{
F_DepartmentId = keyValue,
F_DeleteMark = 1
};
_departmentRepository.Update(entity);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
/// <summary>
/// 保存部门表单(新增、修改)
/// </summary>
/// <param name="keyValue">主键值</param>
/// <param name="departmentEntity">部门实体</param>
/// <returns></returns>
public void SaveEntity(string keyValue, DepartmentEntity departmentEntity)
{
try
{
if (!string.IsNullOrEmpty(keyValue))
{
departmentEntity.Modify(keyValue);
if (keyValue == departmentEntity.F_ParentId)
{
departmentEntity.F_ParentId = "0";
}
_departmentRepository.Update(departmentEntity);
}
else
{
departmentEntity.Create();
_departmentRepository.Insert(departmentEntity);
}
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
}
}