xwt
2025-10-10 0c7322109660b80e359118de04c0b9cc16a030e3
SJ,XJ,RKJ调用FTP附件
已修改10个文件
258 ■■■■ 文件已修改
StandardInterface/MES.Service/Modes/MesQamftp.cs 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
StandardInterface/MES.Service/Modes/QamftpDto.cs 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
StandardInterface/MES.Service/Modes/QsItemOqcItem.cs 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
StandardInterface/MES.Service/Modes/QsQaItemXj01.cs 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
StandardInterface/MES.Service/service/QC/RKJService.cs 68 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
StandardInterface/MES.Service/service/QC/SJService.cs 32 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
StandardInterface/MES.Service/service/QC/XJService.cs 62 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
StandardInterface/MESApplication/Controllers/QC/RKJController.cs 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
StandardInterface/MESApplication/Controllers/QC/SJController.cs 25 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
StandardInterface/MESApplication/Controllers/QC/XJController.cs 26 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
StandardInterface/MES.Service/Modes/MesQamftp.cs
@@ -50,5 +50,7 @@
        [SugarColumn(ColumnName = "ITEM_ID")]
        public decimal? ItemId { get; set; }
        [SugarColumn(ColumnName = "PID")]
        public decimal? Pid { get; set; }
    }
StandardInterface/MES.Service/Modes/QamftpDto.cs
@@ -19,5 +19,6 @@
        public string LastupdateBy { get; set; }
        public DateTime? LastupdateDate { get; set; }
        public decimal? ItemId { get; set; }
        public decimal? Pid { get; set; }
    }
StandardInterface/MES.Service/Modes/QsItemOqcItem.cs
@@ -171,4 +171,10 @@
    [SugarColumn(IsIgnore = true)] public string? imageData { get; set; }
    [SugarColumn(IsIgnore = true)] public int? Unqualified { get; set; }
    /// <summary>
    ///     物料编码(从主表获取)
    /// </summary>
    [SugarColumn(IsIgnore = true)]
    public string? ItemNo { get; set; }
}
StandardInterface/MES.Service/Modes/QsQaItemXj01.cs
@@ -162,4 +162,10 @@
    [SugarColumn(IsIgnore = true)] public string? result { get; set; }
    [SugarColumn(IsIgnore = true)] public string? imageData { get; set; }
    /// <summary>
    ///     物料编码(从主表获取)
    /// </summary>
    [SugarColumn(IsIgnore = true)]
    public string? ItemNo { get; set; }
}
StandardInterface/MES.Service/service/QC/RKJService.cs
@@ -710,8 +710,36 @@
        var rkjDto = new RKJDto();
        var db = SqlSugarHelper.GetInstance();
        var qsItemOqcItem =
            db.Queryable<QsItemOqcItem>().Single(s => s.Id == id);
        // 使用JOIN查询获取子表数据和主表的ItemNo字段
        var qsItemOqcItem = db
            .Queryable<QsItemOqcItem, QsItemOqcReq>((a, b) => new JoinQueryInfos(JoinType.Left, a.Pid == b.Id))
            .Where((a, b) => a.Id == id)
            .Select((a, b) => new QsItemOqcItem
            {
                Id = a.Id,
                Pid = a.Pid,
                ProjName = a.ProjName,
                ItemMod = a.ItemMod,
                InspectionMethod = a.InspectionMethod,
                UsingInstruments = a.UsingInstruments,
                LevelNum = a.LevelNum,
                MaxValue = a.MaxValue,
                StandardValue = a.StandardValue,
                MinValue = a.MinValue,
                Notes = a.Notes,
                FcheckLevel = a.FcheckLevel,
                FacLevel = a.FacLevel,
                QsCode = a.QsCode,
                QsName = a.QsName,
                Picture = a.Picture,
                Picturename = a.Picturename,
                IsPass = a.IsPass,
                Remarks = a.Remarks,
                FreQty = a.FreQty,
                // 添加主表的ItemNo字段
                ItemNo = b.ItemNo
            }).Single();
        if (qsItemOqcItem.IsPass == 0)
            qsItemOqcItem.Result = "不合格";
