154 lines
5.4 KiB
C#
154 lines
5.4 KiB
C#
using System.Collections.Concurrent;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Seyounth.Core.Extensions;
|
|
using Seyounth.Hyosung.Data.Entities;
|
|
using Seyounth.Hyosung.Data.Models;
|
|
using Seyounth.Hyosung.Data.Repositories;
|
|
using Seyounth.Hyosung.Data.Services.Hyosung;
|
|
using Seyounth.Hyosung.Data.Services.Hyosung.Entities;
|
|
using SqlSugar;
|
|
|
|
namespace Seyounth.Hyosung.Data.Services;
|
|
|
|
public class TrayService : ITrayService
|
|
{
|
|
//private readonly ConcurrentDictionary<string, Tray> _cache = new();
|
|
// private readonly <TrayEntity> _repository;
|
|
private readonly IHyosungWmsService _hyosungWmsService;
|
|
|
|
private readonly ISqlSugarClient _db;
|
|
|
|
public TrayService(IServiceProvider provider, IHyosungWmsService hyosungWmsService, ISqlSugarClient db)
|
|
{
|
|
_db = db;
|
|
// _repository = provider.CreateScope().ServiceProvider.GetRequiredService<IRepository<TrayEntity>>();
|
|
//_repository = provider.GetService<IRepository<TrayEntity>>();
|
|
// var trays = _db.Queryable<TrayEntity>().Where(t => t.ControlNo == null).ToListAsync().Result;
|
|
_hyosungWmsService = hyosungWmsService;
|
|
//foreach (var tray in trays)
|
|
//{
|
|
// _cache.TryAdd(tray.TrayCode, Tray.FromEntity(tray));
|
|
//}
|
|
}
|
|
|
|
public async Task<Tray> GeneraNewTray(int varietyId)
|
|
{
|
|
var tray = new Tray()
|
|
{
|
|
TrayCode = DateTime.Now.ToTimestamp().ToString(),
|
|
VarietyId = varietyId,
|
|
CreateTime = DateTime.Now
|
|
};
|
|
var count = await _db.CopyNew().Queryable<TrayEntity>().CountAsync(t => t.VarietyId == tray.VarietyId);
|
|
tray.IsEven = count % 2 == 0;
|
|
var identity = await _db.CopyNew().Insertable<TrayEntity>(tray.ToEntity()).ExecuteReturnIdentityAsync();
|
|
tray.Id = identity;
|
|
// _cache.TryAdd(tray.TrayCode, tray);
|
|
return tray;
|
|
}
|
|
|
|
public async Task<int> GetIdByCode(string code)
|
|
{
|
|
//try
|
|
//{
|
|
// return _cache[code].Id;
|
|
//}
|
|
//catch
|
|
//{
|
|
return (await _db.CopyNew().Queryable<TrayEntity>().Where(d => d.TrayCode == code).FirstAsync()).Id;
|
|
// }
|
|
}
|
|
|
|
public async Task<Tray> GetByCode(string code)
|
|
{
|
|
return Tray.FromEntity(await _db.CopyNew().Queryable<TrayEntity>().Where(t => t.TrayCode == code).FirstAsync());
|
|
}
|
|
|
|
public Task StorageAsync(string trayCode, int stackHeight, int controlNo, MST_ITEM_2240_V itemInfo)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<Tray> PrintTrayAsync(string trayCode, MST_ITEM_2240_V itemInfo, Variety variety)
|
|
{
|
|
Tray tray;
|
|
//try
|
|
//{
|
|
// tray = _cache[trayCode];
|
|
//}
|
|
//catch
|
|
//{
|
|
tray = await GetByCode(trayCode);
|
|
//}
|
|
|
|
tray.Grade = itemInfo.GRADE;
|
|
tray.Type = itemInfo.TYPE;
|
|
tray.DenFila = itemInfo.DEN_FILA;
|
|
tray.DtexFila = itemInfo.DTEX_FILA;
|
|
tray.Unit = itemInfo.UNIT;
|
|
tray.NetWeight = variety.NetWeight ?? itemInfo.NET_WEIGHT;
|
|
tray.GrossWeight = variety.GrossWeight ?? itemInfo.GROSS_WEIGHT;
|
|
tray.Barcode =
|
|
$"{itemInfo.ITEM_CODE} {DateTime.Now:yyMMdd}00{itemInfo.LOTNO.PadLeft(4, '0')}{tray.ControlNo?.ToString().PadLeft(4, '0')}0";
|
|
await _db.Updateable<TrayEntity>(tray.ToEntity()).ExecuteCommandAsync();
|
|
// _cache.Remove(tray.TrayCode, out _);
|
|
return tray;
|
|
}
|
|
|
|
public async Task StorageAsync(string trayCode)
|
|
{
|
|
var tray = await _db.CopyNew().Queryable<TrayEntity>().Where(d => d.TrayCode == trayCode).FirstAsync();
|
|
tray.FinishTime = DateTime.Now;
|
|
tray.IsPacking = true;
|
|
await _db.CopyNew().Updateable<TrayEntity>(tray).ExecuteCommandAsync();
|
|
// _cache.TryRemove(tray.TrayCode, out _);
|
|
}
|
|
|
|
public async Task UpdateHeightAsync(string trayCode, int height)
|
|
{
|
|
await _db.CopyNew().Updateable<TrayEntity>()
|
|
.Where(x => x.TrayCode == trayCode)
|
|
.SetColumns(x => x.StackHeight, height)
|
|
.SetColumns(x => x.IsPacking, false)
|
|
.ExecuteCommandAsync();
|
|
}
|
|
|
|
public Task ExportedAsync(string trayCode)
|
|
{
|
|
return _db.CopyNew().Updateable<TrayEntity>()
|
|
.Where(x => x.TrayCode == trayCode)
|
|
.SetColumns(x => x.Exported, true).ExecuteCommandAsync();
|
|
}
|
|
|
|
public async Task<List<string>> GetNoExportCodesAsync()
|
|
{
|
|
var tray = await _db.CopyNew().Queryable<TrayEntity>().Where(x => x.Exported != true && x.FinishTime != null)
|
|
.ToListAsync();
|
|
var trayCodes = tray.Select(x => x.TrayCode).ToList();
|
|
return trayCodes;
|
|
}
|
|
|
|
public Task SetControlNoAsync(string trayCode, int controlNo)
|
|
{
|
|
return _db.CopyNew()
|
|
.Updateable<TrayEntity>()
|
|
.Where(d => d.TrayCode == trayCode)
|
|
.SetColumns(x => x.ControlNo, controlNo)
|
|
.ExecuteCommandAsync();
|
|
}
|
|
|
|
public Task<List<Tray>> GetTodayTrayAsync()
|
|
{
|
|
return _db.CopyNew()
|
|
.Queryable<TrayEntity>()
|
|
.Where(x => x.FinishTime >= DateTime.Today && x.FinishTime < DateTime.Today.AddDays(1))
|
|
.ToListAsync(x => Tray.FromEntity(x));
|
|
}
|
|
|
|
public async Task<Tray> GetIsPacking()
|
|
{
|
|
var tray = await _db.CopyNew().Queryable<TrayEntity>().Where(x => x.IsPacking != null && x.IsPacking.Value)
|
|
.FirstAsync();
|
|
return Tray.FromEntity(tray);
|
|
}
|
|
} |