using System.Dynamic;
|
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 XJController : ControllerBase
|
{
|
[HttpPost("getAll")]
|
public ResponseResult getAll([FromBody] JObject data)
|
{
|
var modify1Flag = Convert.ToInt32(data["modify1Flag"].ToString());
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
// var tbBillList =
|
// new XJService().getAll(modify1Flag);
|
// resultInfos.tbBillList = tbBillList;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
//getMaxReleaseNo
|
[HttpPost("getMaxReleaseNo")]
|
public ResponseResult getMaxReleaseNo()
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new XJService().getMaxReleaseNo();
|
resultInfos.tbBillList = tbBillList;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
//getLine
|
[HttpPost("getLineAll")]
|
public ResponseResult getLineAll()
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new XJService().getLineAll();
|
resultInfos.tbBillList = tbBillList;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
|
/// <summary>
|
/// 获取工单
|
/// </summary>
|
[HttpPost("getDaa001")]
|
public ResponseResult getDaa001([FromBody] JObject data)
|
{
|
var daa020 = data["daa020"].ToString();
|
var item = data["item"].ToString();
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new XJService().getDaa001(daa020, item);
|
resultInfos.tbBillList = tbBillList;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
/// <summary>
|
/// 根据产线获取物料编码 lineNo
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost("getBoardItem")]
|
public ResponseResult getBoardItem([FromBody] JObject data)
|
{
|
var lineNo = data["lineNo"].ToString();
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new XJService().getBoardItem(lineNo);
|
resultInfos.tbBillList = tbBillList;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
//getItem
|
[HttpPost("getItem")]
|
public ResponseResult getItem([FromBody] JObject data)
|
{
|
var daa001 = data["daa001"].ToString();
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new XJService().getItem(daa001);
|
resultInfos.tbBillList = tbBillList;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
//setJYItem
|
[HttpPost("setJYItem")]
|
public ResponseResult setJYItem([FromBody] JObject data)
|
{
|
var itemNo = data["itemNo"].ToString();
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new XJService().setJYItem(itemNo);
|
resultInfos.tbBillList = tbBillList;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
//save
|
[HttpPost("save")]
|
public ResponseResult save([FromBody] XJDto xjDto)
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new XJService().save(xjDto);
|
resultInfos.tbBillList = tbBillList;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
[HttpPost("saveItem")]
|
public ResponseResult saveItem([FromBody] XJDto xjDto)
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new XJService().saveItem(xjDto);
|
resultInfos.tbBillList = tbBillList;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
//getPage
|
[HttpPost("getPage")]
|
public ResponseResult getPage([FromBody] XJPageResult queryObj)
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new XJService().getPage(queryObj);
|
resultInfos.tbBillList = tbBillList;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
//getJYItem
|
[HttpPost("getJYItem")]
|
public ResponseResult getJYItem([FromBody] JObject data)
|
{
|
var pid = data["pid"]?.ToString();
|
var id = data["id"]?.ToString();
|
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new XJService().getJYItem(Convert.ToDecimal(pid),
|
Convert.ToDecimal(id));
|
resultInfos.tbBillList = tbBillList;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
//getXjDetail02ById
|
[HttpPost("getXjDetail02ById")]
|
public ResponseResult getXjDetail02ById([FromBody] JObject data)
|
{
|
var id = data["id"]?.ToString();
|
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new XJService().getXjDetail02ById(Convert.ToDecimal(id));
|
resultInfos.tbBillList = tbBillList;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
[HttpPost("SetQSItemDetail")]
|
public ResponseResult SetQSItemDetail([FromBody] QsQaItemXj02 detail)
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList = new XJService();
|
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("UpdateQSItemDetail")]
|
public ResponseResult UpdateQSItemDetail(
|
[FromBody] QsQaItemXj02 detail)
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList = new XJService();
|
var detail021 = tbBillList.UpdateQSItemDetail(detail);
|
resultInfos.tbBillList = detail021;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
|
//getQSWorkno 初始化获取单据号
|
[HttpPost("getQSWorkno")]
|
public ResponseResult getQSWorkno([FromBody] JObject data)
|
{
|
var pid = data["pid"]?.ToString();
|
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList = new XJService();
|
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);
|
}
|
}
|
|
|
//SaveItem
|
[HttpPost("SaveWorkNo")]
|
public ResponseResult SaveWorkNo([FromBody] XJDto data)
|
{
|
|
try
|
{
|
// 将单个数据转换为列表
|
// var dataList = new List<QsItemIpiworkno> { data.Worknos };
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new XJService().SaveWorkNo(data.worknos);
|
resultInfos.tbBillList = tbBillList;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
//removeXJ
|
[HttpPost("removeXJ")]
|
public ResponseResult removeXJ([FromBody] JObject data)
|
{
|
var id = data["id"]?.ToString();
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new XJService().removeXJ(Convert.ToDecimal(id));
|
resultInfos.tbBillList = tbBillList;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
|
//saveRemarksGid
|
[HttpPost("saveRemarksGid")]
|
public ResponseResult saveRemarksGid([FromBody] XJDto rkjDto)
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new XJService().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] XJDto rkjDto)
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new XJService().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] XJDto rkjDto)
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new XJService().saveRemarksById(rkjDto);
|
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/XJ/" + 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/XJ/" + 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/XJ/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);
|
}
|
|
}
|