mahao 1 year ago
parent
commit
ff8473d5f6
  1. 185
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs

185
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs

@ -30,7 +30,6 @@ using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
using Volo.Abp.BlobStoring; using Volo.Abp.BlobStoring;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Uow;
using Volo.Abp.Users; using Volo.Abp.Users;
using Volo.Abp.Validation; using Volo.Abp.Validation;
using Win.Sfs.BaseData.ImportExcelCommon; using Win.Sfs.BaseData.ImportExcelCommon;
@ -49,7 +48,7 @@ public interface IVmiService : IApplicationService, ITransientDependency, IJobSe
Task Out(VmiLogType logType, string changedNumber, VmiLog data); Task Out(VmiLogType logType, string changedNumber, VmiLog data);
Task UnDo(string groupId); //Task UnDo(string groupId);
} }
[AllowAnonymous] [AllowAnonymous]
@ -139,7 +138,7 @@ public class VmiAppService : ApplicationService, IVmiService, IJobService, ITran
{ {
//this._hubContext.Clients.All.ServerToClient("JobItem", "refresh", ""); //this._hubContext.Clients.All.ServerToClient("JobItem", "refresh", "");
Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/files/vmi")); Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/files/vmi"));
var date = DateTime.Now.ToString("yyyyMMddHHmmss"); var date = DateTime.Now.ToString("yyyy-MM-dd_HH.mm.ss");
var connectionString = $"Data Source=wwwroot/files/vmi/{date}.db"; var connectionString = $"Data Source=wwwroot/files/vmi/{date}.db";
using var dbContext = new VmiSqliteContext(connectionString); using var dbContext = new VmiSqliteContext(connectionString);
if (!dbContext.GetService<IRelationalDatabaseCreator>().Exists() && dbContext.Database.EnsureCreated()) if (!dbContext.GetService<IRelationalDatabaseCreator>().Exists() && dbContext.Database.EnsureCreated())
@ -361,41 +360,41 @@ public class VmiAppService : ApplicationService, IVmiService, IJobService, ITran
}).ConfigureAwait(false); }).ConfigureAwait(false);
} }
/// <summary> ///// <summary>
/// 库存事务回滚 ///// 库存事务回滚
/// </summary> ///// </summary>
[NonAction] //[NonAction]
[UnitOfWork] //[UnitOfWork]
public async Task UnDo(string groupId) //public async Task UnDo(string groupId)
{ //{
var logList = this._logRepository.Where(o => o.GroupId == groupId).AsNoTracking().OrderBy(o => o.ChangedTime); // var logList = this._logRepository.Where(o => o.GroupId == groupId).AsNoTracking().OrderBy(o => o.ChangedTime);
foreach (var item in logList) // foreach (var item in logList)
{ // {
var balance = this._balanceRepository.FirstOrDefault(o => o.BillType == item.BillType && // var balance = this._balanceRepository.FirstOrDefault(o => o.BillType == item.BillType &&
o.PartCode == item.PartCode && // o.PartCode == item.PartCode &&
o.VinCode == item.VinCode && // o.VinCode == item.VinCode &&
o.ErpToLoc == item.ErpToLoc && // o.ErpToLoc == item.ErpToLoc &&
o.OrderNum == item.OrderNum); // o.OrderNum == item.OrderNum);
if (balance == null) // if (balance == null)
{ // {
balance = new VmiBalance(GuidGenerator.Create()); // balance = new VmiBalance(GuidGenerator.Create());
balance.InjectFrom(item); // balance.InjectFrom(item);
await _balanceRepository.InsertAsync(balance).ConfigureAwait(false); // await _balanceRepository.InsertAsync(balance).ConfigureAwait(false);
} // }
else // else
{ // {
balance.Qty += item.ChangedQty; // balance.Qty += item.ChangedQty;
this._balanceRepository.UpdateAsync(balance).Wait(); // this._balanceRepository.UpdateAsync(balance).Wait();
} // }
var log = new VmiLog(); // var log = new VmiLog();
log.InjectFrom(item); // log.InjectFrom(item);
log.LogType = VmiLogType.Type300; // log.LogType = VmiLogType.Type300;
log.ChangedType = VmiType.In; // log.ChangedType = VmiType.In;
log.ChangedTime = DateTime.Now; // log.ChangedTime = DateTime.Now;
log.ChangedBy = _currentUser.UserName; // log.ChangedBy = _currentUser.UserName;
await _logRepository.InsertAsync(log).ConfigureAwait(false); // await _logRepository.InsertAsync(log).ConfigureAwait(false);
} // }
} //}
/// <summary> /// <summary>
/// 库存余额查询 /// 库存余额查询
@ -520,6 +519,26 @@ public class VmiAppService : ApplicationService, IVmiService, IJobService, ITran
return fileName; return fileName;
} }
/// <summary>
/// 人工调整
/// </summary>
/// <param name="log"></param>
/// <returns></returns>
[HttpPost]
public async Task EditBalance(VmiLog log)
{
if (log.Qty >= decimal.Zero)
{
var data = new VmiBalance();
data.InjectFrom(log);
await In(VmiLogType.Type500, null, data).ConfigureAwait(false);
}
else
{
await this.Out(VmiLogType.Type600, null, log).ConfigureAwait(false);
}
}
private byte[] GetContent<TExport>(List<TExport> entities, string name = "sheet1") private byte[] GetContent<TExport>(List<TExport> entities, string name = "sheet1")
{ {
using var workbook = new XLWorkbook(); using var workbook = new XLWorkbook();
@ -590,51 +609,51 @@ public class VmiAppService : ApplicationService, IVmiService, IJobService, ITran
} }
} }
private void SetPropertyValue(PropertyInfo property, VmiLog entity, string value) //private void SetPropertyValue(PropertyInfo property, VmiLog entity, string value)
{ //{
try // try
{ // {
object propertyValue = null; // object propertyValue = null;
if (!string.IsNullOrEmpty(value)) // if (!string.IsNullOrEmpty(value))
{ // {
propertyValue = Convert.ChangeType(value, property.PropertyType); // propertyValue = Convert.ChangeType(value, property.PropertyType);
} // }
property.SetValue(entity, propertyValue, null); // property.SetValue(entity, propertyValue, null);
} // }
catch (Exception) // catch (Exception)
{ // {
throw; // throw;
} // }
} //}
private string GetOperator(EnumFilterAction action) //private string GetOperator(EnumFilterAction action)
{ //{
var dictonary = new Dictionary<EnumFilterAction, string>() { // var dictonary = new Dictionary<EnumFilterAction, string>() {
{EnumFilterAction.Equal,"={0}"}, // {EnumFilterAction.Equal,"={0}"},
{EnumFilterAction.NotEqual,"!={0}"}, // {EnumFilterAction.NotEqual,"!={0}"},
{EnumFilterAction.SmallThanOrEqual,"<={0}"}, // {EnumFilterAction.SmallThanOrEqual,"<={0}"},
{EnumFilterAction.Like,"~/{0}/"}, // {EnumFilterAction.Like,"~/{0}/"},
{EnumFilterAction.NotLike,"!~/{0}/"}, // {EnumFilterAction.NotLike,"!~/{0}/"},
{EnumFilterAction.BiggerThan,">{0}"}, // {EnumFilterAction.BiggerThan,">{0}"},
{EnumFilterAction.BiggerThanOrEqual,">={0}"}, // {EnumFilterAction.BiggerThanOrEqual,">={0}"},
{EnumFilterAction.SmallThan,"<{0}"}, // {EnumFilterAction.SmallThan,"<{0}"},
}; // };
return dictonary[action]; // return dictonary[action];
} //}
private object GetValue(PropertyInfo property, string value) //private object GetValue(PropertyInfo property, string value)
{ //{
if (property.PropertyType == typeof(int) || // if (property.PropertyType == typeof(int) ||
property.PropertyType == typeof(long) || // property.PropertyType == typeof(long) ||
property.PropertyType == typeof(float) || // property.PropertyType == typeof(float) ||
property.PropertyType == typeof(double) || // property.PropertyType == typeof(double) ||
property.PropertyType == typeof(decimal) || // property.PropertyType == typeof(decimal) ||
property.PropertyType == typeof(bool)) // property.PropertyType == typeof(bool))
{ // {
return value; // return value;
} // }
return $"'{value}'"; // return $"'{value}'";
} //}
} }
public class BackupListRequest : RequestDto public class BackupListRequest : RequestDto

Loading…
Cancel
Save