1
z8018
2025-04-16 1f361850d35ba47225951efbc49d592eea685cf8
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
#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 命名空间:WIDESEAWCS_TaskInfoService
 * 创建者:胡童庆
 * 创建时间:2024/8/2 16:13:36
 * 版本:V1.0.0
 * 描述:
 *
 * ----------------------------------------------------------------
 * 修改人:
 * 修改时间:
 * 版本:V1.0.1
 * 修改说明:
 * 
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
 
using AutoMapper;
using Microsoft.AspNetCore.Mvc.RazorPages;
using NetTaste;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using SqlSugar;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_Core.Enums;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.BasicInfo;
using WIDESEAWCS_IBasicInfoRepository;
using WIDESEAWCS_IBasicInfoService;
using WIDESEAWCS_Model.Models;
 
namespace WIDESEAWCS_BasicInfoService
{
    public class OrderDetailsService : ServiceBase<OrderDetails, IOrderDetailsRepository>, IOrderDetailsService
    {
        private readonly IOrderrowsRepository _orderrowsRepository;
        public OrderDetailsService(IOrderDetailsRepository BaseDal, IOrderrowsRepository orderrowsRepository) : base(BaseDal)
        {
            _orderrowsRepository = orderrowsRepository;
        }
 
        private static bool toggle = false;
 
        private static int lastStaion = 0;
        public int GetOrderDetails(string barcode, List<int> useableStations, out ProductInfoDTO productInfo)
        {
            OrderDetails? orderDetails = BaseDal.QueryData(x => x.Orderdetails_outid == barcode).FirstOrDefault();
            if (orderDetails != null)
            {
                productInfo = new ProductInfoDTO()
                {
                    Code = barcode,
                    Height = Convert.ToInt32(orderDetails.Orderdetails_thickness),
                    Length = Convert.ToInt32(orderDetails.Orderdetails_length),
                    Width = Convert.ToInt32(orderDetails.Orderdetails_width),
                };
                useableStations = useableStations.OrderByDescending(x => x).ToList();
                if (orderDetails.Orderdetails_width < 60)
                    useableStations = useableStations.Where(x => x != 1).OrderByDescending(x => x).ToList();
 
                if (orderDetails.Orderdetails_width <= 800 && orderDetails.Orderdetails_width >= 50)//1,2,3
                {
                    if (lastStaion == 0)
                    {
                        lastStaion = useableStations.FirstOrDefault();
                        return lastStaion;
                    }
                    else
                    {
                        int index = useableStations.IndexOf(lastStaion);
                        if (index + 1 < useableStations.Count)
                        {
                            lastStaion = useableStations[index + 1];
                            return lastStaion;
                        }
                        else
                        {
                            lastStaion = useableStations.FirstOrDefault();
                            return lastStaion;
                        }
                    }
                }
                else if (orderDetails.Orderdetails_width >= 800 && orderDetails.Orderdetails_width <= 1220)//1,2
                {
                    useableStations = useableStations.Where(x => x != 3).ToList();
 
                    if (useableStations.FirstOrDefault() == 0)
                    {
                        return -2;
                    }
                    if (lastStaion == 0)
                    {
                        lastStaion = useableStations.FirstOrDefault();
                        return lastStaion;
                    }
                    else
                    {
                        int index = useableStations.IndexOf(lastStaion);
                        if (index + 1 < useableStations.Count)
                        {
                            lastStaion = useableStations[index + 1];
                            return lastStaion;
                        }
                        else
                        {
                            lastStaion = useableStations.FirstOrDefault();
                            return lastStaion;
                        }
                    }
                }
                else
                {
                    return -2;
                }
            }
            else
            {
                productInfo = new ProductInfoDTO();
                return -1;
            }
        }
 
 
        public string ToMesScan_sync = WIDESEAWCS_Core.Helper.AppSettings.Configuration["ToMesScan_sync"];
 
        public ToMesBarcRes? ToMesBarc(int Barcodes)
        {
            ToMesBarc toMes = new ToMesBarc()
            {
                id = Barcodes.ToString(),
                type = "1",
            };
            ToMesBarcRes? toMesBarc = JsonConvert.DeserializeObject<ToMesBarcRes>(HttpHelper.Post($"{ToMesScan_sync}", toMes.Serialize()));
 
            return toMesBarc;
        }
 
        public OrderInfo GetOrderInfoByBarcode(string barcode)
        {
            try
            {
                OrderDetails orderDetails = BaseDal.QueryFirst(x => x.Orderdetails_outid == barcode);
                if (orderDetails == null)
                {
                    throw new Exception("未找到条码对应订单信息");
                }
 
                Orderrows orderrows = _orderrowsRepository.QueryFirst(x => x.id == orderDetails.Orderrowsid);
                if (orderrows == null)
                {
                    throw new Exception($"未找到对应订单头信息");
                }
 
                OrderInfo orderInfo = new OrderInfo()
                {
                    Barcode = barcode,
                    Length = orderDetails.Orderdetails_length,
                    OrderBatch = orderrows.Orderrows_batchid,
                    OrderHeadId = orderrows.id,
                    OrderNo = orderrows.Orderrows_orderid,
                    OrderRowNum = orderrows.Orderrows_id,
                    Quantity = Convert.ToInt32(orderrows.Orderrows_num),
                    Thickness = orderDetails.Orderdetails_thickness,
                    Width = orderDetails.Orderdetails_width,
                };
                return orderInfo;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
    }
}