学 赵
1 year ago
5 changed files with 279 additions and 13 deletions
@ -0,0 +1,104 @@ |
|||
using SettleAccount.Bases; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Caching; |
|||
using Volo.Abp.Domain.Repositories; |
|||
using Volo.Abp.Domain.Services; |
|||
using Volo.Abp.Guids; |
|||
using Volo.Abp.ObjectMapping; |
|||
using Win.Sfs.SettleAccount.Boms; |
|||
using Win.Sfs.SettleAccount.CommonManagers; |
|||
using Win.Sfs.SettleAccount.Entities.ImportMap; |
|||
using Win.Sfs.SettleAccount.Entities.Materials; |
|||
using Win.Sfs.SettleAccount.FISes; |
|||
using Win.Sfs.SettleAccount.MaterialRelationships; |
|||
|
|||
namespace Win.Sfs.SettleAccount.Bases.DomainServices |
|||
{ |
|||
public class BaseDomainService:DomainService, ICheck |
|||
{ |
|||
private readonly ISettleAccountBQEfCoreRepository<Material, Guid> _materialRepository; |
|||
private readonly ISettleAccountBQEfCoreRepository<MaterialRelationship, Guid> _relationshipRepository; |
|||
private readonly ISettleAccountBQEfCoreRepository<Bom, Guid> _bomshipRepository; |
|||
|
|||
public BaseDomainService( |
|||
IGuidGenerator guidGenerator, |
|||
IObjectMapper objectMapper, |
|||
ISettleAccountBQEfCoreRepository<Material, Guid> materialRepository, |
|||
ISettleAccountBQEfCoreRepository<MaterialRelationship, Guid> relationshipRepository, |
|||
ISettleAccountBQEfCoreRepository<Bom, Guid> bomshipRepository |
|||
//IExcelImportAppService excelImportService,
|
|||
//ISnowflakeIdGenerator snowflakeIdGenerator,
|
|||
//ICommonManager commonManager
|
|||
) |
|||
{ |
|||
_materialRepository = materialRepository; |
|||
_relationshipRepository = relationshipRepository; |
|||
_bomshipRepository = bomshipRepository; |
|||
} |
|||
|
|||
public async Task<List<string>> CheckBase<TEntity>(List<TEntity> p_list ,BASE_CONF p_config) where TEntity : ISBASE |
|||
|
|||
{ |
|||
List<string> errorList = new List<string>(); |
|||
var partList= p_list.Select(p=>p.LU).Distinct().ToList(); |
|||
|
|||
if (p_config.IsBom == true) |
|||
{ |
|||
var bomList =await _bomshipRepository.ToListAsync(); |
|||
var query=from itm in partList join itm1 in bomList on itm equals itm1.ParentItemCode |
|||
into temp |
|||
from tm in temp.DefaultIfEmpty() |
|||
where tm == null |
|||
select itm; |
|||
|
|||
foreach(var itm1 in query.ToList()) |
|||
{ |
|||
errorList.Add(itm1); |
|||
} |
|||
} |
|||
if (p_config.IsMaterial == true) |
|||
{ |
|||
|
|||
var materialList = await _materialRepository.ToListAsync(); |
|||
var query = from itm in partList |
|||
join itm1 in materialList on itm equals itm1.MaterialCode |
|||
into temp |
|||
from tm in temp.DefaultIfEmpty() |
|||
where tm == null |
|||
select itm; |
|||
foreach (var partcode in query.ToList()) |
|||
{ |
|||
errorList.Add(partcode); |
|||
} |
|||
} |
|||
if (p_config.IsRelationShip == true) |
|||
{ |
|||
var materialList =await _relationshipRepository.ToListAsync(); |
|||
var query = from itm in partList |
|||
join itm1 in materialList on itm equals itm1.SettleMaterialCode |
|||
into temp |
|||
from tm in temp.DefaultIfEmpty() |
|||
where tm == null |
|||
select itm; |
|||
|
|||
foreach (var partcode in query.ToList()) |
|||
{ |
|||
errorList.Add(partcode); |
|||
} |
|||
} |
|||
return errorList; |
|||
} |
|||
|
|||
|
|||
} |
|||
public interface ICheck |
|||
{ |
|||
Task<List<string>> CheckBase<TEntity>(List<TEntity> p_list, BASE_CONF p_config) where TEntity : ISBASE; |
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,119 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Data; |
|||
using System.Data.Common; |
|||
using System.Data.SqlClient; |
|||
using System.Linq; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore.Storage; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Entities; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Win.Sfs.Shared; |
|||
using Win.Sfs.Shared.DomainBase; |
|||
using Win.Sfs.Shared.Filter; |
|||
using Win.Sfs.Shared.RepositoryBase; |
|||
|
|||
namespace Win.Sfs.SettleAccount.Repository |
|||
{ |
|||
public class SettleAccountBQEfCoreRepository<TEntity, TKey> : |
|||
SettleAccountEfCoreRepository<TEntity, TKey>, |
|||
ISettleAccountBQEfCoreRepository<TEntity, TKey>, |
|||
ITransientDependency |
|||
where TEntity : class, IBranch<TKey>, IEntity<TKey> |
|||
{ |
|||
|
|||
private readonly IDbContextProvider<SettleAccountDbContext> _dbContextProvider; |
|||
|
|||
|
|||
|
|||
public SettleAccountBQEfCoreRepository(IDbContextProvider<SettleAccountDbContext> dbContextProvider) : |
|||
base(dbContextProvider) |
|||
{ |
|||
|
|||
_dbContextProvider = dbContextProvider; |
|||
|
|||
} |
|||
public SettleAccountBQEfCoreRepository() : base(null) |
|||
{ |
|||
|
|||
} |
|||
|
|||
public DbCommand CreateCommand(string commandText, CommandType commandType, params DbParameter[] parameters) |
|||
{ |
|||
var command = DbContext.Database.GetDbConnection().CreateCommand(); |
|||
|
|||
command.CommandText = commandText; |
|||
command.CommandType = commandType; |
|||
command.Transaction = DbContext.Database.CurrentTransaction?.GetDbTransaction(); |
|||
|
|||
foreach (var parameter in parameters) |
|||
{ |
|||
command.Parameters.Add(parameter); |
|||
} |
|||
|
|||
return command; |
|||
} |
|||
|
|||
public async Task EnsureConnectionOpenAsync(CancellationToken cancellationToken = default) |
|||
{ |
|||
var connection = DbContext.Database.GetDbConnection(); |
|||
|
|||
if (connection.State != ConnectionState.Open) |
|||
{ |
|||
await connection.OpenAsync(cancellationToken); |
|||
} |
|||
} |
|||
public virtual async Task<List<TEntity>> GetAllAsync( bool includeDetails = false, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var query = includeDetails ? this.WithDetails() : this.GetQueryable(); |
|||
|
|||
//query = query.Where(p => p.BranchId.Equals(branchId));
|
|||
|
|||
return await query.ToListAsync(cancellationToken: cancellationToken); |
|||
} |
|||
|
|||
public virtual async Task<long> GetCountAsync(CancellationToken cancellationToken = default) |
|||
{ |
|||
return await this.GetQueryable() |
|||
//.Where(p => p.BranchId.Equals(branchId))
|
|||
.LongCountAsync(GetCancellationToken(cancellationToken)); |
|||
|
|||
} |
|||
|
|||
public virtual async Task<long> GetCountByFilterAsync( List<FilterCondition> filters, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return await this.GetQueryable() |
|||
//.Where(p => p.BranchId.Equals(branchId))
|
|||
.WhereIf(filters?.Count != 0, filters.ToLambda<TEntity>()) |
|||
.LongCountAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<List<TEntity>> GetListByFilterAsync( List<FilterCondition> filters, |
|||
string sorting = null, |
|||
int maxResultCount = int.MaxValue, int skipCount = 0, bool includeDetails = false, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var query = includeDetails ? this.WithDetails() : this.GetQueryable(); |
|||
// query = query.Where(p => p.BranchId.Equals(branchId));
|
|||
var entities = query.WhereIf(filters?.Count != 0, filters.ToLambda<TEntity>()); |
|||
//2021-07-02 设置sorting首字母大小,因设置了驼峰规则,不匹配“ var memberProp = typeof(T).GetProperty(propertyName);”反射
|
|||
if(!string.IsNullOrEmpty(sorting)) |
|||
{ |
|||
sorting = sorting.Substring(0, 1).ToUpper() + sorting.Substring(1); |
|||
} |
|||
entities = GetSortingQueryable(entities, sorting); |
|||
return await entities.PageBy(skipCount, maxResultCount) |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
|
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
} |
Loading…
Reference in new issue