diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_CAN_SA_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_CAN_SA_SERVICE.cs index d1665eaa..56bb96dc 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_CAN_SA_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_CAN_SA_SERVICE.cs @@ -146,28 +146,42 @@ namespace Win.Sfs.SettleAccount.Entities.BQ [UnitOfWork(false)] public virtual async Task BackCanSettlement([FromBody] string selttleBilNum) { + if (selttleBilNum.Substring(0, 1) == "N") { List notList = new List(); - var entites = _repository.Where(p => p.BillNum == selttleBilNum).ToList(); - var main = _repository.Where(p => p.BillNum == selttleBilNum).ToList(); - foreach (var itm in entites) + var entites = _detailRepository.Where(p => p.BillNum == selttleBilNum).ToList(); + var main = _repository.FirstOrDefault(p => p.BillNum == selttleBilNum); + + if (main.State != SettleBillState.未结状态) + { + throw new UserFriendlyException("当前状态不是未结状态无法退回!", "400"); + } + if (entites.Count == 0) { - var detail = new BBAC_NOT_SA_DETAIL(); - detail.InjectFrom(itm); - notList.Add(detail); + throw new UserFriendlyException("当前表单明细无数据无法退回!", "400"); } - var dbcontext = await _repository.GetDbContextAsync().ConfigureAwait(false); - await dbcontext.BulkDeleteAsync(main).ConfigureAwait(false); - await dbcontext.BulkDeleteAsync(entites).ConfigureAwait(false); - await dbcontext.BulkInsertAsync(notList).ConfigureAwait(false); - return new JsonResult(new { Code = 200, Message = "退回成功" }); + main.State = SettleBillState.可结退回不可结同步中; + await _repository.UpdateAsync(main).ConfigureAwait(false); + List customConditionList = new List(); + customConditionList.Add(new CustomCondition() { Name = "BillNum", Value = selttleBilNum }); + customConditionList.Add(new CustomCondition() { Name = "BussinessType", Value = main.BusinessType.ToString() }); + var _taskid = await _service.ExportEnqueueAsync("可结退回不可结", ExportExtentsion.Excel, string.Empty, string.Empty, CurrentUser, typeof(ReturnCanSettlement), customConditionList, (rs) => + { + }).ConfigureAwait(false); + + } else { throw new UserFriendlyException("单据不是从不可结算单生成", "400"); } + + return new JsonResult(new { Code = 200, Message = "开始退回" }); + + + } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_CAN_SA_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_CAN_SA_SERVICE.cs index cfddb79c..077d6028 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_CAN_SA_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_CAN_SA_SERVICE.cs @@ -201,24 +201,53 @@ namespace Win.Sfs.SettleAccount.Entities.BQ if (selttleBilNum.Substring(0, 1) == "N") { List notList = new List(); - var entites = _repository.Where(p => p.BillNum == selttleBilNum).ToList(); - var main = _repository.Where(p => p.BillNum == selttleBilNum).ToList(); - foreach (var itm in entites) + var entites = _detailRepository.Where(p => p.BillNum == selttleBilNum).ToList(); + var main = _repository.FirstOrDefault(p => p.BillNum == selttleBilNum); + + + + + + if (main.State != SettleBillState.未结状态) + { + throw new UserFriendlyException("当前状态不是未结状态无法退回!", "400"); + } + if (entites.Count == 0) { - var detail = new HBPO_NOT_SA_DETAIL(); - detail.InjectFrom(itm); - notList.Add(detail); + throw new UserFriendlyException("当前表单明细无数据无法退回!", "400"); } - var dbcontext = await _repository.GetDbContextAsync().ConfigureAwait(false); - await dbcontext.BulkDeleteAsync(main).ConfigureAwait(false); - await dbcontext.BulkDeleteAsync(entites).ConfigureAwait(false); - await dbcontext.BulkInsertAsync(notList).ConfigureAwait(false); - return new JsonResult(new { Code = 200, Message = "退回成功" }); + main.State = SettleBillState.可结退回不可结同步中; + await _repository.UpdateAsync(main).ConfigureAwait(false); + + List customConditionList = new List(); + customConditionList.Add(new CustomCondition() { Name = "BillNum", Value = selttleBilNum }); + customConditionList.Add(new CustomCondition() { Name = "BussinessType", Value = main.BusinessType.ToString() }); + var _taskid = await _service.ExportEnqueueAsync("可结退回不可结", ExportExtentsion.Excel, string.Empty, string.Empty, CurrentUser, typeof(ReturnCanSettlement), customConditionList, (rs) => + { + }).ConfigureAwait(false); + + //foreach (var itm in entites) + //{ + // var detail = new HBPO_NOT_SA_DETAIL(); + // detail.InjectFrom(itm); + // detail.SetId(detail.Id); + // foreach (var extra in itm.ExtraProperties) + // { + // detail.ExtraProperties.Add(extra.Key, extra.Value); + // } + // notList.Add(detail); + //} + //var dbcontext = await _repository.GetDbContextAsync().ConfigureAwait(false); + //await dbcontext.BulkDeleteAsync(new List() { main }).ConfigureAwait(false); + //await dbcontext.BulkDeleteAsync(entites).ConfigureAwait(false); + //await dbcontext.BulkInsertAsync(notList).ConfigureAwait(false); + //return new JsonResult(new { Code = 200, Message = "退回成功" }); } else { throw new UserFriendlyException("单据不是从不可结算单生成", "400"); } + return new JsonResult(new { Code = 200, Message = "退回开始!" }); } } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_CAN_SA_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_CAN_SA_SERVICE.cs index e01b7aa1..633d0f81 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_CAN_SA_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_CAN_SA_SERVICE.cs @@ -258,16 +258,28 @@ namespace Win.Sfs.SettleAccount.Entities.BQ if (selttleBilNum.Substring(0, 1) == "N") { List notList = new List(); - var entites = _repository.Where(p => p.BillNum == selttleBilNum).ToList(); - var main = _repository.Where(p => p.BillNum == selttleBilNum).ToList(); + var entites = _detailRepository.Where(p => p.BillNum == selttleBilNum).ToList(); + var main = _repository.FirstOrDefault(p => p.BillNum == selttleBilNum); + + if (main.State != SettleBillState.未结状态) + { + throw new UserFriendlyException("当前状态不是未结状态无法退回!", "400"); + } + foreach (var itm in entites) { var detail = new PUB_NOT_SA_DETAIL(); detail.InjectFrom(itm); + detail.SetId(itm.Id); + foreach (var extra in itm.ExtraProperties) + { + detail.ExtraProperties.Add(extra.Key, extra.Value); + } + notList.Add(detail); } var dbcontext = await _repository.GetDbContextAsync().ConfigureAwait(false); - await dbcontext.BulkDeleteAsync(main).ConfigureAwait(false); + await dbcontext.BulkDeleteAsync(new List() { main }).ConfigureAwait(false); await dbcontext.BulkDeleteAsync(entites).ConfigureAwait(false); await dbcontext.BulkInsertAsync(notList).ConfigureAwait(false); return new JsonResult(new { Code = 200, Message = "退回成功" }); diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/ReturnCanSettlement.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/ReturnCanSettlement.cs new file mode 100644 index 00000000..c9dc776d --- /dev/null +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/ReturnCanSettlement.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using EFCore.BulkExtensions; +using Omu.ValueInjecter; +using SettleAccount.Bases; +using SettleAccount.Domain.BQ; +using TaskJob.EventArgs; +using TaskJob.Interfaces; +using Volo.Abp; +using Volo.Abp.Application.Services; +using Volo.Abp.DependencyInjection; + +namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs +{ + public class ReturnCanSettlement : ApplicationService, ITransientDependency, IExportJob + { + protected readonly SettleAccountDbContext _dbcontext; + public ReturnCanSettlement(SettleAccountDbContext dbcontext) + { + _dbcontext = dbcontext; + } + public string ExportFile(Guid id, List exportName, List property) + { + var billNum = property.Where(p => p.Name == "BillNum").FirstOrDefault().Value; + var BussinessType = property.Where(p => p.Name == "BussinessType").FirstOrDefault().Value; + + if (BussinessType == "JisBBAC") + { + var entites = _dbcontext.Set().Where(p => p.BillNum == billNum).ToList(); + var main = _dbcontext.Set().FirstOrDefault(p => p.BillNum == billNum); + Execute(main, entites); + + } + if (BussinessType == "JisHBPO") + { + var entites = _dbcontext.Set().Where(p => p.BillNum == billNum).ToList(); + var main = _dbcontext.Set().FirstOrDefault(p => p.BillNum == billNum); + Execute(main, entites); + + } + + + + return id.ToString(); + } + + public void Execute(TMain p_main,List p_detailList) where TMain : SA_CAN_BASE_MAIN, new() + where TDetail : SA_CAN_BASE, new() + { + + List notList = new List(); + var entites = p_detailList; + var main = p_main; + + + foreach (var itm in entites) + { + var detail = new TDetail(); + detail.InjectFrom(itm); + detail.SetId(detail.Id); + foreach (var extra in itm.ExtraProperties) + { + detail.ExtraProperties.Add(extra.Key, extra.Value); + } + notList.Add(detail); + } + + _dbcontext.BulkDelete(new List() { main }); + _dbcontext.BulkDelete(entites); + _dbcontext.BulkInsert(notList); + } + + + } +} diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationModule.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationModule.cs index 4c4931a7..53843ed2 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationModule.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationModule.cs @@ -114,6 +114,12 @@ namespace Win.Sfs.SettleAccount { return implementationFactory.GetService(); } + if (key.Equals(typeof(ReturnCanSettlement).FullName)) + { + return implementationFactory.GetService(); + } + + else { throw new ArgumentException($"Not Support key:{key}"); diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Bases/EntityBase.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Bases/EntityBase.cs index fc27d430..a1f22694 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Bases/EntityBase.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Bases/EntityBase.cs @@ -462,6 +462,10 @@ namespace SettleAccount.Bases public string RealPartCode { get; set; } public string Site { get; set; } + public virtual void SetId(Guid guid) + { + Id = guid; + } //public SA_CAN_BASE(int version, decimal price, string billNum, DateTime settleDate, string invGroupNum, string lU, string pN, string keyCode, decimal qty, string groupNum) //{ @@ -542,6 +546,14 @@ namespace SettleAccount.Bases public string ErpLoc { get; set; } + + + + public virtual void SetId(Guid guid) + { + Id = guid; + } + //public SA_NOT_BASE(decimal price, int version, string settleBillNum, DateTime settleDate, string invGroupNum, string lU, string pN, string keyCode, decimal qty, string groupNum) //{ // Price = price; diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/BBAC_NOT_SA_DETAIL.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/BBAC_NOT_SA_DETAIL.cs index 166c79ce..f9f706ea 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/BBAC_NOT_SA_DETAIL.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/BBAC_NOT_SA_DETAIL.cs @@ -90,6 +90,7 @@ namespace SettleAccount.Domain.BQ { } + public BBAC_NOT_SA_DETAIL(Guid guid, string keyCode, int version, string settleBillNum, string lU, string pN, string site, decimal qty, decimal price, EnumBusinessType category, bool isReturn, string invGroupNum, DateTime settleDate, string groupNum, string contractDocID, string partcode) { diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/HBPO_NOT_SA_DETAIL.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/HBPO_NOT_SA_DETAIL.cs index 3c27c4c2..7a1ad9bb 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/HBPO_NOT_SA_DETAIL.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/HBPO_NOT_SA_DETAIL.cs @@ -111,7 +111,7 @@ namespace SettleAccount.Domain.BQ BusinessType = businessType; PartCode = partcode; } - + public HBPO_NOT_SA_DETAIL() { } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/PUB_NOT_SA_DETAIL.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/PUB_NOT_SA_DETAIL.cs index 457763c4..6912dd60 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/PUB_NOT_SA_DETAIL.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/PUB_NOT_SA_DETAIL.cs @@ -74,7 +74,7 @@ namespace SettleAccount.Domain.BQ /// [Display(Name = "计数")] public int IndexNum { get; set; } - + public PUB_NOT_SA_DETAIL(string keyCode, int version, string settleBillNum, string lU, string pN, string site, decimal qty, string extend1, string extend2, string extend3, decimal price, string invGroupNum, DateTime settleDate, EnumBusinessType businessType, string groupNum, string partcode, string pobillnum) { KeyCode = keyCode; @@ -95,7 +95,7 @@ namespace SettleAccount.Domain.BQ PartCode = partcode; PoBillNum = pobillnum; } - + public PUB_NOT_SA_DETAIL() { } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/EnumBillState.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/EnumBillState.cs index fe91be69..b587eaa4 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/EnumBillState.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/EnumBillState.cs @@ -39,6 +39,11 @@ namespace Win.Sfs.SettleAccount 扣减单生成中 = 11, [Description("发票同步中")] 发票同步中 = 12, + [Description("可结退回不可结同步中")] + 可结退回不可结同步中 = 13, + + + }