139 lines
4.4 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 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();
2025-06-24 18:26:51 +08:00
boxlist = boxlist.Where(x => x.IsDelete == 0);
2025-06-23 15:41:15 +08:00
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,
2025-06-24 18:26:51 +08:00
Spec = input.Spec,
IsDelete = 0
2025-06-23 15:41:15 +08:00
};
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]
2025-06-24 18:26:51 +08:00
public async Task DeleteBox(BoxInput input)
2025-06-23 15:41:15 +08:00
{
2025-06-24 18:26:51 +08:00
var box = await boxRepository.FirstOrDefaultAsync(x => x.Id == input.id);
if (box == null)
2025-06-23 15:41:15 +08:00
throw Oops.Oh("删除失败,数据为空");
2025-06-24 18:26:51 +08:00
box.IsDelete = 1;
await boxRepository.UpdateAsync(box);
2025-06-23 15:41:15 +08:00
}
/// <summary>
/// 批量删除纸箱
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
2025-06-24 18:26:51 +08:00
public async Task DeletesBoxs(BoxInput input)
2025-06-23 15:41:15 +08:00
{
2025-06-24 18:26:51 +08:00
var boxs = await boxRepository.GetListAsync(x => input.ids.Contains(x.Id));
if (boxs.Count == 0)
2025-06-23 15:41:15 +08:00
throw Oops.Oh("删除失败,数据为空");
2025-06-24 18:26:51 +08:00
for(var i = 0; i < boxs.Count; i++)
{
boxs[i].IsDelete = 1;
}
await boxRepository.UpdateManyAsync(boxs);
2025-06-23 15:41:15 +08:00
}
}
}