From 4f94c61fb26da822256b181a530061ea8d5f0f00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A6=20=E8=B5=B5?= <89237069@qq.com> Date: Mon, 25 Sep 2023 15:29:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=91=E7=A5=A8=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E9=97=AE=E9=A2=98,=E5=8F=8D=E7=BB=93=E7=AE=97?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Bases/PD_SERVICE.cs | 43 ++++-- .../Entities/BQ/INVOICE_SERVICE.cs | 27 +++- .../BQ/Syncs/PendingDeductionService.cs | 132 ++++++++++-------- .../Entities/BQ/Managers/INV_MNG.cs | 16 +-- 4 files changed, 138 insertions(+), 80 deletions(-) diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/PD_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/PD_SERVICE.cs index 0e7ea5c9..764b10ab 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/PD_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/PD_SERVICE.cs @@ -136,23 +136,50 @@ namespace Win.Sfs.SettleAccount.Bases [UnitOfWork(false)] public virtual async Task ApprovalPassed(List p_list) { - return await InvokePD(p_list, _service, false); + return await InvokePD(p_list, _service); } [HttpPost] [UnitOfWork(false)] public virtual async Task RejectAsync(List p_list) { - return await InvokePD(p_list, _service, true); + return await InvokePD(p_list, _service); } - +/// +/// 调用扣减 +/// +/// +/// +/// +/// +/// protected async Task InvokePD(List p_list, TaskJobService p_service, bool isback=false) { + var invlist=_repository.Where(p=>p_list.Contains(p.BillNum)).ToList(); + var states= invlist.Select(p => p.State).Distinct().ToList(); + if (states.Count > 1) + { + throw new UserFriendlyException($"发票不是同一状态", "400"); + } + var first = invlist.FirstOrDefault();//发票状态 + + if(first.State != SettleBillState.客户已收票 && first.State != SettleBillState.已扣减) + { + throw new UserFriendlyException($"当前发票状态不是【客户已收票】或【已扣减状态】不能进行出库扣减或撤销扣减操作", "400"); + } + if (first.State == SettleBillState.客户已收票) + { + isback = false; + } + if(first.State==SettleBillState.已扣减) + { + isback = true; + } var detailist = _detailRepository.Where(p => p_list.Contains(p.BillNum)).ToList(); - var first=detailist.FirstOrDefault(); + var first1=detailist.FirstOrDefault(); List customConditionList = new List(); customConditionList.Add(new CustomCondition() { Name = "BillNumList", Value = string.Join(",", p_list) }); - customConditionList.Add(new CustomCondition() { Name = "Type", Value =first.BusinessType.ToString() }); + customConditionList.Add(new CustomCondition() { Name = "Type", Value =first1.BusinessType.ToString() }); if (isback == false) { customConditionList.Add(new CustomCondition() { Name = "IsOut", Value = "out" }); @@ -161,7 +188,6 @@ namespace Win.Sfs.SettleAccount.Bases { customConditionList.Add(new CustomCondition() { Name = "IsOut", Value = "in" }); } - var ls = _repository.Where(p => p_list.Contains(p.BillNum)).ToList(); var lst=new List(); if (isback == false) @@ -172,8 +198,6 @@ namespace Win.Sfs.SettleAccount.Bases { lst = ls.Where(p => (p.State == SettleBillState.已提交撤销扣减|| p.State == SettleBillState.客户已收票)).ToList(); } - - if (lst.Count() > 0) { throw new UserFriendlyException("当前状态是已提交状态,不能重复已提交", "400"); @@ -190,8 +214,7 @@ namespace Win.Sfs.SettleAccount.Bases } } await _repository.DbContext.BulkUpdateAsync(ls); - - var _taskid = await p_service.ExportEnqueueAsync($"{first.BusinessType.ToString()}待扣减任务", ExportExtentsion.Excel, DateTime.Now.ToString("yyyyMM"), string.Empty, CurrentUser, typeof(PendingDeductionService), customConditionList, (rs) => + var _taskid = await p_service.ExportEnqueueAsync($"{first1.BusinessType.ToString()}待扣减任务", ExportExtentsion.Excel, DateTime.Now.ToString("yyyyMM"), string.Empty, CurrentUser, typeof(PendingDeductionService), customConditionList, (rs) => { }); diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/INVOICE_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/INVOICE_SERVICE.cs index 789518c7..dc4ba738 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/INVOICE_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/INVOICE_SERVICE.cs @@ -298,8 +298,16 @@ namespace Win.Sfs.SettleAccount.Entities.BQ public virtual async Task DetailQueryAsync(INVOICE_GRP_REQ_DTO input) { INVOICE_GRP_DETAIL_DTO entity = new INVOICE_GRP_DETAIL_DTO(); - input.Filters.Add(new FilterCondition("InvoiceState", "1", EnumFilterAction.Equal, EnumFilterLogic.And)); + + var condition = input.Filters.FirstOrDefault(p => p.Column == "invbillNum"); + if( condition==null ) + { + input.Filters.Add(new FilterCondition("InvoiceState", "1", EnumFilterAction.Equal, EnumFilterLogic.And)); + } var invs = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount).ConfigureAwait(false); + + + var m = await _mRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount).ConfigureAwait(false); var mdtos = ObjectMapper.Map, List>(m); var first = invs.FirstOrDefault(); @@ -552,6 +560,12 @@ namespace Win.Sfs.SettleAccount.Entities.BQ entity.ADJ_DETAIL = adjQuery.ToList().OrderBy(p => p.GroupNum).ThenBy(p => p.LU).ToList(); return entity; } + + + + + + [HttpPost] public virtual async Task ExportAsync(INVOICE_GRP_REQ_DTO input) { @@ -598,8 +612,17 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { IExporter _csv = new CsvExporter(); ExcelExporter _excel = new ExcelExporter(); - // var materialList = await _baseservice.GetMaterialList().ConfigureAwait(false); + // var materialList = await _baseservice.GetMaterialList().ConfigureAwait(false); + + + var condition = input.Filters.FirstOrDefault(p => p.Column == "invbillNum"); + if (condition == null) + { + input.Filters.Add(new FilterCondition("InvoiceState", "1", EnumFilterAction.Equal, EnumFilterLogic.And)); + } + var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, 0, true).ConfigureAwait(false); + var first = entities.FirstOrDefault(); var dtoDetails = ObjectMapper.Map, List>(entities); var invdetail = await DetailQueryAsync(input).ConfigureAwait(false); diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/PendingDeductionService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/PendingDeductionService.cs index dad9013f..cfa7add5 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/PendingDeductionService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/PendingDeductionService.cs @@ -199,97 +199,109 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs } var _first = p_ls.FirstOrDefault(); bool issucess = true; - using (var transaction = _dbcontext.Database.BeginTransaction()) - { - try + using (var transaction = _dbcontext.Database.BeginTransaction()) { - // 执行批量数据操作 - if (ls != null && ls.Count > 0) + try { - var messagelist = new List(); - foreach (var item in ls) + // 执行批量数据操作 + if (ls != null && ls.Count > 0) { - var message = new VmiMessage + var messagelist = new List(); + foreach (var item in ls) { - Message = System.Text.Json.JsonSerializer.Serialize(item), - }; - messagelist.Add(message); - } - _dbcontext.BulkInsert(messagelist); - _dbcontext.BulkInsert(ls, new BulkConfig() { }); - var billList = p_ls.Select(p => p.BillNum).Distinct().ToList(); - var pdList = _dbcontext.Set().Where(p => billList.Contains(p.BillNum)).ToList(); - if (pdList.Count > 0) - { - foreach (var item in pdList) + var message = new VmiMessage + { + Message = System.Text.Json.JsonSerializer.Serialize(item), + }; + messagelist.Add(message); + } + _dbcontext.BulkInsert(messagelist); + _dbcontext.BulkInsert(ls, new BulkConfig() { }); + var billList = p_ls.Select(p => p.BillNum).Distinct().ToList();//同步数据的发票号 + var pdList = _dbcontext.Set().Where(p => billList.Contains(p.BillNum)).ToList();//扣减单内容 + var pdinvList = _dbcontext.Set().Where(p => billList.Contains(p.InvbillNum)).ToList(); + if (pdList.Count > 0) { if (flag == true) { - item.State = SettleBillState.已扣减; + foreach (var item in pdList) + { + item.State = SettleBillState.已扣减; + } + foreach (var item in pdinvList) + { + item.State = SettleBillState.已扣减; + } + _dbcontext.BulkUpdate(pdList); + _dbcontext.BulkUpdate(pdinvList); + } else { - item.State = SettleBillState.客户已收票; + _dbcontext.BulkDelete(pdList); + _dbcontext.BulkDelete(p_ls); } } - _dbcontext.BulkUpdate(pdList); - } - var bbacList = _dbcontext.Set().Where(p => billList.Contains(p.BillNum)).ToList(); - if (bbacList.Count > 0) - { - foreach (var item in bbacList) + var bbacList = _dbcontext.Set().Where(p => billList.Contains(p.BillNum)).ToList(); + var bbacinvList = _dbcontext.Set().Where(p => billList.Contains(p.InvbillNum)).ToList(); + if (bbacList.Count > 0) { if (flag == true) { - item.State = SettleBillState.已扣减; + foreach (var item in bbacList) + { + item.State = SettleBillState.已扣减; + } + foreach (var item in bbacinvList) + { + item.State = SettleBillState.已扣减; + } + _dbcontext.BulkUpdate(bbacList); + _dbcontext.BulkUpdate(bbacinvList); + } else { - item.State = SettleBillState.客户已收票; + _dbcontext.BulkDelete(pdList); + _dbcontext.BulkDelete(p_ls); } } - _dbcontext.BulkUpdate(bbacList); - } - var hbpoList = _dbcontext.Set().Where(p => billList.Contains(p.BillNum)).ToList(); - if (hbpoList.Count > 0) - { - foreach (var item in hbpoList) + var hbpoList = _dbcontext.Set().Where(p => billList.Contains(p.BillNum)).ToList(); + var hbpoinvList = _dbcontext.Set().Where(p => billList.Contains(p.InvbillNum)).ToList();//发票 + if (hbpoList.Count > 0) { if (flag == true) { - item.State = SettleBillState.已扣减; + foreach (var item in bbacList) + { + item.State = SettleBillState.已扣减; + } + foreach (var item in bbacinvList) + { + item.State = SettleBillState.已扣减; + } + _dbcontext.BulkUpdate(bbacList); + _dbcontext.BulkUpdate(bbacinvList); + } else { - item.State = SettleBillState.客户已收票; + _dbcontext.BulkDelete(pdList); + _dbcontext.BulkDelete(p_ls); } } - _dbcontext.BulkUpdate(hbpoList); - } - var invoiceList = _dbcontext.Set().Where(p => billList.Contains(p.InvbillNum)).ToList(); - if (invoiceList.Count > 0) - { - foreach (var item in invoiceList) - { - if (flag == true) - { - item.State = SettleBillState.已扣减; - } - } - _dbcontext.BulkUpdate(invoiceList); } + // _emailSender.SendAsync(e) + // 提交事务 + transaction.Commit(); + } + catch (Exception) + { + issucess = false; + // 回滚事务 + transaction.Rollback(); } - // _emailSender.SendAsync(e) - // 提交事务 - transaction.Commit(); - } - catch (Exception) - { - issucess = false; - // 回滚事务 - transaction.Rollback(); } - } if (issucess ==false) { var billList = p_ls.Select(p => p.BillNum).Distinct().ToList(); diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/INV_MNG.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/INV_MNG.cs index cbae226f..37421fb3 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/INV_MNG.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/INV_MNG.cs @@ -1154,10 +1154,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers invoiceBillState: InvoiceBillState.正常, tax: 0.13m, parent: p_parentInvBillNum, - preTaxDiff: 0, - taxDiff: 0, - clientCode: string.Empty, - realAmt: readAmt + preTaxDiff: 0, + taxDiff: 0, + clientCode: string.Empty, + realAmt: readAmt ); invbill.ClientCode = clientCode; invbill.Site = dtos.FirstOrDefault().Site; @@ -1393,7 +1393,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers state: SettleBillState.已开票, invoiceBillState: InvoiceBillState.正常, tax: 0.13m, - parent: string.Empty, + parent: !string.IsNullOrEmpty(p_parentInvBillNum)?p_parentInvBillNum:string.Empty, preTaxDiff: 0, taxDiff: 0, clientCode: string.Empty, @@ -1963,7 +1963,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers state: SettleBillState.已开票, invoiceBillState: InvoiceBillState.正常, tax: 0.13m, - parent: string.Empty, + parent: !string.IsNullOrEmpty(p_parentInvBillNum) ? p_parentInvBillNum : string.Empty, preTaxDiff: 0, taxDiff: 0, clientCode: string.Empty, @@ -2027,7 +2027,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers { if (!string.IsNullOrEmpty(p_OldInvBillNum)) { - var inv = await GetInvoiceAsync(p_OldInvBillNum).ConfigureAwait(false); + var inv = await GetInvoiceAsync(p_OldInvBillNum).ConfigureAwait(false);//获取旧发票 if (inv == null) { @@ -2283,7 +2283,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers state: SettleBillState.已开票, invoiceBillState: InvoiceBillState.正常, tax: 0.13m, - parent: string.Empty, + parent: !string.IsNullOrEmpty(p_parentInvBillNum) ? p_parentInvBillNum : string.Empty, preTaxDiff: 0, taxDiff: 0, clientCode: string.Empty,