From 0fb0f17319ecf71d66b96a6acfd07f754be9443e Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期四, 24 十月 2024 13:44:38 +0800
Subject: [PATCH] WCS添加穿梭车信息表,修改任务信息表
---
项目代码/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseRepository/RepositoryBase.cs | 180 ++++++++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 140 insertions(+), 40 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseRepository/RepositoryBase.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseRepository/RepositoryBase.cs"
index 539c96b..681b8e3 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseRepository/RepositoryBase.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseRepository/RepositoryBase.cs"
@@ -15,6 +15,12 @@
using WIDESEA_Core.DB;
using WIDESEA_Core.Const;
using WIDESEA_Core.AOP;
+using OfficeOpenXml.FormulaParsing.ExpressionGraph;
+using WIDESEA_Core.Enums;
+using WIDESEA_Core.Utilities;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using NetTaste;
+using WIDESEA_Core.DB.Models;
namespace WIDESEA_Core.BaseRepository
{
@@ -51,7 +57,8 @@
IsAutoCloseConnection = true,
AopEvents = new AopEvents()
{
- DataExecuting = SqlSugarAop.DataExecuting
+ DataExecuting = SqlSugarAop.DataExecuting,
+
}
};
iTenant.AddConnection(connectionConfig);
@@ -65,7 +72,9 @@
return db;
}
}
-
+ /// <summary>
+ /// 鍒涘缓鏁版嵁搴撹繛鎺ュ璞�
+ /// </summary>
public ISqlSugarClient Db => _db;
public RepositoryBase(IUnitOfWorkManage unitOfWorkManage)
@@ -123,7 +132,7 @@
public virtual int AddData(List<TEntity> listEntity)
{
IInsertable<TEntity> insert = _db.Insertable(listEntity);
- return insert.ExecuteReturnIdentity();
+ return insert.ExecuteCommand();
}
/// <summary>
@@ -193,7 +202,7 @@
/// <param name="lstColumns"></param>
/// <param name="lstIgnoreColumns"></param>
/// <returns></returns>
- public virtual bool UpdateData(TEntity entity, List<string> lstColumns, List<string> lstIgnoreColumns = null)
+ public virtual bool UpdateData(TEntity entity, List<string> lstColumns, List<string>? lstIgnoreColumns = null)
{
IUpdateable<TEntity> update = _db.Updateable(entity);
@@ -255,9 +264,19 @@
/// <param name="whereExpression"></param>
/// <param name="orderByFields"></param>
/// <returns></returns>
- public virtual List<TEntity> QueryData(Expression<Func<TEntity, bool>> whereExpression, string orderByFields)
+ public virtual List<TEntity> QueryData(Expression<Func<TEntity, bool>> whereExpression, Dictionary<string, OrderByType> orderBy)
{
- return _db.Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).OrderByIF(!string.IsNullOrEmpty(orderByFields), orderByFields).ToList();
+ List<OrderByModel> orderByModels = new List<OrderByModel>();
+ foreach (var item in orderBy)
+ {
+ OrderByModel orderByModel = new OrderByModel()
+ {
+ FieldName = item.Key,
+ OrderByType = item.Value
+ };
+ orderByModels.Add(orderByModel);
+ }
+ return _db.Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).OrderBy(orderByModels).ToList();
}
/// <summary>
@@ -300,7 +319,7 @@
/// <param name="whereExpression"></param>
/// <param name="orderByFields"></param>
/// <returns></returns>
- public virtual List<TResult> QueryData<TResult>(Expression<Func<TEntity, TResult>> expression, Expression<Func<TEntity, bool>> whereExpression, string orderByFields)
+ public virtual List<TResult> QueryData<TResult>(Expression<Func<TEntity, TResult>> expression, Expression<Func<TEntity, bool>> whereExpression, string orderByFields = "")
{
return _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(orderByFields), orderByFields).WhereIF(whereExpression != null, whereExpression).Select(expression).ToList();
}
@@ -334,7 +353,7 @@
/// <param name="sql"></param>
/// <param name="parameters"></param>
/// <returns></returns>
- public virtual List<TEntity> QueryDataBySql(string sql, SugarParameter[] parameters = null)
+ public virtual List<TEntity> QueryDataBySql(string sql, SugarParameter[]? parameters = null)
{
return _db.Ado.SqlQuery<TEntity>(sql, parameters);
}
@@ -345,7 +364,7 @@
/// <param name="sql"></param>
/// <param name="parameters"></param>
/// <returns></returns>
- public virtual List<dynamic> QueryDynamicDataBySql(string sql, SugarParameter[] parameters = null)
+ public virtual List<dynamic> QueryDynamicDataBySql(string sql, SugarParameter[]? parameters = null)
{
return _db.Ado.SqlQuery<dynamic>(sql, parameters);
}
@@ -356,7 +375,7 @@
/// <param name="sql"></param>
/// <param name="parameters"></param>
/// <returns></returns>
- public virtual List<object> QueryObjectDataBySql(string sql, SugarParameter[] parameters = null)
+ public virtual List<object> QueryObjectDataBySql(string sql, SugarParameter[]? parameters = null)
{
return _db.Ado.SqlQuery<object>(sql, parameters);
}
@@ -378,7 +397,7 @@
/// <param name="sql"></param>
/// <param name="parameters"></param>
/// <returns></returns>
- public virtual DataTable QueryTable(string sql, SugarParameter[] parameters = null)
+ public virtual DataTable QueryTable(string sql, SugarParameter[]? parameters = null)
{
return _db.Ado.GetDataTable(sql, parameters);
}
@@ -443,7 +462,7 @@
/// <param name="pageSize"></param>
/// <param name="orderByFields"></param>
/// <returns></returns>
- public virtual PageGridData<TEntity> QueryPage(Expression<Func<TEntity, bool>> whereExpression, int pageIndex, int pageSize, string orderByFields = null)
+ public virtual PageGridData<TEntity> QueryPage(Expression<Func<TEntity, bool>> whereExpression, int pageIndex, int pageSize, string? orderByFields = null)
{
int totalCount = 0;
var list = _db.Queryable<TEntity>()
@@ -521,13 +540,25 @@
/// <param name="whereExpression"></param>
/// <returns></returns>
public virtual List<TResult> QueryTabs<T, T2, TResult>(
- Expression<Func<T, T2, object[]>> joinExpression,
- Expression<Func<T, T2, TResult>> selectExpression,
- Expression<Func<T, T2, bool>> whereExpressionT1,
- Expression<Func<TResult, bool>> whereExpression)
+ Expression<Func<T, T2, object[]>> joinExpression,
+ Expression<Func<T, T2, TResult>> selectExpression,
+ Expression<Func<T, T2, bool>> whereExpressionT1,
+ Expression<Func<TResult, bool>> whereExpression)
{
List<TResult> list = _db.Queryable(joinExpression).WhereIF(whereExpressionT1 != null, whereExpressionT1)
.Select(selectExpression)
+ .WhereIF(whereExpression != null, whereExpression).ToList();
+ return list;
+ }
+
+ public virtual List<TResult> QueryTabs<T, T2, TResult>(
+ Expression<Func<T, T2, bool>> joinExpression,
+ Expression<Func<T, T2, TResult>> selectExpression,
+ Expression<Func<T, bool>> whereExpressionT1,
+ Expression<Func<T2, bool>> whereExpressionT2,
+ Expression<Func<TResult, bool>> whereExpression)
+ {
+ List<TResult> list = _db.Queryable<T>().WhereIF(whereExpressionT1 != null, whereExpressionT1).InnerJoin(_db.Queryable<T2>().WhereIF(whereExpressionT2 != null, whereExpressionT2), joinExpression).Select(selectExpression)
.WhereIF(whereExpression != null, whereExpression).ToList();
return list;
}
@@ -544,7 +575,7 @@
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="orderByFields"></param>
- public virtual PageGridData<TResult> QueryTabsPage<T1, T2, TResult>(Expression<Func<T1, T2, object[]>> joinExpression, Expression<Func<T1, T2, TResult>> selectExpression, Expression<Func<TResult, bool>> whereExpression, int pageIndex, int pageSize, string orderByFields = null)
+ public virtual PageGridData<TResult> QueryTabsPage<T1, T2, TResult>(Expression<Func<T1, T2, object[]>> joinExpression, Expression<Func<T1, T2, TResult>> selectExpression, Expression<Func<TResult, bool>> whereExpression, int pageIndex, int pageSize, string? orderByFields = null)
{
int totalCount = 0;
List<TResult> list = _db.Queryable(joinExpression)
@@ -569,7 +600,7 @@
/// <param name="pageSize"></param>
/// <param name="orderByFields"></param>
/// <returns></returns>
- public virtual PageGridData<TResult> QueryTabsPage<T1, T2, TResult>(Expression<Func<T1, T2, object[]>> joinExpression, Expression<Func<T1, T2, TResult>> selectExpression, Expression<Func<TResult, bool>> whereExpression, Expression<Func<T1, object>> groupExpression, int pageIndex, int pageSize, string orderByFields = null)
+ public virtual PageGridData<TResult> QueryTabsPage<T1, T2, TResult>(Expression<Func<T1, T2, object[]>> joinExpression, Expression<Func<T1, T2, TResult>> selectExpression, Expression<Func<TResult, bool>> whereExpression, Expression<Func<T1, object>> groupExpression, int pageIndex, int pageSize, string? orderByFields = null)
{
int totalCount = 0;
List<TResult> list = _db.Queryable(joinExpression).GroupBy(groupExpression)
@@ -579,13 +610,6 @@
.ToPageList(pageIndex, pageSize, ref totalCount);
return new PageGridData<TResult>(totalCount, list);
}
-
- //List<TResult> QueryMuch<T, T2, T3, TResult>(
- // Expression<Func<T, T2, T3, object[]>> joinExpression,
- // Expression<Func<T, T2, T3, TResult>> selectExpression,
- // Expression<Func<T, T2, T3, bool>> whereLambda = null) where T : class, new(){throw new NotImplementedException();}
- //Task<PageModel<TEntity>> QueryPage(PaginationModel pagination){throw new NotImplementedException();}
-
public Task<TEntity> QureyDataByIdAsync(object id)
{
@@ -840,27 +864,103 @@
.WhereIF(whereExpression != null, whereExpression).ToListAsync();
}
- /// <summary>
- /// 鏉′欢鏌ヨ鏁版嵁骞舵帓搴�
- /// </summary>
- /// <param name="whereExpression"></param>
- /// <param name="orderByFields"></param>
- /// <returns></returns>
- public virtual List<TEntity> QueryData(Expression<Func<TEntity, bool>> whereExpression, Dictionary<string, OrderByType> orderBy)
+ public bool DeleteAndMoveIntoHty(TEntity entity, OperateType operateType)
{
- List<OrderByModel> orderByModels = new List<OrderByModel>();
- foreach (var item in orderBy)
+ Type type = entity.GetType();
+ Assembly assembly = type.Assembly;
+ Type? htyType = assembly.GetType(type.FullName + "_Hty");
+ if (htyType != null)
{
- OrderByModel orderByModel = new OrderByModel()
+ object? obj = Activator.CreateInstance(htyType);
+ PropertyInfo keyPro = typeof(TEntity).GetKeyProperty();
+ PropertyInfo? operateTypePro = htyType.GetProperty(nameof(OperateType));
+ PropertyInfo? sourceIdPro = htyType.GetProperty("SourceId");
+ if (obj != null && keyPro != null && operateTypePro != null && sourceIdPro != null)
{
- FieldName = item.Key,
- OrderByType = item.Value
- };
- orderByModels.Add(orderByModel);
+ operateTypePro.SetValue(obj, operateType.ToString());
+ sourceIdPro.SetValue(obj, keyPro.GetValue(entity));
+
+ List<PropertyInfo> propertyInfos = htyType.GetProperties().Where(x => x.Name != operateTypePro.Name && x.Name != sourceIdPro.Name && x.Name != keyPro.Name).ToList();
+
+ for (int i = 0; i < propertyInfos.Count; i++)
+ {
+ PropertyInfo propertyInfo = propertyInfos[i];
+ PropertyInfo? property = type.GetProperty(propertyInfo.Name);
+
+ if (property != null)
+ {
+ if (propertyInfo.Name == nameof(BaseEntity.Modifier))
+ {
+ propertyInfo.SetValue(obj, App.User.UserId > 0 ? App.User.UserName : App.User.UserId.ToString());
+ }
+ else if (propertyInfo.Name == nameof(BaseEntity.ModifyDate))
+ {
+ propertyInfo.SetValue(obj, DateTime.Now);
+ }
+ else
+ {
+ propertyInfo.SetValue(obj, property.GetValue(entity));
+ }
+ }
+ }
+ _db.InsertableByObject(obj).AS(type.Name + "_Hty").ExecuteCommand();
+ }
}
- return _db.Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).OrderBy(orderByModels).ToList();
+ return DeleteData(entity);
}
+ public bool DeleteAndMoveIntoHty(List<TEntity> entities, OperateType operateType)
+ {
+ Type type = typeof(TEntity);
+ Assembly assembly = type.Assembly;
+ Type? htyType = assembly.GetType(type.FullName + "_Hty");
+ if (htyType != null)
+ {
+ object? obj2 = Activator.CreateInstance(htyType);
+ PropertyInfo keyPro = typeof(TEntity).GetKeyProperty();
+ PropertyInfo? operateTypePro = htyType.GetProperty(nameof(OperateType));
+ PropertyInfo? sourceIdPro = htyType.GetProperty("SourceId");
+ if (obj2 != null && keyPro != null && operateTypePro != null && sourceIdPro != null)
+ {
+ List<PropertyInfo> propertyInfos = htyType.GetProperties().Where(x => x.Name != operateTypePro.Name && x.Name != sourceIdPro.Name && x.Name != keyPro.Name).ToList();
+ List<object> list = new List<object>();
+ foreach (var item in entities)
+ {
+ object? obj = Activator.CreateInstance(htyType);
+ if (obj != null)
+ {
+ operateTypePro.SetValue(obj, operateType.ToString());
+ sourceIdPro.SetValue(obj, keyPro.GetValue(item));
+ for (int i = 0; i < propertyInfos.Count; i++)
+ {
+ PropertyInfo propertyInfo = propertyInfos[i];
+ PropertyInfo? property = type.GetProperty(propertyInfo.Name);
+
+ if (property != null)
+ {
+ if (propertyInfo.Name == nameof(BaseEntity.Modifier))
+ {
+ propertyInfo.SetValue(obj, App.User.UserId > 0 ? App.User.UserName : App.User.UserId.ToString());
+ }
+ else if (propertyInfo.Name == nameof(BaseEntity.ModifyDate))
+ {
+ propertyInfo.SetValue(obj, DateTime.Now);
+ }
+ else
+ {
+ propertyInfo.SetValue(obj, property.GetValue(item));
+ }
+ }
+ }
+ list.Add(obj);
+ }
+ }
+ _db.InsertableByObject(list).AS(type.Name + "_Hty").ExecuteCommand();
+
+ }
+ }
+ return DeleteData(entities);
+ }
//List<TResult> QueryMuch<T, T2, T3, TResult>(
// Expression<Func<T, T2, T3, object[]>> joinExpression,
// Expression<Func<T, T2, T3, TResult>> selectExpression,
--
Gitblit v1.9.3