服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-03-23 5ec2816b25ccc33855c48da7f7f9305e21e6dc38
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
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Rhea.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using Tiger.Model;
using Tiger.Model.Minsun;
using Tiger.IBusiness;
 
namespace Tiger.Business
{
    public partial class Biz
    {
        public partial class ErpT100
        {
 
            /// <summary>
            /// 从T100获取供应商接口
            /// </summary>
            /// <param name="input"></param>
            /// <returns></returns>
            public T100ActionResult<resultStd_data<VenderParameterR>> GetVenderInfo(VenderInputParameter input)
            {
                var t100Action = new T100Action<actionStd_data<VenderParameter>>
                {
                    key = Guid.NewGuid().ToString("N"),
                    type = "sync",
                    host = new host
                    {
                        prod = "MES",
                        ip = "",
                        lang = "zh_CN",
                        acct = "tiptop",
                        timestamp = DateTime.Now.ToString("yyyyMMddHHMMssfff"),
                    },
                    datakey = input.datakey,
                    service = new Service
                    {
                        ip = "",
                        prod = "T100",
                        id = "topprd",
                        name = "wms_erp_wms_getven"
                    },
                    payload = new PayloadData<actionStd_data<VenderParameter>>
                    {
                        std_data = new actionStd_data<VenderParameter>
                        {
                            parameter = input.parameter
                        }
                    }
                }; 
                var requestJson = JsonConvert.SerializeObject(t100Action);
                var response = HttpHelper.PostAsync(t100Url, requestJson).Result;
                var result = JsonConvert.DeserializeObject<T100ActionResult<resultStd_data<VenderParameterR>>>(response.Message);
                return result;
            }
 
            public ApiAction GetVenderInfoToDDL(iVenderParams input)
            {
                var action = new ApiAction();
                try
                {
                    var t100Res = GetVenderInfo(new VenderInputParameter
                    {
                        parameter = new VenderParameter
                        {
                            site = input.company,
                            startdt = input.startDate,
                            enddt = input.endDate
                        },
                        datakey = new Datakey
                        {
                            EntId = ApiConfig.IsTestServer ? "108" : "88",
                            CompanyId = input.company
                        }
                    });
                    if (t100Res.payload.std_data.execution.code == "0")
                    {
                        var list = t100Res.payload.std_data.parameter.@return;
                        action.Data = list;
                        List<BAS_SUPPLIER> suppliers = new List<BAS_SUPPLIER>();
                        var allList = Db.Queryable<BAS_SUPPLIER>().Where(x => x.AUTH_ORG == input.company).ToList();
                        foreach (var item in list)
                        {
                            var query = allList.Where(x => x.SUPP_CODE == item.pmab001).FirstOrDefault();
                            BAS_SUPPLIER entity = query ?? new BAS_SUPPLIER()
                            {
                                SUPP_CODE = item.pmab001,
                                SUPP_NAME_CN = item.pmaal003,
                                AUTH_ORG = input.company
                            };
                            suppliers.Add(entity);
                        }
                        var db = Business.Biz.Db;
                        //数据库处理操作
                        if (action.IsSuccessed)
                        {
                            action.Message = $"供应商信息同步成功";
                            var dbTran = db.UseTran(() =>
                            {
                                db.Storageable(suppliers,"Interface").ExecuteCommand();
 
                            });
                            if (!dbTran.IsSuccess)
                            {
                                action.CatchExceptionWithLog(dbTran.ErrorException, $"数据处理失败");
                            }
                        }
                    }
                    else {
                        action.IsSuccessed = false;
                        action.Message = $"T100返回信息错误:{t100Res.payload.std_data.execution.description}";
                    }
                    
                }
                catch (Exception ex)
                {
                    action.CatchExceptionWithLog(ex, $"数据处理失败");
                }
                return action;
            }
        }
    }
}