服务端的TigerApi 框架,基于.NET6 2024 版本
Ben Lin
2024-09-11 b3f75becd8305056d8ec3b3b732143c387b397e7
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
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.Entitys.MES.BizMesWoBatch;
using Tiger.Model.Entitys.MES.BizMesWo;
using Tiger.Model.Entitys.MES.BizBasPkgRule;
 
namespace Tiger.Business.MES
{
    public partial class BizBasRule : IBasRule
    {
        /// <summary>
        /// 保存物料条码规则
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<ApiAction> SaveBasItemRule(BizBasItemRuleInput input)
        {
            var result = new ApiAction();
            try
            {
                var ItemCusts = input.ItemCusts.Select(q => q.ID).ToList();
                List<BAS_ITEM_CUST> list = await Biz.Db.Queryable<BAS_ITEM_CUST>().Where(q => !SqlFunc.ContainsArray(ItemCusts, q.ID)).ToListAsync();
                var db = Biz.Db;
                var dbTran = db.UseTran(() =>
                {
                    var z = db.Storageable(input.ItemCusts)
                       .WhereColumns(t => new { t.ID, t.GHOST_ROW })
                       .ToStorage();
                    z.AsInsertable.ExecuteCommand();
                    z.AsUpdateable.ExecuteCommand();
 
                    db.Deleteable(list).ExecuteCommand();
                });
                if (!dbTran.IsSuccess)
                {
                    result.IsSuccessed = false;
                    result.Message = $"保存物料条码规则异常";
                }
            }
            catch (Exception ex)
            {
                result.CatchExceptionWithLog(ex, "保存物料条码规则异常");
            }
            return result;
        }
 
        /// <summary>
        /// 保存包装规则,包括明细和重量范围
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<ApiAction> SaveBasPkgRule(BizBasPkgRuleInput input)
        {
            var result = new ApiAction();
            try
            {
                var pkgProds = input.PkgProd.Select(q => q.ID).ToList();
                List<BAS_PKG_PROD> listPrd = await Biz.Db.Queryable<BAS_PKG_PROD>().Where(q => !SqlFunc.ContainsArray(pkgProds, q.ID)).ToListAsync();
                var db = Biz.Db;
                var dbTran = db.UseTran(() =>
                {
                    //if (input.PkgRule!=null)
                    //{
                    //    var y = db.Storageable(input.PkgRule)
                    //       .WhereColumns(t => new { t.ID, t.GHOST_ROW })
                    //       .ToStorage();
                    //    y.AsInsertable.ExecuteCommand();
                    //    y.AsUpdateable.ExecuteCommand();
                    //}
 
                    var z = db.Storageable(input.PkgDtl)
                       .WhereColumns(t => new { t.ID, t.GHOST_ROW })
                       .ToStorage();
                    z.AsInsertable.ExecuteCommand();
                    z.AsUpdateable.ExecuteCommand();
 
                    var o = db.Storageable(input.PkgProd)
                       .WhereColumns(t => new { t.ID, t.GHOST_ROW })
                       .ToStorage();
                    o.AsInsertable.ExecuteCommand();
                    o.AsUpdateable.ExecuteCommand();
 
                    db.Deleteable(listPrd).ExecuteCommand();
                });
                if (!dbTran.IsSuccess)
                {
                    result.IsSuccessed = false;
                    result.Message = $"保存包装规则异常";
                }
            }
            catch (Exception ex)
            {
                result.CatchExceptionWithLog(ex, "保存包装规则异常");
            }
            return result;
        }
    }
}