2025-06-23 15:41:15 +08:00
|
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
2025-06-25 16:06:49 +08:00
|
|
|
|
using NUglify.Helpers;
|
2025-07-01 14:20:07 +08:00
|
|
|
|
using Seyounth.Auto.Hs.Runtime.Plc;
|
|
|
|
|
|
using Seyounth.Auto.Hs.Runtime.Printer;
|
|
|
|
|
|
using Syc.Abp.Application.Contracts;
|
2025-06-23 15:41:15 +08:00
|
|
|
|
using Syc.Basic.Web.WMS.Dto;
|
|
|
|
|
|
using Syc.Basic.Web.WMS.Entitys;
|
2025-07-01 14:20:07 +08:00
|
|
|
|
using Syc.Basic.Web.WMS.IService;
|
2025-06-23 15:41:15 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
2025-06-25 16:06:49 +08:00
|
|
|
|
using System.Linq.Dynamic.Core;
|
2025-06-23 15:41:15 +08:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2025-07-01 14:20:07 +08:00
|
|
|
|
using Volo.Abp.DependencyInjection;
|
2025-06-23 15:41:15 +08:00
|
|
|
|
using Volo.Abp.Domain.Repositories;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Syc.Basic.Web.WMS.Service
|
|
|
|
|
|
{
|
|
|
|
|
|
[AllowAnonymous]
|
2025-07-01 14:20:07 +08:00
|
|
|
|
public class BoxService : ApiService, IBoxService, ITransientDependency
|
2025-06-23 15:41:15 +08:00
|
|
|
|
{
|
|
|
|
|
|
private readonly IRepository<Box> boxRepository;
|
2025-07-01 14:20:07 +08:00
|
|
|
|
private readonly IRepository<Produce> produceRepository;
|
|
|
|
|
|
private readonly IRepository<Silk> silkRepository;
|
|
|
|
|
|
private readonly IPlcService plcService;
|
2025-06-23 15:41:15 +08:00
|
|
|
|
private readonly ILogger<BoxService> logger;
|
2025-07-01 14:20:07 +08:00
|
|
|
|
private readonly IPrinterService printerService;
|
2025-10-31 09:56:25 +08:00
|
|
|
|
private readonly IRepository<AutoLabel> autoRepository;
|
2025-06-23 15:41:15 +08:00
|
|
|
|
|
2025-10-31 09:56:25 +08:00
|
|
|
|
public BoxService(IRepository<Box> boxRepository, IRepository<Produce> produceRepository, IRepository<Silk> silkRepository, IPlcService plcService, ILogger<BoxService> logger, IPrinterService printerService, IRepository<AutoLabel> autoRepository)
|
2025-06-23 15:41:15 +08:00
|
|
|
|
{
|
|
|
|
|
|
this.boxRepository = boxRepository;
|
2025-07-01 14:20:07 +08:00
|
|
|
|
this.produceRepository = produceRepository;
|
|
|
|
|
|
this.silkRepository = silkRepository;
|
|
|
|
|
|
this.plcService = plcService;
|
2025-06-23 15:41:15 +08:00
|
|
|
|
this.logger = logger;
|
2025-07-01 14:20:07 +08:00
|
|
|
|
this.printerService = printerService;
|
2025-10-31 09:56:25 +08:00
|
|
|
|
this.autoRepository = autoRepository;
|
2025-06-23 15:41:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 查询纸箱
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost]
|
2025-06-25 16:06:49 +08:00
|
|
|
|
public async Task<PageOutput<BoxDto>> GetBoxList(BoxInput input)
|
2025-06-23 15:41:15 +08:00
|
|
|
|
{
|
|
|
|
|
|
var boxlist = await boxRepository.GetQueryableAsync();
|
2025-06-24 18:26:51 +08:00
|
|
|
|
boxlist = boxlist.Where(x => x.IsDelete == 0);
|
2025-06-25 16:06:49 +08:00
|
|
|
|
if (input.Lot_No != null)
|
2025-07-01 14:20:07 +08:00
|
|
|
|
boxlist = boxlist.Where(x => x.Lot_No.Contains(input.Lot_No));
|
2025-06-23 15:41:15 +08:00
|
|
|
|
if (input.Spec != null)
|
|
|
|
|
|
boxlist = boxlist.Where(x => x.Spec.Contains(input.Spec));
|
|
|
|
|
|
|
2025-10-31 09:56:25 +08:00
|
|
|
|
var result = boxlist.OrderByDescending(x => x.Id).PageResult(input.Page, input.PageSize);
|
2025-06-25 16:06:49 +08:00
|
|
|
|
var data = result.Queryable.Select(e => new BoxDto()
|
2025-06-23 15:41:15 +08:00
|
|
|
|
{
|
|
|
|
|
|
Length = e.Length,
|
|
|
|
|
|
Net_Weight = e.Net_Weight,
|
|
|
|
|
|
Qty = e.Qty,
|
|
|
|
|
|
Id = e.Id,
|
|
|
|
|
|
Code = e.Code,
|
2025-10-31 09:56:25 +08:00
|
|
|
|
Dom_Time = DateTime.Parse(e.Dom_Time.ToString()).ToString("yyyy-MM-dd HH:mm:ss"),
|
|
|
|
|
|
DataType = e.DataType,
|
|
|
|
|
|
Mark = e.Mark,
|
|
|
|
|
|
Create_Time = e.Create_Time,
|
|
|
|
|
|
Exp_Time = DateTime.Parse(e.Exp_Time.ToString()).ToString("yyyy-MM-dd HH:mm:ss"),
|
2025-06-23 15:41:15 +08:00
|
|
|
|
Lot_No = e.Lot_No,
|
|
|
|
|
|
Spec = e.Spec,
|
2025-07-01 14:20:07 +08:00
|
|
|
|
Gross_Weight = e.Gross_Weight,
|
|
|
|
|
|
Type = e.Type
|
2025-06-23 15:41:15 +08:00
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
PageOutput<BoxDto> pageOutput = new PageOutput<BoxDto>();
|
|
|
|
|
|
pageOutput.Total = boxlist.Count();
|
2025-10-31 09:56:25 +08:00
|
|
|
|
pageOutput.Data = data;
|
2025-06-25 16:06:49 +08:00
|
|
|
|
pageOutput.PageIndex = input.Page;
|
2025-10-31 09:56:25 +08:00
|
|
|
|
pageOutput.PageSize = input.PageSize;
|
2025-06-23 15:41:15 +08:00
|
|
|
|
return pageOutput;
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
2025-07-01 14:20:07 +08:00
|
|
|
|
/// 查询数量纸箱
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
|
public async Task<List<BoxDto>> GetBoxByNum()
|
|
|
|
|
|
{
|
2025-10-31 09:56:25 +08:00
|
|
|
|
var produce = await produceRepository.FirstOrDefaultAsync(x => x.IfUse == 1);
|
|
|
|
|
|
if (produce == null)
|
|
|
|
|
|
throw Oops.Oh("没有生产设置");
|
|
|
|
|
|
//var silks = await silkRepository.GetListAsync(x=>x.Status==1||x.Status==0);
|
2025-07-01 14:20:07 +08:00
|
|
|
|
var boxlist = await boxRepository.GetQueryableAsync();
|
2025-10-31 09:56:25 +08:00
|
|
|
|
boxlist = boxlist.Where(x => x.IsDelete == 0 && x.Spec == produce.Spec && x.Type == produce.Type && x.Lot_No == produce.Lot_No);
|
|
|
|
|
|
|
|
|
|
|
|
var data = boxlist.Where(x => x.DataType == 0).Select(e => new BoxDto()
|
2025-07-01 14:20:07 +08:00
|
|
|
|
{
|
|
|
|
|
|
Net_Weight = e.Net_Weight,
|
|
|
|
|
|
Id = e.Id,
|
2025-10-31 09:56:25 +08:00
|
|
|
|
Code = e.Code,
|
|
|
|
|
|
DataType = e.DataType,
|
|
|
|
|
|
Mark = e.Mark
|
2025-07-01 14:20:07 +08:00
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
2025-10-31 09:56:25 +08:00
|
|
|
|
return data.OrderByDescending(x => x.Id).Take(15).ToList();
|
2025-07-01 14:20:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
2025-06-23 15:41:15 +08:00
|
|
|
|
/// 添加纸箱
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
public async Task InsertBox(BoxDto input)
|
|
|
|
|
|
{
|
2025-10-31 09:56:25 +08:00
|
|
|
|
var produce = await produceRepository.FirstOrDefaultAsync(x => x.IfUse == 1);
|
|
|
|
|
|
var silksQuery = await silkRepository.GetQueryableAsync();
|
|
|
|
|
|
var silks = silksQuery.Where(x => x.IsDelete == 0 && x.Status == (int)SilkStatus.手动添加称重).OrderBy(x => x.Id).Take((int)produce.Qty).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
if (produce == null)
|
|
|
|
|
|
throw Oops.Oh("没有生产设置");
|
|
|
|
|
|
|
|
|
|
|
|
if (silks.Count < produce.Qty)
|
|
|
|
|
|
{
|
|
|
|
|
|
logger.LogWarning($"没有{produce.Qty}条{produce.Type}的单品的信息,只有{silks.Count}条,无法创建码垛信息");
|
|
|
|
|
|
throw Oops.Oh($"没有{produce.Qty}条{produce.Type}的单品的信息,只有{silks.Count}条,无法创建码垛信息");
|
|
|
|
|
|
//return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var netWeight = silks.Sum(x => x.Net_Weight);
|
|
|
|
|
|
var weight = silks.Average(x => x.Net_Weight);
|
|
|
|
|
|
|
|
|
|
|
|
var date = DateOnly.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
|
|
|
|
|
|
var autolabel = await autoRepository.FirstOrDefaultAsync(x => x.Date == date && x.Type == (int)AutoLabelType.成箱码垛流水号);
|
|
|
|
|
|
var timestr = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
|
|
|
|
|
|
|
|
|
|
if (autolabel == null)
|
2025-07-01 14:20:07 +08:00
|
|
|
|
{
|
2025-10-31 09:56:25 +08:00
|
|
|
|
autolabel = await autoRepository.InsertAsync(new AutoLabel()
|
|
|
|
|
|
{
|
|
|
|
|
|
Date = date,
|
|
|
|
|
|
Sort = 0,
|
|
|
|
|
|
Mark = timestr,
|
|
|
|
|
|
Type = (int)AutoLabelType.成箱码垛流水号
|
|
|
|
|
|
}, true);
|
|
|
|
|
|
|
2025-07-01 14:20:07 +08:00
|
|
|
|
}
|
2025-10-31 09:56:25 +08:00
|
|
|
|
autolabel.Sort += 1;
|
|
|
|
|
|
logger.LogInformation("手动添加成箱信息" + timestr + autolabel.Sort.ToString().PadLeft(4, '0'));
|
|
|
|
|
|
await autoRepository.UpdateAsync(autolabel);
|
2025-06-25 16:06:49 +08:00
|
|
|
|
|
2025-06-23 15:41:15 +08:00
|
|
|
|
var box = new Box()
|
|
|
|
|
|
{
|
|
|
|
|
|
Dom_Time = DateTime.Now,
|
2025-10-31 09:56:25 +08:00
|
|
|
|
Exp_Time = produce.Exp_Time,
|
|
|
|
|
|
Qty = produce.Qty,
|
|
|
|
|
|
Length = produce.Length,
|
|
|
|
|
|
Lot_No = produce.Lot_No,
|
|
|
|
|
|
Code = timestr + autolabel.Sort.ToString().PadLeft(4, '0'),
|
|
|
|
|
|
Net_Weight = netWeight,
|
|
|
|
|
|
Spec = produce.Spec,
|
|
|
|
|
|
Create_Time = DateTime.Now,
|
|
|
|
|
|
Type = produce.Type,
|
|
|
|
|
|
IsUse = true,
|
|
|
|
|
|
IsDelete = 0,
|
|
|
|
|
|
DataType = (int)BoxDataType.手动装箱,
|
|
|
|
|
|
Mark = "已经手动添加装箱信息"
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var entity = await boxRepository.InsertAsync(box, true);
|
|
|
|
|
|
|
|
|
|
|
|
logger.LogInformation($"已手动添加装箱信息,装箱编号:{box.Code},包含单品数量:{silks.Count}");
|
|
|
|
|
|
|
|
|
|
|
|
List<Silk> list = new List<Silk>();
|
|
|
|
|
|
foreach (var silk in silks)
|
|
|
|
|
|
{
|
|
|
|
|
|
silk.Status = (int)SilkStatus.已手动装箱;
|
|
|
|
|
|
silk.BoxId = entity.Id;
|
|
|
|
|
|
silk.Status_Details = "已手动装箱";
|
|
|
|
|
|
list.Add(silk);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await silkRepository.UpdateManyAsync(list);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 添加纸箱
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
public async Task AddInsertBox(BoxDto input)
|
|
|
|
|
|
{
|
|
|
|
|
|
var date = DateOnly.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
|
|
|
|
|
|
var autolabel = await autoRepository.FirstOrDefaultAsync(x => x.Date == date && x.Type == (int)AutoLabelType.成箱码垛流水号);
|
|
|
|
|
|
var timestr = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
|
|
|
|
|
|
|
|
|
|
if (autolabel == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
autolabel = await autoRepository.InsertAsync(new AutoLabel()
|
|
|
|
|
|
{
|
|
|
|
|
|
Date = date,
|
|
|
|
|
|
Sort = 0,
|
|
|
|
|
|
Mark = timestr,
|
|
|
|
|
|
Type = (int)AutoLabelType.成箱码垛流水号
|
|
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
autolabel.Sort += 1;
|
|
|
|
|
|
logger.LogInformation("手动添加成箱信息" + timestr + autolabel.Sort.ToString().PadLeft(4, '0'));
|
|
|
|
|
|
await autoRepository.UpdateAsync(autolabel);
|
|
|
|
|
|
|
|
|
|
|
|
var box = new Box()
|
|
|
|
|
|
{
|
|
|
|
|
|
Dom_Time = DateTime.Now,
|
|
|
|
|
|
Exp_Time = DateTime.Parse(input.Exp_Time),
|
2025-06-23 15:41:15 +08:00
|
|
|
|
Qty = input.Qty,
|
|
|
|
|
|
Length = input.Length,
|
|
|
|
|
|
Lot_No = input.Lot_No,
|
2025-10-31 09:56:25 +08:00
|
|
|
|
Code = timestr + autolabel.Sort.ToString().PadLeft(4, '0'),
|
2025-06-23 15:41:15 +08:00
|
|
|
|
Net_Weight = input.Net_Weight,
|
2025-06-24 18:26:51 +08:00
|
|
|
|
Spec = input.Spec,
|
2025-10-31 09:56:25 +08:00
|
|
|
|
Create_Time = DateTime.Now,
|
|
|
|
|
|
Type = input.Type,
|
2025-07-01 14:20:07 +08:00
|
|
|
|
IsUse = true,
|
2025-10-31 09:56:25 +08:00
|
|
|
|
IsDelete = 0,
|
|
|
|
|
|
DataType = (int)BoxDataType.手动成箱未包含单品信息,
|
|
|
|
|
|
Mark = "手动添加的成箱信息数据库未绑定单品信息"
|
2025-06-23 15:41:15 +08:00
|
|
|
|
};
|
2025-07-01 14:20:07 +08:00
|
|
|
|
|
2025-10-31 09:56:25 +08:00
|
|
|
|
var entity = await boxRepository.InsertAsync(box, true);
|
2025-07-01 14:20:07 +08:00
|
|
|
|
|
2025-10-31 09:56:25 +08:00
|
|
|
|
logger.LogInformation($"手动添加的成箱信息未绑定单品信息:{box.Code},未含单品数量");
|
|
|
|
|
|
|
|
|
|
|
|
BarTenderHelper.BoxPrint(box);
|
|
|
|
|
|
logger.LogInformation($"打印条码{box.Code},成箱标签打印成功");
|
2025-07-01 14:20:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 打印纸箱
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
public async Task PrintBox(DelInput input)
|
|
|
|
|
|
{
|
2025-10-31 09:56:25 +08:00
|
|
|
|
var box = await boxRepository.FirstOrDefaultAsync(x => x.Id == input.id);
|
|
|
|
|
|
|
|
|
|
|
|
BarTenderHelper.BoxPrint(box);
|
|
|
|
|
|
logger.LogInformation($"打印条码{box.Code},成箱标签打印成功");
|
|
|
|
|
|
//throw Oops.Oh("成箱标签打印成功");
|
|
|
|
|
|
|
2025-07-01 14:20:07 +08:00
|
|
|
|
|
2025-06-23 15:41:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 修改纸箱
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
public async Task UpdateBox(BoxDto input)
|
|
|
|
|
|
{
|
|
|
|
|
|
var box = await boxRepository.FirstOrDefaultAsync(x => x.Id == input.Id);
|
|
|
|
|
|
|
|
|
|
|
|
box.Spec = input.Spec;
|
|
|
|
|
|
box.Length = input.Length;
|
2025-10-31 09:56:25 +08:00
|
|
|
|
//box.Code = input.Code;
|
2025-06-23 15:41:15 +08:00
|
|
|
|
box.Lot_No = input.Lot_No;
|
|
|
|
|
|
box.Net_Weight = input.Net_Weight;
|
|
|
|
|
|
box.Dom_Time = DateTime.Now;
|
2025-10-31 09:56:25 +08:00
|
|
|
|
box.Type = input.Type;
|
2025-06-23 15:41:15 +08:00
|
|
|
|
box.Qty = input.Qty;
|
2025-06-25 16:06:49 +08:00
|
|
|
|
box.Exp_Time = string.IsNullOrWhiteSpace(input.Exp_Time) ? null : Convert.ToDateTime(input.Exp_Time);
|
2025-06-23 15:41:15 +08:00
|
|
|
|
await boxRepository.UpdateAsync(box);
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 删除纸箱
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost]
|
2025-06-25 16:06:49 +08:00
|
|
|
|
public async Task DeleteBox(DelInput input)
|
2025-06-23 15:41:15 +08:00
|
|
|
|
{
|
2025-06-24 18:26:51 +08:00
|
|
|
|
var box = await boxRepository.FirstOrDefaultAsync(x => x.Id == input.id);
|
|
|
|
|
|
if (box == null)
|
2025-06-23 15:41:15 +08:00
|
|
|
|
throw Oops.Oh("删除失败,数据为空");
|
2025-06-24 18:26:51 +08:00
|
|
|
|
box.IsDelete = 1;
|
|
|
|
|
|
await boxRepository.UpdateAsync(box);
|
2025-06-23 15:41:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 批量删除纸箱
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost]
|
2025-06-25 16:06:49 +08:00
|
|
|
|
public async Task DeletesBoxs(DelInput input)
|
2025-06-23 15:41:15 +08:00
|
|
|
|
{
|
2025-06-24 18:26:51 +08:00
|
|
|
|
var boxs = await boxRepository.GetListAsync(x => input.ids.Contains(x.Id));
|
|
|
|
|
|
if (boxs.Count == 0)
|
2025-06-23 15:41:15 +08:00
|
|
|
|
throw Oops.Oh("删除失败,数据为空");
|
2025-10-31 09:56:25 +08:00
|
|
|
|
for (var i = 0; i < boxs.Count; i++)
|
2025-06-24 18:26:51 +08:00
|
|
|
|
{
|
|
|
|
|
|
boxs[i].IsDelete = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
await boxRepository.UpdateManyAsync(boxs);
|
2025-06-23 15:41:15 +08:00
|
|
|
|
}
|
2025-07-01 14:20:07 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设置热缩机温度
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task SetTemperature(ByIdInput<short> input)
|
|
|
|
|
|
{
|
2025-10-31 09:56:25 +08:00
|
|
|
|
await plcService.SetTemperatureAsync(input.Id);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 复位
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
|
public async Task ClearData()
|
|
|
|
|
|
{
|
|
|
|
|
|
await plcService.ClearData();
|
2025-07-01 14:20:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设置热缩机温度
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task<int> GetTemperature()
|
|
|
|
|
|
{
|
2025-10-31 09:56:25 +08:00
|
|
|
|
return await plcService.GetTemperatureAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 整箱码垛打印标签
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
public async Task BoxsPalletPrint(FullPalletInput input)
|
|
|
|
|
|
{
|
|
|
|
|
|
var produce = await produceRepository.FirstOrDefaultAsync(x => x.IfUse == 1);
|
|
|
|
|
|
var boxQuery = await boxRepository.GetQueryableAsync();
|
|
|
|
|
|
var boxs = boxQuery.Where(x => x.DataType == 0 && x.IsDelete == 0).OrderBy(x => x.Id).Take(input.Num).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
if (produce == null)
|
|
|
|
|
|
throw Oops.Oh("没有生产设置");
|
|
|
|
|
|
|
|
|
|
|
|
if (boxs.Count < input.Num)
|
|
|
|
|
|
{
|
|
|
|
|
|
logger.LogWarning($"没有{input.Num}条{produce.Type}的整箱的信息,只有{boxs.Count}条,无法创建码垛信息");
|
|
|
|
|
|
throw Oops.Oh($"没有{input.Num}条{produce.Type}的整箱的信息,只有{boxs.Count}条,无法创建码垛信息");
|
|
|
|
|
|
//return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region 生成自定义Code
|
|
|
|
|
|
var netWeight = boxs.Sum(x => x.Net_Weight);
|
|
|
|
|
|
|
|
|
|
|
|
var date = DateOnly.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
|
|
|
|
|
|
var autolabel = await autoRepository.FirstOrDefaultAsync(x => x.Date == date && x.Type == (int)AutoLabelType.成箱码垛流水号);
|
|
|
|
|
|
var timestr = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
|
|
|
|
|
|
|
|
|
|
if (autolabel == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
autolabel = await autoRepository.InsertAsync(new AutoLabel()
|
|
|
|
|
|
{
|
|
|
|
|
|
Date = date,
|
|
|
|
|
|
Sort = 0,
|
|
|
|
|
|
Mark = timestr,
|
|
|
|
|
|
Type = (int)AutoLabelType.成箱码垛流水号
|
|
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
autolabel.Sort += 1;
|
|
|
|
|
|
logger.LogInformation("整箱码垛生成Code" + timestr + autolabel.Sort.ToString().PadLeft(4, '0'));
|
|
|
|
|
|
await autoRepository.UpdateAsync(autolabel);
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
var box = new Box()
|
|
|
|
|
|
{
|
|
|
|
|
|
Dom_Time = DateTime.Now,
|
|
|
|
|
|
Type = produce.Type,
|
|
|
|
|
|
Exp_Time = produce.Exp_Time,
|
|
|
|
|
|
Qty = input.Num,
|
|
|
|
|
|
Length = produce.Length,
|
|
|
|
|
|
Lot_No = produce.Lot_No,
|
|
|
|
|
|
//Code = Guid.NewGuid().ToString().Substring(9, 18),
|
|
|
|
|
|
Code = timestr + autolabel.Sort.ToString().PadLeft(4, '0'),
|
|
|
|
|
|
Net_Weight = netWeight,
|
|
|
|
|
|
Spec = produce.Spec,
|
|
|
|
|
|
IsUse = true,
|
|
|
|
|
|
IsDelete = 0,
|
|
|
|
|
|
DataType = (int)BoxDataType.成箱码垛,
|
|
|
|
|
|
Create_Time = DateTime.Now,
|
|
|
|
|
|
Mark = "整箱手动码垛,码垛整箱数量" + input.Num
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var Box = await boxRepository.InsertAsync(box, true);
|
|
|
|
|
|
logger.LogInformation($"已添加码垛信息,码垛编号:{box.Code},包含整箱数量:{boxs.Count}");
|
|
|
|
|
|
|
|
|
|
|
|
List<Box> list = new List<Box>();
|
|
|
|
|
|
foreach (var item in boxs)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.DataType = (int)BoxDataType.已码垛;
|
|
|
|
|
|
item.Mark = "已码垛到编号" + Box.Code + "中,码垛数据编号ID" + Box.Id;
|
|
|
|
|
|
list.Add(item);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await boxRepository.UpdateManyAsync(list);
|
|
|
|
|
|
|
|
|
|
|
|
#region 打印标签
|
|
|
|
|
|
//打印标签
|
|
|
|
|
|
BarTenderHelper.BoxPrint(box);
|
|
|
|
|
|
logger.LogInformation($"打印条码{box.Code},成箱码垛标签打印成功");
|
|
|
|
|
|
//throw Oops.Oh("成箱码垛标签打印成功");
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 单品码垛打印标签
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
public async Task SilksPalletPrint(FullPalletInput input)
|
|
|
|
|
|
{
|
|
|
|
|
|
var produce = await produceRepository.FirstOrDefaultAsync(x => x.IfUse == 1);
|
|
|
|
|
|
var silksQuery = await silkRepository.GetQueryableAsync();
|
|
|
|
|
|
var silks = silksQuery.Where(x => x.IsDelete == 0 && x.Status == (int)SilkStatus.已称重).OrderBy(x => x.Id).Take(input.Num).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
if (produce == null)
|
|
|
|
|
|
throw Oops.Oh("没有生产设置");
|
|
|
|
|
|
|
|
|
|
|
|
if (silks.Count < input.Num)
|
|
|
|
|
|
{
|
|
|
|
|
|
logger.LogWarning($"没有{input.Num}条{produce.Type}的单品的信息,只有{silks.Count}条,无法创建码垛信息");
|
|
|
|
|
|
throw Oops.Oh($"没有{input.Num}条{produce.Type}的单品的信息,只有{silks.Count}条,无法创建码垛信息");
|
|
|
|
|
|
//return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var netWeight = silks.Sum(x => x.Net_Weight);
|
|
|
|
|
|
var weight = silks.Average(x => x.Net_Weight);
|
|
|
|
|
|
|
|
|
|
|
|
#region 自动生成成箱码垛流水号
|
|
|
|
|
|
var date = DateOnly.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
|
|
|
|
|
|
var autolabel = await autoRepository.FirstOrDefaultAsync(x => x.Date == date && x.Type == (int)AutoLabelType.成箱码垛流水号);
|
|
|
|
|
|
var timestr = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
|
|
|
|
|
|
|
|
|
|
if (autolabel == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
autolabel = await autoRepository.InsertAsync(new AutoLabel()
|
|
|
|
|
|
{
|
|
|
|
|
|
Date = date,
|
|
|
|
|
|
Sort = 0,
|
|
|
|
|
|
Mark = timestr,
|
|
|
|
|
|
Type = (int)AutoLabelType.成箱码垛流水号
|
|
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
autolabel.Sort += 1;
|
|
|
|
|
|
logger.LogInformation("丝锭码垛生成Code" + timestr + autolabel.Sort.ToString().PadLeft(4, '0'));
|
|
|
|
|
|
await autoRepository.UpdateAsync(autolabel);
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
var box = new Box()
|
|
|
|
|
|
{
|
|
|
|
|
|
Dom_Time = DateTime.Now,
|
|
|
|
|
|
Type = produce.Type,
|
|
|
|
|
|
Exp_Time = produce.Exp_Time,
|
|
|
|
|
|
Qty = input.Num,
|
|
|
|
|
|
Length = produce.Length,
|
|
|
|
|
|
Lot_No = produce.Lot_No,
|
|
|
|
|
|
//Code = Guid.NewGuid().ToString().Substring(9, 18),
|
|
|
|
|
|
Code = timestr + autolabel.Sort.ToString().PadLeft(4, '0'),
|
|
|
|
|
|
Net_Weight = netWeight,
|
|
|
|
|
|
Spec = produce.Spec,
|
|
|
|
|
|
IsUse = true,
|
|
|
|
|
|
IsDelete = 0,
|
|
|
|
|
|
DataType = (int)BoxDataType.单品码垛,
|
|
|
|
|
|
Create_Time = DateTime.Now,
|
|
|
|
|
|
Mark = "单品手动码垛,码垛单品数量" + input.Num
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var Box = await boxRepository.InsertAsync(box, true);
|
|
|
|
|
|
logger.LogInformation($"已添加码垛信息,码垛编号:{box.Code},包含单品数量:{silks.Count}");
|
|
|
|
|
|
|
|
|
|
|
|
List<Silk> list = new List<Silk>();
|
|
|
|
|
|
foreach (var silk in silks)
|
|
|
|
|
|
{
|
|
|
|
|
|
silk.Status = 3;
|
|
|
|
|
|
silk.BoxId = Box.Id;
|
|
|
|
|
|
silk.Status_Details = "已码垛";
|
|
|
|
|
|
list.Add(silk);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await silkRepository.UpdateManyAsync(list);
|
|
|
|
|
|
|
|
|
|
|
|
#region 打印标签
|
|
|
|
|
|
//打印标签
|
|
|
|
|
|
BarTenderHelper.BoxPrint(box);
|
|
|
|
|
|
logger.LogInformation($"打印条码{box.Code},丝锭码垛标签打印成功");
|
|
|
|
|
|
//throw Oops.Oh("丝锭码垛标签打印成功");
|
|
|
|
|
|
#endregion
|
2025-07-01 14:20:07 +08:00
|
|
|
|
}
|
2025-06-23 15:41:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|