增加同步物料接口

This commit is contained in:
18942506660
2024-11-20 10:32:52 +08:00
parent 338c69f2cf
commit 488c5dbe1e
8 changed files with 220 additions and 2 deletions

View File

@@ -0,0 +1,122 @@
using AutoMapper;
using WMS.Web.Core.Dto.Erp;
using WMS.Web.Core.Help;
using WMS.Web.Core.Internal.Results;
using WMS.Web.Domain.Entitys;
using WMS.Web.Domain.Infrastructure;
using WMS.Web.Domain.IService.Public;
using WMS.Web.Domain.Options;
using WMS.Web.Domain.Services;
using WMS.Web.Domain.Services.Public;
using WMS.Web.Domain.Values;
using WMS.Web.Repositories;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Microsoft.Extensions.Logging;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Linq;
namespace WMS.Web.Api.Controllers
{
/// <summary>
/// 物料
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class MaterialController : ControllerBase
{
private IMapper _mapper;
private ILogger<MaterialController> _logger;
private IErpService _erpService;
private IMaterialsRepositories _materialsRepositories;
private ErpOptions _erpOptions;
private readonly IMemoryCache _memoryCache;
public MaterialController(IMapper mapper, ILogger<MaterialController> logger, IErpService erpService,
IMaterialsRepositories materialsRepositories, IOptions<ErpOptions> erpOptions, IMemoryCache memoryCache)
{
_mapper = mapper;
_logger = logger;
_erpService = erpService;
_materialsRepositories = materialsRepositories;
this._erpOptions = erpOptions.Value;
this._memoryCache = memoryCache;
}
/// <summary>
/// 刷新物料 69条码或物料编码 名字
/// </summary>
/// <param name="number">物料编码</param>
/// <param name="type">69 条码,other 名字和规格型号</param>
/// <returns></returns>
[HttpGet]
[Route("Refresh/{number}/{type}")]
public async Task<Result> Refresh([FromRoute] string number, [FromRoute] string type)
{
if (string.IsNullOrEmpty(number))
return Result.ReFailure("物料编码不能为空", 556677);
if (string.IsNullOrEmpty(type) || (!type.Equals("69") && !type.Equals("other")))
return Result.ReFailure("类型只能是69或other", 556677);
List<string> numbers = new List<string>();
numbers.Add(number);
var list = await _materialsRepositories.GetEntityList(numbers);
if (list.Count() <= 0) return Result.ReFailure(ResultCodes.MateriaNoData);
var mDtos = await _erpService.BillQueryForMaterialByNumbers(numbers);
if (!mDtos.IsSuccess) return Result.ReFailure(mDtos.Message, mDtos.Status);
if (mDtos.Data.Count() <= 0) return Result.ReFailure(ResultCodes.MateriaNoData);
var materials = _memoryCache.Get<List<ErpMaterialDto>>(_erpOptions.cache_materail_key);
List<Materials> update_list = new List<Materials>();
foreach (var m in mDtos.Data)
{
var entity = list.FirstOrDefault(f => f.MaterialNumber.Equals(m.MaterialNumber));
if (entity == null) continue;
if (type.Equals("69"))
{
entity.BarCode = m.BarCode.Trim();
update_list.Add(entity);
}
//if (type.Equals("id"))
//{
// entity.IdConvertBar = m.IdConvertBar.Trim();
// update_list.Add(entity);
//}
if (type.Equals("other"))
{
entity.MaterialName = m.MaterialName;
entity.Specifications = m.Specifications;
update_list.Add(entity);
}
//修改缓存
if (materials == null) continue;
var entity_cache = materials.FirstOrDefault(f => f.MaterialNumber.Equals(m.MaterialNumber));
if (entity_cache == null) continue;
if (type.Equals("69"))
entity_cache.BarCode = m.BarCode.Trim();
//if (type.Equals("id"))
// entity_cache.IdConvertBar = m.IdConvertBar.Trim();
if (type.Equals("other"))
{
entity_cache.MaterialName = m.MaterialName;
entity_cache.Specifications = m.Specifications;
}
}
//修改缓存
if (materials != null && materials.Count() > 0)
{
_memoryCache.Set(_erpOptions.cache_materail_key, materials, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(DateTimeUtil.GetTotalMinutesTimeSpan())));
}
await _materialsRepositories.UpdateRange(update_list);
return Result.ReSuccess();
}
}
}

View File

@@ -6269,6 +6269,14 @@
</summary>
<returns></returns>
</member>
<member name="M:WMS.Web.Domain.Services.Public.ErpService.BillQueryForMaterialByNumbers(System.Collections.Generic.List{System.String})">
<summary>
获取物料id32进制
</summary>
<param name="materialNumbers"></param>
<returns></returns>
<exception cref="T:System.NotImplementedException"></exception>
</member>
<member name="M:WMS.Web.Domain.Services.Public.ErpService.BillQueryForMaterialById(System.Int32)">
<summary>
erp:基础数据-物料-ids查询