1
hutongqing
2025-01-11 9be8d6e3232971246ec6cb2acac1ad4d05798e9b
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
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common.CommonEnum;
using WIDESEA_Common.WareHouseEnum;
using WIDESEA_Core;
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Helper;
using WIDESEA_IBasicRepository;
using WIDESEA_IBasicService;
using WIDESEA_Model.Models;
 
namespace WIDESEA_BasicService
{
    public class PalletCodeInfoService : ServiceBase<Dt_PalletCodeInfo, IPalletCodeInfoRepository>, IPalletCodeInfoService
    {
        private readonly IWarehouseRepository _warehouseRepository;
        private readonly IPalletTypeInfoRepository _palletTypeInfoRepository;
 
        public PalletCodeInfoService(IPalletCodeInfoRepository BaseDal, IWarehouseRepository warehouseRepository, IPalletTypeInfoRepository palletTypeInfoRepository) : base(BaseDal)
        {
            _warehouseRepository = warehouseRepository;
            _palletTypeInfoRepository = palletTypeInfoRepository;
        }
 
        static object locker = new object();
        public override WebResponseContent AddData(SaveModel saveModel)
        {
            int warehouseId = 0;
            int count = 0;
            if (saveModel.MainData.TryGetValue("warehouseId", out object? warehouse) && warehouse != null)
            {
                warehouseId = warehouse.ObjToInt();
            }
            if (saveModel.MainData.TryGetValue("count", out object? countValue) && countValue != null)
            {
                count = countValue.ObjToInt();
            }
            lock (locker)
            {
                List<Dt_PalletCodeInfo> palletCodeInfos = new List<Dt_PalletCodeInfo>();
                int serialNo = 0;
                DateTime now = DateTime.Now;
                Dt_PalletCodeInfo palletCodeInfo = BaseDal.QueryFirst(x => x.WarehouseId == warehouseId, new Dictionary<string, OrderByType> { { nameof(Dt_PalletCodeInfo.SerialNo), OrderByType.Desc } });
                if (palletCodeInfo != null && palletCodeInfo.CreateDate.Year == now.Year && palletCodeInfo.CreateDate.Month == now.Month && palletCodeInfo.CreateDate.Day == now.Day)
                {
                    serialNo = palletCodeInfo.SerialNo + 1;
 
                }
                else
                {
                    serialNo = 1;
                }
                Dt_Warehouse _Warehouse = _warehouseRepository.QueryFirst(x => x.WarehouseId == warehouseId);
                string uplen = "";
                switch (_Warehouse.WarehouseCode)
                {
                    "HA57" => "B",
                    "HA58" => "P",
                    "HA152" => "G",
                    "HA64" => "S",
                    "阻焊仓" => "Z",
                    "HA153" => "Y",
                    "HA71" => "C",
                    "HA60" => "F",
                    _ => "N"
                };
                for (int i = 0; i < count; i++)
                {
 
                    palletCodeInfos.Add(new Dt_PalletCodeInfo
                    {
                        SerialNo = serialNo,
                        PalletCode = uplen + now.ToString("yyyyMMdd") + serialNo.ToString().PadLeft(3, '0'),
                        PalletType = 1,
                        PalletTypeId = 0,
                        WarehouseId = warehouseId,
                        Status = 0,
                        Size = 0
                    });
 
                    serialNo = serialNo + 1;
                }
                return base.AddData(palletCodeInfos);
            }
        }
 
        public WebResponseContent AddData(int warehouseId, int count, int palletTypeId)
        {
            try
            {
                Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.Id == palletTypeId && x.WarehouseId == warehouseId);
                if (palletTypeInfo == null)
                {
                    return WebResponseContent.Instance.Error($"未找到托盘类型配置信息");
                }
                lock (locker)
                {
                    List<Dt_PalletCodeInfo> palletCodeInfos = new List<Dt_PalletCodeInfo>();
                    int serialNo = 0;
                    DateTime now = DateTime.Now;
                    Dt_PalletCodeInfo palletCodeInfo = BaseDal.QueryFirst(x => x.WarehouseId == warehouseId, new Dictionary<string, OrderByType> { { nameof(Dt_PalletCodeInfo.SerialNo), OrderByType.Desc } });
                    if (palletCodeInfo != null && palletCodeInfo.CreateDate.Year == now.Year && palletCodeInfo.CreateDate.Month == now.Month && palletCodeInfo.CreateDate.Day == now.Day)
                    {
                        serialNo = palletCodeInfo.SerialNo + 1;
 
                    }
                    else
                    {
                        serialNo = 1;
                    }
 
                    for (int i = 0; i < count; i++)
                    {
 
                        palletCodeInfos.Add(new Dt_PalletCodeInfo
                        {
                            SerialNo = serialNo,
                            PalletCode = palletTypeInfo.CodeStartStr + now.ToString("yyyyMMdd") + serialNo.ToString().PadLeft(3, '0'),
                            PalletType = 1,
                            PalletTypeId = 0,
                            WarehouseId = warehouseId,
                            Status = 0,
                            Size = 0
                        });
 
                        serialNo = serialNo + 1;
                    }
                    BaseDal.AddData(palletCodeInfos);
                }
                return WebResponseContent.Instance.OK();
            }
            catch(Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
 
        public WebResponseContent PrintStatusUp(string printCode)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                Dt_PalletCodeInfo palletCodeInfo = BaseDal.QueryFirst(x => x.PalletCode == printCode);
                if (palletCodeInfo == null)
                {
                    return content.Error("打印的托盘码不存在");
                }
                palletCodeInfo.Status = PrintStatusEnum.Printed.ObjToInt();
                BaseDal.UpdateData(palletCodeInfo);
                return content.OK();
            }
            catch (Exception ex)
            {
                content.Error("错误:" + ex.Message);
            }
            return content;
        }
    }
}