1
dengjunjie
2025-01-09 be0856c1bf533ed6001ff786908ae98e4b853eb5
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
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;
        public PalletCodeInfoService(IPalletCodeInfoRepository BaseDal, IWarehouseRepository warehouseRepository) : base(BaseDal)
        {
            _warehouseRepository = warehouseRepository;
        }
 
        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)
                {
                    case "HA153":
                        uplen = "Y";
                        break;
                    default:
                        uplen = "N";
                        break;
                }
                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 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;
        }
    }
}