wxw
3 天以前 e9e24ec8741b0a813c43093a1af3be800c1dc0a5
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Model.ModelDto.LogDto;
using Model.ModelVm.LogVm;
using SqlSugar;
using Utility;
using WMS.DAL;
using WMS.Entity.Context;
using WMS.Entity.LogEntity;
using WMS.Entity.SysEntity;
using WMS.IBLL.ILogServer;
 
namespace WMS.BLL.LogServer
{
    public class OperationCrServer: DbHelper<LogOperationCR>,IOperationCRServer
    {
        private static readonly SqlSugarScope Db = DataContext.Db;
        private readonly UserManager _userManager;
        public OperationCrServer() : base(Db)
        {
        }
        public OperationCrServer(UserManager userManager) : base(Db)
        {
            _userManager = userManager;
        }
        public async Task<List<OperationDto>> GetLogOperationCrList(string menuName, string type, string msg, string startTime, string endTime, int page, int limit, RefAsync<int> count)
        {
            try
            {
                var item = Expressionable.Create<LogOperationCR>()
                    .AndIF(!string.IsNullOrWhiteSpace(menuName), it => it.MenuName.Contains(menuName.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(type), it => it.Type == type)
                    .AndIF(!string.IsNullOrWhiteSpace(msg), it => it.Msg.Contains(msg.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(startTime), it => it.CreateTime >= Convert.ToDateTime(startTime))
                    .AndIF(!string.IsNullOrWhiteSpace(endTime), it => it.CreateTime <= Convert.ToDateTime(endTime).AddDays(1))
                    .ToExpression();//注意 这一句 不能少
                var list = await GetAllWhereAsync(item)
                    .LeftJoin<SysDictionary>((it, dic) => it.Type == dic.Id.ToString())
                    .LeftJoin<SysUserInfor>((it, dic, users) => it.CreateUser == users.Id)
                    .Select((it, dic, users) => new OperationDto()
                    {
                        Id = it.Id,
                        ParentNo = it.ParentNo,
                        MenuNo = it.MenuNo,
                        MenuName = it.MenuName,
                        FkNo = it.FkNo,
                        Type = dic.DictName,
                        Msg = it.Msg,
                        CreateTime = it.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
                        CreateUserName = users.RealName,
                    })
                    .OrderByDescending(it => it.CreateTime)
                    .ToPageListAsync(page, limit, count);
                return list;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        public bool AddLogOperationCr(string parentNo, string menuName, string fkNo, string type, string msg, int userId)
        {
            try
            {
                var menu = Db.Queryable<SysFunctionMenu>().Where(m => m.IsDel == "0").ToList();
                var dic = Db.Queryable<SysDictionary>().Where(m => m.ParentNo == "LogType" && m.IsDel == "0").ToList();
                var typeId = dic.FirstOrDefault(m => m.DictName == type);
 
                var n = Add(new LogOperationCR()
                {
                    ParentNo = menu.FirstOrDefault(m => m.MenuName == parentNo) == null ? "" : menu.First(m => m.MenuName == parentNo).MenuNo,
                    MenuNo = menu.FirstOrDefault(m => m.MenuName == menuName) == null ? "" : menu.First(m => m.MenuName == menuName).MenuNo,
                    MenuName = $"{parentNo}-{menuName}",
                    FkNo = fkNo,
                    Type = typeId == null ? "" : typeId.Id.ToString(),
                    Msg = msg,
 
                    CreateUser = userId
                });
                return n > 0;
 
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        /// <summary>
        /// 新增系统操作日志
        /// </summary>
        /// <returns></returns>
        public async Task<int> AddLogOperationCr(OperationInputVm input)
        {
            input.ParentNo = (await Db.Queryable<SysFunctionMenu>().FirstAsync(s => s.MenuName == input.ParentName && s.IsDel == "0"))?.MenuNo;
            input.MenuNo = (await Db.Queryable<SysFunctionMenu>().FirstAsync(s => s.MenuName == input.MenuName && s.IsDel == "0"))?.MenuNo;
            input.Type = (await Db.Queryable<SysDictionary>().FirstAsync(s => s.DictName == input.TypeName && s.IsDel == "0"))?.Id.ToString();
            input.CreateUser = _userManager.UserId;
            input.CreateTime = DateTime.Now;
            return await Db.Insertable<LogOperationCR>(input).ExecuteCommandAsync();
        }
    }
}