using AutoMapper;
|
using Model.ModelDto.SysDto;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Security.Cryptography;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WMS.Entity.SysEntity;
|
using WMS.IBLL.ISysServer;
|
using WMS.IDAL.ISysInterface;
|
|
namespace WMS.BLL.SysServer
|
{
|
public class DictionaryServer : IDictionaryServer
|
{
|
public IDictionaryRepository _dic { get; set; }
|
private readonly IMapper _mapper;
|
public DictionaryServer(IDictionaryRepository dic, IMapper mapper)
|
{
|
_dic = dic;
|
_mapper = mapper;
|
}
|
|
/// <summary>
|
/// 获取字典表数据(根据父级字典号)
|
/// </summary>
|
/// <param name="parentNo">父级字典号</param>
|
/// <returns></returns>
|
public List<SysDictionary> GetDictionaryByParentNo(string parentNo)
|
{
|
try
|
{
|
var data = _dic.GetAllWhereAsync(m => m.ParentNo == parentNo && m.Level == "1").OrderBy(m => m.Ord).ToList();
|
return data;
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// 获取字典信息列表
|
/// </summary>
|
/// <param name="DictName">字典名称</param>
|
/// <param name="DictNo">父级字典号</param>
|
/// <param name="Level">层级</param>
|
/// <param name="IsEdit">允许编辑</param>
|
/// <param name="IsAdd">允许新增</param>
|
/// <returns></returns>
|
public List<DictionaryDto> GetDicList(string DictName,string DictNo, string Level, string IsEdit, string IsAdd)
|
{
|
List<DictionaryDto> diclist = _dic.GetDicList(DictName,DictNo, Level, IsEdit, IsAdd);
|
return diclist;
|
}
|
|
/// <summary>
|
/// 获取父级字典号(根据层级根目录)
|
/// </summary>
|
/// <returns></returns>
|
public List<SysDictionary> GetDicParentListByLevel()
|
{
|
List<SysDictionary> diclist = _dic.GetDicParentListByLevel();
|
return diclist;
|
}
|
|
/// <summary>
|
/// 根据id查询字典信息
|
/// </summary>
|
/// <param name="id">字典id</param>
|
/// <returns></returns>
|
public SysDictionary GetDicById(int id)
|
{
|
SysDictionary dic = _dic.GetDicById(id);
|
return dic;
|
}
|
|
/// <summary>
|
/// 根据编号查询字典信息
|
/// </summary>
|
/// <param name="DictNo">字典编号</param>
|
/// <returns></returns>
|
public int GetDicByNo(string DictNo)
|
{
|
List<SysDictionary> diclist = _dic.GetDicByNo(DictNo);
|
return diclist.Count;
|
}
|
|
/// <summary>
|
/// 新增字典信息
|
/// </summary>
|
/// <param name="dicdto">数据字典Dto</param>
|
/// <returns></returns>
|
/// <exception cref="Exception">捕获异常</exception>
|
public async Task<int> AddDic(DictionaryDto dicdto)
|
{
|
//捕获异常
|
try
|
{
|
//映射模型
|
SysDictionary dic = _mapper.Map<SysDictionary>(dicdto);
|
//获取是否拥有相同字典编码
|
int count = GetDicByNo(dic.DictNo);
|
int i = 0;
|
if (count > 0)
|
{
|
i = 3;
|
}
|
else if (count == 0)
|
{
|
//如层级为子级时验证父级是否为空
|
if (dic.Level == "1")
|
{
|
if (string.IsNullOrEmpty(dic.ParentNo))
|
{
|
throw new Exception("当层级为子级时,父级目录不可为空!");
|
}
|
}
|
//新增
|
i = await _dic.AddDic(dic);
|
}
|
return i;
|
}
|
catch (Exception ex)
|
{
|
//抛出异常
|
throw new Exception("新增字典异常", ex);
|
}
|
}
|
|
/// <summary>
|
/// 删除字典信息
|
/// </summary>
|
/// <param name="dic">字典实体模型</param>
|
/// <returns></returns>
|
/// <exception cref="Exception">捕获异常</exception>
|
public async Task<int> DelDic(SysDictionary dic)
|
{
|
//捕获异常
|
try
|
{
|
//删除
|
int i = await _dic.DelDic(dic);
|
return i;
|
}
|
catch (Exception ex)
|
{
|
//抛出异常
|
throw new Exception("删除字典异常", ex);
|
}
|
}
|
|
/// <summary>
|
/// 编辑字典信息
|
/// </summary>
|
/// <param name="dicdto">数据字典Dto</param>
|
/// <returns></returns>
|
/// <exception cref="Exception">捕获异常</exception>
|
public async Task<int> ExitDic(DictionaryDto dicdto)
|
{
|
//捕获异常
|
try
|
{
|
//映射模型
|
SysDictionary dic = _mapper.Map<SysDictionary>(dicdto);
|
//编辑
|
int i = await _dic.ExitDic(dic);
|
return i;
|
}
|
catch (Exception ex)
|
{
|
//抛出异常
|
throw new Exception("编辑字典异常", ex);
|
}
|
}
|
}
|
}
|