箱唛接口功能
This commit is contained in:
217
src/WMS.Web.Repositories/BoxMarkRepositories.cs
Normal file
217
src/WMS.Web.Repositories/BoxMarkRepositories.cs
Normal file
@@ -0,0 +1,217 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WMS.Web.Core.Dto;
|
||||
using WMS.Web.Core.Dto.Erp;
|
||||
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 BoxMarkRepositories : IBoxMarkRepositories
|
||||
{
|
||||
private readonly ILoginRepositories _loginRepositories;
|
||||
private readonly RepositoryDbContext _context;
|
||||
private readonly ISingleDataService _singleDataService;
|
||||
private readonly IErpService _erpService;
|
||||
private readonly IErpBasicDataExtendService _erpBasicDataExtendService;
|
||||
private readonly IBasicsRepositories _basicsRepositories;
|
||||
|
||||
|
||||
public BoxMarkRepositories(RepositoryDbContext context,
|
||||
IErpService erpService,
|
||||
ILoginRepositories loginRepositories,
|
||||
ISingleDataService singleDataService,
|
||||
IBasicsRepositories basicsRepositories,
|
||||
IErpBasicDataExtendService erpBasicDataExtendService)
|
||||
{
|
||||
_context = context;
|
||||
_erpService = erpService;
|
||||
_basicsRepositories = basicsRepositories;
|
||||
_loginRepositories = loginRepositories;
|
||||
_singleDataService = singleDataService;
|
||||
_erpBasicDataExtendService = erpBasicDataExtendService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 列表-分页
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<(List<BoxMarkQueryResponse> list, int total)> GetPagedList(BoxMarkQueryRequest dto, int companyId)
|
||||
{
|
||||
//1.获取物料集合和组织集合和供应商的集合
|
||||
var materials = new List<ErpMaterialDto>();
|
||||
var materials_result = await _erpService.BillQueryForMaterial();
|
||||
if (materials_result.IsSuccess)
|
||||
materials = materials_result.Data.ToList();
|
||||
|
||||
|
||||
//物料集合;模糊查询后的物料集合
|
||||
if (!string.IsNullOrEmpty(dto.Material))
|
||||
materials = materials.Where(w => w.MaterialNumber.Contains(dto.Material) || w.MaterialName.Contains(dto.Material) || w.Specifications.Contains(dto.Material)).ToList();
|
||||
|
||||
if (companyId == 0)
|
||||
companyId = _loginRepositories.CompanyId;
|
||||
List<int> cr_ids = new List<int>();
|
||||
if (!string.IsNullOrEmpty(dto.Creator))
|
||||
{
|
||||
var staffList = await _basicsRepositories.GetStaffListAsync(companyId);
|
||||
if (staffList != null)
|
||||
cr_ids = staffList.Where(w => w.Name.Contains(dto.Creator)).Select(s => s.Id).ToList();
|
||||
}
|
||||
var query = _context.BoxMark.Where(adv => 1 == 1);
|
||||
|
||||
//编号查询
|
||||
if (!string.IsNullOrEmpty(dto.BeginBillNo) &&
|
||||
!string.IsNullOrEmpty(dto.EndBillNo))
|
||||
{
|
||||
if (dto.BeginBillNo.ToString().Length >= 13 && dto.EndBillNo.ToString().Length >= 13)
|
||||
{
|
||||
var begYMD = Convert.ToInt32(dto.BeginBillNo.Substring(2, 6));
|
||||
var endYMD = Convert.ToInt32(dto.EndBillNo.Substring(2, 6));
|
||||
//if (begYMD <= endYMD)
|
||||
|
||||
var begNo = Convert.ToInt32(dto.BeginBillNo.Substring(8));
|
||||
var endNo = Convert.ToInt32(dto.EndBillNo.Substring(8));
|
||||
query = query.Where(w => w.FirstBillNo >= begYMD && w.FirstBillNo <= endYMD && w.LastBillNo >= begNo && w.LastBillNo <= endNo);
|
||||
}
|
||||
}
|
||||
else
|
||||
query = query.Where(w => w.BillNo == dto.BeginBillNo || w.BillNo == dto.EndBillNo);
|
||||
|
||||
//订单号查询
|
||||
if (!string.IsNullOrEmpty(dto.OrderBillNos))
|
||||
{
|
||||
var orderBNS = dto.OrderBillNos.Replace(",", ",");
|
||||
var orderBillNoList= orderBNS.Split(",").Where(x => !string.IsNullOrEmpty(x)).ToList();
|
||||
if (orderBillNoList != null && orderBillNoList.Count != 0)
|
||||
{
|
||||
query = query.Where(w => orderBillNoList.Contains(w.OrderBillNo));
|
||||
}
|
||||
}
|
||||
|
||||
//物料ID在模糊后的物料
|
||||
if (!string.IsNullOrEmpty(dto.Material))
|
||||
{
|
||||
if (materials != null && materials.Count != 0)
|
||||
{
|
||||
var mids = materials.Select(x => x.MaterialId).ToList();
|
||||
query = query.Where(w => mids.Contains(w.MaterialId));
|
||||
}
|
||||
}
|
||||
|
||||
if (cr_ids.Count != 0)
|
||||
query = query.Where(w => cr_ids.Contains(w.CreatorId));
|
||||
|
||||
if (dto.BeginTime != null)
|
||||
query = query.Where(w => w.CreateTime >= dto.BeginTime.Value);
|
||||
if (dto.EndTime != null)
|
||||
query = query.Where(w => w.CreateTime <= dto.EndTime.Value);
|
||||
|
||||
int total = await query.CountAsync();
|
||||
var list = await query.Select(s => new BoxMarkQueryResponse()
|
||||
{
|
||||
Id = s.Id,
|
||||
BillNo = s.BillNo,
|
||||
OrderBillNo = s.OrderBillNo,
|
||||
MaterialName = _erpBasicDataExtendService.GetMaterialName(materials, s.MaterialId),
|
||||
MaterialNumber = _erpBasicDataExtendService.GetMaterialNumber(materials, s.MaterialId),
|
||||
Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, s.MaterialId),
|
||||
BarCode = "",
|
||||
|
||||
CratingQty = s.CratingQty,
|
||||
CratingNetWeightQty = s.CratingNetWeightQty,
|
||||
CratingGrossWeightQty = s.CratingGrossWeightQty,
|
||||
|
||||
TailboxQty = s.TailboxQty,
|
||||
TailboxNetWeightQty = s.TailboxNetWeightQty,
|
||||
TailboxGrossWeightQty = s.TailboxGrossWeightQty,
|
||||
|
||||
Creator = _singleDataService.GetSingleData(SingleAction.Staffs, companyId, s.CreatorId),
|
||||
CreateTime = s.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
Remark = s.Remark
|
||||
}).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<bool> Add(BoxMark entity, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
await _context.BoxMark.AddAsync(entity);
|
||||
await _context.SaveChangesAsync();
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_transaction != null)
|
||||
_transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 详情-根据最新的ID
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<BoxMark> GetBy()
|
||||
{
|
||||
var entity = await _context.BoxMark.OrderByDescending(x => x.Id).FirstOrDefaultAsync();
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量删除
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> DeleteRange(List<int> ids, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var list = await _context.BoxMark.Where(f => ids.Contains(f.Id)).ToListAsync();
|
||||
_context.BoxMark.RemoveRange(list);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_transaction != null)
|
||||
_transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -351,11 +351,17 @@ namespace WMS.Web.Repositories.Configuration
|
||||
});
|
||||
#endregion
|
||||
|
||||
//箱唛表
|
||||
builder.Entity<BoxMark>(ent =>
|
||||
{
|
||||
ent.ToTable("t_wms_box_mark");
|
||||
ent.HasKey(x => x.Id);
|
||||
});
|
||||
|
||||
|
||||
base.OnModelCreating(builder);
|
||||
}
|
||||
|
||||
public DbSet<BoxMark> BoxMark { get; set; }
|
||||
public DbSet<FileDownManager> FileDownManager { get; set; }
|
||||
public DbSet<SerialNumbers> SerialNumbers { get; set; }
|
||||
public DbSet<ErpOpsSyncDate> ErpOpsSyncDate { get; set; }
|
||||
|
||||
@@ -294,6 +294,7 @@ namespace WMS.Web.Repositories.DependencyInjection
|
||||
Services.AddTransient<IInventoryInOutDetailsService, InventoryInOutDetailsService>();
|
||||
Services.AddTransient<IInventoryDetailsService, InventoryDetailsService>();
|
||||
Services.AddTransient<IInStockTaskBoxService, InStockTaskBoxService>();
|
||||
Services.AddTransient<IBoxMarkService, BoxMarkService>();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,8 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||
services.AddTransient<ITakeStockRepositories, TakeStockRepositories>();
|
||||
services.AddTransient<IErpOpsSyncDateRepositories, ErpOpsSyncDateRepositories>();
|
||||
services.AddTransient<IInStockTaskBoxRepositories, InStockTaskBoxRepositories>();
|
||||
|
||||
services.AddTransient<IBoxMarkRepositories, BoxMarkRepositories>();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user