using System.Dynamic;
|
using System.Net;
|
using MES.Service.Dto.service;
|
using MES.Service.Modes;
|
using MES.Service.service.QC;
|
using MES.Service.util;
|
using Microsoft.AspNetCore.Mvc;
|
using Newtonsoft.Json.Linq;
|
|
namespace MESApplication.Controllers.QC;
|
|
[Route("api/[controller]")]
|
[ApiController]
|
public class SJController : ControllerBase
|
{
|
[HttpPost("GetMaxBillNo")]
|
public ResponseResult GetMaxBillNo()
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new SJService().getMaxBillNo();
|
resultInfos.tbBillList = tbBillList;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
|
[HttpPost("GetPage")]
|
public ResponseResult GetPage([FromBody] SJPageResult queryObj)
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new SJService().getPage(queryObj);
|
resultInfos.tbBillList = tbBillList;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
|
//SetQSItems
|
[HttpPost("SetQSItems")]
|
public ResponseResult SetQSItems([FromBody] JObject data)
|
{
|
var itemNo = data["itemNo"].ToString();
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList = new SJService();
|
var detail021 = tbBillList.SetQSItems(itemNo);
|
resultInfos.tbBillList = detail021;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
|
//SetQSItems
|
[HttpPost("getWrokNoDatile")]
|
public ResponseResult getWrokNoDatile([FromBody] JObject data)
|
{
|
var daa001 = data["daa001"].ToString();
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList = new SJService();
|
var detail021 = tbBillList.getWrokNoDatile(daa001);
|
resultInfos.tbBillList = detail021;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
|
[HttpPost("Save")]
|
public ResponseResult Save([FromBody] QsItem item)
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList = new SJService();
|
var detail021 = tbBillList.Save(item);
|
resultInfos.tbBillList = detail021;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
//SaveItem
|
[HttpPost("SaveItem")]
|
public ResponseResult SaveItem([FromBody] QsItem item)
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList = new SJService();
|
var detail021 = tbBillList.SaveItem(item);
|
resultInfos.tbBillList = detail021;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
//SaveItem
|
[HttpPost("SaveWorkNo")]
|
public ResponseResult SaveWorkNo([FromBody] QsItem data)
|
{
|
|
try
|
{
|
// 将单个数据转换为列表
|
// var dataList = new List<QsItemIpiworkno> { data.Worknos };
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new SJService().SaveWorkNo(data.Worknos);
|
resultInfos.tbBillList = tbBillList;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
//getQSItems
|
[HttpPost("getQSItems")]
|
public ResponseResult getQSItems([FromBody] JObject data)
|
{
|
var pid = data["pid"]?.ToString();
|
var id = data["id"]?.ToString();
|
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList = new SJService();
|
var detail021 = tbBillList.getQSItems(Convert.ToDecimal(pid),
|
Convert.ToDecimal(id));
|
resultInfos.tbBillList = detail021;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
|
//getQSItems
|
[HttpPost("getQSWorkno")]
|
public ResponseResult getQSWorkno([FromBody] JObject data)
|
{
|
var pid = data["pid"]?.ToString();
|
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList = new SJService();
|
var detail021 = tbBillList.getQSWorkno(Convert.ToDecimal(pid));
|
resultInfos.tbBillList = detail021;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
|
[HttpPost("SetQSItemDetail")]
|
public ResponseResult SetQSItemDetail([FromBody] QsItemIpiItemDetail detail)
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList = new SJService();
|
var detail021 = tbBillList.SetQSItemDetail(detail);
|
resultInfos.tbBillList = detail021;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
|
[HttpPost("getQSItemDetail")]
|
public ResponseResult getQSItemDetail([FromBody] JObject data)
|
{
|
var pid = data["pid"]?.ToString();
|
var gid = data["gid"]?.ToString();
|
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList = new SJService();
|
var detail021 = tbBillList.getQSItemDetail(Convert.ToDecimal(pid),
|
Convert.ToDecimal(gid));
|
resultInfos.tbBillList = detail021;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
|
[HttpPost("UpdateQSItemDetail")]
|
public ResponseResult UpdateQSItemDetail(
|
[FromBody] QsItemIpiItemDetail detail)
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList = new SJService();
|
var detail021 = tbBillList.UpdateQSItemDetail(detail);
|
resultInfos.tbBillList = detail021;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
//saveRemarksGid
|
[HttpPost("saveRemarksGid")]
|
public ResponseResult saveRemarksGid([FromBody] QsItem rkjDto)
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new SJService().saveRemarksGid(rkjDto);
|
resultInfos.tbBillList = tbBillList;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
//saveRemarksPid
|
[HttpPost("saveRemarksPid")]
|
public ResponseResult saveRemarksPid([FromBody] QsItem rkjDto)
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new SJService().saveRemarksPid(rkjDto);
|
resultInfos.tbBillList = tbBillList;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
//saveRemarksById
|
[HttpPost("saveRemarksById")]
|
public ResponseResult saveRemarksById([FromBody] QsItem rkjDto)
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new SJService().saveRemarksById(rkjDto);
|
resultInfos.tbBillList = tbBillList;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
//removeSJ
|
[HttpPost("removeSJ")]
|
public ResponseResult removeSJ([FromBody] JObject data)
|
{
|
var id = data["id"]?.ToString();
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new SJService().removeXJ(Convert.ToDecimal(id));
|
resultInfos.tbBillList = tbBillList;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
|
|
//FTPLIST
|
[HttpPost("ftpList")]
|
public async Task<ResponseResult> getFtpList([FromBody] JObject data)
|
{
|
var itemno = data["itemno"]?.ToString();
|
|
if (itemno == null || itemno =="") return new ResponseResult
|
{
|
status = 1,
|
message = "未找到该产品的文件信息",
|
data = "未找到该产品的文件信息"
|
};
|
|
var ftpAddress = "ftp://192.168.1.223:21";
|
var username = "administrator";
|
var password = "Rdyl8888";
|
var remotePath = "PQC/SJ/" + itemno;
|
|
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
|
var ftpFiles = new SJService().GetFtpFileList(ftpAddress, username, password, remotePath);
|
resultInfos.tbBillList = ftpFiles;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
|
|
[HttpPost("download")]
|
public async Task<IActionResult> DownloadFile([FromBody] JObject data)
|
{
|
var fileName = data["fileName"]?.ToString();
|
var itemno = data["itemno"]?.ToString();
|
|
var ftpAddress = "ftp://192.168.1.223:21";
|
var username = "administrator";
|
var password = "Rdyl8888";
|
var remotePath = "PQC/SJ/" + itemno;
|
|
try
|
{
|
byte[] fileData = new SJService().DownloadFtpFile(ftpAddress, username, password, $"{remotePath}/{fileName}"); // 拼接完整路径
|
|
// 生成临时访问 URL(示例逻辑)
|
var tempFileId = Guid.NewGuid().ToString();
|
// 将文件缓存到临时目录(实际项目需考虑清理机制)
|
var tempPath = Path.Combine(Path.GetTempPath(), tempFileId);
|
System.IO.File.WriteAllBytes(tempPath, fileData);
|
|
// 返回可直接访问的 URL
|
var baseUrl = $"{Request.Scheme}://{Request.Host}";
|
|
|
|
return Ok(new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = new
|
{
|
url = $"{baseUrl}/api/SJ/downloadTemp?fileId={tempFileId}&fileName={fileName}",
|
mimeType = GetMimeType(fileName)
|
}
|
});
|
}
|
catch (Exception ex)
|
{
|
return BadRequest(ResponseResult.ResponseError(ex));
|
}
|
}
|
|
|
private string GetMimeType(string fileName)
|
{
|
string mimeType = "application/octet-stream";
|
if (fileName.EndsWith(".jpg") || fileName.EndsWith(".jpeg"))
|
{
|
mimeType = "image/jpeg";
|
}
|
else if (fileName.EndsWith(".png"))
|
{
|
mimeType = "image/png";
|
}
|
else if (fileName.EndsWith(".gif"))
|
{
|
mimeType = "image/gif";
|
}
|
else if (fileName.EndsWith(".pdf"))
|
{
|
mimeType = "application/pdf";
|
}
|
else if (fileName.EndsWith(".doc") || fileName.EndsWith(".docx"))
|
{
|
mimeType = "application/msword";
|
}
|
else if (fileName.EndsWith(".xls") || fileName.EndsWith(".xlsx"))
|
{
|
mimeType = "application/vnd.ms-excel";
|
}
|
return mimeType;
|
}
|
|
|
[HttpGet("downloadTemp")]
|
public IActionResult DownloadTemp(string fileId, string fileName)
|
{
|
var tempPath = Path.Combine(Path.GetTempPath(), fileId);
|
if (!System.IO.File.Exists(tempPath))
|
{
|
return NotFound();
|
}
|
var fileBytes = System.IO.File.ReadAllBytes(tempPath);
|
return File(fileBytes, GetMimeType(fileName), fileName);
|
}
|
|
}
|