username@email.com
2024-07-08 c6c6761506785691ef44e7e232c45e1b4b16f7fa
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
using AutoMapper;
using DTO;
using DTO.Models;
using IServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using zhengcaioa.IService;
using zhengcaioa.Models;
 
namespace Services
{
    public class PltPageService : IPltPageService
    {
        private readonly zhengcaioaContext _context;
        private readonly IMapper _mapper;
        public PltPageService(zhengcaioaContext context, IMapper mapper)
        {
            _context = context;
            _mapper = mapper;
        }
 
 
        public ResultEntity save(PltPageDTO pltPageDTO)
        {
            ResultEntity resultEntity = new ResultEntity();
            try
            {
                var pltPage = _mapper.Map<PltPage>(pltPageDTO);
                if (String.IsNullOrEmpty(pltPage.Id))
                {
                    pltPage.Id = Guid.NewGuid().ToString();
                    _context.PltPages.Add(pltPage);
                }
                else
                {
                    var updatepltPage = _context.PltPages.Find(pltPage.Id);
                    updatepltPage.SystemId = pltPage.SystemId;
                    updatepltPage.PageName = pltPage.PageName;
                    updatepltPage.PageShortcut = pltPage.PageShortcut;
                    updatepltPage.DisplaySeq = pltPage.DisplaySeq;
                    updatepltPage.PagePath = pltPage.PagePath;
                    updatepltPage.PageMethod = pltPage.PageMethod;
                    updatepltPage.PageType = pltPage.PageType;
                    updatepltPage.PageSuperior = pltPage.PageSuperior ;
                    updatepltPage.PageIco = pltPage.PageIco;
                    updatepltPage.OpenType = pltPage.OpenType;
 
 
 
 
 
 
 
                    updatepltPage.RecStatus = pltPage.RecStatus;
                    // updatepltPage.Creater = pltPage.Creater;
                    //updatepltPage.Createtime = pltPage.Createtime;
                    updatepltPage.Modifier = pltPage.Modifier;
                    updatepltPage.Modifytime = pltPage.Modifytime;
 
                }
 
                _context.SaveChanges();
                resultEntity.ReturnID = pltPage.Id;
                resultEntity.Result = true;
            }
            catch (Exception ex)
            {
                resultEntity.Result = false;
                resultEntity.Message = "保存失败,请联系管理员";
 
            }
            return resultEntity;
        }
 
        public PltPageDTO Get(string id)
        {
            PltPage entity = _context.PltPages.Find(id);
 
            if (entity.RecStatus != "A")
            {
                entity = new PltPage();
            }
            var pltPageDTO = _mapper.Map<PltPageDTO>(entity);
            return pltPageDTO;
        }
 
        public ResultDataEntity<PltPageDTO> SearchByPaging(PltPageDTOSearch searchEntity)
        {
            ResultDataEntity<PltPageDTO> data = new ResultDataEntity<PltPageDTO>();
            List<PltPageDTO> list = new List<PltPageDTO>();
            //筛选
            var query = _context.PltPages
                .Where(b => b.RecStatus == "A")
                .ToList();
 
            if (!string.IsNullOrEmpty(searchEntity.SystemId))
            {
                query = query.Where(m => m.SystemId.Contains(searchEntity.SystemId)).ToList();
            }
            if (!string.IsNullOrEmpty(searchEntity.PageName))
            {
                query = query.Where(m => m.PageName.Contains(searchEntity.PageName)).ToList();
            }
            if (!string.IsNullOrEmpty(searchEntity.PageShortcut))
            {
                query = query.Where(m => m.PageShortcut.Contains(searchEntity.PageShortcut)).ToList();
            }
            if (!string.IsNullOrEmpty(searchEntity.PagePath))
            {
                query = query.Where(m => m.PagePath.Contains(searchEntity.PagePath)).ToList();
            }
            if (!string.IsNullOrEmpty(searchEntity.PageType))
            {
                query = query.Where(m => m.PageType.Contains(searchEntity.PageType)).ToList();
            }
            if (!string.IsNullOrEmpty(searchEntity.PageSuperior))
            {
                query = query.Where(m => m.PageSuperior==searchEntity.PageSuperior).ToList();
            }
            if (!string.IsNullOrEmpty(searchEntity.PageIco))
            {
                query = query.Where(m => m.PageIco.Contains(searchEntity.PageIco)).ToList();
            }
            
 
 
 
            query = query.OrderByDescending(x => x.Modifytime).ToList();
            //if (searchEntity.totalrows == 0)
                searchEntity.totalrows = query.Count();
            var rolelist = query.Skip((searchEntity.page - 1) * searchEntity.rows).Take(searchEntity.rows).ToList();
            list = _mapper.Map<List<PltPageDTO>>(rolelist);
            data.LoadData(searchEntity, list);
            return data;
        }
 
