diff --git a/src/WMS.Web.Api/Controllers/BoxMarkController.cs b/src/WMS.Web.Api/Controllers/BoxMarkController.cs index 54969e70..6065e0f6 100644 --- a/src/WMS.Web.Api/Controllers/BoxMarkController.cs +++ b/src/WMS.Web.Api/Controllers/BoxMarkController.cs @@ -60,7 +60,7 @@ namespace WMS.Web.Api.Controllers /// [HttpPost] [Route("generate")] - public async Task DeleteAsync([FromBody] GenerateBoxMarkDto dto) + public async Task> DeleteAsync([FromBody] GenerateBoxMarkDto dto) { var loginInfo = _loginService.GetLoginInfo(this.HttpContext.Request.Headers["Authorization"]); if (loginInfo == null || loginInfo.UserInfo == null) diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml index b15fa025..25e4435d 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml @@ -355,6 +355,11 @@ 唯一ID + + + 明细编号ID + + 箱唛编号 @@ -430,6 +435,11 @@ 创建时间(生成时间) + + + 是否是尾箱 + + 生成箱唛dto diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml index 0d06f1eb..79d26275 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml @@ -280,21 +280,6 @@ ID - - - 箱唛编号 - - - - - 箱唛编号-首位 - - - - - 箱唛编号-末尾序号 - - 订单编号 @@ -355,6 +340,11 @@ 创建时间(生成时间) + + + 编号集合 + + 创建 @@ -368,6 +358,48 @@ + + + 箱唛表-编号表 + + + + + ID + + + + + 上级ID + + + + + 箱唛编号 + + + + + 箱唛编号-首位 + + + + + 箱唛编号-末尾序号 + + + + + 是否是尾箱 + + + + + 生成编号 + + + + wms改箱记录 @@ -2235,6 +2267,20 @@ + + + 列表-详情信息列表 + + + + + + + + 获取最新的编号实体 + + + 批量删除 diff --git a/src/WMS.Web.Core/Dto/BoxMark/BoxMarkQueryResponse.cs b/src/WMS.Web.Core/Dto/BoxMark/BoxMarkQueryResponse.cs index 53522453..a1630c9b 100644 --- a/src/WMS.Web.Core/Dto/BoxMark/BoxMarkQueryResponse.cs +++ b/src/WMS.Web.Core/Dto/BoxMark/BoxMarkQueryResponse.cs @@ -14,6 +14,11 @@ namespace WMS.Web.Core.Dto /// public int Id { get; set; } + /// + /// 明细编号ID + /// + public int DetailId { get; set; } + /// /// 箱唛编号 /// @@ -87,5 +92,10 @@ namespace WMS.Web.Core.Dto /// 创建时间(生成时间) /// public string CreateTime { get; set; } + + /// + /// 是否是尾箱 + /// + public bool IsTail { get; set; } } } diff --git a/src/WMS.Web.Core/Dto/BoxMark/GenerateBoxMarkDto.cs b/src/WMS.Web.Core/Dto/BoxMark/GenerateBoxMarkDto.cs index 39e349ae..94c61b2e 100644 --- a/src/WMS.Web.Core/Dto/BoxMark/GenerateBoxMarkDto.cs +++ b/src/WMS.Web.Core/Dto/BoxMark/GenerateBoxMarkDto.cs @@ -29,12 +29,14 @@ namespace WMS.Web.Core.Dto /// 产品数量 /// [Required(ErrorMessage = "产品数量不能为空")] + [Range(1, int.MaxValue, ErrorMessage = "产品数量不能为0")] public decimal ProductQty { get; set; } /// /// 装箱数量 /// [Required(ErrorMessage = "装箱数量不能为空")] + [Range(1, int.MaxValue, ErrorMessage = "装箱数量不能为0")] public decimal CratingQty { get; set; } /// diff --git a/src/WMS.Web.Domain/Entitys/BoxMark.cs b/src/WMS.Web.Domain/Entitys/BoxMark.cs index 46e5f054..0891f850 100644 --- a/src/WMS.Web.Domain/Entitys/BoxMark.cs +++ b/src/WMS.Web.Domain/Entitys/BoxMark.cs @@ -18,20 +18,20 @@ namespace WMS.Web.Domain.Entitys /// public override int Id { get; set; } - /// - /// 箱唛编号 - /// - public string BillNo { get; set; } + ///// + ///// 箱唛编号 + ///// + //public string BillNo { get; set; } - /// - /// 箱唛编号-首位 - /// - public int FirstBillNo { get; set; } + ///// + ///// 箱唛编号-首位 + ///// + //public int FirstBillNo { get; set; } - /// - /// 箱唛编号-末尾序号 - /// - public int LastBillNo { get; set; } + ///// + ///// 箱唛编号-末尾序号 + ///// + //public int LastBillNo { get; set; } /// /// 订单编号 @@ -93,6 +93,11 @@ namespace WMS.Web.Domain.Entitys /// public DateTime CreateTime { get; set; } + /// + /// 编号集合 + /// + public List BillNos { get; set; } = new List(); + /// /// 创建 /// @@ -108,27 +113,36 @@ namespace WMS.Web.Domain.Entitys /// /// /// - public void GenerateBillNo(int firstBillNo,int lastBillNo) + public void GenerateBillNo(int firstBillNo, int lastBillNo) { - this.FirstBillNo=Convert.ToInt32(DateTime.Now.ToString("yyMMdd")); - if (this.FirstBillNo == firstBillNo) - this.LastBillNo = lastBillNo + 1; - else - this.LastBillNo = 1; + if (this.BillNos == null) + this.BillNos = new List(); - if (this.LastBillNo.ToString().Length >= 5) - { - this.BillNo = "XM" + this.FirstBillNo + this.LastBillNo; - return; - } + //计算要装的箱数量 + var boxCount_tag = this.ProductQty / this.CratingQty; + var boxCount = Convert.ToInt32(boxCount_tag); - string lastStr = this.LastBillNo.ToString(); - while (true) + //判断是否存在小数点;true表明有尾箱数,false没有尾箱数 + var hasPart = Math.Floor(boxCount_tag) != boxCount_tag; + + //有小数点向上取整 + if (hasPart) + boxCount = Convert.ToInt32(Math.Ceiling(boxCount_tag)); + + for (int i = 0; i < boxCount; i++) { - lastStr = "0" + lastStr; - if (lastStr.Length >= 5) break; + //添加编号生成 + var bill = new BoxMarkBillNo(); + bill.GenerateBillNo(firstBillNo, lastBillNo); + this.BillNos.Add(bill); + + //改变前后的billNo值,新的值再一次被使用 + firstBillNo = bill.FirstBillNo; + lastBillNo = bill.LastBillNo; } - this.BillNo = "XM" + this.FirstBillNo + lastStr; + //判断有小数点,那么它就有尾箱,把当前第一条的编号是否是尾箱字段改为true + if (this.BillNos.Count != 0 && hasPart) + this.BillNos[0].IsTail = true; } } diff --git a/src/WMS.Web.Domain/Entitys/BoxMarkBillNo.cs b/src/WMS.Web.Domain/Entitys/BoxMarkBillNo.cs new file mode 100644 index 00000000..45b668f5 --- /dev/null +++ b/src/WMS.Web.Domain/Entitys/BoxMarkBillNo.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Text; +using WMS.Web.Core; + +namespace WMS.Web.Domain.Entitys +{ + /// + /// 箱唛表-编号表 + /// + [Serializable] + [Table("t_wms_box_mark_billno")] + public class BoxMarkBillNo : EntityBase + { + /// + /// ID + /// + public override int Id { get; set; } + + /// + /// 上级ID + /// + public int Fid { get; set; } + + /// + /// 箱唛编号 + /// + public string BillNo { get; set; } + + /// + /// 箱唛编号-首位 + /// + public int FirstBillNo { get; set; } + + /// + /// 箱唛编号-末尾序号 + /// + public int LastBillNo { get; set; } + + /// + /// 是否是尾箱 + /// + public bool IsTail { get; set; } + + /// + /// 生成编号 + /// + /// + /// + public void GenerateBillNo(int firstBillNo, int lastBillNo) + { + this.FirstBillNo = Convert.ToInt32(DateTime.Now.ToString("yyMMdd")); + if (this.FirstBillNo == firstBillNo) + this.LastBillNo = lastBillNo + 1; + else + this.LastBillNo = 1; + + if (this.LastBillNo.ToString().Length >= 5) + { + this.BillNo = "XM" + this.FirstBillNo + this.LastBillNo; + return; + } + + string lastStr = this.LastBillNo.ToString(); + while (true) + { + lastStr = "0" + lastStr; + if (lastStr.Length >= 5) break; + } + this.BillNo = "XM" + this.FirstBillNo + lastStr; + } + } +} diff --git a/src/WMS.Web.Domain/IService/IBoxMarkService.cs b/src/WMS.Web.Domain/IService/IBoxMarkService.cs index 6c4dd3e7..71645a22 100644 --- a/src/WMS.Web.Domain/IService/IBoxMarkService.cs +++ b/src/WMS.Web.Domain/IService/IBoxMarkService.cs @@ -19,6 +19,6 @@ namespace WMS.Web.Domain.IService /// /// /// - Task Generate(GenerateBoxMarkDto dto, LoginInDto loginInfo); + Task> Generate(GenerateBoxMarkDto dto, LoginInDto loginInfo); } } diff --git a/src/WMS.Web.Domain/Infrastructure/IBoxMarkRepositories.cs b/src/WMS.Web.Domain/Infrastructure/IBoxMarkRepositories.cs index 47249f4a..1fae1b0d 100644 --- a/src/WMS.Web.Domain/Infrastructure/IBoxMarkRepositories.cs +++ b/src/WMS.Web.Domain/Infrastructure/IBoxMarkRepositories.cs @@ -26,7 +26,7 @@ namespace WMS.Web.Domain.Infrastructure /// /// /// - Task Add(BoxMark entity, bool isTransaction = true); + Task Add(BoxMark entity, bool isTransaction = true); /// /// 详情-根据最新的ID @@ -34,6 +34,20 @@ namespace WMS.Web.Domain.Infrastructure /// Task GetBy(); + /// + /// 列表-详情信息列表 + /// + /// + /// + /// + Task> GetListInfoBy(int id, int companyId); + + /// + /// 获取最新的编号实体 + /// + /// + Task GetLastBillNo(); + /// /// 批量删除 /// diff --git a/src/WMS.Web.Domain/Mappers/BoxMarkMapper.cs b/src/WMS.Web.Domain/Mappers/BoxMarkMapper.cs index 6b8598b7..0c829b83 100644 --- a/src/WMS.Web.Domain/Mappers/BoxMarkMapper.cs +++ b/src/WMS.Web.Domain/Mappers/BoxMarkMapper.cs @@ -12,6 +12,9 @@ namespace WMS.Web.Domain.Mappers public BoxMarkMapper() { CreateMap(); + + CreateMap() + .ForMember(x => x.BillNos, opt => opt.Ignore()); } } } diff --git a/src/WMS.Web.Domain/Services/BoxMarkService.cs b/src/WMS.Web.Domain/Services/BoxMarkService.cs index 091cec42..0ca9e9f9 100644 --- a/src/WMS.Web.Domain/Services/BoxMarkService.cs +++ b/src/WMS.Web.Domain/Services/BoxMarkService.cs @@ -37,26 +37,29 @@ namespace WMS.Web.Domain.Services /// /// /// - public async Task Generate(GenerateBoxMarkDto dto, LoginInDto loginInfo) + public async Task> Generate(GenerateBoxMarkDto dto, LoginInDto loginInfo) { //1.获取最新的箱唛信息 - var entity_new = await _boxMarkRepositories.GetBy(); + //var entity_new = await _boxMarkRepositories.GetBy(); + var billNo_new = await _boxMarkRepositories.GetLastBillNo(); //2.dto映射实体 var entity = new BoxMark(); entity= _mapper.Map(dto, entity); entity.Create(loginInfo.UserInfo.StaffId); - var new_firstBillNo = entity_new == null ? 0 : entity_new.FirstBillNo; - var new_lastBillNo = entity_new == null ? 0 : entity_new.LastBillNo; + int new_firstBillNo = billNo_new == null ? 0 : billNo_new.FirstBillNo; + int new_lastBillNo = billNo_new == null ? 0 : billNo_new.LastBillNo; entity.GenerateBillNo(new_firstBillNo, new_lastBillNo); //添加 - var isSuccess = await _boxMarkRepositories.Add(entity); - if (!isSuccess) - return Result.ReFailure(ResultCodes.DateWriteError); + var model = await _boxMarkRepositories.Add(entity); + if (model==null) + return ResultList.ReFailure(ResultCodes.DateWriteError); - return Result.ReSuccess(); + //返回列表-对应刚刚生成的数据和编号集合 + var list= await _boxMarkRepositories.GetListInfoBy(model.Id, loginInfo.UserInfo.CompanyId); + return ResultList.ReSuccess(list); } } } diff --git a/src/WMS.Web.Repositories/BoxMarkRepositories.cs b/src/WMS.Web.Repositories/BoxMarkRepositories.cs index c07b4da7..1dbb8873 100644 --- a/src/WMS.Web.Repositories/BoxMarkRepositories.cs +++ b/src/WMS.Web.Repositories/BoxMarkRepositories.cs @@ -71,7 +71,11 @@ namespace WMS.Web.Repositories 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); + //var query = _context.BoxMark.Where(adv => 1 == 1); + var query = _context.BoxMarkBillNo + .GroupJoin(_context.BoxMark, detail => detail.Fid, order => order.Id, (detail, orders) => new { detail, orders }) + .SelectMany(x => x.orders.DefaultIfEmpty(), (p, order) => new { p.detail, order }) + .Where(adv => 1 == 1); //编号查询 if (!string.IsNullOrEmpty(dto.BeginBillNo) && @@ -85,15 +89,15 @@ namespace WMS.Web.Repositories 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); + query = query.Where(w => w.detail.FirstBillNo >= begYMD && w.detail.FirstBillNo <= endYMD && w.detail.LastBillNo >= begNo && w.detail.LastBillNo <= endNo); } else - query = query.Where(w => w.BillNo == dto.BeginBillNo || w.BillNo == dto.EndBillNo); + query = query.Where(w => w.detail.BillNo == dto.BeginBillNo || w.detail.BillNo == dto.EndBillNo); } else if (!string.IsNullOrEmpty(dto.BeginBillNo)) - query = query.Where(w => w.BillNo == dto.BeginBillNo); + query = query.Where(w => w.detail.BillNo == dto.BeginBillNo); else if (!string.IsNullOrEmpty(dto.EndBillNo)) - query = query.Where(w => w.BillNo == dto.EndBillNo); + query = query.Where(w => w.detail.BillNo == dto.EndBillNo); //订单号查询 @@ -103,7 +107,7 @@ namespace WMS.Web.Repositories var orderBillNoList = orderBNS.Split(",").Where(x => !string.IsNullOrEmpty(x)).ToList(); if (orderBillNoList != null && orderBillNoList.Count != 0) { - query = query.Where(w => orderBillNoList.Contains(w.OrderBillNo)); + query = query.Where(w => orderBillNoList.Contains(w.order.OrderBillNo)); } } @@ -113,41 +117,42 @@ namespace WMS.Web.Repositories if (materials != null && materials.Count != 0) { var mids = materials.Select(x => x.MaterialId).ToList(); - query = query.Where(w => mids.Contains(w.MaterialId)); + query = query.Where(w => mids.Contains(w.order.MaterialId)); } } if (cr_ids.Count != 0) - query = query.Where(w => cr_ids.Contains(w.CreatorId)); + query = query.Where(w => cr_ids.Contains(w.order.CreatorId)); if (dto.BeginDate != null) - query = query.Where(w => w.CreateTime.Date >= dto.BeginDate.Value); + query = query.Where(w => w.order.CreateTime.Date >= dto.BeginDate.Value); if (dto.EndDate != null) - query = query.Where(w => w.CreateTime.Date <= dto.EndDate.Value); + query = query.Where(w => w.order.CreateTime.Date <= dto.EndDate.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 = _erpBasicDataExtendService.GetMaterialBarCode(materials, s.MaterialId), + Id = s.order.Id, + DetailId=s.detail.Id, + BillNo = s.detail.BillNo, + OrderBillNo = s.order.OrderBillNo, + MaterialName = _erpBasicDataExtendService.GetMaterialName(materials, s.order.MaterialId), + MaterialNumber = _erpBasicDataExtendService.GetMaterialNumber(materials, s.order.MaterialId), + Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, s.order.MaterialId), + BarCode = _erpBasicDataExtendService.GetMaterialBarCode(materials, s.order.MaterialId), - CratingQty = s.CratingQty, - CratingNetWeightQty = s.CratingNetWeightQty, - CratingGrossWeightQty = s.CratingGrossWeightQty, + CratingQty = s.order.CratingQty, + CratingNetWeightQty = s.order.CratingNetWeightQty, + CratingGrossWeightQty = s.order.CratingGrossWeightQty, - TailboxQty = s.TailboxQty, - TailboxNetWeightQty = s.TailboxNetWeightQty, - TailboxGrossWeightQty = s.TailboxGrossWeightQty, + TailboxQty = s.order.TailboxQty, + TailboxNetWeightQty = s.order.TailboxNetWeightQty, + TailboxGrossWeightQty = s.order.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(); + Creator = _singleDataService.GetSingleData(SingleAction.Staffs, companyId, s.order.CreatorId), + CreateTime = s.order.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"), + Remark = s.order.Remark + }).OrderByDescending(x => x.DetailId).Skip((dto.PageNo - 1) * dto.PageSize).Take(dto.PageSize).ToListAsync(); return (list, total); } @@ -158,7 +163,7 @@ namespace WMS.Web.Repositories /// /// /// - public async Task Add(BoxMark entity, bool isTransaction = true) + public async Task Add(BoxMark entity, bool isTransaction = true) { IDbContextTransaction _transaction = null; if (isTransaction) @@ -169,13 +174,13 @@ namespace WMS.Web.Repositories await _context.SaveChangesAsync(); if (_transaction != null) _transaction.Commit(); - return true; + return entity; } catch (Exception ex) { if (_transaction != null) _transaction.Rollback(); - return false; + return null; } } @@ -191,6 +196,59 @@ namespace WMS.Web.Repositories return entity; } + /// + /// 列表-详情信息列表 + /// + /// + /// + /// + public async Task> GetListInfoBy(int id, int companyId) + { + //1.获取物料集合和组织集合和供应商的集合 + var materials = new List(); + var materials_result = await _erpService.BillQueryForMaterial(); + if (materials_result.IsSuccess) + materials = materials_result.Data.ToList(); + + var query = _context.BoxMarkBillNo + .GroupJoin(_context.BoxMark, detail => detail.Fid, order => order.Id, (detail, orders) => new { detail, orders }) + .SelectMany(x => x.orders.DefaultIfEmpty(), (p, order) => new { p.detail, order }) + .Where(adv => adv.order.Id == id); + var list = await query.Select(s => new BoxMarkQueryResponse() + { + Id = s.order.Id, + DetailId = s.detail.Id, + BillNo = s.detail.BillNo, + OrderBillNo = s.order.OrderBillNo, + MaterialName = _erpBasicDataExtendService.GetMaterialName(materials, s.order.MaterialId), + MaterialNumber = _erpBasicDataExtendService.GetMaterialNumber(materials, s.order.MaterialId), + Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, s.order.MaterialId), + BarCode = _erpBasicDataExtendService.GetMaterialBarCode(materials, s.order.MaterialId), + CratingQty = s.order.CratingQty, + CratingNetWeightQty = s.order.CratingNetWeightQty, + CratingGrossWeightQty = s.order.CratingGrossWeightQty, + TailboxQty = s.order.TailboxQty, + TailboxNetWeightQty = s.order.TailboxNetWeightQty, + TailboxGrossWeightQty = s.order.TailboxGrossWeightQty, + Creator = _singleDataService.GetSingleData(SingleAction.Staffs, companyId, s.order.CreatorId), + CreateTime = s.order.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"), + Remark = s.order.Remark + }).OrderByDescending(x => x.DetailId).ToListAsync(); + + return list; + } + + /// + /// 详情-根据最新的ID + /// + /// + /// + public async Task GetLastBillNo() + { + var entity = await _context.BoxMarkBillNo.OrderByDescending(x => x.Id).FirstOrDefaultAsync(); + return entity; + } + /// /// 批量删除 /// @@ -203,7 +261,7 @@ namespace WMS.Web.Repositories _transaction = _context.Database.BeginTransaction(); try { - var list = await _context.BoxMark.Where(f => ids.Contains(f.Id)).ToListAsync(); + var list = await _context.BoxMark.Include(x=>x.BillNos).Where(f => ids.Contains(f.Id)).ToListAsync(); _context.BoxMark.RemoveRange(list); await _context.SaveChangesAsync(); diff --git a/src/WMS.Web.Repositories/Configuration/RepositoryDbContext.cs b/src/WMS.Web.Repositories/Configuration/RepositoryDbContext.cs index 06ae4eb4..f3fe4704 100644 --- a/src/WMS.Web.Repositories/Configuration/RepositoryDbContext.cs +++ b/src/WMS.Web.Repositories/Configuration/RepositoryDbContext.cs @@ -356,11 +356,24 @@ namespace WMS.Web.Repositories.Configuration { ent.ToTable("t_wms_box_mark"); ent.HasKey(x => x.Id); + + ent.HasMany(p => p.BillNos) + .WithOne() + .HasForeignKey(p => p.Fid) + .OnDelete(DeleteBehavior.Cascade); + }); + + //箱唛表-编号表 + builder.Entity(ent => + { + ent.ToTable("t_wms_box_mark_billno"); + ent.HasKey(x => x.Id); }); base.OnModelCreating(builder); } + public DbSet BoxMarkBillNo { get; set; } public DbSet BoxMark { get; set; } public DbSet FileDownManager { get; set; } public DbSet SerialNumbers { get; set; }