diff --git a/.vs/WMS.Web/DesignTimeBuild/.dtbcache.v2 b/.vs/WMS.Web/DesignTimeBuild/.dtbcache.v2 index 3bcbb831..5f18e85f 100644 Binary files a/.vs/WMS.Web/DesignTimeBuild/.dtbcache.v2 and b/.vs/WMS.Web/DesignTimeBuild/.dtbcache.v2 differ diff --git a/src/WMS.Web.Api/Controllers/ProductInventoryController.cs b/src/WMS.Web.Api/Controllers/ProductInventoryController.cs new file mode 100644 index 00000000..e0ffbeb6 --- /dev/null +++ b/src/WMS.Web.Api/Controllers/ProductInventoryController.cs @@ -0,0 +1,101 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Threading.Tasks; +using WMS.Web.Core.Dto.OutStock; +using WMS.Web.Core.Dto.ProductInventory; +using WMS.Web.Core.Dto.SingleData; +using WMS.Web.Core.Internal.Results; +using WMS.Web.Domain.Infrastructure; +using WMS.Web.Domain.IService.Public; +using WMS.Web.Domain.Services.Public; +using WMS.Web.Domain.Values; +using WMS.Web.Repositories; +using WMS.Web.Core; +using WMS.Web.Domain.IService; +using WMS.Web.Domain.Options; +using Google.Protobuf.WellKnownTypes; +using WMS.Web.Domain.Services; +using Microsoft.Extensions.Options; +using System.Linq; + +namespace WMS.Web.Api.Controllers +{ + /// + /// 成品仓即时库存 + /// + [Route("api/[controller]")] + [ApiController] + public class ProductInventoryController : ControllerBase + { + private readonly ILoginService _loginService; + private readonly IBasicsRepositories _basicsRepositories; + private readonly IProductInventoryRepositories _repositories; + private readonly QiniuOptions _option; + private readonly IExportExcelService _exportExcelService; + public ProductInventoryController(ILoginService loginService, IBasicsRepositories basicsRepositories, + IProductInventoryRepositories repositories, IOptions option, IExportExcelService exportExcelServic) { + _loginService = loginService; + _basicsRepositories = basicsRepositories; + _repositories = repositories; + _option = option?.Value; + _exportExcelService = exportExcelServic; + } + + /// + /// 获取仓库 + /// + /// 仓库模糊匹配 不必填 + /// + [HttpGet] + [Route("GetUcStock")] + public async Task> GetUcStock([FromQuery] string name) + { + var loginInfo = _loginService.GetLoginInfo(this.HttpContext.Request.Headers["Authorization"]); + if (loginInfo == null || loginInfo.UserInfo == null) + return ResultList.ReFailure(ResultCodes.Token_Invalid_Error); + var r = await _basicsRepositories.GetUcStockByHeadOfficeAsync(name, loginInfo.UserInfo.CompanyId); + return ResultList.ReSuccess(r); + } + + /// + /// 列表 + /// + /// + /// + [HttpPost] + [Route("GetList")] + public async Task> GetPagedList([FromBody] ProductInventoryQueryRequest dto) + { + var loginInfo = _loginService.GetLoginInfo(this.HttpContext.Request.Headers["Authorization"]); + if (loginInfo == null || loginInfo.UserInfo == null) + return ResultPagedNumber2List.ReFailure(ResultCodes.Token_Invalid_Error); + + var (list, count, details) = await _repositories.GetListAsync(dto); + var result = ResultPagedNumber2List.ReSuccess(list,count,details); + return result; + } + /// + /// 导出 + /// + /// + /// + [HttpPost] + [Route("Export")] + public Task> Export([FromBody] OutStockQueryRequest dto) + { + var loginInfo = _loginService.GetLoginInfo(this.HttpContext.Request.Headers["Authorization"]); + if (loginInfo == null) + return Task.FromResult(Result.ReFailure(ResultCodes.Token_Invalid_Error)); + string fileName = FileDownLoadOrderType.ProductInventory.GetRemark() + loginInfo.UserInfo.CompanyId + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx"; + string res = _option.Url + fileName; + + Task.Run(async () => + { + await _exportExcelService.ExportList(dto, fileName, loginInfo.UserInfo.StaffId, loginInfo.UserInfo.CompanyId, FileDownLoadOrderType.OutStock); + }); + + return Task.FromResult(Result.ReSuccess(res)); + } + } +} diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml index 3dc39c57..4a712d9a 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml @@ -560,6 +560,32 @@ + + + 成品仓即时库存 + + + + + 获取仓库 + + 仓库模糊匹配 不必填 + + + + + 列表 + + + + + + + 导出 + + + + 获取序列号信息 diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml index f000040e..c53adb3b 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml @@ -5534,6 +5534,86 @@ 每页条数 不传默认每页10 条 + + + 成品即时库存列表 + + + + + 物料编码 + + + + + 仓库编码 + + + + + 客户/店铺 + + + + + 成品即时库存 + + + + + 单据Id + + + + + 单据类型 + + + + + 物料编码 + + + + + 物料规格型号 + + + + + 物料名称 + + + + + 仓库 + + + + + 组织 + + + + + 客户/店铺 + + + + + 批号 + + + + + 可用量 + + + + + 库存量 + + 客户编码 @@ -5824,6 +5904,26 @@ 仓库名称 + + + 根据总公司查仓库 + + + + + 领星仓库编码 + + + + + 聚水潭仓库编码 + + + + + 用途 + + 仓库响应 @@ -6817,6 +6917,78 @@ + + + 实体分页集合结果 + + + + + 实体分页集合结果 + + 实体集合 + 总条数 + + + + 实体分页集合结果 + + + + + + + + Total count of Items. + + + + + 总数量 + + + + + 创建成功的返回消息 + + 实体集合 + 总条数 + + + + + 创建成功的返回消息 + + + + + + 创建返回信息(返回处理失败) + + 结果消息 + 结果状态 + + + + + 创建返回信息(返回处理失败) + + 结果消息 + + + + + 创建返回信息(返回处理失败) + + 结果 + + + + + 转换为 task + + + 分页列表结果对象 diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml index 18545ba5..43b9bb7b 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml @@ -2075,6 +2075,56 @@ 已出库数量 + + + 成品仓即时库存 + + + + + 主键 订单编号 + + + + + 物料编码 + + + + + 单据类型 + + + + + 组织编码 + + + + + 仓库 + + + + + 客户/店铺 + + + + + 批号 + + + + + 可用量 + + + + + 库存量 + + 短信和邮箱发送日志表 @@ -2676,6 +2726,12 @@ + + + 获取仓库总公司 + + + 获取事务 用来处理即时库存 @@ -3364,6 +3420,34 @@ 删除实体集合 + + + 成品仓即时库存 + + + + + 添加 + + + + + + + + 删除 + + + + + + + 列表-分页 + + + + + 批量添加 @@ -6918,6 +7002,11 @@ 出库信息 + + + 成品即时库存 + + 入库状态 @@ -7163,6 +7252,26 @@ 组装拆卸出库 + + + 成品即时库存类型 + + + + + 金蝶 + + + + + 领星 + + + + + 聚水潭 + + 错误提示信息 @@ -7713,6 +7822,11 @@ 获取仓位详情:根据仓位Codes集合和公司ID + + + 获取仓库::根据总公司标记获取仓库 + + 同步金蝶状态 diff --git a/src/WMS.Web.Core/Dto/ProductInventory/ProductInventoryQueryRequest.cs b/src/WMS.Web.Core/Dto/ProductInventory/ProductInventoryQueryRequest.cs new file mode 100644 index 00000000..51a4edcd --- /dev/null +++ b/src/WMS.Web.Core/Dto/ProductInventory/ProductInventoryQueryRequest.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WMS.Web.Core.Dto.ProductInventory +{ + /// + /// 成品即时库存列表 + /// + public class ProductInventoryQueryRequest : PaginationBaseRequestDto + { + /// + /// 物料编码 + /// + public string MaterialNumber { get; set; } + /// + /// 仓库编码 + /// + public string StockCode { get; set; } + /// + /// 客户/店铺 + /// + public string Customer { get; set; } + } +} diff --git a/src/WMS.Web.Core/Dto/ProductInventory/ProductInventoryQueryResponse.cs b/src/WMS.Web.Core/Dto/ProductInventory/ProductInventoryQueryResponse.cs new file mode 100644 index 00000000..ae55748d --- /dev/null +++ b/src/WMS.Web.Core/Dto/ProductInventory/ProductInventoryQueryResponse.cs @@ -0,0 +1,69 @@ +using Npoi.Mapper.Attributes; +using System; +using System.Collections.Generic; +using System.Text; + +namespace WMS.Web.Core.Dto.ProductInventory +{ + /// + /// 成品即时库存 + /// + public class ProductInventoryQueryResponse + { + /// + /// 单据Id + /// + [Ignore] + public int Id { get; set; } + /// + /// 单据类型 + /// + [Ignore] + public string Type { get; set; } + /// + /// 物料编码 + /// + [Column("物料编码")] + public string MaterialNumber { get; set; } + /// + /// 物料规格型号 + /// + [Column("规格型号")] + public string Specifications { get; set; } + /// + /// 物料名称 + /// + [Column("物料名称")] + public string MaterialName { get; set; } + /// + /// 仓库 + /// + [Column("仓库")] + public string Stock { get; set; } + /// + /// 组织 + /// + [Column("组织")] + public string Org { get; set; } + /// + /// 客户/店铺 + /// + [Column("客户/店铺")] + public string Customer { get; set; } + /// + /// 批号 + /// + [Column("批号")] + public string Batch { get; set; } + /// + /// 可用量 + /// + [Column("可用量")] + public decimal Qty { get; set; } = 0; + /// + /// 库存量 + /// + [Column("库存量")] + public decimal BeforeQty { get; set; } = 0; + } +} diff --git a/src/WMS.Web.Core/Dto/SingleData/UcStockHeadOfficeResponse.cs b/src/WMS.Web.Core/Dto/SingleData/UcStockHeadOfficeResponse.cs new file mode 100644 index 00000000..b36d5e5a --- /dev/null +++ b/src/WMS.Web.Core/Dto/SingleData/UcStockHeadOfficeResponse.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Text; + +namespace WMS.Web.Core.Dto.SingleData +{ + /// + /// 根据总公司查仓库 + /// + public class UcStockHeadOfficeResponse: UcStockResponse + { + /// + /// 领星仓库编码 + /// + public string WarehouseCodeOfLingxing { get; set; } + /// + /// 聚水潭仓库编码 + /// + public string WarehouseCodeOfJushuitan { get; set; } + /// + /// 用途 + /// + public int? WarehouseUseTo { get; set; } + } +} diff --git a/src/WMS.Web.Core/Internal/Results/ResultPagedNumber2List.cs b/src/WMS.Web.Core/Internal/Results/ResultPagedNumber2List.cs new file mode 100644 index 00000000..589557d5 --- /dev/null +++ b/src/WMS.Web.Core/Internal/Results/ResultPagedNumber2List.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace WMS.Web.Core.Internal.Results +{ + public class ResultPagedNumber2List : ResultList + { + /// + /// 实体分页集合结果 + /// + public ResultPagedNumber2List() + { + } + + /// + /// 实体分页集合结果 + /// + /// 实体集合 + /// 总条数 + public ResultPagedNumber2List(IList data, int totalCount, List details) : base(data) + { + TotalCount = totalCount; + Details = details; + } + + /// + /// 实体分页集合结果 + /// + /// + /// + /// + public ResultPagedNumber2List(IList data, int totalCount, ValueTuple result) : base(data, result) + { + TotalCount = totalCount; + } + + /// + /// Total count of Items. + /// + public int TotalCount { get; set; } + /// + /// 总数量 + /// + public List Details { get; set; } + + /// + /// 创建成功的返回消息 + /// + /// 实体集合 + /// 总条数 + /// + public static ResultPagedNumber2List ReSuccess(IList data, int totalCount, List details) + { + return new ResultPagedNumber2List(data, totalCount, details); + } + + /// + /// 创建成功的返回消息 + /// + /// + public new static ResultPagedNumber2List ReSuccess() + { + return new ResultPagedNumber2List(new List(), 0, new List()); + } + + /// + /// 创建返回信息(返回处理失败) + /// + /// 结果消息 + /// 结果状态 + /// + public new static ResultPagedNumber2List ReFailure(string message, int status) + { + var result = new ResultPagedNumber2List(); + result.To(message, status); + return result; + } + + /// + /// 创建返回信息(返回处理失败) + /// + /// 结果消息 + /// + public new static ResultPagedNumber2List ReFailure(ValueTuple result) + { + var res = new ResultPagedNumber2List(); + res.To(result); + return res; + } + + /// + /// 创建返回信息(返回处理失败) + /// + /// 结果 + /// + public new static ResultPagedNumber2List ReFailure(Result result) + { + var re = new ResultPagedNumber2List(); + re.To(result); + return re; + } + + /// + /// 转换为 task + /// + /// + public new Task> AsTask() + { + return Task.FromResult(this); + } + } +} diff --git a/src/WMS.Web.Domain/Entitys/ProductInventory.cs b/src/WMS.Web.Domain/Entitys/ProductInventory.cs new file mode 100644 index 00000000..c5e98db4 --- /dev/null +++ b/src/WMS.Web.Domain/Entitys/ProductInventory.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Text; +using WMS.Web.Core; +using WMS.Web.Domain.Values; + +namespace WMS.Web.Domain.Entitys +{ + /// + /// 成品仓即时库存 + /// + [Serializable] + [Table("t_wms_product_inventory")] + public class ProductInventory : EntityBase + { + public ProductInventory() { } + /// + /// 主键 订单编号 + /// + [Column("Id")] + public override int Id { get; set; } + /// + /// 物料编码 + /// + [Column("MaterialNumber")] + public string MaterialNumber { get; set; } + /// + /// 单据类型 + /// + [Column("Type")] + public ProductInventoryType Type { get; set; } = ProductInventoryType.JinDie; + /// + /// 组织编码 + /// + [Column("OrgCode")] + public string OrgCode { get; set; } + /// + /// 仓库 + /// + [Column("StockCode")] + public string StockCode { get; set; } + /// + /// 客户/店铺 + /// + [Column("Customer")] + public string Customer { get; set; } + /// + /// 批号 + /// + [Column("Batch")] + public string Batch { get; set; } + /// + /// 可用量 + /// + [Column("Qty")] + public decimal Qty { get; set; } = 0; + /// + /// 库存量 + /// + [Column("BeforeQty")] + public decimal BeforeQty { get; set; } = 0; + } +} diff --git a/src/WMS.Web.Domain/Infrastructure/IBasicsRepositories.cs b/src/WMS.Web.Domain/Infrastructure/IBasicsRepositories.cs index 070d45f1..d4ee6000 100644 --- a/src/WMS.Web.Domain/Infrastructure/IBasicsRepositories.cs +++ b/src/WMS.Web.Domain/Infrastructure/IBasicsRepositories.cs @@ -71,6 +71,11 @@ namespace WMS.Web.Domain.Infrastructure /// /// Task> GetUcStockAsync(string systemCode,string name, int companyId); + /// + /// 获取仓库总公司 + /// + /// + Task> GetUcStockByHeadOfficeAsync(string name, int companyId); /// /// 获取事务 用来处理即时库存 diff --git a/src/WMS.Web.Domain/Infrastructure/IProductInventoryRepositories.cs b/src/WMS.Web.Domain/Infrastructure/IProductInventoryRepositories.cs new file mode 100644 index 00000000..99021660 --- /dev/null +++ b/src/WMS.Web.Domain/Infrastructure/IProductInventoryRepositories.cs @@ -0,0 +1,40 @@ +using AutoMapper; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using WMS.Web.Core.Dto.Inventory; +using WMS.Web.Core.Dto.ProductInventory; +using WMS.Web.Domain.Entitys; +using WMS.Web.Domain.IService.Public; +using WMS.Web.Domain.Values; + +namespace WMS.Web.Domain.Infrastructure +{ + /// + /// 成品仓即时库存 + /// + public interface IProductInventoryRepositories + { + /// + /// 添加 + /// + /// + /// + /// + Task AddRange(List entitys, bool isTransaction = true); + /// + /// 删除 + /// + /// + /// + Task Delete(ProductInventoryType type, bool isTransaction = true); + /// + /// 列表-分页 + /// + /// + /// + /// + Task<(List list, int total, List details)> GetListAsync(ProductInventoryQueryRequest dto, int companyId = 0); + } +} diff --git a/src/WMS.Web.Domain/Values/FileDownLoadOrderType.cs b/src/WMS.Web.Domain/Values/FileDownLoadOrderType.cs index 33b56314..cfb78d15 100644 --- a/src/WMS.Web.Domain/Values/FileDownLoadOrderType.cs +++ b/src/WMS.Web.Domain/Values/FileDownLoadOrderType.cs @@ -70,5 +70,11 @@ namespace WMS.Web.Domain.Values /// [EnumRemark("出库信息")] OutStockTaskInfo = 12, + /// + /// 成品即时库存 + /// + [EnumRemark("成品即时库存")] + ProductInventory = 13, + } } diff --git a/src/WMS.Web.Domain/Values/ProductInventoryType.cs b/src/WMS.Web.Domain/Values/ProductInventoryType.cs new file mode 100644 index 00000000..6a355305 --- /dev/null +++ b/src/WMS.Web.Domain/Values/ProductInventoryType.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Text; +using WMS.Web.Core; + +namespace WMS.Web.Domain.Values +{ + /// + /// 成品即时库存类型 + /// + public enum ProductInventoryType + { + /// + /// 金蝶 + /// + [EnumRemark("金蝶")] + JinDie = 0, + /// + /// 领星 + /// + [EnumRemark("领星")] + LingXing = 1, + /// + /// 聚水潭 + /// + [EnumRemark("聚水潭")] + JushuiTan = 2, + } +} diff --git a/src/WMS.Web.Domain/Values/Single/SysConfigAction.cs b/src/WMS.Web.Domain/Values/Single/SysConfigAction.cs index c68861fd..04a0d128 100644 --- a/src/WMS.Web.Domain/Values/Single/SysConfigAction.cs +++ b/src/WMS.Web.Domain/Values/Single/SysConfigAction.cs @@ -211,5 +211,9 @@ namespace WMS.Web.Domain.Values.Single /// 获取仓位详情:根据仓位Codes集合和公司ID /// GetWmsSubWarehouseByCodesAndCompany = 48, + /// + /// 获取仓库::根据总公司标记获取仓库 + /// + GetWmsWarehouseByHeadOfficeAndNameAndCompany = 49, } } diff --git a/src/WMS.Web.Repositories/BasicsRepositories.cs b/src/WMS.Web.Repositories/BasicsRepositories.cs index 80212a37..6e645372 100644 --- a/src/WMS.Web.Repositories/BasicsRepositories.cs +++ b/src/WMS.Web.Repositories/BasicsRepositories.cs @@ -168,7 +168,20 @@ namespace WMS.Web.Repositories } return true; } - - + /// + /// 根据总公司获取仓位 + /// + /// + /// + /// + public async Task> GetUcStockByHeadOfficeAsync(string name, int companyId) + { + var result = await _singleDataService.GetSysConfigData, SystemCodeRequest> + (new SystemCodeRequest("", name, companyId), + SysConfigAction.GetWmsWarehouseByHeadOfficeAndNameAndCompany); + if (!result.Success) + return null; + return result.Data.ToList(); + } } } diff --git a/src/WMS.Web.Repositories/Configuration/RepositoryDbContext.cs b/src/WMS.Web.Repositories/Configuration/RepositoryDbContext.cs index bfdfd3f1..5ffd3a6c 100644 --- a/src/WMS.Web.Repositories/Configuration/RepositoryDbContext.cs +++ b/src/WMS.Web.Repositories/Configuration/RepositoryDbContext.cs @@ -414,8 +414,16 @@ namespace WMS.Web.Repositories.Configuration .SetValueComparer(valueComparer); ; }); + //成品即时库存 + builder.Entity(ent => + { + ent.ToTable("t_wms_product_inventory"); + ent.HasKey(x => x.Id); + }); + base.OnModelCreating(builder); } + public DbSet ProductInventory { get; set; } public DbSet Materials { get; set; } public DbSet BoxMarkBillNo { get; set; } public DbSet BoxMark { get; set; } diff --git a/src/WMS.Web.Repositories/DependencyInjection/AppBuilderExtensions.cs b/src/WMS.Web.Repositories/DependencyInjection/AppBuilderExtensions.cs index 00475c06..f9cfa174 100644 --- a/src/WMS.Web.Repositories/DependencyInjection/AppBuilderExtensions.cs +++ b/src/WMS.Web.Repositories/DependencyInjection/AppBuilderExtensions.cs @@ -81,7 +81,7 @@ namespace Microsoft.Extensions.DependencyInjection services.AddTransient(); services.AddTransient(); - + services.AddTransient(); } } } diff --git a/src/WMS.Web.Repositories/ProductInventoryRepositories.cs b/src/WMS.Web.Repositories/ProductInventoryRepositories.cs new file mode 100644 index 00000000..f97e08ec --- /dev/null +++ b/src/WMS.Web.Repositories/ProductInventoryRepositories.cs @@ -0,0 +1,177 @@ +using AutoMapper; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Storage; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WMS.Web.Core.Dto.Erp.Customer; +using WMS.Web.Core.Dto.Erp.Org; +using WMS.Web.Core.Dto.Erp; +using WMS.Web.Core.Dto.ProductInventory; +using WMS.Web.Domain.Entitys; +using WMS.Web.Domain.Infrastructure; +using WMS.Web.Domain.IService.Public; +using WMS.Web.Domain.Values; +using WMS.Web.Repositories.Configuration; +using WMS.Web.Core.Dto.OutStockTask; +using WMS.Web.Domain.Values.Single; +using WMS.Web.Core; +using NPOI.SS.Formula.Functions; + +namespace WMS.Web.Repositories +{ + /// + /// 成品仓即时库存 + /// + public class ProductInventoryRepositories : IAllFielRepositories, IProductInventoryRepositories + { + private readonly IMapper _mapper; + private readonly IServiceProvider _serviceProvider; + private readonly ILoginRepositories _loginRepositories; + private readonly IBasicsRepositories _basicsRepositories; + private readonly RepositoryDbContext _context; + private readonly IErpService _erpService; + private readonly ISingleDataService _singleDataService; + private readonly IErpBasicDataExtendService _erpBasicDataExtendService; + + public ProductInventoryRepositories(RepositoryDbContext context, + IMapper mapper, + IErpService erpService, + IBasicsRepositories basicsRepositories, + ILoginRepositories loginRepositories, + IServiceProvider serviceProvider, + ISingleDataService singleDataService, + IErpBasicDataExtendService erpBasicDataExtendService) + { + _erpService = erpService; + _context = context; + _mapper = mapper; + _basicsRepositories = basicsRepositories; + _serviceProvider = serviceProvider; + _loginRepositories = loginRepositories; + _singleDataService = singleDataService; + _erpBasicDataExtendService = erpBasicDataExtendService; + } + + public async Task AddRange(List entitys, bool isTransaction = true) + { + IDbContextTransaction _transaction = null; + if (isTransaction) + _transaction = _context.Database.BeginTransaction(); + try + { + if (entitys != null && entitys.Count != 0) + { + await _context.ProductInventory.AddRangeAsync(entitys); + await _context.SaveChangesAsync(); + } + if (_transaction != null) + _transaction.Commit(); + return true; + } + catch + { + if (_transaction != null) + _transaction.Rollback(); + return false; + } + } + + public async Task Delete(ProductInventoryType type, bool isTransaction = true) + { + IDbContextTransaction _transaction = null; + if (isTransaction) + _transaction = _context.Database.BeginTransaction(); + try + { + var list = await _context.ProductInventory.Where(w => w.Type == type).ToListAsync(); + _context.RemoveRange(list); + + if (_transaction != null) + _transaction.Commit(); + return true; + } + catch + { + if (_transaction != null) + _transaction.Rollback(); + return false; + } + } + + public async Task<(List list, int total, List details)> GetListAsync(ProductInventoryQueryRequest dto, int companyId = 0) + { + if (companyId == 0) + companyId = _loginRepositories.CompanyId; + #region erp基础资料 + List mNumber = new List(); + var materials_result = await _erpService.BillQueryForMaterial(); + List materials = new List(); + if (materials_result.IsSuccess) + materials = materials_result.Data.ToList(); + //物料集合;模糊查询后的物料集合 + if (!string.IsNullOrEmpty(dto.MaterialNumber)) + { + if (materials != null) + mNumber = materials.Where(w => w.MaterialNumber.Contains(dto.MaterialNumber) + || w.MaterialName.Contains(dto.MaterialNumber) + || w.Specifications.Contains(dto.MaterialNumber) + ).Select(s => s.MaterialNumber).ToList(); + } + + //取组织 + var org_result = await _erpService.BillQueryForOrg(); + List orgs = new List(); + if (org_result.IsSuccess) + orgs = org_result.Data.ToList(); + + + #endregion + + var query = _context.ProductInventory + .OrderByDescending(o => o.Id) + .Where(adv => 1 == 1); + + if (!string.IsNullOrEmpty(dto.MaterialNumber)) + query = query.Where(w => mNumber.Contains(w.MaterialNumber)); + if (!string.IsNullOrEmpty(dto.Customer)) + query = query.Where(w => dto.Customer.Contains(w.MaterialNumber)); + if (!string.IsNullOrEmpty(dto.StockCode)) + query = query.Where(w => dto.StockCode.Contains(w.StockCode)); + + //组装 + int total = await query.CountAsync(); + decimal qty = await query.SumAsync(s => s.Qty); + decimal beforeQty = await query.SumAsync(s => s.BeforeQty); + List details = new List(); + details.Add(qty); + details.Add(beforeQty); + var list = await query.Select(s => new ProductInventoryQueryResponse() + { + #region dto组装 + Id = s.Id, + Type = s.Type.GetRemark(), + Stock = _singleDataService.GetSingleData(SingleAction.StocksJoinOrgCode, companyId, s.StockCode + s.OrgCode), + Org = _erpBasicDataExtendService.GetOrgName(orgs, s.OrgCode), + MaterialName = _erpBasicDataExtendService.GetMaterialName(materials, s.MaterialNumber), + MaterialNumber = s.MaterialNumber, + Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, s.MaterialNumber), + Batch = s.Batch, + Customer = s.Customer, + Qty = s.Qty, + BeforeQty = s.BeforeQty + #endregion + + }).Skip((dto.PageNo - 1) * dto.PageSize).Take(dto.PageSize).ToListAsync(); + return (list, total, details); + } + + public async Task<(object obj, int total)> GetListField(ProductInventoryQueryRequest dto, int companyId) + { + var (list, count, qty) = await GetListAsync(dto, companyId); + return (list, count); + } + } +}