@@ -731,7 +759,6 @@
        qsItemOqcItem.Unqualified = count;
        rkjDto.ItemXj01 = qsItemOqcItem;
        rkjDto.ItemXj02s = db.Queryable<QsItemOqcItemDetail>()
            .Where(s => s.Pid == id)
@@ -960,14 +987,24 @@
    /// 获取附件信息
    /// </summary>
    /// <param name="ItemNo">物料编码</param>
    /// <param name="projName">项目名称(用于过滤)</param>
    /// <returns>附件列表</returns>
    public List<QamftpDto> GetAttachments(string ItemNo)
    public List<QamftpDto> GetAttachments(string ItemNo, string projName = null)
    {
        var db = SqlSugarHelper.GetInstance();
        try
        {
            return db.Queryable<MesQamftp>()
            var query = db.Queryable<MesQamftp>()
                .Where(x => x.ItemNo == ItemNo)
                .Where(x => x.Ftype == "入库检");  // 添加FTYPE = '入库检'的限制
            // 如果传入了projName,则按Fversion过滤
            if (!string.IsNullOrEmpty(projName))
            {
                query = query.Where(x => x.Fversion == projName);
            }
            return query
                .OrderBy(x => x.Fdate, OrderByType.Desc)
                .Select(x => new QamftpDto
                {
@@ -998,24 +1035,33 @@
    /// </summary>
    /// <param name="itemNo">物料编码</param>
    /// <param name="fileName">文件名</param>
    /// <param name="ftpServer">FTP服务器地址</param>
    /// <param name="projName">项目名称</param>
    /// <returns>文件字节数组</returns>
    public byte[] GetFtpFile(string itemNo, string fileName, string ftpServer)
    public byte[] GetFtpFile(string itemNo, string fileName, string projName = null)
    {
        // 参数验证
        if (string.IsNullOrEmpty(itemNo) || string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(ftpServer))
        if (string.IsNullOrEmpty(itemNo) || string.IsNullOrEmpty(fileName))
        {
            throw new ArgumentException("参数不能为空: itemNo, fileName, ftpServer");
            throw new ArgumentException("参数不能为空: itemNo, fileName");
        }
        
        string ftpUser = "hm_ftp";
        string ftpPwd = "dell_123";
        string ftpServer = "ftp://192.168.1.100"; // 默认FTP服务器地址
        
        // 标准化FTP服务器地址
        string normalizedServer = NormalizeFtpServer(ftpServer);
        
        // 构建FTP文件路径 - RKJ使用FQC文件夹
        string ftpPath = $"{normalizedServer}/FQC/{itemNo}/{fileName}";
        // 构建FTP文件路径 - RKJ使用FQC文件夹,如果有projName则使用projName作为路径的最后一段
        string ftpPath;
        if (!string.IsNullOrEmpty(projName))
        {
            ftpPath = $"{normalizedServer}/FQC/{itemNo}/{projName}/{fileName}";
        }
        else
        {
            ftpPath = $"{normalizedServer}/FQC/{itemNo}/{fileName}";
        }
        
        try
        {
StandardInterface/MES.Service/service/QC/SJService.cs
@@ -742,14 +742,22 @@
    /// </summary>
    /// <param name="itemNo">物料编码</param>
    /// <returns>附件列表</returns>
    public List<QamftpDto> GetAttachments(string itemNo)
    public List<QamftpDto> GetAttachments(string itemNo, string projName = null)
    {
        var db = SqlSugarHelper.GetInstance();
        try
        {
            return db.Queryable<MesQamftp>()
            var query = db.Queryable<MesQamftp>()
                .Where(x => x.ItemNo == itemNo)
                .OrderBy(x => x.Fdate, OrderByType.Desc)
                .Where(x => x.Ftype == "首检");
            // 如果传入了projName,则按Fversion过滤
            if (!string.IsNullOrEmpty(projName))
            {
                query = query.Where(x => x.Fversion == projName);
            }
            return query.OrderBy(x => x.Fdate, OrderByType.Desc)
                .Select(x => new QamftpDto
                {
                    Id = x.Id,
@@ -765,7 +773,8 @@
                    F_type = x.F_type,
                    LastupdateBy = x.LastupdateBy,
                    LastupdateDate = x.LastupdateDate,
                    ItemId = x.ItemId
                    ItemId = x.ItemId,
                    Pid = x.Pid
                }).ToList();
        }
        catch (Exception ex)
@@ -780,8 +789,9 @@
    /// <param name="itemNo">物料编码</param>
    /// <param name="fileName">文件名</param>
    /// <param name="ftpServer">FTP服务器地址</param>
    /// <param name="projName">项目名称</param>
    /// <returns>文件字节数组</returns>
    public byte[] GetFtpFile(string itemNo, string fileName, string ftpServer)
    public byte[] GetFtpFile(string itemNo, string fileName, string ftpServer, string projName = null)
    {
        // 参数验证
        if (string.IsNullOrEmpty(itemNo) || string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(ftpServer))
@@ -795,8 +805,16 @@
        // 标准化FTP服务器地址
        string normalizedServer = NormalizeFtpServer(ftpServer);
        
        // 构建FTP文件路径 - 首检使用OPC目录
        string ftpPath = $"{normalizedServer}/OPC/{itemNo}/{fileName}";
        // 构建FTP文件路径 - 首检使用OPC目录,如果传入了projName则使用新格式
        string ftpPath;
        if (!string.IsNullOrEmpty(projName))
        {
            ftpPath = $"{normalizedServer}/OPC/{itemNo}/{projName}/{fileName}";
        }
        else
        {
            ftpPath = $"{normalizedServer}/OPC/{itemNo}/{fileName}";
        }
        
        try
        {
StandardInterface/MES.Service/service/QC/XJService.cs
@@ -418,8 +418,35 @@
        var xjDto = new XJDto();
        var db = SqlSugarHelper.GetInstance();
        var qsQaItemXj01 =
            db.Queryable<QsQaItemXj01>().Single(s => s.Id == id);
        // 使用JOIN查询获取子表数据和主表的ItemNo字段
        var qsQaItemXj01 = db
            .Queryable<QsQaItemXj01, QsQaItemXj>((a, b) => new JoinQueryInfos(JoinType.Left, a.Pid == b.Id))
            .Where((a, b) => a.Id == id)
            .Select((a, b) => new QsQaItemXj01
            {
                Id = a.Id,
                Pid = a.Pid,
                ProjName = a.ProjName,
                ItemMod = a.ItemMod,
                InspectionMethod = a.InspectionMethod,
                UsingInstruments = a.UsingInstruments,
                LevelNum = a.LevelNum,
                MaxValue = a.MaxValue,
                StandardValue = a.StandardValue,
                MinValue = a.MinValue,
                Notes = a.Notes,
                FcheckLevel = a.FcheckLevel,
                FacLevel = a.FacLevel,
                QsCode = a.QsCode,
                QsName = a.QsName,
                Picture = a.Picture,
                Picturename = a.Picturename,
                IsPass = a.IsPass,
                Remarks = a.Remarks,
                // 添加主表的ItemNo字段
                ItemNo = b.ItemNo
            }).Single();
        if (qsQaItemXj01.IsPass == 0)
            qsQaItemXj01.result = "不合格";
@@ -433,7 +460,6 @@
                Convert.ToBase64String(qsQaItemXj01.Picture);
        xjDto.ItemXj01 = qsQaItemXj01;
        xjDto.ItemXj02s = db.Queryable<QsQaItemXj02>().Where(s => s.Pid == id)
            .ToList();
@@ -751,15 +777,24 @@
    /// 获取附件信息
    /// </summary>
    /// <param name="itemNo">物料编码</param>
    /// <param name="projName">项目名称(可选,用于过滤)</param>
    /// <returns>附件列表</returns>
    public List<QamftpDto> GetAttachments(string itemNo)
    public List<QamftpDto> GetAttachments(string itemNo, string projName = null)
    {
        var db = SqlSugarHelper.GetInstance();
        try
        {
            return db.Queryable<MesQamftp>()
            var query = db.Queryable<MesQamftp>()
                .Where(x => x.ItemNo == itemNo)
                .OrderBy(x => x.Fdate, OrderByType.Desc)
                .Where(x => x.Ftype == "巡检");  // 添加FTYPE = '巡检'的限制
            // 如果传入了projName,则按Fversion过滤
            if (!string.IsNullOrEmpty(projName))
            {
                query = query.Where(x => x.Fversion == projName);
            }
            return query.OrderBy(x => x.Fdate, OrderByType.Desc)
                .Select(x => new QamftpDto
                {
                    Id = x.Id,
@@ -790,8 +825,9 @@
    /// <param name="itemNo">物料编码</param>
    /// <param name="fileName">文件名</param>
    /// <param name="ftpServer">FTP服务器地址</param>
    /// <param name="projName">项目名称(可选,用于路径构建)</param>
    /// <returns>文件字节数组</returns>
    public byte[] GetFtpFile(string itemNo, string fileName, string ftpServer)
    public byte[] GetFtpFile(string itemNo, string fileName, string ftpServer, string projName = null)
    {
        // 参数验证
        if (string.IsNullOrEmpty(itemNo) || string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(ftpServer))
@@ -805,8 +841,16 @@
        // 标准化FTP服务器地址
        string normalizedServer = NormalizeFtpServer(ftpServer);
        
        // 构建FTP文件路径 - 巡检使用OPC目录
        string ftpPath = $"{normalizedServer}/OPC/{itemNo}/{fileName}";
        // 构建FTP文件路径 - 巡检使用OPC目录,如果传入了projName则使用新格式
        string ftpPath;
        if (!string.IsNullOrEmpty(projName))
        {
            ftpPath = $"{normalizedServer}/OPC/{itemNo}/{projName}/{fileName}";
        }
        else
        {
            ftpPath = $"{normalizedServer}/OPC/{itemNo}/{fileName}";
        }
        
        try
        {
StandardInterface/MESApplication/Controllers/QC/RKJController.cs
@@ -574,16 +574,26 @@
    /// <summary>
    /// 获取附件信息
    /// </summary>
    /// <param name="data">包含itemNo的JSON对象</param>
    /// <param name="data">包含itemNo、projName、fromPage的JSON对象</param>
    /// <returns>附件列表</returns>
    [HttpPost("getAttachments")]
    public ResponseResult GetAttachments([FromBody] JObject data)
    {
        var itemNo = data["itemNo"]?.ToString();
        var projName = data["projName"]?.ToString();
        var fromPage = data["fromPage"]?.ToString(); // 新增参数
        // 条件过滤逻辑:根据fromPage决定是否过滤
        string filterProjName = null;
        if (fromPage == "Detail" && !string.IsNullOrEmpty(projName))
        {
            filterProjName = projName;  // Detail页面需要过滤
        }
        try
        {
            dynamic resultInfos = new System.Dynamic.ExpandoObject();
            var tbBillList = new RKJService().GetAttachments(itemNo);
            var tbBillList = new RKJService().GetAttachments(itemNo, filterProjName);
            if (tbBillList == null || tbBillList.Count == 0)
            {
                return new ResponseResult
@@ -612,10 +622,10 @@
    /// </summary>
    /// <param name="itemNo">物料编码</param>
    /// <param name="fileName">文件名</param>
    /// <param name="ftpServer">FTP服务器地址</param>
    /// <param name="projName">项目名称</param>
    /// <returns>文件内容</returns>
    [HttpGet("PreviewFtpFile")]
    public IActionResult PreviewFtpFile([FromQuery] string itemNo, [FromQuery] string fileName, [FromQuery] string ftpServer)
    [HttpGet("previewFtpFile")]
    public IActionResult PreviewFtpFile([FromQuery] string itemNo, [FromQuery] string fileName, [FromQuery] string projName = null)
    {
        try
        {
@@ -626,7 +636,7 @@
            Response.Headers.Add("Access-Control-Expose-Headers", "Content-Type, Content-Length");
            
            var service = new RKJService();
            var fileBytes = service.GetFtpFile(itemNo, fileName, ftpServer);
            var fileBytes = service.GetFtpFile(itemNo, fileName, projName);
            
            if (fileBytes == null || fileBytes.Length == 0)
            {
@@ -649,10 +659,10 @@
    /// </summary>
    /// <param name="itemNo">物料编码</param>
    /// <param name="fileName">文件名</param>
    /// <param name="ftpServer">FTP服务器地址</param>
    /// <param name="projName">项目名称</param>
    /// <returns>文件下载</returns>
    [HttpGet("DownloadFtpFile")]
    public IActionResult DownloadFtpFile([FromQuery] string itemNo, [FromQuery] string fileName, [FromQuery] string ftpServer)
    [HttpGet("downloadFtpFile")]
    public IActionResult DownloadFtpFile([FromQuery] string itemNo, [FromQuery] string fileName, [FromQuery] string projName = null)
    {
        try
        {
@@ -663,7 +673,7 @@
            Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition, Content-Length, Content-Type");
            
            var service = new RKJService();
            var fileBytes = service.GetFtpFile(itemNo, fileName, ftpServer);
            var fileBytes = service.GetFtpFile(itemNo, fileName, projName);
            
            if (fileBytes == null || fileBytes.Length == 0)
            {
StandardInterface/MESApplication/Controllers/QC/SJController.cs
@@ -375,16 +375,27 @@
    /// <summary>
    /// 获取附件信息
    /// </summary>
    /// <param name="data">包含itemNo的JSON对象</param>
    /// <param name="data">包含itemNo和projName的JSON对象</param>
    /// <returns>附件列表</returns>
    [HttpPost("getAttachments")]
    public ResponseResult GetAttachments([FromBody] JObject data)
    {
        var itemNo = data["itemNo"]?.ToString();
        var projName = data["projName"]?.ToString();
        var fromPage = data["fromPage"]?.ToString();
        // 根据来源页面决定是否过滤
        string filterProjName = null;
        if (fromPage == "Detail" && !string.IsNullOrEmpty(projName))
        {
            filterProjName = projName;  // Detail页面需要过滤
        }
        // Add页面不传递filterProjName,显示所有附件
        try
        {
            dynamic resultInfos = new System.Dynamic.ExpandoObject();
            var tbBillList = new SJService().GetAttachments(itemNo);
            var tbBillList = new SJService().GetAttachments(itemNo, filterProjName);
            if (tbBillList == null || tbBillList.Count == 0)
            {
                return new ResponseResult
@@ -414,13 +425,14 @@
    /// <param name="itemNo">物料编码</param>
    /// <param name="fileName">文件名</param>
    /// <param name="ftpServer">FTP服务器地址</param>
    /// <param name="projName">项目名称</param>
    /// <returns>文件内容</returns>
    [HttpGet("PreviewFtpFile")]
    public IActionResult PreviewFtpFile([FromQuery] string itemNo, [FromQuery] string fileName, [FromQuery] string ftpServer)
    public IActionResult PreviewFtpFile([FromQuery] string itemNo, [FromQuery] string fileName, [FromQuery] string ftpServer, [FromQuery] string projName = null)
    {
        try
        {
            var fileBytes = new SJService().GetFtpFile(itemNo, fileName, ftpServer);
            var fileBytes = new SJService().GetFtpFile(itemNo, fileName, ftpServer, projName);
            if (fileBytes == null)
            {
                return NotFound(new ResponseResult
@@ -451,13 +463,14 @@
    /// <param name="itemNo">物料编码</param>
    /// <param name="fileName">文件名</param>
    /// <param name="ftpServer">FTP服务器地址</param>
    /// <param name="projName">项目名称</param>
    /// <returns>文件下载</returns>
    [HttpGet("DownloadFtpFile")]
    public IActionResult DownloadFtpFile([FromQuery] string itemNo, [FromQuery] string fileName, [FromQuery] string ftpServer)
    public IActionResult DownloadFtpFile([FromQuery] string itemNo, [FromQuery] string fileName, [FromQuery] string ftpServer, [FromQuery] string projName = null)
    {
        try
        {
            var fileBytes = new SJService().GetFtpFile(itemNo, fileName, ftpServer);
            var fileBytes = new SJService().GetFtpFile(itemNo, fileName, ftpServer, projName);
            if (fileBytes == null)
            {
                return NotFound(new ResponseResult
StandardInterface/MESApplication/Controllers/QC/XJController.cs
@@ -610,10 +610,24 @@
    public ResponseResult GetAttachments([FromBody] JObject data)
    {
        var itemNo = data["itemNo"]?.ToString();
        var projName = data["projName"]?.ToString();
        var fromPage = data["fromPage"]?.ToString(); // 新增参数
        // 调试日志
        Console.WriteLine($"XJController.GetAttachments 接收参数: itemNo='{itemNo}', projName='{projName}', fromPage='{fromPage}'");
        // 条件过滤逻辑:根据fromPage决定是否过滤
        string filterProjName = null;
        if (fromPage == "Detail" && !string.IsNullOrEmpty(projName))
        {
            filterProjName = projName;  // Detail页面需要过滤
        }
        // Add页面不传递filterProjName,显示所有附件
        try
        {
            dynamic resultInfos = new System.Dynamic.ExpandoObject();
            var tbBillList = new XJService().GetAttachments(itemNo);
            var tbBillList = new XJService().GetAttachments(itemNo, filterProjName);
            if (tbBillList == null || tbBillList.Count == 0)
            {
                return new ResponseResult
@@ -643,9 +657,10 @@
    /// <param name="itemNo">物料编码</param>
    /// <param name="fileName">文件名</param>
    /// <param name="ftpServer">FTP服务器地址</param>
    /// <param name="projName">项目名称(可选)</param>
    /// <returns>文件内容</returns>
    [HttpGet("PreviewFtpFile")]
    public IActionResult PreviewFtpFile([FromQuery] string itemNo, [FromQuery] string fileName, [FromQuery] string ftpServer)
    public IActionResult PreviewFtpFile([FromQuery] string itemNo, [FromQuery] string fileName, [FromQuery] string ftpServer, [FromQuery] string projName = null)
    {
        try
        {
@@ -656,7 +671,7 @@
            Response.Headers.Add("Access-Control-Expose-Headers", "Content-Type, Content-Length");
            
            var service = new XJService();
            var fileBytes = service.GetFtpFile(itemNo, fileName, ftpServer);
            var fileBytes = service.GetFtpFile(itemNo, fileName, ftpServer, projName);
            
            if (fileBytes == null || fileBytes.Length == 0)
            {
@@ -680,9 +695,10 @@
    /// <param name="itemNo">物料编码</param>
    /// <param name="fileName">文件名</param>
    /// <param name="ftpServer">FTP服务器地址</param>
    /// <param name="projName">项目名称(可选)</param>
    /// <returns>文件下载</returns>
    [HttpGet("DownloadFtpFile")]
    public IActionResult DownloadFtpFile([FromQuery] string itemNo, [FromQuery] string fileName, [FromQuery] string ftpServer)
    public IActionResult DownloadFtpFile([FromQuery] string itemNo, [FromQuery] string fileName, [FromQuery] string ftpServer, [FromQuery] string projName = null)
    {
        try
        {
@@ -693,7 +709,7 @@
            Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition, Content-Length, Content-Type");
            
            var service = new XJService();
            var fileBytes = service.GetFtpFile(itemNo, fileName, ftpServer);
            var fileBytes = service.GetFtpFile(itemNo, fileName, ftpServer, projName);
            
            if (fileBytes == null || fileBytes.Length == 0)
            {