133 lines
4.2 KiB
C#

using JetBrains.Annotations;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Syc.Basic.Web.WMS.Dto;
using Syc.Basic.Web.WMS.Entitys;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
namespace Syc.Basic.Web.WMS.Service
{
[AllowAnonymous]
public class BoxService : ApiService
{
private readonly IRepository<Box> boxRepository;
private readonly ILogger<BoxService> logger;
public BoxService(IRepository<Box> boxRepository, ILogger<BoxService> logger)
{
this.boxRepository = boxRepository;
this.logger = logger;
}
/// <summary>
/// 查询纸箱
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
public async Task<PageOutput<BoxDto>> GetBoxList(BoxDto input)
{
var boxlist = await boxRepository.GetQueryableAsync();
if (input.Name != null)
boxlist = boxlist.Where(x => x.Name.Contains(input.Name));
if (input.Spec != null)
boxlist = boxlist.Where(x => x.Spec.Contains(input.Spec));
var data = boxlist.Select(e => new BoxDto()
{
Length = e.Length,
Net_Weight = e.Net_Weight,
Qty = e.Qty,
Id = e.Id,
Code = e.Code,
Dom_Time = e.Dom_Time,
Exp_Time = e.Exp_Time,
Lot_No = e.Lot_No,
Name = e.Name,
Spec = e.Spec,
}).ToList();
PageOutput<BoxDto> pageOutput = new PageOutput<BoxDto>();
pageOutput.Total = boxlist.Count();
pageOutput.Data = data;
return pageOutput;
}
/// <summary>
/// 添加纸箱
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
public async Task InsertBox(BoxDto input)
{
var box = new Box()
{
Name = input.Name,
Dom_Time = DateTime.Now,
Exp_Time = input.Exp_Time,
Qty = input.Qty,
Length = input.Length,
Lot_No = input.Lot_No,
Code = input.Code,
Net_Weight = input.Net_Weight,
Spec = input.Spec
};
await boxRepository.InsertAsync(box);
}
/// <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;
box.Code = input.Code;
box.Lot_No = input.Lot_No;
box.Net_Weight = input.Net_Weight;
box.Dom_Time = DateTime.Now;
box.Qty = input.Qty;
box.Name = input.Name;
box.Exp_Time = input.Exp_Time;
await boxRepository.UpdateAsync(box);
}
/// <summary>
/// 删除纸箱
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
public async Task DeleteSilkList(BoxInput input)
{
var silk = await boxRepository.FirstOrDefaultAsync(x => x.Id == input.id);
if (silk == null)
throw Oops.Oh("删除失败,数据为空");
await boxRepository.DeleteAsync(silk);
}
/// <summary>
/// 批量删除纸箱
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
public async Task DeletesSilkList(BoxInput input)
{
var silks = await boxRepository.GetListAsync(x => input.ids.Contains(x.Id));
if (silks == null)
throw Oops.Oh("删除失败,数据为空");
await boxRepository.DeleteManyAsync(silks);
}
}
}