using log4net; using Microsoft.Extensions.Caching.Memory; using System; using System.Collections.Generic; using System.Threading.Tasks; using System.Web.Http; using UFIDA.U8.Framework.Api.ControlObject.AP; using UFIDA.U8.Framework.Api.ControlObject.Models; using UFIDA.U8.Framework.Api.ControlObject.U8M; using UFIDA.U8.Framework.Api.Unit; // ReSharper disable InconsistentNaming namespace UFIDA.U8.Framework.Api.Controllers.U8 { public class APController : 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/AP/{cCardNum}/CloseBillSave")] [Route("api/U8/AR/{cCardNum}/CloseBillSave")] public async Task> CloseBillSave(string cAccId, string cCardNum, [FromBody] Dictionary input) { try { if (!_cache.TryGetValue($"U8AP_{cAccId}", out BaseLogin baseLogin)) { baseLogin = new BaseLogin(); var param = await CommUnit.GetLoginParamter(cAccId); if (param == null) { throw new Exception("未能加载指定系统号的登录信息"); } baseLogin.Init(param, false); _cache.Set($"U8AP_{cAccId}", baseLogin); } var subId = ""; if (cCardNum == "AP48") { subId = "AR"; } if (cCardNum == "AP49") { subId = "AP"; } if (string.IsNullOrWhiteSpace(subId)) throw new Exception("单据标识不正确"); var bo = new UFAPBO(); var res = bo.CloseBillSave(baseLogin, input, subId); 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/AR/AP48/CloseBillSave")] public async Task> AP48Save(string cAccId, [FromBody] Dictionary input) { return await CloseBillSave(cAccId, "AP48", input); } /// /// 收款单保存 /// /// /// /// [HttpPost] [Route("api/U8/AP/AP49/CloseBillSave")] public async Task> AP49Save(string cAccId, [FromBody] Dictionary input) { return await CloseBillSave(cAccId, "AP49", input); } } }