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, IWMCheckInfoServices { private readonly IBaseRepository _dal; public WMCheckInfoServices(IBaseRepository dal) { this._dal = dal; base.BaseDal = dal; } /// /// 搜索选项 /// /// 查询信息 /// 关联表别名列表 /// In优化表关联列表 /// Sql条件(不带where) public static string GetSearchInfo(ShearchWMCheckInfo Search, HashSet JoinTableAliass, List 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> QueryPage(Expression> whereExpression, int intPageIndex = 1, int intPageSize = 20, string strOrderByFileds = null) { var plst = await BaseDal.QueryPage( (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(); foreach (var i in plst.data) { string name; i.CheckTypeName = dic.TryGetValue((EnumWMCheckType)i.CheckType, out name) ? name : string.Empty; } return plst; } } }