1.修复多账套对接时报工切换账套不生效(严重bug)

2.切换底层逻辑,增加外部增加数据源的接口
3.增加缓存,减少频繁登录导致可能存在的突发数据库连接异常
This commit is contained in:
minjQiu
2024-07-14 18:01:02 +08:00
parent 71e2904de7
commit ad475d4ffe
24 changed files with 1161 additions and 105 deletions
@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
// ReSharper disable InconsistentNaming
// ReSharper disable IdentifierTypo
// ReSharper disable StringLiteralTypo
namespace UFIDA.U8.Framework.Api.ControlObject.Common
{
public class BEHelper
{
private readonly dynamic _be;
private readonly PropertyInfo[] _props;
public BEHelper(dynamic be)
{
_be = be;
var tp = be.GetType();
_props = tp.GetProperties();
}
public void SetValue(Dictionary<string,object> dictionary)
{
foreach (var key in dictionary.Keys)
{
if (key.Contains("define") && !key.Contains("chdefine"))
{
var defineCode = int.Parse(key.Replace("define", ""));
if (dictionary.TryGetValue(key, out var bValue) && !string.IsNullOrWhiteSpace($"{bValue}"))
{
_be.UserDefinedItem[defineCode] = dictionary[key];
}
}
else if (key.Contains("chdefine"))
{
var defineCode = int.Parse(key.Replace("chdefine", ""));
if (dictionary.TryGetValue(key, out var bValue) && !string.IsNullOrWhiteSpace($"{bValue}"))
{
_be.ExtendUserDefineItem[defineCode] = dictionary[key];
}
}
else if (key != "body")
{
if (!string.IsNullOrWhiteSpace($"{dictionary[key]}") && _props.Any(a => string.Equals(a.Name, key, StringComparison.OrdinalIgnoreCase)))
{
var prop = _props.First(a => string.Equals(a.Name, key, StringComparison.OrdinalIgnoreCase));
if (prop.PropertyType == typeof(string))
{
prop.SetValue(_be, dictionary[key]);
}
if (prop.PropertyType == typeof(DateTime))
{
prop.SetValue(_be, DateTime.Parse($"{dictionary[key]}"));
}
if (prop.PropertyType == typeof(byte))
{
prop.SetValue(_be, byte.Parse($"{dictionary[key]}"));
}
if (prop.PropertyType == typeof(int))
{
prop.SetValue(_be, int.Parse($"{dictionary[key]}"));
}
if (prop.PropertyType == typeof(long))
{
prop.SetValue(_be, long.Parse($"{dictionary[key]}"));
}
if (prop.PropertyType == typeof(decimal))
{
prop.SetValue(_be, decimal.Parse($"{dictionary[key]}"));
}
}
}
}
}
}
}
@@ -0,0 +1,47 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
namespace UFIDA.U8.Framework.Api.ControlObject.Json
{
public static class JsonHelper
{
public static object ToJson(this string Json)
{
return Json == null ? null : JsonConvert.DeserializeObject(Json);
}
public static string ToJson(this object obj)
{
var timeConverter = new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" };
return JsonConvert.SerializeObject(obj, timeConverter);
}
public static string ToJson(this object obj, string datetimeformats)
{
var timeConverter = new IsoDateTimeConverter { DateTimeFormat = datetimeformats };
return JsonConvert.SerializeObject(obj, timeConverter);
}
public static T ToObject<T>(this string Json)
{
return Json == null ? default : JsonConvert.DeserializeObject<T>(Json);
}
public static List<T> ToList<T>(this string Json)
{
return Json == null ? null : JsonConvert.DeserializeObject<List<T>>(Json);
}
public static DataTable ToTable(this string Json)
{
return Json == null ? null : JsonConvert.DeserializeObject<DataTable>(Json);
}
public static JObject ToJObject(this string Json)
{
return JObject.Parse(Json.Replace("&nbsp;", ""));
}
}
}
@@ -14,7 +14,7 @@ namespace UFIDA.U8.Framework.Api.ControlObject.Models
/// <summary>
/// 登录子系统ID,具体可以查看系统启用
/// </summary>
public string pSubId { get; set; } = "AS";
public string pSubId { get; set; } = "DP";
/// <summary>
/// 账套ID,一般为数据源@账套号
@@ -50,10 +50,5 @@ namespace UFIDA.U8.Framework.Api.ControlObject.Models
/// 序列号,一般不填
/// </summary>
public string cSerial { get; set; } = "";
/// <summary>
/// 账套信息标识
/// </summary>
public string cToken { get; set; } = "";
}
}
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UFIDA.U8.Framework.Api.ControlObject.Models
{
/// <summary>
/// 通用状态枚举
/// </summary>
[Description("通用状态枚举")]
public enum StatusEnum
{
/// <summary>
/// 启用
/// </summary>
[Description("启用")]
Enable = 1,
/// <summary>
/// 停用
/// </summary>
[Description("停用")]
Disable = 2,
}
}
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UFIDA.U8.Framework.Api.ControlObject.Models
{
public class SysU8AccountConfig
{
/// <summary>
/// 系统号
/// </summary>
public virtual string cAccountNo { get; set; }
/// <summary>
/// 账套号
/// </summary>
public virtual string cAcc_Id { get; set; }
/// <summary>
/// 账套名称
/// </summary>
public virtual string cAcc_Name { get; set; }
/// <summary>
/// 账套数据源
/// </summary>
public virtual string cAcc_DataSource { get; set; }
/// <summary>
/// 用户ID
/// </summary>
public virtual string cUser_Id { get; set; }
/// <summary>
/// 用户名
/// </summary>
public virtual string cUser_Name { get; set; }
/// <summary>
/// 密码
/// </summary>
public virtual string cPassword { get; set; }
/// <summary>
/// 服务器地址
/// </summary>
public virtual string cSrv { get; set; }
/// <summary>
/// 状态
/// </summary>
public virtual StatusEnum Status { get; set; } = StatusEnum.Enable;
/// <summary>
/// 备注
/// </summary>
public virtual string Remark { get; set; }
}
}
@@ -19,7 +19,7 @@ namespace UFIDA.U8.Framework.Api.ControlObject.U8M
private NetLogin _netLogin { get; set; }
private VBLogin _vbLogin { get; set; }
private ProductContext _productContext { get; set; }
public ProductContext _productContext { get; set; }
public Connection Connection { get; set; }
@@ -83,49 +83,12 @@ namespace UFIDA.U8.Framework.Api.ControlObject.U8M
Trace.WriteLine($"3--登录令牌:{_vbLogin.userToken}");
//Trace.WriteLine($"4--正在创建应用池:{_netLogin.userToken}");
//var info = U8LoginInfo.CreateInstance(_netLogin.userToken);
//U8LoginInfoPool.Add(_netLogin.userToken, info);
//Trace.WriteLine($"4--创建应用池:{info.U8LoginToken}");
//Trace.WriteLine($"4--正在设置线程登录信息:{_netLogin.userToken}");
//ThreadContext.SetLoginInfo(_netLogin.userToken);
//Trace.WriteLine($"4--设置线程登录信息:{_netLogin.userToken}");
Trace.WriteLine($"4--正在创建应用池:{_netLogin.userToken}");
return;
}
//if (_vbLogin ==null)
//{
// _vbLogin = new VBLogin();
// _vbLogin.ClearError();
// if (!_vbLogin.Login(paramter.pSubId, paramter.pAccId, paramter.pYearId, paramter.pUserId, paramter.pPassword, paramter.pDate, paramter.cSrv, paramter.cSerial) && string.IsNullOrWhiteSpace(_vbLogin.userToken))
// {
// //_vbLogin.ShutDown();
// throw new Exception(_vbLogin.ShareString);
// }
// Trace.WriteLine($"U8版本:{_vbLogin.GetVersionInfo()}");
// Trace.WriteLine($"1--登录令牌:{_netLogin.userToken}");
// if (!string.IsNullOrWhiteSpace(Cryptography.m_userToken))
// {
// Cryptography.m_userToken = "";
// }
//}
//if (!string.IsNullOrWhiteSpace(Cryptography.m_userToken))
//{
// Cryptography.m_userToken = "";
//}
_productContext = _netLogin.Login("AS", _vbLogin.userToken);
Trace.WriteLine($"3--上下文令牌:{_productContext.calledContext.token}");
@@ -133,25 +96,33 @@ namespace UFIDA.U8.Framework.Api.ControlObject.U8M
if (_productContext == null)
throw new Exception($"2--初始化U8登录上下文失败------{_netLogin.ErrDescript}");
ClientUserContext.Instance.RefreshContext();
Connection = new Connection();
Connection.Open(_vbLogin.UfDbName);
}
public void ShutDown()
{
U8LoginInfoPool.Clear();
U8LoginInfoPool.Remove(_netLogin.userToken);
_vbLogin.ShutDown();
_netLogin.ShutDown();
_netLogin.Dispose();
ThreadContext.ServerToken = null;
_vbLogin?.ShutDown();
_productContext=null;
_netLogin?.ShutDown();
_netLogin?.Dispose();
_vbLogin = null;
_netLogin = null;
if (!string.IsNullOrWhiteSpace(Cryptography.m_userToken))
{
Cryptography.m_userToken = "";
}
}
public bool CheckAccId(string cAccId)
{
return _vbLogin.get_cAcc_Id() == cAccId;
}
}
}
@@ -0,0 +1,127 @@
using log4net;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using UFIDA.U8.Framework.Api.ControlObject.Common;
using UFIDA.U8.Framework.Api.ControlObject.Json;
using UFIDA.U8.Framework.Api.ControlObject.Models;
using UFSoft.U8.Framework.BizBase;
using UFSoft.U8.Framework.ContextSrv;
using UFSoft.U8.Framework.DBConnection;
using UFSoft.U8.Framework.LoginContext;
using UFSoft.U8.U8M.BFDispatcher;
using UFSoft.U8.U8M.Common;
using UFSoft.U8.U8M.DOSchema.SF;
using ThreadContext = UFSoft.U8.Framework.ContextSrv.ThreadContext;
// ReSharper disable IdentifierTypo
// ReSharper disable InconsistentNaming
// ReSharper disable StringLiteralTypo
namespace UFIDA.U8.Framework.Api.ControlObject.U8M
{
public class MoRoutingBill
{
protected readonly ILog logInfo = LogManager.GetLogger("logInfo");
private MoRoutingBillDs GetEmptyDs(string cCardNum)
{
var ds = SFExecutor.BFMoRoutingBill_LoadData("LoadFirst", 0, "", cCardNum, new DefaultContextContainer());
#region 清除数据集里的数据
if (ds.Tables.Contains("fc_MoRoutingBilldetail_ExtraDefine"))
{
ds.Tables["fc_MoRoutingBilldetail_ExtraDefine"].Clear();
}
if (ds.Tables.Contains("fc_MoRoutingBill_ExtraDefine"))
{
ds.Tables["fc_MoRoutingBill_ExtraDefine"].Clear();
}
ds.MoRoutingBillRes.Clear();
ds.MoRoutingBillDetail.Clear();
ds.MoRoutingBill.Clear();
#endregion
return ds;
}
private MoRoutingBillDs GetVoucherDs(string cCardNum, AutoDocNoGenerateParam docNoParam, Dictionary<string, object> input)
{
var ds = GetEmptyDs(cCardNum);
var head = ds.MoRoutingBill.NewMoRoutingBillRow();
ds.MoRoutingBill.AddMoRoutingBillRow(head);
var docNo = U8MCommonExecutor.BFVoucher_GetVoucherID(cCardNum, docNoParam.Paramaters, false, new DefaultContextContainer());
var be = new UFSoft.U8.SF.BE.MoRoutingBill(ds);
be.cVouchType = cCardNum;
be.cVouchCode = "";
var beHead = new BEHelper(be);
beHead.SetValue(input);
if (string.IsNullOrWhiteSpace(be.cVouchCode))
{
be.cVouchCode = docNo;
}
var bodys = input["body"] as List<Dictionary<string, object>> ?? $"{input["body"]}".ToObject<List<Dictionary<string, object>>>();
for (var i = 0; i < bodys.Count; i++)
{
var body = bodys[i];
var detail = be.MoRoutingBillDetails[i];
var beBody = new BEHelper(detail);
beBody.SetValue(body);
}
return (MoRoutingBillDs)be.DataObject;
}
public BaseResult<dynamic> Save(string cCardNum, Dictionary<string, object> input)
{
try
{
var docNoParam = new AutoDocNoGenerateParam(EnumAutoDocNoType.HandAuto, cCardNum)
{
IsCurrentDocNoByHand = false
};
var ds = GetVoucherDs(cCardNum, docNoParam, input);
if (ds == null)
{
throw new Exception("未能构建数据集");
}
//var context = new DefaultContextContainer();
//context.context["taskid"] = taskId;
var id = SFExecutor.BFMoRoutingBill_MoRoutingBillSave(ds, docNoParam, new DefaultContextContainer());
return new BaseResult<dynamic>() { bSuccess = true, message = "新增成功", result = id };
}
catch (Exception ex)
{
logInfo.Error(ex.Message, ex);
return new BaseResult<dynamic>() { bSuccess = false, message = "新增失败", result = ex.Message };
}
}
}
}
@@ -57,6 +57,9 @@
<Reference Include="log4net, Version=2.0.17.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.17\lib\net45\log4net.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
@@ -67,10 +70,15 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="UFSoft.U8.Framework.BE">
<HintPath>D:\U8SOFT\U8M\UFSoft.U8.Framework.BE.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UFSoft.U8.Framework.BF.Dispatcher">
<HintPath>D:\U8SOFT\U8M\UFSoft.U8.Framework.BF.Dispatcher.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UFSoft.U8.Framework.BizBase, Version=1.0.0.0, Culture=neutral, PublicKeyToken=79a4e7ad54eeabca" />
<Reference Include="UFSoft.U8.Framework.Common">
<HintPath>D:\U8SOFT\U8M\UFSoft.U8.Framework.Common.dll</HintPath>
<Private>False</Private>
@@ -79,6 +87,10 @@
<HintPath>D:\U8SOFT\U8M\UFSoft.U8.Framework.ContextSrv.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UFSoft.U8.Framework.DBConnection">
<HintPath>D:\U8SOFT\U8M\UFSoft.U8.Framework.DBConnection.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UFSoft.U8.Framework.Login.BO">
<HintPath>D:\U8SOFT\Framework\UFSoft.U8.Framework.Login.BO.dll</HintPath>
<Private>False</Private>
@@ -92,12 +104,41 @@
<HintPath>D:\U8SOFT\Framework\UFSoft.U8.Framework.LoginContext.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UFSoft.U8.SF.BE">
<HintPath>D:\U8SOFT\U8M\UFSoft.U8.SF.BE.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UFSoft.U8.U8M.BE">
<HintPath>D:\U8SOFT\U8M\UFSoft.U8.U8M.BE.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UFSoft.U8.U8M.BFDispatcher">
<HintPath>D:\U8SOFT\U8M\UFSoft.U8.U8M.BFDispatcher.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UFSoft.U8.U8M.Common">
<HintPath>D:\U8SOFT\U8M\UFSoft.U8.U8M.Common.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UFSoft.U8.U8M.DOConvert">
<HintPath>D:\U8SOFT\U8M\UFSoft.U8.U8M.DOConvert.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UFSoft.U8.U8M.DOSchema">
<HintPath>D:\U8SOFT\U8M\UFSoft.U8.U8M.DOSchema.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Common\BEHelper.cs" />
<Compile Include="Json\JsonHelper.cs" />
<Compile Include="Models\BaseResult.cs" />
<Compile Include="Models\LoginParamter.cs" />
<Compile Include="Models\StatusEnum.cs" />
<Compile Include="Models\SysU8AccountConfig.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="U8M\BaseLogin.cs" />
<Compile Include="U8M\MoRoutingBill.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="AA\" />
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.17" targetFramework="net48" />
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
</packages>