        public ResultEntity ModifyStatus(string id, string userid)
        {
 
            ResultEntity result = new ResultEntity();
            result.Result = true;
 
            var model = _context.PltPages.Find(id);
            if (model != null)
            {
                model.RecStatus = "D";
                model.Modifier = userid;
                model.Modifytime = DateTime.Now;
                _context.SaveChanges();
            }
 
            return result;
        }
 
 
        /// <summary>
        /// 获取所有权限
        /// </summary>
        /// <returns></returns>
        public   List<PageEntity> GePagetList()
        {
            List<PageEntity> entitylist = new List<PageEntity>();
 
            
                var listpage = _context.PltPages.Where(p => p.RecStatus == "A").ToList();
                if (listpage.Count > 0)
                {
                    listpage.ForEach(p =>
                    {
                        entitylist.Add(new PageEntity()
                        {
                            Open_Type = p.OpenType!=null?p.OpenType.Value:0,
                            PageID = p.Id,
                            SystemID = p.SystemId,
                            PageName = p.PageName,
                            DisplaySeq = p.DisplaySeq != null ? p.DisplaySeq.Value:0,
                            PagePath = p.PagePath,
                            PageType = p.PageType,
                            PageSuperior = p.PageSuperior,
                            PageIco = (string.IsNullOrEmpty(p.PageIco) || p.PageIco == "00" || p.PageIco == "01") == true ? "fa  fa-angle-right" : p.PageIco,
                            OpenType = p.DisplaySeq != null ? p.OpenType.Value : 0,
                        });
                    });
                }
            
            return entitylist.OrderBy(it => it.PageSuperior).ThenBy(d => d.DisplaySeq).ToList();
        }
 
 
 
