You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
252 lines
9.6 KiB
252 lines
9.6 KiB
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Logging;
|
|
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.Entities.Prices;
|
|
using Win.Sfs.SettleAccount.FISes;
|
|
using Win.Sfs.SettleAccount.MaterialRelationships;
|
|
using Win.Sfs.Shared.RepositoryBase;
|
|
|
|
namespace Win.Sfs.SettleAccount.Bases.DomainServices
|
|
{
|
|
public class BaseDomainService : DomainService
|
|
{
|
|
private readonly INormalEfCoreRepository<Material, Guid> _materialRepository;
|
|
private readonly INormalEfCoreRepository<MaterialRelationship, Guid> _relationshipRepository;
|
|
private readonly INormalEfCoreRepository<PriceList, Guid> _priceRepository;
|
|
private readonly INormalEfCoreRepository<PriceListBJ, Guid> _pricebjRepository;
|
|
private readonly INormalEfCoreRepository<Bom, Guid> _bomshipRepository;
|
|
public BaseDomainService(
|
|
IGuidGenerator guidGenerator,
|
|
IObjectMapper objectMapper,
|
|
INormalEfCoreRepository<Material, Guid> materialRepository,
|
|
INormalEfCoreRepository<MaterialRelationship, Guid> relationshipRepository,
|
|
INormalEfCoreRepository<Bom, Guid> bomshipRepository,
|
|
INormalEfCoreRepository<PriceList, Guid> priceRepository,
|
|
INormalEfCoreRepository<PriceListBJ, Guid> pricebjRepository
|
|
//IExcelImportAppService excelImportService,
|
|
//ISnowflakeIdGenerator snowflakeIdGenerator,
|
|
//ICommonManager commonManager
|
|
)
|
|
{
|
|
_priceRepository = priceRepository;
|
|
_pricebjRepository= pricebjRepository;
|
|
_materialRepository = materialRepository;
|
|
_relationshipRepository = relationshipRepository;
|
|
_bomshipRepository = bomshipRepository;
|
|
}
|
|
|
|
public async Task<List<MaterialRelationship>> GetMaterialList()
|
|
{
|
|
List<MaterialRelationship> ls = new List<MaterialRelationship>();
|
|
var lst = await _relationshipRepository.Where(p => !string.IsNullOrEmpty(p.SettleMaterialCode)).ToListAsync();
|
|
|
|
|
|
var l=lst.GroupBy(p => p.SettleMaterialCode).Select(g=> g.First());
|
|
return l.ToList();
|
|
}
|
|
|
|
public static async Task DoWorkBulkWithTransaction(DbContext dbContext, Action p_dowork)
|
|
{
|
|
using (var transaction = await dbContext.Database.BeginTransactionAsync())
|
|
{
|
|
try
|
|
{
|
|
// 执行批量数据操作
|
|
p_dowork();
|
|
// 提交事务
|
|
await transaction.CommitAsync();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// 回滚事务
|
|
await transaction.RollbackAsync();
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<List<string>> CheckBase(List<string> p_list, BASE_CONF p_config)
|
|
{
|
|
List<string> errorList = new List<string>();
|
|
var partList = p_list;
|
|
|
|
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 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);
|
|
}
|
|
}
|
|
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 async Task<List<TEntity>> CheckPriceList<TEntity>(List<TEntity> p_list,bool isBj=false)
|
|
where TEntity : ISA_BASE,new()
|
|
{
|
|
List<TEntity> errorList = new List<TEntity>();
|
|
if (isBj == true)
|
|
{
|
|
var pricebjlist = _pricebjRepository.ToList();
|
|
|
|
var inner = from d in p_list
|
|
join p in pricebjlist on d.LU equals p.LU
|
|
where
|
|
d.SettleDate >= p.BeginDate && d.SettleDate <= p.EndDate
|
|
select d;
|
|
var left = from d in p_list
|
|
join p in inner on new { d.LU, d.PN } equals new { p.LU, p.PN }
|
|
into temp
|
|
from tm in temp.DefaultIfEmpty()//校验错误项
|
|
where tm == null
|
|
select d;
|
|
errorList = left.ToList();
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
var pricebjlist = _priceRepository.ToList();
|
|
|
|
var inner = from d in p_list
|
|
join p in pricebjlist on d.LU equals p.LU
|
|
where
|
|
d.SettleDate >= p.BeginTime && d.SettleDate <= p.EndTime
|
|
select d;
|
|
var left = from d in p_list
|
|
join p in inner on new { d.LU, d.PN } equals new { p.LU, p.PN }
|
|
into temp
|
|
from tm in temp.DefaultIfEmpty()//校验错误项
|
|
where tm == null
|
|
select d;
|
|
errorList = left.ToList();
|
|
}
|
|
|
|
return errorList;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|