From 043226d19130b7bcd790d1be9e7341cdc88c05fa Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 4 Mar 2022 14:11:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WMS/WmsOutputSumInterfaceAppService.cs | 155 ++++++++++ .../Report/ErpSumOutputDapperRepository.cs | 266 +++++++++++++++++- .../Report/WmsOutputSumDapperRepository.cs | 54 +++- 3 files changed, 459 insertions(+), 16 deletions(-) create mode 100644 src/Modules/SettleAccount/src/SettleAccount.Application/Entities/WMS/WmsOutputSumInterfaceAppService.cs diff --git a/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/WMS/WmsOutputSumInterfaceAppService.cs b/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/WMS/WmsOutputSumInterfaceAppService.cs new file mode 100644 index 00000000..471f4b43 --- /dev/null +++ b/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/WMS/WmsOutputSumInterfaceAppService.cs @@ -0,0 +1,155 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Caching.Distributed; +using AutoMapper; +using System.Linq; +using System.Text; +using Volo.Abp.Guids; +using Volo.Abp.Application.Services; +using Volo.Abp.Caching; + +using Volo.Abp.ObjectMapping; +using Win.Sfs.SettleAccount.ExcelImporter; +using Win.Sfs.Shared.CacheBase; +using Win.Utils; +using Volo.Abp.Application.Dtos; +using Win.Sfs.BaseData.ImportExcelCommon; +using Volo.Abp.Domain.Repositories; +using EFCore.BulkExtensions; +using System.IO; +using Microsoft.EntityFrameworkCore; +using Win.Sfs.SettleAccount.Entities.SettleAccountVersion; +using Win.Sfs.SettleAccount.FISes; +using Win.Sfs.Shared.Enums.SettleAccount; +using Win.Sfs.Shared.Filter; +using Shouldly; +using Magicodes.ExporterAndImporter.Csv; +using Magicodes.ExporterAndImporter.Core; +using Magicodes.ExporterAndImporter.Excel; +using System.Data.Common; +using Volo.Abp.Uow; +using Volo.Abp; +using Win.Abp.Snowflakes; +using Win.Sfs.SettleAccount.CommonManagers; +using Win.Sfs.SettleAccount.ExportReports; +using Win.Sfs.SettleAccount.Constant; +using Win.Sfs.SettleAccount.MaterialRelationships; +using Win.Sfs.SettleAccount.Entities.TaskJobs; +using Magicodes.ExporterAndImporter.Core.Models; + +using TaskJob.Services; +using TaskJob.EventArgs; +using Win.Sfs.SettleAccount.Entities.WMS; +using Win.Sfs.SettleAccount.Entities.Wms; +using Win.Sfs.SettleAccount.Repository; +using WY.NewJit.Extends.PaiGe.WMS; +using System.Text.RegularExpressions; +using Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report; + +namespace Win.Sfs.SettleAccount.Entities.WMS +{ + + + + + [Route("api/settleaccount/WmsOutputSumInterface")] + + public class WmsOutputSumInterfaceAppService :ApplicationService + { + private readonly TaskJobService _service; + private readonly IExcelImportAppService _excelImportService; + private readonly ISettleAccountBranchEfCoreRepository _job; + + private readonly ErpSumOutputDapperRepository _dapper; + + public WmsOutputSumInterfaceAppService( + IExcelImportAppService excelImportService, + ErpSumOutputDapperRepository dapper, + //ISettleAccountBranchEfCoreRepository job, + ISnowflakeIdGenerator snowflakeIdGenerator, + ICommonManager commonManager + + ) + { + _dapper = dapper; + + _excelImportService = excelImportService; + } + + [HttpPost] + [Route("ExcelImport")] + [UnitOfWork(false)] + //[Authorize(SettleAccountPermissions.PriceLists.Create)] + virtual public async Task ImportAsync([FromForm] IFormFileCollection files, string version,string accountDate) + { + ExportImporter _exportImporter = new ExportImporter(); + + var result = await _exportImporter.UploadExcelImport(files, _excelImportService); + var _list = result.Where(p => p.实际出库数量 != 0).ToList(); + + _dapper.InsertWmsSum(_list, version,DateTime.Parse(accountDate)); + + + return ApplicationConsts.SuccessStr; + } + + + + //public async Task GetWmsSum(WmsJitOutPutDetial input) + //{ + // var jobList= _job.Where(p => p.Type == input.Version).ToList(); + + // var _fileList= jobList.Where(p=>p.Name == "准时化结算核对明细" && Regex.Replace(p.FileName, @"^[A-Z]+[0-9]+$", string.Empty)==string.Empty); + + + // List _lst = new List(); + // foreach (var filename in _fileList) + // { + // string fileSavePath = Environment.CurrentDirectory + @"\wwwroot\files\host\my-file-container\" + filename.RealDownFileName; + // ExcelHelper _excelHelper = new ExcelHelper(fileSavePath); + // var _list = _excelHelper.ExcelToList(); + // var _ls1 = _list.Where(p => p.ParentMaterialCode == p.MaterialCode).ToList(); + + // _ls1.GroupBy(p=>new {p.MaterialCode,p. }) + // foreach (var itm in _ls1) + // { + // var _detail = new List(); + // } + + // //var _lsCopy = new List(); + // //foreach (var itm in _list) + // //{ + // // WmsJitOutPutDetial _detail = new WmsJitOutPutDetial( + // // GuidGenerator.Create(), + // // itm.WmsBillNum, + // // itm.KennCode, + // // itm.ChassisNumber, + // // itm.MaterialCode, + // // itm.MaterialDesc, + // // itm.MaterialGroup, + // // string.Empty, + // // string.Empty, + // // 0, + // // string.Empty, + // // string.Empty, + // // input.Version, + // // itm.ParentMaterialCode, + // // itm.BillNum, + // // GuidGenerator.Create() + // // , string.Empty + // // , itm.Qty + // // ); + // // _lsCopy.Add(_detail); + // //} + // //_lst.AddRange(_lsCopy.ToArray()); + // } + //} + + + + } +} diff --git a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/ErpSumOutputDapperRepository.cs b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/ErpSumOutputDapperRepository.cs index f15d0d42..4c44ebca 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/ErpSumOutputDapperRepository.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/ErpSumOutputDapperRepository.cs @@ -10,16 +10,276 @@ using Volo.Abp.EntityFrameworkCore; namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report { + + public class TA_WMS_CTRL + { + public string wms_seq { set; get; } + public string wms_table { set; get; } + public string wms_state { set; get; } + public string SourceBillNum { set; get; } + + public DateTime AccountDate { set; get; } + } + + public class ErpSumOutputDapperRepository: DapperRepository, ITransientDependency { + public ErpSumOutputDapperRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) { } - public virtual async void InsertWmsSum(List p_list) + public virtual List GetTask(string begin,string end) + { + var str = ""; + + if (!string.IsNullOrEmpty(begin)) + { + str += string.Format(" and AccountDate>={0} ", begin); + } + if (!string.IsNullOrEmpty(end)) + { + str += string.Format(" and AccountDate<={0} ", end); + } + + + var sql = "SELECT TOP (1000) [wms_seq]\n" + + " ,[wms_table]\n" + + " ,[wms_table_qty]\n" + + " ,[wms_state]\n" + + " ,[remark]\n" + + " ,[createtime]\n" + + " ,[wms_domin]\n" + + " ,[SourceBillNum]\n" + + " ,[updatetime]\n" + + " ,[wms_uid]\n" + + " ,[JsonString]\n" + + " ,[AccountDate]\n" + + " FROM [TA_WMS_CTRL] WHERE {0}" + + " SourceBillNum LIKE 'S2%' order by createtime desc2"; + + sql= string.Format(sql, str); + var query= DbConnection.Query(sql); + return query.ToList(); + + + + } + public virtual void InsertWmsSum(List p_list,string version,DateTime accountDate) { - - + StringBuilder _buffer = new StringBuilder(); + var billnum ="S" +DateTime.Now.ToString("yyyyMMddhhmmss"); + var taskid = Guid.NewGuid().ToString(); + foreach (var itm in p_list) + { + + // var sql ="INSERT INTO [dbo].[TA_WMS_JSKH]\n" + + //" ([wms_seq]\n" + + //" ,[POSNR]\n" + + //" ,[ZVBELN]\n" + + //" ,[AUART]\n" + + //" ,[VKORG]\n" + + //" ,[SPART]\n" + + //" ,[VTWEG]\n" + + //" ,[KUNNR]\n" + + //" ,[KUNNR2]\n" + + //" ,[AUGRU]\n" + + //" ,[MATNR]\n" + + //" ,[WERKS]\n" + + //" ,[LGORT]\n" + + //" ,[ZPR0]\n" + + //" ,[KWMENG]\n" + + //" ,[ZNOTE1]\n" + + //" ,[ZNOTE2]\n" + + //" ,[ZNOTE3]\n" + + //" ,[ZNOTE4]\n" + + //" ,[ZNOTE5]\n" + + //" ,[STATE]\n" + + //" ,[REMARK])\n" + + //" VALUES\n" + + //" ( '{0}' wms_seq,\n" + + //" '{1}' POSNR, \n" + + //" '{2}' ZVBELN, \n" + + //" '{3}' AUART, \n" + + //" '{4}' VKORG, \n" + + //" '{5}' SPART, \n" + + //" '{6}' VTWEG, \n" + + //" '{7}' KUNNR, \n" + + //" '{8}' KUNNR2, \n" + + //" '{9}' AUGRU, \n" + + //" '{10}' MATNR, \n" + + //" '{11}' WERKS, \n" + + //" '{12}' LGORT, \n" + + //" '{13}' ZPR0, \n" + + //" '{14}' KWMENG, \n" + + //" '{15}' ZNOTE1, \n" + + //" '{16}' ZNOTE2, \n" + + //" '{17}' ZNOTE3, \n" + + //" '{18}' ZNOTE4, \n" + + //" '{19}' ZNOTE5, \n" + + //" {20} STATE, \n" + + //" '{21}' REMARK ) \n"+ + var sql = "INSERT INTO [dbo].[TA_WMS_JSKH]\n" + + " ([wms_seq]\n" + + " ,[POSNR]\n" + + " ,[ZVBELN]\n" + + " ,[AUART]\n" + + " ,[VKORG]\n" + + " ,[SPART]\n" + + " ,[VTWEG]\n" + + " ,[KUNNR]\n" + + " ,[KUNNR2]\n" + + " ,[AUGRU]\n" + + " ,[MATNR]\n" + + " ,[WERKS]\n" + + " ,[LGORT]\n" + + " ,[ZPR0]\n" + + " ,[KWMENG]\n" + + " ,[ZNOTE1]\n" + + " ,[ZNOTE2]\n" + + " ,[ZNOTE3]\n" + + " ,[ZNOTE4]\n" + + " ,[ZNOTE5]\n" + + " ,[STATE]\n" + + " ,[REMARK])\n" + + " VALUES\n" + + " ( '{0}' ,\n" + + " '{1}' , \n" + + " '{2}' , \n" + + " '{3}' , \n" + + " '{4}' , \n" + + " '{5}' , \n" + + " '{6}' , \n" + + " '{7}' , \n" + + " '{8}' , \n" + + " '{9}' , \n" + + " '{10}' , \n" + + " '{11}' , \n" + + " '{12}' , \n" + + " '{13}' , \n" + + " '{14}' , \n" + + " '{15}' , \n" + + " '{16}' , \n" + + " '{17}' , \n" + + " '{18}' , \n" + + " '{19}' , \n" + + " {20} , \n" + + " '{21}' ) \n"; + + sql = string.Format(sql, + taskid, + itm.行号, + itm.结算单, + "ZOR1", + "1001", + "00", + itm.销售渠道, + itm.客户代码, + itm.客户代码, + itm.结算编码, + itm.物料号, + "1000", + itm.寄售类别, + itm.已出库金额, + itm.实际出库数量, + + + itm.客户, + itm.物料组编码, + itm.物料组车型, + itm.出库类型, + itm.开票单价, + "0", + billnum + + ); + _buffer.AppendLine(sql); + } + + + + var count= DbConnection.Execute(_buffer.ToString(), null, null, 1200, null); + if (count > 0) + { + var sql = "INSERT INTO [TA_WMS_CTRL]\n" + + " ([wms_seq]\n" + + " ,[wms_table]\n" + + " ,[wms_table_qty]\n" + + " ,[wms_state]\n" + + " ,[remark]\n" + + " ,[createtime]\n" + + " ,[wms_domin]\n" + + " ,[SourceBillNum]\n" + + + " ,[JsonString]\n" + + " ,[AccountDate])\n" + + " VALUES\n" + + " ( '{0}' \n" + + " , '{1}' \n" + + " , '{2}' \n" + + " , '{3}' \n" + + " , '{4}' \n" + + " , '{5}' \n" + + " , '{6}' \n" + + " , '{7}' \n" + + " , '{8}' \n" + + " , {9} )"; + + sql= string.Format(sql, + taskid + , "TA_WMS_JSKH" + , count.ToString(), + 5, + string.Empty, + DateTime.Now, + "1000", + billnum + ,version + ,accountDate.ToShortDateString() + + ); + + DbConnection.Execute(sql, null, null, 1200, null); + } + + + + + + + + +//" \n" + +//"SELECT NEWID() [wms_seq] \n" + +//" ,[行号] [POSNR] \n" + +//" ,[结算单] [ZVBELN] \n" + +//" ,'ZOR1' [AUART] \n" + +//" ,'1001' [VKORG] \n" + +//" ,'00' [SPART] \n" + +//" ,[销售渠道] [VTWEG] \n" + +//" ,[客户代码] [KUNNR] \n" + +//" ,[客户代码] [KUNNR2] \n" + +//" ,[结算编码] [AUGRU] \n" + +//" ,[物料号] [MATNR] \n" + +//" ,'1000' [WERKS] \n" + +//" ,[寄售类别] [LGORT] \n" + +//" ,[实际出库数量] [KWMENG] \n" + +//" ,已出库金额 [ZPR0]\n" + +//" ,'' [ZNOTE1] \n" + +//" ,'' [ZNOTE2] \n" + +//" ,'' [ZNOTE3] \n" + +//" ,'' [ZNOTE4] \n" + +//" ,'' [ZNOTE5] \n" + +//" ,0 [STATE] \n" + +//" ,'' [REMARK] \n" + +//" \n" + +//" FROM [CPAT_WMS_TEST].[dbo].[temp1]" + + + + + + //DbConnection.Execute("INSERT ") diff --git a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/WmsOutputSumDapperRepository.cs b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/WmsOutputSumDapperRepository.cs index 55dc3a14..2d49204c 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/WmsOutputSumDapperRepository.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/WmsOutputSumDapperRepository.cs @@ -12,46 +12,69 @@ using Volo.Abp.EntityFrameworkCore; namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report { - public class WmsOutputSum + public class WmsOutputSumReport { + [ImporterHeader(Name = "行号")] [ExporterHeader(DisplayName = "行号")] public string 行号 { set; get; } + [ImporterHeader(Name = "客户")] [ExporterHeader(DisplayName = "客户")] public string 客户 { set; get; } + [ImporterHeader(Name = "出库类型")] [ExporterHeader(DisplayName = "出库类型")] public string 出库类型 { set; get; } + [ImporterHeader(Name = "结算编码")] [ExporterHeader(DisplayName = "结算编码")] public string 结算编码 { set; get; } + [ImporterHeader(Name = "销售渠道")] [ExporterHeader(DisplayName = "销售渠道")] public string 销售渠道 { set; get; } + [ImporterHeader(Name = "客户代码")] [ExporterHeader(DisplayName = "客户代码")] public string 客户代码 { set; get; } + [ImporterHeader(Name = "结算单")] [ExporterHeader(DisplayName = "结算单")] public string 结算单 { set; get; } + [ImporterHeader(Name = "物料号")] [ExporterHeader(DisplayName = "物料号")] public string 物料号 { set; get; } + [ImporterHeader(Name = "通用代码号")] [ExporterHeader(DisplayName = "通用代码号")] public string 通用代码号 { set; get; } + [ImporterHeader(Name = "寄售类别")] + [ExporterHeader(DisplayName = "寄售类别")] + public string 寄售类别 { set; get; } + [ImporterHeader(Name = "结算数量")] [ExporterHeader(DisplayName = "结算数量")] public decimal 结算数量 { set; get; } + [ImporterHeader(Name = "实际出库数量")] [ExporterHeader(DisplayName = "实际出库数量")] public decimal 实际出库数量 { set; get; } + [ImporterHeader(Name = "差异数量")] [ExporterHeader(DisplayName = "差异数量")] public decimal 差异数量 { set; get; } + [ImporterHeader(Name = "开票单价")] [ExporterHeader(DisplayName = "开票单价")] public decimal 开票单价 { set; get; } + [ImporterHeader(Name = "结算金额")] [ExporterHeader(DisplayName = "结算金额")] public decimal 结算金额 { set; get; } + [ImporterHeader(Name = "已出库金额")] [ExporterHeader(DisplayName = "已出库金额")] public decimal 已出库金额 { set; get; } + [ImporterHeader(Name = "WMS待出库金额")] [ExporterHeader(DisplayName = "WMS待出库金额")] public decimal WMS待出库金额 { set; get; } + [ImporterHeader(Name = "物料组编码")] [ExporterHeader(DisplayName = "物料组编码")] public string 物料组编码 { set; get; } + [ImporterHeader(Name = "物料组车型")] [ExporterHeader(DisplayName = "物料组车型")] public string 物料组车型 { set; get; } + [ImporterHeader(Name = "物料描述")] [ExporterHeader(DisplayName = "物料描述")] public string 物料描述 { set; get; } + [ImporterHeader(Name = "备注")] [ExporterHeader(DisplayName = "备注")] public string 备注 { set; get; } } @@ -88,7 +111,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report { } - public virtual List GetWmsSumExtendList(string version) + public virtual List GetWmsSumExtendList(string version) { var _sql = "SELECT\n" + @@ -99,11 +122,15 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report " CODE 结算编码,\n" + " SaleCode 销售渠道,\n" + " ClientCode 客户代码,\n" + -" LOGN 寄售类别,\n" + +" LOGN 寄售类别,\n" + " MaterialCode 物料号,\n" + " MaterialDesc 物料描述,\n" + " BillNum 结算单号,\n" + -" MaterialGroup 物料组,\n" + +" MaterialGroup 物料组车型,\n" + + +" EstimateType 物料组编码,\n" + + + " ISnull([ 0 ], 2 ) 结算数量,\n" + " ISNULL([ 2 ], 0 ) 实际出库数量,\n" + " isnull([ 0 ], 2 ) - ISNULL([ 2 ], 0 ) 数量差异,\n" + @@ -602,7 +629,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report " 客户,出库类型,结算单;"; _sql = string.Format(_sql, version); - var _query = DbConnection.Query(_sql, null, null, true, 1200, null); + var _query = DbConnection.Query(_sql, null, null, true, 1200, null); return _query.ToList(); } @@ -613,13 +640,13 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report - public virtual List GetWmsSumReportList(string version,string state) + public virtual List GetWmsSumReportList(string version,string state) { var _sql = "SELECT\n" + - " ROW_NUMBER()OVER(ORDER BY Type DESC) 行号 ,\n"+ + " ROW_NUMBER()OVER(ORDER BY Type DESC) 行号 ,\n" + " temp1.Client 客户,\n" + " temp1.Type 出库类型,\n" + " temp1.BillNum 结算单,\n" + @@ -630,10 +657,10 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report " Isnull( temp1.Qty, 0 )- Isnull( temp1.OutputQty, 0 ) 差异数量,\n" + " temp1.Price 开票单价,\n" + " Round( Isnull( temp1.Qty, 0 )* temp1.Price, 2 ) 结算金额,\n" + - " Round(( Isnull( temp1.Qty, 0 )- Isnull( temp1.OutputQty, 0 ))* temp1.Price, 2 ) WMS待出库金额 \n" + - " temp2.EstimateType 物料组编码, \n"+ - " temp2.EstimateTypeDesc 物料组车型, \n"+ - " temp2.MaterialDesc 物料描述 \n"+ + " Round(( Isnull( temp1.Qty, 0 )- Isnull( temp1.OutputQty, 0 ))* temp1.Price, 2 ) WMS待出库金额, \n" + + " temp2.EstimateType 物料组编码, \n" + + " temp2.EstimateTypeDesc 物料组车型, \n" + + " temp2.MaterialDesc 物料描述 \n" + "FROM\n" + " (\n" + @@ -767,12 +794,13 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report " IsBack = 1 \n" + " AND VERSION = '{0}' \n" + " AND State = 3 \n" + - " ) temp1"; + " ) temp1 \n" + + " LEFT JOIN(SELECT max(Id) Id, MaterialCode, MaterialDesc, EstimateType, EstimateTypeDesc FROM Set_material GROUP BY MaterialCode, MaterialDesc, EstimateTypeDesc, EstimateType) temp2 ON temp1.MaterialCode = temp2.MaterialCode "; _sql = string.Format(_sql, version,state); - var _query = DbConnection.Query(_sql,null,null,true,1200,null); + var _query = DbConnection.Query(_sql,null,null,true,1200,null);