服务端的TigerApi 框架,基于.NET6 2024 版本
Ben Lin
2024-11-25 7630f581e6ed2fabd50ab6ecd444691f1e99b881
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
164
165
166
using Tiger.Model;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Rhea.Common;
using System.Net;
using System.Linq;
using Newtonsoft.Json;
using Tiger.IBusiness;
using Microsoft.AspNetCore.Http;
using Tiger.Model.Minsun;
using Org.BouncyCastle.Asn1.Tsp;
using Tiger.Model.Entitys.MES.Position;
using Apache.NMS.ActiveMQ.Commands;
using System.Security.Cryptography;
using System.Diagnostics;
using Tiger.Model.Entitys.MES.U9C;
using Newtonsoft.Json.Linq;
using System.Security.Policy;
using NetTaste;
 
namespace Tiger.Business.MES
{
    public partial class MES_U9C : IMES_U9C
    {
        public static string U9CAuthLoginUrl { get; set; } = "http://172.16.80.20/U9C/webapi/OAuth2/AuthLogin?";
        public static string secret = "&entcode=02&orgcode=101&clientid=mes&clientsecret=12c8ee7e9bb74ad2a6a0fb3315c8af20";
        public static string RcvRptDocCreateUrl
        { get; set; } = "http://172.16.80.20/u9C/webapi/RcvRptDoc/Create";
 
        /// <summary>
        /// 入库单接口
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<ApiAction<List<InStorePrintJson>>> RcvRptDocCreate(RcvRptDocCreateInput input)
        {
            Logger.Interface.Info($"/**\r\n *进入入库单接口....\r\n */\r\n"); //固定写法
            var action = new ApiAction<List<InStorePrintJson>>();
            try
            {
                //List<RcvRptDocCreateParam> param = new List<RcvRptDocCreateParam>();
                //List<CompleteList> CompleteLists = new List<CompleteList>();
                //param.Add(new RcvRptDocCreateParam
                //{
                //    CompleteList = CompleteLists
                //});
 
                //先保存数据
                bool IsSuccessed = true;
                var db = Biz.Db;
                var dbTran = db.UseTran(() =>
                {
                    var s = db.Storageable(input.ErpProdInBths, "U9C_RcvRptDocCreate")
                                .WhereColumns(t => new { t.ORDER_NO,t.WORK_ORDER, t.GHOST_ROW })
                                .ToStorage();
                    s.AsInsertable.ExecuteCommand();
                    s.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
                });
                if (!dbTran.IsSuccess)
                {
                    action.CatchExceptionWithLog(dbTran.ErrorException, $"数据处理失败");
                    Logger.Interface.Error(action.Message);
                    IsSuccessed = false;
                }
                //保存成功,调用U9C接口
                //int i = 1;
                //foreach (var item in input.RcvRptDocBases)
                //{
                //    foreach (var p in input.PrintJsons)
                //    {
                //        var d = p.Items.Where(q => q.WORK_ORDER == item.WorkOrder).FirstOrDefault();
                //        if (!d.IsNullOrEmpty())
                //        {
                //            d.ORDER_NO = $"XX001-{i}";
                //        }
                //        i++;
                //    }
                //}
                if (IsSuccessed)
                {
                    var u9CLoginResult = await HttpHelper.GetAsync<U9CLoginResult>($"{U9CAuthLoginUrl}userCode=admin{secret}");
                    if (u9CLoginResult.Success)
                    {
                        var token = u9CLoginResult.Data;
                        Logger.Interface.Info($"U9C登录token: {token}");
                        List<BIZ_ERP_PROD_IN_BTH> ErpProdInBths = new List<BIZ_ERP_PROD_IN_BTH>();
                        foreach (var item in input.RcvRptDocBases)
                        {
                            List<RcvRptDocCreateParam> param = new() {
                                new() {
                                    CompleteList = new(){
                                       new CompleteList
                                       {
                                            MOKey = new MOKey { DocNo = item.WorkOrder },
                                            Wh = new Wh { Code = item.WhCode },
                                            DescFlexField = new DescFlexField { PrivateDescSeg1 = item.PkgQty.ToString() },
                                            Item = new Item { Code = item.ItemCode },
                                            CompleteQty = item.CompleteQty,
                                            OutputType = item.OutputType,
                                            StorageType = item.StorageType,
                                            DocState = item.DocState,
                                       }
                                    }
                                }
                            };
                            var response = await HttpHelper.PostAsync(RcvRptDocCreateUrl, JsonConvert.SerializeObject(param), new Dictionary<string, string>() { { "token", token } });
                            var result = JsonConvert.DeserializeObject<U9CResult>(response.Message);
                            if (result != null)
                            {
                                if (result.Success)
                                {
                                    Logger.Interface.Info($"生成入库单接口提交Json: {JsonConvert.SerializeObject(param)},返回Json: {response.Message}");
                                    var ErpProdInBth = Biz.Db.Queryable<BIZ_ERP_PROD_IN_BTH>().Where(q=> q.WORK_ORDER == item.WorkOrder).First();
                                    if (!ErpProdInBth.IsNullOrEmpty())
                                    {
                                        ErpProdInBth.ORDER_NO = result.Data[0].m_code;
                                        ErpProdInBth.IS_HANDLED = "Y";
                                        ErpProdInBth.HANDLED_DATE = DateTime.Now;
                                        ErpProdInBths.Add(ErpProdInBth);
                                    }
                                    foreach (var p in input.PrintJsons)
                                    {
                                        var d = p.Items.Where(q => q.WORK_ORDER == item.WorkOrder).FirstOrDefault();
                                        if (!d.IsNullOrEmpty())
                                        {
                                            d.ORDER_NO = result.Data[0].m_code;
                                        }
                                    }
                                    Logger.Interface.Info($"生成入库单成功");
                                }
                                else
                                {
                                    action.IsSuccessed = false;
                                    action.LocaleMsg = new($"{result.Data[0].m_errorMsg}");
                                    Logger.Interface.Info($"生成入库单失败:{result.Data[0].m_errorMsg}");
                                }
                            }
                        }
                        var _db = Biz.Db;
                        var _dbTran = _db.UseTran(() =>
                        {
                            _db.Updateable(ErpProdInBths, "U9C_RcvRptDocCreate").UpdateColumns(x => new { x.ORDER_NO, x.IS_HANDLED, x.HANDLED_DATE }).ExecuteCommand();
                        });
                        if (!dbTran.IsSuccess)
                        {
                            action.CatchExceptionWithLog(dbTran.ErrorException, $"数据处理失败");
                            Logger.Interface.Error(action.Message);
                            IsSuccessed = false;
                        }
                    }
                }
                action.Data = input.PrintJsons;
            }
            catch (System.Exception ex)
            {
                action.CatchExceptionWithLog(ex, "生成入库单异常");
            }
            Logger.Interface.Info($"/* 入库单接口结束 */\r\n"); //固定写法
            return action;
        }
    }
}