304 lines
12 KiB
C#
304 lines
12 KiB
C#
using JetBrains.Annotations;
|
||
using Microsoft.AspNetCore.Authorization;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using Microsoft.AspNetCore.Mvc.ActionConstraints;
|
||
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||
using Microsoft.Extensions.Logging;
|
||
using Seyounth.Auto.Hs.Runtime.Printer;
|
||
using Syc.Basic.Web.WMS;
|
||
using Syc.Basic.Web.WMS.Dto;
|
||
using Syc.Basic.Web.WMS.Entitys;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.IO;
|
||
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;
|
||
private readonly IRepository<Values> valueRepository;
|
||
|
||
public SilkService(IPrinterService printerService, IRepository<Produce> produceRepository, IRepository<Silk> silkRepository, ILogger<SilkService> logger, IRepository<AutoLabel> autoRepository, IRepository<Values> valueRepository)
|
||
{
|
||
this.printerService = printerService;
|
||
this.produceRepository = produceRepository;
|
||
this.silkRepository = silkRepository;
|
||
this.logger = logger;
|
||
this.autoRepository = autoRepository;
|
||
this.valueRepository = valueRepository;
|
||
}
|
||
/// <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.Name != null)
|
||
silklist = silklist.Where(x => x.Name.Contains(input.Name));
|
||
if (input.Spec != null)
|
||
silklist = silklist.Where(x => x.Type.Contains(input.Spec));
|
||
if (input.Lot_No != null)
|
||
silklist = silklist.Where(x => x.Lot_No.Contains(input.Lot_No));
|
||
if (input.Chang != null)
|
||
silklist = silklist.Where(x => x.Length.Contains(input.Chang));
|
||
if (input.Start_Time != null && input.End_Time != null)
|
||
silklist = silklist.Where(x => x.Date >= DateTime.Parse(input.Start_Time) && x.Date <= DateTime.Parse(input.End_Time));
|
||
if (input.Qty > 0)
|
||
silklist = silklist.OrderByDescending(x => x.Id).Take(input.Qty);
|
||
if (input.Color != null)
|
||
{
|
||
if (input.Color == "无")
|
||
silklist = silklist.Where(x => x.Color == input.Color || x.Color == null);
|
||
else
|
||
silklist = silklist.Where(x => x.Color == input.Color);
|
||
}
|
||
|
||
|
||
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,
|
||
Color = x.Color,
|
||
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);
|
||
var values = await valueRepository.FirstOrDefaultAsync(x => x.Type == 0 && x.IsDelete == 0 && x.IfUse == 1);
|
||
var keys = values.Key1.Split(',');
|
||
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,
|
||
Color = keys[int.Parse(values.Value)],
|
||
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.Color = input.Color;
|
||
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);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 求总
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public async Task<object> Sum(SumInput 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.Name != null)
|
||
silklist = silklist.Where(x => x.Name.Contains(input.Name));
|
||
|
||
if (input.Lot_No != null)
|
||
silklist = silklist.Where(x => x.Lot_No.Contains(input.Lot_No));
|
||
if (input.Chang != null)
|
||
silklist = silklist.Where(x => x.Length.Contains(input.Chang));
|
||
if (input.Start_Time != null && input.End_Time != null)
|
||
silklist = silklist.Where(x => x.Date >= DateTime.Parse(input.Start_Time) && x.Date <= DateTime.Parse(input.End_Time));
|
||
if (input.Qty > 0)
|
||
silklist = silklist.OrderByDescending(x => x.Id).Take(input.Qty);
|
||
if (input.Value != null)
|
||
{
|
||
if (input.Value == "无")
|
||
silklist = silklist.Where(x => x.Color == input.Value || x.Color == null);
|
||
else
|
||
silklist = silklist.Where(x => x.Color == input.Value);
|
||
}
|
||
|
||
|
||
//1:求颜色总数
|
||
if (input.Type == 1)
|
||
{
|
||
if (silklist.Count() == 0)
|
||
throw Oops.Oh("求和失败,数据为空");
|
||
|
||
int sum = silklist.Count();
|
||
return sum;
|
||
}
|
||
//2:求重量总和
|
||
else
|
||
{
|
||
if (silklist.Count() == 0)
|
||
throw Oops.Oh("求和失败,数据为空");
|
||
|
||
double sum = 0;
|
||
foreach (var silk in silklist)
|
||
{
|
||
|
||
sum += (double)silk.Net_Weight;
|
||
}
|
||
return Math.Round(sum, 2);
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
}
|