| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- using Procurement.Enums;
- using Procurement.Models;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using System;
- using System.ComponentModel.DataAnnotations;
- using System.IO;
- using System.Linq;
- using System.Threading.Tasks;
- using Volo.Abp.AspNetCore.Mvc;
- namespace DigitalManufacturing.Controllers
- {
- public class MESController : AbpController
- {
- private readonly IWebHostEnvironment _hostEnvironment;
- private readonly FileManager _fileManager;
- string[] pictureFormatArray = { ".png", ".jpg", ".jpeg", ".gif", ".PNG", ".JPG", ".JPEG", ".GIF" };
- public MESController(
- IWebHostEnvironment hostEnvironment,
- FileManager fileManager)
- {
- _hostEnvironment = hostEnvironment;
- _fileManager = fileManager;
- }
- [HttpPost]
- [Route("api/digitalmanufacturing/mes/addreport")]
- //待收货看板
- //收货通知组织、收货通知日期、收货通知单号、收货申请人、单据类型、供应商编码、供应商名称、已等待收货时间、物料编码、物料名称、规格型号、数量
- public async Task<ActionResult> Feed([Required]string name, IFormFile file)
- {
- string uniqueFileName = null;
- if (file != null)
- {
- //限制100M
- if (file.Length > 104857600)
- {
- return new BadRequestObjectResult("上传文件过大");
- }
- //文件格式
- var fileExtension = Path.GetExtension(file.FileName);
- if (!pictureFormatArray.Contains(fileExtension))
- {
- return new BadRequestObjectResult("上传文件格式错误");
- }
- var size = "";
- if (file.Length < 1024)
- size = file.Length.ToString() + "B";
- else if (file.Length >= 1024 && file.Length < 1048576)
- size = ((float)file.Length / 1024).ToString("F2") + "KB";
- else if (file.Length >= 1048576 && file.Length < 104857600)
- size = ((float)file.Length / 1024 / 1024).ToString("F2") + "MB";
- else size = file.Length.ToString() + "B";
- string uploadsFolder = Path.Combine(_hostEnvironment.WebRootPath, "Images");
- if (!Directory.Exists(uploadsFolder))
- {
- Directory.CreateDirectory(uploadsFolder);
- }
- uniqueFileName = Guid.NewGuid().ToString() + fileExtension;
- string filePath = Path.Combine(uploadsFolder, uniqueFileName);
- using (var fileStream = new FileStream(filePath, FileMode.Create))
- {
- file.CopyTo(fileStream);
- fileStream.Flush();
- }
- //TODO:文件md5哈希校验
- await _fileManager.Create(name, uniqueFileName, fileExtension, "", size, filePath, "/Images/" + uniqueFileName, FileType.Image);
- }
- return Ok(uniqueFileName);
- }
- }
- }
|