using Microsoft.AspNetCore.Mvc; using MiniExcelLibs; using NPOI.SS.UserModel; using SqlSugar; using System.Xml.Linq; using WCS.BLL.DbModels; using WCS.BLL.Manager; using WCS.BLL.Services.IService; using WCS.BLL.Services.Service; using WCS.DAL.Db; using WCS.Model; using WCS.Model.ApiModel; using WCS.Model.ApiModel.MatBaseInfo; using WCS.WebApi.Helper; namespace WCS.WebApi.Controllers { /// /// 接口记录 /// [ApiController] [Route("[controller]")] public class MatBaseInfoController : ControllerBase { public IMatBaseInfoService _matBaseInfoService { get; set; } public IGenerateService _generateMatInfoService { get; set; } public MatBaseInfoController(IMatBaseInfoService matBaseInfoService, IGenerateService generateMatInfoService) { _matBaseInfoService = matBaseInfoService; _generateMatInfoService = generateMatInfoService; } [Route("getMatBaseInfo")] [HttpPost(Name = "getMatBaseInfo")] public async Task getMatBaseInfo(GetMatBaseInfoRequest request) { return await _matBaseInfoService.getMatBaseInfo(request); } [HttpPost("exportMatBaseInfo")] public async Task exportMatBaseInfo(GetMatBaseInfoRequest request) { var result = await _matBaseInfoService.exportMatBaseInfo(request); var data = result.Data?.Lists; var columns = new[] { new ExportableColumn("序号","RowNumber"), new ExportableColumn("物料编码","MatCode"), new ExportableColumn("名称","MatName"), new ExportableColumn("规格","MatSpec"), new ExportableColumn("单位","MatUnit"), new ExportableColumn("客户","MatCustomer"), new ExportableColumn("状态","IsEnableStr"), new ExportableColumn("更新人","ModifyUser"), new ExportableColumn("更新时间", "ModifyTime"), }; if (data == null) { return NotFound(); } else return ExportExcelHelper.Export("导出数据", columns, data); } [HttpPost("importMatBaseInfo")] public async Task importMatBaseInfo([FromForm] IFormFile excelFile, [FromForm] string userName, [FromForm] string deviceType) { //文件校验 if (excelFile == null || excelFile.Length == 0) { return new ResponseCommon() { Code = 201, Message = "导入失败:文件无有效内容!" }; } // using (var stream = new MemoryStream()) { await excelFile.CopyToAsync(stream); stream.Position = 0; var list = MiniExcelLibs.MiniExcel.Query(stream, "物料管理", ExcelType.XLSX).ToList(); return await _matBaseInfoService.importMatBaseInfo(list, userName, deviceType); } } [HttpPost("addOrUpdateMatBaseInfo")] public async Task> addOrUpdateMatBaseInfo(AddMatBaseInfoRequest request) { return await _matBaseInfoService.addOrUpdateMatBaseInfo(request); } [HttpPost("deleteMatBaseInfo")] public async Task> deleteMatBaseInfo(DeleteMatBaseInfosRequest request) { return await _matBaseInfoService.deleteMatBaseInfo(request); } [HttpPost("getMatCodeList")] public async Task>> getMatCodeList(GetMatCodeListRequest request) { return await _matBaseInfoService.getMatCodeList(request); } [HttpPost("generateMatInfo")] public async Task>> generateMatInfo(GenerateMatInfoRequest request) { return await _generateMatInfoService.generateMatInfo(request); } /// /// 获取物料明细 /// /// /// [Route("getMatInfo")] [HttpPost(Name = "getMatInfo")] public async Task getMatInfo(GetMatInfoRequest request) { return await _matBaseInfoService.getMatInfo(request); } /// /// 打印物料条码后上传打印 /// /// /// [Route("printedMatInfo")] [HttpPost(Name = "printedMatInfo")] public async Task printedMatInfo(PrintedMatInfoRequest request) { return await _matBaseInfoService.printedMatInfo(request); } } }