bklLiudl
2025-04-02 1bbbbc8bb49411b544626996a1370788142300e0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
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);
            }
        }
    }
}