Browse Source

替换MERGE

master
赵新宇 4 weeks ago
parent
commit
6c512d5208
  1. 4
      API/TaskManager.EntityFramework/IRepository/IRepository.cs
  2. 341
      API/TaskManager.EntityFramework/Repository/Repository.cs
  3. 2
      API/TaskManager.EntityFramework/TaskManager.EntityFramework.csproj
  4. 2
      API/Wood.Admin.WebApi/Properties/PublishProfiles/FolderProfile.pubxml.user
  5. 5
      API/Wood.Service/Controllers/CheryRecurringJobInputPageController.cs
  6. 5
      API/Wood.Service/Controllers/CheryRecurringJobInputPageExtendController.cs
  7. 150
      API/Wood.Service/Controllers/CheryRecurringJobOutPageController.cs
  8. 7
      API/Wood.Service/Controllers/CherySupplierConDateService.cs
  9. 9
      API/Wood.Service/Controllers/CherySupplierConMmrpService.cs
  10. 7
      API/Wood.Service/Controllers/CherySupplierConPoService.cs
  11. 5
      API/Wood.Service/Controllers/CherySupplierEmployeeService.cs
  12. 5
      API/Wood.Service/Controllers/CherySupplierInfoService.cs
  13. 166
      API/Wood.Service/Controllers/CherySupplierMrpDataService.cs
  14. 103
      API/Wood.Service/Controllers/CherySupplierMrpMonthService.cs
  15. 83
      API/Wood.Service/Controllers/CherySupplierPoService.cs
  16. 5
      API/Wood.Service/Controllers/CherySupplierProProcessEquipmentService.cs
  17. 3
      API/Wood.Service/Controllers/LogServices/CherySupplierMrpMonthService.cs
  18. 3
      API/Wood.Service/Controllers/NormalBaseController.cs
  19. 2
      API/Wood.Service/Controllers/RecurringJobBaseController.cs
  20. 5
      API/Wood.Service/Controllers/TaskSubService.cs
  21. 147
      API/Wood.Service/Datas/SupplierEmployeeDtService.cs
  22. 119
      API/Wood.Service/Datas/SupplierInfoDtService.cs
  23. 146
      API/Wood.Service/Datas/SupplierProProcessEquipmentDtService.cs
  24. 4
      API/Wood.Service/Wood.Service.csproj

4
API/TaskManager.EntityFramework/IRepository/IRepository.cs

@ -8,7 +8,7 @@ using System.Threading.Tasks;
using TaskManager.Entity; using TaskManager.Entity;
using TaskManager.EntityFramework.Repository; using TaskManager.EntityFramework.Repository;
using Wood.Util.Filters; using Wood.Util.Filters;
using Z.BulkOperations;
namespace TaskManager.EntityFramework namespace TaskManager.EntityFramework
{ {
@ -27,9 +27,7 @@ namespace TaskManager.EntityFramework
/// </summary> /// </summary>
/// <param name="entities"></param> /// <param name="entities"></param>
/// <returns></returns> /// <returns></returns>
Task BlukMergeAsync(List<TEntity> entities, Action<BulkOperation<TEntity>> action);
Task BlukInsertAsync(List<TEntity> entities, Action<BulkOperation<TEntity>> action);
Task<PagedResult<TEntity>> GetPagedAsync(PagingParams pagingParams); Task<PagedResult<TEntity>> GetPagedAsync(PagingParams pagingParams);

341
API/TaskManager.EntityFramework/Repository/Repository.cs

@ -1,8 +1,10 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using Serilog; using Serilog;
using SkiaSharp;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data.Common;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Reflection; using System.Reflection;
@ -12,7 +14,7 @@ using TaskManager.Entity;
using TaskManager.EntityFramework; using TaskManager.EntityFramework;
using Wood.Util; using Wood.Util;
using Wood.Util.Filters; using Wood.Util.Filters;
using Z.BulkOperations;
namespace TaskManager.EntityFramework.Repository namespace TaskManager.EntityFramework.Repository
{ {
@ -69,17 +71,6 @@ namespace TaskManager.EntityFramework.Repository
} }
} }
public async Task BlukMergeAsync(List<TEntity> entities,Action<BulkOperation<TEntity>> action)
{
_context.BulkMerge(entities, action);
}
public async Task BlukInsertAsync(List<TEntity> entities, Action<BulkOperation<TEntity>> action)
{
_context.BulkInsert(entities, action);
}
@ -289,4 +280,330 @@ namespace TaskManager.EntityFramework.Repository
} }
} }
public static class EfCoreBulkExtensions
{
//private const int BatchSize = 1000;
private static int CalculateBatchSize(int propertyCount)
{
// 预留100个参数作为缓冲
const int maxParameters = 2000;
return Math.Max(1, maxParameters / propertyCount);
}
/// <summary>
/// EF Core 批量插入或更新扩展方法(支持复合主键)
/// </summary>
public static void BulkMerge<TEntity>(this DbContext context,
IEnumerable<TEntity> entities,
params Expression<Func<TEntity, object>>[] keySelectors)
where TEntity : class
{
if (context == null || entities == null || !entities.Any())
return;
using var transaction = context.Database.BeginTransaction();
try
{
Type entityType = typeof(TEntity);
string tableName = context.Model.FindEntityType(entityType).GetTableName();
string providerName = GetDatabaseProviderName(context);
// 获取所有主键属性
List<string> keyPropNames = keySelectors.Select(GetPropertyName).ToList();
List<PropertyInfo> keyProps = keyPropNames.Select(entityType.GetProperty).ToList();
// 获取所有非主键属性
PropertyInfo[] props = entityType.GetProperties()
.Where(p => !keyPropNames.Contains(p.Name)).ToArray();
// 计算实体的总属性数量
int totalProperties = keyProps.Count + props.Length;
// 动态计算批处理大小
int batchSize = CalculateBatchSize(totalProperties);
// 分批处理
var batches = entities.Chunk(batchSize);
foreach (var batch in batches)
{
// 临时表名
string tempTableName = $"#Temp_Bulk_{Guid.NewGuid().ToString("N").Substring(0, 8)}";
try
{
// 1. 创建临时表
string createSql = $"SELECT * INTO {tempTableName} FROM {tableName} WHERE 1 = 0";
context.Database.ExecuteSqlRaw(createSql);
// 2. 插入数据到临时表
InsertToTempTable(context, batch, tempTableName, keyProps, props);
// 3. 执行MERGE操作
ExecuteMerge(context, tableName, tempTableName, keyPropNames, props);
transaction.Commit();
}
finally
{
// 4. 清理临时表
DropTempTable(context, tempTableName);
}
}
}
catch (Exception ex)
{
transaction.Rollback();
Console.WriteLine($"批量操作失败: {ex.Message}");
throw;
}
}
/// <summary>
/// EF Core 批量插入或更新扩展方法(支持复合主键)
/// </summary>
//public static void BulkMerge<TEntity>(this DbContext context,
// IEnumerable<TEntity> entities,
// params Expression<Func<TEntity, object>>[] keySelectors)
// where TEntity : class
//{
// if (context == null || entities == null || !entities.Any())
// return;
// try
// {
// Type entityType = typeof(TEntity);
// string tableName = context.Model.FindEntityType(entityType).GetTableName();
// string providerName = GetDatabaseProviderName(context);
// // 获取所有主键属性
// List<string> keyPropNames = keySelectors.Select(GetPropertyName).ToList();
// List<PropertyInfo> keyProps = keyPropNames.Select(entityType.GetProperty).ToList();
// // 获取所有非主键属性
// PropertyInfo[] props = entityType.GetProperties()
// .Where(p => !keyPropNames.Contains(p.Name)).ToArray();
// // 分批处理
// var batches = entities.Chunk(BatchSize);
// foreach (var batch in batches)
// {
// // 临时表名
// string tempTableName = $"#Temp_Bulk_{Guid.NewGuid().ToString("N").Substring(0, 8)}";
// try
// {
// // 1. 创建临时表
// string createSql = $"SELECT * INTO {tempTableName} FROM {tableName} WHERE 1 = 0";
// context.Database.ExecuteSqlRaw(createSql);
// //CreateTempTable(context, tempTableName, keyProps, props, providerName);
// // 2. 插入数据到临时表
// InsertToTempTable(context, batch, tempTableName, keyProps, props);
// // 3. 执行MERGE操作
// ExecuteMerge(context, tableName, tempTableName, keyPropNames, props);
// }
// finally
// {
// // 4. 清理临时表
// DropTempTable(context, tempTableName);
// }
// }
// }
// catch (Exception ex)
// {
// Console.WriteLine($"批量操作失败: {ex.Message}");
// throw;
// }
//}
// 解析表达式获取属性名
private static string GetPropertyName<TEntity>(Expression<Func<TEntity, object>> expression)
{
if (expression.Body is UnaryExpression unary)
expression = (Expression<Func<TEntity, object>>)unary.Operand;
if (expression.Body is MemberExpression member)
return member.Member.Name;
throw new ArgumentException("表达式必须指向实体属性", nameof(expression));
}
// 创建临时表
private static void CreateTempTable(DbContext context, string tempTableName,
List<PropertyInfo> keyProps, PropertyInfo[] props, string providerName)
{
string keyConstraints = string.Join(" AND ", keyProps.Select(p => $"[{p.Name}]"));
string sql = $"CREATE TABLE {tempTableName} (" +
string.Join(", ", keyProps.Select(p => $"[{p.Name}] {GetSqlType(p.PropertyType, providerName)}")) +
", " +
string.Join(", ", props.Select(p => $"[{p.Name}] {GetSqlType(p.PropertyType, providerName)}")) +
", PRIMARY KEY (" + keyConstraints + ")" +
")";
context.Database.ExecuteSqlRaw(sql);
}
// 插入数据到临时表
private static void InsertToTempTable<TEntity>(DbContext context, IEnumerable<TEntity> entities,
string tempTableName, List<PropertyInfo> keyProps, PropertyInfo[] props)
{
// 构建参数化SQL
string paramPrefix = "@p";
int paramIndex = 0;
string values = string.Join(",\n", entities.Select(e =>
{
string row = "(";
// 添加主键参数
foreach (var keyProp in keyProps)
row += $"{paramPrefix}{paramIndex++}, ";
// 添加其他属性参数
foreach (var prop in props)
row += $"{paramPrefix}{paramIndex++}, ";
return row.TrimEnd(", ".ToCharArray()) + ")";
}));
string sql = $"INSERT INTO {tempTableName} ({GetColumnList(keyProps, props)}) VALUES {values}";
DbCommand cmd = context.Database.GetDbConnection().CreateCommand();
cmd.CommandText = sql;
// 添加参数
paramIndex = 0;
foreach (var entity in entities)
{
// 添加主键值
foreach (var keyProp in keyProps)
AddParameter(cmd, $"{paramPrefix}{paramIndex++}", keyProp.GetValue(entity));
// 添加其他属性值
foreach (var prop in props)
AddParameter(cmd, $"{paramPrefix}{paramIndex++}", prop.GetValue(entity));
}
context.Database.OpenConnection();
try { cmd.ExecuteNonQuery(); }
finally { context.Database.CloseConnection(); }
}
// 添加参数(防止SQL注入)
private static void AddParameter(DbCommand cmd, string paramName, object value)
{
DbParameter param = cmd.CreateParameter();
param.ParameterName = paramName;
param.Value = value ?? DBNull.Value;
cmd.Parameters.Add(param);
}
// 构建列名列表
private static string GetColumnList(List<PropertyInfo> keyProps, PropertyInfo[] props)
{
return string.Join(", ", keyProps.Select(p => $"[{p.Name}]")) + ", " +
string.Join(", ", props.Select(p => $"[{p.Name}]"));
}
// 获取SQL类型
private static string GetSqlType(Type type, string providerName)
{
type = Nullable.GetUnderlyingType(type) ?? type;
if (providerName.Contains("SqlServer"))
{
if (type == typeof(int)) return "INT";
if (type == typeof(long)) return "BIGINT";
if (type == typeof(short)) return "SMALLINT";
if (type == typeof(byte)) return "TINYINT";
if (type == typeof(bool)) return "BIT";
if (type == typeof(string)) return "NVARCHAR(MAX)";
if (type == typeof(DateTime)) return "DATETIME2";
if (type == typeof(DateTimeOffset)) return "DATETIMEOFFSET";
if (type == typeof(decimal)) return "DECIMAL(18, 2)";
if (type == typeof(float)) return "FLOAT";
if (type == typeof(double)) return "FLOAT";
if (type == typeof(Guid)) return "UNIQUEIDENTIFIER";
if (type == typeof(byte[])) return "VARBINARY(MAX)";
}
else if (providerName.Contains("PostgreSQL"))
{
if (type == typeof(int)) return "INTEGER";
if (type == typeof(long)) return "BIGINT";
if (type == typeof(short)) return "SMALLINT";
if (type == typeof(bool)) return "BOOLEAN";
if (type == typeof(string)) return "TEXT";
if (type == typeof(DateTime)) return "TIMESTAMP";
if (type == typeof(DateTimeOffset)) return "TIMESTAMPTZ";
if (type == typeof(decimal)) return "DECIMAL(18, 2)";
if (type == typeof(float)) return "REAL";
if (type == typeof(double)) return "DOUBLE PRECISION";
if (type == typeof(Guid)) return "UUID";
if (type == typeof(byte[])) return "BYTEA";
}
throw new NotSupportedException($"类型 {type.Name} 或数据库提供者 {providerName} 不支持");
}
// 执行MERGE操作
private static void ExecuteMerge(DbContext context, string tableName, string tempTableName,
List<string> keyPropNames, PropertyInfo[] props)
{
string onClause = string.Join(" AND ", keyPropNames.Select(k =>
$"target.[{k}] = source.[{k}]"));
string updateFields = string.Join(", ", props.Select(p =>
$"target.[{p.Name}] = source.[{p.Name}]"));
string sql = $"MERGE {tableName} AS target " +
$"USING {tempTableName} AS source " +
$"ON ({onClause}) " +
$"WHEN MATCHED THEN UPDATE SET {updateFields} " +
$"WHEN NOT MATCHED THEN " +
$"INSERT ({GetColumnList(keyPropNames, props)}) " +
$"VALUES ({string.Join(", ", keyPropNames.Concat(props.Select(p => $"source.[{p.Name}]")))});";
context.Database.ExecuteSqlRaw(sql);
}
// 删除临时表
private static void DropTempTable(DbContext context, string tempTableName)
{
context.Database.ExecuteSqlRaw($"DROP TABLE IF EXISTS {tempTableName}");
}
// 获取数据库提供者名称
private static string GetDatabaseProviderName(DbContext context)
{
return context.Database.ProviderName;
}
// 构建列名列表(重载版本)
private static string GetColumnList(List<string> keyPropNames, PropertyInfo[] props)
{
return string.Join(", ", keyPropNames.Select(k => $"[{k}]")) + ", " +
string.Join(", ", props.Select(p => $"[{p.Name}]"));
}
}
} }

