修改生成规则

This commit is contained in:
tongfei
2024-02-18 16:53:18 +08:00
parent 8a3d4343a3
commit b3190e67e7
13 changed files with 332 additions and 85 deletions

View File

@@ -18,20 +18,20 @@ namespace WMS.Web.Domain.Entitys
/// </summary>
public override int Id { get; set; }
/// <summary>
/// 箱唛编号
/// </summary>
public string BillNo { get; set; }
///// <summary>
///// 箱唛编号
///// </summary>
//public string BillNo { get; set; }
/// <summary>
/// 箱唛编号-首位
/// </summary>
public int FirstBillNo { get; set; }
///// <summary>
///// 箱唛编号-首位
///// </summary>
//public int FirstBillNo { get; set; }
/// <summary>
/// 箱唛编号-末尾序号
/// </summary>
public int LastBillNo { get; set; }
///// <summary>
///// 箱唛编号-末尾序号
///// </summary>
//public int LastBillNo { get; set; }
/// <summary>
/// 订单编号
@@ -93,6 +93,11 @@ namespace WMS.Web.Domain.Entitys
/// </summary>
public DateTime CreateTime { get; set; }
/// <summary>
/// 编号集合
/// </summary>
public List<BoxMarkBillNo> BillNos { get; set; } = new List<BoxMarkBillNo>();
/// <summary>
/// 创建
/// </summary>
@@ -108,27 +113,36 @@ namespace WMS.Web.Domain.Entitys
/// </summary>
/// <param name="firstBillNo"></param>
/// <param name="lastBillNo"></param>
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<BoxMarkBillNo>();
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;
}
}

View File

@@ -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
{
/// <summary>
/// 箱唛表-编号表
/// </summary>
[Serializable]
[Table("t_wms_box_mark_billno")]
public class BoxMarkBillNo : EntityBase
{
/// <summary>
/// ID
/// </summary>
public override int Id { get; set; }
/// <summary>
/// 上级ID
/// </summary>
public int Fid { get; set; }
/// <summary>
/// 箱唛编号
/// </summary>
public string BillNo { get; set; }
/// <summary>
/// 箱唛编号-首位
/// </summary>
public int FirstBillNo { get; set; }
/// <summary>
/// 箱唛编号-末尾序号
/// </summary>
public int LastBillNo { get; set; }
/// <summary>
/// 是否是尾箱
/// </summary>
public bool IsTail { get; set; }
/// <summary>
/// 生成编号
/// </summary>
/// <param name="firstBillNo"></param>
/// <param name="lastBillNo"></param>
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;
}
}
}

View File

@@ -19,6 +19,6 @@ namespace WMS.Web.Domain.IService
/// <param name="dto"></param>
/// <param name="loginInfo"></param>
/// <returns></returns>
Task<Result> Generate(GenerateBoxMarkDto dto, LoginInDto loginInfo);
Task<ResultList<BoxMarkQueryResponse>> Generate(GenerateBoxMarkDto dto, LoginInDto loginInfo);
}
}

View File

@@ -26,7 +26,7 @@ namespace WMS.Web.Domain.Infrastructure
/// <param name="entity"></param>
/// <param name="isTransaction"></param>
/// <returns></returns>
Task<bool> Add(BoxMark entity, bool isTransaction = true);
Task<BoxMark> Add(BoxMark entity, bool isTransaction = true);
/// <summary>
/// 详情-根据最新的ID
@@ -34,6 +34,20 @@ namespace WMS.Web.Domain.Infrastructure
/// <returns></returns>
Task<BoxMark> GetBy();
/// <summary>
/// 列表-详情信息列表
/// </summary>
/// <param name="id"></param>
/// <param name="companyId"></param>
/// <returns></returns>
Task<List<BoxMarkQueryResponse>> GetListInfoBy(int id, int companyId);
/// <summary>
/// 获取最新的编号实体
/// </summary>
/// <returns></returns>
Task<BoxMarkBillNo> GetLastBillNo();
/// <summary>
/// 批量删除
/// </summary>

View File

@@ -12,6 +12,9 @@ namespace WMS.Web.Domain.Mappers
public BoxMarkMapper()
{
CreateMap<GenerateBoxMarkDto, BoxMark>();
CreateMap<BoxMark, BoxMark>()
.ForMember(x => x.BillNos, opt => opt.Ignore());
}
}
}

View File

@@ -37,26 +37,29 @@ namespace WMS.Web.Domain.Services
/// <param name="dto"></param>
/// <param name="loginInfo"></param>
/// <returns></returns>
public async Task<Result> Generate(GenerateBoxMarkDto dto, LoginInDto loginInfo)
public async Task<ResultList<BoxMarkQueryResponse>> 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<InStockTask>.ReFailure(ResultCodes.DateWriteError);
var model = await _boxMarkRepositories.Add(entity);
if (model==null)
return ResultList<BoxMarkQueryResponse>.ReFailure(ResultCodes.DateWriteError);
return Result.ReSuccess();
//返回列表-对应刚刚生成的数据和编号集合
var list= await _boxMarkRepositories.GetListInfoBy(model.Id, loginInfo.UserInfo.CompanyId);
return ResultList<BoxMarkQueryResponse>.ReSuccess(list);
}
}
}