using Microsoft.AspNetCore.Mvc; using WalkingTec.Mvvm.Core; using WalkingTec.Mvvm.Mvc; using System.Collections.Generic; using HHWMS.Web.Models; using System.Threading.Tasks; using System.Linq; using Microsoft.EntityFrameworkCore; namespace HHWMS.Web.Areas.Receipt.Controllers { [Area("receipt")] [ActionDescription("入库操作")] public partial class ReceiptInController : BaseController { private readonly IUnitWork _unitWork; public ReceiptInController(IUnitWork unitwork) { _unitWork = unitwork; } #region Index [ActionDescription("Sys.Search")] public ActionResult Index() { return PartialView("Index"); } #endregion Index #region API Methods [HttpPost] public IActionResult GetOperators() { // TODO: 从数据库获取操作员列表 var operators = new List { new { value = "1", label = "张三" }, new { value = "2", label = "李四" } }; return Json(new { Code = 200, Data = operators }); } [HttpPost] public IActionResult GetProcesses() { // TODO: 从数据库获取工序列表 var processes = new List { new { value = "1", label = "工序1" }, new { value = "2", label = "工序2" } }; return Json(new { Code = 200, Data = processes }); } [HttpPost] public IActionResult GetOperatorInfo() { // TODO: 获取当前登录用户信息 return Json(new { Code = 200, Data = "当前操作员:张三" }); } [HttpPost] public IActionResult GetOrdersByMaterial(string materialCode) { // TODO: 根据物料码查询相关生产订单 var orders = new List { new { value = "1", label = "生产订单1" }, new { value = "2", label = "生产订单2" } }; return Json(new { Code = 200, Data = orders }); } [HttpPost] public IActionResult SubmitReceipt([FromBody] ReceiptInModel model) { try { // TODO: 实现入库逻辑 return Json(new { Code = 200, Msg = "入库成功" }); } catch (System.Exception ex) { return Json(new { Code = 500, Msg = ex.Message }); } } /// /// 搜索物料 /// [HttpPost] public IActionResult SearchMaterials(string keyword) { try { if (string.IsNullOrWhiteSpace(keyword)) { return Json(new { Code = 200, Data = new object[] { } }); } var materials = _unitWork.Find (m => m.MaterialCode.Contains(keyword) || m.MaterialName.Contains(keyword)) .Select(m => new { MaterialCode = m.MaterialCode, MaterialName = m.MaterialName }) .Take(10) .ToList(); return Json(new { Code = 200, Data = materials }); } catch (System.Exception ex) { return Json(new { Code = 500, Msg = $"搜索物料失败:{ex.Message}" }); } } #endregion API Methods } public class ReceiptInModel { public string PalletCode { get; set; } public string MaterialCode { get; set; } public string OrderId { get; set; } public string OperatorId { get; set; } public string ProcessId { get; set; } public int Quantity { get; set; } public bool IsQualified { get; set; } public string OperatorInfo { get; set; } } }