| | |
| | | using Model.ModelVm; |
| | | using Wms.Tools; |
| | | using Microsoft.Extensions.Options; |
| | | using System.Collections.Generic; |
| | | using System.IO; |
| | | using System.Threading.Tasks; |
| | | using System.Linq; |
| | | |
| | | |
| | | namespace Wms.Controllers |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 发送请验单据 |
| | | /// </summary> |
| | | /// <param name="model">主键ID</param> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | public IActionResult SendInspectionRequest(IdVm model) |
| | | public IActionResult upLoadRequest(IdVm model) |
| | | { |
| | | try |
| | | { |
| | |
| | | } |
| | | var userName = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier)?.Value; |
| | | |
| | | string url = _config.WcsHost + _config.IssueComApiUrl; |
| | | var models = _inspectionRequestServer.SendInspectionRequest(model, int.Parse(userId),url,userName); |
| | | |
| | | return Ok(new { code = 0, count=0, msg = "向Limes请验成功!", data = models }); |
| | | return Ok(new { code = 0, count = 0, msg = "上传图片成功!"}); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | return Ok(new { code = 1, msg = e.Message }); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 删除请验单信息 |
| | |
| | | return Ok(new { code = 1, msg = e.Message }); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 图片上传 |
| | | /// </summary> |
| | | /// <param name="file"></param> |
| | | /// <param name="qualityId"></param> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | public async Task<IActionResult> UploadImage([FromForm] IFormFile file, [FromForm] int qualityId) |
| | | { |
| | | try |
| | | { |
| | | var claimsIdentity = this.User.Identity as ClaimsIdentity; |
| | | var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; |
| | | if (file == null || file.Length == 0) |
| | | return BadRequest(new { code = 1, msg = "请选择上传文件" }); |
| | | |
| | | // 验证文件类型 |
| | | var allowedExtensions = new[] { ".jpg", ".jpeg", ".png", ".gif" }; |
| | | var fileExtension = Path.GetExtension(file.FileName).ToLower(); |
| | | if (!allowedExtensions.Contains(fileExtension)) |
| | | return BadRequest(new { code = 2, msg = "只允许上传图片文件" }); |
| | | |
| | | // 限制文件大小 (5MB) |
| | | if (file.Length > 5 * 1024 * 1024) |
| | | return BadRequest(new { code = 3, msg = "文件大小不能超过5MB" }); |
| | | |
| | | // 创建质量相关的图片目录 |
| | | var uploadPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwRoot", "uploads", "quality", qualityId.ToString()); |
| | | if (!Directory.Exists(uploadPath)) |
| | | Directory.CreateDirectory(uploadPath); |
| | | |
| | | // 生成唯一文件名 |
| | | var fileName = $"{DateTime.Now:yyyyMMddHHmmss}_{userId}{fileExtension}"; |
| | | var filePath = Path.Combine(uploadPath, fileName); |
| | | |
| | | // 保存文件 |
| | | using (var stream = new FileStream(filePath, FileMode.Create)) |
| | | { |
| | | await file.CopyToAsync(stream); |
| | | } |
| | | |
| | | // 返回文件访问路径 |
| | | var fileUrl = $"/wwwRoot/uploads/quality/{qualityId}/{fileName}"; |
| | | |
| | | // 这里可以添加数据库记录等操作 |
| | | // _qualityService.AddImageRecord(qualityId, userId, fileUrl, fileName); |
| | | |
| | | return Ok(new |
| | | { |
| | | code = 0, |
| | | msg = "上传成功", |
| | | data = new |
| | | { |
| | | url = fileUrl, |
| | | fileName = fileName |
| | | } |
| | | }); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return StatusCode(500, new { code = 500, msg = $"上传失败: {ex.Message}" }); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 图片获取 |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | public IActionResult GetImage(BllQualityInspect model) |
| | | { |
| | | try |
| | | { |
| | | |
| | | var fullPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwRoot", "uploads", "quality", model.Id.ToString()); |
| | | if (!Directory.Exists(fullPath)) |
| | | { |
| | | return StatusCode(1, new { code = 1, msg = "图片不存在" }); |
| | | } |
| | | var files = Directory.GetFiles(fullPath); |
| | | if (files.Length <= 0) |
| | | return StatusCode(1, new { code = 1, msg = "图片不存在" }); |
| | | List<string> images = new List<string>(); |
| | | foreach (var file in files) |
| | | { |
| | | images.Add($"{Request.Scheme}://{Request.Host}/uploads/quality/{model.Id.ToString()}/{Path.GetFileName(file)}"); |
| | | } |
| | | return Ok(new |
| | | { |
| | | code = 0, |
| | | msg = "图片" + files.Length + "张", |
| | | data = images |
| | | }); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return StatusCode(500, new { code = 500, msg = $"获取图片失败: {ex.Message}" }); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除图片 |
| | | /// </summary> |
| | | /// <param name="data">图片信息</param> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | public IActionResult DeleteImage(QualityImageVM data) |
| | | { |
| | | try |
| | | { |
| | | string fileName = Path.GetFileName(data.ImageUrl); |
| | | |
| | | var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwRoot", "uploads", "quality", data.QualityId.ToString(), fileName); |
| | | if (System.IO.File.Exists(filePath)) |
| | | { |
| | | System.IO.File.Delete(filePath); |
| | | |
| | | return Ok(new { code = 0, msg = "删除成功" }); |
| | | } |
| | | else |
| | | { |
| | | return Ok(new { code = 1, msg = "图片不存在" }); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return Ok(new { code = 1, msg = ex.Message }); |
| | | } |
| | | } |
| | | #endregion |
| | | } |
| | | } |