This commit is contained in:
tongfei
2023-11-01 09:20:02 +08:00
17 changed files with 319 additions and 136 deletions

View File

@@ -1,14 +1,17 @@
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.Help;
using WMS.Web.Domain.Entitys;
using WMS.Web.Domain.Infrastructure;
using WMS.Web.Domain.IService.Public;
using WMS.Web.Domain.Mappers;
using WMS.Web.Repositories.Configuration;
namespace WMS.Web.Repositories
@@ -35,35 +38,79 @@ namespace WMS.Web.Repositories
_loginRepositories = loginRepositories;
_basicsRepositories = basicsRepositories;
}
public async Task<Box> Get(string BoxBillNo)
public async Task<Box> Get(int id)
{
return await _context.Box.Include(x => x.Details)
.FirstOrDefaultAsync(f => f.BoxBillNo.Equals(BoxBillNo));
var entity= await _context.Box.Include(x => x.Details)
.FirstOrDefaultAsync(f => f.Id.Equals(id));
return entity.Clone();
}
/// <summary>
/// 根据箱号查询物料信息
/// </summary>
/// <param name="BoxBillNo"></param>
/// <returns></returns>
public async Task<List<BoxDetailResponse>> GetDetails(string BoxBillNo)
public async Task<BoxResponse> GetBox(string BoxBillNo)
{
return await _context.BoxDetails
.GroupJoin(_context.Box, detail => detail.Fid, order => order.Id, (detail, orders) => new { detail, orders })
.SelectMany(x => x.orders.DefaultIfEmpty(), (p, order) => new { p.detail, order })
.Where(w => w.order.BoxBillNo.Equals(BoxBillNo))
.Select(s => new BoxDetailResponse()
{
Fid = s.detail.Fid,
BoxId = s.order.OpsBoxId,
MaterialId = s.detail.MaterialId,
MaterialName = "",
MaterialNumber = "",
Specifications = "",
SerialNumbers = s.detail.SerialNumbers,
SupplierId = s.detail.SupplierId,
Qty = s.detail.Qty
})
.ToListAsync();
var entity = await _context.Box.FirstOrDefaultAsync(f => f.BoxBillNo.Equals(BoxBillNo));
if (entity == null) return null;
BoxResponse result = new BoxResponse()
{
Id = entity.Id,
BoxBillNo = entity.BoxBillNo
};
result.Details = await _context.BoxDetails
.GroupJoin(_context.Box, detail => detail.Fid, order => order.Id, (detail, orders) => new { detail, orders })
.SelectMany(x => x.orders.DefaultIfEmpty(), (p, order) => new { p.detail, order })
.Where(w => w.order.BoxBillNo.Equals(BoxBillNo))
.Select(s => new BoxDetailResponse()
{
MaterialId = s.detail.MaterialId,
MaterialName = "",
MaterialNumber = "",
Specifications = "",
SerialNumbers = s.detail.SerialNumbers,
SupplierId = s.detail.SupplierId,
Qty = s.detail.Qty
})
.ToListAsync();
return result;
}
/// <summary>
/// 批量修改
/// </summary>
/// <param name="entitys"></param>
/// <param name="isTransaction"></param>
/// <returns></returns>
public async Task<bool> EditEntityList(List<Box> entitys, bool isTransaction = true)
{
IDbContextTransaction _transaction = null;
if (isTransaction)
_transaction = _context.Database.BeginTransaction();
try
{
List<int> list = entitys.Select(s => s.Id).ToList();
var res = await _context.Box
.Include(s => s.Details)
.Where(f => list.Contains(f.Id)).ToListAsync();
_mapper.ToMapList(entitys, res);
_mapper.ToMapList(entitys.SelectMany(s => s.Details).ToList(), res.SelectMany(s => s.Details).ToList());
await _context.SaveChangesAsync();
if (_transaction != null)
_transaction.Commit();
}
catch (Exception ex)
{
if (_transaction != null)
_transaction.Rollback();
return false;
}
return true;
}
}
}

View File

