WYB
2021-03-22 91b8cdad021ab052e4991f3d41834a6f0ddc36b8
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
using JiepeiWMS.IServices;
using JiepeiWMS.Model.Models;
using JiepeiWMS.Services.BASE;
using JiepeiWMS.IRepository.Base;
using System.Threading.Tasks;
using JiepeiWMS.Model;
using System.Linq.Expressions;
using System;
using SqlSugar;
using JiepeiWMS.Common.Helper;
using JiepeiWMS.Common.Enums;
using JiepeiWMS.Services.SearchModels;
using System.Collections.Generic;
using System.Text;
 
namespace JiepeiWMS.Services
{
    public class WMCheckInfoServices : BaseServices<WMCheckInfo>, IWMCheckInfoServices
    {
        private readonly IBaseRepository<WMCheckInfo> _dal;
        public WMCheckInfoServices(IBaseRepository<WMCheckInfo> dal)
        {
            this._dal = dal;
            base.BaseDal = dal;
        }
 
        /// <summary>
        /// 搜索选项
        /// </summary>
        /// <param name="Search">查询信息</param>
        /// <param name="JoinTableAliass">关联表别名列表</param>
        /// <param name="InJoinTables">In优化表关联列表</param>
        /// <returns>Sql条件(不带where)</returns>
        public static string GetSearchInfo(ShearchWMCheckInfo Search, HashSet<string> JoinTableAliass, List<string> InJoinTables)
        {
            var where = new StringBuilder();
 
            ////新参数JoinTableAliass事例,关联其它表时需加别名(SQL效率优化)
            //if (string.IsNullOrEmpty(Search.PinBanNo))
            //{
            //    where.Append(" and pb.[OrderNo] = " + Search.PinBanNo);
            //    JoinTableAliass.Add("pb");
            //}
            ////新参数InJoinTables事例,关联其它表时需加别名,同时又用In关联(SQL效率优化)
            //if (Search.PinBanStatus.HasValue)
            //{
            //    InJoinTables.Add(GetWhereInToJoin("[Status]", Search.StatusList.Split(','), "pb"));
            //    JoinTableAliass.Add("pb");
            //}
 
            if (Search.Id.HasValue)
            {
                where.Append(" and pg.[Id] = " + Search.Id);
                JoinTableAliass.Add("pg");
            }
 
            if (!string.IsNullOrEmpty(Search.IdList))
            {
                where.Append(" and pg.[Id] in (" + Search.IdList + ")");
                JoinTableAliass.Add("pg");
            }
 
            if (Search.Status.HasValue)
            {
                where.Append(" and pg.[Status] = " + Search.Status);
                JoinTableAliass.Add("pg");
            }
 
            if (Search.StartStatus.HasValue)
            {
                where.Append(" and pg.[Status] >= " + Search.StartStatus);
                JoinTableAliass.Add("pg");
            }
 
            if (Search.ListStatus != null)
            {
                //此实现可使用到索引
                InJoinTables.Add(GetWhereInToJoin("[Status]", Search.ListStatus));
            }
 
            if (Search.StartCreateTime.HasValue)
            {
                where.Append(" and pg.[CreateTime] >= '" + Search.StartCreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss") + "'");
                JoinTableAliass.Add("pg");
            }
 
            if (Search.EndCreateTime.HasValue)
            {
                where.Append(" and pg.[CreateTime] <= '" + Search.EndCreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss") + "'");
                JoinTableAliass.Add("pg");
            }
 
            if (!string.IsNullOrEmpty(Search.Key))
            {
                where.Append("pg.[Key] like '" + Search.Key.Replace("'", "''") + "%'");
            }
 
            return where.Length == 0 ? string.Empty : where.ToString(5, where.Length - 5);
        }
 
 
        public async Task<PageModel<WMCheckInfo>> QueryPage(Expression<Func<WMCheckInfo, Department, bool>> whereExpression,
int intPageIndex = 1, int intPageSize = 20, string strOrderByFileds = null)
        {
            var plst = await BaseDal.QueryPage<WMCheckInfo, Department>(
                (ci, dp) => new object[]{
                    JoinType.Left,ci.DepartId==dp.Id
                },
                (ci, dp) => new WMCheckInfo
                {
                    CheckName = ci.CheckName,
                    DepartName = dp.Name,
                    Id = ci.Id,
                    DepartId = ci.DepartId,
                    CheckRemark = ci.CheckRemark,
                    CheckType = ci.CheckType,
                    CreateTime = ci.CreateTime,
                    IsEnable = ci.IsEnable,
                    Json = ci.Json,
                    Key = ci.Key,
                    UpDateTime = ci.UpDateTime
                },
                whereExpression,
                intPageIndex,
                intPageSize,
                strOrderByFileds);
 
            var dic = typeof(EnumWMCheckType)._GetValueDescriptionDicFromEnumType<EnumWMCheckType>();
            foreach (var i in plst.data)
            {
                string name;
                i.CheckTypeName = dic.TryGetValue((EnumWMCheckType)i.CheckType, out name) ? name : string.Empty;
            }
 
            return plst;
        }
    
 
    }
}