服务端的TigerApi 框架,基于.NET6 2024 版本
Ben Lin
2025-01-10 f7f7279a6631ef9929b8087204c7f210e3ec7f5b
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
using Rhea.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tiger.Model.MES.Yada;
using Tiger.Model;
using Tiger.IBusiness;
using Microsoft.CodeAnalysis.Options;
using Tiger.Model.Entitys.MES.U9C;
using SqlSugar;
using System.Collections;
using System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder;
 
namespace Tiger.Business.WMS
{
    public partial class U9C_WMS: IU9C_WMS
    {
 
 
        /// <summary>
        /// 同步物料条码信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public ApiAction In_BySync(U9C_Base_Input input)
        {
            var action = new ApiAction();
            Logger.Scheduler.Info($"物料条码信息开始同步。。。数据检查进行中。。。");
            Logger.Scheduler.Info($"{input.triggerDetail}");
            DbClient db = Biz.DataSource["YadaU9C"].Client;
            string UserCode = "System_In_BySync";
            var list = db.Ado.SqlQuery<mes_MaterialBarCodeByBin>($"select *,cast('{DateTime.Now.ToString("yyyy-MM-dd")}' as DATETIME) as PROD_DATE,'' as Unit,'' as LotNo from mes_MaterialBarCodeByBin where ModifiedOn > '{input.startTime}' And ModifiedOn < '{input.endTime}'");
            try
            {
                foreach (var item in list)
                {
                    Barcode barcode = new Barcode(item.Code);
                    item.Code = item.Code;
                    item.Segment5 = barcode.ItemCode;
                    item.PROD_DATE = barcode.DateCode.ToDateTime();
                    item.Unit = barcode.Unit;
                    item.LotNo= barcode.LotNo;
                }
 
                //保存到数据库
                var _db = Business.Biz.Db;
                var dbTran = db.UseTran(() =>
                {
                    //入库
                    _db.Insertable(list, UserCode).ExecuteCommand();
                });
                if (!dbTran.IsSuccess)
                {
                    Logger.Default.Fatal(dbTran.ErrorException, "Database transaction save exception");
                    throw dbTran.ErrorException;
                }
 
                SugarParameter[] pars = Biz.Db.Ado.GetParameters(new { ERR_CODE = 0, ERR_MSG = "" });
                pars[0].Direction = System.Data.ParameterDirection.Output;
                pars[1].Direction = System.Data.ParameterDirection.Output;
                var codeList = Biz.Db.Ado.UseStoredProcedure().SqlQuery<mes_MaterialBarCodeByBin>("SP_WMS_IMPORT_ITEM", pars);//返回List
                if (pars[0].Value.ToInt32() == 0)
                {
                    Logger.Scheduler.Info($"同步条码入库,总数:[{list.Count}]");
                    action.Message = $"同步条码入库,总数:[{list.Count}]";
                }
                else
                {
                    Logger.Scheduler.Error(pars[1].Value.ToString());
                }
            }
            catch (Exception ex)
            {
                action.CatchExceptionWithLog(ex, Biz.L(ex.Message));
            }
            return action;
        }
    }
}