@@ -1,6 +1,7 @@
using AutoMapper;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -70,6 +71,34 @@ namespace WMS.Web.Repositories
}
}
/// <summary>
/// 批量添加
/// </summary>
/// <param name="entity"></param>
/// <param name="isTransaction"></param>
/// <returns></returns>
public async Task<bool> AddRange(List<ChangeBoxRecord> list, bool isTransaction = true)
{
IDbContextTransaction _transaction = null;
if (isTransaction)
_transaction = _context.Database.BeginTransaction();
try
{
_context.ChangeBoxRecord.AddRange(list);
await _context.SaveChangesAsync();
if (_transaction != null)
_transaction.Commit();
return true;
}
catch (Exception ex)
{
if (_transaction != null)
_transaction.Rollback();
return false;
}
}
/// <summary>
/// 列表
/// </summary>
@@ -98,12 +127,12 @@ namespace WMS.Web.Repositories
query = query.Where(w => EF.Functions.Like(w.srcBox.BoxBillNo, "%" + dto.SrcBox + "%"));
if (!string.IsNullOrEmpty(dto.DestBox))
query = query.Where(w => EF.Functions.Like(w.destBox.BoxBillNo, "%" + dto.DestBox + "%"));
if (dto.StockId != null)
query = query.Where(w => w.changeBox.StockId == dto.StockId);
if (dto.SrcSubStockId != null)
query = query.Where(w => w.changeBox.SrcSubStockId == dto.SrcSubStockId);
if (dto.DestSubStockId != null)
query = query.Where(w => w.changeBox.DestSubStockId == dto.DestSubStockId);
//if (dto.StockId != null)
// query = query.Where(w => w.changeBox.StockId == dto.StockId);
//if (dto.SrcSubStockId != null)
// query = query.Where(w => w.changeBox.SrcSubStockId == dto.SrcSubStockId);
//if (dto.DestSubStockId != null)
// query = query.Where(w => w.changeBox.DestSubStockId == dto.DestSubStockId);
if (dto.CreateBeginDate != null)
query = query.Where(w => w.changeBox.CreateTime >= dto.CreateBeginDate);
if (dto.CreateEndDate != null)
@@ -116,12 +145,12 @@ namespace WMS.Web.Repositories
MaterialName = "",
MaterialNumber = "",
Specifications = "",
Stock = _singleDataService.GetSingleData(SingleAction.Stocks, _loginRepositories.CompanyId, s.changeBox.StockId),
SerialNumbers = s.changeBox.SerialNumbers,
//Stock = _singleDataService.GetSingleData(SingleAction.Stocks, _loginRepositories.CompanyId, s.changeBox.StockId),
SerialNumbers = JsonConvert.SerializeObject(s.changeBox.SerialNumbers),
SrcBox = s.srcBox.BoxBillNo,
DestBox = s.destBox.BoxBillNo,
SrcSubStock = _singleDataService.GetSingleData(SingleAction.SubStocks, _loginRepositories.CompanyId, s.changeBox.SrcSubStockId),
DestSubStock = _singleDataService.GetSingleData(SingleAction.SubStocks, _loginRepositories.CompanyId, s.changeBox.DestSubStockId),
//SrcSubStock = _singleDataService.GetSingleData(SingleAction.SubStocks, _loginRepositories.CompanyId, s.changeBox.SrcSubStockId),
//DestSubStock = _singleDataService.GetSingleData(SingleAction.SubStocks, _loginRepositories.CompanyId, s.changeBox.DestSubStockId),
Creator = _singleDataService.GetSingleData(SingleAction.Staffs, _loginRepositories.CompanyId, s.changeBox.CreatorId),
CreateTime = s.changeBox.CreateTime.DateToStringSeconds()
#endregion

View File

@@ -1,9 +1,11 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Debug;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
using WMS.Web.Domain.Entitys;
using WMS.Web.Repositories.Configuration.Log;
@@ -35,6 +37,10 @@ namespace WMS.Web.Repositories.Configuration
{
ent.ToTable("t_wms_changebox_record");
ent.HasKey(x => x.Id);
ent.Property(f => f.SerialNumbers).HasConversion(
v => JsonConvert.SerializeObject(v),
v => JsonConvert.DeserializeObject<List<string>>(v));
});
//移箱
builder.Entity<MoveBoxRecord>(ent =>
@@ -197,6 +203,10 @@ namespace WMS.Web.Repositories.Configuration
{
ent.ToTable("t_ops_box_details");
ent.HasKey(x => x.Id);
ent.Property(f => f.SerialNumbers).HasConversion(
v => JsonConvert.SerializeObject(v),
v => JsonConvert.DeserializeObject<List<string>>(v));
});
#endregion