服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-05-30 1ae7b5a517aaa0f3a45f0b31b0c5173c35558318
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
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 static Tiger.Business.Biz;
using Microsoft.AspNetCore.Http;
using System.Collections;
using System.Data;
using Sundial;
 
namespace Tiger.Business.MES
{
    /// <summary>
    /// 工具管理
    /// </summary>
    public partial class SmtTool : ISmtTool
    {
        /// <summary>
        /// 获取未上料列表
        /// </summary>
        /// <param name="paras"></param>
        /// <returns></returns>
        public async Task<ApiAction<List<SMT_WO_TABLE>>> GetNotLoadingMaterial(SmtLoadingInput paras)
        {
            var res = new ApiAction<List<SMT_WO_TABLE>>();
            List<SMT_WO_TABLE> sList = new List<SMT_WO_TABLE>();
            try
            {
                sList = Db.Queryable<SMT_WO_TABLE, SMT_LOADING>((t, l) =>
                                        new JoinQueryInfos(
                                            JoinType.Left,
                                            t.WORK_ORDER == l.WORK_ORDER
                                            && t.PROD_CODE == l.PROD_CODE
                                            && t.PCB_SURFACE == l.PCB_SURFACE
                                            && t.LINE_CODE == l.LINE_CODE
                                            && t.SLOT_NO == l.SLOT_NO
                                        ))
                             .Where((t, l) => SqlFunc.IsNullOrEmpty(l.WORK_ORDER) && t.WORK_ORDER == paras.moCode && t.PROD_CODE == paras.prodCode && t.LINE_CODE == paras.lineCode && t.PCB_SURFACE == paras.pcbSurface)
                             .WhereIF(SqlFunc.IsNullOrEmpty(paras.machineCode), (t, l) => t.SMT_CODE == paras.machineCode)
                             .Select((t, l) => t)
                             .ToList();
            }
            catch (Exception ex)
            {
                res.CatchExceptionWithLog(ex, "查询异常");
            }
            res.Data = sList;
            return await Task.FromResult(res);
        }
        /// <summary>
        /// 导入工单料站表
        /// </summary>
        /// <param name="paras"></param>
        /// <returns></returns>
        public async Task<ApiAction<List<smtWoTableIn>>> ValidateTableImport(List<smtWoTableIn> paras)
        {
            var result = new ApiAction<List<smtWoTableIn>>();
            try
            {
 
                //DataTable dt = JsonConvert.DeserializeObject<DataTable>(paras.ToString());
                List<smtWoTableIn> currentList = new List<smtWoTableIn>();
                if (paras?.Count > 0)
                {
                    //var duplicateWo = paras.GroupBy(p => p.关联工单号)
                    //                 .Where(g => g.Count() > 1)
                    //                 .Select(g => g.Key)
                    //                 .ToList();
                    //if (duplicateWo.Count() > 0)//存在重复数据  
                    //{
                    //    string WORK_ORDER = string.Empty;
                    //    foreach (var item in duplicateWo)
                    //    {
                    //        WORK_ORDER += item;
                    //    }
                    //    WORK_ORDER = WORK_ORDER.TrimEnd(';');
                    //    result.IsSuccessed = false;
                    //    result.Message = $"导入的物料中有重复数据:关联工单:{WORK_ORDER}";
                    //}
                    //else
                    {
                        foreach (var item in paras)
                        {
                            item.处理方式 = "新增";
                            item.原因 = null;
                            if (item.关联工单号 == null || item.关联工单号 == " ")
                            {
                                item.处理方式 = "数据异常";
                                item.原因 += "工单号空或不存在!";
                            }
                            if (item.产品编码 == null || item.产品编码 == " ")
                            {
                                item.处理方式 = "数据异常";
                                item.原因 += $"产品编码为空!";
                            }
                            if (item.物料编码 == null || item.物料编码 == " ")
                            {
                                item.处理方式 = "数据异常";
                                item.原因 += $"物料编码为空!";
                            }
                            if (item.站位号 == null || item.站位号 == " ")
                            {
                                item.处理方式 = "数据异常";
                                item.原因 += $"站位号为空!";
                            }
                            currentList.Add(item);
                            if (await Db.Queryable<SMT_WO_TABLE>().AnyAsync(x => x.WORK_ORDER == item.关联工单号 && x.ITEM_CODE == item.物料编码 && x.SLOT_NO == item.站位号 && x.SMT_CODE == item.贴片机编码))
                            {
                                item.处理方式 = "修改";
                                item.原因 += $"工单{item.关联工单号},物料编码{item.物料编码},站位号{item.站位号},贴片机编码{item.贴片机编码}与数据库重复!";
                            }
                        }
                        //for (int i = 0; i < item..Count; i++)
                        {
                        }
 
                    }
                }
                else
                {
                    result.IsSuccessed = false;
                    result.Message = $"导入的物料不能为空";
                }
                result.Data = currentList;
 
            }
            catch (Exception ex)
            {
                result.CatchException(ex, $"验证导入工单料站表异常");
            }
            return result;
        }
        /// <summary>
        /// 导入工单料站表
        /// </summary>
        /// <param name="paras"></param>
        /// <returns></returns>
        public async Task<ApiAction> SaveValidateTableImport(List<smtWoTableIn> paras)
        {
            var result = new ApiAction();
            try
            {
 
                //DataTable dt = JsonConvert.DeserializeObject<DataTable>(paras.ToString());
                List<SMT_WO_TABLE> currentList = new List<SMT_WO_TABLE>();
                if (paras.Count > 0)
                {
                    var db = Biz.Db;
                    foreach (var item in paras)
                    {
                        var workorder = item.关联工单号.ToString();
                        var id = db.Queryable<SMT_WO_TABLE>().Where(s => s.WORK_ORDER == workorder).Select(q => q.ID).First();
                        SMT_WO_TABLE table = new SMT_WO_TABLE();
                        table.ID = item.处理方式?.ToString() == "新增" ? Guid.NewGuid().ToString() : id;
                        table.CREATE_TIME = DateTime.Now;
                        table.UPDATE_TIME = DateTime.Now;
                        table.WORK_ORDER = item.关联工单号.ToString();
                        table.PROD_CODE = item.产品编码?.ToString();
                        table.ITEM_CODE = item.物料编码?.ToString();
                        table.SUBITEM_CODE = item.替代料?.ToString();
                        table.UNIT = item.单位?.ToString();
                        table.UNIT_QTY = item.单位用量.ToInt32();
                        table.LINE_CODE = item.产线编码?.ToString();
                        table.SMT_CODE = item.贴片机编码?.ToString();
                        table.SMT_STENCIL = item.钢网编码?.ToString();
                        table.SLOT_NO = item.站位号?.ToString();
                        table.LOCATION = item.贴片位置?.ToString();
                        table.FEEDER_CODE = item.飞达编码?.ToString();
                        table.FEEDER_TYPE = item.飞达类型?.ToString();
                        table.PCB_SURFACE = item.加工面?.ToString();
                        table.LOAD_SEQ = item.上料顺序.ToInt32();
                        table.REMARK = item.备注?.ToString();
                        table.VALIDATION_TYPE = item.处理方式?.ToString();
                        table.VALIDATION_RESULT = item.原因?.ToString();
                        currentList.Add(table);
                    }
                    var add = currentList.Where(q => q.VALIDATION_TYPE == "新增").ToList();
                    var upd = currentList.Where(q => q.VALIDATION_TYPE == "修改").ToList();
                    if (add.Count > 0)
                    {
                        Biz.Db.Insertable(add).ExecuteCommand();
                    }
                    if (upd.Count > 0)
                    {
                        Biz.Db.Updateable(upd).ExecuteCommand();
                    }
 
                }
 
            }
            catch (Exception ex)
            {
                result.CatchException(ex, $"验证导入工单料站表异常");
            }
            return result;
        }
    }
}