using HH.MData;
|
using HH.WMS.Common;
|
using HH.WMS.Entitys.Algorithm;
|
using HH.WMS.Entitys.Basic;
|
using HH.WMS.Entitys.Common;
|
using MongoDB.Bson;
|
using MongoDB.Driver;
|
using MongoDB.Driver.Builders;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Text.RegularExpressions;
|
using System.Threading.Tasks;
|
|
namespace HH.WMS.DAL.Basic
|
{
|
public class TN_WMS_ITEMDAL : DapperBaseDAL
|
{
|
#region 根据物料编码返回物料实体
|
/// <summary>
|
/// 根据物料编码返回物料实体
|
/// </summary>
|
/// <param name="itemCode"></param>
|
/// <returns></returns>
|
public AutoBomItemEntity GetItemEntity(string itemCode)
|
{
|
AutoBomItemEntity entity = new AutoBomItemEntity();
|
var query = Query.EQ("CN_S_ITEM_CODE", itemCode);
|
entity = MongoDBSingleton.Instance.FindOne<AutoBomItemEntity>(query, "TN_AB_ITEM");
|
return entity;
|
}
|
public AutoBomItemEntityYS GetItemEntityYS(string itemCode)
|
{
|
AutoBomItemEntityYS entity = new AutoBomItemEntityYS();
|
var query = Query.EQ("CN_S_ITEM_CODE", itemCode);
|
entity = MongoDBSingleton.Instance.FindOne<AutoBomItemEntityYS>(query, "TN_AB_ITEM");
|
return entity;
|
}
|
public List<AutoBomItemEntity> GetItemByNameSpec(string itemName, string specification)
|
{
|
try
|
{
|
Log.Info("===>进度1", "");
|
#region 首先通过物料名称全部匹配查询
|
List<IMongoQuery> queryList = new List<IMongoQuery>();
|
if (!string.IsNullOrEmpty(itemName))
|
{
|
queryList.Add(Query.EQ("CN_S_ITEM_NAME", itemName));
|
}
|
if (!string.IsNullOrEmpty(specification))
|
{
|
queryList.Add(Query.EQ("CN_S_MODEL", specification));
|
}
|
IMongoQuery query = null;
|
if (queryList.Any()) { query = Query.And(queryList); }
|
|
var listCount = MongoDBSingleton.Instance.Find<AutoBomItemEntity>(query, "TN_AB_ITEM");
|
#endregion
|
|
if (listCount.Count == 1)//全匹配情况下单条,直接成功返回
|
{
|
Log.Info("===>进度2", "");
|
return listCount;
|
}
|
if (listCount.Count > 1)//全匹配情况下多条,直接报错返回
|
{
|
Log.Info("===>进度3", "");
|
return new List<AutoBomItemEntity>();
|
}
|
|
if (listCount.Count == 0)//全匹配情况下没有,开始模糊查询
|
{
|
|
Log.Info("===>进度4", "");
|
#region 然后通过物料名称模糊匹配查询
|
queryList = new List<IMongoQuery>();
|
if (!string.IsNullOrEmpty(itemName))
|
{
|
queryList.Add(Query.Matches("CN_S_ITEM_NAME", BsonRegularExpression.Create(new Regex("^" + itemName))));
|
|
}
|
if (!string.IsNullOrEmpty(specification))
|
{
|
queryList.Add(Query.EQ("CN_S_MODEL", specification));
|
}
|
query = null;
|
if (queryList.Any()) { query = Query.And(queryList); }
|
|
var listCount1 = MongoDBSingleton.Instance.Find<AutoBomItemEntity>(query, "TN_AB_ITEM");
|
#endregion
|
|
if (listCount1.Count == 0)//模糊匹配情况下没有,直接报错返回
|
{
|
Log.Info("===>进度5", "");
|
return null;
|
}
|
if (listCount1.Count >= 1)//模糊匹配情况下超过或者等于一条时,开始加括号模糊匹配查询
|
{
|
Log.Info("===>进度6", "");
|
#region 然后通过物料名称加括号模糊匹配查询
|
queryList = new List<IMongoQuery>();
|
if (!string.IsNullOrEmpty(itemName))
|
{
|
queryList.Add(Query.Or(Query.Matches("CN_S_ITEM_NAME", BsonRegularExpression.Create(new Regex("^" + itemName + "\\("))), Query.Or(Query.Matches("CN_S_ITEM_NAME", BsonRegularExpression.Create(new Regex("^" + itemName + "\\("))))));
|
|
}
|
if (!string.IsNullOrEmpty(specification))
|
{
|
queryList.Add(Query.EQ("CN_S_MODEL", specification));
|
}
|
query = null;
|
if (queryList.Any()) { query = Query.And(queryList); }
|
|
var listCount2 = MongoDBSingleton.Instance.Find<AutoBomItemEntity>(query, "TN_AB_ITEM");
|
#endregion
|
if (listCount2.Count >= 1)//多条或者单条的情况下,返回至前台
|
{
|
Log.Info("===>进度7", "");
|
return listCount2;
|
}
|
else//全匹配情况下多条,直接报错返回
|
{
|
Log.Info("===>进度8", "");
|
return new List<AutoBomItemEntity>();
|
}
|
}
|
}
|
Log.Info("===>进度9", "");
|
return new List<AutoBomItemEntity>();
|
}
|
catch (Exception ex)
|
{
|
Log.Info("===>进度10", ex.Message.ToString());
|
return null;
|
}
|
}
|
|
/// <summary>
|
/// 根据物料编码返回物料实体
|
/// </summary>
|
/// <param name="itemCode"></param>
|
/// <returns></returns>
|
public List<AutoBomItemEntity> GetItemList(List<string> itemCodes)
|
{
|
try
|
{
|
var itemCode = itemCodes.ConvertAll<BsonValue>(x => x);
|
var query = Query.In("CN_S_ITEM_CODE", itemCode);
|
|
List<AutoBomItemEntity> list = MongoDBSingleton.Instance.Find<AutoBomItemEntity>(query, "TN_AB_ITEM");
|
return list;
|
}
|
catch (Exception ex)
|
{
|
return null;
|
}
|
}
|
|
/// <summary>
|
/// 根据物料编码返回物料实体
|
/// </summary>
|
/// <param name="itemCode"></param>
|
/// <returns></returns>
|
public List<AutoBomItemEntity> GetAllItem(string itemCode)
|
{
|
List<AutoBomItemEntity> list = new List<AutoBomItemEntity>();
|
if (string.IsNullOrEmpty(itemCode))
|
{
|
list = MongoDBSingleton.Instance.Find<AutoBomItemEntity>(null, "TN_AB_ITEM");
|
}
|
else
|
{
|
var query = Query.EQ("CN_S_ITEM_CODE", itemCode);
|
list = MongoDBSingleton.Instance.Find<AutoBomItemEntity>(query, "TN_AB_ITEM");
|
}
|
return list;
|
|
}
|
|
|
/// <summary>
|
/// 根据物料编码返回物料实体
|
/// </summary>
|
/// <param name="itemCode"></param>
|
/// <returns></returns>
|
/// <history>[HanHe(LT)] CREATED 2018/11/26</history>
|
/// <history>[HanHe(DBS)] CREATED 2019/1/7</history>
|
public List<AutoBomItemEntity> GetListItemByCode(string itemCode, string itemName, string model, int pageIndex, int pageSize, out int total)
|
{
|
List<AutoBomItemEntity> entity = new List<AutoBomItemEntity>();
|
SortByDocument sortBy = new SortByDocument();
|
sortBy.Add("CN_S_ITEM_CODE", -1);
|
|
List<IMongoQuery> queryList = new List<IMongoQuery>();
|
if (!string.IsNullOrEmpty(itemCode))
|
{
|
queryList.Add(Query.Matches("CN_S_ITEM_CODE", itemCode));
|
}
|
if (!string.IsNullOrEmpty(itemName))
|
{
|
queryList.Add(Query.Matches("CN_S_ITEM_NAME", itemName));
|
}
|
if (!string.IsNullOrEmpty(model))
|
{
|
queryList.Add(Query.Matches("CN_S_MODEL", model));
|
}
|
|
IMongoQuery query = null;
|
if (queryList.Any())
|
query = Query.And(queryList);
|
|
total = Convert.ToInt32(MongoDBSingleton.Instance.FindCount<AutoBomItemEntity>(query, "TN_AB_ITEM"));
|
entity = MongoDBSingleton.Instance.Find<AutoBomItemEntity>(query, pageIndex, pageSize, sortBy, "TN_AB_ITEM");
|
return entity;
|
}
|
#endregion
|
|
#region 物料列表
|
/// <summary>
|
/// 物料列表
|
/// </summary>
|
/// <returns></returns>
|
public List<AutoBomItemEntity> GetItemList(SearchModel searchModel, out int total)
|
{
|
List<IMongoQuery> queryList = new List<IMongoQuery>();
|
if (searchModel.SearchCondition != null)
|
{
|
string itemCode = Util.ToString(searchModel.SearchCondition.ItemCode);
|
if (!string.IsNullOrEmpty(itemCode))
|
{
|
queryList.Add(Query.Matches("CN_S_ITEM_CODE", Util.ToMongoLike(itemCode)));
|
}
|
string itemName = Util.ToString(searchModel.SearchCondition.ItemName);
|
if (!string.IsNullOrEmpty(itemName))
|
{
|
queryList.Add(Query.Matches("CN_S_ITEM_NAME", Util.ToMongoLike(itemName)));
|
}
|
string itemModel = Util.ToString(searchModel.SearchCondition.ItemModel);
|
if (!string.IsNullOrEmpty(itemModel))
|
{
|
queryList.Add(Query.Matches("CN_S_MODEL", Util.ToMongoLike(itemModel)));
|
}
|
string itemFigureNo = Util.ToString(searchModel.SearchCondition.ItemFigureNo);
|
if (!string.IsNullOrEmpty(itemFigureNo))
|
{
|
queryList.Add(Query.Matches("CN_S_FIGURE_NO", Util.ToMongoLike(itemFigureNo)));
|
}
|
string itemOwner = Util.ToStringInput(searchModel.SearchCondition.ItemOwner);
|
if (!string.IsNullOrEmpty(itemOwner))
|
{
|
string sql = "SELECT * FROM TN_WM_B_STOCK_QTY WHERE CN_S_OWNER='" + itemOwner + "' AND CN_F_QUANTITY>0 ";
|
var stockQtyList = ExecuteQuery<TN_WM_B_STOCK_QTYEntity>(sql);
|
var itemCodes = stockQtyList.ConvertAll<BsonValue>(x => x.CN_S_ITEM_CODE);
|
queryList.Add(Query.In("CN_S_ITEM_CODE", itemCodes));
|
}
|
}
|
IMongoQuery query = null;
|
if (queryList.Any())
|
query = Query.And(queryList);
|
total = Convert.ToInt32(MongoDBSingleton.Instance.FindCount<AutoBomItemEntity>(query, "TN_AB_ITEM"));
|
return MongoDBSingleton.Instance.Find<AutoBomItemEntity>(query, searchModel.PageIndex, searchModel.PageSize, null, "TN_AB_ITEM");
|
}
|
#endregion
|
|
#region 模糊匹配top条
|
/// <summary>
|
/// 模糊匹配top条
|
/// </summary>
|
/// <param name="key"></param>
|
/// <param name="top"></param>
|
/// <returns></returns>
|
public List<AutoBomItemEntity> GetMatchItem(string key, int top = 10)
|
{
|
IMongoQuery query = Query.Matches("CN_S_ITEM_CODE", "/" + key + "/");
|
return MongoDBSingleton.Instance.Find<AutoBomItemEntity>(query, 1, top, null, "TN_AB_ITEM");
|
}
|
#endregion
|
|
public TN_AB_B_ITEM_PRICEEntity GetItemPriceModel(string itemCode)
|
{
|
try
|
{
|
TN_AB_B_ITEM_PRICEEntity entity = new TN_AB_B_ITEM_PRICEEntity();
|
var query = Query.And(Query.EQ("CN_S_ITEM_CODE", itemCode), Query.EQ("CN_S_PRICE_TYPE", "标准成本"));
|
entity = MongoDBSingleton.Instance.FindOne<TN_AB_B_ITEM_PRICEEntity>(query, "TN_AB_B_ITEM_PRICE");
|
return entity;
|
}
|
catch (Exception ex)
|
{
|
|
}
|
return null;
|
}
|
|
|
//public List<AutoBomItemEntity> GetItemList()
|
//{
|
// var list= MongoDBSingleton.Instance.Find<AutoBomItemEntity>(null, "TN_AB_ITEM");
|
// return list;
|
//}
|
}
|
}
|