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.Minsun; namespace Tiger.Business.MES { public partial class U9C_MES : IU9C_MES { /// /// 从U9C拉取物料数据 /// /// /// public async Task GetBasItem(GetBasItemInput input) { var action = new ApiAction(); Logger.Scheduler.Info(Biz.L($"物料信息开始同步。。。数据检查进行中。。。")); Logger.Scheduler.Info(Biz.L($"{input.triggerDetail}")); DbClient db = Biz.DataSource["YadaU9C"].Client; var list = db.Queryable().AS("mes_ItemMaster").Where("ModifiedOn > @startTime And ModifiedOn < @endTime", new { startTime = input.startTime, endTime = input.endTime }).ToList(); List items = new(); foreach (var item in list) { var d = item as System.Dynamic.ExpandoObject; var di = d as IDictionary; di = di?.ToDictionary(x => x.Key, x => x.Value); if (di != null) { BAS_ITEM basItem = new() { ID = di["ID"].ToString(), ITEM_CODE = di["Code"] == null ? "" : di["Code"].ToString(), ITEM_NAME = di["Name"] == null ? "" : di["Name"].ToString(), ITEM_DESC = di["Description"] == null ?"":di["Description"].ToString(), SPEC = di["SPECS"] == null ? "" : di["SPECS"].ToString(), ITEM_TYPE = di["CategoryCode"] == null ? "" : di["CategoryCode"].ToString(), UNIT = di["InventorySecondUOM"] == null ? "" : di["InventorySecondUOM"].ToString(), PROD_TYPE = di["ProductTypeCode"] == null ? "" : di["ProductTypeCode"].ToString(), CREATE_TIME = di["CreatedOn"].ToDateTime(), UPDATE_TIME = di["ModifiedOn"].ToDateTime(), IS_ACTIVE = "Y", IS_PROD = ((string)di["Code"]).StartsWith("2") ? "Y" : "N", }; items.Add(basItem); } } Logger.Scheduler.Info(Biz.L($"物料信息存入实体中,总数:[{items.Count}]")); db = Biz.Db; var LastRun = db.Queryable().Where(q => q.PRMG_CODE == "Interface_LastRun" && q.PARAM_CODE == "GetItem_LastRun").Single(); LastRun.PARAM_VALUE = input.endTime; var dbTran = db.UseTran(() => { db.Storageable(LastRun, "U9C_MES_GetItem").ExecuteCommand(); if (items.Any()) { if (items.Count > 150) { db.Utilities.PageEach(items, 1000, pageList => { var y = db.Storageable(pageList, "U9C") .WhereColumns(t => new { t.ITEM_CODE, t.GHOST_ROW }) .ToStorage(); y.BulkCopy(); y.BulkUpdate(); }); } else { var s = db.Storageable(items, "U9C") .WhereColumns(t => new { t.ITEM_CODE, t.GHOST_ROW }) .ToStorage(); s.AsInsertable.ExecuteCommand(); s.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand(); } } }); if (!dbTran.IsSuccess) { action.CatchExceptionWithLog(dbTran.ErrorException, $"数据处理失败"); Logger.Scheduler.Error(action.Message); } Logger.Scheduler.Info(Biz.L($"物料信息存入数据库,总数:[{items.Count}]")); return action; } /// /// 获取工单信息 /// /// /// public async Task GetBasWo(GetWoInput input) { var action = new ApiAction(); Logger.Scheduler.Info(Biz.L($"工单信息开始同步。。。数据检查进行中。。。")); Logger.Scheduler.Info(Biz.L($"{input.triggerDetail}")); DbClient db = Biz.DataSource["YadaU9C"].Client; var list = db.Queryable().AS("mes_Mo").Where("ModifiedOn > @startTime And ModifiedOn < @endTime", new { startTime = input.startTime, endTime = input.endTime }).ToList(); List items = new(); foreach (var item in list) { var d = item as System.Dynamic.ExpandoObject; var di = d as IDictionary; di = di?.ToDictionary(x => x.Key, x => x.Value); if (di != null) { BIZ_MES_WO woItem = new() { ID = di["ID"].ToString(), ORDER_NO = di["DocNo"] == null ? "" : di["DocNo"].ToString(), ORDER_TYPE = di["DocTypeCode"] == null ? "" : di["DocTypeCode"].ToString(), PLAN_QTY = di["ProductQty"] == null ? 0 : di["ProductQty"].ToInt32(), CUST_CODE = di["CustomerCode"] == null ? "" : di["CustomerCode"].ToString(), CREATE_TIME = di["CreatedOn"].ToDateTime(), UPDATE_TIME = di["ModifiedOn"].ToDateTime(), PLAN_START_TIME = di["CheckDate"].ToDateTime(), STATUS = 0, }; items.Add(woItem); } } Logger.Scheduler.Info(Biz.L($"工单信息存入实体中,总数:[{items.Count}]")); db = Biz.Db; var LastRun = db.Queryable().Where(q => q.PRMG_CODE == "Interface_LastRun" && q.PARAM_CODE == "GetWo_LastRun").Single(); LastRun.PARAM_VALUE = input.endTime; var dbTran = db.UseTran(() => { db.Storageable(LastRun, "U9C_MES_GetWo").ExecuteCommand(); if (items.Any()) { if (items.Count > 150) { db.Utilities.PageEach(items, 1000, pageList => { var y = db.Storageable(pageList, "U9C") .WhereColumns(t => new { t.ORDER_NO, t.GHOST_ROW }) .ToStorage(); y.BulkCopy(); y.BulkUpdate(); }); } else { var s = db.Storageable(items, "U9C") .WhereColumns(t => new { t.ORDER_NO, t.GHOST_ROW }) .ToStorage(); s.AsInsertable.ExecuteCommand(); s.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand(); } } }); if (!dbTran.IsSuccess) { action.CatchExceptionWithLog(dbTran.ErrorException, $"数据处理失败"); Logger.Scheduler.Error(action.Message); } Logger.Scheduler.Info(Biz.L($"工单信息存入数据库,总数:[{items.Count}]")); return action; } public Task GetCustomer(GetCustomerInput input) { throw new NotImplementedException(); } public Task GetSupplier(GetSupplierInput input) { throw new NotImplementedException(); } } }