修改生成规则

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;
}
}
}