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