| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- using Business.Core.Utilities;
- using Business.Dto;
- using Business.StructuredDB.WMS;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using Volo.Abp.Application.Services;
- using Volo.Abp.DependencyInjection;
- using Volo.Abp.Domain.Repositories;
- using Volo.Abp.MultiTenancy;
- using Volo.Abp.Uow;
- using IUnitOfWorkManager = Volo.Abp.Uow.IUnitOfWorkManager;
- namespace Business.DOP
- {
- //DOP
- public class SyncDOPAppService : ApplicationService, ISyncDOPAppService, ITransientDependency
- {
- #region 服务
- /// <summary>
- /// 平台规格型号对照表
- /// </summary>
- private readonly IRepository<WMS_PlatformSpecificationComparison, long> _PlatformSpecificationComparison;
- /// <summary>
- /// 平台库存表
- /// </summary>
- private readonly IRepository<WMS_PlatformInventory, long> _PlatformInventory;
- /// <summary>
- /// 雪花算法
- /// </summary>
- SnowFlake snowFlake = new SnowFlake();
- /// <summary>
- /// 事务
- /// </summary>
- private readonly IUnitOfWorkManager _unitOfWorkManager;
- #endregion
- #region 构造函数
- /// <summary>
- /// 构造函数
- /// </summary>
- public SyncDOPAppService(
- IRepository<WMS_PlatformSpecificationComparison, long> PlatformSpecificationComparison,
- IRepository<WMS_PlatformInventory, long> PlatformInventory,
- IUnitOfWorkManager unitOfWorkManager,
- ICurrentTenant currentTenant
- )
- {
- _PlatformSpecificationComparison = PlatformSpecificationComparison;
- _PlatformInventory = PlatformInventory;
- _unitOfWorkManager = unitOfWorkManager;
- }
- #endregion
- /// <summary>
- /// 海王平台成品监控
- /// </summary>
- /// <returns></returns>
- /// <exception cref="NotImplementedException"></exception>
- public async Task<string> SyncPlatformFinishedProductMonitoringHW(List<PlatformInventoryDto> platformInventoryDtoList)
- {
- var ret = SavePlatformFinishedProductMonitoringAsync(platformInventoryDtoList, 1);
- return await ret;
- }
- /// <summary>
- /// 国科平台成品监控
- /// </summary>
- /// <returns></returns>
- /// <exception cref="NotImplementedException"></exception>
- public async Task<string> SyncPlatformFinishedProductMonitoringGK(List<PlatformInventoryDto> platformInventoryDtoList)
- {
- var ret = SavePlatformFinishedProductMonitoringAsync(platformInventoryDtoList, 2);
- return await ret;
- }
- /// <summary>
- /// 保存库存信息
- /// </summary>
- /// <param name="platformInventoryDtoList"></param>
- /// <param name="type">1海王,2国科</param>
- public async Task<string> SavePlatformFinishedProductMonitoringAsync(List<PlatformInventoryDto> platformInventoryDtoList, int type)
- {
- if (platformInventoryDtoList.Count == 0)
- {
- return JsonConvert.SerializeObject("成品库存为空!");
- }
- List<WMS_PlatformInventory> platformInventoryInsert = new List<WMS_PlatformInventory>();
- List<WMS_PlatformInventory> platformInventoryDel;
- if (type == 1)
- {
- platformInventoryDel = _PlatformInventory.GetListAsync(x => x.Code == "HW0001").Result;
- }
- else
- {
- platformInventoryDel = _PlatformInventory.GetListAsync(x => x.Code == "HW0002").Result;
- }
- foreach (var item in platformInventoryDtoList)
- {
- WMS_PlatformInventory platformInventory = new WMS_PlatformInventory();
- platformInventory.GenerateNewId(snowFlake.NextId());
- platformInventory.Location = item.Location;
- platformInventory.SpecificationModel = item.SpecificationModel;
- platformInventory.BatchNumber = item.BatchNumber;
- platformInventory.InventoryQuantity = item.InventoryQuantity.GetValueOrDefault();
- platformInventory.PeriodOfValidity = item.PeriodOfValidity.GetValueOrDefault();
- if (type == 1)
- {
- platformInventory.Code = "HW0001";
- }
- else
- {
- platformInventory.Code = "HW0002";
- }
- platformInventoryInsert.Add(platformInventory);
- }
- using (var unitOfWork = _unitOfWorkManager.Begin(false, true))
- {
- try
- {
- //先删后插
- await _PlatformInventory.DeleteManyAsync(platformInventoryDel);
- await _PlatformInventory.InsertManyAsync(platformInventoryInsert);
- await unitOfWork.CompleteAsync();
- }
- catch (Exception e)
- {
- new NLogHelper("SyncDOPAppService").WriteLog("PlatformFinishedProductMonitoringAsyncMerge", "接口异常:" + e.Message);
- unitOfWork.Dispose();
- return JsonConvert.SerializeObject(e.Message);
- }
- }
- return JsonConvert.SerializeObject("ok");
- }
- }
- }
|