服务端的TigerApi 框架,基于.NET6 2024 版本
Ben Lin
2024-07-05 5fe26555029f1a941e5a3418c28499a534138a62
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
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;
 
namespace Tiger.Business.MES
{
    public partial class U9C_MES : IU9C_MES
    {
        /// <summary>
        /// 从U9C拉取物料数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<ApiAction> GetBasItem(GetBasItemInput input)
        {
            var action = new ApiAction();
            Logger.Scheduler.Info(Biz.L($"物料信息开始同步。。。数据检查进行中。。。"));
            Logger.Scheduler.Info(Biz.L($"{input.triggerDetail}"));
            DbClient db = Biz.DataSource["YadaU9C"].Client;
            var list = db.Queryable<dynamic>().AS("mes_ItemMaster").Where("ModifiedOn > @startTime And ModifiedOn < @endTime", new { startTime = input.startTime, endTime = input.endTime }).ToList();
            List<BAS_ITEM> items = new();
            foreach (var item in list)
            {
                var d = item as System.Dynamic.ExpandoObject;
                var di = d as IDictionary<string, object>;
                di = di?.ToDictionary(x => x.Key, x => x.Value);
                if (di != null)
                {
                    BAS_ITEM basItem = new()
                    {
                        ID = di["ID"].ToString(),
                        ITEM_CODE = di["Code"] == null ? "" : di["Code"].ToString(),
                        ITEM_NAME = di["Name"] == null ? "" : di["Name"].ToString(),
                        ITEM_DESC = di["Description"] == null ?"":di["Description"].ToString(),
                        SPEC = di["SPECS"] == null ? "" : di["SPECS"].ToString(),
                        ITEM_TYPE = di["CategoryCode"] == null ? "" : di["CategoryCode"].ToString(),
                        UNIT = di["InventorySecondUOM"] == null ? "" : di["InventorySecondUOM"].ToString(),
                        PROD_TYPE = di["ProductTypeCode"] == null ? "" : di["ProductTypeCode"].ToString(),
                        CREATE_TIME = di["CreatedOn"].ToDateTime(),
                        UPDATE_TIME = di["ModifiedOn"].ToDateTime(),
                        IS_ACTIVE = "Y",
                        IS_PROD = ((string)di["Code"]).StartsWith("2") ? "Y" : "N",
                    };
                    items.Add(basItem);
                }
            }
 
            Logger.Scheduler.Info(Biz.L($"物料信息存入实体中,总数:[{items.Count}]"));
            db = Biz.Db;
            var LastRun = db.Queryable<SYS_PARAM>().Where(q => q.PRMG_CODE == "Interface_LastRun" && q.PARAM_CODE == "GetItem_LastRun").Single();
            LastRun.PARAM_VALUE = input.endTime;
            var dbTran = db.UseTran(() =>
            {
                db.Storageable(LastRun, "U9C_MES_GetItem").ExecuteCommand();
                if (items.Any())
                {
                    if (items.Count > 150)
                    {
                        db.Utilities.PageEach(items, 1000, pageList =>
                        {
                            var y = db.Storageable(pageList, "U9C")
                                   .WhereColumns(t => new { t.ITEM_CODE, t.GHOST_ROW })
                                   .ToStorage();
                            y.BulkCopy();
                            y.BulkUpdate();
                        });
                    }
                    else
                    {
                        var s = db.Storageable(items, "U9C")
                               .WhereColumns(t => new { t.ITEM_CODE, t.GHOST_ROW })
                               .ToStorage();
                        s.AsInsertable.ExecuteCommand();
                        s.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
                    }
                }
 
            });
            if (!dbTran.IsSuccess)
            {
                action.CatchExceptionWithLog(dbTran.ErrorException, $"数据处理失败");
                Logger.Scheduler.Error(action.Message);
            }
 
            Logger.Scheduler.Info(Biz.L($"物料信息存入数据库,总数:[{items.Count}]"));
            return action;
 
        }
 
        public Task<ApiAction> GetCustomer(GetCustomerInput input)
        {
            throw new NotImplementedException();
        }
 
        public Task<ApiAction> GetSupplier(GetSupplierInput input)
        {
            throw new NotImplementedException();
        }
    }
}