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;
|
}
|
}
|
}
|