using log4net; using Microsoft.Extensions.Caching.Memory; using System; using System.Collections.Generic; using System.Diagnostics.SymbolStore; using System.Threading.Tasks; using System.Web.Http; using UFIDA.U8.Framework.Api.ControlObject.AP; using UFIDA.U8.Framework.Api.ControlObject.Entity; using UFIDA.U8.Framework.Api.ControlObject.U8M; using UFIDA.U8.Framework.Api.Models; 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/{cSubId}/{cCardNum}/Save")] public async Task> Save(string cAccId, string cCardNum, string cSubId, [FromBody] Dictionary input, string busDate="", bool bNeedBillClosed = false) { try { switch (cCardNum) { case "AP03": case "AR03": return await ApNote_Save(cAccId, cSubId, input,busDate, bNeedBillClosed); 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 = "保存失败", result = ex.Message }; } } /// /// 收付款单保存 /// /// 系统号 /// 单据类型编码 /// 报文数据 /// [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 = "保存失败", result = ex.Message }; } } /// /// 收款单保存 /// /// /// /// [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/{cSubId}/RP03/NoteSave")] public async Task> ApNote_Save(string cAccId, string cSubId, [FromBody] Dictionary input, string busDate="",bool bNeedBillClosed=false) { try { if (!_cache.TryGetValue($"U8AP_{cAccId}", out BaseLogin baseLogin)) { baseLogin = new BaseLogin(); var param = await CommUnit.GetLoginParamter(cAccId); if (param == null) { throw new Exception("未能加载指定系统号的登录信息"); } var curDate = Convert.ToDateTime(string.IsNullOrWhiteSpace(busDate) ? $"{DateTime.Today:yyyy-MM-dd}" : busDate); param.pDate = $"{curDate:yyyy-MM-dd}"; param.pYearId = $"{curDate.Year}"; baseLogin.Init(param, false); _cache.Set($"U8AP_{cAccId}", baseLogin); } //if (string.IsNullOrWhiteSpace(cSubId)) // throw new Exception("单据标识不正确"); if (cSubId == "AP") { var bo = new NoteManageAP(); var res =await bo.NoteSave(baseLogin, input, bNeedBillClosed); return res; } else { var bo = new NoteManageAR(); var res = await bo.NoteSave(baseLogin, input, bNeedBillClosed); return res; } } catch (Exception ex) { logInfo.Error(ex.Message, ex); return new BaseResult { bSuccess = false, message ="保存失败", result = ex.Message }; } } } }