using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Dynamic; using MES.Service.service; using MES.Service.Dto.webApi; using MES.Service.util; using Newtonsoft.Json; using MES.Service.Modes; namespace MESApplication.Controllers { [ApiController] [Route("api/[controller]")] public class ERPZJDBController : ControllerBase { private readonly ERPZJDBManager _manager = new(); // 这里对应新的 Service private readonly MessageCenterManager _messageManager = new(); private const string METHOD = "POST"; private const string TableName = "ERPZJDB"; private const string URL = "http://localhost:10054/api/ERPZJDB/"; /// /// 保存单条调拨单 /// [HttpPost("Save")] public ResponseResult Save([FromBody] ERPZJDB data) { var msg = new MessageCenter { TableName = TableName, Url = URL + "Save", Method = METHOD, Data = JsonConvert.SerializeObject(data), Status = 1, CreateBy = "PL017", Route = data.ERPZJDBA.billno // 注意取 billno }; try { dynamic resultInfos = new ExpandoObject(); var success = _manager.Save(data); resultInfos.tbBillList = success; msg.Result = success ? (short?)1 : (short?)0; msg.DealWith = 1; _messageManager.save(msg); return new ResponseResult { status = 0, message = "OK", data = resultInfos }; } catch (Exception ex) { msg.Result = 0; msg.DealWith = 0; msg.ResultData = ex.Message; _messageManager.save(msg); return ResponseResult.ResponseError(ex); } } /// /// 批量保存调拨单 /// [HttpPost("SaveList")] public ResponseResult SaveList([FromBody] List dataList) { var msg = new MessageCenter { TableName = TableName, Url = URL + "SaveList", Method = METHOD, Data = JsonConvert.SerializeObject(dataList), Status = 1, CreateBy = "PL017" }; try { dynamic resultInfos = new ExpandoObject(); var success = _manager.SaveList(dataList); resultInfos.tbBillList = success; msg.Result = success ? (short?)1 : (short?)0; msg.DealWith = 1; _messageManager.save(msg); return new ResponseResult { status = 0, message = "OK", data = resultInfos }; } catch (Exception ex) { msg.Result = 0; msg.DealWith = 0; msg.ResultData = ex.Message; _messageManager.save(msg); return ResponseResult.ResponseError(ex); } } } }