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
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
using Model.ModelDto.BllCheckDto;
using SqlSugar;
using WMS.DAL;
using WMS.Entity.BllCheckEntity;
using WMS.Entity.Context;
using WMS.Entity.SysEntity;
using WMS.IBLL.IBllCheckServer;
 
namespace WMS.BLL.BllCheckServer
{
    public class StockCheckLogServer:DbHelper<BllStockCheckLog>,IStockCheckLogServer
    {
        private static readonly SqlSugarScope Db = DataContext.Db;
        public StockCheckLogServer() : base(Db)
        {
        }
 
        //获取盘点记录
        public List<StockCheckLogDto> GetStockCheckLogList(string crNo, string status, string palletNo, string boxNo, string skuNo, string skuName, string lotNo, int page, int limit, out int count)
        {
            try
            {
                Expression<Func<BllStockCheckLog, bool>> item = Expressionable.Create<BllStockCheckLog>()
                    .AndIF(!string.IsNullOrWhiteSpace(crNo), m => m.CRNo.Contains(crNo.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(status), m => m.CheckResult == int.Parse(status)) 
                    .AndIF(!string.IsNullOrWhiteSpace(palletNo), m => m.PalletNo.Contains(palletNo.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(boxNo), m => m.BoxNo.Contains(boxNo.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(skuNo), m => m.SkuNo.Contains(skuName.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(skuName), m => m.SkuName.Contains(lotNo.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(lotNo), m => m.LotNo.Contains(lotNo.Trim()))
                    .And(m => m.IsDel == "0")
                    .ToExpression();//注意 这一句 不能少
                var total = 0;
                var list = GetAllWhereAsync(item)
                    .LeftJoin<SysUserInfor>((a, b) => a.CheckUserId == b.Id)
                    .LeftJoin<SysUserInfor>((a, b,c) => a.CreateUser == c.Id)
                    .LeftJoin<SysUserInfor>((a, b, c,d) => a.UpdateUser == d.Id)
                    .Select((a, b, c,d) => new StockCheckLogDto()
                    {
                        Id = a.Id,
                        CrNo = a.CRNo,
                        PalletNo = a.PalletNo,
                        BoxNo = a.BoxNo,
                        BoxNo2 = a.BoxNo2,
                        BoxNo3 = a.BoxNo3,
                        Qty = a.Qty,
                        RealQty = a.RealQty,
                        CheckDate = a.CheckDate,
                        CheckResult = a.CheckResult,
                        CheckUserName = b.RealName,
                        SkuNo = a.SkuNo,
                        SkuName = a.SkuName,
                        Standard = a.Standard,
                        LotNo = a.LotNo,
                        LotText = a.LotText,
                        SupplierLot = a.SupplierLot,
                        
                        CreateUserName = c.RealName,
                        UpdateUserName = d.RealName,
                        CreateTime = a.CreateTime,
                        UpdateTime = a.UpdateTime,
 
                    }).OrderByDescending(a=>a.CreateTime).ToOffsetPage(page, limit, ref total);
                count = total;
 
                return list;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        #region 数据归档
        /// <summary>
        /// 获取盘点记录-数据归档
        /// </summary>
        /// <returns></returns>
        public List<StockCheckLogDto> GetArchivingStockCheckLogList(string crNo, string status, string palletNo, string boxNo, string skuNo, string skuName,
            string lotNo, int page, int limit, out int count)
        {
            try
            {
                string sqlString = string.Empty;
                string sqlCount = string.Empty;
                string sqlPub = string.Empty;
                sqlCount += "SELECT COUNT(tb1.ID) FROM ArchivingStockCheckLog AS tb1 ";
                sqlString += "select tb1.*,tb2.RealName as CheckUserName,tb3.RealName as CreateUserName,tb4.RealName as UpdateUserName from ArchivingStockCheckLog as tb1 ";
                sqlPub += "left join SysUserInfor as tb2 on tb1.CheckUserId=tb2.Id ";
                sqlPub += "left join SysUserInfor as tb3 on tb1.CreateUser=tb3.Id ";
                sqlPub += "left join SysUserInfor as tb4 on tb1.UpdateUser=tb4.Id ";
                sqlPub += "where tb1.IsDel = '0' ";
                if (!string.IsNullOrEmpty(crNo))
                {
                    sqlPub += $"AND tb1.CRNo like '%{crNo.Trim()}%' ";
                }
                if (!string.IsNullOrEmpty(status))
                {
                    sqlPub += $"AND tb1.CheckResult = {int.Parse(status)} ";
                }
                if (!string.IsNullOrEmpty(palletNo))
                {
                    sqlPub += $"AND tb1.PalletNo like '%{palletNo.Trim()}%' ";
                }
                if (!string.IsNullOrEmpty(boxNo))
                {
                    sqlPub += $"AND tb1.BoxNo like '%{boxNo.Trim()}%' ";
                }
                if (!string.IsNullOrEmpty(skuNo))
                {
                    sqlPub += $"AND tb1.SkuNo like '%{skuNo.Trim()}%' ";
                }
                if (!string.IsNullOrEmpty(skuName))
                {
                    sqlPub += $"AND tb1.SkuName like '%{skuName.Trim()}%' ";
                }
                if (!string.IsNullOrEmpty(lotNo))
                {
                    sqlPub += $"AND tb1.LotNo like '%{lotNo.Trim()}%' ";
                }
 
                sqlCount += sqlPub;
                sqlPub += " order by tb1.CreateTime desc ";
                if (page == 0)
                {
                    page = 1;
                }
                sqlString += sqlPub + $" offset {((page - 1) * limit)} rows fetch next {limit} rows only;";
 
                var com = new Common();
                count = com.GetRowCount(sqlCount);
 
                var modelList = Db.Ado.SqlQuery<StockCheckLogDto>(sqlString);
 
                return modelList;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        #endregion
    }
}