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 LljController : ControllerBase
|
{
|
[HttpPost("getPage")]
|
public ResponseResult getPage([FromBody] XJPageResult queryObj)
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var (item, totalCount) = new LljService().GetPage(queryObj);
|
var tbBillList =
|
resultInfos.tbBillList = item;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos,
|
TotalCount = totalCount
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
|
[HttpPost("setJYItem")]
|
public ResponseResult setJYItem([FromBody] JObject data)
|
{
|
var itemNo = Convert.ToDecimal(data["itemNo"].ToString());
|
var quantity = Convert.ToDecimal(data["quantity"].ToString());
|
var releaseNo = data["releaseNo"].ToString();
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new LljService().SetItems(itemNo, quantity, releaseNo);
|
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] LLJDto lljDto)
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new LljService().saveItem(lljDto);
|
resultInfos.tbBillList = tbBillList;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
//getItems
|
[HttpPost("getJYItem")]
|
public ResponseResult getJYItem([FromBody] JObject data)
|
{
|
var id = data["id"]?.ToString();
|
var releaseNo = data["releaseNo"]?.ToString();
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new LljService().GetItems(releaseNo,
|
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 LljService().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] MesQaItemsDetectDetail12 detail)
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList = new LljService();
|
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] MesQaItemsDetectDetail12 detail)
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList = new LljService();
|
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] LLJDto rkjDto)
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new LljService().saveRemarksGid(rkjDto);
|
resultInfos.tbBillList = tbBillList;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
//savePhsyGid 主表添加破坏实验
|
[HttpPost("savePhsyGid")]
|
public ResponseResult savePhsyGid([FromBody] LLJDto rkjDto)
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new LljService().savePhsyGid(rkjDto);
|
resultInfos.tbBillList = tbBillList;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
[HttpPost("saveDropdownFields")]
|
public ResponseResult saveDropdownFields([FromBody] LLJDto rkjDto)
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new LljService().saveDropdownFields(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] LLJDto rkjDto)
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new LljService().saveRemarksPid(rkjDto);
|
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 releaseNo = data["releaseNo"]?.ToString();
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new LljService().removeXJ(releaseNo);
|
resultInfos.tbBillList = tbBillList;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
//IqcQaSubmit
|
[HttpPost("IqcQaSubmit")]
|
public ResponseResult IqcQaSubmit(LLJDto rkjDto)
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var tbBillList =
|
new LljService().IqcQaSubmit(rkjDto);
|
resultInfos.tbBillList = tbBillList;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
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 itemNo = data["itemNo"]?.ToString();
|
try
|
{
|
dynamic resultInfos = new System.Dynamic.ExpandoObject();
|
var tbBillList = new LljService().GetAttachments(itemNo);
|
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("PreviewFtpFile")]
|
public IActionResult PreviewFtpFile([FromQuery] string itemNo, [FromQuery] string fileName, [FromQuery] string ftpServer)
|
{
|
try
|
{
|
// 添加CORS响应头
|
Response.Headers.Add("Access-Control-Allow-Origin", "*");
|
Response.Headers.Add("Access-Control-Allow-Methods", "GET, OPTIONS");
|
Response.Headers.Add("Access-Control-Allow-Headers", "Content-Type");
|
Response.Headers.Add("Access-Control-Expose-Headers", "Content-Type, Content-Length");
|
|
var service = new LljService();
|
var fileBytes = service.GetFtpFile(itemNo, fileName, ftpServer);
|
|
if (fileBytes == null || fileBytes.Length == 0)
|
{
|
return NotFound("文件在FTP服务器上不存在");
|
}
|
|
var contentType = service.GetContentType(fileName);
|
fileName = fileName?.Trim().Replace("\r", "").Replace("\n", "");
|
|
return File(fileBytes, contentType);
|
}
|
catch (Exception ex)
|
{
|
return StatusCode(500, $"预览文件失败:{ex.Message}");
|
}
|
}
|
|
[HttpGet("DownloadFtpFile")]
|
public IActionResult DownloadFtpFile([FromQuery] string itemNo, [FromQuery] string fileName, [FromQuery] string ftpServer)
|
{
|
try
|
{
|
// 添加CORS响应头 - 关键配置用于解决跨域问题
|
Response.Headers.Add("Access-Control-Allow-Origin", "*");
|
Response.Headers.Add("Access-Control-Allow-Methods", "GET, OPTIONS");
|
Response.Headers.Add("Access-Control-Allow-Headers", "Content-Type, Authorization");
|
Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition, Content-Length, Content-Type");
|
|
var service = new LljService();
|
var fileBytes = service.GetFtpFile(itemNo, fileName, ftpServer);
|
|
if (fileBytes == null || fileBytes.Length == 0)
|
{
|
return NotFound("文件在FTP服务器上不存在");
|
}
|
|
var contentType = service.GetContentType(fileName);
|
fileName = fileName?.Trim().Replace("\r", "").Replace("\n", "");
|
|
// 设置正确的Content-Disposition响应头以支持文件下载
|
var result = File(fileBytes, "application/octet-stream", fileName);
|
|
// 确保Content-Disposition头正确设置,支持中文文件名
|
if (!string.IsNullOrEmpty(fileName))
|
{
|
var encodedFileName = System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8);
|
Response.Headers.Add("Content-Disposition", $"attachment; filename*=UTF-8''{encodedFileName}");
|
}
|
|
return result;
|
}
|
catch (Exception ex)
|
{
|
return StatusCode(500, $"下载文件失败:{ex.Message}");
|
}
|
}
|
|
[HttpOptions("PreviewFtpFile")]
|
[HttpOptions("DownloadFtpFile")]
|
public IActionResult HandleOptions()
|
{
|
// 处理CORS预检请求
|
Response.Headers.Add("Access-Control-Allow-Origin", "*");
|
Response.Headers.Add("Access-Control-Allow-Methods", "GET, OPTIONS");
|
Response.Headers.Add("Access-Control-Allow-Headers", "Content-Type, Authorization");
|
Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition, Content-Length, Content-Type");
|
Response.Headers.Add("Access-Control-Max-Age", "86400");
|
|
return Ok();
|
}
|
[HttpPost("getWomdab")]
|
public ResponseResult getWomdab([FromBody] GetWomdabRequest data)
|
{
|
var daa001 = data.daa001?.ToString();
|
try
|
{
|
dynamic resultInfos = new System.Dynamic.ExpandoObject();
|
var tbBillList = new LljService().GetWomdab(daa001);
|
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);
|
}
|
}
|
|
|
[HttpPost("GetWomdabById")]
|
public ResponseResult GetWomdabById([FromBody] GetWomdabRequest data)
|
{
|
var daa001 = data.daa001?.ToString();
|
var ItemNo = data.ItemNo?.ToString();
|
try
|
{
|
dynamic resultInfos = new System.Dynamic.ExpandoObject();
|
var tbBillList = new LljService().GetWomdabById(daa001,ItemNo);
|
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);
|
}
|
}
|
|
/// <summary>
|
/// 根据二维码查询物料信息
|
/// </summary>
|
/// <param name="data">包含二维码内容和当前到货单号的请求对象</param>
|
/// <returns>物料信息</returns>
|
[HttpPost("GetMaterialByBarcode")]
|
public ResponseResult GetMaterialByBarcode([FromBody] GetMaterialByBarcodeRequest data)
|
{
|
try
|
{
|
if (string.IsNullOrEmpty(data.itemBarcode))
|
{
|
return new ResponseResult
|
{
|
status = 1,
|
message = "二维码内容不能为空",
|
data = null
|
};
|
}
|
|
dynamic resultInfos = new System.Dynamic.ExpandoObject();
|
var materialInfo = new LljService().GetMaterialByBarcode(data.itemBarcode, data.currentBillNo);
|
|
if (materialInfo == null || materialInfo.Count == 0)
|
{
|
return new ResponseResult
|
{
|
status = 1,
|
message = "未找到对应的物料信息,请检查二维码是否正确",
|
data = null
|
};
|
}
|
|
resultInfos.tbBillList = materialInfo;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "查询成功",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return new ResponseResult
|
{
|
status = 1,
|
message = ex.Message, // 直接返回异常信息,包含"该条码不是此检验单条码!"
|
data = null
|
};
|
}
|
}
|
|
/// <summary>
|
/// 查询破坏实验记录是否存在
|
/// </summary>
|
/// <param name="data">查询请求数据</param>
|
/// <returns>查询结果</returns>
|
[HttpPost("CheckPhsyRecord")]
|
public ResponseResult CheckPhsyRecord([FromBody] CheckPhsyRecordRequest data)
|
{
|
try
|
{
|
if (string.IsNullOrEmpty(data.billNo))
|
{
|
return new ResponseResult
|
{
|
status = 1,
|
message = "到货单号不能为空",
|
data = null
|
};
|
}
|
|
if (string.IsNullOrEmpty(data.releaseNo))
|
{
|
return new ResponseResult
|
{
|
status = 1,
|
message = "检验单号不能为空",
|
data = null
|
};
|
}
|
|
var exists = new LljService().CheckPhsyRecordExists(data.billNo, data.releaseNo);
|
|
dynamic resultInfos = new System.Dynamic.ExpandoObject();
|
resultInfos.exists = exists;
|
|
return new ResponseResult
|
{
|
status = 0,
|
message = "查询成功",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return new ResponseResult
|
{
|
status = 1,
|
message = $"查询失败: {ex.Message}",
|
data = null
|
};
|
}
|
}
|
|
/// <summary>
|
/// 调用破坏实验存储过程
|
/// </summary>
|
/// <param name="data">破坏实验请求数据</param>
|
/// <returns>执行结果</returns>
|
[HttpPost("CallPhsyUpdateProcedure")]
|
public ResponseResult CallPhsyUpdateProcedure([FromBody] PhsyUpdateRequest data)
|
{
|
try
|
{
|
if (string.IsNullOrEmpty(data.itemBarcode))
|
{
|
return new ResponseResult
|
{
|
status = 1,
|
message = "条码不能为空",
|
data = null
|
};
|
}
|
|
if (string.IsNullOrEmpty(data.billNo))
|
{
|
return new ResponseResult
|
{
|
status = 1,
|
message = "到货单号不能为空",
|
data = null
|
};
|
}
|
|
if (data.yqty <= 0)
|
{
|
return new ResponseResult
|
{
|
status = 1,
|
message = "条码数量必须大于0",
|
data = null
|
};
|
}
|
|
if (data.cqty <= 0)
|
{
|
return new ResponseResult
|
{
|
status = 1,
|
message = "破坏实验数量必须大于0",
|
data = null
|
};
|
}
|
|
if (string.IsNullOrEmpty(data.releaseNo))
|
{
|
return new ResponseResult
|
{
|
status = 1,
|
message = "检验单号不能为空",
|
data = null
|
};
|
}
|
|
var (result, message) = new LljService().CallPhsyUpdateProcedure(
|
data.itemBarcode,
|
data.yqty,
|
data.cqty,
|
data.billNo,
|
data.lx,
|
data.releaseNo,
|
data.itemId);
|
|
dynamic resultInfos = new System.Dynamic.ExpandoObject();
|
resultInfos.result = result;
|
resultInfos.message = message;
|
|
return new ResponseResult
|
{
|
status = result,
|
message = message,
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return new ResponseResult
|
{
|
status = 1,
|
message = $"调用存储过程失败: {ex.Message}",
|
data = null
|
};
|
}
|
}
|
|
public class GetWomdabRequest
|
{
|
public string daa001 { get; set; }
|
public string ItemNo { get; set; }
|
}
|
|
public class GetMaterialByBarcodeRequest
|
{
|
public string itemBarcode { get; set; }
|
public string currentBillNo { get; set; }
|
}
|
|
public class PhsyUpdateRequest
|
{
|
public string itemBarcode { get; set; }
|
public decimal yqty { get; set; }
|
public decimal cqty { get; set; }
|
public string billNo { get; set; }
|
public int lx { get; set; } // 操作类型:1新增,2修改,3删除
|
public string releaseNo { get; set; } // 检验单号
|
public decimal? itemId { get; set; } // 物料ID
|
}
|
|
public class CheckPhsyRecordRequest
|
{
|
public string billNo { get; set; }
|
public string releaseNo { get; set; }
|
}
|
|
[HttpPost("GetPhsyRecordInfo")]
|
public ResponseResult GetPhsyRecordInfo([FromBody] CheckPhsyRecordRequest data)
|
{
|
try
|
{
|
if (string.IsNullOrEmpty(data.billNo))
|
{
|
return new ResponseResult
|
{
|
status = 1,
|
message = "到货单号不能为空",
|
data = null
|
};
|
}
|
|
if (string.IsNullOrEmpty(data.releaseNo))
|
{
|
return new ResponseResult
|
{
|
status = 1,
|
message = "检验单号不能为空",
|
data = null
|
};
|
}
|
|
var records = new LljService().GetPhsyRecordInfo(data.billNo, data.releaseNo);
|
|
return new ResponseResult
|
{
|
status = 0,
|
message = "查询成功",
|
data = new { tbBillList = records }
|
};
|
}
|
catch (Exception ex)
|
{
|
return new ResponseResult
|
{
|
status = 1,
|
message = $"查询失败: {ex.Message}",
|
data = null
|
};
|
}
|
}
|
|
/// <summary>
|
/// 设置堵穴信息
|
/// </summary>
|
/// <param name="data">堵穴设置请求数据</param>
|
/// <returns>执行结果</returns>
|
[HttpPost("SetBlockedHoles")]
|
public ResponseResult SetBlockedHoles([FromBody] SetBlockedHolesRequest data)
|
{
|
try
|
{
|
if (string.IsNullOrEmpty(data.releaseNo))
|
{
|
return new ResponseResult
|
{
|
status = 1,
|
message = "检验单号不能为空",
|
data = null
|
};
|
}
|
|
if (string.IsNullOrEmpty(data.blockedHoles))
|
{
|
return new ResponseResult
|
{
|
status = 1,
|
message = "堵穴信息不能为空",
|
data = null
|
};
|
}
|
|
if (data.itemId <= 0)
|
{
|
return new ResponseResult
|
{
|
status = 1,
|
message = "检验项目ID不能为空",
|
data = null
|
};
|
}
|
|
var (result, message) = new LljService().SetBlockedHoles(data.releaseNo, data.blockedHoles, data.itemId);
|
|
return new ResponseResult
|
{
|
status = result,
|
message = message,
|
data = new { result = result, message = message }
|
};
|
}
|
catch (Exception ex)
|
{
|
return new ResponseResult
|
{
|
status = 1,
|
message = $"设置堵穴失败: {ex.Message}",
|
data = null
|
};
|
}
|
}
|
|
|
public class SetBlockedHolesRequest
|
{
|
public string releaseNo { get; set; }
|
public string blockedHoles { get; set; }
|
public decimal itemId { get; set; }
|
}
|
|
|
}
|