222 lines
7.7 KiB
C#
222 lines
7.7 KiB
C#
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 Syc.Basic.Web.WMS.IService;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
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 ProduceService : ApiService
|
||
{
|
||
private readonly IRepository<Produce> produceRepository;
|
||
private readonly IBoxService boxService;
|
||
private readonly ILogger<ProduceService> logger;
|
||
|
||
public ProduceService(IRepository<Produce> produceRepository, IBoxService boxService, ILogger<ProduceService> logger)
|
||
{
|
||
this.produceRepository = produceRepository;
|
||
this.boxService = boxService;
|
||
this.logger = logger;
|
||
}
|
||
/// <summary>
|
||
/// 产品选择框
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[HttpGet]
|
||
public async Task<List<ProduceSelectDto>> GetProduceSelectList()
|
||
{
|
||
var list = await produceRepository.GetQueryableAsync();
|
||
list = list.Where(x => x.IsDelete == 0);
|
||
|
||
var data = list.Select(x => new ProduceSelectDto()
|
||
{
|
||
Id = x.Id,
|
||
Label = x.Type + "," + x.Spec + "," + x.Length + "," + x.Lot_No + "," + x.Qty,
|
||
Spec = x.Spec,
|
||
Lot_No = x.Lot_No,
|
||
Length = x.Length,
|
||
Type = x.Type,
|
||
Exp_Time = x.Exp_Time.HasValue ? x.Exp_Time.Value.ToString("yyyy-MM-dd HH:mm") : "-",
|
||
IfUse = x.IfUse,
|
||
Qty = x.Qty
|
||
}).ToList();
|
||
|
||
return data;
|
||
}
|
||
/// <summary>
|
||
/// 查询生产
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public async Task<PageOutput<ProduceDto>> GetProduceList(ProduceInput input)
|
||
{
|
||
var list = await produceRepository.GetQueryableAsync();
|
||
list = list.Where(x => x.IsDelete == 0);
|
||
|
||
if (!string.IsNullOrEmpty(input.Lot_No))
|
||
list = list.Where(x => x.Lot_No.Contains(input.Lot_No));
|
||
|
||
var result = list.PageResult(input.Page, input.PageSize);
|
||
var data = result.Queryable.Select(x => new ProduceDto()
|
||
{
|
||
Spec = x.Spec,
|
||
Lot_No = x.Lot_No,
|
||
Id = x.Id,
|
||
Length = x.Length,
|
||
Type = x.Type,
|
||
//BoxSpec = x.BoxSpec,
|
||
Date = x.Date.HasValue ? x.Exp_Time.Value.ToString("yyyy-MM-dd HH:m") : "-",
|
||
Exp_Time = x.Exp_Time.HasValue ? x.Exp_Time.Value.ToString("yyyy-MM-dd HH:m") : "-",
|
||
IfUse = x.IfUse,
|
||
//Name = x.Name,
|
||
Qty = x.Qty
|
||
});
|
||
|
||
|
||
PageOutput<ProduceDto> pageOutput = new PageOutput<ProduceDto>();
|
||
pageOutput.Total = list.Count();
|
||
pageOutput.Data = data.OrderByDescending(x=>x.Id);
|
||
pageOutput.PageIndex = input.Page;
|
||
pageOutput.PageSize = input.PageSize;
|
||
return pageOutput;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 通过id查询生产列表
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public async Task<List<ProduceDto>> GetProduceListByUse()
|
||
{
|
||
var list = await produceRepository.GetListAsync(x => x.IsDelete == 0 && x.IfUse==1);
|
||
var data = ObjectMapper.Map(list, new List<ProduceDto>());
|
||
return data;
|
||
}
|
||
/// <summary>
|
||
/// 添加生产
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public async Task InsertProduce(ProduceDto input)
|
||
{
|
||
var produces = await produceRepository.GetListAsync();
|
||
if (produces.Count > 0)
|
||
{
|
||
foreach (var item in produces)
|
||
{
|
||
item.IfUse = 0;
|
||
}
|
||
}
|
||
|
||
|
||
var produce = new Produce()
|
||
{
|
||
Length = input.Length,
|
||
Lot_No = input.Lot_No,
|
||
Spec = input.Spec,
|
||
Type = input.Type,
|
||
Qty = input.Qty,
|
||
BoxSpec = input.Spec,
|
||
Date= string.IsNullOrWhiteSpace(input.Date) ? null : Convert.ToDateTime(input.Exp_Time),
|
||
Exp_Time = string.IsNullOrWhiteSpace(input.Exp_Time) ? null : Convert.ToDateTime(input.Exp_Time),
|
||
IfUse = 1,
|
||
Name = input.Type,
|
||
IsDelete = 0
|
||
};
|
||
|
||
await produceRepository.InsertAsync(produce);
|
||
}
|
||
/// <summary>
|
||
/// 修改生产
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public async Task UpdateProduce(ProduceDto input)
|
||
{
|
||
var produce = await produceRepository.FirstOrDefaultAsync(x => x.Id == input.Id);
|
||
|
||
produce.Spec = input.Spec;
|
||
produce.Type = input.Type;
|
||
produce.Length = input.Length;
|
||
produce.Lot_No = input.Lot_No;
|
||
produce.Qty = input.Qty;
|
||
produce.Name = input.Type;
|
||
produce.BoxSpec = input.Spec;
|
||
produce.Date = string.IsNullOrWhiteSpace(input.Date) ? null : Convert.ToDateTime(input.Date);
|
||
produce.Exp_Time = string.IsNullOrWhiteSpace(input.Exp_Time) ? null : Convert.ToDateTime(input.Exp_Time);
|
||
await produceRepository.UpdateAsync(produce);
|
||
}
|
||
/// <summary>
|
||
/// 修改生产
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public async Task UpdateProduceUse(UpdInput input)
|
||
{
|
||
var produces = await produceRepository.GetListAsync();
|
||
var produce = await produceRepository.FirstOrDefaultAsync(x => x.Id == input.Id);
|
||
|
||
if (input.IfUse == 1)
|
||
{
|
||
produce.IfUse = input.IfUse;
|
||
if (produces.Count > 0)
|
||
{
|
||
foreach (var item in produces)
|
||
{
|
||
item.IfUse = 0;
|
||
}
|
||
}
|
||
}
|
||
produce.IfUse = input.IfUse;
|
||
await produceRepository.UpdateAsync(produce);
|
||
}
|
||
/// <summary>
|
||
/// 删除生产
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public async Task DeleteProduce(DelInput input)
|
||
{
|
||
var produce = await produceRepository.FirstOrDefaultAsync(x => x.Id == input.id);
|
||
if (produce == null)
|
||
throw Oops.Oh("删除失败,数据为空");
|
||
produce.IsDelete = 1;
|
||
await produceRepository.UpdateAsync(produce);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 批量删除生产
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public async Task DeletesProduces(DelInput input)
|
||
{
|
||
var produces = await produceRepository.GetListAsync(x => input.ids.Contains(x.Id));
|
||
if (produces.Count == 0)
|
||
throw Oops.Oh("删除失败,数据为空");
|
||
foreach (var produce in produces)
|
||
{
|
||
produce.IsDelete = 1;
|
||
}
|
||
await produceRepository.UpdateManyAsync(produces);
|
||
}
|
||
}
|
||
}
|