wangxinhui
2025-11-21 5336bfc54525253a30f1f8238806d3a67f388e14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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;
        }
    }
}