wangxinhui
2025-01-10 de5761174d24acd3cdb4ac62b128bb3e3ba91d52
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
90
91
92
93
94
95
96
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common.StockEnum;
using WIDESEA_Core;
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_IOutboundRepository;
using WIDESEA_IRecordService;
using WIDESEA_IStockService;
using WIDESEA_Model.Models;
 
namespace WIDESEA_IOutboundService
{
    public partial class OutStockLockInfoService
    {
 
        /// <summary>
        /// 分拣
        /// </summary>
        /// <param name="palletCode">托盘号</param>
        /// <returns></returns>
        public WebResponseContent MaterialPick(string palletCode)
        {
            try
            {
                Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(palletCode);
                if (stockInfo == null)
                {
                    return WebResponseContent.Instance.Error($"未找到该托盘库存信息");
                }
                if (stockInfo.StockStatus != StockStatusEmun.出库完成.ObjToInt())
                {
                    return WebResponseContent.Instance.Error($"该托盘还未出库完成");
                }
                List<Dt_OutStockLockInfo> outStockLockInfos = Repository.QueryData(x => x.PalletCode == palletCode);
                for (int i = 0; i < outStockLockInfos.Count; i++)
                {
                    outStockLockInfos[i].Status = OutLockStockStatusEnum.拣选完成.ObjToInt();
                }
                List<Dt_StockInfoDetail> beforeDetaile = stockInfo.Details.GroupBy(x => x.MaterielCode).Select(x => new Dt_StockInfoDetail { MaterielCode = x.Key, StockQuantity = x.Sum(v => v.StockQuantity) }).ToList();
                List<Dt_StockInfoDetail> updateDetailList = new List<Dt_StockInfoDetail>();
                List<Dt_StockInfoDetail> deleteDetailList = new List<Dt_StockInfoDetail>();
                for (int i = 0; i < stockInfo.Details.Count; i++)
                {
                    if (stockInfo.Details[i].OutboundQuantity > 0)
                    {
                        if (stockInfo.Details[i].StockQuantity > stockInfo.Details[i].OutboundQuantity)
                        {
                            stockInfo.Details[i].StockQuantity -= stockInfo.Details[i].OutboundQuantity;
                            updateDetailList.Add(stockInfo.Details[i]);
                        }
                        else
                        {
                            deleteDetailList.Add(stockInfo.Details[i]);
                        }
                    }
                }
 
                List<string> mCodes = stockInfo.Details.GroupBy(x => x.MaterielCode).Select(x => x.Key).ToList();
                _unitOfWorkManage.BeginTran();
                foreach (string code in mCodes)
                {
                    _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, updateDetailList, deleteDetailList, StockChangeTypeEnum.Outbound);
                }
                updateDetailList.ForEach(x =>
                {
                    x.OutboundQuantity = 0;
                });
                stockInfo.StockStatus = StockStatusEmun.手动组盘入库确认.ObjToInt();
                //_stockService.StockInfoDetailService.Repository.DeleteAndMoveIntoHty(deleteDetailList, OperateTypeEnum.自动完成);
                if (stockInfo.Details.Sum(x=>x.StockQuantity)== stockInfo.Details.Sum(x => x.OutboundQuantity))
                {
                    _stockService.StockInfoService.Repository.DeleteData(stockInfo);
                }
                else
                {
                    _stockService.StockInfoService.Repository.UpdateData(stockInfo);
                }
                _stockService.StockInfoDetailService.Repository.UpdateData(updateDetailList);
                _stockService.StockInfoDetailService.Repository.DeleteData(deleteDetailList);
                BaseDal.UpdateData(outStockLockInfos);
                _unitOfWorkManage.BeginTran();
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
    }
}