xwt
3 天以前 986bbf207ec3ecab9dfbf3fed50b565d2a2676fc
StandardInterface/MESApplication/Controllers/QC/LljController.cs
@@ -39,7 +39,7 @@
    [HttpPost("setJYItem")]
    public ResponseResult setJYItem([FromBody] JObject data)
    {
        var itemNo = data["itemNo"].ToString();
        var itemNo =  Convert.ToDecimal(data["itemNo"].ToString());
        var quantity = Convert.ToDecimal(data["quantity"].ToString());
        var releaseNo = data["releaseNo"].ToString();
        try
@@ -273,4 +273,111 @@
            return ResponseResult.ResponseError(ex);
        }
    }
    [HttpPost("EmergencyRelease")]
    public ResponseResult EmergencyRelease([FromBody] JObject data)
    {
        var id = Convert.ToInt32(data["id"].ToString());
        try
        {
            dynamic resultInfos = new ExpandoObject();
            var tbBillList = new LljService().EmergencyRelease(id);
            resultInfos.tbBillList = tbBillList;
            return new ResponseResult
            {
                status = 0,
                message = "OK",
                data = resultInfos
            };
        }
        catch (Exception ex)
        {
            return ResponseResult.ResponseError(ex);
        }
    }
    [HttpPost("WithdrawEmergencyRelease")]
    public ResponseResult WithdrawEmergencyRelease([FromBody] JObject data)
    {
        var id = Convert.ToInt32(data["id"].ToString());
        try
        {
            dynamic resultInfos = new ExpandoObject();
            var tbBillList = new LljService().WithdrawEmergencyRelease(id);
            resultInfos.tbBillList = tbBillList;
            return new ResponseResult
            {
                status = 0,
                message = "OK",
                data = resultInfos
            };
        }
        catch (Exception ex)
        {
            return ResponseResult.ResponseError(ex);
        }
    }
    [HttpPost("getAttachments")]
    public ResponseResult GetAttachments([FromBody] JObject data)
    {
        var releaseNo = data["releaseNo"]?.ToString();
        try
        {
            dynamic resultInfos = new System.Dynamic.ExpandoObject();
            var tbBillList = new LljService().GetAttachments(releaseNo);
            if (tbBillList == null || tbBillList.Count == 0)
            {
                return new ResponseResult
                {
                    status = 1,
                    message = "该检验单未上传附件信息!",
                    data = null
                };
            }
            resultInfos.tbBillList = tbBillList;
            return new ResponseResult
            {
                status = 0,
                message = "OK",
                data = resultInfos
            };
        }
        catch (Exception ex)
        {
            return ResponseResult.ResponseError(ex);
        }
    }
    [HttpGet("DownloadFtpFile")]
    public IActionResult DownloadFtpFile([FromQuery] string itemNo, [FromQuery] string fileName)
    {
        // FTP服务器信息
        string ftpServer = "ftp://36.26.21.214";
        string ftpUser = "hm_ftp";
        string ftpPwd = "dell_123";
        string ftpPath = $"{ftpServer}/IQC/{itemNo}/{fileName}";
        try
        {
            var request = (System.Net.FtpWebRequest)System.Net.WebRequest.Create(ftpPath);
            request.Method = System.Net.WebRequestMethods.Ftp.DownloadFile;
            request.Credentials = new System.Net.NetworkCredential(ftpUser, ftpPwd);
            request.UseBinary = true;
            request.UsePassive = false;
            using (var response = (System.Net.FtpWebResponse)request.GetResponse())
            using (var ftpStream = response.GetResponseStream())
            using (var ms = new System.IO.MemoryStream())
            {
                ftpStream.CopyTo(ms);
                ms.Position = 0;
                string contentType = "application/octet-stream";
                // 防御性处理,去除fileName中的回车换行和空格
                fileName = fileName?.Trim().Replace("\r", "").Replace("\n", "");
                return File(ms.ToArray(), contentType, fileName);
            }
        }
        catch (Exception ex)
        {
            return BadRequest($"FTP下载失败:{ex.Message},ftpPath={ftpPath},fileName={fileName}");
        }
    }
}