huangxiaoqiang
2025-11-17 b07472f884708a6bfdf63d999004bbf0bb5f00a8
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
using MailKit.Search;
using Masuit.Tools;
using Newtonsoft.Json;
using WIDESEA_Common;
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Const;
using WIDESEA_Core.Helper;
using WIDESEA_IBusinessesRepository;
using WIDESEA_IOrderRepository;
using WIDESEA_IOrderServices;
using WIDESEA_IServices;
using WIDESEA_IStorageTaskRepository;
using WIDESEA_IStorageTaskServices;
using WIDESEA_Model.Models;
using WIDESEA_Model.Models.Order;
using WIDESEA_OrderRepository;
 
namespace WIDESEA_OrderServices
{
    public class Dt_InboundOrderService : ServiceBase<Dt_InboundOrder, IDt_InboundOrderRepository>, IDt_InboundOrderService
    {
        private readonly IUnitOfWorkManage _unitOfWorkManage;
        private readonly ISys_ConfigService _configService;
        private readonly IDt_WareAreaInfoRepository _wareAreaInfoRepository;
 
        public Dt_InboundOrderService(IDt_InboundOrderRepository BaseDal,
                                        IUnitOfWorkManage unitOfWorkManage,
                                        ISys_ConfigService configService,
                                        IDt_WareAreaInfoRepository wareAreaInfoRepository) : base(BaseDal)
        {
            _unitOfWorkManage = unitOfWorkManage;
            _configService = configService;
            _wareAreaInfoRepository = wareAreaInfoRepository;
        }
 
        public override WebResponseContent UpdateData(SaveModel saveModel)
        {
            var quantity = saveModel.MainData["quantity"].ToString();
            var wareHouseId = saveModel.MainData["wareHouseId"].ToString();
 
            Dt_WareAreaInfo? wareinfo = _wareAreaInfoRepository.QueryFirst(x => x.WareAreaCode == wareHouseId);
 
            if (wareinfo == null)
            {
                return WebResponseContent.Instance.Error("未找到仓库信息!");
            }
            saveModel.MainData.Add("warehouseName", wareinfo.WareAreaName.ToString());
            return base.UpdateData(saveModel);
        }
 
        public WebResponseContent GetInboundOrderInfo(string OrderNo)
        {
            WebResponseContent content=new WebResponseContent();
            try
            {
                var InboundOrder = BaseDal.QueryFirst(x => x.OrderNo == OrderNo);
                if (InboundOrder == null)
                {
                    return content.Error($"未找到该单号数据请人工确认");
                }
                return content.OK(data: InboundOrder);
            }
            catch (Exception ex)
            {
                return content.Error(ex.Message);
            }
        }
        public WebResponseContent PrintOrder(int[] keys)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                List<Dt_InboundOrder> inboundOrders = new List<Dt_InboundOrder>();
                foreach (var item in keys)
                {
                    var InboundOrder = BaseDal.QueryFirst(x => x.Id == item);
                    if(InboundOrder != null)
                    {
                        inboundOrders.Add(InboundOrder);
                    }
                }
                content=PrintInbound(inboundOrders);
                return content;
            }
            catch (Exception ex)
            {
                return content.Error("未知错误,请联系管理员");
            }
        }
 
        public WebResponseContent SplitOrder(int id,int num)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var originalOrder = BaseDal.QueryFirst(x => x.Id == id);
                if (originalOrder == null)
                {
                    return content.Error("未找到该入库单信息");
                }
                if(originalOrder.Quantity < num || num <= 0)
                {
                    return content.Error("拆分数量不合法");
                }
                Dt_InboundOrder orderNew = new Dt_InboundOrder()
                {
                    OrderNo = GetOrderPintCode("OrderNoIn"),
                    UpperOrderNo = originalOrder.UpperOrderNo,
                    DemandClassification = originalOrder.DemandClassification,
                    OrderType = originalOrder.OrderType,
                    WarehouseName = originalOrder.WarehouseName,
                    Datetime = originalOrder.Datetime,
                    LineNumber = originalOrder.LineNumber,
                    ProductDrawingNumber = originalOrder.ProductDrawingNumber,
                    MaterialNo = originalOrder.MaterialNo,
                    MaterialName = originalOrder.MaterialName,
                    Weight = originalOrder.Weight,
                    WareHouseId = originalOrder.WareHouseId,
                    Specs = originalOrder.Specs,
                    Unit = originalOrder.Unit,
                    Texture = originalOrder.Texture,
                    Quantity = num,
                    OrderStatus = originalOrder.OrderStatus,
 
                };
                originalOrder.Quantity = originalOrder.Quantity - num;
 
                BaseDal.AddData(orderNew);
                BaseDal.UpdateData(originalOrder);
                return content.OK();
            }
            catch (Exception ex)
            {
                return content.Error("未知错误,请联系管理员");
            }
        }
 
        public WebResponseContent PrintPalletCode(int num)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                List<string> PalletCodes = new List<string>();
                for (int i = 0; i < num; i++)
                {
                    PalletCodes.Add(GetOrderPintCode("PalletCodes"));
                }
                 content= PrintPallet(PalletCodes);
                return content.OK();
            }
            catch (Exception ex)
            {
                return content.Error("未知错误,请联系管理员");
            }
        }
        public string GetOrderPintCode(string printCode)
        {
            string PrintCode = "";
            var PrintSetting = SqlSugarHelper.DbWMS.Queryable<Dt_PrintSetting>().Where(x => x.PrintCode == printCode).ToList().FirstOrDefault();
 
            if (PrintSetting.Spare1 == DateTime.Now.ToString("yyyyMMdd"))
            {
                PrintCode = PrintSetting.Spare1 + PrintSetting.PrintNo.ToString().PadLeft(PrintSetting.Spare2, '0');
                PrintSetting.PrintNo = PrintSetting.PrintNo + 1;
            }
            else
            {
                PrintSetting.Spare1 = DateTime.Now.ToString("yyyyMMdd");
                PrintSetting.PrintNo = 2;
                PrintCode = PrintSetting.Spare1 + 1.ToString().PadLeft(PrintSetting.Spare2, '0');
            }
            SqlSugarHelper.DbWMS.Updateable(PrintSetting).ExecuteCommand();
            return PrintCode;
        }
        public WebResponseContent PrintPallet(List<string> palletCodes)
        {
            var configs = _configService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
            var Base = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.PrintIPAddress)?.ConfigValue;
            var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.PrintPalletCodes)?.ConfigValue;
            if (Base == null || ipAddress == null)
            {
                throw new InvalidOperationException("WMS IP 未配置");
            }
            var IpAddress = Base + ipAddress;
            var result = HttpsClient.PostAsync(IpAddress, palletCodes.ToJsonString()).Result;
            return JsonConvert.DeserializeObject<WebResponseContent>(result);
        }
 
        public WebResponseContent PrintInbound(List<Dt_InboundOrder> orders)
        {
            var configs = _configService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
            var Base = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.PrintIPAddress)?.ConfigValue;
            var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.PrintInboundOrder)?.ConfigValue;
            if (Base == null || ipAddress == null)
            {
                throw new InvalidOperationException("WMS IP 未配置");
            }
            var IpAddress = Base + ipAddress;
            var result = HttpsClient.PostAsync(IpAddress, orders.ToJsonString()).Result;
            return JsonConvert.DeserializeObject<WebResponseContent>(result);
        }
    }
}