自动对账接口修改

usertest
cjy 5 months ago
parent 66bbf80822
commit de366049c7

@ -51,7 +51,7 @@ public class CheckBillAutoController : ApiController
var res = _invokeService.GetCheckBillAutoDetailList(request); var res = _invokeService.GetCheckBillAutoDetailList(request);
return res; return res;
} }
/// <summary> /// <summary>
/// 编辑 /// 编辑
/// </summary> /// </summary>
@ -75,8 +75,8 @@ public class CheckBillAutoController : ApiController
{ {
var res = _invokeService.GetCheckBillAutoInfo(id); var res = _invokeService.GetCheckBillAutoInfo(id);
return res; return res;
} }
/// <summary> /// <summary>
/// 导入对账excel /// 导入对账excel
@ -116,16 +116,78 @@ public class CheckBillAutoController : ApiController
//将内存流转成List集合 //将内存流转成List集合
var list = await stream.QueryAsync<CheckBillAutoExcelReq>(); var list = await stream.QueryAsync<CheckBillAutoExcelReq>();
var res = await _invokeService.CreateCheckBillAutoByExcel(id,list.ToList()); var res = await _invokeService.CreateCheckBillAutoByExcel(id, list.ToList());
return await Task.FromResult(res); return await Task.FromResult(res);
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
throw new Exception(ex.ToString()); throw new Exception(ex.ToString());
} }
} }
} /// <summary>
/// 对账明细批量删除
/// </summary>
/// <param name="req">主表Id及明细业务Ids</param>
/// <returns></returns>
[HttpPost]
[Route("BatchDelCheckBillAutoDetail")]
public DataResult BatchDelCheckBillAutoDetail([FromBody] IdModel req)
{
var res = _invokeService.BatchDelCheckBillAutoDetail(req);
return res;
}
/// <summary>
/// 自动对账批量删除
/// </summary>
/// <param name="req">主表Ids</param>
/// <returns></returns>
[HttpPost]
[Route("BatchDelCheckBillAuto")]
public DataResult BatchDelCheckBillAuto([FromBody] IdModel req)
{
var res = _invokeService.BatchDelCheckBillAuto(req);
return res;
}
/// <summary>
/// 自动对账重新匹配
/// </summary>
/// <param name="req">主表Id</param>
/// <returns></returns>
[HttpPost]
[Route("RecountCheckBillAuto")]
public DataResult RecountCheckBillAuto([FromBody] IdModel req)
{
var res = _invokeService.RecountCheckBillAuto(req);
return res;
}
/// <summary>
/// 生成对账单
/// </summary>
/// <param name="req">主表Id</param>
/// <returns></returns>
[HttpPost]
[Route("CreateCheckBill")]
public async Task<DataResult> CreateCheckBill([FromBody] IdModel req)
{
var res = await _invokeService.CreateCheckBill(req);
return res;
}
/// <summary>
/// 取消生成的对账单
/// </summary>
/// <param name="req">主表Id</param>
/// <returns></returns>
[HttpPost]
[Route("CancelCheckBill")]
public async Task<DataResult> CancelCheckBill([FromBody] IdModel req)
{
var res = await _invokeService.CancelCheckBill(req);
return res;
}
}

@ -62,5 +62,24 @@ namespace DS.WMS.Core.Check.Interface
/// <param name="req">主表Ids</param> /// <param name="req">主表Ids</param>
/// <returns></returns> /// <returns></returns>
public DataResult BatchDelCheckBillAuto(IdModel req); public DataResult BatchDelCheckBillAuto(IdModel req);
/// <summary>
/// 自动对账重新匹配
/// </summary>
/// <param name="req">主表Id</param>
/// <returns></returns>
public DataResult RecountCheckBillAuto(IdModel req);
/// <summary>
/// 生成对账单
/// </summary>
/// <param name="req">主表Id</param>
/// <returns></returns>
public Task<DataResult> CreateCheckBill(IdModel req);
/// <summary>
/// 取消生成的对账单
/// </summary>
/// <param name="req">主表Id</param>
/// <returns></returns>
public Task<DataResult> CancelCheckBill(IdModel req);
} }
} }

