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 RKJController : ControllerBase
{
//getMaxReleaseNo
[HttpPost("getMaxReleaseNo")]
public ResponseResult getMaxReleaseNo()
{
try
{
dynamic resultInfos = new ExpandoObject();
var tbBillList =
new RKJService().getMaxBillNo();
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 RKJService().getLineNo();
resultInfos.tbBillList = tbBillList;
return new ResponseResult
{
status = 0,
message = "OK",
data = resultInfos
};
}
catch (Exception ex)
{
return ResponseResult.ResponseError(ex);
}
}
//getDaa001
[HttpPost("getDaa001")]
public ResponseResult getDaa001([FromBody] JObject data)
{
var lineNo = data["lineNo"].ToString();
try
{
dynamic resultInfos = new ExpandoObject();
var tbBillList =
new RKJService().GetDaa001s(lineNo);
resultInfos.tbBillList = tbBillList;
return new ResponseResult
{
status = 0,
message = "OK",
data = resultInfos
};
}
catch (Exception ex)
{
return ResponseResult.ResponseError(ex);
}
}
[HttpPost("setJYItem")]
public ResponseResult setJYItem([FromBody] JObject data)
{
var itemNo = data["itemNo"].ToString();
var quantityStr = data["quantity"]?.ToString();
// 处理quantity为空或无效的情况
decimal quantity = 0;
if (!string.IsNullOrEmpty(quantityStr) && decimal.TryParse(quantityStr, out var parsedQuantity))
{
quantity = parsedQuantity;
}
try
{
dynamic resultInfos = new ExpandoObject();
var tbBillList =
new RKJService().SetItems(itemNo, quantity);
resultInfos.tbBillList = tbBillList;
return new ResponseResult
{
status = 0,
message = "OK",
data = resultInfos
};
}
catch (Exception ex)
{
return ResponseResult.ResponseError(ex);
}
}
[HttpPost("save")]
public ResponseResult save([FromBody] RKJDto rkjDto)
{
try
{
dynamic resultInfos = new ExpandoObject();
var tbBillList =
new RKJService().save(rkjDto);
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] XJPageResult queryObj)
{
try
{
dynamic resultInfos = new ExpandoObject();
var tbBillList =
new RKJService().getPage(queryObj);
resultInfos.tbBillList = tbBillList;
return new ResponseResult
{
status = 0,
message = "OK",
data = resultInfos
};
}
catch (Exception ex)
{
return ResponseResult.ResponseError(ex);
}
}
//getItems
[HttpPost("getItems")]
public ResponseResult getJYItem([FromBody] JObject data)
{
var pid = data["pid"]?.ToString();
var id = data["id"]?.ToString();
try
{
dynamic resultInfos = new ExpandoObject();
var tbBillList =
new RKJService().GetItems(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);
}
}
//removeXJ
[HttpPost("removeXJ")]
public ResponseResult removeXJ([FromBody] JObject data)
{
var id = data["id"]?.ToString();
try
{
dynamic resultInfos = new ExpandoObject();
var tbBillList =
new RKJService().removeXJ(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 RKJService().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] QsItemOqcItemDetail detail)
{
try
{
dynamic resultInfos = new ExpandoObject();
var tbBillList = new RKJService();
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] QsItemOqcItemDetail detail)
{
try
{
dynamic resultInfos = new ExpandoObject();
var tbBillList = new RKJService();
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] RKJDto rkjDto)
{
try
{
dynamic resultInfos = new ExpandoObject();
var tbBillList =
new RKJService().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] RKJDto rkjDto)
{
try
{
dynamic resultInfos = new ExpandoObject();
var tbBillList =
new RKJService().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] RKJDto rkjDto)
{
try
{
dynamic resultInfos = new ExpandoObject();
var tbBillList =
new RKJService().saveRemarksById(rkjDto);
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] RKJDto xjDto)
{
try
{
dynamic resultInfos = new ExpandoObject();
var tbBillList =
new RKJService().saveItem(xjDto);
resultInfos.tbBillList = tbBillList;
return new ResponseResult
{
status = 0,
message = "OK",
data = resultInfos
};
}
catch (Exception ex)
{
return ResponseResult.ResponseError(ex);
}
}
///
/// 获取有线体的部门列表(生产车间)
///
/// 部门列表
[HttpPost("GetDepartmentsWithLines")]
public ResponseResult GetDepartmentsWithLines()
{
try
{
dynamic resultInfos = new ExpandoObject();
var tbBillList = new RKJService().GetDepartmentsWithLines();
resultInfos.tbBillList = tbBillList;
return new ResponseResult
{
status = 0,
message = "OK",
data = resultInfos
};
}
catch (Exception ex)
{
return ResponseResult.ResponseError(ex);
}
}
///
/// 根据部门ID获取该部门下的线体列表
///
/// 包含departmentId的JSON对象
/// 线体列表
[HttpPost("GetLinesByDepartment")]
public ResponseResult GetLinesByDepartment([FromBody] JObject data)
{
var departmentId = data["departmentId"]?.ToString();
try
{
dynamic resultInfos = new ExpandoObject();
var tbBillList = new RKJService().GetLinesByDepartment(departmentId);
resultInfos.tbBillList = tbBillList;
return new ResponseResult
{
status = 0,
message = "OK",
data = resultInfos
};
}
catch (Exception ex)
{
return ResponseResult.ResponseError(ex);
}
}
///
/// 保存部门选择
///
/// 包含id、departmentId、departmentName的JSON对象
/// 保存结果
[HttpPost("SaveDepartmentSelection")]
public ResponseResult SaveDepartmentSelection([FromBody] JObject data)
{
var id = Convert.ToDecimal(data["id"]?.ToString());
var departmentId = data["departmentId"]?.ToString();
var departmentName = data["departmentName"]?.ToString();
try
{
dynamic resultInfos = new ExpandoObject();
var tbBillList = new RKJService().SaveDepartmentSelection(id, departmentId, departmentName);
resultInfos.tbBillList = tbBillList;
return new ResponseResult
{
status = 0,
message = "OK",
data = resultInfos
};
}
catch (Exception ex)
{
return ResponseResult.ResponseError(ex);
}
}
///
/// 提交检验单
///
/// 包含id、userNo的JSON对象
/// 提交结果
[HttpPost("submitInspection")]
public ResponseResult SubmitInspection([FromBody] JObject data)
{
var id = Convert.ToDecimal(data["id"]?.ToString());
var userNo = data["userNo"]?.ToString();
try
{
dynamic resultInfos = new ExpandoObject();
var tbBillList = new RKJService().SubmitInspection(id, userNo);
resultInfos.tbBillList = tbBillList;
return new ResponseResult
{
status = 0,
message = "OK",
data = resultInfos
};
}
catch (Exception ex)
{
return ResponseResult.ResponseError(ex);
}
}
///
/// 刷新检验项目 - 调用存储过程
///
/// 包含id、no、user的JSON对象
/// 刷新结果
[HttpPost("genUpdate")]
public ResponseResult GenUpdate([FromBody] JObject data)
{
try
{
decimal? id = data["id"]?.ToObject();
string? no = data["no"]?.ToString();
string? user = data["user"]?.ToString();
var (result, message) = new RKJService().GenUpdate(id, no, user);
dynamic resultInfos = new ExpandoObject();
resultInfos.result = result;
resultInfos.message = message;
return new ResponseResult
{
status = 0,
message = "OK",
data = resultInfos
};
}
catch (Exception ex)
{
return ResponseResult.ResponseError(ex);
}
}
}