using AutoMapper;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEA_Common.TaskEnum;
|
using WIDESEA_Core;
|
using WIDESEA_Core.BaseRepository;
|
using WIDESEA_Core.BaseServices;
|
using WIDESEA_Core.Helper;
|
using WIDESEA_IBasicRepository;
|
using WIDESEA_IOutboundRepository;
|
using WIDESEA_IOutboundService;
|
using WIDESEA_Model.Models;
|
|
namespace WIDESEA_OutboundService
|
{
|
public class OutLineViewService : ServiceBase<Dt_OutLineView, IOutLineViewRepository>, IOutLineViewService
|
{
|
public IOutLineViewRepository Repository => BaseDal;
|
private IBasicRepository _basicRepository;
|
private readonly IMapper _mapper;
|
private readonly IUnitOfWorkManage _unitOfWorkManage;
|
|
public OutLineViewService(IOutLineViewRepository BaseDal, IBasicRepository basicRepository, IMapper mapper, IUnitOfWorkManage unitOfWorkManage) : base(BaseDal)
|
{
|
_basicRepository = basicRepository;
|
_mapper = mapper;
|
_unitOfWorkManage = unitOfWorkManage;
|
}
|
/// <summary>
|
/// 获取线体原纸
|
/// </summary>
|
/// <returns></returns>
|
public WebResponseContent GetOutLineView()
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
//获取数据
|
List<Dt_OutLineView> lineViews = BaseDal.QueryData().OrderBy(x=>x.CreateDate).ToList();
|
int taskCount = BaseDal.Db.Queryable<Dt_Task>().Where(x=>x.TaskType==TaskTypeEnum.OldYLOutbound.ObjToInt() && x.TaskStatus==TaskStatusEnum.Line_Executing.ObjToInt()).Count();
|
content.OK($"{taskCount}", lineViews);
|
}
|
catch (Exception ex)
|
{
|
content.Error(ex.Message);
|
}
|
return content;
|
}
|
/// <summary>
|
/// 存入最新的出库纸卷信息
|
/// </summary>
|
/// <param name="outStockLockInfos"></param>
|
/// <returns></returns>
|
public WebResponseContent SaveLineView(List<Dt_OutStockLockInfo> outStockLockInfos)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
//获取当前老厂缓存所有纸卷信息
|
List<Dt_OutLineView> outLineViews = BaseDal.QueryData();
|
//获取当前纸卷个数
|
int? outLineCount = outLineViews?.Select(x => x.PalletCode).Distinct().Count();
|
if (outLineViews==null || outLineViews.Count<=0 || outLineCount<=2)
|
{
|
List<Dt_OutLineView> outLineViewsAdd = outStockLockInfos.Select(x => _mapper.Map<Dt_OutLineView>(x)).ToList();
|
BaseDal.AddData(outLineViewsAdd);
|
}
|
else
|
{
|
//获取最早的纸卷信息
|
string? code= outLineViews.FirstOrDefault()?.PalletCode;
|
List<Dt_OutLineView> outLineViewsDel = outLineViews.Where(x=>x.PalletCode==code).ToList();
|
List<Dt_OutLineView> outLineViewsAdd = outStockLockInfos.Select(x => _mapper.Map<Dt_OutLineView>(x)).ToList();
|
BaseDal.DeleteData(outLineViewsDel);
|
BaseDal.AddData(outLineViewsAdd);
|
}
|
content.OK("成功");
|
}
|
catch (Exception ex)
|
{
|
content.Error(ex.Message);
|
}
|
return content;
|
}
|
}
|
}
|