using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WIDESEA_Core; using WIDESEA_Core.BaseServices; using WIDESEA_Core.Helper; using WIDESEA_IBasicRepository; using WIDESEA_IBasicService; using WIDESEA_Model.Models; namespace WIDESEA_BasicService { public class PalletCodeInfoService : ServiceBase, IPalletCodeInfoService { public PalletCodeInfoService(IPalletCodeInfoRepository BaseDal) : base(BaseDal) { } static object locker = new object(); public override WebResponseContent AddData(SaveModel saveModel) { int warehouseId = 0; int count = 0; if (saveModel.MainData.TryGetValue("warehouseId", out object? warehouse) && warehouse != null) { warehouseId = warehouse.ObjToInt(); } if (saveModel.MainData.TryGetValue("count", out object? countValue) && countValue != null) { count = countValue.ObjToInt(); } lock (locker) { List palletCodeInfos = new List(); int serialNo = 0; DateTime now = DateTime.Now; Dt_PalletCodeInfo palletCodeInfo = BaseDal.QueryFirst(x => x.WarehouseId == warehouseId, new Dictionary { { nameof(Dt_PalletCodeInfo.SerialNo), OrderByType.Desc } }); if (palletCodeInfo != null && palletCodeInfo.CreateDate.Year == now.Year && palletCodeInfo.CreateDate.Month == now.Month && palletCodeInfo.CreateDate.Day == now.Day) { serialNo = palletCodeInfo.SerialNo + 1; } else { serialNo = 1; } for (int i = 0; i < count; i++) { palletCodeInfos.Add(new Dt_PalletCodeInfo { SerialNo = serialNo, PalletCode = now.ToString("yyyyMMdd") + serialNo.ToString().PadLeft(3, '0'), PalletType = 1, PalletTypeId = 0, WarehouseId = warehouseId, Status = 0, Size = 0 }); serialNo = serialNo + 1; } return base.AddData(palletCodeInfos); } } } }