using log4net; using Microsoft.Extensions.Caching.Memory; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Web; using System.Web.Http; using UFIDA.U8.Framework.Api.ControlObject.AP; using UFIDA.U8.Framework.Api.ControlObject.Entity; using UFIDA.U8.Framework.Api.ControlObject.ST; using UFIDA.U8.Framework.Api.ControlObject.U8M; using UFIDA.U8.Framework.Api.Unit; namespace UFIDA.U8.Framework.Api.Controllers.U8 { public class STController : ApiController { /// /// 日志组件 /// protected readonly ILog logInfo = LogManager.GetLogger("logInfo"); private static readonly MemoryCache _cache = new MemoryCache(new MemoryCacheOptions { ExpirationScanFrequency = TimeSpan.FromMinutes(10) }); /// /// 新增单据 /// /// /// /// /// /// /// /// /// /// [HttpPost] [Route("api/U8/ST/0411/Insert")] public async Task> Insert(string cAccId, string cCardNum,[FromBody] Dictionary input, bool bCheck = true,bool bBeforCheckStock=true,bool bIsRedVouch=false,string sAddedState="",bool bReMote=false) { try { if (!_cache.TryGetValue($"U8_{cAccId}", out BaseLogin baseLogin)) { baseLogin = new BaseLogin(); var param = await CommUnit.GetLoginParamter(cAccId); if (param == null) { throw new Exception("未能加载指定系统号的登录信息"); } baseLogin.Init(param, false); _cache.Clear(); _cache.Set($"U8_{cAccId}", baseLogin); } var bo = new USERPCO(); var res =await bo.Insert(baseLogin, input, "11", bCheck, bBeforCheckStock, bIsRedVouch, sAddedState, bReMote); return res; } catch (Exception ex) { logInfo.Error(ex.Message, ex); return new BaseResult { bSuccess = false, message = ex.Message, result = ex.StackTrace }; } } /// /// 更新单据 /// /// /// /// /// /// /// /// /// /// [HttpPost] [Route("api/U8/ST/0411/Update")] public async Task> Update(string cAccId, string cCardNum, [FromBody] Dictionary input, bool bCheck = true, bool bBeforCheckStock = true, bool bIsRedVouch = false, string sAddedState = "", bool bUpdateNeedEas = true) { try { if (!_cache.TryGetValue($"U8_{cAccId}", out BaseLogin baseLogin)) { baseLogin = new BaseLogin(); var param = await CommUnit.GetLoginParamter(cAccId); if (param == null) { throw new Exception("未能加载指定系统号的登录信息"); } baseLogin.Init(param, false); _cache.Clear(); _cache.Set($"U8_{cAccId}", baseLogin); } var bo = new USERPCO(); var res = await bo.Update(baseLogin, input, "0412", "11", bCheck, bBeforCheckStock, bIsRedVouch, sAddedState, bUpdateNeedEas); return res; } catch (Exception ex) { logInfo.Error(ex.Message, ex); return new BaseResult { bSuccess = false, message = ex.Message, result = ex.StackTrace }; } } } }