1
huangxiaoqiang
2 天以前 5a15fa73d5f6a39917013871a65eb11a8c013391
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
using Masuit.Tools;
using SharpCompress.Compressors.ADC;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common;
using WIDESEA_Core.Const;
using WIDESEA_IOrderRepository;
using WIDESEA_IServices;
using WIDESEA_IStorageBasicServices.Stock;
using WIDESEA_Model.Models.ERP;
using WIDESEA_Model.Models.Order;
using WIDESEA_OrderRepository;
 
namespace WIDESEA_StorageBasicServices
{
    public partial class ERPInboundOrderService : IERPInboundOrderService
    {
        private readonly IUnitOfWorkManage _unitOfWorkManage; 
        private readonly ISys_ConfigService _configService;
        private readonly IDt_InboundOrderRepository _inboundOrderRepository;
        public ERPInboundOrderService(IUnitOfWorkManage unitOfWorkManage, ISys_ConfigService configService,IDt_InboundOrderRepository inboundOrderRepository)
        {
            _unitOfWorkManage = unitOfWorkManage;
            _configService = configService;
            _inboundOrderRepository = inboundOrderRepository;
        }
        public virtual PageGridData<WMS_采购及成品入库清单_ST> GetPageData(PageDataOptions options)
        {
            string wheres = options.ValidatePageOptions(typeof(WMS_采购及成品入库清单_ST).GetProperties());
            //获取排序字段
            int totalCount = 0;
            var data = SqlSugarHelper.DBERP.Queryable<WMS_采购及成品入库清单_ST>()
                .WhereIF(!wheres.IsNullOrEmpty(), wheres)
                .ToPageList(options.Page, options.Rows, ref totalCount);
            new PageGridData<WMS_采购及成品入库清单_ST>(totalCount, data);
            return new PageGridData<WMS_采购及成品入库清单_ST>(totalCount, data);
        }
        public WebResponseContent Print(List<WMS_采购及成品入库清单_ST> wMSs)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                List<Dt_InboundOrder> orderinbound=new List<Dt_InboundOrder>();
                foreach (var wMS in wMSs)
                {
                    Dt_InboundOrder Print = new Dt_InboundOrder()
                    {
                        OrderNo = GetOrderPintCode("OrderNoIn"),
                        UpperOrderNo = wMS.单号,
                        DemandClassification = wMS.需求分类,
                        OrderType = wMS.单据类型,
                        WarehouseName = wMS.入库仓库名称,
                        Datetime = wMS.日期.ToString(),
                        LineNumber = wMS.行号,
                        ProductDrawingNumber = wMS.产品图号,
                        MaterialNo = wMS.料号,
                        MaterialName = wMS.品名,
                        Weight = wMS.单重,
                        WareHouseId = wMS.入库仓库编码,
                        Specs = wMS.规格,
                        Unit = wMS.单位,
                        Texture = wMS.用友材质,
                        Quantity = wMS.入库数量,
                        OrderStatus = wMS.单据状态
                    };
                    orderinbound.Add(Print);
                }
                _inboundOrderRepository.AddData(orderinbound);
                PrintInbound(orderinbound);
                return content.OK("打印成功");
            }
            catch (Exception ex)
            {
                return content.Error(ex.Message);
            }
        }
        public void PrintInbound(List<Dt_InboundOrder> orders)
        {
            var configs = _configService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
            var Base = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.PrintIPAddress)?.ConfigValue;
            var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.PrintInboundOrder)?.ConfigValue;
            if (Base == null || ipAddress == null)
            {
                throw new InvalidOperationException("WMS IP 未配置");
            }
            var IpAddress = Base + ipAddress;
            var result = HttpsClient.PostAsync(IpAddress, orders.ToJsonString()).Result;
        }
 
        public string GetOrderPintCode(string printCode)
        {
            string PrintCode = "";
            var PrintSetting = SqlSugarHelper.DbWMS.Queryable<Dt_PrintSetting>().Where(x => x.PrintCode == printCode).ToList().FirstOrDefault();
 
            if (PrintSetting.Spare1 == DateTime.Now.ToString("yyyyMMdd"))
            {
                PrintCode = 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 = PrintSetting.Spare1 + 1.ToString().PadLeft(PrintSetting.Spare2, '0');
            }
            SqlSugarHelper.DbWMS.Updateable(PrintSetting).ExecuteCommand();
            return PrintCode;
        }
    }
}