bklLiudl
2025-04-07 4e8f58cb41c7b6d570fd1979d80f74ab8a4d00c2
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model.ModelDto.LogDto;
using SqlSugar;
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;
        public OperationCrServer() : base(Db)
        {
        }
        public List<OperationDto> GetLogOperationCrList(string menuName, string type, string msg, string startTime, string endTime, int page, int limit, out 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 total = 0;
                var list = 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)
                    .ToOffsetPage(page, limit, ref total);
 
                count = total;
                return list.OrderByDescending(m => m.CreateTime).ToList();
            }
            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 contextDb = DataContext.Db;
                var menu = contextDb.Queryable<SysFunctionMenu>().Where(m => m.IsDel == "0").ToList();
                var dic = contextDb.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);
            }
        }
    }
}