| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- 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 QMSController : AbpController
- {
- private readonly IWebHostEnvironment _hostEnvironment;
- private readonly FileManager _fileManager;
- string[] pictureFormatArray = { ".png", ".jpg", ".jpeg", ".gif", ".PNG", ".JPG", ".JPEG", ".GIF" };
- public QMSController(
- IWebHostEnvironment hostEnvironment,
- FileManager fileManager)
- {
- _hostEnvironment = hostEnvironment;
- _fileManager = fileManager;
- }
- [HttpPost]
- [Route("api/digitalmanufacturing/qms/materialtracing")]
- //物料追溯
- //通过一个物料可以查询到关联物料的使用情况
- public async Task<ActionResult> MaterialTracing([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);
- }
- [HttpPost]
- [Route("api/digitalmanufacturing/qms/inspection ")]
- //移动检验
- //所有检验方案支持移动端检验
- public async Task<ActionResult> Inspection([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);
- }
- }
- }
|