@ -23,6 +23,8 @@ using Quartz.Logging;
using DS.Module.Core.Data; using DS.Module.Core.Data;
using System.Collections; using System.Collections;
using LanguageExt.ClassInstances.Pred; using LanguageExt.ClassInstances.Pred;
using DS.WMS.Core.Fee.Dtos;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
namespace DS.WMS.Core.Check.Method namespace DS.WMS.Core.Check.Method
{ {
@ -279,7 +281,7 @@ namespace DS.WMS.Core.Check.Method
if (req.Ids.Length == 0) if (req.Ids.Length == 0)
return DataResult.Failed("明细业务Ids不能为空"); return DataResult.Failed("明细业务Ids不能为空");
var businessList = tenantDb.Queryable<CheckBillAutoDetail>().Where(x => x.CheckId == checkId && req.Ids.Contains(x.Id)).ToList(); var businessList = tenantDb.Queryable<CheckBillAutoDetail>().Where(x => x.CheckId == checkId && req.Ids.Contains(x.Id)).ToList();
@ -288,7 +290,7 @@ namespace DS.WMS.Core.Check.Method
var details = tenantDb.Queryable<CheckBillAutoDetail>().Where(x => x.CheckId == checkId && !req.Ids.Contains(x.Id)).ToList(); var details = tenantDb.Queryable<CheckBillAutoDetail>().Where(x => x.CheckId == checkId && !req.Ids.Contains(x.Id)).ToList();
if (details.Count > 0) if (details.Count > 0)
{ {
if (details.Where(x => x.IsEqual == false).Any()) if (details.Where(x => x.IsEqual == false).Any())
{ {
@ -346,8 +348,8 @@ namespace DS.WMS.Core.Check.Method
if (req.Id.IsNull()) if (req.Id.IsNull())
return DataResult.Failed("业务Id不能为空"); return DataResult.Failed("业务Id不能为空");
var info = tenantDb.Queryable<CheckBillAuto>().Where(x => x.Id ==long.Parse(req.Id)).First(); var info = tenantDb.Queryable<CheckBillAuto>().Where(x => x.Id == long.Parse(req.Id)).First();
if (info.IsNotNull()) if (info.IsNotNull())
{ {
if (info.BillNo.IsNotNull()) if (info.BillNo.IsNotNull())
@ -403,7 +405,8 @@ namespace DS.WMS.Core.Check.Method
} }
tenantDb.Updateable(info).ExecuteCommand(); tenantDb.Updateable(info).ExecuteCommand();
} }
else { else
{
return DataResult.Failed("自动对账主表信息不存在"); return DataResult.Failed("自动对账主表信息不存在");
} }
@ -417,26 +420,41 @@ namespace DS.WMS.Core.Check.Method
/// </summary> /// </summary>
/// <param name="req">主表Id</param> /// <param name="req">主表Id</param>
/// <returns></returns> /// <returns></returns>
public DataResult CreateCheckBill(IdModel req) public async Task<DataResult> CreateCheckBill(IdModel req)
{ {
var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (req.Id.IsNull()) if (req.Id.IsNull())
return DataResult.Failed("业务Id不能为空"); return await Task.FromResult(DataResult.Failed("业务Id不能为空"));
var info = tenantDb.Queryable<CheckBillAuto>().Where(x => x.Id == long.Parse(req.Id)).First(); var info = await tenantDb.Queryable<CheckBillAuto>().Where(x => x.Id == long.Parse(req.Id)).FirstAsync();
if (info.IsNull()) if (info.IsNull())
return DataResult.Failed("自动对账主表信息不存在"); return await Task.FromResult(DataResult.Failed("自动对账主表信息不存在"));
if (info.BillNo.IsNotNull()) if (info.BillNo.IsNotNull())
return DataResult.Failed("对账信息已生成!"); return await Task.FromResult(DataResult.Failed("对账信息已生成!"));
var list = await tenantDb.Queryable<CheckBillAutoDetail>().Where(x => x.CheckId == long.Parse(req.Id) && x.IsEqual == true).ToListAsync();
if (list.Count == 0)
return await Task.FromResult(DataResult.Failed("自动对账明细无一致的明细!"));
await tenantDb.Ado.BeginTranAsync();
var list = tenantDb.Queryable<CheckBillAutoDetail>().Where(x => x.CheckId == long.Parse(req.Id)).ToList(); try
{
var data = info.Adapt<CheckBill>();
var sequence = commonService.GetSequenceNext<CheckBill>();
if (!sequence.Succeeded)
{
return await Task.FromResult(DataResult.Failed(sequence.Message, MultiLanguageConst.SequenceSetNotExist));
}
data.BillNo = sequence.Data;
var entity = await tenantDb.Insertable(data).ExecuteReturnEntityAsync();
var businessList = new List<CheckBillBusiness>();
var feeList = new List<CheckBillFeeRecords>();
foreach (var bill in list) foreach (var bill in list)
{ {
var mblno = bill.MBLNO; var mblno = bill.MBLNO;
var usdAmount = 0M;
var rmbAmount = 0M;
var bizList = tenantDb.Queryable<VW_Op_Business>().Where(x => x.MBLNO.Contains(mblno)).ToList(); var bizList = tenantDb.Queryable<VW_Op_Business>().Where(x => x.MBLNO.Contains(mblno)).ToList();
var mblnos = bizList.Select(x => x.MBLNO).Distinct(); var mblnos = bizList.Select(x => x.MBLNO).Distinct();
foreach (var temp in mblnos) foreach (var temp in mblnos)
@ -446,31 +464,104 @@ namespace DS.WMS.Core.Check.Method
//var mainBiz = bizlist1[0]; //var mainBiz = bizlist1[0];
foreach (var biz in bizlist1) foreach (var biz in bizlist1)
{ {
var feeList = tenantDb.Queryable<FeeRecord>().Where(x => x.BusinessId == biz.BusinessId && x.CustomerId == info.CustomerId && x.FeeType == FeeType.Payable).ToList(); var feeRecordList = tenantDb.Queryable<FeeRecord>().Where(x => x.BusinessId == biz.BusinessId && x.CustomerId == info.CustomerId && x.FeeType == FeeType.Payable).ToList();
foreach (var record in feeList) if (feeRecordList.Count > 0)
{ {
if (record.Currency == "RMB") businessList.Add(new CheckBillBusiness()
{ {
rmbAmount += record.Amount; CheckId = entity.Id,
} BusinessId = biz.BusinessId
if (record.Currency == "USD") });
foreach (var record in feeRecordList)
{ {
usdAmount += record.Amount; feeList.Add(new CheckBillFeeRecords()
{
CheckId = entity.Id,
BusinessId = biz.BusinessId,
FeeRecordId = record.Id,
CheckBillAmount = record.Amount,
});
//对账标识
record.IsDebit = true;
record.DebitNo = entity.Id.ToString();
} }
//更新费用记录
await tenantDb.Updateable(feeRecordList).ExecuteCommandAsync();
} }
} }
} }
bill.RMBLocalAmount = rmbAmount;
bill.USDLocalAmount = usdAmount; }
bill.RMBDifferenceAmount = rmbAmount - bill.RMBCheckAmount; if (businessList.Count > 0)
bill.USDDifferenceAmount = usdAmount - bill.USDCheckAmount; {
bill.IsEqual = (rmbAmount - bill.RMBCheckAmount == 0 && usdAmount - bill.USDCheckAmount == 0) ? true : false; await tenantDb.Insertable(businessList).ExecuteCommandAsync();
if (feeList.Count > 0)
{
await tenantDb.Insertable(feeList).ExecuteCommandAsync();
}
} }
tenantDb.Updateable(list).ExecuteCommand(); ; info.BillNo = sequence.Data;
await tenantDb.Updateable(info).ExecuteCommandAsync();
return DataResult.Successed("重新匹配成功!", MultiLanguageConst.DataUpdateSuccess);
await tenantDb.Ado.CommitTranAsync();
return await Task.FromResult(DataResult.Successed("生成对账单成功!", MultiLanguageConst.DataUpdateSuccess));
}
catch (Exception ex)
{
await tenantDb.Ado.RollbackTranAsync();
//await ex.LogAsync(tenantDb);
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
}
}
/// <summary>
/// 取消生成的对账单
/// </summary>
/// <param name="req">主表Id</param>
/// <returns></returns>
public async Task<DataResult> CancelCheckBill(IdModel req)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (req.Id.IsNull())
return await Task.FromResult(DataResult.Failed("业务Id不能为空"));
var info = await tenantDb.Queryable<CheckBillAuto>().Where(x => x.Id == long.Parse(req.Id)).FirstAsync();
if (info.IsNull())
return await Task.FromResult(DataResult.Failed("自动对账主表信息不存在"));
if (info.BillNo.IsNull())
return await Task.FromResult(DataResult.Failed("对账信息未生成!"));
var bill = await tenantDb.Queryable<CheckBill>().Where(x => x.BillNo == info.BillNo).FirstAsync();
if (bill.IsNull())
return await Task.FromResult(DataResult.Failed("对账信息不存在!"));
if ((bool)bill.IsLocking)
return await Task.FromResult(DataResult.Failed("对账信息已锁定!"));
await tenantDb.Ado.BeginTranAsync();
try
{
var billlist = await tenantDb.Queryable<CheckBillBusiness>().Where(x => x.CheckId == bill.Id).ToListAsync();
var feelist = await tenantDb.Queryable<CheckBillFeeRecords>().Where(x => x.CheckId == bill.Id).ToListAsync();
await tenantDb.Deleteable(feelist).ExecuteCommandAsync();
await tenantDb.Deleteable(billlist).ExecuteCommandAsync();
await tenantDb.Deleteable(bill).ExecuteCommandAsync();
info.BillNo = "";
await tenantDb.Updateable(info).ExecuteCommandAsync();
await tenantDb.Ado.CommitTranAsync();
return await Task.FromResult(DataResult.Successed("取消对账单成功!", MultiLanguageConst.DataUpdateSuccess));
}
catch (Exception ex)
{
await tenantDb.Ado.RollbackTranAsync();
//await ex.LogAsync(tenantDb);
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
}
} }
} }
} }

Loading…
Cancel
Save