2
API/TaskManager.EntityFramework/TaskManager.EntityFramework.csproj

@ -8,6 +8,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Dapper" Version="2.1.66" /> <PackageReference Include="Dapper" Version="2.1.66" />
<PackageReference Include="EFCore.BulkExtensions" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0"> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
@ -18,7 +19,6 @@
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Z.EntityFramework.Extensions.EFCore" Version="8.103.8.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

2
API/Wood.Admin.WebApi/Properties/PublishProfiles/FolderProfile.pubxml.user

@ -3,7 +3,7 @@
<Project> <Project>
<PropertyGroup> <PropertyGroup>
<_PublishTargetUrl>D:\QRAPI20250528\API\Wood.Admin.WebApi\bin\Release\net8.0\publish\</_PublishTargetUrl> <_PublishTargetUrl>D:\QRAPI20250528\API\Wood.Admin.WebApi\bin\Release\net8.0\publish\</_PublishTargetUrl>
<History>True|2025-06-30T07:39:43.7918723Z||;True|2025-06-30T14:40:36.2678533+08:00||;True|2025-06-30T14:22:36.2631903+08:00||;True|2025-06-30T09:23:23.0780295+08:00||;True|2025-06-28T10:37:00.4525422+08:00||;True|2025-06-27T14:51:18.0006510+08:00||;True|2025-06-27T14:46:36.7189818+08:00||;True|2025-06-25T10:54:54.0406425+08:00||;True|2025-06-24T15:53:07.6141315+08:00||;True|2025-06-24T15:48:22.4116425+08:00||;True|2025-06-24T15:47:33.3794364+08:00||;True|2025-06-24T15:21:28.5600646+08:00||;True|2025-06-23T17:18:30.1990173+08:00||;True|2025-06-23T17:12:33.6485743+08:00||;True|2025-06-19T17:18:07.6086155+08:00||;</History> <History>True|2025-07-01T10:51:45.0206266Z||;True|2025-06-30T15:39:43.7918723+08:00||;True|2025-06-30T14:40:36.2678533+08:00||;True|2025-06-30T14:22:36.2631903+08:00||;True|2025-06-30T09:23:23.0780295+08:00||;True|2025-06-28T10:37:00.4525422+08:00||;True|2025-06-27T14:51:18.0006510+08:00||;True|2025-06-27T14:46:36.7189818+08:00||;True|2025-06-25T10:54:54.0406425+08:00||;True|2025-06-24T15:53:07.6141315+08:00||;True|2025-06-24T15:48:22.4116425+08:00||;True|2025-06-24T15:47:33.3794364+08:00||;True|2025-06-24T15:21:28.5600646+08:00||;True|2025-06-23T17:18:30.1990173+08:00||;True|2025-06-23T17:12:33.6485743+08:00||;True|2025-06-19T17:18:07.6086155+08:00||;</History>
<LastFailureDetails /> <LastFailureDetails />
</PropertyGroup> </PropertyGroup>
</Project> </Project>

5
API/Wood.Service/Controllers/CheryRecurringJobInputPageController.cs

