using AutoMapper.Configuration.Annotations;
using BarCode.Web.Core;
using BarCode.Web.Core.Help;
using BarCode.Web.Core.Internal.Results;
using BarCode.Web.Domain.Services.Public;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BarCode.Web.Domain.Entitys
{
///
/// 序列号 默认Id从 200000000 起始
/// alter table users AUTO_INCREMENT=200000000;
///
[Serializable]
[Table("t_barcode_serialnumbers")]
public class SerialNumbers : EntityLongBase
{
///
/// 主键 订单编号
///
[Column("Id")]
public override long Id { get; set; }
///
/// 组织Code
///
[Column("OrgCode")]
public string OrgCode { get; set; } = string.Empty;
///
/// 供应商code
///
[Column("SupplierCode")]
public string SupplierCode { get; set; } = "";
///
/// 生成记录Id
///
[Column("GenerateRecordId")]
public int GenerateRecordId { get; set; } = 0;
///
/// 序列号
///
[Column("SerialNumber")]
public string SerialNumber { get; set; } = string.Empty;
///
/// 套装(1代表单套,2代表2套,3代表3套) aLTER BY YZH
///
[Column("IsTwo")]
public int IsTwo { get; set; } =1;
///
///当次序号,用来记录当次所产生时所处的序列号
///
[Column("thisNumber")]
public int? thisNumber { get; set; } = 1;
///
/// 序列号
///
[Ignore]
public string SuitNumber { get; set; } = string.Empty;
///
/// 产生第二个
///
[Ignore]
public string TwoSerialNumber { get; set; } = string.Empty;
///
/// 物料Id
///
[Column("MaterialId")]
public int MaterialId { get; set; } = 0;
///
/// 物料编码
///
[Column("MaterialNumber")]
public string MaterialNumber { get; set; } = string.Empty;
///
/// 名称
///
[Column("MaterialName")]
public string? MaterialName { get; set; } = string.Empty;
///
/// 规格型号
///
[Column("Specifications")]
public string? Specifications { get; set; } = string.Empty;
///
///69码
///
[Column("BarCode")]
public string? BarCode { get; set; } = string.Empty;
///
/// 老物料编码(上一次物料编码)
///
[Column("Old_MaterialNumber")]
public string? Old_MaterialNumber { get; set; } = string.Empty;
///
/// 转换前规格型号(上一次规格型号)
///
[Column("old_Specifications")]
public string? old_Specifications { get; set; } = string.Empty;
///
/// 箱ID
///
[Column("BoxId")]
public int BoxId { get; set; } = 0;
///
/// 数字序列码
///
[Column("NumberCode")]
public string NumberCode { get; set; } = string.Empty;
///
/// 数字序列码
///
[Column("TwoNumberCode")]
public string? TwoNumberCode { get; set; } = string.Empty;
///
/// 数字序列码(不包含日期)
///
[Column("Number")]
public int Number { get; set; } = 1;
///
/// 是否使用
///
[Column("IsUse")]
public bool IsUse { get; set; } = false;
///
/// 创建人
///
[Column("CreatorId")]
public int CreatorId { get; set; } = 0;
///
/// 生成时间
///
[Column("CreateTime")]
public DateTime CreateTime { get; set; } = DateTime.Now;
///
/// 完成装箱时间
///
[Column("CompleteCartonTime")]
public DateTime? CompleteCartonTime { get; set; }
///
/// 打印次数
///
[Column("PrintNumber")]
public int PrintNumber { get; set; } = 0;
///
/// 下载次数
///
[Column("DownLoadNumber")]
public int DownLoadNumber { get; set; } = 0;
///
/// 最新打印时间
///
[Column("PrintTime")]
public DateTime? PrintTime { get; set; }
///
/// 最新下载时间
///
[Column("DownLoadTime")]
public DateTime? DownLoadTime { get; set; }
///
/// 是否使用的是数字序列码未使用null,数字序列码true,序列码false
///
[Column("IsUseNumber")]
public bool? IsUseNumber { get; set; } = null;
///
/// 生成序列码
///
public string GenerateSerialNumber()
{
string exclude = "ISOZ";
int? FLength = 6;
var idStr = Radix.ConvertRadix36((ulong)this.Id, exclude.ToCharArray()).PadLeft(FLength ?? 0, '0');
this.SerialNumber = this.SerialNumber + "-" + idStr;
return this.SerialNumber;
}
/////
///// 生成套装编码 alter by yzh
/////
//public void GenerateSuitNumber(string sn,)
//{
// string exclude = "ISOZ";
// int? FLength = 6;
// var idStr = Radix.ConvertRadix36((ulong)this.Id, exclude.ToCharArray()).PadLeft(FLength ?? 0, '0');
// this.SerialNumber = this.SerialNumber + "-" + idStr;
//}
///
/// 生成时间序列码
///
public void GenerateNumberCode()
{
//用户手动输入了 就不自动生成了
if (!string.IsNullOrEmpty(this.NumberCode)) return;
if (this.Number.ToString().Length >= 6)
{
this.NumberCode = this.CreateTime.ToString("yyMMdd") + this.Number.ToString();
return;
}
string idStr = this.Number.ToString();
while (true)
{
idStr = "0" + idStr;
if (idStr.Length >= 6) break;
}
this.NumberCode = this.CreateTime.ToString("yyMMdd") + idStr;
}
///
/// 产生套装编码 alter by yzh
///
///
public void GenerateSuitNumber(string sn)
{
this.SuitNumber = sn;
}
///
/// 设置thisNumber
///
///
public void SetThisNumber(int sn)
{
this.thisNumber = sn;
}
///
/// 产生第二个序列号
///
///
public void GenerateTwoSerialNumber(string sn)
{
this.TwoSerialNumber = sn;
}
///
/// 产生第二个数字序列号
///
///
public void GenerateTwoNumberCode(string sn)
{
this.TwoNumberCode = sn;
}
///
/// 打印
///
public void Print()
{
//被wms使用的数据不能被打印
if (this.BoxId <= 0 && this.IsUse == true) return;
this.PrintNumber++;
this.PrintTime = DateTime.Now;
}
///
/// 下载
///
public void DownLoad()
{
this.DownLoadNumber++;
this.DownLoadTime = DateTime.Now;
}
///
/// 是否不参与计数,0和空代表参与计数,1代表不参与计数
///
[Column("isNotCount")]
public string? IsNotCount { get; set; } = string.Empty;
///
/// 装箱
///
///
///
/// /// 是否不参与计数
public void CompleteBox(int boxId, string str,string isNotCount)
{
//每个序列码延时1毫秒来装箱 这样到时候获取序列码时就可以来排序
Thread.Sleep(1);
this.BoxId = boxId;
this.CompleteCartonTime = DateTime.Now;
this.IsUse = true;
this.IsUseNumber = this.NumberCode.Equals(str) ? true : false;
this.IsNotCount= isNotCount;
}
///
/// 解绑箱
///
public void UnBox()
{
this.BoxId = 0;
this.CompleteCartonTime = null;
this.IsUse = false;
this.IsUseNumber = null;
}
///
/// wms系统获取序列码后 序列码调整为已使用
///
public void WmsGet(string str)
{
this.BoxId = -1;
this.IsUse = true;
this.IsUseNumber = this.NumberCode.Equals(str) ? true : false;
}
///
/// 修改物料编码
///
///
public Result UpdateMaterial(string number,string MaterialName,string MaterialSpecifications,string MaterialBarCode, string old_Specifications)
{
if (this.IsUse)
return Result.ReFailure($"序列码 {this.SerialNumber} 已被使用,不允许规格转换", 600007);
if (!this.MaterialNumber.Equals(number))
{
this.Old_MaterialNumber = this.MaterialNumber;
this.old_Specifications = old_Specifications;
this.MaterialName= MaterialName;
this.Specifications= MaterialSpecifications;
this.BarCode= MaterialBarCode;
this.MaterialNumber = number;
}
return Result.ReSuccess();
}
}
}