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}/Save")] [Route("api/U8/AR/{cCardNum}/Save")] public async Task> Save(string cAccId, string cCardNum, [FromBody] Dictionary input) { try { switch (cCardNum) { case "AP03": case "AR03": return await ApNoteSave(cAccId, cCardNum, input); case "AP48": case "AP49": case "AR48": case "AR49": return await CloseBillSave(cAccId, cCardNum, input); default: throw new Exception("单据标识不正确"); } } catch (Exception ex) { logInfo.Error(ex.Message, ex); return new BaseResult { bSuccess = false, message = ex.Message, result = ex.StackTrace }; } } /// /// 收付款单保存 /// /// 系统号 /// 单据类型编码 /// 报文数据 /// [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 { var subId = ""; if (cCardNum == "AR48" || cCardNum == "AR49") { subId = "AR"; } if (cCardNum == "AP48" || cCardNum == "AP49") { subId = "AP"; } if (!_cache.TryGetValue($"U8AP_{cAccId}_{subId}", 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($"U8AP_{cAccId}_{subId}", baseLogin); } 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/Save")] [Route("api/U8/AR/AP49/Save")] public async Task> AP48Save(string cAccId, [FromBody] Dictionary input) { return await CloseBillSave(cAccId, "AP48", input); } /// /// 收款单保存 /// /// /// /// [HttpPost] [Route("api/U8/AP/AP49/Save")] [Route("api/U8/AP/AP49/Save")] public async Task> AP49Save(string cAccId, [FromBody] Dictionary input) { return await CloseBillSave(cAccId, "AP49", input); } /// /// 票据保存 /// /// 系统号 /// 单据类型编码 /// 报文数据 /// [HttpPost] [Route("api/U8/AP/{cCardNum}/ApNoteSave")] [Route("api/U8/AR/{cCardNum}/ApNoteSave")] public async Task> ApNoteSave(string cAccId, string cCardNum, [FromBody] Dictionary input) { try { var subId = ""; if (cCardNum == "AR03") { subId = "AR"; } if (cCardNum == "AP03") { subId = "AP"; } if (!_cache.TryGetValue($"U8AP_{cAccId}_{subId}", out BaseLogin baseLogin)) { baseLogin = new BaseLogin(); var param = await CommUnit.GetLoginParamter(cAccId); if (param == null) { throw new Exception("未能加载指定系统号的登录信息"); } param.pSubId = subId; baseLogin.Init(param, false); _cache.Set($"U8AP_{cAccId}_{subId}", baseLogin); } if (string.IsNullOrWhiteSpace(subId)) throw new Exception("单据标识不正确"); var bo = new UFAPBO(); var res = bo.ApNoteSave(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/AP/AP03/Save")] public async Task> AP03Save(string cAccId, [FromBody] Dictionary input) { return await ApNoteSave(cAccId, "AP03", input); } /// /// 票据保存 /// /// /// /// [HttpPost] [Route("api/U8/AR/AR03/Save")] public async Task> AR03Save(string cAccId, [FromBody] Dictionary input) { return await ApNoteSave(cAccId, "AR03", input); } } }