hutongqing
2025-01-02 b51a65433d6102f2f8f00226404d9ca3808404af
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
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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
    {
        public PalletCodeInfoService(IPalletCodeInfoRepository BaseDal) : base(BaseDal)
        {
        }
 
        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;
                }
                for (int i = 0; i < count; i++)
                {
                    palletCodeInfos.Add(new Dt_PalletCodeInfo
                    {
                        SerialNo = serialNo,
                        PalletCode = 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);
            }
        }
    }
}