        /// <summary>
        /// 获取所有角色相关权限
        /// </summary>
        /// <returns></returns>
        public   List<PltAuthDTO> GetauthList(string roleid = "")
        {
          
 
            var listAuth = _context.PltAuths.Where(a => a.RecStatus == "A" &&
                (roleid == "" ? true : a.RoleId == roleid)
                ).ToList();
            var list = _mapper.Map<List<PltAuthDTO>>(listAuth);
            return list;
        }
 
 
        /// <summary>
        /// 设置角色权限
        /// </summary>
        /// <param name="roleid"></param>
        /// <param name="pageid"></param>
        /// <param name="User_id"></param>
        /// <returns></returns>
        public   ResultEntity SaveManyEntity(string roleid = "", string pageid = "", string User_id = "")
        {
            var result = new ResultEntity();
            result.Result = true;
            try
            {
                
                    #region 删除角色原来设置的权限
                    var listAuthOld = _context.PltAuths.Where(a => a.RoleId == roleid).ToList();
                    if (listAuthOld.Count > 0)
                    {
                        listAuthOld.ForEach(a => {
                            _context.PltAuths.Remove(a);
                        });
                    }
                    #endregion
 
                    #region 设置新的权限
                    var aryPage = pageid.Split(',').ToList();
                    if (aryPage.Count > 0)
                    {
                        aryPage.ForEach(p => {
                            _context.PltAuths.Add(new PltAuth()
                            {
                                Id = Guid.NewGuid().ToString(),
                                RoleId = roleid,
                                AuthType = "1",
                                ItemId =p,
                                RecStatus = "A",
                                Creater = User_id,
                                Createtime = DateTime.Now,
                                Modifier = User_id,
                                Modifytime = DateTime.Now
                            });
 
                        });
                    }
                #endregion
 
                _context.SaveChanges();
                
 
            }
            catch (Exception ex)
            {
                result.Result = false;
                result.Message = ex.Message;
            }
            return result;
        }
 
 
        /// <summary>
        ///  查询当前菜单的下属按钮
        /// </summary>
        /// <param name="datadt"></param>
        /// <returns></returns>
        public   List<PageEntity> GetUserPage(string userid, string page_path)
        {
            List<PageEntity> entityList = new List<PageEntity>();
 
            
 
                #region 超级管理员操作
                var roleId = _context.PltUserRoles.Where(o => o.UserId == userid).Select(o => o.RoleId).ToList(); ;//获取角色类型
                var rolename = _context.PltRoles.Where(o => roleId.Contains(o.Id) && o.RoleName == "系统管理员").ToList();
 
                if (rolename != null && rolename.Count > 0)//超级管理员操作
                {
                var adminList = from page in _context.PltPages
                                join pagepa in _context.PltPages
                                on page.PageSuperior equals pagepa.Id
                                where
                                page.RecStatus == "A" &&
                                new List<string> { "B" }.Contains(page.PageType)
                                && pagepa.PagePath == page_path
                                    orderby page.DisplaySeq
                                    select new PageEntity()
                                    {
                                        Open_Type = page.OpenType ?? 0,
                                        PageID = page.Id,
                                        SystemID = page.SystemId,
                                        PageName = page.PageName,
                                        PageShortcut = page.PageShortcut,
                                        DisplaySeq = page.DisplaySeq ?? 0,
                                        PagePath = page.PagePath,
                                        PageType = page.PageType,
                                        PageSuperior = page.PageSuperior,
                                        PageIco = page.PageIco ?? "",  //fa  fa-angle-right
                                        OpenType = page.OpenType ?? 0,
                                        PageMethod = page.PageMethod,
                                    };
                    entityList = adminList.ToList();
                }
                #endregion
                else
                {
                    var list = from user in _context.PltUsers
                               join user_role in _context.PltUserRoles on user.Id equals user_role.UserId
                               join role in _context.PltRoles on user_role.RoleId equals role.Id
                               join auth in _context.PltAuths.Distinct() on role.Id equals auth.RoleId
                               join page in _context.PltPages on auth.ItemId equals page.Id
                               join pagepa in _context.PltPages on page.PageSuperior equals pagepa.Id
                               where
                               user.Id == userid &&
                               user.RecStatus == "A" &&
                               user_role.RecStatus == "A" &&
                               role.RecStatus == "A" &&
                               auth.RecStatus == "A" &&
                               page.RecStatus == "A" &&
                               new List<string> { "B"}.Contains(page.PageType)  
                               //systemidlist.Contains(page.system_id) &&
                               && pagepa.PagePath == page_path
                               orderby page.DisplaySeq
                               select new PageEntity()
                               {
                                   Open_Type = page.OpenType ?? 0,
                                   PageID = page.Id,
                                   SystemID = page.SystemId,
                                   PageName = page.PageName,
                                   PageShortcut = page.PageShortcut,
                                   DisplaySeq = page.DisplaySeq ?? 0,
                                   PagePath = page.PagePath,
                                   PageType = page.PageType,
                                   PageSuperior = page.PageSuperior,
                                   PageIco = page.PageIco ?? "",  //fa  fa-angle-right
                                   OpenType = page.OpenType ?? 0,
                                   PageMethod = page.PageMethod,
                               };
                    entityList = list.ToList().Distinct(new PageEntityIdComparer()).ToList();
                }
          
 
            return entityList;
        }
    }
}