using AutoMapper;
|
using Model.ModelDto.SysDto;
|
using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WMS.Entity.SysEntity;
|
using WMS.IBLL.ISysServer;
|
using WMS.IDAL.ISysInterface;
|
|
namespace WMS.BLL.SysServer
|
{
|
/// <summary>
|
/// 部门服务实践
|
/// </summary>
|
public class DepartmentServer : IDepartmentServer
|
{
|
/// <summary>
|
/// 依赖注入
|
/// </summary>
|
private readonly IDepartmentRepository _department;
|
readonly IMapper _mapper;
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
/// <param name="server">部门仓储接口</param>
|
/// <param name="mapper">automapper</param>
|
public DepartmentServer(IDepartmentRepository department, IMapper mapper)
|
{
|
_department = department;//部门
|
_mapper = mapper;//automapper
|
}
|
|
/// <summary>
|
/// 获取部门信息列表
|
/// </summary>
|
/// <param name="DepartmentName">部门名称</param>
|
/// <param name="DepartmentNo">部门号</param>
|
/// <returns></returns>
|
public List<DepartmentDto> GetDepartmentList(string DepartmentName, string DepartmentNo)
|
{
|
List<DepartmentDto> departmentlist = _department.GetDepartmentList(DepartmentName, DepartmentNo);
|
return departmentlist;
|
}
|
|
/// <summary>
|
/// 根据id获取部门信息
|
/// </summary>
|
/// <param name="id">部门id</param>
|
/// <returns></returns>
|
public SysDepartment GetDepartmentById(int id)
|
{
|
SysDepartment department = _department.GetDepartmentById(id);
|
return department;
|
}
|
|
/// <summary>
|
/// 根据部门号获取部门信息
|
/// </summary>
|
/// <returns></returns>
|
public int GetDepartmentByNo(string DepartmentNo)
|
{
|
List<SysDepartment> department = _department.GetDepartmentByNo(DepartmentNo);
|
return department.Count;
|
}
|
|
/// <summary>
|
/// 新增部门信息
|
/// </summary>
|
/// <param name="departmentdto">部门dto</param>
|
/// <returns></returns>
|
/// <exception cref="Exception">捕获异常</exception>
|
public async Task<int> AddDepartment(DepartmentDto departmentdto)
|
{
|
//捕获异常
|
try
|
{
|
//模型映射
|
SysDepartment department = _mapper.Map<SysDepartment>(departmentdto);
|
//判断部门号是否唯一
|
int count = GetDepartmentByNo(department.DepartmentNo);
|
int i = 0;
|
if (count > 0)
|
{
|
i = 3;
|
}
|
else if (count == 0)
|
{
|
i = await _department.AddDepartment(department);
|
}
|
return i;
|
|
}
|
catch (Exception ex)
|
{
|
//抛出异常
|
throw new Exception("新增部门异常", ex);
|
}
|
}
|
|
/// <summary>
|
/// 删除部门信息
|
/// </summary>
|
/// <param name="department">部门实体模型</param>
|
/// <returns></returns>
|
/// <exception cref="Exception">捕获异常</exception>
|
public async Task<int> DelDepartment(SysDepartment department)
|
{
|
//捕获异常
|
try
|
{
|
//删除
|
int i = await _department.DelDepartment(department);
|
return i;
|
}
|
catch (Exception ex)
|
{
|
//抛出异常
|
throw new Exception("删除部门异常", ex);
|
}
|
}
|
|
/// <summary>
|
/// 编辑部门信息
|
/// </summary>
|
/// <param name="departmentdto">部门dto</param>
|
/// <returns></returns>
|
/// <exception cref="Exception">捕获异常</exception>
|
public async Task<int> ExitDepartment(DepartmentDto departmentdto)
|
{
|
//捕获异常
|
try
|
{
|
//模型映射
|
SysDepartment department = _mapper.Map<SysDepartment>(departmentdto);
|
//编辑
|
int i = await _department.ExitDepartment(department);
|
return i;
|
}
|
catch (Exception ex)
|
{
|
//抛出异常
|
throw new Exception("编辑部门异常", ex);
|
}
|
}
|
}
|
}
|