1
yangpeixing
3 天以前 48e2278d7ac330c7f05deda6f884acb6f01206b4
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
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Core;
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Const;
using WIDESEA_Core.Helper;
using WIDESEA_IBasicRepository;
using WIDESEA_IBasicService;
using WIDESEA_Model.Models;
 
namespace WIDESEA_BasicService.Base
{
    public partial class PalletTypeInfoService : ServiceBase<Dt_PalletTypeInfo, IPalletTypeInfoRepository>, IPalletTypeInfoService
    {
        public PalletTypeInfoService(IPalletTypeInfoRepository BaseDal) : base(BaseDal)
        {
        }
 
        /// <summary>
        /// 打印托盘码
        /// </summary>
        /// <param name="num"></param>
        /// <returns></returns>
        public WebResponseContent PrintPalletCode(int num, string palletCodeType)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                List<string> PalletCodes = new List<string>();
                for (int i = 0; i < num; i++)
                {
                    PalletCodes.Add(GetOrderPintCode($"PalletCodes",palletCodeType));
                }
                content= PrintPallet(PalletCodes);
                foreach (var PalletCode in PalletCodes)
                {
                    Console.WriteLine(PalletCode);
                }
                return content.OK();
            }
            catch (Exception ex)
            {
                return content.Error("未知错误,请联系管理员");
            }
        }
 
        /// <summary>
        /// 获取订单编号
        /// </summary>
        /// <param name="printCode"></param>
        /// <returns></returns>
        public string GetOrderPintCode(string printCode,string palletCodeType)
        {
            string PrintCode = "";
            var PrintSetting = Db.Queryable<Dt_PrintSetting>().Where(x => x.PrintCode == printCode).ToList().FirstOrDefault();
 
            if (PrintSetting.Spare1 == DateTime.Now.ToString("yyyyMMdd"))
            {
                PrintCode = palletCodeType+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 = palletCodeType+PrintSetting.Spare1 + 1.ToString().PadLeft(PrintSetting.Spare2, '0');
            }
           Db.Updateable(PrintSetting).ExecuteCommand();
            return PrintCode;
        }
 
        /// <summary>
        /// 调用打印托盘码接口
        /// </summary>
        /// <param name="palletCodes"></param>
        /// <returns></returns>
        /// <exception cref="InvalidOperationException"></exception>
        public WebResponseContent PrintPallet(List<string> palletCodes)
        {
            string url = "http://127.0.0.1:8098/Print/PrintPalletCode";
            HttpHelper.Post(url, palletCodes.Serialize());
            return WebResponseContent.Instance.OK();
        }
 
        /// <summary>
        /// 获取托盘标识
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public WebResponseContent GetPalletTypeInfos(int WarehouseId)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                List<Dt_PalletTypeInfo> dt_PalletTypeInfos = BaseDal.QueryData(x => x.WarehouseId == WarehouseId);
                return content.OK(data: dt_PalletTypeInfos);
            }
            catch(Exception ex)
            {
                return content.Error();
            }
        }
 
        public WebResponseContent GetWarehouses()
        {
            WebResponseContent content = new WebResponseContent();
 
            try
            {
                List<Dt_PalletTypeInfo> dt_PalletTypeInfos = BaseDal.QueryData(x => x);
                List<Dt_Warehouse> dt_Warehouses = new List<Dt_Warehouse>();
                foreach (var item in dt_PalletTypeInfos)
                {
                    Dt_Warehouse dt_Warehouse = Db.Queryable<Dt_Warehouse>().First(x => x.WarehouseId == item.WarehouseId);
                    dt_Warehouses.Add(dt_Warehouse);
                }
                List<Dt_Warehouse> NewDt_Warehouses = new List<Dt_Warehouse>();
                NewDt_Warehouses.AddRange(dt_Warehouses.DistinctBy(x => x.WarehouseId));
                return content.OK(data: NewDt_Warehouses);
            }
            catch(Exception ex)
            {
                return content.Error();
            }
            
        }
 
        public override WebResponseContent UpdateData(SaveModel saveModel)
        {
            var id = saveModel.MainData["id"].ObjToInt();
            var palletType = saveModel.MainData["palletType"].ObjToInt();
            var typeName = saveModel.MainData["typeName"].ToString();
            var length = saveModel.MainData["length"].ObjToInt();
            var width = saveModel.MainData["width"].ObjToInt();
            var height = saveModel.MainData["height"].ObjToInt();
            var locationCount = saveModel.MainData["locaitonCount"].ObjToInt();
            Dt_PalletTypeInfo palletTypeInfo = BaseDal.QueryFirst(x => x.Id == id);
            palletTypeInfo.PalletType = palletType;
            palletTypeInfo.TypeName = typeName;
            palletTypeInfo.Length = length;
            palletTypeInfo.Width = width;
            palletTypeInfo.Height = height;
            palletTypeInfo.LocaitonCount = locationCount;
 
            return base.UpdateData(palletTypeInfo);
        }
    }
}