using HH.MData;
|
using HH.WMS.Entitys;
|
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.Threading.Tasks;
|
|
namespace HH.WMS.DAL.Common
|
{
|
public class TN_WM_MONGODAL : DapperBaseDAL
|
{
|
|
#region 判断记录是否存在
|
/// <summary>
|
/// 判断记录是否存在
|
/// </summary>
|
/// <typeparam name="T">实体</typeparam>
|
/// <param name="fieldValue">字段值</param>
|
/// <param name="fieldName">字段名称</param>
|
/// <param name="collectionName">表名</param>
|
/// <returns></returns>
|
public OperateResult IsExistsMongo<T>(string fieldValue, string fieldName, string collectionName)
|
{
|
MongoDBHelper dbHelper = new MongoDBHelper();
|
IMongoQuery query = Query.EQ(fieldName, fieldValue);
|
long count = dbHelper.FindCount<T>(query, collectionName);
|
if (count > 0) return OperateResult.Error("记录已存在!", "");
|
return OperateResult.Succeed("记录不存在!", "");
|
}
|
#endregion
|
|
|
#region 新增一个集合到mongo数据库
|
/// <summary>
|
/// 新增一个集合到mongo数据库
|
/// </summary>
|
/// <typeparam name="T">实体类</typeparam>
|
/// <param name="lstEntity">实体类集合数据</param>
|
/// <param name="CollectionName">对象名称</param>
|
/// <returns></returns>
|
public OperateResult AddList<T>(List<T> lstEntity, string collectionName)
|
{
|
try
|
{
|
MongoDBHelper dbHelper = new MongoDBHelper();
|
bool result = dbHelper.Insert<T>(lstEntity, collectionName);
|
if (result)
|
return OperateResult.Succeed("执行成功!", "");
|
else
|
return OperateResult.Error("执行失败!", "");
|
}
|
catch (Exception ex)
|
{
|
return OperateResult.Error(ex.ToString(), "");
|
}
|
}
|
#endregion
|
|
#region 根据条件删除Mongo数据
|
/// <summary>
|
/// 根据条件删除Mongo数据
|
/// </summary>
|
/// <typeparam name="T">实体</typeparam>
|
/// <param name="fieldValue">字段值</param>
|
/// <param name="fieldName">字段名称</param>
|
/// <param name="collectionName">表名</param>
|
/// <returns></returns>
|
public OperateResult RemoveData<T>(string fieldValue, string fieldName, string collectionName)
|
{
|
try
|
{
|
MongoDBHelper dbHelper = new MongoDBHelper();
|
IMongoQuery query = Query.EQ(fieldName, fieldValue);
|
bool result = dbHelper.Remove<T>(query, collectionName);
|
if (result)
|
return OperateResult.Succeed("执行成功!", "");
|
else
|
return OperateResult.Error("执行失败!", "");
|
}
|
catch (Exception ex)
|
{
|
return OperateResult.Error(ex.ToString(), "");
|
}
|
}
|
#endregion
|
|
#region 获取仓库信息
|
/// <summary>
|
/// 获取仓库信息
|
/// </summary>
|
/// <param name="fieldName">字段名称</param>
|
/// <param name="inputValue">输入值</param>
|
/// <returns></returns>
|
/// <history>[HanHe(LT)] CREATED 2018/7/5</history>
|
public TN_AB_STOCKEntity GetStockentity(string fieldName, string inputValue)
|
{
|
var query = Query.EQ(fieldName, inputValue);
|
TN_AB_STOCKEntity entity = MongoDBSingleton.Instance.FindOne<TN_AB_STOCKEntity>(query, "TN_AB_STOCK");
|
return entity;
|
}
|
#endregion
|
|
public List<TN_WM_B_UNIQUE_BARCODEEntity> GetXmlList(SearchModel searchModel, out int total)
|
{
|
//List<IMongoQuery> queryList = new List<IMongoQuery>();
|
//string itemCode = Util.ToString(searchModel.SearchCondition.ItemCode);
|
//if (!string.IsNullOrEmpty(itemCode))
|
//{
|
// queryList.Add(Query.Matches("CN_S_ITEM_CODE", "/" + itemCode + "/"));
|
//}
|
//IMongoQuery query = null;
|
//if (queryList.Any())
|
// query = Query.And(queryList);
|
total = Convert.ToInt32(MongoDBSingleton.Instance.FindCount<TN_WM_B_UNIQUE_BARCODEEntity>(null, "TN_WM_B_UNIQUE_BARCODE"));
|
return MongoDBSingleton.Instance.Find<TN_WM_B_UNIQUE_BARCODEEntity>(null, searchModel.PageIndex, searchModel.PageSize, null, "TN_WM_B_UNIQUE_BARCODE");
|
}
|
|
|
#region 根据仓库获得所有库区
|
/// <summary>
|
/// 根据仓库获得所有库区
|
/// </summary>
|
/// <param name="stcokCode"></param>
|
/// <param name="type"></param>
|
/// <returns></returns>
|
/// <history>[HanHe(LT)] CREATED 2018/8/13</history>
|
public List<AutoBomStockAreaEntity> GetList(string stcokCode, string types)
|
{
|
List<AutoBomStockAreaEntity> listLogic = new List<AutoBomStockAreaEntity>();
|
List<IMongoQuery> querys = new List<IMongoQuery>();
|
if (!string.IsNullOrEmpty(stcokCode))
|
{
|
//检索条件 仓库编号=传递的仓库编号 类型 != 2 也就是不等于逻辑分区的
|
//取到当前仓库下的库区以及虚拟分区
|
querys.Add(Query.EQ("CN_S_STOCK_CODE", stcokCode));
|
}
|
if (!string.IsNullOrEmpty(types))
|
{
|
string[] b = types.Split(',');
|
List<int> list = new List<int>();
|
for (int i = 0; i < b.Length; i++)
|
{
|
list.Add(Convert.ToInt32(b[i]));
|
}
|
|
var type = list.ConvertAll<BsonValue>(x => x);
|
querys.Add(Query.In("CN_N_TYPE", type));
|
}
|
IMongoQuery query = Query.And(querys);
|
listLogic = MongoDBSingleton.Instance.Find<AutoBomStockAreaEntity>(query, "TN_AB_B_STOCK_AREA");
|
|
return listLogic;
|
}
|
#endregion
|
|
#region
|
/// <summary>
|
/// 获取库区
|
/// </summary>
|
/// <param name="id"></param>
|
/// <returns></returns>
|
public AutoBomStockAreaEntity GetStockArea(string fieldName, string Value)
|
{
|
IMongoQuery query = Query.EQ("" + fieldName + "", Value);
|
return MongoDBSingleton.Instance.FindOne<AutoBomStockAreaEntity>(query, "TN_AB_B_STOCK_AREA");
|
}
|
#endregion
|
|
/// <summary>
|
/// 根据条件删除Mongo数据
|
/// </summary>
|
/// <typeparam name="T">实体</typeparam>
|
/// <param name="fieldValue">字段值</param>
|
/// <param name="fieldName">字段名称</param>
|
/// <param name="collectionName">表名</param>
|
/// <returns></returns>
|
public OperateResult RemoveDataByCode<T>(string fieldValue, string fieldName, string collectionName)
|
{
|
MongoDBHelper dbHelper = new MongoDBHelper();
|
IMongoQuery query = Query.EQ(fieldName, fieldValue);
|
bool result = dbHelper.Remove<T>(query, collectionName);
|
if (result)
|
return OperateResult.Succeed("", null);
|
else
|
return OperateResult.Error("失败", null);
|
}
|
|
|
#region 获取虚拟库区
|
/// <summary>
|
/// 根据仓库获得所有库区
|
/// </summary>
|
/// <returns></returns>
|
/// <history>[HanHe(LT)] CREATED 2018/12/22</history>
|
public List<AutoBomStockAreaEntity> GetXNAreaList(string stcokCode,string areaCode, string type)
|
{
|
List<IMongoQuery> querys = new List<IMongoQuery>();
|
if (!string.IsNullOrEmpty(stcokCode))
|
{
|
//检索条件 仓库编号=传递的仓库编号 类型 != 2 也就是不等于逻辑分区的
|
//取到当前仓库下的库区以及虚拟分区
|
querys.Add(Query.EQ("CN_S_STOCK_CODE", stcokCode));
|
}
|
if (!string.IsNullOrEmpty(type))
|
{
|
querys.Add(Query.EQ("CN_N_TYPE", Convert.ToInt32(type)));
|
}
|
if (!string.IsNullOrEmpty(areaCode))
|
{
|
querys.Add(Query.EQ("CN_S_AREA_CODE", areaCode));
|
}
|
IMongoQuery query = Query.And(querys);
|
List<AutoBomStockAreaEntity> listLogic = MongoDBSingleton.Instance.Find<AutoBomStockAreaEntity>(query, "TN_AB_B_STOCK_AREA");
|
|
return listLogic;
|
}
|
#endregion
|
|
|
#region 根据库区编码获取库区
|
/// <summary>
|
/// 根据库区编码获取库区
|
/// </summary>
|
/// <param name="stcokCode"></param>
|
/// <param name="type"></param>
|
/// <returns></returns>
|
/// <history>[HanHe(LT)] CREATED 2018/12/29</history>
|
public List<AutoBomStockAreaEntity> GetAreaListByAreaCodeList(List<string> areaLists)
|
{
|
List<AutoBomStockAreaEntity> listLogic = new List<AutoBomStockAreaEntity>();
|
|
var areaList = areaLists.ConvertAll<BsonValue>(x => x);
|
var query = Query.In("CN_S_AREA_CODE", areaList);
|
listLogic = MongoDBSingleton.Instance.Find<AutoBomStockAreaEntity>(query, "TN_AB_B_STOCK_AREA");
|
|
return listLogic;
|
}
|
#endregion
|
}
|
}
|