@ -1,5 +1,6 @@
using Azure.Core; using Azure.Core;
using Dapper; using Dapper;
using EFCore.BulkExtensions;
using Hangfire; using Hangfire;
using Magicodes.ExporterAndImporter.Core; using Magicodes.ExporterAndImporter.Core;
using Magicodes.ExporterAndImporter.Core.Extension; using Magicodes.ExporterAndImporter.Core.Extension;
@ -283,7 +284,7 @@ namespace TaskManager.Controllers
if (result.code == 200) if (result.code == 200)
{ {
await _logger.AddSuccess($"第 {i} 页奇瑞数据保存成功", TaskName, sub.TaskId, version); await _logger.AddSuccess($"第 {i} 页奇瑞数据保存成功", TaskName, sub.TaskId, version);
_jobDbContext.BulkUpdate(records, options => options.UseTableLock = true); await _jobDbContext.BulkUpdateAsync(records);
List<TLOGS> logs = new List<TLOGS>(); List<TLOGS> logs = new List<TLOGS>();
foreach (var itm in records) foreach (var itm in records)
@ -298,7 +299,7 @@ namespace TaskManager.Controllers
logs.Add(log); logs.Add(log);
} }
_jobDbContext.BulkInsert(logs, options => options.UseTableLock = true); _jobDbContext.BulkInsert(logs);
await UpdateAfter(records); await UpdateAfter(records);
sub.SyncedPageCount = i; sub.SyncedPageCount = i;

5
API/Wood.Service/Controllers/CheryRecurringJobInputPageExtendController.cs

