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 boxRepository; private readonly ILogger logger; public BoxService(IRepository boxRepository, ILogger logger) { this.boxRepository = boxRepository; this.logger = logger; } /// /// 查询纸箱 /// /// /// [HttpPost] public async Task> 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 pageOutput = new PageOutput(); pageOutput.Total = boxlist.Count(); pageOutput.Data = data; return pageOutput; } /// /// 添加纸箱 /// /// /// [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); } /// /// 修改纸箱 /// /// /// [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); } /// /// 删除纸箱 /// /// /// [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); } /// /// 批量删除纸箱 /// /// /// [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); } } }