You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.7 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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;
}
/// <summary>
/// 向物料数据库中动态同步mes数据没有就插入不同就修改
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
public async Task<bool> InsertNewMaterialData(List<MaterialRecordListItem> 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;
}
}
}
}