服务端的TigerApi 框架,基于.NET6 2024 版本
Cloud Zhang
2024-05-16 1858d33ed2b1f5013eb2153b32070e0ae6b547f8
Tiger.Business/MES/SMT/Biz.SmtTool.cs
@@ -13,6 +13,8 @@
using static Tiger.Business.Biz;
using Microsoft.AspNetCore.Http;
using System.Collections;
using System.Data;
using Sundial;
namespace Tiger.Business
{
@@ -55,6 +57,138 @@
                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.原因 += "工单号空或不存在!";
                                }
                                if (item.产品编码 == null)
                                {
                                    item.处理方式 = "数据异常";
                                    item.原因 += $"产品编码为空!";
                                }
                                currentList.Add(item);
                                if (await Db.Queryable<SMT_WO_TABLE>().AnyAsync(x => x.WORK_ORDER == item.关联工单号))
                                {
                                    item.处理方式 = "修改";
                                    item.原因 += $"工单{item.关联工单号}与数据库重复!";
                                }
                            }
                            //for (int i = 0; i < item..Count; i++)
                            {
                            }
                        }
                    }
                    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;
            }
        }
    }
}