using Admin.Core.Api.PLTBusiness.Entity; using Admin.Core.IService; using Admin.Core.Model; using Admin.Core.Service; using Microsoft.Extensions.Hosting; using RabbitMQ.Client; using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Security.Policy; using System.Text; using System.Text.Json; using System.Threading; using System.Threading.Tasks; namespace Admin.Core.Api.PLTBusiness { public class XlBusiness { private readonly Ixl_materialServices _xl_materialService; public XlBusiness(Ixl_materialServices xl_materialService) { _xl_materialService = xl_materialService; } /// /// 向物料数据库中动态同步mes数据,没有就插入,不同就修改 /// /// /// public async Task InsertNewMaterialData(List list) { try { foreach (var mesMaterial in list) { // Step 3: 在B表中查询是否存在相同ID的记录 var material = await _xl_materialService.SelectXlMaterialById(mesMaterial.id.ToString()); if (material == null) { // Step 4: 如果B表中不存在该物料,插入新物料 await _xl_materialService.xlInsertMaterial( mesMaterial.id.ToString(), mesMaterial.code, mesMaterial.name, mesMaterial.status, Convert.ToDateTime(mesMaterial.createTime)); } else { // Step 5: 如果B表中存在该物料且有更新,更新物料信息 if (material.Material_code != mesMaterial.code || material.Material_name != mesMaterial.name || material.IsEnable != (mesMaterial.status == 1 ? "是" : "否") || material.CreateDateTime != Convert.ToDateTime(mesMaterial.createTime)) { await _xl_materialService.xlUpdateMaterial( mesMaterial.id.ToString(), mesMaterial.code, mesMaterial.name, mesMaterial.status, Convert.ToDateTime(mesMaterial.createTime)); } } } return true; } catch (Exception ex) { throw; } } } }