124 lines
3.9 KiB
C#
124 lines
3.9 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 SilkService:ApiService
|
|||
|
{
|
|||
|
private readonly IRepository<Silk> silkRepository;
|
|||
|
private readonly ILogger<SilkService> logger;
|
|||
|
|
|||
|
public SilkService(IRepository<Silk> silkRepository,ILogger<SilkService> logger)
|
|||
|
{
|
|||
|
this.silkRepository = silkRepository;
|
|||
|
this.logger = logger;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 查询丝锭
|
|||
|
/// </summary>
|
|||
|
/// <param name="input"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[HttpPost]
|
|||
|
public async Task<PageOutput<SilkDto>> GetSilkList(SilkDto input)
|
|||
|
{
|
|||
|
var silklist = await silkRepository.GetQueryableAsync();
|
|||
|
if (input.Type != null)
|
|||
|
silklist = silklist.Where(x => x.Type.Contains(input.Type));
|
|||
|
|
|||
|
var data = silklist.Select(x=>new SilkDto()
|
|||
|
{
|
|||
|
Spec=x.Spec,
|
|||
|
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
|
|||
|
});
|
|||
|
|
|||
|
PageOutput<SilkDto> pageOutput = new PageOutput<SilkDto>();
|
|||
|
pageOutput.Total = silklist.Count();
|
|||
|
pageOutput.Data = data;
|
|||
|
return pageOutput;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 添加丝锭
|
|||
|
/// </summary>
|
|||
|
/// <param name="input"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[HttpPost]
|
|||
|
public async Task InsertSilk(SilkDto input)
|
|||
|
{
|
|||
|
var silk = new Silk()
|
|||
|
{
|
|||
|
Date = DateTime.Now,
|
|||
|
Length = input.Length,
|
|||
|
Lot_No = input.Lot_No,
|
|||
|
Code = input.Code,
|
|||
|
Net_Weight = input.Net_Weight,
|
|||
|
Spec = input.Spec,
|
|||
|
Type = input.Type
|
|||
|
};
|
|||
|
await silkRepository.InsertAsync(silk);
|
|||
|
}
|
|||
|
/// <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.Spec = input.Spec;
|
|||
|
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(SilkInput input)
|
|||
|
{
|
|||
|
var silk = await silkRepository.FirstOrDefaultAsync(x => x.Id == input.id);
|
|||
|
if (silk == null)
|
|||
|
throw Oops.Oh("删除失败,数据为空");
|
|||
|
await silkRepository.DeleteAsync(silk);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 批量删除丝锭
|
|||
|
/// </summary>
|
|||
|
/// <param name="input"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[HttpPost]
|
|||
|
public async Task DeletesSilks(SilkInput input)
|
|||
|
{
|
|||
|
var silks = await silkRepository.GetListAsync(x => input.ids.Contains(x.Id));
|
|||
|
if (silks == null)
|
|||
|
throw Oops.Oh("删除失败,数据为空");
|
|||
|
await silkRepository.DeleteManyAsync(silks);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|