176 lines
7.3 KiB
C#
176 lines
7.3 KiB
C#
using AutoMapper;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Storage;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using WMS.Web.Core;
|
|
using WMS.Web.Core.Dto;
|
|
using WMS.Web.Core.Dto.Erp;
|
|
using WMS.Web.Core.Dto.Erp.Org;
|
|
using WMS.Web.Core.Internal.Results;
|
|
using WMS.Web.Domain.Entitys;
|
|
using WMS.Web.Domain.Infrastructure;
|
|
using WMS.Web.Domain.IService.Public;
|
|
using WMS.Web.Domain.Values.Single;
|
|
using WMS.Web.Repositories.Configuration;
|
|
|
|
namespace WMS.Web.Repositories
|
|
{
|
|
/// <summary>
|
|
/// 出入库回退记录-仓储
|
|
/// </summary>
|
|
public class BackRecordRepositories : IAllFielRepositories<BackRecordQueryRequest>, IBackRecordRepositories
|
|
{
|
|
private readonly IMapper _mapper;
|
|
private readonly IServiceProvider _serviceProvider;
|
|
private readonly ILoginRepositories _loginRepositories;
|
|
private readonly IBasicsRepositories _basicsRepositories;
|
|
private readonly RepositoryDbContext _context;
|
|
private readonly IErpService _erpService;
|
|
private readonly ISingleDataService _singleDataService;
|
|
private readonly IErpBasicDataExtendService _erpBasicDataExtendService;
|
|
|
|
|
|
public BackRecordRepositories(RepositoryDbContext context,
|
|
IMapper mapper,
|
|
IErpService erpService,
|
|
IBasicsRepositories basicsRepositories,
|
|
ILoginRepositories loginRepositories,
|
|
IServiceProvider serviceProvider,
|
|
ISingleDataService singleDataService,
|
|
IErpBasicDataExtendService erpBasicDataExtendService)
|
|
{
|
|
_erpService = erpService;
|
|
_context = context;
|
|
_mapper = mapper;
|
|
_basicsRepositories = basicsRepositories;
|
|
_serviceProvider = serviceProvider;
|
|
_loginRepositories = loginRepositories;
|
|
_singleDataService = singleDataService;
|
|
_erpBasicDataExtendService = erpBasicDataExtendService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 列表-分页
|
|
/// </summary>
|
|
/// <param name="dto"></param>
|
|
/// <returns></returns>
|
|
public async Task<(List<BackRecordQueryResponse> list,int total)> GetPagedList(BackRecordQueryRequest dto, int companyId)
|
|
{
|
|
//1.获取物料集合和组织集合和供应商的集合
|
|
var materials = new List<ErpMaterialDto>();
|
|
var materials_result = await _erpService.BillQueryForMaterial();
|
|
if (materials_result.IsSuccess)
|
|
materials = materials_result.Data.ToList();
|
|
|
|
//组织集合
|
|
var orgs = new List<ErpOrgDto>();
|
|
var orgs_result = await _erpService.BillQueryForOrg();
|
|
if (orgs_result.IsSuccess)
|
|
orgs = orgs_result.Data.ToList();
|
|
|
|
List<int> ids = new List<int>();
|
|
if (!string.IsNullOrEmpty(dto.Creator))
|
|
{
|
|
var staffList = await _basicsRepositories.GetStaffListAsync(companyId);
|
|
ids = staffList.Where(w =>w.Name.Contains(dto.Creator)).Select(s => s.Id).ToList();
|
|
}
|
|
|
|
var query = _context.BackRecordDetails
|
|
.GroupJoin(_context.BackRecord, detail => detail.Fid, order => order.Id, (detail, orders) => new { detail, orders })
|
|
.SelectMany(x => x.orders.DefaultIfEmpty(), (p, order) => new { p.detail, order })
|
|
.GroupJoin(_context.Box, p => p.detail.BoxId, ts => ts.Id, (p, ts) => new { p.detail, p.order, ts })
|
|
.SelectMany(x => x.ts.DefaultIfEmpty(), (p, box) => new { p.detail, p.order,box })
|
|
.Where(adv => 1 == 1);
|
|
|
|
if(!string.IsNullOrEmpty(dto.BoxBillNo))
|
|
query = query.Where(w => EF.Functions.Like(w.box.BoxBillNo, "%" + dto.BoxBillNo + "%"));
|
|
|
|
if (!string.IsNullOrEmpty(dto.SubStockCode))
|
|
query = query.Where(w => w.order.SubStockCode == dto.SubStockCode);
|
|
|
|
if (dto.Type.HasValue)
|
|
query = query.Where(w => (int)w.order.Type == dto.Type.Value);
|
|
|
|
if (ids.Count() > 0)
|
|
query = query.Where(w => ids.Contains(w.order.CreatorId));
|
|
|
|
if (dto.CreateBeginDate != null)
|
|
query = query.Where(w => w.order.CreateTime >= dto.CreateBeginDate.Value);
|
|
if (dto.CreateEndDate != null)
|
|
query = query.Where(w => w.order.CreateTime <= dto.CreateEndDate.Value);
|
|
|
|
int total = await query.CountAsync();
|
|
var list = await query.Select(s => new BackRecordQueryResponse()
|
|
{
|
|
Id = s.order.Id,
|
|
DetailsId = s.detail.Id,
|
|
BillNo=s.order.BillNo,
|
|
BoxBillNo = s.box.BoxBillNo,
|
|
Type = s.order.Type.GetRemark(),
|
|
Creator = _singleDataService.GetSingleData(SingleAction.Staffs, companyId, s.order.CreatorId),
|
|
CreateTime =s.order.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
|
|
MaterialName = _erpBasicDataExtendService.GetMaterialName(materials, s.detail.MaterialNumber),
|
|
MaterialNumber = s.detail.MaterialNumber,
|
|
Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, s.detail.MaterialNumber),
|
|
Qty = s.detail.Qty,
|
|
Org= _erpBasicDataExtendService.GetOrgName(orgs, s.order.OrgCode),
|
|
Stock = _singleDataService.GetSingleData(SingleAction.StocksJoinOrgCode, companyId, s.order.StockCode + s.order.OrgCode),
|
|
SubStock = _singleDataService.GetSingleData(SingleAction.SubStocksJoinOrgCode, companyId, s.order.SubStockCode + s.order.StockCode + s.order.OrgCode),
|
|
SerialNumbers = (string.Join(",", s.detail.SerialNumbers)).TrimEnd(','),
|
|
}).OrderByDescending(x => x.Id).Skip((dto.PageNo - 1) * dto.PageSize).Take(dto.PageSize).ToListAsync();
|
|
|
|
return (list,total);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增
|
|
/// </summary>
|
|
/// <param name="entity"></param>
|
|
/// <param name="isTransaction"></param>
|
|
/// <returns></returns>
|
|
public async Task<BackRecord> Add(BackRecord entity, bool isTransaction = true)
|
|
{
|
|
IDbContextTransaction _transaction = null;
|
|
if (isTransaction)
|
|
_transaction = _context.Database.BeginTransaction();
|
|
try
|
|
{
|
|
await _context.BackRecord.AddAsync(entity);
|
|
await _context.SaveChangesAsync();
|
|
if (string.IsNullOrEmpty(entity.BillNo))
|
|
{
|
|
entity.GenerateNo();
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
if (_transaction != null)
|
|
_transaction.Commit();
|
|
return entity;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_transaction != null)
|
|
_transaction.Rollback();
|
|
return null;
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导出
|
|
/// </summary>
|
|
/// <param name="dto"></param>
|
|
/// <param name="companyId"></param>
|
|
/// <returns></returns>
|
|
public async Task<(object obj, int total)> GetListField(BackRecordQueryRequest dto, int companyId)
|
|
{
|
|
return await GetPagedList(dto,companyId);
|
|
}
|
|
}
|
|
}
|