@ -1,5 +1,6 @@
using Azure.Core; using Azure.Core;
using Dapper; using Dapper;
using EFCore.BulkExtensions;
using Hangfire; using Hangfire;
using Magicodes.ExporterAndImporter.Core; using Magicodes.ExporterAndImporter.Core;
using Magicodes.ExporterAndImporter.Core.Extension; using Magicodes.ExporterAndImporter.Core.Extension;
@ -350,7 +351,7 @@ namespace TaskManager.Controllers
using (var transaction = await _jobDbContext.Database.BeginTransactionAsync()) using (var transaction = await _jobDbContext.Database.BeginTransactionAsync())
{ {
var tran = transaction.GetDbTransaction(); var tran = transaction.GetDbTransaction();
await _jobDbContext.BulkUpdateAsync(records, options => { options.UseTableLock = false; }); await _jobDbContext.BulkUpdateAsync(records);
List<TLOGS> logs = new List<TLOGS>(); List<TLOGS> logs = new List<TLOGS>();
foreach (var itm in records) foreach (var itm in records)
@ -557,7 +558,7 @@ namespace TaskManager.Controllers
using (var transaction = await _jobDbContext.Database.BeginTransactionAsync()) using (var transaction = await _jobDbContext.Database.BeginTransactionAsync())
{ {
var tran = transaction.GetDbTransaction(); var tran = transaction.GetDbTransaction();
await _jobDbContext.BulkUpdateAsync(records, options => { options.UseTableLock = false; }); await _jobDbContext.BulkUpdateAsync(records);
List<TLOGS> logs = new List<TLOGS>(); List<TLOGS> logs = new List<TLOGS>();
foreach (var itm in records) foreach (var itm in records)
{ {

150
API/Wood.Service/Controllers/CheryRecurringJobOutPageController.cs

@ -1,4 +1,6 @@
using Magicodes.ExporterAndImporter.Core; using EfCore.BulkOperations;
using EFCore.BulkExtensions;
using Magicodes.ExporterAndImporter.Core;
using Magicodes.ExporterAndImporter.Core.Extension; using Magicodes.ExporterAndImporter.Core.Extension;
using Magicodes.ExporterAndImporter.Excel; using Magicodes.ExporterAndImporter.Excel;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
@ -58,6 +60,7 @@ namespace TaskManager.Controllers
{ {
var tran = transaction.GetDbTransaction(); var tran = transaction.GetDbTransaction();
var taskId=list.First().TaskId; var taskId=list.First().TaskId;
var requestDate = list.First().RequestDate;
var version = list.First().RequestDate.Replace("-", string.Empty); var version = list.First().RequestDate.Replace("-", string.Empty);
List<TLOGS> logs = new List<TLOGS>(); List<TLOGS> logs = new List<TLOGS>();
foreach (var itm in list) foreach (var itm in list)
@ -71,9 +74,73 @@ namespace TaskManager.Controllers
} }
try try
{ {
var ids=list.Select(p => p.Id);
await _jobDbContext.BulkMergeAsync(list, options => { options.ColumnPrimaryKeyExpression = p => p.Id; options.Transaction = tran; });
await _jobDbContext.BulkMergeAsync(logs, options => { options.ColumnPrimaryKeyExpression = p =>new { p.Id,p.RequestDate };options.Transaction = tran; }); //日志
var existListLogs = await _jobDbContext.Set<TLOGS>().Where(p => ids.Contains(p.Id) && p.RequestDate==requestDate).ToListAsync();
if (existListLogs.Any())
{
foreach (var itm in existListLogs)
{
var first = logs.FirstOrDefault(p => p.Id == itm.Id && p.RequestDate == requestDate);
if (first != null)
{
itm.InjectFrom(first);
}
}
}
else
{
existListLogs = new List<TLOGS>();
}
var queryLogs = from item in logs
join existItem in existListLogs
on new { item.Id, item.RequestDate } equals new { existItem.Id, existItem.RequestDate } into gj
from subItem in gj.DefaultIfEmpty()
where subItem == null
select item;
_jobDbContext.BulkUpdate(existListLogs.ToList());
_jobDbContext.BulkInsert(queryLogs.ToList());
//记录
var existList = await _jobDbContext.Set<T>().Where(p => ids.Contains(p.Id)).ToListAsync();
if (existList.Any())
{
foreach (var itm in existList)
{
var first = list.FirstOrDefault(p => p.Id == itm.Id);
if (first != null)
{
itm.InjectFrom(first);
}
}
}
else
{
existList = new List<T>();
}
var query = from item in list
join existItem in existList
on item.Id equals existItem.Id into gj
from subItem in gj.DefaultIfEmpty()
where subItem == null
select item;
_jobDbContext.BulkUpdate(existList.ToList());
_jobDbContext.BulkInsert(query.ToList());
//_jobDbContext.BulkInsertOrUpdate
// await _jobDbContext.BulkMergeAsync(list, options => { options.ColumnPrimaryKeyExpression = p => p.Id; options.Transaction = tran; });
// await _jobDbContext.BulkMergeAsync(logs, options => { options.ColumnPrimaryKeyExpression = p =>new { p.Id,p.RequestDate };options.Transaction = tran; });
//}); //});
await ConfirmDataInsertAsync(list, _jobDbContext, tran); await ConfirmDataInsertAsync(list, _jobDbContext, tran);
// 提交事务 // 提交事务
@ -130,37 +197,9 @@ namespace TaskManager.Controllers
pagefirstList.Add(entity); pagefirstList.Add(entity);
allData.Add(itm); allData.Add(itm);
} }
//if (readedcount > 0)
//{
// var listrows = firstResponse.Data.Rows.Where(p => !ids.Contains(p.Id));
// foreach (var itm in firstResponse.Data.Rows)
// {
// T entity = new T();
// entity.InjectFrom(itm);
// entity.CreationTime = DateTime.Now;
// pagefirstList.Add(entity);
// allData.Add(itm);
// }
//}
//else
//{
// foreach (var itm in firstResponse.Data.Rows)
// {
// T entity = new T();
// entity.InjectFrom(itm);
// entity.CreationTime = DateTime.Now;
// pagefirstList.Add(entity);
// allData.Add(itm);
// }
//}
if (pagefirstList.Any()) if (pagefirstList.Any())
{ {
await InsertDataAsync(pagefirstList); await InsertDataAsync(pagefirstList);
} }
// 计算总页数 // 计算总页数
int totalPages = (int)Math.Ceiling((double)totalItems / pageSize); int totalPages = (int)Math.Ceiling((double)totalItems / pageSize);
@ -187,30 +226,6 @@ namespace TaskManager.Controllers
allData.Add(itm); allData.Add(itm);
} }
//if (readedcount > 0)
//{
// var listrows = pageResponse.Data.Rows.Where(p => !ids.Contains(p.Id));
// foreach (var itm in pageResponse.Data.Rows)
// {
// T entity = new T();
// entity.InjectFrom(itm);
// entity.CreationTime = DateTime.Now;
// pageList.Add(entity);
// allData.Add(itm);
// }
//}
//else
//{
// foreach (var itm in pageResponse.Data.Rows)
// {
// T entity = new T();
// entity.InjectFrom(itm);
// entity.CreationTime = DateTime.Now;
// pageList.Add(entity);
// allData.Add(itm);
// }
//}
if (pageList.Any()) if (pageList.Any())
{ {
await InsertDataAsync(pageList); await InsertDataAsync(pageList);
@ -260,31 +275,6 @@ namespace TaskManager.Controllers
entity.RequestDate = date; entity.RequestDate = date;
allData.Add(itm); allData.Add(itm);
} }
//if (readedcount > 0)
//{
// var listrows = firstResponse.Data.Rows.Where(p => !ids.Contains(p.Id));
// foreach (var itm in firstResponse.Data.Rows)
// {
// T entity = new T();
// entity.InjectFrom(itm);
// entity.CreationTime = DateTime.Now;
// pagefirstList.Add(entity);
// allData.Add(itm);
// }
//}
//else
//{
// foreach (var itm in firstResponse.Data.Rows)
// {
// T entity = new T();
// entity.InjectFrom(itm);
// entity.CreationTime = DateTime.Now;
// pagefirstList.Add(entity);
// allData.Add(itm);
// }
//}
if (pagefirstList.Any()) if (pagefirstList.Any())
{ {
await InsertDataAsync(pagefirstList); await InsertDataAsync(pagefirstList);

7
API/Wood.Service/Controllers/CherySupplierConDateService.cs

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc; using EFCore.BulkExtensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage;
using System.Collections.Generic; using System.Collections.Generic;
@ -82,7 +83,7 @@ namespace TaskManager.Controllers
var tran = transaction.GetDbTransaction(); var tran = transaction.GetDbTransaction();
try try
{ {
await _jobDbContext.BulkUpdateAsync(entites, options => { options.Transaction = tran; }); await _jobDbContext.BulkUpdateAsync(entites);
await _jobDbContext.AddAsync(task); await _jobDbContext.AddAsync(task);
_jobDbContext.SaveChanges(); _jobDbContext.SaveChanges();
@ -108,7 +109,7 @@ namespace TaskManager.Controllers
[HttpPost] [HttpPost]
public async Task<ActionResult> BatchUpdate([FromBody] List<SUPPLIER_CON_DATE> entites) public async Task<ActionResult> BatchUpdate([FromBody] List<SUPPLIER_CON_DATE> entites)
{ {
await _jobDbContext.BulkUpdateAsync(entites, options => { options.ColumnPrimaryKeyExpression = p => p.UId; options.UseTableLock = false; }); await _jobDbContext.BulkUpdateAsync(entites);
return new JsonResult(new { Code = 200, Message = "批量修改成功!" }); return new JsonResult(new { Code = 200, Message = "批量修改成功!" });

9
API/Wood.Service/Controllers/CherySupplierConMmrpService.cs

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc; using EFCore.BulkExtensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
@ -84,7 +85,7 @@ namespace TaskManager.Controllers
var tran = transaction.GetDbTransaction(); var tran = transaction.GetDbTransaction();
try try
{ {
await _jobDbContext.BulkUpdateAsync(entites, options => { options.Transaction = tran; }); await _jobDbContext.BulkUpdateAsync(entites);
await _jobDbContext.AddAsync(task); await _jobDbContext.AddAsync(task);
_jobDbContext.SaveChanges(); _jobDbContext.SaveChanges();
@ -111,7 +112,9 @@ namespace TaskManager.Controllers
public async Task<ActionResult> BatchUpdate([FromBody] List<SUPPLIER_CON_MMRP> entites) public async Task<ActionResult> BatchUpdate([FromBody] List<SUPPLIER_CON_MMRP> entites)
{ {
await _jobDbContext.BulkUpdateAsync(entites, options => { options.ColumnPrimaryKeyExpression = p => p.UId; options.UseTableLock = false; });
await _jobDbContext.BulkUpdateAsync(entites);
return new JsonResult(new { Code = 200, Message = "批量修改成功!" }); return new JsonResult(new { Code = 200, Message = "批量修改成功!" });

7
API/Wood.Service/Controllers/CherySupplierConPoService.cs

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc; using EFCore.BulkExtensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage;
using System.Collections.Generic; using System.Collections.Generic;
@ -85,7 +86,7 @@ namespace TaskManager.Controllers
var tran = transaction.GetDbTransaction(); var tran = transaction.GetDbTransaction();
try try
{ {
await _jobDbContext.BulkUpdateAsync(entites, options => { options.Transaction = tran; }); await _jobDbContext.BulkUpdateAsync(entites);
await _jobDbContext.AddAsync(task); await _jobDbContext.AddAsync(task);
_jobDbContext.SaveChanges(); _jobDbContext.SaveChanges();
@ -108,7 +109,7 @@ namespace TaskManager.Controllers
[HttpPost] [HttpPost]
public async Task<ActionResult> BatchUpdate([FromBody] List<SUPPLIER_CON_PO> entites) public async Task<ActionResult> BatchUpdate([FromBody] List<SUPPLIER_CON_PO> entites)
{ {
await _jobDbContext.BulkUpdateAsync(entites, options => { options.ColumnPrimaryKeyExpression = p => p.UId; options.UseTableLock = false; }); await _jobDbContext.BulkUpdateAsync(entites);
return new JsonResult(new { Code = 200, Message = "批量修改成功!" }); return new JsonResult(new { Code = 200, Message = "批量修改成功!" });

5
API/Wood.Service/Controllers/CherySupplierEmployeeService.cs

@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore; using EFCore.BulkExtensions;
using Microsoft.EntityFrameworkCore;
using TaskManager.Contracts.Dtos; using TaskManager.Contracts.Dtos;
using TaskManager.Entity; using TaskManager.Entity;
using TaskManager.EntityFramework; using TaskManager.EntityFramework;
@ -53,7 +54,7 @@ namespace TaskManager.Controllers
entity.ReadState = true; entity.ReadState = true;
entity.WriteState = true; entity.WriteState = true;
} }
_jobDbContext.BulkUpdate(entities); await _jobDbContext.BulkUpdateAsync(entities);
} }

5
API/Wood.Service/Controllers/CherySupplierInfoService.cs

@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore; using EFCore.BulkExtensions;
using Microsoft.EntityFrameworkCore;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using System.Security.Cryptography; using System.Security.Cryptography;
using TaskManager.Contracts.Dtos; using TaskManager.Contracts.Dtos;
@ -53,7 +54,7 @@ namespace TaskManager.Controllers
entity.ReadState = true; entity.ReadState = true;
entity.WriteState = true; entity.WriteState = true;
} }
_jobDbContext.BulkUpdate(entities); await _jobDbContext.BulkUpdateAsync(entities);
} }

166
API/Wood.Service/Controllers/CherySupplierMrpDataService.cs

@ -1,10 +1,17 @@
using System.Data.Common; using EFCore.BulkExtensions;
using Microsoft.EntityFrameworkCore;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using Omu.ValueInjecter;
using Org.BouncyCastle.Crypto;
using System.Collections.Generic;
using System.Data.Common;
using TaskManager.Contracts.Dtos; using TaskManager.Contracts.Dtos;
using TaskManager.Controllers; using TaskManager.Controllers;
using TaskManager.Entity; using TaskManager.Entity;
using TaskManager.Entity.Entitys; using TaskManager.Entity.Entitys;
using TaskManager.EntityFramework; using TaskManager.EntityFramework;
using TaskManager.EntityFramework; using TaskManager.EntityFramework;
using TaskManager.EntityFramework.Repository;
namespace TaskManager.Controllers namespace TaskManager.Controllers
{ {
@ -21,8 +28,125 @@ namespace TaskManager.Controllers
{ {
if (plist.Count > 0) if (plist.Count > 0)
{ {
//List<SUPPLIER_CON_DATE> list = new List<SUPPLIER_CON_DATE>();
//plist.ForEach(p =>
//{
// var con = new SUPPLIER_CON_DATE();
// con.Id=p.Id;
// con.SupplierCode = "8EG";
// con.ReleaseEdition = p.ReleaseEdition;
// con.MaterialCode = p.MaterialCode;
// con.PlantId = p.PlantId;
// con.FeedbackResults = "0";
// con.VentureType = "";
// con.VentureSpecific = "";
// con.Measures = "";
// con.StartDate = p.StartDate;
// con.QuantityMeet1 =p.QuantityDemand1==null? p.QuantityDemand1.Value : 0 ;
// con.QuantityMeet2 = p.QuantityDemand2 == null ? p.QuantityDemand2.Value : 0;
// con.QuantityMeet3 =p.QuantityDemand3 ;
// con.QuantityMeet4 =p.QuantityDemand4 ;
// con.QuantityMeet5 =p.QuantityDemand5 ;
// con.QuantityMeet6 =p.QuantityDemand6 ;
// con.QuantityMeet7 =p.QuantityDemand7 ;
// con.QuantityMeet8 =p.QuantityDemand8 ;
// con.QuantityMeet9 =p.QuantityDemand9 ;
// con.QuantityMeet10 =p.QuantityDemand10 ;
// con.QuantityMeet11 =p.QuantityDemand11 ;
// con.QuantityMeet12 =p.QuantityDemand12 ;
// con.QuantityMeet13 =p.QuantityDemand13 ;
// con.QuantityMeet14 =p.QuantityDemand14 ;
// con.QuantityMeet15 =p.QuantityDemand15 ;
// con.QuantityMeet16 =p.QuantityDemand16 ;
// con.QuantityMeet17 =p.QuantityDemand17 ;
// con.QuantityMeet18 =p.QuantityDemand18 ;
// con.QuantityMeet19 =p.QuantityDemand19 ;
// con.QuantityMeet20 =p.QuantityDemand20 ;
// con.QuantityMeet21 =p.QuantityDemand21 ;
// con.QuantityMeet22 =p.QuantityDemand22 ;
// con.QuantityMeet23 =p.QuantityDemand23 ;
// con.QuantityMeet24 =p.QuantityDemand24 ;
// con.QuantityMeet25 =p.QuantityDemand25 ;
// con.QuantityMeet26 =p.QuantityDemand26 ;
// con.QuantityMeet27 =p.QuantityDemand27 ;
// con.QuantityMeet28 =p.QuantityDemand28 ;
// con.QuantityMeet29 =p.QuantityDemand29 ;
// con.QuantityMeet30 =p.QuantityDemand30 ;
// con.QuantityMeet31 = p.QuantityDemand31;
// con.CreationTime = DateTime.Now;
// list.Add(con);
//});
var ids=plist.Select(p => p.Id);
var existList = await _jobDbContext.Set<SUPPLIER_CON_DATE>().Where(p => ids.Contains(p.Id) && p.ReadState==false).ToListAsync();
if (existList.Any())
{
foreach (var itm in existList)
{
var first = plist.FirstOrDefault(p => p.Id == itm.Id);
if (first != null)
{
itm.Id = first.Id;
itm.SupplierCode = "8EG";
itm.ReleaseEdition = first.ReleaseEdition;
itm.MaterialCode = first.MaterialCode;
itm.PlantId = first.PlantId;
itm.FeedbackResults = "0";
itm.VentureType = "";
itm.VentureSpecific = "";
itm.Measures = "";
itm.StartDate = first.StartDate;
itm.QuantityMeet1 = first.QuantityDemand1 == null ? first.QuantityDemand1.Value : 0;
itm.QuantityMeet2 = first.QuantityDemand2 == null ? first.QuantityDemand2.Value : 0;
itm.QuantityMeet3 = first.QuantityDemand3;
itm.QuantityMeet4 = first.QuantityDemand4;
itm.QuantityMeet5 = first.QuantityDemand5;
itm.QuantityMeet6 = first.QuantityDemand6;
itm.QuantityMeet7 = first.QuantityDemand7;
itm.QuantityMeet8 = first.QuantityDemand8;
itm.QuantityMeet9 = first.QuantityDemand9;
itm.QuantityMeet10 = first.QuantityDemand10;
itm.QuantityMeet11 = first.QuantityDemand11;
itm.QuantityMeet12 = first.QuantityDemand12;
itm.QuantityMeet13 = first.QuantityDemand13;
itm.QuantityMeet14 = first.QuantityDemand14;
itm.QuantityMeet15 = first.QuantityDemand15;
itm.QuantityMeet16 = first.QuantityDemand16;
itm.QuantityMeet17 = first.QuantityDemand17;
itm.QuantityMeet18 = first.QuantityDemand18;
itm.QuantityMeet19 = first.QuantityDemand19;
itm.QuantityMeet20 = first.QuantityDemand20;
itm.QuantityMeet21 = first.QuantityDemand21;
itm.QuantityMeet22 = first.QuantityDemand22;
itm.QuantityMeet23 = first.QuantityDemand23;
itm.QuantityMeet24 = first.QuantityDemand24;
itm.QuantityMeet25 = first.QuantityDemand25;
itm.QuantityMeet26 = first.QuantityDemand26;
itm.QuantityMeet27 = first.QuantityDemand27;
itm.QuantityMeet28 = first.QuantityDemand28;
itm.QuantityMeet29 = first.QuantityDemand29;
itm.QuantityMeet30 = first.QuantityDemand30;
itm.QuantityMeet31 = first.QuantityDemand31;
itm.CreationTime = DateTime.Now;
}
}
}
if(existList.Any())
{
_jobDbContext.BulkUpdate(existList.ToList());
}
var query = from item in plist
join existItem in existList
on item.Id equals existItem.Id into gj
from subItem in gj.DefaultIfEmpty()
where subItem == null
select item;
List < SUPPLIER_CON_DATE > list = new List<SUPPLIER_CON_DATE>(); List < SUPPLIER_CON_DATE > list = new List<SUPPLIER_CON_DATE>();
plist.ForEach(p => foreach (var p in query)
{ {
var con = new SUPPLIER_CON_DATE(); var con = new SUPPLIER_CON_DATE();
@ -69,15 +193,45 @@ namespace TaskManager.Controllers
con.QuantityMeet31 = p.QuantityDemand31; con.QuantityMeet31 = p.QuantityDemand31;
con.CreationTime = DateTime.Now; con.CreationTime = DateTime.Now;
list.Add(con); list.Add(con);
}); }
_jobDbContext.BulkInsert(list);
//else
//{
// existList = new List<SUPPLIER_CON_DATE>();
//}
//var query = from item in list
// join existItem in existList
// on item.Id equals existItem.Id into gj
// from subItem in gj.DefaultIfEmpty()
// where subItem == null
// select item;
//_jobDbContext.BulkUpdate(existList.ToList());
//_jobDbContext.BulkInsert(query.ToList());
//dbContext.BulkInsert(list);
//dbContext.BulkMerge(list,
// p=> p.Id,
// p=> p.ReadState
// );
await dbContext.BulkMergeAsync(list, options => { options.Transaction = dbTransaction; options.UseTableLock = false; //await dbContext.BulkMergeAsync(list, options => { options.Transaction = dbTransaction; options.UseTableLock = false;
options.ColumnPrimaryKeyExpression = p =>new { p.Id, p.ReadState} ; // options.ColumnPrimaryKeyExpression = p =>new { p.Id, p.ReadState} ;
}); //});
} }
return; return;
} }

103
API/Wood.Service/Controllers/CherySupplierMrpMonthService.cs

@ -1,4 +1,5 @@
using Magicodes.ExporterAndImporter.Core; using EFCore.BulkExtensions;
using Magicodes.ExporterAndImporter.Core;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System.Data.Common; using System.Data.Common;
@ -8,8 +9,8 @@ using TaskManager.Controllers;
using TaskManager.Entity; using TaskManager.Entity;
using TaskManager.Entity.Entitys; using TaskManager.Entity.Entitys;
using TaskManager.EntityFramework; using TaskManager.EntityFramework;
using Z.BulkOperations; using TaskManager.EntityFramework.Repository;
using Z.EntityFramework.Extensions;
namespace TaskManager.Controllers namespace TaskManager.Controllers
@ -45,9 +46,91 @@ namespace TaskManager.Controllers
{ {
if (plist.Count > 0) if (plist.Count > 0)
{ {
//List<SUPPLIER_CON_MMRP> list = new List<SUPPLIER_CON_MMRP>();
//plist.ForEach(p =>
//{
// var con = new SUPPLIER_CON_MMRP();
// con.Id = p.Id;
// con.SupplierCode = "8EG";
// con.ReleaseEdition = p.ReleaseEdition;
// con.MaterialCode = p.MaterialCode;
// con.PlantId = p.PlantId;
// con.FeedbackResults = "0";
// con.VentureType = "";
// con.VentureSpecific = "";
// con.Measures = "";
// con.StartMonth = p.StartMonth;
// con.QuantityMeet1 = p.QuantityDemand1;
// con.QuantityMeet2 = p.QuantityDemand2;
// con.QuantityMeet3 = p.QuantityDemand3;
// con.QuantityMeet4 = p.QuantityDemand4;
// con.QuantityMeet5 = p.QuantityDemand5;
// con.QuantityMeet6 = p.QuantityDemand6;
// con.QuantityMeet7 = p.QuantityDemand7;
// con.QuantityMeet8 = p.QuantityDemand8;
// con.QuantityMeet9 = p.QuantityDemand9;
// con.QuantityMeet10 = p.QuantityDemand10;
// con.QuantityMeet11 = p.QuantityDemand11;
// con.QuantityMeet12 = p.QuantityDemand12;
// con.CreationTime = DateTime.Now;
// list.Add(con);
//});
//dbContext.BulkInsert(list);
var ids = plist.Select(p => p.Id);
var existList = await _jobDbContext.Set<SUPPLIER_CON_MMRP>().Where(p => ids.Contains(p.Id) && p.ReadState == false).ToListAsync();
if (existList.Any())
{
foreach (var itm in existList)
{
var first = plist.FirstOrDefault(p => p.Id == itm.Id);
if (first != null)
{
itm.Id = first.Id;
itm.SupplierCode = "8EG";
itm.ReleaseEdition = first.ReleaseEdition;
itm.MaterialCode = first.MaterialCode;
itm.PlantId = first.PlantId;
itm.FeedbackResults = "0";
itm.VentureType = "";
itm.VentureSpecific = "";
itm.Measures = "";
itm.StartMonth = first.StartMonth;
itm.QuantityMeet1 = first.QuantityDemand1;
itm.QuantityMeet2 = first.QuantityDemand2;
itm.QuantityMeet3 = first.QuantityDemand3;
itm.QuantityMeet4 = first.QuantityDemand4;
itm.QuantityMeet5 = first.QuantityDemand5;
itm.QuantityMeet6 = first.QuantityDemand6;
itm.QuantityMeet7 = first.QuantityDemand7;
itm.QuantityMeet8 = first.QuantityDemand8;
itm.QuantityMeet9 = first.QuantityDemand9;
itm.QuantityMeet10 = first.QuantityDemand10;
itm.QuantityMeet11 = first.QuantityDemand11;
itm.QuantityMeet12 = first.QuantityDemand12;
itm.CreationTime = DateTime.Now;
}
}
}
if (existList.Any())
{
_jobDbContext.BulkUpdate(existList.ToList());
}
var query = from item in plist
join existItem in existList
on item.Id equals existItem.Id into gj
from subItem in gj.DefaultIfEmpty()
where subItem == null
select item;
List<SUPPLIER_CON_MMRP> list = new List<SUPPLIER_CON_MMRP>(); List<SUPPLIER_CON_MMRP> list = new List<SUPPLIER_CON_MMRP>();
plist.ForEach(p => foreach (var p in query)
{ {
var con = new SUPPLIER_CON_MMRP(); var con = new SUPPLIER_CON_MMRP();
con.Id = p.Id; con.Id = p.Id;
con.SupplierCode = "8EG"; con.SupplierCode = "8EG";
@ -73,14 +156,12 @@ namespace TaskManager.Controllers
con.QuantityMeet12 = p.QuantityDemand12; con.QuantityMeet12 = p.QuantityDemand12;
con.CreationTime = DateTime.Now; con.CreationTime = DateTime.Now;
list.Add(con); list.Add(con);
}); }
_jobDbContext.BulkInsert(list);
await dbContext.BulkMergeAsync(list, options=> { options.Transaction = dbTransaction; options.UseTableLock = false;
options.ColumnPrimaryKeyExpression = p =>new { p.Id, p.ReadState };
}); //await dbContext.BulkMergeAsync(list, options=> { options.Transaction = dbTransaction; options.UseTableLock = false;
// options.ColumnPrimaryKeyExpression = p =>new { p.Id, p.ReadState };
//});
} }
return; return;
} }

83
API/Wood.Service/Controllers/CherySupplierPoService.cs

@ -1,9 +1,12 @@
using System.Data.Common; using EFCore.BulkExtensions;
using Microsoft.EntityFrameworkCore;
using System.Data.Common;
using TaskManager.Contracts.Dtos; using TaskManager.Contracts.Dtos;
using TaskManager.Controllers; using TaskManager.Controllers;
using TaskManager.Entity; using TaskManager.Entity;
using TaskManager.Entity.Entitys; using TaskManager.Entity.Entitys;
using TaskManager.EntityFramework; using TaskManager.EntityFramework;
using TaskManager.EntityFramework.Repository;
namespace TaskManager.Controllers namespace TaskManager.Controllers
@ -20,8 +23,67 @@ namespace TaskManager.Controllers
{ {
if (plist.Count > 0) if (plist.Count > 0)
{ {
//List<SUPPLIER_CON_PO> list = new List<SUPPLIER_CON_PO>();
//plist.ForEach(p =>
//{
// var con = new SUPPLIER_CON_PO();
// con.Id = p.Id;
// con.SupplierCode = "8EG";
// con.PurchaseOrder =p.PurchaseOrder ;
// con.SerialNumber =p.SerialNumber ;
// con.QuantityMeet =p.QuantityDelivery==null? p.QuantityDelivery.Value : 0 ;
// con.FeedbackResults ="0" ;
// con.VentureType ="" ;
// con.VentureSpecific ="" ;
// con.Measures ="";
// con.CreationTime = DateTime.Now;
// list.Add(con);
//});
//dbContext.BulkInsert(list);
var ids = plist.Select(p => p.Id);
var existList = await _jobDbContext.Set<SUPPLIER_CON_PO>().Where(p => ids.Contains(p.Id) && p.ReadState == false).ToListAsync();
if (existList.Any())
{
foreach (var itm in existList)
{
var first = plist.FirstOrDefault(p => p.Id == itm.Id);
if (first != null)
{
itm.Id = first.Id;
itm.SupplierCode = "8EG";
itm.PurchaseOrder = first.PurchaseOrder;
itm.SerialNumber =first.SerialNumber;
itm.QuantityMeet = first.QuantityDelivery == null ? first.QuantityDelivery.Value : 0;
itm.FeedbackResults = "0";
itm.VentureType = "";
itm.VentureSpecific = "";
itm.Measures = "";
itm.CreationTime = DateTime.Now;
}
}
}
if (existList.Any())
{
_jobDbContext.BulkUpdate(existList.ToList());
}
var query = from item in plist
join existItem in existList
on item.Id equals existItem.Id into gj
from subItem in gj.DefaultIfEmpty()
where subItem == null
select item;
List<SUPPLIER_CON_PO> list = new List<SUPPLIER_CON_PO>(); List<SUPPLIER_CON_PO> list = new List<SUPPLIER_CON_PO>();
plist.ForEach(p => foreach (var p in query)
{ {
var con = new SUPPLIER_CON_PO(); var con = new SUPPLIER_CON_PO();
con.Id = p.Id; con.Id = p.Id;
@ -34,19 +96,24 @@ namespace TaskManager.Controllers
con.VentureType = ""; con.VentureType = "";
con.VentureSpecific = ""; con.VentureSpecific = "";
con.Measures = ""; con.Measures = "";
con.CreationTime = DateTime.Now; con.CreationTime = DateTime.Now;
list.Add(con);
}
_jobDbContext.BulkInsert(list);
list.Add(con); //dbContext.BulkMerge(list,
}); // p => p.Id,
// p => p.ReadState
await dbContext.BulkMergeAsync(list, options => { options.Transaction = dbTransaction; options.UseTableLock = false; // );
//await dbContext.BulkMergeAsync(list, options => { options.Transaction = dbTransaction; options.UseTableLock = false;
options.ColumnPrimaryKeyExpression = p => new { p.Id, p.ReadState}; // options.ColumnPrimaryKeyExpression = p => new { p.Id, p.ReadState};
}); //});
} }
return; return;
} }

5
API/Wood.Service/Controllers/CherySupplierProProcessEquipmentService.cs

@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore; using EFCore.BulkExtensions;
using Microsoft.EntityFrameworkCore;
using TaskManager.Contracts.Dtos; using TaskManager.Contracts.Dtos;
using TaskManager.Entity; using TaskManager.Entity;
using TaskManager.Entity.Entitys; using TaskManager.Entity.Entitys;
@ -51,7 +52,7 @@ namespace TaskManager.Controllers
entity.ReadState = true; entity.ReadState = true;
entity.WriteState = true; entity.WriteState = true;
} }
_jobDbContext.BulkUpdate(entities); await _jobDbContext.BulkUpdateAsync(entities);
} }

3
API/Wood.Service/Controllers/LogServices/CherySupplierMrpMonthService.cs

@ -10,8 +10,7 @@ using TaskManager.Entity;
using TaskManager.Entity.Entitys; using TaskManager.Entity.Entitys;
using TaskManager.EntityFramework; using TaskManager.EntityFramework;
using Wood.Service.Controllers; using Wood.Service.Controllers;
using Z.BulkOperations;
using Z.EntityFramework.Extensions;
namespace TaskManager.Controllers namespace TaskManager.Controllers

3
API/Wood.Service/Controllers/NormalBaseController.cs

@ -1,4 +1,5 @@
using Magicodes.ExporterAndImporter.Core; using EFCore.BulkExtensions;
using Magicodes.ExporterAndImporter.Core;
using Magicodes.ExporterAndImporter.Core.Extension; using Magicodes.ExporterAndImporter.Core.Extension;
using Magicodes.ExporterAndImporter.Excel; using Magicodes.ExporterAndImporter.Excel;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;

2
API/Wood.Service/Controllers/RecurringJobBaseController.cs

@ -110,7 +110,7 @@ namespace TaskManager.Controllers
return string.Empty; return string.Empty;
} }
////string jsonContent = System.IO.File.ReadAllText("日物料需求计划.json"); //string jsonContent = System.IO.File.ReadAllText("日物料需求计划.json");
//string jsonContent = System.IO.File.ReadAllText("M+6月物料需求计划1.json"); //string jsonContent = System.IO.File.ReadAllText("M+6月物料需求计划1.json");
////string jsonContent = System.IO.File.ReadAllText("采购订单.json"); ////string jsonContent = System.IO.File.ReadAllText("采购订单.json");
////// string jsonContent = System.IO.File.ReadAllText("过焊装未过总装.json"); ////// string jsonContent = System.IO.File.ReadAllText("过焊装未过总装.json");

5
API/Wood.Service/Controllers/TaskSubService.cs

@ -1,4 +1,5 @@
using Dapper; using Dapper;
using EFCore.BulkExtensions;
using Hangfire; using Hangfire;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
@ -19,7 +20,7 @@ using TaskManager.Entity.Entitys;
using TaskManager.EntityFramework; using TaskManager.EntityFramework;
using TaskManager.EntityFramework.Repository; using TaskManager.EntityFramework.Repository;
using Wood.Util.Filters; using Wood.Util.Filters;
using Z.EntityFramework.Plus;
namespace Wood.Service.Controllers namespace Wood.Service.Controllers
{ {
@ -275,7 +276,7 @@ namespace Wood.Service.Controllers
item.WriteState = false; item.WriteState = false;
} }
await _context.BulkUpdateAsync(mmrplist,options=>options.Transaction=tran); await _context.BulkUpdateAsync(mmrplist);
_context.SaveChanges(); _context.SaveChanges();
// 提交事务 // 提交事务
await transaction.CommitAsync(); await transaction.CommitAsync();

147
API/Wood.Service/Datas/SupplierEmployeeDtService.cs

@ -1,7 +1,9 @@
using Magicodes.ExporterAndImporter.Core.Models; using EFCore.BulkExtensions;
using Magicodes.ExporterAndImporter.Core.Models;
using Magicodes.ExporterAndImporter.Excel; using Magicodes.ExporterAndImporter.Excel;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
@ -109,19 +111,56 @@ namespace Wood.Service.Datas
emps.Add(empObj); emps.Add(empObj);
} }
_context.BulkInsert(emps,options=>options.Transaction=tran); _context.BulkInsert(emps);
_context.BulkMerge(entityLst, options => {
options.ColumnPrimaryKeyExpression = itm =>
new
foreach (var empDtObj in entityLst)
{ {
itm.SupplierCode, empDtObj.SupplierCode = VendCode;
itm.PlantId, //以“供应商代码+工厂代码+车间代码+产线代码+工位代码+操作人员账号”为唯一标识,做新增或者更新存储
itm.WorkshopId, var firstObj = _context.Set<SUPPLIER_EMPLOYEE_DT>().FirstOrDefault(
itm.ProductionLineId, itm => itm.SupplierCode == empDtObj.SupplierCode
itm.StationId && itm.PlantId == empDtObj.PlantId
}; options.Transaction = tran; && itm.WorkshopId == empDtObj.WorkshopId
} && itm.ProductionLineId == empDtObj.ProductionLineId
&& itm.StationId == empDtObj.StationId
&& itm.OperatorId == empDtObj.OperatorId
); );
if (firstObj == null)
{
var ret = await base.Create(empDtObj);
}
else
{
empDtObj.UId = firstObj.UId;
empDtObj.CreationTime = CommonHelper.CurrentTime;
var ret = await base.Update(empDtObj);
}
}
//_context.BulkMerge(entityLst,
// itm=> itm.SupplierCode,
// itm=> itm.PlantId,
// itm=> itm.WorkshopId,
// itm=> itm.ProductionLineId,
// itm=> itm.StationId
// );
//_context.BulkMerge(entityLst, options => {
// options.ColumnPrimaryKeyExpression = itm =>
//new
//{
// itm.SupplierCode,
// itm.PlantId,
// itm.WorkshopId,
// itm.ProductionLineId,
// itm.StationId
//}; options.Transaction = tran;
//}
//);
//foreach (var empDtObj in entityLst) //foreach (var empDtObj in entityLst)
//{ //{
@ -201,12 +240,47 @@ namespace Wood.Service.Datas
empObj.ReadState = true; empObj.ReadState = true;
await _context.AddAsync(empObj); await _context.AddAsync(empObj);
await _context.BulkMergeAsync(new List<SUPPLIER_EMPLOYEE_DT> { entity }, options =>
empObj.TaskId = taskSubObj.TaskId;
await _supplierEmployeeRepository.AddAsync(empObj);
var firstObj = _context.Set<SUPPLIER_EMPLOYEE_DT>().FirstOrDefault(
itm => itm.SupplierCode == entity.SupplierCode
&& itm.PlantId == entity.PlantId
&& itm.WorkshopId == entity.WorkshopId
&& itm.ProductionLineId == entity.ProductionLineId
&& itm.StationId == entity.StationId
&& itm.OperatorId == entity.OperatorId
);
if (firstObj == null)
{ {
options.ColumnPrimaryKeyExpression = itm => var ret = await base.Create(entity);
new { itm.SupplierCode, itm.PlantId, itm.WorkshopId, itm.ProductionLineId, itm.StationId, itm.OperatorId }; options.Transaction = tran;
} }
); else
{
throw new Exception("数据库已经存在,不能重复插入");
}
// _context.BulkMerge(new List<SUPPLIER_EMPLOYEE_DT> { entity },
//itm => itm.SupplierCode,
//itm => itm.PlantId,
//itm => itm.WorkshopId,
//itm => itm.ProductionLineId,
//itm => itm.StationId
// );
//await _context.BulkMergeAsync(new List<SUPPLIER_EMPLOYEE_DT> { entity }, options =>
//{
// options.ColumnPrimaryKeyExpression = itm =>
//new { itm.SupplierCode, itm.PlantId, itm.WorkshopId, itm.ProductionLineId, itm.StationId, itm.OperatorId }; options.Transaction = tran;
//}
//);
_context.SaveChanges(); _context.SaveChanges();
@ -270,12 +344,45 @@ namespace Wood.Service.Datas
empObj.ReadState = true; empObj.ReadState = true;
await _context.AddAsync(empObj); await _context.AddAsync(empObj);
await _context.BulkMergeAsync(new List<SUPPLIER_EMPLOYEE_DT> { entity }, options =>
var firstObj = _context.Set<SUPPLIER_EMPLOYEE_DT>().FirstOrDefault(
itm => itm.SupplierCode == entity.SupplierCode
&& itm.PlantId == entity.PlantId
&& itm.WorkshopId == entity.WorkshopId
&& itm.ProductionLineId == entity.ProductionLineId
&& itm.StationId == entity.StationId
&& itm.OperatorId == entity.OperatorId
);
if (firstObj == null)
{ {
options.ColumnPrimaryKeyExpression = itm => throw new Exception("数据库不存在,不能更新");
new { itm.SupplierCode, itm.PlantId, itm.WorkshopId, itm.ProductionLineId, itm.StationId, itm.OperatorId }; options.Transaction = tran;
} }
); else
{
var ret = await base.Update(entity);
}
//_context.BulkMerge(new List<SUPPLIER_EMPLOYEE_DT> { entity },
// itm=> itm.SupplierCode,
// itm=> itm.PlantId,
// itm=> itm.WorkshopId,
// itm=> itm.ProductionLineId,
// itm=> itm.StationId,
// itm=> itm.OperatorId
// );
//await _context.BulkMergeAsync(new List<SUPPLIER_EMPLOYEE_DT> { entity }, options =>
//{
// options.ColumnPrimaryKeyExpression = itm =>
//new { itm.SupplierCode, itm.PlantId, itm.WorkshopId, itm.ProductionLineId, itm.StationId, itm.OperatorId }; options.Transaction = tran;
//}
//);
_context.SaveChanges(); _context.SaveChanges();

119
API/Wood.Service/Datas/SupplierInfoDtService.cs

@ -1,4 +1,5 @@
using Magicodes.ExporterAndImporter.Core.Models; using EFCore.BulkExtensions;
using Magicodes.ExporterAndImporter.Core.Models;
using Magicodes.ExporterAndImporter.Excel; using Magicodes.ExporterAndImporter.Excel;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -106,19 +107,56 @@ namespace Wood.Service.Datas
infos.Add(empObj); infos.Add(empObj);
//await _supplierInfoRepository.AddAsync(empObj); //await _supplierInfoRepository.AddAsync(empObj);
} }
_context.BulkInsert(infos,options=>options.Transaction=tran); _context.BulkInsert(infos);
_context.BulkMerge(entityLst, options => {
options.ColumnPrimaryKeyExpression = itm =>
new foreach (var empDtObj in entityLst)
{ {
itm.SupplierCode, empDtObj.SupplierCode = VendCode;
itm.PlantId, //以“供应商代码+工厂代码+车间代码+产线代码+工位代码”为唯一标识,做新增或更新存储
itm.WorkshopId, var firstObj = _context.Set<SUPPLIER_INFO_DT>().FirstOrDefault(
itm.ProductionLineId, itm => itm.SupplierCode == empDtObj.SupplierCode
itm.StationId && itm.PlantId == empDtObj.PlantId
};options.Transaction = tran; && itm.WorkshopId == empDtObj.WorkshopId
} && itm.ProductionLineId == empDtObj.ProductionLineId
&& itm.StationId == empDtObj.StationId
); );
if (firstObj == null)
{
var ret = await base.Create(empDtObj);
}
else
{
empDtObj.UId = firstObj.UId;
empDtObj.CreationTime = CommonHelper.CurrentTime;
var ret = await base.Update(empDtObj);
}
}
//_context.BulkMerge(entityLst,
// itm=> itm.SupplierCode,
// itm=> itm.PlantId,
// itm=> itm.WorkshopId,
// itm=> itm.ProductionLineId,
// itm=> itm.StationId
//);
//_context.BulkMerge(entityLst, options => {
// options.ColumnPrimaryKeyExpression = itm =>
//new
//{
// itm.SupplierCode,
// itm.PlantId,
// itm.WorkshopId,
// itm.ProductionLineId,
// itm.StationId
//};options.Transaction = tran;
//}
//);
//foreach (var empDtObj in entityLst) //foreach (var empDtObj in entityLst)
//{ //{
@ -194,8 +232,38 @@ namespace Wood.Service.Datas
empObj.ReadState = true; empObj.ReadState = true;
await _context.AddAsync(empObj); await _context.AddAsync(empObj);
var firstObj = _context.Set<SUPPLIER_INFO_DT>().FirstOrDefault(
itm => itm.SupplierCode == entity.SupplierCode
&& itm.PlantId == entity.PlantId
&& itm.WorkshopId == entity.WorkshopId
&& itm.ProductionLineId == entity.ProductionLineId
&& itm.StationId == entity.StationId
);
if (firstObj == null)
{
var ret = await base.Create(entity);
}
else
{
throw new Exception("数据库已经存在,不能重复插入");
}
// _context.BulkMerge(new List<SUPPLIER_INFO_DT> { entity },
// itm => itm.SupplierCode,
// itm => itm.PlantId,
// itm => itm.WorkshopId,
// itm => itm.ProductionLineId,
// itm => itm.StationId
//);
await _context.BulkMergeAsync(new List<SUPPLIER_INFO_DT> { entity }, options => { options.ColumnPrimaryKeyExpression = itm => new { itm.SupplierCode, itm.PlantId, itm.WorkshopId, itm.ProductionLineId, itm.StationId }; options.Transaction = tran; });
// await _context.BulkMergeAsync(new List<SUPPLIER_INFO_DT> { entity }, options => { options.ColumnPrimaryKeyExpression = itm => new { itm.SupplierCode, itm.PlantId, itm.WorkshopId, itm.ProductionLineId, itm.StationId }; options.Transaction = tran; });
_context.SaveChanges(); _context.SaveChanges();
@ -251,9 +319,30 @@ namespace Wood.Service.Datas
empObj.TaskId = taskSubObj.TaskId; empObj.TaskId = taskSubObj.TaskId;
empObj.ReadState = true; empObj.ReadState = true;
await _context.AddAsync(empObj); await _context.AddAsync(empObj);
var firstObj = _context.Set<SUPPLIER_INFO_DT>().FirstOrDefault(
itm => itm.SupplierCode == entity.SupplierCode
&& itm.PlantId == entity.PlantId
&& itm.WorkshopId == entity.WorkshopId
&& itm.ProductionLineId == entity.ProductionLineId
&& itm.StationId == entity.StationId
);
if (firstObj == null)
{
throw new Exception("数据库不存在,不能更新");
}
else
{
var ret = await base.Update(entity);
}
// _context.BulkMerge(new List<SUPPLIER_INFO_DT> { entity },
await _context.BulkMergeAsync(new List<SUPPLIER_INFO_DT> { entity }, options => { options.ColumnPrimaryKeyExpression = itm => new { itm.SupplierCode, itm.PlantId, itm.WorkshopId, itm.ProductionLineId, itm.StationId }; options.Transaction = tran; }); // itm => itm.SupplierCode,
// itm => itm.PlantId,
// itm => itm.WorkshopId,
// itm => itm.ProductionLineId,
// itm => itm.StationId
//);
// await _context.BulkMergeAsync(new List<SUPPLIER_INFO_DT> { entity }, options => { options.ColumnPrimaryKeyExpression = itm => new { itm.SupplierCode, itm.PlantId, itm.WorkshopId, itm.ProductionLineId, itm.StationId }; options.Transaction = tran; });
_context.SaveChanges(); _context.SaveChanges();

146
API/Wood.Service/Datas/SupplierProProcessEquipmentDtService.cs

@ -1,4 +1,5 @@
using Magicodes.ExporterAndImporter.Core.Models; using EFCore.BulkExtensions;
using Magicodes.ExporterAndImporter.Core.Models;
using Magicodes.ExporterAndImporter.Excel; using Magicodes.ExporterAndImporter.Excel;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -110,30 +111,41 @@ namespace Wood.Service.Datas
// await _supplierProProcessEquipmentRepository.AddAsync(empObj); // await _supplierProProcessEquipmentRepository.AddAsync(empObj);
} }
_context.BulkInsert(eqs,options=>options.Transaction=tran); _context.BulkInsert(eqs);
_context.BulkMerge(entityLst, options => { options.ColumnPrimaryKeyExpression = itm => new { itm.SupplierCode, itm.CheryProductNo, itm.DeviceCode, itm.DeviceType }; options.Transaction = tran; });
//_context.BulkMerge(entityLst,
// itm=> itm.SupplierCode,
// itm=> itm.CheryProductNo,
// itm=> itm.DeviceCode,
// itm=> itm.DeviceType
//foreach (var empDtObj in entityLst)
//{
// empDtObj.SupplierCode = VendCode;
// //以供应商代码+奇瑞零件号+工艺编码+工艺版本为唯一数据,做新增或者更新存储
// var firstObj = _context.Set<SUPPLIER_PRO_PROCESS_EQUIPMENT_DT>().FirstOrDefault(
// itm => itm.SupplierCode == empDtObj.SupplierCode
// && itm.CheryProductNo == empDtObj.CheryProductNo
// && itm.DeviceCode == empDtObj.DeviceCode
// && itm.DeviceType == empDtObj.DeviceType
// ); // );
// if (firstObj == null)
// { // _context.BulkMerge(entityLst, options => { options.ColumnPrimaryKeyExpression = itm => new { itm.SupplierCode, itm.CheryProductNo, itm.DeviceCode, itm.DeviceType }; options.Transaction = tran; });
// var ret = await base.Create(empDtObj);
// } foreach (var empDtObj in entityLst)
// else {
// { empDtObj.SupplierCode = VendCode;
// empDtObj.UId = firstObj.UId; //以供应商代码+奇瑞零件号+工艺编码+工艺版本为唯一数据,做新增或者更新存储
// empDtObj.CreationTime = CommonHelper.CurrentTime; var firstObj = _context.Set<SUPPLIER_PRO_PROCESS_EQUIPMENT_DT>().FirstOrDefault(
// var ret = await base.Update(empDtObj); itm => itm.SupplierCode == empDtObj.SupplierCode
// } && itm.CheryProductNo == empDtObj.CheryProductNo
//} && itm.DeviceCode == empDtObj.DeviceCode
&& itm.DeviceType == empDtObj.DeviceType
);
if (firstObj == null)
{
var ret = await base.Create(empDtObj);
}
else
{
empDtObj.UId = firstObj.UId;
empDtObj.CreationTime = CommonHelper.CurrentTime;
var ret = await base.Update(empDtObj);
}
}
#endregion #endregion
transaction.Commit(); transaction.Commit();
@ -199,7 +211,40 @@ namespace Wood.Service.Datas
empObj.ReadState = true; empObj.ReadState = true;
await _context.BulkInsertAsync(new List<SUPPLIER_PRO_PROCESS_EQUIPMENT>() { empObj });
await _context.AddAsync(empObj);
var firstObj = _context.Set<SUPPLIER_PRO_PROCESS_EQUIPMENT_DT>().FirstOrDefault(
itm => itm.SupplierCode == entity.SupplierCode
&& itm.CheryProductNo == entity.CheryProductNo
&& itm.DeviceCode == entity.DeviceCode
&& itm.DeviceType == entity.DeviceType
);
if (firstObj == null)
{
var ret = await base.Create(entity);
}
else
{
throw new Exception("数据库已经存在,不能重复插入");
}
// await _context.BulkInsertAsync(new List<SUPPLIER_PRO_PROCESS_EQUIPMENT>() { empObj });
// _context.BulkMerge(new List<SUPPLIER_PRO_PROCESS_EQUIPMENT_DT> { entity },
//itm => itm.SupplierCode,
//itm => itm.CheryProductNo,
//itm => itm.DeviceCode,
//itm => itm.DeviceType
// );
_context.SaveChanges(); _context.SaveChanges();
@ -269,18 +314,59 @@ namespace Wood.Service.Datas
empObj.ReadState = true; empObj.ReadState = true;
await _context.BulkInsertAsync(new List<SUPPLIER_PRO_PROCESS_EQUIPMENT>(){ empObj}); await _context.AddAsync(empObj);
_context.SaveChanges();
//await _supplierProProcessEquipmentRepository.AddAsync(empObj); //await _supplierProProcessEquipmentRepository.AddAsync(empObj);
await _context.BulkMergeAsync(new List<SUPPLIER_PRO_PROCESS_EQUIPMENT_DT> { entity }, options => //_context.BulkMerge(new List<SUPPLIER_PRO_PROCESS_EQUIPMENT_DT> { entity },
//itm => itm.SupplierCode,
//itm => itm.CheryProductNo,
//itm => itm.DeviceCode,
//itm => itm.DeviceType
// );
var firstObj = _context.Set<SUPPLIER_PRO_PROCESS_EQUIPMENT_DT>().FirstOrDefault(
itm => itm.SupplierCode == entity.SupplierCode
&& itm.CheryProductNo == entity.CheryProductNo
&& itm.DeviceCode == entity.DeviceCode
&& itm.DeviceType == entity.DeviceType
);
if (firstObj == null)
{ {
options.ColumnPrimaryKeyExpression = itm => throw new Exception("数据库不存在,不能更新");
new { itm.SupplierCode, itm.CheryProductNo, itm.DeviceCode, itm.DeviceType }; options.Transaction = tran;
} }
); else
{
var ret = await base.Update(entity);
}
_context.SaveChanges();
//await _context.BulkMergeAsync(new List<SUPPLIER_PRO_PROCESS_EQUIPMENT_DT> { entity }, options =>
//{
// options.ColumnPrimaryKeyExpression = itm =>
//new { itm.SupplierCode, itm.CheryProductNo, itm.DeviceCode, itm.DeviceType }; options.Transaction = tran;
//}
//);

