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, 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; } /// /// 获取线体原纸 /// /// public WebResponseContent GetOutLineView() { WebResponseContent content = new WebResponseContent(); try { //获取数据 List lineViews = BaseDal.QueryData().OrderBy(x=>x.CreateDate).ToList(); int taskCount = BaseDal.Db.Queryable().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; } /// /// 存入最新的出库纸卷信息 /// /// /// public WebResponseContent SaveLineView(List outStockLockInfos) { WebResponseContent content = new WebResponseContent(); try { //获取当前老厂缓存所有纸卷信息 List outLineViews = BaseDal.QueryData(); //获取当前纸卷个数 int? outLineCount = outLineViews?.Select(x => x.PalletCode).Distinct().Count(); if (outLineViews==null || outLineViews.Count<=0 || outLineCount<=2) { List outLineViewsAdd = outStockLockInfos.Select(x => _mapper.Map(x)).ToList(); BaseDal.AddData(outLineViewsAdd); } else { //获取最早的纸卷信息 string? code= outLineViews.FirstOrDefault()?.PalletCode; List outLineViewsDel = outLineViews.Where(x=>x.PalletCode==code).ToList(); List outLineViewsAdd = outStockLockInfos.Select(x => _mapper.Map(x)).ToList(); BaseDal.DeleteData(outLineViewsDel); BaseDal.AddData(outLineViewsAdd); } content.OK("成功"); } catch (Exception ex) { content.Error(ex.Message); } return content; } } }