using log4net; using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Net; using System.Net.Http; using System.Threading.Tasks; using System.Web.Http; using Microsoft.Extensions.Caching.Memory; using SqlSugar; using UFIDA.U8.Framework.Api.Common.Unit.GM; using UFIDA.U8.Framework.Api.ControlObject.Models; using UFIDA.U8.Framework.Api.ControlObject.U8M; using UFIDA.U8.Framework.Api.Unit; namespace UFIDA.U8.Framework.Api.Controllers.U8 { /// /// 车间管理 /// public class SFCController : ApiController { protected readonly ILog logInfo = LogManager.GetLogger("logInfo"); private static MemoryCache _cache = new MemoryCache(new MemoryCacheOptions() { ExpirationScanFrequency = TimeSpan.FromMinutes(10) }); /// /// 新增单据 /// /// 系统号 /// 单据类型编码 /// 报文数据 /// [HttpPost] [Route("api/U8/SFC/Save")] public async Task> Save(string cAccId,string cCardNum, [FromBody] Dictionary input) { try { if (!_cache.TryGetValue($"U8M_Single", out BaseLogin baseLogin)) { baseLogin = new BaseLogin(); var param = await CommUnit.GetLoginParamter(cAccId); if (param == null) { throw new Exception("未能加载指定系统号的登录信息"); } baseLogin.Init(param); _cache.Set("U8M_Single", baseLogin); } else { var param = await CommUnit.GetLoginParamter(cAccId); if (param == null) { throw new Exception("未能加载指定系统号的登录信息"); } if (!baseLogin.CheckAccId(param.pAccId)) { baseLogin.ShutDown(); baseLogin.Init(param); } _cache.Remove("U8M_Single"); _cache.Set("U8M_Single", baseLogin); } var bf = new MoRoutingBill(); var res=bf.Save( cCardNum, input); return res; } catch (Exception ex) { logInfo.Error(ex.Message, ex); return new BaseResult {bSuccess = false,message = ex.Message,result = ex.StackTrace}; } } } }