218 lines
8.0 KiB
C#
Raw Normal View History

2025-06-23 15:41:15 +08:00
using JetBrains.Annotations;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Seyounth.Auto.Hs.Runtime.Printer;
2025-06-23 15:41:15 +08:00
using Syc.Basic.Web.WMS.Dto;
using Syc.Basic.Web.WMS.Entitys;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
2025-06-23 15:41:15 +08:00
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
namespace Syc.Basic.Web.WMS.Service
{
[AllowAnonymous]
2025-10-31 09:56:25 +08:00
public class SilkService : ApiService
2025-06-23 15:41:15 +08:00
{
private readonly IPrinterService printerService;
private readonly IRepository<Produce> produceRepository;
2025-06-23 15:41:15 +08:00
private readonly IRepository<Silk> silkRepository;
private readonly ILogger<SilkService> logger;
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 SilkService(IPrinterService printerService, IRepository<Produce> produceRepository, IRepository<Silk> silkRepository, ILogger<SilkService> logger, IRepository<AutoLabel> autoRepository)
2025-06-23 15:41:15 +08:00
{
this.printerService = printerService;
this.produceRepository = produceRepository;
2025-06-23 15:41:15 +08:00
this.silkRepository = silkRepository;
this.logger = logger;
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>
[HttpGet]
public async Task<List<SilkDto>> GetSilkByNum()
{
2025-10-31 09:56:25 +08:00
var produce = await produceRepository.FirstOrDefaultAsync(x => x.IfUse == 1 && x.IsDelete == 0);
if (produce == null)
throw Oops.Oh("没有生产设置");
var list = await silkRepository.GetQueryableAsync();
2025-10-31 09:56:25 +08:00
list = list.Where(x => x.Status == 1 && x.IsDelete == 0 && x.Type == produce.Spec && x.Lot_No == produce.Lot_No && x.Name == produce.Type || x.Status == 0 && x.IsDelete == 0 && x.Type == produce.Spec && x.Lot_No == produce.Lot_No && x.Name == produce.Type);
var data = list.Select(e => new SilkDto()
{
Net_Weight = e.Net_Weight,
Id = e.Id,
Code = e.Code,
Status = e.Status,
Status_Details = e.Status_Details
}).ToList();
2025-10-31 09:56:25 +08:00
return data.OrderByDescending(x => x.Id).ToList();
}
/// <summary>
2025-06-23 15:41:15 +08:00
/// 查询丝锭
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
public async Task<PageOutput<SilkDto>> GetSilkList(SilkInput input)
2025-06-23 15:41:15 +08:00
{
var silklist = await silkRepository.GetQueryableAsync();
2025-06-24 18:26:51 +08:00
silklist = silklist.Where(x => x.IsDelete == 0);
if (input.Spec != null)
silklist = silklist.Where(x => x.Type.Contains(input.Spec));
if (input.Lot_No != null)
silklist = silklist.Where(x => x.Type.Contains(input.Lot_No));
2025-06-23 15:41:15 +08:00
2025-10-31 09:56:25 +08:00
var result = silklist.OrderByDescending(x => x.Id).PageResult(input.Page, input.PageSize);
var data = result.Queryable.Select(x => new SilkDto()
2025-06-23 15:41:15 +08:00
{
2025-10-31 09:56:25 +08:00
Name = x.Name,
Net_Weight = x.Net_Weight,
Lot_No = x.Lot_No,
Code = x.Code,
Date = x.Date,
Id = x.Id,
Length = x.Length,
Type = x.Type,
BoxId = x.BoxId,
Status = x.Status,
Status_Details = x.Status_Details
2025-06-23 15:41:15 +08:00
});
PageOutput<SilkDto> pageOutput = new PageOutput<SilkDto>();
pageOutput.Total = silklist.Count();
2025-10-31 09:56:25 +08:00
pageOutput.Data = data;
pageOutput.PageIndex = input.Page;
pageOutput.PageSize = input.PageSize;
2025-06-23 15:41:15 +08:00
return pageOutput;
}
/// <summary>
/// 添加丝锭
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
public async Task InsertSilk(SilkDto input)
{
2025-10-31 09:56:25 +08:00
var produce = await produceRepository.FirstOrDefaultAsync(x => x.IfUse == 1);
if (produce == null)
throw Oops.Oh("没有生产设置");
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);
2025-06-23 15:41:15 +08:00
var silk = new Silk()
{
Date = DateTime.Now,
2025-10-31 09:56:25 +08:00
Length = produce.Length,
Lot_No = produce.Lot_No,
Code = timestr + autolabel.Sort.ToString().PadLeft(4, '0'),
2025-06-23 15:41:15 +08:00
Net_Weight = input.Net_Weight,
2025-10-31 09:56:25 +08:00
Name = produce.Type,
Type = produce.Spec,
Createtime = DateTime.Now,
Status = (int)SilkStatus.,
Status_Details = "手动添加称重",
2025-06-24 18:26:51 +08:00
IsDelete = 0
2025-06-23 15:41:15 +08:00
};
2025-10-31 09:56:25 +08:00
var entity = await silkRepository.InsertAsync(silk, true);
logger.LogInformation($"添加丝锭成功");
BarTenderHelper.SilkPrint(silk);
logger.LogInformation($"打印{silk.Code}条码丝锭标签成功");
}
/// <summary>
/// 打印丝锭
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
public async Task PrintSilk(DelInput input)
{
2025-10-31 09:56:25 +08:00
var silk = await silkRepository.FirstOrDefaultAsync(x => x.Id == input.id);
BarTenderHelper.SilkPrint(silk);
logger.LogInformation($"打印{silk.Code}条码丝锭标签成功");
2025-06-23 15:41:15 +08:00
}
/// <summary>
/// 修改丝锭
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
public async Task UpdateSilk(SilkDto input)
{
2025-10-31 09:56:25 +08:00
var silks = await silkRepository.FirstOrDefaultAsync(x => x.Id == input.Id);
2025-06-23 15:41:15 +08:00
silks.Name = input.Name;
2025-06-23 15:41:15 +08:00
silks.Type = input.Type;
silks.Length = input.Length;
2025-10-31 09:56:25 +08:00
//silks.Code = input.Code;
2025-06-23 15:41:15 +08:00
silks.Lot_No = input.Lot_No;
silks.Net_Weight = input.Net_Weight;
silks.Date = DateTime.Now;
await silkRepository.UpdateAsync(silks);
}
/// <summary>
/// 删除丝锭
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
public async Task DeleteSilk(DelInput input)
2025-06-23 15:41:15 +08:00
{
var silk = await silkRepository.FirstOrDefaultAsync(x => x.Id == input.id);
if (silk == null)
throw Oops.Oh("删除失败,数据为空");
2025-06-24 18:26:51 +08:00
silk.IsDelete = 1;
await silkRepository.UpdateAsync(silk);
2025-06-23 15:41:15 +08:00
}
/// <summary>
/// 批量删除丝锭
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
public async Task DeletesSilks(DelInput input)
2025-06-23 15:41:15 +08:00
{
var silks = await silkRepository.GetListAsync(x => input.ids.Contains(x.Id));
2025-06-24 18:26:51 +08:00
if (silks.Count == 0)
2025-06-23 15:41:15 +08:00
throw Oops.Oh("删除失败,数据为空");
2025-06-24 18:26:51 +08:00
foreach (var silk in silks)
{
silk.IsDelete = 1;
}
await silkRepository.UpdateManyAsync(silks);
2025-06-23 15:41:15 +08:00
}
}
}