using System.Dynamic;
|
using MES.Service.Dto.service;
|
using MES.Service.Modes;
|
using MES.Service.service;
|
using MES.Service.service.QC;
|
using MES.Service.util;
|
using Microsoft.AspNetCore.Mvc;
|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
|
namespace MESApplication.Controllers.QC;
|
|
/// <summary>
|
/// SPI/AOI检测数据控制器
|
/// </summary>
|
[Route("api/[controller]")]
|
[ApiController]
|
public class SpiAoiController : ControllerBase
|
{
|
private readonly MessageCenterManager _manager = new();
|
private readonly SpiAoiService _service = new();
|
|
private readonly string METHOD = "POST";
|
private readonly string TableName = "MES_SPI_AOI_HEADER";
|
private readonly string URL = "http://localhost:10054/api/QC/SpiAoi/";
|
|
/// <summary>
|
/// 上传SPI/AOI检测数据
|
/// </summary>
|
/// <param name="request">上传请求</param>
|
/// <returns>上传结果</returns>
|
[HttpPost("Upload")]
|
public ResponseResult Upload([FromBody] SpiAoiUploadRequest request)
|
{
|
var entity = new MessageCenter();
|
entity.TableName = TableName;
|
entity.Url = URL + "Upload";
|
entity.Method = METHOD;
|
entity.Data = JsonConvert.SerializeObject(request);
|
entity.Status = 1;
|
entity.CreateBy = "SPI_AOI_SYSTEM";
|
|
try
|
{
|
var response = _service.UploadSpiAoiData(request);
|
|
dynamic resultInfos = new ExpandoObject();
|
resultInfos.headerId = response.HeaderId;
|
resultInfos.detailCount = response.DetailCount;
|
resultInfos.message = "SPI/AOI检测数据上传成功";
|
|
entity.Result = 1;
|
entity.DealWith = 1;
|
entity.ResultData = JsonConvert.SerializeObject(response);
|
_manager.save(entity);
|
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
entity.Result = 0;
|
entity.DealWith = 0;
|
entity.ResultData = ex.Message;
|
_manager.save(entity);
|
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
/// <summary>
|
/// 根据条码查询SPI/AOI检测数据
|
/// </summary>
|
/// <param name="request">请求参数</param>
|
/// <returns>检测数据</returns>
|
[HttpPost("GetByBarcode")]
|
public ResponseResult GetByBarcode([FromBody] JObject request)
|
{
|
try
|
{
|
var boardBarcode = request["boardBarcode"]?.ToString();
|
if (StringUtil.IsNullOrEmpty(boardBarcode))
|
{
|
return new ResponseResult
|
{
|
status = 1,
|
message = "boardBarcode 不能为空",
|
data = null
|
};
|
}
|
|
var (header, details) = _service.GetByBarcode(boardBarcode);
|
|
if (header == null)
|
{
|
return new ResponseResult
|
{
|
status = 1,
|
message = $"未找到条码 {boardBarcode} 的检测数据",
|
data = null
|
};
|
}
|
|
dynamic resultInfos = new ExpandoObject();
|
resultInfos.header = header;
|
resultInfos.details = details;
|
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
/// <summary>
|
/// 根据ID查询SPI/AOI检测数据
|
/// </summary>
|
/// <param name="request">请求参数</param>
|
/// <returns>检测数据</returns>
|
[HttpPost("GetById")]
|
public ResponseResult GetById([FromBody] JObject request)
|
{
|
try
|
{
|
var headerId = request["headerId"]?.ToObject<decimal>();
|
if (!headerId.HasValue)
|
{
|
return new ResponseResult
|
{
|
status = 1,
|
message = "headerId 不能为空",
|
data = null
|
};
|
}
|
|
var (header, details) = _service.GetById(headerId.Value);
|
|
if (header == null)
|
{
|
return new ResponseResult
|
{
|
status = 1,
|
message = $"未找到ID {headerId} 的检测数据",
|
data = null
|
};
|
}
|
|
dynamic resultInfos = new ExpandoObject();
|
resultInfos.header = header;
|
resultInfos.details = details;
|
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
/// <summary>
|
/// 分页查询SPI/AOI检测数据
|
/// </summary>
|
/// <param name="request">查询请求</param>
|
/// <returns>分页数据</returns>
|
[HttpPost("GetPage")]
|
public ResponseResult GetPage([FromBody] JObject request)
|
{
|
try
|
{
|
var boardBarcode = request["boardBarcode"]?.ToString();
|
var workOrder = request["workOrder"]?.ToString();
|
var surface = request["surface"]?.ToString();
|
var startDate = request["startDate"]?.ToString();
|
var endDate = request["endDate"]?.ToString();
|
var pageIndex = request["pageIndex"]?.ToObject<int>() ?? 1;
|
var pageSize = request["pageSize"]?.ToObject<int>() ?? 20;
|
|
DateTime? startDateTime = null;
|
DateTime? endDateTime = null;
|
|
if (StringUtil.IsNotNullOrEmpty(startDate) &&
|
DateTime.TryParse(startDate, out var start))
|
{
|
startDateTime = start;
|
}
|
|
if (StringUtil.IsNotNullOrEmpty(endDate) &&
|
DateTime.TryParse(endDate, out var end))
|
{
|
endDateTime = end;
|
}
|
|
var (items, totalCount) = _service.GetPage(
|
boardBarcode, workOrder, surface, startDateTime, endDateTime,
|
pageIndex, pageSize);
|
|
dynamic resultInfos = new ExpandoObject();
|
resultInfos.items = items;
|
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos,
|
TotalCount = totalCount
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
}
|