cnf
2025-05-07 964b796bb505b036953d16b652c66b03e3616d23
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using ConsoleApp1;
using MES.Service.service.PLM;
using MES.Service.util;
using Microsoft.AspNetCore.Mvc;
using System.Dynamic;
using System.IO;
 
namespace MESApplication.Controllers.PLM;
 
 
[ApiController]
[Route("api/PLM")]
public class PLMController : ControllerBase
{
    private readonly PLMManager m = new();
    private readonly WarehouseDownloadDoc wdd = new();
 
    //RetrieveDrawings  调取图纸
    [HttpPost("RetrieveDrawings")]
    public ResponseResult RetrieveDrawings(string ItemNo)
    {
        try
        {
            dynamic resultInfos = new ExpandoObject();
            resultInfos = m.RetrieveDrawings(ItemNo);
 
            return new ResponseResult
            {
                status = 0,
                message = "OK",
                data = resultInfos
            };
        }
            catch (Exception ex)
        {
            return ResponseResult.ResponseError(ex);
        }
    }
 
    //RetrieveImageFile  调取上传到服务器的拍摄文件
    [HttpGet("GetImageNames")]
    public IActionResult GetImageNames(string releaseNo)
    {
        // 拼接本地文件系统路径
        string basePath = @"D:\MES_FTP\IQC\"; // 服务器D盘下的基础路径
        string folderPath = Path.Combine(basePath, releaseNo); // 动态拼接单号对应的文件夹路径
 
        // 检查文件夹是否存在
        if (!Directory.Exists(folderPath))
        {
            return NotFound($"文件夹 {folderPath} 不存在。请检查路径是否正确。");
        }
 
        // 获取文件夹中的所有图片文件名称
        string[] imageExtensions = { ".jpg", ".jpeg", ".png", ".gif", ".bmp" };
        // 获取文件的完整路径,并返回一个包含文件名和完整路径的对象
        var imageFiles = Directory.GetFiles(folderPath)
            .Where(file => imageExtensions.Any(ext => file.ToLower().EndsWith(ext)))
            .Select(file => new
            {
                FileName = Path.GetFileName(file), // 文件名
                FilePath = file,
                FileBasePath = ConvertFileToBase64(file) // 文件的 Base64 数据 // 文件的完整路径
            });
 
        return Ok(new { success = true, data = imageFiles });
    }
    private string ConvertFileToBase64(string filePath)
    {
        byte[] fileBytes = System.IO.File.ReadAllBytes(filePath);
        return Convert.ToBase64String(fileBytes);
    }
 
    [HttpPost("DeleteImageFile")]
    public IActionResult DeleteImageFile([FromQuery] string filePath)
    {
        // 检查文件路径是否为空
        if (string.IsNullOrWhiteSpace(filePath))
        {
            return BadRequest("文件路径不能为空");
        }
 
        // 确保路径是绝对路径(可以根据需要调整)
        filePath = Path.GetFullPath(filePath);
 
        // 检查文件是否存在
        if (!System.IO.File.Exists(filePath))
        {
            return NotFound("文件不存在");
        }
 
        try
        {
            // 删除文件
            System.IO.File.Delete(filePath);
            return Ok("文件删除成功");
        }
        catch (System.Exception ex)
        {
            // 捕获异常并返回错误信息
            return StatusCode(500, $"删除文件时发生错误: {ex.Message}");
        }
    }
 
    //RetrieveDrawings  调取图纸
    [HttpPost("OpenDrawings")]
    public IActionResult OpenDrawings(string fileId,string fName)
    {
        try
        {
            var resultInfos = wdd.SendRequest("Download", fileId);
 
            return File(resultInfos, "application/octet-stream", fName);
        }
        catch (Exception ex)
        {
            return StatusCode(500, new ResponseResult
            {
                status = 1,
                message = ex.Message,
                data = null
            });
        }
    }
}