Compare commits
2 Commits
9c95697be9
...
6767578cc6
Author | SHA1 | Date |
---|---|---|
lvzb | 6767578cc6 | 10 months ago |
lvzb | 5176d63ddf | 10 months ago |
8 changed files with 340 additions and 0 deletions
@ -0,0 +1,49 @@ |
|||
using Magicodes.ExporterAndImporter.Core; |
|||
using Magicodes.ExporterAndImporter.Excel; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace WY.NewJit.MsgBaseData |
|||
{ |
|||
[ExcelExporter(Name = "SAP物料信息", AutoFitAllColumn = true, MaxRowNumberOnASheet = 1000)] //一个Sheet最大允许的行数,设置了之后将输出多个Sheet
|
|||
[Serializable] |
|||
public class MaterialExtDto : AuditedEntityDto<Guid> |
|||
{ |
|||
/// <summary>
|
|||
/// SAP物料号
|
|||
/// </summary>
|
|||
[ExporterHeader(DisplayName = "SAP物料号")] |
|||
[ImporterHeader(Name = "SAP物料号")] |
|||
public string MaterialNum { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 物料描述(大小量纲、物料描述字段值同时存在时,优先显示大小量纲)
|
|||
/// </summary>
|
|||
[ExporterHeader(DisplayName = "物料描述")] |
|||
[ImporterHeader(Name = "物料描述")] |
|||
public string MaterialDescription { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 大小量纲(大小量纲、物料描述字段值同时存在时,优先显示大小量纲)
|
|||
/// </summary>
|
|||
[ExporterHeader(DisplayName = "大小量纲")] |
|||
[ImporterHeader(Name = "大小量纲")] |
|||
public string MaterialDescription2 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 补充备注(车型、门板代码)
|
|||
/// </summary>
|
|||
[ExporterHeader(DisplayName = "补充备注")] |
|||
[ImporterHeader(Name = "补充备注")] |
|||
public string MaterialMemo { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 物料组:例如 门板成品-C8
|
|||
/// </summary>
|
|||
[ExporterHeader(DisplayName = "物料组")] |
|||
[ImporterHeader(Name = "物料组")] |
|||
public string MaterialGroup { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,30 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using WY.NewJit.Common; |
|||
|
|||
namespace WY.NewJit.MsgBaseData |
|||
{ |
|||
[Serializable] |
|||
public class QueryMaterialExtDto : PagedAndSortedBase |
|||
{ |
|||
/// <summary>
|
|||
/// SAP物料号
|
|||
/// </summary>
|
|||
public string MaterialNum { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 物料描述(大小量纲、物料描述字段值同时存在时,优先显示大小量纲)
|
|||
/// </summary>
|
|||
public string MaterialDescription { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 物料组:例如 门板成品-C8
|
|||
/// </summary>
|
|||
public string MaterialGroup { get; set; } |
|||
/// <summary>
|
|||
/// 物料类型 0 空 1 控制件 2 柱护板 3 门板
|
|||
/// </summary>
|
|||
public string MaterialType { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,11 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace WY.NewJit.MsgBaseData |
|||
{ |
|||
public interface IMaterialExtAppService |
|||
{ |
|||
Task<ObjectResultDto<string>> ExportAsync(QueryMaterialExtDto input); |
|||
Task<PagedResultDto<MaterialExtDto>> GetListAsync(QueryMaterialExtDto input); |
|||
} |
|||
} |
@ -0,0 +1,11 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace WY.NewJit.MsgBaseData |
|||
{ |
|||
public interface IMaterialExtAppService |
|||
{ |
|||
Task<ObjectResultDto<string>> ExportAsync(QueryMaterialExtDto input); |
|||
Task<PagedResultDto<MaterialExtDto>> GetListAsync(QueryMaterialExtDto input); |
|||
} |
|||
} |
@ -0,0 +1,161 @@ |
|||
using Magicodes.ExporterAndImporter.Core; |
|||
using Magicodes.ExporterAndImporter.Excel; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.Extensions.Logging; |
|||
using Shouldly; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Linq.Dynamic.Core; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Application.Services; |
|||
using Volo.Abp.BlobStoring; |
|||
using Volo.Abp.Domain.Repositories; |
|||
using Volo.Abp.Uow; |
|||
using WY.NewJit.Common; |
|||
using WY.NewJit.Extends.PaiGe; |
|||
|
|||
namespace WY.NewJit.MsgBaseData |
|||
{ |
|||
[Route("api/newjit/material")] |
|||
[ApiExplorerSettings(GroupName = SwaggerGroupConsts.基础数据)] |
|||
public class MaterialExtAppService : ApplicationService, IMaterialExtAppService |
|||
{ |
|||
private readonly IRepository<MaterialExt, Guid> _materialExtRepository; |
|||
private ILogger<MaterialExtAppService> _logger; |
|||
/// <summary>
|
|||
/// BLOB存储
|
|||
/// </summary>
|
|||
private readonly IBlobContainer<OurFileContainer> _blobContainer; |
|||
|
|||
/// <summary>
|
|||
/// 错误信息前缀
|
|||
/// </summary>
|
|||
private string _errorMessagePrefix |
|||
{ |
|||
get |
|||
{ |
|||
return System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "."; |
|||
} |
|||
} |
|||
public MaterialExtAppService(IRepository<MaterialExt, Guid> materialExtRepository, ILogger<MaterialExtAppService> logger, IBlobContainer<OurFileContainer> blobContainer) |
|||
{ |
|||
_materialExtRepository = materialExtRepository; |
|||
_logger = logger; |
|||
_blobContainer = blobContainer; |
|||
} |
|||
/// <summary>
|
|||
/// 获取数据
|
|||
/// </summary>
|
|||
/// <param name="input"></param>
|
|||
/// <returns></returns>
|
|||
[HttpGet] |
|||
[UnitOfWork(false)] |
|||
[Route("list")] |
|||
public virtual async Task<PagedResultDto<MaterialExtDto>> GetListAsync(QueryMaterialExtDto input) |
|||
{ |
|||
_logger.LogDebug(_errorMessagePrefix + "GetListAsync 进入"); |
|||
try |
|||
{ |
|||
var page = (PagedAndSortedBase)input; |
|||
IQueryable<MaterialExt> qry1 = QueryByCondition(input); |
|||
if (string.IsNullOrEmpty(page.Sorting)) |
|||
{ |
|||
page.Sorting = "MaterialNum"; |
|||
} |
|||
|
|||
int totalCount = await qry1.CountAsync(); //返回总记录数而不是当前页记录数
|
|||
if (totalCount == 0) |
|||
{ |
|||
return new PagedResultDto<MaterialExtDto>(0, new List<MaterialExtDto>()); |
|||
} |
|||
|
|||
var query = qry1 |
|||
.OrderBy(page.Sorting) |
|||
.Skip(page.SkipCount) |
|||
.Take(page.MaxResultCount); |
|||
|
|||
List<MaterialExt> lst = await query.ToListAsync(); |
|||
|
|||
List<MaterialExtDto> items = |
|||
ObjectMapper.Map<List<MaterialExt>, List<MaterialExtDto>>(lst); |
|||
|
|||
return new PagedResultDto<MaterialExtDto>(totalCount, items); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
string errMsg = _errorMessagePrefix + "GetListAsync 执行出错:" + ex.Message; |
|||
_logger.LogError(errMsg); |
|||
return new PagedResultDto<MaterialExtDto>(0, new List<MaterialExtDto>()); |
|||
} |
|||
} |
|||
/// <summary>
|
|||
/// 导出信息
|
|||
/// </summary>
|
|||
/// <param name="input">导出查询条件</param>
|
|||
/// <returns>执行成功返回真</returns>
|
|||
[UnitOfWork(false)] |
|||
[HttpPost] |
|||
[Route("export")] |
|||
public virtual async Task<ObjectResultDto<string>> ExportAsync(QueryMaterialExtDto input) |
|||
{ |
|||
_logger.LogDebug(_errorMessagePrefix + "ExportAsync 进入"); |
|||
ObjectResultDto<string> ret = new ObjectResultDto<string>(); |
|||
try |
|||
{ |
|||
IQueryable<MaterialExt> query = QueryByCondition(input); |
|||
List<MaterialExt> lst = await query.ToListAsync(); |
|||
List<MaterialExtDto> items = |
|||
ObjectMapper.Map<List<MaterialExt>, List<MaterialExtDto>>(lst); |
|||
//将实体列表转换成excel文件流
|
|||
IExporter exporter = new ExcelExporter(); |
|||
byte[] byteArr = await exporter.ExportAsByteArray<MaterialExtDto>(items); |
|||
byteArr.ShouldNotBeNull(); |
|||
//将excel文件流保存到服务器端文件系统
|
|||
string fileName = string.Format("SAP物料信息_{0}.xlsx", Guid.NewGuid().ToString()); |
|||
await _blobContainer.SaveAsync(fileName, byteArr); |
|||
|
|||
ret.Item = fileName; |
|||
return ret; |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
ret.Status = false; |
|||
ret.Message = _errorMessagePrefix + "ExportAsync 执行出错:" + ex.Message; |
|||
_logger.LogError(ret.Message); |
|||
return ret; |
|||
} |
|||
} |
|||
#region 私有方法
|
|||
/// <summary>
|
|||
/// 根据筛选条件获取实体列表
|
|||
/// </summary>
|
|||
/// <param name="input"></param>
|
|||
/// <returns></returns>
|
|||
private IQueryable<MaterialExt> QueryByCondition(QueryMaterialExtDto input) |
|||
{ |
|||
IQueryable<MaterialExt> ret = _materialExtRepository.Where(itm => 1 == 1); |
|||
if (!string.IsNullOrEmpty(input.MaterialNum)) |
|||
{ |
|||
ret = ret.Where(itm => itm.MaterialNum.Contains(input.MaterialNum)); |
|||
} |
|||
if (!string.IsNullOrEmpty(input.MaterialDescription)) |
|||
{ |
|||
ret = ret.Where(itm => itm.MaterialDescription.Contains(input.MaterialDescription)); |
|||
} |
|||
if (!string.IsNullOrEmpty(input.MaterialGroup)) |
|||
{ |
|||
ret = ret.Where(itm => itm.MaterialGroup == input.MaterialGroup); |
|||
} |
|||
if (!string.IsNullOrEmpty(input.MaterialType)) |
|||
{ |
|||
ret = ret.Where(itm => itm.MaterialType == input.MaterialType); |
|||
} |
|||
return ret; |
|||
} |
|||
#endregion
|
|||
} |
|||
} |
Loading…
Reference in new issue