4
API/Wood.Service/Wood.Service.csproj

@ -20,6 +20,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="EF.BulkExtensions.EFCore" Version="1.4.4" />
<PackageReference Include="EFCore.BulkExtensions" Version="8.0.0" />
<PackageReference Include="EfCore.BulkOperations" Version="1.6.0" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.20" /> <PackageReference Include="Hangfire.AspNetCore" Version="1.8.20" />
<PackageReference Include="Hangfire.Core" Version="1.8.20" /> <PackageReference Include="Hangfire.Core" Version="1.8.20" />
<PackageReference Include="Hangfire.SqlServer" Version="1.8.20" /> <PackageReference Include="Hangfire.SqlServer" Version="1.8.20" />
@ -27,7 +30,6 @@
<PackageReference Include="Magicodes.IE.Excel" Version="2.7.5.2" /> <PackageReference Include="Magicodes.IE.Excel" Version="2.7.5.2" />
<PackageReference Include="Serilog" Version="4.2.0" /> <PackageReference Include="Serilog" Version="4.2.0" />
<PackageReference Include="ValueInjecter" Version="3.2.0" /> <PackageReference Include="ValueInjecter" Version="3.2.0" />
<PackageReference Include="Z.EntityFramework.Extensions.EFCore" Version="8.103.8.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

Loading…
Cancel
Save