using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; using ZR.Model.MES.wms; using ZR.Model.MES.wms.Dto; using ZR.Service.mes.wms.IService; //创建时间:2024-03-16 namespace ZR.Admin.WebApi.Controllers { /// /// 物料记录表增删改查 /// [Verify] [Route("/mes/wm/WmMaterial")] public class WmMaterialController : BaseController { /// /// 物料记录表接口 /// private readonly IWmMaterialService _WmMaterialService; public WmMaterialController(IWmMaterialService WmMaterialService) { _WmMaterialService = WmMaterialService; } /// /// 查询物料记录表列表 /// /// /// [HttpGet("list")] [ActionPermissionFilter(Permission = "wms:wmmaterial:list")] public IActionResult QueryWmMaterial([FromQuery] WmMaterialQueryDto parm) { var response = _WmMaterialService.GetList(parm); return SUCCESS(response); } /// /// 查询物料记录表详情 /// /// /// [HttpGet("{Id}")] [ActionPermissionFilter(Permission = "wms:wmmaterial:query")] public IActionResult GetWmMaterial(string Id) { var response = _WmMaterialService.GetInfo(Id); return SUCCESS(response); } /// /// 添加物料记录表 /// /// [HttpPost] [ActionPermissionFilter(Permission = "wms:wmmaterial:add")] [Log(Title = "物料记录表", BusinessType = BusinessType.INSERT)] public IActionResult AddWmMaterial([FromBody] WmMaterialDto parm) { var modal = parm.Adapt().ToCreate(HttpContext); var response = _WmMaterialService.AddWmMaterial(modal); return SUCCESS(response); } /// /// 更新物料记录表 /// /// [HttpPut] [ActionPermissionFilter(Permission = "wms:wmmaterial:edit")] [Log(Title = "物料记录表", BusinessType = BusinessType.UPDATE)] public IActionResult UpdateWmMaterial([FromBody] WmMaterialDto parm) { var modal = parm.Adapt().ToUpdate(HttpContext); var response = _WmMaterialService.UpdateWmMaterial(modal); return ToResponse(response); } /// /// 删除物料记录表 /// /// [HttpDelete("{ids}")] [ActionPermissionFilter(Permission = "wms:wmmaterial:delete")] [Log(Title = "物料记录表", BusinessType = BusinessType.DELETE)] public IActionResult DeleteWmMaterial(string ids) { long[] idsArr = Tools.SpitLongArrary(ids); if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); } var response = _WmMaterialService.Delete(idsArr); return ToResponse(response); } [HttpGet("getInfoByPatchCode")] [Log(Title = "物料记录表", BusinessType = BusinessType.QUERY)] public IActionResult GetInfoByPatchCode(string patchCode) { if (string.IsNullOrEmpty(patchCode)) { return SUCCESS(null); } WmGoodsNowProduction nowProduction = _WmMaterialService.GetInfoByPatchCode(patchCode); return SUCCESS(nowProduction); } [HttpGet("download_template")] [Log(Title = "下载物料清单模版", BusinessType = BusinessType.EXPORT, IsSaveRequestData = true, IsSaveResponseData = false)] [AllowAnonymous] //不需要授权 就可以访问 public IActionResult DownloadTemplate() { (string, string) result = DownloadImportTemplate("物料清单模版");//返回文件名和路径 return ExportExcel(result.Item2, result.Item1); } [HttpGet("importData")] [Log(Title = "物料清单批量导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = true)] [AllowAnonymous] //不需要授权 就可以访问 public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile, bool updateSupport) { //1.0 读取excel 文件 保存在指定位置 IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment)); string sFileName = DateTime.Now.ToString("yyyyMMddHHmmss") + formFile.FileName; string target = Path.Combine(webHostEnvironment.WebRootPath, "wmmaterial", sFileName); if (!Directory.Exists(Path.Combine(webHostEnvironment.WebRootPath, "wmmaterial"))) { // 如果目录不存在就创建 Directory.CreateDirectory(Path.Combine(webHostEnvironment.WebRootPath, "wmmaterial")); } //2.0 解析 excel using (var stream = formFile.OpenReadStream()) { FileStream targetFileStream = new FileStream(target, FileMode.Create, FileAccess.Write); byte[] buffer = new byte[1024]; int bytesRead; while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0) { targetFileStream.Write(buffer, 0, bytesRead); } //IWorkbook workbook = new XSSFWorkbook(stream); //ISheet sheet = workbook.GetSheetAt(0); // 读取第一个工作表 //for (int i = 0; i <= sheet.LastRowNum; i++) //{ // IRow row = sheet.GetRow(i); // if (row != null) // { // for (int j = 0; j < row.LastCellNum; j++) // { // Console.Write(row.GetCell(j) + "\t"); // } // Console.WriteLine(); // } //} } return null; } } }