wanggang
1 year ago
9 changed files with 377 additions and 203 deletions
@ -0,0 +1,137 @@ |
|||
//库存扣减
|
|||
import { version, state3 } from "../_options.js"; |
|||
|
|||
const schema = { |
|||
title: "寄售库库存扣减审批", |
|||
type: "object", |
|||
properties: { |
|||
version, |
|||
state: state3, |
|||
billNum: { |
|||
title: "发票号", |
|||
type: "string", |
|||
link: true, |
|||
}, |
|||
settleBillNum: { |
|||
title: "关联结算单号", |
|||
type: "string", |
|||
}, |
|||
invGroupNum: { |
|||
title: "发票分组号", |
|||
type: "string", |
|||
link: true, |
|||
}, |
|||
site: { |
|||
title: "地点", |
|||
type: "string", |
|||
}, |
|||
}, |
|||
}; |
|||
|
|||
export default function (businessType) { |
|||
let service; |
|||
if (businessType === "JisBBAC") { |
|||
service = "b-bAC_PD_SERVICE"; |
|||
} else if (businessType === "JisHBPO") { |
|||
service = "h-bPO_PD_SERVICE"; |
|||
} else { |
|||
service = "p-uB_PD_SERVICE"; |
|||
} |
|||
|
|||
const queryUrl = `settleaccount/${service}/detail-query`; |
|||
const queryMethod = "POST"; |
|||
|
|||
return { |
|||
query: { |
|||
url: queryUrl, |
|||
method: queryMethod, |
|||
hasFilter: true, |
|||
schema: { |
|||
title: "不可结算单", |
|||
type: "object", |
|||
properties: { |
|||
filters: { |
|||
title: "项目", |
|||
type: "array", |
|||
hidden: true, |
|||
items: { |
|||
type: "object", |
|||
properties: { |
|||
logic: { |
|||
type: "int", |
|||
}, |
|||
column: { |
|||
type: "string", |
|||
}, |
|||
action: { |
|||
type: "int", |
|||
}, |
|||
value: { |
|||
type: "string", |
|||
}, |
|||
}, |
|||
}, |
|||
default: [ |
|||
{ |
|||
logic: "and", |
|||
column: "version", |
|||
action: "equal", |
|||
value: null, |
|||
readOnly: true, |
|||
}, |
|||
{ |
|||
logic: "and", |
|||
column: "billNum", |
|||
action: "equal", |
|||
value: null, |
|||
readOnly: true, |
|||
}, |
|||
{ |
|||
logic: "and", |
|||
column: "settleBillNum", |
|||
action: "equal", |
|||
value: null, |
|||
readOnly: true, |
|||
}, |
|||
{ |
|||
logic: "and", |
|||
column: "invGroupNum", |
|||
action: "equal", |
|||
value: null, |
|||
readOnly: true, |
|||
}, |
|||
{ |
|||
logic: "and", |
|||
column: "state", |
|||
action: "equal", |
|||
value: null, |
|||
readOnly: true, |
|||
}, |
|||
], |
|||
}, |
|||
skipCount: { |
|||
hidden: true, |
|||
default: 0, |
|||
}, |
|||
maxResultCount: { |
|||
hidden: true, |
|||
default: 10, |
|||
}, |
|||
sorting: { |
|||
hidden: true, |
|||
}, |
|||
businessType: { |
|||
hidden: true, |
|||
default: 0, |
|||
}, |
|||
}, |
|||
}, |
|||
}, |
|||
table: { |
|||
schema: schema, |
|||
}, |
|||
edit: { |
|||
schema: schema, |
|||
}, |
|||
}; |
|||
} |
@ -0,0 +1,106 @@ |
|||
using System; |
|||
using System.Linq; |
|||
using System.Linq.Dynamic.Core; |
|||
using System.Text.Json; |
|||
using System.Threading.Tasks; |
|||
using Magicodes.ExporterAndImporter.Core.Extension; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Omu.ValueInjecter; |
|||
using Volo.Abp.Application.Services; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Win.Sfs.SettleAccount.Entities.BQ.Vmi; |
|||
using Win.Sfs.Shared.RepositoryBase; |
|||
|
|||
namespace Win.Sfs.SettleAccount.Entities.BQ; |
|||
|
|||
/// <summary>
|
|||
/// 异步更新库存
|
|||
/// </summary>
|
|||
public class VmiAsyncBalanceService : ApplicationService, IJobService, ITransientDependency |
|||
{ |
|||
private readonly IServiceProvider _serviceProvider; |
|||
|
|||
public VmiAsyncBalanceService(IServiceProvider serviceProvider) |
|||
{ |
|||
this._serviceProvider = serviceProvider; |
|||
} |
|||
|
|||
public async Task Invoke(IServiceProvider serviceProvider) |
|||
{ |
|||
using var scope = _serviceProvider.CreateScope(); |
|||
var db = scope.ServiceProvider.GetRequiredService<SettleAccountDbContext>(); |
|||
using var transaction = db.Database.BeginTransaction(); |
|||
try |
|||
{ |
|||
var messages = db.Set<VmiMessage>().Where(o => !o.isConsumed).OrderBy(o => o.Number).ToList(); |
|||
var repo = db.Set<VmiBalance>(); |
|||
foreach (var message in messages) |
|||
{ |
|||
var log = JsonSerializer.Deserialize<VmiLog>(message.Message); |
|||
var balance = db.Set<VmiBalance>().FirstOrDefault( |
|||
o => o.DeliverBillType == log.DeliverBillType && |
|||
o.CodeType == log.CodeType && |
|||
o.DeliverBillType == log.DeliverBillType && |
|||
o.VinCode == log.VinCode && |
|||
o.ErpToLoc == log.ErpToLoc && |
|||
o.OrderNum == log.OrderNum && |
|||
o.factory == log.factory && |
|||
o.Configcode == log.Configcode); |
|||
if (balance == null) |
|||
{ |
|||
balance = new VmiBalance(GuidGenerator.Create()); |
|||
balance.InjectFrom(log); |
|||
await repo.AddAsync(balance).ConfigureAwait(false); |
|||
log.InjectFrom(balance); |
|||
} |
|||
else |
|||
{ |
|||
var logType = log.LogType; |
|||
|
|||
var qty = balance.Qty;// + log.ty
|
|||
if (logType == VmiLogType.Type100) |
|||
{ |
|||
//发运入库,负库存字段需要更新
|
|||
if (balance.Qty < decimal.Zero) |
|||
{ |
|||
balance.InjectFrom(log); |
|||
} |
|||
} |
|||
else if (logType == VmiLogType.Type300) |
|||
{ |
|||
//反结入库,只更新库存
|
|||
} |
|||
else if (logType == VmiLogType.Type500) |
|||
{ |
|||
//调整入库,更新库存和其他字段
|
|||
balance.InjectFrom(log); |
|||
} |
|||
// 更新库存
|
|||
balance.Qty = qty; |
|||
if (balance.Qty == decimal.Zero) |
|||
{ |
|||
//删除0库存
|
|||
repo.Remove(balance); |
|||
} |
|||
if (logType == VmiLogType.Type100 && balance.Qty < decimal.Zero && log.Qty > 0) |
|||
{ |
|||
//更新补货
|
|||
var log2 = db.Set<VmiLog>().FirstOrDefault(o => o.Id == log.Id); |
|||
if (log2 != null) |
|||
{ |
|||
log2.IsReplenished = true; |
|||
} |
|||
} |
|||
} |
|||
message.isConsumed = true; |
|||
} |
|||
transaction.Commit(); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
Console.WriteLine(ex.ToString()); |
|||
transaction.Rollback(); |
|||
throw; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,116 @@ |
|||
using System; |
|||
using System.Linq; |
|||
using System.Linq.Dynamic.Core; |
|||
using System.Threading.Tasks; |
|||
using EFCore.BulkExtensions; |
|||
using Microsoft.AspNetCore.SignalR; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using SettleAccount.Job.SignalR; |
|||
using Volo.Abp.Application.Services; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Win.Sfs.SettleAccount.Entities.BQ.Vmi; |
|||
|
|||
namespace Win.Sfs.SettleAccount.Entities.BQ; |
|||
|
|||
/// <summary>
|
|||
/// 消息表定时清理
|
|||
/// </summary>
|
|||
public class VmiAsyncMessageService : ApplicationService, IJobService, ITransientDependency |
|||
{ |
|||
private readonly IServiceProvider _serviceProvider; |
|||
|
|||
public VmiAsyncMessageService(IServiceProvider serviceProvider) |
|||
{ |
|||
this._serviceProvider = serviceProvider; |
|||
} |
|||
|
|||
public Task Invoke(IServiceProvider serviceProvider) |
|||
{ |
|||
using var scope = _serviceProvider.CreateScope(); |
|||
var db = scope.ServiceProvider.GetRequiredService<SettleAccountDbContext>(); |
|||
db.Set<VmiMessage>().Where(o => o.isConsumed).BatchDelete(); |
|||
var count = db.Set<VmiMessage>().Where(o => !o.isConsumed).Count(); |
|||
scope.ServiceProvider.GetService<IHubContext<PageHub>>().Clients.All.ServerToClient("VmiBalance", count.ToString(), ""); |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 库存事务定时备份
|
|||
/// </summary>
|
|||
public class VmiLogbackupService : ApplicationService, IJobService, ITransientDependency |
|||
{ |
|||
private readonly IServiceProvider _serviceProvider; |
|||
|
|||
public VmiLogbackupService(IServiceProvider serviceProvider) |
|||
{ |
|||
this._serviceProvider = serviceProvider; |
|||
} |
|||
|
|||
public Task Invoke(IServiceProvider serviceProvider) |
|||
{ |
|||
using var scope = _serviceProvider.CreateScope(); |
|||
var db = scope.ServiceProvider.GetRequiredService<SettleAccountDbContext>(); |
|||
using var transaction = db.Database.BeginTransaction(); |
|||
try |
|||
{ |
|||
var task = db.Set<VmiSyncTask>().FirstOrDefault(o => o.Number == "Set_VmiLog"); |
|||
if (task != null) |
|||
{ |
|||
var now = DateTime.Now; |
|||
task.LastUpdate = now; |
|||
var query = db.Set<VmiLog>().Where(o => o.UpdatedTime >= task.LastUpdate && o.UpdatedTime < now); |
|||
foreach (var item in query) |
|||
{ |
|||
//同步到questdb
|
|||
} |
|||
} |
|||
} |
|||
catch |
|||
{ |
|||
transaction.Rollback(); |
|||
throw; |
|||
} |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 库存余额定时备份
|
|||
/// </summary>
|
|||
public class VmiLogBalanceService : ApplicationService, IJobService, ITransientDependency |
|||
{ |
|||
private readonly IServiceProvider _serviceProvider; |
|||
|
|||
public VmiLogBalanceService(IServiceProvider serviceProvider) |
|||
{ |
|||
this._serviceProvider = serviceProvider; |
|||
} |
|||
|
|||
public Task Invoke(IServiceProvider serviceProvider) |
|||
{ |
|||
using var scope = _serviceProvider.CreateScope(); |
|||
var db = scope.ServiceProvider.GetRequiredService<SettleAccountDbContext>(); |
|||
using var transaction = db.Database.BeginTransaction(); |
|||
try |
|||
{ |
|||
var task = db.Set<VmiSyncTask>().FirstOrDefault(o => o.Number == "Set_VmiBalance"); |
|||
if (task != null) |
|||
{ |
|||
var now = DateTime.Now; |
|||
task.LastUpdate = now; |
|||
var query = db.Set<VmiBalance>().Where(o => o.UpdatedTime >= task.LastUpdate && o.UpdatedTime < now); |
|||
foreach (var item in query) |
|||
{ |
|||
//同步到questdb
|
|||
} |
|||
} |
|||
} |
|||
catch |
|||
{ |
|||
transaction.Rollback(); |
|||
throw; |
|||
} |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
Loading…
Reference in new issue